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);
39 use SL::ReportGenerator;
47 our ($form, $locale, %myconfig, $lxdebug);
49 require "bin/mozilla/io.pl";
50 require "bin/mozilla/invoice_io.pl";
51 require "bin/mozilla/common.pl";
52 require "bin/mozilla/reportgenerator.pl";
57 # type=submit $locale->text('Add Part')
58 # type=submit $locale->text('Add Service')
59 # type=submit $locale->text('Add Assembly')
60 # type=submit $locale->text('Edit Part')
61 # type=submit $locale->text('Edit Service')
62 # type=submit $locale->text('Edit Assembly')
63 # $locale->text('Parts')
64 # $locale->text('Services')
65 # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
66 # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
67 # $locale->text('Part Number missing!')
68 # $locale->text('Service Number missing!')
69 # $locale->text('Assembly Number missing!')
70 # $locale->text('ea');
75 $lxdebug->enter_sub();
77 $auth->assert('part_service_assembly_edit');
79 $form->{title} = $locale->text('Add ' . ucfirst $form->{item});
80 $form->{callback} = "$form->{script}?action=add&item=$form->{item}" unless $form->{callback};
81 $form->{unit_changeable} = 1;
83 IC->get_pricegroups(\%myconfig, \%$form);
87 $lxdebug->leave_sub();
91 $lxdebug->enter_sub();
93 $auth->assert('part_service_assembly_edit');
95 $form->{revers} = 0; # switch for backward sorting
96 $form->{lastsort} = ""; # memory for which table was sort at last time
97 $form->{ndxs_counter} = 0; # counter for added entries to top100
99 my %is_xyz = map { +"is_$_" => ($form->{searchitems} eq $_) } qw(part service assembly);
101 $form->{title} = (ucfirst $form->{searchitems}) . "s";
102 $form->{title} = $locale->text($form->{title});
103 $form->{title} = $locale->text('Assemblies') if ($is_xyz{is_assembly});
105 $form->{jsscript} = 1;
109 print $form->parse_html_template('ic/search', { %is_xyz,
110 dateformat => $myconfig{dateformat}, });
112 $lxdebug->leave_sub();
115 sub search_update_prices {
116 $lxdebug->enter_sub();
118 $auth->assert('part_service_assembly_edit');
120 my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form);
124 print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups });
126 $lxdebug->leave_sub();
129 sub confirm_price_update {
130 $lxdebug->enter_sub();
132 $auth->assert('part_service_assembly_edit');
134 $form->{nextsub} = "update_prices";
137 map { delete $form->{$_} } qw(action header);
139 print $form->parse_html_template('ic/confirm_price_update', { HIDDENS => [ map { name => $_, value => $form->{$_} }, keys %$form ] });
141 $lxdebug->leave_sub();
145 $lxdebug->enter_sub();
147 $auth->assert('part_service_assembly_edit');
149 if (IC->update_prices(\%myconfig, \%$form)) {
150 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
152 $form->error($locale->text('Could not update prices!'));
155 $lxdebug->leave_sub();
159 # $lxdebug->enter_sub();
161 # $auth->assert('part_service_assembly_edit');
163 # our ($j, $lastndx);
166 # $form->{title} = $locale->text('Top 100 hinzufuegen');
170 # push @custom_hiddens, qw(searchitems title bom titel revers lastsort sort ndxs_counter extras);
171 # push @custom_hiddens, qw(itemstatus l_linetotal l_partnumber l_description l_onhand l_unit l_sellprice l_linetotalsellprice);
173 # +{ name => 'row', value => $j },
174 # +{ name => 'nextsub', value => 'item_selected' },
175 # +{ name => 'test', value => 'item_selected' },
176 # +{ name => 'lastndx', value => $lastndx },
177 # map(+{ name => $_, value => $form->{$_} }, @custom_hiddens),
180 # my ($partnumber, $description, $unit, $sellprice, $soldtotal);
181 # # if choice set data
182 ## if ($form->{ndx}) {
183 ## for my $i (0 .. $form->{ndxs_counter}) {
185 ## # insert data into top100
186 ## push @{ $form->{parts} },
188 ## partnumber => $form->{"totop100_partnumber_$j"},
189 ## description => $form->{"totop100_description_$j"},
190 ## unit => $form->{"totop100_unit_$j"},
191 ## sellprice => $form->{"totop100_sellprice_$j"},
192 ## soldtotal => $form->{"totop100_soldtotal_$j"},
199 # # set data for next page
200 # for my $i (1 .. $form->{ndxs_counter}) {
201 # $partnumber = $form->{"totop100_partnumber_$i"};
202 # $description = $form->{"totop100_description_$i"};
203 # $unit = $form->{"totop100_unit_$i"};
204 # $sellprice = $form->{"totop100_sellprice_$i"};
205 # $soldtotal = $form->{"totop100_soldtotal_$i"};
208 # totop100_partnumber => $form->{"totop100_partnumber_$i"},
209 # totop100_description => $form->{"totop100_description_$i"},
210 # totop100_unit => $form->{"totop100_unit_$i"},
211 # totop100_sellprice => $form->{"totop100_sellprice_$i"},
212 # totop100_soldtotal => $form->{"totop100_soldtotal_$i"},
216 ##<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
217 ##<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
218 ##<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
219 ##<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
220 ##<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
224 # print $form->parse_html_template('ic/choice', +{ HIDDENS => \@HIDDENS, PARTS => \@PARTS });
226 # $lxdebug->leave_sub();
230 # $lxdebug->enter_sub();
232 # $auth->assert('part_service_assembly_edit');
235 # our ($partnumber, $description, $unit, $sellprice, $soldtotal);
237 # my @sortorders = ("", "partnumber", "description", "all");
238 # my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
239 # IC->get_parts(\%myconfig, \%$form, $sortorder);
241 # $form->{title} = $locale->text('Top 100 hinzufuegen');
247 # <form method=post action=ic.pl>
250 # <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
252 # <tr height="5"></tr>
253 # <tr class=listheading>
255 # <th class=listheading>| . $locale->text('Part Number') . qq|</th>
256 # <th class=listheading>| . $locale->text('Part Description') . qq|</th>
257 # <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
258 # <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
259 # <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
263 # my $i = $form->{rows};
265 # for ($j = 1; $j <= $i; $j++) {
268 # <tr class=listrow| . ($j % 2) . qq|>|;
271 # <td><input name=ndx class=radio type=radio value=$j checked></td>|;
274 # <td><input name=ndx class=radio type=radio value=$j></td>|;
277 # <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
278 # <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
279 # <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
280 # <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
281 # <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
284 # <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
294 #<input type=hidden name=itemstatus value="$form->{itemstatus}">
295 #<input type=hidden name=l_linetotal value="$form->{l_linetotal}">
296 #<input type=hidden name=l_partnumber value="$form->{l_partnumber}">
297 #<input type=hidden name=l_description value="$form->{l_description}">
298 #<input type=hidden name=l_onhand value="$form->{l_onhand}">
299 #<input type=hidden name=l_unit value="$form->{l_unit}">
300 #<input type=hidden name=l_sellprice value="$form->{l_sellprice}">
301 #<input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
302 #<input type=hidden name=sort value="$form->{sort}">
303 #<input type=hidden name=revers value="$form->{revers}">
304 #<input type=hidden name=lastsort value="$form->{lastsort}">
306 #<input type=hidden name=bom value="$form->{bom}">
307 #<input type=hidden name=titel value="$form->{titel}">
308 #<input type=hidden name=searchitems value="$form->{searchitems}">
310 #<input type=hidden name=row value=$j>
312 #<input type=hidden name=nextsub value=item_selected>
314 #<input name=lastndx type=hidden value=$lastndx>
316 #<input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
320 # if (($form->{ndxs_counter}) > 0) {
321 # for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
323 # $partnumber = $form->{"totop100_partnumber_$i"};
324 # $description = $form->{"totop100_description_$i"};
325 # $unit = $form->{"totop100_unit_$i"};
326 # $sellprice = $form->{"totop100_sellprice_$i"};
327 # $soldtotal = $form->{"totop100_soldtotal_$i"};
330 #<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
331 #<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
332 #<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
333 #<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
334 #<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
342 #<input class=submit type=submit name=action value="|
343 # . $locale->text('TOP100') . qq|">
349 # $lxdebug->leave_sub();
353 $lxdebug->enter_sub();
355 $auth->assert('part_service_assembly_edit');
358 $form->{ndxs_counter}++;
360 if ($form->{ndxs_counter} > 0) {
362 my $index = $form->{ndx};
364 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
365 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
366 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
367 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
368 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
372 $lxdebug->leave_sub();
376 $lxdebug->enter_sub();
378 $auth->assert('part_service_assembly_edit');
380 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
381 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
382 my (@column_index, %column_header, %column_data);
383 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
385 $form->{top100} = "top100";
386 $form->{l_soldtotal} = "Y";
387 $form->{soldtotal} = "soldtotal";
388 $form->{sort} = "soldtotal";
389 $form->{l_qty} = "N";
390 $form->{l_linetotal} = "";
392 $form->{number} = "position";
393 $form->{l_number} = "Y";
397 $form->{title} = $locale->text('Top 100');
399 $revers = $form->{revers};
400 $lastsort = $form->{lastsort};
402 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
404 $form->{lastsort} = "partnumber";
405 $form->{sort} = "partnumber";
409 "$form->{script}?action=top100&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
410 . $form->escape($form->{title}, 1);
412 # if we have a serialnumber limit search
413 if ($form->{serialnumber} || $form->{l_serialnumber}) {
414 $form->{l_serialnumber} = "Y";
415 unless ( $form->{bought}
418 || $form->{quoted}) {
419 $form->{bought} = $form->{sold} = 1;
422 IC->all_parts(\%myconfig, \%$form);
424 if ($form->{itemstatus} eq 'active') {
425 $option .= $locale->text('Active') . " : ";
427 if ($form->{itemstatus} eq 'obsolete') {
428 $option .= $locale->text('Obsolete') . " : ";
430 if ($form->{itemstatus} eq 'orphaned') {
431 $option .= $locale->text('Orphaned') . " : ";
433 if ($form->{itemstatus} eq 'onhand') {
434 $option .= $locale->text('On Hand') . " : ";
435 $form->{l_onhand} = "Y";
437 if ($form->{itemstatus} eq 'short') {
438 $option .= $locale->text('Short') . " : ";
439 $form->{l_onhand} = "Y";
441 if ($form->{onorder}) {
442 $form->{l_ordnumber} = "Y";
443 $callback .= "&onorder=$form->{onorder}";
444 $option .= $locale->text('On Order') . " : ";
446 if ($form->{ordered}) {
447 $form->{l_ordnumber} = "Y";
448 $callback .= "&ordered=$form->{ordered}";
449 $option .= $locale->text('Ordered') . " : ";
452 $form->{l_quonumber} = "Y";
453 $callback .= "&rfq=$form->{rfq}";
454 $option .= $locale->text('RFQ') . " : ";
456 if ($form->{quoted}) {
457 $form->{l_quonumber} = "Y";
458 $callback .= ""ed=$form->{quoted}";
459 $option .= $locale->text('Quoted') . " : ";
461 if ($form->{bought}) {
462 $form->{l_invnumber} = "Y";
463 $callback .= "&bought=$form->{bought}";
464 $option .= $locale->text('Bought') . " : ";
467 $form->{l_invnumber} = "Y";
468 $callback .= "&sold=$form->{sold}";
469 $option .= $locale->text('Sold') . " : ";
476 || $form->{quoted}) {
478 $form->{l_lastcost} = "";
479 $form->{l_name} = "Y";
480 if ($form->{transdatefrom}) {
481 $callback .= "&transdatefrom=$form->{transdatefrom}";
483 . $locale->text('From')
485 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
487 if ($form->{transdateto}) {
488 $callback .= "&transdateto=$form->{transdateto}";
490 . $locale->text('To')
492 . $locale->date(\%myconfig, $form->{transdateto}, 1);
498 if ($form->{partnumber}) {
499 $callback .= "&partnumber=$form->{partnumber}";
500 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
503 $callback .= "&partnumber=$form->{ean}";
504 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
506 if ($form->{partsgroup}) {
507 $callback .= "&partsgroup=$form->{partsgroup}";
508 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
510 if ($form->{serialnumber}) {
511 $callback .= "&serialnumber=$form->{serialnumber}";
512 $option .= $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
514 if ($form->{description}) {
515 $callback .= "&description=$form->{description}";
516 $description = $form->{description};
517 $description =~ s/\n/<br>/g;
518 $option .= $locale->text('Part Description') . qq| : $form->{description}<br>|;
521 $callback .= "&make=$form->{make}";
522 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
524 if ($form->{model}) {
525 $callback .= "&model=$form->{model}";
526 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
528 if ($form->{drawing}) {
529 $callback .= "&drawing=$form->{drawing}";
530 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
532 if ($form->{microfiche}) {
533 $callback .= "µfiche=$form->{microfiche}";
534 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
536 if ($form->{l_soldtotal}) {
537 $callback .= "&soldtotal=$form->{soldtotal}";
538 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
541 my @columns = $form->sort_columns(
542 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)
545 if ($form->{l_linetotal}) {
546 $form->{l_onhand} = "Y";
547 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
548 if ($form->{l_lastcost}) {
549 $form->{l_linetotallastcost} = "Y";
550 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
551 $form->{l_linetotallastcost} = "";
554 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
557 if ($form->{searchitems} eq 'service') {
559 # remove bin, weight and rop from list
560 map { $form->{"l_$_"} = "" } qw(bin weight rop);
562 $form->{l_onhand} = "";
564 # qty is irrelevant unless bought or sold
570 || $form->{quoted}) {
571 $form->{l_onhand} = "Y";
573 $form->{l_linetotalsellprice} = "";
574 $form->{l_linetotallastcost} = "";
578 foreach my $item (@columns) {
579 if ($form->{"l_$item"} eq "Y") {
580 push @column_index, $item;
582 # add column to callback
583 $callback .= "&l_$item=Y";
587 if ($form->{l_subtotal} eq 'Y') {
588 $callback .= "&l_subtotal=Y";
591 $column_header{number} =
592 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
593 $column_header{partnumber} =
594 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
595 . $locale->text('Part Number')
597 $column_header{description} =
598 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
599 . $locale->text('Part Description')
601 $column_header{partsgroup} =
602 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
603 . $locale->text('Group')
605 $column_header{bin} =
606 qq|<th><a class=listheading href=$callback&sort=bin>|
607 . $locale->text('Bin')
609 $column_header{priceupdate} =
610 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
611 . $locale->text('Updated')
613 $column_header{onhand} =
614 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
615 . $locale->text('Qty')
617 $column_header{unit} =
618 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
619 $column_header{listprice} =
620 qq|<th class=listheading nowrap>|
621 . $locale->text('List Price')
623 $column_header{lastcost} =
624 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
625 $column_header{rop} =
626 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
627 $column_header{weight} =
628 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
630 $column_header{invnumber} =
631 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
632 . $locale->text('Invoice Number')
634 $column_header{ordnumber} =
635 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
636 . $locale->text('Order Number')
638 $column_header{quonumber} =
639 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
640 . $locale->text('Quotation')
643 $column_header{name} =
644 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
645 . $locale->text('Name')
648 $column_header{sellprice} =
649 qq|<th class=listheading nowrap>|
650 . $locale->text('Sell Price')
652 $column_header{linetotalsellprice} =
653 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
654 $column_header{linetotallastcost} =
655 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
656 $column_header{linetotallistprice} =
657 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
659 $column_header{image} =
660 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
661 $column_header{drawing} =
662 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
663 . $locale->text('Drawing')
665 $column_header{microfiche} =
666 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
667 . $locale->text('Microfiche')
670 $column_header{serialnumber} =
671 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
672 . $locale->text('Serial Number')
674 $column_header{soldtotal} =
675 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
676 . $locale->text('soldtotal')
680 my $colspan = $#column_index + 1;
687 <th class=listtop colspan=$colspan>$form->{title}</th>
691 <tr><td colspan=$colspan>$option</td></tr>
693 <tr class=listheading>
696 map { print "\n$column_header{$_}" } @column_index;
702 # add order to callback
703 $form->{callback} = $callback .= "&sort=$form->{sort}";
705 # escape callback for href
706 $callback = $form->escape($callback);
708 if (@{ $form->{parts} }) {
709 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
712 # insert numbers for top100
714 foreach my $ref (@{ $form->{parts} }) {
719 # if avaible -> insert choice here
720 if (($form->{ndxs_counter}) > 0) {
721 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
722 $partnumber = $form->{"totop100_partnumber_$i"};
723 $description = $form->{"totop100_description_$i"};
724 $unit = $form->{"totop100_unit_$i"};
725 $sellprice = $form->{"totop100_sellprice_$i"};
726 $soldtotal = $form->{"totop100_soldtotal_$i"};
729 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
730 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
731 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
732 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
733 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
737 push @{ $form->{parts} },
739 partnumber => "$partnumber",
740 description => "$description",
742 sellprice => "$sellprice",
743 soldtotal => "$soldtotal" };
746 # build data for columns
748 foreach my $ref (@{ $form->{parts} }) {
750 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
751 if ($sameitem ne $ref->{ $form->{sort} }) {
753 $sameitem = $ref->{ $form->{sort} };
757 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
758 $ref->{sellprice} *= $ref->{exchangerate};
759 $ref->{listprice} *= $ref->{exchangerate};
760 $ref->{lastcost} *= $ref->{exchangerate};
762 # use this for assemblies
763 $onhand = $ref->{onhand};
766 if ($ref->{assemblyitem}) {
768 $onhand = 0 if ($form->{sold});
771 $ref->{description} =~ s/\n/<br>/g;
773 $column_data{number} =
775 . $form->format_amount(\%myconfig, $ref->{number})
777 $column_data{partnumber} =
778 "<td align=$align>$ref->{partnumber} </a></td>";
779 $column_data{description} = "<td>$ref->{description} </td>";
780 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
782 $column_data{onhand} =
784 . $form->format_amount(\%myconfig, $ref->{onhand})
786 $column_data{sellprice} =
788 . $form->format_amount(\%myconfig, $ref->{sellprice})
790 $column_data{listprice} =
792 . $form->format_amount(\%myconfig, $ref->{listprice})
794 $column_data{lastcost} =
796 . $form->format_amount(\%myconfig, $ref->{lastcost})
799 $column_data{linetotalsellprice} = "<td align=right>"
800 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
802 $column_data{linetotallastcost} = "<td align=right>"
803 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
805 $column_data{linetotallistprice} = "<td align=right>"
806 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
809 if (!$ref->{assemblyitem}) {
810 $totalsellprice += $onhand * $ref->{sellprice};
811 $totallastcost += $onhand * $ref->{lastcost};
812 $totallistprice += $onhand * $ref->{listprice};
814 $subtotalonhand += $onhand;
815 $subtotalsellprice += $onhand * $ref->{sellprice};
816 $subtotallastcost += $onhand * $ref->{lastcost};
817 $subtotallistprice += $onhand * $ref->{listprice};
822 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
823 $column_data{weight} =
825 . $form->format_amount(\%myconfig, $ref->{weight})
827 $column_data{unit} = "<td>$ref->{unit} </td>";
828 $column_data{bin} = "<td>$ref->{bin} </td>";
829 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
831 $column_data{invnumber} =
832 ($ref->{module} ne 'oe')
833 ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&callback=$callback>$ref->{invnumber}</a></td>"
834 : "<td>$ref->{invnumber}</td>";
835 $column_data{ordnumber} =
836 ($ref->{module} eq 'oe')
837 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{ordnumber}</a></td>"
838 : "<td>$ref->{ordnumber}</td>";
839 $column_data{quonumber} =
840 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
841 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{quonumber}</a></td>"
842 : "<td>$ref->{quonumber}</td>";
844 $column_data{name} = "<td>$ref->{name}</td>";
846 $column_data{image} =
848 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
850 $column_data{drawing} =
852 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
854 $column_data{microfiche} =
856 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
859 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
861 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
865 print "<tr class=listrow$i>";
867 map { print "\n$column_data{$_}" } @column_index;
874 if ($form->{l_subtotal} eq 'Y') {
878 if ($form->{"l_linetotal"}) {
879 map { $column_data{$_} = "<td> </td>" } @column_index;
880 $column_data{linetotalsellprice} =
881 "<th class=listtotal align=right>"
882 . $form->format_amount(\%myconfig, $totalsellprice, 2)
884 $column_data{linetotallastcost} =
885 "<th class=listtotal align=right>"
886 . $form->format_amount(\%myconfig, $totallastcost, 2)
888 $column_data{linetotallistprice} =
889 "<th class=listtotal align=right>"
890 . $form->format_amount(\%myconfig, $totallistprice, 2)
893 print "<tr class=listtotal>";
895 map { print "\n$column_data{$_}" } @column_index;
902 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
911 <form method=post action=$form->{script}>
913 <input type=hidden name=itemstatus value="$form->{itemstatus}">
914 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
915 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
916 <input type=hidden name=l_description value="$form->{l_description}">
917 <input type=hidden name=l_onhand value="$form->{l_onhand}">
918 <input type=hidden name=l_unit value="$form->{l_unit}">
919 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
920 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
921 <input type=hidden name=sort value="$form->{sort}">
922 <input type=hidden name=revers value="$form->{revers}">
923 <input type=hidden name=lastsort value="$form->{lastsort}">
924 <input type=hidden name=parts value="$form->{parts}">
926 <input type=hidden name=bom value="$form->{bom}">
927 <input type=hidden name=titel value="$form->{titel}">
928 <input type=hidden name=searchitems value="$form->{searchitems}">|;
933 <!-- <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">-->
935 <input class=submit type=submit name=action value="|
936 . $locale->text('choice') . qq|">
944 $lxdebug->leave_sub();
949 # Warning, deep magic ahead.
950 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
952 # flags coming from the form:
954 # searchitems=part revers=0 lastsort=''
957 # partnumber ean description partsgroup serialnumber make model drawing microfiche
958 # transdatefrom transdateto
961 # itemstatus = active | onhand | short | obsolete | orphaned
962 # action = continue | top100
965 # bought sold onorder ordered rfq quoted
966 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
967 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
968 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
971 # nextsub revers lastsort sort ndxs_counter
973 sub generate_report {
974 $lxdebug->enter_sub();
976 $auth->assert('part_service_assembly_edit');
978 my ($revers, $lastsort, $description);
980 $form->{title} = (ucfirst $form->{searchitems}) . "s";
981 $form->{title} =~ s/ys$/ies/;
982 $form->{title} = $locale->text($form->{title});
984 my $revers = $form->{revers};
985 my $lastsort = $form->{lastsort};
987 # sorting and direction of sorting
988 # ToDO: change this to the simpler field+direction method
989 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
991 $form->{lastsort} = "partnumber";
992 $form->{sort} = "partnumber";
994 if ($form->{lastsort} eq $form->{sort}) {
995 $form->{revers} = 1 - $form->{revers};
998 $form->{lastsort} = $form->{sort};
1002 # special case if we have a serialnumber limit search
1003 # serialnumbers are only given in invoices and orders,
1004 # so they can only pop up in bought, sold, rfq, and quoted stuff
1005 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
1006 && !$form->{rfq} && !$form->{quoted}
1007 && ($form->{l_serialnumber} || $form->{serialnumber}));
1009 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1010 # if any of these are ticked the behavior changes slightly for lastcost
1011 # since all those are aggregation checks for the legder tables this is an internal switch
1012 # refered to as ledgerchecks
1013 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1014 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1016 # if something should be activated if something else is active, enter it here
1017 my %dependencies = (
1018 onhand => [ qw(l_onhand) ],
1019 short => [ qw(l_onhand) ],
1020 onorder => [ qw(l_ordnumber) ],
1021 ordered => [ qw(l_ordnumber) ],
1022 rfq => [ qw(l_quonumber) ],
1023 quoted => [ qw(l_quonumber) ],
1024 bought => [ qw(l_invnumber) ],
1025 sold => [ qw(l_invnumber) ],
1026 ledgerchecks => [ qw(l_name) ],
1027 serialnumber => [ qw(l_serialnumber) ],
1028 no_sn_joins => [ qw(bought sold) ],
1031 # these strings get displayed at the top of the results to indicate the user which switches were used
1033 active => $locale->text('Active'),
1034 obsolete => $locale->text('Obsolete'),
1035 orphaned => $locale->text('Orphaned'),
1036 onhand => $locale->text('On Hand'),
1037 short => $locale->text('Short'),
1038 onorder => $locale->text('On Order'),
1039 ordered => $locale->text('Ordered'),
1040 rfq => $locale->text('RFQ'),
1041 quoted => $locale->text('Quoted'),
1042 bought => $locale->text('Bought'),
1043 sold => $locale->text('Sold'),
1044 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1045 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1046 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1047 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1048 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1049 description => $locale->text('Part Description') . ": '$form->{description}'",
1050 make => $locale->text('Make') . ": '$form->{make}'",
1051 model => $locale->text('Model') . ": '$form->{model}'",
1052 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1053 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1054 l_soldtotal => $locale->text('soldtotal'),
1057 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1058 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1059 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1061 # calculate dependencies
1062 for (@itemstatus_keys, @callback_keys) {
1063 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1064 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1067 # generate callback and optionstrings
1069 for my $key (@itemstatus_keys, @callback_keys) {
1070 next if ($form->{itemstatus} ne $key && !$form->{$key});
1071 push @options, $optiontexts{$key};
1074 # special case for lastcost
1075 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1077 if ($form->{description}) {
1078 $description = $form->{description};
1079 $description =~ s/\n/<br>/g;
1082 if ($form->{l_linetotal}) {
1083 $form->{l_onhand} = "Y";
1084 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1085 if ($form->{l_lastcost}) {
1086 $form->{l_linetotallastcost} = "Y";
1087 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1088 $form->{l_linetotallastcost} = "";
1091 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1094 if ($form->{searchitems} eq 'service') {
1096 # remove bin, weight and rop from list
1097 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1099 $form->{l_onhand} = "";
1101 # qty is irrelevant unless bought or sold
1102 if ( $form->{bought}
1107 || $form->{quoted}) {
1108 $form->{l_onhand} = "Y";
1110 $form->{l_linetotalsellprice} = "";
1111 $form->{l_linetotallastcost} = "";
1115 IC->all_parts(\%myconfig, \%$form);
1118 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1119 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1122 'bin' => { 'text' => $locale->text('Bin'), },
1123 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1124 'description' => { 'text' => $locale->text('Part Description'), },
1125 'drawing' => { 'text' => $locale->text('Drawing'), },
1126 'image' => { 'text' => $locale->text('Image'), },
1127 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1128 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1129 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1130 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1131 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1132 'listprice' => { 'text' => $locale->text('List Price'), },
1133 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1134 'name' => { 'text' => $locale->text('Name'), },
1135 'onhand' => { 'text' => $locale->text('Qty'), },
1136 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1137 'partnumber' => { 'text' => $locale->text('Part Number'), },
1138 'partsgroup' => { 'text' => $locale->text('Group'), },
1139 'priceupdate' => { 'text' => $locale->text('Updated'), },
1140 'quonumber' => { 'text' => $locale->text('Quotation'), },
1141 'rop' => { 'text' => $locale->text('ROP'), },
1142 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1143 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1144 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1145 'unit' => { 'text' => $locale->text('Unit'), },
1146 'weight' => { 'text' => $locale->text('Weight'), },
1149 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1150 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1152 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1153 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1155 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1156 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1158 foreach my $col (@sort_full) {
1159 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1161 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1163 # add order to callback
1164 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1166 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1168 my %attachment_basenames = (
1169 'part' => $locale->text('part_list'),
1170 'service' => $locale->text('service_list'),
1171 'assembly' => $locale->text('assembly_list'),
1174 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1175 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1176 'output_format' => 'HTML',
1177 'title' => $form->{title},
1178 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1180 $report->set_options_from_form();
1182 $report->set_columns(%column_defs);
1183 $report->set_column_order(@columns);
1185 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1187 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1189 my @subtotal_columns = qw(sellprice listprice lastcost);
1190 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1191 my %totals = map { $_ => 0 } @subtotal_columns;
1193 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1195 my $defaults = AM->get_defaults();
1198 foreach my $ref (@{ $form->{parts} }) {
1200 # fresh row, for inserting later
1201 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1203 $ref->{exchangerate} ||= 1;
1204 $ref->{price_factor} ||= 1;
1205 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1206 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1207 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1209 # use this for assemblies
1210 my $onhand = $ref->{onhand};
1212 if ($ref->{assemblyitem}) {
1213 $row->{partnumber}{align} = 'right';
1214 $row->{onhand}{data} = 0;
1215 $onhand = 0 if ($form->{sold});
1218 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1219 $row->{partnumber}->{link} = $edit_link;
1220 $row->{description}->{link} = $edit_link;
1222 foreach (qw(sellprice listprice lastcost)) {
1223 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1224 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1227 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1229 $row->{weight}->{data} .= ' ' . $defaults->{weightunit};
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->{customer_id} ne '' ? 'sales_order' : 'purchase_order'), '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',
1468 'vendors' => 'ALL_VENDORS',);
1471 IC->retrieve_buchungsgruppen(\%myconfig, $form);
1472 @{ $form->{BUCHUNGSGRUPPEN} } = grep { $_->{id} eq $form->{buchungsgruppen_id} || ($form->{id} && $form->{orphaned}) || !$form->{id} } @{ $form->{BUCHUNGSGRUPPEN} };
1474 # use JavaScript Calendar or not (yes!)
1475 $form->{jsscript} = 1;
1477 $units = AM->retrieve_units(\%myconfig, $form);
1478 $form->{ALL_UNITS} = [ map +{ name => $_ }, sort { $units->{$a}{sortkey} <=> $units->{$b}{sortkey} } keys %$units ];
1480 $form->{defaults} = AM->get_defaults();
1482 $form->{fokus} = "ic.partnumber";
1485 #print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
1486 # ALL_UNITS => $form->{ALL_UNITS},
1487 # BUCHUNGSGRUPPEN => $form->{BUCHUNGSGRUPPEN},
1488 # payment_terms => $form->{payment_terms},
1489 # all_partsgroup => $form->{all_partsgroup}});
1490 print $form->parse_html_template('ic/form_header');
1491 $lxdebug->leave_sub();
1495 $lxdebug->enter_sub();
1497 $auth->assert('part_service_assembly_edit');
1499 print $form->parse_html_template('ic/form_footer');
1501 $lxdebug->leave_sub();
1505 $lxdebug->enter_sub();
1508 my @mm_data = grep { any { $_ ne '' } @$_{qw(make model)} } map +{ make => $form->{"make_$_"}, model => $form->{"model_$_"} }, 1 .. $numrows;
1509 delete @{$form}{grep { m/^make_\d+/ || m/^model_\d+/ } keys %{ $form }};
1510 print $form->parse_html_template('ic/makemodel', { MM_DATA => [ @mm_data, {} ], mm_rows => scalar @mm_data + 1 });
1512 $lxdebug->leave_sub();
1516 $lxdebug->enter_sub();
1518 my (@column_index, %column_data, %column_header);
1519 my ($nochange, $callback, $previousform, $linetotal, $href);
1521 our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
1524 qw(runningnumber qty unit bom partnumber description partsgroup lastcost total);
1526 if ($form->{previousform}) {
1528 @column_index = qw(qty unit bom partnumber description partsgroup total);
1532 $form->{old_callback} = $form->{callback};
1533 $callback = $form->{callback};
1534 $form->{callback} = "$form->{script}?action=display_form";
1537 map { delete $form->{$_} } qw(action header);
1541 # save form variables in a previousform variable
1542 foreach my $key (sort keys %$form) {
1543 next unless ref $form->{$key} eq '' && $form->{$key};
1544 next if $key =~ /^select/; # get rid of these stupid select things
1547 $form->{$key} =~ s/&/%26/g;
1548 $previousform .= qq|$key=$form->{$key}&|;
1551 $previousform = $form->escape($form->escape($previousform, 1));
1552 $form->{callback} = $callback;
1554 $form->{assemblytotal} = 0;
1555 $form->{assembly_purchase_price_total} = 0;
1556 $form->{weight} = 0;
1559 $column_header{runningnumber} =
1560 qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
1561 $column_header{qty} =
1562 qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
1563 $column_header{unit} =
1564 qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
1565 $column_header{partnumber} =
1566 qq|<th align=left nowrap width=20%>|
1567 . $locale->text('Part Number')
1569 $column_header{description} =
1570 qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
1571 $column_header{lastcost} =
1572 qq|<th nowrap width=50%>| . $locale->text('Purchase Price') . qq|</th>|;
1573 $column_header{total} =
1574 qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
1575 $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
1576 $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
1579 <tr class=listheading>
1580 <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
1588 map { print "\n$column_header{$_}" } @column_index;
1594 for my $i (1 .. $numrows) {
1595 $form->{"partnumber_$i"} =~ s/\"/"/g;
1598 $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} / ($form->{"price_factor_$i"} || 1), 2);
1599 $line_purchase_price =
1600 $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / ($form->{"price_factor_$i"} || 1), 2); #lastcost == purchase_price | ungenaue datenbankfeld-übersetzung
1601 $form->{assemblytotal} += $linetotal;
1602 $form->{assembly_purchase_price_total} += $line_purchase_price;
1604 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1606 $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
1607 $line_purchase_price = $form->format_amount(\%myconfig, $line_purchase_price, 2);
1609 if (($i >= 1) && ($i == $numrows)) {
1612 map { $column_data{$_} = qq|<td></td>| }
1613 qw(qty unit partnumber description bom partsgroup);
1616 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
1619 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1620 $column_data{partnumber} =
1621 qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
1622 $column_data{description} =
1623 qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
1624 $column_data{partsgroup} =
1625 qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
1631 if ($form->{previousform}) {
1632 $column_data{partnumber} =
1633 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
1635 qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
1638 qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
1639 $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
1640 $column_data{bom} .= qq|</td>|;
1642 $column_data{partsgroup} =
1643 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1647 qq|$form->{script}?action=edit&id=$form->{"id_$i"}&rowcount=$i&previousform=$previousform|;
1648 $column_data{partnumber} =
1649 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
1650 $column_data{runningnumber} =
1651 qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
1653 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1655 $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
1657 qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
1659 $column_data{partsgroup} =
1660 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1663 $column_data{unit} =
1664 qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
1665 $column_data{description} =
1666 qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
1669 $column_data{lastcost} = qq|<td align=right>$line_purchase_price</td>|;
1670 $column_data{total} = qq|<td align=right>$linetotal</td>|;
1672 $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
1677 map { print "\n$column_data{$_}" } @column_index;
1681 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
1682 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
1683 <input type=hidden name="lastcost_$i" value=$form->{"lastcost_$i"}>
1684 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
1685 <input type=hidden name="price_factor_id_$i" value=$form->{"price_factor_id_$i"}>
1686 <input type=hidden name="price_factor_$i" value=$form->{"price_factor_$i"}>
1696 $lxdebug->leave_sub();
1700 $lxdebug->enter_sub();
1702 if ($form->{item} eq "assembly") {
1703 my $i = $form->{assembly_rows};
1705 # if last row is empty check the form otherwise retrieve item
1706 if ( ($form->{"partnumber_$i"} eq "")
1707 && ($form->{"description_$i"} eq "")
1708 && ($form->{"partsgroup_$i"} eq "")) {
1714 IC->assembly_item(\%myconfig, \%$form);
1716 my $rows = scalar @{ $form->{item_list} };
1719 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1722 $form->{makemodel_rows}--;
1726 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1727 qw(partnumber description unit partsgroup);
1728 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1729 keys %{ $form->{item_list}[0] };
1730 $form->{"runningnumber_$i"} = $form->{assembly_rows};
1731 $form->{assembly_rows}++;
1739 $form->{rowcount} = $i;
1740 $form->{assembly_rows}++;
1747 } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
1751 $lxdebug->leave_sub();
1755 $lxdebug->enter_sub();
1757 $auth->assert('part_service_assembly_edit');
1759 my ($parts_id, %newform, $previousform, $amount, $callback);
1761 # check if there is a part number - commented out, cause there is an automatic allocation of numbers
1762 # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
1764 # check if there is a description
1765 $form->isblank("description", $locale->text("Part Description missing!"));
1767 if ($form->{obsolete}) {
1770 "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
1772 if ($form->{onhand} * 1);
1775 if (!$form->{buchungsgruppen_id}) {
1776 $form->error($locale->text("Parts must have an entry type.") . " " .
1777 $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.")
1781 $form->error($locale->text('Description must not be empty!')) unless $form->{description};
1782 $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
1785 $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
1786 if (IC->save(\%myconfig, \%$form) == 3) {
1787 $form->error($locale->text('Partnumber not unique!'));
1789 # saving the history
1790 if(!exists $form->{addition}) {
1791 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1792 $form->{addition} = "SAVED";
1793 $form->save_history($form->dbconnect(\%myconfig));
1795 # /saving the history
1796 $parts_id = $form->{id};
1799 # load previous variables
1800 if ($form->{previousform}) {
1802 # save the new form variables before splitting previousform
1803 map { $newform{$_} = $form->{$_} } keys %$form;
1805 $previousform = $form->unescape($form->{previousform});
1807 # don't trample on previous variables
1808 map { delete $form->{$_} } keys %newform;
1810 # now take it apart and restore original values
1811 foreach my $item (split /&/, $previousform) {
1812 my ($key, $value) = split m/=/, $item, 2;
1813 $value =~ s/%26/&/g;
1814 $form->{$key} = $value;
1816 $form->{taxaccounts} = $newform{taxaccount2};
1818 if ($form->{item} eq 'assembly') {
1820 # undo number formatting
1821 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1822 qw(weight listprice sellprice rop);
1824 $form->{assembly_rows}--;
1825 $i = $newform{rowcount};
1826 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1828 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
1829 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
1831 # change/add values for assembly item
1832 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
1834 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
1835 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
1839 # set values for last invoice/order item
1840 $i = $form->{rowcount};
1841 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1843 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
1845 $form->{"longdescription_$i"} = $newform{notes};
1847 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
1849 if ($form->{exchangerate} != 0) {
1850 $form->{"sellprice_$i"} /= $form->{exchangerate};
1853 $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
1855 map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
1856 chop $form->{"taxaccounts_$i"};
1857 foreach my $item (qw(description rate taxnumber)) {
1858 my $index = $form->{"taxaccounts_$i"} . "_$item";
1859 $form->{$index} = $newform{$index};
1862 # credit remaining calculation
1863 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
1865 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
1866 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1868 $form->{creditremaining} -= $amount;
1870 # redo number formatting, because invoice parse them!
1871 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
1874 $form->{"id_$i"} = $parts_id;
1876 # Get the actual price factor (not just the ID) for the marge calculation.
1877 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1878 foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
1879 next if ($pfac->{id} != $newform{price_factor_id});
1880 $form->{"marge_price_factor_$i"} = $pfac->{factor};
1883 delete $form->{ALL_PRICE_FACTORS};
1885 delete $form->{action};
1887 # restore original callback
1888 $callback = $form->unescape($form->{callback});
1889 $form->{callback} = $form->unescape($form->{old_callback});
1890 delete $form->{old_callback};
1892 $form->{makemodel_rows}--;
1894 # put callback together
1895 foreach my $key (keys %$form) {
1897 # do single escape for Apache 2.0
1898 my $value = $form->escape($form->{$key}, 1);
1899 $callback .= qq|&$key=$value|;
1901 $form->{callback} = $callback;
1903 $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
1908 $lxdebug->leave_sub();
1912 $lxdebug->enter_sub();
1914 $auth->assert('part_service_assembly_edit');
1916 # saving the history
1917 if(!exists $form->{addition}) {
1918 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1919 $form->{addition} = "SAVED AS NEW";
1920 $form->save_history($form->dbconnect(\%myconfig));
1922 # /saving the history
1924 if ($form->{"original_partnumber"} &&
1925 ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
1926 $form->{partnumber} = "";
1929 $lxdebug->leave_sub();
1933 $lxdebug->enter_sub();
1935 $auth->assert('part_service_assembly_edit');
1937 # saving the history
1938 if(!exists $form->{addition}) {
1939 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1940 $form->{addition} = "DELETED";
1941 $form->save_history($form->dbconnect(\%myconfig));
1943 # /saving the history
1944 my $rc = IC->delete(\%myconfig, \%$form);
1947 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
1948 $form->error($locale->text('Cannot delete item!'));
1950 $lxdebug->leave_sub();
1954 $lxdebug->enter_sub();
1956 $auth->assert('part_service_assembly_edit');
1961 pricegroup => $form->{"pricegroup_$_"},
1962 pricegroup_id => $form->{"pricegroup_id_$_"},
1963 price => $form->{"price_$_"},
1966 print $form->parse_html_template('ic/price_row', { PRICES => \@PRICES });
1968 $lxdebug->leave_sub();
1971 sub parts_language_selection {
1972 $lxdebug->enter_sub();
1974 $auth->assert('part_service_assembly_edit');
1978 my $languages = IC->retrieve_languages(\%myconfig, $form);
1980 if ($form->{language_values} ne "") {
1981 foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
1982 my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
1984 foreach my $language (@{ $languages }) {
1985 next unless ($language->{id} == $language_id);
1987 $language->{translation} = $translation;
1988 $language->{longdescription} = $longdescription;
1994 my @header_sort = qw(name longdescription);
1995 my %header_title = ( "name" => $locale->text("Name"),
1996 "longdescription" => $locale->text("Long Description"),
2000 map(+{ "column_title" => $header_title{$_},
2002 "callback" => $callback,
2006 $form->{"title"} = $locale->text("Language Values");
2008 print $form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
2009 "LANGUAGES" => $languages,
2010 "onload" => $onload });
2012 $lxdebug->leave_sub();
2015 sub continue { call_sub($form->{"nextsub"}); }