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