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