$form->{nodiscount} = $form->format_amount($myconfig, $nodiscount, 2);
$form->{yesdiscount} = $form->format_amount($myconfig, $form->{nodiscount_total} - $nodiscount, 2);
- $form->{invtotal} = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
- $form->{total} = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2);
+ my $grossamount = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
+ $form->{invtotal} = $form->round_amount($grossamount, 2, 1);
+ $form->{rounding} = $form->round_amount(
+ $form->{invtotal} - $form->round_amount($grossamount, 2),
+ 2
+ );
+ $form->{rounding} = $form->format_amount($myconfig, $form->{rounding}, 2);
+ $form->{total} = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2);
$form->{invtotal} = $form->format_amount($myconfig, $form->{invtotal}, 2);
$form->{paid} = $form->format_amount($myconfig, $form->{paid}, 2);
- $form->set_payment_options($myconfig, $form->{invdate});
+ $form->set_payment_options($myconfig, $form->{invdate}, 'sales_invoice');
+ $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id};
$form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef);
$form->{delivery_term}->description_long($form->{delivery_term}->translated_attribute('description_long', $form->{language_id})) if $form->{delivery_term} && $form->{language_id};
- $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id};
$form->{username} = $myconfig->{name};
$ref->{street} = $customer->street;
$ref->{zipcode} = $customer->zipcode;
$ref->{country} = $customer->country;
+ $ref->{gln} = $customer->gln;
}
my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id});
if ($contact) {
$ref->{cp_gender} = $contact->cp_gender;
}
}
- # remove id and taxincluded before copy back
- delete @$ref{qw(id taxincluded)};
+ # remove id,notes (double of customernotes) and taxincluded before copy back
+ delete @$ref{qw(id taxincluded notes)};
@wanted_vars = grep({ $_ } @wanted_vars);
if (scalar(@wanted_vars) > 0) {
}
# Invoice Summary includes Rounding
+ my $grossamount = $netamount + $tax;
my $rounding = $form->round_amount(
- $form->round_amount($netamount + $tax, 2, 1) - $form->round_amount($netamount + $tax, 2), 2
+ $form->round_amount($grossamount, 2, 1) - $form->round_amount($grossamount, 2),
+ 2
);
my $rnd_accno = $rounding == 0 ? 0
: $rounding > 0 ? $form->{rndgain_accno}
- : $form->{rndloss_accno};
- $form->{amount}{ $form->{id} }{ $form->{AR} } = $form->round_amount($netamount + $tax, 2, 1);
- $form->{paid} =
- $form->round_amount($form->{paid} * $form->{exchangerate} + $diff, 2);
+ : $form->{rndloss_accno}
+ ;
+ $form->{amount}{ $form->{id} }{ $form->{AR} } = $form->round_amount($grossamount, 2, 1);
+ $form->{paid} = $form->round_amount(
+ $form->{paid} * $form->{exchangerate} + $diff,
+ 2
+ );
# reverse AR
$form->{amount}{ $form->{id} }{ $form->{AR} } *= -1;
$query = qq|UPDATE ar SET paid = ? WHERE id = ?|;
do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id}));
+ $form->new_lastmtime('ar');
+
$dbh->commit if !$provided_dbh;
$main::lxdebug->leave_sub();
if ($form->{storno}) {
$query =
qq!UPDATE ar SET
- paid = paid + amount,
+ paid = amount,
storno = 't',
intnotes = ? || intnotes
WHERE id = ?!;
do_query($form, $dbh, qq|UPDATE ar SET paid = amount WHERE id = ?|, conv_i($form->{"id"}));
}
+ $form->new_lastmtime('ar');
+
$form->{name} = $form->{customer};
$form->{name} =~ s/--\Q$form->{customer_id}\E//;
parts_id => $part->id,
bin_id => $bin_id);
if ($error == 1) {
- push @errors, $::locale->text('Part "#1" has chargenumber or best before date set. So it cannot be transfered automaticaly.',
+ push @errors, $::locale->text('Part "#1" has chargenumber or best before date set. So it cannot be transfered automatically.',
$part->description);
}
my $form_unit_obj = SL::DB::Unit->new(name => $unit)->load;
# delete acc_trans
my @values = (conv_i($form->{id}));
do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE trans_id = ?|, @values);
+
+ $query = qq|DELETE FROM custom_variables
+ WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE (module = 'ShipTo')))
+ AND (trans_id IN (SELECT shipto_id FROM shipto WHERE (module = 'AR') AND (trans_id = ?)))|;
+ do_query($form, $dbh, $query, @values);
do_query($form, $dbh, qq|DELETE FROM shipto WHERE (trans_id = ?) AND (module = 'AR')|, @values);
$main::lxdebug->leave_sub();
qq|SELECT
a.invnumber, a.ordnumber, a.quonumber, a.cusordnumber,
a.orddate, a.quodate, a.globalproject_id,
- a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate,
+ a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.storno_id, a.gldate,
a.shippingpoint, a.shipvia, a.notes, a.intnotes, a.taxzone_id,
a.duedate, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.shipto_id, a.cp_id,
a.employee_id, a.salesman_id, a.payment_id,
}
$sth->finish;
+ # Fetch shipping address.
+ $query = qq|SELECT s.* FROM shipto s WHERE s.trans_id = ? AND s.module = 'AR'|;
+ $ref = selectfirst_hashref_query($form, $dbh, $query, $form->{id});
+
+ $form->{$_} = $ref->{$_} for grep { $_ ne 'id' } keys %$ref;
+
+ if ($form->{shipto_id}) {
+ my $cvars = CVar->get_custom_variables(
+ dbh => $dbh,
+ module => 'ShipTo',
+ trans_id => $form->{shipto_id},
+ );
+ $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars };
+ }
+
Common::webdav_folder($form);
}
c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit,
c.email, c.cc, c.bcc, c.language_id, c.payment_id, c.delivery_term_id,
c.street, c.zipcode, c.city, c.country,
- c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, cu.name AS curr,
+ c.notes AS intnotes, c.pricegroup_id as customer_pricegroup_id, c.taxzone_id, c.salesman_id, cu.name AS curr,
c.taxincluded_checked, c.direct_debit,
b.discount AS tradediscount, b.description AS business
FROM customer c
my ($table, $field) = split m/\./, $column;
next if !$form->{"${field}_${i}"};
$where .= qq| AND lower(${column}) ILIKE ?|;
- push @values, '%' . $form->{"${field}_${i}"} . '%';
+ push @values, like($form->{"${field}_${i}"});
}
my (%mm_by_id);
my $mm_query = qq|
SELECT parts_id, model FROM makemodel LEFT JOIN parts ON parts.id = parts_id WHERE NOT parts.obsolete AND model ILIKE ?;
|;
- my $mm_results = selectall_hashref_query($::form, $dbh, $mm_query, '%' . $form->{"partnumber_$i"} . '%');
+ my $mm_results = selectall_hashref_query($::form, $dbh, $mm_query, like($form->{"partnumber_$i"}));
my @mm_ids = map { $_->{parts_id} } @$mm_results;
push @{$mm_by_id{ $_->{parts_id} } ||= []}, $_ for @$mm_results;