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,
102 is_service => $is_service,
103 dateformat => $myconfig{dateformat}, });
105 $lxdebug->leave_sub();
108 sub search_update_prices {
109 $lxdebug->enter_sub();
111 my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form);
115 print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups });
117 $lxdebug->leave_sub();
120 sub confirm_price_update {
121 $lxdebug->enter_sub();
124 $form->{nextsub} = "update_prices";
130 <form method=post action=$form->{script}>
133 # delete action variable
134 map { delete $form->{$_} } qw(action header);
136 foreach my $key (keys %$form) {
137 $form->{$key} =~ s/\"/"/g;
138 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
142 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
144 <h4>| . $locale->text('Are you sure you want to update the prices') . qq| </h4>
147 <input name=action class=submit type=submit value="| . $locale->text('Continue') . qq|">
151 $lxdebug->leave_sub();
155 $lxdebug->enter_sub();
157 if (IC->update_prices(\%myconfig, \%$form)) {
158 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
160 $form->error($locale->text('Could not update prices!'));
163 $lxdebug->leave_sub();
167 $lxdebug->enter_sub();
172 $form->{title} = $locale->text('Top 100 hinzufuegen');
179 <form method=post action=$form->{script}>
181 <input type=hidden name=searchitems value=$form->{searchitems}>
182 <input type=hidden name=title value="$form->{title}">
184 <input type=hidden name=revers value="$form->{revers}">
185 <input type=hidden name=lastsort value="$form->{lastsort}">|;
189 <tr class=listheading>
190 <th class=listheading nowrap>| . $locale->text('Part Number') . qq|</th>
191 <th class=listheading nowrap>| . $locale->text('Part Description') . qq|</th>
194 <td><input type=text name=partnumber size=20 value=></td>
195 <td><input type=text name=description size=30 value=></td>
202 <input type=hidden name=login value=$form->{login}>
203 <input type=hidden name=password value=$form->{password}>
205 <input type=hidden name=itemstatus value="$form->{itemstatus}">
206 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
207 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
208 <input type=hidden name=l_description value="$form->{l_description}">
209 <input type=hidden name=l_onhand value="$form->{l_onhand}">
210 <input type=hidden name=l_unit value="$form->{l_unit}">
211 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
212 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
213 <input type=hidden name=sort value="$form->{sort}">
214 <input type=hidden name=revers value="$form->{revers}">
215 <input type=hidden name=lastsort value="$form->{lastsort}">
217 <input type=hidden name=bom value="$form->{bom}">
218 <input type=hidden name=titel value="$form->{titel}">
219 <input type=hidden name=searchitems value="$form->{searchitems}">
221 <input type=hidden name=row value=$j>
223 <input type=hidden name=nextsub value=item_selected>
225 <input type=hidden name=test value=item_selected>
227 <input name=lastndx type=hidden value=$lastndx>
229 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>
231 <input name=extras type=hidden value=$form->{extras}>|;
233 my ($partnumber, $description, $unit, $sellprice, $soldtotal);
236 for (my $i = 0; $i < $form->{ndxs_counter}; $i++) {
239 $partnumber = $form->{"totop100_partnumber_$j"};
240 $description = $form->{"totop100_description_$j"};
241 $unit = $form->{"totop100_unit_$j"};
242 $sellprice = $form->{"totop100_sellprice_$j"};
243 $soldtotal = $form->{"totop100_soldtotal_$j"};
245 # insert data into top100
246 push @{ $form->{parts} },
248 partnumber => "$partnumber",
249 description => "$description",
251 sellprice => "$sellprice",
252 soldtotal => "$soldtotal" };
258 # set data for next page
259 if (($form->{ndxs_counter}) > 0) {
260 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
261 $partnumber = $form->{"totop100_partnumber_$i"};
262 $description = $form->{"totop100_description_$i"};
263 $unit = $form->{"totop100_unit_$i"};
264 $sellprice = $form->{"totop100_sellprice_$i"};
265 $soldtotal = $form->{"totop100_soldtotal_$i"};
268 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
269 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
270 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
271 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
272 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
280 <input class=submit type=submit name=action value="|
281 . $locale->text('list') . qq|">
286 $lxdebug->leave_sub();
290 $lxdebug->enter_sub();
293 our ($partnumber, $description, $unit, $sellprice, $soldtotal);
295 my @sortorders = ("", "partnumber", "description", "all");
296 my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
297 IC->get_parts(\%myconfig, \%$form, $sortorder);
299 $form->{title} = $locale->text('Top 100 hinzufuegen');
305 <form method=post action=ic.pl>
308 <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
311 <tr class=listheading>
313 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
314 <th class=listheading>| . $locale->text('Part Description') . qq|</th>
315 <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
316 <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
317 <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
321 my $i = $form->{rows};
323 for ($j = 1; $j <= $i; $j++) {
326 <tr class=listrow1>|;
329 <td><input name=ndx class=radio type=radio value=$j checked></td>|;
332 <td><input name=ndx class=radio type=radio value=$j></td>|;
335 <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
336 <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
337 <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
338 <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
339 <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
342 <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
352 <input type=hidden name=login value=$form->{login}>
353 <input type=hidden name=password value=$form->{password}>
355 <input type=hidden name=itemstatus value="$form->{itemstatus}">
356 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
357 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
358 <input type=hidden name=l_description value="$form->{l_description}">
359 <input type=hidden name=l_onhand value="$form->{l_onhand}">
360 <input type=hidden name=l_unit value="$form->{l_unit}">
361 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
362 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
363 <input type=hidden name=sort value="$form->{sort}">
364 <input type=hidden name=revers value="$form->{revers}">
365 <input type=hidden name=lastsort value="$form->{lastsort}">
367 <input type=hidden name=bom value="$form->{bom}">
368 <input type=hidden name=titel value="$form->{titel}">
369 <input type=hidden name=searchitems value="$form->{searchitems}">
371 <input type=hidden name=row value=$j>
373 <input type=hidden name=nextsub value=item_selected>
375 <input name=lastndx type=hidden value=$lastndx>
377 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
381 if (($form->{ndxs_counter}) > 0) {
382 for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
384 $partnumber = $form->{"totop100_partnumber_$i"};
385 $description = $form->{"totop100_description_$i"};
386 $unit = $form->{"totop100_unit_$i"};
387 $sellprice = $form->{"totop100_sellprice_$i"};
388 $soldtotal = $form->{"totop100_soldtotal_$i"};
391 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
392 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
393 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
394 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
395 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
403 <input class=submit type=submit name=action value="|
404 . $locale->text('TOP100') . qq|">
410 $lxdebug->leave_sub();
414 $lxdebug->enter_sub();
417 $form->{ndxs_counter}++;
419 if ($form->{ndxs_counter} > 0) {
421 my $index = $form->{ndx};
423 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
424 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
425 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
426 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
427 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
431 $lxdebug->leave_sub();
435 $lxdebug->enter_sub();
437 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
438 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
439 my (@column_index, %column_header, %column_data);
440 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
442 $form->{top100} = "top100";
443 $form->{l_soldtotal} = "Y";
444 $form->{soldtotal} = "soldtotal";
445 $form->{sort} = "soldtotal";
446 $form->{l_qty} = "N";
447 $form->{l_linetotal} = "";
449 $form->{number} = "position";
450 $form->{l_number} = "Y";
454 $form->{title} = $locale->text('Top 100');
456 $revers = $form->{revers};
457 $lastsort = $form->{lastsort};
459 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
461 $form->{lastsort} = "partnumber";
462 $form->{sort} = "partnumber";
466 "$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="
467 . $form->escape($form->{title}, 1);
469 # if we have a serialnumber limit search
470 if ($form->{serialnumber} || $form->{l_serialnumber}) {
471 $form->{l_serialnumber} = "Y";
472 unless ( $form->{bought}
475 || $form->{quoted}) {
476 $form->{bought} = $form->{sold} = 1;
479 IC->all_parts(\%myconfig, \%$form);
481 if ($form->{itemstatus} eq 'active') {
482 $option .= $locale->text('Active') . " : ";
484 if ($form->{itemstatus} eq 'obsolete') {
485 $option .= $locale->text('Obsolete') . " : ";
487 if ($form->{itemstatus} eq 'orphaned') {
488 $option .= $locale->text('Orphaned') . " : ";
490 if ($form->{itemstatus} eq 'onhand') {
491 $option .= $locale->text('On Hand') . " : ";
492 $form->{l_onhand} = "Y";
494 if ($form->{itemstatus} eq 'short') {
495 $option .= $locale->text('Short') . " : ";
496 $form->{l_onhand} = "Y";
498 if ($form->{onorder}) {
499 $form->{l_ordnumber} = "Y";
500 $callback .= "&onorder=$form->{onorder}";
501 $option .= $locale->text('On Order') . " : ";
503 if ($form->{ordered}) {
504 $form->{l_ordnumber} = "Y";
505 $callback .= "&ordered=$form->{ordered}";
506 $option .= $locale->text('Ordered') . " : ";
509 $form->{l_quonumber} = "Y";
510 $callback .= "&rfq=$form->{rfq}";
511 $option .= $locale->text('RFQ') . " : ";
513 if ($form->{quoted}) {
514 $form->{l_quonumber} = "Y";
515 $callback .= ""ed=$form->{quoted}";
516 $option .= $locale->text('Quoted') . " : ";
518 if ($form->{bought}) {
519 $form->{l_invnumber} = "Y";
520 $callback .= "&bought=$form->{bought}";
521 $option .= $locale->text('Bought') . " : ";
524 $form->{l_invnumber} = "Y";
525 $callback .= "&sold=$form->{sold}";
526 $option .= $locale->text('Sold') . " : ";
533 || $form->{quoted}) {
535 $form->{l_lastcost} = "";
536 $form->{l_name} = "Y";
537 if ($form->{transdatefrom}) {
538 $callback .= "&transdatefrom=$form->{transdatefrom}";
540 . $locale->text('From')
542 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
544 if ($form->{transdateto}) {
545 $callback .= "&transdateto=$form->{transdateto}";
547 . $locale->text('To')
549 . $locale->date(\%myconfig, $form->{transdateto}, 1);
555 if ($form->{partnumber}) {
556 $callback .= "&partnumber=$form->{partnumber}";
557 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
560 $callback .= "&partnumber=$form->{ean}";
561 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
563 if ($form->{partsgroup}) {
564 $callback .= "&partsgroup=$form->{partsgroup}";
565 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
567 if ($form->{serialnumber}) {
568 $callback .= "&serialnumber=$form->{serialnumber}";
570 $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
572 if ($form->{description}) {
573 $callback .= "&description=$form->{description}";
574 $description = $form->{description};
578 $locale->text('Part Description') . qq| : $form->{description}<br>|;
581 $callback .= "&make=$form->{make}";
582 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
584 if ($form->{model}) {
585 $callback .= "&model=$form->{model}";
586 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
588 if ($form->{drawing}) {
589 $callback .= "&drawing=$form->{drawing}";
590 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
592 if ($form->{microfiche}) {
593 $callback .= "µfiche=$form->{microfiche}";
594 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
596 if ($form->{l_soldtotal}) {
597 $callback .= "&soldtotal=$form->{soldtotal}";
598 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
601 my @columns = $form->sort_columns(
602 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)
605 if ($form->{l_linetotal}) {
606 $form->{l_onhand} = "Y";
607 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
608 if ($form->{l_lastcost}) {
609 $form->{l_linetotallastcost} = "Y";
610 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
611 $form->{l_linetotallastcost} = "";
614 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
617 if ($form->{searchitems} eq 'service') {
619 # remove bin, weight and rop from list
620 map { $form->{"l_$_"} = "" } qw(bin weight rop);
622 $form->{l_onhand} = "";
624 # qty is irrelevant unless bought or sold
630 || $form->{quoted}) {
631 $form->{l_onhand} = "Y";
633 $form->{l_linetotalsellprice} = "";
634 $form->{l_linetotallastcost} = "";
638 $form->{l_lastcost} = ""
639 if ($form->{searchitems} eq 'assembly' && !$form->{bom});
641 foreach my $item (@columns) {
642 if ($form->{"l_$item"} eq "Y") {
643 push @column_index, $item;
645 # add column to callback
646 $callback .= "&l_$item=Y";
650 if ($form->{l_subtotal} eq 'Y') {
651 $callback .= "&l_subtotal=Y";
654 $column_header{number} =
655 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
656 $column_header{partnumber} =
657 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
658 . $locale->text('Part Number')
660 $column_header{description} =
661 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
662 . $locale->text('Part Description')
664 $column_header{partsgroup} =
665 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
666 . $locale->text('Group')
668 $column_header{bin} =
669 qq|<th><a class=listheading href=$callback&sort=bin>|
670 . $locale->text('Bin')
672 $column_header{priceupdate} =
673 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
674 . $locale->text('Updated')
676 $column_header{onhand} =
677 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
678 . $locale->text('Qty')
680 $column_header{unit} =
681 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
682 $column_header{listprice} =
683 qq|<th class=listheading nowrap>|
684 . $locale->text('List Price')
686 $column_header{lastcost} =
687 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
688 $column_header{rop} =
689 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
690 $column_header{weight} =
691 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
693 $column_header{invnumber} =
694 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
695 . $locale->text('Invoice Number')
697 $column_header{ordnumber} =
698 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
699 . $locale->text('Order Number')
701 $column_header{quonumber} =
702 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
703 . $locale->text('Quotation')
706 $column_header{name} =
707 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
708 . $locale->text('Name')
711 $column_header{sellprice} =
712 qq|<th class=listheading nowrap>|
713 . $locale->text('Sell Price')
715 $column_header{linetotalsellprice} =
716 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
717 $column_header{linetotallastcost} =
718 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
719 $column_header{linetotallistprice} =
720 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
722 $column_header{image} =
723 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
724 $column_header{drawing} =
725 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
726 . $locale->text('Drawing')
728 $column_header{microfiche} =
729 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
730 . $locale->text('Microfiche')
733 $column_header{serialnumber} =
734 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
735 . $locale->text('Serial Number')
737 $column_header{soldtotal} =
738 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
739 . $locale->text('soldtotal')
743 my $colspan = $#column_index + 1;
750 <th class=listtop colspan=$colspan>$form->{title}</th>
754 <tr><td colspan=$colspan>$option</td></tr>
756 <tr class=listheading>
759 map { print "\n$column_header{$_}" } @column_index;
765 # add order to callback
766 $form->{callback} = $callback .= "&sort=$form->{sort}";
768 # escape callback for href
769 $callback = $form->escape($callback);
771 if (@{ $form->{parts} }) {
772 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
775 # insert numbers for top100
777 foreach my $ref (@{ $form->{parts} }) {
782 # if avaible -> insert choice here
783 if (($form->{ndxs_counter}) > 0) {
784 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
785 $partnumber = $form->{"totop100_partnumber_$i"};
786 $description = $form->{"totop100_description_$i"};
787 $unit = $form->{"totop100_unit_$i"};
788 $sellprice = $form->{"totop100_sellprice_$i"};
789 $soldtotal = $form->{"totop100_soldtotal_$i"};
792 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
793 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
794 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
795 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
796 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
800 push @{ $form->{parts} },
802 partnumber => "$partnumber",
803 description => "$description",
805 sellprice => "$sellprice",
806 soldtotal => "$soldtotal" };
809 # build data for columns
810 foreach my $ref (@{ $form->{parts} }) {
813 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
814 if ($sameitem ne $ref->{ $form->{sort} }) {
816 $sameitem = $ref->{ $form->{sort} };
820 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
821 $ref->{sellprice} *= $ref->{exchangerate};
822 $ref->{listprice} *= $ref->{exchangerate};
823 $ref->{lastcost} *= $ref->{exchangerate};
825 # use this for assemblies
826 $onhand = $ref->{onhand};
829 if ($ref->{assemblyitem}) {
831 $onhand = 0 if ($form->{sold});
834 $ref->{description} =~ s/
837 $column_data{number} =
839 . $form->format_amount(\%myconfig, $ref->{number})
841 $column_data{partnumber} =
842 "<td align=$align>$ref->{partnumber} </a></td>";
843 $column_data{description} = "<td>$ref->{description} </td>";
844 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
846 $column_data{onhand} =
848 . $form->format_amount(\%myconfig, $ref->{onhand})
850 $column_data{sellprice} =
852 . $form->format_amount(\%myconfig, $ref->{sellprice})
854 $column_data{listprice} =
856 . $form->format_amount(\%myconfig, $ref->{listprice})
858 $column_data{lastcost} =
860 . $form->format_amount(\%myconfig, $ref->{lastcost})
863 $column_data{linetotalsellprice} = "<td align=right>"
864 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
866 $column_data{linetotallastcost} = "<td align=right>"
867 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
869 $column_data{linetotallistprice} = "<td align=right>"
870 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
873 if (!$ref->{assemblyitem}) {
874 $totalsellprice += $onhand * $ref->{sellprice};
875 $totallastcost += $onhand * $ref->{lastcost};
876 $totallistprice += $onhand * $ref->{listprice};
878 $subtotalonhand += $onhand;
879 $subtotalsellprice += $onhand * $ref->{sellprice};
880 $subtotallastcost += $onhand * $ref->{lastcost};
881 $subtotallistprice += $onhand * $ref->{listprice};
886 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
887 $column_data{weight} =
889 . $form->format_amount(\%myconfig, $ref->{weight})
891 $column_data{unit} = "<td>$ref->{unit} </td>";
892 $column_data{bin} = "<td>$ref->{bin} </td>";
893 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
895 $column_data{invnumber} =
896 ($ref->{module} ne 'oe')
897 ? "<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>"
898 : "<td>$ref->{invnumber}</td>";
899 $column_data{ordnumber} =
900 ($ref->{module} eq 'oe')
901 ? "<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>"
902 : "<td>$ref->{ordnumber}</td>";
903 $column_data{quonumber} =
904 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
905 ? "<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>"
906 : "<td>$ref->{quonumber}</td>";
908 $column_data{name} = "<td>$ref->{name}</td>";
910 $column_data{image} =
912 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
914 $column_data{drawing} =
916 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
918 $column_data{microfiche} =
920 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
923 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
925 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
929 print "<tr class=listrow$i>";
931 map { print "\n$column_data{$_}" } @column_index;
938 if ($form->{l_subtotal} eq 'Y') {
942 if ($form->{"l_linetotal"}) {
943 map { $column_data{$_} = "<td> </td>" } @column_index;
944 $column_data{linetotalsellprice} =
945 "<th class=listtotal align=right>"
946 . $form->format_amount(\%myconfig, $totalsellprice, 2)
948 $column_data{linetotallastcost} =
949 "<th class=listtotal align=right>"
950 . $form->format_amount(\%myconfig, $totallastcost, 2)
952 $column_data{linetotallistprice} =
953 "<th class=listtotal align=right>"
954 . $form->format_amount(\%myconfig, $totallistprice, 2)
957 print "<tr class=listtotal>";
959 map { print "\n$column_data{$_}" } @column_index;
966 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
975 <form method=post action=$form->{script}>
977 <input type=hidden name=login value=$form->{login}>
978 <input type=hidden name=password value=$form->{password}>
980 <input type=hidden name=itemstatus value="$form->{itemstatus}">
981 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
982 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
983 <input type=hidden name=l_description value="$form->{l_description}">
984 <input type=hidden name=l_onhand value="$form->{l_onhand}">
985 <input type=hidden name=l_unit value="$form->{l_unit}">
986 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
987 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
988 <input type=hidden name=sort value="$form->{sort}">
989 <input type=hidden name=revers value="$form->{revers}">
990 <input type=hidden name=lastsort value="$form->{lastsort}">
991 <input type=hidden name=parts value="$form->{parts}">
993 <input type=hidden name=bom value="$form->{bom}">
994 <input type=hidden name=titel value="$form->{titel}">
995 <input type=hidden name=searchitems value="$form->{searchitems}">|;
1000 <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
1002 <input class=submit type=submit name=action value="|
1003 . $locale->text('choice') . qq|">
1011 $lxdebug->leave_sub();
1016 # Warning, deep magic ahead.
1017 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
1019 # flags coming from the form:
1021 # searchitems=part revers=0 lastsort=''
1024 # partnumber ean description partsgroup serialnumber make model drawing microfiche
1025 # transdatefrom transdateto
1028 # itemstatus = active | onhand | short | obsolete | orphaned
1029 # action = continue | top100
1032 # bought sold onorder ordered rfq quoted
1033 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
1034 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
1035 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
1038 # nextsub login password revers lastsort sort ndxs_counter
1040 sub generate_report {
1041 $lxdebug->enter_sub();
1043 my ($revers, $lastsort, $description);
1045 $form->{title} = (ucfirst $form->{searchitems}) . "s";
1046 $form->{title} = $locale->text($form->{title});
1048 my $revers = $form->{revers};
1049 my $lastsort = $form->{lastsort};
1051 # sorting and direction of sorting
1052 # ToDO: change this to the simpler field+direction method
1053 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
1054 $form->{revers} = 0;
1055 $form->{lastsort} = "partnumber";
1056 $form->{sort} = "partnumber";
1058 if ($form->{lastsort} eq $form->{sort}) {
1059 $form->{revers} = 1 - $form->{revers};
1061 $form->{revers} = 0;
1062 $form->{lastsort} = $form->{sort};
1066 # special case if we have a serialnumber limit search
1067 # serialnumbers are only given in invoices and orders,
1068 # so they can only pop up in bought, sold, rfq, and quoted stuff
1069 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
1070 && !$form->{rfq} && !$form->{quoted}
1071 && ($form->{l_serialnumber} || $form->{serialnumber}));
1073 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1074 # if any of these are ticked the behavior changes slightly for lastcost
1075 # since all those are aggregation checks for the legder tables this is an internal switch
1076 # refered to as ledgerchecks
1077 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1078 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1080 # if something should be activated if something else is active, enter it here
1081 my %dependencies = (
1082 onhand => [ qw(l_onhand) ],
1083 short => [ qw(l_onhand) ],
1084 onorder => [ qw(l_ordnumber) ],
1085 ordered => [ qw(l_ordnumber) ],
1086 rfq => [ qw(l_quonumber) ],
1087 quoted => [ qw(l_quonumber) ],
1088 bought => [ qw(l_invnumber) ],
1089 sold => [ qw(l_invnumber) ],
1090 ledgerchecks => [ qw(l_name) ],
1091 serialnumber => [ qw(l_serialnumber) ],
1092 no_sn_joins => [ qw(bought sold) ],
1095 # these strings get displayed at the top of the results to indicate the user which switches were used
1097 active => $locale->text('Active'),
1098 obsolete => $locale->text('Obsolete'),
1099 orphaned => $locale->text('Orphaned'),
1100 onhand => $locale->text('On Hand'),
1101 short => $locale->text('Short'),
1102 onorder => $locale->text('On Order'),
1103 ordered => $locale->text('Ordered'),
1104 rfq => $locale->text('RFQ'),
1105 quoted => $locale->text('Quoted'),
1106 bought => $locale->text('Bought'),
1107 sold => $locale->text('Sold'),
1108 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1109 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1110 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1111 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1112 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1113 description => $locale->text('Part Description') . ": '$form->{description}'",
1114 make => $locale->text('Make') . ": '$form->{make}'",
1115 model => $locale->text('Model') . ": '$form->{model}'",
1116 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1117 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1118 l_soldtotal => $locale->text('soldtotal'),
1121 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1122 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1123 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1125 # calculate dependencies
1126 for (@itemstatus_keys, @callback_keys) {
1127 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1128 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1131 # generate callback and optionstrings
1133 for my $key (@itemstatus_keys, @callback_keys) {
1134 next if ($form->{itemstatus} ne $key && !$form->{$key});
1135 push @options, $optiontexts{$key};
1138 # special case for lastcost
1139 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1141 if ($form->{description}) {
1142 $description = $form->{description};
1143 $description =~ s/\n/<br>/g;
1146 if ($form->{l_linetotal}) {
1147 $form->{l_onhand} = "Y";
1148 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1149 if ($form->{l_lastcost}) {
1150 $form->{l_linetotallastcost} = "Y";
1151 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1152 $form->{l_linetotallastcost} = "";
1155 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1158 if ($form->{searchitems} eq 'service') {
1160 # remove bin, weight and rop from list
1161 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1163 $form->{l_onhand} = "";
1165 # qty is irrelevant unless bought or sold
1166 if ( $form->{bought}
1171 || $form->{quoted}) {
1172 $form->{l_onhand} = "Y";
1174 $form->{l_linetotalsellprice} = "";
1175 $form->{l_linetotallastcost} = "";
1179 $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1181 IC->all_parts(\%myconfig, \%$form);
1184 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1185 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1188 'bin' => { 'text' => $locale->text('Bin'), },
1189 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1190 'description' => { 'text' => $locale->text('Part Description'), },
1191 'drawing' => { 'text' => $locale->text('Drawing'), },
1192 'image' => { 'text' => $locale->text('Image'), },
1193 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1194 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1195 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1196 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1197 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1198 'listprice' => { 'text' => $locale->text('List Price'), },
1199 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1200 'name' => { 'text' => $locale->text('Name'), },
1201 'onhand' => { 'text' => $locale->text('Qty'), },
1202 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1203 'partnumber' => { 'text' => $locale->text('Part Number'), },
1204 'partsgroup' => { 'text' => $locale->text('Group'), },
1205 'priceupdate' => { 'text' => $locale->text('Updated'), },
1206 'quonumber' => { 'text' => $locale->text('Quotation'), },
1207 'rop' => { 'text' => $locale->text('ROP'), },
1208 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1209 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1210 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1211 'unit' => { 'text' => $locale->text('Unit'), },
1212 'weight' => { 'text' => $locale->text('Weight'), },
1215 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1216 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1218 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1219 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1221 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1222 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1224 foreach my $col (@sort_full) {
1225 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1227 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1229 # add order to callback
1230 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1232 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1234 my %attachment_basenames = (
1235 'part' => $locale->text('part_list'),
1236 'service' => $locale->text('service_list'),
1237 'assembly' => $locale->text('assembly_list'),
1240 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1241 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1242 'output_format' => 'HTML',
1243 'title' => $form->{title},
1244 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1246 $report->set_options_from_form();
1248 $report->set_columns(%column_defs);
1249 $report->set_column_order(@columns);
1251 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1253 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1255 my @subtotal_columns = qw(sellprice listprice lastcost);
1256 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1257 my %totals = map { $_ => 0 } @subtotal_columns;
1259 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1262 foreach my $ref (@{ $form->{parts} }) {
1264 # fresh row, for inserting later
1265 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1267 $ref->{exchangerate} ||= 1;
1268 $ref->{price_factor} ||= 1;
1269 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1270 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1271 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1273 # use this for assemblies
1274 my $onhand = $ref->{onhand};
1276 if ($ref->{assemblyitem}) {
1277 $row->{partnumber}{align} = 'right';
1278 $row->{onhand}{data} = 0;
1279 $onhand = 0 if ($form->{sold});
1282 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1283 $row->{partnumber}->{link} = $edit_link;
1284 $row->{description}->{link} = $edit_link;
1286 foreach (qw(sellprice listprice lastcost)) {
1287 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1288 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1291 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1293 if (!$ref->{assemblyitem}) {
1294 foreach my $col (@subtotal_columns) {
1295 $totals{$col} += $onhand * $ref->{$col};
1296 $subtotals{$col} += $onhand * $ref->{$col};
1299 $subtotals{onhand} += $onhand;
1303 if ($ref->{module} eq 'oe') {
1304 my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1305 $row->{ordnumber}{link} = $edit_oe_link;
1306 $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1309 $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1312 # set properties of images
1313 if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1314 $row->{image}{data} = '';
1315 $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1317 map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1319 $report->add_data($row);
1321 my $next_ref = $form->{parts}[$idx + 1];
1323 # insert subtotal rows
1324 if (($form->{l_subtotal} eq 'Y') &&
1326 (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1327 my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1329 if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1330 $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1333 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1334 map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1336 $report->add_data($row);
1338 $same_item = $next_ref->{ $form->{sort} };
1344 if ($form->{"l_linetotal"}) {
1345 my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1347 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1349 $report->add_separator();
1350 $report->add_data($row);
1353 $report->generate_with_headers();
1355 $lxdebug->leave_sub();
1356 } #end generate_report
1358 sub parts_subtotal {
1359 $lxdebug->enter_sub();
1362 our (%column_data, @column_index);
1363 our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1365 map { $column_data{$_} = "<td> </td>" } @column_index;
1366 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1368 $column_data{onhand} =
1369 "<th class=listsubtotal align=right>"
1370 . $form->format_amount(\%myconfig, $subtotalonhand)
1373 $column_data{linetotalsellprice} =
1374 "<th class=listsubtotal align=right>"
1375 . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1377 $column_data{linetotallistprice} =
1378 "<th class=listsubtotal align=right>"
1379 . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1381 $column_data{linetotallastcost} =
1382 "<th class=listsubtotal align=right>"
1383 . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1386 $subtotalonhand = 0;
1387 $subtotalsellprice = 0;
1388 $subtotallistprice = 0;
1389 $subtotallastcost = 0;
1391 print "<tr class=listsubtotal>";
1393 map { print "\n$column_data{$_}" } @column_index;
1399 $lxdebug->leave_sub();
1403 $lxdebug->enter_sub();
1404 # show history button
1405 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1406 #/show hhistory button
1407 IC->get_part(\%myconfig, \%$form);
1409 $form->{"original_partnumber"} = $form->{"partnumber"};
1411 $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1416 $lxdebug->leave_sub();
1420 $lxdebug->enter_sub();
1422 IC->create_links("IC", \%myconfig, \%$form);
1425 map({ $form->{selectcurrency} .= "<option>$_\n" }
1426 split(/:/, $form->{currencies}));
1428 # parts and assemblies have the same links
1429 my $item = $form->{item};
1430 if ($form->{item} eq 'assembly') {
1434 # build the popup menus
1435 $form->{taxaccounts} = "";
1436 foreach my $key (keys %{ $form->{IC_links} }) {
1437 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1439 # if this is a tax field
1440 if ($key =~ /IC_tax/) {
1441 if ($key =~ /\Q$item\E/) {
1442 $form->{taxaccounts} .= "$ref->{accno} ";
1443 $form->{"IC_tax_$ref->{accno}_description"} =
1444 "$ref->{accno}--$ref->{description}";
1447 if ($form->{amount}{ $ref->{accno} }) {
1448 $form->{"IC_tax_$ref->{accno}"} = "checked";
1451 $form->{"IC_tax_$ref->{accno}"} = "checked";
1456 $form->{"select$key"} .=
1457 "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1458 if ($form->{amount}{$key} eq $ref->{accno}) {
1459 $form->{$key} = "$ref->{accno}--$ref->{description}";
1465 chop $form->{taxaccounts};
1467 if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1468 $form->{selectIC_income} = $form->{selectIC_sale};
1469 $form->{selectIC_expense} = $form->{selectIC_cogs};
1470 $form->{IC_income} = $form->{IC_sale};
1471 $form->{IC_expense} = $form->{IC_cogs};
1474 delete $form->{IC_links};
1475 delete $form->{amount};
1477 $form->get_partsgroup(\%myconfig, { all => 1 });
1479 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1481 if (@{ $form->{all_partsgroup} }) {
1482 $form->{selectpartsgroup} = qq|<option>\n|;
1484 $form->{selectpartsgroup} .=
1485 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1486 } @{ $form->{all_partsgroup} };
1489 if ($form->{item} eq 'assembly') {
1491 foreach my $i (1 .. $form->{assembly_rows}) {
1492 if ($form->{"partsgroup_id_$i"}) {
1493 $form->{"partsgroup_$i"} =
1494 qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1497 $form->get_partsgroup(\%myconfig);
1499 if (@{ $form->{all_partsgroup} }) {
1500 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1503 $form->{selectassemblypartsgroup} .=
1504 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1505 } @{ $form->{all_partsgroup} };
1508 $lxdebug->leave_sub();
1512 $lxdebug->enter_sub();
1514 my ($payment, $rows, $notes, $description, $ean, $buchungsgruppe, $partsgroup, $group, $tax, $lastcost, $eur, $linkaccounts, $weight, $n, $rop, $bin, $vegv);
1515 my ($notdiscountableok, $notdiscountable);
1516 my ($formula, $formula_label, $imagelinks, $obsolete, $shopok, $shop);
1518 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1520 map({ $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, -2) }
1521 qw(sellprice listprice lastcost gv));
1523 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
1524 qw(weight rop stock);
1526 foreach my $item (qw(partnumber description unit notes)) {
1527 $form->{$item} =~ s/\"/"/g;
1530 $payment = qq|<option value=""></option>|;
1531 foreach my $item (@{ $form->{payment_terms} }) {
1532 if ($form->{payment_id} eq $item->{id}) {
1533 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1535 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
1540 if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
1545 qq|<textarea name=notes rows=$rows cols=45 wrap=soft>$form->{notes}</textarea>|;
1546 if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
1548 qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
1551 qq|<input name=description size=40 value="$form->{description}">|;
1554 $ean = qq|<input name=ean size=40 value="$form->{ean}">|;
1556 foreach my $item (split / /, $form->{taxaccounts}) {
1557 $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
1560 IC->retrieve_buchungsgruppen(\%myconfig, $form);
1561 if (@{ $form->{BUCHUNGSGRUPPEN} }) {
1562 foreach my $item (@{ $form->{BUCHUNGSGRUPPEN} }) {
1563 if ($item->{id} == $form->{buchungsgruppen_id}) {
1564 $form->{selectbuchungsgruppe} .=
1565 "<option value=$item->{id} selected>$item->{description}\n";
1566 } elsif (($form->{id} && $form->{orphaned}) || (!$form->{id})) {
1567 $form->{selectbuchungsgruppe} .=
1568 "<option value=$item->{id}>$item->{description}\n";
1574 $buchungsgruppe = qq|
1576 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1577 <td><select name=buchungsgruppen_id>$form->{selectbuchungsgruppe}</select></td>
1582 foreach my $item (qw(IC IC_income IC_expense)) {
1583 if ($form->{$item}) {
1584 if ($form->{id} && $form->{orphaned}) {
1585 $form->{"select$item"} =~ s/ selected//;
1586 $form->{"select$item"} =~
1587 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
1589 $form->{"select$item"} = qq|<option selected>$form->{$item}|;
1594 if ($form->{selectpartsgroup}) {
1595 $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
1597 qq|<input type=hidden name=selectpartsgroup value="|
1598 . $form->escape($form->{selectpartsgroup}, 1) . qq|">|;
1599 $form->{selectpartsgroup} =~
1600 s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
1603 qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
1604 $group = $locale->text('Group');
1608 foreach my $item (split / /, $form->{taxaccounts}) {
1610 <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}> <b>$form->{"IC_tax_${item}_description"}</b>
1611 <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
1615 $form->{obsolete} = "checked" if $form->{obsolete};
1619 <th align="right" nowrap="true">|
1620 . $locale->text('Last Cost') . qq|</th>
1621 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
1627 <th align=right>| . $locale->text('Inventory') . qq|</th>
1628 <td><select name=IC>$form->{selectIC}</select></td>
1629 <input name=selectIC type=hidden value="$form->{selectIC}">
1633 if ($form->{item} eq "part") {
1635 $linkaccounts .= qq|
1637 <th align=right>| . $locale->text('Revenue') . qq|</th>
1638 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1639 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1642 <th align=right>| . $locale->text('Expense') . qq|</th>
1643 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
1644 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
1650 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
1655 <input name=weight size=10 value=$form->{weight}>
1665 if ($form->{item} eq "assembly") {
1671 <th align=right>| . $locale->text('Revenue') . qq|</th>
1672 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1673 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1679 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
1684 $form->{weight}
1685 <input type=hidden name=weight value=$form->{weight}>
1695 if ($form->{item} eq "service") {
1699 <th align=right>| . $locale->text('Revenue') . qq|</th>
1700 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1701 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1704 <th align=right>| . $locale->text('Expense') . qq|</th>
1705 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
1706 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
1711 $linkaccounts = qq|<input type=hidden name=IC_income value="$form->{IC_income_default}">|;
1713 if ($form->{IC_cogs_default}) {
1714 $form->{IC_expense_default} = $form->{IC_cogs_default};
1717 if (($form->{item} eq "service") || ($form->{item} eq "part")) {
1718 $linkaccounts .= qq|<input type=hidden name=IC_expense value="$form->{IC_expense_default}">|;
1720 if ($form->{item} eq "part") {
1721 $linkaccounts .= qq|<input type=hidden name=IC value="$form->{IC_default}">|;
1724 if ($form->{item} ne 'service') {
1725 $n = ($form->{onhand} > 0) ? "1" : "0";
1728 <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
1729 <th align=left nowrap class="plus$n"> |
1730 . $form->format_amount(\%myconfig, $form->{onhand}) . qq|</th>
1734 if ($form->{item} eq 'assembly') {
1737 <th align="right" nowrap>| . $locale->text('Stock') . qq|</th>
1738 <td><input name=stock size=10 value=$form->{stock}></td>
1745 <th align="right" nowrap="true">| . $locale->text('ROP') . qq|</th>
1746 <td><input name=rop size=10 value=$form->{rop}></td>
1752 <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
1753 <td><input name=bin size=10 value=$form->{bin}></td>
1758 <th align="right" nowrap="true">|
1759 . $locale->text('Verrechnungseinheit') . qq|</th>
1760 <td><input name=ve size=10 value=$form->{ve}></td>
1763 <th align="right" nowrap="true">|
1764 . $locale->text('Business Volume') . qq|</th>
1765 <td><input name=gv size=10 value=$form->{gv}></td>
1768 $notdiscountableok = ($form->{not_discountable}) == 1 ? "checked" : "";
1769 $notdiscountable .= qq|
1771 <th align=right nowrap>|
1772 . $locale->text('Not Discountable') . qq|</th>
1773 <td><input class=checkbox type=checkbox name=not_discountable value=1 $notdiscountableok></td>
1778 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>|;
1780 $formula_label = $locale->text('Formula');
1787 <th align=right nowrap>| . $locale->text('Image') . qq|</th>
1788 <td><input name=image size=40 value="$form->{image}"></td>
1789 <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
1790 <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
1793 <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
1794 <td><input name=drawing size=40 value="$form->{drawing}"></td>
1806 <th align="right" nowrap="true">| . $locale->text('Obsolete') . qq|</th>
1807 <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td>
1811 $shopok = $form->{shop} == 1 ? "checked" : "";
1814 <th align=right nowrap>|
1815 . $locale->text('Shopartikel') . qq|</th>
1816 <td><input class=checkbox type=checkbox name=shop value=1 $shopok></td>
1821 # type=submit $locale->text('Add Part')
1822 # type=submit $locale->text('Add Service')
1823 # type=submit $locale->text('Add Assembly')
1825 # type=submit $locale->text('Edit Part')
1826 # type=submit $locale->text('Edit Service')
1827 # type=submit $locale->text('Edit Assembly')
1828 # use JavaScript Calendar or not
1829 my ($jsscript, $button1);
1830 $form->{jsscript} = 1;
1832 if ($form->{jsscript}) {
1834 # with JavaScript Calendar
1836 <td width="13"><input name=priceupdate id=priceupdate size=11 title="$myconfig{dateformat}" value="$form->{priceupdate}"></td>
1837 <td width="4" align="left"><input type=button name=priceupdate id="trigger1" value=|
1838 . $locale->text('button') . qq|></td>
1843 Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1");
1846 # without JavaScript Calendar
1848 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1851 my $unit_select = '<input type="hidden" name="unit_changeable" value="' . $form->{"unit_changeable"} . '">';
1852 if (!$form->{"unit_changeable"}) {
1853 $unit_select .= '<input type="hidden" name="unit" value="' . $form->{"unit"} . '">' . $form->{"unit"};
1855 my $units = AM->retrieve_units(\%myconfig, $form, $form->{"item"} eq "service" ? "service" : "dimension");
1856 $unit_select .= AM->unit_select_html($units, "unit", $form->{"unit"});
1860 if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
1861 my @values = ('', map { $_->{id} } @{ $form->{ALL_PRICE_FACTORS} });
1862 my %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
1865 qq|<tr><th align="right">|
1866 . $locale->text('Price Factor')
1868 . NTI($cgi->popup_menu('-name' => 'price_factor_id',
1869 '-default' => $form->{price_factor_id},
1870 '-values' => \@values,
1871 '-labels' => \%labels))
1875 $form->{fokus} = "ic.partnumber";
1879 <body onLoad="fokus()">
1880 <script type="text/javascript" src="js/common.js"></script>
1881 <script type="text/javascript" src="js/parts_language_selection.js"></script>
1883 <form method=post name="ic" action=$form->{script}>
1885 <input name=id type=hidden value=$form->{id}>
1886 <input name=item type=hidden value=$form->{item}>
1887 <input name=title type=hidden value="$form->{title}">
1888 <input name=makemodel type=hidden value="$form->{makemodel}">
1889 <input name=alternate type=hidden value="$form->{alternate}">
1890 <input name=onhand type=hidden value=$form->{onhand}>
1891 <input name=orphaned type=hidden value=$form->{orphaned}>
1892 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1893 <input name=rowcount type=hidden value=$form->{rowcount}>
1894 <input name=eur type=hidden value=$eur>
1895 <input name=language_values type=hidden value="$form->{language_values}">
1896 <input name="original_partnumber" type="hidden" value="| . $form->quote($form->{"original_partnumber"}) . qq|">
1898 <table width="100%">
1900 <th class=listtop>$form->{title}</th>
1902 <tr height="5"></tr>
1905 <table width="100%">
1907 <th align=left>| . $locale->text('Part Number') . qq|</th>
1908 <th align=left>| . $locale->text('Part Description') . qq|</th>
1909 <th align=left>$group</th>
1912 <td><input name=partnumber value="$form->{partnumber}" size=20></td>
1913 <td>$description</td>
1914 <td>$partsgroup</td>
1915 <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}">
1922 <table width="100%" height="100%">
1925 <table width="100%" height="100%">
1935 <th align="left">| . $locale->text('Notes') . qq|</th>
1936 <th align="left">$formula_label</th>
1947 <th align="left"></th>
1948 <th align="left">| . $locale->text('EAN-Code') . qq|</th>
1952 <button type="button" onclick="parts_language_selection_window('language_values')">| . $locale->text('Set Language Values') . qq|</button>
1962 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
1963 <td><select name=payment_id>$payment</select></td>
1971 <table width="100%">
1973 <th align="right" nowrap="true">|
1974 . $locale->text('Updated') . qq|</th>
1978 <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
1979 <td><input name=listprice size=11 value=$form->{listprice}></td>
1982 <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
1983 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
1988 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
1989 <td>$unit_select</td>
2008 $lxdebug->leave_sub();
2012 $lxdebug->enter_sub();
2014 if ($form->{item} eq "assembly") {
2019 <table width="100%">
2021 <th colspan=2 align=right>|
2022 . $locale->text('Total') . qq| </th>
2024 . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
2029 <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2034 <input type=hidden name=login value=$form->{login}>
2035 <input type=hidden name=password value=$form->{password}>
2036 <input type=hidden name=callback value="$form->{callback}">
2037 <input type=hidden name=previousform value="$form->{previousform}">
2038 <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
2039 <input type=hidden name=vc value=$form->{vc}>
2041 <td><hr size=3 noshade></td>
2046 <input class=submit type=submit name=action value="|
2047 . $locale->text('Update') . qq|">
2050 unless ($form->{item} eq "service") {
2052 <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
2057 <input type=hidden name=price_rows value=$form->{price_rows}>|;
2060 <input class=submit type=submit name=action value="|
2061 . $locale->text('Save') . qq|">|;
2065 if (!$form->{previousform}) {
2067 <input class=submit type=submit name=action value="|
2068 . $locale->text('Save as new') . qq|">|;
2071 if ($form->{orphaned}) {
2072 if (!$form->{previousform}) {
2073 if ($form->{item} eq 'assembly') {
2074 if (!$form->{onhand}) {
2076 <input class=submit type=submit name=action value="|
2077 . $locale->text('Delete') . qq|">|;
2081 <input class=submit type=submit name=action value="|
2082 . $locale->text('Delete') . qq|">|;
2088 if (!$form->{previousform}) {
2089 if ($form->{menubar}) {
2090 require "bin/mozilla/menu.pl";
2094 # button for saving history
2095 if($form->{id} ne "") {
2097 <input type=button class=submit onclick=set_history_window(|
2099 . qq|); name=history id=history value=|
2100 . $locale->text('history')
2103 # /button for saving history
2108 <script type="text/javascript" src="js/wz_tooltip.js"></script>
2114 $lxdebug->leave_sub();
2118 $lxdebug->enter_sub();
2126 <th class="listheading">| . $locale->text('Make') . qq|</th>
2127 <th class="listheading">| . $locale->text('Model') . qq|</th>
2131 for my $i (1 .. $numrows) {
2132 $form->{"make_$i"} =~ s/\"/"/g;
2133 $form->{"model_$i"} =~ s/\"/"/g;
2136 <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
2137 <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
2148 $lxdebug->leave_sub();
2152 $lxdebug->enter_sub();
2154 my (@column_index, %column_data, %column_header);
2155 my ($nochange, $callback, $previousform, $linetotal, $href);
2157 our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
2160 qw(runningnumber qty unit bom partnumber description partsgroup total);
2162 if ($form->{previousform}) {
2164 @column_index = qw(qty unit bom partnumber description partsgroup total);
2168 $form->{old_callback} = $form->{callback};
2169 $callback = $form->{callback};
2170 $form->{callback} = "$form->{script}?action=display_form";
2173 map { delete $form->{$_} } qw(action header);
2177 # save form variables in a previousform variable
2178 foreach my $key (sort keys %$form) {
2181 $form->{$key} =~ s/&/%26/g;
2182 $previousform .= qq|$key=$form->{$key}&|;
2185 $previousform = $form->escape($form->escape($previousform, 1));
2186 $form->{callback} = $callback;
2188 $form->{assemblytotal} = 0;
2189 $form->{weight} = 0;
2192 $column_header{runningnumber} =
2193 qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
2194 $column_header{qty} =
2195 qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
2196 $column_header{unit} =
2197 qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
2198 $column_header{partnumber} =
2199 qq|<th align=left nowrap width=20%>|
2200 . $locale->text('Part Number')
2202 $column_header{description} =
2203 qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
2204 $column_header{total} =
2205 qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
2206 $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
2207 $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
2210 <tr class=listheading>
2211 <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
2219 map { print "\n$column_header{$_}" } @column_index;
2225 for my $i (1 .. $numrows) {
2226 $form->{"partnumber_$i"} =~ s/\"/"/g;
2229 $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
2230 $form->{assemblytotal} += $linetotal;
2232 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
2234 $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
2236 if (($i >= 1) && ($i == $numrows)) {
2239 map { $column_data{$_} = qq|<td></td>| }
2240 qw(qty unit partnumber description bom partsgroup);
2243 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
2246 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2247 $column_data{partnumber} =
2248 qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
2249 $column_data{description} =
2250 qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
2251 $column_data{partsgroup} =
2252 qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
2258 if ($form->{previousform}) {
2259 $column_data{partnumber} =
2260 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
2262 qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
2265 qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
2266 $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
2267 $column_data{bom} .= qq|</td>|;
2269 $column_data{partsgroup} =
2270 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2274 qq|$form->{script}?action=edit&id=$form->{"id_$i"}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
2275 $column_data{partnumber} =
2276 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
2277 $column_data{runningnumber} =
2278 qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
2280 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2282 $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
2284 qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
2286 $column_data{partsgroup} =
2287 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2290 $column_data{unit} =
2291 qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
2292 $column_data{description} =
2293 qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
2296 $column_data{total} = qq|<td align=right>$linetotal</td>|;
2298 $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
2303 map { print "\n$column_data{$_}" } @column_index;
2307 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2308 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
2309 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
2319 $lxdebug->leave_sub();
2323 $lxdebug->enter_sub();
2325 if ($form->{item} eq "assembly") {
2326 my $i = $form->{assembly_rows};
2328 # if last row is empty check the form otherwise retrieve item
2329 if ( ($form->{"partnumber_$i"} eq "")
2330 && ($form->{"description_$i"} eq "")
2331 && ($form->{"partsgroup_$i"} eq "")) {
2337 IC->assembly_item(\%myconfig, \%$form);
2339 my $rows = scalar @{ $form->{item_list} };
2342 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2345 $form->{makemodel_rows}--;
2349 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
2350 qw(partnumber description unit partsgroup);
2351 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
2352 keys %{ $form->{item_list}[0] };
2353 $form->{"runningnumber_$i"} = $form->{assembly_rows};
2354 $form->{assembly_rows}++;
2362 $form->{rowcount} = $i;
2363 $form->{assembly_rows}++;
2370 } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
2374 $lxdebug->leave_sub();
2378 $lxdebug->enter_sub();
2380 my ($parts_id, %newform, $previousform, $amount, $callback);
2382 # check if there is a part number - commented out, cause there is an automatic allocation of numbers
2383 # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
2385 # check if there is a description
2386 $form->isblank("description", $locale->text("Part Description missing!"));
2388 if ($form->{obsolete}) {
2391 "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
2393 if ($form->{onhand} * 1);
2396 if (!$form->{buchungsgruppen_id}) {
2397 $form->error($locale->text("Parts must have an entry type.") . " " .
2398 $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.")
2402 $form->error($locale->text('Description must not be empty!')) unless $form->{description};
2403 $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
2405 # expand dynamic strings
2406 # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
2407 # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
2408 # $locale->text('Part Number missing!')
2409 # $locale->text('Service Number missing!')
2410 # $locale->text('Assembly Number missing!')
2413 $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
2414 if (IC->save(\%myconfig, \%$form) == 3) {
2415 $form->error($locale->text('Partnumber not unique!'));
2417 # saving the history
2418 if(!exists $form->{addition}) {
2419 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2420 $form->{addition} = "SAVED";
2421 $form->save_history($form->dbconnect(\%myconfig));
2423 # /saving the history
2424 $parts_id = $form->{id};
2427 # load previous variables
2428 if ($form->{previousform}) {
2430 # save the new form variables before splitting previousform
2431 map { $newform{$_} = $form->{$_} } keys %$form;
2433 $previousform = $form->unescape($form->{previousform});
2435 # don't trample on previous variables
2436 map { delete $form->{$_} } keys %newform;
2438 # now take it apart and restore original values
2439 foreach my $item (split /&/, $previousform) {
2440 my ($key, $value) = split m/=/, $item, 2;
2441 $value =~ s/%26/&/g;
2442 $form->{$key} = $value;
2444 $form->{taxaccounts} = $newform{taxaccount2};
2446 if ($form->{item} eq 'assembly') {
2448 # undo number formatting
2449 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2450 qw(weight listprice sellprice rop);
2452 $form->{assembly_rows}--;
2453 $i = $newform{rowcount};
2454 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2456 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
2457 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
2459 # change/add values for assembly item
2460 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
2462 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2463 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
2467 # set values for last invoice/order item
2468 $i = $form->{rowcount};
2469 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2471 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
2473 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
2475 if ($form->{exchangerate} != 0) {
2476 $form->{"sellprice_$i"} /= $form->{exchangerate};
2479 $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
2481 map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
2482 chop $form->{"taxaccounts_$i"};
2483 foreach my $item (qw(description rate taxnumber)) {
2484 my $index = $form->{"taxaccounts_$i"} . "_$item";
2485 $form->{$index} = $newform{$index};
2488 # credit remaining calculation
2489 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
2491 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
2492 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
2494 $form->{creditremaining} -= $amount;
2496 # redo number formatting, because invoice parse them!
2497 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
2500 $form->{"id_$i"} = $parts_id;
2502 # Get the actual price factor (not just the ID) for the marge calculation.
2503 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
2504 foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
2505 next if ($pfac->{id} != $newform{price_factor_id});
2506 $form->{"marge_price_factor_$i"} = $pfac->{factor};
2509 delete $form->{ALL_PRICE_FACTORS};
2511 delete $form->{action};
2513 # restore original callback
2514 $callback = $form->unescape($form->{callback});
2515 $form->{callback} = $form->unescape($form->{old_callback});
2516 delete $form->{old_callback};
2518 $form->{makemodel_rows}--;
2520 # put callback together
2521 foreach my $key (keys %$form) {
2523 # do single escape for Apache 2.0
2524 my $value = $form->escape($form->{$key}, 1);
2525 $callback .= qq|&$key=$value|;
2527 $form->{callback} = $callback;
2529 $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
2534 $lxdebug->leave_sub();
2538 $lxdebug->enter_sub();
2540 # saving the history
2541 if(!exists $form->{addition}) {
2542 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2543 $form->{addition} = "SAVED AS NEW";
2544 $form->save_history($form->dbconnect(\%myconfig));
2546 # /saving the history
2548 if ($form->{"original_partnumber"} &&
2549 ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
2550 $form->{partnumber} = "";
2553 $lxdebug->leave_sub();
2557 $lxdebug->enter_sub();
2558 # saving the history
2559 if(!exists $form->{addition}) {
2560 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2561 $form->{addition} = "DELETED";
2562 $form->save_history($form->dbconnect(\%myconfig));
2564 # /saving the history
2565 my $rc = IC->delete(\%myconfig, \%$form);
2568 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2569 $form->error($locale->text('Cannot delete item!'));
2571 $lxdebug->leave_sub();
2575 $lxdebug->enter_sub();
2584 <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
2585 <th class="listheading">| . $locale->text('Preis') . qq|</th>
2588 for my $i (1 .. $numrows) {
2591 <td width=50%><input type=hidden name="pricegroup_$i" size=30 value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
2592 <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
2593 <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
2604 $lxdebug->leave_sub();
2607 sub parts_language_selection {
2608 $lxdebug->enter_sub();
2612 my $languages = IC->retrieve_languages(\%myconfig, $form);
2614 if ($form->{language_values} ne "") {
2615 foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
2616 my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
2618 foreach my $language (@{ $languages }) {
2619 next unless ($language->{id} == $language_id);
2621 $language->{translation} = $translation;
2622 $language->{longdescription} = $longdescription;
2628 my @header_sort = qw(name longdescription);
2629 my %header_title = ( "name" => $locale->text("Name"),
2630 "longdescription" => $locale->text("Long Description"),
2634 map(+{ "column_title" => $header_title{$_},
2636 "callback" => $callback,
2640 $form->{"title"} = $locale->text("Language Values");
2642 print $form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
2643 "LANGUAGES" => $languages,
2644 "onload" => $onload });
2646 $lxdebug->leave_sub();
2649 sub continue { call_sub($form->{"nextsub"}); }