summaryrefslogtreecommitdiff
path: root/bin/hr.pl
blob: bf69aac7a05f0862dc725e259f928ff8bfb57aa6 (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 class="date" name=startdatefrom size=11 title="$myconfig{dateformat}"> |
  135. . $locale->text('To')
  136. . qq| <input class="date" 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. if ( @{ $form->{all_deduction} } ) {
  452. $form->{selectdeduction} = "<option>\n";
  453. for ( @{ $form->{all_deduction} } ) {
  454. $form->{selectdeduction} .=
  455. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  456. }
  457. }
  458. $form->{manager} = "$form->{manager}--$form->{managerid}";
  459. if ( @{ $form->{all_manager} } ) {
  460. $form->{selectmanager} = "<option>\n";
  461. for ( @{ $form->{all_manager} } ) {
  462. $form->{selectmanager} .=
  463. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  464. }
  465. }
  466. %role = (
  467. user => $locale->text('User'),
  468. supervisor => $locale->text('Supervisor'),
  469. manager => $locale->text('Manager'),
  470. admin => $locale->text('Administrator')
  471. );
  472. $form->{selectrole} = "<option>\n";
  473. for (qw(user supervisor manager admin)) {
  474. $form->{selectrole} .= "<option value=$_>$role{$_}\n";
  475. }
  476. $i = 1;
  477. foreach $ref ( @{ $form->{all_employeededuction} } ) {
  478. $form->{"deduction_$i"} = "$ref->{description}--$ref->{id}"
  479. if $ref->{id};
  480. for (qw(before after rate)) { $form->{"${_}_$i"} = $ref->{$_} }
  481. $i++;
  482. }
  483. $form->{deduction_rows} = $i - 1;
  484. &employee_header;
  485. &employee_footer;
  486. }
  487. sub employee_header {
  488. $sales = qq|<input type=hidden name=sales value=$form->{sales}>|;
  489. $form->{sales} = ( $form->{sales} ) ? "checked" : "";
  490. $form->{selectrole} =~ s/ selected//;
  491. $form->{selectrole} =~
  492. s/option value=\Q$form->{role}\E>/option value=$form->{role} selected>/;
  493. $form->{selectdeduction} = $form->unescape( $form->{selectdeduction} );
  494. $form->{selectmanager} = $form->unescape( $form->{selectmanager} );
  495. $form->{selectmanager} =~ s/ selected//;
  496. $form->{selectmanager} =~
  497. s/(<option value="\Q$form->{manager}\E")/$1 selected/;
  498. $sales .= qq|
  499. <input type=hidden name=role value=$form->{role}>
  500. <input type=hidden name=manager value=$form->{manager}>
  501. |;
  502. if ( $myconfig{role} ne 'user' ) {
  503. $sales = qq|
  504. <tr>
  505. <th align=right>| . $locale->text('Sales') . qq|</th>
  506. <td><input name=sales class=checkbox type=checkbox value=1 $form->{sales}></td>
  507. </tr>
  508. <tr>
  509. <th align=right>| . $locale->text('Role') . qq|</th>
  510. <td><select name=role>$form->{selectrole}</select></td>
  511. </tr>
  512. |;
  513. if ( $form->{selectmanager} ) {
  514. $sales .= qq|
  515. <tr>
  516. <th align=right>| . $locale->text('Manager') . qq|</th>
  517. <td><select name=manager>$form->{selectmanager}</select></td>
  518. </tr>
  519. |;
  520. }
  521. }
  522. $form->{deduction_rows}++;
  523. for $i ( 1 .. $form->{deduction_rows} ) {
  524. $form->{"selectdeduction_$i"} = $form->{selectdeduction};
  525. if ( $form->{"deduction_$i"} ) {
  526. $form->{"selectdeduction_$i"} =~
  527. s/(<option value="\Q$form->{"deduction_$i"}\E")/$1 selected/;
  528. }
  529. }
  530. $form->{selectdeduction} = $form->escape( $form->{selectdeduction}, 1 );
  531. $form->{selectmanager} = $form->escape( $form->{selectmanager}, 1 );
  532. $form->header;
  533. print qq|
  534. <body>
  535. <form method=post action=$form->{script}>
  536. <input type=hidden name=selectdeduction value="$form->{selectdeduction}">
  537. <input type=hidden name=deduction_rows value=$form->{deduction_rows}>
  538. <input type=hidden name=selectmanager value="$form->{selectmanager}">
  539. <input type=hidden name=selectrole value="$form->{selectrole}">
  540. <input type=hidden name=status value=$form->{status}>
  541. <input type=hidden name=title value="$form->{title}">
  542. <table width=100%>
  543. <tr>
  544. <th class=listtop>$form->{title}</th>
  545. </tr>
  546. <tr height="5"></tr>
  547. <tr>
  548. <td>
  549. <table>
  550. <tr valign=top>
  551. <td>
  552. <table>
  553. <tr>
  554. <th align=right nowrap>| . $locale->text('Number') . qq|</th>
  555. <td><input name=employeenumber size=32 maxlength=32 value="$form->{employeenumber}"></td>
  556. </tr>
  557. <tr>
  558. <th align=right nowrap>| . $locale->text('Name') . qq|</th>
  559. <td><input name=name size=35 maxlength=64 value="$form->{name}"></td>
  560. </tr>
  561. <tr>
  562. <th align=right nowrap>| . $locale->text('Address') . qq|</th>
  563. <td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td>
  564. </tr>
  565. <tr>
  566. <th></th>
  567. <td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td>
  568. </tr>
  569. <tr>
  570. <th align=right nowrap>| . $locale->text('City') . qq|</th>
  571. <td><input name=city size=35 maxlength=32 value="$form->{city}"></td>
  572. </tr>
  573. <tr>
  574. <th align=right nowrap>| . $locale->text('State/Province') . qq|</th>
  575. <td><input name=state size=35 maxlength=32 value="$form->{state}"></td>
  576. </tr>
  577. <tr>
  578. <th align=right nowrap>| . $locale->text('Zip/Postal Code') . qq|</th>
  579. <td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td>
  580. </tr>
  581. <tr>
  582. <th align=right nowrap>| . $locale->text('Country') . qq|</th>
  583. <td><input name=country size=35 maxlength=32 value="$form->{country}"></td>
  584. </tr>
  585. <tr>
  586. <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
  587. <td><input name=email size=35 value="$form->{email}"></td>
  588. </tr>
  589. <tr>
  590. $sales
  591. </table>
  592. </td>
  593. <td>
  594. <table>
  595. <tr>
  596. <th align=right nowrap>| . $locale->text('Work Phone') . qq|</th>
  597. <td><input name=workphone size=20 maxlength=20 value="$form->{workphone}"></td>
  598. </tr>
  599. <tr>
  600. <th align=right nowrap>| . $locale->text('Home Phone') . qq|</th>
  601. <td><input name=homephone size=20 maxlength=20 value="$form->{homephone}"></td>
  602. </tr>
  603. <tr>
  604. <th align=right nowrap>| . $locale->text('Startdate') . qq|</th>
  605. <td><input class="date" name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td>
  606. </tr>
  607. <tr>
  608. <th align=right nowrap>| . $locale->text('Enddate') . qq|</th>
  609. <td><input class="date" name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>
  610. </tr>
  611. <tr>
  612. <th align=right nowrap>| . $locale->text('SSN') . qq|</th>
  613. <td><input name=ssn size=20 maxlength=20 value="$form->{ssn}"></td>
  614. </tr>
  615. <tr>
  616. <th align=right nowrap>| . $locale->text('DOB') . qq|</th>
  617. <td><input name=dob size=11 title="$myconfig{dateformat}" value=$form->{dob}></td>
  618. </tr>
  619. <tr>
  620. <th align=right nowrap>| . $locale->text('IBAN') . qq|</th>
  621. <td><input name=iban size=34 maxlength=34 value="$form->{iban}"></td>
  622. </tr>
  623. <tr>
  624. <th align=right nowrap>| . $locale->text('BIC') . qq|</th>
  625. <td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td>
  626. </tr>
  627. </table>
  628. </td>
  629. </tr>
  630. </table>
  631. </td>
  632. </tr>
  633. <tr>
  634. <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
  635. </tr>
  636. <tr>
  637. <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
  638. </tr>
  639. |;
  640. if ( $form->{selectdeduction} ) {
  641. print qq|
  642. <tr>
  643. <td>
  644. <table width=100%>
  645. <tr class=listheading>
  646. <th class=listheading>| . $locale->text('Payroll Deduction') . qq|</th>
  647. <th class=listheading colspan=3>| . $locale->text('Allowances') . qq|</th>
  648. </tr>
  649. <tr class=listheading>
  650. <th></th>
  651. <th class=listheading>| . $locale->text('Before Deduction') . qq|</th>
  652. <th class=listheading>| . $locale->text('After Deduction') . qq|</th>
  653. <th class=listheading>| . $locale->text('Rate') . qq|</th>
  654. </tr>
  655. |;
  656. for $i ( 1 .. $form->{deduction_rows} ) {
  657. print qq|
  658. <tr>
  659. <td><select name="deduction_$i">$form->{"selectdeduction_$i"}</select></td>
  660. <td><input name="before_$i" value=|
  661. . $form->format_amount( \%myconfig, $form->{"before_$i"}, 2 )
  662. . qq|></td>
  663. <td><input name="after_$i" value=|
  664. . $form->format_amount( \%myconfig, $form->{"after_$i"}, 2 )
  665. . qq|></td>
  666. <td><input name="rate_$i" size=5 value=|
  667. . $form->format_amount( \%myconfig, $form->{"rate_$i"} )
  668. . qq|></td>
  669. </tr>
  670. |;
  671. }
  672. }
  673. print qq|
  674. </table>
  675. </td>
  676. </tr>
  677. <tr>
  678. <td><hr size=3 noshade></td>
  679. </tr>
  680. </table>
  681. |;
  682. }
  683. sub employee_footer {
  684. print qq|
  685. <input name=id type=hidden value=$form->{id}>
  686. <input type=hidden name=db value=$form->{db}>
  687. <input type=hidden name=employeelogin value=$form->{employeelogin}>
  688. <input type=hidden name=path value=$form->{path}>
  689. <input type=hidden name=login value=$form->{login}>
  690. <input type=hidden name=sessionid value=$form->{sessionid}>
  691. <input type=hidden name=callback value="$form->{callback}">
  692. <br>
  693. <button class="submit" type="submit" name="action" value="update">|
  694. . $locale->text('Update')
  695. . qq|</button>
  696. <button class="submit" type="submit" name="action" value="save">|
  697. . $locale->text('Save')
  698. . qq|</button>
  699. |;
  700. if ( $form->{id} ) {
  701. print
  702. qq|<button class="submit" type="submit" name="action" value="save_as_new">|
  703. . $locale->text('Save as new')
  704. . qq|</button>\n|;
  705. if ( $form->{status} eq 'orphaned' ) {
  706. print
  707. qq|<button class="submit" type="submit" name="action" value="delete">|
  708. . $locale->text('Delete')
  709. . qq|</button>\n|;
  710. }
  711. }
  712. if ( $form->{lynx} ) {
  713. require "bin/menu.pl";
  714. &menubar;
  715. }
  716. print qq|
  717. </form>
  718. </body>
  719. </html>
  720. |;
  721. }
  722. sub save { &{"save_$form->{db}"} }
  723. sub save_employee {
  724. $form->isblank( "name", $locale->text("Name missing!") );
  725. HR->save_employee( \%myconfig, \%$form );
  726. # if it is a login change memberfile and .conf
  727. if ( $form->{employeelogin} ) {
  728. $user = LedgerSMB::User->new( $form->{employeelogin} );
  729. for (qw(name email role)) { $user->{$_} = $form->{$_} }
  730. # assign $myconfig for db
  731. for (qw(dbconnect dbhost dbport dbpasswd)) {
  732. $user->{$_} = $myconfig{$_};
  733. }
  734. for (qw(dbpasswd password)) { $user->{"old_$_"} = $user->{$_} }
  735. $user->{packpw} = 1;
  736. $user->save_member() if $user->{login};
  737. }
  738. $form->redirect( $locale->text('Employee saved!') );
  739. }
  740. sub delete { &{"delete_$form->{db}"} }
  741. sub delete_employee {
  742. HR->delete_employee( \%myconfig, \%$form );
  743. $form->redirect( $locale->text('Employee deleted!') );
  744. }
  745. sub continue { &{ $form->{nextsub} } }
  746. sub add_employee { &add }
  747. sub add_deduction { &add }
  748. sub search_deduction {
  749. HR->deductions( \%myconfig, \%$form );
  750. $href =
  751. "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  752. $form->sort_order();
  753. $callback =
  754. "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  755. @column_index =
  756. $form->sort_columns(
  757. qw(description rate amount above below employeepays employerpays ap_accno expense_accno)
  758. );
  759. $form->{callback} = $callback;
  760. $callback = $form->escape( $form->{callback} );
  761. $column_header{description} =
  762. qq|<th class=listheading href=$href>|
  763. . $locale->text('Description')
  764. . qq|</th>|;
  765. $column_header{rate} =
  766. qq|<th class=listheading nowrap>|
  767. . $locale->text('Rate')
  768. . qq|<br>%</th>|;
  769. $column_header{amount} =
  770. qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
  771. $column_header{above} =
  772. qq|<th class=listheading>| . $locale->text('Above') . qq|</th>|;
  773. $column_header{below} =
  774. qq|<th class=listheading>| . $locale->text('Below') . qq|</th>|;
  775. $column_header{employerpays} =
  776. qq|<th class=listheading>| . $locale->text('Employer') . qq|</th>|;
  777. $column_header{employeepays} =
  778. qq|<th class=listheading>| . $locale->text('Employee') . qq|</th>|;
  779. $column_header{ap_accno} =
  780. qq|<th class=listheading>| . $locale->text('AP') . qq|</th>|;
  781. $column_header{expense_accno} =
  782. qq|<th class=listheading>| . $locale->text('Expense') . qq|</th>|;
  783. $form->{title} = $locale->text('Deductions');
  784. $form->header;
  785. print qq|
  786. <body>
  787. <table width=100%>
  788. <tr>
  789. <th class=listtop>$form->{title}</th>
  790. </tr>
  791. <tr height="5"></tr>
  792. <tr>
  793. <td>$option</td>
  794. </tr>
  795. <tr>
  796. <td>
  797. <table width=100%>
  798. <tr class=listheading>
  799. |;
  800. for (@column_index) { print "$column_header{$_}\n" }
  801. print qq|
  802. </tr>
  803. |;
  804. foreach $ref ( @{ $form->{all_deduction} } ) {
  805. $rate =
  806. $form->format_amount( \%myconfig, $ref->{rate} * 100, "", "&nbsp;" );
  807. $column_data{rate} = "<td align=right>$rate</td>";
  808. for (qw(amount below above)) {
  809. $column_data{$_} =
  810. "<td align=right>"
  811. . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
  812. . "</td>";
  813. }
  814. for (qw(ap_accno expense_accno)) {
  815. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  816. }
  817. for (qw(employerpays employeepays)) {
  818. $column_data{$_} =
  819. "<td align=right>"
  820. . $form->format_amount( \%myconfig, $ref->{$_}, "", "&nbsp;" )
  821. . "</td>";
  822. }
  823. if ( $ref->{description} ne $sameitem ) {
  824. $column_data{description} =
  825. "<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>";
  826. }
  827. else {
  828. $column_data{description} = "<td>&nbsp;</td>";
  829. }
  830. $i++;
  831. $i %= 2;
  832. print "
  833. <tr class=listrow$i>
  834. ";
  835. for (@column_index) { print "$column_data{$_}\n" }
  836. print qq|
  837. </tr>
  838. |;
  839. $sameitem = $ref->{description};
  840. }
  841. $i = 1;
  842. $button{'HR--Deductions--Add Deduction'}{code} =
  843. qq|<button class="submit" type="submit" name="action" value="add_deduction">|
  844. . $locale->text('Add Deduction')
  845. . qq|</button> |;
  846. $button{'HR--Deductions--Add Deduction'}{order} = $i++;
  847. foreach $item ( split /;/, $myconfig{acs} ) {
  848. delete $button{$item};
  849. }
  850. print qq|
  851. </table>
  852. </td>
  853. </tr>
  854. <tr>
  855. <td><hr size=3 noshade></td>
  856. </tr>
  857. </table>
  858. <br>
  859. <form method=post action=$form->{script}>
  860. <input type=hidden name=db value=$form->{db}>
  861. <input name=callback type=hidden value="$form->{callback}">
  862. <input type=hidden name=path value=$form->{path}>
  863. <input type=hidden name=login value=$form->{login}>
  864. <input type=hidden name=sessionid value=$form->{sessionid}>
  865. |;
  866. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  867. print $item->{code};
  868. }
  869. if ( $form->{lynx} ) {
  870. require "bin/menu.pl";
  871. &menubar;
  872. }
  873. print qq|
  874. </form>
  875. </body>
  876. </html>
  877. |;
  878. }
  879. sub deduction_links {
  880. HR->get_deduction( \%myconfig, \%$form );
  881. $i = 1;
  882. foreach $ref ( @{ $form->{deductionrate} } ) {
  883. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  884. $i++;
  885. }
  886. $form->{rate_rows} = $i - 1;
  887. $i = 1;
  888. foreach $ref ( @{ $form->{deductionbase} } ) {
  889. $form->{"base_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
  890. $form->{"maximum_$i"} = $ref->{maximum};
  891. $i++;
  892. }
  893. $form->{base_rows} = $i - 1;
  894. $i = 1;
  895. foreach $ref ( @{ $form->{deductionafter} } ) {
  896. $form->{"after_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
  897. $i++;
  898. }
  899. $form->{after_rows} = $i - 1;
  900. $form->{employeepays} = 1;
  901. $selectaccount = "<option>\n";
  902. for ( @{ $form->{ap_accounts} } ) {
  903. $selectaccount .= "<option>$_->{accno}--$_->{description}\n";
  904. }
  905. $form->{ap_accno} = qq|$form->{ap_accno}--$form->{ap_description}|;
  906. $form->{selectap} = $selectaccount;
  907. $selectaccount = "<option>\n";
  908. for ( @{ $form->{expense_accounts} } ) {
  909. $selectaccount .= "<option>$_->{accno}--$_->{description}\n";
  910. }
  911. $form->{expense_accno} =
  912. qq|$form->{expense_accno}--$form->{expense_description}|;
  913. $form->{selectexpense} = $selectaccount;
  914. for ( 1 .. $form->{rate_rows} ) { $form->{"rate_$_"} *= 100 }
  915. $form->{selectbase} = "<option>\n";
  916. for ( @{ $form->{all_deduction} } ) {
  917. $form->{selectbase} .=
  918. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  919. }
  920. &deduction_header;
  921. &deduction_footer;
  922. }
  923. sub deduction_header {
  924. $selectap = $form->{selectap};
  925. $selectap =~
  926. s/option>\Q$form->{ap_accno}\E/option selected>$form->{ap_accno}/;
  927. $selectexpense = $form->{selectexpense};
  928. $selectexpense =~
  929. s/option>\Q$form->{expense_accno}\E/option selected>$form->{expense_accno}/;
  930. $form->{rate_rows}++;
  931. $form->{base_rows}++;
  932. $form->{after_rows}++;
  933. $form->{selectbase} = $form->unescape( $form->{selectbase} );
  934. for $i ( 1 .. $form->{base_rows} ) {
  935. $form->{"selectbase_$i"} = $form->{selectbase};
  936. if ( $form->{"base_$i"} ) {
  937. $form->{"selectbase_$i"} =~
  938. s/(<option value="\Q$form->{"base_$i"}\E")/$1 selected/;
  939. }
  940. }
  941. for $i ( 1 .. $form->{after_rows} ) {
  942. $form->{"selectafter_$i"} = $form->{selectbase};
  943. if ( $form->{"after_$i"} ) {
  944. $form->{"selectafter_$i"} =~
  945. s/(<option value="\Q$form->{"after_$i"}\E")/$1 selected/;
  946. }
  947. }
  948. $form->header;
  949. print qq|
  950. <body>
  951. <form method=post action=$form->{script}>
  952. <input type=hidden name=title value="$form->{title}">
  953. <input type=hidden name=selectap value="$form->{selectap}">
  954. <input type=hidden name=selectexpense value="$form->{selectexpense}">
  955. <input type=hidden name=selectbase value="|
  956. . $form->escape( $form->{selectbase}, 1 ) . qq|">
  957. <input type=hidden name=rate_rows value=$form->{rate_rows}>
  958. <input type=hidden name=base_rows value=$form->{base_rows}>
  959. <input type=hidden name=after_rows value=$form->{after_rows}>
  960. <table width=100%>
  961. <tr>
  962. <th class=listtop>$form->{title}</th>
  963. </tr>
  964. <tr height="5"></tr>
  965. <tr>
  966. <td>
  967. <table>
  968. <tr>
  969. <th align=right nowrap>| . $locale->text('Description') . qq|</th>
  970. <td><input name=description size=35 value="$form->{description}"></td>
  971. </tr>
  972. <tr>
  973. <th align=right nowrap>| . $locale->text('AP') . qq|</th>
  974. <td><select name=ap_accno>$selectap</select></td>
  975. <th align=right nowrap>| . $locale->text('Employee pays') . qq| x</th>
  976. <td><input name=employeepays size=4 value=|
  977. . $form->format_amount( \%myconfig, $form->{employeepays} )
  978. . qq|></td>
  979. </tr>
  980. <tr>
  981. <th align=right nowrap>| . $locale->text('Expense') . qq|</th>
  982. <td><select name=expense_accno>$selectexpense</select></td>
  983. <th align=right nowrap>| . $locale->text('Employer pays') . qq| x</th>
  984. <td><input name=employerpays size=4 value=|
  985. . $form->format_amount( \%myconfig, $form->{employerpays} )
  986. . qq|></td>
  987. </tr>
  988. <tr>
  989. <td></td>
  990. <td></td>
  991. <th align=right nowrap>| . $locale->text('Exempt age <') . qq|</th>
  992. <td><input name=fromage size=4 value=|
  993. . $form->format_amount( \%myconfig, $form->{fromage} )
  994. . qq|></td>
  995. <th align=right nowrap>&gt;</th>
  996. <td><input name=toage size=4 value=|
  997. . $form->format_amount( \%myconfig, $form->{toage} ) . qq|>
  998. </tr>
  999. <tr>
  1000. <td></td>
  1001. <td>
  1002. <table>
  1003. <tr class=listheading>
  1004. <th class=listheading>| . $locale->text('Rate') . qq| %</th>
  1005. <th class=listheading>| . $locale->text('Amount') . qq|</th>
  1006. <th class=listheading>| . $locale->text('Above') . qq|</th>
  1007. <th class=listheading>| . $locale->text('Below') . qq|</th>
  1008. </tr>
  1009. |;
  1010. for $i ( 1 .. $form->{rate_rows} ) {
  1011. print qq|
  1012. <tr>
  1013. <td><input name="rate_$i" size=10 value=|
  1014. . $form->format_amount( \%myconfig, $form->{"rate_$i"} )
  1015. . qq|></td>
  1016. <td><input name="amount_$i" size=10 value=|
  1017. . $form->format_amount( \%myconfig, $form->{"amount_$i"}, 2 )
  1018. . qq|></td>
  1019. <td><input name="above_$i" size=10 value=|
  1020. . $form->format_amount( \%myconfig, $form->{"above_$i"}, 2 )
  1021. . qq|></td>
  1022. <td><input name="below_$i" size=10 value=|
  1023. . $form->format_amount( \%myconfig, $form->{"below_$i"}, 2 )
  1024. . qq|></td>
  1025. </tr>
  1026. |;
  1027. }
  1028. print qq|
  1029. </table>
  1030. </td>
  1031. </tr>
  1032. </table>
  1033. </td>
  1034. </tr>
  1035. |;
  1036. print qq|
  1037. <tr>
  1038. <td>
  1039. <table>
  1040. |;
  1041. $basedon = $locale->text('Based on');
  1042. $maximum = $locale->text('Maximum');
  1043. for $i ( 1 .. $form->{base_rows} ) {
  1044. print qq|
  1045. <tr>
  1046. <th>$basedon</th>
  1047. <td><select name="base_$i">$form->{"selectbase_$i"}</select></td>
  1048. <th>$maximum</th>
  1049. <td><input name="maximum_$i" value=|
  1050. . $form->format_amount( \%myconfig, $form->{"maximum_$i"}, 2 )
  1051. . qq|></td>
  1052. </tr>
  1053. |;
  1054. $basedon = "";
  1055. $maximum = "";
  1056. }
  1057. $deductafter = $locale->text('Deduct after');
  1058. for $i ( 1 .. $form->{after_rows} ) {
  1059. print qq|
  1060. <tr>
  1061. <th>$deductafter</th>
  1062. <td><select name="after_$i">$form->{"selectafter_$i"}</select></td>
  1063. </tr>
  1064. |;
  1065. $deductafter = "";
  1066. }
  1067. print qq|
  1068. </table>
  1069. </td>
  1070. </tr>
  1071. <tr>
  1072. <td><hr size=3 noshade></td>
  1073. </tr>
  1074. </table>
  1075. |;
  1076. }
  1077. sub deduction_footer {
  1078. print qq|
  1079. <input name="id" type="hidden" value="$form->{id}">
  1080. <input type="hidden" name="db" value="$form->{db}">
  1081. <input type="hidden" name="path" value="$form->{path}">
  1082. <input type="hidden" name="login" value="$form->{login}">
  1083. <input type="hidden" name="sessionid" value="$form->{sessionid}">
  1084. <input type="hidden" name="callback" value="$form->{callback}">
  1085. <br>
  1086. <button class="submit" type="submit" name="action" value="update">|
  1087. . $locale->text("Update")
  1088. . qq|</button>
  1089. <button class="submit" type="submit" name="action" value="save">|
  1090. . $locale->text("Save")
  1091. . qq|</button>
  1092. |;
  1093. if ( $form->{id} ) {
  1094. print
  1095. qq|<button class="submit" type="submit" name="action" value="save_as_new">|
  1096. . $locale->text('Save as new')
  1097. . qq|</button>\n|;
  1098. if ( $form->{status} eq 'orphaned' ) {
  1099. print
  1100. qq|<button class="submit" type="submit" name="action" value="delete">|
  1101. . $locale->text('Delete')
  1102. . qq|</button>\n|;
  1103. }
  1104. }
  1105. if ( $form->{lynx} ) {
  1106. require "bin/menu.pl";
  1107. &menubar;
  1108. }
  1109. print qq|
  1110. </form>
  1111. </body>
  1112. </html>
  1113. |;
  1114. }
  1115. sub update { &{"update_$form->{db}"}; }
  1116. sub save { &{"save_$form->{db}"} }
  1117. sub update_deduction {
  1118. # if rate or amount is blank remove row
  1119. @flds = qw(rate amount above below);
  1120. $count = 0;
  1121. @a = ();
  1122. for $i ( 1 .. $form->{rate_rows} ) {
  1123. for (@flds) {
  1124. $form->{"${_}_$i"} =
  1125. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1126. }
  1127. if ( $form->{"rate_$i"} || $form->{"amount_$i"} ) {
  1128. push @a, {};
  1129. $j = $#a;
  1130. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1131. $count++;
  1132. }
  1133. }
  1134. $form->redo_rows( \@flds, \@a, $count, $form->{rate_rows} );
  1135. $form->{rate_rows} = $count;
  1136. @flds = qw(base maximum);
  1137. $count = 0;
  1138. @a = ();
  1139. for $i ( 1 .. $form->{"base_rows"} ) {
  1140. $form->{"maximum_$i"} =
  1141. $form->parse_amount( \%myconfig, $form->{"maximum_$i"} );
  1142. if ( $form->{"base_$i"} ) {
  1143. push @a, {};
  1144. $j = $#a;
  1145. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1146. $count++;
  1147. }
  1148. }
  1149. $form->redo_rows( \@flds, \@a, $count, $form->{"base_rows"} );
  1150. $form->{"base_rows"} = $count;
  1151. @flds = qw(after);
  1152. $count = 0;
  1153. @a = ();
  1154. for $i ( 1 .. $form->{"after_rows"} ) {
  1155. if ( $form->{"after_$i"} ) {
  1156. push @a, {};
  1157. $j = $#a;
  1158. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1159. $count++;
  1160. }
  1161. }
  1162. $form->redo_rows( \@flds, \@a, $count, $form->{"after_rows"} );
  1163. $form->{"after_rows"} = $count;
  1164. &deduction_header;
  1165. &deduction_footer;
  1166. }
  1167. sub update_employee {
  1168. # if rate or amount is blank remove row
  1169. @flds = qw(before after);
  1170. $count = 0;
  1171. @a = ();
  1172. for $i ( 1 .. $form->{deduction_rows} ) {
  1173. for (@flds) {
  1174. $form->{"${_}_$i"} =
  1175. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1176. }
  1177. if ( $form->{"deduction_$i"} ) {
  1178. push @a, {};
  1179. $j = $#a;
  1180. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1181. $count++;
  1182. }
  1183. }
  1184. $form->redo_rows( \@flds, \@a, $count, $form->{deduction_rows} );
  1185. $form->{deduction_rows} = $count;
  1186. &employee_header;
  1187. &employee_footer;
  1188. }
  1189. sub save_as_new {
  1190. $form->{id} = 0;
  1191. delete $form->{employeelogin};
  1192. &save;
  1193. }
  1194. sub save_deduction {
  1195. $form->isblank( "description", $locale->text("Description missing!") );
  1196. unless ( $form->{"rate_1"} || $form->{"amount_1"} ) {
  1197. $form->isblank( "rate_1", $locale->text("Rate missing!") )
  1198. unless $form->{"amount_1"};
  1199. $form->isblank( "amount_1", $locale->text("Amount missing!") );
  1200. }
  1201. HR->save_deduction( \%myconfig, \%$form );
  1202. $form->redirect( $locale->text('Deduction saved!') );
  1203. }
  1204. sub delete_deduction {
  1205. HR->delete_deduction( \%myconfig, \%$form );
  1206. $form->redirect( $locale->text('Deduction deleted!') );
  1207. }