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# payroll module 11# 12#====================================================================== 13 14use SL::HR; 15use SL::User; 16use SL::AA; 17use SL::GL; 18 19require "$form->{path}/arap.pl"; 20require "$form->{path}/arapprn.pl"; 21 221; 23# end of main 24 25 26 27sub add { 28 29# $locale->text('Add Employee') 30# $locale->text('Add Deduction') 31# $locale->text('Add Payroll') 32 33 $label = "Add ".ucfirst $form->{db}; 34 $form->{title} = $locale->text($label); 35 36 $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}" unless $form->{callback}; 37 38 &{ "prepare_$form->{db}" }; 39 40 &display_form; 41 42} 43 44 45sub search { &{ "search_$form->{db}" } }; 46 47 48sub search_employee { 49 50 $form->all_roles(\%myconfig); 51 52 if (@{ $form->{all_acsrole} }) { 53 $selectrole = "\n"; 54 55 for (@{ $form->{all_acsrole} }) { $selectrole .= qq|$_->{description}--$_->{id}\n| } 56 57 $role = qq| 58 <tr> 59 <th align=right nowrap>|.$locale->text('Role').qq|</th> 60 <td><select name=acsrole>| 61 .$form->select_option($selectrole, undef, 1) 62 .qq|</select> 63 </td> 64 </tr> 65|; 66 } 67 68 $form->{title} = $locale->text('Employees'); 69 70 $form->helpref("search_employee", $myconfig{countrycode}); 71 72 @f = (); 73 74 push @f, qq|<input name="l_ndx" type=checkbox class=checkbox value=Y> |.$locale->text('Pos'); 75 push @f, qq|<input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID'); 76 push @f, qq|<input name="l_name" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Name'); 77 push @f, qq|<input name="l_employeenumber" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Number'); 78 push @f, qq|<input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address'); 79 push @f, qq|<input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City'); 80 push @f, qq|<input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province'); 81 push @f, qq|<input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code'); 82 push @f, qq|<input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country'); 83 push @f, qq|<input name="l_workphone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Work Phone'); 84 push @f, qq|<input name="l_workfax" type=checkbox class=checkbox value=Y checked> |.$locale->text('Work Fax'); 85 push @f, qq|<input name="l_workmobile" type=checkbox class=checkbox value=Y> |.$locale->text('Work Mobile'); 86 push @f, qq|<input name="l_homephone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Home Phone'); 87 push @f, qq|<input name="l_homemobile" type=checkbox class=checkbox value=Y checked> |.$locale->text('Home Mobile'); 88 push @f, qq|<input name="l_startdate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Startdate'); 89 push @f, qq|<input name="l_enddate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Enddate'); 90 push @f, qq|<input name="l_acsrole" type=checkbox class=checkbox value=Y checked> |.$locale->text('Role'); 91 push @f, qq|<input name="l_sales" type=checkbox class=checkbox value=Y> |.$locale->text('Sales'); 92 push @f, qq|<input name="l_payroll" type=checkbox class=checkbox value=Y> |.$locale->text('Payroll'); 93 push @f, qq|<input name="l_login" type=checkbox class=checkbox value=Y checked> |.$locale->text('Login'); 94 push @f, qq|<input name="l_email" type=checkbox class=checkbox value=Y> |.$locale->text('E-mail'); 95 push @f, qq|<input name="l_ssn" type=checkbox class=checkbox value=Y> |.$locale->text('SSN'); 96 push @f, qq|<input name="l_dob" type=checkbox class=checkbox value=Y> |.$locale->text('DOB'); 97 push @f, qq|<input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN'); 98 push @f, qq|<input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC'); 99 push @f, qq|<input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes'); 100 101 102 $form->header; 103 104 &calendar; 105 106 print qq| 107<body> 108 109<form method="post" name="main" action="$form->{script}" /> 110 111<table width=100%> 112 <tr> 113 <th class=listtop>$form->{helpref}$form->{title}</a></th> 114 </tr> 115 <tr height="5"></tr> 116 <tr valign=top> 117 <td> 118 <table> 119 <tr> 120 <th align=right nowrap>|.$locale->text('Employee Name').qq|</th> 121 <td colspan=3><input name=name size=35></td> 122 </tr> 123 <tr> 124 <th align=right nowrap>|.$locale->text('Employee Number').qq|</th> 125 <td colspan=3><input name=employeenumber size=35></td> 126 </tr> 127 <tr> 128 <th align=right nowrap>|.$locale->text('Employee Login').qq|</th> 129 <td colspan=3><input name=employeelogin size=35></td> 130 </tr> 131 $role 132 <tr> 133 <th align=right nowrap>|.$locale->text('Startdate').qq|</th> 134 <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "startdatefrom").$locale->text('To').qq| <input name=startdateto size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "startdateto").qq|</td> 135 </tr> 136 <tr valign=top> 137 <th align=right nowrap>|.$locale->text('Notes').qq|</th> 138 <td colspan=3><input name=notes size=40></td> 139 </tr> 140 <tr> 141 <td></td> 142 <td colspan=3><input name=status class=radio type=radio value=all checked> |.$locale->text('All').qq| 143 <input name=status class=radio type=radio value=active> |.$locale->text('Active').qq| 144 <input name=status class=radio type=radio value=inactive> |.$locale->text('Inactive').qq| 145 <input name=status class=radio type=radio value=orphaned> |.$locale->text('Orphaned').qq| 146 <input name=status class=radio type=radio value=sales> |.$locale->text('Sales').qq| 147 <input name=status class=radio type=radio value=payroll> |.$locale->text('Payroll').qq| 148 </tr> 149 <tr> 150 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> 151 <td colspan=3> 152 <table> 153|; 154 155 while (@f) { 156 print qq|<tr>\n|; 157 for (1 .. 5) { 158 print qq|<td nowrap>|. shift @f; 159 print qq|</td>\n|; 160 } 161 print qq|</tr>\n|; 162 } 163 164 print qq| 165 </table> 166 </td> 167 </tr> 168 </table> 169 </td> 170 </tr> 171 <tr> 172 <td><hr size=3 noshade></td> 173 </tr> 174</table> 175|; 176 177 $form->{nextsub} = "list_employees"; 178 179 $form->hide_form(qw(nextsub db path login)); 180 181 print qq| 182<br> 183<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> 184</form> 185|; 186 187 if ($form->{menubar}) { 188 require "$form->{path}/menu.pl"; 189 &menubar; 190 } 191 192 print qq| 193 194</body> 195</html> 196|; 197} 198 199 200sub list_employees { 201 202 HR->employees(\%myconfig, \%$form); 203 204 $href = "$form->{script}?action=list_employees"; 205 for (qw(direction oldsort db path login status)) { $href .= "&$_=$form->{$_}" } 206 207 $form->sort_order(); 208 209 $callback = "$form->{script}?action=list_employees"; 210 for (qw(direction oldsort db path login status)) { $callback .= "&$_=$form->{$_}" } 211 212 @columns = $form->sort_columns(qw(id employeenumber name address city state zipcode country workphone workfax workmobile homephone homemobile email startdate enddate ssn dob iban bic sales payroll acsrole login notes)); 213 unshift @columns, "ndx"; 214 215 $form->{l_acsrole} = "" if $form->{acsrole}; 216 217 for (@columns) { 218 if ($form->{"l_$_"} eq "Y") { 219 push @column_index, $_; 220 221 # add column to href and callback 222 $callback .= "&l_$_=Y"; 223 $href .= "&l_$_=Y"; 224 } 225 } 226 227 @columns = (); 228 for (@column_index) { 229 if ($_ eq 'address') { 230 push @columns, ('address1', 'address2'); 231 } else { 232 push @columns, $_; 233 } 234 } 235 @column_index = @columns; 236 237 $option = $locale->text('All'); 238 239 if ($form->{status} eq 'sales') { 240 $option = $locale->text('Sales'); 241 @column_index = grep !/sales/, @column_index; 242 } 243 if ($form->{status} eq 'orphaned') { 244 $option = $locale->text('Orphaned'); 245 } 246 if ($form->{status} eq 'active') { 247 $option = $locale->text('Active'); 248 } 249 if ($form->{status} eq 'inactive') { 250 $option = $locale->text('Inactive'); 251 } 252 if ($form->{status} eq 'payroll') { 253 $option = $locale->text('Payroll'); 254 @column_index = grep !/payroll/, @column_index; 255 } 256 257 if ($form->{employeenumber}) { 258 $callback .= "&employeenumber=".$form->escape($form->{employeenumber},1); 259 $href .= "&employeenumber=".$form->escape($form->{employeenumber}); 260 $option .= "\n<br>".$locale->text('Employee Number')." : $form->{employeenumber}"; 261 } 262 if ($form->{name}) { 263 $callback .= "&name=".$form->escape($form->{name},1); 264 $href .= "&name=".$form->escape($form->{name}); 265 $option .= "\n<br>".$locale->text('Employee Name')." : $form->{name}"; 266 } 267 if ($form->{employeelogin}) { 268 $callback .= "&employeelogin=".$form->escape($form->{employeelogin},1); 269 $href .= "&employeelogin=".$form->escape($form->{employeelogin}); 270 $option .= "\n<br>".$locale->text('Employee Login')." : $form->{employeelogin}"; 271 } 272 if ($form->{acsrole}) { 273 $callback .= "&acsrole=".$form->escape($form->{acsrole},1); 274 $href .= "&acsrole=".$form->escape($form->{acsrole}); 275 $acsrole = $form->{acsrole}; 276 $acsrole =~ s/--.*//g; 277 $option .= "\n<br>".$locale->text('Role')." : $acsrole"; 278 } 279 if ($form->{startdatefrom}) { 280 $callback .= "&startdatefrom=$form->{startdatefrom}"; 281 $href .= "&startdatefrom=$form->{startdatefrom}"; 282 $fromdate = $locale->date(\%myconfig, $form->{startdatefrom}, 1); 283 } 284 if ($form->{startdateto}) { 285 $callback .= "&startdateto=$form->{startdateto}"; 286 $href .= "&startdateto=$form->{startdateto}"; 287 $todate = $locale->date(\%myconfig, $form->{startdateto}, 1); 288 } 289 if ($fromdate || $todate) { 290 $option .= "\n<br>".$locale->text('Startdate')." $fromdate - $todate"; 291 } 292 293 if ($form->{notes}) { 294 $callback .= "¬es=".$form->escape($form->{notes},1); 295 $href .= "¬es=".$form->escape($form->{notes}); 296 $option .= "\n<br>" if $option; 297 $option .= $locale->text('Notes')." : $form->{notes}"; 298 } 299 300 $form->helpref("list_employees", $myconfig{countrycode}); 301 302 $href .= "&helpref=".$form->escape($form->{helpref}); 303 $callback .= "&helpref=".$form->escape($form->{helpref},1); 304 305 $form->{callback} = "$callback&sort=$form->{sort}"; 306 $callback = $form->escape($form->{callback}); 307 308 $column_header{ndx} = qq|<th class=listheading width=1%> </th>|; 309 $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|; 310 $column_header{employeenumber} = qq|<th><a class=listheading href=$href&sort=employeenumber>|.$locale->text('Number').qq|</a></th>|; 311 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|; 312 $column_header{address1} = qq|<th class=listheading>|.$locale->text('Address').qq|</a></th>|; 313 $column_header{address2} = qq|<th class=listheading> </th>|; 314 $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|; 315 $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|; 316 $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|; 317 $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|; 318 $column_header{workphone} = qq|<th><a class=listheading href=$href&sort=workphone>|.$locale->text('Work Phone').qq|</a></th>|; 319 $column_header{workfax} = qq|<th><a class=listheading href=$href&sort=workfax>|.$locale->text('Work Fax').qq|</a></th>|; 320 $column_header{workmobile} = qq|<th><a class=listheading href=$href&sort=workmobile>|.$locale->text('Work Mobile').qq|</a></th>|; 321 $column_header{homephone} = qq|<th><a class=listheading href=$href&sort=homephone>|.$locale->text('Home Phone').qq|</a></th>|; 322 $column_header{homemobile} = qq|<th><a class=listheading href=$href&sort=homemobile>|.$locale->text('Home Mobile').qq|</a></th>|; 323 324 $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|; 325 $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|; 326 $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|; 327 $column_header{acsrole} = qq|<th><a class=listheading href=$href&sort=acsrole>|.$locale->text('Role').qq|</a></th>|; 328 $column_header{login} = qq|<th><a class=listheading href=$href&sort=login>|.$locale->text('Login').qq|</a></th>|; 329 330 $column_header{sales} = qq|<th class=listheading>|.$locale->text('S').qq|</th>|; 331 $column_header{payroll} = qq|<th class=listheading>|.$locale->text('P').qq|</th>|; 332 $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|; 333 $column_header{ssn} = qq|<th><a class=listheading href=$href&sort=ssn>|.$locale->text('SSN').qq|</a></th>|; 334 $column_header{dob} = qq|<th><a class=listheading href=$href&sort=dob>|.$locale->text('DOB').qq|</a></th>|; 335 $column_header{iban} = qq|<th><a class=listheading href=$href&sort=iban>|.$locale->text('IBAN').qq|</a></th>|; 336 $column_header{bic} = qq|<th><a class=listheading href=$href&sort=bic>|.$locale->text('BIC').qq|</a></th>|; 337 338 $form->{title} = $locale->text('Employees') . " / $form->{company}"; 339 340 $form->header; 341 342 print qq| 343<body> 344 345<table width=100%> 346 <tr> 347 <th class=listtop>$form->{helpref}$form->{title}</a></th> 348 </tr> 349 <tr height="5"></tr> 350 <tr> 351 <td>$option</td> 352 </tr> 353 <tr> 354 <td> 355 <table width=100%> 356 <tr class=listheading> 357|; 358 359 for (@column_index) { print "$column_header{$_}\n" } 360 361 print qq| 362 </tr> 363|; 364 365 $i = 0; 366 foreach $ref (@{ $form->{all_employee} }) { 367 368 $i++; 369 370 $ref->{notes} =~ s/\r?\n/<br>/g; 371 for (@column_index) { $column_data{$_} = "<td>$ref->{$_} </td>" } 372 373 $column_data{ndx} = "<td align=right>$i</td>"; 374 375 for (qw(sales payroll)) { 376 $column_data{$_} = ($ref->{$_}) ? "<td>x</td>" : "<td> </td>"; 377 } 378 $column_data{acsrole} = qq|<td>$ref->{acsrole} </td>|; 379 380 $column_data{name} = "<td><a href=$form->{script}?action=edit&db=employee&id=$ref->{id}&path=$form->{path}&login=$form->{login}&status=$form->{status}&callback=$callback>$ref->{name} </td>"; 381 382 if ($ref->{email}) { 383 $email = $ref->{email}; 384 $email =~ s/</\</; 385 $email =~ s/>/\>/; 386 387 $column_data{email} = qq|<td><a href="mailto:$ref->{email}">$email</a></td>|; 388 } 389 390 $j++; $j %= 2; 391 print " 392 <tr class=listrow$j> 393"; 394 395 for (@column_index) { print "$column_data{$_}\n" } 396 397 print qq| 398 </tr> 399|; 400 401 } 402 403 $i = 1; 404 $button{'HR--Employees--Add Employee'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Employee').qq|"> |; 405 $button{'HR--Employees--Add Employee'}{order} = $i++; 406 407 foreach $item (split /;/, $myconfig{acs}) { 408 delete $button{$item}; 409 } 410 411 print qq| 412 </table> 413 </td> 414 </tr> 415 <tr> 416 <td><hr size=3 noshade></td> 417 </tr> 418</table> 419 420<br> 421<form method=post action=$form->{script}> 422|; 423 424 $form->hide_form(qw(callback db path login)); 425 426 foreach $item (sort { $a->{order} <=> $b->{order} } %button) { 427 print $item->{code}; 428 } 429 430 if ($form->{menubar}) { 431 require "$form->{path}/menu.pl"; 432 &menubar; 433 } 434 435 print qq| 436 </form> 437 438</body> 439</html> 440|; 441 442} 443 444 445sub edit { 446 447# $locale->text('Edit Employee') 448# $locale->text('Edit Deduction') 449# $locale->text('Edit Payroll') 450 451 $label = ucfirst $form->{db}; 452 $form->{title} = $locale->text("Edit $label"); 453 454 &{ "prepare_$form->{db}" }; 455 &display_form; 456 457} 458 459 460sub prepare_employee { 461 462 HR->get_employee(\%myconfig, \%$form); 463 464 for (keys %$form) { $form->{$_} = $form->quote($form->{$_}) } 465 466 for $key (qw(wage deduction acsrole paymentmethod)) { 467 if (@{ $form->{"all_$key"} }) { 468 $form->{"select$key"} = "\n"; 469 470 for (@{ $form->{"all_$key"} }) { $form->{"select$key"} .= qq|$_->{description}--$_->{id}\n| } 471 472 $form->{$key} = qq|$form->{$key}--$form->{"${key}_id"}|; 473 474 } 475 } 476 477 for $key (qw(wage deduction)) { delete $form->{$key} } 478 479 $form->{oldemployeelogin} = $form->{employeelogin}; 480 481 if ($form->{id}) { 482 if ($form->{employeelogin}) { 483 open FH, $memberfile; 484 @member = <FH>; 485 close FH; 486 487 while (@member) { 488 $_ = shift @member; 489 next if ! /\[$form->{employeelogin}\@$myconfig{dbname}\]/; 490 do { 491 chomp; 492 if (/^tan/) { 493 (undef, $form->{tan}) = split /=/, $_, 2; 494 } 495 if (/^password/) { 496 (undef, $form->{employeepassword}) = split /=/, $_, 2; 497 } 498 $_ = shift @member; 499 } until /^\s/; 500 } 501 } 502 } 503 504 $i = 0; 505 foreach $ref (@{ $form->{all_employeewage} }) { 506 $i++; 507 $form->{"wage_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id}; 508 } 509 $form->{wage_rows} = $i; 510 511 $i = 0; 512 foreach $ref (sort { $a->{edid} <=> $b->{edid} } @{ $form->{all_employeededuction} }) { 513 $i++; 514 $form->{"deduction_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id}; 515 $form->{"exempt_$i"} = $ref->{exempt}; 516 $form->{"maximum_$i"} = $ref->{maximum}; 517 $form->{"withholding_$i"} = ($ref->{withholding}) ? 1 : 0; 518 } 519 $form->{deduction_rows} = $i; 520 521 $i = 0; 522 foreach $ref (@{ $form->{all_payrate} }) { 523 $i++; 524 for (qw(rate above)) { $form->{"${_}_$i"} = $ref->{$_} } 525 } 526 $form->{payrate_rows} = $i; 527 528 $form->{payperiod} = "" unless $form->{payperiod} ; 529 530 for $key (qw(ap expense payment)) { 531 if (@{ $form->{"${key}_accounts"} }) { 532 $form->{"select$key"} = "\n"; 533 for (@{ $form->{"${key}_accounts"} }) { $form->{"select$key"} .= qq|$_->{accno}--$_->{description}\n| } 534 } 535 $form->{$key} = qq|$form->{$key}--$form->{"${key}_description"}|; 536 } 537 538 &all_references; 539 540 for (qw(paymentmethod payment ap wage deduction acsrole)) { $form->{"select$_"} = $form->escape($form->{"select$_"},1) } 541 542 if (! $form->{readonly}) { 543 $form->{readonly} = 1 if $myconfig{acs} =~ /Add Employee/; 544 } 545 546 $form->helpref("employee", $myconfig{countrycode}); 547 548} 549 550 551sub employee_header { 552 553 $reference_documents = &references; 554 555 $form->{deduction_rows}++; 556 $form->{payrate_rows}++; 557 $form->{wage_rows}++; 558 559 $form->header; 560 561 &calendar; 562 563 print qq| 564<body> 565 566<form method="post" name="main" action="$form->{script}" /> 567|; 568 569 $form->hide_form(qw(acs payrate_rows wage_rows deduction_rows reference_rows referenceurl status title helpref oldemployeelogin company)); 570 $form->hide_form(map { "select$_" } qw(paymentmethod payment ap wage deduction acsrole)); 571 572 $login = ""; 573 574 if ($form->{admin}) { 575 $sales = ($form->{sales}) ? "checked" : ""; 576 $tan = ($form->{tan}) ? "checked" : ""; 577 578 if ($form->{selectacsrole}) { 579 $login = qq| 580 <tr> 581 <th align=right>|.$locale->text('Role').qq|</th> 582 <td><select name=acsrole>| 583 .$form->select_option($form->{selectacsrole}, $form->{acsrole}, 1) 584 .qq|</select></td> 585 </tr> 586|; 587 } 588 589 $login .= qq| 590 <tr> 591 <th align=right nowrap>|.$locale->text('Login').qq|</th> 592 <td><input name=employeelogin size=20 value="$form->{employeelogin}"></td> 593 </tr> 594 <tr> 595 <th align=right nowrap>|.$locale->text('Password').qq|</th> 596 <td><input name=employeepassword size=20 value="$form->{employeepassword}"></td> 597 </tr> 598 <tr> 599 <th align=right>|.$locale->text('E-mail TAN').qq|</th> 600 <td><input name=tan class=checkbox type=checkbox value=1 $tan></td> 601 </tr> 602 <tr> 603 <th align=right>|.$locale->text('Sales').qq|</th> 604 <td><input name=sales class=checkbox type=checkbox value=1 $sales></td> 605 </tr> 606|; 607 } else { 608 ($acsrole) = split /--/, $form->{acsrole}; 609 if ($form->{selectacsrole}) { 610 $login = qq| 611 <tr> 612 <th align=right>|.$locale->text('Role').qq|</th> 613 <td>$acsrole</td> 614 </tr> 615|; 616 } 617 if ($form->{employeelogin}) { 618 $login .= qq| 619 <tr> 620 <th align=right nowrap>|.$locale->text('Login').qq|</th> 621 <td>$form->{employeelogin}</td> 622 </tr> 623|; 624 } 625 if ($form->{tan}) { 626 $login .= qq| 627 <tr> 628 <th align=right nowrap>|.$locale->text('E-mail TAN').qq|</th> 629 <td>x</td> 630 </tr> 631|; 632 } 633 if ($form->{sales}) { 634 $sales ||= "x"; 635 $login .= qq| 636 <tr> 637 <th align=right>|.$locale->text('Sales').qq|</th> 638 <td>$sales</td> 639 </tr> 640|; 641 } 642 643 $form->hide_form(qw(acsrole employeelogin sales tan employeepassword)); 644 } 645 646 if ($form->{id} && $form->{lock_employeenumber}) { 647 $employeenumber = qq| 648 <tr> 649 <th align=right nowrap>|.$locale->text('Employee Number').qq|</th> 650 <td>|.$form->quote($form->{employeenumber}).qq|</td> 651 </tr>|.$form->hide_form(qw(employeenumber lock_employeenumber)); 652 } else { 653 $employeenumber = qq| 654 <tr> 655 <th align=right nowrap>|.$locale->text('Employee Number').qq|</th> 656 <td><input name=employeenumber size=32 maxlength=32 value="|.$form->quote($form->{employeenumber}).qq|"></td> 657 </tr>|; 658 } 659 660 print qq| 661 662<table width=100%> 663 <tr> 664 <th class=listtop>$form->{helpref}$form->{title}</a></th> 665 </tr> 666 <tr height="5"></tr> 667 <tr> 668 <td> 669 <table> 670 <tr valign=top> 671 <td> 672 <table> 673 $employeenumber 674 <tr> 675 <th align=right nowrap>|.$locale->text('Name').qq| <font color=red>*</font></th> 676 <td><input name=name size=35 maxlength=64 value="|.$form->quote($form->{name}).qq|"></td> 677 </tr> 678 <tr> 679 <th align=right nowrap>|.$locale->text('Address').qq|</th> 680 <td><input name=address1 size=35 maxlength=32 value="|.$form->quote($form->{address1}).qq|"></td> 681 </tr> 682 <tr> 683 <th></th> 684 <td><input name=address2 size=35 maxlength=32 value="|.$form->quote($form->{address2}).qq|"></td> 685 </tr> 686 <tr> 687 <th align=right nowrap>|.$locale->text('City').qq|</th> 688 <td><input name=city size=35 maxlength=32 value="|.$form->quote($form->{city}).qq|"></td> 689 </tr> 690 <tr> 691 <th align=right nowrap>|.$locale->text('State/Province').qq|</th> 692 <td><input name=state size=35 maxlength=32 value="|.$form->quote($form->{state}).qq|"></td> 693 </tr> 694 <tr> 695 <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th> 696 <td><input name=zipcode size=10 maxlength=10 value="|.$form->quote($form->{zipcode}).qq|"></td> 697 </tr> 698 <tr> 699 <th align=right nowrap>|.$locale->text('Country').qq|</th> 700 <td><input name=country size=35 maxlength=32 value="|.$form->quote($form->{country}).qq|"></td> 701 </tr> 702 <tr> 703 <th align=right nowrap>|.$locale->text('E-mail').qq|</th> 704 <td><input name=email size=35 value="$form->{email}"></td> 705 </tr> 706 $login 707 </table> 708 </td> 709 <td> 710 <table> 711 <tr> 712 <th align=right nowrap>|.$locale->text('Work Phone').qq|</th> 713 <td><input name=workphone size=20 maxlength=20 value="$form->{workphone}"></td> 714 </tr> 715 <tr> 716 <th align=right nowrap>|.$locale->text('Work Fax').qq|</th> 717 <td><input name=workfax size=20 maxlength=20 value="$form->{workfax}"></td> 718 </tr> 719 <tr> 720 <th align=right nowrap>|.$locale->text('Work Mobile').qq|</th> 721 <td><input name=workmobile size=20 maxlength=20 value="$form->{workmobile}"></td> 722 </tr> 723 <tr> 724 <th align=right nowrap>|.$locale->text('Home Phone').qq|</th> 725 <td><input name=homephone size=20 maxlength=20 value="$form->{homephone}"></td> 726 </tr> 727 <tr> 728 <th align=right nowrap>|.$locale->text('Home Mobile').qq|</th> 729 <td><input name=homemobile size=20 maxlength=20 value="$form->{homemobile}"></td> 730 </tr> 731 <tr> 732 <th align=right nowrap>|.$locale->text('Startdate').qq|</th> 733 <td><input name=startdate size=11 class=date title="$myconfig{dateformat}" value=$form->{startdate}>|.&js_calendar("main", "startdate").qq|</td> 734 </tr> 735 <tr> 736 <th align=right nowrap>|.$locale->text('Enddate').qq|</th> 737 <td><input name=enddate size=11 class=date title="$myconfig{dateformat}" value=$form->{enddate}>|.&js_calendar("main", "enddate").qq|</td> 738 </tr> 739 740 <tr> 741 <th align=right nowrap>|.$locale->text('SSN').qq|</th> 742 <td><input name=ssn size=20 maxlength=20 value="|.$form->quote($form->{ssn}).qq|"></td> 743 </tr> 744 <tr> 745 <th align=right nowrap>|.$locale->text('DOB').qq|</th> 746 <td><input name=dob size=11 class=date title="$myconfig{dateformat}" value=$form->{dob}>|.&js_calendar("main", "dob").qq|</td> 747 </tr> 748 <tr valign=top> 749 <th align=right nowrap>|.$locale->text('Notes').qq|</th> 750 <td><textarea name=notes rows=3 cols=32>$form->{notes}</textarea></td> 751 </tr> 752 </table> 753 </td> 754 </tr> 755 <tr valign=top> 756 <td> 757 <table> 758 <tr> 759 <th align=right nowrap>|.$locale->text('Bank').qq|</th> 760 <td><input name=bankname size=32 maxlength=64 value="|.$form->quote($form->{bankname}).qq|"></td> 761 </tr> 762 <tr> 763 <th align=right nowrap>|.$locale->text('Address').qq|</th> 764 <td><input name=bankaddress1 size=32 maxlength=32 value="|.$form->quote($form->{bankaddress1}).qq|"></td> 765 </tr> 766 <tr> 767 <th></th> 768 <td><input name=bankaddress2 size=32 maxlength=32 value="|.$form->quote($form->{bankaddress2}).qq|"></td> 769 </tr> 770 <tr> 771 <th align=right nowrap>|.$locale->text('City').qq|</th> 772 <td><input name=bankcity size=32 maxlength=32 value="|.$form->quote($form->{bankcity}).qq|"></td> 773 </tr> 774 <tr> 775 <th align=right nowrap>|.$locale->text('State/Province').qq|</th> 776 <td><input name=bankstate size=32 maxlength=32 value="|.$form->quote($form->{bankstate}).qq|"></td> 777 </tr> 778 <tr> 779 <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th> 780 <td><input name=bankzipcode size=11 maxlength=10 value="|.$form->quote($form->{bankzipcode}).qq|"></td> 781 </tr> 782 <tr> 783 <th align=right nowrap>|.$locale->text('Country').qq|</th> 784 <td><input name=bankcountry size=32 maxlength=32 value="|.$form->quote($form->{bankcountry}).qq|"></td> 785 </tr> 786 </table> 787 </td> 788 <td> 789 <table> 790 <tr> 791 <th align=right nowrap>|.$locale->text('IBAN').qq|</th> 792 <td><input name=iban size=34 maxlength=34 value="|.$form->quote($form->{iban}).qq|"></td> 793 </tr> 794 <tr> 795 <th align=right nowrap>|.$locale->text('BIC').qq|</th> 796 <td><input name=bic size=11 maxlength=11 value="|.$form->quote($form->{bic}).qq|"></td> 797 </tr> 798 <tr> 799 <th align=right nowrap>|.$locale->text('Member No.').qq|</th> 800 <td><input name=membernumber size=20 value="$form->{membernumber}"></td> 801 </tr> 802 <tr> 803 <th align=right nowrap>|.$locale->text('Clearing No.').qq|</th> 804 <td><input name=clearingnumber size=20 value="$form->{clearingnumber}"></td> 805 </tr> 806 </table> 807 </td> 808 </tr> 809 $reference_documents 810 </table> 811 </td> 812 </tr> 813 <tr> 814 <td> 815 <table> 816 <tr valign=top> 817|; 818 if ($form->{selectwage}) { 819 820 print qq| 821 <td> 822 <table> 823 <tr class=listheading> 824 <th class=listheading>|.$locale->text('Wages').qq|</th> 825 </tr> 826|; 827 828 for $i (1 .. $form->{wage_rows}) { 829 830 print qq| 831 <tr> 832 <td><select name="wage_$i">| 833 .$form->select_option($form->{selectwage}, $form->{"wage_$i"}, 1) 834 .qq|</select></td> 835 </tr> 836|; 837 } 838 print qq| 839 </table> 840 </td> 841|; 842 } 843 844 if ($form->{selectdeduction}) { 845 846 print qq| 847 <td> 848 <table> 849 <tr class=listheading> 850 <th class=listheading>|.$locale->text('Payroll Deduction').qq|</th> 851 <th class=listheading>|.$locale->text('Exempt').qq|</th> 852 <th class=listheading>|.$locale->text('Maximum').qq|</th> 853 </tr> 854|; 855 856 for $i (1 .. $form->{deduction_rows}) { 857 858 print qq| 859 <tr> 860 <td><select name="deduction_$i">| 861 .$form->select_option($form->{selectdeduction}, $form->{"deduction_$i"}, 1) 862 .qq|</select></td> 863 <td><input name="exempt_$i" class="inputright" value=|.$form->format_amount(\%myconfig, $form->{"exempt_$i"}, $form->{precision}).qq|></td> 864 <td><input name="maximum_$i" class="inputright" value=|.$form->format_amount(\%myconfig, $form->{"maximum_$i"}, $form->{precision}).qq|></td> 865 </tr> 866|; 867 } 868 print qq| 869 </table> 870 </td> 871 </tr> 872|; 873 } 874 875 if ($form->{selectpaymentmethod}) { 876 $paymentmethod = qq| 877 <tr> 878 <th align=right>|.$locale->text('Method').qq|</th> 879 <td><select name="paymentmethod">| 880 .$form->select_option($form->{selectpaymentmethod}, $form->{paymentmethod}, 1) 881 .qq|</select></td> 882 </tr> 883|; 884 } 885 886 print qq| 887 </tr> 888 <tr valign=top> 889 <td> 890 <table> 891 <tr> 892 <th align=right>|.$locale->text('AP').qq|</th> 893 <td><select name="ap">| 894 .$form->select_option($form->{selectap}, $form->{ap}) 895 .qq|</select></td> 896 </tr> 897 <tr> 898 <th align=right>|.$locale->text('Payment').qq|</th> 899 <td><select name="payment">| 900 .$form->select_option($form->{selectpayment}, $form->{payment}) 901 .qq|</select></td> 902 </tr> 903 $paymentmethod 904 <tr> 905 <th align=right nowrap>|.$locale->text('Pay Periods').qq|</th> 906 <td><input name=payperiod class="inputright" size=3 value=$form->{payperiod}></td> 907 </tr> 908 </table> 909 </td> 910 911 <td> 912 <table> 913 <tr> 914 <th class=listheading>|.$locale->text('Pay Rates').qq|</th> 915 <th class=listheading>|.$locale->text('Over').qq|</th> 916 </tr> 917|; 918 919 for $i (1 .. $form->{payrate_rows}) { 920 print qq| 921 <tr> 922 <td><input name="rate_$i" size=10 class="inputright" value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}, $form->{precision}).qq|></td> 923 <td><input name="above_$i" size=10 class="inputright" value=|.$form->format_amount(\%myconfig, $form->{"above_$i"}).qq|></td> 924 </tr> 925|; 926 } 927 928 print qq| 929 </table> 930 </td> 931 </tr> 932 </table> 933 </td> 934 </tr> 935 <tr> 936 <td><hr size=3 noshade></td> 937 </tr> 938</table> 939|; 940 941} 942 943 944sub employee_footer { 945 946 $form->hide_form(qw(precision id db addressid path login callback)); 947 948 if ($form->{readonly}) { 949 950 &islocked; 951 952 } else { 953 954 %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 955 'Save' => { ndx => 2, key => 'S', value => $locale->text('Save') }, 956 'Save as new' => { ndx => 5, key => 'N', value => $locale->text('Save as new') }, 957 'Access Control' => { ndx => 6, key => 'A', value => $locale->text('Access Control') }, 958 'New Number' => { ndx => 15, key => 'M', value => $locale->text('New Number') }, 959 'Delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') }, 960 ); 961 962 %f = (); 963 for ("Update", "Save", "Save as new", "New Number") { $f{$_} = 1 } 964 965 if ($form->{id}) { 966 if ($form->{status} eq 'orphaned') { 967 $f{'Delete'} = 1; 968 } 969 } 970 if ($form->{admin}) { 971 $f{'Access Control'} = 1; 972 } else { 973 if ($form->{employeelogin}) { 974 delete $f{Delete}; 975 } 976 } 977 978 for (keys %button) { delete $button{$_} if ! $f{$_} } 979 980 $form->print_button(\%button); 981 982 } 983 984 if ($form->{menubar}) { 985 require "$form->{path}/menu.pl"; 986 &menubar; 987 } 988 989 print qq| 990 991 </form> 992 993</body> 994</html> 995|; 996 997} 998 999 1000sub access_control { 1001 1002 $menufile = "menu.ini"; 1003 1004 $form->helpref("access_control", $myconfig{countrycode}); 1005 1006 $form->header; 1007 1008 print qq| 1009<body> 1010 1011<form method=post action=$form->{script}> 1012 1013<table width=100%> 1014 <tr> 1015 <th class=listtop colspan=2>$form->{name}</a></th> 1016 </tr> 1017 <tr height="5"></tr> 1018|; 1019 1020 # access control 1021 open(FH, $menufile) or $form->error("$menufile : $!"); 1022 # scan for first menu level 1023 @f = <FH>; 1024 close(FH); 1025 1026 if (open(FH, "$form->{path}/custom/$menufile")) { 1027 push @f, <FH>; 1028 } 1029 close(FH); 1030 1031 foreach $item (@f) { 1032 next unless $item =~ /\[\w+/; 1033 next if $item =~ /\#/; 1034 1035 $item =~ s/(\[|\])//g; 1036 chomp $item; 1037 1038 if ($item =~ /--/) { 1039 ($level, $menuitem) = split /--/, $item, 2; 1040 } else { 1041 $level = $item; 1042 $menuitem = $item; 1043 push @acsorder, $item; 1044 } 1045 1046 push @{ $acs{$level} }, $menuitem; 1047 1048 } 1049 1050 foreach $item (split /;/, HR->acsrole(\%myconfig, \%$form)) { 1051 ($key, $value) = split /--/, $item, 2; 1052 $disabled{$key}{$value} = 1; 1053 } 1054 1055 foreach $item (split /;/, $form->{acs}) { 1056 ($key, $value) = split /--/, $item, 2; 1057 $excl{$key}{$value} = 1; 1058 } 1059 1060 foreach $key (@acsorder) { 1061 1062 next if $disabled{$key}{$key}; 1063 $checked = ($excl{$key}{$key}) ? "" : "checked"; 1064 1065 # can't have variable names with & and spaces 1066 $item = $form->escape("${key}--$key",1); 1067 1068 $acsheading = $key; 1069 $acsheading =~ s/ / /g; 1070 1071 $acsheading = qq| 1072 <th align=left nowrap><input name="$item" class=checkbox type=checkbox value=1 $checked> $acsheading</th>\n|; 1073 $menuitems .= "$item;"; 1074 1075 $acsdata = qq| 1076 <td>|; 1077 1078 foreach $item (@{ $acs{$key} }) { 1079 next if ($key eq $item); 1080 if ($disabled{$key}{$item}) { 1081 $skipitem = "$item--"; 1082 next; 1083 } 1084 next if $skipitem && $item =~ /$skipitem/; 1085 $skipitem = ""; 1086 1087 $checked = ($excl{$key}{$item}) ? "" : "checked"; 1088 1089 $acsitem = $form->escape("${key}--$item",1); 1090 1091 $acsdata .= qq| 1092 <br><input name="$acsitem" class=checkbox type=checkbox value=1 $checked> $item|; 1093 $menuitems .= "$acsitem;"; 1094 } 1095 $acsdata .= qq| 1096 </td>|; 1097 1098 print qq| 1099 <tr valign=top>$acsheading $acsdata 1100 </tr> 1101|; 1102 } 1103 1104 $form->{access} = "$menuitems"; 1105 1106 print qq| 1107 <tr> 1108 <td colspan=2><hr size=3 noshade></td> 1109 </tr> 1110</table> 1111|; 1112 1113 delete $form->{action}; 1114 1115 $form->{nextsub} = "save_acs"; 1116 1117 $form->hide_form; 1118 1119 %button = ('Continue' => { ndx => 1, key => 'C', value => $locale->text('Continue') } 1120 ); 1121 1122 $form->print_button(\%button); 1123 1124 print qq| 1125 1126 </form> 1127 1128</body> 1129</html> 1130|; 1131 1132} 1133 1134 1135sub save_acs { 1136 1137 $form->{acs} = ""; 1138 for (split /;/, $form->{access}) { 1139 $item = $form->escape($_,1); 1140 if (!$form->{$item}) { 1141 if ($heading) { 1142 if ($item !~ /^$heading/) { 1143 $form->{acs} .= $form->unescape($_).";"; 1144 $heading = "$item--"; 1145 } 1146 } else { 1147 $form->{acs} .= $form->unescape($_).";"; 1148 ($item1, $item2) = split /--/, $item; 1149 if ($item1 eq $item2) { 1150 $heading = "$item1--"; 1151 } else { 1152 $heading = "$item--"; 1153 } 1154 } 1155 } 1156 } 1157 1158 $form->{deduction_rows}--; 1159 $form->{payrate_rows}--; 1160 $form->{wage_rows}--; 1161 1162 &display_form; 1163 1164} 1165 1166 1167sub display_form { 1168 1169 &{ "$form->{db}_header" }; 1170 &{ "$form->{db}_footer" }; 1171 1172} 1173 1174 1175sub save { &{ "save_$form->{db}" } }; 1176 1177 1178sub save_employee { 1179 1180 $form->isblank("name", $locale->text("Name missing!")); 1181 $form->error("$memberfile : ".$locale->text('locked!')) if (-f ${memberfile}.LCK); 1182 $form->error($locale->text('Cannot use admin as login!')) if $form->{employeelogin} eq 'admin'; 1183 1184 $form->{userspath} = $userspath; 1185 1186 if (HR->save_employee(\%myconfig, \%$form)) { 1187 &save_memberfile; 1188 } 1189 1190 $form->redirect($locale->text('Employee saved!')); 1191 1192} 1193 1194 1195sub save_memberfile { 1196 1197 # change memberfile 1198 open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!"); 1199 close(FH); 1200 1201 if (! open(FH, "+<$memberfile")) { 1202 unlink "${memberfile}.LCK"; 1203 $form->error("$memberfile : $!"); 1204 } 1205 1206 $login = ""; 1207 while (<FH>) { 1208 if (/^\[/) { 1209 s/(\[|\])//g; 1210 chomp; 1211 $login = $_; 1212 next; 1213 } 1214 1215 if ($login) { 1216 push @{ $member{$login} }, $_; 1217 } else { 1218 push @member, $_; 1219 } 1220 } 1221 1222 ($form->{templates}) = grep /^templates=/, @{ $member{"admin\@$myconfig{dbname}"} }; 1223 $form->{templates} =~ s/templates=//; 1224 chomp $form->{templates}; 1225 $form->{templates} ||= $myconfig{dbname}; 1226 1227 if ($form->{employeelogin}) { 1228 $employeelogin = $form->{employeelogin}; 1229 $employeelogin .= "\@$myconfig{dbname}"; # new format 1230 1231 unlink "$userspath/${employeelogin}.tan"; 1232 1233 # assign values from old entries 1234 $oldlogin = $form->{oldemployeelogin}; 1235 $oldlogin .= "\@$myconfig{dbname}"; 1236 1237 srand( time() ^ ($$ + ($$ << 15)) ); 1238 1239 if (@{ $member{$oldlogin} }) { 1240 @memberlogin = grep !/^(name|email|password|tan|templates)=/, @{ $member{$oldlogin} }; 1241 ($oldemployeepassword) = grep /^password=/, @{ $member{$oldlogin} }; 1242 pop @memberlogin; 1243 1244 $oldemployeepassword =~ s/password=//; 1245 chomp $oldemployeepassword; 1246 1247 $form->{employeepassword} = $oldemployeepassword if $form->{nochange}; 1248 1249 if ($form->{employeepassword} ne $oldemployeepassword) { 1250 if ($form->{employeepassword}) { 1251 $password = crypt $form->{employeepassword}, substr($form->{employeelogin}, 0, 2); 1252 push @memberlogin, "password=$password\n"; 1253 } 1254 } else { 1255 if ($oldemployeepassword) { 1256 push @memberlogin, "password=$oldemployeepassword\n"; 1257 } 1258 } 1259 1260 for (qw(name email tan templates)) { push @memberlogin, "$_=$form->{$_}\n" if $form->{$_} } 1261 1262 @{ $member{$employeelogin} } = (); 1263 1264 for (sort @memberlogin) { 1265 push @{ $member{$employeelogin} }, $_; 1266 } 1267 1268 } else { 1269 for (qw(company dateformat dbconnect dbdriver dbname dbhost dboptions dbpasswd dbuser numberformat)) { $m{$_} = $myconfig{$_} } 1270 for (qw(name email tan templates)) { $m{$_} = $form->{$_} } 1271 1272 $m{dbpasswd} = pack 'u', $myconfig{dbpasswd}; 1273 chop $m{dbpasswd}; 1274 $m{stylesheet} = 'sql-ledger.css'; 1275 $m{timeout} = 86400; 1276 1277 if ($form->{employeepassword}) { 1278 $m{password} = crypt $form->{employeepassword}, substr($form->{employeelogin}, 0, 2); 1279 } 1280 1281 @{ $member{$employeelogin} } = (); 1282 1283 for (sort keys %m) { 1284 push @{ $member{$employeelogin} }, "$_=$m{$_}\n" if $m{$_}; 1285 } 1286 } 1287 push @{ $member{$employeelogin} }, "\n"; 1288 } 1289 1290 if ($form->{employeelogin} ne $form->{oldemployeelogin}) { 1291 delete $member{$form->{oldemployeelogin}}; # old format 1292 delete $member{"$form->{oldemployeelogin}\@$myconfig{dbname}"}; 1293 } 1294 1295 seek(FH, 0, 0); 1296 truncate(FH, 0); 1297 1298 # create header 1299 for (@member) { 1300 print FH $_; 1301 } 1302 1303 for (sort keys %member) { 1304 print FH "\[$_\]\n"; 1305 for $line (@{ $member{$_} }) { 1306 print FH $line; 1307 } 1308 } 1309 close(FH); 1310 1311 if ($form->{employeelogin} ne $form->{oldemployeelogin}) { 1312 if ($form->{oldemployeelogin}) { 1313 for ("$form->{oldemployeelogin}.conf", "$form->{oldemployeelogin}\@$myconfig{dbname}.conf") { 1314 $filename = "$userspath/$_"; 1315 if (-f $filename) { 1316 unlink "$filename"; 1317 } 1318 } 1319 } 1320 } 1321 1322 unlink "${memberfile}.LCK"; 1323 1324} 1325 1326 1327sub delete { &{ "delete_$form->{db}" } }; 1328 1329 1330sub delete_payroll { 1331 1332 $form->{title} = $locale->text('Confirm!'); 1333 1334 $form->header; 1335 1336 print qq| 1337<body> 1338 1339<form method=post action=$form->{script}> 1340|; 1341 1342 $form->{action} = "yes"; 1343 $form->hide_form; 1344 1345 print qq| 1346<h2 class=confirm>$form->{title}</h2> 1347 1348<h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4> 1349 1350<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> 1351</form> 1352 1353</body> 1354</html> 1355|; 1356 1357} 1358 1359 1360sub yes { 1361 1362 if (AA->delete_transaction(\%myconfig, \%$form)) { 1363 $form->redirect($locale->text('Transaction deleted!')); 1364 } 1365 1366 $form->error($locale->text('Cannot delete transaction!')); 1367 1368} 1369 1370 1371sub delete_employee { 1372 1373 $form->error("$memberfile : ".$locale->text('locked!')) if (-f ${memberfile}.LCK); 1374 1375 if (HR->delete_employee(\%myconfig, \%$form)) { 1376 delete $form->{employeelogin}; 1377 1378 &save_memberfile; 1379 1380 $form->redirect($locale->text('Employee deleted!')); 1381 } 1382 1383 $form->error($locale->text('Cannot delete employee!')); 1384 1385} 1386 1387 1388sub continue { &{ $form->{nextsub} } }; 1389 1390sub add_employee { &add }; 1391sub add_deduction { &add }; 1392sub add_wage { &add }; 1393sub add_transaction { &add }; 1394 1395 1396sub prepare_payroll { 1397 1398 HR->payroll_links(\%myconfig, \%$form); 1399 1400 if (@{ $form->{all_language} }) { 1401 $form->{selectlanguage} = "\n"; 1402 for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|$_->{code}--$_->{description}\n| } 1403 } 1404 1405 for $key (qw(ap payment)) { 1406 if (@{ $form->{"all_$key"} }) { 1407 for (@{ $form->{"all_$key"} }) { $form->{"select$key"} .= qq|$_->{accno}--$_->{description}\n| } 1408 } 1409 } 1410 1411 if (@{ $form->{all_paymentmethod} }) { 1412 $form->{selectpaymentmethod} = "\n"; 1413 for (@{ $form->{all_paymentmethod} }) { $form->{selectpaymentmethod} .= qq|$_->{description}--$_->{id}\n| } 1414 } 1415 1416 if (@{ $form->{all_department} }) { 1417 $form->{selectdepartment} = "\n"; 1418 for (@{ $form->{all_department} }) { 1419 if ($_->{description} !~ /:/) { 1420 $form->{selectdepartment} .= qq|$_->{description}--$_->{id}\n|; 1421 } 1422 } 1423 } 1424 1425 if (@{ $form->{all_project} }) { 1426 $form->{selectproject} = "\n"; 1427 for (@{ $form->{all_project} }) { $form->{selectproject} .= qq|$_->{projectnumber}--$_->{id}\n| } 1428 } 1429 1430 &all_references; 1431 1432 $form->{selectprinter} = ""; 1433 for (@{ $form->{all_printer} }) { $form->{selectprinter} .= "$_->{printer}\n" } 1434 chomp $form->{selectprinter}; 1435 1436 $form->{formname} = 'payslip'; 1437 $form->{format} ||= $myconfig{outputformat}; 1438 1439 if ($myconfig{printer}) { 1440 $form->{format} ||= "postscript"; 1441 } else { 1442 $form->{format} ||= "pdf"; 1443 } 1444 $form->{media} ||= $myconfig{printer}; 1445 1446 $form->{selectformname} = qq|payslip--|.$locale->text('Pay Slip'); 1447 1448 1449 if (@{ $form->{all_employee} }) { 1450 $form->{selectemployee} = "\n"; 1451 for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|$_->{name}--$_->{id}\n| } 1452 } 1453 1454 if (! $form->{readonly}) { 1455 $form->{readonly} = 1 if $myconfig{acs} =~ /Payroll--Add Transaction/; 1456 } 1457 1458 for (qw(formname language employee ap payment paymentmethod printer department project)) { $form->{"select$_"} = $form->escape($form->{"select$_"},1) } 1459 1460 $form->helpref("payrolltransaction", $myconfig{countrycode}); 1461 1462 if ($form->{id}) { 1463 1464 $form->{oldemployee} = $form->{employee}; 1465 1466 for $i (1 .. $form->{wage_rows}) { 1467 $form->{"pay_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"} * $form->{"amount_$i"}, $form->{precision}); 1468 1469 $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, $form->{precision}); 1470 1471 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); 1472 } 1473 1474 for $i (1 .. $form->{payrate_rows}) { 1475 $form->{"rate_$i"} = $form->format_amount(\%myconfig, $form->{"rate_$i"}, $form->{precision}); 1476 $form->{"above_$i"} = $form->format_amount(\%myconfig, $form->{"above_$i"}); 1477 } 1478 1479 $form->{paid} = $form->format_amount(\%myconfig, $form->{paid}, $form->{precision}); 1480 1481 &update_payroll; 1482 1483 } 1484 1485} 1486 1487 1488sub payroll_header { 1489 1490 $paymentmethod = qq| 1491 <tr> 1492 <th align=right nowrap>|.$locale->text('Method').qq|</th> 1493 <td><select name=paymentmethod>| 1494 .$form->select_option($form->{selectpaymentmethod}, $form->{paymentmethod}, 1) 1495 .qq|</select></td> 1496 </tr> 1497| if $form->{selectpaymentmethod}; 1498 1499 $project = qq| 1500 <tr> 1501 <th align=right nowrap>|.$locale->text('Project').qq|</th> 1502 <td><select name=project>| 1503 .$form->select_option($form->{selectproject}, $form->{project}, 1) 1504 .qq|</select></td> 1505 </tr> 1506| if $form->{selectproject}; 1507 1508 $department = qq| 1509 <tr> 1510 <th align=right nowrap>|.$locale->text('Department').qq|</th> 1511 <td><select name=department onChange="javascript:document.main.submit()">| 1512 .$form->select_option($form->{selectdepartment}, $form->{department}, 1) 1513 .qq|</select></td> 1514 </tr> 1515| if $form->{selectdepartment}; 1516 1517 $reference_documents = &references; 1518 1519 (undef, $employee_id) = split /--/, $form->{oldemployee}; 1520 1521 $form->header; 1522 1523 &calendar; 1524 1525 print qq| 1526<body> 1527 1528<form method="post" name="main" action="$form->{script}" /> 1529|; 1530 1531 $form->{ARAP} = "AP"; 1532 1533 $form->hide_form(qw(id invnumber helpref title precision ARAP reference_rows referenceurl)); 1534 $form->hide_form(map { "select$_" } qw(formname language employee ap payment paymentmethod printer department project)); 1535 1536 print qq| 1537 1538<input type=hidden name=action value="update"> 1539 1540<table width=100%> 1541 <tr> 1542 <th class=listtop>$form->{helpref}$form->{title}</a></th> 1543 </tr> 1544 <tr height="5"></tr> 1545 1546 <tr> 1547 <td> 1548 <table width=100%> 1549 <tr valign=top> 1550 <td> 1551 <table> 1552 <tr> 1553 <th align=right nowrap>|.$locale->text('Employee').qq| <font color=red>*</font></th> 1554 <td><select name=employee onChange="javascript:document.main.submit()">| 1555 .$form->select_option($form->{selectemployee}, $form->{employee}, 1) 1556 .qq|</select> 1557 <a href=hr.pl?action=edit&id=$employee_id&db=employee&login=$form->{login}&path=$form->{path} target=_blank>?</a> 1558 </td> 1559 </tr> 1560|; 1561 1562 if ($form->{payrate_rows}) { 1563 print qq| 1564 <tr> 1565 <th align=right nowrap>|.$locale->text('Pay Periods').qq|</th> 1566 <td>$form->{payperiod}</td> 1567 </tr> 1568 <tr> 1569 <th align=right nowrap>|.$locale->text('Pay Rates').qq|</th> 1570 <td>$form->{"rate_1"}</td> 1571 </tr> 1572|; 1573 1574 for $i (2 .. $form->{payrate_rows}) { 1575 print qq| 1576 <tr> 1577 <td></td> 1578 <td>$form->{"rate_$i"} > $form->{"above_$i"}</td> 1579 </tr> 1580|; 1581 } 1582 } 1583 1584 print qq| 1585 <tr> 1586 <th align=right nowrap>|.$locale->text('Pay Period Ending').qq| 1587 <td><input name=transdate size=11 class=date title="$myconfig{dateformat}" value=$form->{transdate}>|.&js_calendar("main", "transdate").qq|</td> 1588 </tr> 1589|; 1590 1591 $exemptlabel = $locale->text('Exempt'); 1592 $deferlabel = $locale->text('Deferred'); 1593 1594 if ($form->{wage_rows}) { 1595 for $i (1 .. $form->{wage_rows}) { 1596 $exempt = ($form->{"exempt_$i"}) ? $exemptlabel : ""; 1597 if ($form->{"defer_$i"}) { 1598 $exempt .= " / " if $exempt; 1599 $exempt .= $deferlabel; 1600 } 1601 1602 print qq| 1603 <tr> 1604 <th align=right nowrap>$form->{"wage_$i"}</th> 1605 <td><input name="qty_$i" class="inputright" size=10 value=$form->{"qty_$i"}> x <input name="amount_$i" class="inputright" size=10 value=$form->{"amount_$i"}> <b>$exempt</b></td> 1606 </tr> 1607|; 1608 } 1609 } 1610 1611 print qq| 1612 $department 1613 $project 1614 1615 <tr> 1616 <th align=right nowrap>|.$locale->text('Description').qq|</th> 1617 <td><input name=description size=50 value="$form->{description}"></td> 1618 </tr> 1619 <tr> 1620 <th align=right nowrap>|.$locale->text('Source').qq|</th> 1621 <td><input name=source value="$form->{source}"></td> 1622 </tr> 1623 <tr> 1624 <th align=right nowrap>|.$locale->text('Memo').qq|</th> 1625 <td><input name=memo value="$form->{memo}"></td> 1626 </tr> 1627 <tr> 1628 <th align=right nowrap>|.$locale->text('Paid').qq|</th> 1629 <td><input name=paid class="inputright" value="$form->{paid}"></td> 1630 </tr> 1631 <tr> 1632 <th align=right nowrap>|.$locale->text('Date').qq| 1633 <td><input name=datepaid size=11 class=date title="$myconfig{dateformat}" value=$form->{datepaid}>|.&js_calendar("main", "datepaid").qq|</td> 1634 </tr> 1635 <tr> 1636 <th align=right nowrap>|.$locale->text('Payment').qq|</th> 1637 <td><select name=payment>| 1638 .$form->select_option($form->{selectpayment}, $form->{payment}) 1639 .qq|</select></td> 1640 </tr> 1641 $paymentmethod 1642 <tr> 1643 <th align=right nowrap>|.$locale->text('AP').qq|</th> 1644 <td><select name=ap>| 1645 .$form->select_option($form->{selectap}, $form->{ap}) 1646 .qq|</select></td> 1647 </tr> 1648 </table> 1649 </td> 1650 1651 <td align=right> 1652 <table> 1653|; 1654 1655 if ($form->{invnumber}) { 1656 print qq| 1657 <tr> 1658 <th align=right nowrap>|.$locale->text('Pay Slip').qq|</th> 1659 <td>$form->{invnumber}</td> 1660 </tr> 1661|; 1662 } 1663 1664 print $gross; 1665 1666 for $i (1 .. $form->{wage_rows}) { 1667 if ($form->{"pay_$i"}) { 1668 print qq| 1669 <tr> 1670 <th align=right nowrap>$form->{"wage_$i"}</th> 1671 <td align=right>$form->{"pay_$i"}</td> 1672 </tr> 1673|; 1674 $form->hide_form(map { "${_}_$i" } qw(wage wage_id pay)); 1675 } 1676 } 1677 1678 for $i (1 .. $form->{deduction_rows}) { 1679 if ($form->{"deduct_$i"}) { 1680 print qq| 1681 <tr> 1682 <th align=right nowrap>$form->{"deduction_$i"}</th> 1683 <td align=right>$form->{"deduct_$i"}</td> 1684 </tr> 1685|; 1686 1687 $form->hide_form(map { "${_}_$i" } qw(deduction deduction_id deduct)); 1688 } 1689 } 1690 1691 if ($form->{net}) { 1692 print qq| 1693 <tr> 1694 <th align=right nowrap>|.$locale->text('Net').qq|</th> 1695 <td align=right>$form->{net}</td> 1696 </tr> 1697|; 1698 } 1699 1700 $form->hide_form(qw(gross net withheld deduction_rows wage_rows)); 1701 1702 print qq| 1703 </table> 1704 </td> 1705 </tr> 1706 $reference_documents 1707 </table> 1708 </td> 1709 </tr> 1710 <tr> 1711 <td><hr size=3 noshade></td> 1712 </tr> 1713</table> 1714|; 1715 1716} 1717 1718 1719sub payroll_footer { 1720 1721 $form->hide_form(qw(closedto oldemployee olddepartment db path login callback)); 1722 1723 $transdate = $form->datetonum(\%myconfig, $form->{transdate}); 1724 1725 if ($form->{readonly}) { 1726 1727 &islocked; 1728 1729 } else { 1730 1731 &print_options; 1732 1733 print qq|<br>|; 1734 1735 %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 1736 'Preview' => { ndx => 2, key => 'V', value => $locale->text('Preview') }, 1737 'Print' => { ndx => 3, key => 'P', value => $locale->text('Print') }, 1738 'Post' => { ndx => 4, key => 'O', value => $locale->text('Post') }, 1739 'Print and Post' => { ndx => 5, key => 'R', value => $locale->text('Print and Post') }, 1740 'Post as new' => { ndx => 6, key => 'N', value => $locale->text('Post as new') }, 1741 'Print and Post as new' => { ndx => 7, key => 'W', value => $locale->text('Print and Post as new') }, 1742 'Delete' => { ndx => 8, key => 'D', value => $locale->text('Delete') } 1743 ); 1744 1745 if (! $form->{id}) { 1746 for ('Delete', 'Post as new', 'Print and Post as new') { delete $button{$_} } 1747 } 1748 1749 if ($form->{locked} || $transdate <= $form->{closedto}) { 1750 for ("Preview", "Print", "Post", "Print and Post", "Delete") { delete $button{$_} } 1751 } 1752 1753 if (!$latex) { 1754 for ("Preview", "Print and Post", "Print and Post as new") { delete $button{$_} } 1755 } 1756 1757 $form->print_button(\%button); 1758 1759 } 1760 1761 if ($form->{menubar}) { 1762 require "$form->{path}/menu.pl"; 1763 &menubar; 1764 } 1765 1766 print qq| 1767 1768 </form> 1769 1770</body> 1771</html> 1772|; 1773 1774} 1775 1776 1777sub update_payroll { 1778 1779 $upd = 1 if $form->{oldemployee} ne $form->{employee}; 1780 $ap = $form->{ap}; 1781 $pa = $form->{payment}; 1782 $pm = $form->{paymentmethod}; 1783 $form->{trans_id} = $id = $form->{id}; 1784 1785 ($employee, $form->{id}) = split /--/, $form->{employee}; 1786 HR->get_employee(\%myconfig, \%$form, 1); 1787 1788 $form->{oldemployee} = $form->{employee}; 1789 $form->{id} = $id; 1790 1791 $form->{paid} = $form->parse_amount(\%myconfig, $form->{paid}); 1792 1793 &rebuild_departments if $form->{department} ne $form->{olddepartment}; 1794 1795 if ($upd) { 1796 for (qw(ap payment)) { $form->{$_} = qq|$form->{$_}--$form->{"${_}_description"}| } 1797 $form->{paymentmethod} = qq|$form->{paymentmethod}--$form->{paymentmethod_id}|; 1798 $form->{paid} = 0; 1799 1800 for (qw(description source memo)) { $form->{$_} = ""; } 1801 1802 for $i (1 .. $form->{wage_rows}) { 1803 for (qw(wage pay wage_id qty amount)) { delete $form->{"${_}_$i"} } 1804 } 1805 1806 } else { 1807 $form->{ap} = $ap; 1808 $form->{payment} = $pa; 1809 $form->{paymentmethod} = $pm; 1810 } 1811 1812 $i = 1; 1813 for $ref (@{ $form->{all_employeewage} }) { 1814 1815 $form->{"exempt_$i"} = ($ref->{exempt}) ? 1 : 0; 1816 $form->{"defer_$i"} = ($ref->{defer}) ? 1 : 0; 1817 $form->{"wage_$i"} = $ref->{description}; 1818 $form->{"wage_id_$i"} = $ref->{id}; 1819 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"}); 1820 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); 1821 1822 if ($upd) { 1823 if ($ref->{amount}) { 1824 $form->{"amount_$i"} = $ref->{amount}; 1825 $form->{"qty_$i"} = 1; 1826 } 1827 } 1828 1829 $amount = $form->round_amount($form->{"qty_$i"} * $form->{"amount_$i"}, $form->{precision}); 1830 $temp{gross} += $amount unless $ref->{exempt}; 1831 $temp{net} += $amount unless $ref->{defer}; 1832 1833 $form->{"pay_$i"} = $form->format_amount(\%myconfig, $amount, $form->{precision}); 1834 1835 $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, $form->{precision}); 1836 1837 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); 1838 1839 $i++; 1840 } 1841 $form->{wage_rows} = $i - 1; 1842 1843 $form->{gross} = $form->format_amount(\%myconfig, $temp{gross}, $form->{precision}); 1844 1845 $form->{withheld} = 0; 1846 1847 $i = 0; 1848 $amount = 0; 1849 1850 $form->{payperiod} ||= 1; 1851 1852 if ($temp{gross}) { 1853 for $ed (@{ $form->{all_employeededuction} }) { 1854 $i++; 1855 $ok = 1; 1856 $form->{"deduction_$i"} = $ed->{description}; 1857 $form->{"deduction_id_$i"} = $ed->{id}; 1858 $form->{"deduct_$i"} = 0; 1859 1860 if ($form->{payrolldeduction}{$ed->{id}}{employeepays}) { 1861 for $ref (@{ $form->{all_deductionrate} }) { 1862 if (($ref->{trans_id} == $ed->{id}) && $ok) { 1863 $fromwithholding = 0; 1864 $fromincome = 0; 1865 $form->{"deduct_$i"} += $ref->{amount}; 1866 1867 $j = 0; 1868 for (@{ $form->{deduct}{$ref->{trans_id}} }) { 1869 if ($form->{deduct}{$ed->{id}}[$j]{trans_id} == $ref->{trans_id}) { 1870 $form->{deduct}{$ed->{id}}[$j]{percent} ||= 1; 1871 $amount = $form->round_amount($temp{$form->{deduct}{$ed->{id}}[$j]{id}} * $form->{deduct}{$ed->{id}}[$j]{percent}, $form->{precision}); 1872 if ($form->{deduct}{$ed->{id}}[$j]{withholding}) { 1873 $fromwithholding += $amount; 1874 } else { 1875 $fromincome += $amount; 1876 } 1877 } 1878 $j++; 1879 } 1880 1881 if ($form->{payrolldeduction}{$ed->{id}}{basedon}) { 1882 $amount = $temp{$form->{payrolldeduction}{$ed->{id}}{basedon}} - $fromincome; 1883 } else { 1884 $amount = $temp{gross} - $fromincome; 1885 } 1886 1887 $m = $form->round_amount($amount * $form->{payperiod}, $form->{precision}); 1888 if ($m > $ref->{above}) { 1889 if ($m < $ref->{below}) { 1890 $form->{"deduct_$i"} += $form->round_amount((($amount * $form->{payperiod}) - $ref->{above}) * $ref->{rate} / $form->{payperiod}, $form->{precision}); 1891 $ok = 0; 1892 } else { 1893 if ($m > $ref->{below}) { 1894 $form->{"deduct_$i"} += $form->round_amount(($ref->{below} - $ref->{above}) * $ref->{rate} / $form->{payperiod}, $form->{precision}); 1895 } else { 1896 $form->{"deduct_$i"} += $form->round_amount((($amount * $form->{payperiod}) - $ref->{above}) * $ref->{rate} / $form->{payperiod}, $form->{precision}); 1897 } 1898 } 1899 } 1900 } 1901 } 1902 1903 $m = $form->round_amount($ed->{exempt} / $form->{payperiod}, $form->{precision}); 1904 $amount = $form->round_amount(($form->{"deduct_$i"} - $fromwithholding - $m) * $form->{payrolldeduction}{$ed->{id}}{employeepays}, $form->{precision}); 1905 $amount = 0 if $amount < 0; 1906 1907 # check if amount is over maximum 1908 if ($ed->{maximum}) { 1909 if (($amount + $form->{total}{$ed->{id}}) > $ed->{maximum}) { 1910 $amount = $ed->{maximum} - $form->{total}{$ed->{id}}; 1911 } 1912 } 1913 1914 # check for age restrictions 1915 if ($form->{payrolldeduction}{$ed->{id}}{fromage} || $form->{payrolldeduction}{$ed->{id}}{toage}) { 1916 $dob = $form->datetonum(\%myconfig, $form->{dob}); 1917 1918 if ($form->{payrolldeduction}{$ed->{id}}{agedob}) { 1919 $transdate = $form->datetonum(\%myconfig, $form->{transdate}); 1920 } else { 1921 $transdate = substr($form->datetonum(\%myconfig, $form->{transdate}),0,4)."1231"; 1922 } 1923 1924 if ($transdate && dob) { 1925 if ($form->{payrolldeduction}{$ed->{id}}{fromage}) { 1926 $d = $dob + ($form->{payrolldeduction}{$ed->{id}}{fromage} * 10000); 1927 $amount = 0 if $transdate <= $d; 1928 } 1929 if ($form->{payrolldeduction}{$ed->{id}}{toage}) { 1930 $d = $dob + ($form->{payrolldeduction}{$ed->{id}}{toage} * 10000); 1931 $transdate = substr($form->datetonum(\%myconfig, $form->{transdate}),0,4)."0101" unless $form->{payrolldeduction}{$ed->{id}}{agedob}; 1932 $amount = 0 if $transdate > $d; 1933 } 1934 } 1935 } 1936 1937 $temp{$ed->{id}} = $form->{"deduct_$i"} = $amount;; 1938 $temp{net} -= $form->{"deduct_$i"}; 1939 } 1940 } 1941 } 1942 $form->{deduction_rows} = $i; 1943 1944 $form->{net} = $form->format_amount(\%myconfig, $temp{net}, $form->{precision}); 1945 1946 for $i (1 .. $form->{deduction_rows}) { 1947 $form->{withheld} += $form->{"deduct_$i"}; 1948 $form->{"deduct_$i"} = $form->format_amount(\%myconfig, $form->{"deduct_$i"} * -1, $form->{precision}); 1949 } 1950 1951 for (qw(paid withheld)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $form->{precision}) } 1952 1953 $i = 0; 1954 for $ref (@{ $form->{all_payrate} }) { 1955 $i++; 1956 $form->{"rate_$i"} = $form->format_amount(\%myconfig, $ref->{rate}, $form->{precision}); 1957 $form->{"above_$i"} = $form->format_amount(\%myconfig, $ref->{above}); 1958 } 1959 $form->{payrate_rows} = $i; 1960 1961} 1962 1963 1964sub post { 1965 1966 (undef, $employee_id) = split /--/, $form->{employee}; 1967 1968 $form->error($locale->text('Employee missing!')) unless $employee_id; 1969 $form->isblank("transdate", $locale->text('Date missing!')); 1970 1971 $transdate = $form->datetonum(\%myconfig, $form->{transdate}); 1972 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $form->{closedto}); 1973 1974 if (! $form->{repost}) { 1975 if ($form->{id}) { 1976 &repost; 1977 exit; 1978 } else { 1979 delete $form->{invnumber}; 1980 } 1981 } 1982 1983 if (HR->post_transaction(\%myconfig, \%$form)) { 1984 $form->redirect($locale->text('Transaction posted!')); 1985 } 1986 1987 $form->error($locale->text('Posting failed!')); 1988 1989} 1990 1991 1992sub search_payroll { 1993 1994 $form->{reportcode} = 'payroll'; 1995 1996 HR->search_payroll(\%myconfig, \%$form); 1997 1998 $form->{title} = $locale->text('Payroll Transactions'); 1999 2000 $form->helpref("payroll_transactions", $myconfig{countrycode}); 2001 2002 $employeelabel = $locale->text('Employee'); 2003 2004 if (@{ $form->{all_employee} }) { 2005 $form->{selectemployee} = "\n"; 2006 for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|$_->{name}--$_->{id}\n| } 2007 2008 $employee = qq| 2009 <tr> 2010 <th align=right nowrap>$employeelabel</th> 2011 <td><select name=employee>| 2012 .$form->select_option($form->{selectemployee}, undef, 1) 2013 .qq|</select></td> 2014 </tr> 2015|; 2016 } else { 2017 $employee = qq| 2018 <tr> 2019 <th align=right nowrap>$employeelabel</th> 2020 <td><input name=employee size=35></td> 2021 </tr> 2022 <tr> 2023 <th align=right nowrap>|.$locale->text('Employee Number').qq|</th> 2024 <td><input name=employeenumber size=35></td> 2025 </tr> 2026|; 2027 } 2028 2029 # departments 2030 if (@{ $form->{all_department} }) { 2031 $form->{selectdepartment} = "\n"; 2032 2033 for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|$_->{description}--$_->{id}\n| } 2034 2035 $department = qq| 2036 <tr> 2037 <th align=right nowrap>|.$locale->text('Department').qq|</th> 2038 <td><select name=department>| 2039 .$form->select_option($form->{selectdepartment}, $form->{department}, 1) 2040 .qq| 2041 </select></td> 2042 </tr> 2043|; 2044 } 2045 2046 # projects 2047 if (@{ $form->{all_project} }) { 2048 $form->{selectprojectnumber} = "\n"; 2049 for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|$_->{projectnumber}--$_->{id}\n| } 2050 2051 $project = qq| 2052 <tr> 2053 <th align=right nowrap>|.$locale->text('Project').qq|</th> 2054 <td><select name=projectnumber>| 2055 .$form->select_option($form->{selectprojectnumber}, $form->{projectnumber}, 1) 2056 .qq|</select></td> 2057 </tr> 2058|; 2059 } 2060 2061 2062 if (@{ $form->{all_report} }) { 2063 $form->{selectreportform} = "\n"; 2064 for (@{ $form->{all_report} }) { $form->{selectreportform} .= qq|$_->{reportdescription}--$_->{reportid}\n| } 2065 2066 $reportform = qq| 2067 <tr> 2068 <th align=right>|.$locale->text('Report').qq|</th> 2069 <td> 2070 <select name=report onChange="ChangeReport();">|.$form->select_option($form->{selectreportform}, undef, 1) 2071 .qq|</select> 2072 </td> 2073 </tr> 2074|; 2075 } 2076 2077 if (@{ $form->{all_paymentmethod} }) { 2078 $form->{selectpaymentmethod} = "\n"; 2079 for (@{ $form->{all_paymentmethod} }) { $form->{selectpaymentmethod} .= qq|$_->{description}--$_->{id}\n| } 2080 2081 $paymentmethod = qq| 2082 <tr> 2083 <th align=right>|.$locale->text('Method').qq|</th> 2084 <td><select name=paymentmethod>| 2085 .$form->select_option($form->{selectpaymentmethod}, $form->{paymentmethod}, 1) 2086 .qq| 2087 </select></td> 2088 </tr> 2089|; 2090 } 2091 2092 @checked = qw(l_subtotal); 2093 @input = qw(employee paymentmethod transdatefrom transdateto month year sort direction reportlogin); 2094 %radio = ( interval => { 0 => 0, 1 => 1, 3 => 2, 12 => 3 }, 2095 summary => { 1 => 0, 0 => 1 } 2096 ); 2097 2098 $form->{sort} = "employee"; 2099 $form->{summary} = 1; 2100 2101 $form->{interval} = "0" unless $form->{interval} =~ /(0|1|3|12)/; 2102 $checked{$form->{interval}} = "checked"; 2103 2104 if (@{ $form->{all_years} }) { 2105 $selectaccountingyear = "\n"; 2106 for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| } 2107 $selectaccountingmonth = "\n"; 2108 for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| } 2109 2110 $selectfrom = qq| 2111 <tr> 2112 <th align=right>|.$locale->text('Period').qq|</th> 2113 <td> 2114 <select name=month>|.$form->select_option($selectaccountingmonth, undef, 1, 1).qq|</select> 2115 <select name=year>|.$form->select_option($selectaccountingyear, undef, 1).qq|</select> 2116 <input name=interval class=radio type=radio value=0 $checked{0}> |.$locale->text('Current').qq| 2117 <input name=interval class=radio type=radio value=1 $checked{1}> |.$locale->text('Month').qq| 2118 <input name=interval class=radio type=radio value=3 $checked{2}> |.$locale->text('Quarter').qq| 2119 <input name=interval class=radio type=radio value=12 $checked{3}> |.$locale->text('Year').qq| 2120 </td> 2121 </tr> 2122|; 2123 } 2124 2125 $form->header; 2126 2127 &change_report(\%$form, \@input, \@checked, \%radio); 2128 2129 &calendar; 2130 2131 print qq| 2132<body> 2133 2134<form method="post" name="main" action="$form->{script}" /> 2135 2136<table width=100%> 2137 <tr> 2138 <th class=listtop>$form->{helpref}$form->{title}</a></th> 2139 </tr> 2140 <tr height="5"></tr> 2141 <tr valign=top> 2142 <td> 2143 <table> 2144 $reportform 2145 $employee 2146 $department 2147 $project 2148 <tr> 2149 <th align=right nowrap>|.$locale->text('Date').qq|</th> 2150 <td>|.$locale->text('From').qq| <input name=transdatefrom size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "transdatefrom").$locale->text('To').qq| <input name=transdateto size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "transdateto").qq|</td> 2151 </tr> 2152 $selectfrom 2153 $paymentmethod 2154 <tr> 2155 <td></td> 2156 <td><input name=summary type=radio class=radio value=1> |.$locale->text('Summary').qq| 2157 <input name=summary type=radio class=radio value=0 checked> |.$locale->text('Detail').qq| 2158 </td> 2159 </tr> 2160 <tr> 2161 <td></td> 2162 <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> 2163 </tr> 2164 </table> 2165 </td> 2166 </tr> 2167 <tr> 2168 <td><hr size=3 noshade></td> 2169 </tr> 2170</table> 2171|; 2172 2173 $form->{nextsub} = "payroll_transactions"; 2174 2175 $form->hide_form(qw(sort direction reportlogin helpref nextsub db path login)); 2176 2177 print qq| 2178<br> 2179<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> 2180</form> 2181|; 2182 2183 if ($form->{menubar}) { 2184 require "$form->{path}/menu.pl"; 2185 &menubar; 2186 } 2187 2188 print qq| 2189 2190</body> 2191</html> 2192|; 2193} 2194 2195 2196sub payroll_transactions { 2197 2198 ($form->{reportdescription}, $form->{reportid}) = split /--/, $form->{report}; 2199 $form->{sort} ||= "employee"; 2200 $form->{reportcode} = 'payroll'; 2201 2202 HR->payroll_transactions(\%myconfig, \%$form); 2203 2204 $form->{title} = $locale->text('Payroll Transactions'); 2205 2206 $href = "$form->{script}?action=payroll_transactions"; 2207 for (qw(path login summary db)) { $href .= qq|&$_=$form->{$_}| } 2208 $href .= "&helpref=".$form->escape($form->{helpref}); 2209 2210 $callback = "$form->{script}?action=payroll_transactions"; 2211 for (qw(path login summary db)) { $callback .= qq|&$_=$form->{$_}| } 2212 $callback .= "&helpref=".$form->escape($form->{helpref},1); 2213 2214 if ($form->{employee}) { 2215 $callback .= "&employee=".$form->escape($form->{employee},1); 2216 $href .= "&employee=".$form->escape($form->{employee}); 2217 ($employee) = split /--/, $form->{employee}; 2218 $option .= "\n<br>" if ($option); 2219 $option .= $locale->text('Employee'); 2220 $option .= " : $employee"; 2221 } 2222 if ($form->{department}) { 2223 $callback .= "&department=".$form->escape($form->{department},1); 2224 $href .= "&department=".$form->escape($form->{department}); 2225 ($department) = split /--/, $form->{department}; 2226 $option .= "\n<br>" if ($option); 2227 $option .= $locale->text('Department')." : $department"; 2228 } 2229 if ($form->{projectnumber}) { 2230 $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1); 2231 $href .= "&projectnumber=".$form->escape($form->{projectnumber}); 2232 ($projectnumber) = split /--/, $form->{projectnumber}; 2233 $option .= "\n<br>" if ($option); 2234 $option .= $locale->text('Project')." : $projectnumber"; 2235 } 2236 if ($form->{transdatefrom}) { 2237 $callback .= "&transdatefrom=$form->{transdatefrom}"; 2238 $href .= "&transdatefrom=$form->{transdatefrom}"; 2239 $option .= "\n<br>" if ($option); 2240 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); 2241 } 2242 if ($form->{transdateto}) { 2243 $callback .= "&transdateto=$form->{transdateto}"; 2244 $href .= "&transdateto=$form->{transdateto}"; 2245 $option .= "\n<br>" if ($option); 2246 $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); 2247 } 2248 2249 if ($form->{summary}) { 2250 @column_index = qw(employee paid); 2251 } else { 2252 @column_index = qw(employee transdate payslip invnumber reference paid); 2253 } 2254 2255 $column_data{employee} = "<th class=listheading>".$locale->text('Employee')."</th>"; 2256 $column_data{transdate} = "<th class=listheading>".$locale->text('Date')."</th>"; 2257 $column_data{invnumber} = "<th class=listheading>".$locale->text('AP')."</th>"; 2258 $column_data{reference} = "<th class=listheading>".$locale->text('GL')."</th>"; 2259 $column_data{payslip} = "<th>".$locale->text('Pay Slip')."</th>"; 2260 $column_data{paid} = "<th class=listheading>" . $locale->text('Paid') . "</th>"; 2261 2262 $column_data{wages} = "<th class=listheading>".$locale->text('Wages')."</th>"; 2263 for (@{ $form->{all_wage} }) { 2264 $column_data{$_->{id}} = "<th class=listheading>$_->{description}</th>"; 2265 push @column_index, $_->{id}; 2266 } 2267 push @column_index, "wages"; 2268 2269 $column_data{deductions} = "<th class=listheading>".$locale->text('Deductions')."</th>"; 2270 for (@{ $form->{all_deduction} }) { 2271 $column_data{$_->{id}} = "<th class=listheading>$_->{description}</th>"; 2272 push @column_index, $_->{id}; 2273 } 2274 push @column_index, "deductions"; 2275 2276 $form->{title} = ($form->{title}) ? $form->{title} : $locale->text('Payroll Transactions'); 2277 $form->{title} .= " / $form->{company}"; 2278 2279 $form->header; 2280 2281 print qq| 2282<body> 2283 2284<table width=100%> 2285 <tr> 2286 <th class=listtop>$form->{helpref}$form->{title}</a></th> 2287 </tr> 2288 <tr height="5"></tr> 2289 <tr> 2290 <td>$option</td> 2291 </tr> 2292 <tr> 2293 <td> 2294 <table width=100%> 2295 <tr class=listheading> 2296|; 2297 2298 for (@column_index) { print "\n$column_data{$_}" } 2299 2300 print qq| 2301 </tr> 2302|; 2303 2304 # add sort and escape callback, this one we use for the add sub 2305 $form->{callback} = $callback .= "&sort=$form->{sort}"; 2306 2307 # escape callback for href 2308 $callback = $form->escape($callback); 2309 2310 $l = $#{$form->{transactions}}; 2311 $i = 0; 2312 2313 foreach $ref (@{ $form->{transactions} }) { 2314 2315 $form->{subtotalpaid} = 0 if $sameitem ne $ref->{$form->{sort}}; 2316 2317 for (qw(paid)) { 2318 $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}, " ")."</td>"; 2319 $form->{"subtotal$_"} += $ref->{$_}; 2320 $form->{"total$_"} += $ref->{$_}; 2321 } 2322 2323 $amount = 0; 2324 for (@{ $form->{all_wage} }) { 2325 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_->{id}}, $form->{precision}, " ")."</td>"; 2326 $form->{"subtotal$_->{id}"} += $ref->{$_->{id}}; 2327 $form->{"total$_->{id}"} += $ref->{$_->{id}}; 2328 $amount += $ref->{$_->{id}}; 2329 } 2330 $column_data{wages} = "<td align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</td>"; 2331 2332 $amount = 0; 2333 for (@{ $form->{all_deduction} }) { 2334 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_->{id}}, $form->{precision}, " ")."</td>"; 2335 $form->{"subtotal$_->{id}"} += $ref->{$_->{id}}; 2336 $form->{"total$_->{id}"} += $ref->{$_->{id}}; 2337 $amount += $ref->{$_->{id}}; 2338 } 2339 $column_data{deductions} = "<td align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</td>"; 2340 2341 $column_data{invnumber} = "<td><a href=ap.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{invnumber} </a></td>"; 2342 $column_data{reference} = "<td><a href=gl.pl?action=edit&id=$ref->{glid}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{reference} </a></td>"; 2343 $column_data{payslip} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=payroll&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{invnumber} </a></td>"; 2344 $column_data{transdate} = "<td nowrap>$ref->{transdate}</td>"; 2345 $column_data{employee} = "<td>$ref->{employee}</td>"; 2346 2347 2348 if ($form->{summary}) { 2349 if ($i < $l) { 2350 if ($ref->{$form->{sort}} ne $form->{transactions}->[$i+1]->{$form->{sort}}) { 2351 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotalpaid"}, $form->{precision}, " ")."</td>"; 2352 2353 $amount = 0; 2354 for (@{ $form->{all_wage} }) { 2355 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotal$_->{id}"}, $form->{precision}, " ")."</td>"; 2356 $amount += $form->{"subtotal$_->{id}"}; 2357 $form->{"subtotal$_->{id}"} = 0 unless $form->{l_subtotal}; 2358 } 2359 2360 $column_data{wages} = "<td align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</td>"; 2361 2362 $amount = 0; 2363 for (@{ $form->{all_deduction} }) { 2364 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotal$_->{id}"}, $form->{precision}, " ")."</td>"; 2365 $amount += $form->{"subtotal$_->{id}"}; 2366 $form->{"subtotal$_->{id}"} = 0 unless $form->{l_subtotal}; 2367 } 2368 2369 $column_data{deductions} = "<td align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</td>"; 2370 2371 $j++; $j %= 2; 2372 print " 2373 <tr class=listrow$j> 2374"; 2375 2376 for (@column_index) { print "\n$column_data{$_}" } 2377 2378 print qq| 2379 </tr> 2380|; 2381 2382 } 2383 } else { 2384 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotalpaid"}, $form->{precision}, " ")."</td>"; 2385 2386 $amount = 0; 2387 for (@{ $form->{all_wage} }) { 2388 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotal$_->{id}"}, $form->{precision}, " ")."</td>"; 2389 $amount += $form->{"subtotal$_->{id}"}; 2390 $form->{"subtotal$_->{id}"} = 0 unless $form->{l_subtotal}; 2391 } 2392 2393 $column_data{wages} = "<td align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</td>"; 2394 2395 $amount = 0; 2396 for (@{ $form->{all_deduction} }) { 2397 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotal$_->{id}"}, $form->{precision}, " ")."</td>"; 2398 $amount += $form->{"subtotal$_->{id}"}; 2399 $form->{"subtotal$_->{id}"} = 0 unless $form->{l_subtotal}; 2400 } 2401 2402 $column_data{deductions} = "<td align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</td>"; 2403 2404 $j++; $j %= 2; 2405 print " 2406 <tr class=listrow$j> 2407"; 2408 2409 for (@column_index) { print "\n$column_data{$_}" } 2410 2411 print qq| 2412 </tr> 2413|; 2414 2415 } 2416 } else { 2417 if ($ref->{$form->{sort}} eq $sameitem) { 2418 $column_data{$form->{sort}} = "<td> </td>"; 2419 } 2420 2421 $j++; $j %= 2; 2422 print " 2423 <tr class=listrow$j> 2424"; 2425 2426 for (@column_index) { print "\n$column_data{$_}" } 2427 2428 print qq| 2429 </tr> 2430|; 2431 2432 } 2433 2434 2435 if ($form->{l_subtotal} eq 'Y') { 2436 if ($i < $l) { 2437 if ($ref->{$form->{sort}} ne $form->{transactions}->[$i+1]->{$form->{sort}}) { 2438 &payroll_subtotal; 2439 } 2440 } else { 2441 &payroll_subtotal; 2442 } 2443 } 2444 2445 $sameitem = $ref->{$form->{sort}}; 2446 2447 $i++; 2448 2449 } 2450 2451 # total 2452 for (@column_index) { $column_data{$_} = "<th> </th>" } 2453 2454 $column_data{paid} = "<th align=right nowrap>".$form->format_amount(\%myconfig, $form->{"totalpaid"}, $form->{precision}, " ")."</th>"; 2455 2456 $amount = 0; 2457 for (@{ $form->{all_wage} }) { 2458 $column_data{$_->{id}} = "<th align=right nowrap>".$form->format_amount(\%myconfig, $form->{"total$_->{id}"}, $form->{precision}, " ")."</th>"; 2459 $amount += $form->{"total$_->{id}"}; 2460 } 2461 $column_data{wages} = "<th align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</th>"; 2462 2463 $amount = 0; 2464 for (@{ $form->{all_deduction} }) { 2465 $column_data{$_->{id}} = "<th align=right nowrap>".$form->format_amount(\%myconfig, $form->{"total$_->{id}"}, $form->{precision}, " ")."</th>"; 2466 $amount += $form->{"total$_->{id}"}; 2467 } 2468 $column_data{deductions} = "<th align=right>".$form->format_amount(\%myconfig, $amount, $form->{precision}, " ")."</th>"; 2469 2470 print " 2471 <tr class=listtotal> 2472"; 2473 2474 for (@column_index) { print "\n$column_data{$_}" } 2475 2476 print qq| 2477 </tr> 2478 </table> 2479 </td> 2480 </tr> 2481 <tr> 2482 <td><hr size=3 noshade></td> 2483 </tr> 2484</table> 2485 2486<br> 2487 2488<form method=post action=$form->{script}> 2489|; 2490 2491 if ($form->{year} && $form->{month}) { 2492 for (qw(transdatefrom transdateto)) { delete $form->{$_} } 2493 } 2494 $form->hide_form(qw(employee paymentmethod transdatefrom transdateto month year interval summary l_subtotal)); 2495 2496 $form->hide_form(qw(callback path login report reportcode reportlogin db sort direction)); 2497 2498 %button = ('Add Transaction' => { ndx => 1, key => 'A', value => $locale->text('Add Transaction') }, 2499 'Save Report' => { ndx => 8, key => 'S', value => $locale->text('Save Report') } 2500 ); 2501 2502 if ($myconfig{acs} =~ /HR--HR/) { 2503 delete $button{'AR--Add Transaction'}; 2504 } 2505 2506 if (!$form->{admin}) { 2507 delete $button{'Save Report'} unless $form->{savereport}; 2508 } 2509 2510 $form->print_button(\%button); 2511 2512 if ($form->{menubar}) { 2513 require "$form->{path}/menu.pl"; 2514 &menubar; 2515 } 2516 2517 print qq| 2518 2519</form> 2520 2521</body> 2522</html> 2523|; 2524 2525} 2526 2527 2528sub payroll_subtotal { 2529 2530 for (@column_index) { $column_data{$_} = "<td> </td>" } 2531 2532 $column_data{paid} = "<th align=right>".$form->format_amount(\%myconfig, $form->{"subtotalpaid"}, $form->{precision}, " ")."</th>"; 2533 $form->{"subtotalpaid"} = 0; 2534 2535 for (@{ $form->{all_wage} }) { 2536 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotal$_->{id}"}, $form->{precision}, " ")."</td>"; 2537 $form->{"subtotal$_->{id}"} = 0; 2538 } 2539 2540 for (@{ $form->{all_deduction} }) { 2541 $column_data{$_->{id}} = "<td align=right>".$form->format_amount(\%myconfig, $form->{"subtotal$_->{id}"}, $form->{precision}, " ")."</td>"; 2542 $form->{"subtotal$_->{id}"} = 0; 2543 } 2544 2545 print " 2546 <tr class=listsubtotal> 2547"; 2548 2549 for (@column_index) { print "\n$column_data{$_}" } 2550 2551 print qq| 2552 </tr> 2553|; 2554 2555} 2556 2557 2558sub search_deduction { 2559 2560 HR->deductions(\%myconfig, \%$form); 2561 2562 $callback = "$form->{script}?action=search_deduction"; 2563 for (qw(db path login)) { $callback .= "&$_=$form->{$_}" } 2564 2565 @column_index = qw(description rate amount above below basedon employeepays employee_accno employerpays employer_accno); 2566 2567 $form->helpref("deductions", $myconfig{countrycode}); 2568 2569 $form->{callback} = $callback; 2570 $callback = $form->escape($form->{callback}); 2571 2572 $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|; 2573 $column_header{rate} = qq|<th class=listheading nowrap>|.$locale->text('Rate %').qq|</th>|; 2574 $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|; 2575 $column_header{above} = qq|<th class=listheading>|.$locale->text('Above').qq|</th>|; 2576 $column_header{below} = qq|<th class=listheading>|.$locale->text('Below').qq|</th>|; 2577 $column_header{basedon} = qq|<th class=listheading>|.$locale->text('Based on').qq|</th>|; 2578 $column_header{employerpays} = qq|<th class=listheading>|.$locale->text('Employer').qq|</th>|; 2579 $column_header{employeepays} = qq|<th class=listheading>|.$locale->text('Employee').qq|</th>|; 2580 2581 $column_header{employee_accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|; 2582 $column_header{employer_accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|; 2583 2584 $form->{title} = $locale->text('Deductions') . " / $form->{company}"; 2585 2586 $form->header; 2587 2588 print qq| 2589<body> 2590 2591<table width=100%> 2592 <tr> 2593 <th class=listtop>$form->{helpref}$form->{title}</a></th> 2594 </tr> 2595 <tr height="5"></tr> 2596 <tr> 2597 <td>$option</td> 2598 </tr> 2599 <tr> 2600 <td> 2601 <table width=100%> 2602 <tr class=listheading> 2603|; 2604 2605 for (@column_index) { print "$column_header{$_}\n" } 2606 2607 print qq| 2608 </tr> 2609|; 2610 2611 2612 foreach $ref (@{ $form->{all_deduction} }) { 2613 2614 $rate = $form->format_amount(\%myconfig, $ref->{rate} * 100, undef, " "); 2615 2616 $column_data{rate} = "<td align=right>$rate</td>"; 2617 2618 for (qw(amount above below)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}, " ")."</td>" } 2619 2620 for (qw(basedon employee_accno employer_accno)) { $column_data{$_} = "<td>$ref->{$_} </td>" } 2621 2622 for (qw(employerpays employeepays)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, undef, " ")."</td>" } 2623 2624 if ($ref->{description} ne $sameitem) { 2625 $column_data{description} = "<td><a href=$form->{script}?action=edit&db=$form->{db}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{description}</a></td>"; 2626 } else { 2627 $column_data{description} = "<td> </td>"; 2628 } 2629 2630 $i++; $i %= 2; 2631 print " 2632 <tr class=listrow$i> 2633"; 2634 2635 for (@column_index) { print "$column_data{$_}\n" } 2636 2637 print qq| 2638 </tr> 2639|; 2640 2641 $sameitem = $ref->{description}; 2642 2643 } 2644 2645 $i = 1; 2646 2647 %button = ('Add Deduction' => { ndx => 1, key => 'A', value => $locale->text('Add Deduction') } 2648 ); 2649 2650 foreach $item (split /;/, $myconfig{acs}) { 2651 delete $button{$item}; 2652 } 2653 2654 print qq| 2655 </table> 2656 </td> 2657 </tr> 2658 <tr> 2659 <td><hr size=3 noshade></td> 2660 </tr> 2661</table> 2662 2663<br> 2664<form method=post action=$form->{script}> 2665|; 2666 2667 $form->hide_form(qw(db callback path login)); 2668 2669 $form->print_button(\%button); 2670 2671 if ($form->{menubar}) { 2672 require "$form->{path}/menu.pl"; 2673 &menubar; 2674 } 2675 2676 print qq| 2677 </form> 2678 2679</body> 2680</html> 2681|; 2682 2683} 2684 2685 2686sub prepare_deduction { 2687 2688 HR->get_deduction(\%myconfig, \%$form); 2689 2690 $i = 1; 2691 foreach $ref (@{ $form->{deductionrate} }) { 2692 for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} } 2693 $i++; 2694 } 2695 $form->{rate_rows} = $i; 2696 2697 $i = 1; 2698 foreach $ref (@{ $form->{deduct} }) { 2699 $form->{"deduct_$i"} = "$ref->{description}--$ref->{id}"; 2700 $form->{"withholding_$i"} = ($ref->{withholding}) ? 1 : 0; 2701 $form->{"percent_$i"} = $ref->{percent} * 100; 2702 $i++; 2703 } 2704 $form->{deduct_rows} = $i; 2705 2706 $form->{selectaccounts} = "\n"; 2707 for (@{ $form->{accounts} }) { $form->{selectaccounts} .= "$_->{accno}--$_->{description}\n" } 2708 2709 for (qw(employee employer)) { $form->{"${_}_accno"} = qq|$form->{"${_}_accno"}--$form->{"${_}_accno_description"}| } 2710 $form->{basedon} = qq|$form->{basedesc}--$form->{basedon}|; 2711 2712 for (1 .. $form->{rate_rows}) { $form->{"rate_$_"} *= 100 } 2713 2714 $form->{selectbasedon} = "\n"; 2715 for (@{ $form->{all_deduction} }) { 2716 $form->{selectbasedon} .= qq|$_->{description}--$_->{id}\n|; 2717 $form->{showbasedon} = 1; 2718 } 2719 2720 if (! $form->{readonly}) { 2721 $form->{readonly} = 1 if $myconfig{acs} =~ /Add Deduction/; 2722 } 2723 2724 for (qw(accounts basedon)) { $form->{"select$_"} = $form->escape($form->{"select$_"},1) } 2725 2726 $form->helpref("deduction", $myconfig{countrycode}); 2727 2728} 2729 2730 2731sub deduction_header { 2732 2733 $agedob{$form->{agedob}} = "checked"; 2734 2735 $form->header; 2736 2737 print qq| 2738<body> 2739 2740<form method=post action=$form->{script}> 2741|; 2742 2743 $form->hide_form(qw(helpref title rate_rows deduct_rows precision showbasedon)); 2744 $form->hide_form(map { "select$_" } qw(basedon accounts)); 2745 2746 print qq| 2747 2748<table width=100%> 2749 <tr> 2750 <th class=listtop>$form->{helpref}$form->{title}</a></th> 2751 </tr> 2752 <tr height="5"></tr> 2753 <tr> 2754 <td> 2755 <table> 2756 <tr> 2757 <th align=right nowrap>|.$locale->text('Description').qq| <font color=red>*</font></th> 2758 <td><input name=description size=35 value="|.$form->quote($form->{description}).qq|"></td> 2759 </tr> 2760 <tr> 2761 <th align=right nowrap>|.$locale->text('Employee pays').qq| x</th> 2762 <td><input name=employeepays class="inputright" size=4 value=|.$form->format_amount(\%myconfig, $form->{employeepays}).qq|> 2763 <select name=employee_accno>| 2764 .$form->select_option($form->{selectaccounts}, $form->{employee_accno}).qq|</select></td> 2765 </tr> 2766 <tr> 2767 <th align=right nowrap>|.$locale->text('Employer pays').qq| x</th> 2768 <td><input name=employerpays class="inputright" size=4 value=|.$form->format_amount(\%myconfig, $form->{employerpays}).qq|> 2769 <select name=employer_accno>| 2770 .$form->select_option($form->{selectaccounts}, $form->{employer_accno}).qq|</select></td> 2771 </tr> 2772 <tr> 2773 <th align=right nowrap>|.$locale->text('Exempt age <').qq|</th> 2774 <td><input name=fromage class="inputright" size=4 value=|.$form->format_amount(\%myconfig, $form->{fromage}).qq|> 2775 <b>></b> 2776 <input name=toage class="inputright" size=4 value=|.$form->format_amount(\%myconfig, $form->{toage}).qq|> 2777 <input name=agedob type=checkbox style=checkbox value=1 $agedob{1}> |.$locale->text('DOB').qq|</td> 2778 </tr> 2779 <tr height="5"></tr> 2780 <tr> 2781 <td colspan=2> 2782 <table> 2783 <tr class=listheading> 2784 <th class=listheading>|.$locale->text('Rate %').qq|</th> 2785 <th class=listheading>|.$locale->text('Amount').qq|</th> 2786 <th class=listheading>|.$locale->text('Above').qq|</th> 2787 <th class=listheading>|.$locale->text('Below').qq|</th> 2788 </tr> 2789|; 2790 2791 for $i (1 .. $form->{rate_rows}) { 2792 print qq| 2793 <tr> 2794 <td><input name="rate_$i" class="inputright" size=11 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td> 2795 <td><input name="amount_$i" class="inputright" size=11 value=|.$form->format_amount(\%myconfig, $form->{"amount_$i"}, $form->{precision}).qq|></td> 2796 <td><input name="above_$i" class="inputright" size=11 value=|.$form->format_amount(\%myconfig, $form->{"above_$i"}, $form->{precision}).qq|></td> 2797 <td><input name="below_$i" class="inputright" size=11 value=|.$form->format_amount(\%myconfig, $form->{"below_$i"}, $form->{precision}).qq|></td> 2798 </tr> 2799|; 2800 } 2801 2802 print qq| 2803 </table> 2804 </td> 2805 </tr> 2806 </table> 2807 </td> 2808 </tr> 2809|; 2810 2811 if ($form->{showbasedon}) { 2812 print qq| 2813 2814 <tr> 2815 <td> 2816 <table> 2817 <tr valign=top> 2818 <td> 2819 2820 <table> 2821 <tr> 2822 <th>|.$locale->text('Based on').qq|</th> 2823 <tr> 2824 </tr> 2825 <td><select name="basedon">| 2826 .$form->select_option($form->{selectbasedon}, $form->{basedon}, 1).qq|</select></td> 2827 </tr> 2828 </table> 2829 </td> 2830 <td> 2831 <table> 2832 <tr> 2833 <th>|.$locale->text('Deduct').qq|</th> 2834 <th>|.$locale->text('Withholding').qq|</th> 2835 <th>|.$locale->text('%').qq|</th> 2836 </tr> 2837 2838|; 2839 2840 for $i (1 .. $form->{deduct_rows}) { 2841 $checked = ($form->{"withholding_$i"}) ? "checked" : ""; 2842 2843 print qq| 2844 <tr> 2845 <td><select name="deduct_$i">| 2846 .$form->select_option($form->{selectbasedon}, $form->{"deduct_$i"}, 1).qq|</select></td> 2847 <td align=center><input name="withholding_$i" type=checkbox class=checkbox value=1 $checked> 2848 <td><input name="percent_$i" class="inputright" size=10 value=|.$form->format_amount(\%myconfig, $form->{"percent_$i"}).qq|></td> 2849 </tr> 2850 |; 2851 } 2852 2853 print qq| 2854 </table> 2855 </td> 2856 </tr> 2857 </table> 2858 </td> 2859 </tr> 2860|; 2861 } 2862 2863 print qq| 2864 <tr> 2865 <td><hr size=3 noshade></td> 2866 </tr> 2867</table> 2868|; 2869 2870} 2871 2872 2873 2874sub deduction_footer { 2875 2876 $form->hide_form(qw(status id db path login callback)); 2877 2878 if ($form->{readonly}) { 2879 2880 &islocked; 2881 2882 } else { 2883 2884 %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 2885 'Save' => { ndx => 3, key => 'S', value => $locale->text('Save') }, 2886 'Save as new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') }, 2887 'Delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') }, 2888 ); 2889 2890 %f = (); 2891 for ('Update', 'Save') { $f{$_} = 1 } 2892 2893 if ($form->{id}) { 2894 if ($form->{status} eq 'orphaned') { 2895 $f{'Delete'} = 1; 2896 } 2897 $f{'Save as new'} = 1; 2898 } 2899 2900 for (keys %button) { delete $button{$_} if ! $f{$_} } 2901 2902 $form->print_button(\%button); 2903 2904 } 2905 2906 if ($form->{menubar}) { 2907 require "$form->{path}/menu.pl"; 2908 &menubar; 2909 } 2910 2911 print qq| 2912 2913 </form> 2914 2915</body> 2916</html> 2917|; 2918 2919} 2920 2921 2922sub search_wage { 2923 2924 HR->wages(\%myconfig, \%$form); 2925 2926 $callback = "$form->{script}?action=search_wage"; 2927 for (qw(db path login)) { $callback .= "&$_=$form->{$_}" } 2928 2929 @column_index = qw(description amount accno defer exempt); 2930 2931 $form->helpref("wages", $myconfig{countrycode}); 2932 2933 $form->{callback} = $callback; 2934 $callback = $form->escape($form->{callback}); 2935 2936 $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|; 2937 $column_data{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|; 2938 $column_data{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|; 2939 $column_data{defer} = qq|<th class=listheading>|.$locale->text('Defer').qq|</th>|; 2940 $column_data{exempt} = qq|<th class=listheading>|.$locale->text('Exempt').qq|</th>|; 2941 2942 $form->{title} = $locale->text('Wages') . " / $form->{company}"; 2943 2944 $form->header; 2945 2946 print qq| 2947<body> 2948 2949<table width=100%> 2950 <tr> 2951 <th class=listtop>$form->{helpref}$form->{title}</a></th> 2952 </tr> 2953 <tr height="5"></tr> 2954 <tr> 2955 <td>$option</td> 2956 </tr> 2957 <tr> 2958 <td> 2959 <table width=100%> 2960 <tr class=listheading> 2961|; 2962 2963 for (@column_index) { print "$column_data{$_}\n" } 2964 2965 print qq| 2966 </tr> 2967|; 2968 2969 2970 foreach $ref (@{ $form->{all_wage} }) { 2971 2972 $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, $form->{precision}, " ")."</td>"; 2973 $column_data{accno} = "<td>$ref->{accno} </td>"; 2974 $column_data{defer} = "<td>$ref->{defer} </td>"; 2975 2976 $column_data{exempt} = ($ref->{exempt}) ? "<td>x</td>" : "<td></td>"; 2977 2978 $column_data{description} = "<td><a href=$form->{script}?action=edit&db=$form->{db}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{description}</a></td>"; 2979 2980 $i++; $i %= 2; 2981 print " 2982 <tr class=listrow$i> 2983"; 2984 2985 for (@column_index) { print "$column_data{$_}\n" } 2986 2987 print qq| 2988 </tr> 2989|; 2990 2991 } 2992 2993 $i = 1; 2994 2995 %button = ('Add Wage' => { ndx => 1, key => 'A', value => $locale->text('Add Wage') } 2996 ); 2997 2998 foreach $item (split /;/, $myconfig{acs}) { 2999 delete $button{$item}; 3000 } 3001 3002 print qq| 3003 </table> 3004 </td> 3005 </tr> 3006 <tr> 3007 <td><hr size=3 noshade></td> 3008 </tr> 3009</table> 3010 3011<br> 3012<form method=post action=$form->{script}> 3013|; 3014 3015 $form->hide_form(qw(db callback path login)); 3016 3017 $form->print_button(\%button); 3018 3019 if ($form->{menubar}) { 3020 require "$form->{path}/menu.pl"; 3021 &menubar; 3022 } 3023 3024 print qq| 3025 </form> 3026 3027</body> 3028</html> 3029|; 3030 3031} 3032 3033 3034sub prepare_wage { 3035 3036 HR->get_wage(\%myconfig, \%$form); 3037 3038 $form->{selectaccounts} = ""; 3039 for (@{ $form->{accounts} }) { $form->{selectaccounts} .= "$_->{accno}--$_->{description}\n" } 3040 3041 $form->{accno} = qq|$form->{accno}--$form->{accno_description}|; 3042 $form->{defer} = qq|$form->{defer}--$form->{defer_description}|; 3043 3044 if (! $form->{readonly}) { 3045 $form->{readonly} = 1 if $myconfig{acs} =~ /Add Wage/; 3046 } 3047 3048 $form->helpref("wage", $myconfig{countrycode}); 3049 3050} 3051 3052 3053sub wage_header { 3054 3055 $form->header; 3056 3057 $checked{exempt} = ($form->{exempt}) ? "checked" : ""; 3058 3059 print qq| 3060<body> 3061 3062<form method=post action=$form->{script}> 3063|; 3064 3065 $form->hide_form(qw(helpref title precision)); 3066 $form->hide_form(map { "select$_" } qw(accounts)); 3067 3068 print qq| 3069 3070<table width=100%> 3071 <tr> 3072 <th class=listtop>$form->{helpref}$form->{title}</a></th> 3073 </tr> 3074 <tr height="5"></tr> 3075 <tr> 3076 <td> 3077 <table> 3078 <tr> 3079 <th align=right nowrap>|.$locale->text('Description').qq| <font color=red>*</font></th> 3080 <td><input name=description size=35 value="|.$form->quote($form->{description}).qq|"></td> 3081 </tr> 3082 <tr> 3083 <th align=right nowrap>|.$locale->text('Account').qq| <font color=red>*</font></th> 3084 <td> 3085 <select name=accno>| 3086 .$form->select_option($form->{selectaccounts}, $form->{accno}).qq|</select></td> 3087 </tr> 3088 <tr> 3089 <th align=right nowrap>|.$locale->text('Defer Payout').qq|</th> 3090 <td> 3091 <select name=defer>| 3092 .$form->select_option("\n".$form->{selectaccounts}, $form->{defer}).qq|</select></td> 3093 </tr> 3094 <tr> 3095 <th align=right nowrap>|.$locale->text('Amount').qq|</th> 3096 <td><input name=amount class=inputright size=10 value=|.$form->format_amount(\%myconfig, $form->{amount}, $form->{precision}).qq|></td> 3097 </tr> 3098 <tr> 3099 <th></th> 3100 <td><input name="exempt" type=checkbox class=checkbox value=1 $checked{exempt}> <b>|.$locale->text('Exempt').qq|</b></td> 3101 </tr> 3102 </table> 3103 </td> 3104 </tr> 3105 <tr> 3106 <td><hr size=3 noshade></td> 3107 </tr> 3108</table> 3109|; 3110 3111} 3112 3113 3114 3115sub wage_footer { 3116 3117 $form->hide_form(qw(status id db path login callback)); 3118 3119 if ($form->{readonly}) { 3120 3121 &islocked; 3122 3123 } else { 3124 3125 %button = ( 3126 'Save' => { ndx => 3, key => 'S', value => $locale->text('Save') }, 3127 'Save as new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') }, 3128 'Delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') }, 3129 ); 3130 3131 %f = (); 3132 for ('Update', 'Save') { $f{$_} = 1 } 3133 3134 if ($form->{id}) { 3135 if ($form->{status} eq 'orphaned') { 3136 $f{'Delete'} = 1; 3137 } 3138 $f{'Save as new'} = 1; 3139 } 3140 3141 for (keys %button) { delete $button{$_} if ! $f{$_} } 3142 3143 $form->print_button(\%button); 3144 3145 } 3146 3147 if ($form->{menubar}) { 3148 require "$form->{path}/menu.pl"; 3149 &menubar; 3150 } 3151 3152 print qq| 3153 3154 </form> 3155 3156</body> 3157</html> 3158|; 3159 3160} 3161 3162 3163sub update { 3164 3165 &{ "update_$form->{db}" }; 3166 &display_form; 3167 3168} 3169 3170 3171sub save { &{ "save_$form->{db}" } }; 3172 3173 3174sub update_deduction { 3175 3176 # if rate or amount is blank remove row 3177 @flds = qw(rate amount above below); 3178 $count = 0; 3179 @f = (); 3180 for $i (1 .. $form->{rate_rows}) { 3181 for (qw(rate amount above below)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } 3182 if ($form->{"rate_$i"} + $form->{"amount_$i"} + $form->{"above_$i"} + $form->{"below_$i"}) { 3183 push @f, {}; 3184 $j = $#f; 3185 3186 for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} } 3187 $count++; 3188 } 3189 } 3190 $form->redo_rows(\@flds, \@f, $count, $form->{rate_rows}); 3191 $form->{rate_rows} = $count + 1; 3192 3193 @flds = qw(deduct withholding percent); 3194 $count = 0; 3195 @f = (); 3196 for $i (1 .. $form->{deduct_rows}) { 3197 if ($form->{"deduct_$i"}) { 3198 $form->{"percent_$i"} = $form->parse_amount(\%myconfig, $form->{"percent_$i"}); 3199 push @f, {}; 3200 $j = $#f; 3201 3202 for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} } 3203 $count++; 3204 } 3205 } 3206 $form->redo_rows(\@flds, \@f, $count, $form->{deduct_rows}); 3207 $form->{deduct_rows} = $count + 1; 3208 3209} 3210 3211 3212sub update_employee { 3213 3214 # if rate or amount is blank remove row 3215 @flds = qw(deduction exempt maximum); 3216 $count = 0; 3217 @f = (); 3218 for $i (1 .. $form->{deduction_rows}) { 3219 for (qw(exempt maximum)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } 3220 if ($form->{"deduction_$i"}) { 3221 push @f, {}; 3222 $j = $#f; 3223 3224 for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} } 3225 $count++; 3226 } 3227 } 3228 $form->redo_rows(\@flds, \@f, $count, $form->{deduction_rows}); 3229 $form->{deduction_rows} = $count; 3230 3231 3232 @flds = qw(rate above); 3233 $count = 0; 3234 @f = (); 3235 for $i (1 .. $form->{payrate_rows}) { 3236 for (@flds) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } 3237 if ($form->{"rate_$i"}) { 3238 push @f, {}; 3239 $j = $#f; 3240 3241 for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} } 3242 $count++; 3243 } 3244 } 3245 $form->redo_rows(\@flds, \@f, $count, $form->{payrate_rows}); 3246 $form->{payrate_rows} = $count; 3247 3248 @flds = qw(wage); 3249 $count = 0; 3250 @f = (); 3251 for $i (1 .. $form->{wage_rows}) { 3252 if ($form->{"wage_$i"}) { 3253 push @f, {}; 3254 $j = $#f; 3255 3256 for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} } 3257 $count++; 3258 } 3259 } 3260 $form->redo_rows(\@flds, \@f, $count, $form->{wage_rows}); 3261 $form->{wage_rows} = $count; 3262 3263 HR->isadmin(\%myconfig, \%$form); 3264 3265} 3266 3267 3268sub save_as_new { 3269 3270 for (qw(id addressid)) { delete $form->{$_} } 3271 if ($form->{lock_employeenumber}) { 3272 delete $form->{employeenumber}; 3273 } 3274 3275 &save; 3276 3277} 3278 3279 3280sub save_deduction { 3281 3282 $form->isblank("description", $locale->text("Description missing!")); 3283 3284 unless ($form->{"rate_1"} || $form->{"amount_1"}) { 3285 $form->isblank("rate_1", $locale->text("Rate missing!")) unless $form->{"amount_1"}; 3286 $form->isblank("amount_1", $locale->text("Amount missing!")); 3287 } 3288 3289 HR->save_deduction(\%myconfig, \%$form); 3290 $form->redirect($locale->text('Deduction saved!')); 3291 3292} 3293 3294 3295sub delete_deduction { 3296 3297 HR->delete_deduction(\%myconfig, \%$form); 3298 $form->redirect($locale->text('Deduction deleted!')); 3299 3300} 3301 3302 3303sub save_wage { 3304 3305 $form->isblank("description", $locale->text("Description missing!")); 3306 3307 HR->save_wage(\%myconfig, \%$form); 3308 $form->redirect($locale->text('Wage saved!')); 3309 3310} 3311 3312 3313sub delete_wage { 3314 3315 HR->delete_wage(\%myconfig, \%$form); 3316 $form->redirect($locale->text('Wage deleted!')); 3317 3318} 3319 3320 3321sub preview { 3322 3323 $form->{format} = "pdf"; 3324 $form->{media} = "screen"; 3325 3326 &print; 3327 3328} 3329 3330