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