use SL::IO;
use SL::MoreCommon;
use SL::DB::Default;
+use SL::TransNumber;
use strict;
} 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;
+ }
}
}
# 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}),
# 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"}),
$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"},
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"},
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);
dbh => $dbh,
from => $transdate,
to => $transdate,
+ trans_id => $form->{id},
);
$datev->export;
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, | .
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});
$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}));
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";
}
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};
}
}
- $form->{taxincluded} = $taxincluded if ($form->{id});
$form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
1;
-