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