summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: ce93f3a7d4fbd266d1d2358b07c759eca6c8d50a (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. #
  7. # Copyright (C) 2006
  8. # This work contains copyrighted information from a number of sources all used
  9. # with permission.
  10. #
  11. # This file contains source code included with or based on SQL-Ledger which
  12. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  13. # under the GNU General Public License version 2 or, at your option, any later
  14. # version. For a full list including contact information of contributors,
  15. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  16. #
  17. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  18. # Copyright (c) 2001
  19. #
  20. # Author: DWS Systems Inc.
  21. # Web: http://www.sql-ledger.org
  22. #
  23. # Contributors:
  24. #
  25. #======================================================================
  26. #
  27. # This file has NOT undergone whitespace cleanup.
  28. #
  29. #======================================================================
  30. #
  31. # administration
  32. #
  33. #======================================================================
  34. use LedgerSMB::AM;
  35. use LedgerSMB::CA;
  36. use LedgerSMB::Form;
  37. use LedgerSMB::User;
  38. use LedgerSMB::RP;
  39. use LedgerSMB::GL;
  40. 1;
  41. # end of main
  42. sub add { &{ "add_$form->{type}" } };
  43. sub edit { &{ "edit_$form->{type}" } };
  44. sub save { &{ "save_$form->{type}" } };
  45. sub delete { &{ "delete_$form->{type}" } };
  46. sub save_as_new {
  47. delete $form->{id};
  48. &save;
  49. }
  50. sub add_account {
  51. $form->{title} = "Add";
  52. $form->{charttype} = "A";
  53. $form->{callback} = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  54. &account_header;
  55. &form_footer;
  56. }
  57. sub edit_account {
  58. $form->{title} = "Edit";
  59. $form->{accno} =~ s/\\'/'/g;
  60. $form->{accno} =~ s/\\\\/\\/g;
  61. AM->get_account(\%myconfig, \%$form);
  62. foreach my $item (split(/:/, $form->{link})) {
  63. $form->{$item} = "checked";
  64. }
  65. &account_header;
  66. &form_footer;
  67. }
  68. sub account_header {
  69. $form->{title} = $locale->text("$form->{title} Account");
  70. $checked{$form->{charttype}} = "checked";
  71. $checked{contra} = "checked" if $form->{contra};
  72. $checked{"$form->{category}_"} = "checked";
  73. for (qw(accno description)) { $form->{$_} = $form->quote($form->{$_}) }
  74. # this is for our parser only!
  75. # type=submit $locale->text('Add Account')
  76. # type=submit $locale->text('Edit Account')
  77. $form->header;
  78. print qq|
  79. <body>
  80. <form method=post action=$form->{script}>
  81. <input type=hidden name=id value=$form->{id}>
  82. <input type=hidden name=type value=account>
  83. <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>
  84. <input type=hidden name=income_accno_id value=$form->{income_accno_id}>
  85. <input type=hidden name=expense_accno_id value=$form->{expense_accno_id}>
  86. <input type=hidden name=fxgain_accno_id values=$form->{fxgain_accno_id}>
  87. <input type=hidden name=fxloss_accno_id values=$form->{fxloss_accno_id}>
  88. <table border=0 width=100%>
  89. <tr>
  90. <th class=listtop>$form->{title}</th>
  91. </tr>
  92. <tr height="5"></tr>
  93. <tr valign=top>
  94. <td>
  95. <table>
  96. <tr>
  97. <th align="right">|.$locale->text('Account Number').qq|</th>
  98. <td><input name=accno size=20 value="$form->{accno}"></td>
  99. </tr>
  100. <tr>
  101. <th align="right">|.$locale->text('Description').qq|</th>
  102. <td><input name=description size=40 value="$form->{description}"></td>
  103. </tr>
  104. <tr>
  105. <th align="right">|.$locale->text('Account Type').qq|</th>
  106. <td>
  107. <table>
  108. <tr valign=top>
  109. <td><input name=category type=radio class=radio value=A $checked{A_}>&nbsp;|.$locale->text('Asset').qq|\n<br>
  110. <input name=category type=radio class=radio value=L $checked{L_}>&nbsp;|.$locale->text('Liability').qq|\n<br>
  111. <input name=category type=radio class=radio value=Q $checked{Q_}>&nbsp;|.$locale->text('Equity').qq|\n<br>
  112. <input name=category type=radio class=radio value=I $checked{I_}>&nbsp;|.$locale->text('Income').qq|\n<br>
  113. <input name=category type=radio class=radio value=E $checked{E_}>&nbsp;|.$locale->text('Expense')
  114. .qq|</td>
  115. <td>
  116. <input name=contra class=checkbox type=checkbox value=1 $checked{contra}>&nbsp;|.$locale->text('Contra').qq|
  117. </td>
  118. <td>
  119. <input name=charttype type=radio class=radio value="H" $checked{H}>&nbsp;|.$locale->text('Heading').qq|<br>
  120. <input name=charttype type=radio class=radio value="A" $checked{A}>&nbsp;|.$locale->text('Account')
  121. .qq|</td>
  122. </tr>
  123. </table>
  124. </td>
  125. </tr>
  126. |;
  127. if ($form->{charttype} eq "A") {
  128. print qq|
  129. <tr>
  130. <td colspan=2>
  131. <table>
  132. <tr>
  133. <th align=left>|.$locale->text('Is this a summary account to record').qq|</th>
  134. <td>
  135. <input name=AR class=checkbox type=checkbox value=AR $form->{AR}>&nbsp;|.$locale->text('AR')
  136. .qq|&nbsp;<input name=AP class=checkbox type=checkbox value=AP $form->{AP}>&nbsp;|.$locale->text('AP')
  137. .qq|&nbsp;<input name=IC class=checkbox type=checkbox value=IC $form->{IC}>&nbsp;|.$locale->text('Inventory')
  138. .qq|</td>
  139. </tr>
  140. </table>
  141. </td>
  142. </tr>
  143. <tr>
  144. <th colspan=2>|.$locale->text('Include in drop-down menus').qq|</th>
  145. </tr>
  146. <tr valign=top>
  147. <td colspan=2>
  148. <table width=100%>
  149. <tr>
  150. <th align=left>|.$locale->text('Receivables').qq|</th>
  151. <th align=left>|.$locale->text('Payables').qq|</th>
  152. <th align=left>|.$locale->text('Tracking Items').qq|</th>
  153. <th align=left>|.$locale->text('Non-tracking Items').qq|</th>
  154. </tr>
  155. <tr>
  156. <td>
  157. <input name=AR_amount class=checkbox type=checkbox value=AR_amount $form->{AR_amount}>&nbsp;|.$locale->text('Income').qq|\n<br>
  158. <input name=AR_paid class=checkbox type=checkbox value=AR_paid $form->{AR_paid}>&nbsp;|.$locale->text('Payment').qq|\n<br>
  159. <input name=AR_tax class=checkbox type=checkbox value=AR_tax $form->{AR_tax}>&nbsp;|.$locale->text('Tax') .qq|
  160. </td>
  161. <td>
  162. <input name=AP_amount class=checkbox type=checkbox value=AP_amount $form->{AP_amount}>&nbsp;|.$locale->text('Expense/Asset').qq|\n<br>
  163. <input name=AP_paid class=checkbox type=checkbox value=AP_paid $form->{AP_paid}>&nbsp;|.$locale->text('Payment').qq|\n<br>
  164. <input name=AP_tax class=checkbox type=checkbox value=AP_tax $form->{AP_tax}>&nbsp;|.$locale->text('Tax') .qq|
  165. </td>
  166. <td>
  167. <input name=IC_sale class=checkbox type=checkbox value=IC_sale $form->{IC_sale}>&nbsp;|.$locale->text('Income').qq|\n<br>
  168. <input name=IC_cogs class=checkbox type=checkbox value=IC_cogs $form->{IC_cogs}>&nbsp;|.$locale->text('COGS').qq|\n<br>
  169. <input name=IC_taxpart class=checkbox type=checkbox value=IC_taxpart $form->{IC_taxpart}>&nbsp;|.$locale->text('Tax') .qq|
  170. </td>
  171. <td>
  172. <input name=IC_income class=checkbox type=checkbox value=IC_income $form->{IC_income}>&nbsp;|.$locale->text('Income').qq|\n<br>
  173. <input name=IC_expense class=checkbox type=checkbox value=IC_expense $form->{IC_expense}>&nbsp;|.$locale->text('Expense').qq|\n<br>
  174. <input name=IC_taxservice class=checkbox type=checkbox value=IC_taxservice $form->{IC_taxservice}>&nbsp;|.$locale->text('Tax') .qq|
  175. </td>
  176. </tr>
  177. </table>
  178. </td>
  179. </tr>
  180. <tr>
  181. </tr>
  182. |;
  183. }
  184. print qq|
  185. <tr>
  186. <th align="right">|.$locale->text('GIFI').qq|</th>
  187. <td><input name=gifi_accno size=9 value=$form->{gifi_accno}></td>
  188. </tr>
  189. </table>
  190. </td>
  191. </tr>
  192. <tr>
  193. <td><hr size=3 noshade></td>
  194. </tr>
  195. </table>
  196. |;
  197. }
  198. sub form_footer {
  199. $form->hide_form(qw(callback path login sessionid));
  200. # type=submit $locale->text('Save')
  201. # type=submit $locale->text('Save as new')
  202. # type=submit $locale->text('Delete')
  203. %button = ();
  204. if ($form->{id}) {
  205. $button{'Save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
  206. $button{'Save as new'} = { ndx => 7, key => 'N', value => $locale->text('Save as new') };
  207. if ($form->{orphaned}) {
  208. $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
  209. }
  210. } else {
  211. $button{'Save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
  212. }
  213. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  214. if ($form->{lynx}) {
  215. require "bin/menu.pl";
  216. &menubar;
  217. }
  218. print qq|
  219. </form>
  220. </body>
  221. </html>
  222. |;
  223. }
  224. sub save_account {
  225. $form->isblank("accno", $locale->text('Account Number missing!'));
  226. $form->isblank("category", $locale->text('Account Type missing!'));
  227. # check for conflicting accounts
  228. if ($form->{AR} || $form->{AP} || $form->{IC}) {
  229. $a = "";
  230. for (qw(AR AP IC)) { $a .= $form->{$_} }
  231. $form->error($locale->text('Cannot set account for more than one of AR, AP or IC')) if length $a > 2;
  232. for (qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_taxpart IC_taxservice IC_sale IC_cogs IC_income IC_expense)) { $form->error("$form->{AR}$form->{AP}$form->{IC} ". $locale->text('account cannot be set to any other type of account')) if $form->{$_} }
  233. }
  234. foreach $item ("AR", "AP") {
  235. $i = 0;
  236. for ("${item}_amount", "${item}_paid", "${item}_tax") { $i++ if $form->{$_} }
  237. $form->error($locale->text('Cannot set multiple options for')." $item") if $i > 1;
  238. }
  239. if (AM->save_account(\%myconfig, \%$form)) {
  240. $form->redirect($locale->text('Account saved!'));
  241. } else {
  242. $form->error($locale->text('Cannot save account!'));
  243. }
  244. }
  245. sub list_account {
  246. CA->all_accounts(\%myconfig, \%$form);
  247. $form->{title} = $locale->text('Chart of Accounts');
  248. # construct callback
  249. $callback = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  250. @column_index = qw(accno gifi_accno description debit credit link);
  251. $column_header{accno} = qq|<th class=listtop>|.$locale->text('Account').qq|</a></th>|;
  252. $column_header{gifi_accno} = qq|<th class=listtop>|.$locale->text('GIFI').qq|</a></th>|;
  253. $column_header{description} = qq|<th class=listtop>|.$locale->text('Description').qq|</a></th>|;
  254. $column_header{debit} = qq|<th class=listtop>|.$locale->text('Debit').qq|</a></th>|;
  255. $column_header{credit} = qq|<th class=listtop>|.$locale->text('Credit').qq|</a></th>|;
  256. $column_header{link} = qq|<th class=listtop>|.$locale->text('Link').qq|</a></th>|;
  257. $form->header;
  258. $colspan = $#column_index + 1;
  259. print qq|
  260. <body>
  261. <table width=100%>
  262. <tr>
  263. <th class=listtop colspan=$colspan>$form->{title}</th>
  264. </tr>
  265. <tr height="5"></tr>
  266. <tr class="listheading">
  267. |;
  268. for (@column_index) { print "$column_header{$_}\n" }
  269. print qq|
  270. </tr>
  271. |;
  272. # escape callback
  273. $callback = $form->escape($callback);
  274. foreach $ca (@{ $form->{CA} }) {
  275. $ca->{debit} = "&nbsp;";
  276. $ca->{credit} = "&nbsp;";
  277. if ($ca->{amount} > 0) {
  278. $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2, "&nbsp;");
  279. }
  280. if ($ca->{amount} < 0) {
  281. $ca->{debit} = $form->format_amount(\%myconfig, -$ca->{amount}, 2, "&nbsp;");
  282. }
  283. $ca->{link} =~ s/:/<br>/og;
  284. $gifi_accno = $form->escape($ca->{gifi_accno});
  285. if ($ca->{charttype} eq "H") {
  286. print qq|<tr class="listheading">|;
  287. $column_data{accno} = qq|<th><a class="listheading" href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></th>|;
  288. $column_data{gifi_accno} = qq|<th class="listheading"><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</th>|;
  289. $column_data{description} = qq|<th class="listheading">$ca->{description}&nbsp;</th>|;
  290. $column_data{debit} = qq|<th>&nbsp;</th>|;
  291. $column_data{credit} = qq| <th>&nbsp;</th>|;
  292. $column_data{link} = qq|<th>&nbsp;</th>|;
  293. } else {
  294. $i++; $i %= 2;
  295. print qq|
  296. <tr valign=top class="listrow$i">|;
  297. $column_data{accno} = qq|<td><a href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></td>|;
  298. $column_data{gifi_accno} = qq|<td><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</td>|;
  299. $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
  300. $column_data{debit} = qq|<td align="right">$ca->{debit}</td>|;
  301. $column_data{credit} = qq|<td align="right">$ca->{credit}</td>|;
  302. $column_data{link} = qq|<td>$ca->{link}&nbsp;</td>|;
  303. }
  304. for (@column_index) { print "$column_data{$_}\n" }
  305. print "</tr>\n";
  306. }
  307. print qq|
  308. <tr><td colspan="$colspan"><hr size="3" noshade /></td></tr>
  309. </table>
  310. </body>
  311. </html>
  312. |;
  313. }
  314. sub delete_account {
  315. $form->{title} = $locale->text('Delete Account');
  316. foreach $id (qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)) {
  317. if ($form->{id} == $form->{$id}) {
  318. $form->error($locale->text('Cannot delete default account!'));
  319. }
  320. }
  321. if (AM->delete_account(\%myconfig, \%$form)) {
  322. $form->redirect($locale->text('Account deleted!'));
  323. } else {
  324. $form->error($locale->text('Cannot delete account!'));
  325. }
  326. }
  327. sub list_gifi {
  328. @{ $form->{fields} } = qw(accno description);
  329. $form->{table} = "gifi";
  330. AM->gifi_accounts(\%myconfig, \%$form);
  331. $form->{title} = $locale->text('GIFI');
  332. # construct callback
  333. $callback = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  334. @column_index = qw(accno description);
  335. $column_header{accno} = qq|<th class="listheading">|.$locale->text('GIFI').qq|</a></th>|;
  336. $column_header{description} = qq|<th class="listheading">|.$locale->text('Description').qq|</a></th>|;
  337. $form->header;
  338. $colspan = $#column_index + 1;
  339. print qq|
  340. <body>
  341. <table width=100%>
  342. <tr>
  343. <th class=listtop colspan=$colspan>$form->{title}</th>
  344. </tr>
  345. <tr height="5"></tr>
  346. <tr class="listheading">
  347. |;
  348. for (@column_index) { print "$column_header{$_}\n" }
  349. print qq|
  350. </tr>
  351. |;
  352. # escape callback
  353. $callback = $form->escape($callback);
  354. foreach $ca (@{ $form->{ALL} }) {
  355. $i++; $i %= 2;
  356. print qq|
  357. <tr valign=top class=listrow$i>|;
  358. $accno = $form->escape($ca->{accno});
  359. $column_data{accno} = qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{accno}</td>|;
  360. $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
  361. for (@column_index) { print "$column_data{$_}\n" }
  362. print "</tr>\n";
  363. }
  364. print qq|
  365. <tr>
  366. <td colspan=$colspan><hr size=3 noshade></td>
  367. </tr>
  368. </table>
  369. </body>
  370. </html>
  371. |;
  372. }
  373. sub add_gifi {
  374. $form->{title} = "Add";
  375. # construct callback
  376. $form->{callback} = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  377. $form->{coa} = 1;
  378. &gifi_header;
  379. &gifi_footer;
  380. }
  381. sub edit_gifi {
  382. $form->{title} = "Edit";
  383. AM->get_gifi(\%myconfig, \%$form);
  384. $form->error($locale->text('Account does not exist!')) unless $form->{accno};
  385. &gifi_header;
  386. &gifi_footer;
  387. }
  388. sub gifi_header {
  389. $form->{title} = $locale->text("$form->{title} GIFI");
  390. # $locale->text('Add GIFI')
  391. # $locale->text('Edit GIFI')
  392. for (qw(accno description)) { $form->{$_} = $form->quote($form->{$_}) }
  393. $form->header;
  394. print qq|
  395. <body>
  396. <form method=post action=$form->{script}>
  397. <input type=hidden name=id value="$form->{accno}">
  398. <input type=hidden name=type value=gifi>
  399. <table width=100%>
  400. <tr>
  401. <th class=listtop>$form->{title}</th>
  402. </tr>
  403. <tr height="5"></tr>
  404. <tr>
  405. <td>
  406. <table>
  407. <tr>
  408. <th align="right">|.$locale->text('GIFI').qq|</th>
  409. <td><input name=accno size=20 value="$form->{accno}"></td>
  410. </tr>
  411. <tr>
  412. <th align="right">|.$locale->text('Description').qq|</th>
  413. <td><input name=description size=60 value="$form->{description}"></td>
  414. </tr>
  415. </table>
  416. </td>
  417. </tr>
  418. <tr>
  419. <td colspan=2><hr size=3 noshade></td>
  420. </tr>
  421. </table>
  422. |;
  423. }
  424. sub gifi_footer {
  425. $form->hide_form(qw(callback path login sessionid));
  426. # type=submit $locale->text('Save')
  427. # type=submit $locale->text('Copy to COA')
  428. # type=submit $locale->text('Delete')
  429. %button = ();
  430. $button{'Save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
  431. if ($form->{accno}) {
  432. if ($form->{orphaned}) {
  433. $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
  434. }
  435. }
  436. if ($form->{coa}) {
  437. $button{'Copy to COA'} = { ndx => 7, key => 'C', value => $locale->text('Copy to COA') };
  438. }
  439. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  440. if ($form->{lynx}) {
  441. require "bin/menu.pl";
  442. &menubar;
  443. }
  444. print qq|
  445. </form>
  446. </body>
  447. </html>
  448. |;
  449. }
  450. sub save_gifi {
  451. $form->isblank("accno", $locale->text('GIFI missing!'));
  452. AM->save_gifi(\%myconfig, \%$form);
  453. $form->redirect($locale->text('GIFI saved!'));
  454. }
  455. sub copy_to_coa {
  456. $form->isblank("accno", $locale->text('GIFI missing!'));
  457. AM->save_gifi(\%myconfig, \%$form);
  458. delete $form->{id};
  459. $form->{gifi_accno} = $form->{accno};
  460. $form->{title} = "Add";
  461. $form->{charttype} = "A";
  462. &account_header;
  463. &form_footer;
  464. }
  465. sub delete_gifi {
  466. AM->delete_gifi(\%myconfig, \%$form);
  467. $form->redirect($locale->text('GIFI deleted!'));
  468. }
  469. sub add_department {
  470. $form->{title} = "Add";
  471. $form->{role} = "P";
  472. $form->{callback} = "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  473. &department_header;
  474. &form_footer;
  475. }
  476. sub edit_department {
  477. $form->{title} = "Edit";
  478. AM->get_department(\%myconfig, \%$form);
  479. &department_header;
  480. &form_footer;
  481. }
  482. sub list_department {
  483. AM->departments(\%myconfig, \%$form);
  484. $href = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  485. $form->sort_order();
  486. $form->{callback} = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  487. $callback = $form->escape($form->{callback});
  488. $form->{title} = $locale->text('Departments');
  489. @column_index = qw(description cost profit);
  490. $column_header{description} = qq|<th width=90%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
  491. $column_header{cost} = qq|<th class="listheading" nowrap>|.$locale->text('Cost Center').qq|</th>|;
  492. $column_header{profit} = qq|<th class="listheading" nowrap>|.$locale->text('Profit Center').qq|</th>|;
  493. $form->header;
  494. print qq|
  495. <body>
  496. <table width=100%>
  497. <tr>
  498. <th class=listtop>$form->{title}</th>
  499. </tr>
  500. <tr height="5"></tr>
  501. <tr>
  502. <td>
  503. <table width=100%>
  504. <tr class="listheading">
  505. |;
  506. for (@column_index) { print "$column_header{$_}\n" }
  507. print qq|
  508. </tr>
  509. |;
  510. foreach $ref (@{ $form->{ALL} }) {
  511. $i++; $i %= 2;
  512. print qq|
  513. <tr valign=top class=listrow$i>
  514. |;
  515. $costcenter = ($ref->{role} eq "C") ? "*" : "&nbsp;";
  516. $profitcenter = ($ref->{role} eq "P") ? "*" : "&nbsp;";
  517. $column_data{description} = qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  518. $column_data{cost} = qq|<td align=center>$costcenter</td>|;
  519. $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
  520. for (@column_index) { print "$column_data{$_}\n" }
  521. print qq|
  522. </tr>
  523. |;
  524. }
  525. print qq|
  526. </table>
  527. </td>
  528. </tr>
  529. <tr>
  530. <td><hr size=3 noshade></td>
  531. </tr>
  532. </table>
  533. <br>
  534. <form method=post action=$form->{script}>
  535. |;
  536. $form->{type} = "department";
  537. $form->hide_form(qw(type callback path login sessionid));
  538. print qq|
  539. <input class=submit type=submit name=action value="|.$locale->text('Add Department').qq|">|;
  540. if ($form->{lynx}) {
  541. require "bin/menu.pl";
  542. &menubar;
  543. }
  544. print qq|
  545. </form>
  546. </body>
  547. </html>
  548. |;
  549. }
  550. sub department_header {
  551. $form->{title} = $locale->text("$form->{title} Department");
  552. # $locale->text('Add Department')
  553. # $locale->text('Edit Department')
  554. $form->{description} = $form->quote($form->{description});
  555. if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
  556. $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  557. } else {
  558. $description = qq|<input name=description size=60 value="$form->{description}">|;
  559. }
  560. $costcenter = "checked" if $form->{role} eq "C";
  561. $profitcenter = "checked" if $form->{role} eq "P";
  562. $form->header;
  563. print qq|
  564. <body>
  565. <form method=post action=$form->{script}>
  566. <input type=hidden name=id value=$form->{id}>
  567. <input type=hidden name=type value=department>
  568. <table width=100%>
  569. <tr>
  570. <th class=listtop colspan=2>$form->{title}</th>
  571. </tr>
  572. <tr height="5"></tr>
  573. <tr>
  574. <th align="right">|.$locale->text('Description').qq|</th>
  575. <td>$description</td>
  576. </tr>
  577. <tr>
  578. <td></td>
  579. <td><input type=radio style=radio name=role value="C" $costcenter> |.$locale->text('Cost Center').qq|
  580. <input type=radio style=radio name=role value="P" $profitcenter> |.$locale->text('Profit Center').qq|
  581. </td>
  582. <tr>
  583. <td colspan=2><hr size=3 noshade></td>
  584. </tr>
  585. </table>
  586. |;
  587. }
  588. sub save_department {
  589. $form->isblank("description", $locale->text('Description missing!'));
  590. AM->save_department(\%myconfig, \%$form);
  591. $form->redirect($locale->text('Department saved!'));
  592. }
  593. sub delete_department {
  594. AM->delete_department(\%myconfig, \%$form);
  595. $form->redirect($locale->text('Department deleted!'));
  596. }
  597. sub add_business {
  598. $form->{title} = "Add";
  599. $form->{callback} = "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  600. &business_header;
  601. &form_footer;
  602. }
  603. sub edit_business {
  604. $form->{title} = "Edit";
  605. AM->get_business(\%myconfig, \%$form);
  606. &business_header;
  607. $form->{orphaned} = 1;
  608. &form_footer;
  609. }
  610. sub list_business {
  611. AM->business(\%myconfig, \%$form);
  612. $href = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  613. $form->sort_order();
  614. $form->{callback} = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  615. $callback = $form->escape($form->{callback});
  616. $form->{title} = $locale->text('Type of Business');
  617. @column_index = qw(description discount);
  618. $column_header{description} = qq|<th width=90%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
  619. $column_header{discount} = qq|<th class="listheading">|.$locale->text('Discount').qq| %</th>|;
  620. $form->header;
  621. print qq|
  622. <body>
  623. <table width=100%>
  624. <tr>
  625. <th class=listtop>$form->{title}</th>
  626. </tr>
  627. <tr height="5"></tr>
  628. <tr>
  629. <td>
  630. <table width=100%>
  631. <tr class="listheading">
  632. |;
  633. for (@column_index) { print "$column_header{$_}\n" }
  634. print qq|
  635. </tr>
  636. |;
  637. foreach $ref (@{ $form->{ALL} }) {
  638. $i++; $i %= 2;
  639. print qq|
  640. <tr valign=top class=listrow$i>
  641. |;
  642. $discount = $form->format_amount(\%myconfig, $ref->{discount} * 100, 2, "&nbsp");
  643. $column_data{description} = qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  644. $column_data{discount} = qq|<td align="right">$discount</td>|;
  645. for (@column_index) { print "$column_data{$_}\n" }
  646. print qq|
  647. </tr>
  648. |;
  649. }
  650. print qq|
  651. </table>
  652. </td>
  653. </tr>
  654. <tr>
  655. <td><hr size=3 noshade></td>
  656. </tr>
  657. </table>
  658. <br>
  659. <form method=post action=$form->{script}>
  660. |;
  661. $form->{type} = "business";
  662. $form->hide_form(qw(type callback path login sessionid));
  663. print qq|
  664. <input class=submit type=submit name=action value="|.$locale->text('Add Business').qq|">|;
  665. if ($form->{lynx}) {
  666. require "bin/menu.pl";
  667. &menubar;
  668. }
  669. print qq|
  670. </form>
  671. </body>
  672. </html>
  673. |;
  674. }
  675. sub business_header {
  676. $form->{title} = $locale->text("$form->{title} Business");
  677. # $locale->text('Add Business')
  678. # $locale->text('Edit Business')
  679. $form->{description} = $form->quote($form->{description});
  680. $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100);
  681. $form->header;
  682. print qq|
  683. <body>
  684. <form method=post action=$form->{script}>
  685. <input type=hidden name=id value=$form->{id}>
  686. <input type=hidden name=type value=business>
  687. <table width=100%>
  688. <tr>
  689. <th class=listtop>$form->{title}</th>
  690. </tr>
  691. <tr height="5"></tr>
  692. <tr>
  693. <td>
  694. <table>
  695. <tr>
  696. <th align="right">|.$locale->text('Type of Business').qq|</th>
  697. <td><input name=description size=30 value="$form->{description}"></td>
  698. <tr>
  699. <tr>
  700. <th align="right">|.$locale->text('Discount').qq| %</th>
  701. <td><input name=discount size=5 value=$form->{discount}></td>
  702. </tr>
  703. </table>
  704. </td>
  705. </tr>
  706. <tr>
  707. <td><hr size=3 noshade></td>
  708. </tr>
  709. </table>
  710. |;
  711. }
  712. sub save_business {
  713. $form->isblank("description", $locale->text('Description missing!'));
  714. AM->save_business(\%myconfig, \%$form);
  715. $form->redirect($locale->text('Business saved!'));
  716. }
  717. sub delete_business {
  718. AM->delete_business(\%myconfig, \%$form);
  719. $form->redirect($locale->text('Business deleted!'));
  720. }
  721. sub add_sic {
  722. $form->{title} = "Add";
  723. $form->{callback} = "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  724. &sic_header;
  725. &form_footer;
  726. }
  727. sub edit_sic {
  728. $form->{title} = "Edit";
  729. $form->{code} =~ s/\\'/'/g;
  730. $form->{code} =~ s/\\\\/\\/g;
  731. AM->get_sic(\%myconfig, \%$form);
  732. $form->{id} = $form->{code};
  733. &sic_header;
  734. $form->{orphaned} = 1;
  735. &form_footer;
  736. }
  737. sub list_sic {
  738. AM->sic(\%myconfig, \%$form);
  739. $href = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  740. $form->sort_order();
  741. $form->{callback} = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  742. $callback = $form->escape($form->{callback});
  743. $form->{title} = $locale->text('Standard Industrial Codes');
  744. @column_index = $form->sort_columns(qw(code description));
  745. $column_header{code} = qq|<th><a class="listheading" href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|;
  746. $column_header{description} = qq|<th><a class="listheading" href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  747. $form->header;
  748. print qq|
  749. <body>
  750. <table width=100%>
  751. <tr>
  752. <th class=listtop>$form->{title}</th>
  753. </tr>
  754. <tr height="5"></tr>
  755. <tr>
  756. <td>
  757. <table width=100%>
  758. <tr class="listheading">
  759. |;
  760. for (@column_index) { print "$column_header{$_}\n" }
  761. print qq|
  762. </tr>
  763. |;
  764. foreach $ref (@{ $form->{ALL} }) {
  765. $i++; $i %= 2;
  766. if ($ref->{sictype} eq 'H') {
  767. print qq|
  768. <tr valign=top class="listheading">
  769. |;
  770. $column_data{code} = qq|<th><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</th>|;
  771. $column_data{description} = qq|<th>$ref->{description}</th>|;
  772. } else {
  773. print qq|
  774. <tr valign=top class=listrow$i>
  775. |;
  776. $column_data{code} = qq|<td><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
  777. $column_data{description} = qq|<td>$ref->{description}</td>|;
  778. }
  779. for (@column_index) { print "$column_data{$_}\n" }
  780. print qq|
  781. </tr>
  782. |;
  783. }
  784. print qq|
  785. </table>
  786. </td>
  787. </tr>
  788. <tr>
  789. <td><hr size=3 noshade></td>
  790. </tr>
  791. </table>
  792. <br>
  793. <form method=post action=$form->{script}>
  794. |;
  795. $form->{type} = "sic";
  796. $form->hide_form(qw(type callback path login sessionid));
  797. print qq|
  798. <input class=submit type=submit name=action value="|.$locale->text('Add SIC').qq|">|;
  799. if ($form->{lynx}) {
  800. require "bin/menu.pl";
  801. &menubar;
  802. }
  803. print qq|
  804. </form>
  805. </body>
  806. </html>
  807. |;
  808. }
  809. sub sic_header {
  810. $form->{title} = $locale->text("$form->{title} SIC");
  811. # $locale->text('Add SIC')
  812. # $locale->text('Edit SIC')
  813. for (qw(code description)) { $form->{$_} = $form->quote($form->{$_}) }
  814. $checked = ($form->{sictype} eq 'H') ? "checked" : "";
  815. $form->header;
  816. print qq|
  817. <body>
  818. <form method=post action=$form->{script}>
  819. <input type=hidden name=type value=sic>
  820. <input type=hidden name=id value="$form->{code}">
  821. <table width=100%>
  822. <tr>
  823. <th class=listtop colspan=2>$form->{title}</th>
  824. </tr>
  825. <tr height="5"></tr>
  826. <tr>
  827. <th align="right">|.$locale->text('Code').qq|</th>
  828. <td><input name=code size=10 value="$form->{code}"></td>
  829. <tr>
  830. <tr>
  831. <td></td>
  832. <th align=left><input name=sictype class=checkbox type=checkbox value="H" $checked> |.$locale->text('Heading').qq|</th>
  833. <tr>
  834. <tr>
  835. <th align="right">|.$locale->text('Description').qq|</th>
  836. <td><input name=description size=60 value="$form->{description}"></td>
  837. </tr>
  838. <td colspan=2><hr size=3 noshade></td>
  839. </tr>
  840. </table>
  841. |;
  842. }
  843. sub save_sic {
  844. $form->isblank("code", $locale->text('Code missing!'));
  845. $form->isblank("description", $locale->text('Description missing!'));
  846. AM->save_sic(\%myconfig, \%$form);
  847. $form->redirect($locale->text('SIC saved!'));
  848. }
  849. sub delete_sic {
  850. AM->delete_sic(\%myconfig, \%$form);
  851. $form->redirect($locale->text('SIC deleted!'));
  852. }
  853. sub add_language {
  854. $form->{title} = "Add";
  855. $form->{callback} = "$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  856. &language_header;
  857. &form_footer;
  858. }
  859. sub edit_language {
  860. $form->{title} = "Edit";
  861. $form->{code} =~ s/\\'/'/g;
  862. $form->{code} =~ s/\\\\/\\/g;
  863. AM->get_language(\%myconfig, \%$form);
  864. $form->{id} = $form->{code};
  865. &language_header;
  866. $form->{orphaned} = 1;
  867. &form_footer;
  868. }
  869. sub list_language {
  870. AM->language(\%myconfig, \%$form);
  871. $href = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  872. $form->sort_order();
  873. $form->{callback} = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  874. $callback = $form->escape($form->{callback});
  875. $form->{title} = $locale->text('Languages');
  876. @column_index = $form->sort_columns(qw(code description));
  877. $column_header{code} = qq|<th><a class="listheading" href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|;
  878. $column_header{description} = qq|<th><a class="listheading" href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  879. $form->header;
  880. print qq|
  881. <body>
  882. <table width=100%>
  883. <tr>
  884. <th class=listtop>$form->{title}</th>
  885. </tr>
  886. <tr height="5"></tr>
  887. <tr>
  888. <td>
  889. <table width=100%>
  890. <tr class="listheading">
  891. |;
  892. for (@column_index) { print "$column_header{$_}\n" }
  893. print qq|
  894. </tr>
  895. |;
  896. foreach $ref (@{ $form->{ALL} }) {
  897. $i++; $i %= 2;
  898. print qq|
  899. <tr valign=top class=listrow$i>
  900. |;
  901. $column_data{code} = qq|<td><a href=$form->{script}?action=edit_language&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
  902. $column_data{description} = qq|<td>$ref->{description}</td>|;
  903. for (@column_index) { print "$column_data{$_}\n" }
  904. print qq|
  905. </tr>
  906. |;
  907. }
  908. print qq|
  909. </table>
  910. </td>
  911. </tr>
  912. <tr>
  913. <td><hr size=3 noshade></td>
  914. </tr>
  915. </table>
  916. <br>
  917. <form method=post action=$form->{script}>
  918. |;
  919. $form->{type} = "language";
  920. $form->hide_form(qw(type callback path login sessionid));
  921. print qq|
  922. <input class=submit type=submit name=action value="|.$locale->text('Add Language').qq|">|;
  923. if ($form->{lynx}) {
  924. require "bin/menu.pl";
  925. &menubar;
  926. }
  927. print qq|
  928. </form>
  929. </body>
  930. </html>
  931. |;
  932. }
  933. sub language_header {
  934. $form->{title} = $locale->text("$form->{title} Language");
  935. # $locale->text('Add Language')
  936. # $locale->text('Edit Language')
  937. for (qw(code description)) { $form->{$_} = $form->quote($form->{$_}) }
  938. $form->header;
  939. print qq|
  940. <body>
  941. <form method=post action=$form->{script}>
  942. <input type=hidden name=type value=language>
  943. <input type=hidden name=id value="$form->{code}">
  944. <table width=100%>
  945. <tr>
  946. <th class=listtop colspan=2>$form->{title}</th>
  947. </tr>
  948. <tr height="5"></tr>
  949. <tr>
  950. <th align="right">|.$locale->text('Code').qq|</th>
  951. <td><input name=code size=10 value="$form->{code}"></td>
  952. <tr>
  953. <tr>
  954. <th align="right">|.$locale->text('Description').qq|</th>
  955. <td><input name=description size=60 value="$form->{description}"></td>
  956. </tr>
  957. <td colspan=2><hr size=3 noshade></td>
  958. </tr>
  959. </table>
  960. |;
  961. }
  962. sub save_language {
  963. $form->isblank("code", $locale->text('Code missing!'));
  964. $form->isblank("description", $locale->text('Description missing!'));
  965. $form->{code} =~ s/(\.\.|\*)//g;
  966. AM->save_language(\%myconfig, \%$form);
  967. if (! -d "$myconfig{templates}/$form->{code}") {
  968. umask(002);
  969. if (mkdir "$myconfig{templates}/$form->{code}", oct("771")) {
  970. umask(007);
  971. opendir TEMPLATEDIR, "$myconfig{templates}" or $form->error("$myconfig{templates} : $!");
  972. @templates = grep !/^(\.|\.\.)/, readdir TEMPLATEDIR;
  973. closedir TEMPLATEDIR;
  974. foreach $file (@templates) {
  975. if (-f "$myconfig{templates}/$file") {
  976. open(TEMP, "$myconfig{templates}/$file") or $form->error("$myconfig{templates}/$file : $!");
  977. open(NEW, ">$myconfig{templates}/$form->{code}/$file") or $form->error("$myconfig{templates}/$form->{code}/$file : $!");
  978. while ($line = <TEMP>) {
  979. print NEW $line;
  980. }
  981. close(TEMP);
  982. close(NEW);
  983. }
  984. }
  985. } else {
  986. $form->error("${templates}/$form->{code} : $!");
  987. }
  988. }
  989. $form->redirect($locale->text('Language saved!'));
  990. }
  991. sub delete_language {
  992. $form->{title} = $locale->text('Confirm!');
  993. $form->header;
  994. print qq|
  995. <body>
  996. <form method=post action=$form->{script}>
  997. |;
  998. for (qw(action nextsub)) { delete $form->{$_} }
  999. $form->hide_form;
  1000. print qq|
  1001. <h2 class=confirm>$form->{title}</h2>
  1002. <h4>|.$locale->text('Deleting a language will also delete the templates for the language').qq| $form->{invnumber}</h4>
  1003. <input type=hidden name=action value=continue>
  1004. <input type=hidden name=nextsub value=yes_delete_language>
  1005. <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
  1006. </form>
  1007. </body>
  1008. </html>
  1009. |;
  1010. }
  1011. sub yes_delete_language {
  1012. AM->delete_language(\%myconfig, \%$form);
  1013. # delete templates
  1014. $dir = "$myconfig{templates}/$form->{code}";
  1015. if (-d $dir) {
  1016. unlink <$dir/*>;
  1017. rmdir "$myconfig{templates}/$form->{code}";
  1018. }
  1019. $form->redirect($locale->text('Language deleted!'));
  1020. }
  1021. sub display_stylesheet {
  1022. $form->{file} = "css/$myconfig{stylesheet}";
  1023. &display_form;
  1024. }
  1025. sub list_templates {
  1026. AM->language(\%myconfig, \%$form);
  1027. if (! @{ $form->{ALL} }) {
  1028. &display_form;
  1029. exit;
  1030. }
  1031. unshift @{ $form->{ALL} }, { code => '.', description => $locale->text('Default Template') };
  1032. $href = "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1033. $form->sort_order();
  1034. $form->{callback} = "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1035. $callback = $form->escape($form->{callback});
  1036. chomp $myconfig{templates};
  1037. $form->{file} =~ s/$myconfig{templates}//;
  1038. $form->{file} =~ s/\///;
  1039. $form->{title} = $form->{file};
  1040. @column_index = $form->sort_columns(qw(code description));
  1041. $column_header{code} = qq|<th><a class="listheading" href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|;
  1042. $column_header{description} = qq|<th><a class="listheading" href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  1043. $form->header;
  1044. print qq|
  1045. <body>
  1046. <table width=100%>
  1047. <tr>
  1048. <th class=listtop>$form->{title}</th>
  1049. </tr>
  1050. <tr height="5"></tr>
  1051. <tr>
  1052. <td>
  1053. <table width=100%>
  1054. <tr class="listheading">
  1055. |;
  1056. for (@column_index) { print "$column_header{$_}\n" }
  1057. print qq|
  1058. </tr>
  1059. |;
  1060. foreach $ref (@{ $form->{ALL} }) {
  1061. $i++; $i %= 2;
  1062. print qq|
  1063. <tr valign=top class=listrow$i>
  1064. |;
  1065. $column_data{code} = qq|<td><a href=$form->{script}?action=display_form&file=$myconfig{templates}/$ref->{code}/$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&code=$ref->{code}&callback=$callback>$ref->{code}</td>|;
  1066. $column_data{description} = qq|<td>$ref->{description}</td>|;
  1067. for (@column_index) { print "$column_data{$_}\n" }
  1068. print qq|
  1069. </tr>
  1070. |;
  1071. }
  1072. print qq|
  1073. </table>
  1074. </td>
  1075. </tr>
  1076. <tr>
  1077. <td><hr size=3 noshade></td>
  1078. </tr>
  1079. </table>
  1080. <br>
  1081. <form method=post action=$form->{script}>
  1082. <input name=callback type=hidden value="$form->{callback}">
  1083. <input type=hidden name=type value=language>
  1084. <input type=hidden name=path value=$form->{path}>
  1085. <input type=hidden name=login value=$form->{login}>
  1086. <input type=hidden name=sessionid value=$form->{sessionid}>
  1087. |;
  1088. if ($form->{lynx}) {
  1089. require "bin/menu.pl";
  1090. &menubar;
  1091. }
  1092. print qq|
  1093. </form>
  1094. </body>
  1095. </html>
  1096. |;
  1097. }
  1098. sub display_form {
  1099. AM->load_template(\%myconfig, \%$form);
  1100. $form->{title} = $form->{file};
  1101. $form->{body} =~ s/<%include (.*?)%>/<a href=$form->{script}\?action=display_form&file=$myconfig{templates}\/$form->{code}\/$1&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}>$1<\/a>/g;
  1102. # if it is anything but html
  1103. if ($form->{file} !~ /\.html$/) {
  1104. $form->{body} = "<pre>\n$form->{body}\n</pre>";
  1105. }
  1106. $form->header;
  1107. print qq|
  1108. <body>
  1109. $form->{body}
  1110. <form method=post action=$form->{script}>
  1111. |;
  1112. $form->{type} = "template";
  1113. $form->hide_form(qw(file type path login sessionid));
  1114. print qq|
  1115. <input name=action type=submit class=submit value="|.$locale->text('Edit').qq|">|;
  1116. if ($form->{lynx}) {
  1117. require "bin/menu.pl";
  1118. &menubar;
  1119. }
  1120. print qq|
  1121. </form>
  1122. </body>
  1123. </html>
  1124. |;
  1125. }
  1126. sub edit_template {
  1127. AM->load_template(\%myconfig, \%$form);
  1128. $form->{title} = $locale->text('Edit Template');
  1129. # convert &nbsp to &amp;nbsp;
  1130. $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
  1131. $form->header;
  1132. print qq|
  1133. <body>
  1134. <form method=post action=$form->{script}>
  1135. <input name=file type=hidden value=$form->{file}>
  1136. <input name=type type=hidden value=template>
  1137. <input type=hidden name=path value=$form->{path}>
  1138. <input type=hidden name=login value=$form->{login}>
  1139. <input type=hidden name=sessionid value=$form->{sessionid}>
  1140. <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}">
  1141. <textarea name=body rows=25 cols=70>
  1142. $form->{body}
  1143. </textarea>
  1144. <br>
  1145. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1146. if ($form->{lynx}) {
  1147. require "bin/menu.pl";
  1148. &menubar;
  1149. }
  1150. print q|
  1151. </form>
  1152. </body>
  1153. </html>
  1154. |;
  1155. }
  1156. sub save_template {
  1157. AM->save_template(\%myconfig, \%$form);
  1158. $form->redirect($locale->text('Template saved!'));
  1159. }
  1160. sub defaults {
  1161. # get defaults for account numbers and last numbers
  1162. AM->defaultaccounts(\%myconfig, \%$form);
  1163. foreach $key (keys %{ $form->{accno} }) {
  1164. foreach $accno (sort keys %{ $form->{accno}{$key} }) {
  1165. $form->{account}{$key} .= "<option>$accno--$form->{accno}{$key}{$accno}{description}\n";
  1166. $form->{accno}{$form->{accno}{$key}{$accno}{id}} = $accno;
  1167. }
  1168. }
  1169. for (qw(IC IC_inventory IC_income IC_expense FX_gain FX_loss)) { $form->{account}{$_} =~ s/>$form->{accno}{$form->{defaults}{$_}}/ selected>$form->{accno}{$form->{defaults}{$_}}/ }
  1170. for (qw(accno defaults)) { delete $form->{$_} }
  1171. $form->{title} = $locale->text('System Defaults');
  1172. $form->header;
  1173. print qq|
  1174. <body>
  1175. <form method=post action=$form->{script}>
  1176. <input type=hidden name=type value=defaults>
  1177. <table width=100%>
  1178. <tr><th class=listtop>$form->{title}</th></tr>
  1179. <tr>
  1180. <td>
  1181. <table>
  1182. <tr>
  1183. <th align="right">|.$locale->text('Business Number').qq|</th>
  1184. <td><input name=businessnumber size=25 value="$form->{businessnumber}"></td>
  1185. </tr>
  1186. <tr>
  1187. <th align="right">|.$locale->text('Weight Unit').qq|</th>
  1188. <td><input name=weightunit size=5 value="$form->{weightunit}"></td>
  1189. </tr>
  1190. </table>
  1191. </td>
  1192. </tr>
  1193. <tr>
  1194. <th class="listheading">|.$locale->text('Last Numbers & Default Accounts').qq|</th>
  1195. </tr>
  1196. <tr>
  1197. <td>
  1198. <table>
  1199. <tr>
  1200. <th align="right" nowrap>|.$locale->text('Inventory').qq|</th>
  1201. <td><select name=IC>$form->{account}{IC}</select></td>
  1202. </tr>
  1203. <tr>
  1204. <th align="right" nowrap>|.$locale->text('Income').qq|</th>
  1205. <td><select name=IC_income>$form->{account}{IC_income}</select></td>
  1206. </tr>
  1207. <tr>
  1208. <th align="right" nowrap>|.$locale->text('Expense').qq|</th>
  1209. <td><select name=IC_expense>$form->{account}{IC_expense}</select></td>
  1210. </tr>
  1211. <tr>
  1212. <th align="right" nowrap>|.$locale->text('Foreign Exchange Gain').qq|</th>
  1213. <td><select name=FX_gain>$form->{account}{FX_gain}</select></td>
  1214. </tr>
  1215. <tr>
  1216. <th align="right" nowrap>|.$locale->text('Foreign Exchange Loss').qq|</th>
  1217. <td><select name=FX_loss>$form->{account}{FX_loss}</select></td>
  1218. </tr>
  1219. </table>
  1220. </td>
  1221. </tr>
  1222. <tr>
  1223. <th align=left>|.$locale->text('Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies').qq|</th>
  1224. </tr>
  1225. <tr>
  1226. <td>
  1227. <input name=curr size=40 value="$form->{curr}">
  1228. </td>
  1229. </tr>
  1230. <tr>
  1231. <td>
  1232. <table>
  1233. <tr>
  1234. <th align="right" nowrap>|.$locale->text('GL Reference Number').qq|</th>
  1235. <td><input name=glnumber size=40 value="$form->{glnumber}"></td>
  1236. </tr>
  1237. <tr>
  1238. <th align="right" nowrap>|.$locale->text('Sales Invoice/AR Transaction Number').qq|</th>
  1239. <td><input name=sinumber size=40 value="$form->{sinumber}"></td>
  1240. </tr>
  1241. <tr>
  1242. <th align="right" nowrap>|.$locale->text('Sales Order Number').qq|</th>
  1243. <td><input name=sonumber size=40 value="$form->{sonumber}"></td>
  1244. </tr>
  1245. <tr>
  1246. <th align="right" nowrap>|.$locale->text('Vendor Invoice/AP Transaction Number').qq|</th>
  1247. <td><input name=vinumber size=40 value="$form->{vinumber}"></td>
  1248. </tr>
  1249. <tr>
  1250. <th align="right" nowrap>|.$locale->text('Purchase Order Number').qq|</th>
  1251. <td><input name=ponumber size=40 value="$form->{ponumber}"></td>
  1252. </tr>
  1253. <tr>
  1254. <th align="right" nowrap>|.$locale->text('Sales Quotation Number').qq|</th>
  1255. <td><input name=sqnumber size=40 value="$form->{sqnumber}"></td>
  1256. </tr>
  1257. <tr>
  1258. <th align="right" nowrap>|.$locale->text('RFQ Number').qq|</th>
  1259. <td><input name=rfqnumber size=40 value="$form->{rfqnumber}"></td>
  1260. </tr>
  1261. <tr>
  1262. <th align="right" nowrap>|.$locale->text('Part Number').qq|</th>
  1263. <td><input name=partnumber size=40 value="$form->{partnumber}"></td>
  1264. </tr>
  1265. <tr>
  1266. <th align="right" nowrap>|.$locale->text('Job/Project Number').qq|</th>
  1267. <td><input name=projectnumber size=40 value="$form->{projectnumber}"></td>
  1268. </tr>
  1269. <tr>
  1270. <th align="right" nowrap>|.$locale->text('Employee Number').qq|</th>
  1271. <td><input name=employeenumber size=40 value="$form->{employeenumber}"></td>
  1272. </tr>
  1273. <tr>
  1274. <th align="right" nowrap>|.$locale->text('Customer Number').qq|</th>
  1275. <td><input name=customernumber size=40 value="$form->{customernumber}"></td>
  1276. </tr>
  1277. <tr>
  1278. <th align="right" nowrap>|.$locale->text('Vendor Number').qq|</th>
  1279. <td><input name=vendornumber size=40 value="$form->{vendornumber}"></td>
  1280. </tr>
  1281. </table>
  1282. </td>
  1283. </tr>
  1284. <tr>
  1285. <td><hr size=3 noshade></td>
  1286. </tr>
  1287. </table>
  1288. |;
  1289. $form->hide_form(qw(path login sessionid));
  1290. print qq|
  1291. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1292. if ($form->{lynx}) {
  1293. require "bin/menu.pl";
  1294. &menubar;
  1295. }
  1296. print qq|
  1297. </form>
  1298. </body>
  1299. </html>
  1300. |;
  1301. }
  1302. sub taxes {
  1303. # get tax account numbers
  1304. AM->taxes(\%myconfig, \%$form);
  1305. $i = 0;
  1306. foreach $ref (@{ $form->{taxrates} }) {
  1307. $i++;
  1308. $form->{"taxrate_$i"} = $form->format_amount(\%myconfig, $ref->{rate});
  1309. $form->{"taxdescription_$i"} = $ref->{description};
  1310. for (qw(taxnumber validto pass taxmodulename)) {
  1311. $form->{"${_}_$i"} = $ref->{$_};
  1312. }
  1313. $form->{taxaccounts} .= "$ref->{id}_$i ";
  1314. }
  1315. chop $form->{taxaccounts};
  1316. &display_taxes;
  1317. }
  1318. sub display_taxes {
  1319. $form->{title} = $locale->text('Taxes');
  1320. $form->header;
  1321. print qq|
  1322. <body>
  1323. <form method=post action=$form->{script}>
  1324. <input type=hidden name=type value=taxes>
  1325. <table width=100%>
  1326. <tr><th class=listtop>$form->{title}</th></tr>
  1327. <tr>
  1328. <td>
  1329. <table>
  1330. <tr>
  1331. <th></th>
  1332. <th>|.$locale->text('Rate').qq| (%)</th>
  1333. <th>|.$locale->text('Number').qq|</th>
  1334. <th>|.$locale->text('Valid To').qq|</th>
  1335. <th>|.$locale->text('Ordering').qq|</th>
  1336. <th>|.$locale->text('Tax Rules').qq|</th>
  1337. </tr>
  1338. |;
  1339. for (split(/ /, $form->{taxaccounts})) {
  1340. ($null, $i) = split /_/, $_;
  1341. $form->{"taxrate_$i"} = $form->format_amount(\%myconfig, $form->{"taxrate_$i"});
  1342. $form->hide_form("taxdescription_$i");
  1343. print qq|
  1344. <tr>
  1345. <th align="right">|;
  1346. if ($form->{"taxdescription_$i"} eq $sametax) {
  1347. print "";
  1348. } else {
  1349. print qq|$form->{"taxdescription_$i"}|;
  1350. }
  1351. print qq|</th>
  1352. <td><input name="taxrate_$i" size=6 value=$form->{"taxrate_$i"}></td>
  1353. <td><input name="taxnumber_$i" value="$form->{"taxnumber_$i"}"></td>
  1354. <td><input name="validto_$i" size=11 value="$form->{"validto_$i"}" title="$myconfig{dateformat}"></td>
  1355. <td><input name="pass_$i" size=6 value="$form->{"pass_$i"}"></td>
  1356. <td><select name="taxmodule_id_$i" size=1>|;
  1357. foreach my $taxmodule (sort keys %$form) {
  1358. next if ($taxmodule !~ /^taxmodule_/);
  1359. next if ($taxmodule =~ /^taxmodule_id_/);
  1360. my $modulenum = $taxmodule;
  1361. $modulenum =~ s/^taxmodule_//;
  1362. print '<option label="'.$form->{$taxmodule}.'" value="'.$modulenum . '"';
  1363. print " SELECTED " if $form->{$taxmodule} eq $form->{"taxmodulename_$i"};
  1364. print " />\n";
  1365. }
  1366. print qq|</select></td>
  1367. </tr> |;
  1368. $sametax = $form->{"taxdescription_$i"};
  1369. }
  1370. print qq|
  1371. </table>
  1372. </td>
  1373. </tr>
  1374. <tr>
  1375. <td><hr size=3 noshade></td>
  1376. </tr>
  1377. </table>
  1378. |;
  1379. $form->hide_form(qw(taxaccounts path login sessionid));
  1380. foreach my $taxmodule (sort keys %$form) {
  1381. next if ($taxmodule !~ /^taxmodule_/);
  1382. next if ($taxmodule =~ /^taxmodule_id_/);
  1383. $form->hide_form("$taxmodule");
  1384. }
  1385. print qq|
  1386. <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">
  1387. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1388. if ($form->{lynx}) {
  1389. require "bin/menu.pl";
  1390. &menubar;
  1391. }
  1392. print qq|
  1393. </form>
  1394. </body>
  1395. </html>
  1396. |;
  1397. }
  1398. sub update {
  1399. @a = split / /, $form->{taxaccounts};
  1400. $ndx = $#a + 1;
  1401. foreach $item (@a) {
  1402. ($accno, $i) = split /_/, $item;
  1403. push @t, $accno;
  1404. $form->{"taxmodulename_$i"} = $form->{"taxmodule_".$form->{"taxmodule_id_$i"}};
  1405. if ($form->{"validto_$i"}) {
  1406. $j = $i + 1;
  1407. if ($form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"}) {
  1408. #insert line
  1409. for ($j = $ndx + 1; $j > $i; $j--) {
  1410. $k = $j - 1;
  1411. for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"} }
  1412. }
  1413. $ndx++;
  1414. $k = $i + 1;
  1415. for (qw(taxdescription taxnumber)) { $form->{"${_}_$k"} = $form->{"${_}_$i"} }
  1416. for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" }
  1417. push @t, $accno;
  1418. }
  1419. } else {
  1420. # remove line
  1421. $j = $i + 1;
  1422. if ($form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"}) {
  1423. for ($j = $i + 1; $j <= $ndx; $j++) {
  1424. $k = $j + 1;
  1425. for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"} }
  1426. }
  1427. $ndx--;
  1428. splice @t, $i-1, 1;
  1429. }
  1430. }
  1431. }
  1432. $i = 1;
  1433. $form->{taxaccounts} = "";
  1434. for (@t) {
  1435. $form->{taxaccounts} .= "${_}_$i ";
  1436. $i++;
  1437. }
  1438. chop $form->{taxaccounts};
  1439. &display_taxes;
  1440. }
  1441. sub config {
  1442. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
  1443. $dateformat .= ($item eq $myconfig{dateformat}) ? "<option selected>$item\n" : "<option>$item\n";
  1444. }
  1445. my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
  1446. push @formats, '1 000.00';
  1447. foreach $item (@formats) {
  1448. $numberformat .= ($item eq $myconfig{numberformat}) ? "<option selected>$item\n" : "<option>$item\n";
  1449. }
  1450. for (qw(name company address signature)) { $myconfig{$_} = $form->quote($myconfig{$_}) }
  1451. for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g }
  1452. %countrycodes = User->country_codes;
  1453. $countrycodes = '';
  1454. foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
  1455. $countrycodes .= ($myconfig{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}\n" : "<option value=$key>$countrycodes{$key}\n";
  1456. }
  1457. $countrycodes = qq|<option value="">English\n$countrycodes|;
  1458. opendir CSS, "css/.";
  1459. @all = grep /.*\.css$/, readdir CSS;
  1460. closedir CSS;
  1461. foreach $item (@all) {
  1462. if ($item eq $myconfig{stylesheet}) {
  1463. $selectstylesheet .= qq|<option selected>$item\n|;
  1464. } else {
  1465. $selectstylesheet .= qq|<option>$item\n|;
  1466. }
  1467. }
  1468. $selectstylesheet .= "<option>\n";
  1469. if (%printer && $latex) {
  1470. $selectprinter = "<option>\n";
  1471. foreach $item (sort keys %printer) {
  1472. if ($myconfig{printer} eq $item) {
  1473. $selectprinter .= qq|<option value="$item" selected>$item\n|;
  1474. } else {
  1475. $selectprinter .= qq|<option value="$item">$item\n|;
  1476. }
  1477. }
  1478. $printer = qq|
  1479. <tr>
  1480. <th align="right">|.$locale->text('Printer').qq|</th>
  1481. <td><select name=printer>$selectprinter</select></td>
  1482. </tr>
  1483. |;
  1484. }
  1485. $form->{title} = $locale->text('Edit Preferences for').qq| $form->{login}|;
  1486. $form->header;
  1487. print qq|
  1488. <body>
  1489. <form method=post action=$form->{script}>
  1490. <input type=hidden name=old_password value=$myconfig{password}>
  1491. <input type=hidden name=type value=preferences>
  1492. <input type=hidden name=role value=$myconfig{role}>
  1493. <table width=100%>
  1494. <tr><th class=listtop>$form->{title}</th></tr>
  1495. <tr>
  1496. <td>
  1497. <table width=100%>
  1498. <tr valign=top>
  1499. <td>
  1500. <table>
  1501. <tr>
  1502. <th align="right">|.$locale->text('Name').qq|</th>
  1503. <td><input name=name size=20 value="$myconfig{name}"></td>
  1504. </tr>
  1505. <tr>
  1506. <th align="right">|.$locale->text('E-mail').qq|</th>
  1507. <td><input name=email size=35 value="$myconfig{email}"></td>
  1508. </tr>
  1509. <tr valign=top>
  1510. <th align="right">|.$locale->text('Signature').qq|</th>
  1511. <td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td>
  1512. </tr>
  1513. <tr>
  1514. <th align="right">|.$locale->text('Phone').qq|</th>
  1515. <td><input name=tel size=14 value="$myconfig{tel}"></td>
  1516. </tr>
  1517. <tr>
  1518. <th align="right">|.$locale->text('Fax').qq|</th>
  1519. <td><input name=fax size=14 value="$myconfig{fax}"></td>
  1520. </tr>
  1521. <tr>
  1522. <th align="right">|.$locale->text('Company').qq|</th>
  1523. <td><input name=company size=35 value="$myconfig{company}"></td>
  1524. </tr>
  1525. <tr valign=top>
  1526. <th align="right">|.$locale->text('Address').qq|</th>
  1527. <td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td>
  1528. </tr>
  1529. </table>
  1530. </td>
  1531. <td>
  1532. <table>
  1533. <tr>
  1534. <th align="right">|.$locale->text('Password').qq|</th>
  1535. <td><input type=password name=new_password size=10 value=$myconfig{password}></td>
  1536. </tr>
  1537. <tr>
  1538. <th align="right">|.$locale->text('Confirm').qq|</th>
  1539. <td><input type=password name=confirm_password size=10></td>
  1540. </tr>
  1541. <tr>
  1542. <th align="right">|.$locale->text('Date Format').qq|</th>
  1543. <td><select name=dateformat>$dateformat</select></td>
  1544. </tr>
  1545. <tr>
  1546. <th align="right">|.$locale->text('Number Format').qq|</th>
  1547. <td><select name=numberformat>$numberformat</select></td>
  1548. </tr>
  1549. <tr>
  1550. <th align="right">|.$locale->text('Dropdown Limit').qq|</th>
  1551. <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
  1552. </tr>
  1553. <tr>
  1554. <th align="right">|.$locale->text('Menu Width').qq|</th>
  1555. <td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td>
  1556. </tr>
  1557. <tr>
  1558. <th align="right">|.$locale->text('Language').qq|</th>
  1559. <td><select name=countrycode>$countrycodes</select></td>
  1560. </tr>
  1561. <tr>
  1562. <th align="right">|.$locale->text('Session Timeout').qq|</th>
  1563. <td><input name=timeout size=10 value="$myconfig{timeout}"></td>
  1564. </tr>
  1565. <tr>
  1566. <th align="right">|.$locale->text('Stylesheet').qq|</th>
  1567. <td><select name=usestylesheet>$selectstylesheet</select></td>
  1568. </tr>
  1569. $printer
  1570. </table>
  1571. </td>
  1572. </tr>
  1573. </table>
  1574. </td>
  1575. <tr>
  1576. <td><hr size=3 noshade></td>
  1577. </tr>
  1578. </table>
  1579. |;
  1580. $form->hide_form(qw(path login sessionid));
  1581. print qq|
  1582. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1583. if ($form->{lynx}) {
  1584. require "bin/menu.pl";
  1585. &menubar;
  1586. }
  1587. print qq|
  1588. </form>
  1589. </body>
  1590. </html>
  1591. |;
  1592. }
  1593. sub save_defaults {
  1594. if (AM->save_defaults(\%myconfig, \%$form)) {
  1595. $form->redirect($locale->text('Defaults saved!'));
  1596. } else {
  1597. $form->error($locale->text('Cannot save defaults!'));
  1598. }
  1599. }
  1600. sub save_taxes {
  1601. if (AM->save_taxes(\%myconfig, \%$form)) {
  1602. $form->redirect($locale->text('Taxes saved!'));
  1603. } else {
  1604. $form->error($locale->text('Cannot save taxes!'));
  1605. }
  1606. }
  1607. sub save_preferences {
  1608. $form->{stylesheet} = $form->{usestylesheet};
  1609. if ($form->{new_password} ne $form->{old_password}) {
  1610. $form->error($locale->text('Password does not match!')) if $form->{new_password} ne $form->{confirm_password};
  1611. }
  1612. if (AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath)) {
  1613. $form->redirect($locale->text('Preferences saved!'));
  1614. } else {
  1615. $form->error($locale->text('Cannot save preferences!'));
  1616. }
  1617. }
  1618. sub backup {
  1619. if ($form->{media} eq 'email') {
  1620. $form->error($locale->text('No email address for')." $myconfig{name}") unless ($myconfig{email});
  1621. $form->{OUT} = "$sendmail";
  1622. }
  1623. $SIG{INT} = 'IGNORE';
  1624. AM->backup(\%myconfig, \%$form, $userspath, $gzip);
  1625. if ($form->{media} eq 'email') {
  1626. $form->redirect($locale->text('Backup sent to').qq| $myconfig{email}|);
  1627. }
  1628. }
  1629. sub audit_control {
  1630. $form->{title} = $locale->text('Audit Control');
  1631. AM->closedto(\%myconfig, \%$form);
  1632. if ($form->{revtrans}) {
  1633. $checked{revtransY} = "checked";
  1634. } else {
  1635. $checked{revtransN} = "checked";
  1636. }
  1637. if ($form->{audittrail}) {
  1638. $checked{audittrailY} = "checked";
  1639. } else {
  1640. $checked{audittrailN} = "checked";
  1641. }
  1642. $form->header;
  1643. print qq|
  1644. <body>
  1645. <form method=post action=$form->{script}>
  1646. <input type=hidden name=path value=$form->{path}>
  1647. <input type=hidden name=login value=$form->{login}>
  1648. <input type=hidden name=sessionid value=$form->{sessionid}>
  1649. <table width=100%>
  1650. <tr><th class=listtop>$form->{title}</th></tr>
  1651. <tr height="5"></tr>
  1652. <tr>
  1653. <td>
  1654. <table>
  1655. <tr>
  1656. <th align="right">|.$locale->text('Enforce transaction reversal for all dates').qq|</th>
  1657. <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> |.$locale->text('Yes').qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> |.$locale->text('No').qq|</td>
  1658. </tr>
  1659. <tr>
  1660. <th align="right">|.$locale->text('Close Books up to').qq|</th>
  1661. <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
  1662. </tr>
  1663. <tr>
  1664. <th align="right">|.$locale->text('Activate Audit trail').qq|</th>
  1665. <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> |.$locale->text('Yes').qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> |.$locale->text('No').qq|</td>
  1666. </tr>
  1667. <tr>
  1668. <th align="right">|.$locale->text('Remove Audit trail up to').qq|</th>
  1669. <td><input name=removeaudittrail size=11 title="$myconfig{dateformat}"></td>
  1670. </tr>
  1671. </table>
  1672. </td>
  1673. </tr>
  1674. </table>
  1675. <hr size=3 noshade>
  1676. <br>
  1677. <input type=hidden name=nextsub value=doclose>
  1678. <input type=hidden name=action value=continue>
  1679. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  1680. </form>
  1681. </body>
  1682. </html>
  1683. |;
  1684. }
  1685. sub doclose {
  1686. AM->closebooks(\%myconfig, \%$form);
  1687. if ($form->{revtrans}) {
  1688. $msg = $locale->text('Transaction reversal enforced for all dates');
  1689. } else {
  1690. if ($form->{closedto}) {
  1691. $msg = $locale->text('Transaction reversal enforced up to')
  1692. ." ".$locale->date(\%myconfig, $form->{closedto}, 1);
  1693. } else {
  1694. $msg = $locale->text('Books are open');
  1695. }
  1696. }
  1697. $msg .= "<p>";
  1698. if ($form->{audittrail}) {
  1699. $msg .= $locale->text('Audit trail enabled');
  1700. } else {
  1701. $msg .= $locale->text('Audit trail disabled');
  1702. }
  1703. $msg .= "<p>";
  1704. if ($form->{removeaudittrail}) {
  1705. $msg .= $locale->text('Audit trail removed up to')
  1706. ." ".$locale->date(\%myconfig, $form->{removeaudittrail}, 1);
  1707. }
  1708. $form->redirect($msg);
  1709. }
  1710. sub add_warehouse {
  1711. $form->{title} = "Add";
  1712. $form->{callback} = "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  1713. &warehouse_header;
  1714. &form_footer;
  1715. }
  1716. sub edit_warehouse {
  1717. $form->{title} = "Edit";
  1718. AM->get_warehouse(\%myconfig, \%$form);
  1719. &warehouse_header;
  1720. &form_footer;
  1721. }
  1722. sub list_warehouse {
  1723. AM->warehouses(\%myconfig, \%$form);
  1724. $href = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1725. $form->sort_order();
  1726. $form->{callback} = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1727. $callback = $form->escape($form->{callback});
  1728. $form->{title} = $locale->text('Warehouses');
  1729. @column_index = qw(description);
  1730. $column_header{description} = qq|<th width=100%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
  1731. $form->header;
  1732. print qq|
  1733. <body>
  1734. <table width=100%>
  1735. <tr>
  1736. <th class=listtop>$form->{title}</th>
  1737. </tr>
  1738. <tr height="5"></tr>
  1739. <tr>
  1740. <td>
  1741. <table width=100%>
  1742. <tr class="listheading">
  1743. |;
  1744. for (@column_index) { print "$column_header{$_}\n" }
  1745. print qq|
  1746. </tr>
  1747. |;
  1748. foreach $ref (@{ $form->{ALL} }) {
  1749. $i++; $i %= 2;
  1750. print qq|
  1751. <tr valign=top class=listrow$i>
  1752. |;
  1753. $column_data{description} = qq|<td><a href=$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  1754. for (@column_index) { print "$column_data{$_}\n" }
  1755. print qq|
  1756. </tr>
  1757. |;
  1758. }
  1759. print qq|
  1760. </table>
  1761. </td>
  1762. </tr>
  1763. <tr>
  1764. <td><hr size=3 noshade></td>
  1765. </tr>
  1766. </table>
  1767. <br>
  1768. <form method=post action=$form->{script}>
  1769. |;
  1770. $form->{type} = "warehouse";
  1771. $form->hide_form(qw(type callback path login sessionid));
  1772. print qq|
  1773. <input class=submit type=submit name=action value="|.$locale->text('Add Warehouse').qq|">|;
  1774. if ($form->{lynx}) {
  1775. require "bin/menu.pl";
  1776. &menubar;
  1777. }
  1778. print qq|
  1779. </form>
  1780. </body>
  1781. </html>
  1782. |;
  1783. }
  1784. sub warehouse_header {
  1785. $form->{title} = $locale->text("$form->{title} Warehouse");
  1786. # $locale->text('Add Warehouse')
  1787. # $locale->text('Edit Warehouse')
  1788. $form->{description} = $form->quote($form->{description});
  1789. if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
  1790. $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  1791. } else {
  1792. $description = qq|<input name=description size=60 value="$form->{description}">|;
  1793. }
  1794. $form->header;
  1795. print qq|
  1796. <body>
  1797. <form method=post action=$form->{script}>
  1798. <input type=hidden name=id value=$form->{id}>
  1799. <input type=hidden name=type value=warehouse>
  1800. <table width=100%>
  1801. <tr>
  1802. <th class=listtop colspan=2>$form->{title}</th>
  1803. </tr>
  1804. <tr height="5"></tr>
  1805. <tr>
  1806. <th align="right">|.$locale->text('Description').qq|</th>
  1807. <td>$description</td>
  1808. </tr>
  1809. <tr>
  1810. <td colspan=2><hr size=3 noshade></td>
  1811. </tr>
  1812. </table>
  1813. |;
  1814. }
  1815. sub save_warehouse {
  1816. $form->isblank("description", $locale->text('Description missing!'));
  1817. AM->save_warehouse(\%myconfig, \%$form);
  1818. $form->redirect($locale->text('Warehouse saved!'));
  1819. }
  1820. sub delete_warehouse {
  1821. AM->delete_warehouse(\%myconfig, \%$form);
  1822. $form->redirect($locale->text('Warehouse deleted!'));
  1823. }
  1824. sub yearend {
  1825. AM->earningsaccounts(\%myconfig, \%$form);
  1826. $chart = "";
  1827. for (@{ $form->{chart} }) { $chart .= "<option>$_->{accno}--$_->{description}" }
  1828. $form->{title} = $locale->text('Yearend');
  1829. $form->header;
  1830. print qq|
  1831. <body>
  1832. <form method=post action=$form->{script}>
  1833. <input type=hidden name=decimalplaces value=2>
  1834. <input type=hidden name=l_accno value=Y>
  1835. <table width=100%>
  1836. <tr>
  1837. <th class=listtop>$form->{title}</th>
  1838. </tr>
  1839. <tr height="5"></tr>
  1840. <tr>
  1841. <td>
  1842. <table>
  1843. <tr>
  1844. <th align="right">|.$locale->text('Yearend').qq|</th>
  1845. <td><input name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
  1846. </tr>
  1847. <tr>
  1848. <th align="right">|.$locale->text('Reference').qq|</th>
  1849. <td><input name=reference size=20 value="|.$locale->text('Yearend').qq|"></td>
  1850. </tr>
  1851. <tr>
  1852. <th align="right">|.$locale->text('Description').qq|</th>
  1853. <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
  1854. </tr>
  1855. <tr>
  1856. <th align="right">|.$locale->text('Retained Earnings').qq|</th>
  1857. <td><select name=accno>$chart</select></td>
  1858. </tr>
  1859. <tr>
  1860. <th align="right">|.$locale->text('Method').qq|</th>
  1861. <td><input name=method class=radio type=radio value=accrual checked>&nbsp;|.$locale->text('Accrual').qq|&nbsp;<input name=method class=radio type=radio value=cash>&nbsp;|.$locale->text('Cash').qq|</td>
  1862. </tr>
  1863. </table>
  1864. </td>
  1865. </tr>
  1866. </table>
  1867. <hr size=3 noshade>
  1868. <input type=hidden name=nextsub value=generate_yearend>
  1869. |;
  1870. $form->hide_form(qw(path login sessionid));
  1871. print qq|
  1872. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
  1873. }
  1874. sub generate_yearend {
  1875. $form->isblank("todate", $locale->text('Yearend date missing!'));
  1876. RP->yearend_statement(\%myconfig, \%$form);
  1877. $form->{transdate} = $form->{todate};
  1878. $earnings = 0;
  1879. $form->{rowcount} = 1;
  1880. foreach $key (keys %{ $form->{I} }) {
  1881. if ($form->{I}{$key}{charttype} eq "A") {
  1882. $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
  1883. $earnings += $form->{I}{$key}{this};
  1884. $form->{"accno_$form->{rowcount}"} = $key;
  1885. $form->{rowcount}++;
  1886. $ok = 1;
  1887. }
  1888. }
  1889. foreach $key (keys %{ $form->{E} }) {
  1890. if ($form->{E}{$key}{charttype} eq "A") {
  1891. $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
  1892. $earnings += $form->{E}{$key}{this};
  1893. $form->{"accno_$form->{rowcount}"} = $key;
  1894. $form->{rowcount}++;
  1895. $ok = 1;
  1896. }
  1897. }
  1898. if ($earnings > 0) {
  1899. $form->{"credit_$form->{rowcount}"} = $earnings;
  1900. $form->{"accno_$form->{rowcount}"} = $form->{accno}
  1901. } else {
  1902. $form->{"debit_$form->{rowcount}"} = $earnings * -1;
  1903. $form->{"accno_$form->{rowcount}"} = $form->{accno}
  1904. }
  1905. if ($ok) {
  1906. if (AM->post_yearend(\%myconfig, \%$form)) {
  1907. $form->redirect($locale->text('Yearend posted!'));
  1908. } else {
  1909. $form->error($locale->text('Yearend posting failed!'));
  1910. }
  1911. } else {
  1912. $form->error('Nothing to do!');
  1913. }
  1914. }
  1915. sub company_logo {
  1916. $myconfig{address} =~ s/\\n/<br>/g;
  1917. $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
  1918. $form->{stylesheet} = $myconfig{stylesheet};
  1919. $form->{title} = $locale->text('About');
  1920. # create the logo screen
  1921. $form->header;
  1922. print qq|
  1923. <body>
  1924. <pre>
  1925. </pre>
  1926. <center>
  1927. <a href="http://www.ledgersmb.org/" target="_blank"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  1928. <h1 class="login">|.$locale->text('Version').qq| $form->{version}</h1>
  1929. <p>
  1930. |.$locale->text('Licensed to').qq|
  1931. <p>
  1932. <b>
  1933. $myconfig{company}
  1934. <br>$myconfig{address}
  1935. </b>
  1936. <p>
  1937. <table border=0>
  1938. <tr>
  1939. <th align="right">|.$locale->text('User').qq|</th>
  1940. <td>$myconfig{name}</td>
  1941. </tr>
  1942. <tr>
  1943. <th align="right">|.$locale->text('Dataset').qq|</th>
  1944. <td>$myconfig{dbname}</td>
  1945. </tr>
  1946. <tr>
  1947. <th align="right">|.$locale->text('Database Host').qq|</th>
  1948. <td>$myconfig{dbhost}</td>
  1949. </tr>
  1950. </table>
  1951. </center>
  1952. </body>
  1953. </html>
  1954. |;
  1955. }
  1956. sub recurring_transactions {
  1957. # $locale->text('Day')
  1958. # $locale->text('Days')
  1959. # $locale->text('Month')
  1960. # $locale->text('Months')
  1961. # $locale->text('Week')
  1962. # $locale->text('Weeks')
  1963. # $locale->text('Year')
  1964. # $locale->text('Years')
  1965. $form->{stylesheet} = $myconfig{stylesheet};
  1966. $form->{title} = $locale->text('Recurring Transactions');
  1967. $column_header{id} = "";
  1968. AM->recurring_transactions(\%myconfig, \%$form);
  1969. $href = "$form->{script}?action=recurring_transactions";
  1970. for (qw(direction oldsort path login sessionid)) { $href .= qq|&$_=$form->{$_}| }
  1971. $form->sort_order();
  1972. # create the logo screen
  1973. $form->header;
  1974. @column_index = qw(ndx reference description);
  1975. push @column_index, qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
  1976. $column_header{reference} = qq|<th><a class="listheading" href="$href&sort=reference">|.$locale->text('Reference').q|</a></th>|;
  1977. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  1978. $column_header{id} = q|<th class="listheading">|.$locale->text('ID').q|</th>|;
  1979. $column_header{description} = q|<th class="listheading">|.$locale->text('Description').q|</th>|;
  1980. $column_header{nextdate} = qq|<th><a class="listheading" href="$href&sort=nextdate">|.$locale->text('Next').q|</a></th>|;
  1981. $column_header{enddate} = qq|<th><a class="listheading" href="$href&sort=enddate">|.$locale->text('Ends').q|</a></th>|;
  1982. $column_header{amount} = q|<th class="listheading">|.$locale->text('Amount').q|</th>|;
  1983. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  1984. $column_header{repeat} = q|<th class="listheading">|.$locale->text('Every').q|</th>|;
  1985. $column_header{howmany} = q|<th class="listheading">|.$locale->text('Times').q|</th>|;
  1986. $column_header{recurringemail} = q|<th class="listheading">|.$locale->text('E-mail').q|</th>|;
  1987. $column_header{recurringprint} = q|<th class="listheading">|.$locale->text('Print').q|</th>|;
  1988. print qq|
  1989. <body>
  1990. <form method=post action=$form->{script}>
  1991. <table width=100%>
  1992. <tr>
  1993. <th class=listtop>$form->{title}</th>
  1994. </tr>
  1995. <tr height="5"></tr>
  1996. <tr>
  1997. <td>
  1998. <table width=100%>
  1999. <tr class="listheading">
  2000. |;
  2001. for (@column_index) { print "\n$column_header{$_}" }
  2002. print qq|
  2003. </tr>
  2004. |;
  2005. $i = 1;
  2006. $colspan = $#column_index + 1;
  2007. %tr = ( ar => $locale->text('AR'),
  2008. ap => $locale->text('AP'),
  2009. gl => $locale->text('GL'),
  2010. so => $locale->text('Sales Orders'),
  2011. po => $locale->text('Purchase Orders'),
  2012. );
  2013. %f = &formnames;
  2014. foreach $transaction (sort keys %{ $form->{transactions} }) {
  2015. print qq|
  2016. <tr>
  2017. <th class="listheading" colspan=$colspan>$tr{$transaction}</th>
  2018. </tr>
  2019. |;
  2020. foreach $ref (@{ $form->{transactions}{$transaction} }) {
  2021. for (@column_index) { $column_data{$_} = "<td nowrap>$ref->{$_}</td>" }
  2022. if ($ref->{repeat} > 1) {
  2023. $unit = $locale->text(ucfirst $ref->{unit});
  2024. $repeat = "$ref->{repeat} $unit";
  2025. } else {
  2026. chop $ref->{unit};
  2027. $unit = $locale->text(ucfirst $ref->{unit});
  2028. $repeat = $unit;
  2029. }
  2030. $column_data{ndx} = qq|<td></td>|;
  2031. if (!$ref->{expired}) {
  2032. if ($ref->{overdue} <= 0) {
  2033. $k++;
  2034. $column_data{ndx} = qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2035. }
  2036. }
  2037. $reference = ($ref->{reference}) ? $ref->{reference} : $locale->text('Next Number');
  2038. $column_data{reference} = qq|<td nowrap><a href=$form->{script}?action=edit_recurring&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&module=$ref->{module}&invoice=$ref->{invoice}&transaction=$ref->{transaction}&recurringnextdate=$ref->{nextdate}>$reference</a></td>|;
  2039. $module = "$ref->{module}.pl";
  2040. $type = "";
  2041. if ($ref->{module} eq 'ar') {
  2042. $module = "is.pl" if $ref->{invoice};
  2043. $ref->{amount} /= $ref->{exchangerate};
  2044. }
  2045. if ($ref->{module} eq 'ap') {
  2046. $module = "ir.pl" if $ref->{invoice};
  2047. $ref->{amount} /= $ref->{exchangerate};
  2048. }
  2049. if ($ref->{module} eq 'oe') {
  2050. $type = ($ref->{vc} eq 'customer') ? "sales_order" : "purchase_order";
  2051. }
  2052. $column_data{id} = qq|<td><a href="$module?action=edit&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$type&readonly=1">$ref->{id}</a></td>|;
  2053. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2054. $column_data{howmany} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{howmany})."</td>";
  2055. $column_data{amount} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{amount}, 2)."</td>";
  2056. $column_data{recurringemail} = "<td nowrap>";
  2057. @f = split /:/, $ref->{recurringemail};
  2058. for (0 .. $#f) { $column_data{recurringemail} .= "$f{$f[$_]}<br>" }
  2059. $column_data{recurringemail} .= "</td>";
  2060. $column_data{recurringprint} = "<td nowrap>";
  2061. @f = split /:/, $ref->{recurringprint};
  2062. for (0 .. $#f) { $column_data{recurringprint} .= "$f{$f[$_]}<br>" }
  2063. $column_data{recurringprint} .= "</td>";
  2064. $j++; $j %= 2;
  2065. print qq|
  2066. <tr class=listrow$j>
  2067. |;
  2068. for (@column_index) { print "\n$column_data{$_}" }
  2069. print qq|
  2070. </tr>
  2071. |;
  2072. }
  2073. }
  2074. print qq|
  2075. </tr>
  2076. </table>
  2077. </td>
  2078. </tr>
  2079. <tr>
  2080. <td><hr size=3 noshade></td>
  2081. </tr>
  2082. </table>
  2083. <input name=lastndx type=hidden value=$k>
  2084. |;
  2085. $form->hide_form(qw(path login sessionid));
  2086. print qq|
  2087. <input class=submit type=submit name=action value="|.$locale->text('Process Transactions').qq|">| if $k;
  2088. if ($form->{lynx}) {
  2089. require "bin/menu.pl";
  2090. &menubar;
  2091. }
  2092. print qq|
  2093. </form>
  2094. </body>
  2095. </html>
  2096. |;
  2097. }
  2098. sub edit_recurring {
  2099. %links = ( ar => 'create_links',
  2100. ap => 'create_links',
  2101. gl => 'create_links',
  2102. is => 'invoice_links',
  2103. ir => 'invoice_links',
  2104. oe => 'order_links',
  2105. );
  2106. %prepare = ( is => 'prepare_invoice',
  2107. ir => 'prepare_invoice',
  2108. oe => 'prepare_order',
  2109. );
  2110. $form->{callback} = "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2111. $form->{type} = "transaction";
  2112. if ($form->{module} eq 'ar') {
  2113. if ($form->{invoice}) {
  2114. $form->{type} = "invoice";
  2115. $form->{module} = "is";
  2116. }
  2117. }
  2118. if ($form->{module} eq 'ap') {
  2119. if ($form->{invoice}) {
  2120. $form->{type} = "invoice";
  2121. $form->{module} = "ir";
  2122. }
  2123. }
  2124. if ($form->{module} eq 'oe') {
  2125. %tr = ( so => sales_order,
  2126. po => purchase_order,
  2127. );
  2128. $form->{type} = $tr{$form->{transaction}};
  2129. }
  2130. $form->{script} = "$form->{module}.pl";
  2131. do "bin/$form->{script}";
  2132. &{ $links{$form->{module}} };
  2133. # return if transaction doesn't exist
  2134. $form->redirect unless $form->{recurring};
  2135. if ($prepare{$form->{module}}) {
  2136. &{ $prepare{$form->{module}} };
  2137. }
  2138. $form->{selectformat} = qq|<option value="html">html\n|;
  2139. if ($latex) {
  2140. $form->{selectformat} .= qq|
  2141. <option value="postscript">|.$locale->text('Postscript').qq|
  2142. <option value="pdf">|.$locale->text('PDF');
  2143. }
  2144. &schedule;
  2145. }
  2146. sub process_transactions {
  2147. # save variables
  2148. my $pt = new Form;
  2149. for (keys %$form) { $pt->{$_} = $form->{$_} }
  2150. my $defaultprinter;
  2151. while (my ($key, $value) = each %printer) {
  2152. if ($value =~ /lpr/) {
  2153. $defaultprinter = $key;
  2154. last;
  2155. }
  2156. }
  2157. $myconfig{vclimit} = 0;
  2158. %f = &formnames;
  2159. for (my $i = 1; $i <= $pt->{lastndx}; $i++) {
  2160. if ($pt->{"ndx_$i"}) {
  2161. $id = $pt->{"ndx_$i"};
  2162. # process transaction
  2163. AM->recurring_details(\%myconfig, \%$pt, $id);
  2164. $header = $form->{header};
  2165. # reset $form
  2166. for (keys %$form) { delete $form->{$_}; }
  2167. for (qw(login path sessionid stylesheet timeout)) { $form->{$_} = $pt->{$_}; }
  2168. $form->{id} = $id;
  2169. $form->{header} = $header;
  2170. # post, print, email
  2171. if ($pt->{arid} || $pt->{apid} || $pt->{oeid}) {
  2172. if ($pt->{arid} || $pt->{apid}) {
  2173. if ($pt->{arid}) {
  2174. $form->{script} = ($pt->{invoice}) ? "is.pl" : "ar.pl";
  2175. $form->{ARAP} = "AR";
  2176. $form->{module} = "ar";
  2177. $invfld = "sinumber";
  2178. } else {
  2179. $form->{script} = ($pt->{invoice}) ? "ir.pl" : "ap.pl";
  2180. $form->{ARAP} = "AP";
  2181. $form->{module} = "ap";
  2182. $invfld = "vinumber";
  2183. }
  2184. do "bin/$form->{script}";
  2185. if ($pt->{invoice}) {
  2186. &invoice_links;
  2187. &prepare_invoice;
  2188. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  2189. } else {
  2190. &create_links;
  2191. $form->{type} = "transaction";
  2192. for (1 .. $form->{rowcount} - 1) { $form->{"amount_$_"} = $form->format_amount(\%myconfig, $form->{"amount_$_"}, 2) }
  2193. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, 2) }
  2194. }
  2195. delete $form->{"$form->{ARAP}_links"};
  2196. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  2197. for (qw(department employee language month partsgroup project years)) { delete $form->{"all_$_"} }
  2198. $form->{invnumber} = $pt->{reference};
  2199. $form->{transdate} = $pt->{nextdate};
  2200. # tax accounts
  2201. $form->all_taxaccounts(\%myconfig, undef, $form->{transdate});
  2202. # calculate duedate
  2203. $form->{duedate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{overdue}, "days");
  2204. if ($pt->{payment}) {
  2205. # calculate date paid
  2206. for ($j = 1; $j <= $form->{paidaccounts}; $j++) {
  2207. $form->{"datepaid_$j"} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{paid}, "days");
  2208. ($form->{"$form->{ARAP}_paid_$j"}) = split /--/, $form->{"$form->{ARAP}_paid_$j"};
  2209. delete $form->{"cleared_$j"};
  2210. }
  2211. $form->{paidaccounts}++;
  2212. } else {
  2213. $form->{paidaccounts} = -1;
  2214. }
  2215. for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
  2216. ($form->{$form->{ARAP}}) = split /--/, $form->{$form->{ARAP}};
  2217. $form->{invnumber} = $form->update_defaults(\%myconfig, "$invfld") unless $form->{invnumber};
  2218. $form->{reference} = $form->{invnumber};
  2219. for (qw(invnumber reference)) { $form->{$_} = $form->unquote($form->{$_}) }
  2220. if ($pt->{invoice}) {
  2221. if ($pt->{arid}) {
  2222. $form->info("\n".$locale->text('Posting')." ".$locale->text('Sales Invoice')." $form->{invnumber}");
  2223. $ok = IS->post_invoice(\%myconfig, \%$form);
  2224. } else {
  2225. $form->info("\n".$locale->text('Posting')." ".$locale->text('Vendor Invoice')." $form->{invnumber}");
  2226. $ok = IR->post_invoice(\%myconfig, \%$form);
  2227. }
  2228. } else {
  2229. if ($pt->{arid}) {
  2230. $form->info("\n".$locale->text('Posting')." ".$locale->text('Transaction')." $form->{invnumber}");
  2231. } else {
  2232. $form->info("\n".$locale->text('Posting')." ".$locale->text('Transaction')." $form->{invnumber}");
  2233. }
  2234. $ok = AA->post_transaction(\%myconfig, \%$form);
  2235. }
  2236. $form->info(" ..... ".$locale->text('done'));
  2237. # print form
  2238. if ($latex && $ok) {
  2239. $ok = &print_recurring(\%$pt, $defaultprinter);
  2240. }
  2241. &email_recurring(\%$pt) if $ok;
  2242. } else {
  2243. # order
  2244. $form->{script} = "oe.pl";
  2245. $form->{module} = "oe";
  2246. $ordnumber = "ordnumber";
  2247. if ($pt->{customer_id}) {
  2248. $form->{vc} = "customer";
  2249. $form->{type} = "sales_order";
  2250. $ordfld = "sonumber";
  2251. $flabel = $locale->text('Sales Order');
  2252. } else {
  2253. $form->{vc} = "vendor";
  2254. $form->{type} = "purchase_order";
  2255. $ordfld = "ponumber";
  2256. $flabel = $locale->text('Purchase Order');
  2257. }
  2258. require "bin/$form->{script}";
  2259. &order_links;
  2260. &prepare_order;
  2261. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  2262. $form->{$ordnumber} = $pt->{reference};
  2263. $form->{transdate} = $pt->{nextdate};
  2264. # calculate reqdate
  2265. $form->{reqdate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{req}, "days") if $form->{reqdate};
  2266. for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
  2267. for (1 .. $form->{rowcount}) { delete $form->{"orderitems_id_$_"} }
  2268. $form->{$ordnumber} = $form->update_defaults(\%myconfig, "$ordfld") unless $form->{$ordnumber};
  2269. $form->{reference} = $form->{$ordnumber};
  2270. for ("$ordnumber", "reference") { $form->{$_} = $form->unquote($form->{$_}) }
  2271. $form->{closed} = 0;
  2272. $form->info("\n".$locale->text('Saving')." ".$flabel." $form->{$ordnumber}");
  2273. if ($ok = OE->save(\%myconfig, \%$form)) {
  2274. $form->info(" ..... ".$locale->text('done'));
  2275. } else {
  2276. $form->info(" ..... ".$locale->text('failed'));
  2277. }
  2278. # print form
  2279. if ($latex && $ok) {
  2280. &print_recurring(\%$pt, $defaultprinter);
  2281. }
  2282. &email_recurring(\%$pt);
  2283. }
  2284. } else {
  2285. # GL transaction
  2286. GL->transaction(\%myconfig, \%$form);
  2287. $form->{reference} = $pt->{reference};
  2288. $form->{transdate} = $pt->{nextdate};
  2289. $j = 1;
  2290. foreach $ref (@{ $form->{GL} }) {
  2291. $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
  2292. $form->{"projectnumber_$j"} = "$ref->{projectnumber}--$ref->{project_id}" if $ref->{project_id};
  2293. $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
  2294. if ($ref->{amount} < 0) {
  2295. $form->{"debit_$j"} = $ref->{amount} * -1;
  2296. } else {
  2297. $form->{"credit_$j"} = $ref->{amount};
  2298. }
  2299. $j++;
  2300. }
  2301. $form->{rowcount} = $j;
  2302. for (qw(id recurring)) { delete $form->{$_} }
  2303. $form->info("\n".$locale->text('Posting')." ".$locale->text('GL Transaction')." $form->{reference}");
  2304. $ok = GL->post_transaction(\%myconfig, \%$form);
  2305. $form->info(" ..... ".$locale->text('done'));
  2306. }
  2307. AM->update_recurring(\%myconfig, \%$pt, $id) if $ok;
  2308. }
  2309. }
  2310. $form->{callback} = "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
  2311. $form->redirect;
  2312. }
  2313. sub print_recurring {
  2314. my ($pt, $defaultprinter) = @_;
  2315. my %f = &formnames;
  2316. my $ok = 1;
  2317. if ($pt->{recurringprint}) {
  2318. @f = split /:/, $pt->{recurringprint};
  2319. for ($j = 0; $j <= $#f; $j += 3) {
  2320. $media = $f[$j+2];
  2321. $media ||= $myconfig->{printer} if $printer{$myconfig->{printer}};
  2322. $media ||= $defaultprinter;
  2323. $form->info("\n".$locale->text('Printing')." ".$locale->text($f{$f[$j]})." $form->{reference}");
  2324. @a = ("perl", "$form->{script}", "action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=$media&vc=$form->{vc}&ARAP=$form->{ARAP}");
  2325. $ok = !(system(@a));
  2326. if ($ok) {
  2327. $form->info(" ..... ".$locale->text('done'));
  2328. } else {
  2329. $form->info(" ..... ".$locale->text('failed'));
  2330. last;
  2331. }
  2332. }
  2333. }
  2334. $ok;
  2335. }
  2336. sub email_recurring {
  2337. my ($pt) = @_;
  2338. my %f = &formnames;
  2339. my $ok = 1;
  2340. if ($pt->{recurringemail}) {
  2341. @f = split /:/, $pt->{recurringemail};
  2342. for ($j = 0; $j <= $#f; $j += 2) {
  2343. $form->info("\n".$locale->text('Sending')." ".$locale->text($f{$f[$j]})." $form->{reference}");
  2344. # no email, bail out
  2345. if (!$form->{email}) {
  2346. $form->info(" ..... ".$locale->text('E-mail address missing!'));
  2347. last;
  2348. }
  2349. $message = $form->escape($pt->{message},1);
  2350. @a = ("perl", "$form->{script}", "action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=email&vc=$form->{vc}&ARAP=$form->{ARAP}&message=$message");
  2351. $ok = !(system(@a));
  2352. if ($ok) {
  2353. $form->info(" ..... ".$locale->text('done'));
  2354. } else {
  2355. $form->info(" ..... ".$locale->text('failed'));
  2356. last;
  2357. }
  2358. }
  2359. }
  2360. $ok;
  2361. }
  2362. sub formnames {
  2363. # $locale->text('Transaction')
  2364. # $locale->text('Invoice')
  2365. # $locale->text('Credit Invoice')
  2366. # $locale->text('Debit Invoice')
  2367. # $locale->text('Packing List')
  2368. # $locale->text('Pick List')
  2369. # $locale->text('Sales Order')
  2370. # $locale->text('Work Order')
  2371. # $locale->text('Purchase Order')
  2372. # $locale->text('Bin List')
  2373. my %f = ( transaction => 'Transaction',
  2374. invoice => 'Invoice',
  2375. credit_invoice => 'Credit Invoice',
  2376. debit_invoice => 'Debit Invoice',
  2377. packing_list => 'Packing List',
  2378. pick_list => 'Pick List',
  2379. sales_order => 'Sales Order',
  2380. work_order => 'Work Order',
  2381. purchase_order => 'Purchase Order',
  2382. bin_list => 'Bin List',
  2383. );
  2384. %f;
  2385. }
  2386. sub continue { &{ $form->{nextsub} } };