Revision 1ae70a98
Von Sven Schöling vor mehr als 17 Jahren hinzugefügt
bin/mozilla/ar.pl | ||
---|---|---|
38 | 38 |
use SL::PE; |
39 | 39 |
use SL::ReportGenerator; |
40 | 40 |
|
41 |
use strict; |
|
42 |
use warnings; |
|
43 |
|
|
44 |
# imports |
|
45 |
our ($cgi, $form, $lxdebug, $locale, %myconfig); |
|
46 |
|
|
41 | 47 |
require "bin/mozilla/arap.pl"; |
42 | 48 |
require "bin/mozilla/common.pl"; |
43 | 49 |
require "bin/mozilla/drafts.pl"; |
... | ... | |
127 | 133 |
sub create_links { |
128 | 134 |
$lxdebug->enter_sub(); |
129 | 135 |
|
136 |
my ($duedate, $taxincluded, @curr); |
|
137 |
|
|
130 | 138 |
$form->create_links("AR", \%myconfig, "customer"); |
131 | 139 |
$duedate = $form->{duedate}; |
132 | 140 |
|
... | ... | |
192 | 200 |
sub form_header { |
193 | 201 |
$lxdebug->enter_sub(); |
194 | 202 |
|
203 |
my ($title, $readonly, $exchangerate, $rows); |
|
204 |
my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project); |
|
205 |
my ($jsscript, $button1, $button2, $onload); |
|
206 |
my ($selectAR_amount, $selectAR_paid, $korrektur_checked, $ARselected, $tax); |
|
207 |
my (@column_index, %column_data); |
|
208 |
|
|
209 |
|
|
195 | 210 |
$title = $form->{title}; |
196 | 211 |
$form->{title} = $locale->text("$title Accounts Receivables Transaction"); |
197 | 212 |
|
... | ... | |
229 | 244 |
$readonly = ($form->{radier}) ? "" : $readonly; |
230 | 245 |
|
231 | 246 |
# set option selected |
232 |
foreach $item (qw(customer currency department employee)) { |
|
247 |
foreach my $item (qw(customer currency department employee)) {
|
|
233 | 248 |
$form->{"select$item"} =~ s/ selected//; |
234 | 249 |
$form->{"select$item"} =~ |
235 | 250 |
s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; |
... | ... | |
295 | 310 |
</tr> |
296 | 311 |
| if $form->{selectdepartment}; |
297 | 312 |
|
298 |
$n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; |
|
313 |
my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
|
|
299 | 314 |
|
300 |
$customer = |
|
301 |
($form->{selectcustomer}) |
|
302 |
? qq|<select name="customer" |
|
303 |
onchange="document.getElementById('update_button').click();">$form->{ |
|
304 |
selectcustomer}</select>| |
|
315 |
$customer = ($form->{selectcustomer}) |
|
316 |
? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>| |
|
305 | 317 |
: qq|<input name=customer value="$form->{customer}" size=35>|; |
306 | 318 |
|
307 | 319 |
$employee = qq| |
... | ... | |
528 | 540 |
$amount = $locale->text('Amount'); |
529 | 541 |
$project = $locale->text('Project'); |
530 | 542 |
|
531 |
for $i (1 .. $form->{rowcount}) { |
|
543 |
for my $i (1 .. $form->{rowcount}) {
|
|
532 | 544 |
|
533 | 545 |
# format amounts |
534 | 546 |
$form->{"amount_$i"} = |
... | ... | |
671 | 683 |
my $totalpaid = 0; |
672 | 684 |
|
673 | 685 |
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); |
674 |
for $i (1 .. $form->{paidaccounts}) { |
|
686 |
for my $i (1 .. $form->{paidaccounts}) {
|
|
675 | 687 |
print " |
676 | 688 |
<tr> |
677 | 689 |
"; |
... | ... | |
775 | 787 |
sub form_footer { |
776 | 788 |
$lxdebug->enter_sub(); |
777 | 789 |
|
790 |
my ($transdate, $closedto); |
|
791 |
|
|
778 | 792 |
print qq| |
779 | 793 |
|
780 | 794 |
<input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|"> |
... | ... | |
866 | 880 |
|
867 | 881 |
my $display = shift; |
868 | 882 |
|
883 |
my ($totaltax, $exchangerate, $totalpaid); |
|
884 |
|
|
869 | 885 |
$form->{invtotal} = 0; |
870 | 886 |
|
871 | 887 |
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } |
872 | 888 |
qw(exchangerate creditlimit creditremaining); |
873 | 889 |
|
874 |
@flds = qw(amount AR_amount projectnumber oldprojectnumber project_id); |
|
875 |
$count = 0; |
|
876 |
@a = (); |
|
890 |
my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
|
|
891 |
my $count = 0;
|
|
892 |
my @a = ();
|
|
877 | 893 |
|
878 |
for $i (1 .. $form->{rowcount}) { |
|
879 |
$form->{"amount_$i"} = |
|
880 |
$form->parse_amount(\%myconfig, $form->{"amount_$i"}); |
|
894 |
for my $i (1 .. $form->{rowcount}) { |
|
895 |
$form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); |
|
881 | 896 |
$form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"}); |
882 | 897 |
if ($form->{"amount_$i"}) { |
883 | 898 |
push @a, {}; |
884 |
$j = $#a; |
|
899 |
my $j = $#a;
|
|
885 | 900 |
if (!$form->{"korrektur_$i"}) { |
886 |
($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); |
|
901 |
my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
|
|
887 | 902 |
if ($taxkey > 1) { |
888 | 903 |
if ($form->{taxincluded}) { |
889 | 904 |
$form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate; |
... | ... | |
915 | 930 |
))); |
916 | 931 |
|
917 | 932 |
$form->{invdate} = $form->{transdate}; |
918 |
$save_AR = $form->{AR}; |
|
919 |
&check_name(customer);
|
|
933 |
my $save_AR = $form->{AR};
|
|
934 |
check_name("customer");
|
|
920 | 935 |
$form->{AR} = $save_AR; |
921 | 936 |
|
922 | 937 |
$form->{invtotal} = |
923 | 938 |
($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; |
924 | 939 |
|
925 |
for $i (1 .. $form->{paidaccounts}) { |
|
940 |
for my $i (1 .. $form->{paidaccounts}) {
|
|
926 | 941 |
if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { |
927 | 942 |
map { |
928 | 943 |
$form->{"${_}_$i"} = |
... | ... | |
952 | 967 |
$lxdebug->leave_sub(); |
953 | 968 |
} |
954 | 969 |
|
970 |
# |
|
971 |
# ToDO: fix $closedto and $invdate |
|
972 |
# |
|
955 | 973 |
sub post_payment { |
956 | 974 |
$lxdebug->enter_sub(); |
957 | 975 |
|
958 | 976 |
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig); |
959 | 977 |
|
960 |
for $i (1 .. $form->{paidaccounts}) { |
|
978 |
for my $i (1 .. $form->{paidaccounts}) { |
|
979 |
|
|
961 | 980 |
if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { |
962 |
$datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); |
|
981 |
my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
|
963 | 982 |
|
964 | 983 |
$form->isblank("datepaid_$i", $locale->text('Payment date missing!')); |
965 | 984 |
|
966 |
$form->error($locale->text('Cannot post payment for a closed period!')) |
|
967 |
if ($datepaid <= $closedto); |
|
985 |
# $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto); |
|
968 | 986 |
|
969 | 987 |
if ($form->{currency} ne $form->{defaultcurrency}) { |
970 |
$form->{"exchangerate_$i"} = $form->{exchangerate} |
|
971 |
if ($invdate == $datepaid); |
|
972 |
$form->isblank("exchangerate_$i", |
|
973 |
$locale->text('Exchangerate for payment missing!')); |
|
988 |
# $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); |
|
989 |
$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); |
|
974 | 990 |
} |
975 | 991 |
} |
976 | 992 |
} |
977 | 993 |
|
978 | 994 |
($form->{AR}) = split /--/, $form->{AR}; |
979 | 995 |
($form->{AR_paid}) = split /--/, $form->{AR_paid}; |
980 |
$form->redirect($locale->text('Payment posted!')) |
|
981 |
if (AR->post_payment(\%myconfig, \%$form)); |
|
982 |
$form->error($locale->text('Cannot post payment!')); |
|
983 |
|
|
996 |
$form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form)); |
|
997 |
$form->error($locale->text('Cannot post payment!')); |
|
984 | 998 |
|
985 | 999 |
$lxdebug->leave_sub(); |
986 | 1000 |
} |
987 | 1001 |
|
1002 |
sub _post { |
|
1003 |
# inline post |
|
1004 |
post(1); |
|
1005 |
} |
|
1006 |
|
|
988 | 1007 |
sub post { |
989 | 1008 |
$lxdebug->enter_sub(); |
990 | 1009 |
|
1010 |
my ($inline) = @_; |
|
1011 |
|
|
1012 |
my ($datepaid); |
|
1013 |
|
|
991 | 1014 |
# check if there is an invoice number, invoice and due date |
992 | 1015 |
$form->isblank("transdate", $locale->text('Invoice Date missing!')); |
993 | 1016 |
$form->isblank("duedate", $locale->text('Due Date missing!')); |
994 | 1017 |
$form->isblank("customer", $locale->text('Customer missing!')); |
995 | 1018 |
|
996 |
$closedto = $form->datetonum($form->{closedto}, \%myconfig); |
|
997 |
$transdate = $form->datetonum($form->{transdate}, \%myconfig); |
|
1019 |
my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
|
|
1020 |
my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
|
|
998 | 1021 |
$form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto); |
999 | 1022 |
|
1000 | 1023 |
$form->error($locale->text('Zero amount posting!')) |
... | ... | |
1005 | 1028 |
|
1006 | 1029 |
delete($form->{AR}); |
1007 | 1030 |
|
1008 |
for $i (1 .. $form->{paidaccounts}) { |
|
1031 |
for my $i (1 .. $form->{paidaccounts}) {
|
|
1009 | 1032 |
if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { |
1010 | 1033 |
$datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); |
1011 | 1034 |
|
... | ... | |
1022 | 1045 |
} |
1023 | 1046 |
|
1024 | 1047 |
# if oldcustomer ne customer redo form |
1025 |
($customer) = split /--/, $form->{customer}; |
|
1048 |
my ($customer) = split /--/, $form->{customer};
|
|
1026 | 1049 |
if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") { |
1027 |
&update;
|
|
1050 |
update();
|
|
1028 | 1051 |
exit; |
1029 | 1052 |
} |
1030 | 1053 |
|
1031 | 1054 |
$form->{AR}{receivables} = $form->{ARselected}; |
1032 | 1055 |
$form->{storno} = 0; |
1033 | 1056 |
|
1057 |
$lxdebug->message(0, $form->{amount}); |
|
1034 | 1058 |
$form->{id} = 0 if $form->{postasnew}; |
1059 |
$form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form); |
|
1035 | 1060 |
|
1036 |
|
|
1037 |
if (AR->post_transaction(\%myconfig, \%$form)) { |
|
1038 |
# saving the history |
|
1039 |
if(!exists $form->{addition} && $form->{id} ne "") { |
|
1040 |
$form->{snumbers} = "invnumber_$form->{invnumber}"; |
|
1041 |
$form->{addition} = "POSTED"; |
|
1042 |
$form->save_history($form->dbconnect(\%myconfig)); |
|
1043 |
} |
|
1044 |
# /saving the history |
|
1045 |
remove_draft() if $form->{remove_draft}; |
|
1046 |
$form->redirect($locale->text('Transaction posted!')); |
|
1061 |
# saving the history |
|
1062 |
if(!exists $form->{addition} && $form->{id} ne "") { |
|
1063 |
$form->{snumbers} = "invnumber_$form->{invnumber}"; |
|
1064 |
$form->{addition} = "POSTED"; |
|
1065 |
$form->save_history($form->dbconnect(\%myconfig)); |
|
1047 | 1066 |
} |
1048 |
$form->error($locale->text('Cannot post transaction!')); |
|
1067 |
# /saving the history |
|
1068 |
remove_draft() if $form->{remove_draft}; |
|
1069 |
|
|
1070 |
$form->redirect($locale->text('Transaction posted!')) unless $inline; |
|
1049 | 1071 |
|
1050 | 1072 |
$lxdebug->leave_sub(); |
1051 | 1073 |
} |
... | ... | |
1093 | 1115 |
<form method=post action=$form->{script}> |
1094 | 1116 |
|; |
1095 | 1117 |
|
1096 |
foreach $key (keys %$form) { |
|
1118 |
foreach my $key (keys %$form) {
|
|
1097 | 1119 |
$form->{$key} =~ s/\"/"/g; |
1098 | 1120 |
print qq|<input type=hidden name=$key value="$form->{$key}">\n|; |
1099 | 1121 |
} |
... | ... | |
1118 | 1140 |
|
1119 | 1141 |
sub yes { |
1120 | 1142 |
$lxdebug->enter_sub(); |
1121 |
if (AR->delete_transaction(\%myconfig, \%$form, $spool)) {
|
|
1143 |
if (AR->delete_transaction(\%myconfig, \%$form)) { |
|
1122 | 1144 |
# saving the history |
1123 | 1145 |
if(!exists $form->{addition}) { |
1124 | 1146 |
$form->{snumbers} = qq|invnumber_| . $form->{invnumber}; |
... | ... | |
1136 | 1158 |
sub search { |
1137 | 1159 |
$lxdebug->enter_sub(); |
1138 | 1160 |
|
1161 |
my ($customer, $department); |
|
1162 |
my ($jsscript, $button1, $button2, $onload); |
|
1163 |
|
|
1139 | 1164 |
# setup customer selection |
1140 | 1165 |
$form->all_vc(\%myconfig, "customer", "AR"); |
1141 | 1166 |
|
... | ... | |
1376 | 1401 |
sub ar_transactions { |
1377 | 1402 |
$lxdebug->enter_sub(); |
1378 | 1403 |
|
1404 |
my ($callback, $href, @columns); |
|
1405 |
|
|
1406 |
$form->{customer} = $form->unescape($form->{customer}); |
|
1379 | 1407 |
($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer}); |
1380 | 1408 |
|
1381 | 1409 |
$form->{sort} ||= 'transdate'; |
... | ... | |
1386 | 1414 |
|
1387 | 1415 |
my $report = SL::ReportGenerator->new(\%myconfig, $form); |
1388 | 1416 |
|
1389 |
my @columns =
|
|
1417 |
@columns = |
|
1390 | 1418 |
qw(transdate id type invnumber ordnumber name netamount tax amount paid |
1391 | 1419 |
datepaid due duedate transaction_description notes employee shippingpoint shipvia |
1392 | 1420 |
globalprojectnumber); |
... | ... | |
1394 | 1422 |
my @hidden_variables = map { "l_${_}" } @columns; |
1395 | 1423 |
push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto); |
1396 | 1424 |
|
1397 |
my $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
|
|
1425 |
$href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables); |
|
1398 | 1426 |
|
1399 | 1427 |
my %column_defs = ( |
1400 | 1428 |
'transdate' => { 'text' => $locale->text('Date'), }, |
... | ... | |
1440 | 1468 |
push @options, $locale->text('Customer') . " : $form->{customer}"; |
1441 | 1469 |
} |
1442 | 1470 |
if ($form->{department}) { |
1443 |
($department) = split /--/, $form->{department}; |
|
1471 |
my ($department) = split /--/, $form->{department};
|
|
1444 | 1472 |
push @options, $locale->text('Department') . " : $department"; |
1445 | 1473 |
} |
1446 | 1474 |
if ($form->{invnumber}) { |
... | ... | |
1489 | 1517 |
|
1490 | 1518 |
my $idx = 0; |
1491 | 1519 |
|
1492 |
foreach $ar (@{ $form->{AR} }) { |
|
1520 |
foreach my $ar (@{ $form->{AR} }) {
|
|
1493 | 1521 |
$ar->{tax} = $ar->{amount} - $ar->{netamount}; |
1494 | 1522 |
$ar->{due} = $ar->{amount} - $ar->{paid}; |
1495 | 1523 |
|
... | ... | |
1544 | 1572 |
sub storno { |
1545 | 1573 |
$lxdebug->enter_sub(); |
1546 | 1574 |
|
1575 |
# don't cancel cancelled transactions |
|
1547 | 1576 |
if (IS->has_storno(\%myconfig, $form, 'ar')) { |
1548 | 1577 |
$form->{title} = $locale->text("Cancel Accounts Receivables Transaction"); |
1549 | 1578 |
$form->error($locale->text("Transaction has already been cancelled!")); |
1550 | 1579 |
} |
1551 | 1580 |
|
1552 |
# negate amount/taxes |
|
1553 |
for my $i (1 .. $form->{rowcount}) { |
|
1554 |
$form->{"amount_$i"} *= -1; |
|
1555 |
$form->{"tax_$i"} *= -1; |
|
1556 |
} |
|
1557 |
|
|
1558 |
# format things |
|
1559 |
for my $i (1 .. $form->{rowcount}) { |
|
1560 |
for (qw(amount tax)) { |
|
1561 |
$form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"}; |
|
1562 |
} |
|
1563 |
} |
|
1564 |
|
|
1565 |
$form->{storno} = 1; |
|
1566 |
$form->{storno_id} = $form->{id}; |
|
1567 |
$form->{id} = 0; |
|
1568 |
|
|
1569 |
$form->{invnumber} = "Storno-" . $form->{invnumber}; |
|
1570 |
|
|
1571 |
post(); |
|
1581 |
AR->storno($form, \%myconfig, $form->{id}); |
|
1572 | 1582 |
|
1573 | 1583 |
# saving the history |
1574 | 1584 |
if(!exists $form->{addition} && $form->{id} ne "") { |
... | ... | |
1578 | 1588 |
} |
1579 | 1589 |
# /saving the history |
1580 | 1590 |
|
1591 |
$form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); |
|
1592 |
|
|
1581 | 1593 |
$lxdebug->leave_sub(); |
1582 | 1594 |
} |
Auch abrufbar als: Unified diff
bin/mozilla/ar.pl auf use strict standard gebracht.
Debitoren storno umgeschrieben und Bug gefixt.