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