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