summaryrefslogtreecommitdiff
path: root/bin/mozilla/am.pl
blob: 666b552281c5ca63588c88fb4d0cfc9870745bc2 (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->{menubar}) {
  215. require "$form->{path}/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->{menubar}) {
  441. require "$form->{path}/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->{menubar}) {
  541. require "$form->{path}/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->{menubar}) {
  666. require "$form->{path}/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->{menubar}) {
  800. require "$form->{path}/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->{menubar}) {
  924. require "$form->{path}/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->{menubar}) {
  1089. require "$form->{path}/menu.pl";
  1090. &menubar;
  1091. }
  1092. print qq|
  1093. </form>
  1094. </body>
  1095. </html>
  1096. |;
  1097. }
  1098. sub display_form {
  1099. $form->{file} =~ s/^(.:)*?\/|\.\.\///g;
  1100. $form->{file} =~ s/^\/*//g;
  1101. $form->{file} =~ s/$userspath//;
  1102. $form->{file} =~ s/$memberfile//;
  1103. $form->error("$!: $form->{file}") unless -f $form->{file};
  1104. AM->load_template(\%myconfig, \%$form);
  1105. $form->{title} = $form->{file};
  1106. $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;
  1107. # if it is anything but html
  1108. if ($form->{file} !~ /\.html$/) {
  1109. $form->{body} = "<pre>\n$form->{body}\n</pre>";
  1110. }
  1111. $form->header;
  1112. print qq|
  1113. <body>
  1114. $form->{body}
  1115. <form method=post action=$form->{script}>
  1116. |;
  1117. $form->{type} = "template";
  1118. $form->hide_form(qw(file type path login sessionid));
  1119. print qq|
  1120. <input name=action type=submit class=submit value="|.$locale->text('Edit').qq|">|;
  1121. if ($form->{menubar}) {
  1122. require "$form->{path}/menu.pl";
  1123. &menubar;
  1124. }
  1125. print qq|
  1126. </form>
  1127. </body>
  1128. </html>
  1129. |;
  1130. }
  1131. sub edit_template {
  1132. AM->load_template(\%myconfig, \%$form);
  1133. $form->{title} = $locale->text('Edit Template');
  1134. # convert &nbsp to &amp;nbsp;
  1135. $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
  1136. $form->header;
  1137. print qq|
  1138. <body>
  1139. <form method=post action=$form->{script}>
  1140. <input name=file type=hidden value=$form->{file}>
  1141. <input name=type type=hidden value=template>
  1142. <input type=hidden name=path value=$form->{path}>
  1143. <input type=hidden name=login value=$form->{login}>
  1144. <input type=hidden name=sessionid value=$form->{sessionid}>
  1145. <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}">
  1146. <textarea name=body rows=25 cols=70>
  1147. $form->{body}
  1148. </textarea>
  1149. <br>
  1150. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1151. if ($form->{menubar}) {
  1152. require "$form->{path}/menu.pl";
  1153. &menubar;
  1154. }
  1155. print q|
  1156. </form>
  1157. </body>
  1158. </html>
  1159. |;
  1160. }
  1161. sub save_template {
  1162. AM->save_template(\%myconfig, \%$form);
  1163. $form->redirect($locale->text('Template saved!'));
  1164. }
  1165. sub defaults {
  1166. # get defaults for account numbers and last numbers
  1167. AM->defaultaccounts(\%myconfig, \%$form);
  1168. foreach $key (keys %{ $form->{accno} }) {
  1169. foreach $accno (sort keys %{ $form->{accno}{$key} }) {
  1170. $form->{account}{$key} .= "<option>$accno--$form->{accno}{$key}{$accno}{description}\n";
  1171. $form->{accno}{$form->{accno}{$key}{$accno}{id}} = $accno;
  1172. }
  1173. }
  1174. 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}{$_}}/ }
  1175. for (qw(accno defaults)) { delete $form->{$_} }
  1176. $form->{title} = $locale->text('System Defaults');
  1177. $form->header;
  1178. print qq|
  1179. <body>
  1180. <form method=post action=$form->{script}>
  1181. <input type=hidden name=type value=defaults>
  1182. <table width=100%>
  1183. <tr><th class=listtop>$form->{title}</th></tr>
  1184. <tr>
  1185. <td>
  1186. <table>
  1187. <tr>
  1188. <th align="right">|.$locale->text('Business Number').qq|</th>
  1189. <td><input name=businessnumber size=25 value="$form->{businessnumber}"></td>
  1190. </tr>
  1191. <tr>
  1192. <th align="right">|.$locale->text('Weight Unit').qq|</th>
  1193. <td><input name=weightunit size=5 value="$form->{weightunit}"></td>
  1194. </tr>
  1195. </table>
  1196. </td>
  1197. </tr>
  1198. <tr>
  1199. <th class="listheading">|.$locale->text('Last Numbers & Default Accounts').qq|</th>
  1200. </tr>
  1201. <tr>
  1202. <td>
  1203. <table>
  1204. <tr>
  1205. <th align="right" nowrap>|.$locale->text('Inventory').qq|</th>
  1206. <td><select name=IC>$form->{account}{IC}</select></td>
  1207. </tr>
  1208. <tr>
  1209. <th align="right" nowrap>|.$locale->text('Income').qq|</th>
  1210. <td><select name=IC_income>$form->{account}{IC_income}</select></td>
  1211. </tr>
  1212. <tr>
  1213. <th align="right" nowrap>|.$locale->text('Expense').qq|</th>
  1214. <td><select name=IC_expense>$form->{account}{IC_expense}</select></td>
  1215. </tr>
  1216. <tr>
  1217. <th align="right" nowrap>|.$locale->text('Foreign Exchange Gain').qq|</th>
  1218. <td><select name=FX_gain>$form->{account}{FX_gain}</select></td>
  1219. </tr>
  1220. <tr>
  1221. <th align="right" nowrap>|.$locale->text('Foreign Exchange Loss').qq|</th>
  1222. <td><select name=FX_loss>$form->{account}{FX_loss}</select></td>
  1223. </tr>
  1224. </table>
  1225. </td>
  1226. </tr>
  1227. <tr>
  1228. <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>
  1229. </tr>
  1230. <tr>
  1231. <td>
  1232. <input name=curr size=40 value="$form->{curr}">
  1233. </td>
  1234. </tr>
  1235. <tr>
  1236. <td>
  1237. <table>
  1238. <tr>
  1239. <th align="right" nowrap>|.$locale->text('GL Reference Number').qq|</th>
  1240. <td><input name=glnumber size=40 value="$form->{glnumber}"></td>
  1241. </tr>
  1242. <tr>
  1243. <th align="right" nowrap>|.$locale->text('Sales Invoice/AR Transaction Number').qq|</th>
  1244. <td><input name=sinumber size=40 value="$form->{sinumber}"></td>
  1245. </tr>
  1246. <tr>
  1247. <th align="right" nowrap>|.$locale->text('Sales Order Number').qq|</th>
  1248. <td><input name=sonumber size=40 value="$form->{sonumber}"></td>
  1249. </tr>
  1250. <tr>
  1251. <th align="right" nowrap>|.$locale->text('Vendor Invoice/AP Transaction Number').qq|</th>
  1252. <td><input name=vinumber size=40 value="$form->{vinumber}"></td>
  1253. </tr>
  1254. <tr>
  1255. <th align="right" nowrap>|.$locale->text('Purchase Order Number').qq|</th>
  1256. <td><input name=ponumber size=40 value="$form->{ponumber}"></td>
  1257. </tr>
  1258. <tr>
  1259. <th align="right" nowrap>|.$locale->text('Sales Quotation Number').qq|</th>
  1260. <td><input name=sqnumber size=40 value="$form->{sqnumber}"></td>
  1261. </tr>
  1262. <tr>
  1263. <th align="right" nowrap>|.$locale->text('RFQ Number').qq|</th>
  1264. <td><input name=rfqnumber size=40 value="$form->{rfqnumber}"></td>
  1265. </tr>
  1266. <tr>
  1267. <th align="right" nowrap>|.$locale->text('Part Number').qq|</th>
  1268. <td><input name=partnumber size=40 value="$form->{partnumber}"></td>
  1269. </tr>
  1270. <tr>
  1271. <th align="right" nowrap>|.$locale->text('Job/Project Number').qq|</th>
  1272. <td><input name=projectnumber size=40 value="$form->{projectnumber}"></td>
  1273. </tr>
  1274. <tr>
  1275. <th align="right" nowrap>|.$locale->text('Employee Number').qq|</th>
  1276. <td><input name=employeenumber size=40 value="$form->{employeenumber}"></td>
  1277. </tr>
  1278. <tr>
  1279. <th align="right" nowrap>|.$locale->text('Customer Number').qq|</th>
  1280. <td><input name=customernumber size=40 value="$form->{customernumber}"></td>
  1281. </tr>
  1282. <tr>
  1283. <th align="right" nowrap>|.$locale->text('Vendor Number').qq|</th>
  1284. <td><input name=vendornumber size=40 value="$form->{vendornumber}"></td>
  1285. </tr>
  1286. </table>
  1287. </td>
  1288. </tr>
  1289. <tr>
  1290. <td><hr size=3 noshade></td>
  1291. </tr>
  1292. </table>
  1293. |;
  1294. $form->hide_form(qw(path login sessionid));
  1295. print qq|
  1296. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1297. if ($form->{menubar}) {
  1298. require "$form->{path}/menu.pl";
  1299. &menubar;
  1300. }
  1301. print qq|
  1302. </form>
  1303. </body>
  1304. </html>
  1305. |;
  1306. }
  1307. sub taxes {
  1308. # get tax account numbers
  1309. AM->taxes(\%myconfig, \%$form);
  1310. $i = 0;
  1311. foreach $ref (@{ $form->{taxrates} }) {
  1312. $i++;
  1313. $form->{"taxrate_$i"} = $form->format_amount(\%myconfig, $ref->{rate});
  1314. $form->{"taxdescription_$i"} = $ref->{description};
  1315. for (qw(taxnumber validto pass taxmodulename)) {
  1316. $form->{"${_}_$i"} = $ref->{$_};
  1317. }
  1318. $form->{taxaccounts} .= "$ref->{id}_$i ";
  1319. }
  1320. chop $form->{taxaccounts};
  1321. &display_taxes;
  1322. }
  1323. sub display_taxes {
  1324. $form->{title} = $locale->text('Taxes');
  1325. $form->header;
  1326. print qq|
  1327. <body>
  1328. <form method=post action=$form->{script}>
  1329. <input type=hidden name=type value=taxes>
  1330. <table width=100%>
  1331. <tr><th class=listtop>$form->{title}</th></tr>
  1332. <tr>
  1333. <td>
  1334. <table>
  1335. <tr>
  1336. <th></th>
  1337. <th>|.$locale->text('Rate').qq| (%)</th>
  1338. <th>|.$locale->text('Number').qq|</th>
  1339. <th>|.$locale->text('Valid To').qq|</th>
  1340. <th>|.$locale->text('Order').qq|</th>
  1341. <th>|.$locale->text('Tax Rules').qq|</th>
  1342. </tr>
  1343. |;
  1344. for (split(/ /, $form->{taxaccounts})) {
  1345. ($null, $i) = split /_/, $_;
  1346. $form->{"taxrate_$i"} = $form->format_amount(\%myconfig, $form->{"taxrate_$i"});
  1347. $form->hide_form("taxdescription_$i");
  1348. print qq|
  1349. <tr>
  1350. <th align="right">|;
  1351. if ($form->{"taxdescription_$i"} eq $sametax) {
  1352. print "";
  1353. } else {
  1354. print qq|$form->{"taxdescription_$i"}|;
  1355. }
  1356. print qq|</th>
  1357. <td><input name="taxrate_$i" size=6 value=$form->{"taxrate_$i"}></td>
  1358. <td><input name="taxnumber_$i" value="$form->{"taxnumber_$i"}"></td>
  1359. <td><input name="validto_$i" size=11 value="$form->{"validto_$i"}" title="$myconfig{dateformat}"></td>
  1360. <td><input name="pass_$i" size=6 value="$form->{"pass_$i"}"></td>
  1361. <td><select name="taxmodule_id_$i" size=1>|;
  1362. foreach my $taxmodule (sort keys %$form) {
  1363. next if ($taxmodule !~ /^taxmodule_/);
  1364. my $modulenum = $taxmodule;
  1365. $modulenum =~ s/^taxmodule_//;
  1366. print '<option label="'.$form->{$taxmodule}.'" value="'.$modulenum . '"';
  1367. print " SELECTED " if $form->{$taxmodule} eq $form->{"taxmodulename_$i"};
  1368. print " />\n";
  1369. }
  1370. print qq|</select></td>
  1371. </tr> |;
  1372. $sametax = $form->{"taxdescription_$i"};
  1373. }
  1374. print qq|
  1375. </table>
  1376. </td>
  1377. </tr>
  1378. <tr>
  1379. <td><hr size=3 noshade></td>
  1380. </tr>
  1381. </table>
  1382. |;
  1383. $form->hide_form(qw(taxaccounts path login sessionid));
  1384. print qq|
  1385. <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">
  1386. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1387. if ($form->{menubar}) {
  1388. require "$form->{path}/menu.pl";
  1389. &menubar;
  1390. }
  1391. print qq|
  1392. </form>
  1393. </body>
  1394. </html>
  1395. |;
  1396. }
  1397. sub update {
  1398. @a = split / /, $form->{taxaccounts};
  1399. $ndx = $#a + 1;
  1400. foreach $item (@a) {
  1401. ($accno, $i) = split /_/, $item;
  1402. push @t, $accno;
  1403. if ($form->{"validto_$i"}) {
  1404. $j = $i + 1;
  1405. if ($form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"}) {
  1406. #insert line
  1407. for ($j = $ndx + 1; $j > $i; $j--) {
  1408. $k = $j - 1;
  1409. for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"} }
  1410. }
  1411. $ndx++;
  1412. $k = $i + 1;
  1413. for (qw(taxdescription taxnumber)) { $form->{"${_}_$k"} = $form->{"${_}_$i"} }
  1414. for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" }
  1415. push @t, $accno;
  1416. }
  1417. } else {
  1418. # remove line
  1419. $j = $i + 1;
  1420. if ($form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"}) {
  1421. for ($j = $i + 1; $j <= $ndx; $j++) {
  1422. $k = $j + 1;
  1423. for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"} }
  1424. }
  1425. $ndx--;
  1426. splice @t, $i-1, 1;
  1427. }
  1428. }
  1429. }
  1430. $i = 1;
  1431. $form->{taxaccounts} = "";
  1432. for (@t) {
  1433. $form->{taxaccounts} .= "${_}_$i ";
  1434. $i++;
  1435. }
  1436. chop $form->{taxaccounts};
  1437. &display_taxes;
  1438. }
  1439. sub config {
  1440. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
  1441. $dateformat .= ($item eq $myconfig{dateformat}) ? "<option selected>$item\n" : "<option>$item\n";
  1442. }
  1443. foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00)) {
  1444. $numberformat .= ($item eq $myconfig{numberformat}) ? "<option selected>$item\n" : "<option>$item\n";
  1445. }
  1446. for (qw(name company address signature)) { $myconfig{$_} = $form->quote($myconfig{$_}) }
  1447. for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g }
  1448. %countrycodes = User->country_codes;
  1449. $countrycodes = '';
  1450. foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
  1451. $countrycodes .= ($myconfig{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}\n" : "<option value=$key>$countrycodes{$key}\n";
  1452. }
  1453. $countrycodes = qq|<option value="">English\n$countrycodes|;
  1454. opendir CSS, "css/.";
  1455. @all = grep /.*\.css$/, readdir CSS;
  1456. closedir CSS;
  1457. foreach $item (@all) {
  1458. if ($item eq $myconfig{stylesheet}) {
  1459. $selectstylesheet .= qq|<option selected>$item\n|;
  1460. } else {
  1461. $selectstylesheet .= qq|<option>$item\n|;
  1462. }
  1463. }
  1464. $selectstylesheet .= "<option>\n";
  1465. if (%printer && $latex) {
  1466. $selectprinter = "<option>\n";
  1467. foreach $item (sort keys %printer) {
  1468. if ($myconfig{printer} eq $item) {
  1469. $selectprinter .= qq|<option value="$item" selected>$item\n|;
  1470. } else {
  1471. $selectprinter .= qq|<option value="$item">$item\n|;
  1472. }
  1473. }
  1474. $printer = qq|
  1475. <tr>
  1476. <th align="right">|.$locale->text('Printer').qq|</th>
  1477. <td><select name=printer>$selectprinter</select></td>
  1478. </tr>
  1479. |;
  1480. }
  1481. $form->{title} = $locale->text('Edit Preferences for').qq| $form->{login}|;
  1482. $form->header;
  1483. print qq|
  1484. <body>
  1485. <form method=post action=$form->{script}>
  1486. <input type=hidden name=old_password value=$myconfig{password}>
  1487. <input type=hidden name=type value=preferences>
  1488. <input type=hidden name=role value=$myconfig{role}>
  1489. <table width=100%>
  1490. <tr><th class=listtop>$form->{title}</th></tr>
  1491. <tr>
  1492. <td>
  1493. <table width=100%>
  1494. <tr valign=top>
  1495. <td>
  1496. <table>
  1497. <tr>
  1498. <th align="right">|.$locale->text('Name').qq|</th>
  1499. <td><input name=name size=20 value="$myconfig{name}"></td>
  1500. </tr>
  1501. <tr>
  1502. <th align="right">|.$locale->text('E-mail').qq|</th>
  1503. <td><input name=email size=35 value="$myconfig{email}"></td>
  1504. </tr>
  1505. <tr valign=top>
  1506. <th align="right">|.$locale->text('Signature').qq|</th>
  1507. <td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td>
  1508. </tr>
  1509. <tr>
  1510. <th align="right">|.$locale->text('Phone').qq|</th>
  1511. <td><input name=tel size=14 value="$myconfig{tel}"></td>
  1512. </tr>
  1513. <tr>
  1514. <th align="right">|.$locale->text('Fax').qq|</th>
  1515. <td><input name=fax size=14 value="$myconfig{fax}"></td>
  1516. </tr>
  1517. <tr>
  1518. <th align="right">|.$locale->text('Company').qq|</th>
  1519. <td><input name=company size=35 value="$myconfig{company}"></td>
  1520. </tr>
  1521. <tr valign=top>
  1522. <th align="right">|.$locale->text('Address').qq|</th>
  1523. <td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td>
  1524. </tr>
  1525. </table>
  1526. </td>
  1527. <td>
  1528. <table>
  1529. <tr>
  1530. <th align="right">|.$locale->text('Password').qq|</th>
  1531. <td><input type=password name=new_password size=10 value=$myconfig{password}></td>
  1532. </tr>
  1533. <tr>
  1534. <th align="right">|.$locale->text('Confirm').qq|</th>
  1535. <td><input type=password name=confirm_password size=10></td>
  1536. </tr>
  1537. <tr>
  1538. <th align="right">|.$locale->text('Date Format').qq|</th>
  1539. <td><select name=dateformat>$dateformat</select></td>
  1540. </tr>
  1541. <tr>
  1542. <th align="right">|.$locale->text('Number Format').qq|</th>
  1543. <td><select name=numberformat>$numberformat</select></td>
  1544. </tr>
  1545. <tr>
  1546. <th align="right">|.$locale->text('Dropdown Limit').qq|</th>
  1547. <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
  1548. </tr>
  1549. <tr>
  1550. <th align="right">|.$locale->text('Menu Width').qq|</th>
  1551. <td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td>
  1552. </tr>
  1553. <tr>
  1554. <th align="right">|.$locale->text('Language').qq|</th>
  1555. <td><select name=countrycode>$countrycodes</select></td>
  1556. </tr>
  1557. <tr>
  1558. <th align="right">|.$locale->text('Session Timeout').qq|</th>
  1559. <td><input name=timeout size=10 value="$myconfig{timeout}"></td>
  1560. </tr>
  1561. <tr>
  1562. <th align="right">|.$locale->text('Stylesheet').qq|</th>
  1563. <td><select name=usestylesheet>$selectstylesheet</select></td>
  1564. </tr>
  1565. $printer
  1566. </table>
  1567. </td>
  1568. </tr>
  1569. </table>
  1570. </td>
  1571. <tr>
  1572. <td><hr size=3 noshade></td>
  1573. </tr>
  1574. </table>
  1575. |;
  1576. $form->hide_form(qw(path login sessionid));
  1577. print qq|
  1578. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;
  1579. if ($form->{menubar}) {
  1580. require "$form->{path}/menu.pl";
  1581. &menubar;
  1582. }
  1583. print qq|
  1584. </form>
  1585. </body>
  1586. </html>
  1587. |;
  1588. }
  1589. sub save_defaults {
  1590. if (AM->save_defaults(\%myconfig, \%$form)) {
  1591. $form->redirect($locale->text('Defaults saved!'));
  1592. } else {
  1593. $form->error($locale->text('Cannot save defaults!'));
  1594. }
  1595. }
  1596. sub save_taxes {
  1597. if (AM->save_taxes(\%myconfig, \%$form)) {
  1598. $form->redirect($locale->text('Taxes saved!'));
  1599. } else {
  1600. $form->error($locale->text('Cannot save taxes!'));
  1601. }
  1602. }
  1603. sub save_preferences {
  1604. $form->{stylesheet} = $form->{usestylesheet};
  1605. if ($form->{new_password} ne $form->{old_password}) {
  1606. $form->error($locale->text('Password does not match!')) if $form->{new_password} ne $form->{confirm_password};
  1607. }
  1608. if (AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath)) {
  1609. $form->redirect($locale->text('Preferences saved!'));
  1610. } else {
  1611. $form->error($locale->text('Cannot save preferences!'));
  1612. }
  1613. }
  1614. sub backup {
  1615. if ($form->{media} eq 'email') {
  1616. $form->error($locale->text('No email address for')." $myconfig{name}") unless ($myconfig{email});
  1617. $form->{OUT} = "$sendmail";
  1618. }
  1619. $SIG{INT} = 'IGNORE';
  1620. AM->backup(\%myconfig, \%$form, $userspath, $gzip);
  1621. if ($form->{media} eq 'email') {
  1622. $form->redirect($locale->text('Backup sent to').qq| $myconfig{email}|);
  1623. }
  1624. }
  1625. sub audit_control {
  1626. $form->{title} = $locale->text('Audit Control');
  1627. AM->closedto(\%myconfig, \%$form);
  1628. if ($form->{revtrans}) {
  1629. $checked{revtransY} = "checked";
  1630. } else {
  1631. $checked{revtransN} = "checked";
  1632. }
  1633. if ($form->{audittrail}) {
  1634. $checked{audittrailY} = "checked";
  1635. } else {
  1636. $checked{audittrailN} = "checked";
  1637. }
  1638. $form->header;
  1639. print qq|
  1640. <body>
  1641. <form method=post action=$form->{script}>
  1642. <input type=hidden name=path value=$form->{path}>
  1643. <input type=hidden name=login value=$form->{login}>
  1644. <input type=hidden name=sessionid value=$form->{sessionid}>
  1645. <table width=100%>
  1646. <tr><th class=listtop>$form->{title}</th></tr>
  1647. <tr height="5"></tr>
  1648. <tr>
  1649. <td>
  1650. <table>
  1651. <tr>
  1652. <th align="right">|.$locale->text('Enforce transaction reversal for all dates').qq|</th>
  1653. <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>
  1654. </tr>
  1655. <tr>
  1656. <th align="right">|.$locale->text('Close Books up to').qq|</th>
  1657. <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
  1658. </tr>
  1659. <tr>
  1660. <th align="right">|.$locale->text('Activate Audit trail').qq|</th>
  1661. <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>
  1662. </tr>
  1663. <tr>
  1664. <th align="right">|.$locale->text('Remove Audit trail up to').qq|</th>
  1665. <td><input name=removeaudittrail size=11 title="$myconfig{dateformat}"></td>
  1666. </tr>
  1667. </table>
  1668. </td>
  1669. </tr>
  1670. </table>
  1671. <hr size=3 noshade>
  1672. <br>
  1673. <input type=hidden name=nextsub value=doclose>
  1674. <input type=hidden name=action value=continue>
  1675. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  1676. </form>
  1677. </body>
  1678. </html>
  1679. |;
  1680. }
  1681. sub doclose {
  1682. AM->closebooks(\%myconfig, \%$form);
  1683. if ($form->{revtrans}) {
  1684. $msg = $locale->text('Transaction reversal enforced for all dates');
  1685. } else {
  1686. if ($form->{closedto}) {
  1687. $msg = $locale->text('Transaction reversal enforced up to')
  1688. ." ".$locale->date(\%myconfig, $form->{closedto}, 1);
  1689. } else {
  1690. $msg = $locale->text('Books are open');
  1691. }
  1692. }
  1693. $msg .= "<p>";
  1694. if ($form->{audittrail}) {
  1695. $msg .= $locale->text('Audit trail enabled');
  1696. } else {
  1697. $msg .= $locale->text('Audit trail disabled');
  1698. }
  1699. $msg .= "<p>";
  1700. if ($form->{removeaudittrail}) {
  1701. $msg .= $locale->text('Audit trail removed up to')
  1702. ." ".$locale->date(\%myconfig, $form->{removeaudittrail}, 1);
  1703. }
  1704. $form->redirect($msg);
  1705. }
  1706. sub add_warehouse {
  1707. $form->{title} = "Add";
  1708. $form->{callback} = "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  1709. &warehouse_header;
  1710. &form_footer;
  1711. }
  1712. sub edit_warehouse {
  1713. $form->{title} = "Edit";
  1714. AM->get_warehouse(\%myconfig, \%$form);
  1715. &warehouse_header;
  1716. &form_footer;
  1717. }
  1718. sub list_warehouse {
  1719. AM->warehouses(\%myconfig, \%$form);
  1720. $href = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1721. $form->sort_order();
  1722. $form->{callback} = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1723. $callback = $form->escape($form->{callback});
  1724. $form->{title} = $locale->text('Warehouses');
  1725. @column_index = qw(description);
  1726. $column_header{description} = qq|<th width=100%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
  1727. $form->header;
  1728. print qq|
  1729. <body>
  1730. <table width=100%>
  1731. <tr>
  1732. <th class=listtop>$form->{title}</th>
  1733. </tr>
  1734. <tr height="5"></tr>
  1735. <tr>
  1736. <td>
  1737. <table width=100%>
  1738. <tr class="listheading">
  1739. |;
  1740. for (@column_index) { print "$column_header{$_}\n" }
  1741. print qq|
  1742. </tr>
  1743. |;
  1744. foreach $ref (@{ $form->{ALL} }) {
  1745. $i++; $i %= 2;
  1746. print qq|
  1747. <tr valign=top class=listrow$i>
  1748. |;
  1749. $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>|;
  1750. for (@column_index) { print "$column_data{$_}\n" }
  1751. print qq|
  1752. </tr>
  1753. |;
  1754. }
  1755. print qq|
  1756. </table>
  1757. </td>
  1758. </tr>
  1759. <tr>
  1760. <td><hr size=3 noshade></td>
  1761. </tr>
  1762. </table>
  1763. <br>
  1764. <form method=post action=$form->{script}>
  1765. |;
  1766. $form->{type} = "warehouse";
  1767. $form->hide_form(qw(type callback path login sessionid));
  1768. print qq|
  1769. <input class=submit type=submit name=action value="|.$locale->text('Add Warehouse').qq|">|;
  1770. if ($form->{menubar}) {
  1771. require "$form->{path}/menu.pl";
  1772. &menubar;
  1773. }
  1774. print qq|
  1775. </form>
  1776. </body>
  1777. </html>
  1778. |;
  1779. }
  1780. sub warehouse_header {
  1781. $form->{title} = $locale->text("$form->{title} Warehouse");
  1782. # $locale->text('Add Warehouse')
  1783. # $locale->text('Edit Warehouse')
  1784. $form->{description} = $form->quote($form->{description});
  1785. if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
  1786. $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  1787. } else {
  1788. $description = qq|<input name=description size=60 value="$form->{description}">|;
  1789. }
  1790. $form->header;
  1791. print qq|
  1792. <body>
  1793. <form method=post action=$form->{script}>
  1794. <input type=hidden name=id value=$form->{id}>
  1795. <input type=hidden name=type value=warehouse>
  1796. <table width=100%>
  1797. <tr>
  1798. <th class=listtop colspan=2>$form->{title}</th>
  1799. </tr>
  1800. <tr height="5"></tr>
  1801. <tr>
  1802. <th align="right">|.$locale->text('Description').qq|</th>
  1803. <td>$description</td>
  1804. </tr>
  1805. <tr>
  1806. <td colspan=2><hr size=3 noshade></td>
  1807. </tr>
  1808. </table>
  1809. |;
  1810. }
  1811. sub save_warehouse {
  1812. $form->isblank("description", $locale->text('Description missing!'));
  1813. AM->save_warehouse(\%myconfig, \%$form);
  1814. $form->redirect($locale->text('Warehouse saved!'));
  1815. }
  1816. sub delete_warehouse {
  1817. AM->delete_warehouse(\%myconfig, \%$form);
  1818. $form->redirect($locale->text('Warehouse deleted!'));
  1819. }
  1820. sub yearend {
  1821. AM->earningsaccounts(\%myconfig, \%$form);
  1822. $chart = "";
  1823. for (@{ $form->{chart} }) { $chart .= "<option>$_->{accno}--$_->{description}" }
  1824. $form->{title} = $locale->text('Yearend');
  1825. $form->header;
  1826. print qq|
  1827. <body>
  1828. <form method=post action=$form->{script}>
  1829. <input type=hidden name=decimalplaces value=2>
  1830. <input type=hidden name=l_accno value=Y>
  1831. <table width=100%>
  1832. <tr>
  1833. <th class=listtop>$form->{title}</th>
  1834. </tr>
  1835. <tr height="5"></tr>
  1836. <tr>
  1837. <td>
  1838. <table>
  1839. <tr>
  1840. <th align="right">|.$locale->text('Yearend').qq|</th>
  1841. <td><input name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
  1842. </tr>
  1843. <tr>
  1844. <th align="right">|.$locale->text('Reference').qq|</th>
  1845. <td><input name=reference size=20 value="|.$locale->text('Yearend').qq|"></td>
  1846. </tr>
  1847. <tr>
  1848. <th align="right">|.$locale->text('Description').qq|</th>
  1849. <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
  1850. </tr>
  1851. <tr>
  1852. <th align="right">|.$locale->text('Retained Earnings').qq|</th>
  1853. <td><select name=accno>$chart</select></td>
  1854. </tr>
  1855. <tr>
  1856. <th align="right">|.$locale->text('Method').qq|</th>
  1857. <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>
  1858. </tr>
  1859. </table>
  1860. </td>
  1861. </tr>
  1862. </table>
  1863. <hr size=3 noshade>
  1864. <input type=hidden name=nextsub value=generate_yearend>
  1865. |;
  1866. $form->hide_form(qw(path login sessionid));
  1867. print qq|
  1868. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
  1869. }
  1870. sub generate_yearend {
  1871. $form->isblank("todate", $locale->text('Yearend date missing!'));
  1872. RP->yearend_statement(\%myconfig, \%$form);
  1873. $form->{transdate} = $form->{todate};
  1874. $earnings = 0;
  1875. $form->{rowcount} = 1;
  1876. foreach $key (keys %{ $form->{I} }) {
  1877. if ($form->{I}{$key}{charttype} eq "A") {
  1878. $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
  1879. $earnings += $form->{I}{$key}{this};
  1880. $form->{"accno_$form->{rowcount}"} = $key;
  1881. $form->{rowcount}++;
  1882. $ok = 1;
  1883. }
  1884. }
  1885. foreach $key (keys %{ $form->{E} }) {
  1886. if ($form->{E}{$key}{charttype} eq "A") {
  1887. $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
  1888. $earnings += $form->{E}{$key}{this};
  1889. $form->{"accno_$form->{rowcount}"} = $key;
  1890. $form->{rowcount}++;
  1891. $ok = 1;
  1892. }
  1893. }
  1894. if ($earnings > 0) {
  1895. $form->{"credit_$form->{rowcount}"} = $earnings;
  1896. $form->{"accno_$form->{rowcount}"} = $form->{accno}
  1897. } else {
  1898. $form->{"debit_$form->{rowcount}"} = $earnings * -1;
  1899. $form->{"accno_$form->{rowcount}"} = $form->{accno}
  1900. }
  1901. if ($ok) {
  1902. if (AM->post_yearend(\%myconfig, \%$form)) {
  1903. $form->redirect($locale->text('Yearend posted!'));
  1904. } else {
  1905. $form->error($locale->text('Yearend posting failed!'));
  1906. }
  1907. } else {
  1908. $form->error('Nothing to do!');
  1909. }
  1910. }
  1911. sub company_logo {
  1912. $myconfig{address} =~ s/\\n/<br>/g;
  1913. $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
  1914. $form->{stylesheet} = $myconfig{stylesheet};
  1915. $form->{title} = $locale->text('About');
  1916. # create the logo screen
  1917. $form->header;
  1918. print qq|
  1919. <body>
  1920. <pre>
  1921. </pre>
  1922. <center>
  1923. <a href="http://www.ledgersmb.org/" target="_blank"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  1924. <h1 class="login">|.$locale->text('Version').qq| $form->{version}</h1>
  1925. <p>
  1926. |.$locale->text('Licensed to').qq|
  1927. <p>
  1928. <b>
  1929. $myconfig{company}
  1930. <br>$myconfig{address}
  1931. </b>
  1932. <p>
  1933. <table border=0>
  1934. <tr>
  1935. <th align="right">|.$locale->text('User').qq|</th>
  1936. <td>$myconfig{name}</td>
  1937. </tr>
  1938. <tr>
  1939. <th align="right">|.$locale->text('Dataset').qq|</th>
  1940. <td>$myconfig{dbname}</td>
  1941. </tr>
  1942. <tr>
  1943. <th align="right">|.$locale->text('Database Host').qq|</th>
  1944. <td>$myconfig{dbhost}</td>
  1945. </tr>
  1946. </table>
  1947. </center>
  1948. </body>
  1949. </html>
  1950. |;
  1951. }
  1952. sub recurring_transactions {
  1953. # $locale->text('Day')
  1954. # $locale->text('Days')
  1955. # $locale->text('Month')
  1956. # $locale->text('Months')
  1957. # $locale->text('Week')
  1958. # $locale->text('Weeks')
  1959. # $locale->text('Year')
  1960. # $locale->text('Years')
  1961. $form->{stylesheet} = $myconfig{stylesheet};
  1962. $form->{title} = $locale->text('Recurring Transactions');
  1963. $column_header{id} = "";
  1964. AM->recurring_transactions(\%myconfig, \%$form);
  1965. $href = "$form->{script}?action=recurring_transactions";
  1966. for (qw(direction oldsort path login sessionid)) { $href .= qq|&$_=$form->{$_}| }
  1967. $form->sort_order();
  1968. # create the logo screen
  1969. $form->header;
  1970. @column_index = qw(ndx reference description);
  1971. push @column_index, qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
  1972. $column_header{reference} = qq|<th><a class="listheading" href="$href&sort=reference">|.$locale->text('Reference').q|</a></th>|;
  1973. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  1974. $column_header{id} = q|<th class="listheading">|.$locale->text('ID').q|</th>|;
  1975. $column_header{description} = q|<th class="listheading">|.$locale->text('Description').q|</th>|;
  1976. $column_header{nextdate} = qq|<th><a class="listheading" href="$href&sort=nextdate">|.$locale->text('Next').q|</a></th>|;
  1977. $column_header{enddate} = qq|<th><a class="listheading" href="$href&sort=enddate">|.$locale->text('Ends').q|</a></th>|;
  1978. $column_header{amount} = q|<th class="listheading">|.$locale->text('Amount').q|</th>|;
  1979. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  1980. $column_header{repeat} = q|<th class="listheading">|.$locale->text('Every').q|</th>|;
  1981. $column_header{howmany} = q|<th class="listheading">|.$locale->text('Times').q|</th>|;
  1982. $column_header{recurringemail} = q|<th class="listheading">|.$locale->text('E-mail').q|</th>|;
  1983. $column_header{recurringprint} = q|<th class="listheading">|.$locale->text('Print').q|</th>|;
  1984. print qq|
  1985. <body>
  1986. <form method=post action=$form->{script}>
  1987. <table width=100%>
  1988. <tr>
  1989. <th class=listtop>$form->{title}</th>
  1990. </tr>
  1991. <tr height="5"></tr>
  1992. <tr>
  1993. <td>
  1994. <table width=100%>
  1995. <tr class="listheading">
  1996. |;
  1997. for (@column_index) { print "\n$column_header{$_}" }
  1998. print qq|
  1999. </tr>
  2000. |;
  2001. $i = 1;
  2002. $colspan = $#column_index + 1;
  2003. %tr = ( ar => $locale->text('AR'),
  2004. ap => $locale->text('AP'),
  2005. gl => $locale->text('GL'),
  2006. so => $locale->text('Sales Orders'),
  2007. po => $locale->text('Purchase Orders'),
  2008. );
  2009. %f = &formnames;
  2010. foreach $transaction (sort keys %{ $form->{transactions} }) {
  2011. print qq|
  2012. <tr>
  2013. <th class="listheading" colspan=$colspan>$tr{$transaction}</th>
  2014. </tr>
  2015. |;
  2016. foreach $ref (@{ $form->{transactions}{$transaction} }) {
  2017. for (@column_index) { $column_data{$_} = "<td nowrap>$ref->{$_}</td>" }
  2018. if ($ref->{repeat} > 1) {
  2019. $unit = $locale->text(ucfirst $ref->{unit});
  2020. $repeat = "$ref->{repeat} $unit";
  2021. } else {
  2022. chop $ref->{unit};
  2023. $unit = $locale->text(ucfirst $ref->{unit});
  2024. $repeat = $unit;
  2025. }
  2026. $column_data{ndx} = qq|<td></td>|;
  2027. if (!$ref->{expired}) {
  2028. if ($ref->{overdue} <= 0) {
  2029. $k++;
  2030. $column_data{ndx} = qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2031. }
  2032. }
  2033. $reference = ($ref->{reference}) ? $ref->{reference} : $locale->text('Next Number');
  2034. $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>|;
  2035. $module = "$ref->{module}.pl";
  2036. $type = "";
  2037. if ($ref->{module} eq 'ar') {
  2038. $module = "is.pl" if $ref->{invoice};
  2039. $ref->{amount} /= $ref->{exchangerate};
  2040. }
  2041. if ($ref->{module} eq 'ap') {
  2042. $module = "ir.pl" if $ref->{invoice};
  2043. $ref->{amount} /= $ref->{exchangerate};
  2044. }
  2045. if ($ref->{module} eq 'oe') {
  2046. $type = ($ref->{vc} eq 'customer') ? "sales_order" : "purchase_order";
  2047. }
  2048. $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>|;
  2049. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2050. $column_data{howmany} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{howmany})."</td>";
  2051. $column_data{amount} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{amount}, 2)."</td>";
  2052. $column_data{recurringemail} = "<td nowrap>";
  2053. @f = split /:/, $ref->{recurringemail};
  2054. for (0 .. $#f) { $column_data{recurringemail} .= "$f{$f[$_]}<br>" }
  2055. $column_data{recurringemail} .= "</td>";
  2056. $column_data{recurringprint} = "<td nowrap>";
  2057. @f = split /:/, $ref->{recurringprint};
  2058. for (0 .. $#f) { $column_data{recurringprint} .= "$f{$f[$_]}<br>" }
  2059. $column_data{recurringprint} .= "</td>";
  2060. $j++; $j %= 2;
  2061. print qq|
  2062. <tr class=listrow$j>
  2063. |;
  2064. for (@column_index) { print "\n$column_data{$_}" }
  2065. print qq|
  2066. </tr>
  2067. |;
  2068. }
  2069. }
  2070. print qq|
  2071. </tr>
  2072. </table>
  2073. </td>
  2074. </tr>
  2075. <tr>
  2076. <td><hr size=3 noshade></td>
  2077. </tr>
  2078. </table>
  2079. <input name=lastndx type=hidden value=$k>
  2080. |;
  2081. $form->hide_form(qw(path login sessionid));
  2082. print qq|
  2083. <input class=submit type=submit name=action value="|.$locale->text('Process Transactions').qq|">| if $k;
  2084. if ($form->{menubar}) {
  2085. require "$form->{path}/menu.pl";
  2086. &menubar;
  2087. }
  2088. print qq|
  2089. </form>
  2090. </body>
  2091. </html>
  2092. |;
  2093. }
  2094. sub edit_recurring {
  2095. %links = ( ar => 'create_links',
  2096. ap => 'create_links',
  2097. gl => 'create_links',
  2098. is => 'invoice_links',
  2099. ir => 'invoice_links',
  2100. oe => 'order_links',
  2101. );
  2102. %prepare = ( is => 'prepare_invoice',
  2103. ir => 'prepare_invoice',
  2104. oe => 'prepare_order',
  2105. );
  2106. $form->{callback} = "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2107. $form->{type} = "transaction";
  2108. if ($form->{module} eq 'ar') {
  2109. if ($form->{invoice}) {
  2110. $form->{type} = "invoice";
  2111. $form->{module} = "is";
  2112. }
  2113. }
  2114. if ($form->{module} eq 'ap') {
  2115. if ($form->{invoice}) {
  2116. $form->{type} = "invoice";
  2117. $form->{module} = "ir";
  2118. }
  2119. }
  2120. if ($form->{module} eq 'oe') {
  2121. %tr = ( so => sales_order,
  2122. po => purchase_order,
  2123. );
  2124. $form->{type} = $tr{$form->{transaction}};
  2125. }
  2126. $form->{script} = "$form->{module}.pl";
  2127. do "$form->{path}/$form->{script}";
  2128. &{ $links{$form->{module}} };
  2129. # return if transaction doesn't exist
  2130. $form->redirect unless $form->{recurring};
  2131. if ($prepare{$form->{module}}) {
  2132. &{ $prepare{$form->{module}} };
  2133. }
  2134. $form->{selectformat} = qq|<option value="html">html\n|;
  2135. if ($latex) {
  2136. $form->{selectformat} .= qq|
  2137. <option value="postscript">|.$locale->text('Postscript').qq|
  2138. <option value="pdf">|.$locale->text('PDF');
  2139. }
  2140. &schedule;
  2141. }
  2142. sub process_transactions {
  2143. # save variables
  2144. my $pt = new Form;
  2145. for (keys %$form) { $pt->{$_} = $form->{$_} }
  2146. my $defaultprinter;
  2147. while (my ($key, $value) = each %printer) {
  2148. if ($value =~ /lpr/) {
  2149. $defaultprinter = $key;
  2150. last;
  2151. }
  2152. }
  2153. $myconfig{vclimit} = 0;
  2154. %f = &formnames;
  2155. for (my $i = 1; $i <= $pt->{lastndx}; $i++) {
  2156. if ($pt->{"ndx_$i"}) {
  2157. $id = $pt->{"ndx_$i"};
  2158. # process transaction
  2159. AM->recurring_details(\%myconfig, \%$pt, $id);
  2160. $header = $form->{header};
  2161. # reset $form
  2162. for (keys %$form) { delete $form->{$_}; }
  2163. for (qw(login path sessionid stylesheet timeout)) { $form->{$_} = $pt->{$_}; }
  2164. $form->{id} = $id;
  2165. $form->{header} = $header;
  2166. # post, print, email
  2167. if ($pt->{arid} || $pt->{apid} || $pt->{oeid}) {
  2168. if ($pt->{arid} || $pt->{apid}) {
  2169. if ($pt->{arid}) {
  2170. $form->{script} = ($pt->{invoice}) ? "is.pl" : "ar.pl";
  2171. $form->{ARAP} = "AR";
  2172. $form->{module} = "ar";
  2173. $invfld = "sinumber";
  2174. } else {
  2175. $form->{script} = ($pt->{invoice}) ? "ir.pl" : "ap.pl";
  2176. $form->{ARAP} = "AP";
  2177. $form->{module} = "ap";
  2178. $invfld = "vinumber";
  2179. }
  2180. do "$form->{path}/$form->{script}";
  2181. if ($pt->{invoice}) {
  2182. &invoice_links;
  2183. &prepare_invoice;
  2184. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  2185. } else {
  2186. &create_links;
  2187. $form->{type} = "transaction";
  2188. for (1 .. $form->{rowcount} - 1) { $form->{"amount_$_"} = $form->format_amount(\%myconfig, $form->{"amount_$_"}, 2) }
  2189. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, 2) }
  2190. }
  2191. delete $form->{"$form->{ARAP}_links"};
  2192. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  2193. for (qw(department employee language month partsgroup project years)) { delete $form->{"all_$_"} }
  2194. $form->{invnumber} = $pt->{reference};
  2195. $form->{transdate} = $pt->{nextdate};
  2196. # tax accounts
  2197. $form->all_taxaccounts(\%myconfig, undef, $form->{transdate});
  2198. # calculate duedate
  2199. $form->{duedate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{overdue}, "days");
  2200. if ($pt->{payment}) {
  2201. # calculate date paid
  2202. for ($j = 1; $j <= $form->{paidaccounts}; $j++) {
  2203. $form->{"datepaid_$j"} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{paid}, "days");
  2204. ($form->{"$form->{ARAP}_paid_$j"}) = split /--/, $form->{"$form->{ARAP}_paid_$j"};
  2205. delete $form->{"cleared_$j"};
  2206. }
  2207. $form->{paidaccounts}++;
  2208. } else {
  2209. $form->{paidaccounts} = -1;
  2210. }
  2211. for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
  2212. ($form->{$form->{ARAP}}) = split /--/, $form->{$form->{ARAP}};
  2213. $form->{invnumber} = $form->update_defaults(\%myconfig, "$invfld") unless $form->{invnumber};
  2214. $form->{reference} = $form->{invnumber};
  2215. for (qw(invnumber reference)) { $form->{$_} = $form->unquote($form->{$_}) }
  2216. if ($pt->{invoice}) {
  2217. if ($pt->{arid}) {
  2218. $form->info("\n".$locale->text('Posting')." ".$locale->text('Sales Invoice')." $form->{invnumber}");
  2219. $ok = IS->post_invoice(\%myconfig, \%$form);
  2220. } else {
  2221. $form->info("\n".$locale->text('Posting')." ".$locale->text('Vendor Invoice')." $form->{invnumber}");
  2222. $ok = IR->post_invoice(\%myconfig, \%$form);
  2223. }
  2224. } else {
  2225. if ($pt->{arid}) {
  2226. $form->info("\n".$locale->text('Posting')." ".$locale->text('Transaction')." $form->{invnumber}");
  2227. } else {
  2228. $form->info("\n".$locale->text('Posting')." ".$locale->text('Transaction')." $form->{invnumber}");
  2229. }
  2230. $ok = AA->post_transaction(\%myconfig, \%$form);
  2231. }
  2232. $form->info(" ..... ".$locale->text('done'));
  2233. # print form
  2234. if ($latex && $ok) {
  2235. $ok = &print_recurring(\%$pt, $defaultprinter);
  2236. }
  2237. &email_recurring(\%$pt) if $ok;
  2238. } else {
  2239. # order
  2240. $form->{script} = "oe.pl";
  2241. $form->{module} = "oe";
  2242. $ordnumber = "ordnumber";
  2243. if ($pt->{customer_id}) {
  2244. $form->{vc} = "customer";
  2245. $form->{type} = "sales_order";
  2246. $ordfld = "sonumber";
  2247. $flabel = $locale->text('Sales Order');
  2248. } else {
  2249. $form->{vc} = "vendor";
  2250. $form->{type} = "purchase_order";
  2251. $ordfld = "ponumber";
  2252. $flabel = $locale->text('Purchase Order');
  2253. }
  2254. require "$form->{path}/$form->{script}";
  2255. &order_links;
  2256. &prepare_order;
  2257. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  2258. $form->{$ordnumber} = $pt->{reference};
  2259. $form->{transdate} = $pt->{nextdate};
  2260. # calculate reqdate
  2261. $form->{reqdate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{req}, "days") if $form->{reqdate};
  2262. for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
  2263. for (1 .. $form->{rowcount}) { delete $form->{"orderitems_id_$_"} }
  2264. $form->{$ordnumber} = $form->update_defaults(\%myconfig, "$ordfld") unless $form->{$ordnumber};
  2265. $form->{reference} = $form->{$ordnumber};
  2266. for ("$ordnumber", "reference") { $form->{$_} = $form->unquote($form->{$_}) }
  2267. $form->{closed} = 0;
  2268. $form->info("\n".$locale->text('Saving')." ".$flabel." $form->{$ordnumber}");
  2269. if ($ok = OE->save(\%myconfig, \%$form)) {
  2270. $form->info(" ..... ".$locale->text('done'));
  2271. } else {
  2272. $form->info(" ..... ".$locale->text('failed'));
  2273. }
  2274. # print form
  2275. if ($latex && $ok) {
  2276. &print_recurring(\%$pt, $defaultprinter);
  2277. }
  2278. &email_recurring(\%$pt);
  2279. }
  2280. } else {
  2281. # GL transaction
  2282. GL->transaction(\%myconfig, \%$form);
  2283. $form->{reference} = $pt->{reference};
  2284. $form->{transdate} = $pt->{nextdate};
  2285. $j = 1;
  2286. foreach $ref (@{ $form->{GL} }) {
  2287. $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
  2288. $form->{"projectnumber_$j"} = "$ref->{projectnumber}--$ref->{project_id}" if $ref->{project_id};
  2289. $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
  2290. if ($ref->{amount} < 0) {
  2291. $form->{"debit_$j"} = $ref->{amount} * -1;
  2292. } else {
  2293. $form->{"credit_$j"} = $ref->{amount};
  2294. }
  2295. $j++;
  2296. }
  2297. $form->{rowcount} = $j;
  2298. for (qw(id recurring)) { delete $form->{$_} }
  2299. $form->info("\n".$locale->text('Posting')." ".$locale->text('GL Transaction')." $form->{reference}");
  2300. $ok = GL->post_transaction(\%myconfig, \%$form);
  2301. $form->info(" ..... ".$locale->text('done'));
  2302. }
  2303. AM->update_recurring(\%myconfig, \%$pt, $id) if $ok;
  2304. }
  2305. }
  2306. $form->{callback} = "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
  2307. $form->redirect;
  2308. }
  2309. sub print_recurring {
  2310. my ($pt, $defaultprinter) = @_;
  2311. my %f = &formnames;
  2312. my $ok = 1;
  2313. if ($pt->{recurringprint}) {
  2314. @f = split /:/, $pt->{recurringprint};
  2315. for ($j = 0; $j <= $#f; $j += 3) {
  2316. $media = $f[$j+2];
  2317. $media ||= $myconfig->{printer} if $printer{$myconfig->{printer}};
  2318. $media ||= $defaultprinter;
  2319. $form->info("\n".$locale->text('Printing')." ".$locale->text($f{$f[$j]})." $form->{reference}");
  2320. @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}");
  2321. $ok = !(system(@a));
  2322. if ($ok) {
  2323. $form->info(" ..... ".$locale->text('done'));
  2324. } else {
  2325. $form->info(" ..... ".$locale->text('failed'));
  2326. last;
  2327. }
  2328. }
  2329. }
  2330. $ok;
  2331. }
  2332. sub email_recurring {
  2333. my ($pt) = @_;
  2334. my %f = &formnames;
  2335. my $ok = 1;
  2336. if ($pt->{recurringemail}) {
  2337. @f = split /:/, $pt->{recurringemail};
  2338. for ($j = 0; $j <= $#f; $j += 2) {
  2339. $form->info("\n".$locale->text('Sending')." ".$locale->text($f{$f[$j]})." $form->{reference}");
  2340. # no email, bail out
  2341. if (!$form->{email}) {
  2342. $form->info(" ..... ".$locale->text('E-mail address missing!'));
  2343. last;
  2344. }
  2345. $message = $form->escape($pt->{message},1);
  2346. @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");
  2347. $ok = !(system(@a));
  2348. if ($ok) {
  2349. $form->info(" ..... ".$locale->text('done'));
  2350. } else {
  2351. $form->info(" ..... ".$locale->text('failed'));
  2352. last;
  2353. }
  2354. }
  2355. }
  2356. $ok;
  2357. }
  2358. sub formnames {
  2359. # $locale->text('Transaction')
  2360. # $locale->text('Invoice')
  2361. # $locale->text('Credit Invoice')
  2362. # $locale->text('Debit Invoice')
  2363. # $locale->text('Packing List')
  2364. # $locale->text('Pick List')
  2365. # $locale->text('Sales Order')
  2366. # $locale->text('Work Order')
  2367. # $locale->text('Purchase Order')
  2368. # $locale->text('Bin List')
  2369. my %f = ( transaction => 'Transaction',
  2370. invoice => 'Invoice',
  2371. credit_invoice => 'Credit Invoice',
  2372. debit_invoice => 'Debit Invoice',
  2373. packing_list => 'Packing List',
  2374. pick_list => 'Pick List',
  2375. sales_order => 'Sales Order',
  2376. work_order => 'Work Order',
  2377. purchase_order => 'Purchase Order',
  2378. bin_list => 'Bin List',
  2379. );
  2380. %f;
  2381. }
  2382. sub continue { &{ $form->{nextsub} } };