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