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});
79 $form->{callback} = "$form->{script}?action=add&item=$form->{item}" unless $form->{callback};
80 $form->{unit_changeable} = 1;
82 IC->get_pricegroups(\%myconfig, \%$form);
86 $lxdebug->leave_sub();
90 $lxdebug->enter_sub();
92 $auth->assert('part_service_assembly_edit');
94 $form->{revers} = 0; # switch for backward sorting
95 $form->{lastsort} = ""; # memory for which table was sort at last time
96 $form->{ndxs_counter} = 0; # counter for added entries to top100
98 my %is_xyz = map { +"is_$_" => ($form->{searchitems} eq $_) } qw(part service assembly);
100 $form->{title} = (ucfirst $form->{searchitems}) . "s";
101 $form->{title} = $locale->text($form->{title});
102 $form->{title} = $locale->text('Assemblies') if ($is_xyz{assembly});
104 $form->{jsscript} = 1;
108 print $form->parse_html_template('ic/search', { %is_xyz,
109 dateformat => $myconfig{dateformat}, });
111 $lxdebug->leave_sub();
114 sub search_update_prices {
115 $lxdebug->enter_sub();
117 $auth->assert('part_service_assembly_edit');
119 my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form);
123 print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups });
125 $lxdebug->leave_sub();
128 sub confirm_price_update {
129 $lxdebug->enter_sub();
131 $auth->assert('part_service_assembly_edit');
133 $form->{nextsub} = "update_prices";
136 map { delete $form->{$_} } qw(action header);
138 print $form->parse_html_template('ic/confirm_price_update', { HIDDENS => [ map { name => $_, value => $form->{$_} }, keys %$form ] });
140 $lxdebug->leave_sub();
144 $lxdebug->enter_sub();
146 $auth->assert('part_service_assembly_edit');
148 if (IC->update_prices(\%myconfig, \%$form)) {
149 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
151 $form->error($locale->text('Could not update prices!'));
154 $lxdebug->leave_sub();
158 # $lxdebug->enter_sub();
160 # $auth->assert('part_service_assembly_edit');
162 # our ($j, $lastndx);
165 # $form->{title} = $locale->text('Top 100 hinzufuegen');
169 # push @custom_hiddens, qw(searchitems title bom titel revers lastsort sort ndxs_counter extras);
170 # push @custom_hiddens, qw(itemstatus l_linetotal l_partnumber l_description l_onhand l_unit l_sellprice l_linetotalsellprice);
172 # +{ name => 'row', value => $j },
173 # +{ name => 'nextsub', value => 'item_selected' },
174 # +{ name => 'test', value => 'item_selected' },
175 # +{ name => 'lastndx', value => $lastndx },
176 # map(+{ name => $_, value => $form->{$_} }, @custom_hiddens),
179 # my ($partnumber, $description, $unit, $sellprice, $soldtotal);
180 # # if choice set data
181 ## if ($form->{ndx}) {
182 ## for my $i (0 .. $form->{ndxs_counter}) {
184 ## # insert data into top100
185 ## push @{ $form->{parts} },
187 ## partnumber => $form->{"totop100_partnumber_$j"},
188 ## description => $form->{"totop100_description_$j"},
189 ## unit => $form->{"totop100_unit_$j"},
190 ## sellprice => $form->{"totop100_sellprice_$j"},
191 ## soldtotal => $form->{"totop100_soldtotal_$j"},
198 # # set data for next page
199 # for my $i (1 .. $form->{ndxs_counter}) {
200 # $partnumber = $form->{"totop100_partnumber_$i"};
201 # $description = $form->{"totop100_description_$i"};
202 # $unit = $form->{"totop100_unit_$i"};
203 # $sellprice = $form->{"totop100_sellprice_$i"};
204 # $soldtotal = $form->{"totop100_soldtotal_$i"};
207 # totop100_partnumber => $form->{"totop100_partnumber_$i"},
208 # totop100_description => $form->{"totop100_description_$i"},
209 # totop100_unit => $form->{"totop100_unit_$i"},
210 # totop100_sellprice => $form->{"totop100_sellprice_$i"},
211 # totop100_soldtotal => $form->{"totop100_soldtotal_$i"},
215 ##<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
216 ##<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
217 ##<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
218 ##<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
219 ##<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
223 # print $form->parse_html_template('ic/choice', +{ HIDDENS => \@HIDDENS, PARTS => \@PARTS });
225 # $lxdebug->leave_sub();
229 # $lxdebug->enter_sub();
231 # $auth->assert('part_service_assembly_edit');
234 # our ($partnumber, $description, $unit, $sellprice, $soldtotal);
236 # my @sortorders = ("", "partnumber", "description", "all");
237 # my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
238 # IC->get_parts(\%myconfig, \%$form, $sortorder);
240 # $form->{title} = $locale->text('Top 100 hinzufuegen');
246 # <form method=post action=ic.pl>
249 # <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
251 # <tr height="5"></tr>
252 # <tr class=listheading>
254 # <th class=listheading>| . $locale->text('Part Number') . qq|</th>
255 # <th class=listheading>| . $locale->text('Part Description') . qq|</th>
256 # <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
257 # <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
258 # <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
262 # my $i = $form->{rows};
264 # for ($j = 1; $j <= $i; $j++) {
267 # <tr class=listrow| . ($j % 2) . qq|>|;
270 # <td><input name=ndx class=radio type=radio value=$j checked></td>|;
273 # <td><input name=ndx class=radio type=radio value=$j></td>|;
276 # <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
277 # <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
278 # <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
279 # <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
280 # <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
283 # <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
293 #<input type=hidden name=itemstatus value="$form->{itemstatus}">
294 #<input type=hidden name=l_linetotal value="$form->{l_linetotal}">
295 #<input type=hidden name=l_partnumber value="$form->{l_partnumber}">
296 #<input type=hidden name=l_description value="$form->{l_description}">
297 #<input type=hidden name=l_onhand value="$form->{l_onhand}">
298 #<input type=hidden name=l_unit value="$form->{l_unit}">
299 #<input type=hidden name=l_sellprice value="$form->{l_sellprice}">
300 #<input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
301 #<input type=hidden name=sort value="$form->{sort}">
302 #<input type=hidden name=revers value="$form->{revers}">
303 #<input type=hidden name=lastsort value="$form->{lastsort}">
305 #<input type=hidden name=bom value="$form->{bom}">
306 #<input type=hidden name=titel value="$form->{titel}">
307 #<input type=hidden name=searchitems value="$form->{searchitems}">
309 #<input type=hidden name=row value=$j>
311 #<input type=hidden name=nextsub value=item_selected>
313 #<input name=lastndx type=hidden value=$lastndx>
315 #<input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
319 # if (($form->{ndxs_counter}) > 0) {
320 # for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
322 # $partnumber = $form->{"totop100_partnumber_$i"};
323 # $description = $form->{"totop100_description_$i"};
324 # $unit = $form->{"totop100_unit_$i"};
325 # $sellprice = $form->{"totop100_sellprice_$i"};
326 # $soldtotal = $form->{"totop100_soldtotal_$i"};
329 #<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
330 #<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
331 #<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
332 #<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
333 #<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
341 #<input class=submit type=submit name=action value="|
342 # . $locale->text('TOP100') . qq|">
348 # $lxdebug->leave_sub();
352 $lxdebug->enter_sub();
354 $auth->assert('part_service_assembly_edit');
357 $form->{ndxs_counter}++;
359 if ($form->{ndxs_counter} > 0) {
361 my $index = $form->{ndx};
363 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
364 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
365 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
366 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
367 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
371 $lxdebug->leave_sub();
375 $lxdebug->enter_sub();
377 $auth->assert('part_service_assembly_edit');
379 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
380 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
381 my (@column_index, %column_header, %column_data);
382 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
384 $form->{top100} = "top100";
385 $form->{l_soldtotal} = "Y";
386 $form->{soldtotal} = "soldtotal";
387 $form->{sort} = "soldtotal";
388 $form->{l_qty} = "N";
389 $form->{l_linetotal} = "";
391 $form->{number} = "position";
392 $form->{l_number} = "Y";
396 $form->{title} = $locale->text('Top 100');
398 $revers = $form->{revers};
399 $lastsort = $form->{lastsort};
401 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
403 $form->{lastsort} = "partnumber";
404 $form->{sort} = "partnumber";
408 "$form->{script}?action=top100&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
409 . $form->escape($form->{title}, 1);
411 # if we have a serialnumber limit search
412 if ($form->{serialnumber} || $form->{l_serialnumber}) {
413 $form->{l_serialnumber} = "Y";
414 unless ( $form->{bought}
417 || $form->{quoted}) {
418 $form->{bought} = $form->{sold} = 1;
421 IC->all_parts(\%myconfig, \%$form);
423 if ($form->{itemstatus} eq 'active') {
424 $option .= $locale->text('Active') . " : ";
426 if ($form->{itemstatus} eq 'obsolete') {
427 $option .= $locale->text('Obsolete') . " : ";
429 if ($form->{itemstatus} eq 'orphaned') {
430 $option .= $locale->text('Orphaned') . " : ";
432 if ($form->{itemstatus} eq 'onhand') {
433 $option .= $locale->text('On Hand') . " : ";
434 $form->{l_onhand} = "Y";
436 if ($form->{itemstatus} eq 'short') {
437 $option .= $locale->text('Short') . " : ";
438 $form->{l_onhand} = "Y";
440 if ($form->{onorder}) {
441 $form->{l_ordnumber} = "Y";
442 $callback .= "&onorder=$form->{onorder}";
443 $option .= $locale->text('On Order') . " : ";
445 if ($form->{ordered}) {
446 $form->{l_ordnumber} = "Y";
447 $callback .= "&ordered=$form->{ordered}";
448 $option .= $locale->text('Ordered') . " : ";
451 $form->{l_quonumber} = "Y";
452 $callback .= "&rfq=$form->{rfq}";
453 $option .= $locale->text('RFQ') . " : ";
455 if ($form->{quoted}) {
456 $form->{l_quonumber} = "Y";
457 $callback .= ""ed=$form->{quoted}";
458 $option .= $locale->text('Quoted') . " : ";
460 if ($form->{bought}) {
461 $form->{l_invnumber} = "Y";
462 $callback .= "&bought=$form->{bought}";
463 $option .= $locale->text('Bought') . " : ";
466 $form->{l_invnumber} = "Y";
467 $callback .= "&sold=$form->{sold}";
468 $option .= $locale->text('Sold') . " : ";
475 || $form->{quoted}) {
477 $form->{l_lastcost} = "";
478 $form->{l_name} = "Y";
479 if ($form->{transdatefrom}) {
480 $callback .= "&transdatefrom=$form->{transdatefrom}";
482 . $locale->text('From')
484 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
486 if ($form->{transdateto}) {
487 $callback .= "&transdateto=$form->{transdateto}";
489 . $locale->text('To')
491 . $locale->date(\%myconfig, $form->{transdateto}, 1);
497 if ($form->{partnumber}) {
498 $callback .= "&partnumber=$form->{partnumber}";
499 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
502 $callback .= "&partnumber=$form->{ean}";
503 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
505 if ($form->{partsgroup}) {
506 $callback .= "&partsgroup=$form->{partsgroup}";
507 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
509 if ($form->{serialnumber}) {
510 $callback .= "&serialnumber=$form->{serialnumber}";
511 $option .= $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
513 if ($form->{description}) {
514 $callback .= "&description=$form->{description}";
515 $description = $form->{description};
516 $description =~ s/\n/<br>/g;
517 $option .= $locale->text('Part Description') . qq| : $form->{description}<br>|;
520 $callback .= "&make=$form->{make}";
521 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
523 if ($form->{model}) {
524 $callback .= "&model=$form->{model}";
525 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
527 if ($form->{drawing}) {
528 $callback .= "&drawing=$form->{drawing}";
529 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
531 if ($form->{microfiche}) {
532 $callback .= "µfiche=$form->{microfiche}";
533 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
535 if ($form->{l_soldtotal}) {
536 $callback .= "&soldtotal=$form->{soldtotal}";
537 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
540 my @columns = $form->sort_columns(
541 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)
544 if ($form->{l_linetotal}) {
545 $form->{l_onhand} = "Y";
546 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
547 if ($form->{l_lastcost}) {
548 $form->{l_linetotallastcost} = "Y";
549 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
550 $form->{l_linetotallastcost} = "";
553 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
556 if ($form->{searchitems} eq 'service') {
558 # remove bin, weight and rop from list
559 map { $form->{"l_$_"} = "" } qw(bin weight rop);
561 $form->{l_onhand} = "";
563 # qty is irrelevant unless bought or sold
569 || $form->{quoted}) {
570 $form->{l_onhand} = "Y";
572 $form->{l_linetotalsellprice} = "";
573 $form->{l_linetotallastcost} = "";
577 $form->{l_lastcost} = ""
578 if ($form->{searchitems} eq 'assembly' && !$form->{bom});
580 foreach my $item (@columns) {
581 if ($form->{"l_$item"} eq "Y") {
582 push @column_index, $item;
584 # add column to callback
585 $callback .= "&l_$item=Y";
589 if ($form->{l_subtotal} eq 'Y') {
590 $callback .= "&l_subtotal=Y";
593 $column_header{number} =
594 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
595 $column_header{partnumber} =
596 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
597 . $locale->text('Part Number')
599 $column_header{description} =
600 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
601 . $locale->text('Part Description')
603 $column_header{partsgroup} =
604 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
605 . $locale->text('Group')
607 $column_header{bin} =
608 qq|<th><a class=listheading href=$callback&sort=bin>|
609 . $locale->text('Bin')
611 $column_header{priceupdate} =
612 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
613 . $locale->text('Updated')
615 $column_header{onhand} =
616 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
617 . $locale->text('Qty')
619 $column_header{unit} =
620 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
621 $column_header{listprice} =
622 qq|<th class=listheading nowrap>|
623 . $locale->text('List Price')
625 $column_header{lastcost} =
626 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
627 $column_header{rop} =
628 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
629 $column_header{weight} =
630 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
632 $column_header{invnumber} =
633 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
634 . $locale->text('Invoice Number')
636 $column_header{ordnumber} =
637 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
638 . $locale->text('Order Number')
640 $column_header{quonumber} =
641 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
642 . $locale->text('Quotation')
645 $column_header{name} =
646 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
647 . $locale->text('Name')
650 $column_header{sellprice} =
651 qq|<th class=listheading nowrap>|
652 . $locale->text('Sell Price')
654 $column_header{linetotalsellprice} =
655 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
656 $column_header{linetotallastcost} =
657 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
658 $column_header{linetotallistprice} =
659 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
661 $column_header{image} =
662 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
663 $column_header{drawing} =
664 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
665 . $locale->text('Drawing')
667 $column_header{microfiche} =
668 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
669 . $locale->text('Microfiche')
672 $column_header{serialnumber} =
673 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
674 . $locale->text('Serial Number')
676 $column_header{soldtotal} =
677 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
678 . $locale->text('soldtotal')
682 my $colspan = $#column_index + 1;
689 <th class=listtop colspan=$colspan>$form->{title}</th>
693 <tr><td colspan=$colspan>$option</td></tr>
695 <tr class=listheading>
698 map { print "\n$column_header{$_}" } @column_index;
704 # add order to callback
705 $form->{callback} = $callback .= "&sort=$form->{sort}";
707 # escape callback for href
708 $callback = $form->escape($callback);
710 if (@{ $form->{parts} }) {
711 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
714 # insert numbers for top100
716 foreach my $ref (@{ $form->{parts} }) {
721 # if avaible -> insert choice here
722 if (($form->{ndxs_counter}) > 0) {
723 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
724 $partnumber = $form->{"totop100_partnumber_$i"};
725 $description = $form->{"totop100_description_$i"};
726 $unit = $form->{"totop100_unit_$i"};
727 $sellprice = $form->{"totop100_sellprice_$i"};
728 $soldtotal = $form->{"totop100_soldtotal_$i"};
731 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
732 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
733 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
734 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
735 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
739 push @{ $form->{parts} },
741 partnumber => "$partnumber",
742 description => "$description",
744 sellprice => "$sellprice",
745 soldtotal => "$soldtotal" };
748 # build data for columns
750 foreach my $ref (@{ $form->{parts} }) {
752 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
753 if ($sameitem ne $ref->{ $form->{sort} }) {
755 $sameitem = $ref->{ $form->{sort} };
759 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
760 $ref->{sellprice} *= $ref->{exchangerate};
761 $ref->{listprice} *= $ref->{exchangerate};
762 $ref->{lastcost} *= $ref->{exchangerate};
764 # use this for assemblies
765 $onhand = $ref->{onhand};
768 if ($ref->{assemblyitem}) {
770 $onhand = 0 if ($form->{sold});
773 $ref->{description} =~ s/\n/<br>/g;
775 $column_data{number} =
777 . $form->format_amount(\%myconfig, $ref->{number})
779 $column_data{partnumber} =
780 "<td align=$align>$ref->{partnumber} </a></td>";
781 $column_data{description} = "<td>$ref->{description} </td>";
782 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
784 $column_data{onhand} =
786 . $form->format_amount(\%myconfig, $ref->{onhand})
788 $column_data{sellprice} =
790 . $form->format_amount(\%myconfig, $ref->{sellprice})
792 $column_data{listprice} =
794 . $form->format_amount(\%myconfig, $ref->{listprice})
796 $column_data{lastcost} =
798 . $form->format_amount(\%myconfig, $ref->{lastcost})
801 $column_data{linetotalsellprice} = "<td align=right>"
802 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
804 $column_data{linetotallastcost} = "<td align=right>"
805 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
807 $column_data{linetotallistprice} = "<td align=right>"
808 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
811 if (!$ref->{assemblyitem}) {
812 $totalsellprice += $onhand * $ref->{sellprice};
813 $totallastcost += $onhand * $ref->{lastcost};
814 $totallistprice += $onhand * $ref->{listprice};
816 $subtotalonhand += $onhand;
817 $subtotalsellprice += $onhand * $ref->{sellprice};
818 $subtotallastcost += $onhand * $ref->{lastcost};
819 $subtotallistprice += $onhand * $ref->{listprice};
824 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
825 $column_data{weight} =
827 . $form->format_amount(\%myconfig, $ref->{weight})
829 $column_data{unit} = "<td>$ref->{unit} </td>";
830 $column_data{bin} = "<td>$ref->{bin} </td>";
831 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
833 $column_data{invnumber} =
834 ($ref->{module} ne 'oe')
835 ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&callback=$callback>$ref->{invnumber}</a></td>"
836 : "<td>$ref->{invnumber}</td>";
837 $column_data{ordnumber} =
838 ($ref->{module} eq 'oe')
839 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{ordnumber}</a></td>"
840 : "<td>$ref->{ordnumber}</td>";
841 $column_data{quonumber} =
842 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
843 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{quonumber}</a></td>"
844 : "<td>$ref->{quonumber}</td>";
846 $column_data{name} = "<td>$ref->{name}</td>";
848 $column_data{image} =
850 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
852 $column_data{drawing} =
854 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
856 $column_data{microfiche} =
858 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
861 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
863 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
867 print "<tr class=listrow$i>";
869 map { print "\n$column_data{$_}" } @column_index;
876 if ($form->{l_subtotal} eq 'Y') {
880 if ($form->{"l_linetotal"}) {
881 map { $column_data{$_} = "<td> </td>" } @column_index;
882 $column_data{linetotalsellprice} =
883 "<th class=listtotal align=right>"
884 . $form->format_amount(\%myconfig, $totalsellprice, 2)
886 $column_data{linetotallastcost} =
887 "<th class=listtotal align=right>"
888 . $form->format_amount(\%myconfig, $totallastcost, 2)
890 $column_data{linetotallistprice} =
891 "<th class=listtotal align=right>"
892 . $form->format_amount(\%myconfig, $totallistprice, 2)
895 print "<tr class=listtotal>";
897 map { print "\n$column_data{$_}" } @column_index;
904 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
913 <form method=post action=$form->{script}>
915 <input type=hidden name=itemstatus value="$form->{itemstatus}">
916 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
917 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
918 <input type=hidden name=l_description value="$form->{l_description}">
919 <input type=hidden name=l_onhand value="$form->{l_onhand}">
920 <input type=hidden name=l_unit value="$form->{l_unit}">
921 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
922 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
923 <input type=hidden name=sort value="$form->{sort}">
924 <input type=hidden name=revers value="$form->{revers}">
925 <input type=hidden name=lastsort value="$form->{lastsort}">
926 <input type=hidden name=parts value="$form->{parts}">
928 <input type=hidden name=bom value="$form->{bom}">
929 <input type=hidden name=titel value="$form->{titel}">
930 <input type=hidden name=searchitems value="$form->{searchitems}">|;
935 <!-- <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">-->
937 <input class=submit type=submit name=action value="|
938 . $locale->text('choice') . qq|">
946 $lxdebug->leave_sub();
951 # Warning, deep magic ahead.
952 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
954 # flags coming from the form:
956 # searchitems=part revers=0 lastsort=''
959 # partnumber ean description partsgroup serialnumber make model drawing microfiche
960 # transdatefrom transdateto
963 # itemstatus = active | onhand | short | obsolete | orphaned
964 # action = continue | top100
967 # bought sold onorder ordered rfq quoted
968 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
969 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
970 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
973 # nextsub revers lastsort sort ndxs_counter
975 sub generate_report {
976 $lxdebug->enter_sub();
978 $auth->assert('part_service_assembly_edit');
980 my ($revers, $lastsort, $description);
982 $form->{title} = (ucfirst $form->{searchitems}) . "s";
983 $form->{title} =~ s/ys$/ies/;
984 $form->{title} = $locale->text($form->{title});
986 my $revers = $form->{revers};
987 my $lastsort = $form->{lastsort};
989 # sorting and direction of sorting
990 # ToDO: change this to the simpler field+direction method
991 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
993 $form->{lastsort} = "partnumber";
994 $form->{sort} = "partnumber";
996 if ($form->{lastsort} eq $form->{sort}) {
997 $form->{revers} = 1 - $form->{revers};
1000 $form->{lastsort} = $form->{sort};
1004 # special case if we have a serialnumber limit search
1005 # serialnumbers are only given in invoices and orders,
1006 # so they can only pop up in bought, sold, rfq, and quoted stuff
1007 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
1008 && !$form->{rfq} && !$form->{quoted}
1009 && ($form->{l_serialnumber} || $form->{serialnumber}));
1011 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1012 # if any of these are ticked the behavior changes slightly for lastcost
1013 # since all those are aggregation checks for the legder tables this is an internal switch
1014 # refered to as ledgerchecks
1015 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1016 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1018 # if something should be activated if something else is active, enter it here
1019 my %dependencies = (
1020 onhand => [ qw(l_onhand) ],
1021 short => [ qw(l_onhand) ],
1022 onorder => [ qw(l_ordnumber) ],
1023 ordered => [ qw(l_ordnumber) ],
1024 rfq => [ qw(l_quonumber) ],
1025 quoted => [ qw(l_quonumber) ],
1026 bought => [ qw(l_invnumber) ],
1027 sold => [ qw(l_invnumber) ],
1028 ledgerchecks => [ qw(l_name) ],
1029 serialnumber => [ qw(l_serialnumber) ],
1030 no_sn_joins => [ qw(bought sold) ],
1033 # these strings get displayed at the top of the results to indicate the user which switches were used
1035 active => $locale->text('Active'),
1036 obsolete => $locale->text('Obsolete'),
1037 orphaned => $locale->text('Orphaned'),
1038 onhand => $locale->text('On Hand'),
1039 short => $locale->text('Short'),
1040 onorder => $locale->text('On Order'),
1041 ordered => $locale->text('Ordered'),
1042 rfq => $locale->text('RFQ'),
1043 quoted => $locale->text('Quoted'),
1044 bought => $locale->text('Bought'),
1045 sold => $locale->text('Sold'),
1046 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1047 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1048 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1049 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1050 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1051 description => $locale->text('Part Description') . ": '$form->{description}'",
1052 make => $locale->text('Make') . ": '$form->{make}'",
1053 model => $locale->text('Model') . ": '$form->{model}'",
1054 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1055 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1056 l_soldtotal => $locale->text('soldtotal'),
1059 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1060 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1061 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1063 # calculate dependencies
1064 for (@itemstatus_keys, @callback_keys) {
1065 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1066 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1069 # generate callback and optionstrings
1071 for my $key (@itemstatus_keys, @callback_keys) {
1072 next if ($form->{itemstatus} ne $key && !$form->{$key});
1073 push @options, $optiontexts{$key};
1076 # special case for lastcost
1077 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1079 if ($form->{description}) {
1080 $description = $form->{description};
1081 $description =~ s/\n/<br>/g;
1084 if ($form->{l_linetotal}) {
1085 $form->{l_onhand} = "Y";
1086 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1087 if ($form->{l_lastcost}) {
1088 $form->{l_linetotallastcost} = "Y";
1089 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1090 $form->{l_linetotallastcost} = "";
1093 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1096 if ($form->{searchitems} eq 'service') {
1098 # remove bin, weight and rop from list
1099 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1101 $form->{l_onhand} = "";
1103 # qty is irrelevant unless bought or sold
1104 if ( $form->{bought}
1109 || $form->{quoted}) {
1110 $form->{l_onhand} = "Y";
1112 $form->{l_linetotalsellprice} = "";
1113 $form->{l_linetotallastcost} = "";
1117 $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1119 IC->all_parts(\%myconfig, \%$form);
1122 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1123 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1126 'bin' => { 'text' => $locale->text('Bin'), },
1127 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1128 'description' => { 'text' => $locale->text('Part Description'), },
1129 'drawing' => { 'text' => $locale->text('Drawing'), },
1130 'image' => { 'text' => $locale->text('Image'), },
1131 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1132 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1133 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1134 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1135 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1136 'listprice' => { 'text' => $locale->text('List Price'), },
1137 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1138 'name' => { 'text' => $locale->text('Name'), },
1139 'onhand' => { 'text' => $locale->text('Qty'), },
1140 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1141 'partnumber' => { 'text' => $locale->text('Part Number'), },
1142 'partsgroup' => { 'text' => $locale->text('Group'), },
1143 'priceupdate' => { 'text' => $locale->text('Updated'), },
1144 'quonumber' => { 'text' => $locale->text('Quotation'), },
1145 'rop' => { 'text' => $locale->text('ROP'), },
1146 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1147 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1148 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1149 'unit' => { 'text' => $locale->text('Unit'), },
1150 'weight' => { 'text' => $locale->text('Weight'), },
1153 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1154 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1156 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1157 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1159 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1160 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1162 foreach my $col (@sort_full) {
1163 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1165 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1167 # add order to callback
1168 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1170 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1172 my %attachment_basenames = (
1173 'part' => $locale->text('part_list'),
1174 'service' => $locale->text('service_list'),
1175 'assembly' => $locale->text('assembly_list'),
1178 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1179 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1180 'output_format' => 'HTML',
1181 'title' => $form->{title},
1182 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1184 $report->set_options_from_form();
1186 $report->set_columns(%column_defs);
1187 $report->set_column_order(@columns);
1189 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1191 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1193 my @subtotal_columns = qw(sellprice listprice lastcost);
1194 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1195 my %totals = map { $_ => 0 } @subtotal_columns;
1197 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1200 foreach my $ref (@{ $form->{parts} }) {
1202 # fresh row, for inserting later
1203 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1205 $ref->{exchangerate} ||= 1;
1206 $ref->{price_factor} ||= 1;
1207 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1208 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1209 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1211 # use this for assemblies
1212 my $onhand = $ref->{onhand};
1214 if ($ref->{assemblyitem}) {
1215 $row->{partnumber}{align} = 'right';
1216 $row->{onhand}{data} = 0;
1217 $onhand = 0 if ($form->{sold});
1220 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1221 $row->{partnumber}->{link} = $edit_link;
1222 $row->{description}->{link} = $edit_link;
1224 foreach (qw(sellprice listprice lastcost)) {
1225 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1226 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1229 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1231 if (!$ref->{assemblyitem}) {
1232 foreach my $col (@subtotal_columns) {
1233 $totals{$col} += $onhand * $ref->{$col};
1234 $subtotals{$col} += $onhand * $ref->{$col};
1237 $subtotals{onhand} += $onhand;
1241 if ($ref->{module} eq 'oe') {
1242 my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1243 $row->{ordnumber}{link} = $edit_oe_link;
1244 $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1247 $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1250 # set properties of images
1251 if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1252 $row->{image}{data} = '';
1253 $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1255 map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1257 $report->add_data($row);
1259 my $next_ref = $form->{parts}[$idx + 1];
1261 # insert subtotal rows
1262 if (($form->{l_subtotal} eq 'Y') &&
1264 (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1265 my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1267 if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1268 $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1271 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1272 map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1274 $report->add_data($row);
1276 $same_item = $next_ref->{ $form->{sort} };
1282 if ($form->{"l_linetotal"}) {
1283 my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1285 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1287 $report->add_separator();
1288 $report->add_data($row);
1291 $report->generate_with_headers();
1293 $lxdebug->leave_sub();
1294 } #end generate_report
1296 sub parts_subtotal {
1297 $lxdebug->enter_sub();
1299 $auth->assert('part_service_assembly_edit');
1302 our (%column_data, @column_index);
1303 our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1305 map { $column_data{$_} = "<td> </td>" } @column_index;
1306 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1308 $column_data{onhand} =
1309 "<th class=listsubtotal align=right>"
1310 . $form->format_amount(\%myconfig, $subtotalonhand)
1313 $column_data{linetotalsellprice} =
1314 "<th class=listsubtotal align=right>"
1315 . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1317 $column_data{linetotallistprice} =
1318 "<th class=listsubtotal align=right>"
1319 . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1321 $column_data{linetotallastcost} =
1322 "<th class=listsubtotal align=right>"
1323 . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1326 $subtotalonhand = 0;
1327 $subtotalsellprice = 0;
1328 $subtotallistprice = 0;
1329 $subtotallastcost = 0;
1331 print "<tr class=listsubtotal>";
1333 map { print "\n$column_data{$_}" } @column_index;
1339 $lxdebug->leave_sub();
1343 $lxdebug->enter_sub();
1345 $auth->assert('part_service_assembly_edit');
1347 # show history button
1348 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1349 #/show hhistory button
1350 IC->get_part(\%myconfig, \%$form);
1352 $form->{"original_partnumber"} = $form->{"partnumber"};
1354 $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1359 $lxdebug->leave_sub();
1363 $lxdebug->enter_sub();
1365 $auth->assert('part_service_assembly_edit');
1367 IC->create_links("IC", \%myconfig, \%$form);
1370 map({ $form->{selectcurrency} .= "<option>$_\n" }
1371 split(/:/, $form->{currencies}));
1373 # parts and assemblies have the same links
1374 my $item = $form->{item};
1375 if ($form->{item} eq 'assembly') {
1379 # build the popup menus
1380 $form->{taxaccounts} = "";
1381 foreach my $key (keys %{ $form->{IC_links} }) {
1382 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1384 # if this is a tax field
1385 if ($key =~ /IC_tax/) {
1386 if ($key =~ /\Q$item\E/) {
1387 $form->{taxaccounts} .= "$ref->{accno} ";
1388 $form->{"IC_tax_$ref->{accno}_description"} =
1389 "$ref->{accno}--$ref->{description}";
1392 if ($form->{amount}{ $ref->{accno} }) {
1393 $form->{"IC_tax_$ref->{accno}"} = "checked";
1396 $form->{"IC_tax_$ref->{accno}"} = "checked";
1401 $form->{"select$key"} .=
1402 "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1403 if ($form->{amount}{$key} eq $ref->{accno}) {
1404 $form->{$key} = "$ref->{accno}--$ref->{description}";
1410 chop $form->{taxaccounts};
1412 if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1413 $form->{selectIC_income} = $form->{selectIC_sale};
1414 $form->{selectIC_expense} = $form->{selectIC_cogs};
1415 $form->{IC_income} = $form->{IC_sale};
1416 $form->{IC_expense} = $form->{IC_cogs};
1419 delete $form->{IC_links};
1420 delete $form->{amount};
1422 $form->get_partsgroup(\%myconfig, { all => 1 });
1424 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1426 if (@{ $form->{all_partsgroup} }) {
1427 $form->{selectpartsgroup} = qq|<option>\n|;
1428 map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1431 if ($form->{item} eq 'assembly') {
1433 foreach my $i (1 .. $form->{assembly_rows}) {
1434 if ($form->{"partsgroup_id_$i"}) {
1435 $form->{"partsgroup_$i"} =
1436 qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1439 $form->get_partsgroup(\%myconfig);
1441 if (@{ $form->{all_partsgroup} }) {
1442 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1445 $form->{selectassemblypartsgroup} .=
1446 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1447 } @{ $form->{all_partsgroup} };
1450 $lxdebug->leave_sub();
1454 $lxdebug->enter_sub();
1456 $auth->assert('part_service_assembly_edit');
1458 $form->{eur} = $eur; # config dumps into namespace - yuck
1459 $form->{pg_keys} = sub { "$_[0]->{partsgroup}--$_[0]->{id}" };
1460 $form->{description_area} = ($form->{rows} = $form->numtextrows($form->{description}, 40)) > 1;
1461 $form->{notes_rows} = max 4, $form->numtextrows($form->{notes}, 40), $form->numtextrows($form->{formel}, 40);
1463 map { $form->{"is_$_"} = ($form->{item} eq $_) } qw(part service assembly);
1464 map { $form->{$_} =~ s/"/"/g; } qw(unit);
1466 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS',
1467 'partsgroup' => 'all_partsgroup');
1469 IC->retrieve_buchungsgruppen(\%myconfig, $form);
1470 @{ $form->{BUCHUNGSGRUPPEN} } = grep { $_->{id} eq $form->{buchungsgruppen_id} || ($form->{id} && $form->{orphaned}) || !$form->{id} } @{ $form->{BUCHUNGSGRUPPEN} };
1472 # use JavaScript Calendar or not (yes!)
1473 $form->{jsscript} = 1;
1475 $units = AM->retrieve_units(\%myconfig, $form);
1476 $form->{ALL_UNITS} = [ map +{ name => $_ }, sort { $units->{$a}{sortkey} <=> $units->{$b}{sortkey} } keys %$units ];
1478 $form->{fokus} = "ic.partnumber";
1481 print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
1482 ALL_UNITS => $form->{ALL_UNITS},
1483 BUCHUNGSGRUPPEN => $form->{BUCHUNGSGRUPPEN},
1484 payment_terms => $form->{payment_terms},
1485 all_partsgroup => $form->{all_partsgroup}});
1486 $lxdebug->leave_sub();
1490 $lxdebug->enter_sub();
1492 $auth->assert('part_service_assembly_edit');
1494 print $form->parse_html_template('ic/form_footer');
1496 $lxdebug->leave_sub();
1500 $lxdebug->enter_sub();
1503 my @mm_data = grep { any { $_ ne '' } @$_{qw(make model)} } map +{ make => $form->{"make_$_"}, model => $form->{"model_$_"} }, 1 .. $numrows;
1504 print $form->parse_html_template('ic/makemodel', { MM_DATA => [ @mm_data, {} ], mm_rows => scalar @mm_data + 1 });
1506 $lxdebug->leave_sub();
1510 $lxdebug->enter_sub();
1512 my (@column_index, %column_data, %column_header);
1513 my ($nochange, $callback, $previousform, $linetotal, $href);
1515 our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
1518 qw(runningnumber qty unit bom partnumber description partsgroup total);
1520 if ($form->{previousform}) {
1522 @column_index = qw(qty unit bom partnumber description partsgroup total);
1526 $form->{old_callback} = $form->{callback};
1527 $callback = $form->{callback};
1528 $form->{callback} = "$form->{script}?action=display_form";
1531 map { delete $form->{$_} } qw(action header);
1535 # save form variables in a previousform variable
1536 foreach my $key (sort keys %$form) {
1539 $form->{$key} =~ s/&/%26/g;
1540 $previousform .= qq|$key=$form->{$key}&|;
1543 $previousform = $form->escape($form->escape($previousform, 1));
1544 $form->{callback} = $callback;
1546 $form->{assemblytotal} = 0;
1547 $form->{weight} = 0;
1550 $column_header{runningnumber} =
1551 qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
1552 $column_header{qty} =
1553 qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
1554 $column_header{unit} =
1555 qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
1556 $column_header{partnumber} =
1557 qq|<th align=left nowrap width=20%>|
1558 . $locale->text('Part Number')
1560 $column_header{description} =
1561 qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
1562 $column_header{total} =
1563 qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
1564 $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
1565 $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
1568 <tr class=listheading>
1569 <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
1577 map { print "\n$column_header{$_}" } @column_index;
1583 for my $i (1 .. $numrows) {
1584 $form->{"partnumber_$i"} =~ s/\"/"/g;
1587 $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
1588 $form->{assemblytotal} += $linetotal;
1590 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1592 $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
1594 if (($i >= 1) && ($i == $numrows)) {
1597 map { $column_data{$_} = qq|<td></td>| }
1598 qw(qty unit partnumber description bom partsgroup);
1601 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
1604 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1605 $column_data{partnumber} =
1606 qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
1607 $column_data{description} =
1608 qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
1609 $column_data{partsgroup} =
1610 qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
1616 if ($form->{previousform}) {
1617 $column_data{partnumber} =
1618 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
1620 qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
1623 qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
1624 $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
1625 $column_data{bom} .= qq|</td>|;
1627 $column_data{partsgroup} =
1628 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1632 qq|$form->{script}?action=edit&id=$form->{"id_$i"}&rowcount=$i&previousform=$previousform|;
1633 $column_data{partnumber} =
1634 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
1635 $column_data{runningnumber} =
1636 qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
1638 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1640 $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
1642 qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
1644 $column_data{partsgroup} =
1645 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1648 $column_data{unit} =
1649 qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
1650 $column_data{description} =
1651 qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
1654 $column_data{total} = qq|<td align=right>$linetotal</td>|;
1656 $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
1661 map { print "\n$column_data{$_}" } @column_index;
1665 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
1666 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
1667 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
1677 $lxdebug->leave_sub();
1681 $lxdebug->enter_sub();
1683 if ($form->{item} eq "assembly") {
1684 my $i = $form->{assembly_rows};
1686 # if last row is empty check the form otherwise retrieve item
1687 if ( ($form->{"partnumber_$i"} eq "")
1688 && ($form->{"description_$i"} eq "")
1689 && ($form->{"partsgroup_$i"} eq "")) {
1695 IC->assembly_item(\%myconfig, \%$form);
1697 my $rows = scalar @{ $form->{item_list} };
1700 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1703 $form->{makemodel_rows}--;
1707 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1708 qw(partnumber description unit partsgroup);
1709 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1710 keys %{ $form->{item_list}[0] };
1711 $form->{"runningnumber_$i"} = $form->{assembly_rows};
1712 $form->{assembly_rows}++;
1720 $form->{rowcount} = $i;
1721 $form->{assembly_rows}++;
1728 } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
1732 $lxdebug->leave_sub();
1736 $lxdebug->enter_sub();
1738 $auth->assert('part_service_assembly_edit');
1740 my ($parts_id, %newform, $previousform, $amount, $callback);
1742 # check if there is a part number - commented out, cause there is an automatic allocation of numbers
1743 # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
1745 # check if there is a description
1746 $form->isblank("description", $locale->text("Part Description missing!"));
1748 if ($form->{obsolete}) {
1751 "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
1753 if ($form->{onhand} * 1);
1756 if (!$form->{buchungsgruppen_id}) {
1757 $form->error($locale->text("Parts must have an entry type.") . " " .
1758 $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.")
1762 $form->error($locale->text('Description must not be empty!')) unless $form->{description};
1763 $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
1766 $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
1767 if (IC->save(\%myconfig, \%$form) == 3) {
1768 $form->error($locale->text('Partnumber not unique!'));
1770 # saving the history
1771 if(!exists $form->{addition}) {
1772 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1773 $form->{addition} = "SAVED";
1774 $form->save_history($form->dbconnect(\%myconfig));
1776 # /saving the history
1777 $parts_id = $form->{id};
1780 # load previous variables
1781 if ($form->{previousform}) {
1783 # save the new form variables before splitting previousform
1784 map { $newform{$_} = $form->{$_} } keys %$form;
1786 $previousform = $form->unescape($form->{previousform});
1788 # don't trample on previous variables
1789 map { delete $form->{$_} } keys %newform;
1791 # now take it apart and restore original values
1792 foreach my $item (split /&/, $previousform) {
1793 my ($key, $value) = split m/=/, $item, 2;
1794 $value =~ s/%26/&/g;
1795 $form->{$key} = $value;
1797 $form->{taxaccounts} = $newform{taxaccount2};
1799 if ($form->{item} eq 'assembly') {
1801 # undo number formatting
1802 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1803 qw(weight listprice sellprice rop);
1805 $form->{assembly_rows}--;
1806 $i = $newform{rowcount};
1807 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1809 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
1810 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
1812 # change/add values for assembly item
1813 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
1815 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
1816 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
1820 # set values for last invoice/order item
1821 $i = $form->{rowcount};
1822 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1824 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
1826 $form->{"longdescription_$i"} = $newform{notes};
1828 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
1830 if ($form->{exchangerate} != 0) {
1831 $form->{"sellprice_$i"} /= $form->{exchangerate};
1834 $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
1836 map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
1837 chop $form->{"taxaccounts_$i"};
1838 foreach my $item (qw(description rate taxnumber)) {
1839 my $index = $form->{"taxaccounts_$i"} . "_$item";
1840 $form->{$index} = $newform{$index};
1843 # credit remaining calculation
1844 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
1846 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
1847 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1849 $form->{creditremaining} -= $amount;
1851 # redo number formatting, because invoice parse them!
1852 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
1855 $form->{"id_$i"} = $parts_id;
1857 # Get the actual price factor (not just the ID) for the marge calculation.
1858 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1859 foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
1860 next if ($pfac->{id} != $newform{price_factor_id});
1861 $form->{"marge_price_factor_$i"} = $pfac->{factor};
1864 delete $form->{ALL_PRICE_FACTORS};
1866 delete $form->{action};
1868 # restore original callback
1869 $callback = $form->unescape($form->{callback});
1870 $form->{callback} = $form->unescape($form->{old_callback});
1871 delete $form->{old_callback};
1873 $form->{makemodel_rows}--;
1875 # put callback together
1876 foreach my $key (keys %$form) {
1878 # do single escape for Apache 2.0
1879 my $value = $form->escape($form->{$key}, 1);
1880 $callback .= qq|&$key=$value|;
1882 $form->{callback} = $callback;
1884 $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
1889 $lxdebug->leave_sub();
1893 $lxdebug->enter_sub();
1895 $auth->assert('part_service_assembly_edit');
1897 # saving the history
1898 if(!exists $form->{addition}) {
1899 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1900 $form->{addition} = "SAVED AS NEW";
1901 $form->save_history($form->dbconnect(\%myconfig));
1903 # /saving the history
1905 if ($form->{"original_partnumber"} &&
1906 ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
1907 $form->{partnumber} = "";
1910 $lxdebug->leave_sub();
1914 $lxdebug->enter_sub();
1916 $auth->assert('part_service_assembly_edit');
1918 # saving the history
1919 if(!exists $form->{addition}) {
1920 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1921 $form->{addition} = "DELETED";
1922 $form->save_history($form->dbconnect(\%myconfig));
1924 # /saving the history
1925 my $rc = IC->delete(\%myconfig, \%$form);
1928 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
1929 $form->error($locale->text('Cannot delete item!'));
1931 $lxdebug->leave_sub();
1935 $lxdebug->enter_sub();
1937 $auth->assert('part_service_assembly_edit');
1942 pricegroup => $form->{"pricegroup_$_"},
1943 pricegroup_id => $form->{"pricegroup_id_$_"},
1944 price => $form->{"price_$_"},
1947 print $form->parse_html_template('ic/price_row', { PRICES => \@PRICES });
1949 $lxdebug->leave_sub();
1952 sub parts_language_selection {
1953 $lxdebug->enter_sub();
1955 $auth->assert('part_service_assembly_edit');
1959 my $languages = IC->retrieve_languages(\%myconfig, $form);
1961 if ($form->{language_values} ne "") {
1962 foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
1963 my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
1965 foreach my $language (@{ $languages }) {
1966 next unless ($language->{id} == $language_id);
1968 $language->{translation} = $translation;
1969 $language->{longdescription} = $longdescription;
1975 my @header_sort = qw(name longdescription);
1976 my %header_title = ( "name" => $locale->text("Name"),
1977 "longdescription" => $locale->text("Long Description"),
1981 map(+{ "column_title" => $header_title{$_},
1983 "callback" => $callback,
1987 $form->{"title"} = $locale->text("Language Values");
1989 print $form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
1990 "LANGUAGES" => $languages,
1991 "onload" => $onload });
1993 $lxdebug->leave_sub();
1996 sub continue { call_sub($form->{"nextsub"}); }