import sql-ledger 2.4.4
[freeside.git] / sql-ledger / bin / mozilla / hr.pl
1 #=====================================================================
2 # SQL-Ledger, Accounting
3 # Copyright (c) 2004
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
23 #
24 # payroll module
25 #
26 #======================================================================
27
28 use SL::HR;
29 use SL::User;
30
31 1;
32 # end of main
33
34
35
36 sub add {
37
38   $label = "Add ".ucfirst $form->{db};
39   $form->{title} = $locale->text($label);
40
41   $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
42
43   &{ "$form->{db}_links" };
44   
45 }
46
47
48 sub search { &{ "search_$form->{db}" } };
49   
50
51 sub search_employee {
52
53   $form->{title} = $locale->text('Employees');
54
55   $form->header;
56   
57   print qq|
58 <body>
59
60 <form method=post action=$form->{script}>
61
62 <table width=100%>
63   <tr>
64     <th class=listtop>$form->{title}</th>
65   </tr>
66   <tr height="5"></tr>
67   <tr valign=top>
68     <td>
69       <table>
70         <tr>
71           <th align=right nowrap>|.$locale->text('Employee Number').qq|</th>
72           <td colspan=3><input name=employeenumber size=20></td>
73         </tr>
74         <tr>
75           <th align=right nowrap>|.$locale->text('Employee Name').qq|</th>
76           <td colspan=3><input name=name size=35></td>
77         </tr>
78         <tr>
79           <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
80           <td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td>
81           <th>|.$locale->text('Enddate').qq|</th>
82           <td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>
83         </tr>
84         <tr valign=top>
85           <th align=right nowrap>|.$locale->text('Notes').qq|</th>
86           <td colspan=3><input name=notes size=40></td>
87         </tr>
88         <tr>
89           <td></td>
90           <td colspan=3><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
91           <input name=status class=radio type=radio value=sales>&nbsp;|.$locale->text('Sales').qq|
92           <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|</td>
93         </tr>
94         <tr>
95           <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
96           <td colspan=3>
97             <table>
98               <tr>
99                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID').qq|</td>
100                 <td><input name="l_employeenumber" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Number').qq|</td>
101                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Name').qq|</td>
102                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address').qq|</td>
103                 <td><input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City').qq|</td>
104               </tr>
105               <tr>
106                 <td><input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province').qq|</td>
107                 <td><input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code').qq|</td>
108                 <td><input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country').qq|</td>
109                 <td><input name="l_workphone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Work Phone').qq|</td>
110               </tr>
111               <tr>
112                 <td><input name="l_homephone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Home Phone').qq|</td>
113                 <td><input name="l_startdate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Startdate').qq|</td>
114                 <td><input name="l_enddate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Enddate').qq|</td>
115                 <td><input name="l_sales" type=checkbox class=checkbox value=Y> |.$locale->text('Sales').qq|</td>
116               </tr>
117               <tr>
118                 <td><input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager').qq|</td>
119                 <td><input name="l_role" type=checkbox class=checkbox value=Y checked> |.$locale->text('Role').qq|</td>
120                 <td><input name="l_login" type=checkbox class=checkbox value=Y checked> |.$locale->text('Login').qq|</td>
121                 <td><input name="l_email" type=checkbox class=checkbox value=Y> |.$locale->text('E-mail').qq|</td>
122               </tr>
123               <tr>
124                 <td><input name="l_ssn" type=checkbox class=checkbox value=Y> |.$locale->text('SSN').qq|</td>
125                 <td><input name="l_dob" type=checkbox class=checkbox value=Y> |.$locale->text('DOB').qq|</td>
126                 <td><input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN').qq|</td>
127                 <td><input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC').qq|</td>
128                 <td><input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes').qq|</td>
129               </tr>
130             </table>
131           </td>
132         </tr>
133       </table>
134     </td>
135   </tr>
136   <tr>
137     <td><hr size=3 noshade></td>
138   </tr>
139 </table>
140
141 <input type=hidden name=nextsub value=list_employees>
142 <input type=hidden name=db value=$form->{db}>
143
144 <input type=hidden name=path value=$form->{path}>
145 <input type=hidden name=login value=$form->{login}>
146 <input type=hidden name=sessionid value=$form->{sessionid}>
147
148 <br>
149 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
150 </form>
151
152 </body>
153 </html>
154 |;
155 }
156
157
158 sub list_employees {
159
160   HR->employees(\%myconfig, \%$form);
161   
162   $href = "$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
163   
164   $form->sort_order();
165
166   $callback = "$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
167   
168   @columns = $form->sort_columns(qw(id employeenumber name address city state zipcode country workphone homephone email startdate enddate ssn dob iban bic sales role manager login notes));
169
170   foreach $item (@columns) {
171     if ($form->{"l_$item"} eq "Y") {
172       push @column_index, $item;
173
174       # add column to href and callback
175       $callback .= "&l_$item=Y";
176       $href .= "&l_$item=Y";
177     }
178   }
179
180   %role = ( user        => $locale->text('User'),
181             supervisor  => $locale->text('Supervisor'),
182             manager     => $locale->text('Manager'),
183             admin       => $locale->text('Administrator')
184           );
185   
186   $option = $locale->text('All');
187
188   if ($form->{status} eq 'sales') {
189     $option = $locale->text('Sales');
190   }
191   if ($form->{status} eq 'orphaned') {
192     $option = $locale->text('Orphaned');
193   }
194   if ($form->{employeenumber}) {
195     $callback .= "&employeenumber=".$form->escape($form->{employeenumber},1);
196     $href .= "&employeenumber=".$form->escape($form->{employeenumber});
197     $option .= "\n<br>".$locale->text('Employee Number')." : $form->{employeenumber}";
198   }
199   if ($form->{name}) {
200     $callback .= "&name=".$form->escape($form->{name},1);
201     $href .= "&name=".$form->escape($form->{name});
202     $option .= "\n<br>".$locale->text('Employee Name')." : $form->{name}";
203   }
204   if ($form->{startdate}) {
205     $callback .= "&startdate=$form->{startdate}";
206     $href .= "&startdate=$form->{startdate}";
207     $option .= "\n<br>" if ($option);
208     $option .= $locale->text('Startdate')."&nbsp;".$locale->date(\%myconfig, $form->{startdate}, 1);
209   }
210   if ($form->{enddate}) {
211     $callback .= "&enddate=$form->{enddate}";
212     $href .= "&enddate=$form->{enddate}";
213     $option .= "\n<br>" if ($option);
214     $option .= $locale->text('Enddate')."&nbsp;".$locale->date(\%myconfig, $form->{enddate}, 1);
215   }
216   if ($form->{notes}) {
217     $callback .= "&notes=".$form->escape($form->{notes},1);
218     $href .= "&notes=".$form->escape($form->{notes});
219     $option .= "\n<br>" if $option;
220     $option .= $locale->text('Notes')." : $form->{notes}";
221   }
222
223   $form->{callback} = "$callback&sort=$form->{sort}";
224   $callback = $form->escape($form->{callback});
225
226   $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|;
227   $column_header{employeenumber} = qq|<th><a class=listheading href=$href&sort=employeenumber>|.$locale->text('Number').qq|</a></th>|;
228   $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
229   $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|;
230   $column_header{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</a></th>|;
231   $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|;
232   $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|;
233   $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|;
234   $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|;
235   $column_header{workphone} = qq|<th><a class=listheading href=$href&sort=workphone>|.$locale->text('Work Phone').qq|</a></th>|;
236   $column_header{homephone} = qq|<th><a class=listheading href=$href&sort=homephone>|.$locale->text('Home Phone').qq|</a></th>|;
237   
238   $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
239   $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
240   $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|;
241   $column_header{role} = qq|<th><a class=listheading href=$href&sort=role>|.$locale->text('Role').qq|</a></th>|;
242   $column_header{login} = qq|<th><a class=listheading href=$href&sort=login>|.$locale->text('Login').qq|</a></th>|;
243   
244   $column_header{sales} = qq|<th class=listheading>|.$locale->text('S').qq|</th>|;
245   $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;
246   $column_header{ssn} = qq|<th><a class=listheading href=$href&sort=ssn>|.$locale->text('SSN').qq|</a></th>|;
247   $column_header{dob} = qq|<th><a class=listheading href=$href&sort=dob>|.$locale->text('DOB').qq|</a></th>|;
248   $column_header{iban} = qq|<th><a class=listheading href=$href&sort=iban>|.$locale->text('IBAN').qq|</a></th>|;
249   $column_header{bic} = qq|<th><a class=listheading href=$href&sort=bic>|.$locale->text('BIC').qq|</a></th>|;
250   
251   $form->{title} = $locale->text('Employees');
252
253   $form->header;
254
255   print qq|
256 <body>
257
258 <table width=100%>
259   <tr>
260     <th class=listtop>$form->{title}</th>
261   </tr>
262   <tr height="5"></tr>
263   <tr>
264     <td>$option</td>
265   </tr>
266   <tr>
267     <td>
268       <table width=100%>
269         <tr class=listheading>
270 |;
271
272   map { print "$column_header{$_}\n" } @column_index;
273   
274   print qq|
275         </tr>
276 |;
277
278   foreach $ref (@{ $form->{all_employee} }) {
279
280     map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
281     
282     $column_data{sales} = ($ref->{sales}) ? "<td>x</td>" : "<td>&nbsp;</td>";
283     $column_data{role} = qq|<td>$role{"$ref->{role}"}&nbsp;</td>|;
284     $column_date{address} = qq|$ref->{address1} $ref->{address2}|;
285
286     $column_data{name} = "<td><a href=$form->{script}?action=edit&db=employee&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
287
288     if ($ref->{email}) {
289       $email = $ref->{email};
290       $email =~ s/</\&lt;/;
291       $email =~ s/>/\&gt;/;
292       
293       $column_data{email} = qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
294     }
295
296     $i++; $i %= 2;
297     print "
298         <tr class=listrow$i>
299 ";
300
301     map { print "$column_data{$_}\n" } @column_index;
302
303     print qq|
304         </tr>
305 |;
306     
307   }
308
309   $i = 1;
310   $button{'HR--Employees--Add Employee'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Employee').qq|"> |;
311   $button{'HR--Employees--Add Employee'}{order} = $i++;
312
313   foreach $item (split /;/, $myconfig{acs}) {
314     delete $button{$item};
315   }
316   
317   print qq|
318       </table>
319     </td>
320   </tr>
321   <tr>
322     <td><hr size=3 noshade></td>
323   </tr>
324 </table>
325
326 <br>
327 <form method=post action=$form->{script}>
328
329 <input name=callback type=hidden value="$form->{callback}">
330
331 <input type=hidden name=db value=$form->{db}>
332
333 <input type=hidden name=path value=$form->{path}>
334 <input type=hidden name=login value=$form->{login}>
335 <input type=hidden name=sessionid value=$form->{sessionid}>
336 |;
337
338   foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
339     print $item->{code};
340   }
341
342   if ($form->{menubar}) {
343     require "$form->{path}/menu.pl";
344     &menubar;
345   }
346
347   print qq|
348   </form>
349
350 </body>
351 </html>
352 |;
353  
354 }
355
356
357 sub edit {
358
359 # $locale->text('Edit Employee')
360 # $locale->text('Edit Deduction')
361
362   $label = ucfirst $form->{db};
363   $form->{title} = "Edit $label";
364
365   &{ "$form->{db}_links" };
366   
367 }
368
369
370 sub employee_links {
371
372 #$form->{deductions} = 1;
373   HR->get_employee(\%myconfig, \%$form);
374
375   map { $form->{$_} = $form->quote($form->{$_}) } keys %$form;
376
377   if ($form->{all_deduction}) {
378     $form->{selectdeduction} = "<option>\n";
379     map { $form->{selectdeduction} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } @{ $form->{all_deduction} };
380   }
381
382   $form->{manager} = "$form->{manager}--$form->{managerid}";
383
384   if ($form->{all_manager}) {
385     $form->{selectmanager} = "<option>\n";
386     map { $form->{selectmanager} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_manager} };
387   }
388
389   %role = ( user        => $locale->text('User'),
390             supervisor  => $locale->text('Supervisor'),
391             manager     => $locale->text('Manager'),
392             admin       => $locale->text('Administrator')
393           );
394   
395   $form->{selectrole} = "<option>\n";
396   map { $form->{selectrole} .= "<option value=$_>$role{$_}\n" } qw(user supervisor manager admin);
397
398   $i = 1;
399   foreach $ref (@{ $form->{all_employeededuction} }) {
400     $form->{"deduction_$i"} = "$ref->{description}--$ref->{id}";
401     map { $form->{"${_}_$i"} = $ref->{$_} } qw(before after rate);
402     $i++;
403   }
404   $form->{deduction_rows} = $i - 1;
405
406   &employee_header;
407   &employee_footer;
408
409 }
410
411
412 sub employee_header {
413
414   $sales = qq|<input type=hidden name=sales value=$form->{sales}>|;
415   $form->{sales} = ($form->{sales}) ? "checked" : "";
416
417   $form->{selectrole} =~ s/ selected//;
418   $form->{selectrole} =~ s/option value=\Q$form->{role}\E>/option value=$form->{role} selected>/;
419
420   $form->{selectdeduction} = $form->unescape($form->{selectdeduction});
421   
422   $form->{selectmanager} = $form->unescape($form->{selectmanager});
423   $form->{selectmanager} =~ s/ selected//;
424   $form->{selectmanager} =~ s/(<option value="\Q$form->{manager}\E")/$1 selected/;
425
426   $sales = qq|
427 <input type=hidden name=role value=$form->{role}>
428 <input type=hidden name=manager value=$form->{manager}>
429 |;
430
431   if ($myconfig{role} ne 'user') {
432     $sales = qq|
433         <tr>
434           <th align=right>|.$locale->text('Sales').qq|</th>
435           <td><input name=sales class=checkbox type=checkbox value=1 $form->{sales}></td>
436         </tr>
437         <tr>
438           <th align=right>|.$locale->text('Role').qq|</th>
439           <td><select name=role>$form->{selectrole}</select></td>
440         </tr>
441 |;
442
443     if ($form->{selectmanager}) {
444       $sales .= qq|
445         <tr>
446           <th align=right>|.$locale->text('Manager').qq|</th>
447           <td><select name=manager>$form->{selectmanager}</select></td>
448         </tr>
449 |;
450     }
451   }
452   
453   $form->{deduction_rows}++;
454   
455   for ($i = 1; $i <= $form->{deduction_rows}; $i++) {
456     $form->{"selectdeduction_$i"} = $form->{selectdeduction};
457     if ($form->{"deduction_$i"}) {
458       $form->{"selectdeduction_$i"} =~ s/(<option value="\Q$form->{"deduction_$i"}\E")/$1 selected/;
459     }
460   }
461
462   $form->{selectdeduction} = $form->escape($form->{selectdeduction},1);
463   $form->{selectmanager} = $form->escape($form->{selectmanager},1);
464
465   $form->header;
466
467   print qq|
468 <body>
469
470 <form method=post action=$form->{script}>
471
472 <input type=hidden name=selectdeduction value="$form->{selectdeduction}">
473 <input type=hidden name=deduction_rows value=$form->{deduction_rows}>
474
475 <input type=hidden name=selectmanager value="$form->{selectmanager}">
476 <input type=hidden name=selectrole value="$form->{selectrole}">
477
478 <input type=hidden name=status value=$form->{status}>
479
480 <input type=hidden name=title value="$form->{title}">
481
482 <table width=100%>
483   <tr>
484     <th class=listtop>$form->{title}</th>
485   </tr>
486   <tr height="5"></tr>
487   <tr>
488     <td>
489       <table>
490         <tr valign=top>
491           <td>
492             <table>
493               <tr>
494                 <th align=right nowrap>|.$locale->text('Number').qq|</th>
495                 <td><input name=employeenumber size=32 maxlength=32 value="$form->{employeenumber}"></td>
496               </tr>
497               <tr>
498                 <th align=right nowrap>|.$locale->text('Name').qq|</th>
499                 <td><input name=name size=35 maxlength=64 value="$form->{name}"></td>
500               </tr>
501               <tr>
502                 <th align=right nowrap>|.$locale->text('Address').qq|</th>
503                 <td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td>
504               </tr>
505               <tr>
506                 <th></th>
507                 <td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td>
508               </tr>
509               <tr>
510                 <th align=right nowrap>|.$locale->text('City').qq|</th>
511                 <td><input name=city size=35 maxlength=32 value="$form->{city}"></td>
512               </tr>
513               <tr>
514                 <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
515                 <td><input name=state size=35 maxlength=32 value="$form->{state}"></td>
516               </tr>
517               <tr>
518                 <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
519                 <td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td>
520               </tr>
521               <tr>
522                 <th align=right nowrap>|.$locale->text('Country').qq|</th>
523                 <td><input name=country size=35 maxlength=32 value="$form->{country}"></td>
524               </tr>
525               <tr>
526                 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
527                 <td><input name=email size=35 value="$form->{email}"></td>
528               </tr>
529               <tr>
530               $sales
531             </table>
532           </td>
533           <td>
534             <table>
535               <tr>
536                 <th align=right nowrap>|.$locale->text('Work Phone').qq|</th>
537                 <td><input name=workphone size=20 maxlength=20 value="$form->{workphone}"></td>
538               </tr>
539               <tr>
540                 <th align=right nowrap>|.$locale->text('Home Phone').qq|</th>
541                 <td><input name=homephone size=20 maxlength=20 value="$form->{homephone}"></td>
542               </tr>
543               <tr>
544                 <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
545                 <td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td>
546               </tr>
547               <tr>
548                 <th align=right nowrap>|.$locale->text('Enddate').qq|</th>
549                 <td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>
550               </tr>
551
552               <tr>
553                 <th align=right nowrap>|.$locale->text('SSN').qq|</th>
554                 <td><input name=ssn size=20 maxlength=20 value="$form->{ssn}"></td>
555               </tr>
556               <tr>
557                 <th align=right nowrap>|.$locale->text('DOB').qq|</th>
558                 <td><input name=dob size=11 title="$myconfig{dateformat}" value=$form->{dob}></td>
559               </tr>
560               <tr>
561                 <th align=right nowrap>|.$locale->text('IBAN').qq|</th>
562                 <td><input name=iban size=34 maxlength=34 value="$form->{iban}"></td>
563               </tr>
564               <tr>
565                 <th align=right nowrap>|.$locale->text('BIC').qq|</th>
566                 <td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td>
567               </tr>
568             </table>
569           </td>
570         </tr>
571       </table>
572     </td>
573   </tr>
574   <tr>
575     <th align=left nowrap>|.$locale->text('Notes').qq|</th>
576   </tr>
577   <tr>
578     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
579   </tr>
580 |;
581
582     if ($form->{selectdeduction}) {
583
584       print qq|
585   <tr>
586     <td>
587       <table width=100%>
588         <tr class=listheading>
589           <th class=listheading>|.$locale->text('Payroll Deduction').qq|</th>
590           <th class=listheading colspan=3>|.$locale->text('Allowances').qq|</th>
591         </tr>
592
593         <tr class=listheading>
594           <th></th>
595           <th class=listheading>|.$locale->text('Before Deduction').qq|</th>
596           <th class=listheading>|.$locale->text('After Deduction').qq|</th>
597           <th class=listheading>|.$locale->text('Rate').qq|</th>
598         </tr>
599 |;
600
601     for ($i = 1; $i <= $form->{deduction_rows}; $i++) {
602       print qq|
603         <tr>
604           <td><select name="deduction_$i">$form->{"selectdeduction_$i"}</select></td>
605           <td><input name="before_$i" value=|.$form->format_amount(\%myconfig, $form->{"before_$i"}, 2).qq|></td>
606           <td><input name="after_$i" value=|.$form->format_amount(\%myconfig, $form->{"after_$i"}, 2).qq|></td>
607           <td><input name="rate_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td>
608         </tr>
609 |;
610     }
611   }
612
613   print qq|
614       </table>
615     </td>
616   </tr>
617   <tr>
618     <td><hr size=3 noshade></td>
619   </tr>
620 </table>
621 |;
622
623 }
624
625
626
627 sub employee_footer {
628
629   print qq|
630 <input name=id type=hidden value=$form->{id}>
631
632 <input type=hidden name=db value=$form->{db}>
633 <input type=hidden name=employeelogin value=$form->{employeelogin}>
634
635 <input type=hidden name=path value=$form->{path}>
636 <input type=hidden name=login value=$form->{login}>
637 <input type=hidden name=sessionid value=$form->{sessionid}>
638
639 <input type=hidden name=callback value="$form->{callback}">
640
641 <br>
642
643 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
644 <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">
645 |;
646
647   if ($form->{id}) {
648     print qq|<input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">\n|;
649     if ($form->{status} eq 'orphaned') {
650       print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
651     }
652   }
653
654   if ($form->{menubar}) {
655     require "$form->{path}/menu.pl";
656     &menubar;
657   }
658
659   print qq|
660  
661   </form>
662
663 </body>
664 </html>
665 |;
666
667 }
668
669
670 sub save { &{ "save_$form->{db}" } };
671
672
673 sub save_employee {
674
675   $form->isblank("name", $locale->text("Name missing!"));
676   HR->save_employee(\%myconfig, \%$form);
677
678   # if it is a login change memberfile and .conf
679   if ($form->{employeelogin}) {
680     $user = new User $memberfile, $form->{employeelogin};
681
682     map { $user->{$_} = $form->{$_} } qw(name email role);
683     map { $user->{"old_$_"} = $user->{$_} } qw(dbpassword password);
684     
685     $user->save_member($memberfile, $userspath) if $user->{login};
686   }
687   
688   $form->redirect($locale->text('Employee saved!'));
689   
690 }
691
692
693 sub delete { &{ "delete_$form->{db}" } };
694
695
696 sub delete_employee {
697
698   HR->delete_employee(\%myconfig, \%$form);
699   $form->redirect($locale->text('Employee deleted!'));
700   
701 }
702
703
704 sub continue { &{ $form->{nextsub} } };
705
706 sub add_employee { &add };
707 sub add_deduction { &add };
708
709
710 sub search_deduction {
711
712   HR->deductions(\%myconfig, \%$form);
713   
714   $href = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
715
716   $form->sort_order();
717
718   $callback = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
719   
720   @column_index = $form->sort_columns(qw(description rate amount above below employeepays employerpays ap_accno expense_accno));
721
722  
723   $form->{callback} = $callback;
724   $callback = $form->escape($form->{callback});
725
726   $column_header{description} = qq|<th class=listheading href=$href>|.$locale->text('Description').qq|</th>|;
727   $column_header{rate} = qq|<th class=listheading nowrap>|.$locale->text('Rate').qq|<br>%</th>|;
728   $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
729   $column_header{above} = qq|<th class=listheading>|.$locale->text('Above').qq|</th>|;
730   $column_header{below} = qq|<th class=listheading>|.$locale->text('Below').qq|</th>|;
731   $column_header{employerpays} = qq|<th class=listheading>|.$locale->text('Employer').qq|</th>|;
732   $column_header{employeepays} = qq|<th class=listheading>|.$locale->text('Employee').qq|</th>|;
733   
734   $column_header{ap_accno} = qq|<th class=listheading>|.$locale->text('AP').qq|</th>|;
735   $column_header{expense_accno} = qq|<th class=listheading>|.$locale->text('Expense').qq|</th>|;
736   
737   $form->{title} = $locale->text('Deductions');
738
739   $form->header;
740
741   print qq|
742 <body>
743
744 <table width=100%>
745   <tr>
746     <th class=listtop>$form->{title}</th>
747   </tr>
748   <tr height="5"></tr>
749   <tr>
750     <td>$option</td>
751   </tr>
752   <tr>
753     <td>
754       <table width=100%>
755         <tr class=listheading>
756 |;
757
758   map { print "$column_header{$_}\n" } @column_index;
759   
760   print qq|
761         </tr>
762 |;
763
764   
765   foreach $ref (@{ $form->{all_deduction} }) {
766
767     $rate = $form->format_amount(\%myconfig, $ref->{rate} * 100, "", "&nbsp;");
768     
769     $column_data{rate} = "<td align=right>$rate</td>";
770
771     map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;")."</td>" } qw(amount below above);
772       
773     map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } qw(ap_accno expense_accno);
774     
775     map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, "", "&nbsp;")."</td>" } qw(employerpays employeepays);
776     
777     if ($ref->{description} ne $sameitem) {
778       $column_data{description} = "<td><a href=$form->{script}?action=edit&db=$form->{db}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</a></td>";
779     } else {
780       $column_data{description} = "<td>&nbsp;</td>";
781     }
782
783     $i++; $i %= 2;
784     print "
785         <tr class=listrow$i>
786 ";
787
788     map { print "$column_data{$_}\n" } @column_index;
789
790     print qq|
791         </tr>
792 |;
793
794     $sameitem = $ref->{description};
795     
796   }
797
798   $i = 1;
799   $button{'HR--Deductions--Add Deduction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Deduction').qq|"> |;
800   $button{'HR--Deductions--Add Deduction'}{order} = $i++;
801
802   foreach $item (split /;/, $myconfig{acs}) {
803     delete $button{$item};
804   }
805   
806   print qq|
807       </table>
808     </td>
809   </tr>
810   <tr>
811     <td><hr size=3 noshade></td>
812   </tr>
813 </table>
814
815 <br>
816 <form method=post action=$form->{script}>
817
818 <input type=hidden name=db value=$form->{db}>
819
820 <input name=callback type=hidden value="$form->{callback}">
821
822 <input type=hidden name=path value=$form->{path}>
823 <input type=hidden name=login value=$form->{login}>
824 <input type=hidden name=sessionid value=$form->{sessionid}>
825 |;
826
827   foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
828     print $item->{code};
829   }
830
831   if ($form->{menubar}) {
832     require "$form->{path}/menu.pl";
833     &menubar;
834   }
835
836   print qq|
837   </form>
838
839 </body>
840 </html>
841 |;
842  
843 }
844
845
846 sub deduction_links {
847   
848   HR->get_deduction(\%myconfig, \%$form);
849
850   $i = 1;
851   foreach $ref (@{ $form->{deductionrate} }) {
852     map { $form->{"${_}_$i"} = $ref->{$_} } keys %$ref;
853     $i++;
854   }
855   $form->{rate_rows} = $i - 1;
856   
857   $i = 1;
858   foreach $ref (@{ $form->{deductionbase} }) {
859     $form->{"base_$i"} = "$ref->{description}--$ref->{id}";
860     $form->{"maximum_$i"} = $ref->{maximum};
861     $i++;
862   }
863   $form->{base_rows} = $i - 1;
864
865   $i = 1;
866   foreach $ref (@{ $form->{deductionafter} }) {
867     $form->{"after_$i"} = "$ref->{description}--$ref->{id}";
868     $i++;
869   }
870   $form->{after_rows} = $i - 1;
871   
872   $form->{employeepays} = 1;
873   
874   $selectaccount = "<option>\n";
875   map { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{ap_accounts} };
876
877   $form->{ap_accno} = qq|$form->{ap_accno}--$form->{ap_description}|;
878   $form->{selectap} = $selectaccount;
879
880   $selectaccount = "<option>\n";
881   map { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{expense_accounts} };
882
883   $form->{expense_accno} = qq|$form->{expense_accno}--$form->{expense_description}|;
884   $form->{selectexpense} = $selectaccount;
885
886   map { $form->{"rate_$_"} *= 100 } (1 .. $form->{rate_rows});
887
888   $form->{selectbase} = "<option>\n";
889   map { $form->{selectbase} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } @{ $form->{all_deduction} };
890   
891   &deduction_header;
892   &deduction_footer;
893   
894 }
895
896
897 sub deduction_header {
898
899   $selectap = $form->{selectap};
900   $selectap =~ s/option>\Q$form->{ap_accno}\E/option selected>$form->{ap_accno}/;
901   $selectexpense = $form->{selectexpense};
902   $selectexpense =~ s/option>\Q$form->{expense_accno}\E/option selected>$form->{expense_accno}/;
903
904
905   $form->{rate_rows}++;
906   $form->{base_rows}++;
907   $form->{after_rows}++;
908
909   $form->{selectbase} = $form->unescape($form->{selectbase});
910   
911   for ($i = 1; $i <= $form->{base_rows}; $i++) {
912     $form->{"selectbase_$i"} = $form->{selectbase};
913     if ($form->{"base_$i"}) {
914       $form->{"selectbase_$i"} =~ s/(<option value="\Q$form->{"base_$i"}\E")/$1 selected/;
915     }
916   }
917   for ($i = 1; $i <= $form->{after_rows}; $i++) {
918     $form->{"selectafter_$i"} = $form->{selectbase};
919     if ($form->{"after_$i"}) {
920       $form->{"selectafter_$i"} =~ s/(<option value="\Q$form->{"after_$i"}\E")/$1 selected/;
921     }
922   }
923  
924
925   $form->header;
926
927   
928   print qq|
929 <body>
930
931 <form method=post action=$form->{script}>
932
933 <input type=hidden name=title value="$form->{title}">
934
935 <input type=hidden name=selectap value="$form->{selectap}">
936 <input type=hidden name=selectexpense value="$form->{selectexpense}">
937 <input type=hidden name=selectbase value="|.$form->escape($form->{selectbase},1).qq|">
938
939 <input type=hidden name=rate_rows value=$form->{rate_rows}>
940 <input type=hidden name=base_rows value=$form->{base_rows}>
941 <input type=hidden name=after_rows value=$form->{after_rows}>
942
943 <table width=100%>
944   <tr>
945     <th class=listtop>$form->{title}</th>
946   </tr>
947   <tr height="5"></tr>
948   <tr>
949     <td>
950       <table>
951         <tr>
952           <th align=right nowrap>|.$locale->text('Description').qq|</th>
953           <td><input name=description size=35 value="$form->{description}"></td>
954         </tr>
955         <tr>
956           <th align=right nowrap>|.$locale->text('AP').qq|</th>
957           <td><select name=ap_accno>$selectap</select></td>
958           <th align=right nowrap>|.$locale->text('Employee pays').qq| x</th>
959           <td><input name=employeepays size=4 value=|.$form->format_amount(\%myconfig, $form->{employeepays}).qq|></td>
960         </tr>
961         <tr>
962           <th align=right nowrap>|.$locale->text('Expense').qq|</th>
963           <td><select name=expense_accno>$selectexpense</select></td>
964           <th align=right nowrap>|.$locale->text('Employer pays').qq| x</th>
965           <td><input name=employerpays size=4 value=|.$form->format_amount(\%myconfig, $form->{employerpays}).qq|></td>
966         </tr>
967         <tr>
968           <td></td>
969           <td></td>
970           <th align=right nowrap>|.$locale->text('Excempt age <').qq|</th>
971           <td><input name=fromage size=4 value=|.$form->format_amount(\%myconfig, $form->{fromage}).qq|></td>
972           <th align=right nowrap>|.$locale->text('>').qq|</th>
973           <td><input name=toage size=4 value=|.$form->format_amount(\%myconfig, $form->{toage}).qq|>
974         </tr>
975         <tr>
976           <td></td>
977           <td>
978             <table>
979               <tr class=listheading>
980                 <th class=listheading>|.$locale->text('Rate').qq| %</th>
981                 <th class=listheading>|.$locale->text('Amount').qq|</th>
982                 <th class=listheading>|.$locale->text('Above').qq|</th>
983                 <th class=listheading>|.$locale->text('Below').qq|</th>
984               </tr>
985 |;
986
987   for ($i = 1; $i <= $form->{rate_rows}; $i++) {
988     print qq|
989               <tr>
990                 <td><input name="rate_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td>
991                 <td><input name="amount_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"amount_$i"}, 2).qq|></td>
992                 <td><input name="above_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"above_$i"}, 2).qq|></td>
993                 <td><input name="below_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"below_$i"}, 2).qq|></td>
994               </tr>
995 |;
996   }
997
998   print qq|
999             </table>
1000           </td>
1001         </tr>
1002       </table>
1003     </td>
1004   </tr>
1005 |;
1006   
1007   print qq|
1008   <tr>
1009     <td>
1010       <table>
1011 |;
1012
1013   $basedon = $locale->text('Based on');
1014   $maximum = $locale->text('Maximum');
1015   
1016   for ($i = 1; $i <= $form->{base_rows}; $i++) {
1017     print qq|
1018         <tr>
1019           <th>$basedon</th>
1020           <td><select name="base_$i">$form->{"selectbase_$i"}</select></td>
1021           <th>$maximum</th>
1022           <td><input name="maximum_$i" value=|.$form->format_amount(\%myconfig, $form->{"maximum_$i"}, 2).qq|></td>
1023         </tr>
1024 |;
1025     $basedon = "";
1026     $maximum = "";
1027   }
1028
1029   $deductafter = $locale->text('Deduct after');
1030   
1031   for ($i = 1; $i <= $form->{after_rows}; $i++) {
1032     print qq|
1033         <tr>
1034           <th>$deductafter</th>
1035           <td><select name="after_$i">$form->{"selectafter_$i"}</select></td>
1036         </tr>
1037 |;
1038     $deductafter = "";
1039   }
1040
1041   print qq|
1042       </table>
1043     </td>
1044   </tr>
1045   <tr>
1046     <td><hr size=3 noshade></td>
1047   </tr>
1048 </table>
1049 |;
1050
1051 }
1052
1053
1054
1055 sub deduction_footer {
1056
1057   print qq|
1058 <input name=id type=hidden value=$form->{id}>
1059
1060 <input type=hidden name=db value=$form->{db}>
1061
1062 <input type=hidden name=path value=$form->{path}>
1063 <input type=hidden name=login value=$form->{login}>
1064 <input type=hidden name=sessionid value=$form->{sessionid}>
1065
1066 <input type=hidden name=callback value="$form->{callback}">
1067
1068 <br>
1069
1070 <input class=submit type=submit name=action value="|.$locale->text("Update").qq|">
1071 <input class=submit type=submit name=action value="|.$locale->text("Save").qq|">
1072 |;
1073
1074   if ($form->{id}) {
1075     print qq|<input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">\n|;
1076     
1077     if ($form->{status} eq 'orphaned') {
1078       print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
1079     }
1080   }
1081
1082   if ($form->{menubar}) {
1083     require "$form->{path}/menu.pl";
1084     &menubar;
1085   }
1086
1087   print qq|
1088  
1089   </form>
1090
1091 </body>
1092 </html>
1093 |;
1094
1095 }
1096
1097
1098 sub update { &{ "update_$form->{db}" }; }
1099 sub save { &{ "save_$form->{db}" } };
1100
1101
1102 sub update_deduction {
1103
1104   # if rate or amount is blank remove row
1105   @flds = qw(rate amount above below);
1106   $count = 0;
1107   @a = ();
1108   for $i (1 .. $form->{rate_rows}) {
1109     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } @flds;
1110     if ($form->{"rate_$i"} || $form->{"amount_$i"}) {
1111       push @a, {};
1112       $j = $#a;
1113
1114       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1115       $count++;
1116     }
1117   }
1118   $form->redo_rows(\@flds, \@a, $count, $form->{rate_rows});
1119   $form->{rate_rows} = $count;
1120
1121
1122   @flds = qw(base maximum);
1123   $count = 0;
1124   @a = ();
1125   for $i (1 .. $form->{"base_rows"}) {
1126     $form->{"maximum_$i"} = $form->parse_amount(\%myconfig, $form->{"maximum_$i"});
1127     if ($form->{"base_$i"}) {
1128       push @a, {};
1129       $j = $#a;
1130
1131       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1132       $count++;
1133     }
1134   }
1135   $form->redo_rows(\@flds, \@a, $count, $form->{"base_rows"});
1136   $form->{"base_rows"} = $count;
1137
1138
1139   @flds = qw(after);
1140   $count = 0;
1141   @a = ();
1142   for $i (1 .. $form->{"after_rows"}) {
1143     if ($form->{"after_$i"}) {
1144       push @a, {};
1145       $j = $#a;
1146
1147       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1148       $count++;
1149     }
1150   }
1151   $form->redo_rows(\@flds, \@a, $count, $form->{"after_rows"});
1152   $form->{"after_rows"} = $count;
1153
1154   &deduction_header;
1155   &deduction_footer;
1156
1157 }
1158
1159
1160 sub update_employee {
1161
1162   # if rate or amount is blank remove row
1163   @flds = qw(before after);
1164   $count = 0;
1165   @a = ();
1166   for $i (1 .. $form->{deduction_rows}) {
1167     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } @flds;
1168     if ($form->{"deduction_$i"}) {
1169       push @a, {};
1170       $j = $#a;
1171
1172       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1173       $count++;
1174     }
1175   }
1176   $form->redo_rows(\@flds, \@a, $count, $form->{deduction_rows});
1177   $form->{deduction_rows} = $count;
1178
1179   &employee_header;
1180   &employee_footer;
1181
1182 }
1183  
1184
1185 sub save_as_new {
1186
1187   $form->{id} = 0;
1188   delete $form->{employeelogin};
1189
1190   &save;
1191
1192 }
1193
1194
1195 sub save_deduction {
1196
1197   $form->isblank("description", $locale->text("Description missing!"));
1198
1199   unless ($form->{"rate_1"} || $form->{"amount_1"}) {
1200     $form->isblank("rate_1", $locale->text("Rate missing!")) unless $form->{"amount_1"};
1201     $form->isblank("amount_1", $locale->text("Amount missing!"));
1202   }
1203   
1204   HR->save_deduction(\%myconfig, \%$form);
1205   $form->redirect($locale->text('Deduction saved!'));
1206   
1207 }
1208
1209
1210 sub delete_deduction {
1211
1212   HR->delete_deduction(\%myconfig, \%$form);
1213   $form->redirect($locale->text('Deduction deleted!'));
1214   
1215 }
1216
1217