summaryrefslogtreecommitdiff
path: root/bin/oe.pl
blob: 81c147cfa556784a83890d200be0115e907a4ee6 (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. #
  22. # This program is free software; you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation; either version 2 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. # You should have received a copy of the GNU General Public License
  32. # along with this program; if not, write to the Free Software
  33. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. #======================================================================
  35. #
  36. # Order entry module
  37. # Quotation module
  38. #
  39. #======================================================================
  40. use LedgerSMB::OE;
  41. use LedgerSMB::IR;
  42. use LedgerSMB::IS;
  43. use LedgerSMB::PE;
  44. use LedgerSMB::Tax;
  45. use LedgerSMB::Locale;
  46. require "bin/arap.pl";
  47. require "bin/io.pl";
  48. 1;
  49. # end of main
  50. sub add {
  51. if ( $form->{type} eq 'purchase_order' ) {
  52. $form->{title} = $locale->text('Add Purchase Order');
  53. $form->{vc} = 'vendor';
  54. }
  55. if ( $form->{type} eq 'sales_order' ) {
  56. $form->{title} = $locale->text('Add Sales Order');
  57. $form->{vc} = 'customer';
  58. }
  59. if ( $form->{type} eq 'request_quotation' ) {
  60. $form->{title} = $locale->text('Add Request for Quotation');
  61. $form->{vc} = 'vendor';
  62. }
  63. if ( $form->{type} eq 'sales_quotation' ) {
  64. $form->{title} = $locale->text('Add Quotation');
  65. $form->{vc} = 'customer';
  66. }
  67. $form->{callback} =
  68. "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}"
  69. unless $form->{callback};
  70. $form->{rowcount} = 0;
  71. &order_links;
  72. &prepare_order;
  73. &display_form;
  74. }
  75. sub edit {
  76. if ( $form->{type} =~ /(purchase_order|bin_list)/ ) {
  77. $form->{title} = $locale->text('Edit Purchase Order');
  78. $form->{vc} = 'vendor';
  79. $form->{type} = 'purchase_order';
  80. }
  81. if ( $form->{type} =~ /((sales|work)_order|(packing|pick)_list)/ ) {
  82. $form->{title} = $locale->text('Edit Sales Order');
  83. $form->{vc} = 'customer';
  84. $form->{type} = 'sales_order';
  85. }
  86. if ( $form->{type} eq 'request_quotation' ) {
  87. $form->{title} = $locale->text('Edit Request for Quotation');
  88. $form->{vc} = 'vendor';
  89. }
  90. if ( $form->{type} eq 'sales_quotation' ) {
  91. $form->{title} = $locale->text('Edit Quotation');
  92. $form->{vc} = 'customer';
  93. }
  94. &order_links;
  95. &prepare_order;
  96. &display_form;
  97. }
  98. sub order_links {
  99. # retrieve order/quotation
  100. OE->retrieve( \%myconfig, \%$form );
  101. # get customer/vendor
  102. $form->all_vc( \%myconfig, $form->{vc},
  103. ( $form->{vc} eq 'customer' ) ? "AR" : "AP",
  104. undef, $form->{transdate}, 1 );
  105. # currencies
  106. @curr = split /:/, $form->{currencies};
  107. $form->{defaultcurrency} = $curr[0];
  108. chomp $form->{defaultcurrency};
  109. $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
  110. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  111. $form->{oldlanguage_code} = $form->{language_code};
  112. $l{language_code} = $form->{language_code};
  113. $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer';
  114. $form->get_partsgroup( \%myconfig, \%l );
  115. if ( @{ $form->{all_partsgroup} } ) {
  116. $form->{selectpartsgroup} = "<option>\n";
  117. foreach $ref ( @{ $form->{all_partsgroup} } ) {
  118. if ( $ref->{translation} ) {
  119. $form->{selectpartsgroup} .=
  120. qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
  121. }
  122. else {
  123. $form->{selectpartsgroup} .=
  124. qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
  125. }
  126. }
  127. }
  128. if ( @{ $form->{all_project} } ) {
  129. $form->{selectprojectnumber} = "<option>\n";
  130. for ( @{ $form->{all_project} } ) {
  131. $form->{selectprojectnumber} .=
  132. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  133. }
  134. }
  135. if ( @{ $form->{"all_$form->{vc}"} } ) {
  136. unless ( $form->{"$form->{vc}_id"} ) {
  137. $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
  138. }
  139. }
  140. for (qw(terms taxincluded)) { $temp{$_} = $form->{$_} }
  141. $form->{shipto} = 1 if $form->{id};
  142. # get customer / vendor
  143. AA->get_name( \%myconfig, \%$form );
  144. if ( $form->{id} ) {
  145. for (qw(terms taxincluded)) { $form->{$_} = $temp{$_} }
  146. }
  147. ( $form->{ $form->{vc} } ) = split /--/, $form->{ $form->{vc} };
  148. $form->{"old$form->{vc}"} =
  149. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  150. # build selection list
  151. $form->{"select$form->{vc}"} = "";
  152. if ( @{ $form->{"all_$form->{vc}"} } ) {
  153. $form->{ $form->{vc} } =
  154. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  155. for ( @{ $form->{"all_$form->{vc}"} } ) {
  156. $form->{"select$form->{vc}"} .=
  157. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  158. }
  159. }
  160. # departments
  161. if ( @{ $form->{all_department} } ) {
  162. $form->{selectdepartment} = "<option>\n";
  163. for ( @{ $form->{all_department} } ) {
  164. $form->{selectdepartment} .=
  165. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  166. }
  167. }
  168. $form->{employee} = "$form->{employee}--$form->{employee_id}";
  169. # sales staff
  170. if ( @{ $form->{all_employee} } ) {
  171. $form->{selectemployee} = "";
  172. for ( @{ $form->{all_employee} } ) {
  173. $form->{selectemployee} .=
  174. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  175. }
  176. }
  177. if ( @{ $form->{all_language} } ) {
  178. $form->{selectlanguage} = "<option>\n";
  179. for ( @{ $form->{all_language} } ) {
  180. $form->{selectlanguage} .=
  181. qq|<option value="$_->{code}">$_->{description}\n|;
  182. }
  183. }
  184. # forex
  185. $form->{forex} = $form->{exchangerate};
  186. }
  187. sub prepare_order {
  188. $form->{format} = "postscript" if $myconfig{printer};
  189. $form->{media} = $myconfig{printer};
  190. $form->{formname} = $form->{type};
  191. $form->{sortby} ||= "runningnumber";
  192. $form->{currency} =~ s/ //g;
  193. $form->{oldcurrency} = $form->{currency};
  194. if ( $form->{id} ) {
  195. for (
  196. qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact)
  197. )
  198. {
  199. $form->{$_} = $form->quote( $form->{$_} );
  200. }
  201. foreach $ref ( @{ $form->{form_details} } ) {
  202. $i++;
  203. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  204. $form->{"projectnumber_$i"} =
  205. qq|$ref->{projectnumber}--$ref->{project_id}|
  206. if $ref->{project_id};
  207. $form->{"partsgroup_$i"} =
  208. qq|$ref->{partsgroup}--$ref->{partsgroup_id}|
  209. if $ref->{partsgroup_id};
  210. $form->{"discount_$i"} =
  211. $form->format_amount( \%myconfig, $form->{"discount_$i"} * 100 );
  212. ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
  213. $dec = length $dec;
  214. $decimalplaces = ( $dec > 2 ) ? $dec : 2;
  215. for ( map { "${_}_$i" } qw(sellprice listprice) ) {
  216. $form->{$_} =
  217. $form->format_amount( \%myconfig, $form->{$_},
  218. $decimalplaces );
  219. }
  220. ($dec) = ( $form->{"lastcost_$i"} =~ /\.(\d+)/ );
  221. $dec = length $dec;
  222. $decimalplaces = ( $dec > 2 ) ? $dec : 2;
  223. $form->{"lastcost_$i"} =
  224. $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
  225. $decimalplaces );
  226. $form->{"qty_$i"} =
  227. $form->format_amount( \%myconfig, $form->{"qty_$i"} );
  228. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  229. for (qw(partnumber sku description unit)) {
  230. $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
  231. }
  232. $form->{rowcount} = $i;
  233. }
  234. }
  235. $form->{oldtransdate} = $form->{transdate};
  236. if ( $form->{type} eq 'sales_quotation' ) {
  237. if ( !$form->{readonly} ) {
  238. $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--Quotation/;
  239. }
  240. $form->{selectformname} =
  241. qq|<option value="sales_quotation">| . $locale->text('Quotation');
  242. }
  243. if ( $form->{type} eq 'request_quotation' ) {
  244. if ( !$form->{readonly} ) {
  245. $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--RFQ/;
  246. }
  247. $form->{selectformname} =
  248. qq|<option value="request_quotation">| . $locale->text('RFQ');
  249. }
  250. if ( $form->{type} eq 'sales_order' ) {
  251. if ( !$form->{readonly} ) {
  252. $form->{readonly} = 1
  253. if $myconfig{acs} =~ /Order Entry--Sales Order/;
  254. }
  255. $form->{selectformname} =
  256. qq|<option value="sales_order">|
  257. . $locale->text('Sales Order') . qq|
  258. <option value="work_order">| . $locale->text('Work Order') . qq|
  259. <option value="pick_list">| . $locale->text('Pick List') . qq|
  260. <option value="packing_list">| . $locale->text('Packing List');
  261. }
  262. if ( $form->{type} eq 'purchase_order' ) {
  263. if ( !$form->{readonly} ) {
  264. $form->{readonly} = 1
  265. if $myconfig{acs} =~ /Order Entry--Purchase Order/;
  266. }
  267. $form->{selectformname} =
  268. qq|<option value="purchase_order">|
  269. . $locale->text('Purchase Order') . qq|
  270. <option value="bin_list">| . $locale->text('Bin List');
  271. }
  272. if ( $form->{type} eq 'ship_order' ) {
  273. $form->{selectformname} =
  274. qq|<option value="pick_list">|
  275. . $locale->text('Pick List') . qq|
  276. <option value="packing_list">| . $locale->text('Packing List');
  277. }
  278. if ( $form->{type} eq 'receive_order' ) {
  279. $form->{selectformname} =
  280. qq|<option value="bin_list">| . $locale->text('Bin List');
  281. }
  282. }
  283. sub form_header {
  284. $checkedopen = ( $form->{closed} ) ? "" : "checked";
  285. $checkedclosed = ( $form->{closed} ) ? "checked" : "";
  286. if ( $form->{id} ) {
  287. $openclosed = qq|
  288. <tr>
  289. <th nowrap align="right"><input name="closed" type="radio" class="radio" value="0" $checkedopen> |
  290. . $locale->text('Open')
  291. . qq|</th>
  292. <th nowrap align="left"><input name="closed" type="radio" class="radio" value="1" $checkedclosed> |
  293. . $locale->text('Closed')
  294. . qq|</th>
  295. </tr>
  296. |;
  297. }
  298. # set option selected
  299. $form->{selectcurrency} =~ s/ selected//;
  300. $form->{selectcurrency} =~
  301. s/option>\Q$form->{currency}\E/option selected>$form->{currency}/;
  302. for ( "$form->{vc}", "department", "employee" ) {
  303. $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
  304. $form->{"select$_"} =~ s/ selected//;
  305. $form->{"select$_"} =~ s/(<option value="[^"]*\Q$form->{$_}\E")/$1 selected/;
  306. }
  307. $form->{exchangerate} =
  308. $form->format_amount( \%myconfig, $form->{exchangerate} );
  309. $exchangerate = qq|<tr>|;
  310. $exchangerate .= qq|
  311. <th align="right" nowrap>| . $locale->text('Currency') . qq|</th>
  312. <td><select name="currency">$form->{selectcurrency}</select></td> |
  313. if $form->{defaultcurrency};
  314. $exchangerate .= qq|
  315. <input type="hidden" name="selectcurrency" value="$form->{selectcurrency}">
  316. <input type="hidden" name="defaultcurrency" value="$form->{defaultcurrency}">
  317. |;
  318. if ( $form->{defaultcurrency}
  319. && $form->{currency} ne $form->{defaultcurrency} )
  320. {
  321. if ( $form->{forex} ) {
  322. $exchangerate .=
  323. qq|<th align="right">|
  324. . $locale->text('Exchange Rate')
  325. . qq|</th><td>$form->{exchangerate}</td>
  326. <input type="hidden" name="exchangerate" value="$form->{exchangerate}">
  327. |;
  328. }
  329. else {
  330. $exchangerate .=
  331. qq|<th align="right">|
  332. . $locale->text('Exchange Rate')
  333. . qq|</th><td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
  334. }
  335. }
  336. $exchangerate .= qq|
  337. <input type="hidden" name="forex" value="$form->{forex}">
  338. </tr>
  339. |;
  340. $vclabel = ucfirst $form->{vc};
  341. $vclabel = $locale->text($vclabel);
  342. $terms = qq|
  343. <tr>
  344. <th align="right" nowrap>| . $locale->text('Terms') . qq|</th>
  345. <td nowrap><input name="terms" size="3" maxlength="3" value="$form->{terms}"> |
  346. . $locale->text('days')
  347. . qq|</td>
  348. </tr>
  349. |;
  350. if ( $form->{business} ) {
  351. $business = qq|
  352. <tr>
  353. <th align="right" nowrap>| . $locale->text('Business') . qq|</th>
  354. <td colspan="3">$form->{business}
  355. &nbsp;&nbsp;&nbsp;|;
  356. $business .= qq|
  357. <b>| . $locale->text('Trade Discount') . qq|</b>
  358. | . $form->format_amount( \%myconfig, $form->{tradediscount} * 100 ) . qq| %|
  359. if $form->{vc} eq 'customer';
  360. $business .= qq|</td>
  361. </tr>
  362. |;
  363. }
  364. if ( $form->{type} !~ /_quotation$/ ) {
  365. $ordnumber = qq|
  366. <tr>
  367. <th width="70%" align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
  368. <td><input name="ordnumber" size="20" value="$form->{ordnumber}"></td>
  369. <input type="hidden" name="quonumber" value="$form->{quonumber}">
  370. </tr>
  371. <tr>
  372. <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
  373. <td><input name="transdate" size="11" title="$myconfig{dateformat}" value="$form->{transdate}"></td>
  374. </tr>
  375. <tr>
  376. <th align="right" nowrap="true">| . $locale->text('Required by') . qq|</th>
  377. <td><input name="reqdate" size="11" title="$myconfig{dateformat}" value="$form->{reqdate}"></td>
  378. </tr>
  379. <tr>
  380. <th align="right" nowrap>| . $locale->text('PO Number') . qq|</th>
  381. <td><input name="ponumber" size="20" value="$form->{ponumber}"></td>
  382. </tr>
  383. |;
  384. $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
  385. $creditremaining = qq|
  386. <tr>
  387. <td></td>
  388. <td colspan="3">
  389. <table>
  390. <tr>
  391. <th align="right" nowrap>| . $locale->text('Credit Limit') . qq|</th>
  392. <td>|
  393. . $form->format_amount( \%myconfig, $form->{creditlimit}, 0, "0" )
  394. . qq|</td>
  395. <td width="10"></td>
  396. <th align="right" nowrap>| . $locale->text('Remaining') . qq|</th>
  397. <td class="plus$n" nowrap>|
  398. . $form->format_amount( \%myconfig, $form->{creditremaining}, 0, "0" )
  399. . qq|</td>
  400. </tr>
  401. </table>
  402. </td>
  403. </tr>
  404. |;
  405. }
  406. else {
  407. $reqlabel =
  408. ( $form->{type} eq 'sales_quotation' )
  409. ? $locale->text('Valid until')
  410. : $locale->text('Required by');
  411. if ( $form->{type} eq 'sales_quotation' ) {
  412. $ordnumber = qq|
  413. <tr>
  414. <th width="70%" align="right" nowrap>|
  415. . $locale->text('Quotation Number')
  416. . qq|</th>
  417. <td><input name="quonumber" size="20" value="$form->{quonumber}"></td>
  418. <input type="hidden" name="ordnumber" value="$form->{ordnumber}">
  419. </tr>
  420. |;
  421. }
  422. else {
  423. $ordnumber = qq|
  424. <tr>
  425. <th width="70%" align="right" nowrap>| . $locale->text('RFQ Number') . qq|</th>
  426. <td><input name="quonumber" size="20" value="$form->{quonumber}"></td>
  427. <input type="hidden" name="ordnumber" value="$form->{ordnumber}">
  428. </tr>
  429. |;
  430. $terms = "";
  431. }
  432. $ordnumber .= qq|
  433. <tr>
  434. <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
  435. <td><input name="transdate" size="11" title="$myconfig{dateformat}" value="$form->{transdate}"></td>
  436. </tr>
  437. <tr>
  438. <th align="right" nowrap="true">$reqlabel</th>
  439. <td><input name="reqdate" size="11" title="$myconfig{dateformat}" value="$form->{reqdate}"></td>
  440. </tr>
  441. |;
  442. }
  443. $ordnumber .= qq|
  444. <input type="hidden" name="oldtransdate" value="$form->{oldtransdate}">|;
  445. if ( $form->{"select$form->{vc}"} ) {
  446. $vc = qq|<select name="$form->{vc}">$form->{"select$form->{vc}"}</select>
  447. <input type="hidden" name="select$form->{vc}" value="|
  448. . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">|;
  449. }
  450. else {
  451. $vc = qq|<input name="$form->{vc}" value="$form->{$form->{vc}}" size="35">|;
  452. }
  453. $department = qq|
  454. <tr>
  455. <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
  456. <td colspan="3"><select name="department">$form->{selectdepartment}</select>
  457. <input type="hidden" name="selectdepartment" value="|
  458. . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
  459. </td>
  460. </tr>
  461. | if $form->{selectdepartment};
  462. $employee = qq|
  463. <input type="hidden" name="employee" value="$form->{employee}">
  464. |;
  465. if ( $form->{type} eq 'sales_order' ) {
  466. if ( $form->{selectemployee} ) {
  467. $employee = qq|
  468. <tr>
  469. <th align="right" nowrap>| . $locale->text('Salesperson') . qq|</th>
  470. <td><select name="employee">$form->{selectemployee}</select></td>
  471. <input type="hidden" name="selectemployee" value="|
  472. . $form->escape( $form->{selectemployee}, 1 ) . qq|"
  473. </tr>
  474. |;
  475. }
  476. }
  477. else {
  478. if ( $form->{selectemployee} ) {
  479. $employee = qq|
  480. <tr>
  481. <th align="right" nowrap>| . $locale->text('Employee') . qq|</th>
  482. <td><select name="employee">$form->{selectemployee}</select></td>
  483. <input type="hidden" name="selectemployee" value="|
  484. . $form->escape( $form->{selectemployee}, 1 ) . qq|"
  485. </tr>
  486. |;
  487. }
  488. }
  489. $i = $form->{rowcount} + 1;
  490. $focus = "partnumber_$i";
  491. $form->header;
  492. print qq|
  493. <body onLoad="document.forms[0].${focus}.focus()">
  494. <form method="post" action="$form->{script}">
  495. |;
  496. $form->hide_form(
  497. qw(id type formname media format printed emailed queued vc title discount creditlimit creditremaining tradediscount business recurring)
  498. );
  499. print qq|
  500. <table width="100%">
  501. <tr class="listtop">
  502. <th class="listtop">$form->{title}</th>
  503. </tr>
  504. <tr height="5"></tr>
  505. <tr>
  506. <td>
  507. <table width="100%">
  508. <tr valign="top">
  509. <td>
  510. <table width="100%">
  511. <tr>
  512. <th align="right">$vclabel</th>
  513. <td colspan="3">$vc</td>
  514. <input type="hidden" name="$form->{vc}_id" value="$form->{"$form->{vc}_id"}">
  515. <input type="hidden" name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
  516. </tr>
  517. $creditremaining
  518. $business
  519. $department
  520. $exchangerate
  521. <tr>
  522. <th align="right">| . $locale->text('Shipping Point') . qq|</th>
  523. <td colspan="3"><input name="shippingpoint" size="35" value="$form->{shippingpoint}"></td>
  524. </tr>
  525. <tr>
  526. <th align="right">| . $locale->text('Ship via') . qq|</th>
  527. <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
  528. </tr>
  529. </table>
  530. </td>
  531. <td align="right">
  532. <table>
  533. $openclosed
  534. $employee
  535. $ordnumber
  536. $terms
  537. </table>
  538. </td>
  539. </tr>
  540. </table>
  541. </td>
  542. </tr>
  543. |;
  544. $form->hide_form(
  545. qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc taxaccounts)
  546. );
  547. for ( split / /, $form->{taxaccounts} ) {
  548. print qq|
  549. <input type="hidden" name="${_}_rate" value="$form->{"${_}_rate"}">
  550. <input type="hidden" name="${_}_description" value="$form->{"${_}_description"}">
  551. |;
  552. }
  553. }
  554. sub form_footer {
  555. $form->{invtotal} = $form->{invsubtotal};
  556. if ( ( $rows = $form->numtextrows( $form->{notes}, 35, 8 ) ) < 2 ) {
  557. $rows = 2;
  558. }
  559. if ( ( $introws = $form->numtextrows( $form->{intnotes}, 35, 8 ) ) < 2 ) {
  560. $introws = 2;
  561. }
  562. $rows = ( $rows > $introws ) ? $rows : $introws;
  563. $notes =
  564. qq|<textarea name="notes" rows="$rows" cols="35" wrap="soft">$form->{notes}</textarea>|;
  565. $intnotes =
  566. qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
  567. $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
  568. $taxincluded = "";
  569. if ( $form->{taxaccounts} ) {
  570. $taxincluded = qq|
  571. <tr height="5"></tr>
  572. <tr>
  573. <td align="right">
  574. <input name="taxincluded" class="checkbox" type="checkbox" value="1" $form->{taxincluded}></td>
  575. <th align="left">| . $locale->text('Tax Included') . qq|</th>
  576. </tr>
  577. |;
  578. }
  579. if ( !$form->{taxincluded} ) {
  580. my @taxes = Tax::init_taxes( $form, $form->{taxaccounts} );
  581. foreach my $item (@taxes) {
  582. my $taccno = $item->account;
  583. $form->{invtotal} += $form->round_amount(
  584. $form->{"${taccno}_rate"} * $form->{"${taccno}_base"}, 2);
  585. $form->{"${taccno}_total"} =
  586. $form->format_amount( \%myconfig,
  587. $form->{"${taccno}_rate"} * $form->{"${taccno}_base"}, 2 );
  588. $tax .= qq|
  589. <tr>
  590. <th align="right">$form->{"${taccno}_description"}</th>
  591. <td align="right">$form->{"${taccno}_total"}</td>
  592. </tr>
  593. | if $form->{"${taccno}_base"};
  594. }
  595. $form->{invsubtotal} =
  596. $form->format_amount( \%myconfig, $form->{invsubtotal}, 2, 0 );
  597. $subtotal = qq|
  598. <tr>
  599. <th align="right">| . $locale->text('Subtotal') . qq|</th>
  600. <td align="right">$form->{invsubtotal}</td>
  601. </tr>
  602. |;
  603. }
  604. $form->{oldinvtotal} = $form->{invtotal};
  605. $form->{invtotal} =
  606. $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
  607. print qq|
  608. <tr>
  609. <td>
  610. <table width="100%">
  611. <tr valign="top">
  612. <td>
  613. <table>
  614. <tr>
  615. <th align="left">| . $locale->text('Notes') . qq|</th>
  616. <th align="left">| . $locale->text('Internal Notes') . qq|</th>
  617. </tr>
  618. <tr valign="top">
  619. <td>$notes</td>
  620. <td>$intnotes</td>
  621. </tr>
  622. </table>
  623. </td>
  624. <td align="right">
  625. <table>
  626. $subtotal
  627. $tax
  628. <tr>
  629. <th align="right">| . $locale->text('Total') . qq|</th>
  630. <td align="right">$form->{invtotal}</td>
  631. </tr>
  632. $taxincluded
  633. </table>
  634. </td>
  635. </tr>
  636. </table>
  637. </td>
  638. </tr>
  639. <input type="hidden" name="oldinvtotal" value="$form->{oldinvtotal}">
  640. <input type="hidden" name="oldtotalpaid" value="$totalpaid">
  641. <tr>
  642. <td><hr size="3" noshade></td>
  643. </tr>
  644. <tr>
  645. <td>
  646. |;
  647. &print_options;
  648. print qq|
  649. </td>
  650. </tr>
  651. </table>
  652. <br>
  653. |;
  654. # type="submit" $locale->text('Update')
  655. # type="submit" $locale->text('Print')
  656. # type="submit" $locale->text('Schedule')
  657. # type="submit" $locale->text('Save')
  658. # type="submit" $locale->text('Print and Save')
  659. # type="submit" $locale->text('Ship to')
  660. # type="submit" $locale->text('Save as new')
  661. # type="submit" $locale->text('Print and Save as new')
  662. # type="submit" $locale->text('E-mail')
  663. # type="submit" $locale->text('Delete')
  664. # type="submit" $locale->text('Sales Invoice')
  665. # type="submit" $locale->text('Vendor Invoice')
  666. # type="submit" $locale->text('Quotation')
  667. # type="submit" $locale->text('RFQ')
  668. # type="submit" $locale->text('Sales Order')
  669. # type="submit" $locale->text('Purchase Order')
  670. if ( !$form->{readonly} ) {
  671. %button = (
  672. 'update' =>
  673. { ndx => 1, key => 'U', value => $locale->text('Update') },
  674. 'print' =>
  675. { ndx => 2, key => 'P', value => $locale->text('Print') },
  676. 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
  677. 'ship_to' =>
  678. { ndx => 4, key => 'T', value => $locale->text('Ship to') },
  679. 'e_mail' =>
  680. { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  681. 'print_and_save' => {
  682. ndx => 6,
  683. key => 'R',
  684. value => $locale->text('Print and Save')
  685. },
  686. 'save_as_new' =>
  687. { ndx => 7, key => 'N', value => $locale->text('Save as new') },
  688. 'print_and_save_as_new' => {
  689. ndx => 8,
  690. key => 'W',
  691. value => $locale->text('Print and Save as new')
  692. },
  693. 'sales_invoice' =>
  694. { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
  695. 'sales_order' =>
  696. { ndx => 10, key => 'O', value => $locale->text('Sales Order') },
  697. 'quotation' =>
  698. { ndx => 11, key => 'Q', value => $locale->text('Quotation') },
  699. 'vendor_invoice' => {
  700. ndx => 12,
  701. key => 'I',
  702. value => $locale->text('Vendor Invoice')
  703. },
  704. 'purchase_order' => {
  705. ndx => 13,
  706. key => 'O',
  707. value => $locale->text('Purchase Order')
  708. },
  709. 'rfq' => { ndx => 14, key => 'Q', value => $locale->text('RFQ') },
  710. 'schedule' =>
  711. { ndx => 15, key => 'H', value => $locale->text('Schedule') },
  712. 'delete' =>
  713. { ndx => 16, key => 'D', value => $locale->text('Delete') },
  714. );
  715. %a = ();
  716. for ( "update", "ship_to", "print", "e_mail", "save" ) { $a{$_} = 1 }
  717. $a{'print_and_save'} = 1 if ${LedgerSMB::Sysconfig::latex};
  718. if ( $form->{id} ) {
  719. $a{'delete'} = 1;
  720. $a{'save_as_new'} = 1;
  721. $a{'print_and_save_as_new'} = 1 if ${LedgerSMB::Sysconfig::latex};
  722. if ( $form->{type} =~ /sales_/ ) {
  723. if ( $myconfig{acs} !~ /AR--Sales Invoice/ ) {
  724. $a{'sales_invoice'} = 1;
  725. }
  726. }
  727. else {
  728. if ( $myconfig{acs} !~ /AP--Vendor Invoice/ ) {
  729. $a{'vendor_invoice'} = 1;
  730. }
  731. }
  732. if ( $form->{type} eq 'sales_order' ) {
  733. if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
  734. $a{'quotation'} = 1;
  735. }
  736. }
  737. if ( $form->{type} eq 'purchase_order' ) {
  738. if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
  739. $a{'rfq'} = 1;
  740. }
  741. }
  742. if ( $form->{type} eq 'sales_quotation' ) {
  743. if ( $myconfig{acs} !~ /Order Entry--Sales Order/ ) {
  744. $a{'sales_order'} = 1;
  745. }
  746. }
  747. if ( $myconfig{acs} !~ /Order Entry--Purchase Order/ ) {
  748. if ( $form->{type} eq 'request_quotation' ) {
  749. $a{'purchase_order'} = 1;
  750. }
  751. }
  752. }
  753. if ( $form->{type} =~ /_order/ ) {
  754. $a{'schedule'} = 1;
  755. }
  756. }
  757. for ( keys %button ) { delete $button{$_} if !$a{$_} }
  758. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  759. $form->print_button( \%button, $_ );
  760. }
  761. if ( $form->{lynx} ) {
  762. require "bin/menu.pl";
  763. &menubar;
  764. }
  765. $form->hide_form(qw(rowcount callback path login sessionid));
  766. print qq|
  767. </form>
  768. </body>
  769. </html>
  770. |;
  771. }
  772. sub update {
  773. if ( $form->{type} eq 'generate_purchase_order' ) {
  774. for ( 1 .. $form->{rowcount} ) {
  775. if ( $form->{"ndx_$_"} ) {
  776. $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
  777. $form->{"$form->{vc}_$_"} =
  778. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  779. }
  780. }
  781. &po_orderitems;
  782. exit;
  783. }
  784. $form->{exchangerate} =
  785. $form->parse_amount( \%myconfig, $form->{exchangerate} );
  786. if ( $form->{vc} eq 'customer' ) {
  787. $buysell = "buy";
  788. $ARAP = "AR";
  789. }
  790. else {
  791. $buysell = "sell";
  792. $ARAP = "AP";
  793. }
  794. if ( $newname = &check_name( $form->{vc} ) ) {
  795. &rebuild_vc( $form->{vc}, $ARAP, $form->{transdate}, 1 );
  796. }
  797. if ( $form->{transdate} ne $form->{oldtransdate} ) {
  798. $form->{reqdate} =
  799. ( $form->{terms} )
  800. ? $form->current_date( \%myconfig, $form->{transdate},
  801. $form->{terms} * 1 )
  802. : $form->{reqdate};
  803. $form->{oldtransdate} = $form->{transdate};
  804. &rebuild_vc( $form->{vc}, $ARAP, $form->{transdate}, 1 ) if !$newname;
  805. if ( $form->{currency} ne $form->{defaultcurrency} ) {
  806. delete $form->{exchangerate};
  807. $form->{exchangerate} = $exchangerate
  808. if (
  809. $form->{forex} = (
  810. $exchangerate = $form->check_exchangerate(
  811. \%myconfig, $form->{currency},
  812. $form->{transdate}, $buysell
  813. )
  814. )
  815. );
  816. }
  817. $form->{selectemployee} = "";
  818. if ( @{ $form->{all_employee} } ) {
  819. for ( @{ $form->{all_employee} } ) {
  820. $form->{selectemployee} .=
  821. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  822. }
  823. }
  824. }
  825. if ( $form->{currency} ne $form->{oldcurrency} ) {
  826. delete $form->{exchangerate};
  827. $form->{exchangerate} = $exchangerate
  828. if (
  829. $form->{forex} = (
  830. $exchangerate = $form->check_exchangerate(
  831. \%myconfig, $form->{currency},
  832. $form->{transdate}, $buysell
  833. )
  834. )
  835. );
  836. }
  837. my $i = $form->{rowcount};
  838. $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
  839. for (qw(partsgroup projectnumber)) {
  840. $form->{"select$_"} = $form->unescape( $form->{"select$_"} )
  841. if $form->{"select$_"};
  842. }
  843. if ( ( $form->{"partnumber_$i"} eq "" )
  844. && ( $form->{"description_$i"} eq "" )
  845. && ( $form->{"partsgroup_$i"} eq "" ) )
  846. {
  847. $form->{creditremaining} +=
  848. ( $form->{oldinvtotal} - $form->{oldtotalpaid} );
  849. &check_form;
  850. }
  851. else {
  852. $retrieve_item = "";
  853. if ( $form->{type} eq 'purchase_order'
  854. || $form->{type} eq 'request_quotation' )
  855. {
  856. $retrieve_item = "IR::retrieve_item";
  857. }
  858. if ( $form->{type} eq 'sales_order'
  859. || $form->{type} eq 'sales_quotation' )
  860. {
  861. $retrieve_item = "IS::retrieve_item";
  862. }
  863. &{"$retrieve_item"}( "", \%myconfig, \%$form );
  864. $rows = scalar @{ $form->{item_list} };
  865. if ( $form->{language_code} && $rows == 0 ) {
  866. $language_code = $form->{language_code};
  867. $form->{language_code} = "";
  868. if ($retrieve_item) {
  869. &{"$retrieve_item"}( "", \%myconfig, \%$form );
  870. }
  871. $form->{language_code} = $language_code;
  872. $rows = scalar @{ $form->{item_list} };
  873. }
  874. if ($rows) {
  875. if ( $rows > 1 ) {
  876. &select_item;
  877. exit;
  878. }
  879. else {
  880. $form->{"qty_$i"} =
  881. ( $form->{"qty_$i"} * 1 ) ? $form->{"qty_$i"} : 1;
  882. $form->{"reqdate_$i"} = $form->{reqdate}
  883. if $form->{type} ne 'sales_quotation';
  884. $sellprice =
  885. $form->parse_amount( \%myconfig, $form->{"sellprice_$i"} );
  886. for (qw(partnumber description unit)) {
  887. $form->{item_list}[$i]{$_} =
  888. $form->quote( $form->{item_list}[$i]{$_} );
  889. }
  890. for ( keys %{ $form->{item_list}[0] } ) {
  891. $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
  892. }
  893. $form->{"discount_$i"} = $form->{discount} * 100;
  894. if ($sellprice) {
  895. $form->{"sellprice_$i"} = $sellprice;
  896. ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
  897. $dec = length $dec;
  898. $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
  899. }
  900. else {
  901. ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
  902. $dec = length $dec;
  903. $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
  904. $form->{"sellprice_$i"} /= $exchangerate;
  905. }
  906. ($dec) = ( $form->{"lastcost_$i"} =~ /\.(\d+)/ );
  907. $dec = length $dec;
  908. $decimalplaces2 = ( $dec > 2 ) ? $dec : 2;
  909. for (qw(listprice lastcost)) {
  910. $form->{"${_}_$i"} /= $exchangerate;
  911. }
  912. $amount =
  913. $form->{"sellprice_$i"} * $form->{"qty_$i"} *
  914. ( 1 - $form->{"discount_$i"} / 100 );
  915. for ( split / /, $form->{taxaccounts} ) {
  916. $form->{"${_}_base"} = 0;
  917. }
  918. for ( split / /, $form->{"taxaccounts_$i"} ) {
  919. $form->{"${_}_base"} += $amount;
  920. }
  921. if ( !$form->{taxincluded} ) {
  922. my @taxes = Tax::init_taxes( $form, $form->{taxaccounts} );
  923. $amount +=
  924. Tax::calculate_taxes( \@taxes, $form, $amount, 0 );
  925. }
  926. $form->{creditremaining} -= $amount;
  927. for (qw(sellprice listprice)) {
  928. $form->{"${_}_$i"} =
  929. $form->format_amount( \%myconfig, $form->{"${_}_$i"},
  930. $decimalplaces1 );
  931. }
  932. $form->{"lastcost_$i"} =
  933. $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
  934. $decimalplaces2 );
  935. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  936. for (qw(qty discount)) {
  937. $form->{"{_}_$i"} =
  938. $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
  939. }
  940. }
  941. &display_form;
  942. }
  943. else {
  944. # ok, so this is a new part
  945. # ask if it is a part or service item
  946. if ( $form->{"partsgroup_$i"}
  947. && ( $form->{"partsnumber_$i"} eq "" )
  948. && ( $form->{"description_$i"} eq "" ) )
  949. {
  950. $form->{rowcount}--;
  951. &display_form;
  952. }
  953. else {
  954. $form->{"id_$i"} = 0;
  955. $form->{"unit_$i"} = $locale->text('ea');
  956. &new_item;
  957. }
  958. }
  959. }
  960. }
  961. sub search {
  962. $requiredby = $locale->text('Required by');
  963. if ( $form->{type} eq 'purchase_order' ) {
  964. $form->{title} = $locale->text('Purchase Orders');
  965. $form->{vc} = 'vendor';
  966. $ordlabel = $locale->text('Order Number');
  967. $ordnumber = 'ordnumber';
  968. $employee = $locale->text('Employee');
  969. }
  970. if ( $form->{type} eq 'receive_order' ) {
  971. $form->{title} = $locale->text('Receive Merchandise');
  972. $form->{vc} = 'vendor';
  973. $ordlabel = $locale->text('Order Number');
  974. $ordnumber = 'ordnumber';
  975. $employee = $locale->text('Employee');
  976. }
  977. if ( $form->{type} eq 'generate_sales_order' ) {
  978. $form->{title} =
  979. $locale->text('Generate Sales Order from Purchase Orders');
  980. $form->{vc} = 'vendor';
  981. $ordlabel = $locale->text('Order Number');
  982. $ordnumber = 'ordnumber';
  983. $employee = $locale->text('Employee');
  984. }
  985. if ( $form->{type} eq 'consolidate_sales_order' ) {
  986. $form->{title} = $locale->text('Consolidate Sales Orders');
  987. $form->{vc} = 'customer';
  988. $ordlabel = $locale->text('Order Number');
  989. $ordnumber = 'ordnumber';
  990. $employee = $locale->text('Salesperson');
  991. }
  992. if ( $form->{type} eq 'request_quotation' ) {
  993. $form->{title} = $locale->text('Request for Quotations');
  994. $form->{vc} = 'vendor';
  995. $ordlabel = $locale->text('RFQ Number');
  996. $ordnumber = 'quonumber';
  997. $employee = $locale->text('Employee');
  998. }
  999. if ( $form->{type} eq 'sales_order' ) {
  1000. $form->{title} = $locale->text('Sales Orders');
  1001. $form->{vc} = 'customer';
  1002. $ordlabel = $locale->text('Order Number');
  1003. $ordnumber = 'ordnumber';
  1004. $employee = $locale->text('Salesperson');
  1005. }
  1006. if ( $form->{type} eq 'ship_order' ) {
  1007. $form->{title} = $locale->text('Ship Merchandise');
  1008. $form->{vc} = 'customer';
  1009. $ordlabel = $locale->text('Order Number');
  1010. $ordnumber = 'ordnumber';
  1011. $employee = $locale->text('Salesperson');
  1012. }
  1013. if ( $form->{type} eq 'sales_quotation' ) {
  1014. $form->{title} = $locale->text('Quotations');
  1015. $form->{vc} = 'customer';
  1016. $ordlabel = $locale->text('Quotation Number');
  1017. $ordnumber = 'quonumber';
  1018. $employee = $locale->text('Employee');
  1019. $requiredby = $locale->text('Valid until');
  1020. }
  1021. if ( $form->{type} eq 'generate_purchase_order' ) {
  1022. $form->{title} =
  1023. $locale->text('Generate Purchase Orders from Sales Order');
  1024. $form->{vc} = 'customer';
  1025. $ordlabel = $locale->text('Order Number');
  1026. $ordnumber = 'ordnumber';
  1027. $employee = $locale->text('Salesperson');
  1028. }
  1029. if ( $form->{type} eq 'consolidate_purchase_order' ) {
  1030. $form->{title} = $locale->text('Consolidate Purchase Orders');
  1031. $form->{vc} = 'vendor';
  1032. $ordlabel = $locale->text('Order Number');
  1033. $ordnumber = 'ordnumber';
  1034. $employee = $locale->text('Employee');
  1035. }
  1036. $l_employee =
  1037. qq|<input name="l_employee" class="checkbox" type="checkbox" value="Y"> $employee|;
  1038. $l_manager =
  1039. qq|<input name="l_manager" class="checkbox" type="checkbox" value="Y"> |
  1040. . $locale->text('Manager');
  1041. if ( $form->{type} =~ /(ship|receive)_order/ ) {
  1042. OE->get_warehouses( \%myconfig, \%$form );
  1043. $l_manager = "";
  1044. # warehouse
  1045. if ( @{ $form->{all_warehouse} } ) {
  1046. $form->{selectwarehouse} = "<option>\n";
  1047. $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|;
  1048. for ( @{ $form->{all_warehouse} } ) {
  1049. $form->{selectwarehouse} .=
  1050. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  1051. }
  1052. $warehouse = qq|
  1053. <tr>
  1054. <th align="right">| . $locale->text('Warehouse') . qq|</th>
  1055. <td><select name="warehouse">$form->{selectwarehouse}</select></td>
  1056. <input type="hidden" name="selectwarehouse" value="|
  1057. . $form->escape( $form->{selectwarehouse}, 1 ) . qq|">
  1058. </tr>
  1059. |;
  1060. }
  1061. }
  1062. # setup vendor / customer selection
  1063. $form->all_vc( \%myconfig, $form->{vc},
  1064. ( $form->{vc} eq 'customer' ) ? "AR" : "AP" );
  1065. for ( @{ $form->{"all_$form->{vc}"} } ) {
  1066. $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1067. }
  1068. $selectemployee = "";
  1069. if ( @{ $form->{all_employee} } ) {
  1070. $selectemployee = "<option>\n";
  1071. for ( @{ $form->{all_employee} } ) {
  1072. $selectemployee .=
  1073. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1074. }
  1075. $selectemployee = qq|
  1076. <tr>
  1077. <th align="right">$employee</th>
  1078. <td colspan="3"><select name="employee">$selectemployee</select></td>
  1079. </tr>
  1080. |;
  1081. }
  1082. else {
  1083. $l_employee = $l_manager = "";
  1084. }
  1085. $vclabel = ucfirst $form->{vc};
  1086. $vclabel = $locale->text($vclabel);
  1087. # $locale->text('Vendor')
  1088. # $locale->text('Customer')
  1089. $vc =
  1090. ($vc)
  1091. ? qq|<select name="$form->{vc}"><option>\n$vc</select>|
  1092. : qq|<input name="$form->{vc}" size="35">|;
  1093. # departments
  1094. if ( @{ $form->{all_department} } ) {
  1095. $form->{selectdepartment} = "<option>\n";
  1096. for ( @{ $form->{all_department} } ) {
  1097. $form->{selectdepartment} .=
  1098. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  1099. }
  1100. }
  1101. $department = qq|
  1102. <tr>
  1103. <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
  1104. <td colspan="3"><select name="department">$form->{selectdepartment}</select></td>
  1105. </tr>
  1106. | if $form->{selectdepartment};
  1107. if ( $form->{type} =~ /(consolidate.*|generate.*|ship|receive)_order/ ) {
  1108. $openclosed = qq|
  1109. <input type="hidden" name="open" value="1">
  1110. |;
  1111. }
  1112. else {
  1113. $openclosed = qq|
  1114. <tr>
  1115. <td nowrap><input name="open" class="checkbox" type="checkbox" value="1" checked> |
  1116. . $locale->text('Open')
  1117. . qq|</td>
  1118. <td nowrap><input name="closed" class="checkbox" type="checkbox" value="1" $form->{closed}> |
  1119. . $locale->text('Closed')
  1120. . qq|</td>
  1121. </tr>
  1122. |;
  1123. }
  1124. if ( @{ $form->{all_years} } ) {
  1125. # accounting years
  1126. $form->{selectaccountingyear} = "<option>\n";
  1127. for ( @{ $form->{all_years} } ) {
  1128. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  1129. }
  1130. $form->{selectaccountingmonth} = "<option>\n";
  1131. for ( sort keys %{ $form->{all_month} } ) {
  1132. $form->{selectaccountingmonth} .=
  1133. qq|<option value=$_>|
  1134. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  1135. }
  1136. $selectfrom = qq|
  1137. <tr>
  1138. <th align="right">| . $locale->text('Period') . qq|</th>
  1139. <td colspan="3">
  1140. <select name="month">$form->{selectaccountingmonth}</select>
  1141. <select name="year">$form->{selectaccountingyear}</select>
  1142. <input name="interval" class="radio" type="radio" value="0" checked>&nbsp;|
  1143. . $locale->text('Current') . qq|
  1144. <input name="interval" class="radio" type="radio" value="1">&nbsp;|
  1145. . $locale->text('Month') . qq|
  1146. <input name="interval" class="radio" type="radio" value="3">&nbsp;|
  1147. . $locale->text('Quarter') . qq|
  1148. <input name="interval" class="radio" type="radio" value="12">&nbsp;|
  1149. . $locale->text('Year') . qq|
  1150. </td>
  1151. </tr>
  1152. |;
  1153. }
  1154. if ( $form->{type} =~ /_order/ ) {
  1155. $ponumber = qq|
  1156. <tr>
  1157. <th align="right">| . $locale->text('PO Number') . qq|</th>
  1158. <td colspan="3"><input name="ponumber" size="20"></td>
  1159. </tr>
  1160. |;
  1161. $l_ponumber =
  1162. qq|<input name="l_ponumber" class="checkbox" type="checkbox" value="Y"> |
  1163. . $locale->text('PO Number');
  1164. }
  1165. @a = ();
  1166. push @a,
  1167. qq|<input name="l_runningnumber" class="checkbox" type="checkbox" value="Y"> |
  1168. . $locale->text('No.');
  1169. push @a, qq|<input name="l_id" class="checkbox" type="checkbox" value="Y"> |
  1170. . $locale->text('ID');
  1171. push @a,
  1172. qq|<input name="l_$ordnumber" class="checkbox" type="checkbox" value="Y" checked> $ordlabel|;
  1173. push @a,
  1174. qq|<input name="l_transdate" class="checkbox" type="checkbox" value="Y" checked> |
  1175. . $locale->text('Date');
  1176. push @a, $l_ponumber if $l_ponumber;
  1177. push @a,
  1178. qq|<input name="l_reqdate" class="checkbox" type="checkbox" value="Y" checked> $requiredby|;
  1179. push @a,
  1180. qq|<input name="l_name" class="checkbox" type="checkbox" value="Y" checked> $vclabel|;
  1181. push @a, $l_employee if $l_employee;
  1182. push @a, $l_manager if $l_manager;
  1183. push @a, qq|<input name="l_shipvia" class="checkbox" type="checkbox" value="Y"> |
  1184. . $locale->text('Ship via');
  1185. push @a,
  1186. qq|<input name="l_netamount" class="checkbox" type="checkbox" value="Y"> |
  1187. . $locale->text('Amount');
  1188. push @a, qq|<input name="l_tax" class="checkbox" type="checkbox" value="Y"> |
  1189. . $locale->text('Tax');
  1190. push @a,
  1191. qq|<input name="l_amount" class="checkbox" type="checkbox" value="Y" checked> |
  1192. . $locale->text('Total');
  1193. push @a,
  1194. qq|<input name="l_curr" class="checkbox" type="checkbox" value="Y" checked> |
  1195. . $locale->text('Currency');
  1196. $form->header;
  1197. print qq|
  1198. <body>
  1199. <form method="post" action="$form->{script}">
  1200. <table width="100%">
  1201. <tr>
  1202. <th class="listtop">$form->{title}</th>
  1203. </tr>
  1204. <tr height="5"></tr>
  1205. <tr>
  1206. <td>
  1207. <table>
  1208. <tr>
  1209. <th align="right">$vclabel</th>
  1210. <td colspan="3">$vc</td>
  1211. </tr>
  1212. $warehouse
  1213. $department
  1214. $selectemployee
  1215. <tr>
  1216. <th align="right">$ordlabel</th>
  1217. <td colspan="3"><input name="$ordnumber" size="20"></td>
  1218. </tr>
  1219. $ponumber
  1220. <tr>
  1221. <th align="right">| . $locale->text('Ship via') . qq|</th>
  1222. <td colspan="3"><input name="shipvia" size="40"></td>
  1223. </tr>
  1224. <tr>
  1225. <th align="right">| . $locale->text('Description') . qq|</th>
  1226. <td colspan="3"><input name="description" size="40"></td>
  1227. </tr>
  1228. <tr>
  1229. <th align="right">| . $locale->text('From') . qq|</th>
  1230. <td><input name="transdatefrom" size="11" title="$myconfig{dateformat}"></td>
  1231. <th align="right">| . $locale->text('To') . qq|</th>
  1232. <td><input name="transdateto" size="11" title="$myconfig{dateformat}"></td>
  1233. </tr>
  1234. <input type="hidden" name="sort" value="transdate">
  1235. $selectfrom
  1236. <tr>
  1237. <th align="right">| . $locale->text('Include in Report') . qq|</th>
  1238. <td colspan="3">
  1239. <table>
  1240. $openclosed
  1241. |;
  1242. while (@a) {
  1243. for ( 1 .. 5 ) {
  1244. print qq|<td nowrap>| . shift @a;
  1245. print qq|</td>\n|;
  1246. }
  1247. print qq|</tr>\n|;
  1248. }
  1249. print qq|
  1250. <tr>
  1251. <td><input name="l_subtotal" class="checkbox" type="checkbox" value="Y"> |
  1252. . $locale->text('Subtotal')
  1253. . qq|</td>
  1254. </tr>
  1255. </table>
  1256. </td>
  1257. </tr>
  1258. </table>
  1259. </td>
  1260. </tr>
  1261. <tr><td colspan="4"><hr size="3" noshade></td></tr>
  1262. </table>
  1263. <br>
  1264. <input type="hidden" name="nextsub" value="transactions">
  1265. |;
  1266. $form->hide_form(qw(path login sessionid vc type));
  1267. print qq|
  1268. <button class="submit" type="submit" name="action" value="continue">|
  1269. . $locale->text('Continue')
  1270. . qq|</button>
  1271. </form>
  1272. |;
  1273. if ( $form->{lynx} ) {
  1274. require "bin/menu.pl";
  1275. &menubar;
  1276. }
  1277. print qq|
  1278. </body>
  1279. </html>
  1280. |;
  1281. }
  1282. sub transactions {
  1283. # split vendor / customer
  1284. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  1285. split( /--/, $form->{ $form->{vc} } );
  1286. $form->{department} = "$form->{department}--$myconfig{department_id}"
  1287. if $myconfig{department_id};
  1288. OE->transactions( \%myconfig, \%$form );
  1289. $ordnumber = ( $form->{type} =~ /_order/ ) ? 'ordnumber' : 'quonumber';
  1290. $name = $form->escape( $form->{ $form->{vc} } );
  1291. $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
  1292. # construct href
  1293. $href = qq|$form->{script}?action=transactions|;
  1294. for (
  1295. "oldsort", "direction", "path", "type",
  1296. "vc", "login", "sessionid", "transdatefrom",
  1297. "transdateto", "open", "closed"
  1298. )
  1299. {
  1300. $href .= qq|&$_=$form->{$_}|;
  1301. }
  1302. for (
  1303. "$ordnumber", "department", "warehouse", "shipvia",
  1304. "ponumber", "description", "employee"
  1305. )
  1306. {
  1307. $href .= qq|&$_=| . $form->escape( $form->{$_} );
  1308. }
  1309. $href .= "&$form->{vc}=$name";
  1310. # construct callback
  1311. $name = $form->escape( $form->{ $form->{vc} }, 1 );
  1312. $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
  1313. # flip direction
  1314. $form->sort_order();
  1315. $callback = qq|$form->{script}?action=transactions|;
  1316. for (
  1317. "oldsort", "direction", "path", "type",
  1318. "vc", "login", "sessionid", "transdatefrom",
  1319. "transdateto", "open", "closed"
  1320. )
  1321. {
  1322. $callback .= qq|&$_=$form->{$_}|;
  1323. }
  1324. for (
  1325. "$ordnumber", "department", "warehouse", "shipvia",
  1326. "ponumber", "description", "employee"
  1327. )
  1328. {
  1329. $callback .= qq|&$_=| . $form->escape( $form->{$_}, 1 );
  1330. }
  1331. $callback .= "&$form->{vc}=$name";
  1332. @columns = $form->sort_columns(
  1333. "transdate", "reqdate", "id", "$ordnumber",
  1334. "ponumber", "name", "netamount", "tax",
  1335. "amount", "curr", "employee", "manager",
  1336. "shipvia", "open", "closed"
  1337. );
  1338. unshift @columns, "runningnumber";
  1339. $form->{l_open} = $form->{l_closed} = "Y"
  1340. if ( $form->{open} && $form->{closed} );
  1341. for (@columns) {
  1342. if ( $form->{"l_$_"} eq "Y" ) {
  1343. push @column_index, $_;
  1344. if ( $form->{l_curr} && $_ =~ /(amount|tax)/ ) {
  1345. push @column_index, "fx_$_";
  1346. }
  1347. # add column to href and callback
  1348. $callback .= "&l_$_=Y";
  1349. $href .= "&l_$_=Y";
  1350. }
  1351. }
  1352. if ( $form->{l_subtotal} eq 'Y' ) {
  1353. $callback .= "&l_subtotal=Y";
  1354. $href .= "&l_subtotal=Y";
  1355. }
  1356. $requiredby = $locale->text('Required by');
  1357. $i = 1;
  1358. if ( $form->{vc} eq 'vendor' ) {
  1359. if ( $form->{type} eq 'receive_order' ) {
  1360. $form->{title} = $locale->text('Receive Merchandise');
  1361. }
  1362. if ( $form->{type} eq 'purchase_order' ) {
  1363. $form->{title} = $locale->text('Purchase Orders');
  1364. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1365. $button{'Order Entry--Purchase Order'}{code} =
  1366. qq|<button class="submit" type="submit" name="action" value="purchase_order">|
  1367. . $locale->text('Purchase Order')
  1368. . qq|</button> |;
  1369. $button{'Order Entry--Purchase Order'}{order} = $i++;
  1370. }
  1371. }
  1372. if ( $form->{type} eq 'generate_sales_order' ) {
  1373. $form->{title} = $locale->text('Purchase Orders');
  1374. $form->{type} = "purchase_order";
  1375. unshift @column_index, "ndx";
  1376. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1377. $button{'Order Entry--Sales Order'}{code} =
  1378. qq|<button class="submit" type="submit" name="action" value="generate_sales_order">|
  1379. . $locale->text('Generate Sales Order')
  1380. . qq|</button> |;
  1381. $button{'Order Entry--Sales Order'}{order} = $i++;
  1382. }
  1383. }
  1384. if ( $form->{type} eq 'consolidate_purchase_order' ) {
  1385. $form->{title} = $locale->text('Purchase Orders');
  1386. $form->{type} = "purchase_order";
  1387. unshift @column_index, "ndx";
  1388. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1389. $button{'Order Entry--Purchase Order'}{code} =
  1390. qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|
  1391. . $locale->text('Consolidate Orders')
  1392. . qq|</button> |;
  1393. $button{'Order Entry--Purchase Order'}{order} = $i++;
  1394. }
  1395. }
  1396. if ( $form->{type} eq 'request_quotation' ) {
  1397. $form->{title} = $locale->text('Request for Quotations');
  1398. $quotation = $locale->text('RFQ');
  1399. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1400. $button{'Quotations--RFQ'}{code} =
  1401. qq|<button class="submit" type="submit" name="action" value="add">|
  1402. . $locale->text('RFQ')
  1403. . qq|</button> |;
  1404. $button{'Quotations--RFQ'}{order} = $i++;
  1405. }
  1406. }
  1407. $name = $locale->text('Vendor');
  1408. $employee = $locale->text('Employee');
  1409. }
  1410. if ( $form->{vc} eq 'customer' ) {
  1411. if ( $form->{type} eq 'sales_order' ) {
  1412. $form->{title} = $locale->text('Sales Orders');
  1413. $employee = $locale->text('Salesperson');
  1414. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1415. $button{'Order Entry--Sales Order'}{code} =
  1416. qq|<button class="submit" type="submit" name="action" value="sales_order">|
  1417. . $locale->text('Sales Order')
  1418. . qq|</button> |;
  1419. $button{'Order Entry--Sales Order'}{order} = $i++;
  1420. }
  1421. }
  1422. if ( $form->{type} eq 'generate_purchase_order' ) {
  1423. $form->{title} = $locale->text('Sales Orders');
  1424. $form->{type} = "sales_order";
  1425. $employee = $locale->text('Salesperson');
  1426. unshift @column_index, "ndx";
  1427. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1428. $button{'Order Entry--Purchase Order'}{code} =
  1429. qq|<button class="submit" type="submit" name="action" value="generate_purchase_orders">|
  1430. . $locale->text('Generate Purchase Orders')
  1431. . qq|</button> |;
  1432. $button{'Order Entry--Purchase Order'}{order} = $i++;
  1433. }
  1434. }
  1435. if ( $form->{type} eq 'consolidate_sales_order' ) {
  1436. $form->{title} = $locale->text('Sales Orders');
  1437. $form->{type} = "sales_order";
  1438. unshift @column_index, "ndx";
  1439. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1440. $button{'Order Entry--Sales Order'}{code} =
  1441. qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|
  1442. . $locale->text('Consolidate Orders')
  1443. . qq|</button> |;
  1444. $button{'Order Entry--Sales Order'}{order} = $i++;
  1445. }
  1446. }
  1447. if ( $form->{type} eq 'ship_order' ) {
  1448. $form->{title} = $locale->text('Ship Merchandise');
  1449. $employee = $locale->text('Salesperson');
  1450. }
  1451. if ( $form->{type} eq 'sales_quotation' ) {
  1452. $form->{title} = $locale->text('Quotations');
  1453. $employee = $locale->text('Employee');
  1454. $requiredby = $locale->text('Valid until');
  1455. $quotation = $locale->text('Quotation');
  1456. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1457. $button{'Quotations--Quotation'}{code} =
  1458. qq|<button class="submit" type="submit" name="action" value="add">|
  1459. . $locale->text('Quotation')
  1460. . qq|</button> |;
  1461. $button{'Quotations--Quotation'}{order} = $i++;
  1462. }
  1463. }
  1464. $name = $locale->text('Customer');
  1465. }
  1466. for ( split /;/, $myconfig{acs} ) { delete $button{$_} }
  1467. $column_header{ndx} = qq|<th class="listheading">&nbsp;</th>|;
  1468. $column_header{runningnumber} = qq|<th class="listheading">&nbsp;</th>|;
  1469. $column_header{id} =
  1470. qq|<th><a class="listheading" href="$href&sort=id">|
  1471. . $locale->text('ID')
  1472. . qq|</a></th>|;
  1473. $column_header{transdate} =
  1474. qq|<th><a class="listheading" href="$href&sort=transdate">|
  1475. . $locale->text('Date')
  1476. . qq|</a></th>|;
  1477. $column_header{reqdate} =
  1478. qq|<th><a class="listheading" href="$href&sort=reqdate">$requiredby</a></th>|;
  1479. $column_header{ordnumber} =
  1480. qq|<th><a class="listheading" href="$href&sort=ordnumber">|
  1481. . $locale->text('Order')
  1482. . qq|</a></th>|;
  1483. $column_header{ponumber} =
  1484. qq|<th><a class="listheading" href="$href&sort=ponumber">|
  1485. . $locale->text('PO Number')
  1486. . qq|</a></th>|;
  1487. $column_header{quonumber} =
  1488. qq|<th><a class="listheading" href="$href&sort=quonumber">$quotation</a></th>|;
  1489. $column_header{name} =
  1490. qq|<th><a class="listheading" href="$href&sort=name">$name</a></th>|;
  1491. $column_header{netamount} =
  1492. qq|<th class="listheading">| . $locale->text('Amount') . qq|</th>|;
  1493. $column_header{tax} =
  1494. qq|<th class="listheading">| . $locale->text('Tax') . qq|</th>|;
  1495. $column_header{amount} =
  1496. qq|<th class="listheading">| . $locale->text('Total') . qq|</th>|;
  1497. $column_header{curr} =
  1498. qq|<th><a class="listheading" href="$href&sort=curr">|
  1499. . $locale->text('Curr')
  1500. . qq|</a></th>|;
  1501. $column_header{shipvia} =
  1502. qq|<th><a class="listheading" href="$href&sort=shipvia">|
  1503. . $locale->text('Ship via')
  1504. . qq|</a></th>|;
  1505. $column_header{open} =
  1506. qq|<th class="listheading">| . $locale->text('O') . qq|</th>|;
  1507. $column_header{closed} =
  1508. qq|<th class="listheading">| . $locale->text('C') . qq|</th>|;
  1509. $column_header{employee} =
  1510. qq|<th><a class="listheading" href="$href&sort=employee">$employee</a></th>|;
  1511. $column_header{manager} =
  1512. qq|<th><a class="listheading" href="$href&sort=manager">|
  1513. . $locale->text('Manager')
  1514. . qq|</a></th>|;
  1515. for (qw(amount tax netamount)) {
  1516. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1517. }
  1518. if ( $form->{ $form->{vc} } ) {
  1519. $option = $locale->text( ucfirst $form->{vc} );
  1520. $option .= " : $form->{$form->{vc}}";
  1521. }
  1522. if ( $form->{warehouse} ) {
  1523. ($warehouse) = split /--/, $form->{warehouse};
  1524. $option .= "\n<br>" if ($option);
  1525. $option .= $locale->text('Warehouse');
  1526. $option .= " : $warehouse";
  1527. }
  1528. if ( $form->{department} ) {
  1529. $option .= "\n<br>" if ($option);
  1530. ($department) = split /--/, $form->{department};
  1531. $option .= $locale->text('Department') . " : $department";
  1532. }
  1533. if ( $form->{employee} ) {
  1534. ($employee) = split /--/, $form->{employee};
  1535. $option .= "\n<br>" if ($option);
  1536. if ( $form->{vc} eq 'customer' ) {
  1537. $option .= $locale->text('Salesperson');
  1538. }
  1539. else {
  1540. $option .= $locale->text('Employee');
  1541. }
  1542. $option .= " : $employee";
  1543. }
  1544. if ( $form->{ordnumber} ) {
  1545. $option .= "\n<br>" if ($option);
  1546. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1547. }
  1548. if ( $form->{quonumber} ) {
  1549. $option .= "\n<br>" if ($option);
  1550. $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
  1551. }
  1552. if ( $form->{ponumber} ) {
  1553. $option = $locale->text('PO Number');
  1554. $option .= " : $form->{ponumber}";
  1555. }
  1556. if ( $form->{shipvia} ) {
  1557. $option .= "\n<br>" if ($option);
  1558. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1559. }
  1560. if ( $form->{description} ) {
  1561. $option .= "\n<br>" if $option;
  1562. $option .= $locale->text('Description') . " : $form->{description}";
  1563. }
  1564. if ( $form->{transdatefrom} ) {
  1565. $option .= "\n<br>"
  1566. . $locale->text('From') . " "
  1567. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1568. }
  1569. if ( $form->{transdateto} ) {
  1570. $option .= "\n<br>"
  1571. . $locale->text('To') . " "
  1572. . $locale->date( \%myconfig, $form->{transdateto}, 1 );
  1573. }
  1574. if ( $form->{open} ) {
  1575. $option .= "\n<br>" if ($option);
  1576. $option .= $locale->text('Open');
  1577. }
  1578. if ( $form->{closed} ) {
  1579. $option .= "\n<br>" if ($option);
  1580. $option .= $locale->text('Closed');
  1581. }
  1582. $form->header;
  1583. print qq|
  1584. <body>
  1585. <form method="post" action="$form->{script}">
  1586. <table width="100%">
  1587. <tr>
  1588. <th class="listtop">$form->{title}</th>
  1589. </tr>
  1590. <tr height="5"></tr>
  1591. <tr>
  1592. <td>$option</td>
  1593. </tr>
  1594. <tr>
  1595. <td>
  1596. <table width="100%">
  1597. <tr class="listheading">|;
  1598. for (@column_index) { print "\n$column_header{$_}" }
  1599. print qq|
  1600. </tr>
  1601. |;
  1602. # add sort and escape callback
  1603. $callback .= "&sort=$form->{sort}";
  1604. $form->{callback} = $callback;
  1605. $callback = $form->escape($callback);
  1606. # flip direction
  1607. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1608. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1609. if ( @{ $form->{OE} } ) {
  1610. $sameitem = $form->{OE}->[0]->{ $form->{sort} };
  1611. }
  1612. $action = "edit";
  1613. $action = "ship_receive" if ( $form->{type} =~ /(ship|receive)_order/ );
  1614. $warehouse = $form->escape( $form->{warehouse} );
  1615. $i = 0;
  1616. foreach $oe ( @{ $form->{OE} } ) {
  1617. $i++;
  1618. if ( $form->{l_subtotal} eq 'Y' ) {
  1619. if ( $sameitem ne $oe->{ $form->{sort} } ) {
  1620. &subtotal;
  1621. $sameitem = $oe->{ $form->{sort} };
  1622. }
  1623. }
  1624. if ( $form->{l_curr} ) {
  1625. for (qw(netamount amount)) { $oe->{"fx_$_"} = $oe->{$_} }
  1626. $oe->{fx_tax} = $oe->{fx_amount} - $oe->{fx_netamount};
  1627. for (qw(netamount amount)) { $oe->{$_} *= $oe->{exchangerate} }
  1628. for (qw(netamount amount)) {
  1629. $column_data{"fx_$_"} = '<td align="right">'
  1630. . $form->format_amount( \%myconfig, $oe->{"fx_$_"}, 2,
  1631. "&nbsp;" )
  1632. . "</td>";
  1633. }
  1634. $column_data{fx_tax} = '<td align="right">'
  1635. . $form->format_amount( \%myconfig,
  1636. $oe->{fx_amount} - $oe->{fx_netamount},
  1637. 2, "&nbsp;" )
  1638. . "</td>";
  1639. $totalfxnetamount += $oe->{fx_netamount};
  1640. $totalfxamount += $oe->{fx_amount};
  1641. $subtotalfxnetamount += $oe->{fx_netamount};
  1642. $subtotalfxamount += $oe->{fx_amount};
  1643. }
  1644. for (qw(netamount amount)) {
  1645. $column_data{$_} =
  1646. '<td align="right">'
  1647. . $form->format_amount( \%myconfig, $oe->{$_}, 2, "&nbsp;" )
  1648. . '</td>';
  1649. }
  1650. $column_data{tax} = '<td align="right">'
  1651. . $form->format_amount( \%myconfig, $oe->{amount} - $oe->{netamount},
  1652. 2, "&nbsp;" )
  1653. . "</td>";
  1654. $totalnetamount += $oe->{netamount};
  1655. $totalamount += $oe->{amount};
  1656. $subtotalnetamount += $oe->{netamount};
  1657. $subtotalamount += $oe->{amount};
  1658. $column_data{id} = "<td>$oe->{id}</td>";
  1659. $column_data{transdate} = "<td>$oe->{transdate}&nbsp;</td>";
  1660. $column_data{reqdate} = "<td>$oe->{reqdate}&nbsp;</td>";
  1661. $column_data{runningnumber} = qq|<td align="right">$i</td>|;
  1662. $column_data{ndx} =
  1663. qq|<td><input name="ndx_$i" class="checkbox" type="checkbox" value="$oe->{id}" checked></td>|;
  1664. $column_data{$ordnumber} =
  1665. qq|<td><a href="$form->{script}?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$oe->{$ordnumber}</a></td>|;
  1666. $name = $form->escape( $oe->{name} );
  1667. $column_data{name} =
  1668. qq|<td><a href="ct.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=edit&id=$oe->{"$form->{vc}_id"}&db=$form->{vc}&callback=$callback">$oe->{name}</a></td>|;
  1669. for (qw(employee manager shipvia curr ponumber)) {
  1670. $column_data{$_} = "<td>$oe->{$_}&nbsp;</td>";
  1671. }
  1672. if ( $oe->{closed} ) {
  1673. $column_data{closed} = '<td align="center">*</td>';
  1674. $column_data{open} = "<td>&nbsp;</td>";
  1675. }
  1676. else {
  1677. $column_data{closed} = "<td>&nbsp;</td>";
  1678. $column_data{open} = '<td align="center">*</td>';
  1679. }
  1680. $j++;
  1681. $j %= 2;
  1682. print qq|
  1683. <tr class="listrow$j">|;
  1684. for (@column_index) { print "\n$column_data{$_}" }
  1685. print qq|
  1686. </tr>
  1687. |;
  1688. }
  1689. if ( $form->{l_subtotal} eq 'Y' ) {
  1690. &subtotal;
  1691. }
  1692. # print totals
  1693. print qq|
  1694. <tr class="listtotal">|;
  1695. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1696. $column_data{netamount} =
  1697. '<th class="listtotal" align="right">'
  1698. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1699. . "</th>";
  1700. $column_data{tax} = '<th class="listtotal" align="right">'
  1701. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1702. 2, "&nbsp;" )
  1703. . "</th>";
  1704. $column_data{amount} =
  1705. '<th class="listtotal" align="right">'
  1706. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1707. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1708. $column_data{fx_netamount} =
  1709. '<th class="listtotal" align="right">'
  1710. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1711. . "</th>";
  1712. $column_data{fx_tax} = '<th class="listtotal" align="right">'
  1713. . $form->format_amount( \%myconfig,
  1714. $totalfxamount - $totalfxnetamount,
  1715. 2, "&nbsp;" )
  1716. . "</th>";
  1717. $column_data{fx_amount} =
  1718. '<th class="listtotal" align="right">'
  1719. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1720. . "</th>";
  1721. }
  1722. for (@column_index) { print "\n$column_data{$_}" }
  1723. print qq|
  1724. </tr>
  1725. </td>
  1726. </table>
  1727. </tr>
  1728. <tr>
  1729. <td><hr size="3" noshade></td>
  1730. </tr>
  1731. </table>
  1732. <br>
  1733. |;
  1734. $form->hide_form(
  1735. qw(callback type vc path login sessionid department ordnumber ponumber shipvia)
  1736. );
  1737. print qq|
  1738. <input type="hidden" name="rowcount" value="$i">
  1739. <input type="hidden" name="$form->{vc}" value="$form->{$form->{vc}}">
  1740. <input type="hidden" name="$form->{vc}_id" value="$form->{"$form->{vc}_id"}">
  1741. |;
  1742. if ( $form->{type} !~ /(ship|receive)_order/ ) {
  1743. for ( sort { $a->{order} <=> $b->{order} } %button ) {
  1744. print $_->{code};
  1745. }
  1746. }
  1747. if ( $form->{lynx} ) {
  1748. require "bin/menu.pl";
  1749. &menubar;
  1750. }
  1751. print qq|
  1752. </form>
  1753. </body>
  1754. </html>
  1755. |;
  1756. }
  1757. sub subtotal {
  1758. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1759. $column_data{netamount} =
  1760. '<th class="listsubtotal" align="right">'
  1761. . $form->format_amount( \%myconfig, $subtotalnetamount, 2, "&nbsp;" )
  1762. . "</th>";
  1763. $column_data{tax} = '<td class="listsubtotal" align="right">'
  1764. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1765. 2, "&nbsp;" )
  1766. . "</th>";
  1767. $column_data{amount} =
  1768. '<th class="listsubtotal" align="right">'
  1769. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1770. . "</th>";
  1771. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1772. $column_data{fx_netamount} =
  1773. '<th class="listsubtotal" align="right">'
  1774. . $form->format_amount( \%myconfig, $subtotalfxnetamount, 2,
  1775. "&nbsp;" )
  1776. . "</th>";
  1777. $column_data{fx_tax} = '<td class="listsubtotal" align="right">'
  1778. . $form->format_amount( \%myconfig,
  1779. $subtotalfxamount - $subtotalfxnetamount,
  1780. 2, "&nbsp;" )
  1781. . "</th>";
  1782. $column_data{fx_amount} =
  1783. '<th class="listsubtotal" align="right">'
  1784. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1785. . "</th>";
  1786. }
  1787. $subtotalnetamount = 0;
  1788. $subtotalamount = 0;
  1789. $subtotalfxnetamount = 0;
  1790. $subtotalfxamount = 0;
  1791. print '
  1792. <tr class="listsubtotal">
  1793. ';
  1794. for (@column_index) { print "\n$column_data{$_}" }
  1795. print qq|
  1796. </tr>
  1797. |;
  1798. }
  1799. sub save {
  1800. if ( $form->{type} =~ /_order$/ ) {
  1801. $msg = $locale->text('Order Date missing!');
  1802. }
  1803. else {
  1804. $msg = $locale->text('Quotation Date missing!');
  1805. }
  1806. $form->isblank( "transdate", $msg );
  1807. $msg = ucfirst $form->{vc};
  1808. $form->isblank( $form->{vc}, $locale->text( $msg . " missing!" ) );
  1809. # $locale->text('Customer missing!');
  1810. # $locale->text('Vendor missing!');
  1811. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
  1812. if ( $form->{currency} ne $form->{defaultcurrency} );
  1813. &validate_items;
  1814. # if the name changed get new values
  1815. if ( &check_name( $form->{vc} ) ) {
  1816. &update;
  1817. exit;
  1818. }
  1819. # this is for the internal notes section for the [email] Subject
  1820. if ( $form->{type} =~ /_order$/ ) {
  1821. if ( $form->{type} eq 'sales_order' ) {
  1822. $form->{label} = $locale->text('Sales Order');
  1823. $numberfld = "sonumber";
  1824. $ordnumber = "ordnumber";
  1825. }
  1826. else {
  1827. $form->{label} = $locale->text('Purchase Order');
  1828. $numberfld = "ponumber";
  1829. $ordnumber = "ordnumber";
  1830. }
  1831. $err = $locale->text('Cannot save order!');
  1832. }
  1833. else {
  1834. if ( $form->{type} eq 'sales_quotation' ) {
  1835. $form->{label} = $locale->text('Quotation');
  1836. $numberfld = "sqnumber";
  1837. $ordnumber = "quonumber";
  1838. }
  1839. else {
  1840. $form->{label} = $locale->text('Request for Quotation');
  1841. $numberfld = "rfqnumber";
  1842. $ordnumber = "quonumber";
  1843. }
  1844. $err = $locale->text('Cannot save quotation!');
  1845. }
  1846. if ( !$form->{repost} ) {
  1847. if ( $form->{id} ) {
  1848. &repost("Save");
  1849. exit;
  1850. }
  1851. }
  1852. if ( OE->save( \%myconfig, \%$form ) ) {
  1853. $form->redirect( $locale->text('Order saved!') );
  1854. }
  1855. else {
  1856. $form->error($err);
  1857. }
  1858. }
  1859. sub print_and_save {
  1860. $form->error( $locale->text('Select postscript or PDF!') )
  1861. if $form->{format} !~ /(postscript|pdf)/;
  1862. $form->error( $locale->text('Select a Printer!') )
  1863. if $form->{media} eq 'screen';
  1864. $old_form = new Form;
  1865. $form->{display_form} = "save";
  1866. for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
  1867. $old_form->{rowcount}++;
  1868. &print_form($old_form);
  1869. }
  1870. sub delete {
  1871. $form->header;
  1872. if ( $form->{type} =~ /_order$/ ) {
  1873. $msg = $locale->text('Are you sure you want to delete Order Number');
  1874. $ordnumber = 'ordnumber';
  1875. }
  1876. else {
  1877. $msg =
  1878. $locale->text('Are you sure you want to delete Quotation Number');
  1879. $ordnumber = 'quonumber';
  1880. }
  1881. print qq|
  1882. <body>
  1883. <form method="post" action="$form->{script}">
  1884. |;
  1885. $form->{action} = "yes";
  1886. $form->hide_form;
  1887. print qq|
  1888. <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
  1889. <h4>$msg $form->{$ordnumber}</h4>
  1890. <p>
  1891. <button name="action" class="submit" type="submit" value="yes">|
  1892. . $locale->text('Yes')
  1893. . qq|</button>
  1894. </form>
  1895. </body>
  1896. </html>
  1897. |;
  1898. }
  1899. sub yes {
  1900. if ( $form->{type} =~ /_order$/ ) {
  1901. $msg = $locale->text('Order deleted!');
  1902. $err = $locale->text('Cannot delete order!');
  1903. }
  1904. else {
  1905. $msg = $locale->text('Quotation deleted!');
  1906. $err = $locale->text('Cannot delete quotation!');
  1907. }
  1908. if ( OE->delete( \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool} ) ) {
  1909. $form->redirect($msg);
  1910. }
  1911. else {
  1912. $form->error($err);
  1913. }
  1914. }
  1915. sub vendor_invoice { &invoice }
  1916. sub sales_invoice { &invoice }
  1917. sub invoice {
  1918. if ( $form->{type} =~ /_order$/ ) {
  1919. $form->isblank( "ordnumber", $locale->text('Order Number missing!') );
  1920. $form->isblank( "transdate", $locale->text('Order Date missing!') );
  1921. }
  1922. else {
  1923. $form->isblank( "quonumber",
  1924. $locale->text('Quotation Number missing!') );
  1925. $form->isblank( "transdate", $locale->text('Quotation Date missing!') );
  1926. $form->{ordnumber} = "";
  1927. }
  1928. # if the name changed get new values
  1929. if ( &check_name( $form->{vc} ) ) {
  1930. &update;
  1931. exit;
  1932. }
  1933. if ( $form->{type} =~ /_order/
  1934. && $form->{currency} ne $form->{defaultcurrency} )
  1935. {
  1936. # check if we need a new exchangerate
  1937. $buysell = ( $form->{type} eq 'sales_order' ) ? "buy" : "sell";
  1938. $orddate = $form->current_date( \%myconfig );
  1939. $exchangerate =
  1940. $form->check_exchangerate( \%myconfig, $form->{currency}, $orddate,
  1941. $buysell );
  1942. if ( !$exchangerate ) {
  1943. &backorder_exchangerate( $orddate, $buysell );
  1944. exit;
  1945. }
  1946. }
  1947. # close orders/quotations
  1948. $form->{closed} = 1;
  1949. OE->save( \%myconfig, \%$form );
  1950. $form->{transdate} = $form->current_date( \%myconfig );
  1951. $form->{duedate} =
  1952. $form->current_date( \%myconfig, $form->{transdate}, $form->{terms} * 1 );
  1953. $form->{id} = '';
  1954. $form->{closed} = 0;
  1955. $form->{rowcount}--;
  1956. $form->{shipto} = 1;
  1957. if ( $form->{type} =~ /_order$/ ) {
  1958. $form->{exchangerate} = $exchangerate;
  1959. &create_backorder;
  1960. }
  1961. if ( $form->{type} eq 'purchase_order'
  1962. || $form->{type} eq 'request_quotation' )
  1963. {
  1964. $form->{title} = $locale->text('Add Vendor Invoice');
  1965. $form->{script} = 'ir.pl';
  1966. $script = "ir";
  1967. $buysell = 'sell';
  1968. }
  1969. if ( $form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation' )
  1970. {
  1971. $form->{title} = $locale->text('Add Sales Invoice');
  1972. $form->{script} = 'is.pl';
  1973. $script = "is";
  1974. $buysell = 'buy';
  1975. }
  1976. for (qw(id subject message printed emailed queued)) { delete $form->{$_} }
  1977. $form->{ $form->{vc} } =~ s/--.*//g;
  1978. $form->{type} = "invoice";
  1979. # locale messages
  1980. $locale = LedgerSMB::Locale->get_handle( $myconfig{countrycode} )
  1981. or $form->error("Locale not loaded: $!\n");
  1982. #$form->{charset} = $locale->encoding;
  1983. $form->{charset} = 'UTF-8';
  1984. $locale->encoding('UTF-8');
  1985. require "bin/$form->{script}";
  1986. # customized scripts
  1987. if ( -f "bin/custom/$form->{script}" ) {
  1988. eval { require "bin/custom/$form->{script}"; };
  1989. }
  1990. # customized scripts for login
  1991. if ( -f "bin/custom/$form->{login}_$form->{script}" ) {
  1992. eval { require "bin/custom/$form->{login}_$form->{script}"; };
  1993. }
  1994. for ( "$form->{vc}", "currency" ) { $form->{"select$_"} = "" }
  1995. for (
  1996. qw(currency oldcurrency employee department intnotes notes taxincluded))
  1997. {
  1998. $temp{$_} = $form->{$_};
  1999. }
  2000. &invoice_links;
  2001. $form->{creditremaining} -= ( $form->{oldinvtotal} - $form->{ordtotal} );
  2002. &prepare_invoice;
  2003. for ( keys %temp ) { $form->{$_} = $temp{$_} }
  2004. $form->{exchangerate} = "";
  2005. $form->{forex} = "";
  2006. $form->{exchangerate} = $exchangerate
  2007. if (
  2008. $form->{forex} = (
  2009. $exchangerate = $form->check_exchangerate(
  2010. \%myconfig, $form->{currency}, $form->{transdate}, $buysell
  2011. )
  2012. )
  2013. );
  2014. for $i ( 1 .. $form->{rowcount} ) {
  2015. $form->{"deliverydate_$i"} = $form->{"reqdate_$i"};
  2016. for (qw(qty sellprice discount)) {
  2017. $form->{"${_}_$i"} =
  2018. $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
  2019. }
  2020. }
  2021. for (qw(id subject message printed emailed queued audittrail)) {
  2022. delete $form->{$_};
  2023. }
  2024. &display_form;
  2025. }
  2026. sub backorder_exchangerate {
  2027. my ( $orddate, $buysell ) = @_;
  2028. $form->header;
  2029. print qq|
  2030. <body>
  2031. <form method="post" action="$form->{script}">
  2032. |;
  2033. # delete action variable
  2034. for (qw(action nextsub exchangerate)) { delete $form->{$_} }
  2035. $form->hide_form;
  2036. $form->{title} = $locale->text('Add Exchange Rate');
  2037. print qq|
  2038. <input type="hidden" name="exchangeratedate" value="$orddate">
  2039. <input type="hidden" name="buysell" value="$buysell">
  2040. <table width="100%">
  2041. <tr><th class="listtop">$form->{title}</th></tr>
  2042. <tr height="5"></tr>
  2043. <tr>
  2044. <td>
  2045. <table>
  2046. <tr>
  2047. <th align="right">| . $locale->text('Currency') . qq|</th>
  2048. <td>$form->{currency}</td>
  2049. </tr>
  2050. <tr>
  2051. <th align="right">| . $locale->text('Date') . qq|</th>
  2052. <td>$orddate</td>
  2053. </tr>
  2054. <tr>
  2055. <th align="right">| . $locale->text('Exchange Rate') . qq|</th>
  2056. <td><input name="exchangerate" size="11"></td>
  2057. </tr>
  2058. </table>
  2059. </td>
  2060. </tr>
  2061. </table>
  2062. <hr size="3" noshade>
  2063. <br>
  2064. <input type="hidden" name="nextsub" value="save_exchangerate">
  2065. <button name="action" class="submit" type="submit" value="continue">|
  2066. . $locale->text('Continue')
  2067. . qq|</button>
  2068. </form>
  2069. </body>
  2070. </html>
  2071. |;
  2072. }
  2073. sub save_exchangerate {
  2074. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') );
  2075. $form->{exchangerate} =
  2076. $form->parse_amount( \%myconfig, $form->{exchangerate} );
  2077. $form->save_exchangerate( \%myconfig, $form->{currency},
  2078. $form->{exchangeratedate},
  2079. $form->{exchangerate}, $form->{buysell} );
  2080. &invoice;
  2081. }
  2082. sub create_backorder {
  2083. $form->{shipped} = 1;
  2084. # figure out if we need to create a backorder
  2085. # items aren't saved if qty != 0
  2086. $dec1 = $dec2 = 0;
  2087. for $i ( 1 .. $form->{rowcount} ) {
  2088. ($dec) = ( $form->{"qty_$i"} =~ /\.(\d+)/ );
  2089. $dec = length $dec;
  2090. $dec1 = ( $dec > $dec1 ) ? $dec : $dec1;
  2091. ($dec) = ( $form->{"ship_$i"} =~ /\.(\d+)/ );
  2092. $dec = length $dec;
  2093. $dec2 = ( $dec > $dec2 ) ? $dec : $dec2;
  2094. $totalqty += $qty = $form->{"qty_$i"};
  2095. $totalship += $ship = $form->{"ship_$i"};
  2096. $form->{"qty_$i"} = $qty - $ship;
  2097. }
  2098. $totalqty = $form->round_amount( $totalqty, $dec1 );
  2099. $totalship = $form->round_amount( $totalship, $dec2 );
  2100. if ( $totalship == 0 ) {
  2101. for ( 1 .. $form->{rowcount} ) {
  2102. $form->{"ship_$_"} = $form->{"qty_$_"};
  2103. }
  2104. $form->{ordtotal} = 0;
  2105. $form->{shipped} = 0;
  2106. return;
  2107. }
  2108. if ( $totalqty == $totalship ) {
  2109. for ( 1 .. $form->{rowcount} ) {
  2110. $form->{"qty_$_"} = $form->{"ship_$_"};
  2111. }
  2112. $form->{ordtotal} = 0;
  2113. return;
  2114. }
  2115. @flds =
  2116. qw(partnumber description qty ship unit sellprice discount oldqty orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand deliverydate reqdate projectnumber partsgroup assembly);
  2117. for $i ( 1 .. $form->{rowcount} ) {
  2118. for (qw(qty sellprice discount)) {
  2119. $form->{"${_}_$i"} =
  2120. $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
  2121. }
  2122. $form->{"oldship_$i"} = $form->{"ship_$i"};
  2123. $form->{"ship_$i"} = 0;
  2124. }
  2125. # clear flags
  2126. for (qw(id subject message cc bcc printed emailed queued audittrail)) {
  2127. delete $form->{$_};
  2128. }
  2129. OE->save( \%myconfig, \%$form );
  2130. # rebuild rows for invoice
  2131. @a = ();
  2132. $count = 0;
  2133. for $i ( 1 .. $form->{rowcount} ) {
  2134. $form->{"qty_$i"} = $form->{"oldship_$i"};
  2135. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  2136. $form->{"orderitems_id_$i"} = "";
  2137. if ( $form->{"qty_$i"} ) {
  2138. push @a, {};
  2139. $j = $#a;
  2140. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2141. $count++;
  2142. }
  2143. }
  2144. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  2145. $form->{rowcount} = $count;
  2146. }
  2147. sub save_as_new {
  2148. for (qw(closed id printed emailed queued)) { delete $form->{$_} }
  2149. &save;
  2150. }
  2151. sub print_and_save_as_new {
  2152. for (qw(closed id printed emailed queued)) { delete $form->{$_} }
  2153. &print_and_save;
  2154. }
  2155. sub ship_receive {
  2156. &order_links;
  2157. &prepare_order;
  2158. OE->get_warehouses( \%myconfig, \%$form );
  2159. # warehouse
  2160. if ( @{ $form->{all_warehouse} } ) {
  2161. $form->{selectwarehouse} = "<option>\n";
  2162. for ( @{ $form->{all_warehouse} } ) {
  2163. $form->{selectwarehouse} .=
  2164. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  2165. }
  2166. if ( $form->{warehouse} ) {
  2167. $form->{selectwarehouse} = qq|<option value="$form->{warehouse}">|;
  2168. $form->{warehouse} =~ s/--.*//;
  2169. $form->{selectwarehouse} .= $form->{warehouse};
  2170. }
  2171. }
  2172. $form->{shippingdate} = $form->current_date( \%myconfig );
  2173. $form->{"$form->{vc}"} =~ s/--.*//;
  2174. $form->{"old$form->{vc}"} =
  2175. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  2176. @flds = ();
  2177. @a = ();
  2178. $count = 0;
  2179. foreach $key ( keys %$form ) {
  2180. if ( $key =~ /_1$/ ) {
  2181. $key =~ s/_1//;
  2182. push @flds, $key;
  2183. }
  2184. }
  2185. for $i ( 1 .. $form->{rowcount} ) {
  2186. # undo formatting from prepare_order
  2187. for (qw(qty ship)) {
  2188. $form->{"${_}_$i"} =
  2189. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  2190. }
  2191. $n = ( $form->{"qty_$i"} -= $form->{"ship_$i"} );
  2192. if ( abs($n) > 0 ) {
  2193. $form->{"ship_$i"} = "";
  2194. $form->{"serialnumber_$i"} = "";
  2195. push @a, {};
  2196. $j = $#a;
  2197. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2198. $count++;
  2199. }
  2200. }
  2201. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  2202. $form->{rowcount} = $count;
  2203. &display_ship_receive;
  2204. }
  2205. sub display_ship_receive {
  2206. $vclabel = ucfirst $form->{vc};
  2207. $vclabel = $locale->text($vclabel);
  2208. $form->{rowcount}++;
  2209. if ( $form->{vc} eq 'customer' ) {
  2210. $form->{title} = $locale->text('Ship Merchandise');
  2211. $shipped = $locale->text('Shipping Date');
  2212. }
  2213. else {
  2214. $form->{title} = $locale->text('Receive Merchandise');
  2215. $shipped = $locale->text('Date Received');
  2216. }
  2217. # set option selected
  2218. for (qw(warehouse employee)) {
  2219. $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
  2220. $form->{"select$_"} =~ s/ selected//;
  2221. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  2222. }
  2223. $warehouse = qq|
  2224. <tr>
  2225. <th align="right">| . $locale->text('Warehouse') . qq|</th>
  2226. <td><select name="warehouse">$form->{selectwarehouse}</select></td>
  2227. <input type="hidden" name="selectwarehouse" value="|
  2228. . $form->escape( $form->{selectwarehouse}, 1 ) . qq|">
  2229. </tr>
  2230. | if $form->{selectwarehouse};
  2231. $employee = qq|
  2232. <tr>
  2233. <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
  2234. <td><select name="employee">$form->{selectemployee}</select></td>
  2235. <input type="hidden" name="selectemployee" value="|
  2236. . $form->escape( $form->{selectemployee}, 1 ) . qq|">
  2237. </tr>
  2238. |;
  2239. $form->header;
  2240. print qq|
  2241. <body>
  2242. <form method="post" action=$form->{script}>
  2243. <input type="hidden" name="display_form" value="display_ship_receive">
  2244. |;
  2245. $form->hide_form(qw(id type media format printed emailed queued vc));
  2246. print qq|
  2247. <input type="hidden" name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
  2248. <table width="100%">
  2249. <tr class="listtop">
  2250. <th class="listtop">$form->{title}</th>
  2251. </tr>
  2252. <tr height="5"></tr>
  2253. <tr>
  2254. <td>
  2255. <table width="100%">
  2256. <tr valign="top">
  2257. <td>
  2258. <table width="100%">
  2259. <tr>
  2260. <th align="right">$vclabel</th>
  2261. <td colspan="3">$form->{$form->{vc}}</td>
  2262. <input type="hidden" name="$form->{vc}" value="$form->{$form->{vc}}">
  2263. <input type="hidden" name="$form->{vc}_id" value="$form->{"$form->{vc}_id"}">
  2264. </tr>
  2265. $department
  2266. <tr>
  2267. <th align="right">| . $locale->text('Shipping Point') . qq|</th>
  2268. <td colspan="3">
  2269. <input name="shippingpoint" size="35" value="$form->{shippingpoint}">
  2270. </tr>
  2271. <tr>
  2272. <th align="right">| . $locale->text('Ship via') . qq|</th>
  2273. <td colspan="3">
  2274. <input name="shipvia" size="35" value="$form->{shipvia}">
  2275. </tr>
  2276. $warehouse
  2277. </table>
  2278. </td>
  2279. <td align="right">
  2280. <table>
  2281. $employee
  2282. <tr>
  2283. <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
  2284. <td>$form->{ordnumber}</td>
  2285. <input type="hidden" name="ordnumber" value="$form->{ordnumber}">
  2286. </tr>
  2287. <tr>
  2288. <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
  2289. <td>$form->{transdate}</td>
  2290. <input type="hidden" name="transdate" value="$form->{transdate}">
  2291. </tr>
  2292. <tr>
  2293. <th align="right" nowrap>| . $locale->text('PO Number') . qq|</th>
  2294. <td>$form->{ponumber}</td>
  2295. <input type="hidden" name="ponumber" value="$form->{ponumber}">
  2296. </tr>
  2297. <tr>
  2298. <th align="right" nowrap>$shipped</th>
  2299. <td><input name="shippingdate" size="11" value="$form->{shippingdate}"></td>
  2300. </tr>
  2301. </table>
  2302. </td>
  2303. </tr>
  2304. </table>
  2305. </td>
  2306. </tr>
  2307. |;
  2308. $form->hide_form(
  2309. qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc)
  2310. );
  2311. @column_index = qw(partnumber);
  2312. if ( $form->{type} eq "ship_order" ) {
  2313. $column_data{ship} =
  2314. qq|<th class="listheading">| . $locale->text('Ship') . qq|</th>|;
  2315. }
  2316. if ( $form->{type} eq "receive_order" ) {
  2317. $column_data{ship} =
  2318. qq|<th class="listheading">| . $locale->text('Recd') . qq|</th>|;
  2319. $column_data{sku} =
  2320. qq|<th class="listheading">| . $locale->text('SKU') . qq|</th>|;
  2321. push @column_index, "sku";
  2322. }
  2323. push @column_index, qw(description qty ship unit bin serialnumber);
  2324. my $colspan = $#column_index + 1;
  2325. $column_data{partnumber} =
  2326. qq|<th class="listheading" nowrap>| . $locale->text('Number') . qq|</th>|;
  2327. $column_data{description} =
  2328. qq|<th class="listheading" nowrap>|
  2329. . $locale->text('Description')
  2330. . qq|</th>|;
  2331. $column_data{qty} =
  2332. qq|<th class="listheading" nowrap>| . $locale->text('Qty') . qq|</th>|;
  2333. $column_data{unit} =
  2334. qq|<th class="listheading" nowrap>| . $locale->text('Unit') . qq|</th>|;
  2335. $column_data{bin} =
  2336. qq|<th class="listheading" nowrap>| . $locale->text('Bin') . qq|</th>|;
  2337. $column_data{serialnumber} =
  2338. qq|<th class="listheading" nowrap>|
  2339. . $locale->text('Serial No.')
  2340. . qq|</th>|;
  2341. print qq|
  2342. <tr>
  2343. <td>
  2344. <table width="100%">
  2345. <tr class="listheading">|;
  2346. for (@column_index) { print "\n$column_data{$_}" }
  2347. print qq|
  2348. </tr>
  2349. |;
  2350. for $i ( 1 .. $form->{rowcount} - 1 ) {
  2351. # undo formatting
  2352. $form->{"ship_$i"} =
  2353. $form->parse_amount( \%myconfig, $form->{"ship_$i"} );
  2354. for (qw(partnumber sku description unit bin serialnumber)) {
  2355. $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
  2356. }
  2357. $description = $form->{"description_$i"};
  2358. $description =~ s/\r?\n/<br>/g;
  2359. $column_data{partnumber} =
  2360. qq|<td>$form->{"partnumber_$i"}<input type="hidden" name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
  2361. $column_data{sku} =
  2362. qq|<td>$form->{"sku_$i"}<input type="hidden" name="sku_$i" value="$form->{"sku_$i"}"></td>|;
  2363. $column_data{description} =
  2364. qq|<td>$description<input type="hidden" name="description_$i" value="$form->{"description_$i"}"></td>|;
  2365. $column_data{qty} =
  2366. qq|<td align="right">|
  2367. . $form->format_amount( \%myconfig, $form->{"qty_$i"} )
  2368. . qq|<input type="hidden" name="qty_$i" value="$form->{"qty_$i"}"></td>|;
  2369. $column_data{ship} =
  2370. qq|<td align="right"><input name="ship_$i" size="5" value="|
  2371. . $form->format_amount( \%myconfig, $form->{"ship_$i"} )
  2372. . qq|"></td>|;
  2373. $column_data{unit} =
  2374. qq|<td>$form->{"unit_$i"}<input type="hidden" name="unit_$i" value="$form->{"unit_$i"}"></td>|;
  2375. $column_data{bin} =
  2376. qq|<td>$form->{"bin_$i"}<input type="hidden" name="bin_$i" value="$form->{"bin_$i"}"></td>|;
  2377. $column_data{serialnumber} =
  2378. qq|<td><input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}"></td>|;
  2379. print qq|
  2380. <tr valign="top">|;
  2381. for (@column_index) { print "\n$column_data{$_}" }
  2382. print qq|
  2383. </tr>
  2384. |;
  2385. $form->hide_form( "orderitems_id_$i", "id_$i", "partsgroup_$i" );
  2386. }
  2387. print qq|
  2388. </table>
  2389. </td>
  2390. </tr>
  2391. <tr>
  2392. <td><hr size="3" noshade></td>
  2393. </tr>
  2394. <tr>
  2395. <td>
  2396. |;
  2397. $form->{copies} = 1;
  2398. &print_options;
  2399. print qq|
  2400. </td>
  2401. </tr>
  2402. </table>
  2403. <br>
  2404. |;
  2405. # type="submit" $locale->text('Done')
  2406. %button = (
  2407. 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  2408. 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
  2409. 'ship_to' =>
  2410. { ndx => 4, key => 'T', value => $locale->text('Ship to') },
  2411. 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  2412. 'done' => { ndx => 11, key => 'D', value => $locale->text('Done') },
  2413. );
  2414. for ( "update", "print" ) { $form->print_button( \%button, $_ ) }
  2415. if ( $form->{type} eq 'ship_order' ) {
  2416. for ( 'ship_to', 'e_mail' ) { $form->print_button( \%button, $_ ) }
  2417. }
  2418. $form->print_button( \%button, 'done' );
  2419. if ( $form->{lynx} ) {
  2420. require "bin/menu.pl";
  2421. &menubar;
  2422. }
  2423. $form->hide_form(qw(rowcount callback path login sessionid));
  2424. print qq|
  2425. </form>
  2426. </body>
  2427. </html>
  2428. |;
  2429. }
  2430. sub done {
  2431. if ( $form->{type} eq 'ship_order' ) {
  2432. $form->isblank( "shippingdate",
  2433. $locale->text('Shipping Date missing!') );
  2434. }
  2435. else {
  2436. $form->isblank( "shippingdate",
  2437. $locale->text('Date received missing!') );
  2438. }
  2439. $total = 0;
  2440. for ( 1 .. $form->{rowcount} - 1 ) {
  2441. $total += $form->{"ship_$_"} =
  2442. $form->parse_amount( \%myconfig, $form->{"ship_$_"} );
  2443. }
  2444. $form->error( $locale->text('Nothing entered!') ) unless $total;
  2445. if ( OE->save_inventory( \%myconfig, \%$form ) ) {
  2446. $form->redirect( $locale->text('Inventory saved!') );
  2447. }
  2448. else {
  2449. $form->error( $locale->text('Could not save!') );
  2450. }
  2451. }
  2452. sub search_transfer {
  2453. OE->get_warehouses( \%myconfig, \%$form );
  2454. # warehouse
  2455. if ( @{ $form->{all_warehouse} } ) {
  2456. $form->{selectwarehouse} = "<option>\n";
  2457. $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|
  2458. if $form->{warehouse_id};
  2459. for ( @{ $form->{all_warehouse} } ) {
  2460. $form->{selectwarehouse} .=
  2461. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  2462. }
  2463. }
  2464. else {
  2465. $form->error( $locale->text('Nothing to transfer!') );
  2466. }
  2467. $form->get_partsgroup( \%myconfig, { searchitems => 'part' } );
  2468. if ( @{ $form->{all_partsgroup} } ) {
  2469. $form->{selectpartsgroup} = "<option>\n";
  2470. for ( @{ $form->{all_partsgroup} } ) {
  2471. $form->{selectpartsgroup} .=
  2472. qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|;
  2473. }
  2474. }
  2475. $form->{title} = $locale->text('Transfer Inventory');
  2476. $form->header;
  2477. print qq|
  2478. <body>
  2479. <form method="post" action="$form->{script}">
  2480. <table width="100%">
  2481. <tr>
  2482. <th class="listtop">$form->{title}</th>
  2483. </tr>
  2484. <tr height="5"></tr>
  2485. <tr>
  2486. <td>
  2487. <table>
  2488. <tr>
  2489. <th align="right" nowrap>| . $locale->text('Transfer from') . qq|</th>
  2490. <td><select name="fromwarehouse">$form->{selectwarehouse}</select></td>
  2491. </tr>
  2492. <tr>
  2493. <th align="right" nowrap>| . $locale->text('Transfer to') . qq|</th>
  2494. <td><select name="towarehouse">$form->{selectwarehouse}</select></td>
  2495. </tr>
  2496. <tr>
  2497. <th align="right" nowrap="true">| . $locale->text('Part Number') . qq|</th>
  2498. <td><input name="partnumber" size="20"></td>
  2499. </tr>
  2500. <tr>
  2501. <th align="right" nowrap="true">| . $locale->text('Description') . qq|</th>
  2502. <td><input name="description" size="40"></td>
  2503. </tr>
  2504. <tr>
  2505. <th align="right" nowrap>| . $locale->text('Group') . qq|</th>
  2506. <td><select name="partsgroup">$form->{selectpartsgroup}</select></td>
  2507. </tr>
  2508. </table>
  2509. </td>
  2510. </tr>
  2511. <tr>
  2512. <td><hr size="3" noshade></td>
  2513. </tr>
  2514. </table>
  2515. <br>
  2516. <input type="hidden" name="nextsub" value="list_transfer">
  2517. <button class="submit" type="submit" name="action" value="continue">|
  2518. . $locale->text('Continue')
  2519. . qq|</button>|;
  2520. $form->hide_form(qw(path login sessionid));
  2521. print qq|
  2522. </form>
  2523. |;
  2524. if ( $form->{lynx} ) {
  2525. require "bin/menu.pl";
  2526. &menubar;
  2527. }
  2528. print qq|
  2529. </body>
  2530. </html>
  2531. |;
  2532. }
  2533. sub list_transfer {
  2534. $form->{sort} = "partnumber" unless $form->{sort};
  2535. OE->get_inventory( \%myconfig, \%$form );
  2536. # construct href
  2537. $href = "$form->{script}?action=list_transfer";
  2538. for (qw(direction oldsort path login sessionid)) {
  2539. $href .= "&$_=$form->{$_}";
  2540. }
  2541. for (qw(partnumber fromwarehouse towarehouse description partsgroup)) {
  2542. $href .= "&$_=" . $form->escape( $form->{$_} );
  2543. }
  2544. $form->sort_order();
  2545. # construct callback
  2546. $callback = "$form->{script}?action=list_transfer";
  2547. for (qw(direction oldsort path login sessionid)) {
  2548. $callback .= "&$_=$form->{$_}";
  2549. }
  2550. for (qw(partnumber fromwarehouse towarehouse description partsgroup)) {
  2551. $callback .= "&$_=" . $form->escape( $form->{$_}, 1 );
  2552. }
  2553. @column_index =
  2554. $form->sort_columns(
  2555. qw(partnumber description partsgroup make model fromwarehouse qty towarehouse transfer)
  2556. );
  2557. $column_header{partnumber} =
  2558. qq|<th><a class="listheading" href="$href&sort=partnumber">|
  2559. . $locale->text('Part Number')
  2560. . qq|</a></th>|;
  2561. $column_header{description} =
  2562. qq|<th><a class="listheading" href="$href&sort=description">|
  2563. . $locale->text('Description')
  2564. . qq|</a></th>|;
  2565. $column_header{partsgroup} =
  2566. qq|<th><a class="listheading" href="$href&sort=partsgroup">|
  2567. . $locale->text('Group')
  2568. . qq|</a></th>|;
  2569. $column_header{fromwarehouse} =
  2570. qq|<th><a class="listheading" href="$href&sort=warehouse">|
  2571. . $locale->text('From')
  2572. . qq|</a></th>|;
  2573. $column_header{towarehouse} =
  2574. qq|<th class="listheading">| . $locale->text('To') . qq|</th>|;
  2575. $column_header{qty} =
  2576. qq|<th class="listheading">| . $locale->text('Qty') . qq|</a></th>|;
  2577. $column_header{transfer} =
  2578. qq|<th class="listheading">| . $locale->text('Transfer') . qq|</a></th>|;
  2579. ( $warehouse, $warehouse_id ) = split /--/, $form->{fromwarehouse};
  2580. if ( $form->{fromwarehouse} ) {
  2581. $option .= "\n<br>";
  2582. $option .= $locale->text('From Warehouse') . " : $warehouse";
  2583. }
  2584. ( $warehouse, $warehouse_id ) = split /--/, $form->{towarehouse};
  2585. if ( $form->{towarehouse} ) {
  2586. $option .= "\n<br>";
  2587. $option .= $locale->text('To Warehouse') . " : $warehouse";
  2588. }
  2589. if ( $form->{partnumber} ) {
  2590. $option .= "\n<br>" if ($option);
  2591. $option .= $locale->text('Part Number') . " : $form->{partnumber}";
  2592. }
  2593. if ( $form->{description} ) {
  2594. $option .= "\n<br>" if ($option);
  2595. $option .= $locale->text('Description') . " : $form->{description}";
  2596. }
  2597. if ( $form->{partsgroup} ) {
  2598. ($partsgroup) = split /--/, $form->{partsgroup};
  2599. $option .= "\n<br>" if ($option);
  2600. $option .= $locale->text('Group') . " : $partsgroup";
  2601. }
  2602. $form->{title} = $locale->text('Transfer Inventory');
  2603. $callback .= "&sort=$form->{sort}";
  2604. $form->header;
  2605. print qq|
  2606. <body>
  2607. <form method="post" action="$form->{script}">
  2608. <input type="hidden" name="warehouse_id" value="$warehouse_id">
  2609. <table width="100%">
  2610. <tr>
  2611. <th class="listtop">$form->{title}</th>
  2612. </tr>
  2613. <tr height="5"></tr>
  2614. <tr>
  2615. <td>$option</td>
  2616. </tr>
  2617. <tr>
  2618. <td>
  2619. <table width="100%">
  2620. <tr class="listheading">|;
  2621. for (@column_index) { print "\n$column_header{$_}" }
  2622. print qq|
  2623. </tr>
  2624. |;
  2625. if ( @{ $form->{all_inventory} } ) {
  2626. $sameitem = $form->{all_inventory}->[0]->{ $form->{sort} };
  2627. }
  2628. $i = 0;
  2629. foreach $ref ( @{ $form->{all_inventory} } ) {
  2630. $i++;
  2631. $column_data{partnumber} =
  2632. qq|<td><input type="hidden" name="id_$i" value="$ref->{id}">$ref->{partnumber}</td>|;
  2633. $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
  2634. $column_data{partsgroup} = "<td>$ref->{partsgroup}&nbsp;</td>";
  2635. $column_data{fromwarehouse} =
  2636. qq|<td><input type="hidden" name="warehouse_id_$i" value="$ref->{warehouse_id}">$ref->{warehouse}&nbsp;</td>|;
  2637. $column_data{towarehouse} = qq|<td>$warehouse&nbsp;</td>|;
  2638. $column_data{qty} =
  2639. qq|<td><input type="hidden" name="qty_$i" value="$ref->{qty}">|
  2640. . $form->format_amount( \%myconfig, $ref->{qty} )
  2641. . qq|</td>|;
  2642. $column_data{transfer} = qq|<td><input name="transfer_$i" size="4"></td>|;
  2643. $j++;
  2644. $j %= 2;
  2645. print qq|
  2646. <tr class="listrow$j">|;
  2647. for (@column_index) { print "\n$column_data{$_}" }
  2648. print qq|
  2649. </tr>
  2650. |;
  2651. }
  2652. print qq|
  2653. </table>
  2654. </td>
  2655. </tr>
  2656. <tr>
  2657. <td><hr size="3" noshade></td>
  2658. </tr>
  2659. </table>
  2660. <br>
  2661. <input name="callback" type="hidden" value="$callback">
  2662. <input type="hidden" name="rowcount" value="$i">
  2663. |;
  2664. $form->{action} = "transfer";
  2665. $form->hide_form(qw(path login sessionid action));
  2666. print qq|
  2667. <button class="submit" type="submit" name="action" value="transfer">|
  2668. . $locale->text('Transfer')
  2669. . qq|</button>|;
  2670. if ( $form->{lynx} ) {
  2671. require "bin/menu.pl";
  2672. &menubar;
  2673. }
  2674. print qq|
  2675. </form>
  2676. </body>
  2677. </html>
  2678. |;
  2679. }
  2680. sub transfer {
  2681. if ( OE->transfer( \%myconfig, \%$form ) ) {
  2682. $form->redirect( $locale->text('Inventory transferred!') );
  2683. }
  2684. else {
  2685. $form->error( $locale->text('Could not transfer Inventory!') );
  2686. }
  2687. }
  2688. sub generate_purchase_orders {
  2689. for ( 1 .. $form->{rowcount} ) {
  2690. if ( $form->{"ndx_$_"} ) {
  2691. $ok = 1;
  2692. last;
  2693. }
  2694. }
  2695. $form->error( $locale->text('Nothing selected!') ) unless $ok;
  2696. ( $null, $argv ) = split /\?/, $form->{callback};
  2697. for ( split /\&/, $argv ) {
  2698. ( $key, $value ) = split /=/, $_;
  2699. $form->{$key} = $value;
  2700. }
  2701. $form->{vc} = "vendor";
  2702. OE->get_soparts( \%myconfig, \%$form );
  2703. # flatten array
  2704. $i = 0;
  2705. foreach $parts_id (
  2706. sort {
  2707. $form->{orderitems}{$a}{partnumber}
  2708. cmp $form->{orderitems}{$b}{partnumber}
  2709. } keys %{ $form->{orderitems} }
  2710. )
  2711. {
  2712. $required = $form->{orderitems}{$parts_id}{required};
  2713. next if $required <= 0;
  2714. $i++;
  2715. $form->{"required_$i"} = $form->format_amount( \%myconfig, $required );
  2716. $form->{"id_$i"} = $parts_id;
  2717. $form->{"sku_$i"} = $form->{orderitems}{$parts_id}{partnumber};
  2718. $form->{"curr_$i"} = $form->{defaultcurrency};
  2719. $form->{"description_$i"} = $form->{orderitems}{$parts_id}{description};
  2720. $form->{"lastcost_$i"} =
  2721. $form->format_amount( \%myconfig,
  2722. $form->{orderitems}{$parts_id}{lastcost}, 2 );
  2723. $form->{"qty_$i"} = $required;
  2724. if ( exists $form->{orderitems}{$parts_id}{"parts$form->{vc}"} ) {
  2725. $form->{"qty_$i"} = "";
  2726. foreach $id (
  2727. sort {
  2728. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$a}
  2729. {lastcost} * $form->{ $form->{orderitems}{$parts_id}
  2730. {"parts$form->{vc}"}{$a}{curr} } <=>
  2731. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$b}
  2732. {lastcost} * $form->{ $form->{orderitems}{$parts_id}
  2733. {"parts$form->{vc}"}{$b}{curr} }
  2734. } keys %{ $form->{orderitems}{$parts_id}{"parts$form->{vc}"} }
  2735. )
  2736. {
  2737. $i++;
  2738. $form->{"qty_$i"} =
  2739. $form->format_amount( \%myconfig, $required );
  2740. $form->{"description_$i"} = "";
  2741. for (qw(partnumber curr)) {
  2742. $form->{"${_}_$i"} =
  2743. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2744. {$_};
  2745. }
  2746. $form->{"lastcost_$i"} = $form->format_amount(
  2747. \%myconfig,
  2748. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2749. {lastcost},
  2750. 2
  2751. );
  2752. $form->{"leadtime_$i"} = $form->format_amount( \%myconfig,
  2753. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2754. {leadtime} );
  2755. $form->{"fx_$i"} = $form->format_amount(
  2756. \%myconfig,
  2757. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2758. {lastcost} * $form->{
  2759. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2760. {curr}
  2761. },
  2762. 2
  2763. );
  2764. $form->{"id_$i"} = $parts_id;
  2765. $form->{"$form->{vc}_$i"} =
  2766. qq|$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{name}--$id|;
  2767. $form->{"$form->{vc}_id_$i"} = $id;
  2768. $required = "";
  2769. }
  2770. }
  2771. $form->{"blankrow_$i"} = 1;
  2772. }
  2773. $form->{rowcount} = $i;
  2774. &po_orderitems;
  2775. }
  2776. sub po_orderitems {
  2777. @column_index =
  2778. qw(sku description partnumber leadtime fx lastcost curr required qty name);
  2779. $column_header{sku} =
  2780. qq|<th class="listheading">| . $locale->text('SKU') . qq|</th>|;
  2781. $column_header{partnumber} =
  2782. qq|<th class="listheading">| . $locale->text('Part Number') . qq|</th>|;
  2783. $column_header{description} =
  2784. qq|<th class="listheading">| . $locale->text('Description') . qq|</th>|;
  2785. $column_header{name} =
  2786. qq|<th class="listheading">| . $locale->text('Vendor') . qq|</th>|;
  2787. $column_header{qty} =
  2788. qq|<th class="listheading">| . $locale->text('Order') . qq|</th>|;
  2789. $column_header{required} =
  2790. qq|<th class="listheading">| . $locale->text('Req') . qq|</th>|;
  2791. $column_header{lastcost} =
  2792. qq|<th class="listheading">| . $locale->text('Cost') . qq|</th>|;
  2793. $column_header{fx} = qq|<th class="listheading">&nbsp;</th>|;
  2794. $column_header{leadtime} =
  2795. qq|<th class="listheading">| . $locale->text('Lead') . qq|</th>|;
  2796. $column_header{curr} =
  2797. qq|<th class="listheading">| . $locale->text('Curr') . qq|</th>|;
  2798. $form->{title} = $locale->text('Generate Purchase Orders');
  2799. $form->header;
  2800. print qq|
  2801. <body>
  2802. <form method="post" action="$form->{script}">
  2803. <table width="100%">
  2804. <tr>
  2805. <th class="listtop">$form->{title}</th>
  2806. </tr>
  2807. <tr height="5"></tr>
  2808. <tr>
  2809. <td>
  2810. <table width="100%">
  2811. <tr class="listheading">|;
  2812. for (@column_index) { print "\n$column_header{$_}" }
  2813. print qq|
  2814. </tr>
  2815. |;
  2816. for $i ( 1 .. $form->{rowcount} ) {
  2817. for (qw(sku partnumber description curr)) {
  2818. $column_data{$_} = qq|<td>$form->{"${_}_$i"}&nbsp;</td>|;
  2819. }
  2820. for (qw(required leadtime lastcost fx)) {
  2821. $column_data{$_} = qq|<td align="right">$form->{"${_}_$i"}</td>|;
  2822. }
  2823. $column_data{qty} =
  2824. qq|<td align="right"><input name="qty_$i" size="6" value="$form->{"qty_$i"}"></td>|;
  2825. if ( $form->{"$form->{vc}_id_$i"} ) {
  2826. $name = $form->{"$form->{vc}_$i"};
  2827. $name =~ s/--.*//;
  2828. $column_data{name} = qq|<td>$name</td>|;
  2829. $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" );
  2830. }
  2831. else {
  2832. $column_data{name} =
  2833. qq|<td><input name="ndx_$i" class="checkbox" type="checkbox" value="1"></td>|;
  2834. }
  2835. $form->hide_form( map { "${_}_$i" }
  2836. qw(id sku partnumber description curr required leadtime lastcost fx name blankrow)
  2837. );
  2838. $blankrow = $form->{"blankrow_$i"};
  2839. BLANKROW:
  2840. $j++;
  2841. $j %= 2;
  2842. print "
  2843. <tr class=listrow$j>";
  2844. for (@column_index) { print "\n$column_data{$_}" }
  2845. print qq|
  2846. </tr>
  2847. |;
  2848. if ($blankrow) {
  2849. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2850. $blankrow = 0;
  2851. goto BLANKROW;
  2852. }
  2853. }
  2854. print qq|
  2855. </table>
  2856. </td>
  2857. </tr>
  2858. <tr>
  2859. <td><hr size="3" noshade></td>
  2860. </tr>
  2861. </table>
  2862. <br>
  2863. |;
  2864. $form->hide_form(
  2865. qw(callback department ponumber path login sessionid employee_id vc nextsub rowcount type)
  2866. );
  2867. print qq|
  2868. <button class="submit" type="submit" name="action" value="generate_orders">|
  2869. . $locale->text('Generate Orders')
  2870. . qq|</button>|;
  2871. print qq|
  2872. <button class="submit" type="submit" name="action" value="select_vendor">|
  2873. . $locale->text('Select Vendor')
  2874. . qq|</button>|;
  2875. if ( $form->{lynx} ) {
  2876. require "bin/menu.pl";
  2877. &menubar;
  2878. }
  2879. print qq|
  2880. </form>
  2881. </body>
  2882. </html>
  2883. |;
  2884. }
  2885. sub generate_orders {
  2886. if ( OE->generate_orders( \%myconfig, \%$form ) ) {
  2887. $form->redirect;
  2888. }
  2889. else {
  2890. $form->error( $locale->text('Order generation failed!') );
  2891. }
  2892. }
  2893. sub consolidate_orders {
  2894. for ( 1 .. $form->{rowcount} ) {
  2895. if ( $form->{"ndx_$_"} ) {
  2896. $ok = 1;
  2897. last;
  2898. }
  2899. }
  2900. $form->error( $locale->text('Nothing selected!') ) unless $ok;
  2901. ( $null, $argv ) = split /\?/, $form->{callback};
  2902. for ( split /\&/, $argv ) {
  2903. ( $key, $value ) = split /=/, $_;
  2904. $form->{$key} = $value;
  2905. }
  2906. if ( OE->consolidate_orders( \%myconfig, \%$form ) ) {
  2907. $form->redirect;
  2908. }
  2909. else {
  2910. $form->error( $locale->text('Order generation failed!') );
  2911. }
  2912. }
  2913. sub select_vendor {
  2914. for ( 1 .. $form->{rowcount} ) {
  2915. last if ( $ok = $form->{"ndx_$_"} );
  2916. }
  2917. $form->error( $locale->text('Nothing selected!') ) unless $ok;
  2918. $form->header;
  2919. print qq|
  2920. <body onload="document.forms[0].vendor.focus()">
  2921. <form method="post" action="$form->{script}">
  2922. <b>| . $locale->text('Vendor') . qq|</b> <input name="vendor" size="40">
  2923. |;
  2924. $form->{nextsub} = "vendor_selected";
  2925. $form->{action} = "vendor_selected";
  2926. $form->hide_form;
  2927. print qq|
  2928. <button class="submit" type="submit" name="action" value="continue">|
  2929. . $locale->text('Continue')
  2930. . qq|</button>
  2931. </form>
  2932. |;
  2933. if ( $form->{lynx} ) {
  2934. require "bin/menu.pl";
  2935. &menubar;
  2936. }
  2937. print qq|
  2938. </body>
  2939. </html>
  2940. |;
  2941. }
  2942. sub vendor_selected {
  2943. if (
  2944. (
  2945. $rv = $form->get_name( \%myconfig, $form->{vc}, $form->{transdate} )
  2946. ) > 1
  2947. )
  2948. {
  2949. &select_name( $form->{vc} );
  2950. exit;
  2951. }
  2952. if ( $rv == 1 ) {
  2953. for ( 1 .. $form->{rowcount} ) {
  2954. if ( $form->{"ndx_$_"} ) {
  2955. $form->{"$form->{vc}_id_$_"} = $form->{name_list}[0]->{id};
  2956. $form->{"$form->{vc}_$_"} =
  2957. "$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}";
  2958. }
  2959. }
  2960. }
  2961. else {
  2962. $msg = ucfirst $form->{vc} . " not on file!" unless $msg;
  2963. $form->error( $locale->text($msg) );
  2964. }
  2965. &po_orderitems;
  2966. }