summaryrefslogtreecommitdiff
path: root/bin/arapprn.pl
blob: 2cc37f46e390fc0af53cf240900d4382d50813c4 (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. $form->{action} = 'post';
  123. delete $form->{printandpost};
  124. &post;
  125. }
  126. else {
  127. &{"print_$form->{formname}"}( $old_form, 1 );
  128. }
  129. }
  130. sub print_check {
  131. my ( $old_form, $i ) = @_;
  132. $display_form =
  133. ( $form->{display_form} ) ? $form->{display_form} : "display_form";
  134. if ( $form->{"paid_$i"} ) {
  135. @a = ();
  136. if ( exists $form->{longformat} ) {
  137. $form->{"datepaid_$i"} =
  138. $locale->date( \%myconfig, $form->{"datepaid_$i"},
  139. $form->{longformat} );
  140. }
  141. push @a, "source_$i", "memo_$i";
  142. $form->format_string(@a);
  143. }
  144. $form->{amount} = $form->{"paid_$i"};
  145. if ( ( $form->{formname} eq 'check' && $form->{vc} eq 'customer' )
  146. || ( $form->{formname} eq 'receipt' && $form->{vc} eq 'vendor' ) )
  147. {
  148. $form->{amount} =~ s/-//g;
  149. }
  150. for (qw(datepaid source memo)) { $form->{$_} = $form->{"${_}_$i"} }
  151. &{"$form->{vc}_details"};
  152. @a = qw(name address1 address2 city state zipcode country);
  153. foreach $item (qw(invnumber ordnumber)) {
  154. $temp{$item} = $form->{$item};
  155. delete $form->{$item};
  156. push( @{ $form->{$item} }, $temp{$item} );
  157. }
  158. push( @{ $form->{invdate} }, $form->{transdate} );
  159. push(
  160. @{ $form->{due} },
  161. $form->format_amount( \%myconfig, $form->{oldinvtotal}, 2 )
  162. );
  163. push( @{ $form->{paid} }, $form->{"paid_$i"} );
  164. use LedgerSMB::CP;
  165. $c =
  166. CP->new( ( $form->{language_code} )
  167. ? $form->{language_code}
  168. : $myconfig{countrycode} );
  169. $c->init;
  170. ( $whole, $form->{decimal} ) = split /\./,
  171. $form->parse_amount( \%myconfig, $form->{amount} );
  172. $form->{decimal} .= "00";
  173. $form->{decimal} = substr( $form->{decimal}, 0, 2 );
  174. $form->{text_decimal} = $c->num2text( $form->{decimal} * 1 );
  175. $form->{text_amount} = $c->num2text($whole);
  176. $form->{integer_amount} = $form->format_amount( $myconfig, $whole );
  177. ( $form->{employee} ) = split /--/, $form->{employee};
  178. $form->{notes} =~ s/^\s+//g;
  179. push @a, "notes";
  180. for (qw(company address tel fax businessnumber)) {
  181. $form->{$_} = $myconfig{$_};
  182. }
  183. $form->{address} =~ s/\\n/\n/g;
  184. push @a,
  185. qw(company address tel fax businessnumber text_amount text_decimal);
  186. $form->format_string(@a);
  187. $form->{templates} = "$myconfig{templates}";
  188. $form->{IN} =
  189. ( $form->{formname} eq 'transaction' )
  190. ? lc $form->{ARAP} . "_$form->{formname}.html"
  191. : "$form->{formname}.html";
  192. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  193. $form->{IN} =~ s/html$/tex/;
  194. }
  195. if ( $form->{media} eq 'queue' ) {
  196. # save status
  197. $form->update_status( \%myconfig );
  198. $form->{queued} = $form->{queued};
  199. %audittrail = (
  200. tablename => ($order) ? 'oe' : lc $ARAP,
  201. reference => $form->{"${inv}number"},
  202. formname => $form->{formname},
  203. action => 'queued',
  204. id => $form->{id}
  205. );
  206. $form->{audittrail} .=
  207. $form->audittrail( "", \%myconfig, \%audittrail );
  208. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  209. $form->{printmode} = '>';
  210. $form->{queued} .= " $form->{formname} $filename";
  211. $form->{queued} =~ s/^ //;
  212. }
  213. if ( $form->{media} !~ /(screen|queue)/ ) {
  214. %queued = split / /, $form->{queued};
  215. $form->{OUT} = ${LedgerSMB::Sysconfig::printer}{ $form->{media} };
  216. $form->{printmode} = '|-';
  217. if ( $form->{printed} !~ /$form->{formname}/ ) {
  218. $form->{printed} .= " $form->{formname}";
  219. $form->{printed} =~ s/^ //;
  220. $form->update_status( \%myconfig );
  221. }
  222. %audittrail = (
  223. tablename => lc $form->{ARAP},
  224. reference => $form->{invnumber},
  225. formname => $form->{formname},
  226. action => 'printed',
  227. id => $form->{id}
  228. );
  229. %status = ();
  230. for (qw(printed audittrail)) { $status{$_} = $form->{$_} }
  231. $status{audittrail} .=
  232. $form->audittrail( "", \%myconfig, \%audittrail );
  233. }
  234. $form->{fileid} = $invnumber;
  235. $form->{fileid} =~ s/(\s|\W)+//g;
  236. my $template = LedgerSMB::Template->new(
  237. user => \%myconfig, template => $form->{'formname'},
  238. format => uc $form->{'format'},
  239. no_auto_output => 1,
  240. output_args => $form,
  241. );
  242. try {
  243. $template->render($form);
  244. $template->output($form);
  245. }
  246. catch Error::Simple with {
  247. my $E = shift;
  248. $form->error( $E->stacktrace );
  249. };
  250. if ( $form->{previousform} ) {
  251. $previousform = $form->unescape( $form->{previousform} );
  252. for ( keys %$form ) { delete $form->{$_} }
  253. foreach $item ( split /&/, $previousform ) {
  254. ( $key, $value ) = split /=/, $item, 2;
  255. $value =~ s/%26/&/g;
  256. $form->{$key} = $value;
  257. }
  258. for (qw(exchangerate creditlimit creditremaining)) {
  259. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  260. }
  261. for ( 1 .. $form->{rowcount} ) {
  262. $form->{"amount_$_"} =
  263. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  264. }
  265. for ( split / /, $form->{taxaccounts} ) {
  266. $form->{"tax_$_"} =
  267. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  268. }
  269. for $i ( 1 .. $form->{paidaccounts} ) {
  270. for (qw(paid exchangerate)) {
  271. $form->{"${_}_$i"} =
  272. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  273. }
  274. }
  275. for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
  276. &{"$display_form"};
  277. }
  278. }
  279. sub print_receipt {
  280. my ( $old_form, $i ) = @_;
  281. &print_check( $old_form, $i );
  282. }
  283. sub print_transaction {
  284. my ($old_form) = @_;
  285. $display_form =
  286. ( $form->{display_form} ) ? $form->{display_form} : "display_form";
  287. &{"$form->{vc}_details"};
  288. @a = qw(name address1 address2 city state zipcode country);
  289. $form->{invtotal} = 0;
  290. foreach $i ( 1 .. $form->{rowcount} - 1 ) {
  291. ( $form->{tempaccno}, $form->{tempaccount} ) = split /--/,
  292. $form->{"$form->{ARAP}_amount_$i"};
  293. ( $form->{tempprojectnumber} ) = split /--/,
  294. $form->{"projectnumber_$i"};
  295. $form->{tempdescription} = $form->{"description_$i"};
  296. $form->format_string(
  297. qw(tempaccno tempaccount tempprojectnumber tempdescription));
  298. push( @{ $form->{accno} }, $form->{tempaccno} );
  299. push( @{ $form->{account} }, $form->{tempaccount} );
  300. push( @{ $form->{description} }, $form->{tempdescription} );
  301. push( @{ $form->{projectnumber} }, $form->{tempprojectnumber} );
  302. push( @{ $form->{amount} }, $form->{"amount_$i"} );
  303. $form->{subtotal} +=
  304. $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
  305. }
  306. foreach $accno ( split / /, $form->{taxaccounts} ) {
  307. if ( $form->{"tax_$accno"} ) {
  308. $form->format_string("${accno}_description");
  309. $tax += $form->parse_amount( \%myconfig, $form->{"tax_$accno"} );
  310. $form->{"${accno}_tax"} = $form->{"tax_$accno"};
  311. push( @{ $form->{tax} }, $form->{"tax_$accno"} );
  312. push(
  313. @{ $form->{taxdescription} },
  314. $form->{"${accno}_description"}
  315. );
  316. $form->{"${accno}_taxrate"} =
  317. $form->format_amount( $myconfig, $form->{"${accno}_rate"} * 100 );
  318. push( @{ $form->{taxrate} }, $form->{"${accno}_taxrate"} );
  319. push( @{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"} );
  320. }
  321. }
  322. $tax = 0 if $form->{taxincluded};
  323. push @a, $form->{ARAP};
  324. $form->format_string(@a);
  325. $form->{paid} = 0;
  326. for $i ( 1 .. $form->{paidaccounts} - 1 ) {
  327. if ( $form->{"paid_$i"} ) {
  328. @a = ();
  329. $form->{paid} +=
  330. $form->parse_amount( \%myconfig, $form->{"paid_$i"} );
  331. if ( exists $form->{longformat} ) {
  332. $form->{"datepaid_$i"} =
  333. $locale->date( \%myconfig, $form->{"datepaid_$i"},
  334. $form->{longformat} );
  335. }
  336. push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
  337. $form->format_string(@a);
  338. ( $accno, $account ) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
  339. push( @{ $form->{payment} }, $form->{"paid_$i"} );
  340. push( @{ $form->{paymentdate} }, $form->{"datepaid_$i"} );
  341. push( @{ $form->{paymentaccount} }, $account );
  342. push( @{ $form->{paymentsource} }, $form->{"source_$i"} );
  343. push( @{ $form->{paymentmemo} }, $form->{"memo_$i"} );
  344. }
  345. }
  346. $form->{invtotal} = $form->{subtotal} + $tax;
  347. $form->{total} = $form->{invtotal} - $form->{paid};
  348. use LedgerSMB::CP;
  349. $c =
  350. CP->new( ( $form->{language_code} )
  351. ? $form->{language_code}
  352. : $myconfig{countrycode} );
  353. $c->init;
  354. ( $whole, $form->{decimal} ) = split /\./, $form->{invtotal};
  355. $form->{decimal} .= "00";
  356. $form->{decimal} = substr( $form->{decimal}, 0, 2 );
  357. $form->{text_decimal} = $c->num2text( $form->{decimal} * 1 );
  358. $form->{text_amount} = $c->num2text($whole);
  359. $form->{integer_amount} = $form->format_amount( $myconfig, $whole );
  360. for (qw(invtotal subtotal paid total)) {
  361. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  362. }
  363. ( $form->{employee} ) = split /--/, $form->{employee};
  364. if ( exists $form->{longformat} ) {
  365. for (qw(duedate transdate)) {
  366. $form->{$_} =
  367. $locale->date( \%myconfig, $form->{$_}, $form->{longformat} );
  368. }
  369. }
  370. $form->{notes} =~ s/^\s+//g;
  371. @a = ( "invnumber", "transdate", "duedate", "notes" );
  372. for (qw(company address tel fax businessnumber)) {
  373. $form->{$_} = $myconfig{$_};
  374. }
  375. $form->{address} =~ s/\\n/\n/g;
  376. push @a,
  377. qw(company address tel fax businessnumber text_amount text_decimal);
  378. $form->format_string(@a);
  379. $form->{invdate} = $form->{transdate};
  380. $form->{templates} = "$myconfig{templates}";
  381. $form->{IN} =
  382. ( $form->{formname} eq 'transaction' )
  383. ? lc $form->{ARAP} . "_$form->{formname}.html"
  384. : "$form->{formname}.html";
  385. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  386. $form->{IN} =~ s/html$/tex/;
  387. }
  388. if ( $form->{media} eq 'queue' ) {
  389. %queued = split / /, $form->{queued};
  390. if ( $filename = $queued{ $form->{formname} } ) {
  391. $form->{queued} =~ s/$form->{formname} $filename//;
  392. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  393. $filename =~ s/\..*$//g;
  394. }
  395. else {
  396. $filename = time;
  397. $filename .= $$;
  398. }
  399. $filename .= ( $form->{format} eq 'postscript' ) ? '.ps' : '.pdf';
  400. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  401. $form->{printmode} = '>';
  402. $form->{queued} .= " $form->{formname} $filename";
  403. $form->{queued} =~ s/^ //;
  404. # save status
  405. $form->update_status( \%myconfig );
  406. $old_form->{queued} = $form->{queued};
  407. %audittrail = (
  408. tablename => ($order) ? 'oe' : lc $ARAP,
  409. reference => $form->{"${inv}number"},
  410. formname => $form->{formname},
  411. action => 'queued',
  412. id => $form->{id}
  413. );
  414. $old_form->{audittrail} .=
  415. $form->audittrail( "", \%myconfig, \%audittrail );
  416. }
  417. if ( $form->{media} !~ /(queue|screen)/ ) {
  418. $form->{OUT} = ${LedgerSMB::Sysconfig::printer}{ $form->{media} };
  419. $form->{printmode} = '|-';
  420. if ( $form->{printed} !~ /$form->{formname}/ ) {
  421. $form->{printed} .= " $form->{formname}";
  422. $form->{printed} =~ s/^ //;
  423. $form->update_status( \%myconfig );
  424. }
  425. $old_form->{printed} = $form->{printed} if %$old_form;
  426. %audittrail = (
  427. tablename => lc $form->{ARAP},
  428. reference => $form->{"invnumber"},
  429. formname => $form->{formname},
  430. action => 'printed',
  431. id => $form->{id}
  432. );
  433. $old_form->{audittrail} .=
  434. $form->audittrail( "", \%myconfig, \%audittrail )
  435. if %$old_form;
  436. }
  437. $form->{fileid} = $form->{invnumber};
  438. $form->{fileid} =~ s/(\s|\W)+//g;
  439. my $template = LedgerSMB::Template->new(
  440. user => \%myconfig, template => $form->{'formname'},
  441. no_auto_output => 1,
  442. format => uc $form->{format} );
  443. try {
  444. $template->render($form);
  445. $template->output(%{$form});
  446. }
  447. catch Error::Simple with {
  448. my $E = shift;
  449. $form->error( $E->stacktrace );
  450. };
  451. if (%$old_form) {
  452. $old_form->{invnumber} = $form->{invnumber};
  453. $old_form->{invtotal} = $form->{invtotal};
  454. for ( keys %$form ) { delete $form->{$_} }
  455. for ( keys %$old_form ) { $form->{$_} = $old_form->{$_} }
  456. if ( !$form->{printandpost} ) {
  457. for (qw(exchangerate creditlimit creditremaining)) {
  458. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  459. }
  460. for ( 1 .. $form->{rowcount} ) {
  461. $form->{"amount_$_"} =
  462. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  463. }
  464. for ( split / /, $form->{taxaccounts} ) {
  465. $form->{"tax_$_"} =
  466. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  467. }
  468. for $i ( 1 .. $form->{paidaccounts} ) {
  469. for (qw(paid exchangerate)) {
  470. $form->{"${_}_$i"} =
  471. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  472. }
  473. }
  474. }
  475. &{"$display_form"};
  476. }
  477. }
  478. sub vendor_details { IR->vendor_details( \%myconfig, \%$form ) }
  479. sub customer_details { IS->customer_details( \%myconfig, \%$form ) }
  480. sub select_payment {
  481. my %hiddens;
  482. my @column_index =
  483. ( "ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid" );
  484. # list payments with radio button on a form
  485. $form->{title} = $locale->text('Select payment');
  486. my %column_heading;
  487. $column_heading{ndx} = ' ';
  488. $column_heading{datepaid} = $locale->text('Date');
  489. $column_heading{source} = $locale->text('Source');
  490. $column_heading{memo} = $locale->text('Memo');
  491. $column_heading{paid} = $locale->text('Amount');
  492. $column_heading{"$form->{ARAP}_paid"} = $locale->text('Account');
  493. my $checked = "checked";
  494. my @rows;
  495. my $j;
  496. my $ok;
  497. foreach my $i ( 1 .. $form->{paidaccounts} - 1 ) {
  498. my %column_data;
  499. for (@column_index) {
  500. $column_data{$_} = $form->{"${_}_$i"};
  501. }
  502. $column_data{ndx} = {input => {
  503. name => 'ndx',
  504. type => 'radio',
  505. value => $i,
  506. }};
  507. $column_data{ndx}{input}{checked} = 'checked' if $checked;
  508. $column_data{paid} = $form->{"paid_$i"};
  509. $checked = "";
  510. $ok = 1;
  511. $j++;
  512. $j %= 2;
  513. $column_data{i} = $j;
  514. push @rows, \%column_data;
  515. }
  516. for (qw(action nextsub)) { delete $form->{$_} }
  517. $hiddens{$_} = $form->{$_} foreach keys %$form;
  518. $hiddens{nextsub} = 'payment_selected';
  519. my @buttons;
  520. if ($ok) {
  521. push @buttons, {
  522. name => 'action',
  523. value => 'payment_selected',
  524. text => $locale->text('Continue'),
  525. };
  526. }
  527. my $template = LedgerSMB::Template->new_UI(
  528. user => \%myconfig,
  529. locale => $locale,
  530. template => 'form-dynatable',
  531. );
  532. $template->render({
  533. form => $form,
  534. buttons => \@buttons,
  535. hiddens => \%hiddens,
  536. columns => \@column_index,
  537. heading => \%column_heading,
  538. rows => \@rows,
  539. row_alignment => {'paid' => 'right'},
  540. });
  541. }
  542. sub payment_selected {
  543. &{"print_$form->{formname}"}( $form->{oldform}, $form->{ndx} );
  544. }
  545. sub print_options {
  546. if ( $form->{selectlanguage} ) {
  547. $form->{"selectlanguage"} =
  548. $form->unescape( $form->{"selectlanguage"} );
  549. $form->{"selectlanguage"} =~ s/ selected//;
  550. $form->{"selectlanguage"} =~
  551. s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  552. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  553. <input type=hidden name=selectlanguage value="|
  554. . $form->escape( $form->{selectlanguage}, 1 ) . qq|">|;
  555. }
  556. $form->{selectformname} = $form->unescape( $form->{selectformname} );
  557. $form->{selectformname} =~ s/ selected//;
  558. $form->{selectformname} =~
  559. s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  560. $type = qq|<select name=formname>$form->{selectformname}</select>
  561. <input type=hidden name=selectformname value="|
  562. . $form->escape( $form->{selectformname}, 1 ) . qq|">|;
  563. $media = qq|<select name=media>
  564. <option value="screen">| . $locale->text('Screen');
  565. $form->{selectformat} = qq|<option value="html">html\n|;
  566. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  567. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  568. $media .= qq|
  569. <option value="$_">$_|;
  570. }
  571. }
  572. if ( ${LedgerSMB::Sysconfig::latex} ) {
  573. $form->{selectformat} .= qq|
  574. <option value="postscript">| . $locale->text('Postscript') . qq|
  575. <option value="pdf">| . $locale->text('PDF');
  576. $media .= qq|<option value="queue">| . $locale->text('Queue');
  577. }
  578. $format = qq|<select name=format>$form->{selectformat}</select>|;
  579. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  580. $format .= qq|
  581. <input type=hidden name=selectformat value="|
  582. . $form->escape( $form->{selectformat}, 1 ) . qq|">|;
  583. $media .= qq|</select>|;
  584. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  585. print qq|
  586. <table width=100%>
  587. <tr>
  588. <td>$type</td>
  589. <td>$lang</td>
  590. <td>$format</td>
  591. <td>$media</td>
  592. <td align=right width=90%>
  593. |;
  594. if ( $form->{printed} =~ /$form->{formname}/ ) {
  595. print $locale->text('Printed') . qq|<br>|;
  596. }
  597. if ( $form->{recurring} ) {
  598. print $locale->text('Scheduled');
  599. }
  600. print qq|
  601. </td>
  602. </tr>
  603. </table>
  604. |;
  605. }
  606. sub print_and_post {
  607. $form->error( $locale->text('Select postscript or PDF!') )
  608. if $form->{format} !~ /(postscript|pdf)/;
  609. $form->error( $locale->text('Select a Printer!') )
  610. if $form->{media} eq 'screen';
  611. $form->{printandpost} = 1;
  612. $form->{display_form} = "post";
  613. &print;
  614. }