X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=b1df09770cddc1bf0f3fb9206d3774e2def38a56;hb=be47ce7f0ee15e692ade53804c8b4682dc89d627;hp=3e72da7aa8b136f35c8a0069ec406b602f68b12f;hpb=d46511359cfa6dd1bdee642b6f852011cb62234b;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index 3e72da7aa..b1df09770 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -58,6 +58,35 @@ sub invoice_details { ($form->{terms}) = $sth->fetchrow_array; $sth->finish; + my (@project_ids, %projectnumbers); + + push(@project_ids, $form->{"globalproject_id"}) if ($form->{"globalproject_id"}); + + # sort items by partsgroup + for $i (1 .. $form->{rowcount}) { + $partsgroup = ""; + if ($form->{"partsgroup_$i"} && $form->{groupitems}) { + $partsgroup = $form->{"partsgroup_$i"}; + } + push @partsgroup, [$i, $partsgroup]; + push(@project_ids, $form->{"project_id_$i"}) if ($form->{"project_id_$i"}); + } + + if (@project_ids) { + $query = "SELECT id, projectnumber FROM project WHERE id IN (" . + join(", ", map({ "?" } @project_ids)) . ")"; + $sth = $dbh->prepare($query); + $sth->execute(@project_ids) || + $form->dberror($query . " (" . join(", ", @project_ids) . ")"); + while (my $ref = $sth->fetchrow_hashref()) { + $projectnumbers{$ref->{id}} = $ref->{projectnumber}; + } + $sth->finish(); + } + + $form->{"globalprojectnumber"} = + $projectnumbers{$form->{"globalproject_id"}}; + my $tax = 0; my $item; my $i; @@ -91,6 +120,15 @@ sub invoice_details { my $subtotal_header = 0; my $subposition = 0; + my @arrays = + qw(runningnumber number description longdescription qty ship unit bin + deliverydate_oe ordnumber_oe transdate_oe licensenumber validuntil + partnotes serialnumber reqdate sellprice listprice netprice + discount p_discount discount_sub nodiscount_sub + linetotal nodiscount_linetotal tax_rate projectnumber); + + my @tax_arrays = + qw(taxbase tax taxdescription taxrate taxnumber); foreach $item (sort { $a->[1] cmp $b->[1] } @partsgroup) { $i = $item->[0]; @@ -99,8 +137,7 @@ sub invoice_details { push(@{ $form->{description} }, qq|$item->[1]|); $sameitem = $item->[1]; - map { push(@{ $form->{$_} }, "") } - qw(runningnumber number serialnumber bin partnotes qty unit deliverydate sellprice listprice netprice discount linetotal); + map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays)); } $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"}); @@ -230,8 +267,8 @@ sub invoice_details { push(@{ $form->{nodiscount_linetotal} }, $form->format_amount($myconfig, $nodiscount_linetotal, 2)); + push(@{ $form->{projectnumber} }, $projectnumbers{$form->{"project_id_$i"}}); - @taxaccounts = split / /, $form->{"taxaccounts_$i"}; $taxrate = 0; $taxdiff = 0; @@ -302,8 +339,7 @@ sub invoice_details { while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { if ($form->{groupitems} && $ref->{partsgroup} ne $sameitem) { - map { push(@{ $form->{$_} }, "") } - qw(runningnumber number serialnumber unit qty bin sellprice listprice netprice discount linetotal nodiscount_linetotal); + map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays)); $sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--"; push(@{ $form->{description} }, $sameitem); } @@ -314,8 +350,7 @@ sub invoice_details { $form->format_amount($myconfig, $ref->{qty} * $form->{"qty_$i"} ) . qq| -- $form->{"a_partnumber"}, $form->{"a_description"}|); - map { push(@{ $form->{$_} }, "") } - qw(number unit qty runningnumber serialnumber bin sellprice listprice netprice discount linetotal nodiscount_linetotal); + map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays)); } $sth->finish; @@ -408,7 +443,7 @@ sub customer_details { } # get rest for the customer - my $query = qq|SELECT ct.*, cp.*, ct.notes as customernotes + my $query = qq|SELECT ct.*, cp.*, ct.notes as customernotes, ct.phone AS customerphone, ct.fax AS customerfax, ct.email AS customeremail FROM customer ct LEFT JOIN contacts cp on ct.id = cp.cp_cv_id WHERE ct.id = $form->{customer_id} $contact order by cp.cp_id limit 1|; @@ -704,7 +739,7 @@ sub post_invoice { '$form->{"description_$i"}', '$form->{"longdescription_$i"}', $form->{"qty_$i"}, $form->{"sellprice_$i"}, $fxsellprice, $form->{"discount_$i"}, $allocated, 'f', - '$form->{"unit_$i"}', $deliverydate, | . conv_i($form->{"project_id_$i"}) . qq|, + '$form->{"unit_$i"}', $deliverydate, | . conv_i($form->{"project_id_$i"}, 'NULL') . qq|, '$form->{"serialnumber_$i"}', '$pricegroup_id', '$form->{"ordnumber_$i"}', '$form->{"transdate_$i"}', '$form->{"cusordnumber_$i"}', $baseqty, '$subtotal')|; $dbh->do($query) || $form->dberror($query); @@ -890,11 +925,11 @@ sub post_invoice { $form->{"paid_$i"} *= -1; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, - source, memo, ?) + source, memo, project_id) VALUES ($form->{id}, (SELECT c.id FROM chart c - WHERE c.accno = '$accno', project_id), + WHERE c.accno = '$accno'), $form->{"paid_$i"}, '$form->{"datepaid_$i"}', - '$form->{"source_$i"}', '$form->{"memo_$i"}')|; + '$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|; do_query($form, $dbh, $query, $project_id); # exchangerate difference