From 98a370bb0bca7072d1f9b8764ce869d57ab7956f Mon Sep 17 00:00:00 2001 From: Phuong Date: Sat, 6 Jul 2019 07:48:52 +0700 Subject: [PATCH] Released 2.4-3 --- README.md | 6 +- hooks.php | 42 +++-- includes/db/account_db.inc | 63 ++++--- includes/db/attendance_db.inc | 46 +++-- includes/db/department_db.inc | 2 +- includes/db/doc_db.inc | 2 +- includes/db/employee_db.inc | 41 +++- includes/db/employee_db_banking.inc | 2 +- includes/db/grade_db.inc | 70 +++++++ includes/db/job_position_db.inc | 88 +++++++++ includes/db/leave_db.inc | 98 ++++++++++ includes/db/overtime_db.inc | 2 +- includes/db/payslip_db.inc | 44 +++-- includes/db/salary_structure_db.inc | 71 +++++-- includes/frontHrm_db.inc | 8 +- includes/frontHrm_ui.inc | 10 +- includes/hrm_classes.inc | 2 +- includes/ui/department_ui.inc | 2 +- includes/ui/doc_ui.inc | 2 +- includes/ui/employee_bank_ui.inc | 62 +++---- includes/ui/employee_ui.inc | 2 +- includes/ui/job_position_ui.inc | 40 ++++ includes/ui/leave_ui.inc | 40 ++++ includes/ui/overtime_ui.inc | 5 +- includes/ui/payslip_ui.inc | 140 ++++++++------ inquiry/emp_inquiry.php | 2 +- inquiry/time_sheet.php | 3 +- js/emp_payalloc.js | 3 +- manage/accounts.php | 73 +++++--- manage/attendance.php | 58 +++--- manage/default_setup.php | 18 +- manage/department.php | 8 +- manage/doc_type.php | 2 +- manage/employee.php | 277 +++++++++++++++++++--------- manage/employee_bank_entry.php | 103 +++++------ manage/employee_docs.php | 2 +- manage/grade.php | 147 +++++++++++++++ manage/leave_types.php | 124 +++++++++++++ manage/overtime.php | 4 +- manage/payroll_rules.php | 71 +++---- manage/payslip.php | 101 +++++----- manage/position.php | 148 +++++++++++++++ manage/salary_structure.php | 85 +++++---- reporting/redirect.php | 2 +- reporting/rep889.php | 19 +- reporting/rep_employees.php | 6 +- reporting/reports_custom.php | 2 +- sql/remove.sql | 14 +- sql/update.sql | 91 +++++++-- 49 files changed, 1686 insertions(+), 567 deletions(-) create mode 100644 includes/db/grade_db.inc create mode 100644 includes/db/job_position_db.inc create mode 100644 includes/db/leave_db.inc create mode 100644 includes/ui/job_position_ui.inc create mode 100644 includes/ui/leave_ui.inc create mode 100644 manage/grade.php create mode 100644 manage/leave_types.php create mode 100644 manage/position.php diff --git a/README.md b/README.md index dd5fb92..e9d4f06 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ Requirement Installation ------------ -##### From 01/Apr/2018 FrontHrm can be installed without any changes in FA core so following steps 2, 4 can be ignored. -1. Rename the folder to `FrontHrm` then copy to FA `modules` directory. +##### From 01/Apr/2018 FrontHrm can be installed without any changes in FA core so following steps 2, 3, 4 can be ignored. +1. Rename the folder to `FrontHrm` then copy to the FA `modules` directory. 2. ~~Copy `rep889.php` to FA `reporting` folder.~~ -3. Copy `dejavu font files` to FA `reporting/font` folder. +3. ~~Copy `dejavu font files` to FA `reporting/font` folder.~~ 4. ~~Replace `reporting/includes/reporting.inc` with `reporting.inc` in the FrontHrm.~~ 5. For FrontAccounting 2.4.4 up to now: just install and active normally. For the earlier versions, do the following: diff --git a/hooks.php b/hooks.php index f423783..2baa637 100644 --- a/hooks.php +++ b/hooks.php @@ -1,24 +1,24 @@ | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | | | -\=======================================================*/ +\=======================================================*/ define ('SS_HRM', 251<<8); class FrontHrm_app extends application { - + function __construct() { global $path_to_root; parent::__construct('FrontHrm', _($this->help_context = 'Human Resource')); $this->add_module(_('Transactions')); - $this->add_lapp_function(0, _('Attendance'), $path_to_root.'/modules/FrontHrm/manage/attendance.php?', 'SA_EMPL', MENU_TRANSACTION); + $this->add_lapp_function(0, _('Attendance'), $path_to_root.'/modules/FrontHrm/manage/attendance.php?', 'SA_EMPL', MENU_TRANSACTION); $this->add_lapp_function(0, _('Payslip Entry'), $path_to_root.'/modules/FrontHrm/manage/payslip.php?NewPayslip=Yes', 'SA_EMPL', MENU_TRANSACTION); $this->add_lapp_function(0, "",""); $this->add_lapp_function(0, _('Document Expiration'), $path_to_root.'/modules/FrontHrm/manage/employee_docs.php?', 'SA_ATTACHDOCUMENT', MENU_TRANSACTION); @@ -26,31 +26,33 @@ function __construct() { $this->add_rapp_function(0, _('Employee Advances'), $path_to_root.'/modules/FrontHrm/manage/employee_bank_entry.php?NewAdvance=Yes', 'SA_EMPL', MENU_TRANSACTION); $this->add_module(_('Inquiries and Reports')); - $this->add_lapp_function(1, _('Timesheet'), $path_to_root.'/modules/FrontHrm/inquiry/time_sheet.php?', 'SA_EMPL', MENU_INQUIRY); - $this->add_lapp_function(1, _('Employee Transaction Inquiry'), $path_to_root.'/modules/FrontHrm/inquiry/emp_inquiry.php?', 'SA_EMPL', MENU_INQUIRY); - $this->add_rapp_function(1, _('Employee Document Inquiry'), $path_to_root.'/modules/FrontHrm/manage/employee_docs.php?View=yes', 'SA_EMPL', MENU_INQUIRY); + $this->add_lapp_function(1, _('Timesheet'), $path_to_root.'/modules/FrontHrm/inquiry/time_sheet.php?', 'SA_EMPL', MENU_INQUIRY); + $this->add_lapp_function(1, _('Employee Transaction Inquiry'), $path_to_root.'/modules/FrontHrm/inquiry/emp_inquiry.php?', 'SA_EMPL', MENU_INQUIRY); + $this->add_rapp_function(1, _('Employee Document Inquiry'), $path_to_root.'/modules/FrontHrm/manage/employee_docs.php?View=yes', 'SA_EMPL', MENU_INQUIRY); $this->add_rapp_function(1, _("Employee &Reports"), "reporting/reports_main.php?Class=8", 'SA_EMPL', MENU_REPORT); $this->add_module(_('Maintenance')); - $this->add_lapp_function(2, _('Employees'), $path_to_root.'/modules/FrontHrm/manage/employee.php?', 'SA_EMPL', MENU_ENTRY); - $this->add_lapp_function(2, _('Document Types'), $path_to_root.'/modules/FrontHrm/manage/doc_type.php?', 'SA_HRSETUP', MENU_MAINTENANCE); - $this->add_lapp_function(2, _('Departments'), $path_to_root.'/modules/FrontHrm/manage/department.php?', 'SA_HRSETUP', MENU_MAINTENANCE); - $this->add_lapp_function(2, _('Manage Overtime'), $path_to_root.'/modules/FrontHrm/manage/overtime.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + $this->add_lapp_function(2, _('Employees'), $path_to_root.'/modules/FrontHrm/manage/employee.php?', 'SA_EMPL', MENU_ENTRY); + $this->add_lapp_function(2, _('Document Types'), $path_to_root.'/modules/FrontHrm/manage/doc_type.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + $this->add_lapp_function(2, _('Departments'), $path_to_root.'/modules/FrontHrm/manage/department.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + $this->add_lapp_function(2, _('Manage Overtime'), $path_to_root.'/modules/FrontHrm/manage/overtime.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + $this->add_lapp_function(2, _('Leave Types'), $path_to_root.'/modules/FrontHrm/manage/leave_types.php?', 'SA_HRSETUP', MENU_MAINTENANCE); $this->add_lapp_function(2, _('Default Settings'), $path_to_root.'/modules/FrontHrm/manage/default_setup.php?', 'SA_HRSETUP', MENU_MAINTENANCE); - - $this->add_rapp_function(2, _('Salary Scales'), $path_to_root.'/modules/FrontHrm/manage/salaryscale.php?', 'SA_HRSETUP', MENU_MAINTENANCE); - $this->add_rapp_function(2, _('Allowance and Deduction Account'), $path_to_root.'/modules/FrontHrm/manage/accounts.php?', 'SA_HRSETUP', MENU_MAINTENANCE); - $this->add_rapp_function(2, _('Allowance and Deduction Rules'), $path_to_root.'/modules/FrontHrm/manage/payroll_rules.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + + $this->add_rapp_function(2, _('Job Positions'), $path_to_root.'/modules/FrontHrm/manage/position.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + $this->add_rapp_function(2, _('Manage Grades'), $path_to_root.'/modules/FrontHrm/manage/grade.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + $this->add_rapp_function(2, _('Pay Elements'), $path_to_root.'/modules/FrontHrm/manage/accounts.php?', 'SA_HRSETUP', MENU_MAINTENANCE); + $this->add_rapp_function(2, _('Pay Elements Allocation'), $path_to_root.'/modules/FrontHrm/manage/payroll_rules.php?', 'SA_HRSETUP', MENU_MAINTENANCE); $this->add_rapp_function(2, _('Salary Structure'), $path_to_root.'/modules/FrontHrm/manage/salary_structure.php?', 'SA_HRSETUP', MENU_MAINTENANCE); - $this->add_extensions(); + $this->add_extensions(); } } class hooks_FrontHrm extends hooks { function __construct() { - $this->module_name = 'FrontHrm'; - } + $this->module_name = 'FrontHrm'; + } function install_tabs($app) { $app->add_application(new FrontHrm_app); @@ -70,7 +72,7 @@ function activate_extension($company, $check_only=true) { return $this->update_databases($company, $updates, $check_only); } - + function deactivate_extension($company, $check_only=true) { global $db_connections; diff --git a/includes/db/account_db.inc b/includes/db/account_db.inc index c1da075..2a9e604 100644 --- a/includes/db/account_db.inc +++ b/includes/db/account_db.inc @@ -2,70 +2,89 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | | | \=======================================================*/ -function add_payroll_account($account) { - $sql= "INSERT INTO ".TB_PREF."payroll_account (account_code) VALUES (".db_escape($account).")"; +function add_pay_element($name, $account) { + $sql= "INSERT INTO ".TB_PREF."pay_element (element_name, account_code) VALUES (".db_escape($name).",".db_escape($account).")"; db_query($sql, _('could not insert account')); } //-------------------------------------------------------------------------- -function get_payroll_accounts() { - $sql = "SELECT pa.account_id, ac.account_code, ac.account_name FROM ".TB_PREF."chart_master ac, ".TB_PREF."payroll_account pa WHERE ac.account_code = pa.account_code"; +function get_payroll_elements($id=false, $account=false) { + $sql = "SELECT e.element_id, e.element_name, a.account_code, a.account_name FROM ".TB_PREF."chart_master a, ".TB_PREF."pay_element e WHERE a.account_code = e.account_code"; + + if($id) + $sql .= " AND e.element_id = ".db_escape($id); + if($account) + $sql .= " AND e.account_code = ".db_escape($account); - return db_query($sql, _('Could not get accounts')); + $result = db_query($sql, _('Could not get accounts')); + + if($account || $id) + return db_fetch($result); + else + return $result; +} + +//-------------------------------------------------------------------------- + +function update_pay_element($id, $name) { + + $sql = "UPDATE ".TB_PREF."pay_element SET element_name = ".db_escape($name)." WHERE element_id = ".db_escape($id); + + db_query($sql, _('could not update pay element')); } //-------------------------------------------------------------------------- function delete_payroll_account($id) { - $sql = "DELETE FROM ".TB_PREF."payroll_account WHERE account_id=".db_escape($id); - $result = db_query($sql, _('Could not delete account')); + $sql = "DELETE FROM ".TB_PREF."pay_element WHERE element_id=".db_escape($id); + $result = db_query($sql, _('Could not delete element')); } //-------------------------------------------------------------------------- function payroll_account_exist($code) { - return check_empty_result("SELECT account_code FROM ".TB_PREF."payroll_account WHERE account_code=".db_escape($code)); + return check_empty_result("SELECT account_code FROM ".TB_PREF."pay_element WHERE account_code=".db_escape($code)); } //-------------------------------------------------------------------------- function payroll_account_used($id) { - return check_empty_result("SELECT pa.account_id, ps.payroll_rule, pa.account_code FROM ".TB_PREF."payroll_structure ps, ".TB_PREF."payroll_account pa WHERE pa.account_id=".db_escape($id)." AND ps.payroll_rule LIKE CONCAT('%',pa.account_code,'%')"); + return check_empty_result("SELECT e.element_id, p.payroll_rule, e.account_code FROM ".TB_PREF."payroll_structure p, ".TB_PREF."pay_element e WHERE e.element_id=".db_escape($id)." AND p.payroll_rule LIKE CONCAT('%',e.account_code,'%')"); } //-------------------------------------------------------------------------- function get_payroll_rules() { - $sql = "SELECT ca.account_code, ca.account_name, pa.account_code FROM ".TB_PREF."chart_master ca, ".TB_PREF."payroll_account pa WHERE ca.account_code = pa.account_code ORDER BY ca.account_code"; + $sql = "SELECT e.element_name, c.account_code, c.account_name FROM ".TB_PREF."chart_master c, ".TB_PREF."pay_element e WHERE c.account_code = e.account_code ORDER BY c.account_code"; return db_query($sql, _('Could not get accounts')); } //-------------------------------------------------------------------------- -function add_payroll_rule($salary_scale_id, $payroll_rule) { +function add_payroll_rule($position_id, $payroll_rule) { - $sql = "INSERT INTO ".TB_PREF."payroll_structure (salary_scale_id, payroll_rule ) VALUES (".db_escape($salary_scale_id).",".db_escape(implode(';',$payroll_rule)).")"; + $sql = "INSERT INTO ".TB_PREF."payroll_structure (position_id, payroll_rule ) VALUES (".db_escape($position_id).",".db_escape(implode(';',$payroll_rule)).")"; db_query($sql, _('The payroll could not be added')); } //-------------------------------------------------------------------------- -function update_payroll_rule($salary_scale_id, $payroll_rule) { +function update_payroll_rule($position_id, $payroll_rule) { - $sql = "UPDATE ".TB_PREF."payroll_structure SET payroll_rule=".db_escape(implode(';', $payroll_rule))."WHERE salary_scale_id=".db_escape($salary_scale_id); + $sql = "UPDATE ".TB_PREF."payroll_structure SET payroll_rule=".db_escape(implode(';', $payroll_rule))."WHERE position_id=".db_escape($position_id); db_query($sql, _('The payroll could not be updated')); @@ -73,22 +92,22 @@ function update_payroll_rule($salary_scale_id, $payroll_rule) { //-------------------------------------------------------------------------- -function payroll_rule_exist($salary_scale_id) { +function payroll_rule_exist($position_id) { - return check_empty_result("SELECT payroll_rule FROM ".TB_PREF."payroll_structure WHERE salary_scale_id=".db_escape($salary_scale_id)); + return check_empty_result("SELECT payroll_rule FROM ".TB_PREF."payroll_structure WHERE position_id=".db_escape($position_id)); } //-------------------------------------------------------------------------- -function payroll_rule_used($salary_scale, $rule) { - return check_empty_result("SELECT id FROM ".TB_PREF."salary_structure WHERE salary_scale_id = ".db_escape($salary_scale)." AND pay_rule_id = ".db_escape($rule)); +function payroll_rule_used($position, $rule) { + return check_empty_result("SELECT id FROM ".TB_PREF."salary_structure WHERE position_id = ".db_escape($position)." AND pay_rule_id = ".db_escape($rule)); } //-------------------------------------------------------------------------- -function reset_payroll($salary_scale_id) { +function reset_payroll($position) { - $sql = "DELETE FROM ".TB_PREF."payroll_structure WHERE salary_scale_id =".db_escape($salary_scale_id); + $sql = "DELETE FROM ".TB_PREF."payroll_structure WHERE position_id =".db_escape($position); db_query($sql, _('could not reset payroll rules')); } @@ -97,7 +116,7 @@ function reset_payroll($salary_scale_id) { function get_payroll_structure($id) { - $sql = "SELECT * FROM ".TB_PREF."payroll_structure WHERE salary_scale_id = ".db_escape($id); + $sql = "SELECT * FROM ".TB_PREF."payroll_structure WHERE position_id = ".db_escape($id); $result = db_query($sql, _('could not get payroll structure')); $row = db_fetch($result); diff --git a/includes/db/attendance_db.inc b/includes/db/attendance_db.inc index 7138b6d..952150d 100644 --- a/includes/db/attendance_db.inc +++ b/includes/db/attendance_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -30,17 +30,38 @@ function check_attended($emp_id, $overtime_id, $att_date) { //-------------------------------------------------------------------------- -function write_attendance($emp_id, $overtime_id, $hours_no=null, $rate=1, $att_date) { +function check_leave($emp_id, $date) { + $sql = "SELECT * FROM ".TB_PREF."leave WHERE emp_id = ".db_escape($emp_id)." AND date = '".date2sql($date)."'"; - if(isset($hours_no) && $hours_no != '') { + return check_empty_result($sql); +} + +//-------------------------------------------------------------------------- + +function write_attendance($emp_id, $overtime_id, $hours_no=null, $rate=1, $att_date, $leave_id = false) { + + if(!empty($leave_id)) { + if(check_leave($emp_id, $att_date)) + $sql = "UPDATE ".TB_PREF."leave SET leave_id = ".db_escape($leave_id).", pay_rate = ".db_escape($rate)." WHERE date = '".date2sql($att_date)."' AND emp_id = ".db_escape($emp_id); + else + $sql = "INSERT INTO ".TB_PREF."leave(emp_id, leave_id, pay_rate, date) VALUES(".db_escape($emp_id).",".db_escape($leave_id).",".db_escape($rate).",'".date2sql($att_date)."')"; + + $sql2 = "DELETE FROM ".TB_PREF."attendance WHERE emp_id = ".db_escape($emp_id)." AND att_date = '".date2sql($att_date)."'"; + } + elseif(isset($hours_no) && $hours_no != '') { if(check_attended($emp_id, $overtime_id, $att_date)) $sql = "UPDATE ".TB_PREF."attendance SET hours_no = ".db_escape($hours_no).", rate = ".db_escape($rate)." WHERE att_date = '".date2sql($att_date)."' AND emp_id = ".db_escape($emp_id)." AND overtime_id = ".db_escape($overtime_id); else $sql = "INSERT INTO ".TB_PREF."attendance(emp_id, overtime_id, hours_no, rate, att_date) VALUES(".db_escape($emp_id).",".db_escape($overtime_id).",".db_escape($hours_no).",".db_escape($rate).",'".date2sql($att_date)."')"; - - db_query($sql, _('Could not add time clock')); + + $sql2 = "DELETE FROM ".TB_PREF."leave WHERE emp_id = ".db_escape($emp_id)." AND date = '".date2sql($att_date)."'"; } + + if(!empty($sql)) + db_query($sql, _('Could not write attendance data')); + if(!empty($sql2)) + db_query($sql2, _('Could not write attendance data')); } //-------------------------------------------------------------------------- @@ -60,24 +81,25 @@ function get_attendance($from, $to, $emp_id = 0, $department = 0, $ot_id = 0) { if($emp_id == 0 && $department == 0) { while(sql_date_comp($from->format('Y-m-d'),$to->format('Y-m-d')) <= 0) { - $sql .= ",MAX(CASE WHEN att.att_date = '".$from->format('Y-m-d')."' AND emp.emp_id = att.emp_id AND att.overtime_id = ".$ot_id." THEN CASE hours_no WHEN '0' THEN 'x' ELSE hours_no END END)"; + $sql .= ",MAX(CASE WHEN att.att_date = '".$from->format('Y-m-d')."' AND emp.emp_id = att.emp_id AND att.overtime_id = ".$ot_id." THEN CASE hours_no WHEN '0' THEN 'X' ELSE hours_no END WHEN emp.emp_id = l.emp_id AND l.date = '".$from->format('Y-m-d')."' THEN CASE WHEN lt.pay_rate >= '100' THEN CONCAT('',lt.leave_code,'') WHEN lt.pay_rate < '100' AND lt.pay_rate > '0' THEN CONCAT('',lt.leave_code,'') WHEN lt.pay_rate <= '0' THEN CONCAT('',lt.leave_code,'') END END)"; $from->modify('+1 day'); } - $sql .= " FROM ".TB_PREF."employee emp, ".TB_PREF."attendance att WHERE !emp.inactive GROUP BY emp.emp_id"; + $sql .= " FROM ".TB_PREF."employee emp, ".TB_PREF."attendance att, ".TB_PREF."leave l, ".TB_PREF."leave_type lt WHERE !emp.inactive AND l.leave_id = lt.leave_id GROUP BY emp.emp_id"; } - else if($emp_id != 0) { + elseif($emp_id != 0) { while(sql_date_comp($from->format('Y-m-d'),$to->format('Y-m-d')) <= 0) { - $sql .= ",MAX(CASE WHEN emp.emp_id = ".$emp_id." AND att.att_date = '".$from->format('Y-m-d')."' AND emp.emp_id = att.emp_id AND att.overtime_id = ".$ot_id." THEN hours_no END)"; + $sql .= ",MAX(CASE WHEN emp.emp_id = ".$emp_id." AND att.att_date = '".$from->format('Y-m-d')."' AND emp.emp_id = att.emp_id AND att.overtime_id = ".$ot_id." THEN hours_no WHEN emp.emp_id = l.emp_id AND l.date = '".$from->format('Y-m-d')."' THEN CASE WHEN lt.pay_rate >= '100' THEN CONCAT('',lt.leave_code,'') WHEN lt.pay_rate < '100' AND lt.pay_rate > '0' THEN CONCAT('',lt.leave_code,'') WHEN lt.pay_rate <= '0' THEN CONCAT('',lt.leave_code,'') END END)"; $from->modify('+1 day'); } - $sql .= " FROM ".TB_PREF."employee emp, ".TB_PREF."attendance att WHERE emp.emp_id = '".$emp_id."' GROUP BY emp.emp_id"; + $sql .= " FROM ".TB_PREF."employee emp, ".TB_PREF."attendance att, ".TB_PREF."leave l, ".TB_PREF."leave_type lt WHERE l.leave_id = lt.leave_id AND emp.emp_id = '".$emp_id."' GROUP BY emp.emp_id"; } else { while(sql_date_comp($from->format('Y-m-d'),$to->format('Y-m-d')) <= 0) { - $sql .= ",MAX(CASE WHEN att.att_date = '".$from->format('Y-m-d')."' AND emp.emp_id = att.emp_id AND att.overtime_id = ".$ot_id." THEN hours_no END)"; + $sql .= ",MAX(CASE WHEN att.att_date = '".$from->format('Y-m-d')."' AND emp.emp_id = att.emp_id AND att.overtime_id = ".$ot_id." THEN hours_no WHEN emp.emp_id = l.emp_id AND l.date = '".$from->format('Y-m-d')."' THEN CASE WHEN lt.pay_rate >= '100' THEN CONCAT('',lt.leave_code,'') WHEN lt.pay_rate < '100' AND lt.pay_rate > '0' THEN CONCAT('',lt.leave_code,'') WHEN lt.pay_rate <= '0' THEN CONCAT('',lt.leave_code,'') END END)"; $from->modify('+1 day'); } - $sql .= " FROM ".TB_PREF."employee emp, ".TB_PREF."attendance att WHERE emp.department_id = ".$department." AND !emp.inactive GROUP BY emp.emp_id"; + $sql .= " FROM ".TB_PREF."employee emp, ".TB_PREF."attendance att, ".TB_PREF."leave l, ".TB_PREF."leave_type lt WHERE l.leave_id = lt.leave_id AND emp.department_id = ".$department." AND !emp.inactive GROUP BY emp.emp_id"; } + return $sql; } \ No newline at end of file diff --git a/includes/db/department_db.inc b/includes/db/department_db.inc index 87ec7ca..0ea54ae 100644 --- a/includes/db/department_db.inc +++ b/includes/db/department_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/db/doc_db.inc b/includes/db/doc_db.inc index 7583702..0c5144e 100644 --- a/includes/db/doc_db.inc +++ b/includes/db/doc_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/db/employee_db.inc b/includes/db/employee_db.inc index 714b7e4..3223b8f 100644 --- a/includes/db/employee_db.inc +++ b/includes/db/employee_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -15,7 +15,7 @@ function db_has_employee() { //-------------------------------------------------------------------------- -function write_employee($id=false, $first_name, $last_name, $gender, $adrs, $mobile, $mail, $birth, $notes, $hire_date, $department, $salary, $release, $active) { +function write_employee($id=false, $first_name, $last_name, $gender, $adrs, $mobile, $mail, $birth, $national_id, $passport, $bank_account, $tax_number, $notes, $hire_date, $department, $position, $grade_id, $personal_salary, $release, $active) { db_query("SET sql_mode = ''"); @@ -29,10 +29,16 @@ function write_employee($id=false, $first_name, $last_name, $gender, $adrs, $mob .db_escape($mobile).", " .db_escape($mail).", '" .date2sql($birth)."', " + .db_escape($national_id).", " + .db_escape($passport).", " + .db_escape($bank_account).", " + .db_escape($tax_number).", " .db_escape($notes).", '" .date2sql($hire_date)."', " .db_escape($department).", " - .db_escape($salary).", '" + .db_escape($position).", " + .db_escape($grade_id).", " + .db_escape($personal_salary).", '" .date2sql($release)."', " .db_escape($active) .")"; @@ -46,10 +52,16 @@ function write_employee($id=false, $first_name, $last_name, $gender, $adrs, $mob emp_mobile = ".db_escape($mobile).", emp_email = ".db_escape($mail).", emp_birthdate = '".date2sql($birth)."', + national_id = ".db_escape($national_id).", + passport = ".db_escape($passport).", + bank_account = ".db_escape($bank_account).", + tax_number = ".db_escape($tax_number).", emp_notes = ".db_escape($notes).", emp_hiredate = '".date2sql($hire_date)."', department_id = ".db_escape($department).", - salary_scale_id = ".db_escape($salary).", + position_id = ".db_escape($position).", + grade_id = ".db_escape($grade_id).", + personal_salary = ".db_escape($personal_salary).", emp_releasedate = '".date2sql($release)."', inactive = ".db_escape($active)." WHERE emp_id = ".db_escape($id); @@ -60,7 +72,7 @@ function write_employee($id=false, $first_name, $last_name, $gender, $adrs, $mob //-------------------------------------------------------------------------- -function get_employees($id = false, $all = false, $department = false) { +function get_employees($id = false, $all=false, $department=false, $gender=false, $position_id=false, $grade_id = -1, $str=false) { $sql = "SELECT *, CONCAT(emp_first_name, ' ', emp_last_name) AS name FROM ".TB_PREF."employee"; $where = array(); @@ -69,8 +81,17 @@ function get_employees($id = false, $all = false, $department = false) { $where[] = "!inactive"; if($id) $where[] = "emp_id=".db_escape($id); - if($department) + if(!empty($department)) $where[] = "department_id = ".db_escape($department); + if($gender) + $where[] = "gender = ".db_escape($gender); + if(!empty($position_id)) + $where[] = "position_id = ".db_escape($position_id); + if($grade_id >= 0) + $where[] = "grade_id = ".db_escape($grade_id); + if(!empty($str)) + $where[] = "(emp_first_name LIKE ".db_escape("%$str%")." OR emp_last_name LIKE ".db_escape("%$str%")." OR emp_email LIKE ".db_escape("%$str%")." OR emp_address LIKE ".db_escape("%$str%")." OR emp_mobile LIKE ".db_escape("%$str%")." OR national_id LIKE ".db_escape("%$str%")." OR passport LIKE ".db_escape("%$str%")." OR tax_number LIKE ".db_escape("%$str%").")"; + if(count($where)) $sql .= ' WHERE '.implode(' AND ', $where); @@ -116,12 +137,12 @@ function check_employee_hired($id, $date) { //-------------------------------------------------------------------------- -function employee_has_salary_scale($id) { - return check_empty_result("SELECT salary_scale_id FROM ".TB_PREF."employee WHERE salary_scale_id != 0 AND emp_id = ".db_escape($id)); +function employee_has_position($id) { + return check_empty_result("SELECT position_id FROM ".TB_PREF."employee WHERE position_id != 0 AND emp_id = ".db_escape($id)); } //-------------------------------------------------------------------------- -function emp_salaryscale_has_structure($id) { - return check_empty_result("SELECT e.salary_scale_id, s.* FROM ".TB_PREF."employee e, ".TB_PREF."salary_structure s WHERE e.salary_scale_id = s.salary_scale_id AND e.emp_id = ".db_escape($id)); +function emp_position_has_structure($id) { + return check_empty_result("SELECT e.position_id, s.* FROM ".TB_PREF."employee e, ".TB_PREF."salary_structure s WHERE e.position_id = s.position_id AND e.emp_id = ".db_escape($id)); } diff --git a/includes/db/employee_db_banking.inc b/includes/db/employee_db_banking.inc index 1ae042c..7f8f753 100644 --- a/includes/db/employee_db_banking.inc +++ b/includes/db/employee_db_banking.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/db/grade_db.inc b/includes/db/grade_db.inc new file mode 100644 index 0000000..f87a0d5 --- /dev/null +++ b/includes/db/grade_db.inc @@ -0,0 +1,70 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +function grade_exist($grade, $position) { + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."grade_table WHERE grade_id = ".db_escape($grade)." AND position_id = ".db_escape($position)); +} + +function add_grade_table($grade, $position, $amount) { + $sql= "INSERT INTO ".TB_PREF."grade_table (grade_id, position_id, amount) VALUES (".db_escape($grade).", ".db_escape($position).", ".db_escape($amount).")"; + + db_query($sql, _('could not insert grade data')); +} + +function update_grade_table($grade, $position, $amount) { + $sql = "UPDATE ".TB_PREF."grade_table SET amount = ".db_escape($amount)." WHERE grade_id = ".db_escape($grade)." AND position_id = ".db_escape($position); + db_query($sql, _('could not update grade data')); +} + +function get_position_grades($position) { + $sql = "SELECT * FROM ".TB_PREF."grade_table WHERE position_id = ".db_escape($position); + + return db_query($sql, _('Could not get grade data')); +} + +function get_grade_amount($position, $grade) { + $sql = "SELECT amount FROM ".TB_PREF."grade_table WHERE position_id = ".db_escape($position)." AND grade_id = ".db_escape($grade); + $result = db_query($sql, _('could not get grade data')); + $amount = db_fetch($result)[0]; + + return $amount; +} + +function get_all_grades() { + $sql = "SELECT * FROM ".TB_PREF."grade_table"; + + return db_query($sql, _('could not read grade table data')); +} + +function delete_grade($position) { + + $sql = "DELETE FROM ".TB_PREF."grade_table WHERE position_id = ".db_escape($position); + db_query($sql, _('Could not delete grade table')); +} + +function max_grade_used() { + $sql = "SELECT MAX(grade_id) FROM ".TB_PREF."employee WHERE !inactive"; + $result = db_query($sql, _('could not get employee data')); + $max = db_fetch($result)[0]; + + return $max; +} + +function set_grade_salary($account, $amount, $position_id, $grade_id, $new=false) { + $date = date2sql(Today()); + + if($new) + $sql = "INSERT INTO ".TB_PREF."salary_structure(date, position_id, grade_id, pay_rule_id, pay_amount, type, is_basic) VALUES ('$date', ".db_escape($position_id).", ".db_escape($grade_id).", ".db_escape($account).", ".db_escape($amount).", 1, 1)"; + else + $sql = "UPDATE ".TB_PREF."salary_structure SET pay_rule_id = ".db_escape($account).", pay_amount = ".db_escape($amount)." WHERE position_id = ".db_escape($position_id)." AND grade_id = ".db_escape($grade_id); + + db_query($sql, _('Could not write salary structure data')); +} \ No newline at end of file diff --git a/includes/db/job_position_db.inc b/includes/db/job_position_db.inc new file mode 100644 index 0000000..8517467 --- /dev/null +++ b/includes/db/job_position_db.inc @@ -0,0 +1,88 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +function db_has_position() { + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."position"); +} + +function set_basic_salary($account, $amount, $position_id, $new=false) { + $date = date2sql(Today()); + + if($new) + $sql = "INSERT INTO ".TB_PREF."salary_structure(date, position_id, pay_rule_id, pay_amount, type, is_basic) VALUES ('$date', ".db_escape($position_id).", ".db_escape($account).", ".db_escape($amount).", 1, 1)"; + else + $sql = "UPDATE ".TB_PREF."salary_structure SET pay_rule_id = ".db_escape($account).", pay_amount = ".db_escape($amount)." WHERE position_id = ".db_escape($position_id); + + db_query($sql, _('Could not write salary structure data')); +} + +function write_position($id = false, $name, $pay_basis) { + + if(!$id) + $sql = "INSERT INTO ".TB_PREF."position(position_name, pay_basis) VALUES (".db_escape($name).",".db_escape($pay_basis).")"; + else + $sql = "UPDATE ".TB_PREF."position SET position_name = ".db_escape($name).", pay_basis = ".db_escape($pay_basis)." WHERE position_id = ".db_escape($id); + + db_query($sql, _('Could not write job position data')); +} + +function delete_position($id) { + $sql = "DELETE FROM ".TB_PREF."position WHERE position_id = ".db_escape($id);; + db_query($sql, _('could not delete job position')); +} + +function get_position($id = false, $all = false) { + + $sql = "SELECT p.*, s.pay_amount, s.pay_rule_id FROM ".TB_PREF."position p, ".TB_PREF."salary_structure s"; + $where = array("p.position_id = s.position_id AND s.is_basic = 1 AND s.grade_id = 0"); + + if(!$all) + $where[] = "!inactive"; + if($id) + $where[] = "p.position_id = ".db_escape($id); + + if(count($where)) + $sql .= ' WHERE '.implode(' AND ', $where); + else + $sql .= ' WHERE 1'; + + $result = db_query($sql, _('Could not get job position data.')); + + if($id) + return db_fetch($result); + else + return $sql; +} + +function position_used($id) { + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."employee WHERE position_id = ".db_escape($id)); +} + +function get_emp_basic_salary($emp_id, $new_staff = false) { + + $person = get_employees($emp_id); + + if(empty($person['personal_salary']) || $new_staff) + $sql = "SELECT s.pay_amount, s.pay_rule_id FROM ".TB_PREF."salary_structure s, ".TB_PREF."employee e WHERE e.position_id = s.position_id AND s.grade_id = e.grade_id AND s.is_basic = 1 AND e.emp_id = ".db_escape($emp_id); + else + $sql = "SELECT pay_amount, pay_rule_id FROM ".TB_PREF."personal_salary_structure WHERE is_basic = 1 AND emp_id = ".db_escape($emp_id); + + $result = db_query($sql, _('could not get salary structure')); + return db_fetch($result); +} + +function is_expenses_account($acc) { + $sql = "SELECT act_class.ctype FROM ".TB_PREF."chart_class act_class, ".TB_PREF."chart_types act_type, ".TB_PREF."chart_master coa WHERE coa.account_type=act_type.id AND act_type.class_id=act_class.cid AND coa.account_code=".db_escape($acc); + + $result = db_query($sql, _('could not retreive the account class for ').$acc); + $row = db_fetch_row($result); + return $row[0] == CL_EXPENSE; +} \ No newline at end of file diff --git a/includes/db/leave_db.inc b/includes/db/leave_db.inc new file mode 100644 index 0000000..cff534c --- /dev/null +++ b/includes/db/leave_db.inc @@ -0,0 +1,98 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +function db_has_leave_type() { + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."leave_type"); +} + +//-------------------------------------------------------------------------- + +function write_leave($id = false, $leave_name, $leave_code, $pay_rate) { + + if($id == -1) + $sql = "INSERT INTO ".TB_PREF."leave_type(leave_name, leave_code, pay_rate) VALUES (".db_escape($leave_name).", ".db_escape($leave_code).", ".db_escape($pay_rate).")"; + else + $sql = "UPDATE ".TB_PREF."leave_type SET leave_name = ".db_escape($leave_name).", leave_code = ".db_escape($leave_code).", pay_rate = ".db_escape($pay_rate)." WHERE leave_id = ".db_escape($id); + + db_query($sql, _('Could not write leave data')); +} + +//-------------------------------------------------------------------------- + +function get_leave_type($id = false, $all = false) { + + $sql = "SELECT * FROM ".TB_PREF."leave_type"; + $where = array(); + + if(!$all) + $where[] = "!inactive"; + if($id) + $where[] = "leave_id=".db_escape($id); + + if(count($where)) + $sql .= ' WHERE '.implode(' AND ', $where); + + $sql .= " ORDER BY leave_id"; + + $result = db_query($sql, _('Could not get leave data.')); + + if($id) + return db_fetch($result); + else + return $sql; +} + +//-------------------------------------------------------------------------- + +function delete_leave_type($id) { + $sql = "DELETE FROM ".TB_PREF."leave_type WHERE leave_id = ".db_escape($id); + db_query($sql, _('Could not delete leave type.')); +} + +//-------------------------------------------------------------------------- + +function leave_type_used($id) { + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."leave WHERE leave_id = ".db_escape($id)); +} + +//-------------------------------------------------------------------------- + +function get_leave($emp_id=false, $leave_id=false, $from=false, $to=false) { + + $sql = "SELECT * FROM ".TB_PREF."leave"; + $where = array(); + + if($emp_id) + $where[] = "emp_id = ".db_escape($emp_id); + if($leave_id) + $where[] = "leave_id = ".db_escape($leave_id); + if($from) + $where[] = "date >= '".date2sql($from)."'"; + if($to) + $where[] = "date <= '".date2sql($to)."'"; + + if(count($where)) + $sql .= ' WHERE '.implode(' AND ', $where); + + $result = db_query($sql, _('could not get leave data.')); + + return $result; +} + +//-------------------------------------------------------------------------- + +function get_employee_leave($emp_id, $leave_id, $from, $to) { + + $sql = "SELECT COUNT(*) FROM ".TB_PREF."leave WHERE emp_id = ".db_escape($emp_id)." AND leave_id = ".db_escape($leave_id)." AND date BETWEEN '".date2sql($from)."' AND '".date2sql($to)."'"; + $result = db_query($sql, _('could not get leave data')); + + return db_fetch($result)[0]; +} \ No newline at end of file diff --git a/includes/db/overtime_db.inc b/includes/db/overtime_db.inc index ebf0f31..a396385 100644 --- a/includes/db/overtime_db.inc +++ b/includes/db/overtime_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/db/payslip_db.inc b/includes/db/payslip_db.inc index 71f5e55..8f05324 100644 --- a/includes/db/payslip_db.inc +++ b/includes/db/payslip_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -21,8 +21,8 @@ function get_next_payslip_no() { //-------------------------------------------------------------------------- function write_payslip(&$cart, $reverse, $use_transaction = true) { - global $Refs; + $date = $cart->tran_date; $ref = $cart->reference; $source_ref = $cart->to_the_order_of; @@ -33,25 +33,25 @@ function write_payslip(&$cart, $reverse, $use_transaction = true) { $payslip_no = $cart->payslip_no; $new = $cart->order_id == 0; - if ($new) + if($new) $cart->order_id = get_next_trans_no($trans_type); $trans_id = $cart->order_id; - if ($use_transaction) + if($use_transaction) begin_transaction(); if(!$new) void_journal_trans($trans_type, $trans_id, false); - foreach ($cart->gl_items as $journal_item) { + foreach($cart->gl_items as $journal_item) { // post to first found bank account using given gl acount code. $is_bank_to = is_bank_account($journal_item->code_id); add_gl_trans($trans_type, $trans_id, $date, $journal_item->code_id, $journal_item->dimension_id, $journal_item->dimension2_id, $journal_item->reference, $journal_item->amount, null, $cart->paytype); - if ($is_bank_to) + if($is_bank_to) add_bank_trans($trans_type, $trans_id, $is_bank_to, $ref, $date, $journal_item->amount, $cart->paytype, $cart->person_id, get_company_currency(), "Cannot insert a destination bank transaction"); // store tax details if the gl account is a tax account @@ -69,27 +69,25 @@ function write_payslip(&$cart, $reverse, $use_transaction = true) { $Refs->save($trans_type, $trans_id, $ref); - if ($new) + if($new) add_comments($trans_type, $trans_id, $date, $memo_); else update_comments($trans_type, $trans_id, null, $memo_); add_audit_trail($trans_type, $trans_id, $date); - if ($reverse) { - - //$reversingDate = date(user_date_display(), - // Mktime(0,0,0,get_month($date)+1,1,get_year($date))); + if($reverse) { + $reversingDate = begin_month(add_months($date, 1)); $trans_id_reverse = get_next_trans_no($trans_type); - foreach ($cart->gl_items as $journal_item) { + foreach($cart->gl_items as $journal_item) { $is_bank_to = is_bank_account($journal_item->code_id); add_gl_trans($trans_type, $trans_id_reverse, $reversingDate, $journal_item->code_id, $journal_item->dimension_id, $journal_item->dimension2_id, $journal_item->reference, -$journal_item->amount); - if ($is_bank_to) { + if($is_bank_to) { add_bank_trans($trans_type, $trans_id_reverse, $is_bank_to, $ref, $reversingDate, -$journal_item->amount, 0, '', get_company_currency(), "Cannot insert a destination bank transaction"); } // store tax details if the gl account is a tax account @@ -102,7 +100,7 @@ function write_payslip(&$cart, $reverse, $use_transaction = true) { add_audit_trail($trans_type, $trans_id_reverse, $reversingDate); } - if ($use_transaction) + if($use_transaction) commit_transaction(); return $trans_id; @@ -160,16 +158,29 @@ function get_payslip($trans_no=false, $payslip_no=false) { elseif($payslip_no) $sql .= " WHERE payslip_no = ".db_escape($payslip_no); - $result = db_query($sql, _('Could retreive payslip data')); + $result = db_query($sql, _('Could not retreive payslip data')); return db_fetch($result); } //-------------------------------------------------------------------------- +function get_employee_payslip($emp_id, $all=false) { + $sql = "SELECT p.* FROM ".TB_PREF."payslip p LEFT JOIN ".TB_PREF."employee_trans t ON p.payslip_no = t.payslip_no WHERE p.emp_id = ".db_escape($emp_id); + + if(!$all) + $sql .= " AND t.payslip_no IS NULL"; + + $result = db_query($sql, _('could not not retreive payslip data')); + + return $result; +} + +//-------------------------------------------------------------------------- + function get_payslip_from_advice($trans_no) { $sql = "SELECT p.* FROM ".TB_PREF."employee_trans t, ".TB_PREF."payslip p WHERE p.payslip_no = t.payslip_no AND t.trans_no = ".db_escape($trans_no); - $result = db_query($sql, _('Could retreive payslip data')); + $result = db_query($sql, _('Could not retreive payslip data')); return db_fetch($result); } @@ -228,5 +239,4 @@ function add_payslip_details($payslip, $allowances) { db_query($sql, _('could not insert payslip details')); } - } \ No newline at end of file diff --git a/includes/db/salary_structure_db.inc b/includes/db/salary_structure_db.inc index 60b6147..b74b323 100644 --- a/includes/db/salary_structure_db.inc +++ b/includes/db/salary_structure_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -17,19 +17,29 @@ function add_salary_structure($pay_rules=array()) { begin_transaction(); foreach($pay_rules as $rule) - insert_structure($rule['salary_scale_id'], $rule['pay_rule_id'], $rule['pay_amount'], $rule['type']); + insert_structure($rule['position_id'], $rule['grade_id'], $rule['pay_rule_id'], $rule['pay_amount'], $rule['type']); commit_transaction(); } +function write_personal_salary_structure($pay_rules=array()) { + + if(empty($pay_rules)) + return false; + + foreach($pay_rules as $rule) + write_personal_structure($rule['emp_id'], $rule['pay_rule_id'], $rule['pay_amount'], $rule['type'], $rule['is_basic']); +} + //-------------------------------------------------------------------------- -function insert_structure($salary_scale_id, $pay_rule_id,$pay_amount, $type) { +function insert_structure($position_id, $grade_id, $pay_rule_id, $pay_amount, $type) { - $date_ = date2sql(Today()); - $sql = "INSERT INTO ".TB_PREF."salary_structure(date,salary_scale_id, pay_rule_id,pay_amount,type) VALUES ('" - .$date_."'," - .db_escape($salary_scale_id)."," + $date = date2sql(Today()); + $sql = "INSERT INTO ".TB_PREF."salary_structure(date, position_id, grade_id, pay_rule_id, pay_amount, type) VALUES ('" + .$date."'," + .db_escape($position_id)."," + .db_escape($grade_id)."," .db_escape($pay_rule_id)."," .db_escape($pay_amount)."," .db_escape($type) @@ -38,26 +48,54 @@ function insert_structure($salary_scale_id, $pay_rule_id,$pay_amount, $type) { db_query($sql, _('could not add salary structure')); } +function write_personal_structure($emp_id, $pay_rule_id, $pay_amount, $type, $is_basic = 0) { + + $date = date2sql(Today()); + + if($pay_amount == 0) + $sql = "DELETE FROM ".TB_PREF."personal_salary_structure WHERE emp_id = ".db_escape($emp_id)." AND pay_rule_id = ".db_escape($pay_rule_id)." AND is_basic = ".db_escape($is_basic); + elseif(!check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."personal_salary_structure WHERE emp_id = ".db_escape($emp_id)." AND pay_rule_id = ".db_escape($pay_rule_id)." AND is_basic = ".db_escape($is_basic))) { + $sql = "INSERT INTO ".TB_PREF."personal_salary_structure(date, emp_id, pay_rule_id, pay_amount, type, is_basic) VALUES ('" + .$date."'," + .db_escape($emp_id)."," + .db_escape($pay_rule_id)."," + .db_escape($pay_amount)."," + .db_escape($type)."," + .db_escape($is_basic) + .")"; + } + else { + $sql = "UPDATE ".TB_PREF."personal_salary_structure SET date = '".$date."', pay_amount = ".db_escape($pay_amount).", type = ".db_escape($type).", is_basic = ".db_escape($is_basic)." WHERE emp_id = ".db_escape($emp_id)." AND pay_rule_id = ".db_escape($pay_rule_id); + } + + db_query($sql, _('could not write salary structure')); +} + +function update_personal_basic_account($emp_id, $acc) { + $sql = "UPDATE ".TB_PREF."personal_salary_structure SET pay_rule_id = ".db_escape($acc)." WHERE emp_id = ".db_escape($emp_id)." AND is_basic = 1"; + db_query($sql, _('could not write salary structure')); +} + //-------------------------------------------------------------------------- -function exists_salary_structure($id) { +function exists_salary_structure($position_id) { - return check_empty_result("SELECT id FROM ".TB_PREF."salary_structure WHERE salary_scale_id = ".db_escape($id)." AND !is_basic"); + return check_empty_result("SELECT id FROM ".TB_PREF."salary_structure WHERE position_id = ".db_escape($position_id)." AND !is_basic"); } //-------------------------------------------------------------------------- -function delete_salary_structure($salary_scale_id) { +function delete_salary_structure($position_id, $grade_id) { - $sql = "DELETE FROM ".TB_PREF."salary_structure WHERE salary_scale_id =".db_escape($salary_scale_id)." AND !is_basic"; + $sql = "DELETE FROM ".TB_PREF."salary_structure WHERE position_id =".db_escape($position_id)." AND grade_id = ".db_escape($grade_id)." AND !is_basic"; db_query($sql, _('could not delete salary structure')); } //-------------------------------------------------------------------------- -function get_salary_structure($salary_scale_id) { +function get_salary_structure($position_id, $grade_id = 0) { - $sql = "SELECT st.*, ac.account_name FROM ".TB_PREF."salary_structure st, ".TB_PREF."chart_master ac WHERE ac.account_code = st.pay_rule_id AND st.salary_scale_id = ".db_escape($salary_scale_id); + $sql = "SELECT st.*, ac.account_name FROM ".TB_PREF."salary_structure st, ".TB_PREF."chart_master ac WHERE ac.account_code = st.pay_rule_id AND st.position_id = ".db_escape($position_id)." AND st.grade_id = ".db_escape($grade_id); return db_query($sql, _('Could not get salary structure')); } @@ -66,7 +104,12 @@ function get_salary_structure($salary_scale_id) { function get_emp_salary_structure($emp_id) { - $sql = "SELECT s.* FROM ".TB_PREF."salary_structure s, ".TB_PREF."employee e WHERE s.salary_scale_id = e.salary_scale_id AND e.emp_id = ".db_escape($emp_id); + $person = get_employees($emp_id); + + if(empty($person['personal_salary'])) + $sql = "SELECT s.* FROM ".TB_PREF."salary_structure s, ".TB_PREF."employee e WHERE s.position_id = e.position_id AND s.grade_id = e.grade_id AND e.emp_id = ".db_escape($emp_id); + else + $sql = "SELECT * FROM ".TB_PREF."personal_salary_structure WHERE emp_id = ".db_escape($emp_id); return db_query($sql, _('Could not get employee salary structure')); } \ No newline at end of file diff --git a/includes/frontHrm_db.inc b/includes/frontHrm_db.inc index c058115..6255135 100644 --- a/includes/frontHrm_db.inc +++ b/includes/frontHrm_db.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -11,11 +11,13 @@ include_once($path_to_root.'/modules/FrontHrm/includes/db/employee_db.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/db/department_db.inc'); -include_once($path_to_root.'/modules/FrontHrm/includes/db/salary_scale_db.inc'); +include_once($path_to_root.'/modules/FrontHrm/includes/db/job_position_db.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/db/overtime_db.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/db/attendance_db.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/db/account_db.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/db/salary_structure_db.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/db/payslip_db.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/db/employee_db_banking.inc'); -include_once($path_to_root.'/modules/FrontHrm/includes/db/doc_db.inc'); \ No newline at end of file +include_once($path_to_root.'/modules/FrontHrm/includes/db/doc_db.inc'); +include_once($path_to_root.'/modules/FrontHrm/includes/db/grade_db.inc'); +include_once($path_to_root.'/modules/FrontHrm/includes/db/leave_db.inc'); \ No newline at end of file diff --git a/includes/frontHrm_ui.inc b/includes/frontHrm_ui.inc index dfc2bc5..433f31e 100644 --- a/includes/frontHrm_ui.inc +++ b/includes/frontHrm_ui.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -11,11 +11,12 @@ include_once($path_to_root.'/modules/FrontHrm/includes/ui/employee_ui.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/ui/department_ui.inc'); -include_once($path_to_root.'/modules/FrontHrm/includes/ui/salary_scale_ui.inc'); +include_once($path_to_root.'/modules/FrontHrm/includes/ui/job_position_ui.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/ui/overtime_ui.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/ui/payslip_ui.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/ui/employee_bank_ui.inc'); include_once($path_to_root.'/modules/FrontHrm/includes/ui/doc_ui.inc'); +include_once($path_to_root.'/modules/FrontHrm/includes/ui/leave_ui.inc'); define('DEBIT', 1); define('CREDIT', 0); @@ -31,4 +32,7 @@ $Deduct_act = get_company_pref('payroll_deductleave_act'); $Overtime_act = get_company_pref('payroll_overtime_act'); $Work_days = get_company_pref('payroll_month_work_days'); $Work_hours = get_company_pref('payroll_work_hours'); -$USE_DEPT_ACC = get_company_pref('payroll_dept_based'); \ No newline at end of file +$USE_DEPT_ACC = get_company_pref('payroll_dept_based'); + +/* Don't change this value after setting up company grades number */ +$max_grade_number = 20; \ No newline at end of file diff --git a/includes/hrm_classes.inc b/includes/hrm_classes.inc index 7a1aacf..d43e233 100644 --- a/includes/hrm_classes.inc +++ b/includes/hrm_classes.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/ui/department_ui.inc b/includes/ui/department_ui.inc index 8b0707d..1672145 100644 --- a/includes/ui/department_ui.inc +++ b/includes/ui/department_ui.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/ui/doc_ui.inc b/includes/ui/doc_ui.inc index 7a20510..098919b 100644 --- a/includes/ui/doc_ui.inc +++ b/includes/ui/doc_ui.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/ui/employee_bank_ui.inc b/includes/ui/employee_bank_ui.inc index 08962da..6aed438 100644 --- a/includes/ui/employee_bank_ui.inc +++ b/includes/ui/employee_bank_ui.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -16,7 +16,7 @@ function employee_bank_header(&$order) { div_start('pmt_header'); - start_outer_table(TABLESTYLE2, "width='90%'"); // outer table + start_outer_table(TABLESTYLE2, "width='90%'"); table_section(1); @@ -26,19 +26,21 @@ function employee_bank_header(&$order) { table_section(2, "33%"); - if (!isset($_POST['PayType'])) { - if (isset($_GET['PayType'])) + if(!isset($_POST['PayType'])) { + + if(isset($_GET['PayType'])) $_POST['PayType'] = $_GET['PayType']; else $_POST['PayType'] = ""; } - if (!isset($_POST['person_id'])) { - if (isset($_GET['PayPerson'])) + if(!isset($_POST['person_id'])) { + + if(isset($_GET['PayPerson'])) $_POST['person_id'] = $_GET['PayPerson']; else $_POST['person_id'] = ""; } - if (isset($_POST['_PayType_update'])) { + if(isset($_POST['_PayType_update'])) { $_POST['person_id'] = ''; $Ajax->activate('pmt_header'); $Ajax->activate('code_id'); @@ -49,7 +51,7 @@ function employee_bank_header(&$order) { hidden('PayType'); employee_list_row(_("Pay To:")." ", 'emp_id', null, _("Select Employee"), true, false, false); - switch ($_POST['PayType']) { + switch($_POST['PayType']) { case PT_MISC : text_row_ex($payment ?_("To the Order of:"):_("Name:"), 'person_id', 40, 50); break; @@ -57,17 +59,18 @@ function employee_bank_header(&$order) { table_section(3, "33%"); - if (!$order->order_id && !get_post('bank_account')) { - if ($_POST['PayType'] == PT_CUSTOMER) + if(!$order->order_id && !get_post('bank_account')) { + + if($_POST['PayType'] == PT_CUSTOMER) $_POST['bank_account'] = get_default_customer_bank_account($_POST['person_id']); - elseif ($_POST['PayType'] == PT_SUPPLIER) + elseif($_POST['PayType'] == PT_SUPPLIER) $_POST['bank_account'] = get_default_supplier_bank_account($_POST['person_id']); else unset($_POST['bank_account']); } bank_accounts_list_row( $payment ? _("From:") : _("Into:"), 'bank_account', null, true); - if ($payment) + if($payment) bank_balance_row($_POST['bank_account']); if(!isset($_GET['PaymentAdvice']) && !isset($_POST['PaymentAdvice']) && !isset($_GET['NewAdvance']) && empty($_POST['NewAdvance'])) @@ -83,7 +86,7 @@ function employee_bank_header(&$order) { exchange_rate_display(get_company_currency(), $bank_currency, $_POST['date_']); - if (list_updated('emp_id')) { + if(list_updated('emp_id')) { $order->clear_items(); unset($_POST['totamount']); @@ -94,7 +97,7 @@ function employee_bank_header(&$order) { $order->payslip_no = 0; } - if (list_updated('for_payslip')) { + if(list_updated('for_payslip')) { $order->clear_items(); $_POST['memo_'] = ''; @@ -145,30 +148,31 @@ function display_bank_gl_items($title, &$order) { div_start('items_table'); start_table(TABLESTYLE, "width='95%'"); - if ($dim == 2) + if($dim == 2) $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1", _("Dimension")." 2", _("Amount"), _("Memo"), ""); - elseif ($dim == 1) + elseif($dim == 1) $th = array(_("Account Code"), _("Account Description"), _("Dimension"), _("Amount"), _("Memo"), ""); else $th = array(_("Account Code"), _("Account Description"), _("Amount"), _("Memo"), ""); - if (count($order->gl_items)) $th[] = ''; + if(count($order->gl_items)) $th[] = ''; table_header($th); $k = 0; $id = find_submit('Edit'); foreach ($order->gl_items as $line => $item) { - if ($id != $line) { + + if($id != $line) { alt_table_row_color($k); label_cell($item->code_id); label_cell($item->description); - if ($dim >= 1) + if($dim >= 1) label_cell(get_dimension_string($item->dimension_id, true)); - if ($dim > 1) + if($dim > 1) label_cell(get_dimension_string($item->dimension2_id, true)); - if ($order->trans_type == ST_BANKDEPOSIT) + if($order->trans_type == ST_BANKDEPOSIT) amount_cell(-$item->amount, false, '', 'item_amount'); else amount_cell($item->amount, false, '', 'item_amount'); @@ -182,10 +186,7 @@ function display_bank_gl_items($title, &$order) { gl_edit_item_controls($order, $dim, $line); } - //if ($id == -1) - //gl_edit_item_controls($order, $dim); - - if ($order->count_gl_items()) + if($order->count_gl_items()) label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()), "colspan=" . $colspan . " align=right", "align=right id='payment_total_amt'", 3); end_table(); @@ -201,16 +202,17 @@ function show_employee_advances($emp_id) { $k = $total_allocated = 0; $advances = get_employee_advances($emp_id); - if (db_num_rows($advances) > 0) { + if(db_num_rows($advances) > 0) { display_heading(sprintf(_("Allocated amounts in %s:"), get_company_pref('curr_default'))); start_table(TABLESTYLE, "width='60%'"); $th = array(_("Transaction Type"), _("#"), _("Ref"), _("Date"), _("Amount"), _("Other Allocations"), _("Left to Allocate"), _("This Allocation"),'',''); table_header($th); - foreach ($advances as $row) { + foreach($advances as $row) { $id = $row['id']; - if (floatcmp(abs($row['pay_amount']), $row['amt_allocated'])) { + + if(floatcmp(abs($row['pay_amount']), $row['amt_allocated'])) { alt_table_row_color($k); label_cell($systypes_array[$row['trans_type']]); label_cell(get_trans_view_str($row['trans_type'], $row['trans_no']), "nowrap align='right'"); @@ -219,11 +221,9 @@ function show_employee_advances($emp_id) { amount_cell(abs($row['pay_amount'])); amount_cell($row['amt_allocated']); - //$_POST['amount' . $id] = price_format($un_allocated); - $un_allocated = round((abs($row['pay_amount']) - $row['amt_allocated']), 6); amount_cell($un_allocated, false,'', 'maxval'.$id); - amount_cells(null, "amount" . $id);//, input_num('amount' . $id)); + amount_cells(null, "amount" . $id); label_cell(""._("All").""); label_cell(""._("None")."".hidden("un_allocated" . $id, price_format($un_allocated), false)); end_row(); diff --git a/includes/ui/employee_ui.inc b/includes/ui/employee_ui.inc index dc48547..0aa0070 100644 --- a/includes/ui/employee_ui.inc +++ b/includes/ui/employee_ui.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/includes/ui/job_position_ui.inc b/includes/ui/job_position_ui.inc new file mode 100644 index 0000000..0b3ef4f --- /dev/null +++ b/includes/ui/job_position_ui.inc @@ -0,0 +1,40 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +function position_list($name, $id = null, $spec_option = false, $submit_on_change = false, $show_inactive = false) { + $sql = "SELECT position_id, position_name, inactive FROM ".TB_PREF."position "; + + return combo_input($name, $id, $sql, 'position_id', 'position_name', + array( + 'spec_option' => $spec_option, + 'select_submit' => $submit_on_change, + 'async' => false, + 'show_inactive' => $show_inactive + )); +} + +//-------------------------------------------------------------------------- + +function position_list_cells($label, $name, $id = null, $all_option = false, $submit_on_change = false, $show_inactive = false) { + if ($label != null) + echo "$label\n"; + echo ""; + echo position_list($name, $id, $all_option, $submit_on_change, $show_inactive); + echo "\n"; +} + +//-------------------------------------------------------------------------- + +function position_list_row($label, $name, $id = null, $all_option = false, $submit_on_change = false, $show_inactive = false) { + echo "$label"; + position_list_cells(null, $name, $id, $all_option, $submit_on_change, $show_inactive); + echo ""; +} \ No newline at end of file diff --git a/includes/ui/leave_ui.inc b/includes/ui/leave_ui.inc new file mode 100644 index 0000000..0f92670 --- /dev/null +++ b/includes/ui/leave_ui.inc @@ -0,0 +1,40 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +function leave_types_list($name, $id = null, $spec_option = false, $submit_on_change = false, $show_inactive = false) { + $sql = "SELECT leave_id, leave_name, inactive FROM ".TB_PREF."leave_type "; + + return combo_input($name, $id, $sql, 'leave_id', 'leave_name', + array( + 'spec_option' => $spec_option, + 'select_submit' => $submit_on_change, + 'async' => false, + 'show_inactive' => $show_inactive + )); +} + +//-------------------------------------------------------------------------- + +function leave_types_list_cells($label, $name, $id = null, $all_option = false, $submit_on_change = false, $show_inactive = false) { + if($label != null) + echo "$label\n"; + echo ""; + echo leave_types_list($name, $id, $all_option, $submit_on_change, $show_inactive); + echo "\n"; +} + +//-------------------------------------------------------------------------- + +function leave_types_list_row($label, $name, $id = null, $all_option = false, $submit_on_change = false, $show_inactive = false) { + echo "$label"; + leave_types_list_cells(null, $name, $id, $all_option, $submit_on_change, $show_inactive); + echo ""; +} \ No newline at end of file diff --git a/includes/ui/overtime_ui.inc b/includes/ui/overtime_ui.inc index ce7cd33..a272252 100644 --- a/includes/ui/overtime_ui.inc +++ b/includes/ui/overtime_ui.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -35,7 +35,6 @@ function overtime_list_cells($label, $name, $id = null, $all_option = false, $su function overtime_list_row($label, $name, $id = null, $all_option = false, $submit_on_change = false, $show_inactive = false) { echo "$label"; - overtime_list_cells(null, $name, $id, $all_option, - $submit_on_change, $show_inactive); + overtime_list_cells(null, $name, $id, $all_option, $submit_on_change, $show_inactive); echo ""; } \ No newline at end of file diff --git a/includes/ui/payslip_ui.inc b/includes/ui/payslip_ui.inc index 1bcd994..7b02fcf 100644 --- a/includes/ui/payslip_ui.inc +++ b/includes/ui/payslip_ui.inc @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -44,46 +44,45 @@ function display_payslip_header(&$Order) { start_outer_table(TABLESTYLE2, "cellpadding='10'"); table_section(1); - date_row(_('Date').': ', 'date_', '', $new); - ref_row(_('Reference').':', 'ref', ''); - - table_section(3); - date_row(_('From Date').':', 'from_date', '', $new, 0, 0, 0, null, true); - date_row(_('To Date').':', 'to_date', '', $new, 0, 0, 0, null, true); + date_row(_('Date:'), 'date_', '', $new); + ref_row(_('Reference:'), 'ref', ''); + date_row(_('From:'), 'from_date', _('Pay From'), null, -30, 0, 0, null, true); + date_row(_('To:'), 'to_date', _('Pay To'), null, 0, 0, 0, null, true); table_section(2); hidden('PayType', PT_EMPLOYEE); - employee_list_row(_('Pay To').': ', 'person_id', null, _("Select employee"), true, false); + employee_list_row(_('Pay To:'), 'person_id', null, _("Select employee"), true, false); if(!isset($_POST['PaySlipNo'])) $_POST['PaySlipNo'] = get_next_payslip_no(); hidden('PaySlipNo', $_POST['PaySlipNo']); if(isset($_POST['person_id']) && $_POST['person_id'] != 0) - label_row(_('Pay Basis').':', $Order->pay_basis == 0 ? _('Monthly salary') : _('Daily wages')); - label_row(_('Payslip No').':', $_POST['PaySlipNo']); + label_row(_('Pay Basis:'), $Order->pay_basis == 0 ? _('Monthly salary') : _('Daily wages')); + label_row(_('Payslip No:'), $_POST['PaySlipNo']); - table_section(4); - - $from = $_POST['from_date']; + table_section(3); + $from = $_POST['from_date']; $to = $_POST['to_date']; $ot = db_query(get_overtime()); - if($_POST['person_id'] != '') { + if(!empty($_POST['person_id'])) { $emp_id = $_POST['person_id']; $workdays = get_workdays_no($from, $to, $emp_id); $leave_hours = get_leave_hours($from, $to, $emp_id); - label_row(_('Work days').':', $workdays.' '._('days')); - label_row(_('Leave hours').':', $leave_hours.' '._('hours')); + $day_txt = $workdays > 1 ? _('days') : _('day'); + $hour_txt = $leave_hours > 1 ? _('hours') : _('hour'); + label_row(_('Work days:'), $workdays.' '.$day_txt); + label_row(_('Leave hours:'), $leave_hours.' '.$hour_txt); while($row = db_fetch($ot)) { $hours_no = 0; foreach(get_ot_from_date_range($from, $to, $emp_id, $row['overtime_id']) as $hours) { $hours_no += $hours['hours_no']; - //$total_ot += $hours['hours_no']; } - label_row($row['overtime_name'].':', $hours_no.' '._('hours')); + $ot_txt = $hours_no > 1 ? _('hours') : _('hour'); + label_row($row['overtime_name'].':', $hours_no.' '.$ot_txt); } hidden('leaves', $leave_hours); hidden('deductableleaves', $Work_days - $workdays); @@ -91,14 +90,30 @@ function display_payslip_header(&$Order) { } else { $emp_id = ''; - label_row(_('Work days').':', ''); - label_row(_('Leave hours').':', ''); + label_row(_('Work days:'), ''); + label_row(_('Leave hours:'), ''); while($row = db_fetch($ot)) { label_row($row['overtime_name'], ''); } } + + table_section(4); + $leave_types = db_query(get_leave_type()); - if (list_updated('person_id')) + if(!empty($_POST['person_id'])) { + foreach($leave_types as $row) { + $leave_days = get_employee_leave($_POST['person_id'], $row['leave_id'], $from, $to); + $txt = $leave_days > 1 ? _('days') : _('day'); + label_row($row['leave_name'].':', $leave_days.' '.$txt); + } + } + else { + foreach($leave_types as $row) { + label_row($row['leave_name'].':', ''); + } + } + + if(list_updated('person_id')) $Order->clear_items(); end_outer_table(); @@ -111,21 +126,23 @@ function generate_gl_items($Order) { global $Ajax, $Payable_act, $Deduct_act, $Overtime_act, $Work_hours, $Work_days, $USE_DEPT_ACC; $emp_id = $_POST['person_id']; - $salary_scale = get_employees($emp_id)['salary_scale_id']; + $position = get_employees($emp_id)['position_id']; $from_date = $_POST['from_date']; $to_date = $_POST['to_date']; $workdays = get_workdays_no($from_date, $to_date, $emp_id); $total_ot = 0; $Order->clear_items(); - $totalCredit = $totalDebit = 0; + $totalCredit = 0; + $totalDebit = 0; $payable_amount = 0; $Order->empty_payment = false; - $Order->pay_basis = get_salary_scale($salary_scale)['pay_basis']; + $Order->pay_basis = get_position($position)['pay_basis']; $allowance = array(); $salary_rules = get_emp_salary_structure($emp_id); - $salary_amount = get_emp_basic_salary($emp_id)['pay_amount']; - $salary_basic_acc = get_emp_basic_salary($emp_id)['pay_rule_id']; + $emp_salary = get_emp_basic_salary($emp_id); + $salary_amount = $emp_salary['pay_amount']; + $salary_basic_acc = $emp_salary['pay_rule_id']; $emp_row = get_employees($emp_id); $emp_dept = $emp_row['department_id']; @@ -140,6 +157,13 @@ function generate_gl_items($Order) { $leave_hours_amount = ($salary_amount/$Work_days)/$Work_hours * $leave_hours; $leave_deduct_amount = (($salary_amount/$Work_days)*$deductableleaves) + $leave_hours_amount; + $paid_leaves = get_leave($emp_id, false, $from_date, $to_date); + + foreach($paid_leaves as $row) { + $row_leave_amt = ($salary_amount/$Work_days)*($row['pay_rate']/100); + $leave_deduct_amount -= $row_leave_amt; + } + if(db_num_rows($salary_rules) > 0) { if(!empty($USE_DEPT_ACC) && empty($emp_dept)) { @@ -276,7 +300,7 @@ function generate_gl_items($Order) { $Order->overtime_amt = abs($overtime_amount); if(($workdays == 0 && $total_ot == 0) || $payable_amount == 0) { - display_warning(_('non-working period')); + display_warning(sprintf(_('non-working period of staff #%d'), $emp_id)); $Order->clear_items(); set_focus('from_date'); } @@ -297,31 +321,31 @@ function display_gl_items($title, &$order) { div_start('items_table'); start_table(TABLESTYLE, "width='80%'"); - if ($dim == 2) + if($dim == 2) $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1", _("Dimension")." 2", _("Debit"), _("Credit"), _("Memo"), ""); - else if ($dim == 1) + elseif($dim == 1) $th = array(_("Account Code"), _("Account Description"), _("Dimension"), _("Debit"), _("Credit"), _("Memo"), ""); else $th = array(_("Account Code"), _("Account Description"), _("Debit"), _("Credit"), _("Memo"), ""); - if (count($order->gl_items)) $th[] = ''; + if(count($order->gl_items)) $th[] = ''; table_header($th); $k = 0; $id = find_submit('Edit'); - foreach ($order->gl_items as $line => $item) { + foreach($order->gl_items as $line => $item) { - if ($id != $line) { + if($id != $line) { alt_table_row_color($k); label_cells($item->code_id, $item->description); - if ($dim >= 1) + if($dim >= 1) label_cell(get_dimension_string($item->dimension_id, true)); - if ($dim > 1) + if($dim > 1) label_cell(get_dimension_string($item->dimension2_id, true)); - if ($item->amount > 0) { + if($item->amount > 0) { amount_cell(abs($item->amount)); label_cell(""); } @@ -335,14 +359,11 @@ function display_gl_items($title, &$order) { delete_button_cell("Delete$line", _("Delete"), _('Remove line from journal')); end_row(); } - else { + else gl_edit_item_controls($order, $dim, $line); - } } - //if ($id == -1) - //gl_edit_item_controls($order, $dim); - if ($order->count_gl_items()!=null) { + if($order->count_gl_items()!=null) { $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2")); start_row(); label_cell(_("Total Salary"), "align=right colspan=" . $colspan); @@ -359,16 +380,18 @@ function display_gl_items($title, &$order) { function gl_edit_item_controls(&$order, $dim, $Index=null) { global $Ajax; + start_row(); $id = find_submit('Edit'); - if ($Index != -1 && $Index == $id) { + if($Index != -1 && $Index == $id) { // Modifying an existing row $item = $order->gl_items[$Index]; $_POST['code_id'] = $item->code_id; $_POST['dimension_id'] = $item->dimension_id; $_POST['dimension2_id'] = $item->dimension2_id; - if ($item->amount > 0) { + + if($item->amount > 0) { $_POST['AmountDebit'] = price_format($item->amount); $_POST['AmountCredit'] = ""; } @@ -382,9 +405,9 @@ function gl_edit_item_controls(&$order, $dim, $Index=null) { hidden('Index', $id); $skip_bank = !$_SESSION["wa_current_user"]->can_access('SA_BANKJOURNAL'); echo gl_all_accounts_list('code_id', null, $skip_bank, true); - if ($dim >= 1) + if($dim >= 1) dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1); - if ($dim > 1) + if($dim > 1) dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2); $Ajax->activate('items_table'); } @@ -394,18 +417,17 @@ function gl_edit_item_controls(&$order, $dim, $Index=null) { $_POST['AmountCredit'] = ''; //price_format(0); $_POST['dimension_id'] = 0; $_POST['dimension2_id'] = 0; - //$_POST['LineMemo'] = ""; // let memo go to next line Joe Hunt 2010-05-30 $_POST['_code_id_edit'] = ""; $_POST['code_id'] = ""; - if(isset($_POST['_code_id_update'])) { + + if(isset($_POST['_code_id_update'])) $Ajax->activate('code_id'); - } $skip_bank = !$_SESSION["wa_current_user"]->can_access('SA_BANKJOURNAL'); echo gl_all_accounts_list('code_id', null, $skip_bank, true); - if ($dim >= 1) + if($dim >= 1) dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1); - if ($dim > 1) + if($dim > 1) dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2); } @@ -418,11 +440,9 @@ function gl_edit_item_controls(&$order, $dim, $Index=null) { small_amount_cells(null, 'AmountCredit'); text_cells_ex(null, 'LineMemo', 35, 255); - if ($id != -1) { - button_cell('UpdateItem', _("Update"), - _('Confirm changes'), ICON_UPDATE); - button_cell('CancelItemChanges', _("Cancel"), - _('Cancel changes'), ICON_CANCEL); + if($id != -1) { + button_cell('UpdateItem', _("Update"), _('Confirm changes'), ICON_UPDATE); + button_cell('CancelItemChanges', _("Cancel"), _('Cancel changes'), ICON_CANCEL); set_focus('amount'); } else @@ -434,10 +454,9 @@ function gl_edit_item_controls(&$order, $dim, $Index=null) { //-------------------------------------------------------------------------- function gl_options_controls() { - echo "
"; + echo "
"; textarea_row(_("Memo"), 'memo_', null, 50, 3); - echo "
"; } @@ -447,7 +466,7 @@ function gl_options_controls() { function _format_emp_payslip($row) { - return "Trans# ".$row['type_no'] ." - ". $row['scale_name']; + return "Trans# ".$row['type_no'] ." - ". $row['position_name']; } //-------------------------------------------------------------------------- @@ -478,11 +497,10 @@ function _format_payslip_date($row) { function employee_payslip_list_cells($label, $name, $selected_id = null, $employee_id, $all_option = false, $submit_on_change = false, $show_inactive = false) { - if ($label != null) + if($label != null) echo "$label\n"; echo ""; - echo employee_payslip_list($name, $selected_id, $employee_id, $all_option, $submit_on_change, - $show_inactive); + echo employee_payslip_list($name, $selected_id, $employee_id, $all_option, $submit_on_change, $show_inactive); echo "\n"; } @@ -501,7 +519,7 @@ function hrm_print_link($doc_no, $link_text, $link=true, $type_no, $icon=false, global $path_to_root; $def_orientation = (user_def_print_orientation() == 1 ? 1 : 0); - $dir = $path_to_root . "/modules/FrontHrm/reporting/redirect.php?"; + $dir = $path_to_root.'/modules/FrontHrm/reporting/redirect.php?'; switch ($type_no) { diff --git a/inquiry/emp_inquiry.php b/inquiry/emp_inquiry.php index 459be07..ce3e406 100644 --- a/inquiry/emp_inquiry.php +++ b/inquiry/emp_inquiry.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/inquiry/time_sheet.php b/inquiry/time_sheet.php index 32e766e..8083626 100644 --- a/inquiry/time_sheet.php +++ b/inquiry/time_sheet.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -64,6 +64,7 @@ $sql = get_attendance($_POST['FromDate'], $_POST['ToDate'], $_POST['EmpId'], $_POST['DeptId'], $_POST['OvertimeId']); $table = & new_db_pager('emp_att_tbl', $sql, $cols); $table->width = '95%'; +$table->page_len = 50; display_db_pager($table); end_form(); diff --git a/js/emp_payalloc.js b/js/emp_payalloc.js index 9fd8fe2..ff9077b 100644 --- a/js/emp_payalloc.js +++ b/js/emp_payalloc.js @@ -1,7 +1,8 @@ + /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/manage/accounts.php b/manage/accounts.php index 28e4400..427dc66 100644 --- a/manage/accounts.php +++ b/manage/accounts.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -21,35 +21,43 @@ //-------------------------------------------------------------------------- -page(_($help_context = 'Manage Payroll Accounts')); +page(_($help_context = 'Manage Pay Elements')); simple_page_mode(false); -if ($Mode=='ADD_ITEM') { +if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { $input_error = 0; - if (payroll_account_exist($_POST['AccountId'])) { + if(empty(trim($_POST['element_name']))) { + $input_error = 1; + display_error(_('Element Name cannot be empty.')); + set_focus('element_name'); + } + elseif(payroll_account_exist($_POST['AccountId']) && $Mode=='ADD_ITEM') { $input_error = 1; - display_error(_('Selected account has been used')); + display_error(_('Selected account has already exists.')); set_focus('AccountId'); } - if (strlen($_POST['AccountId']) == 0 || $_POST['AccountId'] == '') { - $input_error = 1; - display_warning(_('Select account first.')); - set_focus('AccountId'); - } - if ($input_error !=1) { - add_payroll_account($_POST['AccountId']); - display_notification(_('Account has been added.')); + if($input_error != 1) { + + if($selected_id == '') { + add_pay_element($_POST['element_name'], $_POST['AccountId']); + display_notification(_('Pay element has been added.')); + } + else { + update_pay_element($selected_id, $_POST['element_name']); + display_notification(_('The selected pay element has been updated.')); + } + $Mode = 'RESET'; } } //-------------------------------------------------------------------------- -if ($Mode == 'Delete') { +if($Mode == 'Delete') { - if (payroll_account_used($selected_id)) { + if(payroll_account_used($selected_id)) { display_error(_('Cannot delete this account because payroll rules have been created using it.')); } else { @@ -59,27 +67,32 @@ $Mode = 'RESET'; } -if ($Mode == 'RESET') - $selected_id = $_POST['AccountId'] = ''; +if($Mode == 'RESET') { + $selected_id = ''; + $_POST['AccountId'] = ''; + $_POST['element_name'] = ''; +} //-------------------------------------------------------------------------- -$result = get_payroll_accounts(); +$result = get_payroll_elements(); start_form(); start_table(TABLESTYLE2); -$th = array(_('Account Code'), _('Account Name'), ''); +$th = array(_('Element'), _('Account Code'), _('Account Name'), '', ''); table_header($th); $k = 0; -while ($myrow = db_fetch($result)) { +while($myrow = db_fetch($result)) { alt_table_row_color($k); - label_cell($myrow['account_code']); + label_cell($myrow['element_name']); + label_cell($myrow['account_code'], "align='center'"); label_cell($myrow['account_name']); - delete_button_cell('Delete'.$myrow['account_id'], _('Delete')); + edit_button_cell('Edit'.$myrow['element_id'], _('Edit')); + delete_button_cell('Delete'.$myrow['element_id'], _('Delete')); end_row(); } @@ -90,14 +103,22 @@ start_table(TABLESTYLE_NOBORDER); -gl_all_accounts_list_cells(null, 'AccountId', null, false, false, - _('Select account'), true, check_value('show_inactive')); - check_cells(_('Show inactive').':', 'show_inactive', null, true); +if($selected_id != -1) { + + if($Mode == 'Edit') { + $myrow = get_payroll_elements($selected_id); + $_POST['element_name'] = $myrow['element_name']; + $_POST['AccountId'] = $myrow['account_code']; + } + hidden('selected_id', $selected_id); +} + +text_row_ex(_('Element Name:'), 'element_name', 37, 50); +gl_all_accounts_list_row(_('Select Account:'), 'AccountId', null, true); end_table(1); submit_add_or_update_center($selected_id == '', '', 'both'); end_form(); - end_page(); \ No newline at end of file diff --git a/manage/attendance.php b/manage/attendance.php index d309cc8..cbe8483 100644 --- a/manage/attendance.php +++ b/manage/attendance.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -53,18 +53,24 @@ function can_process() { } foreach(db_query(get_employees(false, false, get_post('DeptId'))) as $emp) { + + $emp_id = $emp['emp_id']; + $err = _('Attendance input data must be greater than 0, less than 24 hours and formatted in HH:MM or Integer, example - 02:25 , 2:25, 8, 23:59 ...'); - if(strlen($_POST[$emp['emp_id'].'-0']) != 0 && (!preg_match("/^(?(?=\d{2})(?:2[0-3]|[01][0-9])|[0-9]):[0-5][0-9]$/", $_POST[$emp['emp_id'].'-0']) && (!is_numeric($_POST[$emp['emp_id'].'-0']) || $_POST[$emp['emp_id'].'-0'] >= 24))) { - display_error(_('Attendance input data must be less than 24 hours and formatted in HH:MM or Integer, example - 02:25 , 2:25, 8, 23:59 ...')); - set_focus($emp['emp_id'].'-0'); + if(strlen($_POST[$emp_id.'-0']) != 0 && (!preg_match("/^(?(?=\d{2})(?:2[0-3]|[01][0-9])|[0-9]):[0-5][0-9]$/", $_POST[$emp_id.'-0']) && (!is_numeric($_POST[$emp_id.'-0']) || $_POST[$emp_id.'-0'] >= 24 || $_POST[$emp_id.'-0'] <= 0)) && empty($_POST[$emp_id.'-leave'])) { + + display_error($err); + set_focus($emp_id.'-0'); return false; } foreach(db_query(get_overtime()) as $ot) { + + $ot_id = $ot['overtime_id']; - if(strlen($_POST[$emp['emp_id'].'-'.$ot['overtime_id']]) != 0 && (!preg_match("/^(?(?=\d{2})(?:2[0-3]|[01][0-9])|[0-9]):[0-5][0-9]$/", $_POST[$emp['emp_id'].'-'.$ot['overtime_id']]) && (!is_numeric($_POST[$emp['emp_id'].'-'.$ot['overtime_id']]) || $_POST[$emp['emp_id'].'-'.$ot['overtime_id']] >= 24))) { + if(strlen($_POST[$emp_id.'-'.$ot_id]) != 0 && (!preg_match("/^(?(?=\d{2})(?:2[0-3]|[01][0-9])|[0-9]):[0-5][0-9]$/", $_POST[$emp_id.'-'.$ot_id]) && (!is_numeric($_POST[$emp_id.'-'.$ot_id]) || $_POST[$emp_id.'-'.$ot_id] >= 24 || $_POST[$emp_id.'-0'] <= 0)) && empty($_POST[$emp_id.'-leave'])) { - display_error(_('Attendance input data must be less than 24 hours and formatted in HH:MM or Integer, example - 02:25 , 2:25, 8, 23:59 ...')); - set_focus($emp['emp_id'].'-'.$ot['overtime_id']); + display_error($err); + set_focus($emp_id.'-'.$ot_id); return false; } } @@ -72,7 +78,7 @@ function can_process() { return true; } -function write_attendance_range($emp_id, $time_type, $value, $rate, $from, $to) { +function write_attendance_range($emp_id, $time_type, $value=0, $rate, $from, $to, $leave=false) { $from = date2sql($from); $to = date2sql($to); @@ -85,7 +91,7 @@ function write_attendance_range($emp_id, $time_type, $value, $rate, $from, $to) foreach ($period as $dt) { $day = $dt->format("Y-m-d"); $day = sql2date($day); - write_attendance($emp_id, $time_type, $value, $rate, $day); + write_attendance($emp_id, $time_type, $value, $rate, $day, $leave); } } @@ -134,6 +140,7 @@ function check_paid_in_range($emp_id, $from, $to) { $overtime_id[$k] = $overtime['overtime_id']; $k++; } +$remaining_cols[] = _('Leave Type'); $th = array_merge($initial_cols, $remaining_cols); $employees = db_query(get_employees(false, false, get_post('DeptId'))); @@ -166,11 +173,12 @@ function check_paid_in_range($emp_id, $from, $to) { text_cells(null, $name1, null, 10, 10); $i=0; - while($i < count($remaining_cols)) { + while($i < count($remaining_cols) - 1) { $name2 = $employee['emp_id'].'-'.$overtime_id[$i]; text_cells(null, $name2, null, 10, 10); $i++; } + leave_types_list_cells(null, $employee['emp_id'].'-leave', null, _('Select Leave Type'), true); end_row(); } @@ -193,32 +201,30 @@ function check_paid_in_range($emp_id, $from, $to) { if($_POST[$emp_id.'-0'] && check_paid_in_range($emp_id, $_POST['from_date'], $_POST['to_date'])) { - display_error(_('The selected date range includes a date that has been approved, cannot be updated.')); + display_error(_('The selected date range includes a date that has been approved, please select another date range.')); set_focus('from_date'); exit(); } + elseif(!empty($_POST[$emp_id.'-leave'])) { + $emp_leave = $_POST[$emp_id.'-leave']; + $leave_rate = get_leave_type($emp_leave)['pay_rate']; + $att_items ++; + write_attendance_range($emp_id, 0, 0, $leave_rate, $_POST['from_date'], $_POST['to_date'], $emp_leave); + } else { + if(strlen($_POST[$emp_id.'-0']) > 0) $att_items ++; write_attendance_range($emp_id, 0, time_to_float($_POST[$emp_id.'-0']), 1, $_POST['from_date'], $_POST['to_date']); - } - - foreach($overtime_id as $ot) { - - if($_POST[$emp_id.'-0'] && check_date_paid($emp_id, $_POST['from_date'])){ - - display_error(_('Selected date has already paid for Employee ').$emp_id); - set_focus($emp_id.'-'.$ot); - exit(); - } - else { + + foreach($overtime_id as $ot) { $rate = get_overtime($ot)['overtime_rate']; if(strlen($_POST[$emp_id.'-'.$ot]) > 0) - $att_items ++; + $att_items ++; write_attendance_range($emp_id, $ot, time_to_float($_POST[$emp_id.'-'.$ot]), $rate, $_POST['from_date'], $_POST['to_date']); - } - } + } + } } if($att_items > 0) display_notification(_('Attendance has been saved.')); @@ -228,4 +234,4 @@ function check_paid_in_range($emp_id, $from, $to) { } end_form(); -end_page(); +end_page(); \ No newline at end of file diff --git a/manage/default_setup.php b/manage/default_setup.php index 1f95555..3fbf933 100644 --- a/manage/default_setup.php +++ b/manage/default_setup.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -22,6 +22,9 @@ include_once($path_to_root . '/includes/ui.inc'); include_once($path_to_root . '/admin/db/company_db.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_ui.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_db.inc'); + //-------------------------------------------------------------------------- function can_process() { @@ -36,6 +39,11 @@ function can_process() { set_focus('payroll_work_hours'); return false; } + if(!check_num('payroll_grades', max_grade_used())) { + display_error(sprintf(_("Grade %s is being used by employees, cannot select a lower grade"), max_grade_used())); + set_focus('payroll_grades'); + return false; + } return true; } @@ -44,7 +52,7 @@ function can_process() { if (isset($_POST['submit']) && can_process()) { - update_company_prefs(get_post(array('payroll_payable_act', 'payroll_deductleave_act', 'payroll_overtime_act', 'payroll_month_work_days', 'payroll_work_hours', 'payroll_dept_based'))); + update_company_prefs(get_post(array('payroll_payable_act', 'payroll_deductleave_act', 'payroll_overtime_act', 'payroll_month_work_days', 'payroll_work_hours', 'payroll_dept_based', 'payroll_grades'))); display_notification(_('The Payroll setup has been updated.')); } @@ -67,6 +75,7 @@ function can_process() { $_POST['payroll_month_work_days'] = $myrow['payroll_month_work_days']; $_POST['payroll_work_hours'] = $myrow['payroll_work_hours']; $_POST['payroll_dept_based'] = $myrow['payroll_dept_based']; +$_POST['payroll_grades'] = $myrow['payroll_grades']; table_section_title(_('General GL')); @@ -79,12 +88,13 @@ function can_process() { text_row(_('Work days per month').':', 'payroll_month_work_days', $_POST['payroll_month_work_days'], 6, 6, '', '', _('days')); text_row(_('Work hours per day').':', 'payroll_work_hours', $_POST['payroll_work_hours'], 6, 6, '', '', _('hours')); -table_section_title(_('Basic account type')); +table_section_title(_('Others')); check_row(_('Salary based on department').':', 'payroll_dept_based', $_POST['payroll_dept_based']); +number_list_row(_('Number of Grades').':', 'payroll_grades', null, 1, $max_grade_number); end_outer_table(1); submit_center('submit', _('Update'), true, '', 'default'); end_form(2); -end_page(); +end_page(); \ No newline at end of file diff --git a/manage/department.php b/manage/department.php index c8ecb78..0127cfb 100644 --- a/manage/department.php +++ b/manage/department.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -34,6 +34,10 @@ display_error( _('Please select basic account')); set_focus('basic_acc'); } + elseif(!empty($USE_DEPT_ACC) && !is_expenses_account($_POST['basic_acc'])) { + display_error(_('Salary Basic Account must be an expenses account.')); + set_focus('basic_acc'); + } else { write_department($selected_id, $_POST['name'], $_POST['basic_acc']); @@ -115,4 +119,4 @@ submit_add_or_update_center($selected_id == '', '', 'both'); end_form(); -end_page(); +end_page(); \ No newline at end of file diff --git a/manage/doc_type.php b/manage/doc_type.php index 274e20a..ea53aa4 100644 --- a/manage/doc_type.php +++ b/manage/doc_type.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/manage/employee.php b/manage/employee.php index eb1969f..043ff42 100644 --- a/manage/employee.php +++ b/manage/employee.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -17,9 +17,9 @@ add_access_extensions(); $js = ""; -if ($SysPrefs->use_popup_windows) +if($SysPrefs->use_popup_windows) $js .= get_js_open_window(900, 500); -if (user_use_date_picker()) +if(user_use_date_picker()) $js .= get_js_date_picker(); include_once($path_to_root . '/includes/ui.inc'); @@ -42,7 +42,7 @@ $upload_file = ""; $avatar_path = company_path().'/FrontHrm/images/'; -if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') { +if(isset($_FILES['pic']) && $_FILES['pic']['name'] != '') { $result = $_FILES['pic']['error']; $upload_file = 'Yes'; @@ -112,42 +112,46 @@ function can_process() { - if(strlen($_POST['EmpFirstName']) == 0 || $_POST['EmpFirstName'] == '') { - + if(strlen($_POST['emp_first_name']) == 0 || $_POST['emp_first_name'] == '') { display_error(_('The employee first name must be entered.')); - set_focus('EmpFirstName'); + set_focus('emp_first_name'); return false; } - if(strlen($_POST['EmpLastName']) == 0 || $_POST['EmpLastName'] == '') { - + if(strlen($_POST['emp_last_name']) == 0 || $_POST['emp_last_name'] == '') { display_error(_('Employee last name must be entered.')); - set_focus('EmpLastName'); + set_focus('emp_last_name'); return false; } - if(strlen($_POST['EmpEmail']) > 0 && !filter_var($_POST['EmpEmail'], FILTER_VALIDATE_EMAIL)) { - + if(strlen($_POST['emp_email']) > 0 && !filter_var($_POST['emp_email'], FILTER_VALIDATE_EMAIL)) { display_error(_('Invalid email.')); - set_focus('EmpEmail'); + set_focus('emp_email'); return false; } - if (!is_date($_POST['EmpBirthDate'])) { - - display_error( _('Invalid birth date.')); - set_focus('EmpBirthDate'); + if(!is_date($_POST['emp_birthdate'])) { + display_error(_('Invalid birth date.')); + set_focus('emp_birthdate'); return false; } - if (!is_date($_POST['EmpHireDate']) && $_POST['EmpHireDate'] != null && $_POST['EmpHireDate'] != '00/00/0000') { - - display_error( _('Invalid hire date.')); - set_focus('EmpHireDate'); + if(!is_date($_POST['emp_hiredate']) && $_POST['emp_hiredate'] != null && $_POST['emp_hiredate'] != '00/00/0000') { + display_error(_('Invalid hire date.')); + set_focus('emp_hiredate'); return false; } - if (get_post('EmpInactive') == 1) { - - if (!is_date($_POST['EmpReleaseDate'])) { - display_error( _('Invalid release date.')); - set_focus('EmpReleaseDate'); + if(!empty($_POST['personal_salary']) && !check_num('basic_amt', FLOAT_COMP_DELTA)) { + display_error(_('Basic salary amount must be a positive number')); + set_focus('basic_amt'); + return false; + } + if(!empty($_POST['personal_salary']) && empty($_POST['position_id'])) { + display_error(_("Staff's Job Position must be selected to use Personal Salary Structure")); + set_focus('position_id'); return false; + } + if(get_post('inactive') == 1) { + if(!is_date($_POST['emp_releasedate'])) { + display_error( _('Invalid release date.')); + set_focus('emp_releasedate'); + return false; } } return true; @@ -176,11 +180,11 @@ function get_name($row) { } function gender_name($row) { if($row['gender'] == 0) - return 'Female'; + return _('Female'); elseif($row['gender'] == 1) - return 'Male'; + return _('Male'); else - return 'Other'; + return _('Other'); } function emp_hired($row) { return ($row['emp_hiredate'] == '0000-00-00') ? _('Not hired') : '
'.sql2date($row['emp_hiredate']).'
'; @@ -191,7 +195,6 @@ function emp_department($row) { return _('Not selected'); else return get_departments($row['department_id'])['dept_name']; - } function employees_table() { @@ -199,12 +202,17 @@ function employees_table() { $_SESSION['EmpId'] = ''; if(db_has_employee()) { - $sql = get_employees(false, check_value('show_inactive'), get_post('DeptId')); + $sys_grades = get_company_pref('payroll_grades'); + $sql = get_employees(false, check_value('show_inactive'), get_post('DeptId'), false, get_post('position'), get_post('grade'), get_post('string')); start_table(TABLESTYLE_NOBORDER); start_row(); - department_list_cells(_('Department').':', 'DeptId', null, _('All departments'), true); - check_cells(_('Show resigned').':', 'show_inactive', null, true); + ref_cells(_("Enter Search String:"), 'string', _('Enter fragment or leave empty'), null, null, true); + department_list_cells(null, 'DeptId', null, _('All departments'), true); + position_list_cells(null, 'position', null, _('All Positions'), true); + number_list_cells(null, 'grade', null, 1, $sys_grades, _('All Grades'), true); + check_cells(_('Show resigned:'), 'show_inactive', null, true); + submit_cells('Search', _('Search'), '', '', 'default'); end_row(); end_table(1); @@ -222,8 +230,9 @@ function employees_table() { _('Department') => array('fun'=>'emp_department') ); - $table =& new_db_pager('student_tbl', $sql, $cols); + $table =& new_db_pager('emp_tbl', $sql, $cols); $table->width = "80%"; + $table->page_len = 50; // display_note(_('Press name to edit employee details.')); display_db_pager($table); @@ -239,29 +248,48 @@ function employee_settings($cur_id) { if($cur_id) { $employee = get_employees($cur_id, true); - $_POST['EmpFirstName'] = $employee['emp_first_name']; - $_POST['EmpLastName'] = $employee['emp_last_name']; - $_POST['EmpGender'] = $employee['gender']; - $_POST['EmpAddress'] = $employee['emp_address']; - $_POST['EmpMobile'] = $employee['emp_mobile']; - $_POST['EmpEmail'] = $employee['emp_email']; - $_POST['EmpBirthDate'] = sql2date($employee['emp_birthdate']); - $_POST['EmpNotes'] = $employee['emp_notes']; - $_POST['EmpHireDate'] = sql2date($employee['emp_hiredate']); - $_POST['DepartmentId'] = $employee['department_id']; - $_POST['EmpSalary'] = $employee['salary_scale_id']; - $_POST['EmpReleaseDate'] = sql2date($employee['emp_releasedate']); - $_POST['EmpInactive'] = $employee['inactive']; + $_POST['emp_first_name'] = $employee['emp_first_name']; + $_POST['emp_last_name'] = $employee['emp_last_name']; + $_POST['gender'] = $employee['gender']; + $_POST['emp_address'] = $employee['emp_address']; + $_POST['emp_mobile'] = $employee['emp_mobile']; + $_POST['emp_email'] = $employee['emp_email']; + $_POST['emp_birthdate'] = sql2date($employee['emp_birthdate']); + $_POST['national_id'] = $employee['national_id']; + $_POST['passport'] = $employee['passport']; + $_POST['bank_account'] = $employee['bank_account']; + $_POST['tax_number'] = $employee['tax_number']; + $_POST['emp_notes'] = $employee['emp_notes']; + $_POST['emp_hiredate'] = sql2date($employee['emp_hiredate']); + $_POST['department_id'] = $employee['department_id']; + $_POST['position_id'] = $employee['position_id']; + $_POST['grade_id'] = $employee['grade_id']; + $_POST['personal_salary'] = $employee['personal_salary']; + $_POST['emp_releasedate'] = sql2date($employee['emp_releasedate']); + $_POST['inactive'] = $employee['inactive']; + + if(!empty($employee['personal_salary'])) { + $emp_salary = get_emp_salary_structure($cur_id); + foreach($emp_salary as $pay_element) { + + $element_code = $pay_element['pay_rule_id']; + + if($pay_element['is_basic'] == 1) + $_POST['basic_amt'] = price_format($pay_element['pay_amount']); + else + $_POST['amt_'.$element_code] = price_format($pay_element['pay_amount']); + } + } } start_outer_table(TABLESTYLE2); table_section(1); hidden('emp_id'); - file_row(_('Image File').':', 'pic', 'pic'); + file_row(_('Image File:'), 'pic', 'pic'); $emp_img_link = ''; $check_remove_image = false; - if ($cur_id && file_exists($avatar_path.emp_img_name($cur_id).'.jpg')) { + if($cur_id && file_exists($avatar_path.emp_img_name($cur_id).'.jpg')) { $emp_img_link .= "[".$cur_id.".jpg".
 			"]"; @@ -271,54 +299,78 @@ function employee_settings($cur_id) { $emp_img_link .= ".jpg"; label_row(" ", $emp_img_link); - if ($check_remove_image) - check_row(_('Delete Image').':', 'del_image'); + if($check_remove_image) + check_row(_('Delete Image:'), 'del_image'); table_section_title(_('Personal Information')); if($cur_id) - label_row(_('Employee Id').':', $cur_id); - - text_row(_('First Name').':', 'EmpFirstName', get_post('EmpFirstName'), 37, 50); - text_row(_('Last Name').':', 'EmpLastName', get_post('EmpLastName'), 37, 50); - gender_radio_row(_('Gender').':', 'EmpGender', get_post('EmpGender')); - textarea_row(_('Address').':', 'EmpAddress', get_post('EmpAddress'), 35, 5); - text_row(_('Mobile').':', 'EmpMobile', get_post('EmpMobile'), 37, 30); - email_row(_('e-Mail').':', 'EmpEmail', get_post('EmpEmail'), 37, 100); - date_row(_('Birth Date').':', 'EmpBirthDate', null, null, 0, 0, -13); + label_row(_('Employee Id:'), $cur_id); + + text_row(_('First Name:'), 'emp_first_name', get_post('emp_first_name'), 37, 50); + text_row(_('Last Name:'), 'emp_last_name', get_post('emp_last_name'), 37, 50); + gender_radio_row(_('Gender:'), 'gender', get_post('gender')); + textarea_row(_('Address:'), 'emp_address', get_post('emp_address'), 35, 5); + text_row(_('Mobile:'), 'emp_mobile', get_post('emp_mobile'), 37, 30); + email_row(_('e-Mail:'), 'emp_email', get_post('emp_email'), 37, 100); + date_row(_('Birth Date:'), 'emp_birthdate', null, null, 0, 0, -18); table_section(2); + table_section_title(_('Personal Information')); + text_row(_('National ID:'), 'national_id', get_post('national_id'), 37, 50); + text_row(_('Passport:'), 'passport', get_post('passport'), 37, 50); + text_row(_('Bank Name/Account:'), 'bank_account', get_post('bank_account'), 37, 50); + text_row(_('Tax ID Number:'), 'tax_number', get_post('tax_number'), 37, 50); + table_section_title(_('Job Information')); - textarea_row(_('Notes').':', 'EmpNotes', null, 35, 5); - date_row(_('Hire Date').':', 'EmpHireDate', null, null, 0, 0, 1001); + textarea_row(_('Notes:'), 'emp_notes', null, 35, 5); + date_row(_('Hire Date:'), 'emp_hiredate', null, null, 0, 0, 1001); if($cur_id) { if($employee['emp_hiredate'] != '0000-00-00') - department_list_row(_('Department').':', 'DepartmentId', null, _('Select department')); + department_list_row(_('Department:'), 'department_id', null, _('Not selected')); else { - label_row(_('Department').':', _('Set hire date first')); - hidden('DepartmentId'); + label_row(_('Department:'), _('Set hire date first')); + hidden('department_id'); } } else - department_list_row(_('Department').':', 'DepartmentId', null, _('Select department')); + department_list_row(_('Department:'), 'department_id', null, _('Not selected')); - salaryscale_list_row(_('Salary').':', 'EmpSalary', null, _('Select salary scale')); + position_list_row(_('Job Position:'), 'position_id', null, _('Not selected')); + $sys_grades = get_company_pref('payroll_grades'); + number_list_row(_('Salary Grade:'), 'grade_id', null, 1, $sys_grades, _('Basic')); if($cur_id) { - check_row(_('Resigned').':', 'EmpInactive'); - date_row(_('Release Date').':', 'EmpReleaseDate', null, null, 0, 0, 1001); + check_row(_('Resigned:'), 'inactive'); + date_row(_('Release Date:'), 'emp_releasedate', null, null, 0, 0, 1001); } else{ - hidden('EmpInactive'); - hidden('EmpReleaseDate'); + hidden('inactive'); + hidden('emp_releasedate'); } + + table_section(3); + table_section_title(_('Pay Elements')); + + start_row(); + label_cell('(?)', "title='"._('Enter negative amount for deduction, positive for earning')."' align='right' colspan='2'"); + end_row(); + + yesno_list_row(_('Use Personal Salary Structure:'), 'personal_salary'); + + amount_row(_('Basic Salary Amount:'), 'basic_amt', null, null, null, null, true); + $elements = get_payroll_elements(); + while($row = db_fetch($elements)) { + amount_row($row['element_name'].':', 'amt_'.$row['account_code'], null, null, null, null, true); + } + end_outer_table(1); div_start('controls'); - if ($cur_id) { + if($cur_id) { submit_center_first('addupdate', _('Update Employee'), _('Update employee details'), 'default'); submit_return('select', get_post('emp_id'), _('Select this employee and return to document entry.')); @@ -332,28 +384,75 @@ function employee_settings($cur_id) { //-------------------------------------------------------------------------- -if (isset($_POST['addupdate'])) { +if(isset($_POST['addupdate'])) { if(!can_process()) return; + + if(!empty($_POST['personal_salary'])) + begin_transaction(); + write_employee( $cur_id, - $_POST['EmpFirstName'], - $_POST['EmpLastName'], - $_POST['EmpGender'], - $_POST['EmpAddress'], - $_POST['EmpMobile'], - $_POST['EmpEmail'], - $_POST['EmpBirthDate'], - $_POST['EmpNotes'], - $_POST['EmpHireDate'], - $_POST['DepartmentId'], - $_POST['EmpSalary'], - $_POST['EmpReleaseDate'], - $_POST['EmpInactive'] + $_POST['emp_first_name'], + $_POST['emp_last_name'], + $_POST['gender'], + $_POST['emp_address'], + $_POST['emp_mobile'], + $_POST['emp_email'], + $_POST['emp_birthdate'], + $_POST['national_id'], + $_POST['passport'], + $_POST['bank_account'], + $_POST['tax_number'], + $_POST['emp_notes'], + $_POST['emp_hiredate'], + $_POST['department_id'], + $_POST['position_id'], + $_POST['grade_id'], + $_POST['personal_salary'], + $_POST['emp_releasedate'], + $_POST['inactive'] ); - if (check_value('del_image')) { + if($cur_id) { + $emp_id = $cur_id; + $new = false; + } + else { + $emp_id = db_insert_id(); + $new = true; + } + + if(!empty($_POST['personal_salary'])) { + + $basic = get_position($_POST['position_id']); + $basic_acc = $basic['pay_rule_id']; + $pay_elements = array(); + $pay_elements[] = array( + 'emp_id' => $emp_id, + 'pay_rule_id' => $basic_acc, + 'pay_amount' => input_num('basic_amt'), + 'type' => DEBIT, + 'is_basic' => 1 + ); + + foreach($_POST as $p=>$val) { + if(substr($p, 0, 4) == 'amt_') { + $pay_elements[] = array( + 'emp_id' => $emp_id, + 'pay_rule_id' => substr($p, 4), + 'pay_amount' => $val, + 'type' => input_num($p) > 0 ? DEBIT : CREDIT, + 'is_basic' => 0 + ); + } + } + write_personal_salary_structure($pay_elements); + commit_transaction(); + } + + if(check_value('del_image')) { $filename = $avatar_path.emp_img_name($cur_id).".jpg"; if (file_exists($filename)) unlink($filename); @@ -363,11 +462,11 @@ function employee_settings($cur_id) { display_notification(_('Employee details has been updated.')); } else { - $_SESSION['EmpId'] = db_insert_id(); + $_SESSION['EmpId'] = $emp_id; $cur_id = $_SESSION['EmpId']; display_notification(_('A new employee has been added.')); } - + $Ajax->activate('_page_body'); } elseif(isset($_POST['delete'])) { diff --git a/manage/employee_bank_entry.php b/manage/employee_bank_entry.php index 60fbef4..e72311f 100644 --- a/manage/employee_bank_entry.php +++ b/manage/employee_bank_entry.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -79,7 +79,7 @@ //-------------------------------------------------------------------------------------------------- -check_db_has_bank_accounts(_("There are no bank accounts defined in the system.")); +check_db_has_bank_accounts(_('There are no bank accounts defined in the system.')); if (isset($_GET['ModifyDeposit']) || isset($_GET['ModifyPayment'])) check_is_editable($_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id); @@ -115,11 +115,11 @@ function line_start_focus() { display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Postings for this Payment"))); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Payment"), "NewPayment=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Payment"), 'NewPayment=yes'); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Deposit"), "NewDeposit=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Deposit"), 'NewDeposit=yes'); - hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"), "filterType=$trans_type&trans_no=$trans_no"); + hyperlink_params($path_to_root.'/admin/attachments.php', _('Add an Attachment'), "filterType=$trans_type&trans_no=$trans_no"); display_footer_exit(); } @@ -132,9 +132,9 @@ function line_start_focus() { display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Postings for this Payment"))); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Payment"), "NewPayment=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Payment"), 'NewPayment=yes'); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Deposit"), "NewDeposit=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _('Enter A &Deposit'), 'NewDeposit=yes'); display_footer_exit(); } @@ -145,11 +145,11 @@ function line_start_focus() { display_notification_centered(sprintf(_("Deposit %d has been entered"), $trans_no)); - display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Postings for this Deposit"))); + display_note(get_gl_view_str($trans_type, $trans_no, _('View the GL Postings for this Deposit'))); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Deposit"), "NewDeposit=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _('Enter Another Deposit'), 'NewDeposit=yes'); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter A Payment"), "NewPayment=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _('Enter A Payment'), 'NewPayment=yes'); display_footer_exit(); } @@ -161,9 +161,9 @@ function line_start_focus() { display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Postings for this Deposit"))); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Deposit"), "NewDeposit=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another &Deposit"), 'NewDeposit=yes'); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Payment"), "NewPayment=yes"); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter A &Payment"), 'NewPayment=yes'); display_footer_exit(); } @@ -182,12 +182,12 @@ function create_cart($type, $trans_no, $payslip=array()) { if ($trans_no) { $bank_trans = db_fetch(get_bank_trans($type, $trans_no)); - $_POST['bank_account'] = $bank_trans["bank_act"]; - $_POST['PayType'] = $bank_trans["person_type_id"]; - $cart->reference = $bank_trans["ref"]; + $_POST['bank_account'] = $bank_trans['bank_act']; + $_POST['PayType'] = $bank_trans['person_type_id']; + $cart->reference = $bank_trans['ref']; - if ($bank_trans["person_type_id"] == PT_MISC) - $_POST['person_id'] = $bank_trans["person_id"]; + if ($bank_trans['person_type_id'] == PT_MISC) + $_POST['person_id'] = $bank_trans['person_id']; $cart->memo_ = get_comments_string($type, $trans_no); $cart->tran_date = sql2date($bank_trans['trans_date']); @@ -244,13 +244,13 @@ function check_trans() { $input_error = 0; - if ($_SESSION['pay_items']->count_gl_items() < 1) { - display_error(_("You must enter at least one payment line.")); + if($_SESSION['pay_items']->count_gl_items() < 1) { + display_error(_('You must enter at least one payment line.')); set_focus('code_id'); $input_error = 1; } - if ($_SESSION['pay_items']->gl_items_total() == 0.0) { - display_error(_("The total bank amount cannot be 0.")); + if($_SESSION['pay_items']->gl_items_total() == 0.0) { + display_error(_('The total bank amount cannot be 0.')); set_focus('code_id'); $input_error = 1; } @@ -259,47 +259,47 @@ function check_trans() { $amnt_chg = -$_SESSION['pay_items']->gl_items_total()-$_SESSION['pay_items']->original_amount; - if ($limit !== null && floatcmp($limit, -$amnt_chg) < 0) { + if($limit !== null && floatcmp($limit, -$amnt_chg) < 0) { display_error(sprintf(_("The total bank amount exceeds allowed limit (%s)."), price_format($limit-$_SESSION['pay_items']->original_amount))); set_focus('code_id'); $input_error = 1; } - if ($trans = check_bank_account_history($amnt_chg, $_POST['bank_account'], $_POST['date_'])) { + if($trans = check_bank_account_history($amnt_chg, $_POST['bank_account'], $_POST['date_'])) { display_error(sprintf(_("The bank transaction would result in exceed of authorized overdraft limit for transaction: %s #%s on %s."), $systypes_array[$trans['type']], $trans['trans_no'], sql2date($trans['trans_date']))); set_focus('amount'); $input_error = 1; } - if (!check_reference($_POST['ref'], $_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id)) { + if(!check_reference($_POST['ref'], $_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id)) { set_focus('ref'); $input_error = 1; } - if (!is_date($_POST['date_'])) { - display_error(_("The entered date for the payment is invalid.")); + if(!is_date($_POST['date_'])) { + display_error(_('The entered date for the payment is invalid.')); set_focus('date_'); $input_error = 1; } - elseif (!is_date_in_fiscalyear($_POST['date_'])) { - display_error(_("The entered date is out of fiscal year or is closed for further data entry.")); + elseif(!is_date_in_fiscalyear($_POST['date_'])) { + display_error(_('The entered date is out of fiscal year or is closed for further data entry.')); set_focus('date_'); $input_error = 1; } - if (!get_post('for_payslip') && !get_post('NewAdvance')) { - display_error(_("You have to select a payslip.")); + if(!get_post('for_payslip') && !get_post('NewAdvance')) { + display_error(_('You have to select a payslip.')); set_focus('for_payslip'); $input_error = 1; } - if (!get_post('emp_id')) { - display_error(_("You have to select an employee.")); + if(!get_post('emp_id')) { + display_error(_('You have to select an employee.')); set_focus('emp_id'); $input_error = 1; } - if (!db_has_currency_rates(get_bank_account_currency($_POST['bank_account']), $_POST['date_'], true)) + if(!db_has_currency_rates(get_bank_account_currency($_POST['bank_account']), $_POST['date_'], true)) $input_error = 1; - if (isset($_POST['settled_amount']) && in_array(get_post('PayType'), array(PT_SUPPLIER, PT_CUSTOMER)) && (input_num('settled_amount') <= 0)) { - display_error(_("Settled amount have to be positive number.")); + if(isset($_POST['settled_amount']) && in_array(get_post('PayType'), array(PT_SUPPLIER, PT_CUSTOMER)) && (input_num('settled_amount') <= 0)) { + display_error(_('Settled amount have to be positive number.')); set_focus('person_id'); $input_error = 1; } @@ -316,8 +316,8 @@ function check_trans() { display_error(_('Pay amount have to be positive number.')); set_focus('advance_amount'); } - elseif (!get_post('emp_id')) { - display_error(_("You have to select an employee.")); + elseif(!get_post('emp_id')) { + display_error(_('You have to select an employee.')); set_focus('emp_id'); } else { @@ -363,6 +363,7 @@ function check_trans() { $trans_type = $trans[0]; $trans_no = $trans[1]; + if(!empty($trans[2]) && count($allocs)) { $trans_counter = $trans[2]; add_employee_allocations($trans_counter, $allocs); @@ -375,7 +376,7 @@ function check_trans() { commit_transaction(); - if ($new) + if($new) meta_forward($_SERVER['PHP_SELF'], $trans_type==ST_BANKPAYMENT ? "AddedID=$trans_no" : "AddedDep=$trans_no"); else meta_forward($_SERVER['PHP_SELF'], $trans_type==ST_BANKPAYMENT ? "UpdatedID=$trans_no" : "UpdatedDep=$trans_no"); @@ -385,13 +386,14 @@ function check_trans() { //----------------------------------------------------------------------------------------------- function check_item_data() { - if (!check_num('amount', 0)) { - display_error( _("The amount entered is not a valid number or is less than zero.")); + + if(!check_num('amount', 0)) { + display_error( _('The amount entered is not a valid number or is less than zero.')); set_focus('amount'); return false; } - if (isset($_POST['_ex_rate']) && input_num('_ex_rate') <= 0) { - display_error( _("The exchange rate cannot be zero or a negative number.")); + if(isset($_POST['_ex_rate']) && input_num('_ex_rate') <= 0) { + display_error( _('The exchange rate cannot be zero or a negative number.')); set_focus('_ex_rate'); return false; } @@ -402,22 +404,20 @@ function check_item_data() { //----------------------------------------------------------------------------------------------- function handle_update_item() { + $amount = ($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? 1:-1) * input_num('amount'); + if($_POST['UpdateItem'] != "" && check_item_data()) $_SESSION['pay_items']->update_gl_item($_POST['Index'], $_POST['code_id'], $_POST['dimension_id'], $_POST['dimension2_id'], $amount , $_POST['LineMemo']); line_start_focus(); } -//----------------------------------------------------------------------------------------------- - function handle_delete_item($id) { $_SESSION['pay_items']->remove_gl_item($id); line_start_focus(); } -//----------------------------------------------------------------------------------------------- - function handle_new_item() { if (!check_item_data()) return; @@ -429,15 +429,15 @@ function handle_new_item() { //----------------------------------------------------------------------------------------------- $id = find_submit('Delete'); -if ($id != -1) +if($id != -1) handle_delete_item($id); -if (isset($_POST['AddItem'])) +if(isset($_POST['AddItem'])) handle_new_item(); -if (isset($_POST['UpdateItem'])) +if(isset($_POST['UpdateItem'])) handle_update_item(); -if (isset($_POST['CancelItemChanges'])) +if(isset($_POST['CancelItemChanges'])) line_start_focus(); -if (isset($_POST['go'])) { +if(isset($_POST['go'])) { display_quick_entries($_SESSION['pay_items'], $_POST['person_id'], input_num('totamount'), $_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? QE_PAYMENT : QE_DEPOSIT); $_POST['totamount'] = price_format(0); $Ajax->activate('totamount'); line_start_focus(); @@ -472,5 +472,4 @@ function handle_new_item() { submit_center_last('Process', $_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? _("Process Payment"):_("Process Deposit"), '', 'default'); end_form(); - end_page(); \ No newline at end of file diff --git a/manage/employee_docs.php b/manage/employee_docs.php index c071386..9d4f1fa 100644 --- a/manage/employee_docs.php +++ b/manage/employee_docs.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/manage/grade.php b/manage/grade.php new file mode 100644 index 0000000..739da96 --- /dev/null +++ b/manage/grade.php @@ -0,0 +1,147 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +$page_security = 'SA_HRSETUP'; +$path_to_root = '../../..'; + +include_once($path_to_root . '/includes/session.inc'); +add_access_extensions(); + +include_once($path_to_root . '/includes/ui.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_db.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_ui.inc'); + +//-------------------------------------------------------------------------- + +page(_($help_context = 'Manage Grades')); +simple_page_mode(true); + +$grades_no = get_company_pref('payroll_grades'); + +if($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { + + $basic_acc = db_fetch(get_salary_structure($_POST['position_id']))['pay_rule_id']; + + begin_transaction(); + for($i=1; $i<=$max_grade_number; $i++) { + + if(isset($_POST['amt_'.$i]) && $_POST['amt_'.$i] < 0) { + display_error(_('Pay amount cannot be a negative number')); + set_focus('amt_'.$i); + exit(); + } + $position = get_position($_POST['position_id']); + $amt = input_num('amt_'.$i) > 0 ? input_num('amt_'.$i) : $position['pay_amount']; + + if(!grade_exist($i, $_POST['position_id'])) { + add_grade_table($i, $_POST['position_id'], $amt); + $new = true; + } + else { + update_grade_table($i, $_POST['position_id'], $amt); + $new = false; + } + + set_grade_salary($basic_acc, $amt, $_POST['position_id'], $i, $new); + } + commit_transaction(); + display_notification(_('Grade table has been updated')); + + $Mode = 'RESET'; +} + +if ($Mode == 'Delete') { + + if(grade_used($selected_id)) + display_error( _('Grade table for selected job position cannot be deleted.')); + else { + delete_grade($selected_id); + display_notification(_('Grade table of selected job position has been deleted')); + } + $Mode = 'RESET'; +} + +if($Mode == 'RESET') { + $selected_id = -1; + unset($_POST); +} + +//-------------------------------------------------------------------------- + +start_form(); + +start_table(TABLESTYLE); + +$th = array(_('Job Position'), _('Basic Amount')); +for($i=1; $i<=$grades_no; $i++) + $th[] = _('Grade').' '.$i; + +array_push($th, '', ''); +table_header($th); + +$all_positions = db_query(get_position()); + +$k = 0; +while ($position = db_fetch($all_positions)) { + + alt_table_row_color($k); + label_cell($position['position_name']); + amount_cell($position['pay_amount']); + $grades_row = get_position_grades($position['position_id']); + + for($i=1;$i<=$grades_no;$i++) { + $pay = get_grade_amount($position['position_id'], $i); + if(empty($pay)) + label_cell(''); + else + amount_cell($pay); + } + + edit_button_cell('Edit'.$position['position_id'], _('Edit')); + delete_button_cell('Delete'.$position['position_id'], _('Delete')); + end_row(); +} +end_table(1); + +start_table(TABLESTYLE2); + +if($selected_id != -1) { + + if($Mode == 'Edit') { + unset($_POST); + $position = get_position($selected_id); + $myrow = get_position_grades($selected_id); + $_POST['position_id'] = $selected_id; + + foreach($myrow as $val) { + $grade = $val['grade_id']; + $_POST['amt_'.$grade] = empty($val['amount']) ? price_format($position['pay_amount']) : price_format($val['amount']); + } + } + hidden('selected_id', $selected_id); +} + +position_list_row(_('Job Position').':', 'position_id'); + +if($selected_id != -1) { + $position = get_position($selected_id); + label_row(_('Basic Amount:'), ' '.price_format($position['pay_amount'])); +} + +for($i=1; $i<=$grades_no; $i++) + amount_row(_('Grade').' '.$i, 'amt_'.$i, null, null, null, null, true); + +end_table(1); + +submit_add_or_update_center($selected_id == -1, '', 'both'); + +end_form(); +end_page(); \ No newline at end of file diff --git a/manage/leave_types.php b/manage/leave_types.php new file mode 100644 index 0000000..7f984be --- /dev/null +++ b/manage/leave_types.php @@ -0,0 +1,124 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +$page_security = 'SA_HRSETUP'; +$path_to_root = '../../..'; + +include_once($path_to_root . '/includes/session.inc'); +add_access_extensions(); + +include_once($path_to_root . '/includes/ui.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_db.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_ui.inc'); + +//-------------------------------------------------------------------------- + +page(_($help_context = 'Leave Types')); +simple_page_mode(); + +if($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { + + if(empty(trim($_POST['pay_rate']))) { + display_error(_('The Salary rate field cannot be empty.')); + set_focus('pay_rate'); + } + elseif(!is_numeric($_POST['pay_rate'])) { + display_error(_('Salary rate must be a number.')); + set_focus('pay_rate'); + } + elseif(empty(trim($_POST['leave_name']))) { + display_error(_('The Leave type name cannot be empty.')); + set_focus('leave_name'); + } + elseif(empty(trim($_POST['leave_code'])) || !preg_match("/^[a-zA-Z]+$/", $_POST['leave_code'])) { + display_error(_('The Leave type code cannot be empty and only allows alphabet letters.')); + set_focus('leave_code'); + } + else { + write_leave($selected_id, $_POST['leave_name'], $_POST['leave_code'], input_num('pay_rate')); + if($selected_id != -1) + display_notification(_('Selected leave type has been updated')); + else + display_notification(_('New leave type has been added')); + $Mode = 'RESET'; + } +} + +//-------------------------------------------------------------------------- + +if($Mode == 'Delete') { + + if(leave_type_used($selected_id)) + display_error(_('This leave type cannot be deleted.')); + else { + delete_leave_type($selected_id); + display_notification(_('Selected leave type has been deleted')); + } + $Mode = 'RESET'; +} + +if($Mode == 'RESET') { + $selected_id = -1; + $_POST['leave_name'] = ''; + $_POST['leave_code'] = ''; + $_POST['pay_rate'] = ''; +} + +//-------------------------------------------------------------------------- + +$result = db_query(get_leave_type(false, check_value('show_inactive'))); + +start_form(); +start_table(TABLESTYLE); +$th = array(_('Id'), _('Leave Type Name'), _('Leave Type Code'), _('Salary Rate (%)'), "", ""); +inactive_control_column($th); + +table_header($th); +$k = 0; + +while($myrow = db_fetch($result)) { + alt_table_row_color($k); + label_cell($myrow['leave_id']); + label_cell($myrow['leave_name']); + label_cell($myrow['leave_code']); + percent_cell($myrow['pay_rate']); + inactive_control_cell($myrow['leave_id'], $myrow['inactive'], 'leave_type', 'leave_id'); + edit_button_cell('Edit'.$myrow['leave_id'], _('Edit')); + delete_button_cell('Delete'.$myrow['leave_id'], _('Delete')); + end_row(); +} + +inactive_control_row($th); +end_table(1); + +start_table(TABLESTYLE2); + +if($selected_id != -1) { + + if($Mode == 'Edit') { + $myrow = get_leave_type($selected_id); + $_POST['pay_rate'] = $myrow['pay_rate']; + $_POST['leave_name'] = $myrow['leave_name']; + $_POST['leave_code'] = $myrow['leave_code']; + } + hidden('selected_id', $selected_id); +} + +percent_row(_('Salary rate:'), 'pay_rate', null, 20, 20); +text_row(_('Leave Type Name:'), 'leave_name', null, 30, 30); +text_row(_('Leave Type Code:'), 'leave_code', null, 5, 3); + +end_table(1); + +submit_add_or_update_center($selected_id == -1, '', 'both'); + +end_form(); +end_page(); \ No newline at end of file diff --git a/manage/overtime.php b/manage/overtime.php index 29b3e45..9e144df 100644 --- a/manage/overtime.php +++ b/manage/overtime.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -119,4 +119,4 @@ submit_add_or_update_center($selected_id == '', '', 'both'); end_form(); -end_page(); +end_page(); \ No newline at end of file diff --git a/manage/payroll_rules.php b/manage/payroll_rules.php index 9f2c391..2075051 100644 --- a/manage/payroll_rules.php +++ b/manage/payroll_rules.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -12,27 +12,27 @@ $page_security = 'SA_HRSETUP'; $path_to_root = '../../..'; -include_once($path_to_root . '/includes/session.inc'); +include_once($path_to_root.'/includes/session.inc'); add_access_extensions(); $js = ''; -if ($SysPrefs->use_popup_windows) +if($SysPrefs->use_popup_windows) $js .= get_js_open_window(900, 500); -if (user_use_date_picker()) +if(user_use_date_picker()) $js .= get_js_date_picker(); -include_once($path_to_root . '/includes/ui.inc'); -include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_db.inc'); -include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_ui.inc'); +include_once($path_to_root.'/includes/ui.inc'); +include_once($path_to_root.'/modules/FrontHrm/includes/frontHrm_db.inc'); +include_once($path_to_root.'/modules/FrontHrm/includes/frontHrm_ui.inc'); //-------------------------------------------------------------------------- -$selected_id = get_post('SalaryScaleId', ''); +$selected_id = get_post('PositionId', ''); function handle_submit(&$selected_id) { global $Ajax; - - if ($selected_id) { + + if($selected_id) { $payrule = array(); foreach($_POST as $p => $val) { @@ -47,17 +47,17 @@ function handle_submit(&$selected_id) { } if(payroll_rule_exist($selected_id) && count($payrule) > 0) update_payroll_rule($selected_id, $payrule); - else if(count($payrule) == 0) + elseif(count($payrule) == 0) reset_payroll($selected_id); else add_payroll_rule($selected_id, $payrule); $Ajax->activate('_page_body'); display_notification(_('Accounts have been updated, some accounts might not have been deleted because Salary Structure using them.')); - } + } else { - display_warning(_('Select accounts first.')); - set_focus('SalaryScaleId'); + display_warning(_('Select Job Position first.')); + set_focus('PositionId'); } } @@ -72,7 +72,7 @@ function payroll_rule_settings($selected_id) { $_POST[$p] = ''; } - if ($selected_id) { + if($selected_id) { $payroll_structure = get_payroll_structure($selected_id); @@ -85,18 +85,21 @@ function payroll_rule_settings($selected_id) { $_POST['Payroll'.$rule_code] = 1; } } - $_POST['SalaryScaleId'] = $selected_id; + $_POST['PositionId'] = $selected_id; } start_table(TABLESTYLE2); - $th = array(_("Select Payroll Rules"),''); + $th = array(_('Pay Element'), _('Account'),''); table_header($th); $rules = get_payroll_rules(); while($rule = db_fetch($rules)) { - - check_row($rule['account_code'].' - '.$rule['account_name'], 'Payroll'.$rule['account_code'], null); + start_row(); + label_cell($rule['element_name']); + label_cell($rule['account_code'].' - '.$rule['account_name']); + check_cells(null, 'Payroll'.$rule['account_code']); + end_row(); } end_table(1); @@ -106,7 +109,7 @@ function payroll_rule_settings($selected_id) { submit_center('submit', _('Save'), true, _('Save payroll structure'), 'default'); else { submit_center_first('submit', _('Update'), _('Update payroll rules data'), 'default'); - submit_return('select', $selected_id, _('Select this salary scale and return to document entry.')); + submit_return('select', $selected_id, _('Select this job position and return to document entry.')); submit_center_last('delete', _('Delete'), _('Delete payroll rules if have been never used'), true); } div_end(); @@ -114,49 +117,49 @@ function payroll_rule_settings($selected_id) { //---------------------------------------------------------------------------- -if (isset($_POST['submit'])) +if(isset($_POST['submit'])) handle_submit($selected_id); //---------------------------------------------------------------------------- -if (isset($_POST['delete'])) { +if(isset($_POST['delete'])) { reset_payroll($selected_id); display_notification(_('Selected payroll rules have been deleted.')); - $_POST['SalaryScaleId'] = ''; + $_POST['PositionId'] = ''; $selected_id = ''; $Ajax->activate('_page_body'); } //---------------------------------------------------------------------------- -page(_($help_context = 'Manage Payroll Rule'), false, false, '', $js); +page(_($help_context = 'Manage Payroll Rule'), false, false, '', $js); start_form(); -if (db_has_salary_scale()) { +if(db_has_position()) { start_table(TABLESTYLE_NOBORDER); start_row(); - salaryscale_list_cells(null, 'SalaryScaleId', null, _('Select salary scale'), true, check_value('show_inactive')); + position_list_cells(null, 'PositionId', null, _('Select Job Position'), true, check_value('show_inactive')); check_cells(_('Show inactive').':', 'show_inactive', null, true); end_row(); - end_table(1); - if (get_post('_show_inactive_update')) { - $Ajax->activate('SalaryScaleId'); - set_focus('SalaryScaleId'); + end_table(1); + + if(get_post('_show_inactive_update')) { + $Ajax->activate('PositionId'); + set_focus('PositionId'); } payroll_rule_settings($selected_id); -} +} else { - hidden('SalaryScaleId'); - display_note(_('Define Salary Scales first.')); + hidden('PositionId'); + display_note(_('Define Job Positions first.')); } - hidden('popup', @$_REQUEST['popup']); end_form(); diff --git a/manage/payslip.php b/manage/payslip.php index 4a12c86..27eb194 100644 --- a/manage/payslip.php +++ b/manage/payslip.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -29,7 +29,7 @@ if (isset($_GET['ModifyPaySlip'])) { $_SESSION['page_title'] = sprintf(_('Modifying Employee Payslip #%d.'), $_GET['trans_no']); - $help_context = 'Modifying Employee Payslip'; + $help_context = _('Modifying Employee Payslip'); } else $_SESSION['page_title'] = _($help_context = 'Employee Payslip Entry'); @@ -67,7 +67,7 @@ function line_start_focus() { display_footer_exit(); } -elseif (isset($_GET['UpdatedID'])) { +elseif(isset($_GET['UpdatedID'])) { $trans_no = $_GET['UpdatedID']; $trans_type = ST_JOURNAL; @@ -82,13 +82,12 @@ function line_start_focus() { //-------------------------------------------------------------------------- -if (isset($_GET['NewPayslip'])) { +if(isset($_GET['NewPayslip'])) create_cart(0,0); -} -elseif (isset($_GET['ModifyPaySlip'])) { +elseif(isset($_GET['ModifyPaySlip'])) { check_is_editable($_GET['trans_type'], $_GET['trans_no']); - if (!isset($_GET['trans_type']) || $_GET['trans_type']!= 0) { + if(!isset($_GET['trans_type']) || $_GET['trans_type']!= 0) { display_error(_('You can edit directly only journal entries created via Journal Entry page.')); hyperlink_params($path_to_root.'/gl/gl_journal.php', _('Entry &New Journal Entry'), 'NewJournal=Yes'); display_footer_exit(); @@ -101,7 +100,7 @@ function line_start_focus() { function create_cart($type=0, $trans_no=0) { global $Refs; - if (isset($_SESSION['journal_items'])) + if(isset($_SESSION['journal_items'])) unset($_SESSION['journal_items']); check_is_closed($type, $trans_no); @@ -110,16 +109,17 @@ function create_cart($type=0, $trans_no=0) { $cart->pay_basis = ''; $cart->paytype = PT_EMPLOYEE; - if ($trans_no) { + if($trans_no) { $header = get_journal($type, $trans_no); $cart->tran_date = sql2date($header['tran_date']); $result = get_gl_trans($type, $trans_no); - if ($result) { - while ($row = db_fetch($result)) { + if($result) { + + while($row = db_fetch($result)) { $curr_amount = $cart->rate ? round($row['amount']/$cart->rate, $_SESSION["wa_current_user"]->prefs->price_dec()) : $row['amount']; - if ($curr_amount) + if($curr_amount) $cart->add_gl_item($row['account'], $row['dimension_id'], $row['dimension2_id'], $curr_amount, $row['memo_'], '', $row['person_id']); } } @@ -128,7 +128,7 @@ function create_cart($type=0, $trans_no=0) { } else { $cart->tran_date = new_doc_date(); - if (!is_date_in_fiscalyear($cart->tran_date)) + if(!is_date_in_fiscalyear($cart->tran_date)) $cart->tran_date = end_fiscalyear(); $cart->reference = $Refs->get_next(ST_JOURNAL, null, $cart->tran_date); } @@ -149,17 +149,17 @@ function create_cart($type=0, $trans_no=0) { function validate_payslip_generation() { - if (!$_POST['person_id']) { + if(!$_POST['person_id']) { display_error(_('Employee not selected')); set_focus('person_id'); return false; } - if (!is_date($_POST['from_date'])) { + if(!is_date($_POST['from_date'])) { display_error(_('The entered date is invalid.')); set_focus('from_date'); return false; } - if (!is_date($_POST['to_date'])) { + if(!is_date($_POST['to_date'])) { display_error(_('The entered date is invalid.')); set_focus('to_date'); return false; @@ -184,12 +184,12 @@ function validate_payslip_generation() { set_focus('from_date'); return false; } - if (date_comp($_POST['from_date'], Today()) > 0) { + if(date_comp($_POST['from_date'], Today()) > 0) { display_error(_('Cannot pay for the date in the future.')); set_focus('from_date'); return false; } - if (date_comp($_POST['to_date'], Today()) > 0) { + if(date_comp($_POST['to_date'], Today()) > 0) { display_error(_('Cannot pay for the date in the future.')); set_focus('to_date'); return false; @@ -200,13 +200,13 @@ function validate_payslip_generation() { return false; } // The following two cases need to be set in correct order - if(!employee_has_salary_scale($_POST['person_id'])) { - display_error(_('Selected Employee does not have a Salary Scale, please define it first.')); + if(!employee_has_position($_POST['person_id'])) { + display_error(_('Selected Employee does not have a Job Position, please define it first.')); set_focus('person_id'); return false; } - else if(!emp_salaryscale_has_structure($_POST['person_id'])) { - display_error(_("the Employee's Salary Scale does not have a structure, please define Salary Structure")); + elseif(!emp_position_has_structure($_POST['person_id'])) { + display_error(_("the Employee's Job Position does not have a structure, please define Salary Structure")); set_focus('person_id'); return false; } @@ -220,30 +220,30 @@ function validate_payslip_generation() { //-------------------------------------------------------------------------- -if (isset($_POST['Process'])) { +if(isset($_POST['Process'])) { $input_error = 0; - if ($_SESSION['journal_items']->count_gl_items() < 1) { + if($_SESSION['journal_items']->count_gl_items() < 1) { display_error(_('You must enter at least one journal line.')); set_focus('code_id'); $input_error = 1; } - if (abs($_SESSION['journal_items']->gl_items_total()) > 0.0001) { + if(abs($_SESSION['journal_items']->gl_items_total()) > 0.0001) { display_error(_('The journal must balance (debits equal to credits) before it can be processed.')); set_focus('code_id'); $input_error = 1; } - if (!is_date($_POST['date_'])) { + if(!is_date($_POST['date_'])) { display_error(_('The entered date is invalid.')); set_focus('date_'); $input_error = 1; } - elseif (!is_date_in_fiscalyear($_POST['date_'])) { + elseif(!is_date_in_fiscalyear($_POST['date_'])) { display_error(_('The entered date is out of fiscal year or is closed for further data entry.')); set_focus('date_'); $input_error = 1; } - if (!check_reference($_POST['ref'], ST_JOURNAL, $_SESSION['journal_items']->order_id)) { + if(!check_reference($_POST['ref'], ST_JOURNAL, $_SESSION['journal_items']->order_id)) { set_focus('ref'); $input_error = 1; } @@ -252,18 +252,18 @@ function validate_payslip_generation() { set_focus('from_date'); $input_error = 1; } - if ($input_error == 1) + if($input_error == 1) unset($_POST['Process']); } -if (isset($_POST['Process'])) { +if(isset($_POST['Process'])) { $cart = &$_SESSION['journal_items']; $new = $cart->order_id == 0; $cart->reference = $_POST['ref']; $cart->tran_date = $_POST['date_']; $cart->person_id = $_POST['person_id']; - if (isset($_POST['memo_'])) + if(isset($_POST['memo_'])) $cart->memo_ = $_POST['memo_']; @@ -290,7 +290,7 @@ function validate_payslip_generation() { //-------------------------------------------------------------------------- -if (isset($_POST['CancelOrder']) || !isset($_POST['person_id'])) { +if(isset($_POST['CancelOrder']) || !isset($_POST['person_id'])) { $_SESSION['journal_items']->clear_items(); $_POST['leaves'] = $_POST['deductableleaves'] = $_POST['workdays'] = ''; $Ajax->activate('_page_body'); @@ -299,37 +299,37 @@ function validate_payslip_generation() { //-------------------------------------------------------------------------- function check_item_data() { - if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id'])) { + if(isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id'])) { display_error(_('Dimension is closed.')); set_focus('dimension_id'); return false; } - if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id'])) { + if(isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id'])) { display_error(_('Dimension is closed.')); set_focus('dimension2_id'); return false; } - if (!(input_num('AmountDebit')!=0 ^ input_num('AmountCredit')!=0) ) { + if(!(input_num('AmountDebit')!=0 ^ input_num('AmountCredit')!=0) ) { display_error(_('You must enter either a debit amount or a credit amount.')); set_focus('AmountDebit'); return false; } - if (strlen($_POST['AmountDebit']) && !check_num('AmountDebit', 0)) { + if(strlen($_POST['AmountDebit']) && !check_num('AmountDebit', 0)) { display_error(_('The debit amount entered is not a valid number or is less than zero.')); set_focus('AmountDebit'); return false; } - elseif (strlen($_POST['AmountCredit']) && !check_num('AmountCredit', 0)) { + elseif(strlen($_POST['AmountCredit']) && !check_num('AmountCredit', 0)) { display_error(_('The credit amount entered is not a valid number or is less than zero.')); set_focus('AmountCredit'); return false; } - if (!is_tax_gl_unique(get_post('code_id'))) { + if(!is_tax_gl_unique(get_post('code_id'))) { display_error(_('Cannot post to GL account used by more than one tax type.')); set_focus('code_id'); return false; } - if (!$_SESSION['wa_current_user']->can_access('SA_BANKJOURNAL') && is_bank_account($_POST['code_id'])) { + if(!$_SESSION['wa_current_user']->can_access('SA_BANKJOURNAL') && is_bank_account($_POST['code_id'])) { display_error(_('Cannot make a journal entry for a bank account. Use banking functions for bank transactions.')); set_focus('code_id'); return false; @@ -358,10 +358,11 @@ function handle_delete_item($id) { } function handle_new_item() { - if (!check_item_data()) + + if(!check_item_data()) return; - if (input_num('AmountDebit') > 0) + if(input_num('AmountDebit') > 0) $amount = input_num('AmountDebit'); else $amount = -input_num('AmountCredit'); @@ -373,19 +374,20 @@ function handle_new_item() { //-------------------------------------------------------------------------- $id = find_submit('Delete'); -if ($id != -1) + +if($id != -1) handle_delete_item($id); -if (isset($_POST['AddItem'])) +if(isset($_POST['AddItem'])) handle_new_item(); -if (isset($_POST['UpdateItem'])) +if(isset($_POST['UpdateItem'])) handle_update_item(); -if (isset($_POST['CancelItemChanges'])) +if(isset($_POST['CancelItemChanges'])) line_start_focus(); -if (isset($_POST['go'])) { +if(isset($_POST['go'])) { display_quick_entries($_SESSION['journal_items'], $_POST['person_id'], input_num('totamount'), QE_JOURNAL); $_POST['totamount'] = price_format(0); $Ajax->activate('totamount'); line_start_focus(); @@ -397,14 +399,16 @@ function handle_new_item() { display_payslip_header($_SESSION['journal_items']); -if (!count($_SESSION['journal_items']->gl_items)) { +if(!count($_SESSION['journal_items']->gl_items)) { br(); submit_center('GeneratePayslip', _('Generate Payslip'), _('Generate Payslip For Process'), false); br(); } div_start('payslip_trans'); -if (count($_SESSION['journal_items']->gl_items)) { + +if(count($_SESSION['journal_items']->gl_items)) { + start_table(TABLESTYLE_NOBORDER, "width='90%'", 10); start_row(); echo ""; @@ -417,6 +421,7 @@ function handle_new_item() { submit_center_first('Process', _('Process PaySlip'), _('Process journal entry only if debits equal to credits')); submit_center_last('CancelOrder', _('Cancel'), _('Cancels document entry or removes Gl items'), true); } + div_end(); end_form(); diff --git a/manage/position.php b/manage/position.php new file mode 100644 index 0000000..9e22f56 --- /dev/null +++ b/manage/position.php @@ -0,0 +1,148 @@ + | +| Date : 09-Jul-2017 | +| Description: Frontaccounting Payroll & Hrm Module | +| Free software under GNU GPL | +| | +\=======================================================*/ + +$page_security = 'SA_HRSETUP'; +$path_to_root = '../../..'; + +include_once($path_to_root . '/includes/session.inc'); +add_access_extensions(); + +include_once($path_to_root . '/includes/ui.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_db.inc'); +include_once($path_to_root . '/modules/FrontHrm/includes/frontHrm_ui.inc'); + +//-------------------------------------------------------------------------- + +page(_($help_context = 'Manage Job Positions')); +simple_page_mode(true); + +if($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { + + if(empty(trim($_POST['name']))) { + display_error(_('Name field cannot be empty.')); + set_focus('name'); + } + elseif(!check_num('amount', 0)) { + display_error(_('Amount field value must be a positive number.')); + set_focus('amount'); + } + elseif(isset($_POST['AccountId']) && !is_expenses_account($_POST['AccountId'])) { + display_error(_('Salary Basic Account must be an expenses account.')); + set_focus('AccountId'); + } + else { + + begin_transaction(); + $id = $selected_id == -1 ? false : $selected_id; + write_position($id, $_POST['name'], $_POST['payBasis']); + + if($selected_id == -1) { + $new = true; + $added_position = db_insert_id(); + } + else { + $new = false; + $added_position = $selected_id; + } + + set_basic_salary($_POST['AccountId'], input_num('amount'), $added_position, $new); + + $employees = db_query(get_employees()); + if($id && db_num_rows($employees) > 0) { + foreach ($employees as $staff) { + if($staff['personal_salary'] == 1 && $staff['position_id'] == $added_position) + update_personal_basic_account($staff['emp_id'], $_POST['AccountId']); + } + } + + commit_transaction(); + + if ($selected_id != -1) + display_notification(_('Selected job position has been updated')); + else + display_notification(_('New job position has been added')); + + $Mode = 'RESET'; + } +} + +if ($Mode == 'Delete') { + + if(position_used($selected_id)) + display_error( _('This job position cannot be deleted.')); + else { + delete_position($selected_id); + display_notification(_('Selected job position has been deleted')); + } + $Mode = 'RESET'; +} + +if($Mode == 'RESET') { + $selected_id = -1; + $_POST['name'] = $_POST['amount'] = ''; +} + +//-------------------------------------------------------------------------- + +start_form(); + +start_table(TABLESTYLE); +$th = array(_('Id'), _('Name'), _('Salary amount'), _('Pay basis'), '', ''); +inactive_control_column($th); +table_header($th); + +$result = db_query(get_position(false, check_value('show_inactive'))); +$k = 0; +while ($myrow = db_fetch($result)) { + alt_table_row_color($k); + $pay_basis = $myrow['pay_basis'] == 0 ? _('Monthly') : _('Daily'); + + label_cell($myrow['position_id']); + label_cell($myrow['position_name']); + amount_cell($myrow['pay_amount']); + label_cell($pay_basis); + inactive_control_cell($myrow['position_id'], $myrow['inactive'], 'position', 'position_id'); + edit_button_cell('Edit'.$myrow['position_id'], _('Edit')); + delete_button_cell('Delete'.$myrow['position_id'], _('Delete')); + end_row(); +} +inactive_control_row($th); +end_table(1); + +start_table(TABLESTYLE2); + +if($selected_id != -1) { + + if ($Mode == 'Edit') { + + $myrow = get_position($selected_id); + $_POST['name'] = $myrow['position_name']; + $_POST['AccountId'] = $myrow['pay_rule_id']; + $_POST['amount'] = price_format($myrow['pay_amount']); + $_POST['payBasis'] = $myrow['pay_basis']; + } + hidden('selected_id', $selected_id); +} + +text_row_ex(_('Position Name').':', 'name', 37, 50); +if(empty($USE_DEPT_ACC)) + gl_all_accounts_list_row(_('Salary Basic Account:'), 'AccountId', null, true); +else + hidden('AccountId'); +amount_row(_('Salary Basic Amount').':', 'amount', null, null, null, null, true); +label_row(_('Pay Basis').':', radio(_('Monthly salary'), 'payBasis', 0, 1).'  '.radio(_('Daily wage'), 'payBasis', 1)); + +end_table(1); + +submit_add_or_update_center($selected_id == -1, '', 'both'); + +end_form(); +end_page(); \ No newline at end of file diff --git a/manage/salary_structure.php b/manage/salary_structure.php index 49ffa2c..71819fe 100644 --- a/manage/salary_structure.php +++ b/manage/salary_structure.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -29,14 +29,14 @@ page(_($help_context = 'Manage Salary Structure'), false, false, '', $js); -$selected_id = get_post('salary_scale_id',''); +$selected_id = get_post('position_id',''); function can_process($selected_id) { - if (!$selected_id) { + if(!$selected_id) { - display_error(_('Select salary scale')); - set_focus('salary_scale_id'); + display_error(_('Select job position')); + set_focus('position_id'); return false; } @@ -59,7 +59,7 @@ function can_process($selected_id) { function handle_submit(&$selected_id) { global $Ajax; - if (!can_process($selected_id)) + if(!can_process($selected_id)) return; $payroll_rules = array(); @@ -77,7 +77,8 @@ function handle_submit(&$selected_id) { if($amount > 0) $payroll_rules[] = array( - 'salary_scale_id' => $selected_id, + 'position_id' => $selected_id, + 'grade_id' => get_post('_tabs_sel'), 'pay_rule_id' => $val, 'pay_amount' => $amount, 'type' => $type @@ -85,8 +86,8 @@ function handle_submit(&$selected_id) { } } - delete_salary_structure($selected_id); - add_salary_structure($payroll_rules); + delete_salary_structure($selected_id, get_post('_tabs_sel')); + add_salary_structure($payroll_rules); display_notification(_('Salary structure has been updated.')); $Ajax->activate('_page_body'); @@ -98,24 +99,24 @@ function handle_submit(&$selected_id) { handle_submit($selected_id); if (isset($_POST['delete'])) { - delete_salary_structure($selected_id); display_notification(_('Selected structure has been deleted.')); - $_POST['salary_scale_id'] = $selected_id = ''; + $_POST['position_id'] = $selected_id = ''; $Ajax->activate('_page_body'); } //-------------------------------------------------------------------------- -function payroll_rules_settings($selected_id) { +function payroll_rules_settings($selected_id, $grade_id=0) { global $USE_DEPT_ACC; $new = true; $rules = array(); $basic_salary = ''; $payroll_structure = get_payroll_structure($selected_id); - $pay_basis = get_salary_scale($selected_id)['pay_basis']; - foreach(get_salary_structure($selected_id) as $row) { + $pay_basis = get_position($selected_id)['pay_basis']; + + foreach(get_salary_structure($selected_id, $grade_id) as $row) { if($row['is_basic'] == 1) $basic_salary = $row; } @@ -124,21 +125,24 @@ function payroll_rules_settings($selected_id) { foreach($payroll_structure['payroll_rule'] as $code) { $ac = get_gl_account($code); + $pay_element = get_payroll_elements(false, $code); $rules[] = array( 'account_input' => 'Account'.$code, 'debit_input' => 'Debit'.$code, 'credit_input' => 'Credit'.$code, 'account_code' => $code, 'account_name' => $ac['account_name'], + 'element_name' => $pay_element['element_name'], ); $_POST['Debit'.$code] = price_format(0); $_POST['Credit'.$code] = price_format(0); - } - $rsStr = get_salary_structure($selected_id); + + $rsStr = get_salary_structure($selected_id, $grade_id); if(db_num_rows($rsStr) > 0) { $new = false; + while($rowStr = db_fetch($rsStr)) { if($rowStr['type'] == DEBIT) @@ -151,22 +155,21 @@ function payroll_rules_settings($selected_id) { br(); start_table(TABLESTYLE2); if($pay_basis == MONTHLY_SALARY) - $th = array(_('Payroll Rules'),_('Monthly Earnings'),_('Monthly Deductions')); + $th = array(_('Pay Element'), _('Monthly Earnings'),_('Monthly Deductions')); if($pay_basis == DAILY_WAGE) - $th = array(_('Payroll Rules'),_('Daily Earnings'),_('Daily Deductions')); + $th = array(_('Pay Element'), _('Daily Earnings'),_('Daily Deductions')); + table_header($th); start_row("class='inquirybg'"); - if(empty($USE_DEPT_ACC)) - label_cell($basic_salary['account_name']); - else - label_cell(_('Basic salary')); - amount_cell($basic_salary['pay_amount']); + label_cell(_('Basic Salary')); + amount_cell(@$basic_salary['pay_amount']); amount_cell('0'); end_row(); + foreach($rules as $rule) { start_row(); hidden($rule['account_input'],$rule['account_code']); - label_cell($rule['account_name']); + label_cell($rule['element_name']); amount_cells(null, $rule['debit_input']); amount_cells(null, $rule['credit_input']); end_row(); @@ -184,30 +187,40 @@ function payroll_rules_settings($selected_id) { div_end(); } else - display_error(_('Payroll rules not defined for this salary scale')); + display_error(_('Payroll rules not defined for this job position')); + br(); } //-------------------------------------------------------------------------- start_form(); -if (db_has_salary_scale()) { +if(db_has_position()) { start_table(TABLESTYLE2); - start_row(); - - salaryscale_list_cells(_('Salary scale').':', 'salary_scale_id', null, _('Select salary scale'), true); - - end_row(); + position_list_row(_('Job Position').':', 'position_id', null, _('Select Job Position'), true); end_table(); } else { - hidden('salary_scale_id'); - display_note(_('Before you can run this function Salary Scales must be defined and add Payroll Rules to them.')); + hidden('position_id'); + display_note(_('Before you can run this function Job Positions must be defined and add Payroll Rules to them.')); +} + +$tabs = array(0 => array(_('Basic'), 999)); +$grades = get_company_pref('payroll_grades'); +for($i=1; $i<=$grades; $i++) + $tabs[$i] = array(_('Grade ').$i, 999); + +tabbed_content_start('tabs', $tabs); + +if($selected_id) { + if(grade_exist(get_post('_tabs_sel'), $selected_id) || get_post('_tabs_sel') == 0) + payroll_rules_settings($selected_id, get_post('_tabs_sel')); + else + display_note(_('Please define grade amount for the selected job position first.'), 1, 1); } -if($selected_id) - payroll_rules_settings($selected_id); +tabbed_content_end(); hidden('popup', @$_REQUEST['popup']); -end_form(); +end_form(1); end_page(); \ No newline at end of file diff --git a/reporting/redirect.php b/reporting/redirect.php index aa58ad9..082aad4 100644 --- a/reporting/redirect.php +++ b/reporting/redirect.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/reporting/rep889.php b/reporting/rep889.php index 3e7a355..767ea9d 100644 --- a/reporting/rep889.php +++ b/reporting/rep889.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -99,8 +99,8 @@ $basic_amount = ($day_amount* $work_days) - (($day_amount/$Work_hours)*$leave_hours); $total_earn = $basic_amount; -$contents .= "$work_days days - $leave_hours hours +$contents .= "$work_days".' '._('days')." + $leave_hours".' '._('hours')." ".price_format($basic_amount)." "; @@ -132,10 +132,11 @@ $contents .= ""; } foreach (get_payslip_allowance($payslip_no) as $row) { - $account_name = get_gl_account($row['detail'])['account_name']; + $element = get_payroll_elements(false, $row['detail']); + $element_name = $element['element_name']; $allowance_amount = $row['amount']; $total_earn += $allowance_amount; - $contents .= "$account_name".price_format($allowance_amount).""; + $contents .= "$element_name".price_format($allowance_amount).""; } $allocated = get_payslip_allocated_advances($payslip_no); @@ -203,16 +204,16 @@ function get_payslip_allocated_advances($payslip_no) { $pdf->writeHTMLCell($x, 0, 15, 45, _('Address:').' '.$comp_adrs, 0, 0, 0, true); $pdf->writeHTMLCell($x, 0, 15, 50, _('Phone:').' '.$comp_phone, 0, 0, 0, true); -$pdf->SetFont('dejavu', 'BI', 25); +$pdf->SetFont('', 'BI', 25); $pdf->Write(0, _('Payslip'), '', 0, 'C', true, 0, false, false, 0); -$pdf->SetFont('dejavu', '', 10); +$pdf->SetFont('', '', 10); $pdf->writeHTMLCell($x-30, 0, 15, 85, $head, 0, 0, 0, true); $pdf->writeHTML(""); -$pdf->SetFont('helvetica', 'B', 10); +$pdf->SetFont('', 'B', 10); $pdf->writeHTMLCell($x-30, 0, 15, 123.5, $title, 0, 0, 0, true, 'C'); -$pdf->setFont('dejavu', '', 10); +$pdf->setFont('', '', 10); $pdf->writeHTMLCell($x-30, 0, 15, 130, $contents, 0, 0, 0, true); //-------------------------------------------------------------------------- diff --git a/reporting/rep_employees.php b/reporting/rep_employees.php index be89713..e15cb41 100644 --- a/reporting/rep_employees.php +++ b/reporting/rep_employees.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | @@ -44,7 +44,7 @@ function display_department_employees($dep_id, $dep_name, $gender, $from, $to, $ $rep->TextCol(4, 5, $emp['emp_email']); $rep->DateCol(5, 6, $emp['emp_birthdate'], true); $rep->DateCol(6, 7, $emp['emp_hiredate'], true); - $rep->TextCol(7, 8, get_salary_scale($emp['salary_scale_id'])['scale_name']); + $rep->TextCol(7, 8, get_position($emp['position_id'])['position_name']); $rep->NewLine(); } $rep->NewLine(); @@ -66,7 +66,7 @@ function print_employees_list() { $cols = array(0, 40, 160, 210, 280, 360, 410, 480, 530); - $headers = array(_('Id'), _('Employee name'), _('Gender'), _('Mobile'), _('Email'), _('Birth date'), _('Hired date'), _('Salary scale')); + $headers = array(_('Id'), _('Employee name'), _('Gender'), _('Mobile'), _('Email'), _('Birth date'), _('Hired date'), _('Job Position')); $aligns = array('left', 'left', 'left', 'left', 'left', 'center', 'center', 'left'); diff --git a/reporting/reports_custom.php b/reporting/reports_custom.php index e2896b9..f2dd2fb 100644 --- a/reporting/reports_custom.php +++ b/reporting/reports_custom.php @@ -2,7 +2,7 @@ /*=======================================================\ | FrontHrm | |--------------------------------------------------------| -| Creator: Phương | +| Creator: Phương | | Date : 09-Jul-2017 | | Description: Frontaccounting Payroll & Hrm Module | | Free software under GNU GPL | diff --git a/sql/remove.sql b/sql/remove.sql index c953d74..b06d8a9 100644 --- a/sql/remove.sql +++ b/sql/remove.sql @@ -1,16 +1,26 @@ DROP TABLE IF EXISTS `0_employee`; DROP TABLE IF EXISTS `0_department`; -DROP TABLE IF EXISTS `0_salaryscale`; +DROP TABLE IF EXISTS `0_position`; DROP TABLE IF EXISTS `0_overtime`; DROP TABLE IF EXISTS `0_attendance`; -DROP TABLE IF EXISTS `0_payroll_account`; +DROP TABLE IF EXISTS `0_pay_element`; DROP TABLE IF EXISTS `0_payroll_structure`; DROP TABLE IF EXISTS `0_salary_structure`; +DROP TABLE IF EXISTS `0_personal_salary_structure`; DROP TABLE IF EXISTS `0_payslip`; DROP TABLE IF EXISTS `0_payslip_details`; DROP TABLE IF EXISTS `0_employee_trans`; +DROP TABLE IF EXISTS `0_employee_advance`; +DROP TABLE IF EXISTS `0_employee_advance_allocation`; +DROP TABLE IF EXISTS `0_document_types`; +DROP TABLE IF EXISTS `0_employee_docs`; +DROP TABLE IF EXISTS `0_grade_table`; +DROP TABLE IF EXISTS `0_leave_type`; + DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_deductleave_act'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_month_work_days'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_overtime_act'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_payable_act'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_work_hours'; +DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_dept_based'; +DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_grades'; diff --git a/sql/update.sql b/sql/update.sql index 2e9b372..e235898 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -8,14 +8,20 @@ CREATE TABLE IF NOT EXISTS `0_employee` ( `emp_mobile` varchar(30) DEFAULT NULL, `emp_email` varchar(100) DEFAULT NULL, `emp_birthdate` date NOT NULL, + `national_id` varchar(100) DEFAULT NULL, + `passport` varchar(100) DEFAULT NULL, + `bank_account` varchar(100) DEFAULT NULL, + `tax_number` varchar(100) DEFAULT NULL, `emp_notes` tinytext NOT NULL, `emp_hiredate` date DEFAULT NULL, `department_id` int(11) NOT NULL, - `salary_scale_id` int(11) NOT NULL DEFAULT '0', + `position_id` int(11) NOT NULL DEFAULT '0', + `grade_id` tinyint(2) UNSIGNED NOT NULL DEFAULT '0', + `personal_salary` tinyint(1) UNSIGNED NOT NULL DEFAULT '0', `emp_releasedate` date DEFAULT NULL, `inactive` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`emp_id`), - KEY `salary_scale_id` (`salary_scale_id`), + KEY `position_id` (`position_id`), KEY `department_id` (`department_id`) ) ENGINE=InnoDB; @@ -30,13 +36,13 @@ CREATE TABLE IF NOT EXISTS `0_department` ( ) ENGINE=InnoDB; -DROP TABLE IF EXISTS `0_salaryscale`; -CREATE TABLE IF NOT EXISTS `0_salaryscale` ( - `scale_id` int(11) NOT NULL AUTO_INCREMENT, - `scale_name` text NOT NULL, +DROP TABLE IF EXISTS `0_position`; +CREATE TABLE IF NOT EXISTS `0_position` ( + `position_id` int(11) NOT NULL AUTO_INCREMENT, + `position_name` text NOT NULL, `inactive` tinyint(1) NOT NULL DEFAULT '0', `pay_basis` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0 = monthly, 1 = daily', - PRIMARY KEY (`scale_id`) + PRIMARY KEY (`position_id`) ) ENGINE=InnoDB; @@ -54,26 +60,37 @@ DROP TABLE IF EXISTS `0_attendance`; CREATE TABLE IF NOT EXISTS `0_attendance` ( `emp_id` int(11) NOT NULL, `overtime_id` int(11) NOT NULL, - `hours_no` float(5) NOT NULL DEFAULT '0', + `hours_no` float(5) UNSIGNED NOT NULL, `rate` float(5) NOT NULL DEFAULT '1', `att_date` date NOT NULL, PRIMARY KEY (`emp_id`,`overtime_id`,`att_date`) ) ENGINE=InnoDB; +DROP TABLE IF EXISTS `0_leave`; +CREATE TABLE IF NOT EXISTS `0_leave` ( + `emp_id` int(11) NOT NULL, + `leave_id` int(11) NOT NULL, + `pay_rate` float(5) NOT NULL DEFAULT '1', + `date` date NOT NULL, + PRIMARY KEY (`emp_id`,`leave_id`,`date`) +) ENGINE=InnoDB; + -DROP TABLE IF EXISTS `0_payroll_account`; -CREATE TABLE IF NOT EXISTS `0_payroll_account` ( - `account_id` int(11) NOT NULL AUTO_INCREMENT, +DROP TABLE IF EXISTS `0_pay_element`; +CREATE TABLE IF NOT EXISTS `0_pay_element` ( + `element_id` int(11) NOT NULL AUTO_INCREMENT, + `element_name` varchar(100) NOT NULL DEFAULT '', `account_code` varchar(15) NOT NULL, - PRIMARY KEY (`account_id`) + PRIMARY KEY (`element_id`), + UNIQUE (`account_code`) ) ENGINE=InnoDB; DROP TABLE IF EXISTS `0_payroll_structure`; CREATE TABLE IF NOT EXISTS `0_payroll_structure` ( - `salary_scale_id` int(11) NOT NULL, + `position_id` int(11) NOT NULL, `payroll_rule` text NOT NULL, - KEY `salary_scale_id` (`salary_scale_id`) + KEY `position_id` (`position_id`) ) ENGINE=InnoDB; @@ -81,7 +98,21 @@ DROP TABLE IF EXISTS `0_salary_structure`; CREATE TABLE IF NOT EXISTS `0_salary_structure` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date` date NOT NULL, - `salary_scale_id` int(11) NOT NULL, + `position_id` int(11) NOT NULL, + `grade_id` tinyint(2) NOT NULL DEFAULT '0', + `pay_rule_id` varchar(15) NOT NULL, + `pay_amount` double NOT NULL, + `type` tinyint(1) NOT NULL COMMENT '0 for credit, 1 for debit', + `is_basic` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + + +DROP TABLE IF EXISTS `0_personal_salary_structure`; +CREATE TABLE IF NOT EXISTS `0_personal_salary_structure` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `date` date NOT NULL, + `emp_id` int(11) NOT NULL, `pay_rule_id` varchar(15) NOT NULL, `pay_amount` double NOT NULL, `type` tinyint(1) NOT NULL COMMENT '0 for credit, 1 for debit', @@ -116,8 +147,8 @@ CREATE TABLE IF NOT EXISTS `0_payslip_details` ( DROP TABLE IF EXISTS `0_employee_trans`; CREATE TABLE IF NOT EXISTS `0_employee_trans` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `trans_no` int(11) unsigned NOT NULL DEFAULT '0', - `trans_type` smallint(6) unsigned NOT NULL DEFAULT '0', + `trans_no` int(11) UNSIGNED NOT NULL DEFAULT '0', + `trans_type` smallint(6) UNSIGNED NOT NULL DEFAULT '0', `payslip_no` int(11) NOT NULL DEFAULT '0', `pay_date` date NOT NULL, `to_the_order_of` varchar(255) NOT NULL, @@ -135,14 +166,14 @@ DROP TABLE IF EXISTS `0_employee_advance_allocation`; CREATE TABLE IF NOT EXISTS `0_employee_advance_allocation` ( `trans_no_from` int(11) DEFAULT NULL, `trans_no_to` int(11) DEFAULT NULL, - `amount` double unsigned DEFAULT NULL + `amount` double UNSIGNED DEFAULT NULL ) ENGINE=InnoDB; DROP TABLE IF EXISTS `0_document_types`; CREATE TABLE IF NOT EXISTS `0_document_types` ( `type_id` int(11) NOT NULL AUTO_INCREMENT, `type_name` varchar(100) NOT NULL, - `notify_before` smallint(5) unsigned NOT NULL, + `notify_before` smallint(5) UNSIGNED NOT NULL, `inactive` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`type_id`) ) ENGINE=InnoDB; @@ -163,16 +194,36 @@ CREATE TABLE IF NOT EXISTS `0_employee_docs` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB; +DROP TABLE IF EXISTS `0_grade_table`; +CREATE TABLE IF NOT EXISTS `0_grade_table` ( + `grade_id` tinyint(2) NOT NULL, + `position_id` int(11) NOT NULL, + `amount` double NOT NULL DEFAULT '0', + PRIMARY KEY (`grade_id`, `position_id`) +) ENGINE=InnoDB; + +DROP TABLE IF EXISTS `0_leave_type`; +CREATE TABLE IF NOT EXISTS `0_leave_type` ( + `leave_id` int(11) NOT NULL AUTO_INCREMENT, + `leave_name` varchar(100) NOT NULL, + `leave_code` varchar(3) NOT NULL, + `pay_rate` float(5) NOT NULL, + `inactive` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`leave_id`) +) ENGINE=InnoDB; + DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_deductleave_act'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_month_work_days'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_overtime_act'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_payable_act'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_work_hours'; DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_dept_based'; +DELETE FROM `0_sys_prefs` WHERE `0_sys_prefs`.`name` = 'payroll_grades'; INSERT INTO `0_sys_prefs` VALUES ('payroll_deductleave_act', NULL, 'varchar', 15, ''); INSERT INTO `0_sys_prefs` VALUES ('payroll_month_work_days', NULL, 'float', NULL, 26); INSERT INTO `0_sys_prefs` VALUES ('payroll_overtime_act', NULL, 'varchar', 15, 5420); INSERT INTO `0_sys_prefs` VALUES ('payroll_payable_act', NULL, 'varchar', 15, 2100); INSERT INTO `0_sys_prefs` VALUES ('payroll_work_hours', NULL, 'float', NULL, 8); -INSERT INTO `0_sys_prefs` VALUES ('payroll_dept_based', NULL, 'tinyint', 1, 0); \ No newline at end of file +INSERT INTO `0_sys_prefs` VALUES ('payroll_dept_based', NULL, 'tinyint', 1, 0); +INSERT INTO `0_sys_prefs` VALUES ('payroll_grades', NULL, 'tinyint', 2, 5); \ No newline at end of file