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