summaryrefslogtreecommitdiff
path: root/bin/lynx/bp.pl
blob: 7606cb2386da936bb8691d17722894a260a9cf84 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (C) 2006
  4. # This work contains copyrighted information from a number of sources all used
  5. # with permission.
  6. #
  7. # This file contains source code included with or based on SQL-Ledger which
  8. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  9. # under the GNU General Public License version 2 or, at your option, any later
  10. # version. For a full list including contact information of contributors,
  11. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  12. #
  13. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  14. # Copyright (c) 2003
  15. #
  16. # Author: DWS Systems Inc.
  17. # Web: http://www.sql-ledger.org
  18. #
  19. #
  20. #
  21. # Author: DWS Systems Inc.
  22. # Web: http://sourceforge.net/projects/ledger-smb/
  23. #
  24. #
  25. # This program is free software; you can redistribute it and/or modify
  26. # it under the terms of the GNU General Public License as published by
  27. # the Free Software Foundation; either version 2 of the License, or
  28. # (at your option) any later version.
  29. #
  30. # This program is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. # GNU General Public License for more details.
  34. # You should have received a copy of the GNU General Public License
  35. # along with this program; if not, write to the Free Software
  36. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  37. #======================================================================
  38. #
  39. # Batch printing
  40. #
  41. #======================================================================
  42. use SL::BP;
  43. 1;
  44. # end of main
  45. sub search {
  46. # $locale->text('Sales Invoices')
  47. # $locale->text('Packing Lists')
  48. # $locale->text('Pick Lists')
  49. # $locale->text('Sales Orders')
  50. # $locale->text('Work Orders')
  51. # $locale->text('Purchase Orders')
  52. # $locale->text('Bin Lists')
  53. # $locale->text('Quotations')
  54. # $locale->text('RFQs')
  55. # $locale->text('Time Cards')
  56. # setup customer/vendor selection
  57. BP->get_vc(\%myconfig, \%$form);
  58. if (@{ $form->{"all_$form->{vc}"} }) {
  59. $name = "<option>\n";
  60. for (@{ $form->{"all_$form->{vc}"} }) { $name .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  61. $name = qq|<select name=$form->{vc}>$name</select>|;
  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 = ( invoice => { title => 'Sales Invoices', name => 'Customer' },
  69. packing_list => { title => 'Packing Lists', name => 'Customer' },
  70. pick_list => { title => 'Pick Lists', name => 'Customer' },
  71. sales_order => { title => 'Sales Orders', name => 'Customer' },
  72. work_order => { title => 'Work Orders', name => 'Customer' },
  73. purchase_order => { title => 'Purchase Orders', name => 'Vendor' },
  74. bin_list => { title => 'Bin Lists', name => 'Vendor' },
  75. sales_quotation => { title => 'Quotations', name => 'Customer' },
  76. request_quotation => { title => 'RFQs', name => 'Vendor' },
  77. timecard => { title => 'Time Cards', name => 'Employee' },
  78. );
  79. $label{invoice}{invnumber} = qq|
  80. <tr>
  81. <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
  82. <td colspan=3><input name=invnumber size=20></td>
  83. </tr>
  84. |;
  85. $label{invoice}{ordnumber} = qq|
  86. <tr>
  87. <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
  88. <td colspan=3><input name=ordnumber size=20></td>
  89. </tr>
  90. |;
  91. $label{sales_quotation}{quonumber} = qq|
  92. <tr>
  93. <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
  94. <td colspan=3><input name=quonumber size=20></td>
  95. </tr>
  96. |;
  97. $label{packing_list}{invnumber} = $label{invoice}{invnumber};
  98. $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
  99. $label{pick_list}{invnumber} = $label{invoice}{invnumber};
  100. $label{pick_list}{ordnumber} = $label{invoice}{ordnumber};
  101. $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
  102. $label{work_order}{ordnumber} = $label{invoice}{ordnumber};
  103. $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
  104. $label{bin_list}{ordnumber} = $label{invoice}{ordnumber};
  105. $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
  106. # do one call to text
  107. $form->{title} = $locale->text('Print')." ".$locale->text($label{$form->{type}}{title});
  108. # accounting years
  109. if (@{ $form->{all_years} }) {
  110. # accounting years
  111. $form->{selectaccountingyear} = "<option>\n";
  112. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  113. $form->{selectaccountingmonth} = "<option>\n";
  114. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  115. $selectfrom = qq|
  116. <tr>
  117. <th align=right>|.$locale->text('Period').qq|</th>
  118. <td colspan=3>
  119. <select name=month>$form->{selectaccountingmonth}</select>
  120. <select name=year>$form->{selectaccountingyear}</select>
  121. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  122. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  123. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  124. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  125. </td>
  126. </tr>
  127. |;
  128. }
  129. $form->header;
  130. print qq|
  131. <body>
  132. <form method=post action=$form->{script}>
  133. |;
  134. $form->hide_form(qw(vc type title));
  135. print qq|
  136. <table width=100%>
  137. <tr><th class=listtop>$form->{title}</th></tr>
  138. <tr height="5"></tr>
  139. <tr>
  140. <td>
  141. <table>
  142. <tr>
  143. <th align=right>|.$locale->text($label{$form->{type}}{name}).qq|</th>
  144. <td colspan=3>$name</td>
  145. </tr>
  146. $account
  147. $label{$form->{type}}{invnumber}
  148. $label{$form->{type}}{ordnumber}
  149. $label{$form->{type}}{quonumber}
  150. <tr>
  151. <th align=right nowrap>|.$locale->text('From').qq|</th>
  152. <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  153. <th align=right>|.$locale->text('To').qq|</th>
  154. <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  155. </tr>
  156. $selectfrom
  157. </table>
  158. </td>
  159. </tr>
  160. <tr>
  161. <td><hr size=3 noshade></td>
  162. </tr>
  163. </table>
  164. <input type=hidden name=sort value=transdate>
  165. <input type=hidden name=nextsub value=list_spool>
  166. <br>
  167. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  168. |;
  169. $form->hide_form(qw(path login sessionid));
  170. print qq|
  171. </form>
  172. </body>
  173. </html>
  174. |;
  175. }
  176. sub remove {
  177. $selected = 0;
  178. for $i (1 .. $form->{rowcount}) {
  179. if ($form->{"checked_$i"}) {
  180. $selected = 1;
  181. last;
  182. }
  183. }
  184. $form->error('Nothing selected!') unless $selected;
  185. $form->{title} = $locale->text('Confirm!');
  186. $form->header;
  187. print qq|
  188. <body>
  189. <form method=post action=$form->{script}>
  190. |;
  191. for (qw(action header)) { delete $form->{$_} }
  192. foreach $key (keys %$form) {
  193. print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
  194. }
  195. print qq|
  196. <h2 class=confirm>$form->{title}</h2>
  197. <h4>|.$locale->text('Are you sure you want to remove the marked entries from the queue?').qq|</h4>
  198. <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
  199. </form>
  200. </body>
  201. </html>
  202. |;
  203. }
  204. sub yes {
  205. $form->info($locale->text('Removing marked entries from queue ...'));
  206. $form->{callback} .= "&header=1" if $form->{callback};
  207. if (BP->delete_spool(\%myconfig, \%$form, $spool)) {
  208. $form->redirect($locale->text('Removed spoolfiles!'));
  209. } else {
  210. $form->error($locale->text('Cannot remove files!'));
  211. }
  212. }
  213. sub print {
  214. if ($form->{callback}) {
  215. for (1 .. $form->{rowcount}) { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
  216. $form->{callback} .= "&header=1";
  217. }
  218. for $i (1 .. $form->{rowcount}) {
  219. if ($form->{"checked_$i"}) {
  220. $form->{OUT} = "| $printer{$form->{media}}";
  221. $form->info($locale->text('Printing')." ...");
  222. if (BP->print_spool(\%myconfig, \%$form, $spool)) {
  223. print $locale->text('done');
  224. $form->redirect($locale->text('Marked entries printed!'));
  225. }
  226. exit;
  227. }
  228. }
  229. $form->error('Nothing selected!');
  230. }
  231. sub list_spool {
  232. $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}});
  233. ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
  234. BP->get_spoolfiles(\%myconfig, \%$form);
  235. $title = $form->escape($form->{title});
  236. $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";
  237. $form->sort_order();
  238. $title = $form->escape($form->{title},1);
  239. $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";
  240. if ($form->{$form->{vc}}) {
  241. $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1);
  242. $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}});
  243. $option = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
  244. $option .= " : $form->{$form->{vc}}";
  245. }
  246. if ($form->{account}) {
  247. $callback .= "&account=".$form->escape($form->{account},1);
  248. $href .= "&account=".$form->escape($form->{account});
  249. $option .= "\n<br>" if ($option);
  250. $option .= $locale->text('Account')." : $form->{account}";
  251. }
  252. if ($form->{invnumber}) {
  253. $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
  254. $href .= "&invnumber=".$form->escape($form->{invnumber});
  255. $option .= "\n<br>" if ($option);
  256. $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
  257. }
  258. if ($form->{ordnumber}) {
  259. $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
  260. $href .= "&ordnumber=".$form->escape($form->{ordnumber});
  261. $option .= "\n<br>" if ($option);
  262. $option .= $locale->text('Order Number')." : $form->{ordnumber}";
  263. }
  264. if ($form->{quonumber}) {
  265. $callback .= "&quonumber=".$form->escape($form->{quonumber},1);
  266. $href .= "&quonumber=".$form->escape($form->{quonumber});
  267. $option .= "\n<br>" if ($option);
  268. $option .= $locale->text('Quotation Number')." : $form->{quonumber}";
  269. }
  270. if ($form->{transdatefrom}) {
  271. $callback .= "&transdatefrom=$form->{transdatefrom}";
  272. $href .= "&transdatefrom=$form->{transdatefrom}";
  273. $option .= "\n<br>" if ($option);
  274. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
  275. }
  276. if ($form->{transdateto}) {
  277. $callback .= "&transdateto=$form->{transdateto}";
  278. $href .= "&transdateto=$form->{transdateto}";
  279. $option .= "\n<br>" if ($option);
  280. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
  281. }
  282. $name = ucfirst $form->{vc};
  283. @columns = qw(transdate);
  284. if ($form->{type} =~ /(invoice)/) {
  285. push @columns, "invnumber";
  286. }
  287. if ($form->{type} =~ /(packing|pick)_list/) {
  288. push @columns, "invnumber";
  289. }
  290. if ($form->{type} =~ /_(order|list)$/) {
  291. push @columns, "ordnumber";
  292. }
  293. if ($form->{type} =~ /_quotation$/) {
  294. push @columns, "quonumber";
  295. }
  296. if ($form->{type} eq 'timecard') {
  297. push @columns, "id";
  298. }
  299. push @columns, (name, spoolfile);
  300. @column_index = $form->sort_columns(@columns);
  301. unshift @column_index, "checked";
  302. $column_header{checked} = "<th class=listheading>&nbsp;</th>";
  303. $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
  304. $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
  305. $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
  306. $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>";
  307. $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text($name)."</a></th>";
  308. $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
  309. $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>";
  310. $form->header;
  311. print qq|
  312. <body>
  313. <form method=post action=$form->{script}>
  314. <table width=100%>
  315. <tr>
  316. <th class=listtop>$form->{title}</th>
  317. </tr>
  318. <tr height="5"></tr>
  319. <tr>
  320. <td>$option</td>
  321. </tr>
  322. <tr>
  323. <td>
  324. <table width=100%>
  325. <tr class=listheading>
  326. |;
  327. for (@column_index) { print "\n$column_header{$_}" }
  328. print qq|
  329. </tr>
  330. |;
  331. # add sort and escape callback, this one we use for the add sub
  332. $form->{callback} = $callback .= "&sort=$form->{sort}";
  333. # escape callback for href
  334. $callback = $form->escape($callback);
  335. $i = 0;
  336. foreach $ref (@{ $form->{SPOOL} }) {
  337. $i++;
  338. $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
  339. # this is for audittrail
  340. $form->{module} = $ref->{module};
  341. if ($ref->{invoice}) {
  342. $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
  343. }
  344. $module = "$ref->{module}.pl";
  345. $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
  346. if ($spoolfile eq $ref->{spoolfile}) {
  347. $column_data{checked} = qq|<td></td>|;
  348. } else {
  349. $column_data{checked} = qq|<td><input name=checked_$i type=checkbox class=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
  350. }
  351. for (qw(id invnumber ordnumber quonumber)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
  352. if ($ref->{module} eq 'oe') {
  353. $column_data{invnumber} = qq|<td>&nbsp</td>|;
  354. $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>
  355. <input type=hidden name="reference_$i" value="$ref->{ordnumber}">|;
  356. $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>
  357. <input type=hidden name="reference_$i" value="$ref->{quonumber}">|;
  358. } elsif ($ref->{module} eq 'jc') {
  359. $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>
  360. <input type=hidden name="reference_$i" value="$ref->{id}">|;
  361. } else {
  362. $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>
  363. <input type=hidden name="reference_$i" value="$ref->{invnumber}">|;
  364. }
  365. $column_data{name} = "<td>$ref->{name}</td>";
  366. $column_data{spoolfile} = qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
  367. |;
  368. $spoolfile = $ref->{spoolfile};
  369. $j++; $j %= 2;
  370. print "
  371. <tr class=listrow$j>
  372. ";
  373. for (@column_index) { print "\n$column_data{$_}" }
  374. print qq|
  375. <input type=hidden name="id_$i" value=$ref->{id}>
  376. <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
  377. </tr>
  378. |;
  379. }
  380. print qq|
  381. <input type=hidden name=rowcount value=$i>
  382. </table>
  383. </td>
  384. </tr>
  385. <tr>
  386. <td><hr size=3 noshade></td>
  387. </tr>
  388. </table>
  389. <br>
  390. |;
  391. $form->hide_form(qw(callback title vc type sort module account path login sessionid));
  392. if (%printer && $latex) {
  393. foreach $key (sort keys %printer) {
  394. print qq|
  395. <input name=media type=radio class=radio value="$key" |;
  396. print qq|checked| if $key eq $myconfig{printer};
  397. print qq|>$key|;
  398. }
  399. print qq|<p>\n|;
  400. # type=submit $locale->text('Select all')
  401. # type=submit $locale->text('Print')
  402. # type=submit $locale->text('Remove')
  403. %button = ('Select all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
  404. 'Print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
  405. 'Remove' => { ndx => 4, key => 'R', value => $locale->text('Remove') },
  406. );
  407. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  408. }
  409. if ($form->{menubar}) {
  410. require "$form->{path}/menu.pl";
  411. &menubar;
  412. }
  413. print qq|
  414. </form>
  415. </body>
  416. </html>
  417. |;
  418. }
  419. sub select_all {
  420. for (1 .. $form->{rowcount}) { $form->{"checked_$_"} = 1 }
  421. &list_spool;
  422. }
  423. sub continue { &{ $form->{nextsub} } };