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