X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=667c7b3b7a56efc28b54d8955bb8c0f39689c91d;hb=2efc8cbcc63c56094e0692067b7cb678c1583987;hp=da33886a12e23d10b012e8775b6ddd919c30b36d;hpb=3c5e4df9e938a8f2c9b045774bda00095b976e49;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index da33886a1..667c7b3b7 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -177,112 +177,7 @@ sub create_links { # build the popup menus $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked"; - # forex - $form->{forex} = $form->{exchangerate}; - $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; - foreach $key (keys %{ $form->{AR_links} }) { - # if there is a value we have an old entry - my $j = 0; - my $k = 0; - - for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { - if ($key eq "AR_paid") { - $j++; - $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno}; - - # reverse paid - $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; - $form->{"datepaid_$j"} = - $form->{acc_trans}{$key}->[$i - 1]->{transdate}; - $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source}; - $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo}; - - $form->{"forex_$j"} = $form->{"exchangerate_$i"} = - $form->{acc_trans}{$key}->[$i - 1]->{exchangerate}; - $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id}; - $form->{paidaccounts}++; - - } else { - - $akey = $key; - $akey =~ s/AR_//; - - if ($key eq "AR_tax" || $key eq "AP_tax") { - $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = - "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = - $form->round_amount( - $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate, - 2); - - if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) { - $totaltax += - $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; - $taxrate += - $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; - } else { - $totalwithholding += - $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; - $withholdingrate += - $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; - } - $index = $form->{acc_trans}{$key}->[$i - 1]->{index}; - $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount}; - $totaltax += $form->{"tax_$index"}; - - } else { - $k++; - $form->{"${akey}_$k"} = - $form->round_amount( - $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate, - 2); - if ($akey eq 'amount') { - $form->{rowcount}++; - $totalamount += $form->{"${akey}_$i"}; - - $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} = - "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}"; - $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate}; - $form->{"project_id_$k"} = - "$form->{acc_trans}{$key}->[$i-1]->{project_id}"; - } - $form->{"${key}_$i"} = - "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - - if ($akey eq "AR") { - $form->{ARselected} = $form->{acc_trans}{$key}->[$i-1]->{accno}; - - } elsif ($akey eq "amount") { - $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} . - "--" . $form->{acc_trans}{$key}->[$i-1]->{id}; - $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} . - "--" . $form->{acc_trans}{$key}->[$i-1]->{rate}; - } - } - } - } - } - - $form->{taxincluded} = $taxincluded if ($form->{id}); - $form->{paidaccounts} = 1 if not defined $form->{paidaccounts}; - - if ($form->{taxincluded} && $form->{taxrate} && $totalamount) { - - # add tax to amounts and invtotal - for $i (1 .. $form->{rowcount}) { - $taxamount = - ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount; - $tax = $form->round_amount($taxamount, 2); - $diff += ($taxamount - $tax); - $form->{"amount_$i"} += $form->{"tax_$i"}; - } - $form->{amount_1} += $form->round_amount($diff, 2); - } - - $taxamount = $form->round_amount($taxamount, 2); - $form->{tax} = $taxamount; - - $form->{invtotal} = $totalamount + $totaltax; + AR->setup_form($form); $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= @@ -471,7 +366,7 @@ selectcustomer}| $form->{fokus} = "arledger.customer"; # use JavaScript Calendar or not - $form->{jsscript} = $jscalendar; + $form->{jsscript} = 1; $jsscript = ""; if ($form->{jsscript}) { @@ -500,6 +395,10 @@ selectcustomer}| qq||; } + $form->{javascript} .= + qq|| . + qq||; + $form->header; $onload = qq|focus()|; $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|; @@ -530,7 +429,7 @@ selectcustomer}| - + @@ -681,6 +580,7 @@ $jsscript $project = ""; } + $form->{invtotal_unformatted} = $form->{invtotal}; $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); $ARselected = @@ -752,7 +652,9 @@ $jsscript "; - my @triggers = (); + my @triggers = (); + my $totalpaid = 0; + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for $i (1 .. $form->{paidaccounts}) { print " @@ -766,6 +668,8 @@ $jsscript '-labels' => \%AR_paid_labels, '-default' => $form->{"AR_paid_$i"})); + $totalpaid += $form->{"paid_$i"}; + # format amounts if ($form->{"paid_$i"}) { $form->{"paid_$i"} = @@ -818,7 +722,22 @@ $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| + + + + + + + + + + + + +| . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . qq| {paidaccounts}> @@ -865,35 +784,28 @@ sub form_footer { $transdate = $form->datetonum($form->{transdate}, \%myconfig); $closedto = $form->datetonum($form->{closedto}, \%myconfig); - 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, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && !$form->{paid_1}); + + print qq|\n|; if ($form->{id}) { if ($form->{radier}) { print qq| - - - |; + + |; } if ($transdate > $closedto) { print qq| - - |; + |; } print qq| - - |; + |; } else { if ($transdate > $closedto) { - print qq| | . - NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), - '-class' => 'submit')); + print qq| | . + NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit')); } } @@ -903,12 +815,7 @@ sub form_footer { } # button for saving history if($form->{id} ne "") { - print qq| - {id} - . qq|); name=history id=history value=| - . $locale->text('history') - . qq|>|; + print qq|{id}); name=history id=history value=| . $locale->text('history') . qq|>|; } # /button for saving history print " @@ -1015,7 +922,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!')); @@ -1034,7 +941,7 @@ sub post_payment { ($form->{AR}) = split /--/, $form->{AR}; ($form->{AR_paid}) = split /--/, $form->{AR_paid}; - $form->redirect($locale->text(' Payment posted!')) + $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form)); $form->error($locale->text('Cannot post payment!')); @@ -1052,9 +959,10 @@ 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); + $form->error($locale->text('Zero amount posting!')) + unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount}; $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); @@ -1071,10 +979,8 @@ sub post { if ($datepaid <= $closedto); if ($form->{currency} ne $form->{defaultcurrency}) { - $form->{"exchangerate_$i"} = $form->{exchangerate} - if ($transdate == $datepaid); - $form->isblank("exchangerate_$i", - $locale->text('Exchangerate for payment missing!')); + $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid); + $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); } } } @@ -1092,9 +998,9 @@ sub post { if (AR->post_transaction(\%myconfig, \%$form)) { # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "POSTED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{snumbers} = "invnumber_$form->{invnumber}"; + $form->{addition} = "POSTED"; + $form->save_history($form->dbconnect(\%myconfig)); } # /saving the history remove_draft() if $form->{remove_draft}; @@ -1224,7 +1130,7 @@ sub search { $form->{javascript} .= qq||; # use JavaScript Calendar or not - $form->{jsscript} = $jscalendar; + $form->{jsscript} = 1; $jsscript = ""; if ($form->{jsscript}) { @@ -1295,6 +1201,10 @@ sub search { + + + + @@ -1371,6 +1281,8 @@ sub search { + +
| . $locale->text('Customer') . qq|$customer$customer
| . $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|
| . $locale->text('Order Number') . qq|
| . $locale->text('Transaction description') . qq|
| . $locale->text('Notes') . qq| | . $locale->text('Subtotal') . qq| | . $locale->text('Project Number') . qq|| . $locale->text('Transaction description') . qq|
@@ -1446,6 +1358,12 @@ sub ar_transactions { $option .= "\n
" if $option; $option .= $locale->text('Notes') . " : $form->{notes}"; } + if ($form->{transaction_description}) { + $callback .= "&transaction_description=" . $form->escape($form->{transaction_description}, 1); + $href .= "&transaction_description=" . $form->escape($form->{transaction_description}); + $option .= "\n
" if $option; + $option .= $locale->text('Transaction description') . " : $form->{transaction_description}"; + } if ($form->{transdatefrom}) { $callback .= "&transdatefrom=$form->{transdatefrom}"; @@ -1482,7 +1400,7 @@ sub ar_transactions { @columns = qw(transdate id type invnumber ordnumber name netamount tax amount paid - datepaid due duedate notes employee shippingpoint shipvia + datepaid due duedate transaction_description notes employee shippingpoint shipvia globalprojectnumber); $form->{"l_type"} = "Y"; @@ -1558,6 +1476,8 @@ sub ar_transactions { . ""; $column_header{globalprojectnumber} = qq|| . $locale->text('Project Number') . qq||; + $column_header{transaction_description} = + "" . $locale->text('Transaction description') . ""; $form->{title} = $locale->text('AR Transactions'); @@ -1644,8 +1564,13 @@ sub ar_transactions { $column_data{invnumber} = "{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}"; + + my $is_storno = $ar->{storno} && IS->is_storno(\%myconfig, $form, 'ar'); + my $has_storno = $ar->{storno} && !$is_storno; + $column_data{type} = "" . - ($ar->{storno} ? $locale->text("Storno (one letter abbreviation)") : + ($has_storno ? $locale->text("Invoice with Storno (abbreviation)") : + $is_storno ? $locale->text("Storno (one letter abbreviation)") : $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") : $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") : $locale->text("AR Transaction (abbreviation)")) @@ -1659,6 +1584,8 @@ sub ar_transactions { $column_data{employee} = "$ar->{employee} "; $column_data{globalprojectnumber} = "" . H($ar->{globalprojectnumber}) . ""; + $column_data{transaction_description} = + "" . H($ar->{transaction_description}) . ""; $i++; $i %= 2; @@ -1772,3 +1699,44 @@ sub ar_subtotal { $lxdebug->leave_sub(); } + + +sub storno { + $lxdebug->enter_sub(); + + if (IS->has_storno(\%myconfig, $form, 'ar')) { + $form->{title} = $locale->text("Cancel Accounts Receivables 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(); +}