use SL::IC;
use SL::IO;
use SL::TransNumber;
+use SL::DB::Default;
use Data::Dumper;
use strict;
my ($dec) = ($sellprice =~ /\.(\d+)/);
my $decimalplaces = max 2, length($dec);
- my $parsed_discount = $form->parse_amount($myconfig, $form->{"discount_$i"});
- my $linetotal_exact = $form->{"qty_$i"} * $sellprice * (100 - $parsed_discount) / 100 / $price_factor->{factor};
- my $linetotal = $form->round_amount($linetotal_exact, 2);
- my $discount = $form->round_amount($form->{"qty_$i"} * $sellprice * $parsed_discount / 100 / $price_factor->{factor} - ($linetotal - $linetotal_exact),
- $decimalplaces);
- my $nodiscount_linetotal = $form->round_amount($form->{"qty_$i"} * $sellprice / $price_factor->{factor}, 2);
+ my $parsed_discount = $form->parse_amount($myconfig, $form->{"discount_$i"});
+
+ my $linetotal_exact = $form->{"qty_$i"} * $sellprice * (100 - $parsed_discount) / 100 / $price_factor->{factor};
+ my $linetotal = $form->round_amount($linetotal_exact, 2);
+
+ my $nodiscount_exact_linetotal = $form->{"qty_$i"} * $sellprice / $price_factor->{factor};
+ my $nodiscount_linetotal = $form->round_amount($nodiscount_exact_linetotal,2);
+
+ my $discount = $nodiscount_linetotal - $linetotal; # is always rounded because $nodiscount_linetotal and $linetotal are rounded
+
+ my $discount_round_error = $discount + ($linetotal_exact - $nodiscount_exact_linetotal); # not used
+
$form->{"netprice_$i"} = $form->round_amount($form->{"qty_$i"} ? ($linetotal / $form->{"qty_$i"}) : 0, 2);
push @{ $form->{TEMPLATE_ARRAYS}->{netprice} }, ($form->{"netprice_$i"} != 0) ? $form->format_amount($myconfig, $form->{"netprice_$i"}, $decimalplaces) : '';
$subtotal_header = 0;
} else {
- push @{ $form->{TEMPLATE_ARRAYS}->{discount_sub} }, "";
- push @{ $form->{TEMPLATE_ARRAYS}->{nodiscount_sub} }, "";
+ push @{ $form->{TEMPLATE_ARRAYS}->{$_} }, "" for qw(discount_sub nodiscount_sub discount_sub_nofmt nodiscount_sub_nofmt);
}
if (!$form->{"discount_$i"}) {
if ($form->{"acc_trans_id_$i"}
&& $payments_only
- && ($::lx_office_conf{features}->{payments_changeable} == 0)) {
+ && (SL::DB::Default->get->payments_changeable == 0)) {
next;
}
# exchangerate difference
$form->{fx}{$accno}{ $form->{"datepaid_$i"} } +=
- $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) + $diff;
+ $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) + $diff;
# gain/loss
$amount =
- $form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} *
- $form->{"exchangerate_$i"};
+ $form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} *
+ $form->{"exchangerate_$i"};
if ($amount > 0) {
- $form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } +=
- $amount;
+ $form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } += $amount;
} else {
- $form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } +=
- $amount;
+ $form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } += $amount;
}
$diff = 0;
IO->set_datepaid(table => 'ar', id => $form->{id}, dbh => $dbh);
- if ($payments_only) {
- $query = qq|UPDATE ar SET paid = ? WHERE id = ?|;
- do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id}));
-
- $dbh->commit if !$provided_dbh;
-
- $main::lxdebug->leave_sub();
- return;
- }
-
# record exchange rate differences and gains/losses
foreach my $accno (keys %{ $form->{fx} }) {
foreach my $transdate (keys %{ $form->{fx}{$accno} }) {
- if (
- ($form->{fx}{$accno}{$transdate} =
- $form->round_amount($form->{fx}{$accno}{$transdate}, 2)
- ) != 0
- ) {
+ $form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2);
+ if ( $form->{fx}{$accno}{$transdate} != 0 ) {
$query =
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1',
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
- @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, $project_id);
+ @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_i($project_id));
do_query($form, $dbh, $query, @values);
}
}
}
+ if ($payments_only) {
+ $query = qq|UPDATE ar SET paid = ? WHERE id = ?|;
+ do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id}));
+
+ $dbh->commit if !$provided_dbh;
+
+ $main::lxdebug->leave_sub();
+ return;
+ }
+
$amount = $netamount + $tax;
# save AR record
cp_id = ?, marge_total = ?, marge_percent = ?,
globalproject_id = ?, delivery_customer_id = ?,
transaction_description = ?, delivery_vendor_id = ?,
- donumber = ?, invnumber_for_credit_note = ?
+ donumber = ?, invnumber_for_credit_note = ?, direct_debit = ?
WHERE id = ?|;
@values = ( $form->{"invnumber"}, $form->{"ordnumber"}, $form->{"quonumber"}, $form->{"cusordnumber"},
conv_date($form->{"invdate"}), conv_date($form->{"orddate"}), conv_date($form->{"quodate"}), conv_i($form->{"customer_id"}),
conv_i($form->{"cp_id"}), 1 * $form->{marge_total} , 1 * $form->{marge_percent},
conv_i($form->{"globalproject_id"}), conv_i($form->{"delivery_customer_id"}),
$form->{transaction_description}, conv_i($form->{"delivery_vendor_id"}),
- $form->{"donumber"}, $form->{"invnumber_for_credit_note"},
+ $form->{"donumber"}, $form->{"invnumber_for_credit_note"}, $form->{direct_debit} ? 't' : 'f',
conv_i($form->{"id"}));
do_query($form, $dbh, $query, @values);
'table' => 'ar',);
# safety check datev export
- if ($::lx_office_conf{datev_check}{check_on_sales_invoice}) {
+ if ($::instance_conf->get_datev_check_on_sales_invoice) {
my $transdate = $::form->{invdate} ? DateTime->from_lxoffice($::form->{invdate}) : undef;
$transdate ||= DateTime->today;
$old_form = save_form();
# Delete all entries in acc_trans from prior payments.
- if ($::lx_office_conf{features}->{payments_changeable} != 0) {
+ if (SL::DB::Default->get->payments_changeable != 0) {
$self->_delete_payments($form, $dbh);
}
a.employee_id, a.salesman_id, a.payment_id,
a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type,
a.transaction_description, a.donumber, a.invnumber_for_credit_note,
- a.marge_total, a.marge_percent,
+ a.marge_total, a.marge_percent, a.direct_debit,
e.name AS employee
FROM ar a
LEFT JOIN employee e ON (e.id = a.employee_id)
c.email, c.cc, c.bcc, c.language_id, c.payment_id,
c.street, c.zipcode, c.city, c.country,
c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, c.curr,
+ c.taxincluded_checked, c.direct_debit,
$duedate + COALESCE(pt.terms_netto, 0) AS duedate,
b.discount AS tradediscount, b.description AS business
FROM customer c
my $pricegroup_old = $form->{"pricegroup_old_$i"};
- # sellprice has format 13,0000 or 0,00000, can't check for 0 numerically
+ # sellprice has format 13,0000 or 0,00000, can't check for 0 numerically
my $sellprice = $form->{"sellprice_$i"};
my $pricegroup_id = $form->{"pricegroup_id_$i"};
$form->{"new_pricegroup_$i"} = $selectedpricegroup_id;
$pkr->{selected} = ' selected'; # unless $form->{selected};
# no customer pricesgroup set
- if ($pkr->{price_unfmt} == $pkr->{default_sellprice}) {
+ if ($pkr->{price_ufmt} == $pkr->{default_sellprice}) {
$pkr->{price} = $form->{"sellprice_$i"};
$form->{"sellprice_$i"} = $pkr->{price};
}
- } elsif ($pkr->{price_unfmt} == $pkr->{default_sellprice} and $pkr->{default_sellprice} != 0) {
+ } elsif ($pkr->{price_ufmt} == $pkr->{default_sellprice} and $pkr->{default_sellprice} != 0) {
$pkr->{price} = $form->{"sellprice_$i"};
$pkr->{selected} = ' selected';
}