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