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