summaryrefslogtreecommitdiff
path: root/bin/mozilla/hr.pl
blob: 42325e58b3c25742dc81bebbd4cc34bef102f9d3 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. #
  5. # See COPYRIGHT file for copyright information
  6. #======================================================================
  7. #
  8. # This file has NOT undergone whitespace cleanup.
  9. #
  10. #======================================================================
  11. #
  12. # payroll module
  13. #
  14. #======================================================================
  15. use LedgerSMB::HR;
  16. use LedgerSMB::User;
  17. 1;
  18. # end of main
  19. sub add {
  20. $label = "Add ".ucfirst $form->{db};
  21. $form->{title} = $locale->text($label);
  22. $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  23. &{ "$form->{db}_links" };
  24. }
  25. sub search { &{ "search_$form->{db}" } };
  26. sub search_employee {
  27. $form->{title} = $locale->text('Employees');
  28. @a = ();
  29. push @a, qq|<input name="l_ndx" type=checkbox class=checkbox value=Y> |.$locale->text('Pos');
  30. push @a, qq|<input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID');
  31. push @a, qq|<input name="l_employeenumber" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Number');
  32. push @a, qq|<input name="l_name" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Name');
  33. push @a, qq|<input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address');
  34. push @a, qq|<input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City');
  35. push @a, qq|<input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province');
  36. push @a, qq|<input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code');
  37. push @a, qq|<input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country');
  38. push @a, qq|<input name="l_workphone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Work Phone');
  39. push @a, qq|<input name="l_homephone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Home Phone');
  40. push @a, qq|<input name="l_startdate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Startdate');
  41. push @a, qq|<input name="l_enddate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Enddate');
  42. push @a, qq|<input name="l_sales" type=checkbox class=checkbox value=Y> |.$locale->text('Sales');
  43. push @a, qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager');
  44. push @a, qq|<input name="l_role" type=checkbox class=checkbox value=Y checked> |.$locale->text('Role');
  45. push @a, qq|<input name="l_login" type=checkbox class=checkbox value=Y checked> |.$locale->text('Login');
  46. push @a, qq|<input name="l_email" type=checkbox class=checkbox value=Y> |.$locale->text('E-mail');
  47. push @a, qq|<input name="l_ssn" type=checkbox class=checkbox value=Y> |.$locale->text('SSN');
  48. push @a, qq|<input name="l_dob" type=checkbox class=checkbox value=Y> |.$locale->text('DOB');
  49. push @a, qq|<input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN');
  50. push @a, qq|<input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC');
  51. push @a, qq|<input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes');
  52. $form->header;
  53. print qq|
  54. <body>
  55. <form method=post action=$form->{script}>
  56. <table width=100%>
  57. <tr>
  58. <th class=listtop>$form->{title}</th>
  59. </tr>
  60. <tr height="5"></tr>
  61. <tr valign=top>
  62. <td>
  63. <table>
  64. <tr>
  65. <th align=right nowrap>|.$locale->text('Employee Number').qq|</th>
  66. <td colspan=3><input name=employeenumber size=20></td>
  67. </tr>
  68. <tr>
  69. <th align=right nowrap>|.$locale->text('Employee Name').qq|</th>
  70. <td colspan=3><input name=name size=35></td>
  71. </tr>
  72. <tr>
  73. <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
  74. <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 title="$myconfig{dateformat}"> |.$locale->text('To').qq| <input name=startdateto size=11 title="$myconfig{dateformat}"></td>
  75. </tr>
  76. <tr valign=top>
  77. <th align=right nowrap>|.$locale->text('Notes').qq|</th>
  78. <td colspan=3><input name=notes size=40></td>
  79. </tr>
  80. <tr>
  81. <td></td>
  82. <td colspan=3><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
  83. <input name=status class=radio type=radio value=active>&nbsp;|.$locale->text('Active').qq|
  84. <input name=status class=radio type=radio value=inactive>&nbsp;|.$locale->text('Inactive').qq|
  85. <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|
  86. <input name=sales class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Sales').qq|
  87. </tr>
  88. <tr>
  89. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  90. <td colspan=3>
  91. <table>
  92. |;
  93. while (@a) {
  94. print qq|<tr>\n|;
  95. for (1 .. 5) {
  96. print qq|<td nowrap>|. shift @a;
  97. print qq|</td>\n|;
  98. }
  99. print qq|</tr>\n|;
  100. }
  101. print qq|
  102. </table>
  103. </td>
  104. </tr>
  105. </table>
  106. </td>
  107. </tr>
  108. <tr>
  109. <td><hr size=3 noshade></td>
  110. </tr>
  111. </table>
  112. <input type=hidden name=nextsub value=list_employees>
  113. |;
  114. $form->hide_form(qw(db path login sessionid));
  115. print qq|
  116. <br>
  117. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  118. </form>
  119. |;
  120. if ($form->{menubar}) {
  121. require "$form->{path}/menu.pl";
  122. &menubar;
  123. }
  124. print qq|
  125. </body>
  126. </html>
  127. |;
  128. }
  129. sub list_employees {
  130. HR->employees(\%myconfig, \%$form);
  131. $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}";
  132. $form->sort_order();
  133. $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}";
  134. @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));
  135. unshift @columns, "ndx";
  136. foreach $item (@columns) {
  137. if ($form->{"l_$item"} eq "Y") {
  138. push @column_index, $item;
  139. # add column to href and callback
  140. $callback .= "&l_$item=Y";
  141. $href .= "&l_$item=Y";
  142. }
  143. }
  144. %role = ( user => $locale->text('User'),
  145. supervisor => $locale->text('Supervisor'),
  146. manager => $locale->text('Manager'),
  147. admin => $locale->text('Administrator')
  148. );
  149. $option = $locale->text('All');
  150. if ($form->{status} eq 'sales') {
  151. $option = $locale->text('Sales');
  152. }
  153. if ($form->{status} eq 'orphaned') {
  154. $option = $locale->text('Orphaned');
  155. }
  156. if ($form->{status} eq 'active') {
  157. $option = $locale->text('Active');
  158. }
  159. if ($form->{status} eq 'inactive') {
  160. $option = $locale->text('Inactive');
  161. }
  162. if ($form->{employeenumber}) {
  163. $callback .= "&employeenumber=".$form->escape($form->{employeenumber},1);
  164. $href .= "&employeenumber=".$form->escape($form->{employeenumber});
  165. $option .= "\n<br>".$locale->text('Employee Number')." : $form->{employeenumber}";
  166. }
  167. if ($form->{name}) {
  168. $callback .= "&name=".$form->escape($form->{name},1);
  169. $href .= "&name=".$form->escape($form->{name});
  170. $option .= "\n<br>".$locale->text('Employee Name')." : $form->{name}";
  171. }
  172. if ($form->{startdatefrom}) {
  173. $callback .= "&startdatefrom=$form->{startdatefrom}";
  174. $href .= "&startdatefrom=$form->{startdatefrom}";
  175. $fromdate = $locale->date(\%myconfig, $form->{startdatefrom}, 1);
  176. }
  177. if ($form->{startdateto}) {
  178. $callback .= "&startdateto=$form->{startdateto}";
  179. $href .= "&startdateto=$form->{startdateto}";
  180. $todate = $locale->date(\%myconfig, $form->{startdateto}, 1);
  181. }
  182. if ($fromdate || $todate) {
  183. $option .= "\n<br>".$locale->text('Startdate')." $fromdate - $todate";
  184. }
  185. if ($form->{notes}) {
  186. $callback .= "&notes=".$form->escape($form->{notes},1);
  187. $href .= "&notes=".$form->escape($form->{notes});
  188. $option .= "\n<br>" if $option;
  189. $option .= $locale->text('Notes')." : $form->{notes}";
  190. }
  191. $form->{callback} = "$callback&sort=$form->{sort}";
  192. $callback = $form->escape($form->{callback});
  193. $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
  194. $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|;
  195. $column_header{employeenumber} = qq|<th><a class=listheading href=$href&sort=employeenumber>|.$locale->text('Number').qq|</a></th>|;
  196. $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
  197. $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|;
  198. $column_header{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</a></th>|;
  199. $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|;
  200. $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|;
  201. $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|;
  202. $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|;
  203. $column_header{workphone} = qq|<th><a class=listheading href=$href&sort=workphone>|.$locale->text('Work Phone').qq|</a></th>|;
  204. $column_header{homephone} = qq|<th><a class=listheading href=$href&sort=homephone>|.$locale->text('Home Phone').qq|</a></th>|;
  205. $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
  206. $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
  207. $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|;
  208. $column_header{role} = qq|<th><a class=listheading href=$href&sort=role>|.$locale->text('Role').qq|</a></th>|;
  209. $column_header{login} = qq|<th><a class=listheading href=$href&sort=login>|.$locale->text('Login').qq|</a></th>|;
  210. $column_header{sales} = qq|<th class=listheading>|.$locale->text('S').qq|</th>|;
  211. $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;
  212. $column_header{ssn} = qq|<th><a class=listheading href=$href&sort=ssn>|.$locale->text('SSN').qq|</a></th>|;
  213. $column_header{dob} = qq|<th><a class=listheading href=$href&sort=dob>|.$locale->text('DOB').qq|</a></th>|;
  214. $column_header{iban} = qq|<th><a class=listheading href=$href&sort=iban>|.$locale->text('IBAN').qq|</a></th>|;
  215. $column_header{bic} = qq|<th><a class=listheading href=$href&sort=bic>|.$locale->text('BIC').qq|</a></th>|;
  216. $form->{title} = $locale->text('Employees');
  217. $form->header;
  218. print qq|
  219. <body>
  220. <table width=100%>
  221. <tr>
  222. <th class=listtop>$form->{title}</th>
  223. </tr>
  224. <tr height="5"></tr>
  225. <tr>
  226. <td>$option</td>
  227. </tr>
  228. <tr>
  229. <td>
  230. <table width=100%>
  231. <tr class=listheading>
  232. |;
  233. for (@column_index) { print "$column_header{$_}\n" }
  234. print qq|
  235. </tr>
  236. |;
  237. $i = 0;
  238. foreach $ref (@{ $form->{all_employee} }) {
  239. $i++;
  240. $ref->{notes} =~ s/\r?\n/<br>/g;
  241. for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  242. $column_data{ndx} = "<td align=right>$i</td>";
  243. $column_data{sales} = ($ref->{sales}) ? "<td>x</td>" : "<td>&nbsp;</td>";
  244. $column_data{role} = qq|<td>$role{"$ref->{role}"}&nbsp;</td>|;
  245. $column_date{address} = qq|$ref->{address1} $ref->{address2}|;
  246. $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>";
  247. if ($ref->{email}) {
  248. $email = $ref->{email};
  249. $email =~ s/</\&lt;/;
  250. $email =~ s/>/\&gt;/;
  251. $column_data{email} = qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
  252. }
  253. $j++; $j %= 2;
  254. print "
  255. <tr class=listrow$j>
  256. ";
  257. for (@column_index) { print "$column_data{$_}\n" }
  258. print qq|
  259. </tr>
  260. |;
  261. }
  262. $i = 1;
  263. $button{'HR--Employees--Add Employee'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Employee').qq|"> |;
  264. $button{'HR--Employees--Add Employee'}{order} = $i++;
  265. foreach $item (split /;/, $myconfig{acs}) {
  266. delete $button{$item};
  267. }
  268. print qq|
  269. </table>
  270. </td>
  271. </tr>
  272. <tr>
  273. <td><hr size=3 noshade></td>
  274. </tr>
  275. </table>
  276. <br>
  277. <form method=post action=$form->{script}>
  278. |;
  279. $form->hide_form(qw(callback db path login sessionid));
  280. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  281. print $item->{code};
  282. }
  283. if ($form->{menubar}) {
  284. require "$form->{path}/menu.pl";
  285. &menubar;
  286. }
  287. print qq|
  288. </form>
  289. </body>
  290. </html>
  291. |;
  292. }
  293. sub edit {
  294. # $locale->text('Edit Employee')
  295. # $locale->text('Edit Deduction')
  296. $label = ucfirst $form->{db};
  297. $form->{title} = "Edit $label";
  298. &{ "$form->{db}_links" };
  299. }
  300. sub employee_links {
  301. #$form->{deductions} = 1;
  302. HR->get_employee(\%myconfig, \%$form);
  303. for (keys %$form) { $form->{$_} = $form->quote($form->{$_}) }
  304. if (@{ $form->{all_deduction} }) {
  305. $form->{selectdeduction} = "<option>\n";
  306. for (@{ $form->{all_deduction} }) { $form->{selectdeduction} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  307. }
  308. $form->{manager} = "$form->{manager}--$form->{managerid}";
  309. if (@{ $form->{all_manager} }) {
  310. $form->{selectmanager} = "<option>\n";
  311. for (@{ $form->{all_manager} }) { $form->{selectmanager} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  312. }
  313. %role = ( user => $locale->text('User'),
  314. supervisor => $locale->text('Supervisor'),
  315. manager => $locale->text('Manager'),
  316. admin => $locale->text('Administrator')
  317. );
  318. $form->{selectrole} = "<option>\n";
  319. for (qw(user supervisor manager admin)) { $form->{selectrole} .= "<option value=$_>$role{$_}\n" }
  320. $i = 1;
  321. foreach $ref (@{ $form->{all_employeededuction} }) {
  322. $form->{"deduction_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
  323. for (qw(before after rate)) { $form->{"${_}_$i"} = $ref->{$_} }
  324. $i++;
  325. }
  326. $form->{deduction_rows} = $i - 1;
  327. &employee_header;
  328. &employee_footer;
  329. }
  330. sub employee_header {
  331. $sales = qq|<input type=hidden name=sales value=$form->{sales}>|;
  332. $form->{sales} = ($form->{sales}) ? "checked" : "";
  333. $form->{selectrole} =~ s/ selected//;
  334. $form->{selectrole} =~ s/option value=\Q$form->{role}\E>/option value=$form->{role} selected>/;
  335. $form->{selectdeduction} = $form->unescape($form->{selectdeduction});
  336. $form->{selectmanager} = $form->unescape($form->{selectmanager});
  337. $form->{selectmanager} =~ s/ selected//;
  338. $form->{selectmanager} =~ s/(<option value="\Q$form->{manager}\E")/$1 selected/;
  339. $sales .= qq|
  340. <input type=hidden name=role value=$form->{role}>
  341. <input type=hidden name=manager value=$form->{manager}>
  342. |;
  343. if ($myconfig{role} ne 'user') {
  344. $sales = qq|
  345. <tr>
  346. <th align=right>|.$locale->text('Sales').qq|</th>
  347. <td><input name=sales class=checkbox type=checkbox value=1 $form->{sales}></td>
  348. </tr>
  349. <tr>
  350. <th align=right>|.$locale->text('Role').qq|</th>
  351. <td><select name=role>$form->{selectrole}</select></td>
  352. </tr>
  353. |;
  354. if ($form->{selectmanager}) {
  355. $sales .= qq|
  356. <tr>
  357. <th align=right>|.$locale->text('Manager').qq|</th>
  358. <td><select name=manager>$form->{selectmanager}</select></td>
  359. </tr>
  360. |;
  361. }
  362. }
  363. $form->{deduction_rows}++;
  364. for $i (1 .. $form->{deduction_rows}) {
  365. $form->{"selectdeduction_$i"} = $form->{selectdeduction};
  366. if ($form->{"deduction_$i"}) {
  367. $form->{"selectdeduction_$i"} =~ s/(<option value="\Q$form->{"deduction_$i"}\E")/$1 selected/;
  368. }
  369. }
  370. $form->{selectdeduction} = $form->escape($form->{selectdeduction},1);
  371. $form->{selectmanager} = $form->escape($form->{selectmanager},1);
  372. $form->header;
  373. print qq|
  374. <body>
  375. <form method=post action=$form->{script}>
  376. <input type=hidden name=selectdeduction value="$form->{selectdeduction}">
  377. <input type=hidden name=deduction_rows value=$form->{deduction_rows}>
  378. <input type=hidden name=selectmanager value="$form->{selectmanager}">
  379. <input type=hidden name=selectrole value="$form->{selectrole}">
  380. <input type=hidden name=status value=$form->{status}>
  381. <input type=hidden name=title value="$form->{title}">
  382. <table width=100%>
  383. <tr>
  384. <th class=listtop>$form->{title}</th>
  385. </tr>
  386. <tr height="5"></tr>
  387. <tr>
  388. <td>
  389. <table>
  390. <tr valign=top>
  391. <td>
  392. <table>
  393. <tr>
  394. <th align=right nowrap>|.$locale->text('Number').qq|</th>
  395. <td><input name=employeenumber size=32 maxlength=32 value="$form->{employeenumber}"></td>
  396. </tr>
  397. <tr>
  398. <th align=right nowrap>|.$locale->text('Name').qq|</th>
  399. <td><input name=name size=35 maxlength=64 value="$form->{name}"></td>
  400. </tr>
  401. <tr>
  402. <th align=right nowrap>|.$locale->text('Address').qq|</th>
  403. <td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td>
  404. </tr>
  405. <tr>
  406. <th></th>
  407. <td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td>
  408. </tr>
  409. <tr>
  410. <th align=right nowrap>|.$locale->text('City').qq|</th>
  411. <td><input name=city size=35 maxlength=32 value="$form->{city}"></td>
  412. </tr>
  413. <tr>
  414. <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
  415. <td><input name=state size=35 maxlength=32 value="$form->{state}"></td>
  416. </tr>
  417. <tr>
  418. <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
  419. <td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td>
  420. </tr>
  421. <tr>
  422. <th align=right nowrap>|.$locale->text('Country').qq|</th>
  423. <td><input name=country size=35 maxlength=32 value="$form->{country}"></td>
  424. </tr>
  425. <tr>
  426. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  427. <td><input name=email size=35 value="$form->{email}"></td>
  428. </tr>
  429. <tr>
  430. $sales
  431. </table>
  432. </td>
  433. <td>
  434. <table>
  435. <tr>
  436. <th align=right nowrap>|.$locale->text('Work Phone').qq|</th>
  437. <td><input name=workphone size=20 maxlength=20 value="$form->{workphone}"></td>
  438. </tr>
  439. <tr>
  440. <th align=right nowrap>|.$locale->text('Home Phone').qq|</th>
  441. <td><input name=homephone size=20 maxlength=20 value="$form->{homephone}"></td>
  442. </tr>
  443. <tr>
  444. <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
  445. <td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td>
  446. </tr>
  447. <tr>
  448. <th align=right nowrap>|.$locale->text('Enddate').qq|</th>
  449. <td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>
  450. </tr>
  451. <tr>
  452. <th align=right nowrap>|.$locale->text('SSN').qq|</th>
  453. <td><input name=ssn size=20 maxlength=20 value="$form->{ssn}"></td>
  454. </tr>
  455. <tr>
  456. <th align=right nowrap>|.$locale->text('DOB').qq|</th>
  457. <td><input name=dob size=11 title="$myconfig{dateformat}" value=$form->{dob}></td>
  458. </tr>
  459. <tr>
  460. <th align=right nowrap>|.$locale->text('IBAN').qq|</th>
  461. <td><input name=iban size=34 maxlength=34 value="$form->{iban}"></td>
  462. </tr>
  463. <tr>
  464. <th align=right nowrap>|.$locale->text('BIC').qq|</th>
  465. <td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td>
  466. </tr>
  467. </table>
  468. </td>
  469. </tr>
  470. </table>
  471. </td>
  472. </tr>
  473. <tr>
  474. <th align=left nowrap>|.$locale->text('Notes').qq|</th>
  475. </tr>
  476. <tr>
  477. <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
  478. </tr>
  479. |;
  480. if ($form->{selectdeduction}) {
  481. print qq|
  482. <tr>
  483. <td>
  484. <table width=100%>
  485. <tr class=listheading>
  486. <th class=listheading>|.$locale->text('Payroll Deduction').qq|</th>
  487. <th class=listheading colspan=3>|.$locale->text('Allowances').qq|</th>
  488. </tr>
  489. <tr class=listheading>
  490. <th></th>
  491. <th class=listheading>|.$locale->text('Before Deduction').qq|</th>
  492. <th class=listheading>|.$locale->text('After Deduction').qq|</th>
  493. <th class=listheading>|.$locale->text('Rate').qq|</th>
  494. </tr>
  495. |;
  496. for $i (1 .. $form->{deduction_rows}) {
  497. print qq|
  498. <tr>
  499. <td><select name="deduction_$i">$form->{"selectdeduction_$i"}</select></td>
  500. <td><input name="before_$i" value=|.$form->format_amount(\%myconfig, $form->{"before_$i"}, 2).qq|></td>
  501. <td><input name="after_$i" value=|.$form->format_amount(\%myconfig, $form->{"after_$i"}, 2).qq|></td>
  502. <td><input name="rate_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td>
  503. </tr>
  504. |;
  505. }
  506. }
  507. print qq|
  508. </table>
  509. </td>
  510. </tr>
  511. <tr>
  512. <td><hr size=3 noshade></td>
  513. </tr>
  514. </table>
  515. |;
  516. }
  517. sub employee_footer {
  518. print qq|
  519. <input name=id type=hidden value=$form->{id}>
  520. <input type=hidden name=db value=$form->{db}>
  521. <input type=hidden name=employeelogin value=$form->{employeelogin}>
  522. <input type=hidden name=path value=$form->{path}>
  523. <input type=hidden name=login value=$form->{login}>
  524. <input type=hidden name=sessionid value=$form->{sessionid}>
  525. <input type=hidden name=callback value="$form->{callback}">
  526. <br>
  527. <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
  528. <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">
  529. |;
  530. if ($form->{id}) {
  531. print qq|<input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">\n|;
  532. if ($form->{status} eq 'orphaned') {
  533. print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
  534. }
  535. }
  536. if ($form->{menubar}) {
  537. require "$form->{path}/menu.pl";
  538. &menubar;
  539. }
  540. print qq|
  541. </form>
  542. </body>
  543. </html>
  544. |;
  545. }
  546. sub save { &{ "save_$form->{db}" } };
  547. sub save_employee {
  548. $form->isblank("name", $locale->text("Name missing!"));
  549. HR->save_employee(\%myconfig, \%$form);
  550. # if it is a login change memberfile and .conf
  551. if ($form->{employeelogin}) {
  552. $user = new User $memberfile, $form->{employeelogin};
  553. for (qw(name email role)) { $user->{$_} = $form->{$_} }
  554. # assign $myconfig for db
  555. for (qw(dbconnect dbhost dbport dbpasswd)) { $user->{$_} = $myconfig{$_} }
  556. for (qw(dbpasswd password)) { $user->{"old_$_"} = $user->{$_} }
  557. $user->{packpw} = 1;
  558. $user->save_member($memberfile, $userspath) if $user->{login};
  559. }
  560. $form->redirect($locale->text('Employee saved!'));
  561. }
  562. sub delete { &{ "delete_$form->{db}" } };
  563. sub delete_employee {
  564. HR->delete_employee(\%myconfig, \%$form);
  565. $form->redirect($locale->text('Employee deleted!'));
  566. }
  567. sub continue { &{ $form->{nextsub} } };
  568. sub add_employee { &add };
  569. sub add_deduction { &add };
  570. sub search_deduction {
  571. HR->deductions(\%myconfig, \%$form);
  572. $href = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  573. $form->sort_order();
  574. $callback = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  575. @column_index = $form->sort_columns(qw(description rate amount above below employeepays employerpays ap_accno expense_accno));
  576. $form->{callback} = $callback;
  577. $callback = $form->escape($form->{callback});
  578. $column_header{description} = qq|<th class=listheading href=$href>|.$locale->text('Description').qq|</th>|;
  579. $column_header{rate} = qq|<th class=listheading nowrap>|.$locale->text('Rate').qq|<br>%</th>|;
  580. $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
  581. $column_header{above} = qq|<th class=listheading>|.$locale->text('Above').qq|</th>|;
  582. $column_header{below} = qq|<th class=listheading>|.$locale->text('Below').qq|</th>|;
  583. $column_header{employerpays} = qq|<th class=listheading>|.$locale->text('Employer').qq|</th>|;
  584. $column_header{employeepays} = qq|<th class=listheading>|.$locale->text('Employee').qq|</th>|;
  585. $column_header{ap_accno} = qq|<th class=listheading>|.$locale->text('AP').qq|</th>|;
  586. $column_header{expense_accno} = qq|<th class=listheading>|.$locale->text('Expense').qq|</th>|;
  587. $form->{title} = $locale->text('Deductions');
  588. $form->header;
  589. print qq|
  590. <body>
  591. <table width=100%>
  592. <tr>
  593. <th class=listtop>$form->{title}</th>
  594. </tr>
  595. <tr height="5"></tr>
  596. <tr>
  597. <td>$option</td>
  598. </tr>
  599. <tr>
  600. <td>
  601. <table width=100%>
  602. <tr class=listheading>
  603. |;
  604. for (@column_index) { print "$column_header{$_}\n" }
  605. print qq|
  606. </tr>
  607. |;
  608. foreach $ref (@{ $form->{all_deduction} }) {
  609. $rate = $form->format_amount(\%myconfig, $ref->{rate} * 100, "", "&nbsp;");
  610. $column_data{rate} = "<td align=right>$rate</td>";
  611. for (qw(amount below above)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;")."</td>" }
  612. for (qw(ap_accno expense_accno)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  613. for (qw(employerpays employeepays)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, "", "&nbsp;")."</td>" }
  614. if ($ref->{description} ne $sameitem) {
  615. $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>";
  616. } else {
  617. $column_data{description} = "<td>&nbsp;</td>";
  618. }
  619. $i++; $i %= 2;
  620. print "
  621. <tr class=listrow$i>
  622. ";
  623. for (@column_index) { print "$column_data{$_}\n" }
  624. print qq|
  625. </tr>
  626. |;
  627. $sameitem = $ref->{description};
  628. }
  629. $i = 1;
  630. $button{'HR--Deductions--Add Deduction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Deduction').qq|"> |;
  631. $button{'HR--Deductions--Add Deduction'}{order} = $i++;
  632. foreach $item (split /;/, $myconfig{acs}) {
  633. delete $button{$item};
  634. }
  635. print qq|
  636. </table>
  637. </td>
  638. </tr>
  639. <tr>
  640. <td><hr size=3 noshade></td>
  641. </tr>
  642. </table>
  643. <br>
  644. <form method=post action=$form->{script}>
  645. <input type=hidden name=db value=$form->{db}>
  646. <input name=callback type=hidden value="$form->{callback}">
  647. <input type=hidden name=path value=$form->{path}>
  648. <input type=hidden name=login value=$form->{login}>
  649. <input type=hidden name=sessionid value=$form->{sessionid}>
  650. |;
  651. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  652. print $item->{code};
  653. }
  654. if ($form->{menubar}) {
  655. require "$form->{path}/menu.pl";
  656. &menubar;
  657. }
  658. print qq|
  659. </form>
  660. </body>
  661. </html>
  662. |;
  663. }
  664. sub deduction_links {
  665. HR->get_deduction(\%myconfig, \%$form);
  666. $i = 1;
  667. foreach $ref (@{ $form->{deductionrate} }) {
  668. for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
  669. $i++;
  670. }
  671. $form->{rate_rows} = $i - 1;
  672. $i = 1;
  673. foreach $ref (@{ $form->{deductionbase} }) {
  674. $form->{"base_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
  675. $form->{"maximum_$i"} = $ref->{maximum};
  676. $i++;
  677. }
  678. $form->{base_rows} = $i - 1;
  679. $i = 1;
  680. foreach $ref (@{ $form->{deductionafter} }) {
  681. $form->{"after_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
  682. $i++;
  683. }
  684. $form->{after_rows} = $i - 1;
  685. $form->{employeepays} = 1;
  686. $selectaccount = "<option>\n";
  687. for (@{ $form->{ap_accounts} }) { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" }
  688. $form->{ap_accno} = qq|$form->{ap_accno}--$form->{ap_description}|;
  689. $form->{selectap} = $selectaccount;
  690. $selectaccount = "<option>\n";
  691. for (@{ $form->{expense_accounts} }) { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" }
  692. $form->{expense_accno} = qq|$form->{expense_accno}--$form->{expense_description}|;
  693. $form->{selectexpense} = $selectaccount;
  694. for (1 .. $form->{rate_rows}) { $form->{"rate_$_"} *= 100 }
  695. $form->{selectbase} = "<option>\n";
  696. for (@{ $form->{all_deduction} }) { $form->{selectbase} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  697. &deduction_header;
  698. &deduction_footer;
  699. }
  700. sub deduction_header {
  701. $selectap = $form->{selectap};
  702. $selectap =~ s/option>\Q$form->{ap_accno}\E/option selected>$form->{ap_accno}/;
  703. $selectexpense = $form->{selectexpense};
  704. $selectexpense =~ s/option>\Q$form->{expense_accno}\E/option selected>$form->{expense_accno}/;
  705. $form->{rate_rows}++;
  706. $form->{base_rows}++;
  707. $form->{after_rows}++;
  708. $form->{selectbase} = $form->unescape($form->{selectbase});
  709. for $i (1 .. $form->{base_rows}) {
  710. $form->{"selectbase_$i"} = $form->{selectbase};
  711. if ($form->{"base_$i"}) {
  712. $form->{"selectbase_$i"} =~ s/(<option value="\Q$form->{"base_$i"}\E")/$1 selected/;
  713. }
  714. }
  715. for $i (1 .. $form->{after_rows}) {
  716. $form->{"selectafter_$i"} = $form->{selectbase};
  717. if ($form->{"after_$i"}) {
  718. $form->{"selectafter_$i"} =~ s/(<option value="\Q$form->{"after_$i"}\E")/$1 selected/;
  719. }
  720. }
  721. $form->header;
  722. print qq|
  723. <body>
  724. <form method=post action=$form->{script}>
  725. <input type=hidden name=title value="$form->{title}">
  726. <input type=hidden name=selectap value="$form->{selectap}">
  727. <input type=hidden name=selectexpense value="$form->{selectexpense}">
  728. <input type=hidden name=selectbase value="|.$form->escape($form->{selectbase},1).qq|">
  729. <input type=hidden name=rate_rows value=$form->{rate_rows}>
  730. <input type=hidden name=base_rows value=$form->{base_rows}>
  731. <input type=hidden name=after_rows value=$form->{after_rows}>
  732. <table width=100%>
  733. <tr>
  734. <th class=listtop>$form->{title}</th>
  735. </tr>
  736. <tr height="5"></tr>
  737. <tr>
  738. <td>
  739. <table>
  740. <tr>
  741. <th align=right nowrap>|.$locale->text('Description').qq|</th>
  742. <td><input name=description size=35 value="$form->{description}"></td>
  743. </tr>
  744. <tr>
  745. <th align=right nowrap>|.$locale->text('AP').qq|</th>
  746. <td><select name=ap_accno>$selectap</select></td>
  747. <th align=right nowrap>|.$locale->text('Employee pays').qq| x</th>
  748. <td><input name=employeepays size=4 value=|.$form->format_amount(\%myconfig, $form->{employeepays}).qq|></td>
  749. </tr>
  750. <tr>
  751. <th align=right nowrap>|.$locale->text('Expense').qq|</th>
  752. <td><select name=expense_accno>$selectexpense</select></td>
  753. <th align=right nowrap>|.$locale->text('Employer pays').qq| x</th>
  754. <td><input name=employerpays size=4 value=|.$form->format_amount(\%myconfig, $form->{employerpays}).qq|></td>
  755. </tr>
  756. <tr>
  757. <td></td>
  758. <td></td>
  759. <th align=right nowrap>|.$locale->text('Exempt age <').qq|</th>
  760. <td><input name=fromage size=4 value=|.$form->format_amount(\%myconfig, $form->{fromage}).qq|></td>
  761. <th align=right nowrap>&gt;</th>
  762. <td><input name=toage size=4 value=|.$form->format_amount(\%myconfig, $form->{toage}).qq|>
  763. </tr>
  764. <tr>
  765. <td></td>
  766. <td>
  767. <table>
  768. <tr class=listheading>
  769. <th class=listheading>|.$locale->text('Rate').qq| %</th>
  770. <th class=listheading>|.$locale->text('Amount').qq|</th>
  771. <th class=listheading>|.$locale->text('Above').qq|</th>
  772. <th class=listheading>|.$locale->text('Below').qq|</th>
  773. </tr>
  774. |;
  775. for $i (1 .. $form->{rate_rows}) {
  776. print qq|
  777. <tr>
  778. <td><input name="rate_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td>
  779. <td><input name="amount_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"amount_$i"}, 2).qq|></td>
  780. <td><input name="above_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"above_$i"}, 2).qq|></td>
  781. <td><input name="below_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"below_$i"}, 2).qq|></td>
  782. </tr>
  783. |;
  784. }
  785. print qq|
  786. </table>
  787. </td>
  788. </tr>
  789. </table>
  790. </td>
  791. </tr>
  792. |;
  793. print qq|
  794. <tr>
  795. <td>
  796. <table>
  797. |;
  798. $basedon = $locale->text('Based on');
  799. $maximum = $locale->text('Maximum');
  800. for $i (1 .. $form->{base_rows}) {
  801. print qq|
  802. <tr>
  803. <th>$basedon</th>
  804. <td><select name="base_$i">$form->{"selectbase_$i"}</select></td>
  805. <th>$maximum</th>
  806. <td><input name="maximum_$i" value=|.$form->format_amount(\%myconfig, $form->{"maximum_$i"}, 2).qq|></td>
  807. </tr>
  808. |;
  809. $basedon = "";
  810. $maximum = "";
  811. }
  812. $deductafter = $locale->text('Deduct after');
  813. for $i (1 .. $form->{after_rows}) {
  814. print qq|
  815. <tr>
  816. <th>$deductafter</th>
  817. <td><select name="after_$i">$form->{"selectafter_$i"}</select></td>
  818. </tr>
  819. |;
  820. $deductafter = "";
  821. }
  822. print qq|
  823. </table>
  824. </td>
  825. </tr>
  826. <tr>
  827. <td><hr size=3 noshade></td>
  828. </tr>
  829. </table>
  830. |;
  831. }
  832. sub deduction_footer {
  833. print qq|
  834. <input name=id type=hidden value=$form->{id}>
  835. <input type=hidden name=db value=$form->{db}>
  836. <input type=hidden name=path value=$form->{path}>
  837. <input type=hidden name=login value=$form->{login}>
  838. <input type=hidden name=sessionid value=$form->{sessionid}>
  839. <input type=hidden name=callback value="$form->{callback}">
  840. <br>
  841. <input class=submit type=submit name=action value="|.$locale->text("Update").qq|">
  842. <input class=submit type=submit name=action value="|.$locale->text("Save").qq|">
  843. |;
  844. if ($form->{id}) {
  845. print qq|<input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">\n|;
  846. if ($form->{status} eq 'orphaned') {
  847. print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
  848. }
  849. }
  850. if ($form->{menubar}) {
  851. require "$form->{path}/menu.pl";
  852. &menubar;
  853. }
  854. print qq|
  855. </form>
  856. </body>
  857. </html>
  858. |;
  859. }
  860. sub update { &{ "update_$form->{db}" }; }
  861. sub save { &{ "save_$form->{db}" } };
  862. sub update_deduction {
  863. # if rate or amount is blank remove row
  864. @flds = qw(rate amount above below);
  865. $count = 0;
  866. @a = ();
  867. for $i (1 .. $form->{rate_rows}) {
  868. for (@flds) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  869. if ($form->{"rate_$i"} || $form->{"amount_$i"}) {
  870. push @a, {};
  871. $j = $#a;
  872. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  873. $count++;
  874. }
  875. }
  876. $form->redo_rows(\@flds, \@a, $count, $form->{rate_rows});
  877. $form->{rate_rows} = $count;
  878. @flds = qw(base maximum);
  879. $count = 0;
  880. @a = ();
  881. for $i (1 .. $form->{"base_rows"}) {
  882. $form->{"maximum_$i"} = $form->parse_amount(\%myconfig, $form->{"maximum_$i"});
  883. if ($form->{"base_$i"}) {
  884. push @a, {};
  885. $j = $#a;
  886. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  887. $count++;
  888. }
  889. }
  890. $form->redo_rows(\@flds, \@a, $count, $form->{"base_rows"});
  891. $form->{"base_rows"} = $count;
  892. @flds = qw(after);
  893. $count = 0;
  894. @a = ();
  895. for $i (1 .. $form->{"after_rows"}) {
  896. if ($form->{"after_$i"}) {
  897. push @a, {};
  898. $j = $#a;
  899. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  900. $count++;
  901. }
  902. }
  903. $form->redo_rows(\@flds, \@a, $count, $form->{"after_rows"});
  904. $form->{"after_rows"} = $count;
  905. &deduction_header;
  906. &deduction_footer;
  907. }
  908. sub update_employee {
  909. # if rate or amount is blank remove row
  910. @flds = qw(before after);
  911. $count = 0;
  912. @a = ();
  913. for $i (1 .. $form->{deduction_rows}) {
  914. for (@flds) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  915. if ($form->{"deduction_$i"}) {
  916. push @a, {};
  917. $j = $#a;
  918. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  919. $count++;
  920. }
  921. }
  922. $form->redo_rows(\@flds, \@a, $count, $form->{deduction_rows});
  923. $form->{deduction_rows} = $count;
  924. &employee_header;
  925. &employee_footer;
  926. }
  927. sub save_as_new {
  928. $form->{id} = 0;
  929. delete $form->{employeelogin};
  930. &save;
  931. }
  932. sub save_deduction {
  933. $form->isblank("description", $locale->text("Description missing!"));
  934. unless ($form->{"rate_1"} || $form->{"amount_1"}) {
  935. $form->isblank("rate_1", $locale->text("Rate missing!")) unless $form->{"amount_1"};
  936. $form->isblank("amount_1", $locale->text("Amount missing!"));
  937. }
  938. HR->save_deduction(\%myconfig, \%$form);
  939. $form->redirect($locale->text('Deduction saved!'));
  940. }
  941. sub delete_deduction {
  942. HR->delete_deduction(\%myconfig, \%$form);
  943. $form->redirect($locale->text('Deduction deleted!'));
  944. }