summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: 5015660ee365357ef8d166ed9c6aeb94d717e477 (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')." $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').qq| $form->{invnumber}</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->defaultaccounts(\%myconfig, \%$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').qq| $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, ${LedgerSMB::Sysconfig::memberfile}, ${LedgerSMB::Sysconfig::userspath})) {
  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')." $myconfig{name}") unless ($myconfig{email});
  1620. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1621. }
  1622. $SIG{INT} = 'IGNORE';
  1623. AM->backup(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::userspath}, ${LedgerSMB::Sysconfig::gzip});
  1624. if ($form->{media} eq 'email') {
  1625. $form->redirect($locale->text('Backup sent to').qq| $myconfig{email}|);
  1626. }
  1627. }
  1628. sub audit_control {
  1629. $form->{title} = $locale->text('Audit Control');
  1630. AM->closedto(\%myconfig, \%$form);
  1631. if ($form->{revtrans}) {
  1632. $checked{revtransY} = "checked";
  1633. } else {
  1634. $checked{revtransN} = "checked";
  1635. }
  1636. if ($form->{audittrail}) {
  1637. $checked{audittrailY} = "checked";
  1638. } else {
  1639. $checked{audittrailN} = "checked";
  1640. }
  1641. $form->header;
  1642. print qq|
  1643. <body>
  1644. <form method=post action=$form->{script}>
  1645. <input type=hidden name=path value=$form->{path}>
  1646. <input type=hidden name=login value=$form->{login}>
  1647. <input type=hidden name=sessionid value=$form->{sessionid}>
  1648. <table width=100%>
  1649. <tr><th class=listtop>$form->{title}</th></tr>
  1650. <tr height="5"></tr>
  1651. <tr>
  1652. <td>
  1653. <table>
  1654. <tr>
  1655. <th align="right">|.$locale->text('Enforce transaction reversal for all dates').qq|</th>
  1656. <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>
  1657. </tr>
  1658. <tr>
  1659. <th align="right">|.$locale->text('Close Books up to').qq|</th>
  1660. <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
  1661. </tr>
  1662. <tr>
  1663. <th align="right">|.$locale->text('Activate Audit trail').qq|</th>
  1664. <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>
  1665. </tr>
  1666. <tr>
  1667. <th align="right">|.$locale->text('Remove Audit trail up to').qq|</th>
  1668. <td><input name=removeaudittrail size=11 title="$myconfig{dateformat}"></td>
  1669. </tr>
  1670. </table>
  1671. </td>
  1672. </tr>
  1673. </table>
  1674. <hr size=3 noshade>
  1675. <br>
  1676. <input type=hidden name=nextsub value=doclose>
  1677. <input type=hidden name=action value=continue>
  1678. <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1679. </form>
  1680. </body>
  1681. </html>
  1682. |;
  1683. }
  1684. sub doclose {
  1685. AM->closebooks(\%myconfig, \%$form);
  1686. if ($form->{revtrans}) {
  1687. $msg = $locale->text('Transaction reversal enforced for all dates');
  1688. } else {
  1689. if ($form->{closedto}) {
  1690. $msg = $locale->text('Transaction reversal enforced up to')
  1691. ." ".$locale->date(\%myconfig, $form->{closedto}, 1);
  1692. } else {
  1693. $msg = $locale->text('Books are open');
  1694. }
  1695. }
  1696. $msg .= "<p>";
  1697. if ($form->{audittrail}) {
  1698. $msg .= $locale->text('Audit trail enabled');
  1699. } else {
  1700. $msg .= $locale->text('Audit trail disabled');
  1701. }
  1702. $msg .= "<p>";
  1703. if ($form->{removeaudittrail}) {
  1704. $msg .= $locale->text('Audit trail removed up to')
  1705. ." ".$locale->date(\%myconfig, $form->{removeaudittrail}, 1);
  1706. }
  1707. $form->redirect($msg);
  1708. }
  1709. sub add_warehouse {
  1710. $form->{title} = "Add";
  1711. $form->{callback} = "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  1712. &warehouse_header;
  1713. &form_footer;
  1714. }
  1715. sub edit_warehouse {
  1716. $form->{title} = "Edit";
  1717. AM->get_warehouse(\%myconfig, \%$form);
  1718. &warehouse_header;
  1719. &form_footer;
  1720. }
  1721. sub list_warehouse {
  1722. AM->warehouses(\%myconfig, \%$form);
  1723. $href = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1724. $form->sort_order();
  1725. $form->{callback} = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1726. $callback = $form->escape($form->{callback});
  1727. $form->{title} = $locale->text('Warehouses');
  1728. @column_index = qw(description);
  1729. $column_header{description} = qq|<th width=100%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
  1730. $form->header;
  1731. print qq|
  1732. <body>
  1733. <table width=100%>
  1734. <tr>
  1735. <th class=listtop>$form->{title}</th>
  1736. </tr>
  1737. <tr height="5"></tr>
  1738. <tr>
  1739. <td>
  1740. <table width=100%>
  1741. <tr class="listheading">
  1742. |;
  1743. for (@column_index) { print "$column_header{$_}\n" }
  1744. print qq|
  1745. </tr>
  1746. |;
  1747. foreach $ref (@{ $form->{ALL} }) {
  1748. $i++; $i %= 2;
  1749. print qq|
  1750. <tr valign=top class=listrow$i>
  1751. |;
  1752. $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>|;
  1753. for (@column_index) { print "$column_data{$_}\n" }
  1754. print qq|
  1755. </tr>
  1756. |;
  1757. }
  1758. print qq|
  1759. </table>
  1760. </td>
  1761. </tr>
  1762. <tr>
  1763. <td><hr size=3 noshade></td>
  1764. </tr>
  1765. </table>
  1766. <br>
  1767. <form method=post action=$form->{script}>
  1768. |;
  1769. $form->{type} = "warehouse";
  1770. $form->hide_form(qw(type callback path login sessionid));
  1771. print qq|
  1772. <button class="submit" type="submit" name="action" value="add_warehouse">|.$locale->text('Add Warehouse').qq|</button>|;
  1773. if ($form->{lynx}) {
  1774. require "bin/menu.pl";
  1775. &menubar;
  1776. }
  1777. print qq|
  1778. </form>
  1779. </body>
  1780. </html>
  1781. |;
  1782. }
  1783. sub warehouse_header {
  1784. $form->{title} = $locale->text("$form->{title} Warehouse");
  1785. # $locale->text('Add Warehouse')
  1786. # $locale->text('Edit Warehouse')
  1787. $form->{description} = $form->quote($form->{description});
  1788. if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
  1789. $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  1790. } else {
  1791. $description = qq|<input name=description size=60 value="$form->{description}">|;
  1792. }
  1793. $form->header;
  1794. print qq|
  1795. <body>
  1796. <form method=post action=$form->{script}>
  1797. <input type=hidden name=id value=$form->{id}>
  1798. <input type=hidden name=type value=warehouse>
  1799. <table width=100%>
  1800. <tr>
  1801. <th class=listtop colspan=2>$form->{title}</th>
  1802. </tr>
  1803. <tr height="5"></tr>
  1804. <tr>
  1805. <th align="right">|.$locale->text('Description').qq|</th>
  1806. <td>$description</td>
  1807. </tr>
  1808. <tr>
  1809. <td colspan=2><hr size=3 noshade></td>
  1810. </tr>
  1811. </table>
  1812. |;
  1813. }
  1814. sub save_warehouse {
  1815. $form->isblank("description", $locale->text('Description missing!'));
  1816. AM->save_warehouse(\%myconfig, \%$form);
  1817. $form->redirect($locale->text('Warehouse saved!'));
  1818. }
  1819. sub delete_warehouse {
  1820. AM->delete_warehouse(\%myconfig, \%$form);
  1821. $form->redirect($locale->text('Warehouse deleted!'));
  1822. }
  1823. sub yearend {
  1824. AM->earningsaccounts(\%myconfig, \%$form);
  1825. $chart = "";
  1826. for (@{ $form->{chart} }) { $chart .= "<option>$_->{accno}--$_->{description}" }
  1827. $form->{title} = $locale->text('Yearend');
  1828. $form->header;
  1829. print qq|
  1830. <body>
  1831. <form method=post action=$form->{script}>
  1832. <input type=hidden name=decimalplaces value=2>
  1833. <input type=hidden name=l_accno value=Y>
  1834. <table width=100%>
  1835. <tr>
  1836. <th class=listtop>$form->{title}</th>
  1837. </tr>
  1838. <tr height="5"></tr>
  1839. <tr>
  1840. <td>
  1841. <table>
  1842. <tr>
  1843. <th align="right">|.$locale->text('Yearend').qq|</th>
  1844. <td><input name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
  1845. </tr>
  1846. <tr>
  1847. <th align="right">|.$locale->text('Reference').qq|</th>
  1848. <td><input name=reference size=20 value="|.$locale->text('Yearend').qq|"></td>
  1849. </tr>
  1850. <tr>
  1851. <th align="right">|.$locale->text('Description').qq|</th>
  1852. <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
  1853. </tr>
  1854. <tr>
  1855. <th align="right">|.$locale->text('Retained Earnings').qq|</th>
  1856. <td><select name=accno>$chart</select></td>
  1857. </tr>
  1858. <tr>
  1859. <th align="right">|.$locale->text('Method').qq|</th>
  1860. <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>
  1861. </tr>
  1862. </table>
  1863. </td>
  1864. </tr>
  1865. </table>
  1866. <hr size=3 noshade>
  1867. <input type=hidden name=nextsub value=generate_yearend>
  1868. |;
  1869. $form->hide_form(qw(path login sessionid));
  1870. print qq|
  1871. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
  1872. }
  1873. sub generate_yearend {
  1874. $form->isblank("todate", $locale->text('Yearend date missing!'));
  1875. RP->yearend_statement(\%myconfig, \%$form);
  1876. $form->{transdate} = $form->{todate};
  1877. $earnings = 0;
  1878. $form->{rowcount} = 1;
  1879. foreach $key (keys %{ $form->{I} }) {
  1880. if ($form->{I}{$key}{charttype} eq "A") {
  1881. $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
  1882. $earnings += $form->{I}{$key}{this};
  1883. $form->{"accno_$form->{rowcount}"} = $key;
  1884. $form->{rowcount}++;
  1885. $ok = 1;
  1886. }
  1887. }
  1888. foreach $key (keys %{ $form->{E} }) {
  1889. if ($form->{E}{$key}{charttype} eq "A") {
  1890. $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
  1891. $earnings += $form->{E}{$key}{this};
  1892. $form->{"accno_$form->{rowcount}"} = $key;
  1893. $form->{rowcount}++;
  1894. $ok = 1;
  1895. }
  1896. }
  1897. if ($earnings > 0) {
  1898. $form->{"credit_$form->{rowcount}"} = $earnings;
  1899. $form->{"accno_$form->{rowcount}"} = $form->{accno}
  1900. } else {
  1901. $form->{"debit_$form->{rowcount}"} = $earnings * -1;
  1902. $form->{"accno_$form->{rowcount}"} = $form->{accno}
  1903. }
  1904. if ($ok) {
  1905. if (AM->post_yearend(\%myconfig, \%$form)) {
  1906. $form->redirect($locale->text('Yearend posted!'));
  1907. } else {
  1908. $form->error($locale->text('Yearend posting failed!'));
  1909. }
  1910. } else {
  1911. $form->error('Nothing to do!');
  1912. }
  1913. }
  1914. sub company_logo {
  1915. $myconfig{address} =~ s/\\n/<br>/g;
  1916. $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
  1917. $form->{stylesheet} = $myconfig{stylesheet};
  1918. $form->{title} = $locale->text('About');
  1919. # create the logo screen
  1920. $form->header;
  1921. print qq|
  1922. <body>
  1923. <pre>
  1924. </pre>
  1925. <center>
  1926. <a href="http://www.ledgersmb.org/" target="_blank"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  1927. <h1 class="login">|.$locale->text('Version').qq| $form->{version}</h1>
  1928. <p>
  1929. |.$locale->text('Licensed to').qq|
  1930. <p>
  1931. <b>
  1932. $myconfig{company}
  1933. <br>$myconfig{address}
  1934. </b>
  1935. <p>
  1936. <table border=0>
  1937. <tr>
  1938. <th align="right">|.$locale->text('User').qq|</th>
  1939. <td>$myconfig{name}</td>
  1940. </tr>
  1941. <tr>
  1942. <th align="right">|.$locale->text('Dataset').qq|</th>
  1943. <td>$myconfig{dbname}</td>
  1944. </tr>
  1945. <tr>
  1946. <th align="right">|.$locale->text('Database Host').qq|</th>
  1947. <td>$myconfig{dbhost}</td>
  1948. </tr>
  1949. </table>
  1950. </center>
  1951. </body>
  1952. </html>
  1953. |;
  1954. }
  1955. sub recurring_transactions {
  1956. # $locale->text('Day')
  1957. # $locale->text('Days')
  1958. # $locale->text('Month')
  1959. # $locale->text('Months')
  1960. # $locale->text('Week')
  1961. # $locale->text('Weeks')
  1962. # $locale->text('Year')
  1963. # $locale->text('Years')
  1964. $form->{stylesheet} = $myconfig{stylesheet};
  1965. $form->{title} = $locale->text('Recurring Transactions');
  1966. $column_header{id} = "";
  1967. AM->recurring_transactions(\%myconfig, \%$form);
  1968. $href = "$form->{script}?action=recurring_transactions";
  1969. for (qw(direction oldsort path login sessionid)) { $href .= qq|&$_=$form->{$_}| }
  1970. $form->sort_order();
  1971. # create the logo screen
  1972. $form->header;
  1973. @column_index = qw(ndx reference description);
  1974. push @column_index, qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
  1975. $column_header{reference} = qq|<th><a class="listheading" href="$href&sort=reference">|.$locale->text('Reference').q|</a></th>|;
  1976. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  1977. $column_header{id} = q|<th class="listheading">|.$locale->text('ID').q|</th>|;
  1978. $column_header{description} = q|<th class="listheading">|.$locale->text('Description').q|</th>|;
  1979. $column_header{nextdate} = qq|<th><a class="listheading" href="$href&sort=nextdate">|.$locale->text('Next').q|</a></th>|;
  1980. $column_header{enddate} = qq|<th><a class="listheading" href="$href&sort=enddate">|.$locale->text('Ends').q|</a></th>|;
  1981. $column_header{amount} = q|<th class="listheading">|.$locale->text('Amount').q|</th>|;
  1982. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  1983. $column_header{repeat} = q|<th class="listheading">|.$locale->text('Every').q|</th>|;
  1984. $column_header{howmany} = q|<th class="listheading">|.$locale->text('Times').q|</th>|;
  1985. $column_header{recurringemail} = q|<th class="listheading">|.$locale->text('E-mail').q|</th>|;
  1986. $column_header{recurringprint} = q|<th class="listheading">|.$locale->text('Print').q|</th>|;
  1987. print qq|
  1988. <body>
  1989. <form method=post action=$form->{script}>
  1990. <table width=100%>
  1991. <tr>
  1992. <th class=listtop>$form->{title}</th>
  1993. </tr>
  1994. <tr height="5"></tr>
  1995. <tr>
  1996. <td>
  1997. <table width=100%>
  1998. <tr class="listheading">
  1999. |;
  2000. for (@column_index) { print "\n$column_header{$_}" }
  2001. print qq|
  2002. </tr>
  2003. |;
  2004. $i = 1;
  2005. $colspan = $#column_index + 1;
  2006. %tr = ( ar => $locale->text('AR'),
  2007. ap => $locale->text('AP'),
  2008. gl => $locale->text('GL'),
  2009. so => $locale->text('Sales Orders'),
  2010. po => $locale->text('Purchase Orders'),
  2011. );
  2012. %f = &formnames;
  2013. foreach $transaction (sort keys %{ $form->{transactions} }) {
  2014. print qq|
  2015. <tr>
  2016. <th class="listheading" colspan=$colspan>$tr{$transaction}</th>
  2017. </tr>
  2018. |;
  2019. foreach $ref (@{ $form->{transactions}{$transaction} }) {
  2020. for (@column_index) { $column_data{$_} = "<td nowrap>$ref->{$_}</td>" }
  2021. if ($ref->{repeat} > 1) {
  2022. $unit = $locale->text(ucfirst $ref->{unit});
  2023. $repeat = "$ref->{repeat} $unit";
  2024. } else {
  2025. chop $ref->{unit};
  2026. $unit = $locale->text(ucfirst $ref->{unit});
  2027. $repeat = $unit;
  2028. }
  2029. $column_data{ndx} = qq|<td></td>|;
  2030. if (!$ref->{expired}) {
  2031. if ($ref->{overdue} <= 0) {
  2032. $k++;
  2033. $column_data{ndx} = qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2034. }
  2035. }
  2036. $reference = ($ref->{reference}) ? $ref->{reference} : $locale->text('Next Number');
  2037. $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>|;
  2038. $module = "$ref->{module}.pl";
  2039. $type = "";
  2040. if ($ref->{module} eq 'ar') {
  2041. $module = "is.pl" if $ref->{invoice};
  2042. $ref->{amount} /= $ref->{exchangerate};
  2043. }
  2044. if ($ref->{module} eq 'ap') {
  2045. $module = "ir.pl" if $ref->{invoice};
  2046. $ref->{amount} /= $ref->{exchangerate};
  2047. }
  2048. if ($ref->{module} eq 'oe') {
  2049. $type = ($ref->{vc} eq 'customer') ? "sales_order" : "purchase_order";
  2050. }
  2051. $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>|;
  2052. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2053. $column_data{howmany} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{howmany})."</td>";
  2054. $column_data{amount} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{amount}, 2)."</td>";
  2055. $column_data{recurringemail} = "<td nowrap>";
  2056. @f = split /:/, $ref->{recurringemail};
  2057. for (0 .. $#f) { $column_data{recurringemail} .= "$f{$f[$_]}<br>" }
  2058. $column_data{recurringemail} .= "</td>";
  2059. $column_data{recurringprint} = "<td nowrap>";
  2060. @f = split /:/, $ref->{recurringprint};
  2061. for (0 .. $#f) { $column_data{recurringprint} .= "$f{$f[$_]}<br>" }
  2062. $column_data{recurringprint} .= "</td>";
  2063. $j++; $j %= 2;
  2064. print qq|
  2065. <tr class=listrow$j>
  2066. |;
  2067. for (@column_index) { print "\n$column_data{$_}" }
  2068. print qq|
  2069. </tr>
  2070. |;
  2071. }
  2072. }
  2073. print qq|
  2074. </tr>
  2075. </table>
  2076. </td>
  2077. </tr>
  2078. <tr>
  2079. <td><hr size=3 noshade></td>
  2080. </tr>
  2081. </table>
  2082. <input name=lastndx type=hidden value=$k>
  2083. |;
  2084. $form->hide_form(qw(path login sessionid));
  2085. print qq|
  2086. <button class="submit" type="submit" name="action" value="process_transactions">|.$locale->text('Process Transactions').qq|</button>| if $k;
  2087. if ($form->{lynx}) {
  2088. require "bin/menu.pl";
  2089. &menubar;
  2090. }
  2091. print qq|
  2092. </form>
  2093. </body>
  2094. </html>
  2095. |;
  2096. }
  2097. sub edit_recurring {
  2098. %links = ( ar => 'create_links',
  2099. ap => 'create_links',
  2100. gl => 'create_links',
  2101. is => 'invoice_links',
  2102. ir => 'invoice_links',
  2103. oe => 'order_links',
  2104. );
  2105. %prepare = ( is => 'prepare_invoice',
  2106. ir => 'prepare_invoice',
  2107. oe => 'prepare_order',
  2108. );
  2109. $form->{callback} = "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2110. $form->{type} = "transaction";
  2111. if ($form->{module} eq 'ar') {
  2112. if ($form->{invoice}) {
  2113. $form->{type} = "invoice";
  2114. $form->{module} = "is";
  2115. }
  2116. }
  2117. if ($form->{module} eq 'ap') {
  2118. if ($form->{invoice}) {
  2119. $form->{type} = "invoice";
  2120. $form->{module} = "ir";
  2121. }
  2122. }
  2123. if ($form->{module} eq 'oe') {
  2124. %tr = ( so => sales_order,
  2125. po => purchase_order,
  2126. );
  2127. $form->{type} = $tr{$form->{transaction}};
  2128. }
  2129. $form->{script} = "$form->{module}.pl";
  2130. do "bin/$form->{script}";
  2131. &{ $links{$form->{module}} };
  2132. # return if transaction doesn't exist
  2133. $form->redirect unless $form->{recurring};
  2134. if ($prepare{$form->{module}}) {
  2135. &{ $prepare{$form->{module}} };
  2136. }
  2137. $form->{selectformat} = qq|<option value="html">html\n|;
  2138. if (${LedgerSMB::Sysconfig::latex}) {
  2139. $form->{selectformat} .= qq|
  2140. <option value="postscript">|.$locale->text('Postscript').qq|
  2141. <option value="pdf">|.$locale->text('PDF');
  2142. }
  2143. &schedule;
  2144. }
  2145. sub process_transactions {
  2146. # save variables
  2147. my $pt = new Form;
  2148. for (keys %$form) { $pt->{$_} = $form->{$_} }
  2149. my $defaultprinter;
  2150. while (my ($key, $value) = each %{LedgerSMB::Sysconfig::printer}) {
  2151. if ($value =~ /lpr/) {
  2152. $defaultprinter = $key;
  2153. last;
  2154. }
  2155. }
  2156. $myconfig{vclimit} = 0;
  2157. %f = &formnames;
  2158. for (my $i = 1; $i <= $pt->{lastndx}; $i++) {
  2159. if ($pt->{"ndx_$i"}) {
  2160. $id = $pt->{"ndx_$i"};
  2161. # process transaction
  2162. AM->recurring_details(\%myconfig, \%$pt, $id);
  2163. $header = $form->{header};
  2164. # reset $form
  2165. for (keys %$form) { delete $form->{$_}; }
  2166. for (qw(login path sessionid stylesheet timeout)) { $form->{$_} = $pt->{$_}; }
  2167. $form->{id} = $id;
  2168. $form->{header} = $header;
  2169. # post, print, email
  2170. if ($pt->{arid} || $pt->{apid} || $pt->{oeid}) {
  2171. if ($pt->{arid} || $pt->{apid}) {
  2172. if ($pt->{arid}) {
  2173. $form->{script} = ($pt->{invoice}) ? "is.pl" : "ar.pl";
  2174. $form->{ARAP} = "AR";
  2175. $form->{module} = "ar";
  2176. $invfld = "sinumber";
  2177. } else {
  2178. $form->{script} = ($pt->{invoice}) ? "ir.pl" : "ap.pl";
  2179. $form->{ARAP} = "AP";
  2180. $form->{module} = "ap";
  2181. $invfld = "vinumber";
  2182. }
  2183. do "bin/$form->{script}";
  2184. if ($pt->{invoice}) {
  2185. &invoice_links;
  2186. &prepare_invoice;
  2187. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  2188. } else {
  2189. &create_links;
  2190. $form->{type} = "transaction";
  2191. for (1 .. $form->{rowcount} - 1) { $form->{"amount_$_"} = $form->format_amount(\%myconfig, $form->{"amount_$_"}, 2) }
  2192. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, 2) }
  2193. }
  2194. delete $form->{"$form->{ARAP}_links"};
  2195. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  2196. for (qw(department employee language month partsgroup project years)) { delete $form->{"all_$_"} }
  2197. $form->{invnumber} = $pt->{reference};
  2198. $form->{transdate} = $pt->{nextdate};
  2199. # tax accounts
  2200. $form->all_taxaccounts(\%myconfig, undef, $form->{transdate});
  2201. # calculate duedate
  2202. $form->{duedate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{overdue}, "days");
  2203. if ($pt->{payment}) {
  2204. # calculate date paid
  2205. for ($j = 1; $j <= $form->{paidaccounts}; $j++) {
  2206. $form->{"datepaid_$j"} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{paid}, "days");
  2207. ($form->{"$form->{ARAP}_paid_$j"}) = split /--/, $form->{"$form->{ARAP}_paid_$j"};
  2208. delete $form->{"cleared_$j"};
  2209. }
  2210. $form->{paidaccounts}++;
  2211. } else {
  2212. $form->{paidaccounts} = -1;
  2213. }
  2214. for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
  2215. ($form->{$form->{ARAP}}) = split /--/, $form->{$form->{ARAP}};
  2216. $form->{invnumber} = $form->update_defaults(\%myconfig, "$invfld") unless $form->{invnumber};
  2217. $form->{reference} = $form->{invnumber};
  2218. for (qw(invnumber reference)) { $form->{$_} = $form->unquote($form->{$_}) }
  2219. if ($pt->{invoice}) {
  2220. if ($pt->{arid}) {
  2221. $form->info("\n".$locale->text('Posting')." ".$locale->text('Sales Invoice')." $form->{invnumber}");
  2222. $ok = IS->post_invoice(\%myconfig, \%$form);
  2223. } else {
  2224. $form->info("\n".$locale->text('Posting')." ".$locale->text('Vendor Invoice')." $form->{invnumber}");
  2225. $ok = IR->post_invoice(\%myconfig, \%$form);
  2226. }
  2227. } else {
  2228. if ($pt->{arid}) {
  2229. $form->info("\n".$locale->text('Posting')." ".$locale->text('Transaction')." $form->{invnumber}");
  2230. } else {
  2231. $form->info("\n".$locale->text('Posting')." ".$locale->text('Transaction')." $form->{invnumber}");
  2232. }
  2233. $ok = AA->post_transaction(\%myconfig, \%$form);
  2234. }
  2235. $form->info(" ..... ".$locale->text('done'));
  2236. # print form
  2237. if (${LedgerSMB::Sysconfig::latex} && $ok) {
  2238. $ok = &print_recurring(\%$pt, $defaultprinter);
  2239. }
  2240. &email_recurring(\%$pt) if $ok;
  2241. } else {
  2242. # order
  2243. $form->{script} = "oe.pl";
  2244. $form->{module} = "oe";
  2245. $ordnumber = "ordnumber";
  2246. if ($pt->{customer_id}) {
  2247. $form->{vc} = "customer";
  2248. $form->{type} = "sales_order";
  2249. $ordfld = "sonumber";
  2250. $flabel = $locale->text('Sales Order');
  2251. } else {
  2252. $form->{vc} = "vendor";
  2253. $form->{type} = "purchase_order";
  2254. $ordfld = "ponumber";
  2255. $flabel = $locale->text('Purchase Order');
  2256. }
  2257. require "bin/$form->{script}";
  2258. &order_links;
  2259. &prepare_order;
  2260. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  2261. $form->{$ordnumber} = $pt->{reference};
  2262. $form->{transdate} = $pt->{nextdate};
  2263. # calculate reqdate
  2264. $form->{reqdate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{req}, "days") if $form->{reqdate};
  2265. for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
  2266. for (1 .. $form->{rowcount}) { delete $form->{"orderitems_id_$_"} }
  2267. $form->{$ordnumber} = $form->update_defaults(\%myconfig, "$ordfld") unless $form->{$ordnumber};
  2268. $form->{reference} = $form->{$ordnumber};
  2269. for ("$ordnumber", "reference") { $form->{$_} = $form->unquote($form->{$_}) }
  2270. $form->{closed} = 0;
  2271. $form->info("\n".$locale->text('Saving')." ".$flabel." $form->{$ordnumber}");
  2272. if ($ok = OE->save(\%myconfig, \%$form)) {
  2273. $form->info(" ..... ".$locale->text('done'));
  2274. } else {
  2275. $form->info(" ..... ".$locale->text('failed'));
  2276. }
  2277. # print form
  2278. if (${LedgerSMB::Sysconfig::latex} && $ok) {
  2279. &print_recurring(\%$pt, $defaultprinter);
  2280. }
  2281. &email_recurring(\%$pt);
  2282. }
  2283. } else {
  2284. # GL transaction
  2285. GL->transaction(\%myconfig, \%$form);
  2286. $form->{reference} = $pt->{reference};
  2287. $form->{transdate} = $pt->{nextdate};
  2288. $j = 1;
  2289. foreach $ref (@{ $form->{GL} }) {
  2290. $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
  2291. $form->{"projectnumber_$j"} = "$ref->{projectnumber}--$ref->{project_id}" if $ref->{project_id};
  2292. $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
  2293. if ($ref->{amount} < 0) {
  2294. $form->{"debit_$j"} = $ref->{amount} * -1;
  2295. } else {
  2296. $form->{"credit_$j"} = $ref->{amount};
  2297. }
  2298. $j++;
  2299. }
  2300. $form->{rowcount} = $j;
  2301. for (qw(id recurring)) { delete $form->{$_} }
  2302. $form->info("\n".$locale->text('Posting')." ".$locale->text('GL Transaction')." $form->{reference}");
  2303. $ok = GL->post_transaction(\%myconfig, \%$form);
  2304. $form->info(" ..... ".$locale->text('done'));
  2305. }
  2306. AM->update_recurring(\%myconfig, \%$pt, $id) if $ok;
  2307. }
  2308. }
  2309. $form->{callback} = "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
  2310. $form->redirect;
  2311. }
  2312. sub print_recurring {
  2313. my ($pt, $defaultprinter) = @_;
  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. $ok = !(system(@a));
  2326. if ($ok) {
  2327. $form->info(" ..... ".$locale->text('done'));
  2328. } else {
  2329. $form->info(" ..... ".$locale->text('failed'));
  2330. last;
  2331. }
  2332. }
  2333. }
  2334. $ok;
  2335. }
  2336. sub email_recurring {
  2337. my ($pt) = @_;
  2338. my %f = &formnames;
  2339. my $ok = 1;
  2340. if ($pt->{recurringemail}) {
  2341. @f = split /:/, $pt->{recurringemail};
  2342. for ($j = 0; $j <= $#f; $j += 2) {
  2343. $form->info("\n".$locale->text('Sending')." ".$locale->text($f{$f[$j]})." $form->{reference}");
  2344. # no email, bail out
  2345. if (!$form->{email}) {
  2346. $form->info(" ..... ".$locale->text('E-mail address missing!'));
  2347. last;
  2348. }
  2349. $message = $form->escape($pt->{message},1);
  2350. @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");
  2351. $ok = !(system(@a));
  2352. if ($ok) {
  2353. $form->info(" ..... ".$locale->text('done'));
  2354. } else {
  2355. $form->info(" ..... ".$locale->text('failed'));
  2356. last;
  2357. }
  2358. }
  2359. }
  2360. $ok;
  2361. }
  2362. sub formnames {
  2363. # $locale->text('Transaction')
  2364. # $locale->text('Invoice')
  2365. # $locale->text('Credit Invoice')
  2366. # $locale->text('Debit Invoice')
  2367. # $locale->text('Packing List')
  2368. # $locale->text('Pick List')
  2369. # $locale->text('Sales Order')
  2370. # $locale->text('Work Order')
  2371. # $locale->text('Purchase Order')
  2372. # $locale->text('Bin List')
  2373. my %f = ( transaction => 'Transaction',
  2374. invoice => 'Invoice',
  2375. credit_invoice => 'Credit Invoice',
  2376. debit_invoice => 'Debit Invoice',
  2377. packing_list => 'Packing List',
  2378. pick_list => 'Pick List',
  2379. sales_order => 'Sales Order',
  2380. work_order => 'Work Order',
  2381. purchase_order => 'Purchase Order',
  2382. bin_list => 'Bin List',
  2383. );
  2384. %f;
  2385. }
  2386. sub continue { &{ $form->{nextsub} } };