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