4 my $curuser = $FS::CurrentUser::CurrentUser;
5 die "access denied" unless $curuser->access_right('Post credit');
9 my $conf = new FS::Conf;
11 my $sub = $cgi->param('sub');
15 if ( $sub eq 'calculate_taxes' ) {
19 my %arg = $cgi->param('arg');
21 warn join('', map "$_: $arg{$_}\n", keys %arg )
24 #some false laziness w/cust_credit::credit_lineitems
26 my $cust_main = qsearchs({
27 'table' => 'cust_main',
28 'hashref' => { 'custnum' => $arg{custnum} },
29 'extra_sql' => ' AND '. $curuser->agentnums_sql,
30 }) or die 'unknown customer';
32 my @billpkgnums = split(',', $arg{billpkgnums});
33 my @setuprecurs = split(',', $arg{setuprecurs});
34 my @amounts = split(',', $arg{amounts});
36 my @cust_bill_pkg = ();
38 while ( @billpkgnums ) {
39 my $billpkgnum = shift @billpkgnums;
40 my $setuprecur = shift @setuprecurs;
41 my $amount = shift @amounts;
43 my $cust_bill_pkg = qsearchs({
44 'table' => 'cust_bill_pkg',
45 'hashref' => { 'billpkgnum' => $billpkgnum },
46 'addl_from' => 'LEFT JOIN cust_bill USING (invnum)',
47 'extra_sql' => 'AND custnum = '. $cust_main->custnum,
48 }) or die "unknown billpkgnum $billpkgnum";
50 #shouldn't be passed# next if $cust_bill_pkg->pkgnum == 0;
52 if ( $setuprecur eq 'setup' ) {
53 $cust_bill_pkg->setup($amount);
54 $cust_bill_pkg->recur(0);
55 $cust_bill_pkg->unitrecur(0);
56 $cust_bill_pkg->type('');
58 $cust_bill_pkg->recur($amount);
59 $cust_bill_pkg->setup(0);
60 $cust_bill_pkg->unitsetup(0);
63 push @cust_bill_pkg, $cust_bill_pkg;
65 my $part_pkg = $cust_bill_pkg->part_pkg;
66 $cust_main->_handle_taxes( $part_pkg,
69 $cust_bill_pkg->cust_pkg,
70 $cust_bill_pkg->cust_bill->_date,
71 $cust_bill_pkg->cust_pkg->pkgpart,
76 if ( @cust_bill_pkg ) {
78 my $listref_or_error =
79 $cust_main->calculate_taxes( \@cust_bill_pkg, $taxlisthash, $cust_bill_pkg[0]->cust_bill->_date );
81 unless ( ref( $listref_or_error ) ) {
82 $return->{error} = $listref_or_error;
88 $return->{taxlines} = \@taxlines;
89 foreach my $taxline ( @$listref_or_error ) {
90 my $amount = $taxline->setup;
91 my $desc = $taxline->desc;
92 foreach my $location ( @{$taxline->cust_bill_pkg_tax_location}, @{$taxline->cust_bill_pkg_tax_rate_location} ) {
93 my $taxlocnum = $location->locationnum || '';
94 my $taxratelocnum = $location->taxratelocationnum || '';
95 $location->cust_bill_pkg_desc($taxline->desc); #ugh @ that kludge
96 $taxtotal += $location->amount;
98 #[ $location->desc, $taxline->setup, $taxlocnum, $taxratelocnum ];
99 [ $location->desc, $location->amount, $taxlocnum, $taxratelocnum ];
100 $amount -= $location->amount;
103 $taxtotal += $amount;
105 [ $taxline->itemdesc. ' (default)', sprintf('%.2f', $amount), '', '' ];
109 $return->{taxlines} = \@taxlines;
110 $return->{taxtotal} = sprintf('%.2f', $taxtotal);
114 $return->{taxlines} = [];
115 $return->{taxtotal} = '0.00';