1#===================================================================== 2# LedgerSMB 3# Small Medium Business Accounting software 4# http://www.ledgersmb.org/ 5# 6# 7# See COPYRIGHT file for copyright information 8#====================================================================== 9# 10# This file has NOT undergone whitespace cleanup. 11# 12#====================================================================== 13# 14# project/job administration 15# partsgroup administration 16# translation maintainance 17# 18#====================================================================== 19 20use LedgerSMB::PE; 21use LedgerSMB::AA; 22use LedgerSMB::OE; 23 241; 25 26# end of main 27 28sub add { 29 30 # construct callback 31 $form->{callback} = 32"$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" 33 unless $form->{callback}; 34 35 &{"prepare_$form->{type}"}; 36 37 $form->{orphaned} = 1; 38 &display_form; 39 40} 41 42sub edit { 43 44 &{"prepare_$form->{type}"}; 45 &display_form; 46 47} 48 49sub prepare_partsgroup { 50 PE->get_partsgroup( \%myconfig, \%$form ) 51 if $form->{id}; 52} 53sub prepare_pricegroup { 54 PE->get_pricegroup( \%myconfig, \%$form ) 55 if $form->{id}; 56} 57 58sub prepare_job { 59 60 # $locale->text('Add Job') 61 # $locale->text('Edit Job') 62 63 $form->{vc} = 'customer'; 64 65 PE->get_job( \%myconfig, \%$form ); 66 67 $form->{taxaccounts} = ""; 68 for ( keys %{ $form->{IC_links} } ) { 69 70 $form->{"select$_"} = ""; 71 foreach $ref ( @{ $form->{IC_links}{$_} } ) { 72 if (/IC_tax/) { 73 if (/taxpart/) { 74 $form->{taxaccounts} .= "$ref->{accno} "; 75 $form->{"IC_tax_$ref->{accno}_description"} = 76 "$ref->{accno}--$ref->{description}"; 77 if ( $form->{id} ) { 78 if ( $form->{amount}{ $ref->{accno} } ) { 79 $form->{"IC_tax_$ref->{accno}"} = "checked"; 80 } 81 } 82 else { 83 $form->{"IC_tax_$ref->{accno}"} = "checked"; 84 } 85 } 86 } 87 else { 88 $form->{"select$_"} .= 89 "<option>$ref->{accno}--$ref->{description}\n"; 90 } 91 } 92 } 93 chop $form->{taxaccounts}; 94 95 $form->{selectIC_income} = $form->{selectIC_sale}; 96 $form->{IC_income} = $form->{IC_sale}; 97 98 $form->{IC_income} = qq|$form->{income_accno}--$form->{income_description}|; 99 100 delete $form->{IC_links}; 101 102 $form->{"old$form->{vc}"} = 103 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; 104 105 if ( @{ $form->{"all_$form->{vc}"} } ) { 106 $form->{"$form->{vc}"} = 107 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; 108 $form->{"select$form->{vc}"} = qq|<option>\n|; 109 for ( @{ $form->{"all_$form->{vc}"} } ) { 110 $form->{"select$form->{vc}"} .= 111 qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|; 112 } 113 } 114 115 $form->get_partsgroup( \%myconfig, { all => 1 } ); 116 $form->{partsgroup} = 117 $form->quote( $form->{partsgroup} ) . "--$form->{partsgroup_id}"; 118 if ( @{ $form->{all_partsgroup} } ) { 119 $form->{selectpartsgroup} = qq|<option>\n|; 120 for ( @{ $form->{all_partsgroup} } ) { 121 $form->{selectpartsgroup} .= 122 qq|<option value="| 123 . $form->quote( $_->{partsgroup} ) 124 . qq|--$_->{id}">$_->{partsgroup}\n|; 125 } 126 } 127 128 $form->{locked} = 129 ( $form->{revtrans} ) 130 ? '1' 131 : ( $form->datetonum( \%myconfig, $form->{transdate} ) <= 132 $form->datetonum( \%myconfig, $form->{closedto} ) ); 133 134 $form->{readonly} = 1 if $myconfig{acs} =~ /Job Costing--Add Job/; 135 136} 137 138sub job_header { 139 140 for (qw(partnumber partdescription description notes unit)) { 141 $form->{$_} = $form->quote( $form->{$_} ); 142 } 143 144 for (qw(production weight)) { 145 $form->{$_} = $form->format_amount( \%myconfig, $form->{$_} ); 146 } 147 for (qw(listprice sellprice)) { 148 $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 ); 149 } 150 151 if ( ( $rows = $form->numtextrows( $form->{partdescription}, 60 ) ) > 1 ) { 152 $partdescription = 153qq|<textarea name="partdescription" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{partdescription}</textarea>|; 154 } 155 else { 156 $partdescription = 157qq|<input name=partdescription size=60 value="$form->{partdescription}">|; 158 } 159 160 if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) { 161 $description = 162qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|; 163 } 164 else { 165 $description = 166 qq|<input name=description size=60 value="$form->{description}">|; 167 } 168 169 if ( ( $rows = $form->numtextrows( $form->{notes}, 40 ) ) < 2 ) { 170 $rows = 2; 171 } 172 173 $notes = 174qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|; 175 176 $form->{selectIC_income} = $form->unescape( $form->{selectIC_income} ); 177 $form->{"select$form->{vc}"} = 178 $form->unescape( $form->{"select$form->{vc}"} ); 179 $form->{"select$form->{vc}"} =~ s/ selected//; 180 $form->{"select$form->{vc}"} =~ 181 s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/; 182 183 $label = ucfirst $form->{vc}; 184 if ( $form->{"select$form->{vc}"} ) { 185 $name = qq| 186 <tr> 187 <th align=right nowrap>| . $locale->text($label) . qq|</th> 188 <td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td> 189 <input type=hidden name="select$form->{vc}" value="| 190 . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|"> 191 </tr> 192|; 193 } 194 else { 195 $name = qq| 196 <tr> 197 <th align=right nowrap>| . $locale->text($label) . qq|</th> 198 <td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td> 199 <input type=hidden name="select$form->{vc}" value="| 200 . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|"> 201 </tr> 202|; 203 } 204 205 if ( $form->{orphaned} ) { 206 207 for (qw(income)) { 208 $form->{"selectIC_$_"} =~ s/ selected//; 209 $form->{"selectIC_$_"} =~ 210 s/option>\Q$form->{"IC_$_"}\E/option selected>$form->{"IC_$_"}/; 211 } 212 213 $production = qq| 214 <tr> 215 <th align=right nowrap>| . $locale->text('Production') . qq|</th> 216 <td><input name=production size=10 value="$form->{production}"></td> 217 <th align=right nowrap>| . $locale->text('Completed') . qq|</th> 218 <td>$form->{completed}</td> 219 </tr> 220|; 221 222 } 223 else { 224 225 $form->{selectIC_income} = qq|<option selected>$form->{IC_income}|; 226 227 $production = qq| 228 <tr> 229 <th align=right nowrap>| . $locale->text('Production') . qq|</th> 230 <td><input type=hidden name=production value="$form->{production}">$form->{production}</td> 231 <th align=right nowrap>| . $locale->text('Completed') . qq|</th> 232 <td>$form->{completed}</td> 233 </tr> 234|; 235 236 } 237 238 for ( split / /, $form->{taxaccounts} ) { 239 $form->{"IC_tax_$_"} = ( $form->{"IC_tax_$_"} ) ? "checked" : ""; 240 } 241 242 if ( $form->{selectpartsgroup} ) { 243 $form->{selectpartsgroup} = 244 $form->unescape( $form->{selectpartsgroup} ); 245 246 $partsgroup = 247 qq|<input type=hidden name=selectpartsgroup value="| 248 . $form->escape( $form->{selectpartsgroup}, 1 ) . qq|">|; 249 $form->{partsgroup} = $form->quote( $form->{partsgroup} ); 250 $form->{selectpartsgroup} =~ 251 s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/; 252 253 $partsgroup .= 254 qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|; 255 $group = $locale->text('Group'); 256 } 257 258 $linkaccounts = qq| 259 <tr> 260 <th align=right nowrap>| . $locale->text('Income') . qq|</th> 261 <td><select name=IC_income>$form->{selectIC_income}</select></td> 262 </tr> 263|; 264 265 for ( split / /, $form->{taxaccounts} ) { 266 $tax .= qq| 267 <input class=checkbox type=checkbox name="IC_tax_$_" value=1 $form->{"IC_tax_$_"}> <b>$form->{"IC_tax_${_}_description"}</b> 268 <br><input type=hidden name=IC_tax_${_}_description value="$form->{"IC_tax_${_}_description"}"> 269|; 270 } 271 272 if ($tax) { 273 $linkaccounts .= qq| 274 <tr> 275 <th align=right>| . $locale->text('Tax') . qq|</th> 276 <td>$tax</td> 277 </tr> 278|; 279 } 280 281 $partnumber = qq| 282 <tr> 283 <td> 284 <table> 285 <tr valign=top> 286 <th align=left>| . $locale->text('Number') . qq|</th> 287 <th align=left>| . $locale->text('Description') . qq|</th> 288 <th align=left>$group</th> 289 </tr> 290 <tr valign=top> 291 <td><input name=partnumber value="$form->{partnumber}" size=20></td> 292 <td>$partdescription</td> 293 <td>$partsgroup</td> 294 </tr> 295 </table> 296 </td> 297 </tr> 298|; 299 300 $form->{title} = 301 ( $form->{id} ) ? $locale->text('Edit Job') : $locale->text('Add Job'); 302 303 $form->header; 304 305 print qq| 306<body> 307 308<form method=post action=$form->{script}> 309|; 310 311 for (qw(partnumber startdate enddate)) { $form->{"old$_"} = $form->{$_} } 312 313 print qq|<input type=hidden name="selectIC_income" value="| 314 . $form->escape( $form->{"selectIC_income"}, 1 ) 315 . qq|">\n|; 316 317 $form->hide_form( 318 "id", "type", 319 "old$form->{vc}", "$form->{vc}_id", 320 "orphaned", "taxaccounts", 321 "vc", "project" 322 ); 323 324 print qq| 325 326<table width=100%> 327 <tr> 328 <th class=listtop>$form->{title}</th> 329 </tr> 330 <tr height="5"></tr> 331 <tr> 332 <td> 333 <table> 334 <tr> 335 <th align=right>| . $locale->text('Number') . qq|</th> 336 <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td> 337 <th align=right>| . $locale->text('Description') . qq|</th> 338 <td>$description</td> 339 </tr> 340 $name 341 <tr> 342 <th align=right>| . $locale->text('Startdate') . qq|</th> 343 <td><input name=startdate size=11 title="($myconfig{dateformat})" value="$form->{startdate}"></td> 344 <th align=right>| . $locale->text('Enddate') . qq|</th> 345 <td><input name=enddate size=11 title="($myconfig{dateformat})" value="$form->{enddate}"></td> 346 </tr> 347 $production 348 </table> 349 </td> 350 </tr> 351 <tr class="listheading"> 352 <th class="listheading" align="center">| 353 . $locale->text('Assembly') 354 . qq|</th> 355 </tr> 356 <tr> 357 <td> 358 <table width=100%> 359 $partnumber 360 <tr> 361 <td colspan=3> 362 <table width=100%> 363 <tr> 364 <td width=70%> 365 <table width=100%> 366 <tr class="listheading"> 367 <th class="listheading" align="center" colspan=2>| 368 . $locale->text('Link Accounts') 369 . qq|</th> 370 </tr> 371 $linkaccounts 372 <tr> 373 <th align="left">| . $locale->text('Notes') . qq|</th> 374 </tr> 375 <tr> 376 <td colspan=2> 377 $notes 378 </td> 379 </tr> 380 </table> 381 </td> 382 <td align=right> 383 <table> 384 <tr> 385 <th align="right" nowrap="true">| . $locale->text('Updated') . qq|</th> 386 <td><input name=priceupdate size=11 title="$myconfig{dateformat}" value="$form->{priceupdate}"></td> 387 </tr> 388 <tr> 389 <th align="right" nowrap="true">| 390 . $locale->text('List Price') 391 . qq|</th> 392 <td><input name=listprice size=11 value="$form->{listprice}"></td> 393 </tr> 394 <tr> 395 <th align="right" nowrap="true">| 396 . $locale->text('Sell Price') 397 . qq|</th> 398 <td><input name=sellprice size=11 value="$form->{sellprice}"></td> 399 </tr> 400 <tr> 401 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th> 402 <td> 403 <table> 404 <tr> 405 <td> 406 <input name=weight size=10 value="$form->{weight}"> 407 </td> 408 <th> 409 410 $form->{weightunit} 411 <input type=hidden name=weightunit value="$form->{weightunit}"> 412 </th> 413 </tr> 414 </table> 415 </td> 416 <tr> 417 <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th> 418 <td><input name=bin size=10 value="$form->{bin}"></td> 419 </tr> 420 <tr> 421 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th> 422 <td><input name=unit size=5 value="$form->{unit}"></td> 423 </tr> 424 </table> 425 </td> 426 </tr> 427 </table> 428 </td> 429 </tr> 430 </table> 431 </td> 432 </tr> 433 <tr> 434 <td><hr size=3 noshade></td> 435 </tr> 436</table> 437|; 438 439} 440 441sub job_footer { 442 443 $form->hide_form(qw(callback path login sessionid)); 444 445 # type=submit $locale->text('Update') 446 # type=submit $locale->text('Save') 447 # type=submit $locale->text('Delete') 448 449 %button = 450 ( 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 451 ); 452 453 if ( $myconfig{acs} !~ /Job Costing--Add Job/ ) { 454 $button{'save'} = 455 { ndx => 3, key => 'S', value => $locale->text('Save') }; 456 457 if ( $form->{id} && $form->{orphaned} ) { 458 $button{'delete'} = 459 { ndx => 16, key => 'D', value => $locale->text('Delete') }; 460 } 461 } 462 463 for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { 464 $form->print_button( \%button, $_ ); 465 } 466 467 if ( $form->{lynx} ) { 468 require "bin/menu.pl"; 469 &menubar; 470 } 471 472 print qq| 473</form> 474 475</body> 476</html> 477|; 478 479} 480 481sub list_stock { 482 483 PE->list_stock( \%myconfig, \%$form ); 484 485 $form->{title} = $locale->text('Stock Finished Goods'); 486 $form->{action} = "list_stock"; 487 488 $href = "$form->{script}?"; 489 for (qw(action direction oldsort type path login sessionid status)) { 490 $href .= "$_=$form->{$_}&"; 491 } 492 493 $form->sort_order(); 494 495 $callback = "$form->{script}?"; 496 for (qw(action direction oldsort type path login sessionid status)) { 497 $callback .= "$_=$form->{$_}&"; 498 } 499 500 @column_index = 501 $form->sort_columns( 502 qw(projectnumber description startdate partnumber production completed stock) 503 ); 504 505 if ( $form->{projectnumber} ) { 506 $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} ); 507 $callback .= "&projectnumber=$form->{projectnumber}"; 508 ($var) = split /--/, $form->{projectnumber}; 509 $option .= "\n<br>" . $locale->text('Job Number') . " : $var"; 510 } 511 if ( $form->{stockingdate} ) { 512 $href .= "&stockingdate=$form->{stockingdate}"; 513 $option .= "\n<br>" 514 . $locale->text('As of') . " : " 515 . $locale->date( \%myconfig, $form->{stockingdate}, 1 ); 516 } 517 518 $column_header{projectnumber} = 519 qq|<th width=30%><a class=listheading href=$href&sort=projectnumber>| 520 . $locale->text('Number') 521 . qq|</a></th>|; 522 $column_header{description} = 523 qq|<th width=50%><a class=listheading href=$href&sort=description>| 524 . $locale->text('Description') 525 . qq|</a></th>|; 526 $column_header{startdate} = 527 qq|<th width=10%><a class=listheading href=$href&sort=startdate>| 528 . $locale->text('Startdate') 529 . qq|</a></th>|; 530 $column_header{partnumber} = 531 "<th><a class=listheading href=$href&sort=partnumber>" 532 . $locale->text('Assembly') 533 . "</a></th>"; 534 $column_header{production} = 535 "<th class=listheading>" . $locale->text('Production') . "</a></th>"; 536 $column_header{completed} = 537 "<th class=listheading>" . $locale->text('Completed') . "</a></th>"; 538 $column_header{stock} = 539 "<th class=listheading>" . $locale->text('Add') . "</a></th>"; 540 541 $form->header; 542 543 if ( @{ $form->{all_project} } ) { 544 $sameitem = $form->{all_project}->[0]->{ $form->{sort} }; 545 } 546 547 print qq| 548<body> 549 550<form method=post action=$form->{script}> 551 552<table width=100%> 553 <tr> 554 <th class=listtop>$form->{title}</th> 555 </tr> 556 <tr height="5"></tr> 557 <tr> 558 <td>$option</td> 559 </tr> 560 <tr> 561 <td> 562 <table width=100%> 563 <tr class=listheading> 564|; 565 566 for (@column_index) { print "$column_header{$_}\n" } 567 568 print qq| 569 </tr> 570|; 571 572 # escape callback 573 $form->{callback} = $callback .= "&sort=$form->{sort}"; 574 575 # escape callback for href 576 $callback = $form->escape($callback); 577 578 # flip direction 579 $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC"; 580 $href =~ s/&direction=(\w+)&/&direction=$direction&/; 581 582 $i = 0; 583 foreach $ref ( @{ $form->{all_project} } ) { 584 585 $i++; 586 587 for (qw(projectnumber description startdate enddate partnumber)) { 588 $column_data{$_} = qq|<td>$ref->{$_} </td>|; 589 } 590 for (qw(production completed)) { 591 $column_data{$_} = 592 qq|<td align=right>| 593 . $form->format_amount( \%myconfig, $ref->{$_} ) 594 . qq|</td>|; 595 } 596 $column_data{stock} = qq|<td><input name="stock_$i" size=6></td>|; 597 598 $j++; 599 $j %= 2; 600 601 print qq| 602 <tr valign=top class="listrow$j"> 603 <input type=hidden name="id_$i" value="$ref->{id}"> 604|; 605 606 for (@column_index) { print "$column_data{$_}\n" } 607 608 print " 609 </tr> 610"; 611 } 612 613 print qq| 614 </table> 615 </td> 616 </tr> 617 <tr> 618 <td><hr size=3 noshade></td> 619 </tr> 620</table> 621|; 622 623 $form->hide_form(qw(callback type path login sessionid status)); 624 625 print qq| 626<input type="hidden" name="nextsub" value="stock"> 627<br> 628<button type="submit" class="submit" name="action" value="continue">| 629 . $locale->text('Continue') 630 . qq|</button> 631</form> 632 633</body> 634</html> 635|; 636 637} 638 639sub stock { 640 641 if ( PE->stock_assembly( \%myconfig, \%$form ) ) { 642 $form->redirect( $locale->text('Assembly stocked!') ); 643 } 644 else { 645 $form->error( $locale->text('Cannot stock Assembly!') ); 646 } 647 648} 649 650sub prepare_project { 651 652 $form->{vc} = 'customer'; 653 654 PE->get_project( \%myconfig, \%$form ); 655 656 $form->{title} = 657 ( $form->{id} ) 658 ? $locale->text('Edit Project') 659 : $locale->text('Add Project'); 660 661 $form->{"old$form->{vc}"} = 662 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; 663 664 if ( @{ $form->{"all_$form->{vc}"} } ) { 665 $form->{"$form->{vc}"} = 666 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; 667 $form->{"select$form->{vc}"} = qq|<option>\n|; 668 for ( @{ $form->{"all_$form->{vc}"} } ) { 669 $form->{"select$form->{vc}"} .= 670 qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|; 671 } 672 } 673 674} 675 676sub search { 677 678 # accounting years 679 $form->all_years( \%myconfig ); 680 681 if ( @{ $form->{all_years} } ) { 682 $form->{selectaccountingyear} = "<option>\n"; 683 for ( @{ $form->{all_years} } ) { 684 $form->{selectaccountingyear} .= qq|<option>$_\n|; 685 } 686 687 $form->{selectaccountingmonth} = "<option>\n"; 688 for ( sort keys %{ $form->{all_month} } ) { 689 $form->{selectaccountingmonth} .= 690 qq|<option value=$_>| 691 . $locale->text( $form->{all_month}{$_} ) . qq|\n|; 692 } 693 694 $fromto = qq| 695 <tr> 696 <th align=right>| . $locale->text('Startdate') . qq|</th> 697 <td>| 698 . $locale->text('From') 699 . qq| <input name=startdatefrom size=11 title="($myconfig{'dateformat'})">| 700 . $locale->text('To') . qq| 701 <input name=startdateto size=11 title="($myconfig{'dateformat'})"></td> 702 </tr> 703|; 704 705 $selectperiod = qq| 706 <tr> 707 <th align=right>| . $locale->text('Period') . qq|</th> 708 <td colspan=3> 709 <select name=month>$form->{selectaccountingmonth}</select> 710 <select name=year>$form->{selectaccountingyear}</select> 711 <input name=interval class=radio type=radio value=0 checked> | 712 . $locale->text('Current') . qq| 713 <input name=interval class=radio type=radio value=1> | 714 . $locale->text('Month') . qq| 715 <input name=interval class=radio type=radio value=3> | 716 . $locale->text('Quarter') . qq| 717 <input name=interval class=radio type=radio value=12> | 718 . $locale->text('Year') . qq| 719 </td> 720 </tr> 721|; 722 } 723 724 $orphaned = qq| 725 <input name=status class=radio type=radio value=orphaned> | 726 . $locale->text('Orphaned'); 727 728 if ( $form->{type} eq 'project' ) { 729 $report = "project_report"; 730 $sort = "projectnumber"; 731 $form->{title} = $locale->text('Projects'); 732 733 $number = qq| 734 <tr> 735 <th align=right width=1%>| . $locale->text('Number') . qq|</th> 736 <td><input name=projectnumber size=20></td> 737 </tr> 738 <tr> 739 <th align=right>| . $locale->text('Description') . qq|</th> 740 <td><input name=description size=60></td> 741 </tr> 742|; 743 } 744 745 if ( $form->{type} eq 'stock' ) { 746 $report = "list_stock"; 747 $form->{title} = $locale->text('Stock Finished Goods'); 748 PE->list_stock( \%myconfig, \%$form ); 749 750 $selectperiod = ""; 751 $orphaned = ""; 752 $fromto = qq| 753 <tr> 754 <th align=right nowrap>| . $locale->text('As of') . qq|</th> 755 <td><input name=stockingdate size=11 title="$myconfig{dateformat}"></td> 756 </tr> 757|; 758 759 $number = qq| 760 <tr> 761 <th align=right width=1%>| . $locale->text('Job Number') . qq|</th> 762 <td><input name=projectnumber size=20></td> 763 </tr> 764 <tr> 765 <th align=right>| . $locale->text('Description') . qq|</th> 766 <td><input name=description size=60></td> 767 </tr> 768|; 769 } 770 771 if ( $form->{type} eq 'job' ) { 772 $report = "job_report"; 773 $sort = "projectnumber"; 774 $form->{title} = $locale->text('Jobs'); 775 776 $number = qq| 777 <tr> 778 <th align=right width=1%>| . $locale->text('Number') . qq|</th> 779 <td><input name=projectnumber size=20></td> 780 </tr> 781 <tr> 782 <th align=right>| . $locale->text('Description') . qq|</th> 783 <td><input name=description size=60></td> 784 </tr> 785|; 786 } 787 788 if ( $form->{type} eq 'partsgroup' ) { 789 $report = "partsgroup_report"; 790 $sort = 'partsgroup'; 791 $form->{title} = $locale->text('Groups'); 792 793 $fromto = ""; 794 $selectperiod = ""; 795 $number = qq| 796 <tr> 797 <th align=right width=1%>| . $locale->text('Group') . qq|</th> 798 <td><input name=partsgroup size=20></td> 799 </tr> 800|; 801 } 802 803 if ( $form->{type} eq 'pricegroup' ) { 804 $report = "pricegroup_report"; 805 $sort = 'pricegroup'; 806 $form->{title} = $locale->text('Pricegroups'); 807 808 $fromto = ""; 809 $selectperiod = ""; 810 $number = qq| 811 <tr> 812 <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th> 813 <td><input name=pricegroup size=20></td> 814 </tr> 815|; 816 } 817 818 $form->header; 819 820 print qq| 821<body> 822 823<form method="post" action="$form->{script}"> 824 825<input type=hidden name=sort value="$sort"> 826<input type=hidden name=type value="$form->{type}"> 827 828<table width="100%"> 829 <tr> 830 <th class=listtop>$form->{title}</th> 831 </tr> 832 <tr height="5"></tr> 833 <tr> 834 <td> 835 <table width="100%"> 836 $number 837 $fromto 838 $selectperiod 839 <tr> 840 <td></td> 841 <td><input name=status class=radio type=radio value=all checked> | 842 . $locale->text('All') . qq| 843 <input name=status class=radio type=radio value=active> | 844 . $locale->text('Active') . qq| 845 <input name=status class=radio type=radio value=inactive> | 846 . $locale->text('Inactive') . qq| 847 $orphaned</td> 848 </tr> 849 </table> 850 </td> 851 </tr> 852 <tr> 853 <td><hr size=3 noshade></td> 854 </tr> 855</table> 856 857<input type="hidden" name="nextsub" value="$report"> 858|; 859 860 $form->hide_form(qw(path login sessionid title)); 861 862 print qq| 863<button class="submit" type="submit" name="action" value="continue">| 864 . $locale->text('Continue') 865 . qq|</button> 866</form> 867|; 868 869 if ( $form->{lynx} ) { 870 require "bin/menu.pl"; 871 &menubar; 872 } 873 874 print qq| 875 876</body> 877</html> 878|; 879 880} 881 882sub job_report { 883 884 for (qw(projectnumber description)) { 885 $form->{$_} = $form->unescape( $form->{$_} ); 886 } 887 PE->jobs( \%myconfig, \%$form ); 888 889 $form->{action} = "job_report"; 890 &list_projects; 891 892} 893 894sub project_report { 895 896 for (qw(projectnumber description)) { 897 $form->{$_} = $form->unescape( $form->{$_} ); 898 } 899 PE->projects( \%myconfig, \%$form ); 900 901 $form->{action} = "project_report"; 902 &list_projects; 903 904} 905 906sub list_projects { 907 908 $href = "$form->{script}?"; 909 for ( 910 qw(action direction oldsort type path login sessionid status startdatefrom startdateto) 911 ) 912 { 913 $href .= "$_=$form->{$_}&"; 914 } 915 916 $form->sort_order(); 917 918 $callback = "$form->{script}?"; 919 for ( 920 qw(action direction oldsort type path login sessionid status startdatefrom startdateto) 921 ) 922 { 923 $callback .= "$_=$form->{$_}&"; 924 } 925 926 @column_index = 927 $form->sort_columns(qw(projectnumber description name startdate enddate)); 928 929 if ( $form->{status} eq 'all' ) { 930 $option = $locale->text('All'); 931 } 932 if ( $form->{status} eq 'orphaned' ) { 933 $option .= $locale->text('Orphaned'); 934 } 935 if ( $form->{status} eq 'active' ) { 936 $option = $locale->text('Active'); 937 @column_index = 938 $form->sort_columns(qw(projectnumber description name startdate)); 939 } 940 if ( $form->{status} eq 'inactive' ) { 941 $option = $locale->text('Inactive'); 942 } 943 944 if ( $form->{type} eq 'project' ) { 945 $label = $locale->text('Project'); 946 $form->{title} = $locale->text('Projects'); 947 } 948 else { 949 $label = $locale->text('Job'); 950 push @column_index, qw(partnumber production completed); 951 $form->{title} = $locale->text('Jobs'); 952 } 953 954 if ( $form->{projectnumber} ) { 955 $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} ); 956 $callback .= "&projectnumber=$form->{projectnumber}"; 957 $option .= "\n<br>$label : $form->{projectnumber}"; 958 } 959 if ( $form->{description} ) { 960 $href .= "&description=" . $form->escape( $form->{description} ); 961 $callback .= "&description=$form->{description}"; 962 $option .= 963 "\n<br>" . $locale->text('Description') . " : $form->{description}"; 964 } 965 if ( $form->{startdatefrom} ) { 966 $href .= "&startdatefrom=$form->{startdatefrom}"; 967 $option .= "\n<br>" 968 . $locale->text('From') 969 . " " 970 . $locale->date( \%myconfig, $form->{startdatefrom}, 1 ); 971 } 972 if ( $form->{startdateto} ) { 973 $href .= "&startdateto=$form->{startdateto}"; 974 if ( $form->{startdatefrom} ) { 975 $option .= " "; 976 } 977 else { 978 $option .= "\n<br>" if ($option); 979 } 980 $option .= 981 $locale->text('To') . " " 982 . $locale->date( \%myconfig, $form->{startdateto}, 1 ); 983 } 984 985 $column_header{projectnumber} = 986 qq|<th><a class=listheading href=$href&sort=projectnumber>| 987 . $locale->text('Number') 988 . qq|</a></th>|; 989 $column_header{description} = 990 qq|<th><a class=listheading href=$href&sort=description>| 991 . $locale->text('Description') 992 . qq|</a></th>|; 993 $column_header{startdate} = 994 qq|<th width=10><a class=listheading href=$href&sort=startdate>| 995 . $locale->text('Startdate') 996 . qq|</a></th>|; 997 $column_header{enddate} = 998 qq|<th width=10><a class=listheading href=$href&sort=enddate>| 999 . $locale->text('Enddate') 1000 . qq|</a></th>|; 1001 1002 $column_header{partnumber} = 1003 "<th><a class=listheading href=$href&sort=partnumber>" 1004 . $locale->text('Assembly') 1005 . "</a></th>"; 1006 $column_header{production} = 1007 "<th width=10 class=listheading>" . $locale->text('Production') . "</th>"; 1008 $column_header{completed} = 1009 "<th width=10 class=listheading>" . $locale->text('Completed') . "</th>"; 1010 $column_header{name} = 1011 "<th class=listheading>" . $locale->text('Customer') . "</th>"; 1012 1013 $form->header; 1014 1015 if ( @{ $form->{all_project} } ) { 1016 $sameitem = $form->{all_project}->[0]->{ $form->{sort} }; 1017 } 1018 1019 print qq| 1020<body> 1021 1022<table width=100%> 1023 <tr> 1024 <th class=listtop>$form->{title}</th> 1025 </tr> 1026 <tr height="5"></tr> 1027 <tr> 1028 <td>$option</td> 1029 </tr> 1030 <tr> 1031 <td> 1032 <table width=100%> 1033 <tr class=listheading> 1034|; 1035 1036 for (@column_index) { print "$column_header{$_}\n" } 1037 1038 print qq| 1039 </tr> 1040|; 1041 1042 # escape callback 1043 $form->{callback} = $callback .= "&sort=$form->{sort}"; 1044 1045 # escape callback for href 1046 $callback = $form->escape($callback); 1047 1048 # flip direction 1049 $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC"; 1050 $href =~ s/&direction=(\w+)&/&direction=$direction&/; 1051 1052 foreach $ref ( @{ $form->{all_project} } ) { 1053 1054 for (qw(description startdate enddate name)) { 1055 $column_data{$_} = qq|<td>$ref->{$_} </td>|; 1056 } 1057 1058 for (qw(production completed)) { 1059 $column_data{$_} = 1060 qq|<td align=right>| 1061 . $form->format_amount( \%myconfig, $ref->{$_} ); 1062 } 1063 1064 $column_data{projectnumber} = 1065qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{projectnumber}</td>|; 1066 $column_data{partnumber} = 1067qq|<td><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|; 1068 1069 $j++; 1070 $j %= 2; 1071 1072 print qq| 1073 <tr valign=top class=listrow$j> 1074|; 1075 1076 for (@column_index) { print "$column_data{$_}\n" } 1077 1078 print " 1079 </tr> 1080"; 1081 } 1082 1083 $i = 1; 1084 if ( $form->{type} eq 'project' ) { 1085 if ( $myconfig{acs} !~ /Projects--Projects/ ) { 1086 $button{'Projects--Add Project'}{code} = 1087qq|<button class="submit" type="submit" name="action" value="add_project">| 1088 . $locale->text('Add Project') 1089 . qq|</button> |; 1090 $button{'Projects--Add Project'}{order} = $i++; 1091 1092 for ( split /;/, $myconfig{acs} ) { 1093 delete $button{$_}; 1094 } 1095 } 1096 } 1097 else { 1098 if ( $myconfig{acs} !~ /Job Costing--Job Costing/ ) { 1099 $button{'Job Costing--Add Job'}{code} = 1100qq|<button class="submit" type="submit" name="action" value="add_job">| 1101 . $locale->text('Add Job') 1102 . qq|</button> |; 1103 $button{'Job Costing--Add Job'}{order} = $i++; 1104 1105 for ( split /;/, $myconfig{acs} ) { 1106 delete $button{$_}; 1107 } 1108 } 1109 } 1110 1111 print qq| 1112 </table> 1113 </td> 1114 </tr> 1115 <tr> 1116 <td><hr size=3 noshade></td> 1117 </tr> 1118</table> 1119 1120<br> 1121<form method=post action=$form->{script}> 1122|; 1123 1124 $form->hide_form(qw(callback type path login sessionid)); 1125 1126 foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) { 1127 print $item->{code}; 1128 } 1129 1130 if ( $form->{lynx} ) { 1131 require "bin/menu.pl"; 1132 &menubar; 1133 } 1134 1135 print qq| 1136 </form> 1137 1138</body> 1139</html> 1140|; 1141 1142} 1143 1144sub project_header { 1145 1146 $form->{description} = $form->quote( $form->{description} ); 1147 1148 if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) { 1149 $description = 1150qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|; 1151 } 1152 else { 1153 $description = 1154 qq|<input name=description size=60 value="$form->{description}">|; 1155 } 1156 1157 $form->{"select$form->{vc}"} = 1158 $form->unescape( $form->{"select$form->{vc}"} ); 1159 $form->{"select$form->{vc}"} =~ s/ selected//; 1160 $form->{"select$form->{vc}"} =~ 1161 s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/; 1162 1163 $label = ucfirst $form->{vc}; 1164 if ( $form->{"select$form->{vc}"} ) { 1165 $name = qq| 1166 <tr> 1167 <th align=right nowrap>| . $locale->text($label) . qq|</th> 1168 <td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td> 1169 <input type=hidden name="select$form->{vc}" value="| 1170 . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|"> 1171 </tr> 1172|; 1173 } 1174 else { 1175 $name = qq| 1176 <tr> 1177 <th align=right nowrap>| . $locale->text($label) . qq|</th> 1178 <td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td> 1179 <input type=hidden name="select$form->{vc}" value="| 1180 . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|"> 1181 </tr> 1182|; 1183 } 1184 1185 $form->header; 1186 1187 print qq| 1188<body> 1189 1190<form method=post action=$form->{script}> 1191|; 1192 1193 $form->hide_form( 1194 "id", "type", 1195 "old$form->{vc}", "$form->{vc}_id", 1196 "orphaned", "vc", 1197 "title" 1198 ); 1199 1200 print qq| 1201<table width=100%> 1202 <tr> 1203 <th class=listtop>$form->{title}</th> 1204 </tr> 1205 <tr height="5"></tr> 1206 <tr> 1207 <td> 1208 <table> 1209 <tr> 1210 <th align=right>| . $locale->text('Number') . qq|</th> 1211 <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td> 1212 <th align=right>| . $locale->text('Description') . qq|</th> 1213 <td>$description</td> 1214 </tr> 1215 $name 1216 <tr> 1217 <th align=right>| . $locale->text('Startdate') . qq|</th> 1218 <td><input name=startdate size=11 title="($myconfig{dateformat})" value="$form->{startdate}"></td> 1219 <th align=right>| . $locale->text('Enddate') . qq|</th> 1220 <td><input name=enddate size=11 title="($myconfig{dateformat})" value="$form->{enddate}"></td> 1221 </tr> 1222 </table> 1223 </td> 1224 </tr> 1225 <tr> 1226 <td><hr size="3" noshade></td> 1227 </tr> 1228</table> 1229|; 1230 1231} 1232 1233sub project_footer { 1234 1235 $form->hide_form(qw(callback path login sessionid)); 1236 1237 %button = 1238 ( 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 1239 ); 1240 1241 if ( $myconfig{acs} !~ /Projects--Add Project/ ) { 1242 $button{'save'} = 1243 { ndx => 3, key => 'S', value => $locale->text('Save') }; 1244 1245 if ( $form->{id} && $form->{orphaned} ) { 1246 $button{'delete'} = 1247 { ndx => 16, key => 'D', value => $locale->text('Delete') }; 1248 } 1249 } 1250 1251 for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { 1252 $form->print_button( \%button, $_ ); 1253 } 1254 1255 if ( $form->{lynx} ) { 1256 require "bin/menu.pl"; 1257 &menubar; 1258 } 1259 1260 print qq| 1261</form> 1262 1263</body> 1264</html> 1265|; 1266 1267} 1268 1269sub save { 1270 1271 if ( $form->{translation} ) { 1272 PE->save_translation( \%myconfig, \%$form ); 1273 $form->redirect( $locale->text('Translations saved!') ); 1274 exit; 1275 } 1276 1277 if ( $form->{type} eq 'project' ) { 1278 if ( $form->{"select$form->{vc}"} ) { 1279 ( $null, $form->{"$form->{vc}_id"} ) = split /--/, 1280 $form->{"$form->{vc}"}; 1281 } 1282 else { 1283 if ( $form->{"old$form->{vc}"} ne 1284 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| ) 1285 { 1286 1287 if ( 1288 ( 1289 $rv = $form->get_name( 1290 \%myconfig, $form->{vc}, $form->{startdate} 1291 ) 1292 ) > 1 1293 ) 1294 { 1295 &select_name; 1296 exit; 1297 } 1298 1299 if ( $rv == 1 ) { 1300 $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id}; 1301 $form->{"$form->{vc}"} = $form->{name_list}[0]->{name}; 1302 $form->{"old$form->{vc}"} = 1303 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; 1304 } 1305 } 1306 } 1307 1308 PE->save_project( \%myconfig, \%$form ); 1309 $form->redirect( $locale->text('Project saved!') ); 1310 } 1311 1312 if ( $form->{type} eq 'partsgroup' ) { 1313 $form->isblank( "partsgroup", $locale->text('Group missing!') ); 1314 PE->save_partsgroup( \%myconfig, \%$form ); 1315 $form->redirect( $locale->text('Group saved!') ); 1316 } 1317 1318 if ( $form->{type} eq 'pricegroup' ) { 1319 $form->isblank( "pricegroup", $locale->text('Pricegroup missing!') ); 1320 PE->save_pricegroup( \%myconfig, \%$form ); 1321 $form->redirect( $locale->text('Pricegroup saved!') ); 1322 } 1323 1324 if ( $form->{type} eq 'job' ) { 1325 if ( $form->{"select$form->{vc}"} ) { 1326 ( $null, $form->{"$form->{vc}_id"} ) = split /--/, 1327 $form->{"$form->{vc}"}; 1328 } 1329 else { 1330 if ( $form->{"old$form->{vc}"} ne 1331 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| ) 1332 { 1333 1334 if ( 1335 ( 1336 $rv = $form->get_name( 1337 \%myconfig, $form->{vc}, $form->{startdate} 1338 ) 1339 ) > 1 1340 ) 1341 { 1342 &select_name; 1343 exit; 1344 } 1345 1346 if ( $rv == 1 ) { 1347 $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id}; 1348 $form->{"$form->{vc}"} = $form->{name_list}[0]->{name}; 1349 $form->{"old$form->{vc}"} = 1350 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; 1351 } 1352 } 1353 } 1354 1355 PE->save_job( \%myconfig, \%$form ); 1356 $form->redirect( $locale->text('Job saved!') ); 1357 } 1358 1359} 1360 1361sub delete { 1362 1363 if ( $form->{translation} ) { 1364 PE->delete_translation( \%myconfig, \%$form ); 1365 $form->redirect( $locale->text('Translation deleted!') ); 1366 1367 } 1368 else { 1369 1370 if ( $form->{type} eq 'project' ) { 1371 PE->delete_project( \%myconfig, \%$form ); 1372 $form->redirect( $locale->text('Project deleted!') ); 1373 } 1374 if ( $form->{type} eq 'job' ) { 1375 PE->delete_job( \%myconfig, \%$form ); 1376 $form->redirect( $locale->text('Job deleted!') ); 1377 } 1378 if ( $form->{type} eq 'partsgroup' ) { 1379 PE->delete_partsgroup( \%myconfig, \%$form ); 1380 $form->redirect( $locale->text('Group deleted!') ); 1381 } 1382 if ( $form->{type} eq 'pricegroup' ) { 1383 PE->delete_pricegroup( \%myconfig, \%$form ); 1384 $form->redirect( $locale->text('Pricegroup deleted!') ); 1385 } 1386 } 1387 1388} 1389 1390sub partsgroup_report { 1391 1392 $form->{partsgroup} = $form->unescape( $form->{partsgroup} ); 1393 PE->partsgroups( \%myconfig, \%$form ); 1394 1395 $href = 1396"$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; 1397 1398 $form->sort_order(); 1399 1400 $callback = 1401"$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; 1402 1403 if ( $form->{status} eq 'all' ) { 1404 $option = $locale->text('All'); 1405 } 1406 if ( $form->{status} eq 'orphaned' ) { 1407 $option .= $locale->text('Orphaned'); 1408 } 1409 if ( $form->{partsgroup} ) { 1410 $callback .= "&partsgroup=$form->{partsgroup}"; 1411 $option .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}"; 1412 } 1413 1414 @column_index = $form->sort_columns(qw(partsgroup)); 1415 1416 $column_header{partsgroup} = 1417 qq|<th><a class=listheading href=$href&sort=partsgroup width=90%>| 1418 . $locale->text('Group') 1419 . qq|</a></th>|; 1420 1421 $form->{title} = $locale->text('Groups'); 1422 1423 $form->header; 1424 1425 print qq| 1426<body> 1427 1428<table width=100%> 1429 <tr> 1430 <th class=listtop>$form->{title}</th> 1431 </tr> 1432 <tr height="5"></tr> 1433 <tr> 1434 <td>$option</td> 1435 </tr> 1436 <tr> 1437 <td> 1438 <table width=100%> 1439 <tr class=listheading> 1440|; 1441 1442 for (@column_index) { print "$column_header{$_}\n" } 1443 1444 print qq| 1445 </tr> 1446|; 1447 1448 # escape callback 1449 $form->{callback} = $callback; 1450 1451 # escape callback for href 1452 $callback = $form->escape($callback); 1453 1454 foreach $ref ( @{ $form->{item_list} } ) { 1455 1456 $i++; 1457 $i %= 2; 1458 1459 print qq| 1460 <tr valign=top class=listrow$i> 1461|; 1462 1463 $column_data{partsgroup} = 1464qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partsgroup}</td>|; 1465 for (@column_index) { print "$column_data{$_}\n" } 1466 1467 print " 1468 </tr> 1469"; 1470 } 1471 1472 $i = 1; 1473 if ( $myconfig{acs} !~ /Goods \& Services--Goods \& Services/ ) { 1474 $button{'Goods & Services--Add Group'}{code} = 1475qq|<button class="submit" type="submit" name="action" value="add_group">| 1476 . $locale->text('Add Group') 1477 . qq|</button> |; 1478 $button{'Goods & Services--Add Group'}{order} = $i++; 1479 1480 foreach $item ( split /;/, $myconfig{acs} ) { 1481 delete $button{$item}; 1482 } 1483 } 1484 1485 print qq| 1486 </table> 1487 </td> 1488 </tr> 1489 <tr> 1490 <td><hr size=3 noshade></td> 1491 </tr> 1492</table> 1493 1494<br> 1495<form method=post action=$form->{script}> 1496|; 1497 1498 $form->hide_form(qw(callback type path login sessionid)); 1499 1500 foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) { 1501 print $item->{code}; 1502 } 1503 1504 if ( $form->{lynx} ) { 1505 require "bin/menu.pl"; 1506 &menubar; 1507 } 1508 1509 print qq| 1510 </form> 1511 1512</body> 1513</html> 1514|; 1515 1516} 1517 1518sub partsgroup_header { 1519 1520 $form->{action} =~ s/_.*//; 1521 $form->{title} = $locale->text( ucfirst $form->{action} . " Group" ); 1522 1523 # $locale->text('Add Group') 1524 # $locale->text('Edit Group') 1525 1526 $form->{partsgroup} = $form->quote( $form->{partsgroup} ); 1527 1528 $form->header; 1529 1530 print qq| 1531<body> 1532 1533<form method="post" action="$form->{script}"> 1534 1535<input type="hidden" name="id" value="$form->{id}"> 1536<input type="hidden" name="type" value="$form->{type}"> 1537 1538<table width="100%"> 1539 <tr> 1540 <th class=listtop>$form->{title}</th> 1541 </tr> 1542 <tr height="5"></tr> 1543 <tr> 1544 <td> 1545 <table width=100%> 1546 <tr> 1547 <th align=right>| . $locale->text('Group') . qq|</th> 1548 1549 <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td> 1550 </tr> 1551 </table> 1552 </td> 1553 </tr> 1554 <tr> 1555 <td colspan=2><hr size=3 noshade></td> 1556 </tr> 1557</table> 1558|; 1559 1560} 1561 1562sub partsgroup_footer { 1563 1564 $form->hide_form(qw(callback path login sessionid)); 1565 1566 if ( $myconfig{acs} !~ /Goods \& Services--Add Group/ ) { 1567 print qq| 1568<button type="submit" class="submit" name="action" value="save">| 1569 . $locale->text('Save') 1570 . qq|</button> 1571|; 1572 1573 if ( $form->{id} && $form->{orphaned} ) { 1574 print qq| 1575<button type="submit" class="submit" name="action" value="delete">| 1576 . $locale->text('Delete') 1577 . qq|</button>|; 1578 } 1579 } 1580 1581 if ( $form->{lynx} ) { 1582 require "bin/menu.pl"; 1583 &menubar; 1584 } 1585 1586 print qq| 1587</form> 1588 1589</body> 1590</html> 1591|; 1592 1593} 1594 1595sub pricegroup_report { 1596 1597 $form->{pricegroup} = $form->unescape( $form->{pricegroup} ); 1598 PE->pricegroups( \%myconfig, \%$form ); 1599 1600 $href = 1601"$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; 1602 1603 $form->sort_order(); 1604 1605 $callback = 1606"$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; 1607 1608 if ( $form->{status} eq 'all' ) { 1609 $option = $locale->text('All'); 1610 } 1611 if ( $form->{status} eq 'orphaned' ) { 1612 $option .= $locale->text('Orphaned'); 1613 } 1614 if ( $form->{pricegroup} ) { 1615 $callback .= "&pricegroup=$form->{pricegroup}"; 1616 $option .= 1617 "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}"; 1618 } 1619 1620 @column_index = $form->sort_columns(qw(pricegroup)); 1621 1622 $column_header{pricegroup} = 1623 qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>| 1624 . $locale->text('Pricegroup') 1625 . qq|</th>|; 1626 1627 $form->{title} = $locale->text('Pricegroups'); 1628 1629 $form->header; 1630 1631 print qq| 1632<body> 1633 1634<table width=100%> 1635 <tr> 1636 <th class=listtop>$form->{title}</th> 1637 </tr> 1638 <tr height="5"></tr> 1639 <tr> 1640 <td>$option</td> 1641 </tr> 1642 <tr> 1643 <td> 1644 <table width=100%> 1645 <tr class=listheading> 1646|; 1647 1648 for (@column_index) { print "$column_header{$_}\n" } 1649 1650 print qq| 1651 </tr> 1652|; 1653 1654 # escape callback 1655 $form->{callback} = $callback; 1656 1657 # escape callback for href 1658 $callback = $form->escape($callback); 1659 1660 foreach $ref ( @{ $form->{item_list} } ) { 1661 1662 $i++; 1663 $i %= 2; 1664 1665 print qq| 1666 <tr valign=top class=listrow$i> 1667|; 1668 1669 $column_data{pricegroup} = 1670qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{pricegroup}</td>|; 1671 for (@column_index) { print "$column_data{$_}\n" } 1672 1673 print " 1674 </tr> 1675"; 1676 } 1677 1678 $i = 1; 1679 if ( $myconfig{acs} !~ /Goods \& Services--Goods \& Services/ ) { 1680 $button{'Goods & Services--Add Pricegroup'}{code} = 1681qq|<button class="submit" type="submit" name="action" value="add_pricegroup">| 1682 . $locale->text('Add Pricegroup') 1683 . qq|</button> |; 1684 $button{'Goods & Services--Add Pricegroup'}{order} = $i++; 1685 1686 foreach $item ( split /;/, $myconfig{acs} ) { 1687 delete $button{$item}; 1688 } 1689 } 1690 1691 print qq| 1692 </table> 1693 </td> 1694 </tr> 1695 <tr> 1696 <td><hr size=3 noshade></td> 1697 </tr> 1698</table> 1699 1700<br> 1701<form method=post action=$form->{script}> 1702|; 1703 1704 $form->hide_form(qw(callback type path login sessionid)); 1705 1706 foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) { 1707 print $item->{code}; 1708 } 1709 1710 if ( $form->{lynx} ) { 1711 require "bin/menu.pl"; 1712 &menubar; 1713 } 1714 1715 print qq| 1716 </form> 1717 1718</body> 1719</html> 1720|; 1721 1722} 1723 1724sub pricegroup_header { 1725 1726 $form->{title} = $locale->text( ucfirst $form->{action} . " Pricegroup" ); 1727 1728 # $locale->text('Add Pricegroup') 1729 # $locale->text('Edit Pricegroup') 1730 1731 $form->{pricegroup} = $form->quote( $form->{pricegroup} ); 1732 1733 $form->header; 1734 1735 print qq| 1736<body> 1737 1738<form method="post" action="$form->{script}"> 1739 1740<input type="hidden" name="id" value="$form->{id}"> 1741<input type="hidden" name="type" value="$form->{type}"> 1742 1743<table width=100%> 1744 <tr> 1745 <th class=listtop>$form->{title}</th> 1746 </tr> 1747 <tr height="5"></tr> 1748 <tr> 1749 <td> 1750 <table width=100%> 1751 <tr> 1752 <th align=right>| . $locale->text('Pricegroup') . qq|</th> 1753 1754 <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td> 1755 </tr> 1756 </table> 1757 </td> 1758 </tr> 1759 <tr> 1760 <td colspan=2><hr size=3 noshade></td> 1761 </tr> 1762</table> 1763|; 1764 1765} 1766 1767sub pricegroup_footer { 1768 1769 $form->hide_form(qw(callback path login sessionid)); 1770 1771 if ( $myconfig{acs} !~ /Goods \& Services--Add Pricegroup/ ) { 1772 print qq| 1773<button type="submit" class="submit" name="action" value="save">| 1774 . $locale->text('Save') 1775 . qq|</button> 1776|; 1777 1778 if ( $form->{id} && $form->{orphaned} ) { 1779 print qq| 1780<button type="submit" class="submit" name="action" value="delete">| 1781 . $locale->text('Delete') 1782 . qq|</button>|; 1783 } 1784 } 1785 1786 if ( $form->{lynx} ) { 1787 require "bin/menu.pl"; 1788 &menubar; 1789 } 1790 1791 print qq| 1792</form> 1793 1794</body> 1795</html> 1796|; 1797 1798} 1799 1800sub translation { 1801 1802 if ( $form->{translation} eq 'description' ) { 1803 $form->{title} = $locale->text('Description Translations'); 1804 $sort = qq|<input type=hidden name=sort value=partnumber>|; 1805 $form->{number} = "partnumber"; 1806 $number = qq| 1807 <tr> 1808 <th align=right nowrap>| . $locale->text('Number') . qq|</th> 1809 <td><input name=partnumber size=20></td> 1810 </tr> 1811|; 1812 } 1813 1814 if ( $form->{translation} eq 'partsgroup' ) { 1815 $form->{title} = $locale->text('Group Translations'); 1816 $sort = qq|<input type=hidden name=sort value=partsgroup>|; 1817 } 1818 1819 if ( $form->{translation} eq 'project' ) { 1820 $form->{title} = $locale->text('Project Description Translations'); 1821 $form->{number} = "projectnumber"; 1822 $sort = qq|<input type=hidden name=sort value=projectnumber>|; 1823 $number = qq| 1824 <tr> 1825 <th align=right nowrap>| . $locale->text('Project Number') . qq|</th> 1826 <td><input name=projectnumber size=20></td> 1827 </tr> 1828|; 1829 } 1830 1831 $form->header; 1832 1833 print qq| 1834<body> 1835 1836<form method=post action=$form->{script}> 1837|; 1838 1839 $form->hide_form(qw(translation title number)); 1840 1841 print qq| 1842 1843<table width="100%"> 1844 <tr><th class=listtop>$form->{title}</th></tr> 1845 <tr height="5"></tr> 1846 <tr valign=top> 1847 <td> 1848 <table> 1849 $number 1850 <tr> 1851 <th align=right nowrap>| . $locale->text('Description') . qq|</th> 1852 <td colspan=3><input name=description size=40></td> 1853 </tr> 1854 </table> 1855 </td> 1856 </tr> 1857 <tr><td><hr size=3 noshade></td></tr> 1858</table> 1859 1860<input type=hidden name=nextsub value=list_translations> 1861$sort 1862|; 1863 1864 $form->hide_form(qw(path login sessionid)); 1865 1866 print qq| 1867 1868<br> 1869<button class="submit" type="submit" name="action" value="continue">| 1870 . $locale->text('Continue') 1871 . qq|</button> 1872</form> 1873 1874</body> 1875</html> 1876|; 1877 1878} 1879 1880sub list_translations { 1881 1882 $title = $form->escape( $form->{title}, 1 ); 1883 1884 $callback = 1885"$form->{script}?action=list_translations&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&translation=$form->{translation}&number=$form->{number}&title=$title"; 1886 1887 if ( $form->{"$form->{number}"} ) { 1888 $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|; 1889 $option .= 1890 $locale->text('Number') . qq| : $form->{"$form->{number}"}<br>|; 1891 } 1892 if ( $form->{description} ) { 1893 $callback .= "&description=$form->{description}"; 1894 $description = $form->{description}; 1895 $description =~ s/\r?\n/<br>/g; 1896 $option .= 1897 $locale->text('Description') . qq| : $form->{description}<br>|; 1898 } 1899 1900 if ( $form->{translation} eq 'partsgroup' ) { 1901 @column_index = qw(description language translation); 1902 $form->{sort} = ""; 1903 } 1904 else { 1905 @column_index = 1906 $form->sort_columns( "$form->{number}", "description", "language", 1907 "translation" ); 1908 } 1909 1910 &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form ); 1911 1912 $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}"; 1913 1914 $href = $callback; 1915 1916 $form->sort_order(); 1917 1918 $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/; 1919 1920 $column_header{"$form->{number}"} = 1921 qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>| 1922 . $locale->text('Number') 1923 . qq|</a></th>|; 1924 $column_header{description} = 1925 qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>| 1926 . $locale->text('Description') 1927 . qq|</a></th>|; 1928 $column_header{language} = 1929 qq|<th nowrap class=listheading>| 1930 . $locale->text('Language') 1931 . qq|</a></th>|; 1932 $column_header{translation} = 1933 qq|<th nowrap width=40% class=listheading>| 1934 . $locale->text('Translation') 1935 . qq|</a></th>|; 1936 1937 $form->header; 1938 1939 print qq| 1940<body> 1941 1942<table width=100%> 1943 <tr> 1944 <th class=listtop>$form->{title}</th> 1945 </tr> 1946 <tr height="5"></tr> 1947 1948 <tr><td>$option</td></tr> 1949 1950 <tr> 1951 <td> 1952 <table width=100%> 1953 <tr class=listheading> 1954|; 1955 1956 for (@column_index) { print "\n$column_header{$_}" } 1957 1958 print qq| 1959 </tr> 1960 |; 1961 1962 # add order to callback 1963 $form->{callback} = $callback .= "&sort=$form->{sort}"; 1964 1965 # escape callback for href 1966 $callback = $form->escape($callback); 1967 1968 if ( @{ $form->{translations} } ) { 1969 $sameitem = $form->{translations}->[0]->{ $form->{sort} }; 1970 } 1971 1972 foreach $ref ( @{ $form->{translations} } ) { 1973 1974 $ref->{description} =~ s/\r?\n/<br>/g; 1975 1976 for (@column_index) { $column_data{$_} = "<td>$ref->{$_} </td>" } 1977 1978 $column_data{description} = 1979"<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description} </a></td>"; 1980 1981 $i++; 1982 $i %= 2; 1983 print "<tr class=listrow$i>"; 1984 1985 for (@column_index) { print "\n$column_data{$_}" } 1986 1987 print qq| 1988 </tr> 1989|; 1990 1991 } 1992 1993 print qq| 1994 </table> 1995 </td> 1996 </tr> 1997 <tr><td><hr size=3 noshade></td></tr> 1998</table> 1999 2000|; 2001 2002 print qq| 2003 2004<br> 2005 2006<form method=post action=$form->{script}> 2007 2008<input name=callback type=hidden value="$form->{callback}"> 2009|; 2010 2011 $form->hide_form(qw(path login sessionid)); 2012 2013 if ( $form->{lynx} ) { 2014 require "bin/menu.pl"; 2015 &menubar; 2016 } 2017 2018 print qq| 2019 </form> 2020 2021</body> 2022</html> 2023|; 2024 2025} 2026 2027sub edit_translation { 2028 2029 &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form ); 2030 2031 $form->error( $locale->text('Languages not defined!') ) 2032 unless @{ $form->{all_language} }; 2033 2034 $form->{selectlanguage} = qq|<option>\n|; 2035 for ( @{ $form->{all_language} } ) { 2036 $form->{selectlanguage} .= 2037 qq|<option value="$_->{code}">$_->{description}\n|; 2038 } 2039 2040 $form->{"$form->{number}"} = 2041 $form->{translations}->[0]->{"$form->{number}"}; 2042 $form->{description} = $form->{translations}->[0]->{description}; 2043 $form->{description} =~ s/\r?\n/<br>/g; 2044 2045 shift @{ $form->{translations} }; 2046 2047 $i = 1; 2048 foreach $row ( @{ $form->{translations} } ) { 2049 $form->{"language_code_$i"} = $row->{code}; 2050 $form->{"translation_$i"} = $row->{translation}; 2051 $i++; 2052 } 2053 $form->{translation_rows} = $i - 1; 2054 2055 $form->{title} = $locale->text('Edit Description Translations'); 2056 2057 &translation_header; 2058 &translation_footer; 2059 2060} 2061 2062sub translation_header { 2063 2064 $form->{translation_rows}++; 2065 2066 $form->{selectlanguage} = $form->unescape( $form->{selectlanguage} ); 2067 for $i ( 1 .. $form->{translation_rows} ) { 2068 $form->{"selectlanguage_$i"} = $form->{selectlanguage}; 2069 if ( $form->{"language_code_$i"} ) { 2070 $form->{"selectlanguage_$i"} =~ 2071 s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/; 2072 } 2073 } 2074 2075 $form->{selectlanguage} = $form->escape( $form->{selectlanguage}, 1 ); 2076 2077 $form->header; 2078 2079 print qq| 2080<body> 2081 2082<form method=post action=$form->{script}> 2083 2084<input type=hidden name=$form->{number} value="| 2085 . $form->quote( $form->{"$form->{number}"} ) . qq|"> 2086<input type=hidden name=description value="| 2087 . $form->quote( $form->{description} ) . qq|"> 2088|; 2089 2090 $form->hide_form( 2091 qw(id trans_id selectlanguage translation_rows number translation title) 2092 ); 2093 2094 print qq| 2095 2096<table width="100%"> 2097 <tr><th class=listtop>$form->{title}</th></tr> 2098 <tr height="5"></tr> 2099 <tr valign=top> 2100 <td> 2101 <table width=100%> 2102 <tr> 2103 <td align=left>$form->{"$form->{number}"}</th> 2104 <td align=left>$form->{description}</th> 2105 </tr> 2106 <tr> 2107 <tr> 2108 <th class=listheading>| . $locale->text('Language') . qq|</th> 2109 <th class=listheading>| . $locale->text('Translation') . qq|</th> 2110 </tr> 2111|; 2112 2113 for $i ( 1 .. $form->{translation_rows} ) { 2114 2115 if ( ( $rows = $form->numtextrows( $form->{"translation_$i"}, 40 ) ) > 2116 1 ) 2117 { 2118 $translation = 2119qq|<textarea name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|; 2120 } 2121 else { 2122 $translation = 2123qq|<input name="translation_$i" size=40 value="$form->{"translation_$i"}">|; 2124 } 2125 2126 print qq| 2127 <tr valign=top> 2128 <td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td> 2129 <td>$translation</td> 2130 </tr> 2131|; 2132 } 2133 2134 print qq| 2135 </table> 2136 </td> 2137 </tr> 2138 <tr> 2139 <td><hr size=3 noshade></td> 2140 </tr> 2141</table> 2142|; 2143 2144} 2145 2146sub translation_footer { 2147 2148 $form->hide_form(qw(path login sessionid callback)); 2149 2150 %button = ( 2151 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 2152 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') }, 2153 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') }, 2154 ); 2155 2156 if ( !$form->{trans_id} ) { 2157 delete $button{'delete'}; 2158 } 2159 2160 for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { 2161 $form->print_button( \%button, $_ ); 2162 } 2163 2164 if ( $form->{lynx} ) { 2165 require "bin/menu.pl"; 2166 &menubar; 2167 } 2168 2169 print qq| 2170 2171 </form> 2172 2173</body> 2174</html> 2175|; 2176 2177} 2178 2179sub update { 2180 2181 if ( $form->{translation} ) { 2182 @flds = qw(language translation); 2183 $count = 0; 2184 @a = (); 2185 for $i ( 1 .. $form->{translation_rows} ) { 2186 if ( $form->{"language_code_$i"} ne "" ) { 2187 push @a, {}; 2188 $j = $#a; 2189 2190 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} } 2191 $count++; 2192 } 2193 } 2194 $form->redo_rows( \@flds, \@a, $count, $form->{translation_rows} ); 2195 $form->{translation_rows} = $count; 2196 2197 &translation_header; 2198 &translation_footer; 2199 2200 exit; 2201 2202 } 2203 2204 if ( $form->{type} =~ /(job|project)/ ) { 2205 2206 # $locale->text('Customer not on file!') 2207 # $locale->text('Vendor not on file!') 2208 2209 for (qw(production listprice sellprice weight)) { 2210 $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} ); 2211 } 2212 2213 $form->{projectnumber} = 2214 $form->update_defaults( \%myconfig, "projectnumber" ) 2215 unless $form->{projectnumber}; 2216 2217 if ( $form->{"select$form->{vc}"} ) { 2218 if ( $form->{startdate} ne $form->{oldstartdate} 2219 || $form->{enddate} ne $form->{oldenddate} ) 2220 { 2221 2222 PE->get_customer( \%myconfig, \%$form ); 2223 2224 if ( @{ $form->{"all_$form->{vc}"} } ) { 2225 $form->{"select$form->{vc}"} = qq|<option>\n|; 2226 for ( @{ $form->{"all_$form->{vc}"} } ) { 2227 $form->{"select$form->{vc}"} .= 2228 qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|; 2229 } 2230 } 2231 } 2232 2233 $form->{"old$form->{vc}"} = $form->{"$form->{vc}"}; 2234 ( $null, $form->{"$form->{vc}_id"} ) = split /--/, 2235 $form->{"$form->{vc}"}; 2236 2237 } 2238 else { 2239 2240 if ( $form->{"old$form->{vc}"} ne 2241 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| ) 2242 { 2243 2244 if ( 2245 ( 2246 $rv = $form->get_name( 2247 \%myconfig, $form->{vc}, $form->{startdate} 2248 ) 2249 ) > 1 2250 ) 2251 { 2252 &select_name; 2253 exit; 2254 } 2255 2256 if ( $rv == 1 ) { 2257 $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id}; 2258 $form->{"$form->{vc}"} = $form->{name_list}[0]->{name}; 2259 $form->{"old$form->{vc}"} = 2260 qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; 2261 } 2262 else { 2263 $msg = ucfirst $form->{vc} . " not on file!"; 2264 $form->error( $locale->text($msg) ); 2265 } 2266 } 2267 } 2268 } 2269 2270 &display_form; 2271 2272} 2273 2274sub select_name { 2275 2276 $label = ucfirst $form->{vc}; 2277 2278 @column_index = qw(ndx name address); 2279 $column_data{ndx} = qq|<th> </th>|; 2280 $column_data{name} = 2281 qq|<th class=listheading>| . $locale->text($label) . qq|</th>|; 2282 $column_data{address} = 2283 qq|<th class=listheading colspan=5>| 2284 . $locale->text('Address') 2285 . qq|</th>|; 2286 2287 $form->header; 2288 $title = $locale->text('Select from one of the names below'); 2289 print qq| 2290<body> 2291 2292<form method=post action=$form->{script}> 2293 2294<table width=100%> 2295 <tr> 2296 <th class=listtop>$title</th> 2297 </tr> 2298 <tr space=5></tr> 2299 <tr> 2300 <td> 2301 <table width=100%> 2302 <tr class=listheading>|; 2303 2304 for (@column_index) { print "\n$column_data{$_}" } 2305 2306 print qq| 2307 </tr> 2308|; 2309 2310 @column_index = qw(ndx name address city state zipcode country); 2311 2312 my $i = 0; 2313 foreach $ref ( @{ $form->{name_list} } ) { 2314 $checked = ( $i++ ) ? "" : "checked"; 2315 2316 $ref->{name} = $form->quote( $ref->{name} ); 2317 2318 $column_data{ndx} = 2319qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; 2320 $column_data{name} = 2321qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|; 2322 $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|; 2323 for (qw(city state zipcode country)) { 2324 $column_data{$_} = qq|<td>$ref->{$_} </td>|; 2325 } 2326 2327 $j++; 2328 $j %= 2; 2329 print qq| 2330 <tr class=listrow$j>|; 2331 2332 for (@column_index) { print "\n$column_data{$_}" } 2333 2334 print qq| 2335 </tr> 2336 2337<input name="new_id_$i" type=hidden value="$ref->{id}"> 2338 2339|; 2340 2341 } 2342 2343 print qq| 2344 </table> 2345 </td> 2346 </tr> 2347 <tr> 2348 <td><hr size=3 noshade></td> 2349 </tr> 2350</table> 2351 2352<input name=lastndx type=hidden value="$i"> 2353 2354|; 2355 2356 # delete variables 2357 for (qw(action nextsub name_list)) { delete $form->{$_} } 2358 2359 $form->hide_form; 2360 2361 print qq| 2362<input type="hidden" name="nextsub" value="name_selected"> 2363<br> 2364<button class="submit" type="submit" name="action" value="continue">| 2365 . $locale->text('Continue') 2366 . qq|</button> 2367</form> 2368 2369</body> 2370</html> 2371|; 2372 2373} 2374 2375sub name_selected { 2376 2377 # replace the variable with the one checked 2378 2379 # index for new item 2380 $i = $form->{ndx}; 2381 2382 $form->{ $form->{vc} } = $form->{"new_name_$i"}; 2383 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"}; 2384 $form->{"old$form->{vc}"} = 2385 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; 2386 2387 # delete all the new_ variables 2388 for $i ( 1 .. $form->{lastndx} ) { 2389 for (qw(id name)) { delete $form->{"new_${_}_$i"} } 2390 } 2391 2392 for (qw(ndx lastndx nextsub)) { delete $form->{$_} } 2393 2394 &display_form; 2395 2396} 2397 2398sub display_form { 2399 2400 &{"$form->{type}_header"}; 2401 &{"$form->{type}_footer"}; 2402 2403} 2404 2405sub continue { &{ $form->{nextsub} } } 2406 2407sub add_group { &add } 2408sub add_project { &add } 2409sub add_job { &add } 2410sub add_pricegroup { &add } 2411 2412sub project_sales_order { 2413 2414 PE->project_sales_order( \%myconfig, \%$form ); 2415 2416 if ( @{ $form->{all_years} } ) { 2417 $form->{selectaccountingyear} = "<option>\n"; 2418 for ( @{ $form->{all_years} } ) { 2419 $form->{selectaccountingyear} .= qq|<option>$_\n|; 2420 } 2421 2422 $form->{selectaccountingmonth} = "<option>\n"; 2423 for ( sort keys %{ $form->{all_month} } ) { 2424 $form->{selectaccountingmonth} .= 2425 qq|<option value=$_>| 2426 . $locale->text( $form->{all_month}{$_} ) . qq|\n|; 2427 } 2428 2429 $selectfrom = qq| 2430 <tr> 2431 <th align=right>| . $locale->text('Period') . qq|</th> 2432 <td colspan=3> 2433 <select name=month>$form->{selectaccountingmonth}</select> 2434 <select name=year>$form->{selectaccountingyear}</select> 2435 <input name=interval class=radio type=radio value=0 checked> | 2436 . $locale->text('Current') . qq| 2437 <input name=interval class=radio type=radio value=1> | 2438 . $locale->text('Month') . qq| 2439 <input name=interval class=radio type=radio value=3> | 2440 . $locale->text('Quarter') . qq| 2441 <input name=interval class=radio type=radio value=12> | 2442 . $locale->text('Year') . qq| 2443 </td> 2444 </tr> 2445|; 2446 } 2447 2448 $fromto = qq| 2449 <tr> 2450 <th align=right nowrap>| . $locale->text('Transaction Dates') . qq|</th> 2451 <td>| 2452 . $locale->text('From') 2453 . qq| <input name=transdatefrom size=11 title="$myconfig{dateformat}"> 2454 | 2455 . $locale->text('To') 2456 . qq| <input name=transdateto size=11 title="$myconfig{dateformat}"></td> 2457 </tr> 2458 $selectfrom 2459|; 2460 2461 if ( @{ $form->{all_project} } ) { 2462 $form->{selectprojectnumber} = "<option>\n"; 2463 for ( @{ $form->{all_project} } ) { 2464 $form->{selectprojectnumber} .= 2465qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|; 2466 } 2467 } 2468 else { 2469 $form->error( $locale->text('No open Projects!') ); 2470 } 2471 2472 if ( @{ $form->{all_employee} } ) { 2473 $form->{selectemployee} = "<option>\n"; 2474 for ( @{ $form->{all_employee} } ) { 2475 $form->{selectemployee} .= 2476 qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|; 2477 } 2478 2479 $employee = qq| 2480 <tr> 2481 <th align=right nowrap>| . $locale->text('Employee') . qq|</th> 2482 <td><select name=employee>$form->{selectemployee}</select></td> 2483 </tr> 2484|; 2485 } 2486 2487 $form->{title} = $locale->text('Generate Sales Orders'); 2488 $form->{vc} = "customer"; 2489 $form->{type} = "sales_order"; 2490 2491 $form->header; 2492 2493 print qq| 2494<body> 2495 2496<form method=post action=$form->{script}> 2497 2498<table width=100%> 2499 <tr> 2500 <th class=listtop>$form->{title}</th> 2501 </tr> 2502 <tr height="5"></tr> 2503 <tr valign=top> 2504 <td> 2505 <table> 2506 <tr> 2507 <th align=right>| . $locale->text('Project') . qq|</th> 2508 <td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td> 2509 </tr> 2510 $employee 2511 $fromto 2512 <tr> 2513 <th></th> 2514 <td><input name=summary type=radio class=radio value=1 checked> | 2515 . $locale->text('Summary') . qq| 2516 <input name=summary type=radio class=radio value=0> | 2517 . $locale->text('Detail') . qq| 2518 </td> 2519 </tr> 2520 </table> 2521 </td> 2522 </tr> 2523 <tr> 2524 <td><hr size=3 noshade></td> 2525 </tr> 2526</table> 2527 2528|; 2529 2530 $form->{nextsub} = "project_jcitems_list"; 2531 $form->hide_form(qw(path login sessionid nextsub type vc)); 2532 2533 print qq| 2534<button type="submit" class="submit" name="action" value="continue">| 2535 . $locale->text('Continue') 2536 . qq|</button> 2537 2538</form> 2539|; 2540 2541 if ( $form->{lynx} ) { 2542 require "bin/menu.pl"; 2543 &menubar; 2544 } 2545 2546 print qq| 2547 2548</body> 2549</html> 2550|; 2551 2552} 2553 2554sub project_jcitems_list { 2555 2556 $form->{projectnumber} = $form->unescape( $form->{projectnumber} ); 2557 $form->{employee} = $form->unescape( $form->{employee} ); 2558 $form->{callback} = "$form->{script}?action=project_jcitems_list"; 2559 for ( 2560 qw(month year interval summary transdatefrom transdateto login path sessionid nextsub type vc) 2561 ) 2562 { 2563 $form->{callback} .= "&$_=$form->{$_}"; 2564 } 2565 for (qw(employe projectnumber)) { 2566 $form->{callback} .= "&$_=" . $form->escape( $form->{$_}, 1 ); 2567 } 2568 2569 PE->get_jcitems( \%myconfig, \%$form ); 2570 2571 # flatten array 2572 $i = 1; 2573 foreach $ref ( @{ $form->{jcitems} } ) { 2574 2575 if ( $form->{summary} ) { 2576 2577 $thisitem = 2578 qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|; 2579 2580 if ( $thisitem eq $sameitem ) { 2581 2582 $i--; 2583 for (qw(qty amount)) { $form->{"${_}_$i"} += $ref->{$_} } 2584 $form->{"id_$i"} .= " $ref->{id}:$ref->{qty}"; 2585 if ( $form->{"notes_$i"} ) { 2586 $form->{"notes_$i"} .= qq|\n\n$ref->{notes}|; 2587 } 2588 else { 2589 $form->{"notes_$i"} = $ref->{notes}; 2590 } 2591 2592 } 2593 else { 2594 2595 for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} } 2596 2597 $form->{"checked_$i"} = 1; 2598 $form->{"$form->{vc}_$i"} = $ref->{ $form->{vc} }; 2599 $form->{"id_$i"} = "$ref->{id}:$ref->{qty}"; 2600 2601 } 2602 2603 $sameitem = 2604 qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|; 2605 } 2606 else { 2607 2608 for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} } 2609 $form->{"checked_$i"} = 1; 2610 $form->{"id_$i"} = "$ref->{id}:$ref->{qty}"; 2611 2612 } 2613 2614 $i++; 2615 2616 } 2617 2618 $form->{rowcount} = $i - 1; 2619 2620 for $i ( 1 .. $form->{rowcount} ) { 2621 for (qw(qty allocated)) { 2622 $form->{"${_}_$i"} = 2623 $form->format_amount( \%myconfig, $form->{"${_}_$i"} ); 2624 } 2625 for (qw(amount sellprice)) { 2626 $form->{"${_}_$i"} = 2627 $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 ); 2628 } 2629 } 2630 2631 &jcitems; 2632 2633} 2634 2635sub jcitems { 2636 2637 # $locale->text('Customer') 2638 # $locale->text('Vendor') 2639 2640 $vc = ucfirst $form->{vc}; 2641 2642 @column_index = qw(id projectnumber name); 2643 if ( !$form->{summary} ) { 2644 push @column_index, qw(transdate); 2645 } 2646 push @column_index, qw(partnumber description qty amount); 2647 2648 $column_header{id} = qq|<th> </th>|; 2649 $column_header{transdate} = 2650 qq|<th class=listheading>| . $locale->text('Date') . qq|</th>|; 2651 $column_header{partnumber} = 2652 qq|<th class=listheading>| 2653 . $locale->text('Service Code') 2654 . qq|<br>| 2655 . $locale->text('Part Number') 2656 . qq|</th>|; 2657 $column_header{projectnumber} = 2658 qq|<th class=listheading>| . $locale->text('Project Number') . qq|</th>|; 2659 $column_header{description} = 2660 qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|; 2661 $column_header{name} = qq|<th class=listheading>$vc</th>|; 2662 $column_header{qty} = 2663 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|; 2664 $column_header{amount} = 2665 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|; 2666 2667 if ( $form->{type} eq 'sales_order' ) { 2668 $form->{title} = $locale->text('Generate Sales Orders'); 2669 } 2670 2671 $form->header; 2672 2673 print qq| 2674<body> 2675 2676<form method=post action=$form->{script}> 2677 2678<table width=100%> 2679 <tr> 2680 <th class=listtop>$form->{title}</th> 2681 </tr> 2682 <tr height="5"></tr> 2683 <tr> 2684 <td> 2685 <table width=100%> 2686 <tr class=listheading>|; 2687 2688 for (@column_index) { print "\n$column_header{$_}" } 2689 2690 print qq| 2691 </tr> 2692|; 2693 2694 for $i ( 1 .. $form->{rowcount} ) { 2695 2696 for (@column_index) { 2697 $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>|; 2698 } 2699 for (qw(qty amount)) { 2700 $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>|; 2701 } 2702 2703 $checked = ( $form->{"checked_$i"} ) ? "checked" : ""; 2704 $column_data{id} = 2705qq|<td><input name="checked_$i" class=checkbox type=checkbox value="1" $checked></td>|; 2706 2707 if ( $form->{"$form->{vc}_id_$i"} ) { 2708 $column_data{name} = qq|<td>$form->{"$form->{vc}_$i"}</td>|; 2709 $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" ); 2710 } 2711 else { 2712 $column_data{name} = 2713qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|; 2714 } 2715 2716 for (qw(projectnumber partnumber description notes)) { 2717 $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} ); 2718 } 2719 $form->hide_form( map { "${_}_$i" } 2720 qw(id project_id parts_id projectnumber transdate partnumber description notes qty amount taxaccounts sellprice) 2721 ); 2722 2723 $j++; 2724 $j %= 2; 2725 print " 2726 <tr class=listrow$j>"; 2727 2728 for (@column_index) { print "\n$column_data{$_}" } 2729 2730 print qq| 2731 </tr> 2732|; 2733 2734 } 2735 2736 print qq| 2737 </table> 2738 </td> 2739 </tr> 2740 2741 <tr> 2742 <td><hr size=3 noshade></td> 2743 </tr> 2744</table> 2745 2746<br> 2747|; 2748 2749 $form->hide_form( 2750 qw(path login sessionid vc nextsub rowcount type currency defaultcurrency taxaccounts summary callback) 2751 ); 2752 2753 for ( split / /, $form->{taxaccounts} ) { $form->hide_form("${_}_rate") } 2754 2755 if ( $form->{rowcount} ) { 2756 print qq| 2757<button class="submit" type="submit" name="action" value="generate_sales_orders">| 2758 . $locale->text('Generate Sales Orders') 2759 . qq|</button>|; 2760 2761 print qq| 2762<button class="submit" type="submit" name="action" value="select_customer">| 2763 . $locale->text('Select Customer') 2764 . qq|</button>|; 2765 2766 } 2767 2768 if ( $form->{lynx} ) { 2769 require "bin/menu.pl"; 2770 &menubar; 2771 } 2772 2773 print qq| 2774</form> 2775 2776</body> 2777</html> 2778|; 2779 2780} 2781 2782sub select_customer { 2783 2784 for ( 1 .. $form->{rowcount} ) { 2785 last if ( $ok = $form->{"ndx_$_"} ); 2786 } 2787 2788 $form->error( $locale->text('Nothing selected!') ) unless $ok; 2789 2790 $label = 2791 ( $form->{vc} eq 'customer' ) 2792 ? $locale->text('Customer') 2793 : $locale->text('Vendor'); 2794 2795 $form->header; 2796 2797 print qq| 2798<body onLoad="document.forms[0].$form->{vc}.focus()"> 2799 2800<form method=post action=$form->{script}> 2801 2802<b>$label</b> <input name=$form->{vc} size=40> 2803 2804|; 2805 2806 $form->{nextsub} = "$form->{vc}_selected"; 2807 $form->{action} = "$form->{vc}_selected"; 2808 2809 $form->hide_form; 2810 2811 print qq| 2812<button class="submit" type="submit" name="action" value="continue">| 2813 . $locale->text('Continue') 2814 . qq|</button> 2815 2816</form> 2817|; 2818 2819 print qq| 2820 2821</body> 2822</html> 2823|; 2824 2825} 2826 2827sub customer_selected { 2828 2829 if ( 2830 ( 2831 $rv = $form->get_name( \%myconfig, $form->{vc}, $form->{startdate} ) 2832 ) > 1 2833 ) 2834 { 2835 &select_name( $form->{vc} ); 2836 exit; 2837 } 2838 2839 if ( $rv == 1 ) { 2840 $form->{"$form->{vc}"} = $form->{name_list}[0]->{name}; 2841 $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id}; 2842 } 2843 else { 2844 $msg = 2845 ( $form->{vc} eq 'customer' ) 2846 ? $locale->text('Customer not on file!') 2847 : $locale->text('Vendor not on file!'); 2848 $form->error( $locale->text($msg) ); 2849 } 2850 2851 &display_form; 2852 2853} 2854 2855sub sales_order_header { 2856 2857 for ( 1 .. $form->{rowcount} ) { 2858 if ( $form->{"ndx_$_"} ) { 2859 $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"}; 2860 $form->{"$form->{vc}_$_"} = $form->{"$form->{vc}"}; 2861 } 2862 } 2863 2864} 2865 2866sub sales_order_footer { &jcitems } 2867 2868sub generate_sales_orders { 2869 2870 for $i ( 1 .. $form->{rowcount} ) { 2871 $form->error( $locale->text('Customer missing!') ) 2872 if ( $form->{"checked_$i"} && !$form->{"customer_$i"} ); 2873 } 2874 2875 for $i ( 1 .. $form->{rowcount} ) { 2876 if ( $form->{"checked_$i"} ) { 2877 push @{ $form->{order}{qq|$form->{"customer_id_$i"}|} }, 2878 { 2879 partnumber => $form->{"partnumber_$i"}, 2880 id => $form->{"parts_id_$i"}, 2881 description => $form->{"description_$i"}, 2882 qty => $form->{"qty_$i"}, 2883 sellprice => $form->{"sellprice_$i"}, 2884 projectnumber => qq|--$form->{"project_id_$i"}|, 2885 reqdate => $form->{"transdate_$i"}, 2886 taxaccounts => $form->{"taxaccounts_$i"}, 2887 jcitems => $form->{"id_$i"}, 2888 notes => $form->{"notes_$i"}, 2889 }; 2890 } 2891 } 2892 2893 $order = new Form; 2894 for ( keys %{ $form->{order} } ) { 2895 $order->{dbh} = $form->{dbh}; 2896 2897 for (qw(type vc defaultcurrency login)) { $order->{$_} = $form->{$_} } 2898 for (qw(currency)) { $order->{$_} = $form->{$_} } 2899 for ( split / /, $form->{taxaccounts} ) { 2900 $order->{"${_}_rate"} = $form->{"${_}_rate"}; 2901 } 2902 2903 $i = 0; 2904 $order->{"$order->{vc}_id"} = $_; 2905 2906 AA->get_name( \%myconfig, \%$order ); 2907 PE->timecard_get_currency( \%$order ); 2908 2909 foreach $ref ( @{ $form->{order}{$_} } ) { 2910 $i++; 2911 2912 for ( keys %$ref ) { $order->{"${_}_$i"} = $ref->{$_} } 2913 2914 $taxaccounts = ""; 2915 for ( split / /, $order->{taxaccounts} ) { 2916 $taxaccounts .= qq|$_ | 2917 if ( $_ =~ /$order->{"taxaccounts_$i"}/ ); 2918 } 2919 $order->{"taxaccounts_$i"} = $taxaccounts; 2920 2921 } 2922 $order->{rowcount} = $i; 2923 2924 $order->{ordnumber} = $order->update_defaults( \%myconfig, 'sonumber' ); 2925 $order->{transdate} = $order->current_date( \%myconfig ); 2926 $order->{reqdate} = $order->{transdate}; 2927 2928 for (qw(intnotes employee employee_id)) { delete $order->{$_} } 2929 2930 if ( OE->save( \%myconfig, \%$order ) ) { 2931 if ( !PE->allocate_projectitems( \%myconfig, \%$order ) ) { 2932 OE->delete( \%myconfig, \%$order, 2933 ${LedgerSMB::Sysconfig::spool} ); 2934 } 2935 } 2936 else { 2937 $order->error( $locale->text('Failed to save order!') ); 2938 } 2939 2940 for ( keys %$order ) { delete $order->{$_} } 2941 2942 } 2943 2944 $form->redirect( $locale->text('Orders generated!') ); 2945 2946} 2947 2948