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