summaryrefslogtreecommitdiff
path: root/bin/oe.pl
blob: 0d98b5e44b6b1f4cda0a7aae306b39bb92f2f280 (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. $form->{"discount_$i"} = $form->{discount} * 100;
  897. if ($sellprice) {
  898. $form->{"sellprice_$i"} = $sellprice;
  899. ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
  900. $dec = length $dec;
  901. $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
  902. }
  903. else {
  904. ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
  905. $dec = length $dec;
  906. $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
  907. $form->{"sellprice_$i"} /= $exchangerate;
  908. }
  909. ($dec) = ( $form->{"lastcost_$i"} =~ /\.(\d+)/ );
  910. $dec = length $dec;
  911. $decimalplaces2 = ( $dec > 2 ) ? $dec : 2;
  912. for (qw(listprice lastcost)) {
  913. $form->{"${_}_$i"} /= $exchangerate;
  914. }
  915. $amount =
  916. $form->{"sellprice_$i"} * $form->{"qty_$i"} *
  917. ( 1 - $form->{"discount_$i"} / 100 );
  918. for ( split / /, $form->{taxaccounts} ) {
  919. $form->{"${_}_base"} = 0;
  920. }
  921. for ( split / /, $form->{"taxaccounts_$i"} ) {
  922. $form->{"${_}_base"} += $amount;
  923. }
  924. if ( !$form->{taxincluded} ) {
  925. my @taxes = Tax::init_taxes( $form, $form->{taxaccounts} );
  926. $amount +=
  927. Tax::calculate_taxes( \@taxes, $form, $amount, 0 );
  928. }
  929. $form->{creditremaining} -= $amount;
  930. for (qw(sellprice listprice)) {
  931. $form->{"${_}_$i"} =
  932. $form->format_amount( \%myconfig, $form->{"${_}_$i"},
  933. $decimalplaces1 );
  934. }
  935. $form->{"lastcost_$i"} =
  936. $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
  937. $decimalplaces2 );
  938. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  939. for (qw(qty discount)) {
  940. $form->{"{_}_$i"} =
  941. $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
  942. }
  943. }
  944. &display_form;
  945. }
  946. else {
  947. # ok, so this is a new part
  948. # ask if it is a part or service item
  949. if ( $form->{"partsgroup_$i"}
  950. && ( $form->{"partsnumber_$i"} eq "" )
  951. && ( $form->{"description_$i"} eq "" ) )
  952. {
  953. $form->{rowcount}--;
  954. &display_form;
  955. }
  956. else {
  957. $form->{"id_$i"} = 0;
  958. $form->{"unit_$i"} = $locale->text('ea');
  959. &new_item;
  960. }
  961. }
  962. }
  963. }
  964. sub search {
  965. $requiredby = $locale->text('Required by');
  966. if ( $form->{type} eq 'purchase_order' ) {
  967. $form->{title} = $locale->text('Purchase Orders');
  968. $form->{vc} = 'vendor';
  969. $ordlabel = $locale->text('Order Number');
  970. $ordnumber = 'ordnumber';
  971. $employee = $locale->text('Employee');
  972. }
  973. if ( $form->{type} eq 'receive_order' ) {
  974. $form->{title} = $locale->text('Receive Merchandise');
  975. $form->{vc} = 'vendor';
  976. $ordlabel = $locale->text('Order Number');
  977. $ordnumber = 'ordnumber';
  978. $employee = $locale->text('Employee');
  979. }
  980. if ( $form->{type} eq 'generate_sales_order' ) {
  981. $form->{title} =
  982. $locale->text('Generate Sales Order from Purchase Orders');
  983. $form->{vc} = 'vendor';
  984. $ordlabel = $locale->text('Order Number');
  985. $ordnumber = 'ordnumber';
  986. $employee = $locale->text('Employee');
  987. }
  988. if ( $form->{type} eq 'consolidate_sales_order' ) {
  989. $form->{title} = $locale->text('Consolidate Sales Orders');
  990. $form->{vc} = 'customer';
  991. $ordlabel = $locale->text('Order Number');
  992. $ordnumber = 'ordnumber';
  993. $employee = $locale->text('Salesperson');
  994. }
  995. if ( $form->{type} eq 'request_quotation' ) {
  996. $form->{title} = $locale->text('Request for Quotations');
  997. $form->{vc} = 'vendor';
  998. $ordlabel = $locale->text('RFQ Number');
  999. $ordnumber = 'quonumber';
  1000. $employee = $locale->text('Employee');
  1001. }
  1002. if ( $form->{type} eq 'sales_order' ) {
  1003. $form->{title} = $locale->text('Sales Orders');
  1004. $form->{vc} = 'customer';
  1005. $ordlabel = $locale->text('Order Number');
  1006. $ordnumber = 'ordnumber';
  1007. $employee = $locale->text('Salesperson');
  1008. }
  1009. if ( $form->{type} eq 'ship_order' ) {
  1010. $form->{title} = $locale->text('Ship Merchandise');
  1011. $form->{vc} = 'customer';
  1012. $ordlabel = $locale->text('Order Number');
  1013. $ordnumber = 'ordnumber';
  1014. $employee = $locale->text('Salesperson');
  1015. }
  1016. if ( $form->{type} eq 'sales_quotation' ) {
  1017. $form->{title} = $locale->text('Quotations');
  1018. $form->{vc} = 'customer';
  1019. $ordlabel = $locale->text('Quotation Number');
  1020. $ordnumber = 'quonumber';
  1021. $employee = $locale->text('Employee');
  1022. $requiredby = $locale->text('Valid until');
  1023. }
  1024. if ( $form->{type} eq 'generate_purchase_order' ) {
  1025. $form->{title} =
  1026. $locale->text('Generate Purchase Orders from Sales Order');
  1027. $form->{vc} = 'customer';
  1028. $ordlabel = $locale->text('Order Number');
  1029. $ordnumber = 'ordnumber';
  1030. $employee = $locale->text('Salesperson');
  1031. }
  1032. if ( $form->{type} eq 'consolidate_purchase_order' ) {
  1033. $form->{title} = $locale->text('Consolidate Purchase Orders');
  1034. $form->{vc} = 'vendor';
  1035. $ordlabel = $locale->text('Order Number');
  1036. $ordnumber = 'ordnumber';
  1037. $employee = $locale->text('Employee');
  1038. }
  1039. $l_employee =
  1040. qq|<input name="l_employee" class="checkbox" type="checkbox" value="Y"> $employee|;
  1041. $l_manager =
  1042. qq|<input name="l_manager" class="checkbox" type="checkbox" value="Y"> |
  1043. . $locale->text('Manager');
  1044. if ( $form->{type} =~ /(ship|receive)_order/ ) {
  1045. OE->get_warehouses( \%myconfig, \%$form );
  1046. $l_manager = "";
  1047. # warehouse
  1048. if ( @{ $form->{all_warehouse} } ) {
  1049. $form->{selectwarehouse} = "<option>\n";
  1050. $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|;
  1051. for ( @{ $form->{all_warehouse} } ) {
  1052. $form->{selectwarehouse} .=
  1053. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  1054. }
  1055. $warehouse = qq|
  1056. <tr>
  1057. <th align="right">| . $locale->text('Warehouse') . qq|</th>
  1058. <td><select name="warehouse">$form->{selectwarehouse}</select></td>
  1059. <input type="hidden" name="selectwarehouse" value="|
  1060. . $form->escape( $form->{selectwarehouse}, 1 ) . qq|">
  1061. </tr>
  1062. |;
  1063. }
  1064. }
  1065. # setup vendor / customer selection
  1066. $form->all_vc( \%myconfig, $form->{vc},
  1067. ( $form->{vc} eq 'customer' ) ? "AR" : "AP" );
  1068. for ( @{ $form->{"all_$form->{vc}"} } ) {
  1069. $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1070. }
  1071. $selectemployee = "";
  1072. if ( @{ $form->{all_employee} } ) {
  1073. $selectemployee = "<option>\n";
  1074. for ( @{ $form->{all_employee} } ) {
  1075. $selectemployee .=
  1076. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1077. }
  1078. $selectemployee = qq|
  1079. <tr>
  1080. <th align="right">$employee</th>
  1081. <td colspan="3"><select name="employee">$selectemployee</select></td>
  1082. </tr>
  1083. |;
  1084. }
  1085. else {
  1086. $l_employee = $l_manager = "";
  1087. }
  1088. $vclabel = ucfirst $form->{vc};
  1089. $vclabel = $locale->text($vclabel);
  1090. # $locale->text('Vendor')
  1091. # $locale->text('Customer')
  1092. $vc =
  1093. ($vc)
  1094. ? qq|<select name="$form->{vc}"><option>\n$vc</select>|
  1095. : qq|<input name="$form->{vc}" size="35">|;
  1096. # departments
  1097. if ( @{ $form->{all_department} } ) {
  1098. $form->{selectdepartment} = "<option>\n";
  1099. for ( @{ $form->{all_department} } ) {
  1100. $form->{selectdepartment} .=
  1101. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  1102. }
  1103. }
  1104. $department = qq|
  1105. <tr>
  1106. <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
  1107. <td colspan="3"><select name="department">$form->{selectdepartment}</select></td>
  1108. </tr>
  1109. | if $form->{selectdepartment};
  1110. if ( $form->{type} =~ /(consolidate.*|generate.*|ship|receive)_order/ ) {
  1111. $openclosed = qq|
  1112. <input type="hidden" name="open" value="1">
  1113. |;
  1114. }
  1115. else {
  1116. $openclosed = qq|
  1117. <tr>
  1118. <td nowrap><input name="open" class="checkbox" type="checkbox" value="1" checked> |
  1119. . $locale->text('Open')
  1120. . qq|</td>
  1121. <td nowrap><input name="closed" class="checkbox" type="checkbox" value="1" $form->{closed}> |
  1122. . $locale->text('Closed')
  1123. . qq|</td>
  1124. </tr>
  1125. |;
  1126. }
  1127. if ( @{ $form->{all_years} } ) {
  1128. # accounting years
  1129. $form->{selectaccountingyear} = "<option>\n";
  1130. for ( @{ $form->{all_years} } ) {
  1131. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  1132. }
  1133. $form->{selectaccountingmonth} = "<option>\n";
  1134. for ( sort keys %{ $form->{all_month} } ) {
  1135. $form->{selectaccountingmonth} .=
  1136. qq|<option value=$_>|
  1137. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  1138. }
  1139. $selectfrom = qq|
  1140. <tr>
  1141. <th align="right">| . $locale->text('Period') . qq|</th>
  1142. <td colspan="3">
  1143. <select name="month">$form->{selectaccountingmonth}</select>
  1144. <select name="year">$form->{selectaccountingyear}</select>
  1145. <input name="interval" class="radio" type="radio" value="0" checked>&nbsp;|
  1146. . $locale->text('Current') . qq|
  1147. <input name="interval" class="radio" type="radio" value="1">&nbsp;|
  1148. . $locale->text('Month') . qq|
  1149. <input name="interval" class="radio" type="radio" value="3">&nbsp;|
  1150. . $locale->text('Quarter') . qq|
  1151. <input name="interval" class="radio" type="radio" value="12">&nbsp;|
  1152. . $locale->text('Year') . qq|
  1153. </td>
  1154. </tr>
  1155. |;
  1156. }
  1157. if ( $form->{type} =~ /_order/ ) {
  1158. $ponumber = qq|
  1159. <tr>
  1160. <th align="right">| . $locale->text('PO Number') . qq|</th>
  1161. <td colspan="3"><input name="ponumber" size="20"></td>
  1162. </tr>
  1163. |;
  1164. $l_ponumber =
  1165. qq|<input name="l_ponumber" class="checkbox" type="checkbox" value="Y"> |
  1166. . $locale->text('PO Number');
  1167. }
  1168. @a = ();
  1169. push @a,
  1170. qq|<input name="l_runningnumber" class="checkbox" type="checkbox" value="Y"> |
  1171. . $locale->text('No.');
  1172. push @a, qq|<input name="l_id" class="checkbox" type="checkbox" value="Y"> |
  1173. . $locale->text('ID');
  1174. push @a,
  1175. qq|<input name="l_$ordnumber" class="checkbox" type="checkbox" value="Y" checked> $ordlabel|;
  1176. push @a,
  1177. qq|<input name="l_transdate" class="checkbox" type="checkbox" value="Y" checked> |
  1178. . $locale->text('Date');
  1179. push @a, $l_ponumber if $l_ponumber;
  1180. push @a,
  1181. qq|<input name="l_reqdate" class="checkbox" type="checkbox" value="Y" checked> $requiredby|;
  1182. push @a,
  1183. qq|<input name="l_name" class="checkbox" type="checkbox" value="Y" checked> $vclabel|;
  1184. push @a, $l_employee if $l_employee;
  1185. push @a, $l_manager if $l_manager;
  1186. push @a, qq|<input name="l_shipvia" class="checkbox" type="checkbox" value="Y"> |
  1187. . $locale->text('Ship via');
  1188. push @a,
  1189. qq|<input name="l_netamount" class="checkbox" type="checkbox" value="Y"> |
  1190. . $locale->text('Amount');
  1191. push @a, qq|<input name="l_tax" class="checkbox" type="checkbox" value="Y"> |
  1192. . $locale->text('Tax');
  1193. push @a,
  1194. qq|<input name="l_amount" class="checkbox" type="checkbox" value="Y" checked> |
  1195. . $locale->text('Total');
  1196. push @a,
  1197. qq|<input name="l_curr" class="checkbox" type="checkbox" value="Y" checked> |
  1198. . $locale->text('Currency');
  1199. $form->header;
  1200. print qq|
  1201. <body>
  1202. <form method="post" action="$form->{script}">
  1203. <table width="100%">
  1204. <tr>
  1205. <th class="listtop">$form->{title}</th>
  1206. </tr>
  1207. <tr height="5"></tr>
  1208. <tr>
  1209. <td>
  1210. <table>
  1211. <tr>
  1212. <th align="right">$vclabel</th>
  1213. <td colspan="3">$vc</td>
  1214. </tr>
  1215. $warehouse
  1216. $department
  1217. $selectemployee
  1218. <tr>
  1219. <th align="right">$ordlabel</th>
  1220. <td colspan="3"><input name="$ordnumber" size="20"></td>
  1221. </tr>
  1222. $ponumber
  1223. <tr>
  1224. <th align="right">| . $locale->text('Ship via') . qq|</th>
  1225. <td colspan="3"><input name="shipvia" size="40"></td>
  1226. </tr>
  1227. <tr>
  1228. <th align="right">| . $locale->text('Description') . qq|</th>
  1229. <td colspan="3"><input name="description" size="40"></td>
  1230. </tr>
  1231. <tr>
  1232. <th align="right">| . $locale->text('From') . qq|</th>
  1233. <td><input name="transdatefrom" size="11" title="$myconfig{dateformat}"></td>
  1234. <th align="right">| . $locale->text('To') . qq|</th>
  1235. <td><input name="transdateto" size="11" title="$myconfig{dateformat}"></td>
  1236. </tr>
  1237. <input type="hidden" name="sort" value="transdate">
  1238. $selectfrom
  1239. <tr>
  1240. <th align="right">| . $locale->text('Include in Report') . qq|</th>
  1241. <td colspan="3">
  1242. <table>
  1243. $openclosed
  1244. |;
  1245. while (@a) {
  1246. for ( 1 .. 5 ) {
  1247. print qq|<td nowrap>| . shift @a;
  1248. print qq|</td>\n|;
  1249. }
  1250. print qq|</tr>\n|;
  1251. }
  1252. print qq|
  1253. <tr>
  1254. <td><input name="l_subtotal" class="checkbox" type="checkbox" value="Y"> |
  1255. . $locale->text('Subtotal')
  1256. . qq|</td>
  1257. </tr>
  1258. </table>
  1259. </td>
  1260. </tr>
  1261. </table>
  1262. </td>
  1263. </tr>
  1264. <tr><td colspan="4"><hr size="3" noshade></td></tr>
  1265. </table>
  1266. <br>
  1267. <input type="hidden" name="nextsub" value="transactions">
  1268. |;
  1269. $form->hide_form(qw(path login sessionid vc type));
  1270. print qq|
  1271. <button class="submit" type="submit" name="action" value="continue">|
  1272. . $locale->text('Continue')
  1273. . qq|</button>
  1274. </form>
  1275. |;
  1276. if ( $form->{lynx} ) {
  1277. require "bin/menu.pl";
  1278. &menubar;
  1279. }
  1280. print qq|
  1281. </body>
  1282. </html>
  1283. |;
  1284. }
  1285. sub transactions {
  1286. # split vendor / customer
  1287. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  1288. split( /--/, $form->{ $form->{vc} } );
  1289. OE->transactions( \%myconfig, \%$form );
  1290. $ordnumber = ( $form->{type} =~ /_order/ ) ? 'ordnumber' : 'quonumber';
  1291. $name = $form->escape( $form->{ $form->{vc} } );
  1292. $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
  1293. # construct href
  1294. $href = qq|$form->{script}?action=transactions|;
  1295. for (
  1296. "oldsort", "direction", "path", "type",
  1297. "vc", "login", "sessionid", "transdatefrom",
  1298. "transdateto", "open", "closed"
  1299. )
  1300. {
  1301. $href .= qq|&$_=$form->{$_}|;
  1302. }
  1303. for (
  1304. "$ordnumber", "department", "warehouse", "shipvia",
  1305. "ponumber", "description", "employee"
  1306. )
  1307. {
  1308. $href .= qq|&$_=| . $form->escape( $form->{$_} );
  1309. }
  1310. $href .= "&$form->{vc}=$name";
  1311. # construct callback
  1312. $name = $form->escape( $form->{ $form->{vc} }, 1 );
  1313. $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
  1314. # flip direction
  1315. $form->sort_order();
  1316. $callback = qq|$form->{script}?action=transactions|;
  1317. for (
  1318. "oldsort", "direction", "path", "type",
  1319. "vc", "login", "sessionid", "transdatefrom",
  1320. "transdateto", "open", "closed"
  1321. )
  1322. {
  1323. $callback .= qq|&$_=$form->{$_}|;
  1324. }
  1325. for (
  1326. "$ordnumber", "department", "warehouse", "shipvia",
  1327. "ponumber", "description", "employee"
  1328. )
  1329. {
  1330. $callback .= qq|&$_=| . $form->escape( $form->{$_}, 1 );
  1331. }
  1332. $callback .= "&$form->{vc}=$name";
  1333. @columns = $form->sort_columns(
  1334. "transdate", "reqdate", "id", "$ordnumber",
  1335. "ponumber", "name", "netamount", "tax",
  1336. "amount", "curr", "employee", "manager",
  1337. "shipvia", "open", "closed"
  1338. );
  1339. unshift @columns, "runningnumber";
  1340. $form->{l_open} = $form->{l_closed} = "Y"
  1341. if ( $form->{open} && $form->{closed} );
  1342. for (@columns) {
  1343. if ( $form->{"l_$_"} eq "Y" ) {
  1344. push @column_index, $_;
  1345. if ( $form->{l_curr} && $_ =~ /(amount|tax)/ ) {
  1346. push @column_index, "fx_$_";
  1347. }
  1348. # add column to href and callback
  1349. $callback .= "&l_$_=Y";
  1350. $href .= "&l_$_=Y";
  1351. }
  1352. }
  1353. if ( $form->{l_subtotal} eq 'Y' ) {
  1354. $callback .= "&l_subtotal=Y";
  1355. $href .= "&l_subtotal=Y";
  1356. }
  1357. $requiredby = $locale->text('Required by');
  1358. $i = 1;
  1359. if ( $form->{vc} eq 'vendor' ) {
  1360. if ( $form->{type} eq 'receive_order' ) {
  1361. $form->{title} = $locale->text('Receive Merchandise');
  1362. }
  1363. if ( $form->{type} eq 'purchase_order' ) {
  1364. $form->{title} = $locale->text('Purchase Orders');
  1365. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1366. $button{'Order Entry--Purchase Order'}{code} =
  1367. qq|<button class="submit" type="submit" name="action" value="purchase_order">|
  1368. . $locale->text('Purchase Order')
  1369. . qq|</button> |;
  1370. $button{'Order Entry--Purchase Order'}{order} = $i++;
  1371. }
  1372. }
  1373. if ( $form->{type} eq 'generate_sales_order' ) {
  1374. $form->{title} = $locale->text('Purchase Orders');
  1375. $form->{type} = "purchase_order";
  1376. unshift @column_index, "ndx";
  1377. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1378. $button{'Order Entry--Sales Order'}{code} =
  1379. qq|<button class="submit" type="submit" name="action" value="generate_sales_order">|
  1380. . $locale->text('Generate Sales Order')
  1381. . qq|</button> |;
  1382. $button{'Order Entry--Sales Order'}{order} = $i++;
  1383. }
  1384. }
  1385. if ( $form->{type} eq 'consolidate_purchase_order' ) {
  1386. $form->{title} = $locale->text('Purchase Orders');
  1387. $form->{type} = "purchase_order";
  1388. unshift @column_index, "ndx";
  1389. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1390. $button{'Order Entry--Purchase Order'}{code} =
  1391. qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|
  1392. . $locale->text('Consolidate Orders')
  1393. . qq|</button> |;
  1394. $button{'Order Entry--Purchase Order'}{order} = $i++;
  1395. }
  1396. }
  1397. if ( $form->{type} eq 'request_quotation' ) {
  1398. $form->{title} = $locale->text('Request for Quotations');
  1399. $quotation = $locale->text('RFQ');
  1400. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1401. $button{'Quotations--RFQ'}{code} =
  1402. qq|<button class="submit" type="submit" name="action" value="add">|
  1403. . $locale->text('RFQ')
  1404. . qq|</button> |;
  1405. $button{'Quotations--RFQ'}{order} = $i++;
  1406. }
  1407. }
  1408. $name = $locale->text('Vendor');
  1409. $employee = $locale->text('Employee');
  1410. }
  1411. if ( $form->{vc} eq 'customer' ) {
  1412. if ( $form->{type} eq 'sales_order' ) {
  1413. $form->{title} = $locale->text('Sales Orders');
  1414. $employee = $locale->text('Salesperson');
  1415. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1416. $button{'Order Entry--Sales Order'}{code} =
  1417. qq|<button class="submit" type="submit" name="action" value="sales_order">|
  1418. . $locale->text('Sales Order')
  1419. . qq|</button> |;
  1420. $button{'Order Entry--Sales Order'}{order} = $i++;
  1421. }
  1422. }
  1423. if ( $form->{type} eq 'generate_purchase_order' ) {
  1424. $form->{title} = $locale->text('Sales Orders');
  1425. $form->{type} = "sales_order";
  1426. $employee = $locale->text('Salesperson');
  1427. unshift @column_index, "ndx";
  1428. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1429. $button{'Order Entry--Purchase Order'}{code} =
  1430. qq|<button class="submit" type="submit" name="action" value="generate_purchase_orders">|
  1431. . $locale->text('Generate Purchase Orders')
  1432. . qq|</button> |;
  1433. $button{'Order Entry--Purchase Order'}{order} = $i++;
  1434. }
  1435. }
  1436. if ( $form->{type} eq 'consolidate_sales_order' ) {
  1437. $form->{title} = $locale->text('Sales Orders');
  1438. $form->{type} = "sales_order";
  1439. unshift @column_index, "ndx";
  1440. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1441. $button{'Order Entry--Sales Order'}{code} =
  1442. qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|
  1443. . $locale->text('Consolidate Orders')
  1444. . qq|</button> |;
  1445. $button{'Order Entry--Sales Order'}{order} = $i++;
  1446. }
  1447. }
  1448. if ( $form->{type} eq 'ship_order' ) {
  1449. $form->{title} = $locale->text('Ship Merchandise');
  1450. $employee = $locale->text('Salesperson');
  1451. }
  1452. if ( $form->{type} eq 'sales_quotation' ) {
  1453. $form->{title} = $locale->text('Quotations');
  1454. $employee = $locale->text('Employee');
  1455. $requiredby = $locale->text('Valid until');
  1456. $quotation = $locale->text('Quotation');
  1457. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1458. $button{'Quotations--Quotation'}{code} =
  1459. qq|<button class="submit" type="submit" name="action" value="add">|
  1460. . $locale->text('Quotation')
  1461. . qq|</button> |;
  1462. $button{'Quotations--Quotation'}{order} = $i++;
  1463. }
  1464. }
  1465. $name = $locale->text('Customer');
  1466. }
  1467. for ( split /;/, $myconfig{acs} ) { delete $button{$_} }
  1468. $column_header{ndx} = qq|<th class="listheading">&nbsp;</th>|;
  1469. $column_header{runningnumber} = qq|<th class="listheading">&nbsp;</th>|;
  1470. $column_header{id} =
  1471. qq|<th><a class="listheading" href="$href&sort=id">|
  1472. . $locale->text('ID')
  1473. . qq|</a></th>|;
  1474. $column_header{transdate} =
  1475. qq|<th><a class="listheading" href="$href&sort=transdate">|
  1476. . $locale->text('Date')
  1477. . qq|</a></th>|;
  1478. $column_header{reqdate} =
  1479. qq|<th><a class="listheading" href="$href&sort=reqdate">$requiredby</a></th>|;
  1480. $column_header{ordnumber} =
  1481. qq|<th><a class="listheading" href="$href&sort=ordnumber">|
  1482. . $locale->text('Order')
  1483. . qq|</a></th>|;
  1484. $column_header{ponumber} =
  1485. qq|<th><a class="listheading" href="$href&sort=ponumber">|
  1486. . $locale->text('PO Number')
  1487. . qq|</a></th>|;
  1488. $column_header{quonumber} =
  1489. qq|<th><a class="listheading" href="$href&sort=quonumber">$quotation</a></th>|;
  1490. $column_header{name} =
  1491. qq|<th><a class="listheading" href="$href&sort=name">$name</a></th>|;
  1492. $column_header{netamount} =
  1493. qq|<th class="listheading">| . $locale->text('Amount') . qq|</th>|;
  1494. $column_header{tax} =
  1495. qq|<th class="listheading">| . $locale->text('Tax') . qq|</th>|;
  1496. $column_header{amount} =
  1497. qq|<th class="listheading">| . $locale->text('Total') . qq|</th>|;
  1498. $column_header{curr} =
  1499. qq|<th><a class="listheading" href="$href&sort=curr">|
  1500. . $locale->text('Curr')
  1501. . qq|</a></th>|;
  1502. $column_header{shipvia} =
  1503. qq|<th><a class="listheading" href="$href&sort=shipvia">|
  1504. . $locale->text('Ship via')
  1505. . qq|</a></th>|;
  1506. $column_header{open} =
  1507. qq|<th class="listheading">| . $locale->text('O') . qq|</th>|;
  1508. $column_header{closed} =
  1509. qq|<th class="listheading">| . $locale->text('C') . qq|</th>|;
  1510. $column_header{employee} =
  1511. qq|<th><a class="listheading" href="$href&sort=employee">$employee</a></th>|;
  1512. $column_header{manager} =
  1513. qq|<th><a class="listheading" href="$href&sort=manager">|
  1514. . $locale->text('Manager')
  1515. . qq|</a></th>|;
  1516. for (qw(amount tax netamount)) {
  1517. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1518. }
  1519. if ( $form->{ $form->{vc} } ) {
  1520. $option = $locale->text( ucfirst $form->{vc} );
  1521. $option .= " : $form->{$form->{vc}}";
  1522. }
  1523. if ( $form->{warehouse} ) {
  1524. ($warehouse) = split /--/, $form->{warehouse};
  1525. $option .= "\n<br>" if ($option);
  1526. $option .= $locale->text('Warehouse');
  1527. $option .= " : $warehouse";
  1528. }
  1529. if ( $form->{department} ) {
  1530. $option .= "\n<br>" if ($option);
  1531. ($department) = split /--/, $form->{department};
  1532. $option .= $locale->text('Department') . " : $department";
  1533. }
  1534. if ( $form->{employee} ) {
  1535. ($employee) = split /--/, $form->{employee};
  1536. $option .= "\n<br>" if ($option);
  1537. if ( $form->{vc} eq 'customer' ) {
  1538. $option .= $locale->text('Salesperson');
  1539. }
  1540. else {
  1541. $option .= $locale->text('Employee');
  1542. }
  1543. $option .= " : $employee";
  1544. }
  1545. if ( $form->{ordnumber} ) {
  1546. $option .= "\n<br>" if ($option);
  1547. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1548. }
  1549. if ( $form->{quonumber} ) {
  1550. $option .= "\n<br>" if ($option);
  1551. $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
  1552. }
  1553. if ( $form->{ponumber} ) {
  1554. $option = $locale->text('PO Number');
  1555. $option .= " : $form->{ponumber}";
  1556. }
  1557. if ( $form->{shipvia} ) {
  1558. $option .= "\n<br>" if ($option);
  1559. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1560. }
  1561. if ( $form->{description} ) {
  1562. $option .= "\n<br>" if $option;
  1563. $option .= $locale->text('Description') . " : $form->{description}";
  1564. }
  1565. if ( $form->{transdatefrom} ) {
  1566. $option .= "\n<br>"
  1567. . $locale->text('From') . " "
  1568. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1569. }
  1570. if ( $form->{transdateto} ) {
  1571. $option .= "\n<br>"
  1572. . $locale->text('To') . " "
  1573. . $locale->date( \%myconfig, $form->{transdateto}, 1 );
  1574. }
  1575. if ( $form->{open} ) {
  1576. $option .= "\n<br>" if ($option);
  1577. $option .= $locale->text('Open');
  1578. }
  1579. if ( $form->{closed} ) {
  1580. $option .= "\n<br>" if ($option);
  1581. $option .= $locale->text('Closed');
  1582. }
  1583. $form->header;
  1584. print qq|
  1585. <body>
  1586. <form method="post" action="$form->{script}">
  1587. <table width="100%">
  1588. <tr>
  1589. <th class="listtop">$form->{title}</th>
  1590. </tr>
  1591. <tr height="5"></tr>
  1592. <tr>
  1593. <td>$option</td>
  1594. </tr>
  1595. <tr>
  1596. <td>
  1597. <table width="100%">
  1598. <tr class="listheading">|;
  1599. for (@column_index) { print "\n$column_header{$_}" }
  1600. print qq|
  1601. </tr>
  1602. |;
  1603. # add sort and escape callback
  1604. $callback .= "&sort=$form->{sort}";
  1605. $form->{callback} = $callback;
  1606. $callback = $form->escape($callback);
  1607. # flip direction
  1608. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1609. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1610. if ( @{ $form->{OE} } ) {
  1611. $sameitem = $form->{OE}->[0]->{ $form->{sort} };
  1612. }
  1613. $action = "edit";
  1614. $action = "ship_receive" if ( $form->{type} =~ /(ship|receive)_order/ );
  1615. $warehouse = $form->escape( $form->{warehouse} );
  1616. $i = 0;
  1617. foreach $oe ( @{ $form->{OE} } ) {
  1618. $i++;
  1619. if ( $form->{l_subtotal} eq 'Y' ) {
  1620. if ( $sameitem ne $oe->{ $form->{sort} } ) {
  1621. &subtotal;
  1622. $sameitem = $oe->{ $form->{sort} };
  1623. }
  1624. }
  1625. if ( $form->{l_curr} ) {
  1626. for (qw(netamount amount)) { $oe->{"fx_$_"} = $oe->{$_} }
  1627. $oe->{fx_tax} = $oe->{fx_amount} - $oe->{fx_netamount};
  1628. for (qw(netamount amount)) { $oe->{$_} *= $oe->{exchangerate} }
  1629. for (qw(netamount amount)) {
  1630. $column_data{"fx_$_"} = '<td align="right">'
  1631. . $form->format_amount( \%myconfig, $oe->{"fx_$_"}, 2,
  1632. "&nbsp;" )
  1633. . "</td>";
  1634. }
  1635. $column_data{fx_tax} = '<td align="right">'
  1636. . $form->format_amount( \%myconfig,
  1637. $oe->{fx_amount} - $oe->{fx_netamount},
  1638. 2, "&nbsp;" )
  1639. . "</td>";
  1640. $totalfxnetamount += $oe->{fx_netamount};
  1641. $totalfxamount += $oe->{fx_amount};
  1642. $subtotalfxnetamount += $oe->{fx_netamount};
  1643. $subtotalfxamount += $oe->{fx_amount};
  1644. }
  1645. for (qw(netamount amount)) {
  1646. $column_data{$_} =
  1647. '<td align="right">'
  1648. . $form->format_amount( \%myconfig, $oe->{$_}, 2, "&nbsp;" )
  1649. . '</td>';
  1650. }
  1651. $column_data{tax} = '<td align="right">'
  1652. . $form->format_amount( \%myconfig, $oe->{amount} - $oe->{netamount},
  1653. 2, "&nbsp;" )
  1654. . "</td>";
  1655. $totalnetamount += $oe->{netamount};
  1656. $totalamount += $oe->{amount};
  1657. $subtotalnetamount += $oe->{netamount};
  1658. $subtotalamount += $oe->{amount};
  1659. $column_data{id} = "<td>$oe->{id}</td>";
  1660. $column_data{transdate} = "<td>$oe->{transdate}&nbsp;</td>";
  1661. $column_data{reqdate} = "<td>$oe->{reqdate}&nbsp;</td>";
  1662. $column_data{runningnumber} = qq|<td align="right">$i</td>|;
  1663. $column_data{ndx} =
  1664. qq|<td><input name="ndx_$i" class="checkbox" type="checkbox" value="$oe->{id}" checked></td>|;
  1665. $column_data{$ordnumber} =
  1666. 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>|;
  1667. $name = $form->escape( $oe->{name} );
  1668. $column_data{name} =
  1669. 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>|;
  1670. for (qw(employee manager shipvia curr ponumber)) {
  1671. $column_data{$_} = "<td>$oe->{$_}&nbsp;</td>";
  1672. }
  1673. if ( $oe->{closed} ) {
  1674. $column_data{closed} = '<td align="center">*</td>';
  1675. $column_data{open} = "<td>&nbsp;</td>";
  1676. }
  1677. else {
  1678. $column_data{closed} = "<td>&nbsp;</td>";
  1679. $column_data{open} = '<td align="center">*</td>';
  1680. }
  1681. $j++;
  1682. $j %= 2;
  1683. print qq|
  1684. <tr class="listrow$j">|;
  1685. for (@column_index) { print "\n$column_data{$_}" }
  1686. print qq|
  1687. </tr>
  1688. |;
  1689. }
  1690. if ( $form->{l_subtotal} eq 'Y' ) {
  1691. &subtotal;
  1692. }
  1693. # print totals
  1694. print qq|
  1695. <tr class="listtotal">|;
  1696. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1697. $column_data{netamount} =
  1698. '<th class="listtotal" align="right">'
  1699. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1700. . "</th>";
  1701. $column_data{tax} = '<th class="listtotal" align="right">'
  1702. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1703. 2, "&nbsp;" )
  1704. . "</th>";
  1705. $column_data{amount} =
  1706. '<th class="listtotal" align="right">'
  1707. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1708. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1709. $column_data{fx_netamount} =
  1710. '<th class="listtotal" align="right">'
  1711. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1712. . "</th>";
  1713. $column_data{fx_tax} = '<th class="listtotal" align="right">'
  1714. . $form->format_amount( \%myconfig,
  1715. $totalfxamount - $totalfxnetamount,
  1716. 2, "&nbsp;" )
  1717. . "</th>";
  1718. $column_data{fx_amount} =
  1719. '<th class="listtotal" align="right">'
  1720. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1721. . "</th>";
  1722. }
  1723. for (@column_index) { print "\n$column_data{$_}" }
  1724. print qq|
  1725. </tr>
  1726. </td>
  1727. </table>
  1728. </tr>
  1729. <tr>
  1730. <td><hr size="3" noshade></td>
  1731. </tr>
  1732. </table>
  1733. <br>
  1734. |;
  1735. $form->hide_form(
  1736. qw(callback type vc path login sessionid department ordnumber ponumber shipvia)
  1737. );
  1738. print qq|
  1739. <input type="hidden" name="rowcount" value="$i">
  1740. <input type="hidden" name="$form->{vc}" value="$form->{$form->{vc}}">
  1741. <input type="hidden" name="$form->{vc}_id" value="$form->{"$form->{vc}_id"}">
  1742. |;
  1743. if ( $form->{type} !~ /(ship|receive)_order/ ) {
  1744. for ( sort { $a->{order} <=> $b->{order} } %button ) {
  1745. print $_->{code};
  1746. }
  1747. }
  1748. if ( $form->{lynx} ) {
  1749. require "bin/menu.pl";
  1750. &menubar;
  1751. }
  1752. print qq|
  1753. </form>
  1754. </body>
  1755. </html>
  1756. |;
  1757. }
  1758. sub subtotal {
  1759. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1760. $column_data{netamount} =
  1761. '<th class="listsubtotal" align="right">'
  1762. . $form->format_amount( \%myconfig, $subtotalnetamount, 2, "&nbsp;" )
  1763. . "</th>";
  1764. $column_data{tax} = '<td class="listsubtotal" align="right">'
  1765. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1766. 2, "&nbsp;" )
  1767. . "</th>";
  1768. $column_data{amount} =
  1769. '<th class="listsubtotal" align="right">'
  1770. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1771. . "</th>";
  1772. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1773. $column_data{fx_netamount} =
  1774. '<th class="listsubtotal" align="right">'
  1775. . $form->format_amount( \%myconfig, $subtotalfxnetamount, 2,
  1776. "&nbsp;" )
  1777. . "</th>";
  1778. $column_data{fx_tax} = '<td class="listsubtotal" align="right">'
  1779. . $form->format_amount( \%myconfig,
  1780. $subtotalfxamount - $subtotalfxnetamount,
  1781. 2, "&nbsp;" )
  1782. . "</th>";
  1783. $column_data{fx_amount} =
  1784. '<th class="listsubtotal" align="right">'
  1785. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1786. . "</th>";
  1787. }
  1788. $subtotalnetamount = 0;
  1789. $subtotalamount = 0;
  1790. $subtotalfxnetamount = 0;
  1791. $subtotalfxamount = 0;
  1792. print '
  1793. <tr class="listsubtotal">
  1794. ';
  1795. for (@column_index) { print "\n$column_data{$_}" }
  1796. print qq|
  1797. </tr>
  1798. |;
  1799. }
  1800. sub save {
  1801. if ( $form->{type} =~ /_order$/ ) {
  1802. $msg = $locale->text('Order Date missing!');
  1803. }
  1804. else {
  1805. $msg = $locale->text('Quotation Date missing!');
  1806. }
  1807. $form->isblank( "transdate", $msg );
  1808. $msg = ucfirst $form->{vc};
  1809. $form->isblank( $form->{vc}, $locale->text( $msg . " missing!" ) );
  1810. # $locale->text('Customer missing!');
  1811. # $locale->text('Vendor missing!');
  1812. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
  1813. if ( $form->{currency} ne $form->{defaultcurrency} );
  1814. &validate_items;
  1815. # if the name changed get new values
  1816. if ( &check_name( $form->{vc} ) ) {
  1817. &update;
  1818. exit;
  1819. }
  1820. # this is for the internal notes section for the [email] Subject
  1821. if ( $form->{type} =~ /_order$/ ) {
  1822. if ( $form->{type} eq 'sales_order' ) {
  1823. $form->{label} = $locale->text('Sales Order');
  1824. $numberfld = "sonumber";
  1825. $ordnumber = "ordnumber";
  1826. }
  1827. else {
  1828. $form->{label} = $locale->text('Purchase Order');
  1829. $numberfld = "ponumber";
  1830. $ordnumber = "ordnumber";
  1831. }
  1832. $err = $locale->text('Cannot save order!');
  1833. }
  1834. else {
  1835. if ( $form->{type} eq 'sales_quotation' ) {
  1836. $form->{label} = $locale->text('Quotation');
  1837. $numberfld = "sqnumber";
  1838. $ordnumber = "quonumber";
  1839. }
  1840. else {
  1841. $form->{label} = $locale->text('Request for Quotation');
  1842. $numberfld = "rfqnumber";
  1843. $ordnumber = "quonumber";
  1844. }
  1845. $err = $locale->text('Cannot save quotation!');
  1846. }
  1847. if ( !$form->{repost} ) {
  1848. if ( $form->{id} ) {
  1849. &repost("Save");
  1850. exit;
  1851. }
  1852. }
  1853. if ( OE->save( \%myconfig, \%$form ) ) {
  1854. $form->redirect( $locale->text('Order saved!') );
  1855. }
  1856. else {
  1857. $form->error($err);
  1858. }
  1859. }
  1860. sub print_and_save {
  1861. $form->error( $locale->text('Select postscript or PDF!') )
  1862. if $form->{format} !~ /(postscript|pdf)/;
  1863. $form->error( $locale->text('Select a Printer!') )
  1864. if $form->{media} eq 'screen';
  1865. $old_form = new Form;
  1866. $form->{display_form} = "save";
  1867. for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
  1868. $old_form->{rowcount}++;
  1869. &print_form($old_form);
  1870. }
  1871. sub delete {
  1872. $form->header;
  1873. if ( $form->{type} =~ /_order$/ ) {
  1874. $msg = $locale->text('Are you sure you want to delete Order Number');
  1875. $ordnumber = 'ordnumber';
  1876. }
  1877. else {
  1878. $msg =
  1879. $locale->text('Are you sure you want to delete Quotation Number');
  1880. $ordnumber = 'quonumber';
  1881. }
  1882. print qq|
  1883. <body>
  1884. <form method="post" action="$form->{script}">
  1885. |;
  1886. $form->{action} = "yes";
  1887. $form->hide_form;
  1888. print qq|
  1889. <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
  1890. <h4>$msg $form->{$ordnumber}</h4>
  1891. <p>
  1892. <button name="action" class="submit" type="submit" value="yes">|
  1893. . $locale->text('Yes')
  1894. . qq|</button>
  1895. </form>
  1896. </body>
  1897. </html>
  1898. |;
  1899. }
  1900. sub yes {
  1901. if ( $form->{type} =~ /_order$/ ) {
  1902. $msg = $locale->text('Order deleted!');
  1903. $err = $locale->text('Cannot delete order!');
  1904. }
  1905. else {
  1906. $msg = $locale->text('Quotation deleted!');
  1907. $err = $locale->text('Cannot delete quotation!');
  1908. }
  1909. if ( OE->delete( \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool} ) ) {
  1910. $form->redirect($msg);
  1911. }
  1912. else {
  1913. $form->error($err);
  1914. }
  1915. }
  1916. sub vendor_invoice { &invoice }
  1917. sub sales_invoice { &invoice }
  1918. sub invoice {
  1919. if ( $form->{type} =~ /_order$/ ) {
  1920. $form->isblank( "ordnumber", $locale->text('Order Number missing!') );
  1921. $form->isblank( "transdate", $locale->text('Order Date missing!') );
  1922. }
  1923. else {
  1924. $form->isblank( "quonumber",
  1925. $locale->text('Quotation Number missing!') );
  1926. $form->isblank( "transdate", $locale->text('Quotation Date missing!') );
  1927. $form->{ordnumber} = "";
  1928. }
  1929. # if the name changed get new values
  1930. if ( &check_name( $form->{vc} ) ) {
  1931. &update;
  1932. exit;
  1933. }
  1934. if ( $form->{type} =~ /_order/
  1935. && $form->{currency} ne $form->{defaultcurrency} )
  1936. {
  1937. # check if we need a new exchangerate
  1938. $buysell = ( $form->{type} eq 'sales_order' ) ? "buy" : "sell";
  1939. $orddate = $form->current_date( \%myconfig );
  1940. $exchangerate =
  1941. $form->check_exchangerate( \%myconfig, $form->{currency}, $orddate,
  1942. $buysell );
  1943. if ( !$exchangerate ) {
  1944. &backorder_exchangerate( $orddate, $buysell );
  1945. exit;
  1946. }
  1947. }
  1948. # close orders/quotations
  1949. $form->{closed} = 1;
  1950. OE->save( \%myconfig, \%$form );
  1951. $form->{transdate} = $form->current_date( \%myconfig );
  1952. $form->{duedate} =
  1953. $form->current_date( \%myconfig, $form->{transdate}, $form->{terms} * 1 );
  1954. $form->{id} = '';
  1955. $form->{closed} = 0;
  1956. $form->{rowcount}--;
  1957. $form->{shipto} = 1;
  1958. if ( $form->{type} =~ /_order$/ ) {
  1959. $form->{exchangerate} = $exchangerate;
  1960. &create_backorder;
  1961. }
  1962. if ( $form->{type} eq 'purchase_order'
  1963. || $form->{type} eq 'request_quotation' )
  1964. {
  1965. $form->{title} = $locale->text('Add Vendor Invoice');
  1966. $form->{script} = 'ir.pl';
  1967. $script = "ir";
  1968. $buysell = 'sell';
  1969. }
  1970. if ( $form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation' )
  1971. {
  1972. $form->{title} = $locale->text('Add Sales Invoice');
  1973. $form->{script} = 'is.pl';
  1974. $script = "is";
  1975. $buysell = 'buy';
  1976. }
  1977. for (qw(id subject message printed emailed queued)) { delete $form->{$_} }
  1978. $form->{ $form->{vc} } =~ s/--.*//g;
  1979. $form->{type} = "invoice";
  1980. # locale messages
  1981. $locale = LedgerSMB::Locale->get_handle( $myconfig{countrycode} )
  1982. or $form->error("Locale not loaded: $!\n");
  1983. #$form->{charset} = $locale->encoding;
  1984. $form->{charset} = 'UTF-8';
  1985. $locale->encoding('UTF-8');
  1986. require "bin/$form->{script}";
  1987. # customized scripts
  1988. if ( -f "bin/custom/$form->{script}" ) {
  1989. eval { require "bin/custom/$form->{script}"; };
  1990. }
  1991. # customized scripts for login
  1992. if ( -f "bin/custom/$form->{login}_$form->{script}" ) {
  1993. eval { require "bin/custom/$form->{login}_$form->{script}"; };
  1994. }
  1995. for ( "$form->{vc}", "currency" ) { $form->{"select$_"} = "" }
  1996. for (
  1997. qw(currency oldcurrency employee department intnotes notes taxincluded))
  1998. {
  1999. $temp{$_} = $form->{$_};
  2000. }
  2001. &invoice_links;
  2002. $form->{creditremaining} -= ( $form->{oldinvtotal} - $form->{ordtotal} );
  2003. &prepare_invoice;
  2004. for ( keys %temp ) { $form->{$_} = $temp{$_} }
  2005. $form->{exchangerate} = "";
  2006. $form->{forex} = "";
  2007. $form->{exchangerate} = $exchangerate
  2008. if (
  2009. $form->{forex} = (
  2010. $exchangerate = $form->check_exchangerate(
  2011. \%myconfig, $form->{currency}, $form->{transdate}, $buysell
  2012. )
  2013. )
  2014. );
  2015. for $i ( 1 .. $form->{rowcount} ) {
  2016. $form->{"deliverydate_$i"} = $form->{"reqdate_$i"};
  2017. for (qw(qty sellprice discount)) {
  2018. $form->{"${_}_$i"} =
  2019. $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
  2020. }
  2021. }
  2022. for (qw(id subject message printed emailed queued audittrail)) {
  2023. delete $form->{$_};
  2024. }
  2025. &display_form;
  2026. }
  2027. sub backorder_exchangerate {
  2028. my ( $orddate, $buysell ) = @_;
  2029. $form->header;
  2030. print qq|
  2031. <body>
  2032. <form method="post" action="$form->{script}">
  2033. |;
  2034. # delete action variable
  2035. for (qw(action nextsub exchangerate)) { delete $form->{$_} }
  2036. $form->hide_form;
  2037. $form->{title} = $locale->text('Add Exchange Rate');
  2038. print qq|
  2039. <input type="hidden" name="exchangeratedate" value="$orddate">
  2040. <input type="hidden" name="buysell" value="$buysell">
  2041. <table width="100%">
  2042. <tr><th class="listtop">$form->{title}</th></tr>
  2043. <tr height="5"></tr>
  2044. <tr>
  2045. <td>
  2046. <table>
  2047. <tr>
  2048. <th align="right">| . $locale->text('Currency') . qq|</th>
  2049. <td>$form->{currency}</td>
  2050. </tr>
  2051. <tr>
  2052. <th align="right">| . $locale->text('Date') . qq|</th>
  2053. <td>$orddate</td>
  2054. </tr>
  2055. <tr>
  2056. <th align="right">| . $locale->text('Exchange Rate') . qq|</th>
  2057. <td><input name="exchangerate" size="11"></td>
  2058. </tr>
  2059. </table>
  2060. </td>
  2061. </tr>
  2062. </table>
  2063. <hr size="3" noshade>
  2064. <br>
  2065. <input type="hidden" name="nextsub" value="save_exchangerate">
  2066. <button name="action" class="submit" type="submit" value="continue">|
  2067. . $locale->text('Continue')
  2068. . qq|</button>
  2069. </form>
  2070. </body>
  2071. </html>
  2072. |;
  2073. }
  2074. sub save_exchangerate {
  2075. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') );
  2076. $form->{exchangerate} =
  2077. $form->parse_amount( \%myconfig, $form->{exchangerate} );
  2078. $form->save_exchangerate( \%myconfig, $form->{currency},
  2079. $form->{exchangeratedate},
  2080. $form->{exchangerate}, $form->{buysell} );
  2081. &invoice;
  2082. }
  2083. sub create_backorder {
  2084. $form->{shipped} = 1;
  2085. # figure out if we need to create a backorder
  2086. # items aren't saved if qty != 0
  2087. $dec1 = $dec2 = 0;
  2088. for $i ( 1 .. $form->{rowcount} ) {
  2089. ($dec) = ( $form->{"qty_$i"} =~ /\.(\d+)/ );
  2090. $dec = length $dec;
  2091. $dec1 = ( $dec > $dec1 ) ? $dec : $dec1;
  2092. ($dec) = ( $form->{"ship_$i"} =~ /\.(\d+)/ );
  2093. $dec = length $dec;
  2094. $dec2 = ( $dec > $dec2 ) ? $dec : $dec2;
  2095. $totalqty += $qty = $form->{"qty_$i"};
  2096. $totalship += $ship = $form->{"ship_$i"};
  2097. $form->{"qty_$i"} = $qty - $ship;
  2098. }
  2099. $totalqty = $form->round_amount( $totalqty, $dec1 );
  2100. $totalship = $form->round_amount( $totalship, $dec2 );
  2101. if ( $totalship == 0 ) {
  2102. for ( 1 .. $form->{rowcount} ) {
  2103. $form->{"ship_$_"} = $form->{"qty_$_"};
  2104. }
  2105. $form->{ordtotal} = 0;
  2106. $form->{shipped} = 0;
  2107. return;
  2108. }
  2109. if ( $totalqty == $totalship ) {
  2110. for ( 1 .. $form->{rowcount} ) {
  2111. $form->{"qty_$_"} = $form->{"ship_$_"};
  2112. }
  2113. $form->{ordtotal} = 0;
  2114. return;
  2115. }
  2116. @flds =
  2117. 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);
  2118. for $i ( 1 .. $form->{rowcount} ) {
  2119. for (qw(qty sellprice discount)) {
  2120. $form->{"${_}_$i"} =
  2121. $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
  2122. }
  2123. $form->{"oldship_$i"} = $form->{"ship_$i"};
  2124. $form->{"ship_$i"} = 0;
  2125. }
  2126. # clear flags
  2127. for (qw(id subject message cc bcc printed emailed queued audittrail)) {
  2128. delete $form->{$_};
  2129. }
  2130. OE->save( \%myconfig, \%$form );
  2131. # rebuild rows for invoice
  2132. @a = ();
  2133. $count = 0;
  2134. for $i ( 1 .. $form->{rowcount} ) {
  2135. $form->{"qty_$i"} = $form->{"oldship_$i"};
  2136. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  2137. $form->{"orderitems_id_$i"} = "";
  2138. if ( $form->{"qty_$i"} ) {
  2139. push @a, {};
  2140. $j = $#a;
  2141. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2142. $count++;
  2143. }
  2144. }
  2145. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  2146. $form->{rowcount} = $count;
  2147. }
  2148. sub save_as_new {
  2149. for (qw(closed id printed emailed queued)) { delete $form->{$_} }
  2150. &save;
  2151. }
  2152. sub print_and_save_as_new {
  2153. for (qw(closed id printed emailed queued)) { delete $form->{$_} }
  2154. &print_and_save;
  2155. }
  2156. sub ship_receive {
  2157. &order_links;
  2158. &prepare_order;
  2159. OE->get_warehouses( \%myconfig, \%$form );
  2160. # warehouse
  2161. if ( @{ $form->{all_warehouse} } ) {
  2162. $form->{selectwarehouse} = "<option>\n";
  2163. for ( @{ $form->{all_warehouse} } ) {
  2164. $form->{selectwarehouse} .=
  2165. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  2166. }
  2167. if ( $form->{warehouse} ) {
  2168. $form->{selectwarehouse} = qq|<option value="$form->{warehouse}">|;
  2169. $form->{warehouse} =~ s/--.*//;
  2170. $form->{selectwarehouse} .= $form->{warehouse};
  2171. }
  2172. }
  2173. $form->{shippingdate} = $form->current_date( \%myconfig );
  2174. $form->{"$form->{vc}"} =~ s/--.*//;
  2175. $form->{"old$form->{vc}"} =
  2176. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  2177. @flds = ();
  2178. @a = ();
  2179. $count = 0;
  2180. foreach $key ( keys %$form ) {
  2181. if ( $key =~ /_1$/ ) {
  2182. $key =~ s/_1//;
  2183. push @flds, $key;
  2184. }
  2185. }
  2186. for $i ( 1 .. $form->{rowcount} ) {
  2187. # undo formatting from prepare_order
  2188. for (qw(qty ship)) {
  2189. $form->{"${_}_$i"} =
  2190. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  2191. }
  2192. $n = ( $form->{"qty_$i"} -= $form->{"ship_$i"} );
  2193. if ( abs($n) > 0 ) {
  2194. $form->{"ship_$i"} = "";
  2195. $form->{"serialnumber_$i"} = "";
  2196. push @a, {};
  2197. $j = $#a;
  2198. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  2199. $count++;
  2200. }
  2201. }
  2202. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  2203. $form->{rowcount} = $count;
  2204. &display_ship_receive;
  2205. }
  2206. sub display_ship_receive {
  2207. $vclabel = ucfirst $form->{vc};
  2208. $vclabel = $locale->text($vclabel);
  2209. $form->{rowcount}++;
  2210. if ( $form->{vc} eq 'customer' ) {
  2211. $form->{title} = $locale->text('Ship Merchandise');
  2212. $shipped = $locale->text('Shipping Date');
  2213. }
  2214. else {
  2215. $form->{title} = $locale->text('Receive Merchandise');
  2216. $shipped = $locale->text('Date Received');
  2217. }
  2218. # set option selected
  2219. for (qw(warehouse employee)) {
  2220. $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
  2221. $form->{"select$_"} =~ s/ selected//;
  2222. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  2223. }
  2224. $warehouse = qq|
  2225. <tr>
  2226. <th align="right">| . $locale->text('Warehouse') . qq|</th>
  2227. <td><select name="warehouse">$form->{selectwarehouse}</select></td>
  2228. <input type="hidden" name="selectwarehouse" value="|
  2229. . $form->escape( $form->{selectwarehouse}, 1 ) . qq|">
  2230. </tr>
  2231. | if $form->{selectwarehouse};
  2232. $employee = qq|
  2233. <tr>
  2234. <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
  2235. <td><select name="employee">$form->{selectemployee}</select></td>
  2236. <input type="hidden" name="selectemployee" value="|
  2237. . $form->escape( $form->{selectemployee}, 1 ) . qq|">
  2238. </tr>
  2239. |;
  2240. $form->header;
  2241. print qq|
  2242. <body>
  2243. <form method="post" action=$form->{script}>
  2244. <input type="hidden" name="display_form" value="display_ship_receive">
  2245. |;
  2246. $form->hide_form(qw(id type media format printed emailed queued vc));
  2247. print qq|
  2248. <input type="hidden" name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
  2249. <table width="100%">
  2250. <tr class="listtop">
  2251. <th class="listtop">$form->{title}</th>
  2252. </tr>
  2253. <tr height="5"></tr>
  2254. <tr>
  2255. <td>
  2256. <table width="100%">
  2257. <tr valign="top">
  2258. <td>
  2259. <table width="100%">
  2260. <tr>
  2261. <th align="right">$vclabel</th>
  2262. <td colspan="3">$form->{$form->{vc}}</td>
  2263. <input type="hidden" name="$form->{vc}" value="$form->{$form->{vc}}">
  2264. <input type="hidden" name="$form->{vc}_id" value="$form->{"$form->{vc}_id"}">
  2265. </tr>
  2266. $department
  2267. <tr>
  2268. <th align="right">| . $locale->text('Shipping Point') . qq|</th>
  2269. <td colspan="3">
  2270. <input name="shippingpoint" size="35" value="$form->{shippingpoint}">
  2271. </tr>
  2272. <tr>
  2273. <th align="right">| . $locale->text('Ship via') . qq|</th>
  2274. <td colspan="3">
  2275. <input name="shipvia" size="35" value="$form->{shipvia}">
  2276. </tr>
  2277. $warehouse
  2278. </table>
  2279. </td>
  2280. <td align="right">
  2281. <table>
  2282. $employee
  2283. <tr>
  2284. <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
  2285. <td>$form->{ordnumber}</td>
  2286. <input type="hidden" name="ordnumber" value="$form->{ordnumber}">
  2287. </tr>
  2288. <tr>
  2289. <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
  2290. <td>$form->{transdate}</td>
  2291. <input type="hidden" name="transdate" value="$form->{transdate}">
  2292. </tr>
  2293. <tr>
  2294. <th align="right" nowrap>| . $locale->text('PO Number') . qq|</th>
  2295. <td>$form->{ponumber}</td>
  2296. <input type="hidden" name="ponumber" value="$form->{ponumber}">
  2297. </tr>
  2298. <tr>
  2299. <th align="right" nowrap>$shipped</th>
  2300. <td><input name="shippingdate" size="11" value="$form->{shippingdate}"></td>
  2301. </tr>
  2302. </table>
  2303. </td>
  2304. </tr>
  2305. </table>
  2306. </td>
  2307. </tr>
  2308. |;
  2309. $form->hide_form(
  2310. qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc)
  2311. );
  2312. @column_index = qw(partnumber);
  2313. if ( $form->{type} eq "ship_order" ) {
  2314. $column_data{ship} =
  2315. qq|<th class="listheading">| . $locale->text('Ship') . qq|</th>|;
  2316. }
  2317. if ( $form->{type} eq "receive_order" ) {
  2318. $column_data{ship} =
  2319. qq|<th class="listheading">| . $locale->text('Recd') . qq|</th>|;
  2320. $column_data{sku} =
  2321. qq|<th class="listheading">| . $locale->text('SKU') . qq|</th>|;
  2322. push @column_index, "sku";
  2323. }
  2324. push @column_index, qw(description qty ship unit bin serialnumber);
  2325. my $colspan = $#column_index + 1;
  2326. $column_data{partnumber} =
  2327. qq|<th class="listheading" nowrap>| . $locale->text('Number') . qq|</th>|;
  2328. $column_data{description} =
  2329. qq|<th class="listheading" nowrap>|
  2330. . $locale->text('Description')
  2331. . qq|</th>|;
  2332. $column_data{qty} =
  2333. qq|<th class="listheading" nowrap>| . $locale->text('Qty') . qq|</th>|;
  2334. $column_data{unit} =
  2335. qq|<th class="listheading" nowrap>| . $locale->text('Unit') . qq|</th>|;
  2336. $column_data{bin} =
  2337. qq|<th class="listheading" nowrap>| . $locale->text('Bin') . qq|</th>|;
  2338. $column_data{serialnumber} =
  2339. qq|<th class="listheading" nowrap>|
  2340. . $locale->text('Serial No.')
  2341. . qq|</th>|;
  2342. print qq|
  2343. <tr>
  2344. <td>
  2345. <table width="100%">
  2346. <tr class="listheading">|;
  2347. for (@column_index) { print "\n$column_data{$_}" }
  2348. print qq|
  2349. </tr>
  2350. |;
  2351. for $i ( 1 .. $form->{rowcount} - 1 ) {
  2352. # undo formatting
  2353. $form->{"ship_$i"} =
  2354. $form->parse_amount( \%myconfig, $form->{"ship_$i"} );
  2355. for (qw(partnumber sku description unit bin serialnumber)) {
  2356. $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
  2357. }
  2358. $description = $form->{"description_$i"};
  2359. $description =~ s/\r?\n/<br>/g;
  2360. $column_data{partnumber} =
  2361. qq|<td>$form->{"partnumber_$i"}<input type="hidden" name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
  2362. $column_data{sku} =
  2363. qq|<td>$form->{"sku_$i"}<input type="hidden" name="sku_$i" value="$form->{"sku_$i"}"></td>|;
  2364. $column_data{description} =
  2365. qq|<td>$description<input type="hidden" name="description_$i" value="$form->{"description_$i"}"></td>|;
  2366. $column_data{qty} =
  2367. qq|<td align="right">|
  2368. . $form->format_amount( \%myconfig, $form->{"qty_$i"} )
  2369. . qq|<input type="hidden" name="qty_$i" value="$form->{"qty_$i"}"></td>|;
  2370. $column_data{ship} =
  2371. qq|<td align="right"><input name="ship_$i" size="5" value="|
  2372. . $form->format_amount( \%myconfig, $form->{"ship_$i"} )
  2373. . qq|"></td>|;
  2374. $column_data{unit} =
  2375. qq|<td>$form->{"unit_$i"}<input type="hidden" name="unit_$i" value="$form->{"unit_$i"}"></td>|;
  2376. $column_data{bin} =
  2377. qq|<td>$form->{"bin_$i"}<input type="hidden" name="bin_$i" value="$form->{"bin_$i"}"></td>|;
  2378. $column_data{serialnumber} =
  2379. qq|<td><input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}"></td>|;
  2380. print qq|
  2381. <tr valign="top">|;
  2382. for (@column_index) { print "\n$column_data{$_}" }
  2383. print qq|
  2384. </tr>
  2385. |;
  2386. $form->hide_form( "orderitems_id_$i", "id_$i", "partsgroup_$i" );
  2387. }
  2388. print qq|
  2389. </table>
  2390. </td>
  2391. </tr>
  2392. <tr>
  2393. <td><hr size="3" noshade></td>
  2394. </tr>
  2395. <tr>
  2396. <td>
  2397. |;
  2398. $form->{copies} = 1;
  2399. &print_options;
  2400. print qq|
  2401. </td>
  2402. </tr>
  2403. </table>
  2404. <br>
  2405. |;
  2406. # type="submit" $locale->text('Done')
  2407. %button = (
  2408. 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  2409. 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
  2410. 'ship_to' =>
  2411. { ndx => 4, key => 'T', value => $locale->text('Ship to') },
  2412. 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  2413. 'done' => { ndx => 11, key => 'D', value => $locale->text('Done') },
  2414. );
  2415. for ( "update", "print" ) { $form->print_button( \%button, $_ ) }
  2416. if ( $form->{type} eq 'ship_order' ) {
  2417. for ( 'ship_to', 'e_mail' ) { $form->print_button( \%button, $_ ) }
  2418. }
  2419. $form->print_button( \%button, 'done' );
  2420. if ( $form->{lynx} ) {
  2421. require "bin/menu.pl";
  2422. &menubar;
  2423. }
  2424. $form->hide_form(qw(rowcount callback path login sessionid));
  2425. print qq|
  2426. </form>
  2427. </body>
  2428. </html>
  2429. |;
  2430. }
  2431. sub done {
  2432. if ( $form->{type} eq 'ship_order' ) {
  2433. $form->isblank( "shippingdate",
  2434. $locale->text('Shipping Date missing!') );
  2435. }
  2436. else {
  2437. $form->isblank( "shippingdate",
  2438. $locale->text('Date received missing!') );
  2439. }
  2440. $total = 0;
  2441. for ( 1 .. $form->{rowcount} - 1 ) {
  2442. $total += $form->{"ship_$_"} =
  2443. $form->parse_amount( \%myconfig, $form->{"ship_$_"} );
  2444. }
  2445. $form->error( $locale->text('Nothing entered!') ) unless $total;
  2446. if ( OE->save_inventory( \%myconfig, \%$form ) ) {
  2447. $form->redirect( $locale->text('Inventory saved!') );
  2448. }
  2449. else {
  2450. $form->error( $locale->text('Could not save!') );
  2451. }
  2452. }
  2453. sub search_transfer {
  2454. OE->get_warehouses( \%myconfig, \%$form );
  2455. # warehouse
  2456. if ( @{ $form->{all_warehouse} } ) {
  2457. $form->{selectwarehouse} = "<option>\n";
  2458. $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|
  2459. if $form->{warehouse_id};
  2460. for ( @{ $form->{all_warehouse} } ) {
  2461. $form->{selectwarehouse} .=
  2462. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  2463. }
  2464. }
  2465. else {
  2466. $form->error( $locale->text('Nothing to transfer!') );
  2467. }
  2468. $form->get_partsgroup( \%myconfig, { searchitems => 'part' } );
  2469. if ( @{ $form->{all_partsgroup} } ) {
  2470. $form->{selectpartsgroup} = "<option>\n";
  2471. for ( @{ $form->{all_partsgroup} } ) {
  2472. $form->{selectpartsgroup} .=
  2473. qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|;
  2474. }
  2475. }
  2476. $form->{title} = $locale->text('Transfer Inventory');
  2477. $form->header;
  2478. print qq|
  2479. <body>
  2480. <form method="post" action="$form->{script}">
  2481. <table width="100%">
  2482. <tr>
  2483. <th class="listtop">$form->{title}</th>
  2484. </tr>
  2485. <tr height="5"></tr>
  2486. <tr>
  2487. <td>
  2488. <table>
  2489. <tr>
  2490. <th align="right" nowrap>| . $locale->text('Transfer from') . qq|</th>
  2491. <td><select name="fromwarehouse">$form->{selectwarehouse}</select></td>
  2492. </tr>
  2493. <tr>
  2494. <th align="right" nowrap>| . $locale->text('Transfer to') . qq|</th>
  2495. <td><select name="towarehouse">$form->{selectwarehouse}</select></td>
  2496. </tr>
  2497. <tr>
  2498. <th align="right" nowrap="true">| . $locale->text('Part Number') . qq|</th>
  2499. <td><input name="partnumber" size="20"></td>
  2500. </tr>
  2501. <tr>
  2502. <th align="right" nowrap="true">| . $locale->text('Description') . qq|</th>
  2503. <td><input name="description" size="40"></td>
  2504. </tr>
  2505. <tr>
  2506. <th align="right" nowrap>| . $locale->text('Group') . qq|</th>
  2507. <td><select name="partsgroup">$form->{selectpartsgroup}</select></td>
  2508. </tr>
  2509. </table>
  2510. </td>
  2511. </tr>
  2512. <tr>
  2513. <td><hr size="3" noshade></td>
  2514. </tr>
  2515. </table>
  2516. <br>
  2517. <input type="hidden" name="nextsub" value="list_transfer">
  2518. <button class="submit" type="submit" name="action" value="continue">|
  2519. . $locale->text('Continue')
  2520. . qq|</button>|;
  2521. $form->hide_form(qw(path login sessionid));
  2522. print qq|
  2523. </form>
  2524. |;
  2525. if ( $form->{lynx} ) {
  2526. require "bin/menu.pl";
  2527. &menubar;
  2528. }
  2529. print qq|
  2530. </body>
  2531. </html>
  2532. |;
  2533. }
  2534. sub list_transfer {
  2535. $form->{sort} = "partnumber" unless $form->{sort};
  2536. OE->get_inventory( \%myconfig, \%$form );
  2537. # construct href
  2538. $href = "$form->{script}?action=list_transfer";
  2539. for (qw(direction oldsort path login sessionid)) {
  2540. $href .= "&$_=$form->{$_}";
  2541. }
  2542. for (qw(partnumber fromwarehouse towarehouse description partsgroup)) {
  2543. $href .= "&$_=" . $form->escape( $form->{$_} );
  2544. }
  2545. $form->sort_order();
  2546. # construct callback
  2547. $callback = "$form->{script}?action=list_transfer";
  2548. for (qw(direction oldsort path login sessionid)) {
  2549. $callback .= "&$_=$form->{$_}";
  2550. }
  2551. for (qw(partnumber fromwarehouse towarehouse description partsgroup)) {
  2552. $callback .= "&$_=" . $form->escape( $form->{$_}, 1 );
  2553. }
  2554. @column_index =
  2555. $form->sort_columns(
  2556. qw(partnumber description partsgroup make model fromwarehouse qty towarehouse transfer)
  2557. );
  2558. $column_header{partnumber} =
  2559. qq|<th><a class="listheading" href="$href&sort=partnumber">|
  2560. . $locale->text('Part Number')
  2561. . qq|</a></th>|;
  2562. $column_header{description} =
  2563. qq|<th><a class="listheading" href="$href&sort=description">|
  2564. . $locale->text('Description')
  2565. . qq|</a></th>|;
  2566. $column_header{partsgroup} =
  2567. qq|<th><a class="listheading" href="$href&sort=partsgroup">|
  2568. . $locale->text('Group')
  2569. . qq|</a></th>|;
  2570. $column_header{fromwarehouse} =
  2571. qq|<th><a class="listheading" href="$href&sort=warehouse">|
  2572. . $locale->text('From')
  2573. . qq|</a></th>|;
  2574. $column_header{towarehouse} =
  2575. qq|<th class="listheading">| . $locale->text('To') . qq|</th>|;
  2576. $column_header{qty} =
  2577. qq|<th class="listheading">| . $locale->text('Qty') . qq|</a></th>|;
  2578. $column_header{transfer} =
  2579. qq|<th class="listheading">| . $locale->text('Transfer') . qq|</a></th>|;
  2580. ( $warehouse, $warehouse_id ) = split /--/, $form->{fromwarehouse};
  2581. if ( $form->{fromwarehouse} ) {
  2582. $option .= "\n<br>";
  2583. $option .= $locale->text('From Warehouse') . " : $warehouse";
  2584. }
  2585. ( $warehouse, $warehouse_id ) = split /--/, $form->{towarehouse};
  2586. if ( $form->{towarehouse} ) {
  2587. $option .= "\n<br>";
  2588. $option .= $locale->text('To Warehouse') . " : $warehouse";
  2589. }
  2590. if ( $form->{partnumber} ) {
  2591. $option .= "\n<br>" if ($option);
  2592. $option .= $locale->text('Part Number') . " : $form->{partnumber}";
  2593. }
  2594. if ( $form->{description} ) {
  2595. $option .= "\n<br>" if ($option);
  2596. $option .= $locale->text('Description') . " : $form->{description}";
  2597. }
  2598. if ( $form->{partsgroup} ) {
  2599. ($partsgroup) = split /--/, $form->{partsgroup};
  2600. $option .= "\n<br>" if ($option);
  2601. $option .= $locale->text('Group') . " : $partsgroup";
  2602. }
  2603. $form->{title} = $locale->text('Transfer Inventory');
  2604. $callback .= "&sort=$form->{sort}";
  2605. $form->header;
  2606. print qq|
  2607. <body>
  2608. <form method="post" action="$form->{script}">
  2609. <input type="hidden" name="warehouse_id" value="$warehouse_id">
  2610. <table width="100%">
  2611. <tr>
  2612. <th class="listtop">$form->{title}</th>
  2613. </tr>
  2614. <tr height="5"></tr>
  2615. <tr>
  2616. <td>$option</td>
  2617. </tr>
  2618. <tr>
  2619. <td>
  2620. <table width="100%">
  2621. <tr class="listheading">|;
  2622. for (@column_index) { print "\n$column_header{$_}" }
  2623. print qq|
  2624. </tr>
  2625. |;
  2626. if ( @{ $form->{all_inventory} } ) {
  2627. $sameitem = $form->{all_inventory}->[0]->{ $form->{sort} };
  2628. }
  2629. $i = 0;
  2630. foreach $ref ( @{ $form->{all_inventory} } ) {
  2631. $i++;
  2632. $column_data{partnumber} =
  2633. qq|<td><input type="hidden" name="id_$i" value="$ref->{id}">$ref->{partnumber}</td>|;
  2634. $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
  2635. $column_data{partsgroup} = "<td>$ref->{partsgroup}&nbsp;</td>";
  2636. $column_data{fromwarehouse} =
  2637. qq|<td><input type="hidden" name="warehouse_id_$i" value="$ref->{warehouse_id}">$ref->{warehouse}&nbsp;</td>|;
  2638. $column_data{towarehouse} = qq|<td>$warehouse&nbsp;</td>|;
  2639. $column_data{qty} =
  2640. qq|<td><input type="hidden" name="qty_$i" value="$ref->{qty}">|
  2641. . $form->format_amount( \%myconfig, $ref->{qty} )
  2642. . qq|</td>|;
  2643. $column_data{transfer} = qq|<td><input name="transfer_$i" size="4"></td>|;
  2644. $j++;
  2645. $j %= 2;
  2646. print qq|
  2647. <tr class="listrow$j">|;
  2648. for (@column_index) { print "\n$column_data{$_}" }
  2649. print qq|
  2650. </tr>
  2651. |;
  2652. }
  2653. print qq|
  2654. </table>
  2655. </td>
  2656. </tr>
  2657. <tr>
  2658. <td><hr size="3" noshade></td>
  2659. </tr>
  2660. </table>
  2661. <br>
  2662. <input name="callback" type="hidden" value="$callback">
  2663. <input type="hidden" name="rowcount" value="$i">
  2664. |;
  2665. $form->{action} = "transfer";
  2666. $form->hide_form(qw(path login sessionid action));
  2667. print qq|
  2668. <button class="submit" type="submit" name="action" value="transfer">|
  2669. . $locale->text('Transfer')
  2670. . qq|</button>|;
  2671. if ( $form->{lynx} ) {
  2672. require "bin/menu.pl";
  2673. &menubar;
  2674. }
  2675. print qq|
  2676. </form>
  2677. </body>
  2678. </html>
  2679. |;
  2680. }
  2681. sub transfer {
  2682. if ( OE->transfer( \%myconfig, \%$form ) ) {
  2683. $form->redirect( $locale->text('Inventory transferred!') );
  2684. }
  2685. else {
  2686. $form->error( $locale->text('Could not transfer Inventory!') );
  2687. }
  2688. }
  2689. sub generate_purchase_orders {
  2690. for ( 1 .. $form->{rowcount} ) {
  2691. if ( $form->{"ndx_$_"} ) {
  2692. $ok = 1;
  2693. last;
  2694. }
  2695. }
  2696. $form->error( $locale->text('Nothing selected!') ) unless $ok;
  2697. ( $null, $argv ) = split /\?/, $form->{callback};
  2698. for ( split /\&/, $argv ) {
  2699. ( $key, $value ) = split /=/, $_;
  2700. $form->{$key} = $value;
  2701. }
  2702. $form->{vc} = "vendor";
  2703. OE->get_soparts( \%myconfig, \%$form );
  2704. # flatten array
  2705. $i = 0;
  2706. foreach $parts_id (
  2707. sort {
  2708. $form->{orderitems}{$a}{partnumber}
  2709. cmp $form->{orderitems}{$b}{partnumber}
  2710. } keys %{ $form->{orderitems} }
  2711. )
  2712. {
  2713. $required = $form->{orderitems}{$parts_id}{required};
  2714. next if $required <= 0;
  2715. $i++;
  2716. $form->{"required_$i"} = $form->format_amount( \%myconfig, $required );
  2717. $form->{"id_$i"} = $parts_id;
  2718. $form->{"sku_$i"} = $form->{orderitems}{$parts_id}{partnumber};
  2719. $form->{"curr_$i"} = $form->{defaultcurrency};
  2720. $form->{"description_$i"} = $form->{orderitems}{$parts_id}{description};
  2721. $form->{"lastcost_$i"} =
  2722. $form->format_amount( \%myconfig,
  2723. $form->{orderitems}{$parts_id}{lastcost}, 2 );
  2724. $form->{"qty_$i"} = $required;
  2725. if ( exists $form->{orderitems}{$parts_id}{"parts$form->{vc}"} ) {
  2726. $form->{"qty_$i"} = "";
  2727. foreach $id (
  2728. sort {
  2729. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$a}
  2730. {lastcost} * $form->{ $form->{orderitems}{$parts_id}
  2731. {"parts$form->{vc}"}{$a}{curr} } <=>
  2732. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$b}
  2733. {lastcost} * $form->{ $form->{orderitems}{$parts_id}
  2734. {"parts$form->{vc}"}{$b}{curr} }
  2735. } keys %{ $form->{orderitems}{$parts_id}{"parts$form->{vc}"} }
  2736. )
  2737. {
  2738. $i++;
  2739. $form->{"qty_$i"} =
  2740. $form->format_amount( \%myconfig, $required );
  2741. $form->{"description_$i"} = "";
  2742. for (qw(partnumber curr)) {
  2743. $form->{"${_}_$i"} =
  2744. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2745. {$_};
  2746. }
  2747. $form->{"lastcost_$i"} = $form->format_amount(
  2748. \%myconfig,
  2749. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2750. {lastcost},
  2751. 2
  2752. );
  2753. $form->{"leadtime_$i"} = $form->format_amount( \%myconfig,
  2754. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2755. {leadtime} );
  2756. $form->{"fx_$i"} = $form->format_amount(
  2757. \%myconfig,
  2758. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2759. {lastcost} * $form->{
  2760. $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
  2761. {curr}
  2762. },
  2763. 2
  2764. );
  2765. $form->{"id_$i"} = $parts_id;
  2766. $form->{"$form->{vc}_$i"} =
  2767. qq|$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{name}--$id|;
  2768. $form->{"$form->{vc}_id_$i"} = $id;
  2769. $required = "";
  2770. }
  2771. }
  2772. $form->{"blankrow_$i"} = 1;
  2773. }
  2774. $form->{rowcount} = $i;
  2775. &po_orderitems;
  2776. }
  2777. sub po_orderitems {
  2778. @column_index =
  2779. qw(sku description partnumber leadtime fx lastcost curr required qty name);
  2780. $column_header{sku} =
  2781. qq|<th class="listheading">| . $locale->text('SKU') . qq|</th>|;
  2782. $column_header{partnumber} =
  2783. qq|<th class="listheading">| . $locale->text('Part Number') . qq|</th>|;
  2784. $column_header{description} =
  2785. qq|<th class="listheading">| . $locale->text('Description') . qq|</th>|;
  2786. $column_header{name} =
  2787. qq|<th class="listheading">| . $locale->text('Vendor') . qq|</th>|;
  2788. $column_header{qty} =
  2789. qq|<th class="listheading">| . $locale->text('Order') . qq|</th>|;
  2790. $column_header{required} =
  2791. qq|<th class="listheading">| . $locale->text('Req') . qq|</th>|;
  2792. $column_header{lastcost} =
  2793. qq|<th class="listheading">| . $locale->text('Cost') . qq|</th>|;
  2794. $column_header{fx} = qq|<th class="listheading">&nbsp;</th>|;
  2795. $column_header{leadtime} =
  2796. qq|<th class="listheading">| . $locale->text('Lead') . qq|</th>|;
  2797. $column_header{curr} =
  2798. qq|<th class="listheading">| . $locale->text('Curr') . qq|</th>|;
  2799. $form->{title} = $locale->text('Generate Purchase Orders');
  2800. $form->header;
  2801. print qq|
  2802. <body>
  2803. <form method="post" action="$form->{script}">
  2804. <table width="100%">
  2805. <tr>
  2806. <th class="listtop">$form->{title}</th>
  2807. </tr>
  2808. <tr height="5"></tr>
  2809. <tr>
  2810. <td>
  2811. <table width="100%">
  2812. <tr class="listheading">|;
  2813. for (@column_index) { print "\n$column_header{$_}" }
  2814. print qq|
  2815. </tr>
  2816. |;
  2817. for $i ( 1 .. $form->{rowcount} ) {
  2818. for (qw(sku partnumber description curr)) {
  2819. $column_data{$_} = qq|<td>$form->{"${_}_$i"}&nbsp;</td>|;
  2820. }
  2821. for (qw(required leadtime lastcost fx)) {
  2822. $column_data{$_} = qq|<td align="right">$form->{"${_}_$i"}</td>|;
  2823. }
  2824. $column_data{qty} =
  2825. qq|<td align="right"><input name="qty_$i" size="6" value="$form->{"qty_$i"}"></td>|;
  2826. if ( $form->{"$form->{vc}_id_$i"} ) {
  2827. $name = $form->{"$form->{vc}_$i"};
  2828. $name =~ s/--.*//;
  2829. $column_data{name} = qq|<td>$name</td>|;
  2830. $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" );
  2831. }
  2832. else {
  2833. $column_data{name} =
  2834. qq|<td><input name="ndx_$i" class="checkbox" type="checkbox" value="1"></td>|;
  2835. }
  2836. $form->hide_form( map { "${_}_$i" }
  2837. qw(id sku partnumber description curr required leadtime lastcost fx name blankrow)
  2838. );
  2839. $blankrow = $form->{"blankrow_$i"};
  2840. BLANKROW:
  2841. $j++;
  2842. $j %= 2;
  2843. print "
  2844. <tr class=listrow$j>";
  2845. for (@column_index) { print "\n$column_data{$_}" }
  2846. print qq|
  2847. </tr>
  2848. |;
  2849. if ($blankrow) {
  2850. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2851. $blankrow = 0;
  2852. goto BLANKROW;
  2853. }
  2854. }
  2855. print qq|
  2856. </table>
  2857. </td>
  2858. </tr>
  2859. <tr>
  2860. <td><hr size="3" noshade></td>
  2861. </tr>
  2862. </table>
  2863. <br>
  2864. |;
  2865. $form->hide_form(
  2866. qw(callback department ponumber path login sessionid employee_id vc nextsub rowcount type)
  2867. );
  2868. print qq|
  2869. <button class="submit" type="submit" name="action" value="generate_orders">|
  2870. . $locale->text('Generate Orders')
  2871. . qq|</button>|;
  2872. print qq|
  2873. <button class="submit" type="submit" name="action" value="select_vendor">|
  2874. . $locale->text('Select Vendor')
  2875. . qq|</button>|;
  2876. if ( $form->{lynx} ) {
  2877. require "bin/menu.pl";
  2878. &menubar;
  2879. }
  2880. print qq|
  2881. </form>
  2882. </body>
  2883. </html>
  2884. |;
  2885. }
  2886. sub generate_orders {
  2887. if ( OE->generate_orders( \%myconfig, \%$form ) ) {
  2888. $form->redirect;
  2889. }
  2890. else {
  2891. $form->error( $locale->text('Order generation failed!') );
  2892. }
  2893. }
  2894. sub consolidate_orders {
  2895. for ( 1 .. $form->{rowcount} ) {
  2896. if ( $form->{"ndx_$_"} ) {
  2897. $ok = 1;
  2898. last;
  2899. }
  2900. }
  2901. $form->error( $locale->text('Nothing selected!') ) unless $ok;
  2902. ( $null, $argv ) = split /\?/, $form->{callback};
  2903. for ( split /\&/, $argv ) {
  2904. ( $key, $value ) = split /=/, $_;
  2905. $form->{$key} = $value;
  2906. }
  2907. if ( OE->consolidate_orders( \%myconfig, \%$form ) ) {
  2908. $form->redirect;
  2909. }
  2910. else {
  2911. $form->error( $locale->text('Order generation failed!') );
  2912. }
  2913. }
  2914. sub select_vendor {
  2915. for ( 1 .. $form->{rowcount} ) {
  2916. last if ( $ok = $form->{"ndx_$_"} );
  2917. }
  2918. $form->error( $locale->text('Nothing selected!') ) unless $ok;
  2919. $form->header;
  2920. print qq|
  2921. <body onload="document.forms[0].vendor.focus()">
  2922. <form method="post" action="$form->{script}">
  2923. <b>| . $locale->text('Vendor') . qq|</b> <input name="vendor" size="40">
  2924. |;
  2925. $form->{nextsub} = "vendor_selected";
  2926. $form->{action} = "vendor_selected";
  2927. $form->hide_form;
  2928. print qq|
  2929. <button class="submit" type="submit" name="action" value="continue">|
  2930. . $locale->text('Continue')
  2931. . qq|</button>
  2932. </form>
  2933. |;
  2934. if ( $form->{lynx} ) {
  2935. require "bin/menu.pl";
  2936. &menubar;
  2937. }
  2938. print qq|
  2939. </body>
  2940. </html>
  2941. |;
  2942. }
  2943. sub vendor_selected {
  2944. if (
  2945. (
  2946. $rv = $form->get_name( \%myconfig, $form->{vc}, $form->{transdate} )
  2947. ) > 1
  2948. )
  2949. {
  2950. &select_name( $form->{vc} );
  2951. exit;
  2952. }
  2953. if ( $rv == 1 ) {
  2954. for ( 1 .. $form->{rowcount} ) {
  2955. if ( $form->{"ndx_$_"} ) {
  2956. $form->{"$form->{vc}_id_$_"} = $form->{name_list}[0]->{id};
  2957. $form->{"$form->{vc}_$_"} =
  2958. "$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}";
  2959. }
  2960. }
  2961. }
  2962. else {
  2963. $msg = ucfirst $form->{vc} . " not on file!" unless $msg;
  2964. $form->error( $locale->text($msg) );
  2965. }
  2966. &po_orderitems;
  2967. }