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