X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fic.pl;h=dde593feb69454cebc6beef603f0604dbcbf51f6;hb=cd16e60235994b69cdff63da70f73eb284fdf4a7;hp=bccac308a16fbb2b3cef1ed5a872d78b4a30659f;hpb=d467f40de696218e7cde1b78704c32443fa5b986;p=kivitendo-erp.git diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index bccac308a..dde593feb 100644 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -30,9 +30,12 @@ # Inventory Control module # #====================================================================== -#$locale->text('ea'); + +use POSIX qw(strftime); +use List::Util qw(max); use SL::IC; +use SL::ReportGenerator; #use SL::PE; @@ -43,19 +46,38 @@ use SL::IC; our ($form, $locale, %myconfig, $lxdebug); require "bin/mozilla/io.pl"; +require "bin/mozilla/invoice_io.pl"; require "bin/mozilla/common.pl"; +require "bin/mozilla/reportgenerator.pl"; 1; +# Parserhappy(R): +# type=submit $locale->text('Add Part') +# type=submit $locale->text('Add Service') +# type=submit $locale->text('Add Assembly') +# type=submit $locale->text('Edit Part') +# type=submit $locale->text('Edit Service') +# type=submit $locale->text('Edit Assembly') +# $locale->text('Parts') +# $locale->text('Services') +# $locale->text('Inventory quantity must be zero before you can set this part obsolete!') +# $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!') +# $locale->text('Part Number missing!') +# $locale->text('Service Number missing!') +# $locale->text('Assembly Number missing!') +# $locale->text('ea'); + # end of main sub add { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + $form->{title} = $locale->text('Add ' . ucfirst $form->{item}); - $form->{callback} = - "$form->{script}?action=add&item=$form->{item}&login=$form->{login}&password=$form->{password}" + $form->{callback} = "$form->{script}?action=add&item=$form->{item}" unless $form->{callback}; $form->{"unit_changeable"} = 1; @@ -70,551 +92,55 @@ sub add { sub search { $lxdebug->enter_sub(); - my ($button1, $button2, $onhand, $makemodel, $serialnumber, $l_serialnumber, $toplevel, $bought); - - $form->{title} = (ucfirst $form->{searchitems}) . "s"; - $form->{title} = $locale->text($form->{title}); + $auth->assert('part_service_assembly_edit'); - # switch for backward sorting - $form->{revers} = 0; + $form->{revers} = 0; # switch for backward sorting + $form->{lastsort} = ""; # memory for which table was sort at last time + $form->{ndxs_counter} = 0; # counter for added entries to top100 - # memory for which table was sort at last time - $form->{lastsort} = ""; + my $is_service = $form->{searchitems} eq 'service'; + my $is_assembly = $form->{searchitems} eq 'assembly'; - # counter for added entries to top100 - $form->{ndxs_counter} = 0; - - # $locale->text('Parts') - # $locale->text('Services') + $form->{title} = (ucfirst $form->{searchitems}) . "s"; + $form->{title} = $locale->text($form->{title}); + $form->{title} = $locale->text('Assemblies') if $is_assembly; - # use JavaScript Calendar or not $form->{jsscript} = 1; - my $jsscript = ""; - if ($form->{jsscript}) { - - # with JavaScript Calendar - $button1 = qq| - - text('button') . qq|> - |; - $button2 = qq| - - text('button') . qq|> - |; - - #write Trigger - $jsscript = - Form->write_trigger(\%myconfig, "2", "transdatefrom", "BL", "trigger1", - "transdateto", "BL", "trigger2"); - } else { - - # without JavaScript Calendar - $button1 = qq| - |; - $button2 = qq| - |; - } - - unless ($form->{searchitems} eq 'service') { - - $onhand = qq| -  | - . $locale->text('On Hand') . qq| -  | - . $locale->text('Short') . qq| -|; - - $makemodel = qq| - - | . $locale->text('Make') . qq| - - | . $locale->text('Model') . qq| - - -|; - - $serialnumber = qq| - | . $locale->text('Serial Number') . qq| - -|; - - $l_serialnumber = qq| -  | - . $locale->text('Serial Number') . qq| -|; - - } - - if ($form->{searchitems} eq 'assembly') { - - $form->{title} = $locale->text('Assemblies'); - - $toplevel = qq| - - - -  | - . $locale->text('Top Level') . qq| -  | - . $locale->text('Individual Items') . qq| - - -|; - - $bought = qq| - - - - - - - - - $button1 - - $button2 - -
- - - - - - - - - - - - - - - - - - - -
| . $locale->text('Sold') . qq|

| . $locale->text('Ordered') . qq|

| . $locale->text('Quoted') . qq|
-
 | . $locale->text('From') . qq|| . $locale->text('To (time)') . qq|
- - -|; - - } else { - - $bought = qq| - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
| . $locale->text('Bought') . qq|| . $locale->text('Sold') . qq|

| . $locale->text('On Order') . qq|| . $locale->text('Ordered') . qq|

| . $locale->text('RFQ') . qq|| . $locale->text('Quoted') . qq|
-
  - - - - $button1 - - $button2 - -
| . $locale->text('From') . qq|| . $locale->text('To (time)') . qq|
-
- - -|; - } $form->header; - print qq| - - -
{script}> - -{searchitems}> - - - - - - - - - - - - -
$form->{title}
- - - - - - - - - - - - - - - $serialnumber - - $makemodel - - - - - - - $toplevel - - - - - $bought - - - - - - - - -
| . $locale->text('Part Number') . qq|| . $locale->text('EAN') . qq|
| - . $locale->text('Part Description') . qq|
| . $locale->text('Group') . qq|
| . $locale->text('Drawing') . qq|| . $locale->text('Microfiche') . qq|
-  | - . $locale->text('Active') . qq| - $onhand -  | - . $locale->text('Obsolete') . qq| -  | - . $locale->text('Orphaned') . qq| -
-
-
| - . $locale->text('Include in Report') . qq| - - - - - $l_serialnumber - - - - - - - - - - - - - - - - - - - - - - - - - -
 | - . $locale->text('Part Number') . qq| | - . $locale->text('Part Description') . qq| | - . $locale->text('Unit of measure') . qq|
 | - . $locale->text('List Price') . qq| | - . $locale->text('Sell Price') . qq| | - . $locale->text('Last Cost') . qq| | - . $locale->text('Line Total') . qq|
 | - . $locale->text('Updated') . qq| | - . $locale->text('Bin') . qq| | - . $locale->text('ROP') . qq| | - . $locale->text('Weight') . qq|
 | - . $locale->text('Image') . qq| | - . $locale->text('Drawing') . qq| | - . $locale->text('Microfiche') . qq| | - . $locale->text('Group') . qq|
 | - . $locale->text('Subtotal') . qq| | - . $locale->text('soldtotal') . qq| | - . $locale->text('deliverydate') . qq|
-
-

- -$jsscript - - + print $form->parse_html_template('ic/search', { is_assembly => $is_assembly, + is_service => $is_service, + dateformat => $myconfig{dateformat}, }); -{login}> -{password}> - - - - - - - -
- - -
- - - -|; $lxdebug->leave_sub(); } #end search() sub search_update_prices { $lxdebug->enter_sub(); - my ($onhand, $makemodel, $serialnumber, $l_serialnumber, $toplevel, $bought); - - $form->{title} = $locale->text('Update prices'); - IC->get_pricegroups(\%myconfig, \%$form); - - # use JavaScript Calendar or not -# $form->{jsscript} = 1; -# $jsscript = ""; -# if ($form->{jsscript}) { -# -# # with JavaScript Calendar -# $button1 = qq| -# -# text('button') . qq|> -# |; -# $button2 = qq| -# -# text('button') . qq|> -# |; -# -# #write Trigger -# $jsscript = -# Form->write_trigger(\%myconfig, "2", "transdatefrom", "BL", "trigger1", -# "transdateto", "BL", "trigger2"); -# } else { -# -# # without JavaScript Calendar -# $button1 = qq| -# |; -# $button2 = qq| -# |; -# } - - $onhand = qq| -  | - . $locale->text('On Hand') . qq| -  | - . $locale->text('Short') . qq| -|; - - $makemodel = qq| - - | . $locale->text('Make') . qq| - - | . $locale->text('Model') . qq| - - -|; - - $serialnumber = qq| - | . $locale->text('Serial Number') . qq| - -|; - - $l_serialnumber = qq| -  | - . $locale->text('Serial Number') . qq| -|; - + $auth->assert('part_service_assembly_edit'); + my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form); $form->header; - print qq| - - -
{script}> - - - - - - - - |; + |; if ($j == 1) { print qq| |; @@ -817,9 +295,6 @@ sub list {
-{login}> -{password}> - @@ -881,6 +356,8 @@ sub list { sub top100 { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + if ($form->{ndx}) { $form->{ndxs_counter}++; @@ -902,6 +379,8 @@ sub top100 { sub addtop100 { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + my ($revers, $lastsort, $callback, $option, $description, $sameitem, $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align); my (@column_index, %column_header, %column_data); @@ -909,7 +388,7 @@ sub addtop100 { $form->{top100} = "top100"; $form->{l_soldtotal} = "Y"; - $form->{soldtotal} = "soldtotal"; +# $form->{soldtotal} = "soldtotal"; $form->{sort} = "soldtotal"; $form->{l_qty} = "N"; $form->{l_linetotal} = ""; @@ -931,7 +410,7 @@ sub addtop100 { } #fi $callback = - "$form->{script}?action=top100&login=$form->{login}&password=$form->{password}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title=" + "$form->{script}?action=top100&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title=" . $form->escape($form->{title}, 1); # if we have a serialnumber limit search @@ -1034,16 +513,13 @@ sub addtop100 { } if ($form->{serialnumber}) { $callback .= "&serialnumber=$form->{serialnumber}"; - $option .= - $locale->text('Serial Number') . qq| : $form->{serialnumber}
|; + $option .= $locale->text('Serial Number') . qq| : $form->{serialnumber}
|; } if ($form->{description}) { - $callback .= "&description=$form->{description}"; + $callback .= "&description=$form->{description}"; $description = $form->{description}; - $description =~ s/ -/
/g; - $option .= - $locale->text('Part Description') . qq| : $form->{description}
|; + $description =~ s/\n/
/g; + $option .= $locale->text('Part Description') . qq| : $form->{description}
|; } if ($form->{make}) { $callback .= "&make=$form->{make}"; @@ -1275,8 +751,8 @@ sub addtop100 { } #rof } #fi # build data for columns + my $i = 0; foreach my $ref (@{ $form->{parts} }) { - my $i = 0; if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) { if ($sameitem ne $ref->{ $form->{sort} }) { @@ -1299,8 +775,7 @@ sub addtop100 { $onhand = 0 if ($form->{sold}); } - $ref->{description} =~ s/ -/
/g; + $ref->{description} =~ s/\n/
/g; $column_data{number} = "" + ? "" : ""; $column_data{ordnumber} = ($ref->{module} eq 'oe') - ? "" + ? "" : ""; $column_data{quonumber} = ($ref->{module} eq 'oe' && !$ref->{ordnumber}) - ? "" + ? "" : ""; $column_data{name} = ""; @@ -1442,9 +917,6 @@ sub addtop100 { {script}> -{login}> -{password}> - @@ -1503,18 +975,20 @@ sub addtop100 { # l_partsgroup l_subtotal l_soldtotal l_deliverydate # # hiddens: -# nextsub login password revers lastsort sort ndxs_counter +# nextsub revers lastsort sort ndxs_counter # sub generate_report { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + 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 +1019,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,36 +1060,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); # special case for lastcost $form->{l_lastcost} = "" if $form->{ledgerchecks}; @@ -1625,11 +1085,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 +1118,181 @@ 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||; - $column_header{description} = - qq||; - $column_header{partsgroup} = - qq||; - $column_header{bin} = - qq||; - $column_header{priceupdate} = - qq||; - $column_header{onhand} = - qq||; - $column_header{unit} = - qq||; - $column_header{listprice} = - qq||; - $column_header{lastcost} = - qq||; - $column_header{rop} = - qq||; - $column_header{weight} = - qq||; - - $column_header{invnumber} = - qq||; - $column_header{ordnumber} = - qq||; - $column_header{quonumber} = - qq||; - - $column_header{name} = - qq||; + $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom}); - $column_header{sellprice} = - qq||; - $column_header{linetotalsellprice} = - qq||; - $column_header{linetotallastcost} = - qq||; - $column_header{linetotallistprice} = - qq||; + IC->all_parts(\%myconfig, \%$form); - $column_header{image} = - qq||; - $column_header{drawing} = - qq||; - $column_header{microfiche} = - qq||; + 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||; - $column_header{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||; + 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; -
$form->{title}
- - - - - - - - - - - - - $serialnumber - - $makemodel - - - - - - - $toplevel - - - - - $bought - - - - |; - print qq| - - - - - -
| . $locale->text('Part Number') . qq|
| - . $locale->text('Part Description') . qq|
| . $locale->text('Group') . qq|
| . $locale->text('Drawing') . qq|| . $locale->text('Microfiche') . qq|
-  | - . $locale->text('Active') . qq| - $onhand -  | - . $locale->text('Obsolete') . qq| -  | - . $locale->text('Orphaned') . qq| -
-
-
- - - - - - - - - - - - - - - - -|; - for my $i (1 .. $form->{price_rows}) { - print qq| - - - - - - -|; - } - - print qq| -
| . $locale->text('Preisklasse') . qq|| . $locale->text('Preis') . qq|| . $locale->text('Prozentual/Absolut') . qq|
| . $locale->text('Sell Price') . qq|/
| . $locale->text('List Price') . qq|/
$form->{"pricegroup_$i"}/
-

- -{price_rows}> - -{login}> -{password}> - -
- - + print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups }); - - -|; $lxdebug->leave_sub(); } #end search() sub confirm_price_update { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); $form->{nextsub} = "update_prices"; $form->header; - print qq| - - -
{script}> -|; - - # delete action variable map { delete $form->{$_} } qw(action header); - - foreach my $key (keys %$form) { - $form->{$key} =~ s/\"/"/g; - print qq|\n|; - } - - print qq| -

| . $locale->text('Confirm!') . qq|

- -

| - . $locale->text('Are you sure you want to update the prices') -. qq|

- -

- -

-|; + + print $form->parse_html_template('ic/confirm_price_update', { HIDDENS => [ map { name => $_, value => $form->{$_} }, keys %$form ] }); $lxdebug->leave_sub(); } @@ -622,6 +148,8 @@ sub confirm_price_update { sub update_prices { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + if (IC->update_prices(\%myconfig, \%$form)) { $form->redirect($form->{update_count} . $locale->text('prices updated!')); } else { @@ -634,6 +162,8 @@ sub update_prices { sub choice { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + our ($j, $lastndx); my ($totop100); @@ -641,122 +171,70 @@ sub choice { $form->header; - print qq| - - -
{script}> - - {searchitems}> - - - - |; - - print qq| - - - - - - - - - -
| . $locale->text('Part Number') . qq|| . $locale->text('Part Description') . qq|
-
|; - - print qq| - -{login}> -{password}> - - - - - - - - - - - - - - - - - - - - - - - - - -{ndxs_counter}> - -{extras}>|; + push @custom_hiddens, qw(searchitems title bom titel revers lastsort sort ndxs_counter extras); + push @custom_hiddens, qw(itemstatus l_linetotal l_partnumber l_description l_onhand l_unit l_sellprice l_linetotalsellprice); + my @HIDDENS = ( + +{ name => 'row', value => $j }, + +{ name => 'nextsub', value => 'item_selected' }, + +{ name => 'test', value => 'item_selected' }, + +{ name => 'lastndx', value => $lastndx }, + map(+{ name => $_, value => $form->{$_} }, @custom_hiddens), + ); my ($partnumber, $description, $unit, $sellprice, $soldtotal); # if choice set data - if ($form->{ndx}) { - for (my $i = 0; $i < $form->{ndxs_counter}; $i++) { - - # prepeare data - $partnumber = $form->{"totop100_partnumber_$j"}; - $description = $form->{"totop100_description_$j"}; - $unit = $form->{"totop100_unit_$j"}; - $sellprice = $form->{"totop100_sellprice_$j"}; - $soldtotal = $form->{"totop100_soldtotal_$j"}; - - # insert data into top100 - push @{ $form->{parts} }, - { number => "", - partnumber => "$partnumber", - description => "$description", - unit => "$unit", - sellprice => "$sellprice", - soldtotal => "$soldtotal" }; - } #rof - } #fi +# if ($form->{ndx}) { +# for my $i (0 .. $form->{ndxs_counter}) { +# +# # insert data into top100 +# push @{ $form->{parts} }, +# { number => "", +# partnumber => $form->{"totop100_partnumber_$j"}, +# description => $form->{"totop100_description_$j"}, +# unit => $form->{"totop100_unit_$j"}, +# sellprice => $form->{"totop100_sellprice_$j"}, +# soldtotal => $form->{"totop100_soldtotal_$j"}, +# }; +# } #rof +# } #fi $totop100 = ""; # set data for next page - if (($form->{ndxs_counter}) > 0) { - for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) { - $partnumber = $form->{"totop100_partnumber_$i"}; - $description = $form->{"totop100_description_$i"}; - $unit = $form->{"totop100_unit_$i"}; - $sellprice = $form->{"totop100_sellprice_$i"}; - $soldtotal = $form->{"totop100_soldtotal_$i"}; - - $totop100 .= qq| -{"totop100_partnumber_$i"}> -{"totop100_description_$i"}> -{"totop100_unit_$i"}> -{"totop100_sellprice_$i"}> -{"totop100_soldtotal_$i"}> - |; - } #rof - } #fi - - print $totop100; + for my $i (1 .. $form->{ndxs_counter}) { + $partnumber = $form->{"totop100_partnumber_$i"}; + $description = $form->{"totop100_description_$i"}; + $unit = $form->{"totop100_unit_$i"}; + $sellprice = $form->{"totop100_sellprice_$i"}; + $soldtotal = $form->{"totop100_soldtotal_$i"}; + + push @PARTS, { + totop100_partnumber => $form->{"totop100_partnumber_$i"}, + totop100_description => $form->{"totop100_description_$i"}, + totop100_unit => $form->{"totop100_unit_$i"}, + totop100_sellprice => $form->{"totop100_sellprice_$i"}, + totop100_soldtotal => $form->{"totop100_soldtotal_$i"}, + } + +# $totop100 .= qq| +#{"totop100_partnumber_$i"}> +#{"totop100_description_$i"}> +#{"totop100_unit_$i"}> +#{"totop100_sellprice_$i"}> +#{"totop100_soldtotal_$i"}> +# |; + } #rof + + print $form->parse_html_template('ic/choice', +{ HIDDENS => \@HIDDENS, PARTS => \@PARTS }); - print qq| - -
- - - |; $lxdebug->leave_sub(); } #end choice sub list { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + our ($lastndx); our ($partnumber, $description, $unit, $sellprice, $soldtotal); @@ -791,7 +269,7 @@ sub list { for ($j = 1; $j <= $i; $j++) { print qq| -
" @@ -1362,15 +837,15 @@ sub addtop100 { $column_data{invnumber} = ($ref->{module} ne 'oe') - ? "{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&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}{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&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}{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{quonumber}$ref->{quonumber}$ref->{name}
{revers}&lastsort=$form->{lastsort}>| - . $locale->text('Part Number') - . qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('Part Description') - . qq|| - . $locale->text('Group') - . qq|| - . $locale->text('Bin') - . qq|| - . $locale->text('Updated') - . qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('Qty') - . qq|| . $locale->text('Unit') . qq|| - . $locale->text('List Price') - . qq|| . $locale->text('Last Cost') . qq|| . $locale->text('ROP') . qq|| . $locale->text('Weight') . qq|| - . $locale->text('Invoice Number') - . qq|| - . $locale->text('Order Number') - . qq|| - . $locale->text('Quotation') - . qq|| - . $locale->text('Name') - . qq|| - . $locale->text('Sell Price') - . qq|| . $locale->text('Extended') . qq|| . $locale->text('Extended') . qq|| . $locale->text('Extended') . qq|| . $locale->text('Image') . qq|| - . $locale->text('Drawing') - . qq|| - . $locale->text('Microfiche') - . qq|| - . $locale->text('Serial Number') - . qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('soldtotal') - . qq|{revers}&lastsort=$form->{lastsort}>| - . $locale->text('deliverydate') - . qq|
- - - - + # 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_template('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; + 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{partnumber} = - ""; - $column_data{description} = ""; - $column_data{partsgroup} = ""; - - $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 { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns; - map { print "\n$column_data{$_}" } @column_index; - - 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 @@ -1994,6 +1300,8 @@ sub generate_report { sub parts_subtotal { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + # imports our (%column_data, @column_index); our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice); @@ -2037,6 +1345,9 @@ sub parts_subtotal { sub edit { $lxdebug->enter_sub(); + + $auth->assert('part_service_assembly_edit'); + # show history button $form->{javascript} = qq||; #/show hhistory button @@ -2055,6 +1366,8 @@ sub edit { sub link_part { $lxdebug->enter_sub(); + $auth->assert('part_service_assembly_edit'); + IC->create_links("IC", \%myconfig, \%$form); # currencies @@ -2074,7 +1387,7 @@ sub link_part { # if this is a tax field if ($key =~ /IC_tax/) { - if ($key =~ /$item/) { + if ($key =~ /\Q$item\E/) { $form->{taxaccounts} .= "$ref->{accno} "; $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}"; @@ -2116,10 +1429,7 @@ sub link_part { if (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} = qq||; - foreach my $item (@{ $form->{payment_terms} }) { - if ($form->{payment_id} eq $item->{id}) { - $payment .= qq||; - } else { - $payment .= qq||; - } - } - + $auth->assert('part_service_assembly_edit'); - if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) { - $rows = 4; - } - - $notes = - qq||; - if (($rows = $form->numtextrows($form->{description}, 40)) > 1) { - $description = - qq||; - } else { - $description = - qq||; - } + $form->{eur} = $eur; # config dumps into namespace - yuck + $form->{pg_keys} = sub { "$_[0]->{partsgroup}--$_[0]->{id}" }; + $form->{description_area} = ($form->{rows} = $form->numtextrows($form->{description}, 40)) > 1; + $form->{notes_rows} = max 4, $form->numtextrows($form->{notes}, 40), $form->numtextrows($form->{formel}, 40); - $ean = qq||; - - foreach my $item (split / /, $form->{taxaccounts}) { - $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : ""; - } + map { $form->{"is_$_"} = ($form->{item} eq $_) } qw(part service assembly); + map { $form->{$_} =~ s/"/"/g; } qw(unit); + + $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS', + 'partsgroup' => 'all_partsgroup'); IC->retrieve_buchungsgruppen(\%myconfig, $form); - if (@{ $form->{BUCHUNGSGRUPPEN} }) { - foreach my $item (@{ $form->{BUCHUNGSGRUPPEN} }) { - if ($item->{id} == $form->{buchungsgruppen_id}) { - $form->{selectbuchungsgruppe} .= - "