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