Revision 886784c7
Von Sven Schöling vor fast 13 Jahren hinzugefügt
bin/mozilla/rp.pl | ||
---|---|---|
1349 | 1349 |
} |
1350 | 1350 |
|
1351 | 1351 |
sub generate_tax_report { |
1352 |
$main::lxdebug->enter_sub(); |
|
1353 |
|
|
1354 |
$main::auth->assert('report'); |
|
1355 |
|
|
1356 |
my $form = $main::form; |
|
1357 |
my %myconfig = %main::myconfig; |
|
1358 |
my $locale = $main::locale; |
|
1352 |
$::lxdebug->enter_sub; |
|
1353 |
$::auth->assert('report'); |
|
1359 | 1354 |
|
1360 |
RP->tax_report(\%myconfig, \%$form);
|
|
1355 |
RP->tax_report(\%::myconfig, $::form);
|
|
1361 | 1356 |
|
1362 |
my $descvar = "$form->{accno}_description"; |
|
1363 |
my $description = $form->escape($form->{$descvar}); |
|
1364 |
my $ratevar = "$form->{accno}_rate"; |
|
1357 |
my $descvar = "$::form->{accno}_description"; |
|
1365 | 1358 |
my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0); |
1366 | 1359 |
|
1367 |
my $department = $form->escape($form->{department}); |
|
1368 |
|
|
1369 | 1360 |
# construct href |
1370 |
my $href = |
|
1371 |
"$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&report=$form->{report}"; |
|
1372 |
|
|
1373 |
# construct callback |
|
1374 |
$description = $form->escape($form->{$descvar}, 1); |
|
1375 |
$department = $form->escape($form->{department}, 1); |
|
1376 |
my $callback = |
|
1377 |
"$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&report=$form->{report}"; |
|
1378 |
|
|
1379 |
my $title = $form->escape($form->{title}); |
|
1380 |
$href .= "&title=$title"; |
|
1381 |
$title = $form->escape($form->{title}, 1); |
|
1382 |
$callback .= "&title=$title"; |
|
1361 |
my $href = |
|
1362 |
my $callback = build_std_url('action=generate_tax_report', $descvar, |
|
1363 |
qw(fromdate todate db method accno department report title)); |
|
1383 | 1364 |
|
1384 |
$form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |; |
|
1385 |
|
|
1386 |
my @columns = |
|
1387 |
$form->sort_columns(qw(id transdate invnumber name netamount tax amount)); |
|
1365 |
my @columns = $::form->sort_columns(qw(id transdate invnumber name netamount tax amount)); |
|
1388 | 1366 |
my @column_index; |
1389 | 1367 |
|
1390 |
foreach my $item (@columns) { |
|
1391 |
if ($form->{"l_$item"} eq "Y") { |
|
1392 |
push @column_index, $item; |
|
1393 |
|
|
1394 |
# add column to href and callback |
|
1368 |
for my $item (@columns, 'subtotal') { |
|
1369 |
if ($::form->{"l_$item"} eq "Y") { |
|
1395 | 1370 |
$callback .= "&l_$item=Y"; |
1396 | 1371 |
$href .= "&l_$item=Y"; |
1397 | 1372 |
} |
1398 | 1373 |
} |
1399 | 1374 |
|
1400 |
if ($form->{l_subtotal} eq 'Y') { |
|
1401 |
$callback .= "&l_subtotal=Y"; |
|
1402 |
$href .= "&l_subtotal=Y"; |
|
1375 |
for my $item (@columns) { |
|
1376 |
if ($::form->{"l_$item"} eq "Y") { |
|
1377 |
push @column_index, $item; |
|
1378 |
} |
|
1403 | 1379 |
} |
1404 | 1380 |
|
1405 |
my $option;
|
|
1406 |
if ($form->{department}) { |
|
1407 |
($department) = split /--/, $form->{department};
|
|
1408 |
$option = $locale->text('Department') . " : $department";
|
|
1381 |
my @options;
|
|
1382 |
if ($::form->{department}) {
|
|
1383 |
my ($department) = split /--/, $::form->{department};
|
|
1384 |
push @options, $::locale->text('Department') . " : $department";
|
|
1409 | 1385 |
} |
1410 | 1386 |
|
1411 |
my ($fromdate, $todate); |
|
1412 | 1387 |
# if there are any dates |
1413 |
if ($form->{fromdate} || $form->{todate}) { |
|
1414 |
if ($form->{fromdate}) { |
|
1415 |
$fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1); |
|
1416 |
} |
|
1417 |
if ($form->{todate}) { |
|
1418 |
$todate = $locale->date(\%myconfig, $form->{todate}, 1); |
|
1419 |
} |
|
1420 |
|
|
1421 |
$form->{period} = "$fromdate - $todate"; |
|
1388 |
if ($::form->{fromdate} || $::form->{todate}) { |
|
1389 |
my $fromdate = $::locale->date(\%::myconfig, $::form->{fromdate}, 1) if $::form->{fromdate}; |
|
1390 |
my $todate = $::locale->date(\%::myconfig, $::form->{todate}, 1) if $::form->{todate}; |
|
1391 |
push @options, "$fromdate - $todate"; |
|
1422 | 1392 |
} else { |
1423 |
$form->{period} = |
|
1424 |
$locale->date(\%myconfig, $form->current_date(\%myconfig), 1); |
|
1393 |
push @options, $::locale->date(\%::myconfig, $::form->current_date, 1); |
|
1425 | 1394 |
} |
1426 | 1395 |
|
1427 | 1396 |
my ($name, $invoice, $arap); |
1428 |
if ($form->{db} eq 'ar') { |
|
1429 |
$name = $locale->text('Customer'); |
|
1397 |
if ($::form->{db} eq 'ar') {
|
|
1398 |
$name = $::locale->text('Customer');
|
|
1430 | 1399 |
$invoice = 'is.pl'; |
1431 | 1400 |
$arap = 'ar.pl'; |
1432 | 1401 |
} |
1433 |
if ($form->{db} eq 'ap') { |
|
1434 |
$name = $locale->text('Vendor'); |
|
1402 |
if ($::form->{db} eq 'ap') {
|
|
1403 |
$name = $::locale->text('Vendor');
|
|
1435 | 1404 |
$invoice = 'ir.pl'; |
1436 | 1405 |
$arap = 'ap.pl'; |
1437 | 1406 |
} |
1438 | 1407 |
|
1439 |
$option .= "<br>" if $option; |
|
1440 |
$option .= "$form->{period}"; |
|
1441 |
|
|
1442 |
my %column_header; |
|
1443 |
$column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|; |
|
1444 |
$column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|; |
|
1445 |
$column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|; |
|
1446 |
$column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|; |
|
1447 |
$column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|; |
|
1448 |
$column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|; |
|
1449 |
|
|
1450 |
$column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|; |
|
1451 |
|
|
1452 |
$form->header; |
|
1453 |
|
|
1454 |
print qq| |
|
1455 |
<body> |
|
1456 |
|
|
1457 |
<table width=100%> |
|
1458 |
<tr> |
|
1459 |
<th class=listtop>$form->{title}</th> |
|
1460 |
</tr> |
|
1461 |
<tr height="5"></tr> |
|
1462 |
<tr> |
|
1463 |
<td>$option</td> |
|
1464 |
</tr> |
|
1465 |
<tr> |
|
1466 |
<td> |
|
1467 |
<table width=100%> |
|
1468 |
<tr class=listheading> |
|
1469 |
|; |
|
1470 |
|
|
1471 |
map { print "$column_header{$_}\n" } @column_index; |
|
1408 |
my %column_header = ( |
|
1409 |
id => $::locale->text('ID'), |
|
1410 |
invnumber => $::locale->text('Invoice'), |
|
1411 |
transdate => $::locale->text('Date'), |
|
1412 |
netamount => $::locale->text('Amount'), |
|
1413 |
tax => $::locale->text('Tax'), |
|
1414 |
amount => $::locale->text('Total'), |
|
1415 |
name => $name, |
|
1416 |
); |
|
1472 | 1417 |
|
1473 |
print qq| |
|
1474 |
</tr> |
|
1475 |
|; |
|
1418 |
my %column_sorted = map { $_ => 1 } qw(id invnumber transdate); |
|
1476 | 1419 |
|
1477 |
# add sort and escape callback |
|
1478 |
$callback = $form->escape($callback . "&sort=$form->{sort}"); |
|
1420 |
$callback .= "&sort=$::form->{sort}"; |
|
1479 | 1421 |
|
1480 | 1422 |
my $sameitem; |
1481 |
if (@{ $form->{TR} }) { |
|
1482 |
$sameitem = $form->{TR}->[0]->{ $form->{sort} };
|
|
1423 |
if (@{ $::form->{TR} }) {
|
|
1424 |
$sameitem = $::form->{TR}->[0]->{ $::form->{sort} };
|
|
1483 | 1425 |
} |
1484 | 1426 |
|
1485 |
my ($totalnetamount, $totaltax); |
|
1486 |
my ($i); |
|
1487 |
foreach my $ref (@{ $form->{TR} }) { |
|
1427 |
my ($totalnetamount, $totaltax, @data); |
|
1428 |
for my $ref (@{ $::form->{TR} }) { |
|
1488 | 1429 |
|
1489 | 1430 |
my $module = ($ref->{invoice}) ? $invoice : $arap; |
1490 | 1431 |
|
1491 |
if ($form->{l_subtotal} eq 'Y') { |
|
1492 |
if ($sameitem ne $ref->{ $form->{sort} }) { |
|
1493 |
tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal); |
|
1494 |
$sameitem = $ref->{ $form->{sort} }; |
|
1432 |
if ($::form->{l_subtotal} eq 'Y') { |
|
1433 |
if ($sameitem ne $ref->{ $::form->{sort} }) { |
|
1434 |
push @data, { |
|
1435 |
subtotal => 1, |
|
1436 |
netamount => $subtotalnetamount, |
|
1437 |
tax => $subtotaltax, |
|
1438 |
amount => $subtotal, |
|
1439 |
}; |
|
1440 |
$subtotalnetamount = 0; |
|
1441 |
$subtotaltax = 0; |
|
1442 |
$sameitem = $ref->{ $::form->{sort} }; |
|
1495 | 1443 |
} |
1496 | 1444 |
} |
1497 | 1445 |
|
1498 |
$totalnetamount += $ref->{netamount}; |
|
1499 |
$totaltax += $ref->{tax}; |
|
1500 |
$ref->{amount} = $ref->{netamount} + $ref->{tax}; |
|
1501 |
|
|
1502 | 1446 |
$subtotalnetamount += $ref->{netamount}; |
1503 | 1447 |
$subtotaltax += $ref->{tax}; |
1448 |
$totalnetamount += $ref->{netamount}; |
|
1449 |
$totaltax += $ref->{tax}; |
|
1450 |
$ref->{amount} = $ref->{netamount} + $ref->{tax}; |
|
1504 | 1451 |
|
1505 |
map { |
|
1506 |
$ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " "); |
|
1507 |
} qw(netamount tax amount); |
|
1508 |
|
|
1509 |
my %column_data; |
|
1510 |
$column_data{id} = qq|<td>$ref->{id}</td>|; |
|
1511 |
$column_data{invnumber} = |
|
1512 |
qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|; |
|
1513 |
$column_data{transdate} = qq|<td>$ref->{transdate}</td>|; |
|
1514 |
$column_data{name} = qq|<td>$ref->{name} </td>|; |
|
1515 |
|
|
1516 |
map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } |
|
1517 |
qw(netamount tax amount); |
|
1518 |
|
|
1519 |
$i++; |
|
1520 |
$i %= 2; |
|
1521 |
print qq| |
|
1522 |
<tr class=listrow$i> |
|
1523 |
|; |
|
1524 |
|
|
1525 |
map { print "$column_data{$_}\n" } @column_index; |
|
1526 |
|
|
1527 |
print qq| |
|
1528 |
</tr> |
|
1529 |
|; |
|
1530 |
|
|
1452 |
push @data, { map { $_ => { data => $ref->{$_} } } keys %$ref }; |
|
1453 |
$data[-1]{invnumber}{link} = "$module?action=edit&id=$ref->{id}&callback=$callback"; |
|
1454 |
$data[-1]{$_}{numeric} = 1 for qw(netamount tax amount); |
|
1531 | 1455 |
} |
1532 | 1456 |
|
1533 |
if ($form->{l_subtotal} eq 'Y') { |
|
1534 |
tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal); |
|
1457 |
if ($::form->{l_subtotal} eq 'Y') { |
|
1458 |
push @data, { |
|
1459 |
subtotal => 1, |
|
1460 |
netamount => $subtotalnetamount, |
|
1461 |
tax => $subtotaltax, |
|
1462 |
amount => $subtotal, |
|
1463 |
}; |
|
1535 | 1464 |
} |
1536 | 1465 |
|
1537 |
my %column_data; |
|
1538 |
map { $column_data{$_} = qq|<th> </th>| } @column_index; |
|
1539 |
|
|
1540 |
print qq| |
|
1541 |
</tr> |
|
1542 |
<tr class=listtotal> |
|
1543 |
|; |
|
1544 |
|
|
1545 |
my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " "); |
|
1546 |
$totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " "); |
|
1547 |
$totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " "); |
|
1548 |
|
|
1549 |
$column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|; |
|
1550 |
$column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|; |
|
1551 |
$column_data{amount} = qq|<th class=listtotal align=right>$total</th>|; |
|
1552 |
|
|
1553 |
map { print "$column_data{$_}\n" } @column_index; |
|
1554 |
|
|
1555 |
print qq| |
|
1556 |
</tr> |
|
1557 |
</table> |
|
1558 |
</td> |
|
1559 |
</tr> |
|
1560 |
<tr> |
|
1561 |
<td><hr size=3 noshade></td> |
|
1562 |
</tr> |
|
1563 |
</table> |
|
1564 |
|
|
1565 |
</body> |
|
1566 |
</html> |
|
1567 |
|; |
|
1568 |
|
|
1569 |
$main::lxdebug->leave_sub(); |
|
1570 |
} |
|
1571 |
|
|
1572 |
sub tax_subtotal { |
|
1573 |
$main::lxdebug->enter_sub(); |
|
1574 |
|
|
1575 |
my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_; |
|
1576 |
|
|
1577 |
my $form = $main::form; |
|
1578 |
my %myconfig = %main::myconfig; |
|
1579 |
my $locale = $main::locale; |
|
1580 |
|
|
1581 |
my %column_data; |
|
1582 |
map { $column_data{$_} = "<td> </td>" } @{ $column_index }; |
|
1583 |
|
|
1584 |
$$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, " "); |
|
1585 |
$$subtotaltax = $form->format_amount(\%myconfig, $$subtotaltax, 2, " "); |
|
1586 |
$$subtotal = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, " "); |
|
1587 |
|
|
1588 |
$column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>"; |
|
1589 |
$column_data{tax} = "<th class=listsubtotal align=right>$$subtotaltax</th>"; |
|
1590 |
$column_data{amount} = "<th class=listsubtotal align=right>$$subtotal</th>"; |
|
1591 |
|
|
1592 |
$$subtotalnetamount = 0; |
|
1593 |
$$subtotaltax = 0; |
|
1594 |
|
|
1595 |
print qq| |
|
1596 |
<tr class=listsubtotal> |
|
1597 |
|; |
|
1598 |
map { print "\n$column_data{$_}" } @{ $column_index }; |
|
1466 |
push @data, { |
|
1467 |
total => 1, |
|
1468 |
netamount => $totalnetamount, |
|
1469 |
tax => $totaltax, |
|
1470 |
amount => $totalnetamount + $totaltax, |
|
1471 |
}; |
|
1599 | 1472 |
|
1600 |
print qq| |
|
1601 |
</tr> |
|
1602 |
|; |
|
1473 |
$::form->header; |
|
1474 |
print $::form->parse_html_template('rp/tax_report', { |
|
1475 |
column_index => \@column_index, |
|
1476 |
column_header => \%column_header, |
|
1477 |
column_sorted => \%column_sorted, |
|
1478 |
sort_base => $href, |
|
1479 |
DATA => \@data, |
|
1480 |
options => \@options, |
|
1481 |
}); |
|
1603 | 1482 |
|
1604 |
$main::lxdebug->leave_sub();
|
|
1483 |
$::lxdebug->leave_sub;
|
|
1605 | 1484 |
} |
1606 | 1485 |
|
1607 | 1486 |
sub list_payments { |
Auch abrufbar als: Unified diff
rp.pl::tax_report nach template ausgelagert.