X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fic.pl;h=28d41f3b3928c0aaac41a001517a5b4fe21ca44f;hb=b6133a726fa261cb97f2c105ea4a93161609d6ca;hp=4830cc49d55d77fa05c401a85fd12e55a8ff15bc;hpb=9a0aeac2e700a10e3ba54653f0b0db127edc21df;p=kivitendo-erp.git diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index 4830cc49d..28d41f3b3 100644 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -32,11 +32,14 @@ #====================================================================== #$locale->text('ea'); +use POSIX qw(strftime); + use SL::IC; +use SL::ReportGenerator; #use SL::PE; -use strict; +# use strict; #use warnings; # global imports @@ -44,6 +47,7 @@ our ($form, $locale, %myconfig, $lxdebug); require "bin/mozilla/io.pl"; require "bin/mozilla/common.pl"; +require "bin/mozilla/reportgenerator.pl"; 1; @@ -1509,12 +1513,12 @@ sub generate_report { $lxdebug->enter_sub(); my ($revers, $lastsort, $description); - my (@column_index, %column_header, %column_data, @columns, @options, @callbacks); - my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice); - my ($colspan, $sameitem, $onhand, $align); - $revers = $form->{revers}; - $lastsort = $form->{lastsort}; + $form->{title} = (ucfirst $form->{searchitems}) . "s"; + $form->{title} = $locale->text($form->{title}); + + my $revers = $form->{revers}; + my $lastsort = $form->{lastsort}; # sorting and direction of sorting # ToDO: change this to the simpler field+direction method @@ -1545,7 +1549,7 @@ sub generate_report { $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered} || $form->{rfq} || $form->{quoted}); - # if something should be aktivated if something else is active, enter it here + # if something should be activated if something else is active, enter it here my %dependencies = ( onhand => [ qw(l_onhand) ], short => [ qw(l_onhand) ], @@ -1586,34 +1590,22 @@ sub generate_report { l_soldtotal => $locale->text('soldtotal'), ); - # this local subfunction generates a callback token from the input key. - # easy to join into a callback later - sub callback_token { - map { /\w+$/; return "&$&=$form->{$&}" } @_; - } - my @itemstatus_keys = qw(active obsolete orphaned onhand short); - my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model - drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto); - my $callback = "$form->{script}?action=generate_report"; - map { $callback .= "&$_=" . $form->escape($form->{$_}) } qw(login password searchitems itemstatus bom l_linetotal title); - + my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model + drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean); + # calculate dependencies - for (@itemstatus_keys, @callback_keys) { + for (@itemstatus_keys, @callback_keys) { next if ($form->{itemstatus} ne $_ && !$form->{$_}); map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_}; } # generate callback and optionstrings + my @options; for my $key (@itemstatus_keys, @callback_keys) { next if ($form->{itemstatus} ne $key && !$form->{$key}); push @options, $optiontexts{$key}; - push @callbacks, callback_token($key) if grep { $_ eq $key } @callback_keys;; } - my $option = $locale->text('Options') . ': ' . join(', ', grep $_, @options) . '
'; - $callback .= join '', grep $_, @callbacks; - - $lxdebug->message(0, $callback); IC->all_parts(\%myconfig, \%$form); @@ -1625,11 +1617,6 @@ sub generate_report { $description =~ s/\n/
/g; } - @columns = $form->sort_columns( - qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice - lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate) - ); - if ($form->{l_linetotal}) { $form->{l_onhand} = "Y"; $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice}; @@ -1663,330 +1650,179 @@ sub generate_report { } } - $form->{l_lastcost} = "" - if ($form->{searchitems} eq 'assembly' && !$form->{bom}); - - foreach my $item (@columns) { - if ($form->{"l_$item"} eq "Y") { - push @column_index, $item; - - # add column to callback - $callback .= "&l_$item=Y"; - } - } - - if ($form->{l_subtotal} eq 'Y') { - $callback .= "&l_subtotal=Y"; - } - $column_header{partnumber} = - qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('Part Number') - . qq||; - $column_header{description} = - qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('Part Description') - . qq||; - $column_header{partsgroup} = - qq|| - . $locale->text('Group') - . qq||; - $column_header{bin} = - qq|| - . $locale->text('Bin') - . qq||; - $column_header{priceupdate} = - qq|| - . $locale->text('Updated') - . qq||; - $column_header{onhand} = - qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('Qty') - . qq||; - $column_header{unit} = - qq|| . $locale->text('Unit') . qq||; - $column_header{listprice} = - qq|| - . $locale->text('List Price') - . qq||; - $column_header{lastcost} = - qq|| . $locale->text('Last Cost') . qq||; - $column_header{rop} = - qq|| . $locale->text('ROP') . qq||; - $column_header{weight} = - qq|| . $locale->text('Weight') . qq||; - - $column_header{invnumber} = - qq|| - . $locale->text('Invoice Number') - . qq||; - $column_header{ordnumber} = - qq|| - . $locale->text('Order Number') - . qq||; - $column_header{quonumber} = - qq|| - . $locale->text('Quotation') - . qq||; - - $column_header{name} = - qq|| - . $locale->text('Name') - . qq||; - - $column_header{sellprice} = - qq|| - . $locale->text('Sell Price') - . qq||; - $column_header{linetotalsellprice} = - qq|| . $locale->text('Extended') . qq||; - $column_header{linetotallastcost} = - qq|| . $locale->text('Extended') . qq||; - $column_header{linetotallistprice} = - qq|| . $locale->text('Extended') . qq||; - - $column_header{image} = - qq|| . $locale->text('Image') . qq||; - $column_header{drawing} = - qq|| - . $locale->text('Drawing') - . qq||; - $column_header{microfiche} = - qq|| - . $locale->text('Microfiche') - . qq||; + $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom}); + + my @columns = + qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost + priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate); + + my %column_defs = ( + 'bin' => { 'text' => $locale->text('Bin'), }, + 'deliverydate' => { 'text' => $locale->text('deliverydate'), }, + 'description' => { 'text' => $locale->text('Part Description'), }, + 'drawing' => { 'text' => $locale->text('Drawing'), }, + 'image' => { 'text' => $locale->text('Image'), }, + 'invnumber' => { 'text' => $locale->text('Invoice Number'), }, + 'lastcost' => { 'text' => $locale->text('Last Cost'), }, + 'linetotallastcost' => { 'text' => $locale->text('Extended'), }, + 'linetotallistprice' => { 'text' => $locale->text('Extended'), }, + 'linetotalsellprice' => { 'text' => $locale->text('Extended'), }, + 'listprice' => { 'text' => $locale->text('List Price'), }, + 'microfiche' => { 'text' => $locale->text('Microfiche'), }, + 'name' => { 'text' => $locale->text('Name'), }, + 'onhand' => { 'text' => $locale->text('Qty'), }, + 'ordnumber' => { 'text' => $locale->text('Order Number'), }, + 'partnumber' => { 'text' => $locale->text('Part Number'), }, + 'partsgroup' => { 'text' => $locale->text('Group'), }, + 'priceupdate' => { 'text' => $locale->text('Updated'), }, + 'quonumber' => { 'text' => $locale->text('Quotation'), }, + 'rop' => { 'text' => $locale->text('ROP'), }, + 'sellprice' => { 'text' => $locale->text('Sell Price'), }, + 'serialnumber' => { 'text' => $locale->text('Serial Number'), }, + 'soldtotal' => { 'text' => $locale->text('soldtotal'), }, + 'unit' => { 'text' => $locale->text('Unit'), }, + 'weight' => { 'text' => $locale->text('Weight'), }, + ); - $column_header{serialnumber} = - qq|| - . $locale->text('Serial Number') - . qq||; - $column_header{soldtotal} = - qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('soldtotal') - . qq||; + map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns; + map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal); - $column_header{deliverydate} = - qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('deliverydate') - . qq||; + my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns); + my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables); - $form->header; - $colspan = $#column_index + 1; + my @sort_full = qw(partnumber description onhand soldtotal deliverydate); + my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber); - print qq| - + foreach my $col (@sort_full) { + $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort); + } + map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers; - - - - - + # add order to callback + $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers)); - + my $report = SL::ReportGenerator->new(\%myconfig, $form); - -|; + my %attachment_basenames = ( + 'part' => $locale->text('part_list'), + 'service' => $locale->text('service_list'), + 'assembly' => $locale->text('assembly_list'), + ); - map { print "\n$column_header{$_}" } @column_index; + $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options), + 'raw_bottom_info_text' => $form->parse_html_template2('ic/generate_report_bottom'), + 'output_format' => 'HTML', + 'title' => $form->{title}, + 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time), + ); + $report->set_options_from_form(); - print qq| - - |; + $report->set_columns(%column_defs); + $report->set_column_order(@columns); - # add order to callback - $form->{callback} = $callback .= "&sort=$form->{sort}"; + $report->set_export_options('generate_report', @hidden_variables, qw(sort revers)); - # escape callback for href - $callback = $form->escape($callback); + $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1); - if (@{ $form->{parts} }) { - $sameitem = $form->{parts}->[0]->{ $form->{sort} }; - } + my @subtotal_columns = qw(sellprice listprice lastcost); + my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns); + my %totals = map { $_ => 0 } @subtotal_columns; + my $idx = 0; + my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} }); + # postprocess parts foreach my $ref (@{ $form->{parts} }) { - my $i = 0; - if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) { - if ($sameitem ne $ref->{ $form->{sort} }) { - &parts_subtotal; - $sameitem = $ref->{ $form->{sort} }; - } - } + # fresh row, for inserting later + my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns }; - $ref->{exchangerate} = 1 unless $ref->{exchangerate}; - $ref->{sellprice} *= $ref->{exchangerate}; - $ref->{listprice} *= $ref->{exchangerate}; - $ref->{lastcost} *= $ref->{exchangerate}; + $ref->{exchangerate} ||= 1; + $ref->{price_factor} ||= 1; + $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor}; + $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor}; + $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor}; # use this for assemblies - $onhand = $ref->{onhand}; + my $onhand = $ref->{onhand}; - $align = "left"; if ($ref->{assemblyitem}) { - $align = "right"; - $onhand = 0 if ($form->{sold}); + $row->{partnumber}{align} = 'right'; + $row->{onhand}{data} = 0; + $onhand = 0 if ($form->{sold}); } - $ref->{description} =~ s/ -/
/g; - - $column_data{partnumber} = - ""; - $column_data{description} = ""; - $column_data{partsgroup} = ""; + my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback'); + $row->{partnumber}->{link} = $edit_link; + $row->{description}->{link} = $edit_link; - $column_data{onhand} = - ""; - $column_data{sellprice} = - ""; - $column_data{listprice} = - ""; - $column_data{lastcost} = - ""; + foreach (qw(sellprice listprice lastcost)) { + $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2); + $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2); + } - $column_data{linetotalsellprice} = ""; - $column_data{linetotallastcost} = ""; - $column_data{linetotallistprice} = ""; + map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal); if (!$ref->{assemblyitem}) { - $totalsellprice += $onhand * $ref->{sellprice}; - $totallastcost += $onhand * $ref->{lastcost}; - $totallistprice += $onhand * $ref->{listprice}; + foreach my $col (@subtotal_columns) { + $totals{$col} += $onhand * $ref->{$col}; + $subtotals{$col} += $onhand * $ref->{$col}; + } - $subtotalonhand += $onhand; - $subtotalsellprice += $onhand * $ref->{sellprice}; - $subtotallastcost += $onhand * $ref->{lastcost}; - $subtotallistprice += $onhand * $ref->{listprice}; + $subtotals{onhand} += $onhand; } - $column_data{rop} = - ""; - $column_data{weight} = - ""; - $column_data{unit} = ""; - $column_data{bin} = ""; - $column_data{priceupdate} = ""; - - $column_data{invnumber} = - ($ref->{module} ne 'oe') - ? "" - : ""; - $column_data{ordnumber} = - ($ref->{module} eq 'oe') - ? "" - : ""; - $column_data{quonumber} = - ($ref->{module} eq 'oe' && !$ref->{ordnumber}) - ? "" - : ""; + # set module stuff + if ($ref->{module} eq 'oe') { + my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback'); + $row->{ordnumber}{link} = $edit_oe_link; + $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber}); - $column_data{name} = ""; + } else { + $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback'); + } - $column_data{image} = - ($ref->{image}) - ? "" - : ""; - $column_data{drawing} = - ($ref->{drawing}) - ? "" - : ""; - $column_data{microfiche} = - ($ref->{microfiche}) - ? "" - : ""; + # set properties of images + if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) { + $row->{image}{data} = ''; + $row->{image}{raw_data} = ''; + } + map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche); - $column_data{serialnumber} = ""; + $report->add_data($row); - $column_data{soldtotal} = - ""; + my $next_ref = $form->{parts}[$idx + 1]; - $column_data{deliverydate} = ""; + # insert subtotal rows + if (($form->{l_subtotal} eq 'Y') && + (!$next_ref || + (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) { + my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns }; - $i++; - $i %= 2; - print ""; + if (($form->{searchitems} ne 'assembly') || !$form->{bom}) { + $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand}); + } - map { print "\n$column_data{$_}" } @column_index; + map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns; + map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns); - print qq| - -|; + $report->add_data($row); - } + $same_item = $next_ref->{ $form->{sort} }; + } - if ($form->{l_subtotal} eq 'Y') { - &parts_subtotal; + $idx++; } if ($form->{"l_linetotal"}) { - map { $column_data{$_} = "" } @column_index; - $column_data{linetotalsellprice} = - ""; - $column_data{linetotallastcost} = - ""; - $column_data{linetotallistprice} = - ""; + my $row = { map { $_ => { 'class' => 'listtotal', } } @columns }; - print ""; - - map { print "\n$column_data{$_}" } @column_index; + map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns; - print qq| - |; + $report->add_separator(); + $report->add_data($row); } - print qq| - -
$form->{title}
$option
{script}?action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partnumber} {script}?action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description} $ref->{partsgroup} " - . $form->format_amount(\%myconfig, $ref->{onhand}) - . "" - . $form->format_amount(\%myconfig, $ref->{sellprice}, -2) - . "" - . $form->format_amount(\%myconfig, $ref->{listprice}, -2) - . "" - . $form->format_amount(\%myconfig, $ref->{lastcost}, -2) - . "" - . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2) - . "" - . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2) - . "" - . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2) - . "" - . $form->format_amount(\%myconfig, $ref->{rop}) . "" - . $form->format_amount(\%myconfig, $ref->{weight}) - . "$ref->{unit} $ref->{bin} $ref->{priceupdate} {module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}$ref->{invnumber}{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}$ref->{ordnumber}{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}$ref->{quonumber}$ref->{name}{image}>{image} height=32 border=0> {drawing}>$ref->{drawing} {microfiche}>$ref->{microfiche} $ref->{serialnumber}" - . $form->format_amount(\%myconfig, $ref->{soldtotal}) - . "$ref->{deliverydate}
 " - . $form->format_amount(\%myconfig, $totalsellprice, 2) - . "" - . $form->format_amount(\%myconfig, $totallastcost, 2) - . "" - . $form->format_amount(\%myconfig, $totallistprice, 2) - . "

- -|; - - print qq| - -
- -
{script}> - - - -{searchitems}> - -{login}> -{password}>|; - - print qq| - - -
- - - -|; + $report->generate_with_headers(); $lxdebug->leave_sub(); } #end generate_report @@ -2149,8 +1985,9 @@ sub form_header { my ($payment, $rows, $notes, $description, $ean, $buchungsgruppe, $partsgroup, $group, $tax, $lastcost, $eur, $linkaccounts, $weight, $n, $rop, $bin, $vegv); my ($notdiscountableok, $notdiscountable); - my ($formel, $imagelinks, $obsolete, $shopok, $shop); + my ($formula, $formula_label, $imagelinks, $obsolete, $shopok, $shop); + $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS'); map({ $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, -2) } qw(sellprice listprice lastcost gv)); @@ -2409,8 +2246,11 @@ sub form_header { |; - $formel = - qq||; + $formula = + qq||; + + $formula_label = $locale->text('Formula'); + $imagelinks = qq| @@ -2488,6 +2328,22 @@ sub form_header { $unit_select .= AM->unit_select_html($units, "unit", $form->{"unit"}); } + my $price_factor; + if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) { + my @values = ('', map { $_->{id} } @{ $form->{ALL_PRICE_FACTORS} }); + my %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} }; + + $price_factor = + qq|| + . $locale->text('Price Factor') + . qq|| + . NTI($cgi->popup_menu('-name' => 'price_factor_id', + '-default' => $form->{price_factor_id}, + '-values' => \@values, + '-labels' => \%labels)) + . qq||; + } + $form->{fokus} = "ic.partnumber"; $form->header; @@ -2551,14 +2407,14 @@ sub form_header { | . $locale->text('Notes') . qq| - | . $locale->text('Formula') . qq| + $formula_label $notes - $formel + $formula @@ -2601,6 +2457,7 @@ sub form_header { {sellprice}> $lastcost + $price_factor | . $locale->text('Unit') . qq| $unit_select @@ -2983,20 +2840,11 @@ sub update { } } - } - if ($form->{item} eq "part") { + } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) { &check_form; } - if ($form->{item} eq 'service') { - map({ $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } - qw(sellprice listprice lastcost)); - &form_header; - &price_row; - &form_footer; - } - $lxdebug->leave_sub(); } @@ -3063,7 +2911,7 @@ sub save { # now take it apart and restore original values foreach my $item (split /&/, $previousform) { - my ($key, $value) = split /=/, $item, 2; + my ($key, $value) = split m/=/, $item, 2; $value =~ s/%26/&/g; $form->{$key} = $value; } @@ -3083,8 +2931,7 @@ sub save { $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"}; # change/add values for assembly item - map { $form->{"${_}_$i"} = $newform{$_} } - qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno); + map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id); $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"}; $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"}; @@ -3095,15 +2942,17 @@ sub save { $i = $form->{rowcount}; $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); - map { $form->{"${_}_$i"} = $newform{$_} } - qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice); + map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id); + $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id}); + if ($form->{exchangerate} != 0) { $form->{"sellprice_$i"} /= $form->{exchangerate}; } + $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|); - map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, - $newform{taxaccount}; + + map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount}; chop $form->{"taxaccounts_$i"}; foreach my $item (qw(description rate taxnumber)) { my $index = $form->{"taxaccounts_$i"} . "_$item"; @@ -3111,26 +2960,28 @@ sub save { } # credit remaining calculation - $amount = - $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * - $form->{"qty_$i"}; - map { $form->{"${_}_base"} += $amount } - (split / /, $form->{"taxaccounts_$i"}); - map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } - split / /, $form->{"taxaccounts_$i"} - if !$form->{taxincluded}; + $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"}; + + map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"}); + map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded}; $form->{creditremaining} -= $amount; # redo number formatting, because invoice parse them! - $i = $form->{rowcount}; - map { - $form->{"${_}_$i"} = - $form->format_amount(\%myconfig, $form->{"${_}_$i"}) - } qw(weight listprice sellprice rop); + map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop); } $form->{"id_$i"} = $parts_id; + + # Get the actual price factor (not just the ID) for the marge calculation. + $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS'); + foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) { + next if ($pfac->{id} != $newform{price_factor_id}); + $form->{"marge_price_factor_$i"} = $pfac->{factor}; + last; + } + delete $form->{ALL_PRICE_FACTORS}; + delete $form->{action}; # restore original callback