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