| . $locale->text('Vendor') . qq| |
- $vendor |
+ $vendor |
@@ -669,6 +552,7 @@ $jsscript
? $locale->text('Tax Included')
: $locale->text('Tax');
+ $form->{invtotal_unformatted} = $form->{invtotal};
$form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
$APselected =
@@ -738,7 +622,9 @@ $jsscript
";
- my @triggers = ();
+ my @triggers = ();
+ my $totalpaid = 0;
+
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
for $i (1 .. $form->{paidaccounts}) {
print "
@@ -752,6 +638,8 @@ $jsscript
'-labels' => \%AP_paid_labels,
'-default' => $form->{"AP_paid_$i"}));
+ $totalpaid += $form->{"paid_$i"};
+
# format amounts
if ($form->{"paid_$i"}) {
$form->{"paid_$i"} =
@@ -776,12 +664,12 @@ $jsscript
|;
$column_data{"paid_$i"} =
- qq|{"paid_$i"} onBlur=\"check_right_number_format(this)\"> | |;
+ qq| | |;
$column_data{"AP_paid_$i"} =
qq|${selectAP_paid} | |;
$column_data{"exchangerate_$i"} = qq|$exchangerate | |;
$column_data{"datepaid_$i"} =
- qq|{"datepaid_$i"} onBlur=\"check_right_date_format(this)\">
+ qq| |
| |;
$column_data{"source_$i"} =
qq| | |;
@@ -802,7 +690,23 @@ $jsscript
";
push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
}
- print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
+
+ my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
+
+ print qq|
+
+ |
+ |
+ | . $locale->text('Total') . qq| |
+ | . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq| |
+
+
+ |
+ |
+ | . $locale->text('Missing amount') . qq| |
+ | . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq| |
+
+| . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
qq|
{paidaccounts}>
@@ -826,7 +730,6 @@ sub form_footer {
-{path}>
{login}>
{password}>
|
@@ -849,43 +752,30 @@ sub form_footer {
$transdate = $form->datetonum($form->{transdate}, \%myconfig);
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
- print qq||;
+ print qq||;
if ($form->{id}) {
-
- # print qq|
- # |;
if ($form->{radier}) {
- print qq|
-
-
+ print qq|
+
|;
}
- print qq|
-
-
+ # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
+ print qq| |
+ if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap') && !$form->{paid_1});
+
+ print qq|
+
|;
} elsif (($transdate > $closedto) && !$form->{id}) {
print qq|
- | .
- NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
- '-class' => 'submit'));
+ | .
+ NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
}
# button for saving history
if($form->{id} ne "") {
- print qq|
- {id}
- . qq|); name=history id=history value=|
- . $locale->text('history')
- . qq|>|;
+ print qq| |;
}
# /button for saving history
print "
@@ -992,7 +882,7 @@ sub update {
sub post_payment {
$lxdebug->enter_sub();
for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
+ if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
$datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
@@ -1011,7 +901,7 @@ sub post_payment {
($form->{AP}) = split /--/, $form->{AP};
($form->{AP_paid}) = split /--/, $form->{AP_paid};
- $form->redirect($locale->text(' Payment posted!'))
+ $form->redirect($locale->text('Payment posted!'))
if (AP->post_payment(\%myconfig, \%$form));
$form->error($locale->text('Cannot post payment!'));
@@ -1030,9 +920,17 @@ sub post {
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
$transdate = $form->datetonum($form->{transdate}, \%myconfig);
+ $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
- $form->error($locale->text('Cannot post transaction for a closed period!'))
- if ($transdate <= $closedto);
+ my $zero_amount_posting = 1;
+ for $i (1 .. $form->{rowcount}) {
+ if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
+ $zero_amount_posting = 0;
+ last;
+ }
+ }
+
+ $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
if ($form->{currency} ne $form->{defaultcurrency});
@@ -1075,7 +973,7 @@ sub post {
if (AP->post_transaction(\%myconfig, \%$form)) {
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumber} = qq|invnumber_| . $form->{invnumber};
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
$form->{addition} = "POSTED";
$form->save_history($form->dbconnect(\%myconfig));
}
@@ -1094,7 +992,7 @@ sub post_as_new {
$form->{postasnew} = 1;
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumber} = qq|invnumber_| . $form->{invnumber};
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
$form->{addition} = "POSTED AS NEW";
$form->save_history($form->dbconnect(\%myconfig));
}
@@ -1159,7 +1057,7 @@ sub yes {
if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
# saving the history
if(!exists $form->{addition}) {
- $form->{snumber} = qq|invnumber_| . $form->{invnumber};
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
$form->{addition} = "DELETED";
$form->save_history($form->dbconnect(\%myconfig));
}
@@ -1205,7 +1103,7 @@ sub search {
$form->{title} = $locale->text('AP Transactions');
# use JavaScript Calendar or not
- $form->{jsscript} = $jscalendar;
+ $form->{jsscript} = 1;
$jsscript = "";
if ($form->{jsscript}) {
@@ -1366,7 +1264,6 @@ $jsscript
{nextsub}>
-{path}>
{login}>
{password}>
@@ -1390,7 +1287,7 @@ sub ap_transactions {
AP->ap_transactions(\%myconfig, \%$form);
$callback =
- "$form->{script}?action=ap_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+ "$form->{script}?action=ap_transactions&login=$form->{login}&password=$form->{password}";
$href = $callback;
if ($form->{vendor}) {
@@ -1458,9 +1355,11 @@ sub ap_transactions {
}
@columns =
- qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid
+ qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
due duedate notes employee globalprojectnumber);
+ $form->{"l_type"} = "Y";
+
foreach $item (@columns) {
if ($form->{"l_$item"} eq "Y") {
push @column_index, $item;
@@ -1484,6 +1383,8 @@ sub ap_transactions {
qq||
. $locale->text('Date')
. qq| | |;
+ $column_header{type} =
+ "" . $locale->text('Type') . " | ";
$column_header{duedate} =
qq||
. $locale->text('Due Date')
@@ -1598,13 +1499,17 @@ sub ap_transactions {
$subtotaldue += ($ap->{amount} - $ap->{paid});
$column_data{transdate} = " | $ap->{transdate} | ";
+ $column_data{type} = "" .
+ ($ap->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
+ $locale->text("AP Transaction (abbreviation)"))
+ . " | ";
$column_data{duedate} = "$ap->{duedate} | ";
$column_data{datepaid} = "$ap->{datepaid} | ";
$module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
$column_data{invnumber} =
- qq|$ap->{invnumber} | |;
+ qq|$ap->{invnumber} | |;
$column_data{id} = "$ap->{id} | ";
$column_data{ordnumber} = "$ap->{ordnumber} | ";
$column_data{name} = "$ap->{name} | ";
@@ -1673,7 +1578,6 @@ sub ap_transactions {
-{path}>
{login}>
{password}>
@@ -1730,3 +1634,43 @@ sub ap_subtotal {
$lxdebug->leave_sub();
}
+
+sub storno {
+ $lxdebug->enter_sub();
+
+ if (IS->has_storno(\%myconfig, $form, 'ap')) {
+ $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
+ $form->error($locale->text("Transaction has already been cancelled!"));
+ }
+
+ # negate amount/taxes
+ for my $i (1 .. $form->{rowcount}) {
+ $form->{"amount_$i"} *= -1;
+ $form->{"tax_$i"} *= -1;
+ }
+
+ # format things
+ for my $i (1 .. $form->{rowcount}) {
+ for (qw(amount tax)) {
+ $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
+ }
+ }
+
+ $form->{storno} = 1;
+ $form->{storno_id} = $form->{id};
+ $form->{id} = 0;
+
+ $form->{invnumber} = "Storno-" . $form->{invnumber};
+
+ post();
+
+ # saving the history
+ if(!exists $form->{addition} && $form->{id} ne "") {
+ $form->{snumbers} = "ordnumber_$form->{ordnumber}";
+ $form->{addition} = "STORNO";
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+ # /saving the history
+
+ $lxdebug->leave_sub();
+}