1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # Inventory Control module
32 #======================================================================
34 use POSIX qw(strftime);
35 use List::Util qw(max);
38 use SL::ReportGenerator;
46 our ($form, $locale, %myconfig, $lxdebug);
48 require "bin/mozilla/io.pl";
49 require "bin/mozilla/invoice_io.pl";
50 require "bin/mozilla/common.pl";
51 require "bin/mozilla/reportgenerator.pl";
56 # type=submit $locale->text('Add Part')
57 # type=submit $locale->text('Add Service')
58 # type=submit $locale->text('Add Assembly')
59 # type=submit $locale->text('Edit Part')
60 # type=submit $locale->text('Edit Service')
61 # type=submit $locale->text('Edit Assembly')
62 # $locale->text('Parts')
63 # $locale->text('Services')
64 # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
65 # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
66 # $locale->text('Part Number missing!')
67 # $locale->text('Service Number missing!')
68 # $locale->text('Assembly Number missing!')
69 # $locale->text('ea');
74 $lxdebug->enter_sub();
76 $auth->assert('part_service_assembly_edit');
78 $form->{title} = $locale->text('Add ' . ucfirst $form->{item});
80 $form->{callback} = "$form->{script}?action=add&item=$form->{item}"
81 unless $form->{callback};
83 $form->{"unit_changeable"} = 1;
85 IC->get_pricegroups(\%myconfig, \%$form);
89 $lxdebug->leave_sub();
93 $lxdebug->enter_sub();
95 $auth->assert('part_service_assembly_edit');
97 $form->{revers} = 0; # switch for backward sorting
98 $form->{lastsort} = ""; # memory for which table was sort at last time
99 $form->{ndxs_counter} = 0; # counter for added entries to top100
101 my $is_service = $form->{searchitems} eq 'service';
102 my $is_assembly = $form->{searchitems} eq 'assembly';
104 $form->{title} = (ucfirst $form->{searchitems}) . "s";
105 $form->{title} = $locale->text($form->{title});
106 $form->{title} = $locale->text('Assemblies') if $is_assembly;
108 $form->{jsscript} = 1;
112 print $form->parse_html_template('ic/search', { is_assembly => $is_assembly,
113 is_service => $is_service,
114 dateformat => $myconfig{dateformat}, });
116 $lxdebug->leave_sub();
119 sub search_update_prices {
120 $lxdebug->enter_sub();
122 $auth->assert('part_service_assembly_edit');
124 my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form);
128 print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups });
130 $lxdebug->leave_sub();
133 sub confirm_price_update {
134 $lxdebug->enter_sub();
136 $auth->assert('part_service_assembly_edit');
138 $form->{nextsub} = "update_prices";
141 map { delete $form->{$_} } qw(action header);
143 print $form->parse_html_template('ic/confirm_price_update', { HIDDENS => [ map { name => $_, value => $form->{$_} }, keys %$form ] });
145 $lxdebug->leave_sub();
149 $lxdebug->enter_sub();
151 $auth->assert('part_service_assembly_edit');
153 if (IC->update_prices(\%myconfig, \%$form)) {
154 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
156 $form->error($locale->text('Could not update prices!'));
159 $lxdebug->leave_sub();
163 $lxdebug->enter_sub();
165 $auth->assert('part_service_assembly_edit');
170 $form->{title} = $locale->text('Top 100 hinzufuegen');
174 push @custom_hiddens, qw(searchitems title bom titel revers lastsort sort ndxs_counter extras);
175 push @custom_hiddens, qw(itemstatus l_linetotal l_partnumber l_description l_onhand l_unit l_sellprice l_linetotalsellprice);
177 +{ name => 'row', value => $j },
178 +{ name => 'nextsub', value => 'item_selected' },
179 +{ name => 'test', value => 'item_selected' },
180 +{ name => 'lastndx', value => $lastndx },
181 map(+{ name => $_, value => $form->{$_} }, @custom_hiddens),
184 my ($partnumber, $description, $unit, $sellprice, $soldtotal);
186 # if ($form->{ndx}) {
187 # for my $i (0 .. $form->{ndxs_counter}) {
189 # # insert data into top100
190 # push @{ $form->{parts} },
192 # partnumber => $form->{"totop100_partnumber_$j"},
193 # description => $form->{"totop100_description_$j"},
194 # unit => $form->{"totop100_unit_$j"},
195 # sellprice => $form->{"totop100_sellprice_$j"},
196 # soldtotal => $form->{"totop100_soldtotal_$j"},
203 # set data for next page
204 for my $i (1 .. $form->{ndxs_counter}) {
205 $partnumber = $form->{"totop100_partnumber_$i"};
206 $description = $form->{"totop100_description_$i"};
207 $unit = $form->{"totop100_unit_$i"};
208 $sellprice = $form->{"totop100_sellprice_$i"};
209 $soldtotal = $form->{"totop100_soldtotal_$i"};
212 totop100_partnumber => $form->{"totop100_partnumber_$i"},
213 totop100_description => $form->{"totop100_description_$i"},
214 totop100_unit => $form->{"totop100_unit_$i"},
215 totop100_sellprice => $form->{"totop100_sellprice_$i"},
216 totop100_soldtotal => $form->{"totop100_soldtotal_$i"},
220 #<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
221 #<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
222 #<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
223 #<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
224 #<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
228 print $form->parse_html_template('ic/choice', +{ HIDDENS => \@HIDDENS, PARTS => \@PARTS });
230 $lxdebug->leave_sub();
234 $lxdebug->enter_sub();
236 $auth->assert('part_service_assembly_edit');
239 our ($partnumber, $description, $unit, $sellprice, $soldtotal);
241 my @sortorders = ("", "partnumber", "description", "all");
242 my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
243 IC->get_parts(\%myconfig, \%$form, $sortorder);
245 $form->{title} = $locale->text('Top 100 hinzufuegen');
251 <form method=post action=ic.pl>
254 <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
257 <tr class=listheading>
259 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
260 <th class=listheading>| . $locale->text('Part Description') . qq|</th>
261 <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
262 <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
263 <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
267 my $i = $form->{rows};
269 for ($j = 1; $j <= $i; $j++) {
272 <tr class=listrow| . ($j % 2) . qq|>|;
275 <td><input name=ndx class=radio type=radio value=$j checked></td>|;
278 <td><input name=ndx class=radio type=radio value=$j></td>|;
281 <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
282 <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
283 <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
284 <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
285 <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
288 <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
298 <input type=hidden name=itemstatus value="$form->{itemstatus}">
299 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
300 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
301 <input type=hidden name=l_description value="$form->{l_description}">
302 <input type=hidden name=l_onhand value="$form->{l_onhand}">
303 <input type=hidden name=l_unit value="$form->{l_unit}">
304 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
305 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
306 <input type=hidden name=sort value="$form->{sort}">
307 <input type=hidden name=revers value="$form->{revers}">
308 <input type=hidden name=lastsort value="$form->{lastsort}">
310 <input type=hidden name=bom value="$form->{bom}">
311 <input type=hidden name=titel value="$form->{titel}">
312 <input type=hidden name=searchitems value="$form->{searchitems}">
314 <input type=hidden name=row value=$j>
316 <input type=hidden name=nextsub value=item_selected>
318 <input name=lastndx type=hidden value=$lastndx>
320 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
324 if (($form->{ndxs_counter}) > 0) {
325 for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
327 $partnumber = $form->{"totop100_partnumber_$i"};
328 $description = $form->{"totop100_description_$i"};
329 $unit = $form->{"totop100_unit_$i"};
330 $sellprice = $form->{"totop100_sellprice_$i"};
331 $soldtotal = $form->{"totop100_soldtotal_$i"};
334 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
335 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
336 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
337 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
338 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
346 <input class=submit type=submit name=action value="|
347 . $locale->text('TOP100') . qq|">
353 $lxdebug->leave_sub();
357 $lxdebug->enter_sub();
359 $auth->assert('part_service_assembly_edit');
362 $form->{ndxs_counter}++;
364 if ($form->{ndxs_counter} > 0) {
366 my $index = $form->{ndx};
368 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
369 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
370 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
371 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
372 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
376 $lxdebug->leave_sub();
380 $lxdebug->enter_sub();
382 $auth->assert('part_service_assembly_edit');
384 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
385 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
386 my (@column_index, %column_header, %column_data);
387 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
389 $form->{top100} = "top100";
390 $form->{l_soldtotal} = "Y";
391 $form->{soldtotal} = "soldtotal";
392 $form->{sort} = "soldtotal";
393 $form->{l_qty} = "N";
394 $form->{l_linetotal} = "";
396 $form->{number} = "position";
397 $form->{l_number} = "Y";
401 $form->{title} = $locale->text('Top 100');
403 $revers = $form->{revers};
404 $lastsort = $form->{lastsort};
406 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
408 $form->{lastsort} = "partnumber";
409 $form->{sort} = "partnumber";
413 "$form->{script}?action=top100&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
414 . $form->escape($form->{title}, 1);
416 # if we have a serialnumber limit search
417 if ($form->{serialnumber} || $form->{l_serialnumber}) {
418 $form->{l_serialnumber} = "Y";
419 unless ( $form->{bought}
422 || $form->{quoted}) {
423 $form->{bought} = $form->{sold} = 1;
426 IC->all_parts(\%myconfig, \%$form);
428 if ($form->{itemstatus} eq 'active') {
429 $option .= $locale->text('Active') . " : ";
431 if ($form->{itemstatus} eq 'obsolete') {
432 $option .= $locale->text('Obsolete') . " : ";
434 if ($form->{itemstatus} eq 'orphaned') {
435 $option .= $locale->text('Orphaned') . " : ";
437 if ($form->{itemstatus} eq 'onhand') {
438 $option .= $locale->text('On Hand') . " : ";
439 $form->{l_onhand} = "Y";
441 if ($form->{itemstatus} eq 'short') {
442 $option .= $locale->text('Short') . " : ";
443 $form->{l_onhand} = "Y";
445 if ($form->{onorder}) {
446 $form->{l_ordnumber} = "Y";
447 $callback .= "&onorder=$form->{onorder}";
448 $option .= $locale->text('On Order') . " : ";
450 if ($form->{ordered}) {
451 $form->{l_ordnumber} = "Y";
452 $callback .= "&ordered=$form->{ordered}";
453 $option .= $locale->text('Ordered') . " : ";
456 $form->{l_quonumber} = "Y";
457 $callback .= "&rfq=$form->{rfq}";
458 $option .= $locale->text('RFQ') . " : ";
460 if ($form->{quoted}) {
461 $form->{l_quonumber} = "Y";
462 $callback .= ""ed=$form->{quoted}";
463 $option .= $locale->text('Quoted') . " : ";
465 if ($form->{bought}) {
466 $form->{l_invnumber} = "Y";
467 $callback .= "&bought=$form->{bought}";
468 $option .= $locale->text('Bought') . " : ";
471 $form->{l_invnumber} = "Y";
472 $callback .= "&sold=$form->{sold}";
473 $option .= $locale->text('Sold') . " : ";
480 || $form->{quoted}) {
482 $form->{l_lastcost} = "";
483 $form->{l_name} = "Y";
484 if ($form->{transdatefrom}) {
485 $callback .= "&transdatefrom=$form->{transdatefrom}";
487 . $locale->text('From')
489 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
491 if ($form->{transdateto}) {
492 $callback .= "&transdateto=$form->{transdateto}";
494 . $locale->text('To')
496 . $locale->date(\%myconfig, $form->{transdateto}, 1);
502 if ($form->{partnumber}) {
503 $callback .= "&partnumber=$form->{partnumber}";
504 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
507 $callback .= "&partnumber=$form->{ean}";
508 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
510 if ($form->{partsgroup}) {
511 $callback .= "&partsgroup=$form->{partsgroup}";
512 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
514 if ($form->{serialnumber}) {
515 $callback .= "&serialnumber=$form->{serialnumber}";
516 $option .= $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
518 if ($form->{description}) {
519 $callback .= "&description=$form->{description}";
520 $description = $form->{description};
521 $description =~ s/\n/<br>/g;
522 $option .= $locale->text('Part Description') . qq| : $form->{description}<br>|;
525 $callback .= "&make=$form->{make}";
526 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
528 if ($form->{model}) {
529 $callback .= "&model=$form->{model}";
530 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
532 if ($form->{drawing}) {
533 $callback .= "&drawing=$form->{drawing}";
534 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
536 if ($form->{microfiche}) {
537 $callback .= "µfiche=$form->{microfiche}";
538 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
540 if ($form->{l_soldtotal}) {
541 $callback .= "&soldtotal=$form->{soldtotal}";
542 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
545 my @columns = $form->sort_columns(
546 qw(number partnumber ean description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal)
549 if ($form->{l_linetotal}) {
550 $form->{l_onhand} = "Y";
551 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
552 if ($form->{l_lastcost}) {
553 $form->{l_linetotallastcost} = "Y";
554 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
555 $form->{l_linetotallastcost} = "";
558 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
561 if ($form->{searchitems} eq 'service') {
563 # remove bin, weight and rop from list
564 map { $form->{"l_$_"} = "" } qw(bin weight rop);
566 $form->{l_onhand} = "";
568 # qty is irrelevant unless bought or sold
574 || $form->{quoted}) {
575 $form->{l_onhand} = "Y";
577 $form->{l_linetotalsellprice} = "";
578 $form->{l_linetotallastcost} = "";
582 $form->{l_lastcost} = ""
583 if ($form->{searchitems} eq 'assembly' && !$form->{bom});
585 foreach my $item (@columns) {
586 if ($form->{"l_$item"} eq "Y") {
587 push @column_index, $item;
589 # add column to callback
590 $callback .= "&l_$item=Y";
594 if ($form->{l_subtotal} eq 'Y') {
595 $callback .= "&l_subtotal=Y";
598 $column_header{number} =
599 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
600 $column_header{partnumber} =
601 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
602 . $locale->text('Part Number')
604 $column_header{description} =
605 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
606 . $locale->text('Part Description')
608 $column_header{partsgroup} =
609 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
610 . $locale->text('Group')
612 $column_header{bin} =
613 qq|<th><a class=listheading href=$callback&sort=bin>|
614 . $locale->text('Bin')
616 $column_header{priceupdate} =
617 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
618 . $locale->text('Updated')
620 $column_header{onhand} =
621 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
622 . $locale->text('Qty')
624 $column_header{unit} =
625 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
626 $column_header{listprice} =
627 qq|<th class=listheading nowrap>|
628 . $locale->text('List Price')
630 $column_header{lastcost} =
631 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
632 $column_header{rop} =
633 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
634 $column_header{weight} =
635 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
637 $column_header{invnumber} =
638 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
639 . $locale->text('Invoice Number')
641 $column_header{ordnumber} =
642 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
643 . $locale->text('Order Number')
645 $column_header{quonumber} =
646 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
647 . $locale->text('Quotation')
650 $column_header{name} =
651 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
652 . $locale->text('Name')
655 $column_header{sellprice} =
656 qq|<th class=listheading nowrap>|
657 . $locale->text('Sell Price')
659 $column_header{linetotalsellprice} =
660 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
661 $column_header{linetotallastcost} =
662 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
663 $column_header{linetotallistprice} =
664 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
666 $column_header{image} =
667 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
668 $column_header{drawing} =
669 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
670 . $locale->text('Drawing')
672 $column_header{microfiche} =
673 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
674 . $locale->text('Microfiche')
677 $column_header{serialnumber} =
678 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
679 . $locale->text('Serial Number')
681 $column_header{soldtotal} =
682 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
683 . $locale->text('soldtotal')
687 my $colspan = $#column_index + 1;
694 <th class=listtop colspan=$colspan>$form->{title}</th>
698 <tr><td colspan=$colspan>$option</td></tr>
700 <tr class=listheading>
703 map { print "\n$column_header{$_}" } @column_index;
709 # add order to callback
710 $form->{callback} = $callback .= "&sort=$form->{sort}";
712 # escape callback for href
713 $callback = $form->escape($callback);
715 if (@{ $form->{parts} }) {
716 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
719 # insert numbers for top100
721 foreach my $ref (@{ $form->{parts} }) {
726 # if avaible -> insert choice here
727 if (($form->{ndxs_counter}) > 0) {
728 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
729 $partnumber = $form->{"totop100_partnumber_$i"};
730 $description = $form->{"totop100_description_$i"};
731 $unit = $form->{"totop100_unit_$i"};
732 $sellprice = $form->{"totop100_sellprice_$i"};
733 $soldtotal = $form->{"totop100_soldtotal_$i"};
736 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
737 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
738 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
739 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
740 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
744 push @{ $form->{parts} },
746 partnumber => "$partnumber",
747 description => "$description",
749 sellprice => "$sellprice",
750 soldtotal => "$soldtotal" };
753 # build data for columns
755 foreach my $ref (@{ $form->{parts} }) {
757 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
758 if ($sameitem ne $ref->{ $form->{sort} }) {
760 $sameitem = $ref->{ $form->{sort} };
764 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
765 $ref->{sellprice} *= $ref->{exchangerate};
766 $ref->{listprice} *= $ref->{exchangerate};
767 $ref->{lastcost} *= $ref->{exchangerate};
769 # use this for assemblies
770 $onhand = $ref->{onhand};
773 if ($ref->{assemblyitem}) {
775 $onhand = 0 if ($form->{sold});
778 $ref->{description} =~ s/\n/<br>/g;
780 $column_data{number} =
782 . $form->format_amount(\%myconfig, $ref->{number})
784 $column_data{partnumber} =
785 "<td align=$align>$ref->{partnumber} </a></td>";
786 $column_data{description} = "<td>$ref->{description} </td>";
787 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
789 $column_data{onhand} =
791 . $form->format_amount(\%myconfig, $ref->{onhand})
793 $column_data{sellprice} =
795 . $form->format_amount(\%myconfig, $ref->{sellprice})
797 $column_data{listprice} =
799 . $form->format_amount(\%myconfig, $ref->{listprice})
801 $column_data{lastcost} =
803 . $form->format_amount(\%myconfig, $ref->{lastcost})
806 $column_data{linetotalsellprice} = "<td align=right>"
807 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
809 $column_data{linetotallastcost} = "<td align=right>"
810 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
812 $column_data{linetotallistprice} = "<td align=right>"
813 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
816 if (!$ref->{assemblyitem}) {
817 $totalsellprice += $onhand * $ref->{sellprice};
818 $totallastcost += $onhand * $ref->{lastcost};
819 $totallistprice += $onhand * $ref->{listprice};
821 $subtotalonhand += $onhand;
822 $subtotalsellprice += $onhand * $ref->{sellprice};
823 $subtotallastcost += $onhand * $ref->{lastcost};
824 $subtotallistprice += $onhand * $ref->{listprice};
829 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
830 $column_data{weight} =
832 . $form->format_amount(\%myconfig, $ref->{weight})
834 $column_data{unit} = "<td>$ref->{unit} </td>";
835 $column_data{bin} = "<td>$ref->{bin} </td>";
836 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
838 $column_data{invnumber} =
839 ($ref->{module} ne 'oe')
840 ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&callback=$callback>$ref->{invnumber}</a></td>"
841 : "<td>$ref->{invnumber}</td>";
842 $column_data{ordnumber} =
843 ($ref->{module} eq 'oe')
844 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{ordnumber}</a></td>"
845 : "<td>$ref->{ordnumber}</td>";
846 $column_data{quonumber} =
847 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
848 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{quonumber}</a></td>"
849 : "<td>$ref->{quonumber}</td>";
851 $column_data{name} = "<td>$ref->{name}</td>";
853 $column_data{image} =
855 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
857 $column_data{drawing} =
859 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
861 $column_data{microfiche} =
863 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
866 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
868 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
872 print "<tr class=listrow$i>";
874 map { print "\n$column_data{$_}" } @column_index;
881 if ($form->{l_subtotal} eq 'Y') {
885 if ($form->{"l_linetotal"}) {
886 map { $column_data{$_} = "<td> </td>" } @column_index;
887 $column_data{linetotalsellprice} =
888 "<th class=listtotal align=right>"
889 . $form->format_amount(\%myconfig, $totalsellprice, 2)
891 $column_data{linetotallastcost} =
892 "<th class=listtotal align=right>"
893 . $form->format_amount(\%myconfig, $totallastcost, 2)
895 $column_data{linetotallistprice} =
896 "<th class=listtotal align=right>"
897 . $form->format_amount(\%myconfig, $totallistprice, 2)
900 print "<tr class=listtotal>";
902 map { print "\n$column_data{$_}" } @column_index;
909 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
918 <form method=post action=$form->{script}>
920 <input type=hidden name=itemstatus value="$form->{itemstatus}">
921 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
922 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
923 <input type=hidden name=l_description value="$form->{l_description}">
924 <input type=hidden name=l_onhand value="$form->{l_onhand}">
925 <input type=hidden name=l_unit value="$form->{l_unit}">
926 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
927 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
928 <input type=hidden name=sort value="$form->{sort}">
929 <input type=hidden name=revers value="$form->{revers}">
930 <input type=hidden name=lastsort value="$form->{lastsort}">
931 <input type=hidden name=parts value="$form->{parts}">
933 <input type=hidden name=bom value="$form->{bom}">
934 <input type=hidden name=titel value="$form->{titel}">
935 <input type=hidden name=searchitems value="$form->{searchitems}">|;
940 <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
942 <input class=submit type=submit name=action value="|
943 . $locale->text('choice') . qq|">
951 $lxdebug->leave_sub();
956 # Warning, deep magic ahead.
957 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
959 # flags coming from the form:
961 # searchitems=part revers=0 lastsort=''
964 # partnumber ean description partsgroup serialnumber make model drawing microfiche
965 # transdatefrom transdateto
968 # itemstatus = active | onhand | short | obsolete | orphaned
969 # action = continue | top100
972 # bought sold onorder ordered rfq quoted
973 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
974 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
975 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
978 # nextsub revers lastsort sort ndxs_counter
980 sub generate_report {
981 $lxdebug->enter_sub();
983 $auth->assert('part_service_assembly_edit');
985 my ($revers, $lastsort, $description);
987 $form->{title} = (ucfirst $form->{searchitems}) . "s";
988 $form->{title} =~ s/ys$/ies/;
989 $form->{title} = $locale->text($form->{title});
991 my $revers = $form->{revers};
992 my $lastsort = $form->{lastsort};
994 # sorting and direction of sorting
995 # ToDO: change this to the simpler field+direction method
996 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
998 $form->{lastsort} = "partnumber";
999 $form->{sort} = "partnumber";
1001 if ($form->{lastsort} eq $form->{sort}) {
1002 $form->{revers} = 1 - $form->{revers};
1004 $form->{revers} = 0;
1005 $form->{lastsort} = $form->{sort};
1009 # special case if we have a serialnumber limit search
1010 # serialnumbers are only given in invoices and orders,
1011 # so they can only pop up in bought, sold, rfq, and quoted stuff
1012 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
1013 && !$form->{rfq} && !$form->{quoted}
1014 && ($form->{l_serialnumber} || $form->{serialnumber}));
1016 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1017 # if any of these are ticked the behavior changes slightly for lastcost
1018 # since all those are aggregation checks for the legder tables this is an internal switch
1019 # refered to as ledgerchecks
1020 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1021 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1023 # if something should be activated if something else is active, enter it here
1024 my %dependencies = (
1025 onhand => [ qw(l_onhand) ],
1026 short => [ qw(l_onhand) ],
1027 onorder => [ qw(l_ordnumber) ],
1028 ordered => [ qw(l_ordnumber) ],
1029 rfq => [ qw(l_quonumber) ],
1030 quoted => [ qw(l_quonumber) ],
1031 bought => [ qw(l_invnumber) ],
1032 sold => [ qw(l_invnumber) ],
1033 ledgerchecks => [ qw(l_name) ],
1034 serialnumber => [ qw(l_serialnumber) ],
1035 no_sn_joins => [ qw(bought sold) ],
1038 # these strings get displayed at the top of the results to indicate the user which switches were used
1040 active => $locale->text('Active'),
1041 obsolete => $locale->text('Obsolete'),
1042 orphaned => $locale->text('Orphaned'),
1043 onhand => $locale->text('On Hand'),
1044 short => $locale->text('Short'),
1045 onorder => $locale->text('On Order'),
1046 ordered => $locale->text('Ordered'),
1047 rfq => $locale->text('RFQ'),
1048 quoted => $locale->text('Quoted'),
1049 bought => $locale->text('Bought'),
1050 sold => $locale->text('Sold'),
1051 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1052 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1053 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1054 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1055 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1056 description => $locale->text('Part Description') . ": '$form->{description}'",
1057 make => $locale->text('Make') . ": '$form->{make}'",
1058 model => $locale->text('Model') . ": '$form->{model}'",
1059 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1060 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1061 l_soldtotal => $locale->text('soldtotal'),
1064 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1065 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1066 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1068 # calculate dependencies
1069 for (@itemstatus_keys, @callback_keys) {
1070 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1071 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1074 # generate callback and optionstrings
1076 for my $key (@itemstatus_keys, @callback_keys) {
1077 next if ($form->{itemstatus} ne $key && !$form->{$key});
1078 push @options, $optiontexts{$key};
1081 # special case for lastcost
1082 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1084 if ($form->{description}) {
1085 $description = $form->{description};
1086 $description =~ s/\n/<br>/g;
1089 if ($form->{l_linetotal}) {
1090 $form->{l_onhand} = "Y";
1091 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1092 if ($form->{l_lastcost}) {
1093 $form->{l_linetotallastcost} = "Y";
1094 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1095 $form->{l_linetotallastcost} = "";
1098 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1101 if ($form->{searchitems} eq 'service') {
1103 # remove bin, weight and rop from list
1104 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1106 $form->{l_onhand} = "";
1108 # qty is irrelevant unless bought or sold
1109 if ( $form->{bought}
1114 || $form->{quoted}) {
1115 $form->{l_onhand} = "Y";
1117 $form->{l_linetotalsellprice} = "";
1118 $form->{l_linetotallastcost} = "";
1122 $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1124 IC->all_parts(\%myconfig, \%$form);
1127 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1128 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1131 'bin' => { 'text' => $locale->text('Bin'), },
1132 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1133 'description' => { 'text' => $locale->text('Part Description'), },
1134 'drawing' => { 'text' => $locale->text('Drawing'), },
1135 'image' => { 'text' => $locale->text('Image'), },
1136 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1137 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1138 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1139 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1140 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1141 'listprice' => { 'text' => $locale->text('List Price'), },
1142 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1143 'name' => { 'text' => $locale->text('Name'), },
1144 'onhand' => { 'text' => $locale->text('Qty'), },
1145 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1146 'partnumber' => { 'text' => $locale->text('Part Number'), },
1147 'partsgroup' => { 'text' => $locale->text('Group'), },
1148 'priceupdate' => { 'text' => $locale->text('Updated'), },
1149 'quonumber' => { 'text' => $locale->text('Quotation'), },
1150 'rop' => { 'text' => $locale->text('ROP'), },
1151 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1152 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1153 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1154 'unit' => { 'text' => $locale->text('Unit'), },
1155 'weight' => { 'text' => $locale->text('Weight'), },
1158 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1159 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1161 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1162 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1164 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1165 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1167 foreach my $col (@sort_full) {
1168 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1170 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1172 # add order to callback
1173 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1175 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1177 my %attachment_basenames = (
1178 'part' => $locale->text('part_list'),
1179 'service' => $locale->text('service_list'),
1180 'assembly' => $locale->text('assembly_list'),
1183 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1184 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1185 'output_format' => 'HTML',
1186 'title' => $form->{title},
1187 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1189 $report->set_options_from_form();
1191 $report->set_columns(%column_defs);
1192 $report->set_column_order(@columns);
1194 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1196 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1198 my @subtotal_columns = qw(sellprice listprice lastcost);
1199 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1200 my %totals = map { $_ => 0 } @subtotal_columns;
1202 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1205 foreach my $ref (@{ $form->{parts} }) {
1207 # fresh row, for inserting later
1208 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1210 $ref->{exchangerate} ||= 1;
1211 $ref->{price_factor} ||= 1;
1212 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1213 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1214 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1216 # use this for assemblies
1217 my $onhand = $ref->{onhand};
1219 if ($ref->{assemblyitem}) {
1220 $row->{partnumber}{align} = 'right';
1221 $row->{onhand}{data} = 0;
1222 $onhand = 0 if ($form->{sold});
1225 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1226 $row->{partnumber}->{link} = $edit_link;
1227 $row->{description}->{link} = $edit_link;
1229 foreach (qw(sellprice listprice lastcost)) {
1230 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1231 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1234 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1236 if (!$ref->{assemblyitem}) {
1237 foreach my $col (@subtotal_columns) {
1238 $totals{$col} += $onhand * $ref->{$col};
1239 $subtotals{$col} += $onhand * $ref->{$col};
1242 $subtotals{onhand} += $onhand;
1246 if ($ref->{module} eq 'oe') {
1247 my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1248 $row->{ordnumber}{link} = $edit_oe_link;
1249 $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1252 $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1255 # set properties of images
1256 if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1257 $row->{image}{data} = '';
1258 $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1260 map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1262 $report->add_data($row);
1264 my $next_ref = $form->{parts}[$idx + 1];
1266 # insert subtotal rows
1267 if (($form->{l_subtotal} eq 'Y') &&
1269 (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1270 my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1272 if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1273 $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1276 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1277 map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1279 $report->add_data($row);
1281 $same_item = $next_ref->{ $form->{sort} };
1287 if ($form->{"l_linetotal"}) {
1288 my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1290 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1292 $report->add_separator();
1293 $report->add_data($row);
1296 $report->generate_with_headers();
1298 $lxdebug->leave_sub();
1299 } #end generate_report
1301 sub parts_subtotal {
1302 $lxdebug->enter_sub();
1304 $auth->assert('part_service_assembly_edit');
1307 our (%column_data, @column_index);
1308 our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1310 map { $column_data{$_} = "<td> </td>" } @column_index;
1311 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1313 $column_data{onhand} =
1314 "<th class=listsubtotal align=right>"
1315 . $form->format_amount(\%myconfig, $subtotalonhand)
1318 $column_data{linetotalsellprice} =
1319 "<th class=listsubtotal align=right>"
1320 . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1322 $column_data{linetotallistprice} =
1323 "<th class=listsubtotal align=right>"
1324 . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1326 $column_data{linetotallastcost} =
1327 "<th class=listsubtotal align=right>"
1328 . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1331 $subtotalonhand = 0;
1332 $subtotalsellprice = 0;
1333 $subtotallistprice = 0;
1334 $subtotallastcost = 0;
1336 print "<tr class=listsubtotal>";
1338 map { print "\n$column_data{$_}" } @column_index;
1344 $lxdebug->leave_sub();
1348 $lxdebug->enter_sub();
1350 $auth->assert('part_service_assembly_edit');
1352 # show history button
1353 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1354 #/show hhistory button
1355 IC->get_part(\%myconfig, \%$form);
1357 $form->{"original_partnumber"} = $form->{"partnumber"};
1359 $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1364 $lxdebug->leave_sub();
1368 $lxdebug->enter_sub();
1370 $auth->assert('part_service_assembly_edit');
1372 IC->create_links("IC", \%myconfig, \%$form);
1375 map({ $form->{selectcurrency} .= "<option>$_\n" }
1376 split(/:/, $form->{currencies}));
1378 # parts and assemblies have the same links
1379 my $item = $form->{item};
1380 if ($form->{item} eq 'assembly') {
1384 # build the popup menus
1385 $form->{taxaccounts} = "";
1386 foreach my $key (keys %{ $form->{IC_links} }) {
1387 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1389 # if this is a tax field
1390 if ($key =~ /IC_tax/) {
1391 if ($key =~ /\Q$item\E/) {
1392 $form->{taxaccounts} .= "$ref->{accno} ";
1393 $form->{"IC_tax_$ref->{accno}_description"} =
1394 "$ref->{accno}--$ref->{description}";
1397 if ($form->{amount}{ $ref->{accno} }) {
1398 $form->{"IC_tax_$ref->{accno}"} = "checked";
1401 $form->{"IC_tax_$ref->{accno}"} = "checked";
1406 $form->{"select$key"} .=
1407 "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1408 if ($form->{amount}{$key} eq $ref->{accno}) {
1409 $form->{$key} = "$ref->{accno}--$ref->{description}";
1415 chop $form->{taxaccounts};
1417 if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1418 $form->{selectIC_income} = $form->{selectIC_sale};
1419 $form->{selectIC_expense} = $form->{selectIC_cogs};
1420 $form->{IC_income} = $form->{IC_sale};
1421 $form->{IC_expense} = $form->{IC_cogs};
1424 delete $form->{IC_links};
1425 delete $form->{amount};
1427 $form->get_partsgroup(\%myconfig, { all => 1 });
1429 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1431 if (@{ $form->{all_partsgroup} }) {
1432 $form->{selectpartsgroup} = qq|<option>\n|;
1433 map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1436 if ($form->{item} eq 'assembly') {
1438 foreach my $i (1 .. $form->{assembly_rows}) {
1439 if ($form->{"partsgroup_id_$i"}) {
1440 $form->{"partsgroup_$i"} =
1441 qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1444 $form->get_partsgroup(\%myconfig);
1446 if (@{ $form->{all_partsgroup} }) {
1447 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1450 $form->{selectassemblypartsgroup} .=
1451 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1452 } @{ $form->{all_partsgroup} };
1455 $lxdebug->leave_sub();
1459 $lxdebug->enter_sub();
1461 $auth->assert('part_service_assembly_edit');
1463 $form->{eur} = $eur; # config dumps into namespace - yuck
1464 $form->{pg_keys} = sub { "$_[0]->{partsgroup}--$_[0]->{id}" };
1465 $form->{description_area} = ($form->{rows} = $form->numtextrows($form->{description}, 40)) > 1;
1466 $form->{notes_rows} = max 4, $form->numtextrows($form->{notes}, 40), $form->numtextrows($form->{formel}, 40);
1468 map { $form->{"is_$_"} = ($form->{item} eq $_) } qw(part service assembly);
1469 map { $form->{$_} =~ s/"/"/g; } qw(unit);
1471 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS',
1472 'partsgroup' => 'all_partsgroup');
1474 IC->retrieve_buchungsgruppen(\%myconfig, $form);
1475 @{ $form->{BUCHUNGSGRUPPEN} } = grep { $_->{id} eq $form->{buchungsgruppen_id} || ($form->{id} && $form->{orphaned}) || !$form->{id} } @{ $form->{BUCHUNGSGRUPPEN} };
1477 # use JavaScript Calendar or not (yes!)
1478 $form->{jsscript} = 1;
1480 $units = AM->retrieve_units(\%myconfig, $form);
1481 $form->{ALL_UNITS} = [ map +{ name => $_ }, sort { $units->{$a}{sortkey} <=> $units->{$b}{sortkey} } keys %$units ];
1483 $form->{fokus} = "ic.partnumber";
1486 print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
1487 ALL_UNITS => $form->{ALL_UNITS},
1488 BUCHUNGSGRUPPEN => $form->{BUCHUNGSGRUPPEN},
1489 payment_terms => $form->{payment_terms},
1490 all_partsgroup => $form->{all_partsgroup}});
1491 $lxdebug->leave_sub();
1495 $lxdebug->enter_sub();
1497 $auth->assert('part_service_assembly_edit');
1499 if ($form->{item} eq "assembly") {
1504 <table width="100%">
1506 <th colspan=2 align=right>| . $locale->text('Total') . qq| </th>
1507 <th align=right>| . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
1512 <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
1517 <input type=hidden name=callback value="$form->{callback}">
1518 <input type=hidden name=previousform value="$form->{previousform}">
1519 <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
1520 <input type=hidden name=vc value=$form->{vc}>
1522 <td><hr size=3 noshade></td>
1527 <input class=submit type=submit name=action value="|
1528 . $locale->text('Update') . qq|">
1531 unless ($form->{item} eq "service") {
1533 <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
1538 <input type=hidden name=price_rows value=$form->{price_rows}>|;
1541 <input class=submit type=submit name=action value="|
1542 . $locale->text('Save') . qq|">|;
1546 if (!$form->{previousform}) {
1548 <input class=submit type=submit name=action value="|
1549 . $locale->text('Save as new') . qq|">|;
1552 if ($form->{orphaned}) {
1553 if (!$form->{previousform}) {
1554 if ($form->{item} eq 'assembly') {
1555 if (!$form->{onhand}) {
1557 <input class=submit type=submit name=action value="|
1558 . $locale->text('Delete') . qq|">|;
1562 <input class=submit type=submit name=action value="|
1563 . $locale->text('Delete') . qq|">|;
1569 if (!$form->{previousform}) {
1570 if ($form->{menubar}) {
1571 require "bin/mozilla/menu.pl";
1575 # button for saving history
1576 if($form->{id} ne "") {
1578 <input type=button class=submit onclick=set_history_window(|
1580 . qq|); name=history id=history value=|
1581 . $locale->text('history')
1584 # /button for saving history
1589 <script type="text/javascript" src="js/wz_tooltip.js"></script>
1595 $lxdebug->leave_sub();
1599 $lxdebug->enter_sub();
1607 <th class="listheading">| . $locale->text('Make') . qq|</th>
1608 <th class="listheading">| . $locale->text('Model') . qq|</th>
1612 for my $i (1 .. $numrows) {
1613 $form->{"make_$i"} =~ s/\"/"/g;
1614 $form->{"model_$i"} =~ s/\"/"/g;
1617 <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
1618 <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
1629 $lxdebug->leave_sub();
1633 $lxdebug->enter_sub();
1635 my (@column_index, %column_data, %column_header);
1636 my ($nochange, $callback, $previousform, $linetotal, $href);
1638 our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
1641 qw(runningnumber qty unit bom partnumber description partsgroup total);
1643 if ($form->{previousform}) {
1645 @column_index = qw(qty unit bom partnumber description partsgroup total);
1649 $form->{old_callback} = $form->{callback};
1650 $callback = $form->{callback};
1651 $form->{callback} = "$form->{script}?action=display_form";
1654 map { delete $form->{$_} } qw(action header);
1658 # save form variables in a previousform variable
1659 foreach my $key (sort keys %$form) {
1662 $form->{$key} =~ s/&/%26/g;
1663 $previousform .= qq|$key=$form->{$key}&|;
1666 $previousform = $form->escape($form->escape($previousform, 1));
1667 $form->{callback} = $callback;
1669 $form->{assemblytotal} = 0;
1670 $form->{weight} = 0;
1673 $column_header{runningnumber} =
1674 qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
1675 $column_header{qty} =
1676 qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
1677 $column_header{unit} =
1678 qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
1679 $column_header{partnumber} =
1680 qq|<th align=left nowrap width=20%>|
1681 . $locale->text('Part Number')
1683 $column_header{description} =
1684 qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
1685 $column_header{total} =
1686 qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
1687 $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
1688 $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
1691 <tr class=listheading>
1692 <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
1700 map { print "\n$column_header{$_}" } @column_index;
1706 for my $i (1 .. $numrows) {
1707 $form->{"partnumber_$i"} =~ s/\"/"/g;
1710 $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
1711 $form->{assemblytotal} += $linetotal;
1713 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1715 $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
1717 if (($i >= 1) && ($i == $numrows)) {
1720 map { $column_data{$_} = qq|<td></td>| }
1721 qw(qty unit partnumber description bom partsgroup);
1724 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
1727 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1728 $column_data{partnumber} =
1729 qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
1730 $column_data{description} =
1731 qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
1732 $column_data{partsgroup} =
1733 qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
1739 if ($form->{previousform}) {
1740 $column_data{partnumber} =
1741 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
1743 qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
1746 qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
1747 $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
1748 $column_data{bom} .= qq|</td>|;
1750 $column_data{partsgroup} =
1751 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1755 qq|$form->{script}?action=edit&id=$form->{"id_$i"}&rowcount=$i&previousform=$previousform|;
1756 $column_data{partnumber} =
1757 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
1758 $column_data{runningnumber} =
1759 qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
1761 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1763 $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
1765 qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
1767 $column_data{partsgroup} =
1768 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1771 $column_data{unit} =
1772 qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
1773 $column_data{description} =
1774 qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
1777 $column_data{total} = qq|<td align=right>$linetotal</td>|;
1779 $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
1784 map { print "\n$column_data{$_}" } @column_index;
1788 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
1789 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
1790 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
1800 $lxdebug->leave_sub();
1804 $lxdebug->enter_sub();
1806 if ($form->{item} eq "assembly") {
1807 my $i = $form->{assembly_rows};
1809 # if last row is empty check the form otherwise retrieve item
1810 if ( ($form->{"partnumber_$i"} eq "")
1811 && ($form->{"description_$i"} eq "")
1812 && ($form->{"partsgroup_$i"} eq "")) {
1818 IC->assembly_item(\%myconfig, \%$form);
1820 my $rows = scalar @{ $form->{item_list} };
1823 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1826 $form->{makemodel_rows}--;
1830 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1831 qw(partnumber description unit partsgroup);
1832 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1833 keys %{ $form->{item_list}[0] };
1834 $form->{"runningnumber_$i"} = $form->{assembly_rows};
1835 $form->{assembly_rows}++;
1843 $form->{rowcount} = $i;
1844 $form->{assembly_rows}++;
1851 } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
1855 $lxdebug->leave_sub();
1859 $lxdebug->enter_sub();
1861 $auth->assert('part_service_assembly_edit');
1863 my ($parts_id, %newform, $previousform, $amount, $callback);
1865 # check if there is a part number - commented out, cause there is an automatic allocation of numbers
1866 # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
1868 # check if there is a description
1869 $form->isblank("description", $locale->text("Part Description missing!"));
1871 if ($form->{obsolete}) {
1874 "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
1876 if ($form->{onhand} * 1);
1879 if (!$form->{buchungsgruppen_id}) {
1880 $form->error($locale->text("Parts must have an entry type.") . " " .
1881 $locale->text("If you see this message, you most likely just setup your LX-Office and haven't added any entry types. If this is the case, the option is accessible for administrators in the System menu.")
1885 $form->error($locale->text('Description must not be empty!')) unless $form->{description};
1886 $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
1889 $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
1890 if (IC->save(\%myconfig, \%$form) == 3) {
1891 $form->error($locale->text('Partnumber not unique!'));
1893 # saving the history
1894 if(!exists $form->{addition}) {
1895 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1896 $form->{addition} = "SAVED";
1897 $form->save_history($form->dbconnect(\%myconfig));
1899 # /saving the history
1900 $parts_id = $form->{id};
1903 # load previous variables
1904 if ($form->{previousform}) {
1906 # save the new form variables before splitting previousform
1907 map { $newform{$_} = $form->{$_} } keys %$form;
1909 $previousform = $form->unescape($form->{previousform});
1911 # don't trample on previous variables
1912 map { delete $form->{$_} } keys %newform;
1914 # now take it apart and restore original values
1915 foreach my $item (split /&/, $previousform) {
1916 my ($key, $value) = split m/=/, $item, 2;
1917 $value =~ s/%26/&/g;
1918 $form->{$key} = $value;
1920 $form->{taxaccounts} = $newform{taxaccount2};
1922 if ($form->{item} eq 'assembly') {
1924 # undo number formatting
1925 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1926 qw(weight listprice sellprice rop);
1928 $form->{assembly_rows}--;
1929 $i = $newform{rowcount};
1930 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1932 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
1933 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
1935 # change/add values for assembly item
1936 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
1938 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
1939 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
1943 # set values for last invoice/order item
1944 $i = $form->{rowcount};
1945 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1947 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
1949 $form->{"longdescription_$i"} = $newform{notes};
1951 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
1953 if ($form->{exchangerate} != 0) {
1954 $form->{"sellprice_$i"} /= $form->{exchangerate};
1957 $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
1959 map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
1960 chop $form->{"taxaccounts_$i"};
1961 foreach my $item (qw(description rate taxnumber)) {
1962 my $index = $form->{"taxaccounts_$i"} . "_$item";
1963 $form->{$index} = $newform{$index};
1966 # credit remaining calculation
1967 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
1969 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
1970 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1972 $form->{creditremaining} -= $amount;
1974 # redo number formatting, because invoice parse them!
1975 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
1978 $form->{"id_$i"} = $parts_id;
1980 # Get the actual price factor (not just the ID) for the marge calculation.
1981 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1982 foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
1983 next if ($pfac->{id} != $newform{price_factor_id});
1984 $form->{"marge_price_factor_$i"} = $pfac->{factor};
1987 delete $form->{ALL_PRICE_FACTORS};
1989 delete $form->{action};
1991 # restore original callback
1992 $callback = $form->unescape($form->{callback});
1993 $form->{callback} = $form->unescape($form->{old_callback});
1994 delete $form->{old_callback};
1996 $form->{makemodel_rows}--;
1998 # put callback together
1999 foreach my $key (keys %$form) {
2001 # do single escape for Apache 2.0
2002 my $value = $form->escape($form->{$key}, 1);
2003 $callback .= qq|&$key=$value|;
2005 $form->{callback} = $callback;
2007 $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
2012 $lxdebug->leave_sub();
2016 $lxdebug->enter_sub();
2018 $auth->assert('part_service_assembly_edit');
2020 # saving the history
2021 if(!exists $form->{addition}) {
2022 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2023 $form->{addition} = "SAVED AS NEW";
2024 $form->save_history($form->dbconnect(\%myconfig));
2026 # /saving the history
2028 if ($form->{"original_partnumber"} &&
2029 ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
2030 $form->{partnumber} = "";
2033 $lxdebug->leave_sub();
2037 $lxdebug->enter_sub();
2039 $auth->assert('part_service_assembly_edit');
2041 # saving the history
2042 if(!exists $form->{addition}) {
2043 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2044 $form->{addition} = "DELETED";
2045 $form->save_history($form->dbconnect(\%myconfig));
2047 # /saving the history
2048 my $rc = IC->delete(\%myconfig, \%$form);
2051 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2052 $form->error($locale->text('Cannot delete item!'));
2054 $lxdebug->leave_sub();
2058 $lxdebug->enter_sub();
2060 $auth->assert('part_service_assembly_edit');
2065 pricegroup => $form->{"pricegroup_$_"},
2066 pricegroup_id => $form->{"pricegroup_id_$_"},
2067 price => $form->{"price_$_"},
2070 print $form->parse_html_template('ic/price_row', { PRICES => \@PRICES });
2072 $lxdebug->leave_sub();
2075 sub parts_language_selection {
2076 $lxdebug->enter_sub();
2078 $auth->assert('part_service_assembly_edit');
2082 my $languages = IC->retrieve_languages(\%myconfig, $form);
2084 if ($form->{language_values} ne "") {
2085 foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
2086 my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
2088 foreach my $language (@{ $languages }) {
2089 next unless ($language->{id} == $language_id);
2091 $language->{translation} = $translation;
2092 $language->{longdescription} = $longdescription;
2098 my @header_sort = qw(name longdescription);
2099 my %header_title = ( "name" => $locale->text("Name"),
2100 "longdescription" => $locale->text("Long Description"),
2104 map(+{ "column_title" => $header_title{$_},
2106 "callback" => $callback,
2110 $form->{"title"} = $locale->text("Language Values");
2112 print $form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
2113 "LANGUAGES" => $languages,
2114 "onload" => $onload });
2116 $lxdebug->leave_sub();
2119 sub continue { call_sub($form->{"nextsub"}); }