use SL::TransNumber;
use SL::Util qw(trim);
use SL::DB;
+use Carp;
use strict;
my %accno_by_part = map { $_->{id} => $_ }
selectall_hashref_query($form, $dbh, <<SQL, @part_ids);
SELECT
- p.id, p.inventory_accno_id AS is_part,
+ p.id, p.part_type,
bg.inventory_accno_id,
tc.income_accno_id AS income_accno_id,
tc.expense_accno_id AS expense_accno_id,
while (my ($index => $part_id) = each %args) {
my $ref = $accno_by_part{$part_id} or next;
- $ref->{"inventory_accno_id"} = undef unless $ref->{"is_part"};
+ $ref->{"inventory_accno_id"} = undef unless $ref->{"part_type"} eq 'part';
my %accounts;
for my $type (qw(inventory income expense)) {
# reverse inventory items
my $query =
- qq|SELECT i.parts_id, p.inventory_accno_id, p.expense_accno_id, i.qty, i.allocated, i.sellprice
+ qq|SELECT i.parts_id, p.part_type, i.qty, i.allocated, i.sellprice
FROM invoice i, parts p
WHERE (i.parts_id = p.id)
AND (i.trans_id = ?)|;
while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
$netamount += $form->round_amount($ref->{sellprice} * $ref->{qty} * -1, 2);
- next unless $ref->{inventory_accno_id};
+ next unless $ref->{part_type} eq 'part';
# if $ref->{allocated} > 0 than we sold that many items
next if ($ref->{allocated} <= 0);
i.id AS invoice_id,
i.description, i.longdescription, i.qty, i.fxsellprice AS sellprice, i.parts_id AS id, i.unit, i.deliverydate, i.project_id, i.serialnumber,
i.price_factor_id, i.price_factor, i.marge_price_factor, i.discount, i.active_price_source, i.active_discount_source,
- p.partnumber, p.inventory_accno_id AS part_inventory_accno_id, pr.projectnumber, pg.partsgroup
+ p.partnumber, p.part_type, pr.projectnumber, pg.partsgroup
FROM invoice i
JOIN parts p ON (i.parts_id = p.id)
);
map { $ref->{"ic_cvar_$_->{name}"} = $_->{value} } @{ $cvars };
- map({ delete($ref->{$_}); } qw(inventory_accno inventory_new_chart inventory_valid)) if !$ref->{"part_inventory_accno_id"};
- delete($ref->{"part_inventory_accno_id"});
+ map({ delete($ref->{$_}); } qw(inventory_accno inventory_new_chart inventory_valid)) if !$ref->{"part_type"} eq 'part';
foreach my $type (qw(inventory income expense)) {
while ($ref->{"${type}_new_chart"} && ($ref->{"${type}_valid"} >=0)) {
my ($dbh, $myconfig, $form, $position, $id, $totalqty) = @_;
my $query =
- qq|SELECT a.parts_id, a.qty, p.part_type, p.partnumber, p.description, p.unit,
- p.inventory_accno_id, p.income_accno_id, p.expense_accno_id
+ qq|SELECT a.parts_id, a.qty, p.part_type, p.partnumber, p.description, p.unit
FROM assembly a
JOIN parts p ON (a.parts_id = p.id)
WHERE (a.id = ?)|;
# reverse inventory items
my $query =
- qq|SELECT i.id, i.parts_id, i.qty, i.assemblyitem, p.part_type, p.inventory_accno_id
+ qq|SELECT i.id, i.parts_id, i.qty, i.assemblyitem, p.part_type
FROM invoice i
JOIN parts p ON (i.parts_id = p.id)
WHERE i.trans_id = ?|;
i.description, i.longdescription, i.qty, i.fxsellprice AS sellprice, i.discount, i.parts_id AS id, i.unit, i.deliverydate AS reqdate,
i.project_id, i.serialnumber, i.pricegroup_id, i.ordnumber, i.donumber, i.transdate, i.cusordnumber, i.subtotal, i.lastcost,
i.price_factor_id, i.price_factor, i.marge_price_factor, i.active_price_source, i.active_discount_source,
- p.partnumber, p.part_type, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id, p.formel, p.listprice,
+ p.partnumber, p.part_type, p.notes AS partnotes, p.formel, p.listprice,
pr.projectnumber, pg.partsgroup, prg.pricegroup
FROM invoice i
c3.accno AS expense_accno, c3.new_chart_id AS expense_new_chart, date($transdate) - c3.valid_from as expense_valid,
oe.ordnumber AS ordnumber_oe, oe.transdate AS transdate_oe, oe.cusordnumber AS cusordnumber_oe,
p.partnumber, p.part_type, p.listprice, o.description, o.qty,
- o.sellprice, o.parts_id AS id, o.unit, o.discount, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id,
+ o.sellprice, o.parts_id AS id, o.unit, o.discount, p.notes AS partnotes, p.part_type,
o.reqdate, o.project_id, o.serialnumber, o.ship, o.lastcost,
o.ordnumber, o.transdate, o.cusordnumber, o.subtotal, o.longdescription,
o.price_factor_id, o.price_factor, o.marge_price_factor, o.active_price_source, o.active_discount_source,
map { $ref->{"ic_cvar_$_->{name}"} = $_->{value} } @{ $cvars };
# Handle accounts.
- if (!$ref->{"part_inventory_accno_id"}) {
+ if (!$ref->{"part_type"} eq 'part') {
map({ delete($ref->{$_}); } qw(inventory_accno inventory_new_chart inventory_valid));
}
- delete($ref->{"part_inventory_accno_id"});
+ # delete($ref->{"part_inventory_accno_id"});
# in collective order, copy global ordnumber, transdate, cusordnumber into item scope
# unless already present there