use SL::Common;
use SL::DBUtils;
use SL::MoreCommon;
+use Data::Dumper;
sub invoice_details {
$main::lxdebug->enter_sub();
if (!$form->{employee_id}) {
$form->get_employee($dbh);
}
+
+ $form->{defaultcurrency} = $form->get_default_currency($myconfig);
($null, $form->{department_id}) = split(/--/, $form->{department});
my $basefactor;
my $basqty;
+ $form->{"marge_percent_$i"} = $form->parse_amount($myconfig, $form->{"marge_percent_$i"}) * 1;
+ $form->{"marge_absolut_$i"} = $form->parse_amount($myconfig, $form->{"marge_absolut_$i"}) * 1;
+ $form->{"lastcost_$i"} = $form->{"lastcost_$i"} * 1;
+
if ($form->{storno}) {
$form->{"qty_$i"} *= -1;
}
qq|INSERT INTO invoice (trans_id, parts_id, description, longdescription, qty,
sellprice, fxsellprice, discount, allocated, assemblyitem,
unit, deliverydate, project_id, serialnumber, pricegroup_id,
- ordnumber, transdate, cusordnumber, base_qty, subtotal)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
+ ordnumber, transdate, cusordnumber, base_qty, subtotal,
+ marge_percent, marge_total, lastcost)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
@values = (conv_i($form->{id}), conv_i($form->{"id_$i"}),
$form->{"description_$i"}, $form->{"longdescription_$i"}, $form->{"qty_$i"},
$form->{"unit_$i"}, conv_date($form->{"deliverydate_$i"}), conv_i($form->{"project_id_$i"}),
$form->{"serialnumber_$i"}, conv_i($pricegroup_id),
$form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
- $form->{"cusordnumber_$i"}, $baseqty, $subtotal);
+ $form->{"cusordnumber_$i"}, $baseqty, $subtotal,
+ $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
+ $form->{"lastcost_$i"});
do_query($form, $dbh, $query, @values);
if ($form->{lizenzen} && $form->{"licensenumber_$i"}) {
$form->{"exchangerate_$i"}, 0);
}
}
+
+ } else { # if (!$form->{storno})
+ $form->{marge_total} *= -1;
}
if ($payments_only) {
$amount = $netamount + $tax;
- # fill in subject if there is none
- $form->{subject} = qq|$form->{label} $form->{invnumber}|
- unless $form->{subject};
-
- # if there is a message stuff it into the intnotes
- my $cc = "Cc: $form->{cc}\\r\n" if $form->{cc};
- my $bcc = "Bcc: $form->{bcc}\\r\n" if $form->{bcc};
- my $now = scalar localtime;
- $form->{intnotes} .= qq|\r
-\r| if $form->{intnotes};
-
- $form->{intnotes} .= qq|[email]\r
-Date: $now
-To: $form->{email}\r
-$cc${bcc}Subject: $form->{subject}\r
-\r
-Message: $form->{message}\r| if $form->{message};
-
# save AR record
$query = qq|UPDATE ar set
invnumber = ?,
employee_id = ?,
salesman_id = ?,
storno = ?,
+ storno_id = ?,
globalproject_id = ?,
cp_id = ?,
- transaction_description = ?
+ transaction_description = ?,
+ marge_total = ?,
+ marge_percent = ?
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->{"shipto_id"}),
conv_i($form->{"delivery_customer_id"}), conv_i($form->{"delivery_vendor_id"}),
conv_i($form->{"employee_id"}), conv_i($form->{"salesman_id"}),
- $form->{"storno"} ? 't' : 'f', conv_i($form->{"globalproject_id"}),
+ $form->{"storno"} ? 't' : 'f', conv_i($form->{storno_id}), conv_i($form->{"globalproject_id"}),
conv_i($form->{"cp_id"}), $form->{transaction_description},
+ $form->{marge_total} * 1, $form->{marge_percent} * 1,
conv_i($form->{"id"}));
do_query($form, $dbh, $query, @values);
# Delete all entries in acc_trans from prior payments.
$self->_delete_payments($form, $dbh);
- my @after_dp;
- push @after_dp, selectall_hashref_query($form, $dbh, qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY oid|, $form->{id});
-
# Save the new payments the user made before cleaning up $form.
map { $payments{$_} = $form->{$_} } grep m/^datepaid_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^AR_paid_\d+$|^paidaccounts$/, keys %{ $form };
# Retrieve the invoice from the database.
$self->retrieve_invoice($myconfig, $form);
- # Set up the content of $form in the way that IR::post_invoice() expects.
+ # Set up the content of $form in the way that IS::post_invoice() expects.
$form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate});
for $row (1 .. scalar @{ $form->{invoice_details} }) {
# Restore the payment options from the user input.
map { $form->{$_} = $payments{$_} } keys %payments;
- # Get the AP accno (which is normally done by Form::create_links()).
+ # Get the AR accno (which is normally done by Form::create_links()).
$query =
qq|SELECT c.accno
FROM acc_trans at
my $taxzone_id = $form->{"taxzone_id"} * 1;
my $query =
qq|SELECT i.id, i.trans_id, i.base_qty, i.allocated, i.sellprice,
-
- c1.accno AS inventory_accno,
- c1.new_chart_id AS inventory_new_chart,
- date($transdate) - c1.valid_from AS inventory_valid,
-
- c2.accno AS income_accno,
- c2.new_chart_id AS income_new_chart,
- date($transdate) - c2.valid_from AS income_valid,
-
- c3.accno AS expense_accno,
- c3.new_chart_id AS expense_new_chart,
- date($transdate) - c3.valid_from AS expense_valid
-
+ c1.accno AS inventory_accno, c1.new_chart_id AS inventory_new_chart, date($transdate) - c1.valid_from AS inventory_valid,
+ c2.accno AS income_accno, c2.new_chart_id AS income_new_chart, date($transdate) - c2.valid_from AS income_valid,
+ c3.accno AS expense_accno, c3.new_chart_id AS expense_new_chart, date($transdate) - c3.valid_from AS expense_valid
FROM invoice i, parts p
LEFT JOIN chart c1 ON ((SELECT inventory_accno_id FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c1.id)
LEFT JOIN chart c2 ON ((SELECT income_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c2.id)
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.marge_total, a.marge_percent,
e.name AS employee
FROM ar a
LEFT JOIN employee e ON (e.id = a.employee_id)
i.description, i.longdescription, i.qty, i.fxsellprice AS sellprice,
i.discount, i.parts_id AS id, i.unit, i.deliverydate,
i.project_id, i.serialnumber, i.id AS invoice_pos, i.pricegroup_id,
- i.ordnumber, i.transdate, i.cusordnumber, i.subtotal,
+ i.ordnumber, i.transdate, i.cusordnumber, i.subtotal, i.lastcost,
p.partnumber, p.assembly, p.bin, p.notes AS partnotes,
p.inventory_accno_id AS part_inventory_accno_id, p.formel,
my $query =
qq|SELECT
p.id, p.partnumber, p.description, p.sellprice,
- p.listprice, p.inventory_accno_id,
+ p.listprice, p.inventory_accno_id, p.lastcost,
c1.accno AS inventory_accno,
c1.new_chart_id AS inventory_new_chart,
sub is_storno {
$main::lxdebug->enter_sub();
- my ($self, $myconfig, $form, $table) = @_;
+ my ($self, $myconfig, $form, $table, $id) = @_;
- $main::lxdebug->leave_sub() and return 0 unless ($form->{id});
+ $main::lxdebug->leave_sub() and return 0 unless ($id);
# make sure there's no funny stuff in $table
# ToDO: die when this happens and throw an error
my $dbh = $form->dbconnect($myconfig);
my $query = qq|SELECT storno FROM $table WHERE id = ?|;
- my ($result) = selectrow_query($form, $dbh, $query, $form->{id});
+ my ($result) = selectrow_query($form, $dbh, $query, $id);
$dbh->disconnect();