X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/b98b8e3f73a399d2d4df7be4962b56bd4ad8c82b..a7b9212927afc0b5b02295db4f7c2fba7318508f:/bin/mozilla/ap.pl diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index dc48e3d70..0afc2d842 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -32,7 +32,8 @@ #====================================================================== use POSIX qw(strftime); -use List::Util qw(sum); +use List::Util qw(max sum); +use List::UtilsBy qw(sort_by); use SL::AP; use SL::FU; @@ -41,10 +42,10 @@ use SL::IS; use SL::PE; use SL::ReportGenerator; use SL::DB::Default; +use SL::DB::PurchaseInvoice; require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; -require "bin/mozilla/drafts.pl"; require "bin/mozilla/reportgenerator.pl"; use strict; @@ -89,11 +90,9 @@ sub add { $main::auth->assert('general_ledger'); - return $main::lxdebug->leave_sub() if (load_draft_maybe()); - $form->{title} = "Add"; - $form->{callback} = "ap.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; + $form->{callback} = "ap.pl?action=add" unless $form->{callback}; AP->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; @@ -147,6 +146,8 @@ sub create_links { if (!$params{dont_save}) { %saved = map { ($_ => $form->{$_}) } qw(direct_debit taxincluded); $saved{duedate} = $form->{duedate} if $form->{duedate}; + $saved{currency} = $form->{currency} if $form->{currency}; + $saved{taxincluded} = $form->{taxincluded} if $form->{taxincluded}; } IR->get_vendor(\%myconfig, \%$form); @@ -187,6 +188,25 @@ sub create_links { $main::lxdebug->leave_sub(); } +sub _sort_payments { + my @fields = qw(acc_trans_id gldate datepaid source memo paid AP_paid paid_project_id); + my @payments = + grep { $_->{paid} != 0 } + map { + my $idx = $_; + +{ map { ($_ => delete($::form->{"${_}_${idx}"})) } @fields } + } (1..$::form->{paidaccounts}); + + @payments = sort_by { DateTime->from_kivitendo($_->{datepaid}) } @payments; + + $::form->{paidaccounts} = max scalar(@payments), 1; + + foreach my $idx (1 .. scalar(@payments)) { + my $payment = $payments[$idx - 1]; + $::form->{"${_}_${idx}"} = $payment->{$_} for @fields; + } +} + sub form_header { $main::lxdebug->enter_sub(); @@ -197,6 +217,8 @@ sub form_header { $main::auth->assert('general_ledger'); + $::form->{invoice_obj} = SL::DB::PurchaseInvoice->new(id => $::form->{id})->load if $::form->{id}; + $form->{title_} = $form->{title}; $form->{title} = $form->{title} eq 'Add' ? $locale->text('Add Accounts Payables Transaction') : $locale->text('Edit Accounts Payables Transaction'); @@ -303,6 +325,7 @@ sub form_header { $form->{javascript} .= qq||; $form->{javascript} .= qq||; $form->{javascript} .= qq||; + $form->{javascript} .= qq||; $form->header(); @@ -372,6 +395,8 @@ sub form_header { $form->{totalpaid} = 0; + _sort_payments(); + if ( $form->{'paid_'. $form->{paidaccounts}} ) { $form->{paidaccounts}++; } @@ -403,6 +428,11 @@ sub form_header { $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"}); } + #deaktivieren von gebuchten Zahlungen ausserhalb der Bücherkontrolle, vorher prüfen ob heute eingegeben + if ($form->date_closed($form->{"gldate_$i"})) { + $changeable = 0; + } + $form->{'paidaccount_changeable_'. $i} = $changeable; $form->{'labelpaid_project_id_'. $i} = $project_labels{$form->{'paid_project_id_'. $i}}; @@ -410,7 +440,9 @@ sub form_header { $form->{paid_missing} = $form->{invtotal_unformatted} - $form->{totalpaid}; - print $form->parse_html_template('ap/form_header'); + print $form->parse_html_template('ap/form_header', { + today => DateTime->today, + }); $main::lxdebug->leave_sub(); } @@ -422,7 +454,7 @@ sub form_footer { my $num_due; my $num_follow_ups; if ($::form->{id}) { - my $follow_ups = FU->follow_ups('trans_id' => $::form->{id}); + my $follow_ups = FU->follow_ups('trans_id' => $::form->{id}, 'not_done' => 1); if (@{ $follow_ups }) { $num_due = sum map { $_->{due} * 1 } @{ $follow_ups }; @@ -557,6 +589,7 @@ sub post_payment { my $locale = $main::locale; $main::auth->assert('general_ledger'); + $form->mtime_ischanged('ap'); $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); @@ -568,8 +601,13 @@ sub post_payment { $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + $form->error($locale->text('Cannot post transaction above the maximum future booking date!')) + if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig)); + + #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen + # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll) $form->error($locale->text('Cannot post payment for a closed period!')) - if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig)); + if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig)); if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { $form->{"exchangerate_$i"} = $form->{exchangerate} @@ -582,9 +620,15 @@ sub post_payment { ($form->{AP}) = split /--/, $form->{AP}; ($form->{AP_paid}) = split /--/, $form->{AP_paid}; - $form->redirect($locale->text('Payment posted!')) - if (AP->post_payment(\%myconfig, \%$form)); + if (AP->post_payment(\%myconfig, \%$form)) { + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{what_done} = 'invoice'; + $form->{addition} = "PAYMENT POSTED"; + $form->save_history; + $form->redirect($locale->text('Payment posted!')) + } else { $form->error($locale->text('Cannot post payment!')); + }; $main::lxdebug->leave_sub(); @@ -599,6 +643,7 @@ sub post { my $locale = $main::locale; $main::auth->assert('general_ledger'); + $form->mtime_ischanged('ap'); my ($inline) = @_; @@ -641,8 +686,13 @@ sub post { $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + $form->error($locale->text('Cannot post transaction above the maximum future booking date!')) + if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig)); + + #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen + # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll) $form->error($locale->text('Cannot post payment for a closed period!')) - if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig)); + if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig)); if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { $form->{"exchangerate_$i"} = $form->{exchangerate} @@ -658,7 +708,7 @@ sub post { my ($vendor) = split /--/, $form->{vendor}; if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") { &update; - ::end_of_request(); + $::dispatcher->end_request; } my ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected}; my ($taxkey, $NULL) = split /--/, $form->{taxchartselected}; @@ -673,12 +723,12 @@ sub post { if (AP->post_transaction(\%myconfig, \%$form)) { # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "POSTED"; + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "POSTED"; + $form->{what_done} = "invoice"; $form->save_history; } # /saving the history - remove_draft() if $form->{remove_draft}; # Dieser Text wird niemals ausgegeben: Probleme beim redirect? $form->redirect($locale->text('Transaction posted!')) unless $inline; } else { @@ -699,8 +749,12 @@ sub post_as_new { $form->{postasnew} = 1; # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "POSTED AS NEW"; + # does this work? post_as_new for ap doesn't immediately save the + # invoice, because the invnumber has to be entered by hand. + # And the value of $form->{postasnew} isn't checked when calling post + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "POSTED AS NEW"; + $form->{what_done} = "invoice"; $form->save_history; } # /saving the history @@ -777,8 +831,9 @@ sub yes { if (AP->delete_transaction(\%myconfig, \%$form)) { # saving the history if(!exists $form->{addition}) { - $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "DELETED"; + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "DELETED"; + $form->{what_done} = "invoice"; $form->save_history; } # /saving the history @@ -859,10 +914,11 @@ sub ap_transactions { my @columns = qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid due duedate transaction_description notes employee globalprojectnumber - vendornumber country ustid taxzone payment_terms charts); + vendornumber country ustid taxzone payment_terms charts direct_debit); my @hidden_variables = map { "l_${_}" } @columns; - push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto department); + push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto department + parts_partnumber parts_description); my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables); @@ -887,12 +943,13 @@ sub ap_transactions { 'vendornumber' => { 'text' => $locale->text('Vendor Number'), }, 'country' => { 'text' => $locale->text('Country'), }, 'ustid' => { 'text' => $locale->text('USt-IdNr.'), }, - 'taxzone' => { 'text' => $locale->text('Steuersatz'), }, + 'taxzone' => { 'text' => $locale->text('Tax rate'), }, 'payment_terms' => { 'text' => $locale->text('Payment Terms'), }, 'charts' => { 'text' => $locale->text('Buchungskonto'), }, + 'direct_debit' => { 'text' => $locale->text('direct debit'), }, ); - foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) { + foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit)) { my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir}; $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir"; } @@ -917,6 +974,8 @@ sub ap_transactions { push @options, $locale->text('Order Number') . " : $form->{ordnumber}" if ($form->{ordnumber}); push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes}); push @options, $locale->text('Transaction description') . " : $form->{transaction_description}" if ($form->{transaction_description}); + push @options, $locale->text('Part Description') . " : $form->{parts_description}" if $form->{parts_description}; + push @options, $locale->text('Part Number') . " : $form->{parts_partnumber}" if $form->{parts_partnumber}; push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1) if ($form->{transdatefrom}); push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1) if ($form->{transdateto}); push @options, $locale->text('Open') if ($form->{open}); @@ -968,6 +1027,8 @@ sub ap_transactions { : $locale->text("AP Transaction (abbreviation)"); } + $ap->{direct_debit} = $ap->{direct_debit} ? $::locale->text('yes') : $::locale->text('no'); + my $row = { }; foreach my $column (@columns) { @@ -1022,8 +1083,9 @@ sub storno { # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = "ordnumber_$form->{ordnumber}"; - $form->{addition} = "STORNO"; + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "STORNO"; + $form->{what_done} = "invoice"; $form->save_history; } # /saving the history