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