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