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.pl') { 457 &order_links; 458 &prepare_order; 459 $form->{formname} = $myform->{type}; 460 $inv = ($form->{formname} =~ /_quotation/) ? 'quo' : 'ord'; 461 } elsif ($myform->{"module_$i"} eq 'jc.pl') { 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_$_"} if $form->{"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 if ($form->{media} eq 'email') { 500 if ($inv) { 501 %label = ( invoice => $locale->text('Invoice'), 502 credit_invoice => $locale->text('Credit Invoice'), 503 debit_invoice => $locale->text('Debit Invoice'), 504 remittance_voucher => $locale->text('Remittance Voucher'), 505 sales_order => $locale->text('Sales Order'), 506 work_order => $locale->text('Work Order'), 507 sales_quotation => $locale->text('Quotation'), 508 packing_list => $locale->text('Packing List'), 509 pick_list => $locale->text('Pick List'), 510 purchase_order => $locale->text('Purchase Order'), 511 bin_list => $locale->text('Bin List'), 512 request_quotation => $locale->text('RFQ') 513 ); 514 515 $form->{subject} = qq|$label{$form->{formname}} $form->{"${inv}number"}| unless $form->{subject}; 516 517 $now = scalar localtime; 518 $cc = $locale->text('Cc').qq|: $form->{cc}\n| if $form->{cc}; 519 $bcc = $locale->text('Bcc').qq|: $form->{bcc}\n| if $form->{bcc}; 520 521 $form->{intnotes} = qq|$form->{intnotes}\n\n| if $form->{intnotes}; 522 523 $form->{intnotes} .= qq|[email]\n| 524 .$locale->text('Date').qq|: $now\n| 525 .$locale->text('To').qq|: $form->{email}\n${cc}${bcc}| 526 .$locale->text('Subject').qq|: $form->{subject}\n|; 527 $form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |; 528 $form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent'); 529 $form->save_intnotes(\%myconfig, ($inv =~ /ord|quo/) ? 'oe' : $arap); 530 } 531 } 532 533 &print_form; 534 535 $myform->info(qq|${r}. $msg{$myform->{batch}} ... $myform->{"reference_$i"}|); 536 $myform->info(qq|, $myform->{description}|) if $myform->{description}; 537 538 if ($myform->{"module_$i"} ne 'jc.pl') { 539 if ($form->{formname} =~ /_invoice/) { 540 $total -= $form->parse_amount(\%myconfig, $form->{"${inv}total"}); 541 $form->{"${inv}total"} = qq|($form->{"${inv}total"})| if ($form->{formname} eq "credit_invoice"); 542 } else { 543 $total += $form->parse_amount(\%myconfig, $form->{"${inv}total"}); 544 } 545 $myform->info(qq|, $form->{"${inv}total"}, $form->{"$form->{vc}number"}, $form->{"$form->{vc}"} $form->{city}|); 546 } 547 $myform->info(" ... ".$locale->text('ok')."\n"); 548 549 $r++; 550 } 551 } 552 } 553 554 $myform->info($locale->text('Total').": ".$form->format_amount(\%myconfig, $total, $myform->{precision})) if $total; 555 556 for (keys %$form) { delete $form->{$_} } 557 for (keys %$myform) { $form->{$_} = $myform->{$_} } 558 559 if ($ok) { 560 $form->{callback} = ""; 561 $form->redirect; 562 } else { 563 $form->error($locale->text('Nothing selected!')); 564 } 565 566} 567 568 569sub e_mail { &print } 570 571 572sub list_spool { 573 574 BP->get_spoolfiles(\%myconfig, \%$form); 575 576 @f = qw(direction oldsort path login type printcustomer printvendor batch allbox); 577 $href = "$form->{script}?action=list_spool"; 578 for (@f) { $href .= "&$_=$form->{$_}" } 579 $href .= "&title=".$form->escape($form->{title}); 580 581 582 $form->sort_order(); 583 584 $callback = "$form->{script}?action=list_spool"; 585 for (@f) { $callback .= "&$_=$form->{$_}" } 586 $callback .= "&title=".$form->escape($form->{title},1); 587 588 %vc = ( customer => { name => 'Customer', number => 'Customer Number' }, 589 vendor => { name => 'Vendor', number => 'Vendor Number' }, 590 employee => { name => 'Employee', number => 'Employee Number' } 591 ); 592 593 for (qw(customer vendor employee)) { 594 if ($form->{$_}) { 595 $var = qq|$form->{$_}--$form->{"${_}_id"}|; 596 $callback .= "&$_=".$form->escape($var,1); 597 $href .= "&$_=".$form->escape($var); 598 $option .= "\n<br>" if ($option); 599 $option .= $locale->text($vc{$_}{name})." : $form->{$_}"; 600 } 601 if ($form->{"${_}number"}) { 602 $callback .= qq|&${_}number=|.$form->escape($form->{$form->{"${_}number"}},1); 603 $href .= qq|&${_}number=|.$form->escape($form->{$form->{"${_}number"}}); 604 $option .= "\n<br>" if ($option); 605 $option .= $locale->text($vc{$_}{number}).qq| : $form->{"${_}number"}|; 606 } 607 608 } 609 if ($form->{invnumber}) { 610 $callback .= "&invnumber=".$form->escape($form->{invnumber},1); 611 $href .= "&invnumber=".$form->escape($form->{invnumber}); 612 $option .= "\n<br>" if ($option); 613 $option .= $locale->text('Invoice Number')." : $form->{invnumber}"; 614 } 615 if ($form->{ordnumber}) { 616 $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1); 617 $href .= "&ordnumber=".$form->escape($form->{ordnumber}); 618 $option .= "\n<br>" if ($option); 619 $option .= $locale->text('Order Number')." : $form->{ordnumber}"; 620 } 621 if ($form->{quonumber}) { 622 $callback .= "&quonumber=".$form->escape($form->{quonumber},1); 623 $href .= "&quonumber=".$form->escape($form->{quonumber}); 624 $option .= "\n<br>" if ($option); 625 $option .= $locale->text('Quotation Number')." : $form->{quonumber}"; 626 } 627 if ($form->{projectnumber}) { 628 $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1); 629 $href .= "&projectnumber=".$form->escape($form->{projectnumber}); 630 $option .= "\n<br>" if ($option); 631 ($projectnumber) = split /--/, $form->{projectnumber}; 632 $option .= $locale->text('Project Number')." : $projectnumber"; 633 } 634 635 if ($form->{description}) { 636 $callback .= "&description=".$form->escape($form->{description},1); 637 $href .= "&description=".$form->escape($form->{description}); 638 $option .= "\n<br>" if ($option); 639 $option .= $locale->text('Description')." : $form->{description}"; 640 } 641 if ($form->{transdatefrom}) { 642 $callback .= "&transdatefrom=$form->{transdatefrom}"; 643 $href .= "&transdatefrom=$form->{transdatefrom}"; 644 $option .= "\n<br>" if ($option); 645 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); 646 } 647 if ($form->{transdateto}) { 648 $callback .= "&transdateto=$form->{transdateto}"; 649 $href .= "&transdateto=$form->{transdateto}"; 650 $option .= "\n<br>" if ($option); 651 $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); 652 } 653 if ($form->{open}) { 654 $callback .= "&open=$form->{open}"; 655 $href .= "&open=$form->{open}"; 656 $option .= "\n<br>" if ($option); 657 $option .= $locale->text('Open'); 658 } 659 if ($form->{closed}) { 660 $callback .= "&closed=$form->{closed}"; 661 $href .= "&closed=$form->{closed}"; 662 $option .= "\n<br>" if ($option); 663 $option .= $locale->text('Closed'); 664 } 665 if ($form->{onhold}) { 666 $callback .= "&onhold=$form->{onhold}"; 667 $href .= "&onhold=$form->{onhold}"; 668 $option .= "\n<br>" if ($option); 669 $option .= $locale->text('On Hold'); 670 } 671 if ($form->{printed}) { 672 $callback .= "&printed=$form->{printed}"; 673 $href .= "&printed=$form->{printed}"; 674 $option .= "\n<br>" if ($option); 675 $option .= $locale->text('Printed'); 676 } 677 if ($form->{emailed}) { 678 $callback .= "&emailed=$form->{emailed}"; 679 $href .= "&emailed=$form->{emailed}"; 680 $option .= "\n<br>" if ($option); 681 $option .= $locale->text('E-mailed'); 682 } 683 if ($form->{notprinted}) { 684 $callback .= "¬printed=$form->{notprinted}"; 685 $href .= "¬printed=$form->{notprinted}"; 686 $option .= "\n<br>" if ($option); 687 $option .= $locale->text('Not Printed'); 688 } 689 if ($form->{notemailed}) { 690 $callback .= "¬emailed=$form->{notemailed}"; 691 $href .= "¬emailed=$form->{notemailed}"; 692 $option .= "\n<br>" if ($option); 693 $option .= $locale->text('Not E-mailed'); 694 } 695 696 697 @columns = qw(transdate); 698 if ($form->{type} =~ /(packing|pick|bin)_list|invoice|remittance_voucher/) { 699 push @columns, "invnumber"; 700 } 701 if ($form->{type} =~ /_(order|list)$/) { 702 push @columns, "ordnumber"; 703 } 704 if ($form->{type} =~ /_quotation$/) { 705 push @columns, "quonumber"; 706 } 707 if ($form->{type} =~ /(timecard|storescard)/) { 708 push @columns, "id"; 709 } 710 711 push @columns, qw(description name vcnumber); 712 push @columns, "email" if $form->{batch} eq 'email'; 713 push @columns, qw(city amount); 714 push @columns, "spoolfile" if $form->{batch} eq 'queue'; 715 716 @column_index = $form->sort_columns(@columns); 717 unshift @column_index, qw(runningnumber ndx); 718 719 $column_header{runningnumber} = "<th><a class=listheading> </th>"; 720 $form->{allbox} = ($form->{allbox}) ? "checked" : ""; 721 $action = ($form->{deselect}) ? "deselect_all" : "select_all"; 722 $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>|; 723 $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>"; 724 $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>"; 725 $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>"; 726 $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>"; 727 $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Name')."</a></th>"; 728 729 $column_header{vcnumber} = "<th><a class=listheading href=$href&sort=vcnumber>".$locale->text('Number')."</a></th>"; 730 731 $column_header{email} = "<th class=listheading>".$locale->text('E-mail')."</th>"; 732 $column_header{city} = "<th class=listheading>".$locale->text('City')."</th>"; 733 $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>"; 734 $column_header{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>"; 735 $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>"; 736 $column_header{amount} = "<th class=listheading>".$locale->text('Amount')."</th>"; 737 738 $form->helpref("list_spool", $myconfig{countrycode}); 739 740 $form->header; 741 742 &check_all(qw(allbox ndx_)); 743 744print qq| 745<body> 746 747<form method="post" name="main" action="$form->{script}"> 748 749<table width=100%> 750 <tr> 751 <th class=listtop>$form->{helpref}$form->{title}</a></th> 752 </tr> 753 <tr height="5"></tr> 754 <tr> 755 <td>$option</td> 756 </tr> 757 <tr> 758 <td> 759 <table width=100%> 760 <tr class=listheading> 761|; 762 763 for (@column_index) { print "\n$column_header{$_}" } 764 765 print qq| 766 </tr> 767|; 768 769 770 # add sort and escape callback, this one we use for the add sub 771 $form->{callback} = $callback .= "&sort=$form->{sort}"; 772 773 # escape callback for href 774 $callback = $form->escape($callback); 775 776 $i = 0; 777 $totalamount = 0; 778 779 foreach $ref (@{ $form->{SPOOL} }) { 780 781 $i++; 782 783 if ($form->{"ndx_$i"}) { 784 $form->{"ndx_$i"} = "checked"; 785 } 786 787 $totalamount += $ref->{amount}; 788 789 # this one is for printing spool entries 790 $form->{tablename} = $ref->{tablename}; 791 792 $module = $ref->{tablename}; 793 if ($ref->{tablename} eq 'jcitems') { 794 $module = 'jc'; 795 } 796 if ($ref->{invoice}) { 797 $module = ($ref->{tablename} eq 'ar') ? "is" : "ir"; 798 } 799 $module .= ".pl"; 800 801 $column_data{amount} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{amount}, $form->{precision}).qq|</td>|; 802 803 $column_data{ndx} = qq|<td><input name="ndx_$i" type=checkbox class=checkbox $form->{"ndx_$i"} $form->{"ndx_$i"}></td>|; 804 805 if ($form->{batch} eq 'queue') { 806 if ($spoolfile eq $ref->{spoolfile}) { 807 $column_data{ndx} = qq|<td></td>|; 808 } 809 } 810 811 $column_data{runningnumber} = qq|<td>$i</td>|; 812 813 for (qw(description email city id invnumber ordnumber quonumber vcnumber)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| } 814 $column_data{transdate} = qq|<td nowrap>$ref->{transdate}</td>|; 815 816 $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>|; 817 818 if ($ref->{tablename} eq 'oe') { 819 $column_data{invnumber} = qq|<td> </td>|; 820 $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> 821 <input type=hidden name="reference_$i" value="|.$form->quote($ref->{ordnumber}).qq|">|; 822 823 $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> 824 <input type=hidden name="reference_$i" value="|.$form->quote($ref->{quonumber}).qq|">|; 825 826 } elsif ($ref->{tablename} eq 'jc') { 827 $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> 828 <input type=hidden name="reference_$i" value="$ref->{id}">|; 829 830 $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>|; 831 } else { 832 $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> 833 <input type=hidden name="reference_$i" value="|.$form->quote($ref->{invnumber}).qq|">|; 834 } 835 836 $column_data{spoolfile} = qq|<td><a href=$spool/$myconfig{dbname}/$ref->{spoolfile}>$ref->{spoolfile}</a></td> 837|; 838 839 $spoolfile = $ref->{spoolfile}; 840 841 $j++; $j %= 2; 842 print " 843 <tr class=listrow$j> 844"; 845 846 for (@column_index) { print "\n$column_data{$_}" } 847 848 print qq| 849 </tr> 850 851<input type=hidden name="id_$i" value="$ref->{id}"> 852<input type=hidden name="spoolfile_$i" value="$ref->{spoolfile}"> 853<input type=hidden name="vc_$i" value="$ref->{vc}"> 854<input type=hidden name="tablename_$i" value="$ref->{tablename}"> 855<input type=hidden name="module_$i" value="$module"> 856|; 857 } 858 859 for (@column_index) { $column_data{$_} = "<td> </td>" } 860 861 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, $form->{precision}, " ")."</th>"; 862 863 print qq|<tr class=listtotal>|; 864 865 for (@column_index) { print "\n$column_data{$_}" } 866 867 print qq| 868<input type=hidden name=rowcount value=$i> 869 870 </table> 871 </td> 872 </tr> 873 <tr> 874 <td><hr size=3 noshade></td> 875 </tr> 876</table> 877 878<br> 879|; 880 881 $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)); 882 883 $form->{copies} ||= 1; 884 885 $selectformat = ""; 886 $media = qq|<select name=media>|; 887 888 if ($form->{batch} eq 'email') { 889 $form->{format} ||= "pdf"; 890 $selectformat .= qq|<option value="html">|.$locale->text('html').qq| 891<option value="xml">|.$locale->text('XML').qq| 892<option value="txt">|.$locale->text('Text'); 893 } else { 894 $form->{format} ||= $myconfig{outputformat}; 895 $form->{media} ||= $myconfig{printer}; 896 $form->{format} ||= "ps"; 897 exit if (! $latex && $form->{batch} eq 'print'); 898 } 899 900 if ($latex) { 901 $selectformat .= qq| 902 <option value="ps">|.$locale->text('Postscript').qq| 903 <option value="pdf">|.$locale->text('PDF'); 904 } 905 906 if (@{ $form->{all_printer} } && $form->{batch} ne 'email') { 907 908 for (@{ $form->{all_printer} }) { 909 $media .= qq| 910 <option value="$_->{printer}">$_->{printer}|; 911 } 912 913 $copies = $locale->text('Copies').qq| <input name=copies size=2 value=$form->{copies}>|; 914 915 } 916 917 if ($form->{batch} eq 'email') { 918 $sendmode = qq|<select name="sendmode"> 919 <option value="attachment">|.$locale->text('Attachment').qq| 920 <option value="inline">|.$locale->text('In-line').qq|</select>|; 921 } 922 923 if ($form->{batch} ne 'email') { 924 $media .= qq| 925 <option value="queue">|.$locale->text('Queue') if $form->{batch} eq 'print'; 926 } 927 928 $media .= qq|</select>|; 929 930 $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/; 931 932 $format = qq|<select name=format>$selectformat</select>|; 933 $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/; 934 935 if ($form->{batch} eq 'email') { 936 $sendmode =~ s/(<option value="\Q$form->{sendmode}\E")/$1 selected/; 937 938 $message = qq|<tr> 939 <td nowrap><b>|.$locale->text('Subject').qq|</b> <input name=subject size=60></td> 940 </tr> 941 <tr> 942 <td><b>|.$locale->text('Message').qq|</b><br><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td> 943 </tr>|; 944 945 $media = qq|<input type="hidden" name="media" value="email"> 946|; 947 } 948 if ($form->{batch} eq 'queue') { 949 $format = ""; 950 $copies = ""; 951 $media = "" if ! @{ $form->{all_printer} }; 952 } 953 954 955 print qq| 956<table> 957 $message 958 <tr> 959 <td nowrap=1>$format $sendmode $media $copies</td> 960 </tr> 961</table> 962<p> 963|; 964 965 for (@{ $form->{all_printer} }) { 966 $form->{"$_->{printer}_printer"} = $_->{command}; 967 $form->hide_form("$_->{printer}_printer"); 968 } 969 970 %button = ('Select all' => { ndx => 2, key => 'A', value => $locale->text('Select all') }, 971 'Deselect all' => { ndx => 3, key => 'A', value => $locale->text('Deselect all') }, 972 'Print' => { ndx => 5, key => 'P', value => $locale->text('Print') }, 973 'E-mail' => { ndx => 6, key => 'E', value => $locale->text('E-mail') }, 974 'Combine' => { ndx => 7, key => 'C', value => $locale->text('Combine') }, 975 'Remove' => { ndx => 8, key => 'R', value => $locale->text('Remove') }, 976 ); 977 978 979 if ($form->{deselect}) { 980 delete $button{'Select all'}; 981 } else { 982 delete $button{'Deselect all'}; 983 } 984 985 if ($form->{batch} eq 'print') { 986 delete $button{'E-mail'}; 987 } 988 if ($form->{batch} ne 'queue') { 989 delete $button{'Remove'}; 990 delete $button{'Combine'}; 991 } 992 if ($form->{batch} eq 'email') { 993 delete $button{'Print'}; 994 } 995 if ($form->{batch} eq 'queue') { 996 delete $button{'E-mail'}; 997 delete $button{'Print'} if ! @{ $form->{all_printer} }; 998 } 999 if (!$pdftk) { 1000 delete $button{'Combine'}; 1001 } 1002 1003 $form->print_button(\%button); 1004 1005 1006 if ($form->{menubar}) { 1007 require "$form->{path}/menu.pl"; 1008 &menubar; 1009 } 1010 1011 print qq| 1012</form> 1013 1014</body> 1015</html> 1016|; 1017 1018} 1019 1020 1021sub select_all { 1022 1023 for (1 .. $form->{rowcount}) { $form->{"ndx_$_"} = 1 } 1024 $form->{allbox} = 1; 1025 $form->{deselect} = 1; 1026 &list_spool; 1027 1028} 1029 1030 1031sub deselect_all { 1032 1033 for (1 .. $form->{rowcount}) { $form->{"ndx_$_"} = "" } 1034 $form->{allbox} = ""; 1035 &list_spool; 1036 1037} 1038 1039 1040sub combine { 1041 1042 use Cwd; 1043 $dir = cwd(); 1044 $files = ""; 1045 1046 for (1 .. $form->{rowcount}) { 1047 if ($form->{"ndx_$_"}) { 1048 if ($form->{"spoolfile_$_"} =~ /\.pdf$/) { 1049 $files .= qq|$form->{"spoolfile_$_"} |; 1050 } 1051 } 1052 } 1053 1054 $form->{format} = "pdf"; 1055 $form->{callback} =~ s/\&allbox=1//; 1056 1057 if ($files) { 1058 chdir("$spool/$myconfig{dbname}"); 1059 if ($filename = BP->spoolfile(\%myconfig, \%$form)) { 1060 @args = ("pdftk $files cat output $filename"); 1061 system(@args) % 256 == 0 or $form->error("@args : $?"); 1062 } 1063 } else { 1064 $form->error($locale->text('Nothing selected!')); 1065 } 1066 1067 chdir("$dir"); 1068 1069 $form->redirect; 1070 1071} 1072 1073 1074sub continue { &{ $form->{nextsub} } }; 1075 1076