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