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