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 #======================================================================
35 use POSIX qw(strftime);
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";
58 $lxdebug->enter_sub();
60 $form->{title} = $locale->text('Add ' . ucfirst $form->{item});
63 "$form->{script}?action=add&item=$form->{item}&login=$form->{login}&password=$form->{password}"
64 unless $form->{callback};
66 $form->{"unit_changeable"} = 1;
68 IC->get_pricegroups(\%myconfig, \%$form);
72 $lxdebug->leave_sub();
76 $lxdebug->enter_sub();
78 # switch for backward sorting
81 # memory for which table was sort at last time
82 $form->{lastsort} = "";
84 # counter for added entries to top100
85 $form->{ndxs_counter} = 0;
87 # $locale->text('Parts')
88 # $locale->text('Services')
90 my $is_service = $form->{searchitems} eq 'service';
91 my $is_assembly = $form->{searchitems} eq 'assembly';
93 $form->{title} = (ucfirst $form->{searchitems}) . "s";
94 $form->{title} = $locale->text($form->{title});
95 $form->{title} = $locale->text('Assemblies') if $is_assembly;
97 $form->{jsscript} = 1;
101 print $form->parse_html_template('ic/search', { is_assembly => $is_assembly, is_service => $is_service, dateformat => $myconfig{dateformat} });
103 $lxdebug->leave_sub();
106 sub search_update_prices {
107 $lxdebug->enter_sub();
109 my ($onhand, $makemodel, $serialnumber, $l_serialnumber, $toplevel, $bought);
111 $form->{title} = $locale->text('Update prices');
112 IC->get_pricegroups(\%myconfig, \%$form);
114 # use JavaScript Calendar or not
115 # $form->{jsscript} = 1;
117 # if ($form->{jsscript}) {
119 # # with JavaScript Calendar
121 # <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>
122 # <td><input type=button name=transdatefrom id="trigger1" value=|
123 # . $locale->text('button') . qq|></td>
126 # <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>
127 # <td><input type=button name=transdateto name=transdateto id="trigger2" value=|
128 # . $locale->text('button') . qq|></td>
133 # Form->write_trigger(\%myconfig, "2", "transdatefrom", "BL", "trigger1",
134 # "transdateto", "BL", "trigger2");
137 # # without JavaScript Calendar
139 # <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
141 # <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
145 <input name=itemstatus class=radio type=radio value=onhand> |
146 . $locale->text('On Hand') . qq|
147 <input name=itemstatus class=radio type=radio value=short> |
148 . $locale->text('Short') . qq|
153 <th align=right nowrap>| . $locale->text('Make') . qq|</th>
154 <td><input name=make size=20></td>
155 <th align=right nowrap>| . $locale->text('Model') . qq|</th>
156 <td><input name=model size=20></td>
161 <th align=right nowrap>| . $locale->text('Serial Number') . qq|</th>
162 <td><input name=serialnumber size=20></td>
165 $l_serialnumber = qq|
166 <td><input name=l_serialnumber class=checkbox type=checkbox value=Y> |
167 . $locale->text('Serial Number') . qq|</td>
177 <form method=post action=$form->{script}>
179 <input type=hidden name=title value="$form->{title}">
182 <tr><th class=listtop>$form->{title}</th></tr>
188 <th align=right nowrap>| . $locale->text('Part Number') . qq|</th>
189 <td><input name=partnumber size=20></td>
192 <th align=right nowrap>|
193 . $locale->text('Part Description') . qq|</th>
194 <td colspan=3><input name=description size=40></td>
197 <th align=right nowrap>| . $locale->text('Group') . qq|</th>
198 <td><input name=partsgroup size=20></td>
203 <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
204 <td><input name=drawing size=20></td>
205 <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
206 <td><input name=microfiche size=20></td>
212 <input name=itemstatus class=radio type=radio value=active checked> |
213 . $locale->text('Active') . qq|
215 <input name=itemstatus class=radio type=radio value=obsolete> |
216 . $locale->text('Obsolete') . qq|
217 <input name=itemstatus class=radio type=radio value=orphaned> |
218 . $locale->text('Orphaned') . qq|
233 <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
234 <th class="listheading">| . $locale->text('Preis') . qq|</th>
235 <th class="listheading">| . $locale->text('Prozentual/Absolut') . qq|</th>
238 <td>| . $locale->text('Sell Price') . qq|</td>
239 <td><input name="sellprice" size=11 value="$form->{"sellprice"}"></td>
240 <td><input name="sellprice_type" class=radio type=radio value=percent checked>/<input name="sellprice_type" class=radio type=radio value=absolut></td>
243 <td>| . $locale->text('List Price') . qq|</td>
244 <td><input name="listprice" size=11 value="$form->{"listprice"}"></td>
245 <td><input name="listprice_type" class=radio type=radio value=percent checked>/<input name="listprice_type" class=radio type=radio value=absolut></td>
248 for my $i (1 .. $form->{price_rows}) {
251 <td width=50%><input type=hidden name="pricegroup_$i" size=30 value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
252 <td width=50%><input name="price_$i" size=11></td>
253 <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
254 <td><input name="pricegroup_type_$i" class=radio type=radio value=percent checked>/<input name="pricegroup_type_$i" class=radio type=radio value=absolut></td>
264 <tr><td colspan=4><hr size=3 noshade></td></tr>
266 <input type=hidden name=nextsub value=confirm_price_update>
267 <input type=hidden name=price_rows value=$form->{price_rows}>
269 <input type=hidden name=login value=$form->{login}>
270 <input type=hidden name=password value=$form->{password}>
273 <input class=submit type=submit name=action value="|
274 . $locale->text('Continue') . qq|">
280 $lxdebug->leave_sub();
283 sub confirm_price_update {
284 $lxdebug->enter_sub();
287 $form->{nextsub} = "update_prices";
293 <form method=post action=$form->{script}>
296 # delete action variable
297 map { delete $form->{$_} } qw(action header);
299 foreach my $key (keys %$form) {
300 $form->{$key} =~ s/\"/"/g;
301 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
305 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
308 . $locale->text('Are you sure you want to update the prices')
312 <input name=action class=submit type=submit value="|
313 . $locale->text('Continue') . qq|">
317 $lxdebug->leave_sub();
321 $lxdebug->enter_sub();
323 if (IC->update_prices(\%myconfig, \%$form)) {
324 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
326 $form->error($locale->text('Could not update prices!'));
329 $lxdebug->leave_sub();
333 $lxdebug->enter_sub();
338 $form->{title} = $locale->text('Top 100 hinzufuegen');
345 <form method=post action=$form->{script}>
347 <input type=hidden name=searchitems value=$form->{searchitems}>
348 <input type=hidden name=title value="$form->{title}">
350 <input type=hidden name=revers value="$form->{revers}">
351 <input type=hidden name=lastsort value="$form->{lastsort}">|;
355 <tr class=listheading>
356 <th class=listheading nowrap>| . $locale->text('Part Number') . qq|</th>
357 <th class=listheading nowrap>| . $locale->text('Part Description') . qq|</th>
360 <td><input type=text name=partnumber size=20 value=></td>
361 <td><input type=text name=description size=30 value=></td>
368 <input type=hidden name=login value=$form->{login}>
369 <input type=hidden name=password value=$form->{password}>
371 <input type=hidden name=itemstatus value="$form->{itemstatus}">
372 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
373 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
374 <input type=hidden name=l_description value="$form->{l_description}">
375 <input type=hidden name=l_onhand value="$form->{l_onhand}">
376 <input type=hidden name=l_unit value="$form->{l_unit}">
377 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
378 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
379 <input type=hidden name=sort value="$form->{sort}">
380 <input type=hidden name=revers value="$form->{revers}">
381 <input type=hidden name=lastsort value="$form->{lastsort}">
383 <input type=hidden name=bom value="$form->{bom}">
384 <input type=hidden name=titel value="$form->{titel}">
385 <input type=hidden name=searchitems value="$form->{searchitems}">
387 <input type=hidden name=row value=$j>
389 <input type=hidden name=nextsub value=item_selected>
391 <input type=hidden name=test value=item_selected>
393 <input name=lastndx type=hidden value=$lastndx>
395 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>
397 <input name=extras type=hidden value=$form->{extras}>|;
399 my ($partnumber, $description, $unit, $sellprice, $soldtotal);
402 for (my $i = 0; $i < $form->{ndxs_counter}; $i++) {
405 $partnumber = $form->{"totop100_partnumber_$j"};
406 $description = $form->{"totop100_description_$j"};
407 $unit = $form->{"totop100_unit_$j"};
408 $sellprice = $form->{"totop100_sellprice_$j"};
409 $soldtotal = $form->{"totop100_soldtotal_$j"};
411 # insert data into top100
412 push @{ $form->{parts} },
414 partnumber => "$partnumber",
415 description => "$description",
417 sellprice => "$sellprice",
418 soldtotal => "$soldtotal" };
424 # set data for next page
425 if (($form->{ndxs_counter}) > 0) {
426 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
427 $partnumber = $form->{"totop100_partnumber_$i"};
428 $description = $form->{"totop100_description_$i"};
429 $unit = $form->{"totop100_unit_$i"};
430 $sellprice = $form->{"totop100_sellprice_$i"};
431 $soldtotal = $form->{"totop100_soldtotal_$i"};
434 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
435 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
436 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
437 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
438 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
446 <input class=submit type=submit name=action value="|
447 . $locale->text('list') . qq|">
452 $lxdebug->leave_sub();
456 $lxdebug->enter_sub();
459 our ($partnumber, $description, $unit, $sellprice, $soldtotal);
461 my @sortorders = ("", "partnumber", "description", "all");
462 my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
463 IC->get_parts(\%myconfig, \%$form, $sortorder);
465 $form->{title} = $locale->text('Top 100 hinzufuegen');
471 <form method=post action=ic.pl>
474 <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
477 <tr class=listheading>
479 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
480 <th class=listheading>| . $locale->text('Part Description') . qq|</th>
481 <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
482 <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
483 <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
487 my $i = $form->{rows};
489 for ($j = 1; $j <= $i; $j++) {
492 <tr class=listrow1>|;
495 <td><input name=ndx class=radio type=radio value=$j checked></td>|;
498 <td><input name=ndx class=radio type=radio value=$j></td>|;
501 <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
502 <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
503 <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
504 <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
505 <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
508 <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
518 <input type=hidden name=login value=$form->{login}>
519 <input type=hidden name=password value=$form->{password}>
521 <input type=hidden name=itemstatus value="$form->{itemstatus}">
522 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
523 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
524 <input type=hidden name=l_description value="$form->{l_description}">
525 <input type=hidden name=l_onhand value="$form->{l_onhand}">
526 <input type=hidden name=l_unit value="$form->{l_unit}">
527 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
528 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
529 <input type=hidden name=sort value="$form->{sort}">
530 <input type=hidden name=revers value="$form->{revers}">
531 <input type=hidden name=lastsort value="$form->{lastsort}">
533 <input type=hidden name=bom value="$form->{bom}">
534 <input type=hidden name=titel value="$form->{titel}">
535 <input type=hidden name=searchitems value="$form->{searchitems}">
537 <input type=hidden name=row value=$j>
539 <input type=hidden name=nextsub value=item_selected>
541 <input name=lastndx type=hidden value=$lastndx>
543 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
547 if (($form->{ndxs_counter}) > 0) {
548 for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
550 $partnumber = $form->{"totop100_partnumber_$i"};
551 $description = $form->{"totop100_description_$i"};
552 $unit = $form->{"totop100_unit_$i"};
553 $sellprice = $form->{"totop100_sellprice_$i"};
554 $soldtotal = $form->{"totop100_soldtotal_$i"};
557 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
558 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
559 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
560 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
561 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
569 <input class=submit type=submit name=action value="|
570 . $locale->text('TOP100') . qq|">
576 $lxdebug->leave_sub();
580 $lxdebug->enter_sub();
583 $form->{ndxs_counter}++;
585 if ($form->{ndxs_counter} > 0) {
587 my $index = $form->{ndx};
589 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
590 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
591 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
592 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
593 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
597 $lxdebug->leave_sub();
601 $lxdebug->enter_sub();
603 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
604 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
605 my (@column_index, %column_header, %column_data);
606 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
608 $form->{top100} = "top100";
609 $form->{l_soldtotal} = "Y";
610 $form->{soldtotal} = "soldtotal";
611 $form->{sort} = "soldtotal";
612 $form->{l_qty} = "N";
613 $form->{l_linetotal} = "";
615 $form->{number} = "position";
616 $form->{l_number} = "Y";
620 $form->{title} = $locale->text('Top 100');
622 $revers = $form->{revers};
623 $lastsort = $form->{lastsort};
625 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
627 $form->{lastsort} = "partnumber";
628 $form->{sort} = "partnumber";
632 "$form->{script}?action=top100&login=$form->{login}&password=$form->{password}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
633 . $form->escape($form->{title}, 1);
635 # if we have a serialnumber limit search
636 if ($form->{serialnumber} || $form->{l_serialnumber}) {
637 $form->{l_serialnumber} = "Y";
638 unless ( $form->{bought}
641 || $form->{quoted}) {
642 $form->{bought} = $form->{sold} = 1;
645 IC->all_parts(\%myconfig, \%$form);
647 if ($form->{itemstatus} eq 'active') {
648 $option .= $locale->text('Active') . " : ";
650 if ($form->{itemstatus} eq 'obsolete') {
651 $option .= $locale->text('Obsolete') . " : ";
653 if ($form->{itemstatus} eq 'orphaned') {
654 $option .= $locale->text('Orphaned') . " : ";
656 if ($form->{itemstatus} eq 'onhand') {
657 $option .= $locale->text('On Hand') . " : ";
658 $form->{l_onhand} = "Y";
660 if ($form->{itemstatus} eq 'short') {
661 $option .= $locale->text('Short') . " : ";
662 $form->{l_onhand} = "Y";
664 if ($form->{onorder}) {
665 $form->{l_ordnumber} = "Y";
666 $callback .= "&onorder=$form->{onorder}";
667 $option .= $locale->text('On Order') . " : ";
669 if ($form->{ordered}) {
670 $form->{l_ordnumber} = "Y";
671 $callback .= "&ordered=$form->{ordered}";
672 $option .= $locale->text('Ordered') . " : ";
675 $form->{l_quonumber} = "Y";
676 $callback .= "&rfq=$form->{rfq}";
677 $option .= $locale->text('RFQ') . " : ";
679 if ($form->{quoted}) {
680 $form->{l_quonumber} = "Y";
681 $callback .= ""ed=$form->{quoted}";
682 $option .= $locale->text('Quoted') . " : ";
684 if ($form->{bought}) {
685 $form->{l_invnumber} = "Y";
686 $callback .= "&bought=$form->{bought}";
687 $option .= $locale->text('Bought') . " : ";
690 $form->{l_invnumber} = "Y";
691 $callback .= "&sold=$form->{sold}";
692 $option .= $locale->text('Sold') . " : ";
699 || $form->{quoted}) {
701 $form->{l_lastcost} = "";
702 $form->{l_name} = "Y";
703 if ($form->{transdatefrom}) {
704 $callback .= "&transdatefrom=$form->{transdatefrom}";
706 . $locale->text('From')
708 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
710 if ($form->{transdateto}) {
711 $callback .= "&transdateto=$form->{transdateto}";
713 . $locale->text('To')
715 . $locale->date(\%myconfig, $form->{transdateto}, 1);
721 if ($form->{partnumber}) {
722 $callback .= "&partnumber=$form->{partnumber}";
723 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
726 $callback .= "&partnumber=$form->{ean}";
727 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
729 if ($form->{partsgroup}) {
730 $callback .= "&partsgroup=$form->{partsgroup}";
731 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
733 if ($form->{serialnumber}) {
734 $callback .= "&serialnumber=$form->{serialnumber}";
736 $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
738 if ($form->{description}) {
739 $callback .= "&description=$form->{description}";
740 $description = $form->{description};
744 $locale->text('Part Description') . qq| : $form->{description}<br>|;
747 $callback .= "&make=$form->{make}";
748 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
750 if ($form->{model}) {
751 $callback .= "&model=$form->{model}";
752 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
754 if ($form->{drawing}) {
755 $callback .= "&drawing=$form->{drawing}";
756 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
758 if ($form->{microfiche}) {
759 $callback .= "µfiche=$form->{microfiche}";
760 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
762 if ($form->{l_soldtotal}) {
763 $callback .= "&soldtotal=$form->{soldtotal}";
764 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
767 my @columns = $form->sort_columns(
768 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)
771 if ($form->{l_linetotal}) {
772 $form->{l_onhand} = "Y";
773 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
774 if ($form->{l_lastcost}) {
775 $form->{l_linetotallastcost} = "Y";
776 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
777 $form->{l_linetotallastcost} = "";
780 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
783 if ($form->{searchitems} eq 'service') {
785 # remove bin, weight and rop from list
786 map { $form->{"l_$_"} = "" } qw(bin weight rop);
788 $form->{l_onhand} = "";
790 # qty is irrelevant unless bought or sold
796 || $form->{quoted}) {
797 $form->{l_onhand} = "Y";
799 $form->{l_linetotalsellprice} = "";
800 $form->{l_linetotallastcost} = "";
804 $form->{l_lastcost} = ""
805 if ($form->{searchitems} eq 'assembly' && !$form->{bom});
807 foreach my $item (@columns) {
808 if ($form->{"l_$item"} eq "Y") {
809 push @column_index, $item;
811 # add column to callback
812 $callback .= "&l_$item=Y";
816 if ($form->{l_subtotal} eq 'Y') {
817 $callback .= "&l_subtotal=Y";
820 $column_header{number} =
821 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
822 $column_header{partnumber} =
823 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
824 . $locale->text('Part Number')
826 $column_header{description} =
827 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
828 . $locale->text('Part Description')
830 $column_header{partsgroup} =
831 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
832 . $locale->text('Group')
834 $column_header{bin} =
835 qq|<th><a class=listheading href=$callback&sort=bin>|
836 . $locale->text('Bin')
838 $column_header{priceupdate} =
839 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
840 . $locale->text('Updated')
842 $column_header{onhand} =
843 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
844 . $locale->text('Qty')
846 $column_header{unit} =
847 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
848 $column_header{listprice} =
849 qq|<th class=listheading nowrap>|
850 . $locale->text('List Price')
852 $column_header{lastcost} =
853 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
854 $column_header{rop} =
855 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
856 $column_header{weight} =
857 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
859 $column_header{invnumber} =
860 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
861 . $locale->text('Invoice Number')
863 $column_header{ordnumber} =
864 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
865 . $locale->text('Order Number')
867 $column_header{quonumber} =
868 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
869 . $locale->text('Quotation')
872 $column_header{name} =
873 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
874 . $locale->text('Name')
877 $column_header{sellprice} =
878 qq|<th class=listheading nowrap>|
879 . $locale->text('Sell Price')
881 $column_header{linetotalsellprice} =
882 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
883 $column_header{linetotallastcost} =
884 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
885 $column_header{linetotallistprice} =
886 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
888 $column_header{image} =
889 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
890 $column_header{drawing} =
891 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
892 . $locale->text('Drawing')
894 $column_header{microfiche} =
895 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
896 . $locale->text('Microfiche')
899 $column_header{serialnumber} =
900 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
901 . $locale->text('Serial Number')
903 $column_header{soldtotal} =
904 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
905 . $locale->text('soldtotal')
909 my $colspan = $#column_index + 1;
916 <th class=listtop colspan=$colspan>$form->{title}</th>
920 <tr><td colspan=$colspan>$option</td></tr>
922 <tr class=listheading>
925 map { print "\n$column_header{$_}" } @column_index;
931 # add order to callback
932 $form->{callback} = $callback .= "&sort=$form->{sort}";
934 # escape callback for href
935 $callback = $form->escape($callback);
937 if (@{ $form->{parts} }) {
938 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
941 # insert numbers for top100
943 foreach my $ref (@{ $form->{parts} }) {
948 # if avaible -> insert choice here
949 if (($form->{ndxs_counter}) > 0) {
950 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
951 $partnumber = $form->{"totop100_partnumber_$i"};
952 $description = $form->{"totop100_description_$i"};
953 $unit = $form->{"totop100_unit_$i"};
954 $sellprice = $form->{"totop100_sellprice_$i"};
955 $soldtotal = $form->{"totop100_soldtotal_$i"};
958 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
959 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
960 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
961 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
962 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
966 push @{ $form->{parts} },
968 partnumber => "$partnumber",
969 description => "$description",
971 sellprice => "$sellprice",
972 soldtotal => "$soldtotal" };
975 # build data for columns
976 foreach my $ref (@{ $form->{parts} }) {
979 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
980 if ($sameitem ne $ref->{ $form->{sort} }) {
982 $sameitem = $ref->{ $form->{sort} };
986 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
987 $ref->{sellprice} *= $ref->{exchangerate};
988 $ref->{listprice} *= $ref->{exchangerate};
989 $ref->{lastcost} *= $ref->{exchangerate};
991 # use this for assemblies
992 $onhand = $ref->{onhand};
995 if ($ref->{assemblyitem}) {
997 $onhand = 0 if ($form->{sold});
1000 $ref->{description} =~ s/
1003 $column_data{number} =
1005 . $form->format_amount(\%myconfig, $ref->{number})
1007 $column_data{partnumber} =
1008 "<td align=$align>$ref->{partnumber} </a></td>";
1009 $column_data{description} = "<td>$ref->{description} </td>";
1010 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
1012 $column_data{onhand} =
1014 . $form->format_amount(\%myconfig, $ref->{onhand})
1016 $column_data{sellprice} =
1018 . $form->format_amount(\%myconfig, $ref->{sellprice})
1020 $column_data{listprice} =
1022 . $form->format_amount(\%myconfig, $ref->{listprice})
1024 $column_data{lastcost} =
1026 . $form->format_amount(\%myconfig, $ref->{lastcost})
1029 $column_data{linetotalsellprice} = "<td align=right>"
1030 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
1032 $column_data{linetotallastcost} = "<td align=right>"
1033 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
1035 $column_data{linetotallistprice} = "<td align=right>"
1036 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
1039 if (!$ref->{assemblyitem}) {
1040 $totalsellprice += $onhand * $ref->{sellprice};
1041 $totallastcost += $onhand * $ref->{lastcost};
1042 $totallistprice += $onhand * $ref->{listprice};
1044 $subtotalonhand += $onhand;
1045 $subtotalsellprice += $onhand * $ref->{sellprice};
1046 $subtotallastcost += $onhand * $ref->{lastcost};
1047 $subtotallistprice += $onhand * $ref->{listprice};
1052 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
1053 $column_data{weight} =
1055 . $form->format_amount(\%myconfig, $ref->{weight})
1057 $column_data{unit} = "<td>$ref->{unit} </td>";
1058 $column_data{bin} = "<td>$ref->{bin} </td>";
1059 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
1061 $column_data{invnumber} =
1062 ($ref->{module} ne 'oe')
1063 ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>"
1064 : "<td>$ref->{invnumber}</td>";
1065 $column_data{ordnumber} =
1066 ($ref->{module} eq 'oe')
1067 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}</a></td>"
1068 : "<td>$ref->{ordnumber}</td>";
1069 $column_data{quonumber} =
1070 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
1071 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}</a></td>"
1072 : "<td>$ref->{quonumber}</td>";
1074 $column_data{name} = "<td>$ref->{name}</td>";
1076 $column_data{image} =
1078 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
1079 : "<td> </td>";
1080 $column_data{drawing} =
1082 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
1083 : "<td> </td>";
1084 $column_data{microfiche} =
1085 ($ref->{microfiche})
1086 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
1087 : "<td> </td>";
1089 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
1091 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
1095 print "<tr class=listrow$i>";
1097 map { print "\n$column_data{$_}" } @column_index;
1104 if ($form->{l_subtotal} eq 'Y') {
1108 if ($form->{"l_linetotal"}) {
1109 map { $column_data{$_} = "<td> </td>" } @column_index;
1110 $column_data{linetotalsellprice} =
1111 "<th class=listtotal align=right>"
1112 . $form->format_amount(\%myconfig, $totalsellprice, 2)
1114 $column_data{linetotallastcost} =
1115 "<th class=listtotal align=right>"
1116 . $form->format_amount(\%myconfig, $totallastcost, 2)
1118 $column_data{linetotallistprice} =
1119 "<th class=listtotal align=right>"
1120 . $form->format_amount(\%myconfig, $totallistprice, 2)
1123 print "<tr class=listtotal>";
1125 map { print "\n$column_data{$_}" } @column_index;
1132 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
1141 <form method=post action=$form->{script}>
1143 <input type=hidden name=login value=$form->{login}>
1144 <input type=hidden name=password value=$form->{password}>
1146 <input type=hidden name=itemstatus value="$form->{itemstatus}">
1147 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
1148 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
1149 <input type=hidden name=l_description value="$form->{l_description}">
1150 <input type=hidden name=l_onhand value="$form->{l_onhand}">
1151 <input type=hidden name=l_unit value="$form->{l_unit}">
1152 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
1153 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
1154 <input type=hidden name=sort value="$form->{sort}">
1155 <input type=hidden name=revers value="$form->{revers}">
1156 <input type=hidden name=lastsort value="$form->{lastsort}">
1157 <input type=hidden name=parts value="$form->{parts}">
1159 <input type=hidden name=bom value="$form->{bom}">
1160 <input type=hidden name=titel value="$form->{titel}">
1161 <input type=hidden name=searchitems value="$form->{searchitems}">|;
1166 <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
1168 <input class=submit type=submit name=action value="|
1169 . $locale->text('choice') . qq|">
1177 $lxdebug->leave_sub();
1182 # Warning, deep magic ahead.
1183 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
1185 # flags coming from the form:
1187 # searchitems=part revers=0 lastsort=''
1190 # partnumber ean description partsgroup serialnumber make model drawing microfiche
1191 # transdatefrom transdateto
1194 # itemstatus = active | onhand | short | obsolete | orphaned
1195 # action = continue | top100
1198 # bought sold onorder ordered rfq quoted
1199 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
1200 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
1201 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
1204 # nextsub login password revers lastsort sort ndxs_counter
1206 sub generate_report {
1207 $lxdebug->enter_sub();
1209 my ($revers, $lastsort, $description);
1211 $form->{title} = (ucfirst $form->{searchitems}) . "s";
1212 $form->{title} = $locale->text($form->{title});
1214 my $revers = $form->{revers};
1215 my $lastsort = $form->{lastsort};
1217 # sorting and direction of sorting
1218 # ToDO: change this to the simpler field+direction method
1219 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
1220 $form->{revers} = 0;
1221 $form->{lastsort} = "partnumber";
1222 $form->{sort} = "partnumber";
1224 if ($form->{lastsort} eq $form->{sort}) {
1225 $form->{revers} = 1 - $form->{revers};
1227 $form->{revers} = 0;
1228 $form->{lastsort} = $form->{sort};
1232 # special case if we have a serialnumber limit search
1233 # serialnumbers are only given in invoices and orders,
1234 # so they can only pop up in bought, sold, rfq, and quoted stuff
1235 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
1236 && !$form->{rfq} && !$form->{quoted}
1237 && ($form->{l_serialnumber} || $form->{serialnumber}));
1239 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1240 # if any of these are ticked the behavior changes slightly for lastcost
1241 # since all those are aggregation checks for the legder tables this is an internal switch
1242 # refered to as ledgerchecks
1243 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1244 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1246 # if something should be activated if something else is active, enter it here
1247 my %dependencies = (
1248 onhand => [ qw(l_onhand) ],
1249 short => [ qw(l_onhand) ],
1250 onorder => [ qw(l_ordnumber) ],
1251 ordered => [ qw(l_ordnumber) ],
1252 rfq => [ qw(l_quonumber) ],
1253 quoted => [ qw(l_quonumber) ],
1254 bought => [ qw(l_invnumber) ],
1255 sold => [ qw(l_invnumber) ],
1256 ledgerchecks => [ qw(l_name) ],
1257 serialnumber => [ qw(l_serialnumber) ],
1258 no_sn_joins => [ qw(bought sold) ],
1261 # these strings get displayed at the top of the results to indicate the user which switches were used
1263 active => $locale->text('Active'),
1264 obsolete => $locale->text('Obsolete'),
1265 orphaned => $locale->text('Orphaned'),
1266 onhand => $locale->text('On Hand'),
1267 short => $locale->text('Short'),
1268 onorder => $locale->text('On Order'),
1269 ordered => $locale->text('Ordered'),
1270 rfq => $locale->text('RFQ'),
1271 quoted => $locale->text('Quoted'),
1272 bought => $locale->text('Bought'),
1273 sold => $locale->text('Sold'),
1274 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1275 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1276 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1277 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1278 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1279 description => $locale->text('Part Description') . ": '$form->{description}'",
1280 make => $locale->text('Make') . ": '$form->{make}'",
1281 model => $locale->text('Model') . ": '$form->{model}'",
1282 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1283 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1284 l_soldtotal => $locale->text('soldtotal'),
1287 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1288 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1289 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1291 # calculate dependencies
1292 for (@itemstatus_keys, @callback_keys) {
1293 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1294 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1297 # generate callback and optionstrings
1299 for my $key (@itemstatus_keys, @callback_keys) {
1300 next if ($form->{itemstatus} ne $key && !$form->{$key});
1301 push @options, $optiontexts{$key};
1304 # special case for lastcost
1305 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1307 if ($form->{description}) {
1308 $description = $form->{description};
1309 $description =~ s/\n/<br>/g;
1312 if ($form->{l_linetotal}) {
1313 $form->{l_onhand} = "Y";
1314 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1315 if ($form->{l_lastcost}) {
1316 $form->{l_linetotallastcost} = "Y";
1317 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1318 $form->{l_linetotallastcost} = "";
1321 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1324 if ($form->{searchitems} eq 'service') {
1326 # remove bin, weight and rop from list
1327 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1329 $form->{l_onhand} = "";
1331 # qty is irrelevant unless bought or sold
1332 if ( $form->{bought}
1337 || $form->{quoted}) {
1338 $form->{l_onhand} = "Y";
1340 $form->{l_linetotalsellprice} = "";
1341 $form->{l_linetotallastcost} = "";
1345 $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1347 IC->all_parts(\%myconfig, \%$form);
1350 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1351 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1354 'bin' => { 'text' => $locale->text('Bin'), },
1355 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1356 'description' => { 'text' => $locale->text('Part Description'), },
1357 'drawing' => { 'text' => $locale->text('Drawing'), },
1358 'image' => { 'text' => $locale->text('Image'), },
1359 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1360 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1361 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1362 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1363 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1364 'listprice' => { 'text' => $locale->text('List Price'), },
1365 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1366 'name' => { 'text' => $locale->text('Name'), },
1367 'onhand' => { 'text' => $locale->text('Qty'), },
1368 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1369 'partnumber' => { 'text' => $locale->text('Part Number'), },
1370 'partsgroup' => { 'text' => $locale->text('Group'), },
1371 'priceupdate' => { 'text' => $locale->text('Updated'), },
1372 'quonumber' => { 'text' => $locale->text('Quotation'), },
1373 'rop' => { 'text' => $locale->text('ROP'), },
1374 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1375 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1376 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1377 'unit' => { 'text' => $locale->text('Unit'), },
1378 'weight' => { 'text' => $locale->text('Weight'), },
1381 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1382 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1384 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1385 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1387 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1388 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1390 foreach my $col (@sort_full) {
1391 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1393 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1395 # add order to callback
1396 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1398 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1400 my %attachment_basenames = (
1401 'part' => $locale->text('part_list'),
1402 'service' => $locale->text('service_list'),
1403 'assembly' => $locale->text('assembly_list'),
1406 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1407 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1408 'output_format' => 'HTML',
1409 'title' => $form->{title},
1410 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1412 $report->set_options_from_form();
1414 $report->set_columns(%column_defs);
1415 $report->set_column_order(@columns);
1417 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1419 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1421 my @subtotal_columns = qw(sellprice listprice lastcost);
1422 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1423 my %totals = map { $_ => 0 } @subtotal_columns;
1425 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1428 foreach my $ref (@{ $form->{parts} }) {
1430 # fresh row, for inserting later
1431 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1433 $ref->{exchangerate} ||= 1;
1434 $ref->{price_factor} ||= 1;
1435 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1436 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1437 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1439 # use this for assemblies
1440 my $onhand = $ref->{onhand};
1442 if ($ref->{assemblyitem}) {
1443 $row->{partnumber}{align} = 'right';
1444 $row->{onhand}{data} = 0;
1445 $onhand = 0 if ($form->{sold});
1448 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1449 $row->{partnumber}->{link} = $edit_link;
1450 $row->{description}->{link} = $edit_link;
1452 foreach (qw(sellprice listprice lastcost)) {
1453 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1454 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1457 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1459 if (!$ref->{assemblyitem}) {
1460 foreach my $col (@subtotal_columns) {
1461 $totals{$col} += $onhand * $ref->{$col};
1462 $subtotals{$col} += $onhand * $ref->{$col};
1465 $subtotals{onhand} += $onhand;
1469 if ($ref->{module} eq 'oe') {
1470 my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1471 $row->{ordnumber}{link} = $edit_oe_link;
1472 $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1475 $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1478 # set properties of images
1479 if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1480 $row->{image}{data} = '';
1481 $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1483 map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1485 $report->add_data($row);
1487 my $next_ref = $form->{parts}[$idx + 1];
1489 # insert subtotal rows
1490 if (($form->{l_subtotal} eq 'Y') &&
1492 (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1493 my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1495 if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1496 $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1499 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1500 map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1502 $report->add_data($row);
1504 $same_item = $next_ref->{ $form->{sort} };
1510 if ($form->{"l_linetotal"}) {
1511 my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1513 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1515 $report->add_separator();
1516 $report->add_data($row);
1519 $report->generate_with_headers();
1521 $lxdebug->leave_sub();
1522 } #end generate_report
1524 sub parts_subtotal {
1525 $lxdebug->enter_sub();
1528 our (%column_data, @column_index);
1529 our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1531 map { $column_data{$_} = "<td> </td>" } @column_index;
1532 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1534 $column_data{onhand} =
1535 "<th class=listsubtotal align=right>"
1536 . $form->format_amount(\%myconfig, $subtotalonhand)
1539 $column_data{linetotalsellprice} =
1540 "<th class=listsubtotal align=right>"
1541 . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1543 $column_data{linetotallistprice} =
1544 "<th class=listsubtotal align=right>"
1545 . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1547 $column_data{linetotallastcost} =
1548 "<th class=listsubtotal align=right>"
1549 . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1552 $subtotalonhand = 0;
1553 $subtotalsellprice = 0;
1554 $subtotallistprice = 0;
1555 $subtotallastcost = 0;
1557 print "<tr class=listsubtotal>";
1559 map { print "\n$column_data{$_}" } @column_index;
1565 $lxdebug->leave_sub();
1569 $lxdebug->enter_sub();
1570 # show history button
1571 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1572 #/show hhistory button
1573 IC->get_part(\%myconfig, \%$form);
1575 $form->{"original_partnumber"} = $form->{"partnumber"};
1577 $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1582 $lxdebug->leave_sub();
1586 $lxdebug->enter_sub();
1588 IC->create_links("IC", \%myconfig, \%$form);
1591 map({ $form->{selectcurrency} .= "<option>$_\n" }
1592 split(/:/, $form->{currencies}));
1594 # parts and assemblies have the same links
1595 my $item = $form->{item};
1596 if ($form->{item} eq 'assembly') {
1600 # build the popup menus
1601 $form->{taxaccounts} = "";
1602 foreach my $key (keys %{ $form->{IC_links} }) {
1603 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1605 # if this is a tax field
1606 if ($key =~ /IC_tax/) {
1607 if ($key =~ /\Q$item\E/) {
1608 $form->{taxaccounts} .= "$ref->{accno} ";
1609 $form->{"IC_tax_$ref->{accno}_description"} =
1610 "$ref->{accno}--$ref->{description}";
1613 if ($form->{amount}{ $ref->{accno} }) {
1614 $form->{"IC_tax_$ref->{accno}"} = "checked";
1617 $form->{"IC_tax_$ref->{accno}"} = "checked";
1622 $form->{"select$key"} .=
1623 "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1624 if ($form->{amount}{$key} eq $ref->{accno}) {
1625 $form->{$key} = "$ref->{accno}--$ref->{description}";
1631 chop $form->{taxaccounts};
1633 if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1634 $form->{selectIC_income} = $form->{selectIC_sale};
1635 $form->{selectIC_expense} = $form->{selectIC_cogs};
1636 $form->{IC_income} = $form->{IC_sale};
1637 $form->{IC_expense} = $form->{IC_cogs};
1640 delete $form->{IC_links};
1641 delete $form->{amount};
1643 $form->get_partsgroup(\%myconfig, { all => 1 });
1645 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1647 if (@{ $form->{all_partsgroup} }) {
1648 $form->{selectpartsgroup} = qq|<option>\n|;
1650 $form->{selectpartsgroup} .=
1651 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1652 } @{ $form->{all_partsgroup} };
1655 if ($form->{item} eq 'assembly') {
1657 foreach my $i (1 .. $form->{assembly_rows}) {
1658 if ($form->{"partsgroup_id_$i"}) {
1659 $form->{"partsgroup_$i"} =
1660 qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1663 $form->get_partsgroup(\%myconfig);
1665 if (@{ $form->{all_partsgroup} }) {
1666 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1669 $form->{selectassemblypartsgroup} .=
1670 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1671 } @{ $form->{all_partsgroup} };
1674 $lxdebug->leave_sub();
1678 $lxdebug->enter_sub();
1680 my ($payment, $rows, $notes, $description, $ean, $buchungsgruppe, $partsgroup, $group, $tax, $lastcost, $eur, $linkaccounts, $weight, $n, $rop, $bin, $vegv);
1681 my ($notdiscountableok, $notdiscountable);
1682 my ($formula, $formula_label, $imagelinks, $obsolete, $shopok, $shop);
1684 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1686 map({ $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, -2) }
1687 qw(sellprice listprice lastcost gv));
1689 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
1690 qw(weight rop stock);
1692 foreach my $item (qw(partnumber description unit notes)) {
1693 $form->{$item} =~ s/\"/"/g;
1696 $payment = qq|<option value=""></option>|;
1697 foreach my $item (@{ $form->{payment_terms} }) {
1698 if ($form->{payment_id} eq $item->{id}) {
1699 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1701 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
1706 if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
1711 qq|<textarea name=notes rows=$rows cols=45 wrap=soft>$form->{notes}</textarea>|;
1712 if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
1714 qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
1717 qq|<input name=description size=40 value="$form->{description}">|;
1720 $ean = qq|<input name=ean size=40 value="$form->{ean}">|;
1722 foreach my $item (split / /, $form->{taxaccounts}) {
1723 $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
1726 IC->retrieve_buchungsgruppen(\%myconfig, $form);
1727 if (@{ $form->{BUCHUNGSGRUPPEN} }) {
1728 foreach my $item (@{ $form->{BUCHUNGSGRUPPEN} }) {
1729 if ($item->{id} == $form->{buchungsgruppen_id}) {
1730 $form->{selectbuchungsgruppe} .=
1731 "<option value=$item->{id} selected>$item->{description}\n";
1732 } elsif (($form->{id} && $form->{orphaned}) || (!$form->{id})) {
1733 $form->{selectbuchungsgruppe} .=
1734 "<option value=$item->{id}>$item->{description}\n";
1740 $buchungsgruppe = qq|
1742 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1743 <td><select name=buchungsgruppen_id>$form->{selectbuchungsgruppe}</select></td>
1748 foreach my $item (qw(IC IC_income IC_expense)) {
1749 if ($form->{$item}) {
1750 if ($form->{id} && $form->{orphaned}) {
1751 $form->{"select$item"} =~ s/ selected//;
1752 $form->{"select$item"} =~
1753 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
1755 $form->{"select$item"} = qq|<option selected>$form->{$item}|;
1760 if ($form->{selectpartsgroup}) {
1761 $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
1763 qq|<input type=hidden name=selectpartsgroup value="|
1764 . $form->escape($form->{selectpartsgroup}, 1) . qq|">|;
1765 $form->{selectpartsgroup} =~
1766 s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
1769 qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
1770 $group = $locale->text('Group');
1774 foreach my $item (split / /, $form->{taxaccounts}) {
1776 <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}> <b>$form->{"IC_tax_${item}_description"}</b>
1777 <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
1781 $form->{obsolete} = "checked" if $form->{obsolete};
1785 <th align="right" nowrap="true">|
1786 . $locale->text('Last Cost') . qq|</th>
1787 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
1793 <th align=right>| . $locale->text('Inventory') . qq|</th>
1794 <td><select name=IC>$form->{selectIC}</select></td>
1795 <input name=selectIC type=hidden value="$form->{selectIC}">
1799 if ($form->{item} eq "part") {
1801 $linkaccounts .= qq|
1803 <th align=right>| . $locale->text('Revenue') . qq|</th>
1804 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1805 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1808 <th align=right>| . $locale->text('Expense') . qq|</th>
1809 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
1810 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
1816 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
1821 <input name=weight size=10 value=$form->{weight}>
1831 if ($form->{item} eq "assembly") {
1837 <th align=right>| . $locale->text('Revenue') . qq|</th>
1838 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1839 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1845 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
1850 $form->{weight}
1851 <input type=hidden name=weight value=$form->{weight}>
1861 if ($form->{item} eq "service") {
1865 <th align=right>| . $locale->text('Revenue') . qq|</th>
1866 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1867 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1870 <th align=right>| . $locale->text('Expense') . qq|</th>
1871 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
1872 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
1877 $linkaccounts = qq|<input type=hidden name=IC_income value="$form->{IC_income_default}">|;
1879 if ($form->{IC_cogs_default}) {
1880 $form->{IC_expense_default} = $form->{IC_cogs_default};
1883 if (($form->{item} eq "service") || ($form->{item} eq "part")) {
1884 $linkaccounts .= qq|<input type=hidden name=IC_expense value="$form->{IC_expense_default}">|;
1886 if ($form->{item} eq "part") {
1887 $linkaccounts .= qq|<input type=hidden name=IC value="$form->{IC_default}">|;
1890 if ($form->{item} ne 'service') {
1891 $n = ($form->{onhand} > 0) ? "1" : "0";
1894 <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
1895 <th align=left nowrap class="plus$n"> |
1896 . $form->format_amount(\%myconfig, $form->{onhand}) . qq|</th>
1900 if ($form->{item} eq 'assembly') {
1903 <th align="right" nowrap>| . $locale->text('Stock') . qq|</th>
1904 <td><input name=stock size=10 value=$form->{stock}></td>
1911 <th align="right" nowrap="true">| . $locale->text('ROP') . qq|</th>
1912 <td><input name=rop size=10 value=$form->{rop}></td>
1918 <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
1919 <td><input name=bin size=10 value=$form->{bin}></td>
1924 <th align="right" nowrap="true">|
1925 . $locale->text('Verrechnungseinheit') . qq|</th>
1926 <td><input name=ve size=10 value=$form->{ve}></td>
1929 <th align="right" nowrap="true">|
1930 . $locale->text('Business Volume') . qq|</th>
1931 <td><input name=gv size=10 value=$form->{gv}></td>
1934 $notdiscountableok = ($form->{not_discountable}) == 1 ? "checked" : "";
1935 $notdiscountable .= qq|
1937 <th align=right nowrap>|
1938 . $locale->text('Not Discountable') . qq|</th>
1939 <td><input class=checkbox type=checkbox name=not_discountable value=1 $notdiscountableok></td>
1944 qq|<ilayer><layer onmouseover="this.T_STICKY=true;this.T_STATIC=true;return escape('| . $locale->text('The formula needs the following syntax:<br>For regular article:<br>Variablename= Variable Unit;<br>Variablename2= Variable2 Unit2;<br>...<br>###<br>Variable + ( Variable2 / Variable )<br><b>Please be beware of the spaces in the formula</b><br>') . qq|')"><textarea name=formel rows=4 cols=30 wrap=soft>$form->{formel}</textarea></layer><ilayer>|;
1946 $formula_label = $locale->text('Formula');
1953 <th align=right nowrap>| . $locale->text('Image') . qq|</th>
1954 <td><input name=image size=40 value="$form->{image}"></td>
1955 <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
1956 <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
1959 <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
1960 <td><input name=drawing size=40 value="$form->{drawing}"></td>
1972 <th align="right" nowrap="true">| . $locale->text('Obsolete') . qq|</th>
1973 <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td>
1977 $shopok = $form->{shop} == 1 ? "checked" : "";
1980 <th align=right nowrap>|
1981 . $locale->text('Shopartikel') . qq|</th>
1982 <td><input class=checkbox type=checkbox name=shop value=1 $shopok></td>
1987 # type=submit $locale->text('Add Part')
1988 # type=submit $locale->text('Add Service')
1989 # type=submit $locale->text('Add Assembly')
1991 # type=submit $locale->text('Edit Part')
1992 # type=submit $locale->text('Edit Service')
1993 # type=submit $locale->text('Edit Assembly')
1994 # use JavaScript Calendar or not
1995 my ($jsscript, $button1);
1996 $form->{jsscript} = 1;
1998 if ($form->{jsscript}) {
2000 # with JavaScript Calendar
2002 <td width="13"><input name=priceupdate id=priceupdate size=11 title="$myconfig{dateformat}" value="$form->{priceupdate}"></td>
2003 <td width="4" align="left"><input type=button name=priceupdate id="trigger1" value=|
2004 . $locale->text('button') . qq|></td>
2009 Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1");
2012 # without JavaScript Calendar
2014 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
2017 my $unit_select = '<input type="hidden" name="unit_changeable" value="' . $form->{"unit_changeable"} . '">';
2018 if (!$form->{"unit_changeable"}) {
2019 $unit_select .= '<input type="hidden" name="unit" value="' . $form->{"unit"} . '">' . $form->{"unit"};
2021 my $units = AM->retrieve_units(\%myconfig, $form, $form->{"item"} eq "service" ? "service" : "dimension");
2022 $unit_select .= AM->unit_select_html($units, "unit", $form->{"unit"});
2026 if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
2027 my @values = ('', map { $_->{id} } @{ $form->{ALL_PRICE_FACTORS} });
2028 my %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
2031 qq|<tr><th align="right">|
2032 . $locale->text('Price Factor')
2034 . NTI($cgi->popup_menu('-name' => 'price_factor_id',
2035 '-default' => $form->{price_factor_id},
2036 '-values' => \@values,
2037 '-labels' => \%labels))
2041 $form->{fokus} = "ic.partnumber";
2045 <body onLoad="fokus()">
2046 <script type="text/javascript" src="js/common.js"></script>
2047 <script type="text/javascript" src="js/parts_language_selection.js"></script>
2049 <form method=post name="ic" action=$form->{script}>
2051 <input name=id type=hidden value=$form->{id}>
2052 <input name=item type=hidden value=$form->{item}>
2053 <input name=title type=hidden value="$form->{title}">
2054 <input name=makemodel type=hidden value="$form->{makemodel}">
2055 <input name=alternate type=hidden value="$form->{alternate}">
2056 <input name=onhand type=hidden value=$form->{onhand}>
2057 <input name=orphaned type=hidden value=$form->{orphaned}>
2058 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
2059 <input name=rowcount type=hidden value=$form->{rowcount}>
2060 <input name=eur type=hidden value=$eur>
2061 <input name=language_values type=hidden value="$form->{language_values}">
2062 <input name="original_partnumber" type="hidden" value="| . $form->quote($form->{"original_partnumber"}) . qq|">
2064 <table width="100%">
2066 <th class=listtop>$form->{title}</th>
2068 <tr height="5"></tr>
2071 <table width="100%">
2073 <th align=left>| . $locale->text('Part Number') . qq|</th>
2074 <th align=left>| . $locale->text('Part Description') . qq|</th>
2075 <th align=left>$group</th>
2078 <td><input name=partnumber value="$form->{partnumber}" size=20></td>
2079 <td>$description</td>
2080 <td>$partsgroup</td>
2081 <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}">
2088 <table width="100%" height="100%">
2091 <table width="100%" height="100%">
2101 <th align="left">| . $locale->text('Notes') . qq|</th>
2102 <th align="left">$formula_label</th>
2113 <th align="left"></th>
2114 <th align="left">| . $locale->text('EAN-Code') . qq|</th>
2118 <button type="button" onclick="parts_language_selection_window('language_values')">| . $locale->text('Set Language Values') . qq|</button>
2128 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
2129 <td><select name=payment_id>$payment</select></td>
2137 <table width="100%">
2139 <th align="right" nowrap="true">|
2140 . $locale->text('Updated') . qq|</th>
2144 <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
2145 <td><input name=listprice size=11 value=$form->{listprice}></td>
2148 <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
2149 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
2154 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
2155 <td>$unit_select</td>
2174 $lxdebug->leave_sub();
2178 $lxdebug->enter_sub();
2180 if ($form->{item} eq "assembly") {
2185 <table width="100%">
2187 <th colspan=2 align=right>|
2188 . $locale->text('Total') . qq| </th>
2190 . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
2195 <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2200 <input type=hidden name=login value=$form->{login}>
2201 <input type=hidden name=password value=$form->{password}>
2202 <input type=hidden name=callback value="$form->{callback}">
2203 <input type=hidden name=previousform value="$form->{previousform}">
2204 <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
2205 <input type=hidden name=vc value=$form->{vc}>
2207 <td><hr size=3 noshade></td>
2212 <input class=submit type=submit name=action value="|
2213 . $locale->text('Update') . qq|">
2216 unless ($form->{item} eq "service") {
2218 <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
2223 <input type=hidden name=price_rows value=$form->{price_rows}>|;
2226 <input class=submit type=submit name=action value="|
2227 . $locale->text('Save') . qq|">|;
2231 if (!$form->{previousform}) {
2233 <input class=submit type=submit name=action value="|
2234 . $locale->text('Save as new') . qq|">|;
2237 if ($form->{orphaned}) {
2238 if (!$form->{previousform}) {
2239 if ($form->{item} eq 'assembly') {
2240 if (!$form->{onhand}) {
2242 <input class=submit type=submit name=action value="|
2243 . $locale->text('Delete') . qq|">|;
2247 <input class=submit type=submit name=action value="|
2248 . $locale->text('Delete') . qq|">|;
2254 if (!$form->{previousform}) {
2255 if ($form->{menubar}) {
2256 require "bin/mozilla/menu.pl";
2260 # button for saving history
2261 if($form->{id} ne "") {
2263 <input type=button class=submit onclick=set_history_window(|
2265 . qq|); name=history id=history value=|
2266 . $locale->text('history')
2269 # /button for saving history
2274 <script type="text/javascript" src="js/wz_tooltip.js"></script>
2280 $lxdebug->leave_sub();
2284 $lxdebug->enter_sub();
2292 <th class="listheading">| . $locale->text('Make') . qq|</th>
2293 <th class="listheading">| . $locale->text('Model') . qq|</th>
2297 for my $i (1 .. $numrows) {
2298 $form->{"make_$i"} =~ s/\"/"/g;
2299 $form->{"model_$i"} =~ s/\"/"/g;
2302 <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
2303 <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
2314 $lxdebug->leave_sub();
2318 $lxdebug->enter_sub();
2320 my (@column_index, %column_data, %column_header);
2321 my ($nochange, $callback, $previousform, $linetotal, $href);
2323 our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
2326 qw(runningnumber qty unit bom partnumber description partsgroup total);
2328 if ($form->{previousform}) {
2330 @column_index = qw(qty unit bom partnumber description partsgroup total);
2334 $form->{old_callback} = $form->{callback};
2335 $callback = $form->{callback};
2336 $form->{callback} = "$form->{script}?action=display_form";
2339 map { delete $form->{$_} } qw(action header);
2343 # save form variables in a previousform variable
2344 foreach my $key (sort keys %$form) {
2347 $form->{$key} =~ s/&/%26/g;
2348 $previousform .= qq|$key=$form->{$key}&|;
2351 $previousform = $form->escape($form->escape($previousform, 1));
2352 $form->{callback} = $callback;
2354 $form->{assemblytotal} = 0;
2355 $form->{weight} = 0;
2358 $column_header{runningnumber} =
2359 qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
2360 $column_header{qty} =
2361 qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
2362 $column_header{unit} =
2363 qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
2364 $column_header{partnumber} =
2365 qq|<th align=left nowrap width=20%>|
2366 . $locale->text('Part Number')
2368 $column_header{description} =
2369 qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
2370 $column_header{total} =
2371 qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
2372 $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
2373 $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
2376 <tr class=listheading>
2377 <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
2385 map { print "\n$column_header{$_}" } @column_index;
2391 for my $i (1 .. $numrows) {
2392 $form->{"partnumber_$i"} =~ s/\"/"/g;
2395 $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
2396 $form->{assemblytotal} += $linetotal;
2398 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
2400 $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
2402 if (($i >= 1) && ($i == $numrows)) {
2405 map { $column_data{$_} = qq|<td></td>| }
2406 qw(qty unit partnumber description bom partsgroup);
2409 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
2412 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2413 $column_data{partnumber} =
2414 qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
2415 $column_data{description} =
2416 qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
2417 $column_data{partsgroup} =
2418 qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
2424 if ($form->{previousform}) {
2425 $column_data{partnumber} =
2426 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
2428 qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
2431 qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
2432 $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
2433 $column_data{bom} .= qq|</td>|;
2435 $column_data{partsgroup} =
2436 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2440 qq|$form->{script}?action=edit&id=$form->{"id_$i"}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
2441 $column_data{partnumber} =
2442 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
2443 $column_data{runningnumber} =
2444 qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
2446 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2448 $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
2450 qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
2452 $column_data{partsgroup} =
2453 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2456 $column_data{unit} =
2457 qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
2458 $column_data{description} =
2459 qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
2462 $column_data{total} = qq|<td align=right>$linetotal</td>|;
2464 $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
2469 map { print "\n$column_data{$_}" } @column_index;
2473 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2474 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
2475 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
2485 $lxdebug->leave_sub();
2489 $lxdebug->enter_sub();
2491 if ($form->{item} eq "assembly") {
2492 my $i = $form->{assembly_rows};
2494 # if last row is empty check the form otherwise retrieve item
2495 if ( ($form->{"partnumber_$i"} eq "")
2496 && ($form->{"description_$i"} eq "")
2497 && ($form->{"partsgroup_$i"} eq "")) {
2503 IC->assembly_item(\%myconfig, \%$form);
2505 my $rows = scalar @{ $form->{item_list} };
2508 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2511 $form->{makemodel_rows}--;
2515 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
2516 qw(partnumber description unit partsgroup);
2517 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
2518 keys %{ $form->{item_list}[0] };
2519 $form->{"runningnumber_$i"} = $form->{assembly_rows};
2520 $form->{assembly_rows}++;
2528 $form->{rowcount} = $i;
2529 $form->{assembly_rows}++;
2536 } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
2540 $lxdebug->leave_sub();
2544 $lxdebug->enter_sub();
2546 my ($parts_id, %newform, $previousform, $amount, $callback);
2548 # check if there is a part number - commented out, cause there is an automatic allocation of numbers
2549 # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
2551 # check if there is a description
2552 $form->isblank("description", $locale->text("Part Description missing!"));
2554 if ($form->{obsolete}) {
2557 "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
2559 if ($form->{onhand} * 1);
2562 if (!$form->{buchungsgruppen_id}) {
2563 $form->error($locale->text("Parts must have an entry type.") . " " .
2564 $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.")
2568 $form->error($locale->text('Description must not be empty!')) unless $form->{description};
2569 $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
2571 # expand dynamic strings
2572 # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
2573 # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
2574 # $locale->text('Part Number missing!')
2575 # $locale->text('Service Number missing!')
2576 # $locale->text('Assembly Number missing!')
2579 $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
2580 if (IC->save(\%myconfig, \%$form) == 3) {
2581 $form->error($locale->text('Partnumber not unique!'));
2583 # saving the history
2584 if(!exists $form->{addition}) {
2585 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2586 $form->{addition} = "SAVED";
2587 $form->save_history($form->dbconnect(\%myconfig));
2589 # /saving the history
2590 $parts_id = $form->{id};
2593 # load previous variables
2594 if ($form->{previousform}) {
2596 # save the new form variables before splitting previousform
2597 map { $newform{$_} = $form->{$_} } keys %$form;
2599 $previousform = $form->unescape($form->{previousform});
2601 # don't trample on previous variables
2602 map { delete $form->{$_} } keys %newform;
2604 # now take it apart and restore original values
2605 foreach my $item (split /&/, $previousform) {
2606 my ($key, $value) = split m/=/, $item, 2;
2607 $value =~ s/%26/&/g;
2608 $form->{$key} = $value;
2610 $form->{taxaccounts} = $newform{taxaccount2};
2612 if ($form->{item} eq 'assembly') {
2614 # undo number formatting
2615 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2616 qw(weight listprice sellprice rop);
2618 $form->{assembly_rows}--;
2619 $i = $newform{rowcount};
2620 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2622 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
2623 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
2625 # change/add values for assembly item
2626 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
2628 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2629 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
2633 # set values for last invoice/order item
2634 $i = $form->{rowcount};
2635 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2637 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
2639 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
2641 if ($form->{exchangerate} != 0) {
2642 $form->{"sellprice_$i"} /= $form->{exchangerate};
2645 $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
2647 map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
2648 chop $form->{"taxaccounts_$i"};
2649 foreach my $item (qw(description rate taxnumber)) {
2650 my $index = $form->{"taxaccounts_$i"} . "_$item";
2651 $form->{$index} = $newform{$index};
2654 # credit remaining calculation
2655 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
2657 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
2658 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
2660 $form->{creditremaining} -= $amount;
2662 # redo number formatting, because invoice parse them!
2663 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
2666 $form->{"id_$i"} = $parts_id;
2668 # Get the actual price factor (not just the ID) for the marge calculation.
2669 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
2670 foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
2671 next if ($pfac->{id} != $newform{price_factor_id});
2672 $form->{"marge_price_factor_$i"} = $pfac->{factor};
2675 delete $form->{ALL_PRICE_FACTORS};
2677 delete $form->{action};
2679 # restore original callback
2680 $callback = $form->unescape($form->{callback});
2681 $form->{callback} = $form->unescape($form->{old_callback});
2682 delete $form->{old_callback};
2684 $form->{makemodel_rows}--;
2686 # put callback together
2687 foreach my $key (keys %$form) {
2689 # do single escape for Apache 2.0
2690 my $value = $form->escape($form->{$key}, 1);
2691 $callback .= qq|&$key=$value|;
2693 $form->{callback} = $callback;
2695 $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
2700 $lxdebug->leave_sub();
2704 $lxdebug->enter_sub();
2706 # saving the history
2707 if(!exists $form->{addition}) {
2708 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2709 $form->{addition} = "SAVED AS NEW";
2710 $form->save_history($form->dbconnect(\%myconfig));
2712 # /saving the history
2714 if ($form->{"original_partnumber"} &&
2715 ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
2716 $form->{partnumber} = "";
2719 $lxdebug->leave_sub();
2723 $lxdebug->enter_sub();
2724 # saving the history
2725 if(!exists $form->{addition}) {
2726 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2727 $form->{addition} = "DELETED";
2728 $form->save_history($form->dbconnect(\%myconfig));
2730 # /saving the history
2731 my $rc = IC->delete(\%myconfig, \%$form);
2734 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2735 $form->error($locale->text('Cannot delete item!'));
2737 $lxdebug->leave_sub();
2741 $lxdebug->enter_sub();
2750 <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
2751 <th class="listheading">| . $locale->text('Preis') . qq|</th>
2754 for my $i (1 .. $numrows) {
2757 <td width=50%><input type=hidden name="pricegroup_$i" size=30 value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
2758 <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
2759 <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
2770 $lxdebug->leave_sub();
2773 sub parts_language_selection {
2774 $lxdebug->enter_sub();
2778 my $languages = IC->retrieve_languages(\%myconfig, $form);
2780 if ($form->{language_values} ne "") {
2781 foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
2782 my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
2784 foreach my $language (@{ $languages }) {
2785 next unless ($language->{id} == $language_id);
2787 $language->{translation} = $translation;
2788 $language->{longdescription} = $longdescription;
2794 my @header_sort = qw(name longdescription);
2795 my %header_title = ( "name" => $locale->text("Name"),
2796 "longdescription" => $locale->text("Long Description"),
2800 map(+{ "column_title" => $header_title{$_},
2802 "callback" => $callback,
2806 $form->{"title"} = $locale->text("Language Values");
2808 print $form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
2809 "LANGUAGES" => $languages,
2810 "onload" => $onload });
2812 $lxdebug->leave_sub();
2815 sub continue { call_sub($form->{"nextsub"}); }