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