summaryrefslogtreecommitdiff
path: root/bin/oe.pl
blob: f933b40bdc15733bfa0e033cee03a81709d4a248 (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}) or
  1544. $form->error("Locale not loaded: $!\n");
  1545. #$form->{charset} = $locale->encoding;
  1546. $form->{charset} = 'UTF-8';
  1547. $locale->encoding('UTF-8');
  1548. require "bin/$form->{script}";
  1549. # customized scripts
  1550. if (-f "bin/custom/$form->{script}") {
  1551. eval { require "bin/custom/$form->{script}"; };
  1552. }
  1553. # customized scripts for login
  1554. if (-f "bin/custom/$form->{login}_$form->{script}") {
  1555. eval { require "bin/custom/$form->{login}_$form->{script}"; };
  1556. }
  1557. for ("$form->{vc}", "currency") { $form->{"select$_"} = "" }
  1558. for (qw(currency oldcurrency employee department intnotes notes taxincluded)) { $temp{$_} = $form->{$_} }
  1559. &invoice_links;
  1560. $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
  1561. &prepare_invoice;
  1562. for (keys %temp) { $form->{$_} = $temp{$_} }
  1563. $form->{exchangerate} = "";
  1564. $form->{forex} = "";
  1565. $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
  1566. for $i (1 .. $form->{rowcount}) {
  1567. $form->{"deliverydate_$i"} = $form->{"reqdate_$i"};
  1568. for (qw(qty sellprice discount)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
  1569. }
  1570. for (qw(id subject message cc bcc printed emailed queued audittrail)) { delete $form->{$_} }
  1571. &display_form;
  1572. }
  1573. sub backorder_exchangerate {
  1574. my ($orddate, $buysell) = @_;
  1575. $form->header;
  1576. print qq|
  1577. <body>
  1578. <form method=post action=$form->{script}>
  1579. |;
  1580. # delete action variable
  1581. for (qw(action nextsub exchangerate)) { delete $form->{$_} }
  1582. $form->hide_form;
  1583. $form->{title} = $locale->text('Add Exchange Rate');
  1584. print qq|
  1585. <input type=hidden name=exchangeratedate value=$orddate>
  1586. <input type=hidden name=buysell value=$buysell>
  1587. <table width=100%>
  1588. <tr><th class=listtop>$form->{title}</th></tr>
  1589. <tr height="5"></tr>
  1590. <tr>
  1591. <td>
  1592. <table>
  1593. <tr>
  1594. <th align=right>|.$locale->text('Currency').qq|</th>
  1595. <td>$form->{currency}</td>
  1596. </tr>
  1597. <tr>
  1598. <th align=right>|.$locale->text('Date').qq|</th>
  1599. <td>$orddate</td>
  1600. </tr>
  1601. <tr>
  1602. <th align=right>|.$locale->text('Exchange Rate').qq|</th>
  1603. <td><input name=exchangerate size=11></td>
  1604. </tr>
  1605. </table>
  1606. </td>
  1607. </tr>
  1608. </table>
  1609. <hr size=3 noshade>
  1610. <br>
  1611. <input type=hidden name=nextsub value=save_exchangerate>
  1612. <button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
  1613. </form>
  1614. </body>
  1615. </html>
  1616. |;
  1617. }
  1618. sub save_exchangerate {
  1619. $form->isblank("exchangerate", $locale->text('Exchange rate missing!'));
  1620. $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
  1621. $form->save_exchangerate(\%myconfig, $form->{currency}, $form->{exchangeratedate}, $form->{exchangerate}, $form->{buysell});
  1622. &invoice;
  1623. }
  1624. sub create_backorder {
  1625. $form->{shipped} = 1;
  1626. # figure out if we need to create a backorder
  1627. # items aren't saved if qty != 0
  1628. $dec1 = $dec2 = 0;
  1629. for $i (1 .. $form->{rowcount}) {
  1630. ($dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
  1631. $dec = length $dec;
  1632. $dec1 = ($dec > $dec1) ? $dec : $dec1;
  1633. ($dec) = ($form->{"ship_$i"} =~ /\.(\d+)/);
  1634. $dec = length $dec;
  1635. $dec2 = ($dec > $dec2) ? $dec : $dec2;
  1636. $totalqty += $qty = $form->{"qty_$i"};
  1637. $totalship += $ship = $form->{"ship_$i"};
  1638. $form->{"qty_$i"} = $qty - $ship;
  1639. }
  1640. $totalqty = $form->round_amount($totalqty, $dec1);
  1641. $totalship = $form->round_amount($totalship, $dec2);
  1642. if ($totalship == 0) {
  1643. for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
  1644. $form->{ordtotal} = 0;
  1645. $form->{shipped} = 0;
  1646. return;
  1647. }
  1648. if ($totalqty == $totalship) {
  1649. for (1 .. $form->{rowcount}) { $form->{"qty_$_"} = $form->{"ship_$_"} }
  1650. $form->{ordtotal} = 0;
  1651. return;
  1652. }
  1653. @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);
  1654. for $i (1 .. $form->{rowcount}) {
  1655. for (qw(qty sellprice discount)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
  1656. $form->{"oldship_$i"} = $form->{"ship_$i"};
  1657. $form->{"ship_$i"} = 0;
  1658. }
  1659. # clear flags
  1660. for (qw(id subject message cc bcc printed emailed queued audittrail)) { delete $form->{$_} }
  1661. OE->save(\%myconfig, \%$form);
  1662. # rebuild rows for invoice
  1663. @a = ();
  1664. $count = 0;
  1665. for $i (1 .. $form->{rowcount}) {
  1666. $form->{"qty_$i"} = $form->{"oldship_$i"};
  1667. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  1668. $form->{"orderitems_id_$i"} = "";
  1669. if ($form->{"qty_$i"}) {
  1670. push @a, {};
  1671. $j = $#a;
  1672. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1673. $count++;
  1674. }
  1675. }
  1676. $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
  1677. $form->{rowcount} = $count;
  1678. }
  1679. sub save_as_new {
  1680. for (qw(closed id printed emailed queued)) { delete $form->{$_} }
  1681. &save;
  1682. }
  1683. sub print_and_save_as_new {
  1684. for (qw(closed id printed emailed queued)) { delete $form->{$_} }
  1685. &print_and_save;
  1686. }
  1687. sub ship_receive {
  1688. &order_links;
  1689. &prepare_order;
  1690. OE->get_warehouses(\%myconfig, \%$form);
  1691. # warehouse
  1692. if (@{ $form->{all_warehouse} }) {
  1693. $form->{selectwarehouse} = "<option>\n";
  1694. for (@{ $form->{all_warehouse} }) { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  1695. if ($form->{warehouse}) {
  1696. $form->{selectwarehouse} = qq|<option value="$form->{warehouse}">|;
  1697. $form->{warehouse} =~ s/--.*//;
  1698. $form->{selectwarehouse} .= $form->{warehouse};
  1699. }
  1700. }
  1701. $form->{shippingdate} = $form->current_date(\%myconfig);
  1702. $form->{"$form->{vc}"} =~ s/--.*//;
  1703. $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  1704. @flds = ();
  1705. @a = ();
  1706. $count = 0;
  1707. foreach $key (keys %$form) {
  1708. if ($key =~ /_1$/) {
  1709. $key =~ s/_1//;
  1710. push @flds, $key;
  1711. }
  1712. }
  1713. for $i (1 .. $form->{rowcount}) {
  1714. # undo formatting from prepare_order
  1715. for (qw(qty ship)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  1716. $n = ($form->{"qty_$i"} -= $form->{"ship_$i"});
  1717. if (abs($n) > 0) {
  1718. $form->{"ship_$i"} = "";
  1719. $form->{"serialnumber_$i"} = "";
  1720. push @a, {};
  1721. $j = $#a;
  1722. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1723. $count++;
  1724. }
  1725. }
  1726. $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
  1727. $form->{rowcount} = $count;
  1728. &display_ship_receive;
  1729. }
  1730. sub display_ship_receive {
  1731. $vclabel = ucfirst $form->{vc};
  1732. $vclabel = $locale->text($vclabel);
  1733. $form->{rowcount}++;
  1734. if ($form->{vc} eq 'customer') {
  1735. $form->{title} = $locale->text('Ship Merchandise');
  1736. $shipped = $locale->text('Shipping Date');
  1737. } else {
  1738. $form->{title} = $locale->text('Receive Merchandise');
  1739. $shipped = $locale->text('Date Received');
  1740. }
  1741. # set option selected
  1742. for (qw(warehouse employee)) {
  1743. $form->{"select$_"} = $form->unescape($form->{"select$_"});
  1744. $form->{"select$_"} =~ s/ selected//;
  1745. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  1746. }
  1747. $warehouse = qq|
  1748. <tr>
  1749. <th align=right>|.$locale->text('Warehouse').qq|</th>
  1750. <td><select name=warehouse>$form->{selectwarehouse}</select></td>
  1751. <input type=hidden name=selectwarehouse value="|.
  1752. $form->escape($form->{selectwarehouse},1).qq|">
  1753. </tr>
  1754. | if $form->{selectwarehouse};
  1755. $employee = qq|
  1756. <tr>
  1757. <th align=right nowrap>|.$locale->text('Contact').qq|</th>
  1758. <td><select name=employee>$form->{selectemployee}</select></td>
  1759. <input type=hidden name=selectemployee value="|.
  1760. $form->escape($form->{selectemployee},1).qq|">
  1761. </tr>
  1762. |;
  1763. $form->header;
  1764. print qq|
  1765. <body>
  1766. <form method=post action=$form->{script}>
  1767. <input type=hidden name=display_form value=display_ship_receive>
  1768. |;
  1769. $form->hide_form(qw(id type media format printed emailed queued vc));
  1770. print qq|
  1771. <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
  1772. <table width=100%>
  1773. <tr class=listtop>
  1774. <th class=listtop>$form->{title}</th>
  1775. </tr>
  1776. <tr height="5"></tr>
  1777. <tr>
  1778. <td>
  1779. <table width="100%">
  1780. <tr valign=top>
  1781. <td>
  1782. <table width=100%>
  1783. <tr>
  1784. <th align=right>$vclabel</th>
  1785. <td colspan=3>$form->{$form->{vc}}</td>
  1786. <input type=hidden name=$form->{vc} value="$form->{$form->{vc}}">
  1787. <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
  1788. </tr>
  1789. $department
  1790. <tr>
  1791. <th align=right>|.$locale->text('Shipping Point').qq|</th>
  1792. <td colspan=3>
  1793. <input name=shippingpoint size=35 value="$form->{shippingpoint}">
  1794. </tr>
  1795. <tr>
  1796. <th align=right>|.$locale->text('Ship via').qq|</th>
  1797. <td colspan=3>
  1798. <input name=shipvia size=35 value="$form->{shipvia}">
  1799. </tr>
  1800. $warehouse
  1801. </table>
  1802. </td>
  1803. <td align=right>
  1804. <table>
  1805. $employee
  1806. <tr>
  1807. <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
  1808. <td>$form->{ordnumber}</td>
  1809. <input type=hidden name=ordnumber value="$form->{ordnumber}">
  1810. </tr>
  1811. <tr>
  1812. <th align=right nowrap>|.$locale->text('Order Date').qq|</th>
  1813. <td>$form->{transdate}</td>
  1814. <input type=hidden name=transdate value=$form->{transdate}>
  1815. </tr>
  1816. <tr>
  1817. <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
  1818. <td>$form->{ponumber}</td>
  1819. <input type=hidden name=ponumber value="$form->{ponumber}">
  1820. </tr>
  1821. <tr>
  1822. <th align=right nowrap>$shipped</th>
  1823. <td><input name=shippingdate size=11 value=$form->{shippingdate}></td>
  1824. </tr>
  1825. </table>
  1826. </td>
  1827. </tr>
  1828. </table>
  1829. </td>
  1830. </tr>
  1831. |;
  1832. $form->hide_form(qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc));
  1833. @column_index = qw(partnumber);
  1834. if ($form->{type} eq "ship_order") {
  1835. $column_data{ship} = qq|<th class=listheading>|.$locale->text('Ship').qq|</th>|;
  1836. }
  1837. if ($form->{type} eq "receive_order") {
  1838. $column_data{ship} = qq|<th class=listheading>|.$locale->text('Recd').qq|</th>|;
  1839. $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
  1840. push @column_index, "sku";
  1841. }
  1842. push @column_index, qw(description qty ship unit bin serialnumber);
  1843. my $colspan = $#column_index + 1;
  1844. $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
  1845. $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
  1846. $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
  1847. $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
  1848. $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
  1849. $column_data{serialnumber} = qq|<th class=listheading nowrap>|.$locale->text('Serial No.').qq|</th>|;
  1850. print qq|
  1851. <tr>
  1852. <td>
  1853. <table width=100%>
  1854. <tr class=listheading>|;
  1855. for (@column_index) { print "\n$column_data{$_}" }
  1856. print qq|
  1857. </tr>
  1858. |;
  1859. for $i (1 .. $form->{rowcount} - 1) {
  1860. # undo formatting
  1861. $form->{"ship_$i"} = $form->parse_amount(\%myconfig, $form->{"ship_$i"});
  1862. for (qw(partnumber sku description unit bin serialnumber)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  1863. $description = $form->{"description_$i"};
  1864. $description =~ s/\r?\n/<br>/g;
  1865. $column_data{partnumber} = qq|<td>$form->{"partnumber_$i"}<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
  1866. $column_data{sku} = qq|<td>$form->{"sku_$i"}<input type=hidden name="sku_$i" value="$form->{"sku_$i"}"></td>|;
  1867. $column_data{description} = qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
  1868. $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>|;
  1869. $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
  1870. $column_data{unit} = qq|<td>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
  1871. $column_data{bin} = qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|;
  1872. $column_data{serialnumber} = qq|<td><input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}"></td>|;
  1873. print qq|
  1874. <tr valign=top>|;
  1875. for (@column_index) { print "\n$column_data{$_}" }
  1876. print qq|
  1877. </tr>
  1878. |;
  1879. $form->hide_form("orderitems_id_$i","id_$i","partsgroup_$i");
  1880. }
  1881. print qq|
  1882. </table>
  1883. </td>
  1884. </tr>
  1885. <tr>
  1886. <td><hr size=3 noshade></td>
  1887. </tr>
  1888. <tr>
  1889. <td>
  1890. |;
  1891. $form->{copies} = 1;
  1892. &print_options;
  1893. print qq|
  1894. </td>
  1895. </tr>
  1896. </table>
  1897. <br>
  1898. |;
  1899. # type=submit $locale->text('Done')
  1900. %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  1901. 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
  1902. 'ship_to' => { ndx => 4, key => 'T', value => $locale->text('Ship to') },
  1903. 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1904. 'done' => { ndx => 11, key => 'D', value => $locale->text('Done') },
  1905. );
  1906. for ("update", "print") { $form->print_button(\%button, $_) }
  1907. if ($form->{type} eq 'ship_order') {
  1908. for ('ship_to', 'e_mail') { $form->print_button(\%button, $_) }
  1909. }
  1910. $form->print_button(\%button, 'done');
  1911. if ($form->{lynx}) {
  1912. require "bin/menu.pl";
  1913. &menubar;
  1914. }
  1915. $form->hide_form(qw(rowcount callback path login sessionid));
  1916. print qq|
  1917. </form>
  1918. </body>
  1919. </html>
  1920. |;
  1921. }
  1922. sub done {
  1923. if ($form->{type} eq 'ship_order') {
  1924. $form->isblank("shippingdate", $locale->text('Shipping Date missing!'));
  1925. } else {
  1926. $form->isblank("shippingdate", $locale->text('Date received missing!'));
  1927. }
  1928. $total = 0;
  1929. for (1 .. $form->{rowcount} - 1) { $total += $form->{"ship_$_"} = $form->parse_amount(\%myconfig, $form->{"ship_$_"}) }
  1930. $form->error($locale->text('Nothing entered!')) unless $total;
  1931. if (OE->save_inventory(\%myconfig, \%$form)) {
  1932. $form->redirect($locale->text('Inventory saved!'));
  1933. } else {
  1934. $form->error($locale->text('Could not save!'));
  1935. }
  1936. }
  1937. sub search_transfer {
  1938. OE->get_warehouses(\%myconfig, \%$form);
  1939. # warehouse
  1940. if (@{ $form->{all_warehouse} }) {
  1941. $form->{selectwarehouse} = "<option>\n";
  1942. $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}| if $form->{warehouse_id};
  1943. for (@{ $form->{all_warehouse} }) { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  1944. } else {
  1945. $form->error($locale->text('Nothing to transfer!'));
  1946. }
  1947. $form->get_partsgroup(\%myconfig, { searchitems => 'part'});
  1948. if (@{ $form->{all_partsgroup} }) {
  1949. $form->{selectpartsgroup} = "<option>\n";
  1950. for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| }
  1951. }
  1952. $form->{title} = $locale->text('Transfer Inventory');
  1953. $form->header;
  1954. print qq|
  1955. <body>
  1956. <form method=post action=$form->{script}>
  1957. <table width=100%>
  1958. <tr>
  1959. <th class=listtop>$form->{title}</th>
  1960. </tr>
  1961. <tr height="5"></tr>
  1962. <tr>
  1963. <td>
  1964. <table>
  1965. <tr>
  1966. <th align=right nowrap>|.$locale->text('Transfer from').qq|</th>
  1967. <td><select name=fromwarehouse>$form->{selectwarehouse}</select></td>
  1968. </tr>
  1969. <tr>
  1970. <th align=right nowrap>|.$locale->text('Transfer to').qq|</th>
  1971. <td><select name=towarehouse>$form->{selectwarehouse}</select></td>
  1972. </tr>
  1973. <tr>
  1974. <th align="right" nowrap="true">|.$locale->text('Part Number').qq|</th>
  1975. <td><input name=partnumber size=20></td>
  1976. </tr>
  1977. <tr>
  1978. <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
  1979. <td><input name=description size=40></td>
  1980. </tr>
  1981. <tr>
  1982. <th align=right nowrap>|.$locale->text('Group').qq|</th>
  1983. <td><select name=partsgroup>$form->{selectpartsgroup}</select></td>
  1984. </tr>
  1985. </table>
  1986. </td>
  1987. </tr>
  1988. <tr>
  1989. <td><hr size=3 noshade></td>
  1990. </tr>
  1991. </table>
  1992. <br>
  1993. <input type=hidden name=nextsub value=list_transfer>
  1994. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
  1995. $form->hide_form(qw(path login sessionid));
  1996. print qq|
  1997. </form>
  1998. |;
  1999. if ($form->{lynx}) {
  2000. require "bin/menu.pl";
  2001. &menubar;
  2002. }
  2003. print qq|
  2004. </body>
  2005. </html>
  2006. |;
  2007. }
  2008. sub list_transfer {
  2009. $form->{sort} = "partnumber" unless $form->{sort};
  2010. OE->get_inventory(\%myconfig, \%$form);
  2011. # construct href
  2012. $href = "$form->{script}?action=list_transfer";
  2013. for (qw(direction oldsort path login sessionid)) { $href .= "&$_=$form->{$_}" }
  2014. for (qw(partnumber fromwarehouse towarehouse description partsgroup)) { $href .= "&$_=".$form->escape($form->{$_}) }
  2015. $form->sort_order();
  2016. # construct callback
  2017. $callback = "$form->{script}?action=list_transfer";
  2018. for (qw(direction oldsort path login sessionid)) { $callback .= "&$_=$form->{$_}" }
  2019. for (qw(partnumber fromwarehouse towarehouse description partsgroup)) { $callback .= "&$_=".$form->escape($form->{$_},1) }
  2020. @column_index = $form->sort_columns(qw(partnumber description partsgroup make model fromwarehouse qty towarehouse transfer));
  2021. $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|;
  2022. $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  2023. $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|;
  2024. $column_header{fromwarehouse} = qq|<th><a class=listheading href=$href&sort=warehouse>|.$locale->text('From').qq|</a></th>|;
  2025. $column_header{towarehouse} = qq|<th class=listheading>|.$locale->text('To').qq|</th>|;
  2026. $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</a></th>|;
  2027. $column_header{transfer} = qq|<th class=listheading>|.$locale->text('Transfer').qq|</a></th>|;
  2028. ($warehouse, $warehouse_id) = split /--/, $form->{fromwarehouse};
  2029. if ($form->{fromwarehouse}) {
  2030. $option .= "\n<br>";
  2031. $option .= $locale->text('From Warehouse')." : $warehouse";
  2032. }
  2033. ($warehouse, $warehouse_id) = split /--/, $form->{towarehouse};
  2034. if ($form->{towarehouse}) {
  2035. $option .= "\n<br>";
  2036. $option .= $locale->text('To Warehouse')." : $warehouse";
  2037. }
  2038. if ($form->{partnumber}) {
  2039. $option .= "\n<br>" if ($option);
  2040. $option .= $locale->text('Part Number')." : $form->{partnumber}";
  2041. }
  2042. if ($form->{description}) {
  2043. $option .= "\n<br>" if ($option);
  2044. $option .= $locale->text('Description')." : $form->{description}";
  2045. }
  2046. if ($form->{partsgroup}) {
  2047. ($partsgroup) = split /--/, $form->{partsgroup};
  2048. $option .= "\n<br>" if ($option);
  2049. $option .= $locale->text('Group')." : $partsgroup";
  2050. }
  2051. $form->{title} = $locale->text('Transfer Inventory');
  2052. $callback .= "&sort=$form->{sort}";
  2053. $form->header;
  2054. print qq|
  2055. <body>
  2056. <form method=post action=$form->{script}>
  2057. <input type=hidden name=warehouse_id value=$warehouse_id>
  2058. <table width=100%>
  2059. <tr>
  2060. <th class=listtop>$form->{title}</th>
  2061. </tr>
  2062. <tr height="5"></tr>
  2063. <tr>
  2064. <td>$option</td>
  2065. </tr>
  2066. <tr>
  2067. <td>
  2068. <table width=100%>
  2069. <tr class=listheading>|;
  2070. for (@column_index) { print "\n$column_header{$_}" }
  2071. print qq|
  2072. </tr>
  2073. |;
  2074. if (@{ $form->{all_inventory} }) {
  2075. $sameitem = $form->{all_inventory}->[0]->{$form->{sort}};
  2076. }
  2077. $i = 0;
  2078. foreach $ref (@{ $form->{all_inventory} }) {
  2079. $i++;
  2080. $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|;
  2081. $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
  2082. $column_data{partsgroup} = "<td>$ref->{partsgroup}&nbsp;</td>";
  2083. $column_data{fromwarehouse} = qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse}&nbsp;</td>|;
  2084. $column_data{towarehouse} = qq|<td>$warehouse&nbsp;</td>|;
  2085. $column_data{qty} = qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|.$form->format_amount(\%myconfig, $ref->{qty}).qq|</td>|;
  2086. $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
  2087. $j++; $j %= 2;
  2088. print "
  2089. <tr class=listrow$j>";
  2090. for (@column_index) { print "\n$column_data{$_}" }
  2091. print qq|
  2092. </tr>
  2093. |;
  2094. }
  2095. print qq|
  2096. </table>
  2097. </td>
  2098. </tr>
  2099. <tr>
  2100. <td><hr size=3 noshade></td>
  2101. </tr>
  2102. </table>
  2103. <br>
  2104. <input name=callback type=hidden value="$callback">
  2105. <input type=hidden name=rowcount value=$i>
  2106. |;
  2107. $form->{action} = "transfer";
  2108. $form->hide_form(qw(path login sessionid action));
  2109. print qq|
  2110. <button class="submit" type="submit" name="action" value="transfer">|.$locale->text('Transfer').qq|</button>|;
  2111. if ($form->{lynx}) {
  2112. require "bin/menu.pl";
  2113. &menubar;
  2114. }
  2115. print qq|
  2116. </form>
  2117. </body>
  2118. </html>
  2119. |;
  2120. }
  2121. sub transfer {
  2122. if (OE->transfer(\%myconfig, \%$form)) {
  2123. $form->redirect($locale->text('Inventory transferred!'));
  2124. } else {
  2125. $form->error($locale->text('Could not transfer Inventory!'));
  2126. }
  2127. }
  2128. sub rfq_ { &add };
  2129. sub quotation_ { &add };
  2130. sub generate_purchase_orders {
  2131. for (1 .. $form->{rowcount}) {
  2132. if ($form->{"ndx_$_"}) {
  2133. $ok = 1;
  2134. last;
  2135. }
  2136. }
  2137. $form->error($locale->text('Nothing selected!')) unless $ok;
  2138. ($null, $argv) = split /\?/, $form->{callback};
  2139. for (split /\&/, $argv) {
  2140. ($key, $value) = split /=/, $_;
  2141. $form->{$key} = $value;
  2142. }
  2143. $form->{vc} = "vendor";
  2144. OE->get_soparts(\%myconfig, \%$form);
  2145. # flatten array
  2146. $i = 0;
  2147. foreach $parts_id (sort { $form->{orderitems}{$a}{partnumber} cmp $form->{orderitems}{$b}{partnumber} } keys %{ $form->{orderitems} }) {
  2148. $required = $form->{orderitems}{$parts_id}{required};
  2149. next if $required <= 0;
  2150. $i++;
  2151. $form->{"required_$i"} = $form->format_amount(\%myconfig, $required);
  2152. $form->{"id_$i"} = $parts_id;
  2153. $form->{"sku_$i"} = $form->{orderitems}{$parts_id}{partnumber};
  2154. $form->{"curr_$i"} = $form->{defaultcurrency};
  2155. $form->{"description_$i"} = $form->{orderitems}{$parts_id}{description};
  2156. $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{orderitems}{$parts_id}{lastcost}, 2);
  2157. $form->{"qty_$i"} = $required;
  2158. if (exists $form->{orderitems}{$parts_id}{"parts$form->{vc}"}) {
  2159. $form->{"qty_$i"} = "";
  2160. 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}"} }) {
  2161. $i++;
  2162. $form->{"qty_$i"} = $form->format_amount(\%myconfig, $required);
  2163. $form->{"description_$i"} = "";
  2164. for (qw(partnumber curr)) { $form->{"${_}_$i"} = $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{$_} }
  2165. $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{lastcost}, 2);
  2166. $form->{"leadtime_$i"} = $form->format_amount(\%myconfig, $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{leadtime});
  2167. $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);
  2168. $form->{"id_$i"} = $parts_id;
  2169. $form->{"$form->{vc}_$i"} = qq|$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{name}--$id|;
  2170. $form->{"$form->{vc}_id_$i"} = $id;
  2171. $required = "";
  2172. }
  2173. }
  2174. $form->{"blankrow_$i"} = 1;
  2175. }
  2176. $form->{rowcount} = $i;
  2177. &po_orderitems;
  2178. }
  2179. sub po_orderitems {
  2180. @column_index = qw(sku description partnumber leadtime fx lastcost curr required qty name);
  2181. $column_header{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
  2182. $column_header{partnumber} = qq|<th class=listheading>|.$locale->text('Part Number').qq|</th>|;
  2183. $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
  2184. $column_header{name} = qq|<th class=listheading>|.$locale->text('Vendor').qq|</th>|;
  2185. $column_header{qty} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|;
  2186. $column_header{required} = qq|<th class=listheading>|.$locale->text('Req').qq|</th>|;
  2187. $column_header{lastcost} = qq|<th class=listheading>|.$locale->text('Cost').qq|</th>|;
  2188. $column_header{fx} = qq|<th class=listheading>&nbsp;</th>|;
  2189. $column_header{leadtime} = qq|<th class=listheading>|.$locale->text('Lead').qq|</th>|;
  2190. $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|;
  2191. $form->{title} = $locale->text('Generate Purchase Orders');
  2192. $form->header;
  2193. print qq|
  2194. <body>
  2195. <form method=post action=$form->{script}>
  2196. <table width=100%>
  2197. <tr>
  2198. <th class=listtop>$form->{title}</th>
  2199. </tr>
  2200. <tr height="5"></tr>
  2201. <tr>
  2202. <td>
  2203. <table width=100%>
  2204. <tr class=listheading>|;
  2205. for (@column_index) { print "\n$column_header{$_}" }
  2206. print qq|
  2207. </tr>
  2208. |;
  2209. for $i (1 .. $form->{rowcount}) {
  2210. for (qw(sku partnumber description curr)) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}&nbsp;</td>| }
  2211. for (qw(required leadtime lastcost fx)) { $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>| }
  2212. $column_data{qty} = qq|<td align=right><input name="qty_$i" size=6 value=$form->{"qty_$i"}></td>|;
  2213. if ($form->{"$form->{vc}_id_$i"}) {
  2214. $name = $form->{"$form->{vc}_$i"};
  2215. $name =~ s/--.*//;
  2216. $column_data{name} = qq|<td>$name</td>|;
  2217. $form->hide_form("$form->{vc}_id_$i", "$form->{vc}_$i");
  2218. } else {
  2219. $column_data{name} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
  2220. }
  2221. $form->hide_form(map { "${_}_$i" } qw(id sku partnumber description curr required leadtime lastcost fx name blankrow));
  2222. $blankrow = $form->{"blankrow_$i"};
  2223. BLANKROW:
  2224. $j++; $j %= 2;
  2225. print "
  2226. <tr class=listrow$j>";
  2227. for (@column_index) { print "\n$column_data{$_}" }
  2228. print qq|
  2229. </tr>
  2230. |;
  2231. if ($blankrow) {
  2232. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2233. $blankrow = 0;
  2234. goto BLANKROW;
  2235. }
  2236. }
  2237. print qq|
  2238. </table>
  2239. </td>
  2240. </tr>
  2241. <tr>
  2242. <td><hr size=3 noshade></td>
  2243. </tr>
  2244. </table>
  2245. <br>
  2246. |;
  2247. $form->hide_form(qw(callback department ponumber path login sessionid employee_id vc nextsub rowcount type));
  2248. print qq|
  2249. <button class="submit" type="submit" name="action" value="generate_orders">|.$locale->text('Generate Orders').qq|</button>|;
  2250. print qq|
  2251. <button class="submit" type="submit" name="action" value="select_vendor">|.$locale->text('Select Vendor').qq|</button>|;
  2252. if ($form->{lynx}) {
  2253. require "bin/menu.pl";
  2254. &menubar;
  2255. }
  2256. print qq|
  2257. </form>
  2258. </body>
  2259. </html>
  2260. |;
  2261. }
  2262. sub generate_orders {
  2263. if (OE->generate_orders(\%myconfig, \%$form)) {
  2264. $form->redirect;
  2265. } else {
  2266. $form->error($locale->text('Order generation failed!'));
  2267. }
  2268. }
  2269. sub consolidate_orders {
  2270. for (1 .. $form->{rowcount}) {
  2271. if ($form->{"ndx_$_"}) {
  2272. $ok = 1;
  2273. last;
  2274. }
  2275. }
  2276. $form->error($locale->text('Nothing selected!')) unless $ok;
  2277. ($null, $argv) = split /\?/, $form->{callback};
  2278. for (split /\&/, $argv) {
  2279. ($key, $value) = split /=/, $_;
  2280. $form->{$key} = $value;
  2281. }
  2282. if (OE->consolidate_orders(\%myconfig, \%$form)) {
  2283. $form->redirect;
  2284. } else {
  2285. $form->error($locale->text('Order generation failed!'));
  2286. }
  2287. }
  2288. sub select_vendor {
  2289. for (1 .. $form->{rowcount}) {
  2290. last if ($ok = $form->{"ndx_$_"});
  2291. }
  2292. $form->error($locale->text('Nothing selected!')) unless $ok;
  2293. $form->header;
  2294. print qq|
  2295. <body onload="document.forms[0].vendor.focus()" />
  2296. <form method=post action=$form->{script}>
  2297. <b>|.$locale->text('Vendor').qq|</b> <input name=vendor size=40>
  2298. |;
  2299. $form->{nextsub} = "vendor_selected";
  2300. $form->{action} = "vendor_selected";
  2301. $form->hide_form;
  2302. print qq|
  2303. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  2304. </form>
  2305. |;
  2306. if ($form->{lynx}) {
  2307. require "bin/menu.pl";
  2308. &menubar;
  2309. }
  2310. print qq|
  2311. </body>
  2312. </html>
  2313. |;
  2314. }
  2315. sub vendor_selected {
  2316. if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{transdate})) > 1) {
  2317. &select_name($form->{vc});
  2318. exit;
  2319. }
  2320. if ($rv == 1) {
  2321. for (1 .. $form->{rowcount}) {
  2322. if ($form->{"ndx_$_"}) {
  2323. $form->{"$form->{vc}_id_$_"} = $form->{name_list}[0]->{id};
  2324. $form->{"$form->{vc}_$_"} = "$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}";
  2325. }
  2326. }
  2327. } else {
  2328. $msg = ucfirst $form->{vc} . " not on file!" unless $msg;
  2329. $form->error($locale->text($msg));
  2330. }
  2331. &po_orderitems;
  2332. }