/** * اين تابع قلمهاي مربوط به يک حکم را محاسبه مي نمايد * */ public static function compute_writ_items($writ_id, $writ_ver, $staff_id, $reComputeFlag = false) { //__________________________________________ //کنترل معتبر بودن کد و نسخه حکم $curWrit = new manage_writ($writ_id, $writ_ver, $staff_id); if (empty($curWrit->writ_id)) { parent::PushException(WRIT_NOT_FOUND); return false; } if ($curWrit->salary_pay_proc != BENEFIT_CUT) { if (!$reComputeFlag) { //__________________________________________ //first delete all current rows parent::runquery(" delete from HRM_writ_salary_items where writ_id=$writ_id AND writ_ver=$writ_ver AND staff_id= $staff_id"); //__________________________________________ //copy all of prior writ items to this writ $prior_writ_Obj = $curWrit->get_prior_writ("","","2013-02-19"); if (!empty($prior_writ_Obj->writ_id)) { $query = "SELECT wsi.salary_item_type_id, wsi.param1, wsi.param2, wsi.param3, wsi.param4, wsi.param5, wsi.param6, wsi.param7, wsi.value, wsi.base_value, wsi.automatic, wsi.remember_date, wsi.remember_message, wsi.remembered FROM HRM_writ_salary_items wsi LEFT OUTER JOIN HRM_salary_item_types sit ON (wsi.salary_item_type_id = sit.salary_item_type_id) WHERE writ_id = " . $prior_writ_Obj->writ_id . " AND writ_ver = " . $prior_writ_Obj->writ_ver . " AND staff_id = " . $prior_writ_Obj->staff_id . " AND validity_start_date <= '" . $curWrit->execute_date . "'AND (validity_end_date >= '" . $curWrit->execute_date . "' OR validity_end_date IS NULL OR validity_end_date = '0000-00-00' ) ORDER BY ComputeOrder "; $all_items = PdoDataAccess::runquery_fetchMode($query); // $all_items = parent::runquery($query ); //______________________________________________________________ // // //درج قلم هاي حکم قبلي براي اين حکم for ($i = 0; $i < $all_items->rowCount(); $i++) { $ItemRow = $all_items->fetch(); $current_itemRecord = $ItemRow; $wsi_object = new manage_writ_item(); parent::FillObjectByArray($wsi_object, $current_itemRecord); $wsi_object->writ_id = $curWrit->writ_id; $wsi_object->writ_ver = $curWrit->writ_ver; $wsi_object->staff_id = $curWrit->staff_id; $return = $wsi_object->AddWritItem(); if ($return === false) { return false; } } } } /*if (!manage_writ::is_auto_writ($curWrit->execute_date, $curWrit->person_type)) return true; */ $WsiObj = new manage_writ_item(); $return = $WsiObj->compute_automatic_writ_salary_items($curWrit); if ($return === false) { return false; } $WsiObj->compute_semi_automatic_writ_salary_items($curWrit); /*if ($curWrit->person_type == HR_EMPLOYEE) { unset($WsiObj); $WsiObj = new manage_writ_item(); $return = $WsiObj->compute_automatic_writ_salary_items($curWrit,"1"); if ($return === false) { return false; } } */ //______________________________________________________________ //بر اساس روال پرداخت حقوق نحوه پرداخت اقلام حقوقي کنترل مي شود require_once 'writ_subtype.class.php'; $writTypes_obj = new manage_writ_subType($curWrit->person_type, $curWrit->writ_type_id, $curWrit->writ_subtype_id); if (!$curWrit->salary_pay_proc) $curWrit->salary_pay_proc = $writTypes_obj->salary_pay_proc; if ($curWrit->salary_pay_proc) { switch ($curWrit->salary_pay_proc) { case BENEFIT_CUT : if (!manage_writ_item::RemoveWritItem(" writ_id=" . $curWrit->writ_id . " AND writ_ver=" . $curWrit->writ_ver . " AND staff_id=" . $curWrit->staff_id)) { parent::PushException(CAN_NOT_DELETE_SALARY_ITEMS); return false; } break; case ONLY_BASE_SALARY_PAY : switch ($curWrit->person_type) { case HR_PROFESSOR : $salary_item_type_id = SIT_PROFESSOR_BASE_SALARY; break; case HR_EMPLOYEE : $salary_item_type_id = SIT_STAFF_BASE_SALARY; break; case HR_WORKER : $salary_item_type_id = SIT_WORKER_BASE_SALARY; break; } if (!manage_writ_item::RemoveWritItem("writ_id=" . $curWrit->writ_id . " AND writ_ver=" . $curWrit->writ_ver . " AND salary_item_type_id != " . $salary_item_type_id . " AND staff_id = " . $staff_id)) { parent::PushException(CAN_NOT_DELETE_SALARY_ITEMS); return false; } break; case ONLY_CONTINUES_SALARY_PAY : $dt = manage_writ_item::get_continouse_salary_items($curWrit->writ_id, $curWrit->writ_ver, $curWrit->staff_id); $items = ""; for ($i = 0; $i < count($dt); $i++) $items .= $dt[$i]["salary_item_type_id"] . ","; $items = ($items != "") ? substr($items, 0, strlen($items) - 1) : ""; //........................................ if ($items != "") { if (!manage_writ_item::RemoveWritItem(" writ_id =" . $curWrit->writ_id . " AND writ_ver =" . $writ_ver . " AND staff_id =" . $curWrit->staff_id . " AND salary_item_type_id NOT IN (" . $items . ")")) { parent::PushException(CAN_NOT_DELETE_SALARY_ITEMS); return false; } } break; case CONTINUES_SALARY_RETIRED_HALF_BENEFIT_PAY : case CONTINUES_SALARY_HALF_BENEFIT_RETIRED_PAY : case CONTINUES_SALARY_HALF_BENEFIT_FRACTION_PAY : $dt = manage_writ_item::get_continouse_salary_items($curWrit->writ_id, $curWrit->writ_ver, $curWrit->staff_id); $items = ""; for ($i = 0; $i < count($dt); $i++) $items .= $dt[$i]["salary_item_type_id"] . ","; $items = ($items != "") ? substr($items, 0, strlen($items) - 1) : ""; //........................................ if ($items != "") { $query = "update HRM_writ_salary_items set value = value * 0.5 where writ_id = " . $curWrit->writ_id . " AND writ_ver = " . $curWrit->writ_ver . " AND staff_id = " . $curWrit->staff_id . " AND salary_item_type_id in (" . $items . ")"; parent::runquery($query); } break; case BENEFIT_PAY : case BENEFIT_WITHOUT_EXTRAWORK : case BENEFIT_EXIT_IN_WRIT_NOT_EXIST_IN_PAYMENT : break; } } if ($curWrit->worktime_type == HALF_TIME) $WsiObj->compute_half_time_salary_items($curWrit->corrective_writ_id, $curWrit->corrective_writ_ver, $curWrit->execute_date); if ($curWrit->worktime_type == QUARTER_TIME) $WsiObj->compute_quarter_time_salary_items($curWrit->corrective_writ_id, $curWrit->corrective_writ_ver, $curWrit->execute_date); } //__________________________________________ //اعمال تغييرات با توجه به ايجاد و کامل شدن قلم هاي حکم جديد $is_auto_writ = $curWrit->is_auto_writ($curWrit->execute_date, $curWrit->person_type); if ($is_auto_writ) manage_writ::change_writ_state($curWrit->state, WRIT_PERSONAL, $curWrit->writ_id, $curWrit->writ_ver, $curWrit->staff_id, $curWrit->execute_date); else { if ($curWrit->history_only != 1) manage_writ::change_writ_state($curWrit->state, $curWrit->state, $curWrit->writ_id, $curWrit->writ_ver, $curWrit->staff_id, $curWrit->execute_date); } return true; }
function transferAction() { $selected_writs = array(); $keys = array_keys($_POST); for ($i = 0; $i < count($_POST); $i++) { if (strpos($keys[$i], "chk_") !== false) { $arr = preg_split('/_/', $keys[$i]); $selected_writs[] = array("writ_id" => $arr[1], "writ_ver" => $arr[2], "staff_id" => $arr[3], "execute_date" => $arr[4]); } } $new_state = $_POST["new_state"]; $old_state = $_POST["mode"] == "return" ? $new_state + 1 : $new_state - 1; $return = true; for ($i = 0; $i < count($selected_writs); $i++) { if (manage_writ::change_writ_state($old_state, $new_state, $selected_writs[$i]["writ_id"], $selected_writs[$i]["writ_ver"], $selected_writs[$i]["staff_id"], $selected_writs[$i]["execute_date"]) == false) { $return = false; } } if ($return) { echo "true"; } else { print_r(ExceptionHandler::PopAllExceptions()); } die; /* $selected_writs = ""; $keys = array_keys($_POST); for($i=0; $i < count($_POST); $i++) { if(strpos($keys[$i],"chk_") !== false) { $arr = preg_split('/_/', $keys[$i]); $selected_writs .= "'" . $arr[1] . "_" . $arr[2] . "_" . $arr[3] . "',"; } } $selected_writs = ($selected_writs != "") ? substr($selected_writs, 0, strlen($selected_writs) - 1) : "''"; $return = PdoDataAccess::runquery("DROP TABLE if EXISTS tmp_transfer_writs"); if($return === false) { $DB->rollBack(); echo "false"; die(); } $return = PdoDataAccess::runquery("CREATE TABLE tmp_transfer_writs TYPE=MyIsam AS (SELECT w.staff_id , w.writ_id , w.writ_ver , w.execute_date FROM writs w WHERE (w.history_only=0 OR w.history_only IS NULL) AND (w.dont_transfer = 0 OR w.dont_transfer IS NULL) AND (w.correct_completed !=" . WRIT_CORRECTING . ") AND CONCAT(writ_id,'_',writ_ver,'_',staff_id) in (" . $selected_writs . "))"); if($return === false) { $DB->rollBack(); echo "false"; die(); } $return = PdoDataAccess::runquery("UPDATE writs w SET state = " . $_POST["new_state"] . ($_POST["new_state"] == "2" ? ",view_flag=1" : "") . " WHERE (w.history_only=0 OR w.history_only IS NULL) AND (w.dont_transfer = 0 OR w.dont_transfer IS NULL) AND (w.correct_completed!=" . WRIT_CORRECTING . ") AND CONCAT(writ_id,'_',writ_ver,'_',staff_id) in (" . $selected_writs . ")"); if($return === false) { $DB->rollBack(); echo "false"; die(); } if(PdoDataAccess::AffectedRows() > 0) { $return = PdoDataAccess::runquery("UPDATE writs w INNER JOIN tmp_transfer_writs tw ON(tw.staff_id = w.staff_id AND tw.execute_date = w.execute_date AND tw.staff_id = w.staff_id AND ((tw.writ_id=w.writ_id AND tw.writ_ver>w.writ_ver) OR tw.writ_id>w.writ_id) AND (w.history_only=0 OR w.history_only IS NULL)) SET history_only=1 WHERE w.state = " . $_POST["new_state"]); if($return === false) { $DB->rollBack(); echo "false"; die(); } } $DB->commit(); echo "true"; die();*/ }
public static function RemoveWrit($writ_id, $writ_ver, $staff_id) { $obj = new manage_writ($writ_id, $writ_ver, $staff_id); if (!$obj->onBeforeDelete()) { return false; } $DB = PdoDataAccess::getPdoObject(); /*@var $DB PDO*/ $DB->beginTransaction(); $return = PdoDataAccess::delete("writ_salary_items", "writ_id=:wid AND writ_ver=:wver AND staff_id=:stid", array(":wid" => $obj->writ_id, ":wver" => $obj->writ_ver, ":stid" => $obj->staff_id)); if ($return === false) { $DB->rollBack(); return false; } $return = PdoDataAccess::delete("writs", "writ_id=:wid AND writ_ver=:wver AND staff_id=:stid", array(":wid" => $obj->writ_id, ":wver" => $obj->writ_ver, ":stid" => $obj->staff_id)); if ($return === false) { $DB->rollBack(); return false; } $daObj = new DataAudit(); $daObj->ActionType = DataAudit::Action_delete; $daObj->MainObjectID = $obj->staff_id; $daObj->TableName = "writs"; $daObj->execute(); $last_writ_obj = manage_staff::GetLastWrit($obj->staff_id); if ($last_writ_obj) { //__________________________________________________ // دادن پست حكم قبلي به فرد در صورت خالي بودن اين پست if ($obj->is_last($obj->staff_id, $obj->execute_date) && $last_writ_obj->post_id != $obj->post_id) { if (!manage_posts::change_user_post($obj->staff_id, $obj->post_id, $last_writ_obj->post_id, $obj->execute_date)) { $DB->rollBack(); return false; } } } if ($obj->history_only != HISTORY_ONLY) { if (!manage_writ::change_writ_state(WRIT_PERSONAL, WRIT_PERSONAL, $obj->writ_id, $obj->writ_ver, $obj->staff_id, $obj->execute_date, $DB)) { $DB->rollBack(); return false; } } //__________________________________________________ //در صورت حذف يک حکم نسخه قبلي آن را در صورتي که به حقوق منتقل نشده است فعال مي کند if (!manage_staff::SetStaffLastWrit($obj->staff_id)) { $DB->rollBack(); return false; } $DB->commit(); return true; }