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