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