summaryrefslogtreecommitdiff
path: root/bin/arapprn.pl
blob: 0d256c282bc9232cda91147bc626c70d83af154c (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://www.ledgersmb.org/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2003
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. #
  22. # This program is free software; you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation; either version 2 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. # You should have received a copy of the GNU General Public License
  32. # along with this program; if not, write to the Free Software
  33. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. #======================================================================
  35. #
  36. # This file has not undergone any whitespace cleanup.
  37. #
  38. # printing routines for ar, ap
  39. #
  40. use Error qw(:try);
  41. use LedgerSMB::Template;
  42. # any custom scripts for this one
  43. if ( -f "bin/custom/arapprn.pl" ) {
  44. eval { require "bin/custom/arapprn.pl"; };
  45. }
  46. if ( -f "bin/custom/$form->{login}_arapprn.pl" ) {
  47. eval { require "bin/custom/$form->{login}_arapprn.pl"; };
  48. }
  49. 1;
  50. # end of main
  51. sub print {
  52. if ( $form->{media} !~ /screen/ ) {
  53. $form->error( $locale->text('Select postscript or PDF!') )
  54. if $form->{format} !~ /(postscript|pdf)/;
  55. $old_form = new Form;
  56. for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
  57. }
  58. if ( $form->{formname} =~ /(check|receipt)/ ) {
  59. if ( $form->{media} eq 'screen' ) {
  60. $form->error( $locale->text('Select postscript or PDF!') )
  61. if $form->{format} !~ /(postscript|pdf)/;
  62. }
  63. }
  64. if ( !$form->{invnumber} ) {
  65. $invfld = 'sinumber';
  66. $invfld = 'vinumber' if $form->{ARAP} eq 'AP';
  67. $form->{invnumber} = $form->update_defaults( \%myconfig, $invfld );
  68. if ( $form->{media} eq 'screen' ) {
  69. if ( $form->{media} eq 'screen' ) {
  70. &update;
  71. exit;
  72. }
  73. }
  74. }
  75. if ( $form->{formname} =~ /(check|receipt)/ ) {
  76. if ( $form->{media} ne 'screen' ) {
  77. for (qw(action header)) { delete $form->{$_} }
  78. $form->{invtotal} = $form->{oldinvtotal};
  79. foreach $key ( keys %$form ) {
  80. $form->{$key} =~ s/&/%26/g;
  81. $form->{previousform} .= qq|$key=$form->{$key}&|;
  82. }
  83. chop $form->{previousform};
  84. $form->{previousform} = $form->escape( $form->{previousform}, 1 );
  85. }
  86. if ( $form->{paidaccounts} > 1 ) {
  87. if ( $form->{"paid_$form->{paidaccounts}"} ) {
  88. &update;
  89. exit;
  90. }
  91. elsif ( $form->{paidaccounts} > 2 ) {
  92. # select payment
  93. &select_payment;
  94. exit;
  95. }
  96. }
  97. else {
  98. $form->error( $locale->text('Nothing to print!') );
  99. }
  100. }
  101. if ( $filename = $queued{ $form->{formname} } ) {
  102. $form->{queued} =~ s/$form->{formname} $filename//;
  103. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  104. $filename =~ s/\..*$//g;
  105. }
  106. else {
  107. $filename = time;
  108. $filename .= $$;
  109. }
  110. $filename .= ( $form->{format} eq 'postscript' ) ? '.ps' : '.pdf';
  111. if ( $form->{media} ne 'screen' ) {
  112. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  113. $form{printmode} = '>';
  114. }
  115. $form->{queued} .= " $form->{formname} $filename";
  116. $form->{queued} =~ s/^ //;
  117. $printform = new Form;
  118. for ( keys %$form ) {
  119. $printform->{$_} = $form->{$_};
  120. }
  121. if ( $form->{printandpost} ) {
  122. &post;
  123. }
  124. else {
  125. &{"print_$form->{formname}"}( $old_form, 1 );
  126. }
  127. }
  128. sub print_check {
  129. my ( $old_form, $i ) = @_;
  130. $display_form =
  131. ( $form->{display_form} ) ? $form->{display_form} : "display_form";
  132. if ( $form->{"paid_$i"} ) {
  133. @a = ();
  134. if ( exists $form->{longformat} ) {
  135. $form->{"datepaid_$i"} =
  136. $locale->date( \%myconfig, $form->{"datepaid_$i"},
  137. $form->{longformat} );
  138. }
  139. push @a, "source_$i", "memo_$i";
  140. $form->format_string(@a);
  141. }
  142. $form->{amount} = $form->{"paid_$i"};
  143. if ( ( $form->{formname} eq 'check' && $form->{vc} eq 'customer' )
  144. || ( $form->{formname} eq 'receipt' && $form->{vc} eq 'vendor' ) )
  145. {
  146. $form->{amount} =~ s/-//g;
  147. }
  148. for (qw(datepaid source memo)) { $form->{$_} = $form->{"${_}_$i"} }
  149. &{"$form->{vc}_details"};
  150. @a = qw(name address1 address2 city state zipcode country);
  151. foreach $item (qw(invnumber ordnumber)) {
  152. $temp{$item} = $form->{$item};
  153. delete $form->{$item};
  154. push( @{ $form->{$item} }, $temp{$item} );
  155. }
  156. push( @{ $form->{invdate} }, $form->{transdate} );
  157. push(
  158. @{ $form->{due} },
  159. $form->format_amount( \%myconfig, $form->{oldinvtotal}, 2 )
  160. );
  161. push( @{ $form->{paid} }, $form->{"paid_$i"} );
  162. use LedgerSMB::CP;
  163. $c =
  164. CP->new( ( $form->{language_code} )
  165. ? $form->{language_code}
  166. : $myconfig{countrycode} );
  167. $c->init;
  168. ( $whole, $form->{decimal} ) = split /\./,
  169. $form->parse_amount( \%myconfig, $form->{amount} );
  170. $form->{decimal} .= "00";
  171. $form->{decimal} = substr( $form->{decimal}, 0, 2 );
  172. $form->{text_decimal} = $c->num2text( $form->{decimal} * 1 );
  173. $form->{text_amount} = $c->num2text($whole);
  174. $form->{integer_amount} = $form->format_amount( $myconfig, $whole );
  175. ( $form->{employee} ) = split /--/, $form->{employee};
  176. $form->{notes} =~ s/^\s+//g;
  177. push @a, "notes";
  178. for (qw(company address tel fax businessnumber)) {
  179. $form->{$_} = $myconfig{$_};
  180. }
  181. $form->{address} =~ s/\\n/\n/g;
  182. push @a,
  183. qw(company address tel fax businessnumber text_amount text_decimal);
  184. $form->format_string(@a);
  185. $form->{templates} = "$myconfig{templates}";
  186. $form->{IN} =
  187. ( $form->{formname} eq 'transaction' )
  188. ? lc $form->{ARAP} . "_$form->{formname}.html"
  189. : "$form->{formname}.html";
  190. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  191. $form->{IN} =~ s/html$/tex/;
  192. }
  193. if ( $form->{media} eq 'queue' ) {
  194. # save status
  195. $form->update_status( \%myconfig );
  196. $form->{queued} = $form->{queued};
  197. %audittrail = (
  198. tablename => ($order) ? 'oe' : lc $ARAP,
  199. reference => $form->{"${inv}number"},
  200. formname => $form->{formname},
  201. action => 'queued',
  202. id => $form->{id}
  203. );
  204. $form->{audittrail} .=
  205. $form->audittrail( "", \%myconfig, \%audittrail );
  206. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  207. $form->{printmode} = '>';
  208. $form->{queued} .= " $form->{formname} $filename";
  209. $form->{queued} =~ s/^ //;
  210. }
  211. if ( $form->{media} !~ /(screen|queue)/ ) {
  212. %queued = split / /, $form->{queued};
  213. $form->{OUT} = ${LedgerSMB::Sysconfig::printer}{ $form->{media} };
  214. $form->{printmode} = '|-';
  215. if ( $form->{printed} !~ /$form->{formname}/ ) {
  216. $form->{printed} .= " $form->{formname}";
  217. $form->{printed} =~ s/^ //;
  218. $form->update_status( \%myconfig );
  219. }
  220. %audittrail = (
  221. tablename => lc $form->{ARAP},
  222. reference => $form->{invnumber},
  223. formname => $form->{formname},
  224. action => 'printed',
  225. id => $form->{id}
  226. );
  227. %status = ();
  228. for (qw(printed audittrail)) { $status{$_} = $form->{$_} }
  229. $status{audittrail} .=
  230. $form->audittrail( "", \%myconfig, \%audittrail );
  231. }
  232. $form->{fileid} = $invnumber;
  233. $form->{fileid} =~ s/(\s|\W)+//g;
  234. if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
  235. {
  236. my $template =
  237. LedgerSMB::Template->new(
  238. user => \%myconfig, template => $form->{'formname'},
  239. format => 'HTML' );
  240. try {
  241. $template->render($form);
  242. $form->header;
  243. print $template->{'output'};
  244. exit;
  245. }
  246. catch Error::Simple with {
  247. my $E = shift;
  248. $form->error( $E->stacktrace );
  249. };
  250. }
  251. $form->parse_template( \%myconfig );
  252. if ( $form->{previousform} ) {
  253. $previousform = $form->unescape( $form->{previousform} );
  254. for ( keys %$form ) { delete $form->{$_} }
  255. foreach $item ( split /&/, $previousform ) {
  256. ( $key, $value ) = split /=/, $item, 2;
  257. $value =~ s/%26/&/g;
  258. $form->{$key} = $value;
  259. }
  260. for (qw(exchangerate creditlimit creditremaining)) {
  261. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  262. }
  263. for ( 1 .. $form->{rowcount} ) {
  264. $form->{"amount_$_"} =
  265. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  266. }
  267. for ( split / /, $form->{taxaccounts} ) {
  268. $form->{"tax_$_"} =
  269. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  270. }
  271. for $i ( 1 .. $form->{paidaccounts} ) {
  272. for (qw(paid exchangerate)) {
  273. $form->{"${_}_$i"} =
  274. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  275. }
  276. }
  277. for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
  278. &{"$display_form"};
  279. }
  280. }
  281. sub print_receipt {
  282. my ( $old_form, $i ) = @_;
  283. &print_check( $old_form, $i );
  284. }
  285. sub print_transaction {
  286. my ($old_form) = @_;
  287. $display_form =
  288. ( $form->{display_form} ) ? $form->{display_form} : "display_form";
  289. &{"$form->{vc}_details"};
  290. @a = qw(name address1 address2 city state zipcode country);
  291. $form->{invtotal} = 0;
  292. foreach $i ( 1 .. $form->{rowcount} - 1 ) {
  293. ( $form->{tempaccno}, $form->{tempaccount} ) = split /--/,
  294. $form->{"$form->{ARAP}_amount_$i"};
  295. ( $form->{tempprojectnumber} ) = split /--/,
  296. $form->{"projectnumber_$i"};
  297. $form->{tempdescription} = $form->{"description_$i"};
  298. $form->format_string(
  299. qw(tempaccno tempaccount tempprojectnumber tempdescription));
  300. push( @{ $form->{accno} }, $form->{tempaccno} );
  301. push( @{ $form->{account} }, $form->{tempaccount} );
  302. push( @{ $form->{description} }, $form->{tempdescription} );
  303. push( @{ $form->{projectnumber} }, $form->{tempprojectnumber} );
  304. push( @{ $form->{amount} }, $form->{"amount_$i"} );
  305. $form->{subtotal} +=
  306. $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
  307. }
  308. foreach $accno ( split / /, $form->{taxaccounts} ) {
  309. if ( $form->{"tax_$accno"} ) {
  310. $form->format_string("${accno}_description");
  311. $tax += $form->parse_amount( \%myconfig, $form->{"tax_$accno"} );
  312. $form->{"${accno}_tax"} = $form->{"tax_$accno"};
  313. push( @{ $form->{tax} }, $form->{"tax_$accno"} );
  314. push(
  315. @{ $form->{taxdescription} },
  316. $form->{"${accno}_description"}
  317. );
  318. $form->{"${accno}_taxrate"} =
  319. $form->format_amount( $myconfig, $form->{"${accno}_rate"} * 100 );
  320. push( @{ $form->{taxrate} }, $form->{"${accno}_taxrate"} );
  321. push( @{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"} );
  322. }
  323. }
  324. $tax = 0 if $form->{taxincluded};
  325. push @a, $form->{ARAP};
  326. $form->format_string(@a);
  327. $form->{paid} = 0;
  328. for $i ( 1 .. $form->{paidaccounts} - 1 ) {
  329. if ( $form->{"paid_$i"} ) {
  330. @a = ();
  331. $form->{paid} +=
  332. $form->parse_amount( \%myconfig, $form->{"paid_$i"} );
  333. if ( exists $form->{longformat} ) {
  334. $form->{"datepaid_$i"} =
  335. $locale->date( \%myconfig, $form->{"datepaid_$i"},
  336. $form->{longformat} );
  337. }
  338. push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
  339. $form->format_string(@a);
  340. ( $accno, $account ) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
  341. push( @{ $form->{payment} }, $form->{"paid_$i"} );
  342. push( @{ $form->{paymentdate} }, $form->{"datepaid_$i"} );
  343. push( @{ $form->{paymentaccount} }, $account );
  344. push( @{ $form->{paymentsource} }, $form->{"source_$i"} );
  345. push( @{ $form->{paymentmemo} }, $form->{"memo_$i"} );
  346. }
  347. }
  348. $form->{invtotal} = $form->{subtotal} + $tax;
  349. $form->{total} = $form->{invtotal} - $form->{paid};
  350. use LedgerSMB::CP;
  351. $c =
  352. CP->new( ( $form->{language_code} )
  353. ? $form->{language_code}
  354. : $myconfig{countrycode} );
  355. $c->init;
  356. ( $whole, $form->{decimal} ) = split /\./, $form->{invtotal};
  357. $form->{decimal} .= "00";
  358. $form->{decimal} = substr( $form->{decimal}, 0, 2 );
  359. $form->{text_decimal} = $c->num2text( $form->{decimal} * 1 );
  360. $form->{text_amount} = $c->num2text($whole);
  361. $form->{integer_amount} = $form->format_amount( $myconfig, $whole );
  362. for (qw(invtotal subtotal paid total)) {
  363. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  364. }
  365. ( $form->{employee} ) = split /--/, $form->{employee};
  366. if ( exists $form->{longformat} ) {
  367. for (qw(duedate transdate)) {
  368. $form->{$_} =
  369. $locale->date( \%myconfig, $form->{$_}, $form->{longformat} );
  370. }
  371. }
  372. $form->{notes} =~ s/^\s+//g;
  373. @a = ( "invnumber", "transdate", "duedate", "notes" );
  374. for (qw(company address tel fax businessnumber)) {
  375. $form->{$_} = $myconfig{$_};
  376. }
  377. $form->{address} =~ s/\\n/\n/g;
  378. push @a,
  379. qw(company address tel fax businessnumber text_amount text_decimal);
  380. $form->format_string(@a);
  381. $form->{invdate} = $form->{transdate};
  382. $form->{templates} = "$myconfig{templates}";
  383. $form->{IN} =
  384. ( $form->{formname} eq 'transaction' )
  385. ? lc $form->{ARAP} . "_$form->{formname}.html"
  386. : "$form->{formname}.html";
  387. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  388. $form->{IN} =~ s/html$/tex/;
  389. }
  390. if ( $form->{media} eq 'queue' ) {
  391. %queued = split / /, $form->{queued};
  392. if ( $filename = $queued{ $form->{formname} } ) {
  393. $form->{queued} =~ s/$form->{formname} $filename//;
  394. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  395. $filename =~ s/\..*$//g;
  396. }
  397. else {
  398. $filename = time;
  399. $filename .= $$;
  400. }
  401. $filename .= ( $form->{format} eq 'postscript' ) ? '.ps' : '.pdf';
  402. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  403. $form->{printmode} = '>';
  404. $form->{queued} .= " $form->{formname} $filename";
  405. $form->{queued} =~ s/^ //;
  406. # save status
  407. $form->update_status( \%myconfig );
  408. $old_form->{queued} = $form->{queued};
  409. %audittrail = (
  410. tablename => ($order) ? 'oe' : lc $ARAP,
  411. reference => $form->{"${inv}number"},
  412. formname => $form->{formname},
  413. action => 'queued',
  414. id => $form->{id}
  415. );
  416. $old_form->{audittrail} .=
  417. $form->audittrail( "", \%myconfig, \%audittrail );
  418. }
  419. if ( $form->{media} !~ /(queue|screen)/ ) {
  420. $form->{OUT} = ${LedgerSMB::Sysconfig::printer}{ $form->{media} };
  421. $form->{printmode} = '|-';
  422. if ( $form->{printed} !~ /$form->{formname}/ ) {
  423. $form->{printed} .= " $form->{formname}";
  424. $form->{printed} =~ s/^ //;
  425. $form->update_status( \%myconfig );
  426. }
  427. $old_form->{printed} = $form->{printed} if %$old_form;
  428. %audittrail = (
  429. tablename => lc $form->{ARAP},
  430. reference => $form->{"invnumber"},
  431. formname => $form->{formname},
  432. action => 'printed',
  433. id => $form->{id}
  434. );
  435. $old_form->{audittrail} .=
  436. $form->audittrail( "", \%myconfig, \%audittrail )
  437. if %$old_form;
  438. }
  439. $form->{fileid} = $form->{invnumber};
  440. $form->{fileid} =~ s/(\s|\W)+//g;
  441. if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
  442. {
  443. my $template =
  444. LedgerSMB::Template->new(
  445. user => \%myconfig, template => $form->{'formname'},
  446. format => 'HTML' );
  447. try {
  448. $template->render($form);
  449. $form->header;
  450. print $template->{'output'};
  451. exit;
  452. }
  453. catch Error::Simple with {
  454. my $E = shift;
  455. $form->error( $E->stacktrace );
  456. };
  457. }
  458. $form->parse_template( \%myconfig );
  459. if (%$old_form) {
  460. $old_form->{invnumber} = $form->{invnumber};
  461. $old_form->{invtotal} = $form->{invtotal};
  462. for ( keys %$form ) { delete $form->{$_} }
  463. for ( keys %$old_form ) { $form->{$_} = $old_form->{$_} }
  464. if ( !$form->{printandpost} ) {
  465. for (qw(exchangerate creditlimit creditremaining)) {
  466. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  467. }
  468. for ( 1 .. $form->{rowcount} ) {
  469. $form->{"amount_$_"} =
  470. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  471. }
  472. for ( split / /, $form->{taxaccounts} ) {
  473. $form->{"tax_$_"} =
  474. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  475. }
  476. for $i ( 1 .. $form->{paidaccounts} ) {
  477. for (qw(paid exchangerate)) {
  478. $form->{"${_}_$i"} =
  479. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  480. }
  481. }
  482. }
  483. &{"$display_form"};
  484. }
  485. }
  486. sub vendor_details { IR->vendor_details( \%myconfig, \%$form ) }
  487. sub customer_details { IS->customer_details( \%myconfig, \%$form ) }
  488. sub select_payment {
  489. @column_index =
  490. ( "ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid" );
  491. # list payments with radio button on a form
  492. $form->header;
  493. $title = $locale->text('Select payment');
  494. $column_data{ndx} = qq|<th width=1%>&nbsp;</th>|;
  495. $column_data{datepaid} = qq|<th>| . $locale->text('Date') . qq|</th>|;
  496. $column_data{source} = qq|<th>| . $locale->text('Source') . qq|</th>|;
  497. $column_data{memo} = qq|<th>| . $locale->text('Memo') . qq|</th>|;
  498. $column_data{paid} = qq|<th>| . $locale->text('Amount') . qq|</th>|;
  499. $column_data{"$form->{ARAP}_paid"} =
  500. qq|<th>| . $locale->text('Account') . qq|</th>|;
  501. print qq|
  502. <body>
  503. <form method=post action=$form->{script}>
  504. <table width=100%>
  505. <tr>
  506. <th class=listtop>$title</th>
  507. </tr>
  508. <tr space=5></tr>
  509. <tr>
  510. <td>
  511. <table width=100%>
  512. <tr class=listheading>|;
  513. for (@column_index) { print "\n$column_data{$_}" }
  514. print qq|
  515. </tr>
  516. |;
  517. $checked = "checked";
  518. foreach $i ( 1 .. $form->{paidaccounts} - 1 ) {
  519. for (@column_index) {
  520. $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>|;
  521. }
  522. $paid = $form->{"paid_$i"};
  523. $ok = 1;
  524. $column_data{ndx} =
  525. qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  526. $column_data{paid} = qq|<td align=right>$paid</td>|;
  527. $checked = "";
  528. $j++;
  529. $j %= 2;
  530. print qq|
  531. <tr class=listrow$j>|;
  532. for (@column_index) { print "\n$column_data{$_}" }
  533. print qq|
  534. </tr>
  535. |;
  536. }
  537. print qq|
  538. </table>
  539. </td>
  540. </tr>
  541. <tr>
  542. <td><hr size=3 noshade></td>
  543. </tr>
  544. </table>
  545. |;
  546. for (qw(action nextsub)) { delete $form->{$_} }
  547. $form->hide_form;
  548. print qq|
  549. <br>
  550. <input type=hidden name=nextsub value=payment_selected>
  551. |;
  552. if ($ok) {
  553. print qq|
  554. <button class="submit" type="submit" name="action" value="continue">|
  555. . $locale->text('Continue')
  556. . qq|</button>|;
  557. }
  558. print qq|
  559. </form>
  560. </body>
  561. </html>
  562. |;
  563. }
  564. sub payment_selected {
  565. &{"print_$form->{formname}"}( $form->{oldform}, $form->{ndx} );
  566. }
  567. sub print_options {
  568. if ( $form->{selectlanguage} ) {
  569. $form->{"selectlanguage"} =
  570. $form->unescape( $form->{"selectlanguage"} );
  571. $form->{"selectlanguage"} =~ s/ selected//;
  572. $form->{"selectlanguage"} =~
  573. s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  574. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  575. <input type=hidden name=selectlanguage value="|
  576. . $form->escape( $form->{selectlanguage}, 1 ) . qq|">|;
  577. }
  578. $form->{selectformname} = $form->unescape( $form->{selectformname} );
  579. $form->{selectformname} =~ s/ selected//;
  580. $form->{selectformname} =~
  581. s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  582. $type = qq|<select name=formname>$form->{selectformname}</select>
  583. <input type=hidden name=selectformname value="|
  584. . $form->escape( $form->{selectformname}, 1 ) . qq|">|;
  585. $media = qq|<select name=media>
  586. <option value="screen">| . $locale->text('Screen');
  587. $form->{selectformat} = qq|<option value="html">html\n|;
  588. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  589. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  590. $media .= qq|
  591. <option value="$_">$_|;
  592. }
  593. }
  594. if ( ${LedgerSMB::Sysconfig::latex} ) {
  595. $form->{selectformat} .= qq|
  596. <option value="postscript">| . $locale->text('Postscript') . qq|
  597. <option value="pdf">| . $locale->text('PDF');
  598. $media .= qq|<option value="queue">| . $locale->text('Queue');
  599. }
  600. $format = qq|<select name=format>$form->{selectformat}</select>|;
  601. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  602. $format .= qq|
  603. <input type=hidden name=selectformat value="|
  604. . $form->escape( $form->{selectformat}, 1 ) . qq|">|;
  605. $media .= qq|</select>|;
  606. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  607. print qq|
  608. <table width=100%>
  609. <tr>
  610. <td>$type</td>
  611. <td>$lang</td>
  612. <td>$format</td>
  613. <td>$media</td>
  614. <td align=right width=90%>
  615. |;
  616. if ( $form->{printed} =~ /$form->{formname}/ ) {
  617. print $locale->text('Printed') . qq|<br>|;
  618. }
  619. if ( $form->{recurring} ) {
  620. print $locale->text('Scheduled');
  621. }
  622. print qq|
  623. </td>
  624. </tr>
  625. </table>
  626. |;
  627. }
  628. sub print_and_post {
  629. $form->error( $locale->text('Select postscript or PDF!') )
  630. if $form->{format} !~ /(postscript|pdf)/;
  631. $form->error( $locale->text('Select a Printer!') )
  632. if $form->{media} eq 'screen';
  633. $form->{printandpost} = 1;
  634. $form->{display_form} = "post";
  635. &print;
  636. }