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