summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: 2279a66a8d80cf6141ab08896e0c16630c7f170a (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>
  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. $msg .= "<p>";
  1990. if ( $form->{removeaudittrail} ) {
  1991. $msg .=
  1992. $locale->text('Audit trail removed up to') . " "
  1993. . $locale->date( \%myconfig, $form->{removeaudittrail}, 1 );
  1994. }
  1995. $form->redirect($msg);
  1996. }
  1997. sub add_warehouse {
  1998. $form->{title} = "Add";
  1999. $form->{callback} =
  2000. "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  2001. unless $form->{callback};
  2002. &warehouse_header;
  2003. &form_footer;
  2004. }
  2005. sub edit_warehouse {
  2006. $form->{title} = "Edit";
  2007. AM->get_warehouse( \%myconfig, \%$form );
  2008. &warehouse_header;
  2009. &form_footer;
  2010. }
  2011. sub list_warehouse {
  2012. AM->warehouses( \%myconfig, \%$form );
  2013. $href =
  2014. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2015. $form->sort_order();
  2016. $form->{callback} =
  2017. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2018. $callback = $form->escape( $form->{callback} );
  2019. $form->{title} = $locale->text('Warehouses');
  2020. @column_index = qw(description);
  2021. $column_header{description} =
  2022. qq|<th width=100%><a class="listheading" href=$href>|
  2023. . $locale->text('Description')
  2024. . qq|</a></th>|;
  2025. $form->header;
  2026. print qq|
  2027. <body>
  2028. <table width=100%>
  2029. <tr>
  2030. <th class=listtop>$form->{title}</th>
  2031. </tr>
  2032. <tr height="5"></tr>
  2033. <tr>
  2034. <td>
  2035. <table width=100%>
  2036. <tr class="listheading">
  2037. |;
  2038. for (@column_index) { print "$column_header{$_}\n" }
  2039. print qq|
  2040. </tr>
  2041. |;
  2042. foreach $ref ( @{ $form->{ALL} } ) {
  2043. $i++;
  2044. $i %= 2;
  2045. print qq|
  2046. <tr valign=top class=listrow$i>
  2047. |;
  2048. $column_data{description} =
  2049. 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>|;
  2050. for (@column_index) { print "$column_data{$_}\n" }
  2051. print qq|
  2052. </tr>
  2053. |;
  2054. }
  2055. print qq|
  2056. </table>
  2057. </td>
  2058. </tr>
  2059. <tr>
  2060. <td><hr size=3 noshade></td>
  2061. </tr>
  2062. </table>
  2063. <br>
  2064. <form method=post action=$form->{script}>
  2065. |;
  2066. $form->{type} = "warehouse";
  2067. $form->hide_form(qw(type callback path login sessionid));
  2068. print qq|
  2069. <button class="submit" type="submit" name="action" value="add_warehouse">|
  2070. . $locale->text('Add Warehouse')
  2071. . qq|</button>|;
  2072. if ( $form->{lynx} ) {
  2073. require "bin/menu.pl";
  2074. &menubar;
  2075. }
  2076. print qq|
  2077. </form>
  2078. </body>
  2079. </html>
  2080. |;
  2081. }
  2082. sub warehouse_header {
  2083. $form->{title} = $locale->text("$form->{title} Warehouse");
  2084. # $locale->text('Add Warehouse')
  2085. # $locale->text('Edit Warehouse')
  2086. $form->{description} = $form->quote( $form->{description} );
  2087. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  2088. $description =
  2089. qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  2090. }
  2091. else {
  2092. $description =
  2093. qq|<input name=description size=60 value="$form->{description}">|;
  2094. }
  2095. $form->header;
  2096. print qq|
  2097. <body>
  2098. <form method=post action=$form->{script}>
  2099. <input type=hidden name=id value=$form->{id}>
  2100. <input type=hidden name=type value=warehouse>
  2101. <table width=100%>
  2102. <tr>
  2103. <th class=listtop colspan=2>$form->{title}</th>
  2104. </tr>
  2105. <tr height="5"></tr>
  2106. <tr>
  2107. <th align="right">| . $locale->text('Description') . qq|</th>
  2108. <td>$description</td>
  2109. </tr>
  2110. <tr>
  2111. <td colspan=2><hr size=3 noshade></td>
  2112. </tr>
  2113. </table>
  2114. |;
  2115. }
  2116. sub save_warehouse {
  2117. $form->isblank( "description", $locale->text('Description missing!') );
  2118. AM->save_warehouse( \%myconfig, \%$form );
  2119. $form->redirect( $locale->text('Warehouse saved!') );
  2120. }
  2121. sub delete_warehouse {
  2122. AM->delete_warehouse( \%myconfig, \%$form );
  2123. $form->redirect( $locale->text('Warehouse deleted!') );
  2124. }
  2125. sub yearend {
  2126. AM->earningsaccounts( \%myconfig, \%$form );
  2127. $chart = "";
  2128. for ( @{ $form->{chart} } ) {
  2129. $chart .= "<option>$_->{accno}--$_->{description}";
  2130. }
  2131. $form->{title} = $locale->text('Yearend');
  2132. $form->header;
  2133. print qq|
  2134. <body>
  2135. <form method=post action=$form->{script}>
  2136. <input type=hidden name=decimalplaces value=2>
  2137. <input type=hidden name=l_accno value=Y>
  2138. <table width=100%>
  2139. <tr>
  2140. <th class=listtop>$form->{title}</th>
  2141. </tr>
  2142. <tr height="5"></tr>
  2143. <tr>
  2144. <td>
  2145. <table>
  2146. <tr>
  2147. <th align="right">| . $locale->text('Yearend') . qq|</th>
  2148. <td><input name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
  2149. </tr>
  2150. <tr>
  2151. <th align="right">| . $locale->text('Reference') . qq|</th>
  2152. <td><input name=reference size=20 value="|
  2153. . $locale->text('Yearend')
  2154. . qq|"></td>
  2155. </tr>
  2156. <tr>
  2157. <th align="right">| . $locale->text('Description') . qq|</th>
  2158. <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
  2159. </tr>
  2160. <tr>
  2161. <th align="right">| . $locale->text('Retained Earnings') . qq|</th>
  2162. <td><select name=accno>$chart</select></td>
  2163. </tr>
  2164. <tr>
  2165. <th align="right">| . $locale->text('Method') . qq|</th>
  2166. <td><input name=method class=radio type=radio value=accrual checked>&nbsp;|
  2167. . $locale->text('Accrual')
  2168. . qq|&nbsp;<input name=method class=radio type=radio value=cash>&nbsp;|
  2169. . $locale->text('Cash')
  2170. . qq|</td>
  2171. </tr>
  2172. </table>
  2173. </td>
  2174. </tr>
  2175. </table>
  2176. <hr size=3 noshade>
  2177. <input type=hidden name=nextsub value=generate_yearend>
  2178. |;
  2179. $form->hide_form(qw(path login sessionid));
  2180. print qq|
  2181. <button class="submit" type="submit" name="action" value="continue">|
  2182. . $locale->text('Continue')
  2183. . qq|</button>|;
  2184. }
  2185. sub generate_yearend {
  2186. $form->isblank( "todate", $locale->text('Yearend date missing!') );
  2187. RP->yearend_statement( \%myconfig, \%$form );
  2188. $form->{transdate} = $form->{todate};
  2189. $earnings = 0;
  2190. $form->{rowcount} = 1;
  2191. foreach $key ( keys %{ $form->{I} } ) {
  2192. if ( $form->{I}{$key}{charttype} eq "A" ) {
  2193. $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
  2194. $earnings += $form->{I}{$key}{this};
  2195. $form->{"accno_$form->{rowcount}"} = $key;
  2196. $form->{rowcount}++;
  2197. $ok = 1;
  2198. }
  2199. }
  2200. foreach $key ( keys %{ $form->{E} } ) {
  2201. if ( $form->{E}{$key}{charttype} eq "A" ) {
  2202. $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
  2203. $earnings += $form->{E}{$key}{this};
  2204. $form->{"accno_$form->{rowcount}"} = $key;
  2205. $form->{rowcount}++;
  2206. $ok = 1;
  2207. }
  2208. }
  2209. if ( $earnings > 0 ) {
  2210. $form->{"credit_$form->{rowcount}"} = $earnings;
  2211. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  2212. }
  2213. else {
  2214. $form->{"debit_$form->{rowcount}"} = $earnings * -1;
  2215. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  2216. }
  2217. if ($ok) {
  2218. if ( AM->post_yearend( \%myconfig, \%$form ) ) {
  2219. $form->redirect( $locale->text('Yearend posted!') );
  2220. }
  2221. else {
  2222. $form->error( $locale->text('Yearend posting failed!') );
  2223. }
  2224. }
  2225. else {
  2226. $form->error('Nothing to do!');
  2227. }
  2228. }
  2229. sub company_logo {
  2230. $myconfig{address} =~ s/\\n/<br>/g;
  2231. $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
  2232. $form->{stylesheet} = $myconfig{stylesheet};
  2233. $form->{title} = $locale->text('About');
  2234. # create the logo screen
  2235. $form->header;
  2236. print qq|
  2237. <body>
  2238. <pre>
  2239. </pre>
  2240. <center>
  2241. <a href="http://www.ledgersmb.org/" target="_blank"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  2242. <h1 class="login">| . $locale->text('Version') . qq| $form->{version}</h1>
  2243. <p>
  2244. | . $locale->text('Company') . qq| :
  2245. <p>
  2246. <b>
  2247. $myconfig{company}
  2248. <br>$myconfig{address}
  2249. </b>
  2250. <p>
  2251. <table border=0>
  2252. <tr>
  2253. <th align="right">| . $locale->text('User') . qq|</th>
  2254. <td>$myconfig{name}</td>
  2255. </tr>
  2256. <tr>
  2257. <th align="right">| . $locale->text('Dataset') . qq|</th>
  2258. <td>$myconfig{dbname}</td>
  2259. </tr>
  2260. <tr>
  2261. <th align="right">| . $locale->text('Database Host') . qq|</th>
  2262. <td>$myconfig{dbhost}</td>
  2263. </tr>
  2264. </table>
  2265. </center>
  2266. </body>
  2267. </html>
  2268. |;
  2269. }
  2270. sub recurring_transactions {
  2271. # $locale->text('Day')
  2272. # $locale->text('Days')
  2273. # $locale->text('Month')
  2274. # $locale->text('Months')
  2275. # $locale->text('Week')
  2276. # $locale->text('Weeks')
  2277. # $locale->text('Year')
  2278. # $locale->text('Years')
  2279. $form->{stylesheet} = $myconfig{stylesheet};
  2280. $form->{title} = $locale->text('Recurring Transactions');
  2281. $column_header{id} = "";
  2282. AM->recurring_transactions( \%myconfig, \%$form );
  2283. $href = "$form->{script}?action=recurring_transactions";
  2284. for (qw(direction oldsort path login sessionid)) {
  2285. $href .= qq|&$_=$form->{$_}|;
  2286. }
  2287. $form->sort_order();
  2288. # create the logo screen
  2289. $form->header;
  2290. @column_index = qw(ndx reference description);
  2291. push @column_index,
  2292. qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
  2293. $column_header{reference} =
  2294. qq|<th><a class="listheading" href="$href&sort=reference">|
  2295. . $locale->text('Reference')
  2296. . q|</a></th>|;
  2297. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  2298. $column_header{id} =
  2299. q|<th class="listheading">| . $locale->text('ID') . q|</th>|;
  2300. $column_header{description} =
  2301. q|<th class="listheading">| . $locale->text('Description') . q|</th>|;
  2302. $column_header{nextdate} =
  2303. qq|<th><a class="listheading" href="$href&sort=nextdate">|
  2304. . $locale->text('Next')
  2305. . q|</a></th>|;
  2306. $column_header{enddate} =
  2307. qq|<th><a class="listheading" href="$href&sort=enddate">|
  2308. . $locale->text('Ends')
  2309. . q|</a></th>|;
  2310. $column_header{amount} =
  2311. q|<th class="listheading">| . $locale->text('Amount') . q|</th>|;
  2312. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  2313. $column_header{repeat} =
  2314. q|<th class="listheading">| . $locale->text('Every') . q|</th>|;
  2315. $column_header{howmany} =
  2316. q|<th class="listheading">| . $locale->text('Times') . q|</th>|;
  2317. $column_header{recurringemail} =
  2318. q|<th class="listheading">| . $locale->text('E-mail') . q|</th>|;
  2319. $column_header{recurringprint} =
  2320. q|<th class="listheading">| . $locale->text('Print') . q|</th>|;
  2321. print qq|
  2322. <body>
  2323. <form method=post action=$form->{script}>
  2324. <table width=100%>
  2325. <tr>
  2326. <th class=listtop>$form->{title}</th>
  2327. </tr>
  2328. <tr height="5"></tr>
  2329. <tr>
  2330. <td>
  2331. <table width=100%>
  2332. <tr class="listheading">
  2333. |;
  2334. for (@column_index) { print "\n$column_header{$_}" }
  2335. print qq|
  2336. </tr>
  2337. |;
  2338. $i = 1;
  2339. $colspan = $#column_index + 1;
  2340. %tr = (
  2341. ar => $locale->text('AR'),
  2342. ap => $locale->text('AP'),
  2343. gl => $locale->text('GL'),
  2344. so => $locale->text('Sales Orders'),
  2345. po => $locale->text('Purchase Orders'),
  2346. );
  2347. %f = &formnames;
  2348. foreach $transaction ( sort keys %{ $form->{transactions} } ) {
  2349. print qq|
  2350. <tr>
  2351. <th class="listheading" colspan=$colspan>$tr{$transaction}</th>
  2352. </tr>
  2353. |;
  2354. foreach $ref ( @{ $form->{transactions}{$transaction} } ) {
  2355. for (@column_index) {
  2356. $column_data{$_} = "<td nowrap>$ref->{$_}</td>";
  2357. }
  2358. if ( $ref->{repeat} > 1 ) {
  2359. $unit = $locale->text( ucfirst $ref->{unit} );
  2360. $repeat = "$ref->{repeat} $unit";
  2361. }
  2362. else {
  2363. chop $ref->{unit};
  2364. $unit = $locale->text( ucfirst $ref->{unit} );
  2365. $repeat = $unit;
  2366. }
  2367. $column_data{ndx} = qq|<td></td>|;
  2368. if ( !$ref->{expired} ) {
  2369. if ( $ref->{overdue} <= 0 ) {
  2370. $k++;
  2371. $column_data{ndx} =
  2372. qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2373. }
  2374. }
  2375. $reference =
  2376. ( $ref->{reference} )
  2377. ? $ref->{reference}
  2378. : $locale->text('Next Number');
  2379. $column_data{reference} =
  2380. 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>|;
  2381. $module = "$ref->{module}.pl";
  2382. $type = "";
  2383. if ( $ref->{module} eq 'ar' ) {
  2384. $module = "is.pl" if $ref->{invoice};
  2385. $ref->{amount} /= $ref->{exchangerate};
  2386. }
  2387. if ( $ref->{module} eq 'ap' ) {
  2388. $module = "ir.pl" if $ref->{invoice};
  2389. $ref->{amount} /= $ref->{exchangerate};
  2390. }
  2391. if ( $ref->{module} eq 'oe' ) {
  2392. $type =
  2393. ( $ref->{vc} eq 'customer' )
  2394. ? "sales_order"
  2395. : "purchase_order";
  2396. }
  2397. $column_data{id} =
  2398. 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>|;
  2399. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2400. $column_data{howmany} =
  2401. qq|<td align="right" nowrap>|
  2402. . $form->format_amount( \%myconfig, $ref->{howmany} ) . "</td>";
  2403. $column_data{amount} =
  2404. qq|<td align="right" nowrap>|
  2405. . $form->format_amount( \%myconfig, $ref->{amount}, 2 ) . "</td>";
  2406. $column_data{recurringemail} = "<td nowrap>";
  2407. @f = split /:/, $ref->{recurringemail};
  2408. for ( 0 .. $#f ) {
  2409. $column_data{recurringemail} .= "$f{$f[$_]}<br>";
  2410. }
  2411. $column_data{recurringemail} .= "</td>";
  2412. $column_data{recurringprint} = "<td nowrap>";
  2413. @f = split /:/, $ref->{recurringprint};
  2414. for ( 0 .. $#f ) {
  2415. $column_data{recurringprint} .= "$f{$f[$_]}<br>";
  2416. }
  2417. $column_data{recurringprint} .= "</td>";
  2418. $j++;
  2419. $j %= 2;
  2420. print qq|
  2421. <tr class=listrow$j>
  2422. |;
  2423. for (@column_index) { print "\n$column_data{$_}" }
  2424. print qq|
  2425. </tr>
  2426. |;
  2427. }
  2428. }
  2429. print qq|
  2430. </tr>
  2431. </table>
  2432. </td>
  2433. </tr>
  2434. <tr>
  2435. <td><hr size=3 noshade></td>
  2436. </tr>
  2437. </table>
  2438. <input name=lastndx type=hidden value=$k>
  2439. |;
  2440. $form->hide_form(qw(path login sessionid));
  2441. print qq|
  2442. <button class="submit" type="submit" name="action" value="process_transactions">|
  2443. . $locale->text('Process Transactions')
  2444. . qq|</button>|
  2445. if $k;
  2446. if ( $form->{lynx} ) {
  2447. require "bin/menu.pl";
  2448. &menubar;
  2449. }
  2450. print qq|
  2451. </form>
  2452. </body>
  2453. </html>
  2454. |;
  2455. }
  2456. sub edit_recurring {
  2457. %links = (
  2458. ar => 'create_links',
  2459. ap => 'create_links',
  2460. gl => 'create_links',
  2461. is => 'invoice_links',
  2462. ir => 'invoice_links',
  2463. oe => 'order_links',
  2464. );
  2465. %prepare = (
  2466. is => 'prepare_invoice',
  2467. ir => 'prepare_invoice',
  2468. oe => 'prepare_order',
  2469. );
  2470. $form->{callback} =
  2471. "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2472. $form->{type} = "transaction";
  2473. if ( $form->{module} eq 'ar' ) {
  2474. if ( $form->{invoice} ) {
  2475. $form->{type} = "invoice";
  2476. $form->{module} = "is";
  2477. }
  2478. }
  2479. if ( $form->{module} eq 'ap' ) {
  2480. if ( $form->{invoice} ) {
  2481. $form->{type} = "invoice";
  2482. $form->{module} = "ir";
  2483. }
  2484. }
  2485. if ( $form->{module} eq 'oe' ) {
  2486. %tr = (
  2487. so => sales_order,
  2488. po => purchase_order,
  2489. );
  2490. $form->{type} = $tr{ $form->{transaction} };
  2491. }
  2492. $form->{script} = "$form->{module}.pl";
  2493. do "bin/$form->{script}";
  2494. &{ $links{ $form->{module} } };
  2495. # return if transaction doesn't exist
  2496. $form->redirect unless $form->{recurring};
  2497. if ( $prepare{ $form->{module} } ) {
  2498. &{ $prepare{ $form->{module} } };
  2499. }
  2500. $form->{selectformat} = qq|<option value="html">html\n|;
  2501. if ( ${LedgerSMB::Sysconfig::latex} ) {
  2502. $form->{selectformat} .= qq|
  2503. <option value="postscript">| . $locale->text('Postscript') . qq|
  2504. <option value="pdf">| . $locale->text('PDF');
  2505. }
  2506. &schedule;
  2507. }
  2508. sub process_transactions {
  2509. # save variables
  2510. my $pt = new Form;
  2511. for ( keys %$form ) { $pt->{$_} = $form->{$_} }
  2512. my $defaultprinter;
  2513. while ( my ( $key, $value ) = each %{LedgerSMB::Sysconfig::printer} ) {
  2514. if ( $value =~ /lpr/ ) {
  2515. $defaultprinter = $key;
  2516. last;
  2517. }
  2518. }
  2519. $myconfig{vclimit} = 0;
  2520. %f = &formnames;
  2521. for ( my $i = 1 ; $i <= $pt->{lastndx} ; $i++ ) {
  2522. if ( $pt->{"ndx_$i"} ) {
  2523. $id = $pt->{"ndx_$i"};
  2524. # process transaction
  2525. AM->recurring_details( \%myconfig, \%$pt, $id );
  2526. $header = $form->{header};
  2527. # reset $form
  2528. for ( keys %$form ) { delete $form->{$_}; }
  2529. for (qw(login path sessionid stylesheet timeout)) {
  2530. $form->{$_} = $pt->{$_};
  2531. }
  2532. $form->{id} = $id;
  2533. $form->{header} = $header;
  2534. $form->db_init(\%myconfig);
  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. my $orig_callback = $form->{callback};
  2778. @f = split /:/, $pt->{recurringprint};
  2779. for ( $j = 0 ; $j <= $#f ; $j += 3 ) {
  2780. $media = $f[ $j + 2 ];
  2781. $media ||= $myconfig->{printer}
  2782. if ${LedgerSMB::Sysconfig::printer}{ $myconfig->{printer} };
  2783. $media ||= $defaultprinter;
  2784. $form->info( "\n"
  2785. . $locale->text('Printing') . " "
  2786. . $locale->text( $f{ $f[$j] } )
  2787. . " $form->{reference}" );
  2788. $form->error( $locale->text('Invalid redirect') )
  2789. unless first { $_ eq $form->{script} }
  2790. @{LedgerSMB::Sysconfig::scripts};
  2791. $form->{callback} = "$form->{script}?action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=$media&vc=$form->{vc}&ARAP=$form->{ARAP}";
  2792. $ok = !(main::redirect());
  2793. if ($ok) {
  2794. $form->info( " ..... " . $locale->text('done') );
  2795. }
  2796. else {
  2797. $form->info( " ..... " . $locale->text('failed') );
  2798. last;
  2799. }
  2800. }
  2801. $form->{callback} = $orig_callback;
  2802. }
  2803. $ok;
  2804. }
  2805. sub email_recurring {
  2806. my ($pt) = @_;
  2807. use List::Util qw(first);
  2808. my %f = &formnames;
  2809. my $ok = 1;
  2810. if ( $pt->{recurringemail} ) {
  2811. @f = split /:/, $pt->{recurringemail};
  2812. my $orig_callback = $form->{callback};
  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. $form->error( $locale->text('Invalid redirect') )
  2826. unless first { $_ eq $form->{script} }
  2827. @{LedgerSMB::Sysconfig::scripts};
  2828. $form->{callback} = "$form->{script}?action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=email&vc=$form->{vc}&ARAP=$form->{ARAP}&message=$message";
  2829. $ok = !( main::redirect() );
  2830. if ($ok) {
  2831. $form->info( " ..... " . $locale->text('done') );
  2832. }
  2833. else {
  2834. $form->info( " ..... " . $locale->text('failed') );
  2835. last;
  2836. }
  2837. }
  2838. $form->{callback} = $orig_callback;
  2839. }
  2840. $ok;
  2841. }
  2842. sub formnames {
  2843. # $locale->text('Transaction')
  2844. # $locale->text('Invoice')
  2845. # $locale->text('Credit Invoice')
  2846. # $locale->text('Debit Invoice')
  2847. # $locale->text('Packing List')
  2848. # $locale->text('Pick List')
  2849. # $locale->text('Sales Order')
  2850. # $locale->text('Work Order')
  2851. # $locale->text('Purchase Order')
  2852. # $locale->text('Bin List')
  2853. my %f = (
  2854. transaction => 'Transaction',
  2855. invoice => 'Invoice',
  2856. credit_invoice => 'Credit Invoice',
  2857. debit_invoice => 'Debit Invoice',
  2858. packing_list => 'Packing List',
  2859. pick_list => 'Pick List',
  2860. sales_order => 'Sales Order',
  2861. work_order => 'Work Order',
  2862. purchase_order => 'Purchase Order',
  2863. bin_list => 'Bin List',
  2864. );
  2865. %f;
  2866. }
  2867. sub continue { &{ $form->{nextsub} } }