summaryrefslogtreecommitdiff
path: root/bin/bp.pl
blob: b6579805e9fa26ee06e087c12df8fb1f4c4c5a5c (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. # Batch printing
  37. #
  38. #======================================================================
  39. use LedgerSMB::BP;
  40. 1;
  41. # end of main
  42. sub search {
  43. # $locale->text('Sales Invoices')
  44. # $locale->text('Packing Lists')
  45. # $locale->text('Pick Lists')
  46. # $locale->text('Sales Orders')
  47. # $locale->text('Work Orders')
  48. # $locale->text('Purchase Orders')
  49. # $locale->text('Bin Lists')
  50. # $locale->text('Quotations')
  51. # $locale->text('RFQs')
  52. # $locale->text('Time Cards')
  53. # setup customer/vendor selection
  54. BP->get_vc( \%myconfig, \%$form );
  55. if ( @{ $form->{"all_$form->{vc}"} } ) {
  56. $name = "<option>\n";
  57. for ( @{ $form->{"all_$form->{vc}"} } ) {
  58. $name .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  59. }
  60. $name = qq|<select name=$form->{vc}>$name</select>|;
  61. }
  62. else {
  63. $name = qq|<input name=$form->{vc} size=35>|;
  64. }
  65. # $locale->text('Customer')
  66. # $locale->text('Vendor')
  67. # $locale->text('Employee')
  68. %label = (
  69. invoice => { title => 'Sales Invoices', name => 'Customer' },
  70. packing_list => { title => 'Packing Lists', name => 'Customer' },
  71. pick_list => { title => 'Pick Lists', name => 'Customer' },
  72. sales_order => { title => 'Sales Orders', name => 'Customer' },
  73. work_order => { title => 'Work Orders', name => 'Customer' },
  74. purchase_order => { title => 'Purchase Orders', name => 'Vendor' },
  75. bin_list => { title => 'Bin Lists', name => 'Vendor' },
  76. sales_quotation => { title => 'Quotations', name => 'Customer' },
  77. request_quotation => { title => 'RFQs', name => 'Vendor' },
  78. timecard => { title => 'Time Cards', name => 'Employee' },
  79. check => { title => 'Check', name => 'Vendor' },
  80. );
  81. $label{invoice}{invnumber} = qq|
  82. <tr>
  83. <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
  84. <td colspan=3><input name=invnumber size=20></td>
  85. </tr>
  86. |;
  87. $label{invoice}{ordnumber} = qq|
  88. <tr>
  89. <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
  90. <td colspan=3><input name=ordnumber size=20></td>
  91. </tr>
  92. |;
  93. $label{sales_quotation}{quonumber} = qq|
  94. <tr>
  95. <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
  96. <td colspan=3><input name=quonumber size=20></td>
  97. </tr>
  98. |;
  99. $label{packing_list}{invnumber} = $label{invoice}{invnumber};
  100. $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
  101. $label{pick_list}{invnumber} = $label{invoice}{invnumber};
  102. $label{pick_list}{ordnumber} = $label{invoice}{ordnumber};
  103. $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
  104. $label{work_order}{ordnumber} = $label{invoice}{ordnumber};
  105. $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
  106. $label{bin_list}{ordnumber} = $label{invoice}{ordnumber};
  107. $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
  108. # do one call to text
  109. $form->{title} =
  110. $locale->text('Print') . " "
  111. . $locale->text( $label{ $form->{type} }{title} );
  112. # accounting years
  113. if ( @{ $form->{all_years} } ) {
  114. # accounting years
  115. $form->{selectaccountingyear} = "<option>\n";
  116. for ( @{ $form->{all_years} } ) {
  117. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  118. }
  119. $form->{selectaccountingmonth} = "<option>\n";
  120. for ( sort keys %{ $form->{all_month} } ) {
  121. $form->{selectaccountingmonth} .=
  122. qq|<option value=$_>|
  123. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  124. }
  125. $selectfrom = qq|
  126. <tr>
  127. <th align=right>| . $locale->text('Period') . qq|</th>
  128. <td colspan=3>
  129. <select name=month>$form->{selectaccountingmonth}</select>
  130. <select name=year>$form->{selectaccountingyear}</select>
  131. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  132. . $locale->text('Current') . qq|
  133. <input name=interval class=radio type=radio value=1>&nbsp;|
  134. . $locale->text('Month') . qq|
  135. <input name=interval class=radio type=radio value=3>&nbsp;|
  136. . $locale->text('Quarter') . qq|
  137. <input name=interval class=radio type=radio value=12>&nbsp;|
  138. . $locale->text('Year') . qq|
  139. </td>
  140. </tr>
  141. |;
  142. }
  143. $form->header;
  144. print qq|
  145. <body>
  146. <form method=post action=$form->{script}>
  147. |;
  148. $form->hide_form(qw(vc type title));
  149. print qq|
  150. <table width=100%>
  151. <tr><th class=listtop>$form->{title}</th></tr>
  152. <tr height="5"></tr>
  153. <tr>
  154. <td>
  155. <table>
  156. <tr>
  157. <th align=right>| . $locale->text( $label{ $form->{type} }{name} ) . qq|</th>
  158. <td colspan=3>$name</td>
  159. </tr>
  160. $account
  161. $label{$form->{type}}{invnumber}
  162. $label{$form->{type}}{ordnumber}
  163. $label{$form->{type}}{quonumber}
  164. <tr>
  165. <th align=right nowrap>| . $locale->text('From') . qq|</th>
  166. <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  167. <th align=right>| . $locale->text('To') . qq|</th>
  168. <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  169. </tr>
  170. $selectfrom
  171. </table>
  172. </td>
  173. </tr>
  174. <tr>
  175. <td><hr size=3 noshade></td>
  176. </tr>
  177. </table>
  178. <input type=hidden name=sort value=transdate>
  179. <input type=hidden name=nextsub value=list_spool>
  180. <br>
  181. <button class="submit" type="submit" name="action" value="continue">|
  182. . $locale->text('Continue')
  183. . qq|</button>
  184. |;
  185. $form->hide_form(qw(path login sessionid));
  186. print qq|
  187. </form>
  188. </body>
  189. </html>
  190. |;
  191. }
  192. sub remove {
  193. $selected = 0;
  194. for $i ( 1 .. $form->{rowcount} ) {
  195. if ( $form->{"checked_$i"} ) {
  196. $selected = 1;
  197. last;
  198. }
  199. }
  200. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  201. $form->{title} = $locale->text('Confirm!');
  202. $form->header;
  203. print qq|
  204. <body>
  205. <form method=post action=$form->{script}>
  206. |;
  207. for (qw(action header)) { delete $form->{$_} }
  208. foreach $key ( keys %$form ) {
  209. print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
  210. }
  211. print qq|
  212. <h2 class=confirm>$form->{title}</h2>
  213. <h4>|
  214. . $locale->text(
  215. 'Are you sure you want to remove the marked entries from the queue?')
  216. . qq|</h4>
  217. <button name="action" class="submit" type="submit" value="yes">|
  218. . $locale->text('Yes')
  219. . qq|</button>
  220. </form>
  221. </body>
  222. </html>
  223. |;
  224. }
  225. sub yes {
  226. $form->info( $locale->text('Removing marked entries from queue ...') );
  227. $form->{callback} .= "&header=1" if $form->{callback};
  228. if ( BP->delete_spool( \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool} )
  229. )
  230. {
  231. $form->redirect( $locale->text('Removed spoolfiles!') );
  232. }
  233. else {
  234. $form->error( $locale->text('Cannot remove files!') );
  235. }
  236. }
  237. sub print {
  238. if ( $form->{callback} ) {
  239. for ( 1 .. $form->{rowcount} ) {
  240. $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"};
  241. }
  242. $form->{callback} .= "&header=1";
  243. }
  244. for $i ( 1 .. $form->{rowcount} ) {
  245. if ( $form->{"checked_$i"} ) {
  246. $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  247. $form->{printmode} = '|-';
  248. $form->info( $locale->text('Printing') . " ..." );
  249. if (
  250. BP->print_spool(
  251. \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool}
  252. )
  253. )
  254. {
  255. print $locale->text('done');
  256. $form->redirect( $locale->text('Marked entries printed!') );
  257. }
  258. exit;
  259. }
  260. }
  261. $form->error('Nothing selected!');
  262. }
  263. sub list_spool {
  264. $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
  265. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  266. split( /--/, $form->{ $form->{vc} } );
  267. BP->get_spoolfiles( \%myconfig, \%$form );
  268. $title = $form->escape( $form->{title} );
  269. $href =
  270. "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title";
  271. $form->sort_order();
  272. $title = $form->escape( $form->{title}, 1 );
  273. $callback =
  274. "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title";
  275. if ( $form->{ $form->{vc} } ) {
  276. $callback .=
  277. "&$form->{vc}=" . $form->escape( $form->{ $form->{vc} }, 1 );
  278. $href .= "&$form->{vc}=" . $form->escape( $form->{ $form->{vc} } );
  279. $option =
  280. ( $form->{vc} eq 'customer' )
  281. ? $locale->text('Customer')
  282. : $locale->text('Vendor');
  283. $option .= " : $form->{$form->{vc}}";
  284. }
  285. if ( $form->{account} ) {
  286. $callback .= "&account=" . $form->escape( $form->{account}, 1 );
  287. $href .= "&account=" . $form->escape( $form->{account} );
  288. $option .= "\n<br>" if ($option);
  289. $option .= $locale->text('Account') . " : $form->{account}";
  290. }
  291. if ( $form->{invnumber} ) {
  292. $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
  293. $href .= "&invnumber=" . $form->escape( $form->{invnumber} );
  294. $option .= "\n<br>" if ($option);
  295. $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
  296. }
  297. if ( $form->{ordnumber} ) {
  298. $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
  299. $href .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
  300. $option .= "\n<br>" if ($option);
  301. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  302. }
  303. if ( $form->{quonumber} ) {
  304. $callback .= "&quonumber=" . $form->escape( $form->{quonumber}, 1 );
  305. $href .= "&quonumber=" . $form->escape( $form->{quonumber} );
  306. $option .= "\n<br>" if ($option);
  307. $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
  308. }
  309. if ( $form->{transdatefrom} ) {
  310. $callback .= "&transdatefrom=$form->{transdatefrom}";
  311. $href .= "&transdatefrom=$form->{transdatefrom}";
  312. $option .= "\n<br>" if ($option);
  313. $option .=
  314. $locale->text('From') . "&nbsp;"
  315. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  316. }
  317. if ( $form->{transdateto} ) {
  318. $callback .= "&transdateto=$form->{transdateto}";
  319. $href .= "&transdateto=$form->{transdateto}";
  320. $option .= "\n<br>" if ($option);
  321. $option .=
  322. $locale->text('To') . "&nbsp;"
  323. . $locale->date( \%myconfig, $form->{transdateto}, 1 );
  324. }
  325. $name = ucfirst $form->{vc};
  326. @columns = qw(transdate);
  327. if ( $form->{type} =~ /(invoice)/ ) {
  328. push @columns, "invnumber";
  329. }
  330. if ( $form->{type} =~ /(packing|pick)_list/ ) {
  331. push @columns, "invnumber";
  332. }
  333. if ( $form->{type} =~ /_(order|list)$/ ) {
  334. push @columns, "ordnumber";
  335. }
  336. if ( $form->{type} =~ /_quotation$/ ) {
  337. push @columns, "quonumber";
  338. }
  339. if ( $form->{type} eq 'timecard' ) {
  340. push @columns, "id";
  341. }
  342. push @columns, ( name, spoolfile );
  343. @column_index = $form->sort_columns(@columns);
  344. unshift @column_index, "checked";
  345. $column_header{checked} = "<th class=listheading>&nbsp;</th>";
  346. $column_header{transdate} =
  347. "<th><a class=listheading href=$href&sort=transdate>"
  348. . $locale->text('Date')
  349. . "</a></th>";
  350. $column_header{invnumber} =
  351. "<th><a class=listheading href=$href&sort=invnumber>"
  352. . $locale->text('Invoice')
  353. . "</a></th>";
  354. $column_header{ordnumber} =
  355. "<th><a class=listheading href=$href&sort=ordnumber>"
  356. . $locale->text('Order')
  357. . "</a></th>";
  358. $column_header{quonumber} =
  359. "<th><a class=listheading href=$href&sort=quonumber>"
  360. . $locale->text('Quotation')
  361. . "</a></th>";
  362. $column_header{name} =
  363. "<th><a class=listheading href=$href&sort=name>"
  364. . $locale->text($name)
  365. . "</a></th>";
  366. $column_header{id} =
  367. "<th><a class=listheading href=$href&sort=id>"
  368. . $locale->text('ID')
  369. . "</a></th>";
  370. $column_header{spoolfile} =
  371. "<th class=listheading>" . $locale->text('Spoolfile') . "</th>";
  372. $form->header;
  373. print qq|
  374. <body>
  375. <form method=post action=$form->{script}>
  376. <table width=100%>
  377. <tr>
  378. <th class=listtop>$form->{title}</th>
  379. </tr>
  380. <tr height="5"></tr>
  381. <tr>
  382. <td>$option</td>
  383. </tr>
  384. <tr>
  385. <td>
  386. <table width=100%>
  387. <tr class=listheading>
  388. |;
  389. for (@column_index) { print "\n$column_header{$_}" }
  390. print qq|
  391. </tr>
  392. |;
  393. # add sort and escape callback, this one we use for the add sub
  394. $form->{callback} = $callback .= "&sort=$form->{sort}";
  395. # escape callback for href
  396. $callback = $form->escape($callback);
  397. $i = 0;
  398. foreach $ref ( @{ $form->{SPOOL} } ) {
  399. $i++;
  400. $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
  401. # this is for audittrail
  402. $form->{module} = $ref->{module};
  403. if ( $ref->{invoice} ) {
  404. $ref->{module} = ( $ref->{module} eq 'ar' ) ? "is" : "ir";
  405. }
  406. $module = "$ref->{module}.pl";
  407. $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
  408. if ( ${LedgerSMB::Sysconfig::spool} eq $ref->{spoolfile} ) {
  409. $column_data{checked} = qq|<td></td>|;
  410. }
  411. else {
  412. $column_data{checked} =
  413. qq|<td><input name=checked_$i type=checkbox class=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
  414. }
  415. for (qw(id invnumber ordnumber quonumber)) {
  416. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  417. }
  418. if ( $ref->{module} eq 'oe' ) {
  419. $column_data{invnumber} = qq|<td>&nbsp</td>|;
  420. $column_data{ordnumber} =
  421. qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td>
  422. <input type=hidden name="reference_$i" value="$ref->{ordnumber}">|;
  423. $column_data{quonumber} =
  424. qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td>
  425. <input type=hidden name="reference_$i" value="$ref->{quonumber}">|;
  426. }
  427. elsif ( $ref->{module} eq 'jc' ) {
  428. $column_data{id} =
  429. qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{id}</a></td>
  430. <input type=hidden name="reference_$i" value="$ref->{id}">|;
  431. }
  432. else {
  433. $column_data{invnumber} =
  434. qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td>
  435. <input type=hidden name="reference_$i" value="$ref->{invnumber}">|;
  436. }
  437. $column_data{name} = "<td>$ref->{name}</td>";
  438. $column_data{spoolfile} =
  439. qq|<td><a href=${LedgerSMB::Sysconfig::spool}/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
  440. |;
  441. ${LedgerSMB::Sysconfig::spool} = $ref->{spoolfile};
  442. $j++;
  443. $j %= 2;
  444. print "
  445. <tr class=listrow$j>
  446. ";
  447. for (@column_index) { print "\n$column_data{$_}" }
  448. print qq|
  449. <input type=hidden name="id_$i" value=$ref->{id}>
  450. <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
  451. </tr>
  452. |;
  453. }
  454. print qq|
  455. <input type=hidden name=rowcount value=$i>
  456. </table>
  457. </td>
  458. </tr>
  459. <tr>
  460. <td><hr size=3 noshade></td>
  461. </tr>
  462. </table>
  463. <br>
  464. |;
  465. $form->hide_form(
  466. qw(callback title vc type sort module account path login sessionid));
  467. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  468. foreach $key ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  469. print qq|
  470. <input name=media type=radio class=radio value="$key" |;
  471. print qq|checked| if $key eq $myconfig{printer};
  472. print qq|>$key|;
  473. }
  474. print qq|<p>\n|;
  475. # type=submit $locale->text('Select all')
  476. # type=submit $locale->text('Print')
  477. # type=submit $locale->text('Remove')
  478. %button = (
  479. 'select_all' =>
  480. { ndx => 2, key => 'A', value => $locale->text('Select all') },
  481. 'print' =>
  482. { ndx => 3, key => 'P', value => $locale->text('Print') },
  483. 'remove' =>
  484. { ndx => 4, key => 'R', value => $locale->text('Remove') },
  485. );
  486. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  487. {
  488. $form->print_button( \%button, $_ );
  489. }
  490. }
  491. if ( $form->{lynx} ) {
  492. require "bin/menu.pl";
  493. &menubar;
  494. }
  495. print qq|
  496. </form>
  497. </body>
  498. </html>
  499. |;
  500. }
  501. sub select_all {
  502. for ( 1 .. $form->{rowcount} ) { $form->{"checked_$_"} = 1 }
  503. &list_spool;
  504. }
  505. sub continue { &{ $form->{nextsub} } }