summaryrefslogtreecommitdiff
path: root/bin/mozilla/ic.pl
blob: f689954f04340395058cd8875afdd503d140498e (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://sourceforge.net/projects/ledger-smb/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2001
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. # Contributors:
  22. #
  23. #
  24. # This program is free software; you can redistribute it and/or modify
  25. # it under the terms of the GNU General Public License as published by
  26. # the Free Software Foundation; either version 2 of the License, or
  27. # (at your option) any later version.
  28. #
  29. # This program is distributed in the hope that it will be useful,
  30. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. # GNU General Public License for more details.
  33. # You should have received a copy of the GNU General Public License
  34. # along with this program; if not, write to the Free Software
  35. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  36. #======================================================================
  37. #
  38. # Inventory Control module
  39. #
  40. #======================================================================
  41. use LedgerSMB::IC;
  42. require "$form->{path}/io.pl";
  43. 1;
  44. # end of main
  45. sub add {
  46. %label = ( part => 'Part',
  47. service => 'Service',
  48. assembly => 'Assembly',
  49. labor => 'Labor/Overhead', );
  50. # $locale->text('Add Part')
  51. # $locale->text('Add Service')
  52. # $locale->text('Add Assembly')
  53. # $locale->text('Add Labor/Overhead')
  54. $label = "Add $label{$form->{item}}";
  55. $form->{title} = $locale->text($label);
  56. $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  57. $form->{orphaned} = 1;
  58. if ($form->{previousform}) {
  59. $form->{callback} = "";
  60. }
  61. &link_part;
  62. &display_form;
  63. }
  64. sub edit {
  65. %label = ( part => 'Part',
  66. service => 'Service',
  67. assembly => 'Assembly',
  68. labor => 'Labor/Overhead', );
  69. # $locale->text('Edit Part')
  70. # $locale->text('Edit Service')
  71. # $locale->text('Edit Assembly')
  72. # $locale->text('Edit Labor/Overhead')
  73. IC->get_part(\%myconfig, \%$form);
  74. $label = "Edit $label{$form->{item}}";
  75. $form->{title} = $locale->text($label);
  76. $form->{previousform} = $form->escape($form->{previousform}, 1) if $form->{previousform};
  77. &link_part;
  78. &display_form;
  79. }
  80. sub link_part {
  81. IC->create_links("IC", \%myconfig, \%$form);
  82. # currencies
  83. $form->{selectcurrency} = "";
  84. for (split /:/, $form->{currencies}) { $form->{selectcurrency} .= "<option>$_\n" }
  85. # readonly
  86. if ($form->{item} eq 'part') {
  87. $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Part/;
  88. $form->error($locale->text('Cannot create Part').";".$locale->text('Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} };
  89. $form->error($locale->text('Cannot create Part').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_sale} };
  90. $form->error($locale->text('Cannot create Part').";".$locale->text('COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} };
  91. }
  92. if ($form->{item} eq 'service') {
  93. $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Service/;
  94. $form->error($locale->text('Cannot create Service').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} };
  95. $form->error($locale->text('Cannot create Service').";".$locale->text('Expense account does not exist!')) if ! @{ $form->{IC_links}{IC_expense} };
  96. }
  97. if ($form->{item} eq 'assembly') {
  98. $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Assembly/;
  99. $form->error($locale->text('Cannot create Assembly').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} };
  100. }
  101. if ($form->{item} eq 'labor') {
  102. $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/;
  103. $form->error($locale->text('Cannot create Labor').";".$locale->text('Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} };
  104. $form->error($locale->text('Cannot create Labor').";".$locale->text('COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} };
  105. }
  106. # parts, assemblies , labor and overhead have the same links
  107. $taxpart = ($form->{item} eq 'service') ? "service" : "part";
  108. # build the popup menus
  109. $form->{taxaccounts} = "";
  110. foreach $key (keys %{ $form->{IC_links} }) {
  111. $form->{"select$key"} = "";
  112. foreach $ref (@{ $form->{IC_links}{$key} }) {
  113. # if this is a tax field
  114. if ($key =~ /IC_tax/) {
  115. if ($key =~ /$taxpart/) {
  116. $form->{taxaccounts} .= "$ref->{accno} ";
  117. $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}";
  118. if ($form->{id}) {
  119. if ($form->{amount}{$ref->{accno}}) {
  120. $form->{"IC_tax_$ref->{accno}"} = "checked";
  121. }
  122. } else {
  123. $form->{"IC_tax_$ref->{accno}"} = "checked";
  124. }
  125. }
  126. } else {
  127. $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
  128. }
  129. }
  130. }
  131. chop $form->{taxaccounts};
  132. if ($form->{item} !~ /service/) {
  133. $form->{selectIC_inventory} = $form->{selectIC};
  134. $form->{selectIC_income} = $form->{selectIC_sale};
  135. $form->{selectIC_expense} = $form->{selectIC_cogs};
  136. $form->{IC_income} = $form->{IC_sale};
  137. $form->{IC_expense} = $form->{IC_cogs};
  138. }
  139. # set option
  140. for (qw(IC_inventory IC_income IC_expense)) { $form->{$_} = "$form->{amount}{$_}{accno}--$form->{amount}{$_}{description}" if $form->{amount}{$_}{accno} }
  141. delete $form->{IC_links};
  142. delete $form->{amount};
  143. $form->get_partsgroup(\%myconfig, {all => 1});
  144. if ($form->{partsgroup}) {
  145. $form->{partsgroup} = $form->quote($form->{partsgroup})."--$form->{partsgroup_id}";
  146. }
  147. if (@{ $form->{all_partsgroup} }) {
  148. $form->{selectpartsgroup} = qq|<option>\n|;
  149. for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
  150. delete $form->{all_partsgroup};
  151. }
  152. if ($form->{item} eq 'assembly') {
  153. for (1 .. $form->{assembly_rows}) {
  154. if ($form->{"partsgroup_id_$_"}) {
  155. $form->{"partsgroup_$_"} = qq|$form->{"partsgroup_$_"}--$form->{"partsgroup_id_$_"}|;
  156. }
  157. }
  158. $form->get_partsgroup(\%myconfig);
  159. if (@{ $form->{all_partsgroup} }) {
  160. $form->{selectassemblypartsgroup} = qq|<option>\n|;
  161. for (@{ $form->{all_partsgroup} }) { $form->{selectassemblypartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| }
  162. delete $form->{all_partsgroup};
  163. }
  164. }
  165. # setup make and models
  166. $i = 1;
  167. foreach $ref (@{ $form->{makemodels} }) {
  168. for (qw(make model)) { $form->{"${_}_$i"} = $ref->{$_} }
  169. $i++;
  170. }
  171. $form->{makemodel_rows} = $i - 1;
  172. delete $form->{makemodels};
  173. # setup vendors
  174. if (@{ $form->{all_vendor} }) {
  175. $form->{selectvendor} = "<option>\n";
  176. for (@{ $form->{all_vendor} }) { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  177. delete $form->{all_vendor};
  178. }
  179. # vendor matrix
  180. $i = 1;
  181. foreach $ref (@{ $form->{vendormatrix} }) {
  182. $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|;
  183. for (qw(partnumber lastcost leadtime vendorcurr)) { $form->{"${_}_$i"} = $ref->{$_} }
  184. $i++;
  185. }
  186. $form->{vendor_rows} = $i - 1;
  187. delete $form->{vendormatrix};
  188. # setup customers and groups
  189. if (@{ $form->{all_customer} }) {
  190. $form->{selectcustomer} = "<option>\n";
  191. for (@{ $form->{all_customer} }) { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  192. delete $form->{all_customer};
  193. }
  194. if (@{ $form->{all_pricegroup} }) {
  195. $form->{selectpricegroup} = "<option>\n";
  196. for (@{ $form->{all_pricegroup} }) { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| }
  197. delete $form->{all_pricegroup};
  198. }
  199. $i = 1;
  200. # customer matrix
  201. foreach $ref (@{ $form->{customermatrix} }) {
  202. $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid};
  203. $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}" if $ref->{gid};
  204. for (qw(validfrom validto pricebreak customerprice customercurr)) { $form->{"${_}_$i"} = $ref->{$_} }
  205. $i++;
  206. }
  207. $form->{customer_rows} = $i - 1;
  208. delete $form->{customermatrix};
  209. }
  210. sub form_header {
  211. if ($form->{lastcost} > 0) {
  212. $markup = $form->round_amount((($form->{sellprice}/$form->{lastcost} - 1) * 100), 1);
  213. $form->{markup} = $form->format_amount(\%myconfig, $markup, 1);
  214. }
  215. ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
  216. $dec = length $dec;
  217. $decimalplaces = ($dec > 2) ? $dec : 2;
  218. for (qw(listprice sellprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) }
  219. ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
  220. $dec = length $dec;
  221. $decimalplaces = ($dec > 2) ? $dec : 2;
  222. for (qw(lastcost avgcost)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) }
  223. for (qw(weight rop stock)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
  224. for (qw(partnumber description unit notes)) { $form->{$_} = $form->quote($form->{$_}) }
  225. if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
  226. $rows = 2;
  227. }
  228. $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
  229. if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
  230. $description = qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
  231. } else {
  232. $description = qq|<input name=description size=40 value="$form->{description}">|;
  233. }
  234. for (split / /, $form->{taxaccounts}) { $form->{"IC_tax_$_"} = ($form->{"IC_tax_$_"}) ? "checked" : "" }
  235. $form->{selectIC_inventory} = $form->{selectIC};
  236. # set option
  237. for (qw(IC_inventory IC_income IC_expense)) {
  238. if ($form->{$_}) {
  239. if ($form->{orphaned}) {
  240. $form->{"select$_"} =~ s/ selected//;
  241. $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
  242. } else {
  243. $form->{"select$_"} = qq|<option selected>$form->{$_}|;
  244. }
  245. }
  246. }
  247. if ($form->{selectpartsgroup}) {
  248. $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
  249. $partsgroup = qq|<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">|;
  250. $form->{partsgroup} = $form->quote($form->{partsgroup});
  251. $form->{selectpartsgroup} =~ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
  252. $partsgroup .= qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|;
  253. $group = $locale->text('Group');
  254. }
  255. # tax fields
  256. foreach $item (split / /, $form->{taxaccounts}) {
  257. $tax .= qq|
  258. <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
  259. <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
  260. |;
  261. }
  262. $sellprice = qq|
  263. <tr>
  264. <th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
  265. <td><input name=sellprice size=11 value=$form->{sellprice}></td>
  266. </tr>
  267. <tr>
  268. <th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
  269. <td><input name=listprice size=11 value=$form->{listprice}></td>
  270. </tr>
  271. |;
  272. $avgcost = qq|
  273. <tr>
  274. <th align="right" nowrap="true">|.$locale->text('Average Cost').qq|</th>
  275. <td><input type=hidden name=avgcost value=$form->{avgcost}>$form->{avgcost}</td>
  276. </tr>
  277. |;
  278. $lastcost = qq|
  279. <tr>
  280. <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th>
  281. <td><input name=lastcost size=11 value=$form->{lastcost}></td>
  282. </tr>
  283. <tr>
  284. <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
  285. <td><input name=markup size=5 value=$form->{markup}></td>
  286. <input type=hidden name=oldmarkup value=$markup>
  287. </tr>
  288. |;
  289. if ($form->{item} =~ /(part|assembly)/) {
  290. $n = ($form->{onhand} > 0) ? "1" : "0";
  291. $onhand = qq|
  292. <tr>
  293. <th align="right" nowrap>|.$locale->text('On Hand').qq|</th>
  294. <th align=left nowrap class="plus$n">&nbsp;|.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th>
  295. </tr>
  296. |;
  297. $rop = qq|
  298. <tr>
  299. <th align="right" nowrap="true">|.$locale->text('ROP').qq|</th>
  300. <td><input name=rop size=10 value=$form->{rop}></td>
  301. </tr>
  302. |;
  303. $bin = qq|
  304. <tr>
  305. <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
  306. <td><input name=bin size=10 value="$form->{bin}"></td>
  307. </tr>
  308. |;
  309. $imagelinks = qq|
  310. <tr>
  311. <td>
  312. <table width=100%>
  313. <tr>
  314. <th align=right nowrap>|.$locale->text('Image').qq|</th>
  315. <td><input name=image size=40 value="$form->{image}"></td>
  316. <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
  317. <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
  318. </tr>
  319. <tr>
  320. <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
  321. <td><input name=drawing size=40 value="$form->{drawing}"></td>
  322. </tr>
  323. </table>
  324. </td>
  325. </tr>
  326. |;
  327. }
  328. if ($form->{item} eq "part") {
  329. $linkaccounts = qq|
  330. <tr>
  331. <th align=right>|.$locale->text('Inventory').qq|</th>
  332. <td><select name=IC_inventory>$form->{selectIC_inventory}</select></td>
  333. <input name=selectIC type=hidden value="$form->{selectIC}">
  334. </tr>
  335. <tr>
  336. <th align=right>|.$locale->text('Income').qq|</th>
  337. <td><select name=IC_income>$form->{selectIC_income}</select></td>
  338. <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
  339. </tr>
  340. <tr>
  341. <th align=right>|.$locale->text('COGS').qq|</th>
  342. <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
  343. <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
  344. </tr>
  345. |;
  346. if ($tax) {
  347. $linkaccounts .= qq|
  348. <tr>
  349. <th align=right>|.$locale->text('Tax').qq|</th>
  350. <td>$tax</td>
  351. </tr>
  352. |;
  353. }
  354. $weight = qq|
  355. <tr>
  356. <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
  357. <td>
  358. <table>
  359. <tr>
  360. <td>
  361. <input name=weight size=10 value=$form->{weight}>
  362. </td>
  363. <th>
  364. &nbsp;
  365. $form->{weightunit}
  366. <input type=hidden name=weightunit value=$form->{weightunit}>
  367. </th>
  368. </tr>
  369. </table>
  370. </td>
  371. </tr>
  372. |;
  373. }
  374. if ($form->{item} eq "assembly") {
  375. $avgcost = "";
  376. if ($form->{project_id}) {
  377. $weight = qq|
  378. <tr>
  379. <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
  380. <td>
  381. <table>
  382. <tr>
  383. <td>
  384. <input name=weight size=10 value=$form->{weight}>
  385. </td>
  386. <th>
  387. &nbsp;
  388. $form->{weightunit}
  389. <input type=hidden name=weightunit value=$form->{weightunit}>
  390. </th>
  391. </tr>
  392. </table>
  393. </td>
  394. </tr>
  395. |;
  396. } else {
  397. $weight = qq|
  398. <tr>
  399. <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
  400. <td>
  401. <table>
  402. <tr>
  403. <td>
  404. &nbsp;$form->{weight}
  405. <input type=hidden name=weight value=$form->{weight}>
  406. </td>
  407. <th>
  408. &nbsp;
  409. $form->{weightunit}
  410. <input type=hidden name=weightunit value=$form->{weightunit}>
  411. </th>
  412. </tr>
  413. </table>
  414. </td>
  415. </tr>
  416. |;
  417. }
  418. if ($form->{project_id}) {
  419. $lastcost = "";
  420. $avgcost = "";
  421. $onhand = "";
  422. $rop = "";
  423. $form->{isassemblyitem} = 1;
  424. } else {
  425. $stock = qq|
  426. <tr>
  427. <th align="right" nowrap>|.$locale->text('Stock').qq|</th>
  428. <td><input name=stock size=10 value=$form->{stock}></td>
  429. </tr>
  430. |;
  431. $lastcost = qq|
  432. <tr>
  433. <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th>
  434. <td><input type=hidden name=lastcost value=$form->{lastcost}>$form->{lastcost}</td>
  435. </tr>
  436. <tr>
  437. <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
  438. <td><input name=markup size=5 value=$form->{markup}></td>
  439. <input type=hidden name=oldmarkup value=$markup>
  440. </tr>
  441. |;
  442. }
  443. $linkaccounts = qq|
  444. <tr>
  445. <th align=right>|.$locale->text('Income').qq|</th>
  446. <td><select name=IC_income>$form->{selectIC_income}</select></td>
  447. <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
  448. </tr>
  449. |;
  450. if ($tax) {
  451. $linkaccounts .= qq|
  452. <tr>
  453. <th align=right>|.$locale->text('Tax').qq|</th>
  454. <td>$tax</td>
  455. </tr>
  456. |;
  457. }
  458. }
  459. if ($form->{item} eq "service") {
  460. $avgcost = "";
  461. $linkaccounts = qq|
  462. <tr>
  463. <th align=right>|.$locale->text('Income').qq|</th>
  464. <td><select name=IC_income>$form->{selectIC_income}</select></td>
  465. <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
  466. </tr>
  467. <tr>
  468. <th align=right>|.$locale->text('Expense').qq|</th>
  469. <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
  470. <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
  471. </tr>
  472. |;
  473. if ($tax) {
  474. $linkaccounts .= qq|
  475. <tr>
  476. <th align=right>|.$locale->text('Tax').qq|</th>
  477. <td>$tax</td>
  478. </tr>
  479. |;
  480. }
  481. }
  482. if ($form->{item} eq 'labor') {
  483. $avgcost = "";
  484. $n = ($form->{onhand} > 0) ? "1" : "0";
  485. $onhand = qq|
  486. <tr>
  487. <th align="right" nowrap>|.$locale->text('On Hand').qq|</th>
  488. <th align=left nowrap class="plus$n">&nbsp;|.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th>
  489. </tr>
  490. |;
  491. $linkaccounts = qq|
  492. <tr>
  493. <th align=right>|.$locale->text('Labor/Overhead').qq|</th>
  494. <td><select name=IC_inventory>$form->{selectIC_inventory}</select></td>
  495. <input name=selectIC type=hidden value="$form->{selectIC}">
  496. </tr>
  497. <tr>
  498. <th align=right>|.$locale->text('COGS').qq|</th>
  499. <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
  500. <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
  501. </tr>
  502. |;
  503. }
  504. if ($form->{id}) {
  505. $checked = ($form->{obsolete}) ? "checked" : "";
  506. $obsolete = qq|
  507. <tr>
  508. <th align="right" nowrap="true">|.$locale->text('Obsolete').qq|</th>
  509. <td><input name=obsolete type=checkbox class=checkbox value=1 $checked></td>
  510. </tr>
  511. |;
  512. $obsolete = "<input type=hidden name=obsolete value=$form->{obsolete}>" if $form->{project_id};
  513. }
  514. # type=submit $locale->text('Edit Part')
  515. # type=submit $locale->text('Edit Service')
  516. # type=submit $locale->text('Edit Assembly')
  517. $form->header;
  518. print qq|
  519. <body>
  520. <form method=post action="$form->{script}">
  521. |;
  522. $form->hide_form(qw(id item title makemodel alternate onhand orphaned taxaccounts rowcount baseassembly project_id));
  523. print qq|
  524. <table width="100%">
  525. <tr>
  526. <th class=listtop>$form->{title}</th>
  527. </tr>
  528. <tr height="5"></tr>
  529. <tr>
  530. <td>
  531. <table width="100%">
  532. <tr valign=top>
  533. <th align=left>|.$locale->text('Number').qq|</th>
  534. <th align=left>|.$locale->text('Description').qq|</th>
  535. <th align=left>$group</th>
  536. </tr>
  537. <tr valign=top>
  538. <td><input name=partnumber value="$form->{partnumber}" size=20></td>
  539. <td>$description</td>
  540. <td>$partsgroup</td>
  541. </tr>
  542. </table>
  543. </td>
  544. </tr>
  545. <tr>
  546. <td>
  547. <table width="100%" height="100%">
  548. <tr valign=top>
  549. <td width=70%>
  550. <table width="100%" height="100%">
  551. <tr class="listheading">
  552. <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
  553. </tr>
  554. $linkaccounts
  555. <tr>
  556. <th align="left">|.$locale->text('Notes').qq|</th>
  557. </tr>
  558. <tr>
  559. <td colspan=2>
  560. $notes
  561. </td>
  562. </tr>
  563. </table>
  564. </td>
  565. <td width="30%">
  566. <table width="100%">
  567. <tr>
  568. <th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>
  569. <td><input name=priceupdate size=11 title="$myconfig{dateformat}" value=$form->{priceupdate}></td>
  570. </tr>
  571. $sellprice
  572. $lastcost
  573. $avgcost
  574. <tr>
  575. <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
  576. <td><input name=unit size=5 value="$form->{unit}"></td>
  577. </tr>
  578. $weight
  579. $onhand
  580. $stock
  581. $rop
  582. $bin
  583. $obsolete
  584. </table>
  585. </td>
  586. </tr>
  587. </table>
  588. </td>
  589. </tr>
  590. $imagelinks
  591. |;
  592. }
  593. sub form_footer {
  594. print qq|
  595. <tr>
  596. <td><hr size=3 noshade></td>
  597. </tr>
  598. </table>
  599. |;
  600. $form->hide_form(qw(customer_rows));
  601. if ($form->{item} =~ /(part|assembly)/) {
  602. $form->hide_form(qw(makemodel_rows));
  603. }
  604. if ($form->{item} =~ /(part|service)/) {
  605. $form->hide_form(qw(vendor_rows));
  606. }
  607. # type=submit $locale->text('Update')
  608. # type=submit $locale->text('Save')
  609. # type=submit $locale->text('Save as new')
  610. # type=submit $locale->text('Delete')
  611. if (! $form->{readonly}) {
  612. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  613. 'Save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
  614. );
  615. if ($form->{id}) {
  616. if (!$form->{isassemblyitem}) {
  617. $button{'Save as new'} = { ndx => 7, key => 'N', value => $locale->text('Save as new') };
  618. }
  619. if ($form->{orphaned}) {
  620. $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
  621. }
  622. }
  623. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  624. }
  625. if ($form->{menubar}) {
  626. require "$form->{path}/menu.pl";
  627. &menubar;
  628. }
  629. &assembly_row(++$form->{assembly_rows}) if $form->{item} eq 'assembly';
  630. $form->hide_form(qw(login path sessionid callback previousform isassemblyitem));
  631. print qq|
  632. </form>
  633. </body>
  634. </html>
  635. |;
  636. }
  637. sub search {
  638. $form->get_partsgroup(\%myconfig, { searchitems => $form->{searchitems}});
  639. IC->get_warehouses(\%myconfig, \%$form) unless $form->{searchitems} =~ /(service|labor)/;
  640. if (@{ $form->{all_partsgroup} }) {
  641. $partsgroup = qq|<option>\n|;
  642. for (@{ $form->{all_partsgroup} }) { $partsgroup .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
  643. $partsgroup = qq|
  644. <th align=right nowrap>|.$locale->text('Group').qq|</th>
  645. <td><select name=partsgroup>$partsgroup</select></td>
  646. |;
  647. $l_partsgroup = qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group');
  648. }
  649. $l_listprice = qq|<input name=l_listprice class=checkbox type=checkbox value=Y> |.$locale->text('List Price');
  650. $l_sellprice = qq|<input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Sell Price');
  651. $l_lastcost = qq|<input name=l_lastcost class=checkbox type=checkbox value=Y checked> |.$locale->text('Last Cost');
  652. $l_avgcost = qq|<input name=l_avgcost class=checkbox type=checkbox value=Y checked> |.$locale->text('Average Cost');
  653. $l_linetotal = qq|<input name=l_linetotal class=checkbox type=checkbox value=Y> |.$locale->text('Line Total');
  654. $l_markup = qq|<input name=l_markup class=checkbox type=checkbox value=Y> |.$locale->text('Markup');
  655. $l_account = qq|<input name=l_account class=checkbox type=checkbox value=Y> |.$locale->text('Accounts');
  656. $bought = qq|
  657. <td>
  658. <table>
  659. <tr>
  660. <td><input name=bought class=checkbox type=checkbox value=1></td>
  661. <td nowrap>|.$locale->text('Vendor Invoices').qq|</td>
  662. </tr>
  663. <tr>
  664. <td><input name=onorder class=checkbox type=checkbox value=1></td>
  665. <td nowrap>|.$locale->text('Purchase Orders').qq|</td>
  666. </tr>
  667. <tr>
  668. <td><input name=rfq class=checkbox type=checkbox value=1></td>
  669. <td nowrap>|.$locale->text('RFQ').qq|</td>
  670. </tr>
  671. </table>
  672. </td>
  673. |;
  674. $sold = qq|
  675. <td>
  676. <table>
  677. <tr>
  678. <td><input name=sold class=checkbox type=checkbox value=1></td>
  679. <td nowrap>|.$locale->text('Sales Invoices').qq|</td>
  680. </tr>
  681. <tr>
  682. <td><input name=ordered class=checkbox type=checkbox value=1></td>
  683. <td nowrap>|.$locale->text('Sales Orders').qq|</td>
  684. </tr>
  685. <tr>
  686. <td><input name=quoted class=checkbox type=checkbox value=1></td>
  687. <td nowrap>|.$locale->text('Quotations').qq|</td>
  688. </tr>
  689. </table>
  690. </td>
  691. |;
  692. $fromto = qq|
  693. <td>
  694. <table>
  695. <tr>
  696. <td nowrap><b>|.$locale->text('From').qq|</b>
  697. <input name=transdatefrom size=11 title="$myconfig{dateformat}">
  698. <b>|.$locale->text('To').qq|</b>
  699. <input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  700. </tr>
  701. <tr>
  702. <td nowrap><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  703. <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  704. </tr>
  705. <tr>
  706. <td nowrap>
  707. <input name=open class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|
  708. <input name=closed class=checkbox type=checkbox> |.$locale->text('Closed').qq|
  709. <input name=summary type=radio class=radio value=1> |.$locale->text('Summary').qq|
  710. <input name=summary type=radio class=radio value=0 checked> |.$locale->text('Detail').qq|
  711. </td>
  712. </tr>
  713. </table>
  714. </td>
  715. |;
  716. $l_name = qq|<input name=l_name class=checkbox type=checkbox value=Y> |.$locale->text('Name');
  717. $l_curr = qq|<input name=l_curr class=checkbox type=checkbox value=Y> |.$locale->text('Currency');
  718. $l_employee = qq|<input name=l_employee class=checkbox type=checkbox value=Y> |.$locale->text('Employee');
  719. $l_serialnumber = qq|<input name=l_serialnumber class=checkbox type=checkbox value=Y> |.$locale->text('Serial Number');
  720. $serialnumber = qq|
  721. <th align=right nowrap>|.$locale->text('Serial Number').qq|</th>
  722. <td><input name=serialnumber size=20></td>
  723. |;
  724. $orphaned = qq|
  725. <input name=itemstatus class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned');
  726. if ($form->{searchitems} =~ /(all|part|assembly)/) {
  727. $onhand = qq|
  728. <input name=itemstatus class=radio type=radio value=onhand>&nbsp;|.$locale->text('On Hand').qq|
  729. <input name=itemstatus class=radio type=radio value=short>&nbsp;|.$locale->text('Short').qq|
  730. |;
  731. $makemodel = qq|
  732. <tr>
  733. <th align=right nowrap>|.$locale->text('Make').qq|</th>
  734. <td><input name=make size=20></td>
  735. <th align=right nowrap>|.$locale->text('Model').qq|</th>
  736. <td><input name=model size=20></td>
  737. </tr>
  738. |;
  739. $l_make = qq|<input name=l_make class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Make');
  740. $l_model = qq|<input name=l_model class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Model');
  741. $l_bin = qq|<input name=l_bin class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Bin');
  742. $l_rop = qq|<input name=l_rop class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('ROP');
  743. $l_weight = qq|<input name=l_weight class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Weight');
  744. if (@{ $form->{all_warehouse} }) {
  745. $selectwarehouse = "<option>\n";
  746. for (@{ $form->{all_warehouse} }) { $selectwarehouse .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  747. $warehouse = qq|
  748. <th align=right nowrap>|.$locale->text('Warehouse').qq|</th>
  749. <td><select name=warehouse>$selectwarehouse</select></td>
  750. |;
  751. $l_warehouse = qq|<input name=l_warehouse class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Warehouse');
  752. }
  753. $drawing = qq|
  754. <tr>
  755. <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
  756. <td><input name=drawing size=20></td>
  757. <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
  758. <td><input name=microfiche size=20></td>
  759. </tr>
  760. |;
  761. $l_image = qq|<input name=l_image class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Image');
  762. $l_drawing = qq|<input name=l_drawing class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Drawing');
  763. $l_microfiche = qq|<input name=l_microfiche class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Microfiche');
  764. }
  765. if ($form->{searchitems} eq 'assembly') {
  766. $bought = "";
  767. $toplevel = qq|
  768. <tr>
  769. <td></td>
  770. <td colspan=3>
  771. <input name=null class=radio type=radio checked>&nbsp;|.$locale->text('Top Level').qq|
  772. <input name=individual class=checkbox type=checkbox value=1>&nbsp;|.$locale->text('Individual Items').qq|
  773. </td>
  774. </tr>
  775. |;
  776. $bom = qq|<input name=itemstatus type=radio value=bom>&nbsp;|.$locale->text('BOM');
  777. } elsif ($form->{searchitems} eq 'component') {
  778. $bought = "";
  779. $sold = "";
  780. $fromto = "";
  781. $l_name = "";
  782. $l_curr = "";
  783. $l_employee = "";
  784. $l_serialnumber = "";
  785. $warehouse = "";
  786. $serialnumber = "";
  787. $orphaned = "";
  788. $l_warehouse = "";
  789. $l_account = "";
  790. } elsif ($form->{searchitems} eq 'labor') {
  791. $sold = "";
  792. $warehouse = "";
  793. $serialnumber = "";
  794. $l_avgcost = "";
  795. }
  796. @a = ();
  797. push @a, qq|<input name=l_runningnumber class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('No.');
  798. push @a, qq|<input name=l_partnumber class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Number');
  799. push @a, qq|<input name=l_description class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Description');
  800. push @a, qq|<input name=l_qty class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Qty');
  801. push @a, qq|<input name=l_unit class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Unit');
  802. push @a, qq|<input name=l_priceupdate class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Updated');
  803. push @a, $l_partsgroup if $l_partsgroup;
  804. push @a, $l_listprice if $l_listprice;
  805. push @a, $l_sellprice if $l_sellprice;
  806. push @a, $l_lastcost if $l_lastcost;
  807. push @a, $l_avgcost if $l_avgcost;
  808. push @a, $l_linetotal if $l_linetotal;
  809. push @a, $l_markup if $l_markup;
  810. push @a, $l_bin if $l_bin;
  811. push @a, $l_rop if $l_rop;
  812. push @a, $l_weight if $l_weight;
  813. push @a, qq|<input name=l_notes class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Notes');
  814. push @a, $l_image if $l_image;
  815. push @a, $l_drawing if $l_drawing;
  816. push @a, $l_microfiche if $l_microfiche;
  817. push @a, $l_make if $l_make;
  818. push @a, $l_model if $l_model;
  819. push @a, $l_warehouse if $l_warehouse;
  820. push @a, $l_account if $l_account;
  821. push @a, $l_name if $l_name;
  822. push @a, $l_curr if $l_curr;
  823. push @a, $l_employee if $l_employee;
  824. push @a, $l_serialnumber if $l_serialnumber;
  825. %title = ( all => 'Items',
  826. part => 'Parts',
  827. labor => 'Labor/Overhead',
  828. service => 'Services',
  829. assembly => 'Assemblies',
  830. component => 'Components'
  831. );
  832. # $locale->text('Items')
  833. # $locale->text('Parts')
  834. # $locale->text('Labor/Overhead')
  835. # $locale->text('Services')
  836. # $locale->text('Assemblies')
  837. # $locale->text('Components')
  838. $form->{title} = $locale->text($title{$form->{searchitems}});
  839. $form->header;
  840. print qq|
  841. <body>
  842. <form method=post action=$form->{script}>
  843. |;
  844. $form->hide_form(qw(searchitems title));
  845. print qq|
  846. <table width="100%">
  847. <tr><th class=listtop>$form->{title}</th></tr>
  848. <tr height="5"></tr>
  849. <tr valign=top>
  850. <td>
  851. <table>
  852. <tr>
  853. <th align=right nowrap>|.$locale->text('Number').qq|</th>
  854. <td><input name=partnumber size=20></td>
  855. </tr>
  856. <tr>
  857. <th align=right nowrap>|.$locale->text('Description').qq|</th>
  858. <td colspan=3><input name=description size=40></td>
  859. </tr>
  860. <tr>
  861. $warehouse
  862. </tr>
  863. <tr>
  864. $partsgroup
  865. $serialnumber
  866. </tr>
  867. $makemodel
  868. $drawing
  869. $toplevel
  870. <tr>
  871. <td></td>
  872. <td colspan=3>
  873. <input name=itemstatus class=radio type=radio value=active checked>&nbsp;|.$locale->text('Active').qq|
  874. $onhand
  875. <input name=itemstatus class=radio type=radio value=obsolete>&nbsp;|.$locale->text('Obsolete').qq|
  876. $orphaned
  877. $bom
  878. </td>
  879. </tr>
  880. <tr>
  881. <td></td>
  882. <td colspan=3>
  883. <hr size=1 noshade>
  884. </td>
  885. </tr>
  886. <tr>
  887. <td></td>
  888. $bought
  889. $sold
  890. $fromto
  891. <tr>
  892. <td></td>
  893. <td colspan=3>
  894. <hr size=1 noshade>
  895. </td>
  896. </tr>
  897. <tr>
  898. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  899. <td colspan=3>
  900. <table>
  901. <tr>
  902. |;
  903. while (@a) {
  904. for (1 .. 5) {
  905. print qq|<td nowrap>|. shift @a;
  906. print qq|</td>\n|;
  907. }
  908. print qq|</tr>\n|;
  909. }
  910. print qq|
  911. </tr>
  912. <tr>
  913. <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
  914. </tr>
  915. </table>
  916. </td>
  917. </tr>
  918. </table>
  919. </td>
  920. </tr>
  921. <tr><td colspan=4><hr size=3 noshade></td></tr>
  922. </table>
  923. <input type=hidden name=nextsub value=generate_report>
  924. <br>
  925. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
  926. $form->hide_form(qw(path login sessionid));
  927. print qq|
  928. </form>
  929. |;
  930. if ($form->{menubar}) {
  931. require "$form->{path}/menu.pl";
  932. &menubar;
  933. }
  934. print qq|
  935. </body>
  936. </html>
  937. |;
  938. }
  939. sub generate_report {
  940. # setup $form->{sort}
  941. unless ($form->{sort}) {
  942. if ($form->{description} && !($form->{partnumber})) {
  943. $form->{sort} = "description";
  944. } else {
  945. $form->{sort} = "partnumber";
  946. }
  947. }
  948. if ($form->{itemstatus} eq 'bom') {
  949. $form->{l_perassembly} = "Y" if $form->{l_qty} eq "Y";
  950. $form->{individual} = 1;
  951. $form->{title} = $locale->text('BOM');
  952. }
  953. $callback = "$form->{script}?action=generate_report";
  954. for (qw(path login sessionid searchitems itemstatus individual bom l_linetotal method)) { $callback .= qq|&$_=$form->{$_}| }
  955. for (qw(warehouse partsgroup title)) { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
  956. # if we have a serialnumber limit search
  957. if ($form->{serialnumber} || $form->{l_serialnumber}) {
  958. $form->{l_serialnumber} = "Y";
  959. unless ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) {
  960. if ($form->{searchitems} eq 'assembly') {
  961. $form->{sold} = $form->{ordered} = 1;
  962. } else {
  963. $form->{bought} = $form->{sold} = $form->{onorder} = $form->{ordered} = 1;
  964. }
  965. }
  966. }
  967. if ($form->{itemstatus} eq 'active') {
  968. $option .= $locale->text('Active')." : ";
  969. }
  970. if ($form->{itemstatus} eq 'obsolete') {
  971. $form->{onhand} = $form->{short} = 0;
  972. $form->{l_qty} = 0;
  973. $form->{warehouse} = "";
  974. $form->{l_warehouse} = 0;
  975. $option .= $locale->text('Obsolete')." : ";
  976. }
  977. if ($form->{itemstatus} eq 'orphaned') {
  978. $form->{onhand} = $form->{short} = 0;
  979. $form->{bought} = $form->{sold} = 0;
  980. $form->{onorder} = $form->{ordered} = 0;
  981. $form->{rfq} = $form->{quoted} = 0;
  982. $form->{l_qty} = 0;
  983. $form->{warehouse} = "";
  984. $form->{l_warehouse} = 0;
  985. $form->{transdatefrom} = $form->{transdateto} = "";
  986. $option .= $locale->text('Orphaned')." : ";
  987. }
  988. if ($form->{itemstatus} eq 'onhand') {
  989. $option .= $locale->text('On Hand')." : ";
  990. $form->{l_onhand} = "Y";
  991. }
  992. if ($form->{itemstatus} eq 'short') {
  993. $option .= $locale->text('Short')." : ";
  994. $form->{l_onhand} = "Y";
  995. $form->{l_rop} = "Y" unless $form->{searchitems} eq 'labor';
  996. $form->{warehouse} = "";
  997. $form->{l_warehouse} = 0;
  998. }
  999. if ($form->{l_account}) {
  1000. for (qw(l_name l_curr l_employee)) { delete $form->{$_} }
  1001. } else {
  1002. $ok = 0;
  1003. foreach $l (qw(l_name l_curr l_employee)) {
  1004. if ($form->{$l}) {
  1005. foreach $v (qw(onorder ordered rfq quoted bought sold)) {
  1006. if ($form->{$v}) {
  1007. $ok = 1;
  1008. last;
  1009. }
  1010. }
  1011. if (!$ok) {
  1012. for (qw(onorder ordered rfq quoted bought sold)) { $form->{$_} = 1 }
  1013. }
  1014. last;
  1015. }
  1016. }
  1017. }
  1018. if ($form->{onorder}) {
  1019. $form->{l_ordnumber} = "Y";
  1020. $callback .= "&onorder=$form->{onorder}";
  1021. $option .= $locale->text('Purchase Order')." : ";
  1022. }
  1023. if ($form->{ordered}) {
  1024. $form->{l_ordnumber} = "Y";
  1025. $callback .= "&ordered=$form->{ordered}";
  1026. $option .= $locale->text('Sales Order')." : ";
  1027. }
  1028. if ($form->{rfq}) {
  1029. $form->{l_quonumber} = "Y";
  1030. $callback .= "&rfq=$form->{rfq}";
  1031. $option .= $locale->text('RFQ')." : ";
  1032. }
  1033. if ($form->{quoted}) {
  1034. $form->{l_quonumber} = "Y";
  1035. $callback .= "&quoted=$form->{quoted}";
  1036. $option .= $locale->text('Quotation')." : ";
  1037. }
  1038. if ($form->{bought}) {
  1039. $form->{l_invnumber} = "Y";
  1040. $callback .= "&bought=$form->{bought}";
  1041. $option .= $locale->text('Vendor Invoice')." : ";
  1042. }
  1043. if ($form->{sold}) {
  1044. $form->{l_invnumber} = "Y";
  1045. $callback .= "&sold=$form->{sold}";
  1046. $option .= $locale->text('Sales Invoice')." : ";
  1047. }
  1048. if ($form->{sold} || $form->{bought}) {
  1049. $label = ucfirst $form->{method};
  1050. $option .= $locale->text($label) ." : ";
  1051. }
  1052. if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered} || $form->{rfq} || $form->{quoted}) {
  1053. # warehouse stuff is meaningless
  1054. $form->{warehouse} = "";
  1055. $form->{l_warehouse} = 0;
  1056. $form->{l_account} = "";
  1057. if ($form->{open}) {
  1058. $callback .= "&open=$form->{open}";
  1059. $option .= $locale->text('Open');
  1060. }
  1061. if ($form->{closed}) {
  1062. $callback .= "&closed=$form->{closed}";
  1063. if ($form->{open}) {
  1064. $option .= " : ".$locale->text('Closed');
  1065. } else {
  1066. $option .= $locale->text('Closed');
  1067. }
  1068. }
  1069. if ($form->{summary}) {
  1070. $callback .= "&summary=$form->{summary}";
  1071. $option .= " : ".$locale->text('Summary');
  1072. $form->{l_ordnumber} = "";
  1073. $form->{l_quonumber} = "";
  1074. $form->{l_invnumber} = "";
  1075. } else {
  1076. $option .= " : ".$locale->text('Detail');
  1077. }
  1078. if ($form->{transdatefrom}) {
  1079. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1080. $option .= "\n<br>".$locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
  1081. }
  1082. if ($form->{transdateto}) {
  1083. $callback .= "&transdateto=$form->{transdateto}";
  1084. $option .= "\n<br>".$locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
  1085. }
  1086. }
  1087. if ($form->{warehouse}) {
  1088. ($warehouse) = split /--/, $form->{warehouse};
  1089. $option .= "<br>".$locale->text('Warehouse')." : $warehouse";
  1090. $form->{l_warehouse} = 0;
  1091. }
  1092. $option .= "<br>";
  1093. if ($form->{partnumber}) {
  1094. $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
  1095. $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
  1096. }
  1097. if ($form->{partsgroup}) {
  1098. ($partsgroup) = split /--/, $form->{partsgroup};
  1099. $option .= $locale->text('Group').qq| : $partsgroup<br>|;
  1100. }
  1101. if ($form->{serialnumber}) {
  1102. $callback .= "&serialnumber=".$form->escape($form->{serialnumber},1);
  1103. $option .= $locale->text('Serial Number').qq| : $form->{serialnumber}<br>|;
  1104. }
  1105. if ($form->{description}) {
  1106. $callback .= "&description=".$form->escape($form->{description},1);
  1107. $description = $form->{description};
  1108. $description =~ s/\r?\n/<br>/g;
  1109. $option .= $locale->text('Description').qq| : $form->{description}<br>|;
  1110. }
  1111. if ($form->{make}) {
  1112. $callback .= "&make=".$form->escape($form->{make},1);
  1113. $option .= $locale->text('Make').qq| : $form->{make}<br>|;
  1114. }
  1115. if ($form->{model}) {
  1116. $callback .= "&model=".$form->escape($form->{model},1);
  1117. $option .= $locale->text('Model').qq| : $form->{model}<br>|;
  1118. }
  1119. if ($form->{drawing}) {
  1120. $callback .= "&drawing=".$form->escape($form->{drawing},1);
  1121. $option .= $locale->text('Drawing').qq| : $form->{drawing}<br>|;
  1122. }
  1123. if ($form->{microfiche}) {
  1124. $callback .= "&microfiche=".$form->escape($form->{microfiche},1);
  1125. $option .= $locale->text('Microfiche').qq| : $form->{microfiche}<br>|;
  1126. }
  1127. if ($form->{l_markup}) {
  1128. $form->{l_sellprice} = "Y";
  1129. $form->{l_lastcostmarkup} = "Y" if $form->{l_lastcost};
  1130. $form->{l_avgcostmarkup} = "Y" if $form->{l_avgcost};
  1131. }
  1132. @columns = $form->sort_columns(qw(partnumber description notes assemblypartnumber partsgroup make model bin onhand perassembly rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost lastcostmarkup avgcost linetotalavgcost avgcostmarkup curr priceupdate weight image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse));
  1133. unshift @columns, "runningnumber";
  1134. if ($form->{l_linetotal}) {
  1135. $form->{l_onhand} = "Y";
  1136. $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
  1137. $form->{l_linetotallastcost} = "Y" if $form->{l_lastcost};
  1138. $form->{l_linetotalavgcost} = "Y" if $form->{l_avgcost};
  1139. $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
  1140. }
  1141. if ($form->{searchitems} eq 'service') {
  1142. # remove bin, weight and rop from list
  1143. for (qw(bin weight rop)) { $form->{"l_$_"} = "" }
  1144. $form->{l_onhand} = "";
  1145. # qty is irrelevant unless bought or sold
  1146. if ($form->{bought} || $form->{sold} || $form->{onorder} ||
  1147. $form->{ordered} || $form->{rfq} || $form->{quoted}) {
  1148. $form->{l_onhand} = "Y";
  1149. } else {
  1150. for (qw(sellprice lastcost avgcost listprice)) { $form->{"l_linetotal$_"} = "" }
  1151. }
  1152. } else {
  1153. $form->{l_onhand} = "Y" if $form->{l_qty};
  1154. }
  1155. foreach $item (@columns) {
  1156. if ($form->{"l_$item"} eq "Y") {
  1157. push @column_index, $item;
  1158. # add column to callback
  1159. $callback .= "&l_$item=Y";
  1160. }
  1161. }
  1162. if ($form->{l_account} eq 'Y') {
  1163. if ($form->{searchitems} eq 'all' || $form->{searchitems} eq 'part') {
  1164. push @column_index, (qw(inventory income expense tax));
  1165. } elsif ($form->{searchitems} eq 'service') {
  1166. push @column_index, (qw(income expense tax));
  1167. } elsif ($form->{searchitems} eq 'assembly') {
  1168. push @column_index, (qw(income tax));
  1169. } else {
  1170. push @column_index, (qw(inventory expense));
  1171. }
  1172. $callback .= "&l_account=Y";
  1173. }
  1174. if ($form->{l_subtotal} eq 'Y') {
  1175. $callback .= "&l_subtotal=Y";
  1176. }
  1177. IC->all_parts(\%myconfig, \%$form);
  1178. $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
  1179. $href = $callback;
  1180. $form->sort_order();
  1181. $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
  1182. if ($form->{searchitems} eq 'assembly') {
  1183. if ($form->{l_partnumber}) {
  1184. # replace partnumber with partnumber_
  1185. $ndx = 0;
  1186. foreach $item (@column_index) {
  1187. $ndx++;
  1188. last if $item eq 'partnumber';
  1189. }
  1190. splice @column_index, $ndx, 0, map { "partnumber_$_" } (1 .. $form->{pncol});
  1191. $colspan = $form->{pncol} + 1;
  1192. }
  1193. }
  1194. if ($form->{searchitems} eq 'component') {
  1195. if ($form->{l_partnumber}) {
  1196. # splice it in after the partnumber
  1197. $ndx = 0;
  1198. foreach $item (@column_index) {
  1199. $ndx++;
  1200. last if $item eq 'partnumber';
  1201. }
  1202. @a = splice @column_index, 0, $ndx;
  1203. unshift @column_index, "assemblypartnumber";
  1204. unshift @column_index, @a;
  1205. }
  1206. }
  1207. $column_header{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
  1208. $column_header{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|;
  1209. $column_header{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  1210. $column_header{notes} = qq|<th nowrap class=listheading>|.$locale->text('Notes').qq|</th>|;
  1211. $column_header{partsgroup} = qq|<th nowrap><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|;
  1212. $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</a></th>|;
  1213. $column_header{priceupdate} = qq|<th nowrap><a class=listheading href=$href&sort=priceupdate>|.$locale->text('Updated').qq|</a></th>|;
  1214. $column_header{onhand} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
  1215. $column_header{perassembly} = qq|<th>&nbsp;</th>|;
  1216. $column_header{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
  1217. $column_header{listprice} = qq|<th class=listheading nowrap>|.$locale->text('List Price').qq|</th>|;
  1218. $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Last Cost').qq|</th>|;
  1219. $column_header{avgcost} = qq|<th class=listheading nowrap>|.$locale->text('Avg Cost').qq|</th>|;
  1220. $column_header{rop} = qq|<th class=listheading nowrap>|.$locale->text('ROP').qq|</th>|;
  1221. $column_header{weight} = qq|<th class=listheading nowrap>|.$locale->text('Weight').qq|</th>|;
  1222. $column_header{avgcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
  1223. $column_header{lastcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
  1224. $column_header{make} = qq|<th nowrap><a class=listheading href=$href&sort=make>|.$locale->text('Make').qq|</a></th>|;
  1225. $column_header{model} = qq|<th nowrap><a class=listheading href=$href&sort=model>|.$locale->text('Model').qq|</a></th>|;
  1226. $column_header{invnumber} = qq|<th nowrap><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice Number').qq|</a></th>|;
  1227. $column_header{ordnumber} = qq|<th nowrap><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order Number').qq|</a></th>|;
  1228. $column_header{quonumber} = qq|<th nowrap><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;
  1229. $column_header{name} = qq|<th nowrap><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
  1230. $column_header{employee} = qq|<th nowrap><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|;
  1231. $column_header{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Sell Price').qq|</th>|;
  1232. for (qw(sellprice lastcost avgcost listprice)) { $column_header{"linetotal$_"} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>| }
  1233. $column_header{curr} = qq|<th nowrap><a class=listheading href=$href&sort=curr>|.$locale->text('Curr').qq|</a></th>|;
  1234. $column_header{image} = qq|<th class=listheading nowrap>|.$locale->text('Image').qq|</a></th>|;
  1235. $column_header{drawing} = qq|<th nowrap><a class=listheading href=$href&sort=drawing>|.$locale->text('Drawing').qq|</a></th>|;
  1236. $column_header{microfiche} = qq|<th nowrap><a class=listheading href=$href&sort=microfiche>|.$locale->text('Microfiche').qq|</a></th>|;
  1237. $column_header{serialnumber} = qq|<th nowrap><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|;
  1238. $column_header{assemblypartnumber} = qq|<th nowrap><a class=listheading href=$href&sort=assemblypartnumber>|.$locale->text('Assembly').qq|</a></th>|;
  1239. $column_header{warehouse} = qq|<th nowrap class=listheading>|.$locale->text('Warehouse').qq|</th>|;
  1240. $column_header{inventory} = qq|<th nowrap class=listheading>|.$locale->text('Inventory').qq|</th>|;
  1241. $column_header{income} = qq|<th nowrap class=listheading>|.$locale->text('Income').qq|</th>|;
  1242. $column_header{expense} = qq|<th nowrap class=listheading>|.$locale->text('Expense').qq|</th>|;
  1243. $column_header{tax} = qq|<th nowrap class=listheading>|.$locale->text('Tax').qq|</th>|;
  1244. $form->header;
  1245. $i = 1;
  1246. if ($form->{searchitems} eq 'part') {
  1247. $button{'Goods & Services--Add Part'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Part').qq|"> |;
  1248. $button{'Goods & Services--Add Part'}{order} = $i++;
  1249. }
  1250. if ($form->{searchitems} eq 'service') {
  1251. $button{'Goods & Services--Add Service'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Service').qq|"> |;
  1252. $button{'Goods & Services--Add Service'}{order} = $i++;
  1253. }
  1254. if ($form->{searchitems} eq 'assembly') {
  1255. $button{'Goods & Services--Add Assembly'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Assembly').qq|"> |;
  1256. $button{'Goods & Services--Add Assembly'}{order} = $i++;
  1257. }
  1258. if ($form->{searchitems} eq 'labor') {
  1259. $button{'Goods & Services--Add Labor/Overhead'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Labor/Overhead').qq|"> |;
  1260. $button{'Goods & Services--Add Labor/Overhead'}{order} = $i++;
  1261. }
  1262. foreach $item (split /;/, $myconfig{acs}) {
  1263. delete $button{$item};
  1264. }
  1265. print qq|
  1266. <body>
  1267. <table width=100%>
  1268. <tr>
  1269. <th class=listtop>$form->{title}</th>
  1270. </tr>
  1271. <tr height="5"></tr>
  1272. <tr><td>$option</td></tr>
  1273. <tr>
  1274. <td>
  1275. <table width=100%>
  1276. <tr class=listheading>
  1277. |;
  1278. for (@column_index) { print "\n$column_header{$_}" }
  1279. print qq|
  1280. </tr>
  1281. |;
  1282. # add order to callback
  1283. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1284. # escape callback for href
  1285. $callback = $form->escape($callback);
  1286. $k = $#{@{ $form->{parts} }};
  1287. @groupby = ($form->{sort});
  1288. if ($form->{summary}) {
  1289. @groupby = ();
  1290. for (qw(partnumber description notes partsgroup make model bin curr priceupdate image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse)) { $a{$_} = 1 };
  1291. for (@column_index) {
  1292. if ($a{$_}) {
  1293. push @groupby, $_;
  1294. }
  1295. }
  1296. push @groupby, "id";
  1297. }
  1298. if ($k > 0) {
  1299. $samegroup = "";
  1300. for (@groupby) { $samegroup .= $form->{parts}->[0]->{$_} }
  1301. }
  1302. $i = 0;
  1303. $n = 0;
  1304. foreach $ref (@{ $form->{parts} }) {
  1305. $ref->{exchangerate} ||= 1;
  1306. $ref->{discount} *= 1;
  1307. if ($form->{summary}) {
  1308. $summary{$ref->{id}}{total} += $ref->{sellprice} * $ref->{onhand};
  1309. $summary{$ref->{id}}{onhand} += $ref->{onhand};
  1310. if ($n < $k) {
  1311. $nextgroup = "";
  1312. for (@groupby) { $nextgroup .= $form->{parts}->[$n+1]->{$_} }
  1313. $n++;
  1314. $form->{parts}->[$n]->{exchangerate} ||= 1;
  1315. if ($samegroup eq $nextgroup) {
  1316. for (qw(exchangerate discount)) { $form->{parts}->[$n]->{$_} = ($ref->{$_} + $form->{parts}->[$n]->{$_}) / 2 }
  1317. next;
  1318. }
  1319. $samegroup = $nextgroup;
  1320. }
  1321. $ref->{onhand} = $summary{$ref->{id}}{onhand};
  1322. $ref->{sellprice} = ($ref->{onhand}) ? $summary{$ref->{id}}{total} / $ref->{onhand} : 0;
  1323. $summary{$ref->{id}}{total} = 0;
  1324. $summary{$ref->{id}}{onhand} = 0;
  1325. }
  1326. if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
  1327. if ($sameitem ne $ref->{$form->{sort}}) {
  1328. &parts_subtotal;
  1329. $sameitem = $ref->{$form->{sort}};
  1330. }
  1331. }
  1332. $i++;
  1333. if ($form->{l_curr}) {
  1334. if ($ref->{module} eq 'oe') {
  1335. $ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount});
  1336. } else {
  1337. for (qw(sellprice listprice lastcost avgcost)) { $ref->{$_} /= $ref->{exchangerate} }
  1338. }
  1339. } else {
  1340. if ($ref->{module} eq 'oe') {
  1341. $ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount});
  1342. for (qw(sellprice listprice lastcost avgcost)) { $ref->{$_} *= $ref->{exchangerate} }
  1343. }
  1344. }
  1345. if (!$form->{summary}) {
  1346. for (qw(sellprice listprice lastcost avgcost)) { $ref->{$_} = $form->round_amount($ref->{$_}, 2) }
  1347. }
  1348. if ($form->{l_markup}) {
  1349. $ref->{lastcostmarkup} = (($ref->{sellprice} / $ref->{lastcost}) - 1) * 100 if $ref->{lastcost} != 0;
  1350. $ref->{avgcostmarkup} = (($ref->{sellprice} / $ref->{avgcost}) - 1) * 100 if $ref->{avgcost} != 0;
  1351. }
  1352. # use this for assemblies
  1353. $onhand = $ref->{onhand};
  1354. for (qw(description notes)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1355. for (1 .. $form->{pncol}) { $column_data{"partnumber_$_"} = "<td>&nbsp;</td>" }
  1356. $column_data{runningnumber} = "<td align=right>$i</td>";
  1357. $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
  1358. if ($ref->{assemblypartnumber}) {
  1359. if ($sameid eq $ref->{id}) {
  1360. $i--;
  1361. for (qw(runningnumber partnumber)) { $column_data{$_} = "<td>&nbsp;</td>" }
  1362. }
  1363. }
  1364. $column_data{assemblypartnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{assembly_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{assemblypartnumber}&nbsp;</a></td>";
  1365. if ($ref->{assemblyitem}) {
  1366. $onhand = 0 if $form->{sold};
  1367. $ref->{income} = "";
  1368. for (qw(runningnumber partnumber)) { $column_data{$_} = "<td>&nbsp;</td>" }
  1369. $i--;
  1370. $column_data{"partnumber_$ref->{stagger}"} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
  1371. }
  1372. for (qw(description notes partsgroup employee curr)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1373. $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")."</td>";
  1374. $column_data{perassembly} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{perassembly}, '', "&nbsp;")."</td>";
  1375. if ($form->{summary}) {
  1376. $column_data{sellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{sellprice}, 4, "&nbsp;") . "</td>";
  1377. } else {
  1378. $column_data{sellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;") . "</td>";
  1379. }
  1380. for (qw(listprice lastcost avgcost)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;") . "</td>" }
  1381. for (qw(lastcost avgcost)) { $column_data{"${_}markup"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{"${_}markup"}, 1, "&nbsp;")."</td>" }
  1382. if ($form->{l_linetotal}) {
  1383. for (qw(sellprice lastcost avgcost listprice)) { $column_data{"linetotal$_"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2, "&nbsp;")."</td>" }
  1384. }
  1385. if ($ref->{assemblyitem} && $ref->{stagger} > 1) {
  1386. for (qw(sellprice lastcost avgcost listprice)) { $column_data{"linetotal$_"} = "<td>&nbsp;</td>" }
  1387. }
  1388. if (!$ref->{assemblyitem}) {
  1389. $totalsellprice += $onhand * $ref->{sellprice};
  1390. $totallastcost += $onhand * $ref->{lastcost};
  1391. $totalavgcost += $onhand * $ref->{avgcost};
  1392. $totallistprice += $onhand * $ref->{listprice};
  1393. $subtotalonhand += $onhand;
  1394. $subtotalsellprice += $onhand * $ref->{sellprice};
  1395. $subtotallastcost += $onhand * $ref->{lastcost};
  1396. $subtotalavgcost += $onhand * $ref->{avgcost};
  1397. $subtotallistprice += $onhand * $ref->{listprice};
  1398. }
  1399. $column_data{rop} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;")."</td>";
  1400. $column_data{weight} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{weight}, '', "&nbsp;")."</td>";
  1401. $column_data{unit} = "<td>$ref->{unit}&nbsp;</td>";
  1402. $column_data{bin} = "<td>$ref->{bin}&nbsp;</td>";
  1403. $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
  1404. $ref->{module} = 'ps' if $ref->{till};
  1405. $column_data{invnumber} = ($ref->{module} ne 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</a></td>" : "<td>$ref->{invnumber}&nbsp;</td>";
  1406. $column_data{ordnumber} = ($ref->{module} eq 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber}&nbsp;</a></td>" : "<td>$ref->{ordnumber}&nbsp;</td>";
  1407. $column_data{quonumber} = ($ref->{module} eq 'oe' && !$ref->{ordnumber}) ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber}&nbsp;</a></td>" : "<td>$ref->{quonumber}&nbsp;</td>";
  1408. $column_data{name} = "<td>$ref->{name}&nbsp;</td>";
  1409. $column_data{image} = ($ref->{image}) ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>" : "<td>&nbsp;</td>";
  1410. $column_data{drawing} = ($ref->{drawing}) ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>" : "<td>&nbsp;</td>";
  1411. $column_data{microfiche} = ($ref->{microfiche}) ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>" : "<td>&nbsp;</td>";
  1412. for (qw(make model serialnumber warehouse inventory income expense tax)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1413. $j++; $j %= 2;
  1414. print "<tr class=listrow$j>";
  1415. for (@column_index) { print "\n$column_data{$_}" }
  1416. print qq|
  1417. </tr>
  1418. |;
  1419. $sameid = $ref->{id};
  1420. }
  1421. if ($form->{l_subtotal} eq 'Y') {
  1422. &parts_subtotal;
  1423. }
  1424. if ($form->{"l_linetotal"}) {
  1425. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1426. $column_data{linetotalsellprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalsellprice, 2, "&nbsp;")."</th>";
  1427. $column_data{linetotallastcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallastcost, 2, "&nbsp;")."</th>";
  1428. $column_data{linetotalavgcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalavgcost, 2, "&nbsp;")."</th>";
  1429. $column_data{linetotallistprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallistprice, 2, "&nbsp;")."</th>";
  1430. print "<tr class=listtotal>";
  1431. for (@column_index) { print "\n$column_data{$_}" }
  1432. print qq|</tr>
  1433. |;
  1434. }
  1435. print qq|
  1436. </table>
  1437. </td>
  1438. </tr>
  1439. <tr><td><hr size=3 noshade></td></tr>
  1440. </table>
  1441. |;
  1442. print qq|
  1443. <br>
  1444. <form method=post action=$form->{script}>
  1445. <input type=hidden name=item value=$form->{searchitems}>
  1446. |;
  1447. $form->hide_form(qw(callback path login sessionid));
  1448. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  1449. print $item->{code};
  1450. }
  1451. if ($form->{menubar}) {
  1452. require "$form->{path}/menu.pl";
  1453. &menubar;
  1454. }
  1455. print qq|
  1456. </form>
  1457. </body>
  1458. </html>
  1459. |;
  1460. }
  1461. sub parts_subtotal {
  1462. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1463. $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{individual});
  1464. $column_data{onhand} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalonhand, '', "&nbsp;")."</th>";
  1465. $column_data{linetotalsellprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalsellprice, 2, "&nbsp;")."</th>";
  1466. $column_data{linetotallistprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallistprice, 2, "&nbsp;")."</th>";
  1467. $column_data{linetotallastcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallastcost, 2, "&nbsp;")."</th>";
  1468. $column_data{linetotalavgcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalavgcost, 2, "&nbsp;")."</th>";
  1469. $subtotalonhand = 0;
  1470. $subtotalsellprice = 0;
  1471. $subtotallistprice = 0;
  1472. $subtotallastcost = 0;
  1473. $subtotalavgcost = 0;
  1474. print "<tr class=listsubtotal>";
  1475. for (@column_index) { print "\n$column_data{$_}" }
  1476. print qq|
  1477. </tr>
  1478. |;
  1479. }
  1480. sub requirements {
  1481. $form->get_partsgroup(\%myconfig, { searchitems => 'parts'});
  1482. $form->all_years(\%myconfig);
  1483. if (@{ $form->{all_partsgroup} }) {
  1484. $partsgroup = qq|<option>\n|;
  1485. for (@{ $form->{all_partsgroup} }) { $partsgroup .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
  1486. $partsgroup = qq|
  1487. <th align=right nowrap>|.$locale->text('Group').qq|</th>
  1488. <td><select name=partsgroup>$partsgroup</select></td>
  1489. |;
  1490. $l_partsgroup = qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group');
  1491. }
  1492. if (@{ $form->{all_years} }) {
  1493. # accounting years
  1494. $form->{selectaccountingyear} = qq|<option>\n|;
  1495. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  1496. $selectfrom = qq|
  1497. <tr>
  1498. <th align=right>|.$locale->text('Period').qq|</th>
  1499. <td colspan=3>
  1500. <table>
  1501. <tr>
  1502. <td>
  1503. <select name=year>$form->{selectaccountingyear}</select>
  1504. </td>
  1505. <td>
  1506. |;
  1507. $selectfrom .= qq|
  1508. <table>
  1509. <tr>
  1510. |;
  1511. for (sort keys %{ $form->{all_month} }) {
  1512. $i = ($_ * 1) - 1;
  1513. if (($i % 3) == 0) {
  1514. $selectfrom .= qq|
  1515. </tr>
  1516. <tr>
  1517. |;
  1518. }
  1519. $i = $_ * 1;
  1520. $selectfrom .= qq|
  1521. <td nowrap><input name="l_month_$i" class checkbox type=checkbox value=Y>&nbsp;|.$locale->text($form->{all_month}{$_}).qq|</td>\n|;
  1522. }
  1523. $selectfrom .= qq|
  1524. </tr>
  1525. </table>
  1526. </td>
  1527. </tr>
  1528. </table>
  1529. </td>
  1530. </tr>
  1531. |;
  1532. } else {
  1533. $form->error($locale->text('No History!'));
  1534. }
  1535. $form->{title} = $locale->text('Parts Requirements');
  1536. $form->header;
  1537. print qq|
  1538. <body>
  1539. <form method=post action=$form->{script}>
  1540. |;
  1541. print qq|
  1542. <table width="100%">
  1543. <tr><th class=listtop>$form->{title}</th></tr>
  1544. <tr height="5"></tr>
  1545. <tr valign=top>
  1546. <td>
  1547. <table>
  1548. <tr>
  1549. <th align=right nowrap>|.$locale->text('Number').qq|</th>
  1550. <td><input name=partnumber size=20></td>
  1551. </tr>
  1552. <tr>
  1553. <th align=right nowrap>|.$locale->text('Description').qq|</th>
  1554. <td colspan=3><input name=description size=40></td>
  1555. </tr>
  1556. <tr>
  1557. $partsgroup
  1558. </tr>
  1559. $selectfrom
  1560. </table>
  1561. </td>
  1562. </tr>
  1563. <tr>
  1564. <td><hr size=3 noshade></td>
  1565. </tr>
  1566. </table>
  1567. <input type=hidden name=nextsub value=requirements_report>
  1568. <input type=hidden name=sort value=partnumber>
  1569. <br>
  1570. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
  1571. $form->hide_form(qw(path login sessionid));
  1572. print qq|
  1573. </form>
  1574. |;
  1575. if ($form->{menubar}) {
  1576. require "$form->{path}/menu.pl";
  1577. &menubar;
  1578. }
  1579. print qq|
  1580. </body>
  1581. </html>
  1582. |;
  1583. }
  1584. sub requirements_report {
  1585. $callback = "$form->{script}?action=requirements_report";
  1586. for (qw(path login sessionid year)) { $callback .= qq|&$_=$form->{$_}| }
  1587. for (qw(partsgroup)) { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
  1588. if ($form->{partnumber}) {
  1589. $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
  1590. $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
  1591. }
  1592. if ($form->{partsgroup}) {
  1593. ($partsgroup) = split /--/, $form->{partsgroup};
  1594. $option .= $locale->text('Group').qq| : $partsgroup<br>|;
  1595. }
  1596. if ($form->{description}) {
  1597. $callback .= "&description=".$form->escape($form->{description},1);
  1598. $description = $form->{description};
  1599. $description =~ s/\r?\n/<br>/g;
  1600. $option .= $locale->text('Description').qq| : $form->{description}<br>|;
  1601. }
  1602. @column_index = $form->sort_columns(qw(partnumber description));
  1603. unshift @column_index, "runningnumber";
  1604. for (1 .. 12) {
  1605. if ($form->{"l_month_$_"}) {
  1606. $callback .= qq|&l_month_$_=$form->{"l_month_$_"}|;
  1607. push @column_index, $_;
  1608. $month{$_} = 1;
  1609. }
  1610. }
  1611. push @column_index, "year" unless %month;
  1612. push @column_index, qw(onhand so po order);
  1613. IC->requirements(\%myconfig, \%$form);
  1614. $form->sort_order();
  1615. $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
  1616. $href = $callback;
  1617. $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
  1618. if (%month) {
  1619. $option .= $locale->text('Year').qq| : $form->{year}<br>|;
  1620. }
  1621. $column_header{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
  1622. $column_header{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|;
  1623. $column_header{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  1624. $column_header{onhand} = qq|<th class=listheading nowrap>|.$locale->text('Onhand').qq|</th>|;
  1625. $column_header{so} = qq|<th class=listheading nowrap>|.$locale->text('SO').qq|</th>|;
  1626. $column_header{po} = qq|<th class=listheading nowrap>|.$locale->text('PO').qq|</th>|;
  1627. $column_header{order} = qq|<th class=listheading nowrap>|.$locale->text('Order').qq|</th>|;
  1628. $column_header{year} = qq|<th class=listheading nowrap>$form->{year}</th>|;
  1629. for (sort { $a <=> $b } keys %month) { $column_header{$_} = qq|<th class=listheading nowrap>|.$locale->text($locale->{SHORT_MONTH}[$_-1]).qq|</th>| }
  1630. $form->{title} = $locale->text('Parts Requirements');
  1631. $form->header;
  1632. print qq|
  1633. <body>
  1634. <table width=100%>
  1635. <tr>
  1636. <th class=listtop>$form->{title}</th>
  1637. </tr>
  1638. <tr height="5"></tr>
  1639. <tr><td>$option</td></tr>
  1640. <tr>
  1641. <td>
  1642. <table width=100%>
  1643. <tr class=listheading>
  1644. |;
  1645. for (@column_index) { print "\n$column_header{$_}" }
  1646. print qq|
  1647. </tr>
  1648. |;
  1649. # add order to callback
  1650. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1651. # escape callback for href
  1652. $callback = $form->escape($callback);
  1653. if (@{ $form->{parts} }) {
  1654. $sameid = $form->{parts}->[0]->{id};
  1655. }
  1656. for (keys %month) { $column_data{$_} = "<td>&nbsp;</td>" }
  1657. $i = 0;
  1658. $qty = 0;
  1659. foreach $ref (@{ $form->{parts} }) {
  1660. if ($ref->{id} != $sameid) {
  1661. $i++;
  1662. $column_data{runningnumber} = "<td align=right>$i</td>";
  1663. $order = 0 if $order < 0;
  1664. $column_data{order} = "<td align=right>".$form->format_amount(\%myconfig, $order, '', "-")."</td>";
  1665. $j++; $j %= 2;
  1666. print "<tr class=listrow$j>";
  1667. for (@column_index) {
  1668. print "\n$column_data{$_}";
  1669. $column_data{$_} = "<td>&nbsp;</td>";
  1670. }
  1671. print qq|
  1672. </tr>
  1673. |;
  1674. $qty = 0;
  1675. }
  1676. $ref->{description} =~ s/\r?\n/<br>/g;
  1677. $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
  1678. $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
  1679. $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")."</td>";
  1680. $column_data{so} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{so}, '', "&nbsp;")."</td>";
  1681. $column_data{po} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{po}, '', "&nbsp;")."</td>";
  1682. $column_data{$ref->{month}} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{qty}, '', "&nbsp;")."</td>";
  1683. if (%month) {
  1684. $qty += $ref->{qty} if exists $month{$ref->{month}};
  1685. } else {
  1686. $qty += $ref->{qty};
  1687. }
  1688. $column_data{year} = "<td align=right>".$form->format_amount(\%myconfig, $qty, '', "&nbsp;")."</td>";
  1689. $order = $qty + $ref->{so} - $ref->{po} - $ref->{onhand};
  1690. $sameid = $ref->{id};
  1691. }
  1692. if (@{ $form->{parts} }) {
  1693. $i++;
  1694. $column_data{runningnumber} = "<td align=right>$i</td>";
  1695. $order = 0 if $order < 0;
  1696. $column_data{order} = "<td align=right>".$form->format_amount(\%myconfig, $order, '', "-")."</td>";
  1697. $j++; $j %= 2;
  1698. print "<tr class=listrow$j>";
  1699. for (@column_index) { print "\n$column_data{$_}" }
  1700. print qq|
  1701. </tr>
  1702. |;
  1703. }
  1704. print qq|
  1705. </table>
  1706. </td>
  1707. </tr>
  1708. <tr><td><hr size=3 noshade></td></tr>
  1709. </table>
  1710. |;
  1711. print qq|
  1712. <br>
  1713. <form method=post action=$form->{script}>
  1714. |;
  1715. $form->hide_form(qw(callback path login sessionid));
  1716. if ($form->{menubar}) {
  1717. require "$form->{path}/menu.pl";
  1718. &menubar;
  1719. }
  1720. print qq|
  1721. </form>
  1722. </body>
  1723. </html>
  1724. |;
  1725. }
  1726. sub makemodel_row {
  1727. my ($numrows) = @_;
  1728. for (qw(make model)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  1729. print qq|
  1730. <tr>
  1731. <td>
  1732. <table width=100%>
  1733. <tr>
  1734. <th class="listheading">|.$locale->text('Make').qq|</th>
  1735. <th class="listheading">|.$locale->text('Model').qq|</th>
  1736. </tr>
  1737. |;
  1738. for $i (1 .. $numrows) {
  1739. print qq|
  1740. <tr>
  1741. <td><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
  1742. <td><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
  1743. </tr>
  1744. |;
  1745. }
  1746. print qq|
  1747. </table>
  1748. </td>
  1749. </tr>
  1750. |;
  1751. }
  1752. sub vendor_row {
  1753. my ($numrows) = @_;
  1754. $form->{selectvendor} = $form->unescape($form->{selectvendor});
  1755. $currency = qq|
  1756. <th class="listheading">|.$locale->text('Curr').qq|</th>| if $form->{selectcurrency};
  1757. print qq|
  1758. <input type=hidden name=selectvendor value="|.$form->escape($form->{selectvendor},1).qq|">
  1759. <tr>
  1760. <td>
  1761. <table width=100%>
  1762. <tr>
  1763. <th class="listheading">|.$locale->text('Vendor').qq|</th>
  1764. <th class="listheading">|.$locale->text('Number').qq|</th>
  1765. <th class="listheading">|.$locale->text('Cost').qq|</th>
  1766. $currency
  1767. <th class="listheading">|.$locale->text('Leadtime').qq|</th>
  1768. </tr>
  1769. |;
  1770. for $i (1 .. $numrows) {
  1771. if ($form->{selectcurrency}) {
  1772. $form->{selectcurrency} =~ s/ selected//;
  1773. $form->{selectcurrency} =~ s/option>$form->{"vendorcurr_$i"}/option selected>$form->{"vendorcurr_$i"}/;
  1774. $currency = qq|
  1775. <td><select name="vendorcurr_$i">$form->{selectcurrency}</select></td>|;
  1776. }
  1777. if ($i == $numrows) {
  1778. $vendor = qq|
  1779. <td><input name="vendor_$i" size=35 value="$form->{"vendor_$i"}"></td>
  1780. |;
  1781. if ($form->{selectvendor}) {
  1782. $vendor = qq|
  1783. <td width=99%><select name="vendor_$i">$form->{selectvendor}</select></td>
  1784. |;
  1785. }
  1786. } else {
  1787. ($vendor) = split /--/, $form->{"vendor_$i"};
  1788. $vendor = qq|
  1789. <td>$vendor
  1790. <input type=hidden name="vendor_$i" value="$form->{"vendor_$i"}">
  1791. </td>
  1792. |;
  1793. }
  1794. $form->{"partnumber_$i"} = $form->quote($form->{"partnumber_$i"});
  1795. print qq|
  1796. <tr>
  1797. $vendor
  1798. <td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></td>
  1799. <td><input name="lastcost_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2).qq|></td>
  1800. $currency
  1801. <td nowrap><input name="leadtime_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|> <b>|.$locale->text('days').qq|</b></td>
  1802. </tr>
  1803. |;
  1804. }
  1805. print qq|
  1806. </table>
  1807. </td>
  1808. </tr>
  1809. |;
  1810. }
  1811. sub customer_row {
  1812. my ($numrows) = @_;
  1813. if ($form->{selectpricegroup}) {
  1814. $pricegroup = qq|
  1815. <th class="listheading">|.$locale->text('Pricegroup').qq|
  1816. </th>
  1817. |;
  1818. }
  1819. $form->{selectcustomer} = $form->unescape($form->{selectcustomer});
  1820. $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
  1821. $form->hide_form(qw(selectcurrency));
  1822. $currency = qq|<th class="listheading">|.$locale->text('Curr').qq|</th>| if $form->{selectcurrency};
  1823. print qq|
  1824. <input type=hidden name=selectcustomer value="|.$form->escape($form->{selectcustomer},1).qq|">
  1825. <input type=hidden name=selectpricegroup value="|.$form->escape($form->{selectpricegroup},1).qq|">
  1826. <tr>
  1827. <td>
  1828. <table width=100%>
  1829. <tr>
  1830. <th class="listheading">|.$locale->text('Customer').qq|</th>
  1831. $pricegroup
  1832. <th class="listheading">|.$locale->text('Break').qq|</th>
  1833. <th class="listheading">|.$locale->text('Sell Price').qq|</th>
  1834. $currency
  1835. <th class="listheading">|.$locale->text('From').qq|</th>
  1836. <th class="listheading">|.$locale->text('To').qq|</th>
  1837. </tr>
  1838. |;
  1839. for $i (1 .. $numrows) {
  1840. if ($form->{selectcurrency}) {
  1841. $form->{selectcurrency} =~ s/ selected//;
  1842. $form->{selectcurrency} =~ s/option>$form->{"customercurr_$i"}/option selected>$form->{"customercurr_$i"}/;
  1843. $currency = qq|
  1844. <td><select name="customercurr_$i">$form->{selectcurrency}</select></td>|;
  1845. }
  1846. if ($i == $numrows) {
  1847. $customer = qq|
  1848. <td><input name="customer_$i" size=35 value="$form->{"customer_$i"}"></td>
  1849. |;
  1850. if ($form->{selectcustomer}) {
  1851. $customer = qq|
  1852. <td><select name="customer_$i">$form->{selectcustomer}</select></td>
  1853. |;
  1854. }
  1855. if ($form->{selectpricegroup}) {
  1856. $pricegroup = qq|
  1857. <td><select name="pricegroup_$i">$form->{selectpricegroup}</select></td>
  1858. |;
  1859. }
  1860. } else {
  1861. ($customer) = split /--/, $form->{"customer_$i"};
  1862. $customer = qq|
  1863. <td>$customer</td>
  1864. <input type=hidden name="customer_$i" value="$form->{"customer_$i"}">
  1865. |;
  1866. if ($form->{selectpricegroup}) {
  1867. ($pricegroup) = split /--/, $form->{"pricegroup_$i"};
  1868. $pricegroup = qq|
  1869. <td>$pricegroup</td>
  1870. <input type=hidden name="pricegroup_$i" value="$form->{"pricegroup_$i"}">
  1871. |;
  1872. }
  1873. }
  1874. print qq|
  1875. <tr>
  1876. $customer
  1877. $pricegroup
  1878. <td><input name="pricebreak_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td>
  1879. <td><input name="customerprice_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"customerprice_$i"}, 2).qq|></td>
  1880. $currency
  1881. <td><input name="validfrom_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validfrom_$i"}"></td>
  1882. <td><input name="validto_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validto_$i"}"></td>
  1883. </tr>
  1884. |;
  1885. }
  1886. print qq|
  1887. </table>
  1888. </td>
  1889. </tr>
  1890. |;
  1891. }
  1892. sub assembly_row {
  1893. my ($numrows) = @_;
  1894. @column_index = qw(runningnumber qty unit bom adj partnumber description sellprice listprice lastcost);
  1895. if ($form->{selectassemblypartsgroup}) {
  1896. $form->{selectassemblypartsgroup} = $form->unescape($form->{selectassemblypartsgroup});
  1897. @column_index = qw(runningnumber qty unit bom adj partnumber description partsgroup sellprice listprice lastcost);
  1898. }
  1899. delete $form->{previousform};
  1900. # change callback
  1901. $form->{old_callback} = $form->{callback};
  1902. $callback = $form->{callback};
  1903. $form->{callback} = "$form->{script}?action=display_form";
  1904. # delete action
  1905. for (qw(action header)) { delete $form->{$_} }
  1906. $form->{baseassembly} = 0;
  1907. $previousform = "";
  1908. # save form variables in a previousform variable
  1909. $form->{selectcustomer} = ""; # we seem to have run into a 40kb limit
  1910. foreach $key (sort keys %$form) {
  1911. # escape ampersands
  1912. $form->{$key} =~ s/&/%26/g;
  1913. $previousform .= qq|$key=$form->{$key}&| if $form->{$key};
  1914. }
  1915. chop $previousform;
  1916. $form->{previousform} = $form->escape($previousform, 1);
  1917. $form->{sellprice} = 0;
  1918. $form->{listprice} = 0;
  1919. $form->{lastcost} = 0;
  1920. $form->{weight} = 0;
  1921. $form->{callback} = $callback;
  1922. $column_header{runningnumber} = qq|<th nowrap width=5%>|.$locale->text('Item').qq|</th>|;
  1923. $column_header{qty} = qq|<th align=left nowrap width=10%>|.$locale->text('Qty').qq|</th>|;
  1924. $column_header{unit} = qq|<th align=left nowrap width=5%>|.$locale->text('Unit').qq|</th>|;
  1925. $column_header{partnumber} = qq|<th align=left nowrap width=20%>|.$locale->text('Number').qq|</th>|;
  1926. $column_header{description} = qq|<th nowrap width=50%>|.$locale->text('Description').qq|</th>|;
  1927. $column_header{sellprice} = qq|<th align=right nowrap>|.$locale->text('Sell').qq|</th>|;
  1928. $column_header{listprice} = qq|<th align=right nowrap>|.$locale->text('List').qq|</th>|;
  1929. $column_header{lastcost} = qq|<th align=right nowrap>|.$locale->text('Cost').qq|</th>|;
  1930. $column_header{bom} = qq|<th>|.$locale->text('BOM').qq|</th>|;
  1931. $column_header{adj} = qq|<th>|.$locale->text('A').qq|</th>|;
  1932. $column_header{partsgroup} = qq|<th>|.$locale->text('Group').qq|</th>|;
  1933. print qq|
  1934. <p>
  1935. <table width=100%>
  1936. <tr class=listheading>
  1937. <th class=listheading>|.$locale->text('Individual Items').qq|</th>
  1938. </tr>
  1939. <tr>
  1940. <td>
  1941. <table width=100%>
  1942. <tr>
  1943. |;
  1944. for (@column_index) { print "\n$column_header{$_}" }
  1945. print qq|
  1946. </tr>
  1947. |;
  1948. $spc = ($form->{path} =~ /lynx/) ? "." : " ";
  1949. $numrows-- if $form->{project_id};
  1950. for $i (1 .. $numrows) {
  1951. for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  1952. $linetotalsellprice = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
  1953. $form->{sellprice} += $linetotalsellprice;
  1954. $linetotallistprice = $form->round_amount($form->{"listprice_$i"} * $form->{"qty_$i"}, 2);
  1955. $form->{listprice} += $linetotallistprice;
  1956. $linetotallastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"}, 2);
  1957. $form->{lastcost} += $linetotallastcost;
  1958. $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
  1959. $linetotalsellprice = $form->format_amount(\%myconfig, $linetotalsellprice, 2);
  1960. $linetotallistprice = $form->format_amount(\%myconfig, $linetotallistprice, 2);
  1961. $linetotallastcost = $form->format_amount(\%myconfig, $linetotallastcost, 2);
  1962. if ($i == $numrows && !$form->{project_id}) {
  1963. for (qw(runningnumber unit bom adj)) { $column_data{$_} = qq|<td></td>| }
  1964. $column_data{qty} = qq|<td><input name="qty_$i" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
  1965. $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
  1966. $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
  1967. $column_data{partsgroup} = qq|<td><select name="partsgroup_$i">$form->{selectassemblypartsgroup}</select></td>|;
  1968. } else {
  1969. $column_data{partnumber} = qq|<td><input class=submit type=submit name=action value="$spc$form->{"partnumber_$i"}"></td>
  1970. <input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">|;
  1971. $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
  1972. $column_data{qty} = qq|<td><input name="qty_$i" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
  1973. for (qw(bom adj)) { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? "checked" : "" }
  1974. $column_data{bom} = qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
  1975. $column_data{adj} = qq|<td align=center><input name="adj_$i" type=checkbox class=checkbox value=1 $form->{"adj_$i"}></td>|;
  1976. ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
  1977. $column_data{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$partsgroup</td>|;
  1978. $column_data{unit} = qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
  1979. $column_data{description} = qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
  1980. }
  1981. $column_data{sellprice} = qq|<td align=right>$linetotalsellprice</td>|;
  1982. $column_data{listprice} = qq|<td align=right>$linetotallistprice</td>|;
  1983. $column_data{lastcost} = qq|<td align=right>$linetotallastcost</td>|;
  1984. print qq|
  1985. <tr>|;
  1986. for (@column_index) { print "\n$column_data{$_}" }
  1987. print qq|
  1988. </tr>
  1989. |;
  1990. $form->hide_form("id_$i","sellprice_$i","listprice_$i","lastcost_$i","weight_$i","assembly_$i");
  1991. }
  1992. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1993. $column_data{sellprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{sellprice}, 2)."</th>";
  1994. $column_data{listprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{listprice}, 2)."</th>";
  1995. $column_data{lastcost} = "<th align=right>".$form->format_amount(\%myconfig, $form->{lastcost}, 2)."</th>";
  1996. print qq|
  1997. <tr>|;
  1998. for (@column_index) { print "\n$column_data{$_}" }
  1999. print qq|
  2000. </tr>
  2001. </table>
  2002. </td>
  2003. </tr>
  2004. <tr>
  2005. <td><hr size=3 noshade></td>
  2006. </tr>
  2007. </table>
  2008. <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
  2009. <input type=hidden name=nextsub value=edit_assemblyitem>
  2010. <input type=hidden name=selectassemblypartsgroup value="|.$form->escape($form->{selectassemblypartsgroup},1).qq|">
  2011. |;
  2012. }
  2013. sub edit_assemblyitem {
  2014. $pn = substr($form->{action}, 1);
  2015. $i = 0;
  2016. for (1 .. $form->{assembly_rows} - 1) {
  2017. $i++;
  2018. last if $form->{"partnumber_$_"} eq $pn;
  2019. }
  2020. $form->error($locale->text('unexpected error!')) unless $i;
  2021. $form->{baseassembly} = ($form->{baseassembly}) ? $form->{baseassembly} : $form->{"assembly_$i"};
  2022. $form->{callback} = qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&rowcount=$i&baseassembly=$form->{baseassembly}&isassemblyitem=1&previousform=$form->{previousform}|;
  2023. $form->redirect;
  2024. }
  2025. sub update {
  2026. if ($form->{item} eq "assembly") {
  2027. $i = $form->{assembly_rows};
  2028. $i = $form->{assembly_rows} + 1 if $form->{project_id};
  2029. # if last row is empty check the form otherwise retrieve item
  2030. if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
  2031. &check_form;
  2032. } else {
  2033. IC->assembly_item(\%myconfig, \%$form);
  2034. $rows = scalar @{ $form->{item_list} };
  2035. if ($rows) {
  2036. $form->{"adj_$i"} = 1;
  2037. if ($rows > 1) {
  2038. $form->{makemodel_rows}--;
  2039. $form->{customer_rows}--;
  2040. &select_item;
  2041. exit;
  2042. } else {
  2043. $form->{"qty_$i"} = 1;
  2044. $form->{"adj_$i"} = 1;
  2045. for (qw(partnumber description unit)) { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) }
  2046. for (keys %{ $form->{item_list}[0] }) { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
  2047. if ($form->{item_list}[0]{partsgroup_id}) {
  2048. $form->{"partsgroup_$i"} = qq|$form->{item_list}[0]{partsgroup}--$form->{item_list}[0]{partsgroup_id}|;
  2049. }
  2050. $form->{"runningnumber_$i"} = $form->{assembly_rows};
  2051. $form->{assembly_rows}++;
  2052. &check_form;
  2053. }
  2054. } else {
  2055. $form->{rowcount} = $i;
  2056. $form->{assembly_rows}++;
  2057. &new_item;
  2058. }
  2059. }
  2060. } else {
  2061. &check_form;
  2062. }
  2063. }
  2064. sub check_vendor {
  2065. @flds = qw(vendor partnumber lastcost leadtime vendorcurr);
  2066. @a = ();
  2067. $count = 0;
  2068. for (qw(lastcost leadtime)) { $form->{"${_}_$form->{vendor_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{vendor_rows}"}) }
  2069. for $i (1 .. $form->{vendor_rows} - 1) {
  2070. for (qw(lastcost leadtime)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  2071. if ($form->{"lastcost_$i"} || $form->{"partnumber_$i"}) {
  2072. push @a, {};
  2073. $j = $#a;
  2074. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2075. $count++;
  2076. }
  2077. }
  2078. $i = $form->{vendor_rows};
  2079. if (!$form->{selectvendor}) {
  2080. if ($form->{"vendor_$i"} && !$form->{"vendor_id_$i"}) {
  2081. ($form->{vendor}) = split /--/, $form->{"vendor_$i"};
  2082. if (($j = $form->get_name(\%myconfig, vendor)) > 1) {
  2083. &select_name(vendor, $i);
  2084. exit;
  2085. }
  2086. if ($j == 1) {
  2087. # we got one name
  2088. $form->{"vendor_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
  2089. } else {
  2090. # name is not on file
  2091. $form->error(qq|$form->{"vendor_$i"} : |.$locale->text('Vendor not on file!'));
  2092. }
  2093. }
  2094. }
  2095. if ($form->{"vendor_$i"}) {
  2096. push @a, {};
  2097. $j = $#a;
  2098. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2099. $count++;
  2100. }
  2101. $form->redo_rows(\@flds, \@a, $count, $form->{vendor_rows});
  2102. $form->{vendor_rows} = $count;
  2103. }
  2104. sub check_customer {
  2105. @flds = qw(customer validfrom validto pricebreak customerprice pricegroup customercurr);
  2106. @a = ();
  2107. $count = 0;
  2108. for (qw(customerprice pricebreak)) { $form->{"${_}_$form->{customer_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{customer_rows}"}) }
  2109. for $i (1 .. $form->{customer_rows} - 1) {
  2110. for (qw(customerprice pricebreak)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  2111. if ($form->{"customerprice_$i"}) {
  2112. if ($form->{"pricebreak_$i"} || $form->{"customer_$i"} || $form->{"pricegroup_$i"}) {
  2113. push @a, {};
  2114. $j = $#a;
  2115. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2116. $count++;
  2117. }
  2118. }
  2119. }
  2120. $i = $form->{customer_rows};
  2121. if (!$form->{selectcustomer}) {
  2122. if ($form->{"customer_$i"} && !$form->{"customer_id_$i"}) {
  2123. ($form->{customer}) = split /--/, $form->{"customer_$i"};
  2124. if (($j = $form->get_name(\%myconfig, customer)) > 1) {
  2125. &select_name(customer, $i);
  2126. exit;
  2127. }
  2128. if ($j == 1) {
  2129. # we got one name
  2130. $form->{"customer_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
  2131. } else {
  2132. # name is not on file
  2133. $form->error(qq|$form->{customer} : |.$locale->text('Customer not on file!'));
  2134. }
  2135. }
  2136. }
  2137. if ($form->{"customer_$i"} || $form->{"pricegroup_$i"} || ($form->{"customerprice_$i"} || $form->{"pricebreak_$i"})) {
  2138. push @a, {};
  2139. $j = $#a;
  2140. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2141. $count++;
  2142. }
  2143. $form->redo_rows(\@flds, \@a, $count, $form->{customer_rows});
  2144. $form->{customer_rows} = $count;
  2145. }
  2146. sub select_name {
  2147. my ($table, $vr) = @_;
  2148. @column_index = qw(ndx name address);
  2149. $label = ucfirst $table;
  2150. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  2151. $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
  2152. $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
  2153. # list items with radio button on a form
  2154. $form->header;
  2155. $title = $locale->text('Select from one of the names below');
  2156. print qq|
  2157. <body>
  2158. <form method=post action="$form->{script}">
  2159. <input type=hidden name=vr value=$vr>
  2160. <table width=100%>
  2161. <tr>
  2162. <th class=listtop>$title</th>
  2163. </tr>
  2164. <tr space=5></tr>
  2165. <tr>
  2166. <td>
  2167. <table width=100%>
  2168. <tr class=listheading>|;
  2169. for (@column_index) { print "\n$column_data{$_}" }
  2170. print qq|
  2171. </tr>
  2172. |;
  2173. @column_index = qw(ndx name address city state zipcode country);
  2174. my $i = 0;
  2175. foreach $ref (@{ $form->{name_list} }) {
  2176. $checked = ($i++) ? "" : "checked";
  2177. $ref->{name} = $form->quote($ref->{name});
  2178. $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  2179. $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
  2180. $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}|;
  2181. for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  2182. $j++; $j %= 2;
  2183. print qq|
  2184. <tr class=listrow$j>|;
  2185. for (@column_index) { print "\n$column_data{$_}" }
  2186. print qq|
  2187. </tr>
  2188. <input name="new_id_$i" type=hidden value=$ref->{id}>
  2189. |;
  2190. }
  2191. print qq|
  2192. </table>
  2193. </td>
  2194. </tr>
  2195. <tr>
  2196. <td><hr size=3 noshade></td>
  2197. </tr>
  2198. </table>
  2199. <input name=lastndx type=hidden value=$i>
  2200. |;
  2201. # delete variables
  2202. for (qw(action nextsub name_list)) { delete $form->{$_} }
  2203. $form->hide_form;
  2204. print qq|
  2205. <input type=hidden name=nextsub value=name_selected>
  2206. <input type=hidden name=vc value=$table>
  2207. <br>
  2208. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  2209. </form>
  2210. </body>
  2211. </html>
  2212. |;
  2213. }
  2214. sub name_selected {
  2215. # replace the variable with the one checked
  2216. # index for new item
  2217. $i = $form->{ndx};
  2218. $form->{"$form->{vc}_$form->{vr}"} = qq|$form->{"new_name_$i"}--$form->{"new_id_$i"}|;
  2219. $form->{"$form->{vc}_id_$form->{vr}"} = $form->{"new_id_$i"};
  2220. # delete all the new_ variables
  2221. for $i (1 .. $form->{lastndx}) {
  2222. for (qw(id name)) { delete $form->{"new_${_}_$i"} }
  2223. }
  2224. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  2225. &update;
  2226. }
  2227. sub save {
  2228. if ($form->{obsolete}) {
  2229. $form->error($locale->text("Inventory quantity must be zero before you can set this $form->{item} obsolete!")) if ($form->{onhand});
  2230. }
  2231. # expand dynamic strings
  2232. # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
  2233. # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
  2234. $olditem = $form->{id};
  2235. # save part
  2236. $rc = IC->save(\%myconfig, \%$form);
  2237. $parts_id = $form->{id};
  2238. # load previous variables
  2239. if ($form->{previousform} && !$form->{callback}) {
  2240. # save the new form variables before splitting previousform
  2241. for (keys %$form) { $newform{$_} = $form->{$_} }
  2242. $previousform = $form->unescape($form->{previousform});
  2243. $baseassembly = $form->{baseassembly};
  2244. # don't trample on previous variables
  2245. for (keys %newform) { delete $form->{$_} }
  2246. # now take it apart and restore original values
  2247. foreach $item (split /&/, $previousform) {
  2248. ($key, $value) = split /=/, $item, 2;
  2249. $value =~ s/%26/&/g;
  2250. $form->{$key} = $value;
  2251. }
  2252. if ($form->{item} eq 'assembly') {
  2253. if ($baseassembly) {
  2254. #redo the assembly
  2255. $previousform =~ /\&id=(\d+)/;
  2256. $form->{id} = $1;
  2257. # restore original callback
  2258. $form->{callback} = $form->unescape($form->{old_callback});
  2259. &edit;
  2260. exit;
  2261. }
  2262. # undo number formatting
  2263. for (qw(weight listprice sellprice lastcost rop)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  2264. $form->{assembly_rows}-- if $olditem;
  2265. $i = $newform{rowcount};
  2266. $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
  2267. $form->{listprice} -= $form->{"listprice_$i"} * $form->{"qty_$i"};
  2268. $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
  2269. $form->{lastcost} -= $form->{"lastcost_$i"} * $form->{"qty_$i"};
  2270. $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
  2271. # change/add values for assembly item
  2272. for (qw(partnumber description bin unit weight listprice sellprice lastcost)) { $form->{"${_}_$i"} = $newform{$_} }
  2273. foreach $item (qw(listprice sellprice lastcost)) {
  2274. $form->{$item} += $form->{"${item}_$i"} * $form->{"qty_$i"};
  2275. $form->{$item} = $form->round_amount($form->{$item}, 2);
  2276. }
  2277. $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
  2278. $form->{"adj_$i"} = 1 if !$olditem;
  2279. $form->{customer_rows}--;
  2280. } else {
  2281. # set values for last invoice/order item
  2282. $i = $form->{rowcount};
  2283. $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
  2284. for (qw(partnumber description bin unit listprice sellprice partsgroup)) { $form->{"${_}_$i"} = $newform{$_} }
  2285. for (qw(inventory income expense)) {
  2286. $form->{"${_}_accno_id_$i"} = $newform{"IC_$_"};
  2287. $form->{"${_}_accno_id_$i"} =~ s/--.*//;
  2288. }
  2289. $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
  2290. if ($form->{exchangerate} != 0) {
  2291. $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} / $form->{exchangerate}, 2);
  2292. }
  2293. for (split / /, $newform{taxaccounts}) { $form->{"taxaccounts_$i"} .= "$_ " if ($newform{"IC_tax_$_"}) }
  2294. chop $form->{"taxaccounts_$i"};
  2295. # credit remaining calculation
  2296. $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
  2297. for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  2298. if (!$form->{taxincluded}) {
  2299. for (split / /, $form->{"taxaccounts_$i"}) { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
  2300. }
  2301. $ml = 1;
  2302. if ($form->{type} =~ /invoice/) {
  2303. $ml = -1 if $form->{type} =~ /_invoice/;
  2304. }
  2305. $form->{creditremaining} -= ($amount * $ml);
  2306. }
  2307. $form->{"id_$i"} = $parts_id;
  2308. delete $form->{action};
  2309. # restore original callback
  2310. $callback = $form->unescape($form->{callback});
  2311. $form->{callback} = $form->unescape($form->{old_callback});
  2312. delete $form->{old_callback};
  2313. $form->{makemodel_rows}--;
  2314. # put callback together
  2315. foreach $key (keys %$form) {
  2316. # do single escape for Apache 2.0
  2317. $value = $form->escape($form->{$key}, 1);
  2318. $callback .= qq|&$key=$value|;
  2319. }
  2320. $form->{callback} = $callback;
  2321. }
  2322. # redirect
  2323. $form->redirect;
  2324. }
  2325. sub save_as_new {
  2326. $form->{id} = 0;
  2327. &save;
  2328. }
  2329. sub delete {
  2330. # redirect
  2331. if (IC->delete(\%myconfig, \%$form)) {
  2332. $form->redirect($locale->text('Item deleted!'));
  2333. } else {
  2334. $form->error($locale->text('Cannot delete item!'));
  2335. }
  2336. }
  2337. sub stock_assembly {
  2338. $form->{title} = $locale->text('Stock Assembly');
  2339. $form->header;
  2340. print qq|
  2341. <body>
  2342. <form method=post action=$form->{script}>
  2343. <table width="100%">
  2344. <tr>
  2345. <th class=listtop>$form->{title}</th>
  2346. </tr>
  2347. <tr height="5"></tr>
  2348. <tr valign=top>
  2349. <td>
  2350. <table>
  2351. <tr>
  2352. <th align="right" nowrap="true">|.$locale->text('Number').qq|</th>
  2353. <td><input name=partnumber size=20></td>
  2354. <td>&nbsp;</td>
  2355. </tr>
  2356. <tr>
  2357. <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
  2358. <td><input name=description size=40></td>
  2359. </tr>
  2360. <tr>
  2361. <td></td>
  2362. <td><input name=checkinventory class=checkbox type=checkbox value=1>&nbsp;|.$locale->text('Check Inventory').qq|</td>
  2363. </tr>
  2364. </table>
  2365. </td>
  2366. </tr>
  2367. <tr><td><hr size=3 noshade></td></tr>
  2368. </table>
  2369. <input type=hidden name=sort value=partnumber>
  2370. |;
  2371. $form->hide_form(qw(path login sessionid));
  2372. print qq|
  2373. <input type=hidden name=nextsub value=list_assemblies>
  2374. <br>
  2375. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  2376. </form>
  2377. |;
  2378. if ($form->{menubar}) {
  2379. require "$form->{path}/menu.pl";
  2380. &menubar;
  2381. }
  2382. print qq|
  2383. </body>
  2384. </html>
  2385. |;
  2386. }
  2387. sub list_assemblies {
  2388. IC->retrieve_assemblies(\%myconfig, \%$form);
  2389. $callback = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
  2390. $form->sort_order();
  2391. $href = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
  2392. if ($form->{partnumber}) {
  2393. $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
  2394. $href .= "&partnumber=".$form->escape($form->{partnumber});
  2395. $form->{sort} = "partnumber" unless $form->{sort};
  2396. }
  2397. if ($form->{description}) {
  2398. $callback .= "&description=".$form->escape($form->{description},1);
  2399. $href .= "&description=".$form->escape($form->{description});
  2400. $form->{sort} = "description" unless $form->{sort};
  2401. }
  2402. $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</th>|;
  2403. $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
  2404. $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</th>|;
  2405. $column_header{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
  2406. $column_header{rop} = qq|<th class=listheading>|.$locale->text('ROP').qq|</th>|;
  2407. $column_header{stock} = qq|<th class=listheading>|.$locale->text('Add').qq|</th>|;
  2408. @column_index = $form->sort_columns(qw(partnumber description bin onhand rop stock));
  2409. $form->{title} = $locale->text('Stock Assembly');
  2410. $form->header;
  2411. print qq|
  2412. <body>
  2413. <form method=post action=$form->{script}>
  2414. <table width=100%>
  2415. <tr>
  2416. <th class=listtop>$form->{title}</th>
  2417. </tr>
  2418. <tr size=5></tr>
  2419. <tr>
  2420. <td>
  2421. <table width=100%>
  2422. <tr class=listheading>
  2423. |;
  2424. for (@column_index) { print "\n$column_header{$_}" }
  2425. print qq|
  2426. </tr>
  2427. |;
  2428. # add sort and escape callback
  2429. $form->{callback} = $callback .= "&sort=$form->{sort}";
  2430. # escape callback for href
  2431. $callback = $form->escape($callback);
  2432. $i = 1;
  2433. foreach $ref (@{ $form->{assembly_items} }) {
  2434. for (qw(partnumber description)) { $ref->{$_} = $form->quote($ref->{$_}) }
  2435. $column_data{partnumber} = "<td width=20%><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
  2436. $column_data{description} = qq|<td width=50%>$ref->{description}&nbsp;</td>|;
  2437. $column_data{bin} = qq|<td>$ref->{bin}&nbsp;</td>|;
  2438. $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, "", "&nbsp;").qq|</td>|;
  2439. $column_data{rop} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;").qq|</td>|;
  2440. $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10 value=|.$form->format_amount(\%myconfig, $ref->{stock}).qq|></td>
  2441. <input type=hidden name="stock_$i" value=$ref->{stock}>|;
  2442. $j++; $j %= 2;
  2443. print qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
  2444. for (@column_index) { print "\n$column_data{$_}" }
  2445. print qq|
  2446. </tr>
  2447. |;
  2448. $i++;
  2449. }
  2450. $i--;
  2451. print qq|
  2452. </td>
  2453. </table>
  2454. <tr>
  2455. <td><hr size=3 noshade>
  2456. </tr>
  2457. </table>
  2458. |;
  2459. $form->hide_form(qw(checkinventory path login sessionid callback));
  2460. print qq|
  2461. <input type=hidden name=rowcount value="$i">
  2462. <input type=hidden name=nextsub value=restock_assemblies>
  2463. <br>
  2464. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  2465. </form>
  2466. </body>
  2467. </html>
  2468. |;
  2469. }
  2470. sub restock_assemblies {
  2471. if ($form->{checkinventory}) {
  2472. for (1 .. $form->{rowcount}) { $form->error($locale->text('Quantity exceeds available units to stock!')) if $form->parse_amount($myconfig, $form->{"qty_$_"}) > $form->{"stock_$_"} }
  2473. }
  2474. if (IC->restock_assemblies(\%myconfig, \%$form)) {
  2475. if ($form->{callback} =~ /(direction=)(.*?)\&/) {
  2476. $direction = ($2 eq 'ASC') ? 'DESC' : 'ASC';
  2477. }
  2478. $form->{callback} =~ s/direction=(.*?)\&/direction=$direction\&/;
  2479. $form->redirect($locale->text('Assemblies restocked!'));
  2480. } else {
  2481. $form->error($locale->text('Cannot stock assemblies!'));
  2482. }
  2483. }
  2484. sub continue { &{ $form->{nextsub} } };
  2485. sub add_part { &add };
  2486. sub add_service { &add };
  2487. sub add_assembly { &add };
  2488. sub add_labor_overhead { &add };