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