X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAR.pm;h=a842b9da5a99e2c1a20765f9b87cb89d0f36444f;hb=85ab58eb1bbdb3fc723bb3ab30e15e150e62556d;hp=3def7597a5ff358777de8f3af4ddb93664dcfeb0;hpb=d331a3d77f0b24a301412799d2e9cc5fa1bf27ba;p=kivitendo-erp.git diff --git a/SL/AR.pm b/SL/AR.pm index 3def7597a..a842b9da5 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -40,6 +40,7 @@ use SL::DBUtils; use SL::IO; use SL::MoreCommon; use SL::DB::Default; +use SL::TransNumber; use strict; @@ -134,9 +135,12 @@ sub post_transaction { } else { $query = qq|SELECT nextval('glid')|; ($form->{id}) = selectrow_query($form, $dbh, $query); - $query = qq|INSERT INTO ar (id, invnumber, employee_id, curr) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE curr=?))|; + $query = qq|INSERT INTO ar (id, invnumber, employee_id, currency_id) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE name=?))|; do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency}); - $form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh) unless $form->{invnumber}; + if (!$form->{invnumber}) { + my $trans_number = SL::TransNumber->new(type => 'invoice', dbh => $dbh, number => $form->{partnumber}, id => $form->{id}); + $form->{invnumber} = $trans_number->create_unique; + } } } @@ -191,12 +195,12 @@ sub post_transaction { # add recievables $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), - (SELECT tax_id - FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) - AND startdate <= ? + (SELECT tax_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), @@ -239,12 +243,12 @@ sub post_transaction { # add receivable $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), - (SELECT tax_id - FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) - AND startdate <= ? + (SELECT tax_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}, $form->{AR}{receivables}, conv_date($form->{"datepaid_$i"}), @@ -260,12 +264,12 @@ sub post_transaction { $amount = $form->{"paid_$i"} * -1; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), - (SELECT tax_id - FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) - AND startdate <= ? + (SELECT tax_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}, @@ -278,12 +282,12 @@ sub post_transaction { if ($amount != 0) { $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), - (SELECT tax_id - FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) - AND startdate <= ? + (SELECT tax_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"}, @@ -298,12 +302,12 @@ sub post_transaction { my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), - (SELECT tax_id - FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) - AND startdate <= ? + (SELECT tax_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno, $accno, conv_date($form->{"datepaid_$i"}), $accno); @@ -330,6 +334,7 @@ sub post_transaction { dbh => $dbh, from => $transdate, to => $transdate, + trans_id => $form->{id}, ); $datev->export; @@ -483,7 +488,7 @@ sub ar_transactions { my @values; my $query = - qq|SELECT DISTINCT a.id, a.invnumber, a.ordnumber, a.transdate, | . + qq|SELECT DISTINCT a.id, a.invnumber, a.ordnumber, a.cusordnumber, a.transdate, | . qq| a.duedate, a.netamount, a.amount, a.paid, | . qq| a.invoice, a.datepaid, a.terms, a.notes, a.shipvia, | . qq| a.shippingpoint, a.storno, a.storno_id, a.globalproject_id, | . @@ -508,12 +513,17 @@ sub ar_transactions { qq|LEFT JOIN employee e ON (a.employee_id = e.id) | . qq|LEFT JOIN employee e2 ON (a.salesman_id = e2.id) | . qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id)| . - qq|LEFT JOIN tax_zones tz ON (tz.id = c.taxzone_id)| . - qq|LEFT JOIN payment_terms pt ON (pt.id = c.payment_id)| . + qq|LEFT JOIN tax_zones tz ON (tz.id = a.taxzone_id)| . + qq|LEFT JOIN payment_terms pt ON (pt.id = a.payment_id)| . qq|LEFT JOIN business b ON (b.id = c.business_id)| . qq|LEFT JOIN department d ON (d.id = a.department_id)|; my $where = "1 = 1"; + + unless ( $::auth->assert('show_ar_transactions', 1) ) { + $where .= " AND NOT invoice = 'f' "; # remove ar transactions from Sales -> Reports -> Invoices + }; + if ($form->{customernumber}) { $where .= " AND c.customernumber = ?"; push(@values, $form->{customernumber}); @@ -540,7 +550,7 @@ sub ar_transactions { $where .= " AND d.description ILIKE ?"; push(@values, $department); } - foreach my $column (qw(invnumber ordnumber notes transaction_description)) { + foreach my $column (qw(invnumber ordnumber cusordnumber notes transaction_description)) { if ($form->{$column}) { $where .= " AND a.$column ILIKE ?"; push(@values, $form->like($form->{$column})); @@ -593,7 +603,7 @@ sub ar_transactions { my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC'; my $sortorder = join(', ', map { "$_ $sortdir" } @a); - if (grep({ $_ eq $form->{sort} } qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description))) { + if (grep({ $_ eq $form->{sort} } qw(id transdate duedate invnumber ordnumber cusordnumber name datepaid employee shippingpoint shipvia transaction_description))) { $sortorder = $form->{sort} . " $sortdir"; } @@ -632,7 +642,7 @@ sub setup_form { my ($self, $form, $for_post_payments) = @_; my ($exchangerate, $akey, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate, - $totalamount, $taxincluded, $tax); + $totalamount, $tax); # forex $form->{forex} = $form->{exchangerate}; @@ -716,7 +726,6 @@ sub setup_form { } } - $form->{taxincluded} = $taxincluded if ($form->{id}); $form->{paidaccounts} = 1 if not defined $form->{paidaccounts}; if ($form->{taxincluded} && $form->{taxrate} && $totalamount) { @@ -795,4 +804,3 @@ sub storno { 1; -