summaryrefslogtreecommitdiff
path: root/bin/io.pl
blob: efeaf8b495e3babfffc65603b18a5ab3e2607f26 (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) 2002
  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. # common routines used in is, ir, oe
  37. #
  38. #######################################################################
  39. use LedgerSMB::Tax;
  40. use LedgerSMB::Sysconfig;
  41. # any custom scripts for this one
  42. if (-f "bin/custom/io.pl") {
  43. eval { require "bin/custom/io.pl"; };
  44. }
  45. if (-f "bin/custom/$form->{login}_io.pl") {
  46. eval { require "bin/custom/$form->{login}_io.pl"; };
  47. }
  48. 1;
  49. # end of main
  50. # this is for our long dates
  51. # $locale->text('January')
  52. # $locale->text('February')
  53. # $locale->text('March')
  54. # $locale->text('April')
  55. # $locale->text('May ')
  56. # $locale->text('June')
  57. # $locale->text('July')
  58. # $locale->text('August')
  59. # $locale->text('September')
  60. # $locale->text('October')
  61. # $locale->text('November')
  62. # $locale->text('December')
  63. # this is for our short month
  64. # $locale->text('Jan')
  65. # $locale->text('Feb')
  66. # $locale->text('Mar')
  67. # $locale->text('Apr')
  68. # $locale->text('May')
  69. # $locale->text('Jun')
  70. # $locale->text('Jul')
  71. # $locale->text('Aug')
  72. # $locale->text('Sep')
  73. # $locale->text('Oct')
  74. # $locale->text('Nov')
  75. # $locale->text('Dec')
  76. sub display_row {
  77. my $numrows = shift;
  78. @column_index = qw(runningnumber partnumber description qty);
  79. if ($form->{type} eq "sales_order") {
  80. push @column_index, "ship";
  81. $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;
  82. }
  83. if ($form->{type} eq "purchase_order") {
  84. push @column_index, "ship";
  85. $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;
  86. }
  87. for (qw(projectnumber partsgroup)) {
  88. $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
  89. }
  90. if ($form->{language_code} ne $form->{oldlanguage_code}) {
  91. # rebuild partsgroup
  92. $l{language_code} = $form->{language_code};
  93. $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer';
  94. $form->get_partsgroup(\%myconfig, \%l);
  95. if (@ { $form->{all_partsgroup} }) {
  96. $form->{selectpartsgroup} = "<option>\n";
  97. foreach $ref (@ { $form->{all_partsgroup} }) {
  98. if ($ref->{translation}) {
  99. $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
  100. } else {
  101. $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
  102. }
  103. }
  104. }
  105. $form->{oldlanguage_code} = $form->{language_code};
  106. }
  107. push @column_index, @{LedgerSMB::Sysconfig::io_lineitem_columns};
  108. my $colspan = $#column_index + 1;
  109. $form->{invsubtotal} = 0;
  110. for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
  111. $column_data{runningnumber} = qq|<th class=listheading nowrap>|.$locale->text('Item').qq|</th>|;
  112. $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
  113. $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
  114. $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
  115. $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
  116. $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
  117. $column_data{discount} = qq|<th class=listheading>%</th>|;
  118. $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
  119. $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
  120. $column_data{onhand} = qq|<th class=listheading nowrap>|.$locale->text('OH').qq|</th>|;
  121. print qq|
  122. <tr>
  123. <td>
  124. <table width=100%>
  125. <tr class=listheading>|;
  126. for (@column_index) { print "\n$column_data{$_}" }
  127. print qq|
  128. </tr>
  129. |;
  130. $deliverydate = $locale->text('Delivery Date');
  131. $serialnumber = $locale->text('Serial No.');
  132. $projectnumber = $locale->text('Project');
  133. $group = $locale->text('Group');
  134. $sku = $locale->text('SKU');
  135. $delvar = 'deliverydate';
  136. if ($form->{type} =~ /_(order|quotation)$/) {
  137. $reqdate = $locale->text('Required by');
  138. $delvar = 'reqdate';
  139. }
  140. $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
  141. $exchangerate = ($exchangerate) ? $exchangerate : 1;
  142. $spc = substr($myconfig{numberformat},-3,1);
  143. for $i (1 .. $numrows) {
  144. if ($spc eq '.') {
  145. ($null, $dec) = split /\./, $form->{"sellprice_$i"};
  146. } else {
  147. ($null, $dec) = split /,/, $form->{"sellprice_$i"};
  148. }
  149. $dec = length $dec;
  150. $decimalplaces = ($dec > 2) ? $dec : 2;
  151. # undo formatting
  152. for (qw(qty oldqty ship discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  153. if ($form->{"qty_$i"} != $form->{"oldqty_$i"}) {
  154. # check pricematrix
  155. @a = split / /, $form->{"pricematrix_$i"};
  156. if (scalar @a > 2) {
  157. foreach $item (@a) {
  158. ($q, $p) = split /:/, $item;
  159. if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
  160. ($dec) = ($p =~ /\.(\d+)/);
  161. $dec = length $dec;
  162. $decimalplaces = ($dec > 2) ? $dec : 2;
  163. $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
  164. }
  165. }
  166. }
  167. }
  168. $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
  169. $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
  170. $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
  171. if (($rows = $form->numtextrows($form->{"description_$i"}, 46, 6)) > 1) {
  172. $form->{"description_$i"} = $form->quote($form->{"description_$i"});
  173. $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
  174. } else {
  175. $form->{"description_$i"} = $form->quote($form->{"description_$i"});
  176. $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
  177. }
  178. for (qw(partnumber sku unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  179. $skunumber = qq|
  180. <p><b>$sku</b> $form->{"sku_$i"}| if ($form->{vc} eq 'vendor' && $form->{"sku_$i"});
  181. if ($form->{selectpartsgroup}) {
  182. if ($i < $numrows) {
  183. $partsgroup = qq|
  184. <b>$group</b>
  185. <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|;
  186. ($form->{"partsgroup_$i"}) = split /--/, $form->{"partsgroup_$i"};
  187. $partsgroup .= $form->{"partsgroup_$i"};
  188. $partsgroup = "" unless $form->{"partsgroup_$i"};
  189. }
  190. }
  191. $delivery = qq|
  192. <td colspan=2 nowrap>
  193. <b>${$delvar}</b>
  194. <input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"></td>
  195. |;
  196. $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
  197. $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]">$skunumber</td>|;
  198. $column_data{qty} = qq|<td align=right><input name="qty_$i" title="$form->{"onhand_$i"}" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
  199. $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
  200. $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
  201. $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
  202. $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
  203. $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
  204. $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
  205. $column_data{onhand} = qq|<td>$form->{"onhand_$i"}</td>|;
  206. print qq|
  207. <tr valign=top>|;
  208. for (@column_index) {
  209. print "\n$column_data{$_}";
  210. }
  211. print qq|
  212. </tr>
  213. <input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}">
  214. |;
  215. for (qw(orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id)) {
  216. $form->hide_form("${_}_$i");
  217. }
  218. $form->{selectprojectnumber} =~ s/ selected//;
  219. $form->{selectprojectnumber} =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
  220. $project = qq|
  221. <b>$projectnumber</b>
  222. <select name="projectnumber_$i">$form->{selectprojectnumber}</select>
  223. | if $form->{selectprojectnumber};
  224. if (($rows = $form->numtextrows($form->{"notes_$i"}, 46, 6)) > 1) {
  225. $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
  226. $notes = qq|<td><textarea name="notes_$i" rows=$rows cols=46 wrap=soft>$form->{"notes_$i"}</textarea></td>|;
  227. } else {
  228. $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
  229. $notes = qq|<td><input name="notes_$i" size=48 value="$form->{"notes_$i"}"></td>|;
  230. }
  231. $serial = qq|
  232. <td colspan=6 nowrap><b>$serialnumber</b> <input name="serialnumber_$i" value="$form->{"serialnumber_$i"}"></td>| if $form->{type} !~ /_quotation/;
  233. if ($i == $numrows) {
  234. $partsgroup = "";
  235. if ($form->{selectpartsgroup}) {
  236. $partsgroup = qq|
  237. <b>$group</b>
  238. <select name="partsgroup_$i">$form->{selectpartsgroup}</select>
  239. |;
  240. }
  241. $serial = "";
  242. $project = "";
  243. $delivery = "";
  244. $notes = "";
  245. }
  246. # print second and third row
  247. print qq|
  248. <tr valign=top>
  249. $delivery
  250. $notes
  251. $serial
  252. </tr>
  253. <tr valign=top>
  254. <td colspan=$colspan>
  255. $project
  256. $partsgroup
  257. </td>
  258. </tr>
  259. <tr>
  260. <td colspan=$colspan><hr size=1 noshade></td>
  261. </tr>
  262. |;
  263. $skunumber = "";
  264. for (split / /, $form->{"taxaccounts_$i"}) {
  265. $form->{"${_}_base"} += $linetotal;
  266. }
  267. $form->{invsubtotal} += $linetotal;
  268. }
  269. print qq|
  270. </table>
  271. </td>
  272. </tr>
  273. |;
  274. $form->hide_form(qw(audittrail));
  275. print qq|
  276. <input type=hidden name=oldcurrency value=$form->{currency}>
  277. <input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">
  278. <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
  279. |;
  280. }
  281. sub select_item {
  282. if ($form->{vc} eq "vendor") {
  283. @column_index = qw(ndx partnumber sku description partsgroup onhand sellprice);
  284. } else {
  285. @column_index = qw(ndx partnumber description partsgroup onhand sellprice);
  286. }
  287. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  288. $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
  289. $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
  290. $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
  291. $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
  292. $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
  293. $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
  294. $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
  295. # list items with radio button on a form
  296. $form->header;
  297. $title = $locale->text('Select items');
  298. print qq|
  299. <body>
  300. <form method=post action="$form->{script}">
  301. <table width=100%>
  302. <tr>
  303. <th class=listtop>$title</th>
  304. </tr>
  305. <tr height="5"></tr>
  306. <tr>
  307. <td>$option</td>
  308. </tr>
  309. <tr>
  310. <td>
  311. <table width=100%>
  312. <tr class=listheading>|;
  313. for (@column_index) { print "\n$column_data{$_}" }
  314. print qq|
  315. </tr>
  316. |;
  317. my $i = 0;
  318. foreach $ref (@{ $form->{item_list} }) {
  319. $i++;
  320. for (qw(sku partnumber description unit notes partsgroup)) {
  321. $ref->{$_} = $form->quote($ref->{$_});
  322. }
  323. $column_data{ndx} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
  324. for (qw(partnumber sku description partsgroup)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  325. $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice} / $exchangerate, 2, "&nbsp;").qq|</td>|;
  326. $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;").qq|</td>|;
  327. $j++; $j %= 2;
  328. print qq|
  329. <tr class=listrow$j>|;
  330. for (@column_index) {
  331. print "\n$column_data{$_}";
  332. }
  333. print qq|
  334. </tr>
  335. |;
  336. for (qw(partnumber sku description partsgroup partsgroup_id bin weight sellprice listprice lastcost onhand unit assembly taxaccounts inventory_accno_id income_accno_id expense_accno_id pricematrix id notes)) {
  337. print qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
  338. }
  339. }
  340. print qq|
  341. </table>
  342. </td>
  343. </tr>
  344. <tr>
  345. <td><hr size=3 noshade></td>
  346. </tr>
  347. </table>
  348. <input name=lastndx type=hidden value=$i>
  349. |;
  350. # delete variables
  351. for (qw(nextsub item_list)) { delete $form->{$_} }
  352. $form->{action} = "item_selected";
  353. $form->hide_form;
  354. print qq|
  355. <input type="hidden" name="nextsub" value="item_selected">
  356. <br>
  357. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  358. </form>
  359. </body>
  360. </html>
  361. |;
  362. }
  363. sub item_selected {
  364. $i = $form->{rowcount} - 1;
  365. $i = $form->{assembly_rows} - 1 if ($form->{item} eq 'assembly');
  366. $qty = ($form->{"qty_$form->{rowcount}"}) ? $form->{"qty_$form->{rowcount}"} : 1;
  367. for $j (1 .. $form->{lastndx}) {
  368. if ($form->{"ndx_$j"}) {
  369. $i++;
  370. $form->{"qty_$i"} = $qty;
  371. $form->{"discount_$i"} = $form->{discount} * 100;
  372. $form->{"reqdate_$i"} = $form->{reqdate} if $form->{type} !~ /_quotation/;
  373. for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
  374. $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
  375. }
  376. $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
  377. ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
  378. $dec = length $dec;
  379. $decimalplaces1 = ($dec > 2) ? $dec : 2;
  380. ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
  381. $dec = length $dec;
  382. $decimalplaces2 = ($dec > 2) ? $dec : 2;
  383. # if there is an exchange rate adjust sellprice
  384. if (($form->{exchangerate} * 1)) {
  385. for (qw(sellprice listprice lastcost)) { $form->{"${_}_$i"} /= $form->{exchangerate} }
  386. # don't format list and cost
  387. $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces1);
  388. }
  389. # this is for the assembly
  390. if ($form->{item} eq 'assembly') {
  391. $form->{"adj_$i"} = 1;
  392. for (qw(sellprice listprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  393. $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
  394. $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
  395. }
  396. $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
  397. for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  398. if (!$form->{taxincluded}) {
  399. my @taxlist= Tax::init_taxes($form, $form->{"taxaccounts_$i"});
  400. $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0);
  401. }
  402. $form->{creditremaining} -= $amount;
  403. $form->{"runningnumber_$i"} = $i;
  404. # format amounts
  405. if ($form->{item} ne 'assembly') {
  406. for (qw(sellprice listprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces1) }
  407. $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces2);
  408. }
  409. $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
  410. }
  411. }
  412. $form->{rowcount} = $i;
  413. $form->{assembly_rows} = $i if ($form->{item} eq 'assembly');
  414. $form->{focus} = "description_$i";
  415. # delete all the new_ variables
  416. for $i (1 .. $form->{lastndx}) {
  417. for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
  418. delete $form->{"new_${_}_$i"};
  419. }
  420. }
  421. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  422. &display_form;
  423. }
  424. sub new_item {
  425. if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) {
  426. $form->error($locale->text('Translation not on file!'));
  427. }
  428. # change callback
  429. $form->{old_callback} = $form->escape($form->{callback},1);
  430. $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
  431. # delete action
  432. delete $form->{action};
  433. # save all other form variables in a previousform variable
  434. if (!$form->{previousform}) {
  435. foreach $key (keys %$form) {
  436. # escape ampersands
  437. $form->{$key} =~ s/&/%26/g;
  438. $form->{previousform} .= qq|$key=$form->{$key}&|;
  439. }
  440. chop $form->{previousform};
  441. $form->{previousform} = $form->escape($form->{previousform}, 1);
  442. }
  443. $i = $form->{rowcount};
  444. for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  445. $form->header;
  446. print qq|
  447. <body>
  448. <h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|;
  449. if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) {
  450. print qq|
  451. <h4>|.$locale->text('What type of item is this?').qq|</h4>
  452. <form method=post action=ic.pl>
  453. <p>
  454. <input class=radio type=radio name=item value=part checked>&nbsp;|.$locale->text('Part')
  455. .qq|<br>
  456. <input class=radio type=radio name=item value=service>&nbsp;|.$locale->text('Service')
  457. .qq|
  458. <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
  459. <input type=hidden name=description value="$form->{"description_$i"}">
  460. <input type=hidden name=nextsub value=add>
  461. <input type=hidden name=action value=add>
  462. |;
  463. $form->hide_form(qw(previousform rowcount path login sessionid));
  464. print qq|
  465. <p>
  466. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  467. </form>
  468. |;
  469. }
  470. print qq|
  471. </body>
  472. </html>
  473. |;
  474. }
  475. sub display_form {
  476. # if we have a display_form
  477. if ($form->{display_form}) {
  478. &{ "$form->{display_form}" };
  479. exit;
  480. }
  481. &form_header;
  482. $numrows = ++$form->{rowcount};
  483. $subroutine = "display_row";
  484. if ($form->{item} eq 'part') {
  485. # create makemodel rows
  486. &makemodel_row(++$form->{makemodel_rows});
  487. &vendor_row(++$form->{vendor_rows});
  488. $numrows = ++$form->{customer_rows};
  489. $subroutine = "customer_row";
  490. }
  491. if ($form->{item} eq 'assembly') {
  492. # create makemodel rows
  493. &makemodel_row(++$form->{makemodel_rows});
  494. $numrows = ++$form->{customer_rows};
  495. $subroutine = "customer_row";
  496. }
  497. if ($form->{item} eq 'service') {
  498. &vendor_row(++$form->{vendor_rows});
  499. $numrows = ++$form->{customer_rows};
  500. $subroutine = "customer_row";
  501. }
  502. if ($form->{item} eq 'labor') {
  503. $numrows = 0;
  504. }
  505. # create rows
  506. &{ $subroutine }($numrows) if $numrows;
  507. &form_footer;
  508. }
  509. sub check_form {
  510. my @a = ();
  511. my $count = 0;
  512. my $i;
  513. my $j;
  514. my @flds = qw(id runningnumber partnumber description partsgroup qty ship unit sellprice discount oldqty orderitems_id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id notes reqdate deliverydate serialnumber projectnumber);
  515. # remove any makes or model rows
  516. if ($form->{item} eq 'part') {
  517. for (qw(listprice sellprice lastcost avgcost weight rop markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  518. &calc_markup;
  519. @flds = qw(make model);
  520. $count = 0;
  521. @a = ();
  522. for $i (1 .. $form->{makemodel_rows}) {
  523. if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  524. push @a, {};
  525. $j = $#a;
  526. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  527. $count++;
  528. }
  529. }
  530. $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  531. $form->{makemodel_rows} = $count;
  532. &check_vendor;
  533. &check_customer;
  534. }
  535. if ($form->{item} eq 'service') {
  536. for (qw(sellprice listprice lastcost avgcost markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  537. &calc_markup;
  538. &check_vendor;
  539. &check_customer;
  540. }
  541. if ($form->{item} eq 'assembly') {
  542. if (!$form->{project_id}) {
  543. $form->{sellprice} = 0;
  544. $form->{listprice} = 0;
  545. $form->{lastcost} = 0;
  546. $form->{weight} = 0;
  547. }
  548. for (qw(rop stock markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  549. @flds = qw(id qty unit bom adj partnumber description sellprice listprice lastcost weight assembly runningnumber partsgroup);
  550. $count = 0;
  551. @a = ();
  552. for $i (1 .. ($form->{assembly_rows} - 1)) {
  553. if ($form->{"qty_$i"}) {
  554. push @a, {};
  555. my $j = $#a;
  556. $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  557. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  558. if (! $form->{project_id}) {
  559. for (qw(sellprice listprice weight lastcost)) { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) }
  560. }
  561. $count++;
  562. }
  563. }
  564. if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) {
  565. $form->{sellprice} = 0;
  566. &calc_markup;
  567. }
  568. for (qw(sellprice lastcost listprice)) { $form->{$_} = $form->round_amount($form->{$_}, 2) }
  569. $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
  570. $form->{assembly_rows} = $count;
  571. $count = 0;
  572. @flds = qw(make model);
  573. @a = ();
  574. for $i (1 .. ($form->{makemodel_rows})) {
  575. if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  576. push @a, {};
  577. my $j = $#a;
  578. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  579. $count++;
  580. }
  581. }
  582. $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  583. $form->{makemodel_rows} = $count;
  584. &check_customer;
  585. }
  586. if ($form->{type}) {
  587. # this section applies to invoices and orders
  588. # remove any empty numbers
  589. $count = 0;
  590. @a = ();
  591. if ($form->{rowcount}) {
  592. for $i (1 .. $form->{rowcount} - 1) {
  593. if ($form->{"partnumber_$i"}) {
  594. push @a, {};
  595. my $j = $#a;
  596. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  597. $count++;
  598. }
  599. }
  600. $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
  601. $form->{rowcount} = $count;
  602. $form->{creditremaining} -= &invoicetotal;
  603. }
  604. }
  605. &display_form;
  606. }
  607. sub calc_markup {
  608. if ($form->{markup}) {
  609. if ($form->{markup} != $form->{oldmarkup}) {
  610. if ($form->{lastcost}) {
  611. $form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100);
  612. $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
  613. } else {
  614. $form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100);
  615. $form->{lastcost} = $form->round_amount($form->{lastcost}, 2);
  616. }
  617. }
  618. } else {
  619. if ($form->{lastcost}) {
  620. $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1);
  621. }
  622. $form->{markup} = "" if $form->{markup} == 0;
  623. }
  624. }
  625. sub invoicetotal {
  626. $form->{oldinvtotal} = 0;
  627. # add all parts and deduct paid
  628. for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
  629. my ($amount, $sellprice, $discount, $qty);
  630. for $i (1 .. $form->{rowcount}) {
  631. $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
  632. $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
  633. $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  634. $amount = $sellprice * (1 - $discount / 100) * $qty;
  635. for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  636. $form->{oldinvtotal} += $amount;
  637. }
  638. if (!$form->{taxincluded}) {
  639. my @taxlist= Tax::init_taxes($form, $form->{taxaccounts});
  640. $form->{oldinvtotal} += Tax::calculate_taxes(\@taxlist, $form,
  641. $amount, 0);
  642. }
  643. $form->{oldtotalpaid} = 0;
  644. for $i (1 .. $form->{paidaccounts}) {
  645. $form->{oldtotalpaid} += $form->{"paid_$i"};
  646. }
  647. # return total
  648. ($form->{oldinvtotal} - $form->{oldtotalpaid});
  649. }
  650. sub validate_items {
  651. # check if items are valid
  652. if ($form->{rowcount} == 1) {
  653. &update;
  654. exit;
  655. }
  656. for $i (1 .. $form->{rowcount} - 1) {
  657. $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i");
  658. }
  659. }
  660. sub purchase_order {
  661. $form->{title} = $locale->text('Add Purchase Order');
  662. $form->{vc} = 'vendor';
  663. $form->{type} = 'purchase_order';
  664. $buysell = 'sell';
  665. &create_form;
  666. }
  667. sub sales_order {
  668. $form->{title} = $locale->text('Add Sales Order');
  669. $form->{vc} = 'customer';
  670. $form->{type} = 'sales_order';
  671. $buysell = 'buy';
  672. &create_form;
  673. }
  674. sub rfq {
  675. $form->{title} = $locale->text('Add Request for Quotation');
  676. $form->{vc} = 'vendor';
  677. $form->{type} = 'request_quotation';
  678. $buysell = 'sell';
  679. &create_form;
  680. }
  681. sub quotation {
  682. $form->{title} = $locale->text('Add Quotation');
  683. $form->{vc} = 'customer';
  684. $form->{type} = 'sales_quotation';
  685. $buysell = 'buy';
  686. &create_form;
  687. }
  688. sub create_form {
  689. for (qw(id printed emailed queued)) { delete $form->{$_} }
  690. $form->{script} = 'oe.pl';
  691. $form->{shipto} = 1;
  692. $form->{rowcount}-- if $form->{rowcount};
  693. $form->{rowcount} = 0 if ! $form->{"$form->{vc}_id"};
  694. do "bin/$form->{script}";
  695. for ("$form->{vc}", "currency") { $form->{"select$_"} = "" }
  696. for (qw(currency employee department intnotes notes language_code taxincluded)) { $temp{$_} = $form->{$_} }
  697. &order_links;
  698. for (keys %temp) { $form->{$_} = $temp{$_} if $temp{$_} }
  699. $form->{exchangerate} = "";
  700. $form->{forex} = "";
  701. if ($form->{currency} ne $form->{defaultcurrency}) {
  702. $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
  703. }
  704. &prepare_order;
  705. &display_form;
  706. }
  707. sub e_mail {
  708. $bcc = qq|<input type=hidden name=bcc value="$form->{bcc}">|;
  709. if ($myconfig{role} =~ /(admin|manager)/) {
  710. $bcc = qq|
  711. <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
  712. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  713. |;
  714. }
  715. if ($form->{formname} =~ /(pick|packing|bin)_list/) {
  716. $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
  717. }
  718. $name = $form->{$form->{vc}};
  719. $name =~ s/--.*//g;
  720. $title = $locale->text('E-mail')." $name";
  721. $form->header;
  722. print qq|
  723. <body>
  724. <form method=post action="$form->{script}">
  725. <table width=100%>
  726. <tr class=listtop>
  727. <th class=listtop>$title</th>
  728. </tr>
  729. <tr height="5"></tr>
  730. <tr>
  731. <td>
  732. <table width=100%>
  733. <tr>
  734. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  735. <td><input name=email size=30 value="$form->{email}"></td>
  736. <th align=right nowrap>|.$locale->text('Cc').qq|</th>
  737. <td><input name=cc size=30 value="$form->{cc}"></td>
  738. </tr>
  739. <tr>
  740. <th align=right nowrap>|.$locale->text('Subject').qq|</th>
  741. <td><input name=subject size=30 value="$form->{subject}"></td>
  742. $bcc
  743. </tr>
  744. </table>
  745. </td>
  746. </tr>
  747. <tr>
  748. <td>
  749. <table width=100%>
  750. <tr>
  751. <th align=left nowrap>|.$locale->text('Message').qq|</th>
  752. </tr>
  753. <tr>
  754. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  755. </tr>
  756. </table>
  757. </td>
  758. </tr>
  759. <tr>
  760. <td>
  761. |;
  762. $form->{oldmedia} = $form->{media};
  763. $form->{media} = "email";
  764. $form->{format} = "pdf";
  765. &print_options;
  766. for (qw(email cc bcc subject message formname sendmode format language_code action nextsub)) { delete $form->{$_} }
  767. $form->hide_form;
  768. print qq|
  769. </td>
  770. </tr>
  771. <tr>
  772. <td><hr size=3 noshade></td>
  773. </tr>
  774. </table>
  775. <input type="hidden" name="nextsub" value="send_email">
  776. <br>
  777. <button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
  778. </form>
  779. </body>
  780. </html>
  781. |;
  782. }
  783. sub send_email {
  784. $old_form = new Form;
  785. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  786. $old_form->{media} = $old_form->{oldmedia};
  787. &print_form($old_form);
  788. }
  789. sub print_options {
  790. $form->{sendmode} = "attachment";
  791. $form->{copies} = 1 unless $form->{copies};
  792. $form->{SM}{$form->{sendmode}} = "selected";
  793. if ($form->{selectlanguage}) {
  794. $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
  795. $form->{"selectlanguage"} =~ s/ selected//;
  796. $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  797. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  798. <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
  799. <input type=hidden name=selectlanguage value="|.$form->escape($form->{selectlanguage},1).qq|">|;
  800. }
  801. $form->{selectformname} = $form->unescape($form->{selectformname});
  802. $form->{selectformname} =~ s/ selected//;
  803. $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  804. $type = qq|<select name=formname>$form->{selectformname}</select>
  805. <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
  806. if ($form->{media} eq 'email') {
  807. $media = qq|<select name=sendmode>
  808. <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
  809. <option value=inline $form->{SM}{inline}>|.$locale->text('In-line').qq|</select>|;
  810. } else {
  811. $media = qq|<select name=media>
  812. <option value="screen">|.$locale->text('Screen');
  813. if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
  814. for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
  815. <option value="$_">$_| }
  816. }
  817. if (${LedgerSMB::Sysconfig::latex}) {
  818. $media .= qq|
  819. <option value="queue">|.$locale->text('Queue');
  820. }
  821. $media .= qq|</select>|;
  822. # set option selected
  823. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  824. }
  825. $form->{selectformat} = qq|<option value="html">html\n|;
  826. # <option value="txt">|.$locale->text('Text');
  827. if (${LedgerSMB::Sysconfig::latex}) {
  828. $form->{selectformat} .= qq|
  829. <option value="postscript">|.$locale->text('Postscript').qq|
  830. <option value="pdf">|.$locale->text('PDF');
  831. }
  832. $format = qq|<select name=format>$form->{selectformat}</select>|;
  833. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  834. $format .= qq|
  835. <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
  836. print qq|
  837. <table width=100%>
  838. <tr>
  839. <td>$type</td>
  840. <td>$lang</td>
  841. <td>$format</td>
  842. <td>$media</td>
  843. |;
  844. if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} && $form->{media} ne 'email') {
  845. print qq|
  846. <td nowrap>|.$locale->text('Copies').qq|
  847. <input name=copies size=2 value=$form->{copies}></td>
  848. |;
  849. }
  850. # $locale->text('Printed')
  851. # $locale->text('E-mailed')
  852. # $locale->text('Queued')
  853. # $locale->text('Scheduled')
  854. %status = ( printed => 'Printed',
  855. emailed => 'E-mailed',
  856. queued => 'Queued',
  857. recurring => 'Scheduled' );
  858. print qq|<td align=right width=90%>|;
  859. for (qw(printed emailed queued recurring)) {
  860. if ($form->{$_} =~ /$form->{formname}/) {
  861. print $locale->text($status{$_}).qq|<br>|;
  862. }
  863. }
  864. print qq|
  865. </td>
  866. </tr>
  867. |;
  868. $form->{groupprojectnumber} = "checked" if $form->{groupprojectnumber};
  869. $form->{grouppartsgroup} = "checked" if $form->{grouppartsgroup};
  870. for (qw(runningnumber partnumber description bin)) { $sortby{$_} = "checked" if $form->{sortby} eq $_ }
  871. print qq|
  872. <tr>
  873. <td colspan=3>|.$locale->text('Group by').qq| ->
  874. <input name=groupprojectnumber type=checkbox class=checkbox $form->{groupprojectnumber}>
  875. |.$locale->text('Project').qq|
  876. <input name=grouppartsgroup type=checkbox class=checkbox $form->{grouppartsgroup}>
  877. |.$locale->text('Group').qq|
  878. </td>
  879. <td colspan=3>|.$locale->text('Sort by').qq| ->
  880. <input name=sortby type=radio class=radio value=runningnumber $sortby{runningnumber}>
  881. |.$locale->text('Item').qq|
  882. <input name=sortby type=radio class=radio value=partnumber $sortby{partnumber}>
  883. |.$locale->text('Number').qq|
  884. <input name=sortby type=radio class=radio value=description $sortby{description}>
  885. |.$locale->text('Description').qq|
  886. <input name=sortby type=radio class=radio value=bin $sortby{bin}>
  887. |.$locale->text('Bin').qq|
  888. </td>
  889. </tr>
  890. </table>
  891. |;
  892. }
  893. sub print {
  894. # if this goes to the printer pass through
  895. if ($form->{media} !~ /(screen|email)/) {
  896. $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
  897. $old_form = new Form;
  898. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  899. }
  900. &print_form($old_form);
  901. }
  902. sub print_form {
  903. my ($old_form) = @_;
  904. $inv = "inv";
  905. $due = "due";
  906. $numberfld = "sinumber";
  907. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  908. if ($form->{formname} eq "invoice") {
  909. $form->{label} = $locale->text('Invoice');
  910. }
  911. if ($form->{formname} eq 'sales_order') {
  912. $inv = "ord";
  913. $due = "req";
  914. $form->{label} = $locale->text('Sales Order');
  915. $numberfld = "sonumber";
  916. $order = 1;
  917. }
  918. if ($form->{formname} eq 'work_order') {
  919. $inv = "ord";
  920. $due = "req";
  921. $form->{label} = $locale->text('Work Order');
  922. $numberfld = "sonumber";
  923. $order = 1;
  924. }
  925. if ($form->{formname} eq 'packing_list') {
  926. # we use the same packing list as from an invoice
  927. $form->{label} = $locale->text('Packing List');
  928. if ($form->{type} ne 'invoice') {
  929. $inv = "ord";
  930. $due = "req";
  931. $numberfld = "sonumber";
  932. $order = 1;
  933. $filled = 0;
  934. for ($i = 1; $i < $form->{rowcount}; $i++) {
  935. if ($form->{"ship_$i"}) {
  936. $filled = 1;
  937. last;
  938. }
  939. }
  940. if (!$filled) {
  941. for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
  942. }
  943. }
  944. }
  945. if ($form->{formname} eq 'pick_list') {
  946. $form->{label} = $locale->text('Pick List');
  947. if ($form->{type} ne 'invoice') {
  948. $inv = "ord";
  949. $due = "req";
  950. $order = 1;
  951. $numberfld = "sonumber";
  952. }
  953. }
  954. if ($form->{formname} eq 'purchase_order') {
  955. $inv = "ord";
  956. $due = "req";
  957. $form->{label} = $locale->text('Purchase Order');
  958. $numberfld = "ponumber";
  959. $order = 1;
  960. }
  961. if ($form->{formname} eq 'bin_list') {
  962. $inv = "ord";
  963. $due = "req";
  964. $form->{label} = $locale->text('Bin List');
  965. $numberfld = "ponumber";
  966. $order = 1;
  967. }
  968. if ($form->{formname} eq 'sales_quotation') {
  969. $inv = "quo";
  970. $due = "req";
  971. $form->{label} = $locale->text('Quotation');
  972. $numberfld = "sqnumber";
  973. $order = 1;
  974. }
  975. if ($form->{formname} eq 'request_quotation') {
  976. $inv = "quo";
  977. $due = "req";
  978. $form->{label} = $locale->text('Quotation');
  979. $numberfld = "rfqnumber";
  980. $order = 1;
  981. }
  982. &validate_items;
  983. $form->{"${inv}date"} = $form->{transdate};
  984. $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
  985. $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
  986. # get next number
  987. if (! $form->{"${inv}number"}) {
  988. $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
  989. if ($form->{media} eq 'screen') {
  990. &update;
  991. exit;
  992. }
  993. }
  994. # $locale->text('Invoice Number missing!')
  995. # $locale->text('Invoice Date missing!')
  996. # $locale->text('Packing List Number missing!')
  997. # $locale->text('Packing List Date missing!')
  998. # $locale->text('Order Number missing!')
  999. # $locale->text('Order Date missing!')
  1000. # $locale->text('Quotation Number missing!')
  1001. # $locale->text('Quotation Date missing!')
  1002. &{ "$form->{vc}_details" };
  1003. @a = ();
  1004. foreach $i (1 .. $form->{rowcount}) {
  1005. push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i", "notes_$i");
  1006. }
  1007. for (split / /, $form->{taxaccounts}) { push @a, "${_}_description" }
  1008. $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
  1009. push @a, $ARAP;
  1010. # format payment dates
  1011. for $i (1 .. $form->{paidaccounts} - 1) {
  1012. if (exists $form->{longformat}) {
  1013. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  1014. }
  1015. push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
  1016. }
  1017. $form->format_string(@a);
  1018. ($form->{employee}) = split /--/, $form->{employee};
  1019. ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
  1020. # this is a label for the subtotals
  1021. $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
  1022. delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
  1023. $duedate = $form->{"${due}date"};
  1024. # create the form variables
  1025. if ($order) {
  1026. OE->order_details(\%myconfig, \%$form);
  1027. } else {
  1028. IS->invoice_details(\%myconfig, \%$form);
  1029. }
  1030. if (exists $form->{longformat}) {
  1031. $form->{"${due}date"} = $duedate;
  1032. for ("${inv}date", "${due}date", "shippingdate", "transdate") { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
  1033. }
  1034. @a = qw(name address1 address2 city state zipcode country contact phone fax email);
  1035. $shipto = 1;
  1036. # if there is no shipto fill it in from billto
  1037. foreach $item (@a) {
  1038. if ($form->{"shipto$item"}) {
  1039. $shipto = 0;
  1040. last;
  1041. }
  1042. }
  1043. if ($shipto) {
  1044. if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
  1045. $form->{shiptoname} = $myconfig{company};
  1046. $form->{shiptoaddress1} = $myconfig{address};
  1047. $form->{shiptoaddress1} =~ s/\\n/\n/g;
  1048. } else {
  1049. if ($form->{formname} !~ /bin_list/) {
  1050. for (@a) { $form->{"shipto$_"} = $form->{$_} }
  1051. }
  1052. }
  1053. }
  1054. # some of the stuff could have umlauts so we translate them
  1055. push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes intnotes employee warehouse);
  1056. push @a, ("${inv}number", "${inv}date", "${due}date");
  1057. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  1058. $form->{address} =~ s/\\n/\n/g;
  1059. for (qw(name email)) { $form->{"user$_"} = $myconfig{$_} }
  1060. push @a, qw(company address tel fax businessnumber username useremail);
  1061. for (qw(notes intnotes)) { $form->{$_} =~ s/^\s+//g }
  1062. # before we format replace <%var%>
  1063. for (qw(notes intnotes message)) { $form->{$_} =~ s/<%(.*?)%>/$form->{$1}/g }
  1064. $form->format_string(@a);
  1065. $form->{templates} = "$myconfig{templates}";
  1066. $form->{IN} = "$form->{formname}.$form->{format}";
  1067. if ($form->{format} =~ /(postscript|pdf)/) {
  1068. $form->{IN} =~ s/$&$/tex/;
  1069. }
  1070. $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt';
  1071. if ($form->{media} !~ /(screen|queue|email)/) {
  1072. $form->{OUT} = "| ${LedgerSMB::SysConfig::printer}{$form->{media}}";
  1073. $form->{OUT} =~ s/<%(fax)%>/<%$form->{vc}$1%>/;
  1074. $form->{OUT} =~ s/<%(.*?)%>/$form->{$1}/g;
  1075. if ($form->{printed} !~ /$form->{formname}/) {
  1076. $form->{printed} .= " $form->{formname}";
  1077. $form->{printed} =~ s/^ //;
  1078. $form->update_status(\%myconfig);
  1079. }
  1080. $old_form->{printed} = $form->{printed} if defined %$old_form;
  1081. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1082. reference => $form->{"${inv}number"},
  1083. formname => $form->{formname},
  1084. action => 'printed',
  1085. id => $form->{id} );
  1086. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1087. }
  1088. if ($form->{media} eq 'email') {
  1089. $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
  1090. $form->{plainpaper} = 1;
  1091. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1092. if ($form->{emailed} !~ /$form->{formname}/) {
  1093. $form->{emailed} .= " $form->{formname}";
  1094. $form->{emailed} =~ s/^ //;
  1095. # save status
  1096. $form->update_status(\%myconfig);
  1097. }
  1098. $now = scalar localtime;
  1099. $cc = $locale->text('Cc: [_1]', $form->{cc}).qq|\n| if $form->{cc};
  1100. $bcc = $locale->text('Bcc: [_1]', $form->{bcc}).qq|\n| if $form->{bcc};
  1101. if (defined %$old_form) {
  1102. $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
  1103. $old_form->{intnotes} .= qq|[email]\n|
  1104. .$locale->text('Date: [_1]', $now).qq|\n|
  1105. .$locale->text('To: [_1]', $form->{email}).qq|\n${cc}${bcc}|
  1106. .$locale->text('Subject: [_1]', $form->{subject}).qq|\n|;
  1107. $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
  1108. $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
  1109. $old_form->{message} = $form->{message};
  1110. $old_form->{emailed} = $form->{emailed};
  1111. $old_form->{format} = "postscript" if $myconfig{printer};
  1112. $old_form->{media} = $myconfig{printer};
  1113. $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
  1114. }
  1115. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1116. reference => $form->{"${inv}number"},
  1117. formname => $form->{formname},
  1118. action => 'emailed',
  1119. id => $form->{id} );
  1120. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1121. }
  1122. if ($form->{media} eq 'queue') {
  1123. %queued = split / /, $form->{queued};
  1124. if ($filename = $queued{$form->{formname}}) {
  1125. $form->{queued} =~ s/$form->{formname} $filename//;
  1126. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  1127. $filename =~ s/\..*$//g;
  1128. } else {
  1129. $filename = time;
  1130. $filename .= $$;
  1131. }
  1132. $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
  1133. $form->{OUT} = ">${LedgerSMB::Sysconfig::spool}/$filename";
  1134. $form->{queued} .= " $form->{formname} $filename";
  1135. $form->{queued} =~ s/^ //;
  1136. # save status
  1137. $form->update_status(\%myconfig);
  1138. $old_form->{queued} = $form->{queued};
  1139. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1140. reference => $form->{"${inv}number"},
  1141. formname => $form->{formname},
  1142. action => 'queued',
  1143. id => $form->{id} );
  1144. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  1145. }
  1146. $form->format_string("email", "cc", "bcc");
  1147. $form->{fileid} = $form->{"${inv}number"};
  1148. $form->{fileid} =~ s/(\s|\W)+//g;
  1149. $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
  1150. # if we got back here restore the previous form
  1151. if (defined %$old_form) {
  1152. $old_form->{"${inv}number"} = $form->{"${inv}number"};
  1153. # restore and display form
  1154. for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
  1155. delete $form->{pre};
  1156. $form->{rowcount}--;
  1157. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1158. for $i (1 .. $form->{paidaccounts}) {
  1159. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  1160. }
  1161. &{ "$display_form" };
  1162. }
  1163. }
  1164. sub customer_details {
  1165. IS->customer_details(\%myconfig, \%$form);
  1166. }
  1167. sub vendor_details {
  1168. IR->vendor_details(\%myconfig, \%$form);
  1169. }
  1170. sub ship_to {
  1171. $title = $form->{title};
  1172. $form->{title} = $locale->text('Ship to');
  1173. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1174. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->parse_amount(\%myconfig, $form->{"paid_$_"}) }
  1175. # get details for name
  1176. &{ "$form->{vc}_details" };
  1177. $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
  1178. $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
  1179. $form->{rowcount}--;
  1180. $form->header;
  1181. print qq|
  1182. <body>
  1183. <form method=post action=$form->{script}>
  1184. <table width=100%>
  1185. <tr>
  1186. <td>
  1187. <table>
  1188. <tr class=listheading>
  1189. <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
  1190. <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
  1191. </tr>
  1192. <tr height="5"></tr>
  1193. <tr>
  1194. <th align=right nowrap>$number</th>
  1195. <td>$form->{"$form->{vc}number"}</td>
  1196. </tr>
  1197. <tr>
  1198. <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
  1199. <td>$form->{name}</td>
  1200. <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
  1201. </tr>
  1202. <tr>
  1203. <th align=right nowrap>|.$locale->text('Address').qq|</th>
  1204. <td>$form->{address1}</td>
  1205. <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
  1206. </tr>
  1207. <tr>
  1208. <th></th>
  1209. <td>$form->{address2}</td>
  1210. <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
  1211. </tr>
  1212. <tr>
  1213. <th align=right nowrap>|.$locale->text('City').qq|</th>
  1214. <td>$form->{city}</td>
  1215. <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
  1216. </tr>
  1217. <tr>
  1218. <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
  1219. <td>$form->{state}</td>
  1220. <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
  1221. </tr>
  1222. <tr>
  1223. <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
  1224. <td>$form->{zipcode}</td>
  1225. <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
  1226. </tr>
  1227. <tr>
  1228. <th align=right nowrap>|.$locale->text('Country').qq|</th>
  1229. <td>$form->{country}</td>
  1230. <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
  1231. </tr>
  1232. <tr>
  1233. <th align=right nowrap>|.$locale->text('Contact').qq|</th>
  1234. <td>$form->{contact}</td>
  1235. <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
  1236. </tr>
  1237. <tr>
  1238. <th align=right nowrap>|.$locale->text('Phone').qq|</th>
  1239. <td>$form->{"$form->{vc}phone"}</td>
  1240. <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
  1241. </tr>
  1242. <tr>
  1243. <th align=right nowrap>|.$locale->text('Fax').qq|</th>
  1244. <td>$form->{"$form->{vc}fax"}</td>
  1245. <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
  1246. </tr>
  1247. <tr>
  1248. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  1249. <td>$form->{email}</td>
  1250. <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
  1251. </tr>
  1252. </table>
  1253. </td>
  1254. </tr>
  1255. </table>
  1256. <input type=hidden name=nextsub value=$nextsub>
  1257. |;
  1258. # delete shipto
  1259. for (qw(action nextsub)) { delete $form->{$_} }
  1260. for (qw(name address1 address2 city state zipcode country contact phone fax email)) { delete $form->{"shipto$_"} }
  1261. $form->{title} = $title;
  1262. $form->hide_form;
  1263. print qq|
  1264. <hr size=3 noshade>
  1265. <br>
  1266. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1267. </form>
  1268. </body>
  1269. </html>
  1270. |;
  1271. }