1#===================================================================== 2# SQL-Ledger 3# Copyright (c) DWS Systems Inc. 4# 5# Author: DWS Systems Inc. 6# Web: http://www.sql-ledger.com 7# 8#====================================================================== 9# 10# Batch printing 11# 12#====================================================================== 13 14 15use SL::BP; 16require "$form->{path}/js.pl"; 17 181; 19# end of main 20 21 22# this is for our long dates 23# $locale->text('January') 24# $locale->text('February') 25# $locale->text('March') 26# $locale->text('April') 27# $locale->text('May ') 28# $locale->text('June') 29# $locale->text('July') 30# $locale->text('August') 31# $locale->text('September') 32# $locale->text('October') 33# $locale->text('November') 34# $locale->text('December') 35 36# this is for our short month 37# $locale->text('Jan') 38# $locale->text('Feb') 39# $locale->text('Mar') 40# $locale->text('Apr') 41# $locale->text('May') 42# $locale->text('Jun') 43# $locale->text('Jul') 44# $locale->text('Aug') 45# $locale->text('Sep') 46# $locale->text('Oct') 47# $locale->text('Nov') 48# $locale->text('Dec') 49 50 51sub search { 52 53# $locale->text('Invoices') 54# $locale->text('Remittance Vouchers') 55# $locale->text('Packing Lists') 56# $locale->text('Pick Lists') 57# $locale->text('Sales Orders') 58# $locale->text('Work Orders') 59# $locale->text('Purchase Orders') 60# $locale->text('Bin Lists') 61# $locale->text('Quotations') 62# $locale->text('RFQs') 63# $locale->text('Time Cards') 64# $locale->text('Stores Cards') 65 66# $locale->text('Customer') 67# $locale->text('Customer Number') 68# $locale->text('Vendor') 69# $locale->text('Vendor Number') 70# $locale->text('Employee') 71# $locale->text('Employee Number') 72 73 %label = ( invoice => { title => 'Invoices', name => ['Customer','Vendor'] }, 74 remittance_voucher => { title => 'Remittance Vouchers', name => ['Customer'] }, 75 packing_list => { title => 'Packing Lists', name => ['Customer', 'Vendor'] }, 76 pick_list => { title => 'Pick Lists', name => ['Customer','Vendor'] }, 77 sales_order => { title => 'Sales Orders', name => ['Customer'] }, 78 work_order => { title => 'Work Orders', name => ['Customer'] }, 79 purchase_order => { title => 'Purchase Orders', name => ['Vendor'] }, 80 bin_list => { title => 'Bin Lists', name => ['Customer', 'Vendor'] }, 81 sales_quotation => { title => 'Quotations', name => ['Customer'] }, 82 request_quotation => { title => 'RFQs', name => ['Vendor'] }, 83 timecard => { title => 'Time Cards', name => ['Employee'] }, 84 storescard => { title => 'Stores Cards', name => ['Employee'] }, 85 ); 86 87 $label{invoice}{invnumber} = qq| 88 <tr> 89 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> 90 <td colspan=3><input name=invnumber size=20></td> 91 </tr> 92|; 93 $label{invoice}{ordnumber} = qq| 94 <tr> 95 <th align=right nowrap>|.$locale->text('Order Number').qq|</th> 96 <td colspan=3><input name=ordnumber size=20></td> 97 </tr> 98|; 99 $label{sales_quotation}{quonumber} = qq| 100 <tr> 101 <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th> 102 <td colspan=3><input name=quonumber size=20></td> 103 </tr> 104|; 105 106 $label{remittance_voucher}{invnumber} = $label{invoice}{invnumber}; 107 $label{packing_list}{invnumber} = $label{invoice}{invnumber}; 108 $label{packing_list}{ordnumber} = $label{invoice}{ordnumber}; 109 $label{pick_list}{invnumber} = $label{invoice}{invnumber}; 110 $label{pick_list}{ordnumber} = $label{invoice}{ordnumber}; 111 $label{sales_order}{ordnumber} = $label{invoice}{ordnumber}; 112 $label{work_order}{ordnumber} = $label{invoice}{ordnumber}; 113 $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber}; 114 $label{bin_list}{invnumber} = $label{invoice}{invnumber}; 115 $label{bin_list}{ordnumber} = $label{invoice}{ordnumber}; 116 $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber}; 117 118 $label{print}{title} = "Print"; 119 $label{queue}{title} = "Queued"; 120 $label{email}{title} = "E-mail"; 121 122 $checked{$form->{batch}} = "checked"; 123 124# $locale->text('Print') 125# $locale->text('Queued') 126# $locale->text('E-mail') 127 128 $form->{title} = $locale->text($label{$form->{batch}}{title})." ".$locale->text($label{$form->{type}}{title}); 129 130 if ($form->{batch} ne 'queue') { 131 $onhold = qq| 132 <input name=onhold class=checkbox type=checkbox value=Y> |.$locale->text('On Hold'); 133 134 @f = qw(invoice packing_list pick_list bin_list); 135 136 if (! grep /$form->{type}/, @f) { 137 $onhold = ""; 138 } 139 140 $openclosed = qq| 141 <tr> 142 <td></td> 143 <td colspan=3 nowrap><input name=open class=checkbox type=checkbox value=Y checked> |.$locale->text('Open').qq| 144 <input name=closed class=checkbox type=checkbox value=Y> |.$locale->text('Closed').qq| 145 $onhold 146 <input name="printed" class=checkbox type=checkbox value=Y> |.$locale->text('Printed').qq| 147 <input name="notprinted" class=checkbox type=checkbox value=Y $checked{print}> |.$locale->text('Not Printed').qq| 148 <input name="emailed" class=checkbox type=checkbox value=Y> |.$locale->text('E-mailed').qq| 149 <input name="notemailed" class=checkbox type=checkbox value=Y $checked{email}> |.$locale->text('Not E-mailed').qq| 150 </td> 151 </tr> 152|; 153 } 154 155 156 # setup customer/vendor/employee selection 157 if (! BP->get_vc(\%myconfig, \%$form)) { 158 if ($form->{batch} eq 'queue') { 159 $form->error($locale->text('Nothing in the Queue!')); 160 } 161 } 162 163 if ($form->{vc}) { 164 @{ $label{$form->{type}}{name} } = (ucfirst $form->{vc}); 165 } 166 167 $k = 0; 168 foreach $vc (@{ $label{$form->{type}}{name} }) { 169 $vcn = lc $vc; 170 if ($form->{$vcn}) { 171 $k++; 172 if (@{ $form->{"all_$vcn"} }) { 173 174 $form->{"select$vcn"} = qq| 175 <tr> 176 <th align=right>|.$locale->text($vc).qq|</th> 177 <td colspan=3><select name=$vcn><option>\n|; 178 179 for (@{ $form->{"all_$vcn"} }) { $form->{"select$vcn"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } 180 181 $form->{"select$vcn"} .= qq|<option value="1--0">|.$locale->text('None') if $k > 1; 182 183 $form->{"select$vcn"} .= qq|</select></tr> 184 <input type=hidden name="print$vcn" value=Y>|; 185 186 } else { 187 $form->{"select$vcn"} = qq| 188 <tr> 189 <th align=right>|.$locale->text($vc).qq|</th> 190 <td colspan=3><input name=$vcn size=35>|; 191 192 if ($#{$label{$form->{type}}{name}} > 0) { 193 $form->{"select$vcn"} .= qq| 194 <input name=print$vcn type=checkbox class=checkbox value=Y checked>|; 195 } else { 196 $form->{"select$vcn"} .= qq| 197 <input name=print$vcn type=hidden value="Y">|; 198 199 } 200 201 $vcnumber = "$vc Number"; 202 $form->{"select$vcn"} .= qq| 203 </td> 204 </tr> 205 <tr> 206 <th align=right>|.$locale->text($vcnumber).qq|</th> 207 <td colspan=3><input name="${vcn}number" size=35></td> 208 </tr>|; 209 210 } 211 } 212 } 213 214 if (@{ $form->{all_project} }) { 215 if ($form->{type} eq 'timecard') { 216 $projectlabel = $locale->text('Project Number'); 217 } 218 219 if ($form->{type} eq 'storescard') { 220 $projectlabel = $locale->text('Job Number'); 221 } 222 223 $selectprojectnumber = "\n"; 224 for (@{ $form->{all_project} }) { $selectprojectnumber .= qq|$_->{projectnumber}--$_->{id}\n| } 225 226 $projectnumber = qq| 227 <tr> 228 <th align=right>$projectlabel</th> 229 <td colspan=3><select name=projectnumber>|.$form->select_option($selectprojectnumber, $form->{projectnumber}, 1) 230 .qq|</select></td> 231 </tr> 232|; 233 } 234 235 if ($form->{type} eq 'remittance_voucher' || $form->{type} eq 'invoice') { 236 if (@{ $form->{all_paymentmethod} }) { 237 $paymentmethod = qq| 238 <tr> 239 <th align=right>|.$locale->text('Payment Method').qq|</th> 240 <td colspan=3><select name=paymentmethod><option>\n|; 241 242 for (@{ $form->{all_paymentmethod} }) { $paymentmethod .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } 243 $paymentmethod .= qq|</select></tr>|; 244 } 245 } 246 247 # accounting years 248 if (@{ $form->{all_years} }) { 249 # accounting years 250 $selectaccountingyear = "\n"; 251 for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| } 252 $selectaccountingmonth = "\n"; 253 for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| } 254 255 $selectfrom = qq| 256 <tr> 257 <th align=right>|.$locale->text('Period').qq|</th> 258 <td colspan=3 nowrap> 259 <select name=month>|.$form->select_option($selectaccountingmonth, undef, 1, 1).qq|</select> 260 <select name=year>|.$form->select_option($selectaccountingyear).qq|</select> 261 <input name=interval class=radio type=radio value=0 checked> |.$locale->text('Current').qq| 262 <input name=interval class=radio type=radio value=1> |.$locale->text('Month').qq| 263 <input name=interval class=radio type=radio value=3> |.$locale->text('Quarter').qq| 264 <input name=interval class=radio type=radio value=12> |.$locale->text('Year').qq| 265 </td> 266 </tr> 267|; 268 } 269 270 $form->{sort} = "transdate"; 271 $form->{nextsub} = "list_spool"; 272 273 $form->helpref("bp_$form->{type}", $myconfig{countrycode}); 274 275 $form->header; 276 277 &calendar; 278 279 print qq| 280<body> 281 282<form method="post" name="main" action="$form->{script}"> 283|; 284 285 $form->hide_form(qw(batch sort nextsub type title)); 286 287 print qq| 288<table width=100%> 289 <tr><th class=listtop>$form->{helpref}$form->{title}</a></th></tr> 290 <tr height="5"></tr> 291 <tr> 292 <td> 293 <table> 294 $form->{selectcustomer} 295 $form->{selectvendor} 296 $form->{selectemployee} 297 $account 298 $label{$form->{type}}{invnumber} 299 $label{$form->{type}}{ordnumber} 300 $label{$form->{type}}{quonumber} 301 $projectnumber 302 <tr> 303 <th align=right nowrap>|.$locale->text('Description').qq|</th> 304 <td><input name=description size=40></td> 305 </tr> 306 $paymentmethod 307 <tr> 308 <th align=right nowrap>|.$locale->text('From').qq|</th> 309 <td><input name=transdatefrom size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "transdatefrom").qq| 310 <b>|.$locale->text('To').qq|</b> 311 <input name=transdateto size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "transdateto").qq|</td> 312 </tr> 313 $selectfrom 314 $openclosed 315 </table> 316 </td> 317 </tr> 318 <tr> 319 <td><hr size=3 noshade></td> 320 </tr> 321</table> 322 323<br> 324<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> 325|; 326 327 $form->hide_form(qw(path login)); 328 329 print qq| 330 331</form> 332 333</body> 334</html> 335|; 336 337} 338 339 340 341sub remove { 342 343 $selected = 0; 344 345 for $i (1 .. $form->{rowcount}) { 346 if ($form->{"ndx_$i"}) { 347 $selected = 1; 348 last; 349 } 350 } 351 352 $form->error('Nothing selected!') unless $selected; 353 354 $form->{title} = $locale->text('Confirm!'); 355 356 $form->header; 357 358 print qq| 359<body> 360 361<form method=post action=$form->{script}> 362|; 363 364 for (qw(action header)) { delete $form->{$_} } 365 366 $form->hide_form; 367 368 print qq| 369<h2 class=confirm>$form->{title}</h2> 370 371<h4>|.$locale->text('Are you sure you want to remove the marked entries from the queue?').qq|</h4> 372 373<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> 374</form> 375 376</body> 377</html> 378|; 379 380} 381 382 383 384sub yes { 385 386 $form->info($locale->text('Removing marked entries from queue ...')); 387 $form->{callback} .= "&header=1" if $form->{callback}; 388 389 if (BP->delete_spool(\%myconfig, \%$form, $spool)) { 390 $form->redirect($locale->text('Removed spoolfiles!')); 391 } else { 392 $form->error($locale->text('Cannot remove files!')); 393 } 394 395} 396 397 398 399sub print { 400 401 $myform = new Form; 402 403 for (keys %$form) { 404 $myform->{$_} = $form->{$_}; 405 delete $form->{$_}; 406 } 407 408 %msg = ( print => $locale->text('Printing'), 409 email => $locale->text('E-mailing'), 410 ); 411 412 $ok = 0; 413 $myconfig{vclimit} = 0; 414 $r = 1; 415 $total = 0; 416 417 for $i (1 .. $myform->{rowcount}) { 418 419 if ($myform->{"ndx_$i"}) { 420 421 $ok = 1; 422 423 if ($myform->{batch} eq 'queue') { 424 if (open(FH, qq|$spool/$myconfig{dbname}/$myform->{"spoolfile_$i"}|)) { 425 binmode FH; 426 427 if (open(OUT, qq~| $myform->{"$myform->{media}_printer"}~)) { 428 binmode OUT; 429 430 $myform->info(qq|$msg{print} ... $myform->{"spoolfile_$i"}\n|); 431 432 while (<FH>) { 433 print OUT $_; 434 } 435 436 close(OUT); 437 close(FH); 438 } else { 439 $myform->info($!); 440 } 441 } else { 442 $myform->info($!); 443 } 444 } else { 445 446 for (keys %$form) { delete $form->{$_} } 447 448 for (qw(id vc)) { $form->{$_} = $myform->{"${_}_$i"} } 449 $form->{script} = $myform->{"module_$i"}; 450 for (qw(login path media sendmode subject message format type header copies)) { $form->{$_} = $myform->{$_} } 451 452 do "$form->{path}/$form->{script}"; 453 454 $form->{linkshipto} = 1; 455 456 if ($myform->{"module_$i"} eq 'oe') { 457 &order_links; 458 &prepare_order; 459 $form->{formname} = $myform->{type}; 460 $inv = 'ord' 461 } elsif ($myform->{"module_$i"} eq 'jc') { 462 $form->{formname} = $myform->{type}; 463 &{"prepare_$myform->{type}"}; 464 } else { 465 &invoice_links; 466 &prepare_invoice; 467 if ($myform->{type} ne 'invoice') { 468 $form->{formname} = $myform->{type}; 469 } 470 delete $form->{paid}; 471 472 $arap = ($form->{vc} eq 'customer') ? "AR" : "AP"; 473 $form->{payment_accno} = $form->unescape($form->{payment_accno}); 474 475 # default 476 @f = split /\n/, $form->unescape($form->{"select${arap}_paid"}); 477 $form->{payment_accno} ||= $f[0]; 478 479 for (1 .. $form->{paidaccounts}) { 480 $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, $form->{precision}); 481 $form->{payment_accno} = $form->{"${arap}_paid_$_"}; 482 } 483 484 $form->{"${arap}_paid_$form->{paidaccounts}"} = $form->{payment_accno}; 485 $inv = 'inv'; 486 } 487 488 $form->{rowcount}++; 489 490 # unquote variables 491 if ($form->{media} eq 'email' || $form->{media} eq 'queue') { 492 for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) } 493 } 494 495 $myform->{description} = $form->{description}; 496 497 $form->fdld(\%myconfig, \%$locale); 498 499 &print_form; 500 501 $myform->info(qq|${r}. $msg{$myform->{batch}} ... $myform->{"reference_$i"}|); 502 $myform->info(qq|, $myform->{description}|) if $myform->{description}; 503 504 if ($myform->{"module_$i"} ne 'jc') { 505 if ($form->{formname} =~ /_invoice/) { 506 $total -= $form->parse_amount(\%myconfig, $form->{"${inv}total"}); 507 } else { 508 $total += $form->parse_amount(\%myconfig, $form->{"${inv}total"}); 509 } 510 $myform->info(qq|, $form->{"${inv}total"}, $form->{"$form->{vc}number"}, $form->{"$form->{vc}"} $form->{city}|); 511 } 512 $myform->info(" ... ".$locale->text('ok')."\n"); 513 514 $r++; 515 } 516 } 517 } 518 519 $myform->info($locale->text('Total').": ".$form->format_amount(\%myconfig, $total, $myform->{precision})) if $total; 520 521 for (keys %$form) { delete $form->{$_} } 522 for (keys %$myform) { $form->{$_} = $myform->{$_} } 523 524 if ($ok) { 525 $form->{callback} = ""; 526 $form->redirect; 527 } else { 528 $form->error($locale->text('Nothing selected!')); 529 } 530 531} 532 533 534sub e_mail { &print } 535 536 537sub list_spool { 538 539 BP->get_spoolfiles(\%myconfig, \%$form); 540 541 @f = qw(direction oldsort path login type printcustomer printvendor batch allbox); 542 $href = "$form->{script}?action=list_spool"; 543 for (@f) { $href .= "&$_=$form->{$_}" } 544 $href .= "&title=".$form->escape($form->{title}); 545 546 547 $form->sort_order(); 548 549 $callback = "$form->{script}?action=list_spool"; 550 for (@f) { $callback .= "&$_=$form->{$_}" } 551 $callback .= "&title=".$form->escape($form->{title},1); 552 553 %vc = ( customer => { name => 'Customer', number => 'Customer Number' }, 554 vendor => { name => 'Vendor', number => 'Vendor Number' }, 555 employee => { name => 'Employee', number => 'Employee Number' } 556 ); 557 558 for (qw(customer vendor employee)) { 559 if ($form->{$_}) { 560 $var = qq|$form->{$_}--$form->{"${_}_id"}|; 561 $callback .= "&$_=".$form->escape($var,1); 562 $href .= "&$_=".$form->escape($var); 563 $option .= "\n<br>" if ($option); 564 $option .= $locale->text($vc{$_}{name})." : $form->{$_}"; 565 } 566 if ($form->{"${_}number"}) { 567 $callback .= qq|&${_}number=|.$form->escape($form->{$form->{"${_}number"}},1); 568 $href .= qq|&${_}number=|.$form->escape($form->{$form->{"${_}number"}}); 569 $option .= "\n<br>" if ($option); 570 $option .= $locale->text($vc{$_}{number}).qq| : $form->{"${_}number"}|; 571 } 572 573 } 574 if ($form->{invnumber}) { 575 $callback .= "&invnumber=".$form->escape($form->{invnumber},1); 576 $href .= "&invnumber=".$form->escape($form->{invnumber}); 577 $option .= "\n<br>" if ($option); 578 $option .= $locale->text('Invoice Number')." : $form->{invnumber}"; 579 } 580 if ($form->{ordnumber}) { 581 $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1); 582 $href .= "&ordnumber=".$form->escape($form->{ordnumber}); 583 $option .= "\n<br>" if ($option); 584 $option .= $locale->text('Order Number')." : $form->{ordnumber}"; 585 } 586 if ($form->{quonumber}) { 587 $callback .= "&quonumber=".$form->escape($form->{quonumber},1); 588 $href .= "&quonumber=".$form->escape($form->{quonumber}); 589 $option .= "\n<br>" if ($option); 590 $option .= $locale->text('Quotation Number')." : $form->{quonumber}"; 591 } 592 if ($form->{projectnumber}) { 593 $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1); 594 $href .= "&projectnumber=".$form->escape($form->{projectnumber}); 595 $option .= "\n<br>" if ($option); 596 ($projectnumber) = split /--/, $form->{projectnumber}; 597 $option .= $locale->text('Project Number')." : $projectnumber"; 598 } 599 600 if ($form->{description}) { 601 $callback .= "&description=".$form->escape($form->{description},1); 602 $href .= "&description=".$form->escape($form->{description}); 603 $option .= "\n<br>" if ($option); 604 $option .= $locale->text('Description')." : $form->{description}"; 605 } 606 if ($form->{transdatefrom}) { 607 $callback .= "&transdatefrom=$form->{transdatefrom}"; 608 $href .= "&transdatefrom=$form->{transdatefrom}"; 609 $option .= "\n<br>" if ($option); 610 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); 611 } 612 if ($form->{transdateto}) { 613 $callback .= "&transdateto=$form->{transdateto}"; 614 $href .= "&transdateto=$form->{transdateto}"; 615 $option .= "\n<br>" if ($option); 616 $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); 617 } 618 if ($form->{open}) { 619 $callback .= "&open=$form->{open}"; 620 $href .= "&open=$form->{open}"; 621 $option .= "\n<br>" if ($option); 622 $option .= $locale->text('Open'); 623 } 624 if ($form->{closed}) { 625 $callback .= "&closed=$form->{closed}"; 626 $href .= "&closed=$form->{closed}"; 627 $option .= "\n<br>" if ($option); 628 $option .= $locale->text('Closed'); 629 } 630 if ($form->{onhold}) { 631 $callback .= "&onhold=$form->{onhold}"; 632 $href .= "&onhold=$form->{onhold}"; 633 $option .= "\n<br>" if ($option); 634 $option .= $locale->text('On Hold'); 635 } 636 if ($form->{printed}) { 637 $callback .= "&printed=$form->{printed}"; 638 $href .= "&printed=$form->{printed}"; 639 $option .= "\n<br>" if ($option); 640 $option .= $locale->text('Printed'); 641 } 642 if ($form->{emailed}) { 643 $callback .= "&emailed=$form->{emailed}"; 644 $href .= "&emailed=$form->{emailed}"; 645 $option .= "\n<br>" if ($option); 646 $option .= $locale->text('E-mailed'); 647 } 648 if ($form->{notprinted}) { 649 $callback .= "¬printed=$form->{notprinted}"; 650 $href .= "¬printed=$form->{notprinted}"; 651 $option .= "\n<br>" if ($option); 652 $option .= $locale->text('Not Printed'); 653 } 654 if ($form->{notemailed}) { 655 $callback .= "¬emailed=$form->{notemailed}"; 656 $href .= "¬emailed=$form->{notemailed}"; 657 $option .= "\n<br>" if ($option); 658 $option .= $locale->text('Not E-mailed'); 659 } 660 661 662 @columns = qw(transdate); 663 if ($form->{type} =~ /(packing|pick|bin)_list|invoice|remittance_voucher/) { 664 push @columns, "invnumber"; 665 } 666 if ($form->{type} =~ /_(order|list)$/) { 667 push @columns, "ordnumber"; 668 } 669 if ($form->{type} =~ /_quotation$/) { 670 push @columns, "quonumber"; 671 } 672 if ($form->{type} =~ /(timecard|storescard)/) { 673 push @columns, "id"; 674 } 675 676 push @columns, qw(description name vcnumber); 677 push @columns, "email" if $form->{batch} eq 'email'; 678 push @columns, qw(city amount); 679 push @columns, "spoolfile" if $form->{batch} eq 'queue'; 680 681 @column_index = $form->sort_columns(@columns); 682 unshift @column_index, qw(runningnumber ndx); 683 684 $column_header{runningnumber} = "<th><a class=listheading> </th>"; 685 $form->{allbox} = ($form->{allbox}) ? "checked" : ""; 686 $action = ($form->{deselect}) ? "deselect_all" : "select_all"; 687 $column_header{ndx} = qq|<th class=listheading width=1%><input name="allbox" type=checkbox class=checkbox value="1" $form->{allbox} onChange="CheckAll(); Javascript:document.main.submit()"><input type=hidden name=action value="$action"></th>|; 688 $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>"; 689 $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>"; 690 $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>"; 691 $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>"; 692 $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Name')."</a></th>"; 693 694 $column_header{vcnumber} = "<th><a class=listheading href=$href&sort=vcnumber>".$locale->text('Number')."</a></th>"; 695 696 $column_header{email} = "<th class=listheading>".$locale->text('E-mail')."</th>"; 697 $column_header{city} = "<th class=listheading>".$locale->text('City')."</th>"; 698 $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>"; 699 $column_header{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>"; 700 $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>"; 701 $column_header{amount} = "<th class=listheading>".$locale->text('Amount')."</th>"; 702 703 $form->helpref("list_spool", $myconfig{countrycode}); 704 705 $form->header; 706 707 &check_all(qw(allbox ndx_)); 708 709print qq| 710<body> 711 712<form method="post" name="main" action="$form->{script}"> 713 714<table width=100%> 715 <tr> 716 <th class=listtop>$form->{helpref}$form->{title}</a></th> 717 </tr> 718 <tr height="5"></tr> 719 <tr> 720 <td>$option</td> 721 </tr> 722 <tr> 723 <td> 724 <table width=100%> 725 <tr class=listheading> 726|; 727 728 for (@column_index) { print "\n$column_header{$_}" } 729 730 print qq| 731 </tr> 732|; 733 734 735 # add sort and escape callback, this one we use for the add sub 736 $form->{callback} = $callback .= "&sort=$form->{sort}"; 737 738 # escape callback for href 739 $callback = $form->escape($callback); 740 741 $i = 0; 742 $totalamount = 0; 743 744 foreach $ref (@{ $form->{SPOOL} }) { 745 746 $i++; 747 748 if ($form->{"ndx_$i"}) { 749 $form->{"ndx_$i"} = "checked"; 750 } 751 752 $totalamount += $ref->{amount}; 753 754 # this one is for printing spool entries 755 $form->{tablename} = $ref->{tablename}; 756 757 $module = $ref->{tablename}; 758 if ($ref->{tablename} eq 'jcitems') { 759 $module = 'jc'; 760 } 761 if ($ref->{invoice}) { 762 $module = ($ref->{tablename} eq 'ar') ? "is" : "ir"; 763 } 764 $module .= ".pl"; 765 766 $column_data{amount} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{amount}, $form->{precision}).qq|</td>|; 767 768 $column_data{ndx} = qq|<td><input name="ndx_$i" type=checkbox class=checkbox $form->{"ndx_$i"} $form->{"ndx_$i"}></td>|; 769 770 if ($form->{batch} eq 'queue') { 771 if ($spoolfile eq $ref->{spoolfile}) { 772 $column_data{ndx} = qq|<td></td>|; 773 } 774 } 775 776 $column_data{runningnumber} = qq|<td>$i</td>|; 777 778 for (qw(description email city id invnumber ordnumber quonumber vcnumber)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| } 779 $column_data{transdate} = qq|<td nowrap>$ref->{transdate}</td>|; 780 781 $column_data{name} = qq|<td><a href=ct.pl?action=edit&id=$ref->{vc_id}&db=$ref->{db}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{name}</a></td>|; 782 783 if ($ref->{tablename} eq 'oe') { 784 $column_data{invnumber} = qq|<td> </td>|; 785 $column_data{ordnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td> 786 <input type=hidden name="reference_$i" value="|.$form->quote($ref->{ordnumber}).qq|">|; 787 788 $column_data{quonumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td> 789 <input type=hidden name="reference_$i" value="|.$form->quote($ref->{quonumber}).qq|">|; 790 791 } elsif ($ref->{tablename} eq 'jc') { 792 $column_data{id} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&type=$form->{type}&callback=$callback>$ref->{id}</a></td> 793 <input type=hidden name="reference_$i" value="$ref->{id}">|; 794 795 $column_data{name} = qq|<td><a href=hr.pl?action=edit&id=$ref->{employee_id}&db=employee&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{name}</a></td>|; 796 } else { 797 $column_data{invnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td> 798 <input type=hidden name="reference_$i" value="|.$form->quote($ref->{invnumber}).qq|">|; 799 } 800 801 $column_data{spoolfile} = qq|<td><a href=$spool/$myconfig{dbname}/$ref->{spoolfile}>$ref->{spoolfile}</a></td> 802|; 803 804 $spoolfile = $ref->{spoolfile}; 805 806 $j++; $j %= 2; 807 print " 808 <tr class=listrow$j> 809"; 810 811 for (@column_index) { print "\n$column_data{$_}" } 812 813 print qq| 814 </tr> 815 816<input type=hidden name="id_$i" value="$ref->{id}"> 817<input type=hidden name="spoolfile_$i" value="$ref->{spoolfile}"> 818<input type=hidden name="vc_$i" value="$ref->{vc}"> 819<input type=hidden name="tablename_$i" value="$ref->{tablename}"> 820<input type=hidden name="module_$i" value="$module"> 821|; 822 } 823 824 for (@column_index) { $column_data{$_} = "<td> </td>" } 825 826 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, $form->{precision}, " ")."</th>"; 827 828 print qq|<tr class=listtotal>|; 829 830 for (@column_index) { print "\n$column_data{$_}" } 831 832 print qq| 833<input type=hidden name=rowcount value=$i> 834 835 </table> 836 </td> 837 </tr> 838 <tr> 839 <td><hr size=3 noshade></td> 840 </tr> 841</table> 842 843<br> 844|; 845 846 $form->hide_form(qw(callback title type sort path login printcustomer printvendor customer customernumber vendor vendornumber employee employeenumber batch invnumber ordnumber quonumber description transdatefrom transdateto open closed onhold printed emailed notprinted notemailed precision)); 847 848 $form->{copies} ||= 1; 849 850 $selectformat = ""; 851 $media = qq|<select name=media>|; 852 853 if ($form->{batch} eq 'email') { 854 $form->{format} ||= "pdf"; 855 $selectformat .= qq|<option value="html">|.$locale->text('html').qq| 856<option value="xml">|.$locale->text('XML').qq| 857<option value="txt">|.$locale->text('Text'); 858 } else { 859 $form->{format} ||= $myconfig{outputformat}; 860 $form->{media} ||= $myconfig{printer}; 861 $form->{format} ||= "ps"; 862 exit if (! $latex && $form->{batch} eq 'print'); 863 } 864 865 if ($latex) { 866 $selectformat .= qq| 867 <option value="ps">|.$locale->text('Postscript').qq| 868 <option value="pdf">|.$locale->text('PDF'); 869 } 870 871 if (@{ $form->{all_printer} } && $form->{batch} ne 'email') { 872 873 for (@{ $form->{all_printer} }) { 874 $media .= qq| 875 <option value="$_->{printer}">$_->{printer}|; 876 } 877 878 $copies = $locale->text('Copies').qq| <input name=copies size=2 value=$form->{copies}>|; 879 880 } 881 882 if ($form->{batch} eq 'email') { 883 $sendmode = qq|<select name="sendmode"> 884 <option value="attachment">|.$locale->text('Attachment').qq| 885 <option value="inline">|.$locale->text('In-line').qq|</select>|; 886 } 887 888 if ($form->{batch} ne 'email') { 889 $media .= qq| 890 <option value="queue">|.$locale->text('Queue') if $form->{batch} eq 'print'; 891 } 892 893 $media .= qq|</select>|; 894 895 $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/; 896 897 $format = qq|<select name=format>$selectformat</select>|; 898 $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/; 899 900 if ($form->{batch} eq 'email') { 901 $sendmode =~ s/(<option value="\Q$form->{sendmode}\E")/$1 selected/; 902 903 $message = qq|<tr> 904 <td nowrap><b>|.$locale->text('Subject').qq|</b> <input name=subject size=60></td> 905 </tr> 906 <tr> 907 <td><b>|.$locale->text('Message').qq|</b><br><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td> 908 </tr>|; 909 910 $media = qq|<input type="hidden" name="media" value="email"> 911|; 912 } 913 if ($form->{batch} eq 'queue') { 914 $format = ""; 915 $copies = ""; 916 $media = "" if ! @{ $form->{all_printer} }; 917 } 918 919 920 print qq| 921<table> 922 $message 923 <tr> 924 <td nowrap=1>$format $sendmode $media $copies</td> 925 </tr> 926</table> 927<p> 928|; 929 930 for (@{ $form->{all_printer} }) { 931 $form->{"$_->{printer}_printer"} = $_->{command}; 932 $form->hide_form("$_->{printer}_printer"); 933 } 934 935 %button = ('Select all' => { ndx => 2, key => 'A', value => $locale->text('Select all') }, 936 'Deselect all' => { ndx => 3, key => 'A', value => $locale->text('Deselect all') }, 937 'Print' => { ndx => 5, key => 'P', value => $locale->text('Print') }, 938 'E-mail' => { ndx => 6, key => 'E', value => $locale->text('E-mail') }, 939 'Combine' => { ndx => 7, key => 'C', value => $locale->text('Combine') }, 940 'Remove' => { ndx => 8, key => 'R', value => $locale->text('Remove') }, 941 ); 942 943 944 if ($form->{deselect}) { 945 delete $button{'Select all'}; 946 } else { 947 delete $button{'Deselect all'}; 948 } 949 950 if ($form->{batch} eq 'print') { 951 delete $button{'E-mail'}; 952 } 953 if ($form->{batch} ne 'queue') { 954 delete $button{'Remove'}; 955 delete $button{'Combine'}; 956 } 957 if ($form->{batch} eq 'email') { 958 delete $button{'Print'}; 959 } 960 if ($form->{batch} eq 'queue') { 961 delete $button{'E-mail'}; 962 delete $button{'Print'} if ! @{ $form->{all_printer} }; 963 } 964 if (!$pdftk) { 965 delete $button{'Combine'}; 966 } 967 968 $form->print_button(\%button); 969 970 971 if ($form->{menubar}) { 972 require "$form->{path}/menu.pl"; 973 &menubar; 974 } 975 976 print qq| 977</form> 978 979</body> 980</html> 981|; 982 983} 984 985 986sub select_all { 987 988 for (1 .. $form->{rowcount}) { $form->{"ndx_$_"} = 1 } 989 $form->{allbox} = 1; 990 $form->{deselect} = 1; 991 &list_spool; 992 993} 994 995 996sub deselect_all { 997 998 for (1 .. $form->{rowcount}) { $form->{"ndx_$_"} = "" } 999 $form->{allbox} = ""; 1000 &list_spool; 1001 1002} 1003 1004 1005sub combine { 1006 1007 use Cwd; 1008 $dir = cwd(); 1009 $files = ""; 1010 1011 for (1 .. $form->{rowcount}) { 1012 if ($form->{"ndx_$_"}) { 1013 if ($form->{"spoolfile_$_"} =~ /\.pdf$/) { 1014 $files .= qq|$form->{"spoolfile_$_"} |; 1015 } 1016 } 1017 } 1018 1019 $form->{format} = "pdf"; 1020 1021 if ($files) { 1022 chdir("$spool/$myconfig{dbname}"); 1023 if ($filename = BP->spoolfile(\%myconfig, \%$form)) { 1024 @args = ("pdftk $files cat output $filename"); 1025 system(@args) % 256 == 0 or $form->error("@args : $?"); 1026 } 1027 } else { 1028 $form->error($locale->text('Nothing selected!')); 1029 } 1030 1031 chdir("$dir"); 1032 1033 $form->redirect; 1034 1035} 1036 1037 1038sub continue { &{ $form->{nextsub} } }; 1039 1040