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