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