private function save_to_DataBase()
 {
     //نوشتن آرايه paymnet_items در فايل
     ob_start();
     $pure_pay = 0;
     //متغيري جهت نگهداري خالص پرداختي
     reset($this->payment_items);
     foreach ($this->payment_items as $pay_row) {
         if ($pay_row['pay_value'] == 0 && $pay_row['get_value'] == 0 && (!empty($pay_row['diff_pay_value']) && $pay_row['diff_pay_value'] == 0) && (!empty($pay_row['diff_get_value']) && $pay_row['diff_get_value'] == 0) && $pay_row['salary_item_type_id'] != SIT_PROFESSOR_RETIRED && $pay_row['salary_item_type_id'] != SIT_STAFF_RETIRED) {
             continue;
         }
         if (empty($pay_row['pay_value'])) {
             $pay_row['pay_value'] = 0;
         }
         if (empty($pay_row['get_value'])) {
             $pay_row['get_value'] = 0;
         }
         if (empty($pay_row['param1'])) {
             $pay_row['param1'] = 0;
         }
         if (empty($pay_row['param2'])) {
             $pay_row['param2'] = 0;
         }
         if (empty($pay_row['param3'])) {
             $pay_row['param3'] = 0;
         }
         if (empty($pay_row['param4'])) {
             $pay_row['param4'] = 0;
         }
         if (empty($pay_row['param5'])) {
             $pay_row['param5'] = 0;
         }
         if (empty($pay_row['param6'])) {
             $pay_row['param6'] = 0;
         }
         if (empty($pay_row['param7'])) {
             $pay_row['param7'] = 0;
         }
         if (empty($pay_row['param8'])) {
             $pay_row['param8'] = 0;
         }
         if (empty($pay_row['param9'])) {
             $pay_row['param9'] = 0;
         }
         if (empty($pay_row['diff_param1'])) {
             $pay_row['diff_param1'] = 0;
         }
         if (empty($pay_row['diff_param2'])) {
             $pay_row['diff_param2'] = 0;
         }
         if (empty($pay_row['diff_param3'])) {
             $pay_row['diff_param3'] = 0;
         }
         if (empty($pay_row['diff_param4'])) {
             $pay_row['diff_param4'] = 0;
         }
         if (empty($pay_row['diff_param5'])) {
             $pay_row['diff_param5'] = 0;
         }
         if (empty($pay_row['diff_param6'])) {
             $pay_row['diff_param6'] = 0;
         }
         if (empty($pay_row['diff_param7'])) {
             $pay_row['diff_param7'] = 0;
         }
         if (empty($pay_row['diff_param8'])) {
             $pay_row['diff_param8'] = 0;
         }
         if (empty($pay_row['diff_param9'])) {
             $pay_row['diff_param9'] = 0;
         }
         if (empty($pay_row['diff_get_value'])) {
             $pay_row['diff_get_value'] = 0;
         }
         if (empty($pay_row['diff_pay_value'])) {
             $pay_row['diff_pay_value'] = 0;
         }
         if (!isset($pay_row['diff_value_coef'])) {
             $pay_row['diff_value_coef'] = 1;
         }
         echo '(' . $pay_row['diff_get_value'] . ',' . $pay_row['diff_pay_value'] . ',' . $pay_row['pay_year'] . ',' . $pay_row['pay_month'] . ',' . $pay_row['staff_id'] . ',' . $pay_row['salary_item_type_id'] . ',' . $pay_row['pay_value'] . ',' . $pay_row['get_value'] . ',' . $pay_row['param1'] . ',' . $pay_row['param2'] . ',' . $pay_row['param3'] . ',' . $pay_row['param4'] . ',' . $pay_row['param5'] . ',' . $pay_row['param6'] . ',' . $pay_row['param7'] . ',' . $pay_row['param8'] . ',' . $pay_row['param9'] . ',' . $pay_row['diff_param1'] . ',' . $pay_row['diff_param2'] . ',' . $pay_row['diff_param3'] . ',' . $pay_row['diff_param4'] . ',' . $pay_row['diff_param5'] . ',' . $pay_row['diff_param6'] . ',' . $pay_row['diff_param7'] . ',' . $pay_row['diff_param8'] . ',' . $pay_row['diff_param9'] . ',' . $pay_row['cost_center_id'] . ',' . $pay_row['payment_type'] . ',' . $pay_row['diff_value_coef'] . '),';
         echo chr(10);
         $pure_pay += $pay_row['pay_value'] + $pay_row['diff_pay_value'] * $pay_row['diff_value_coef'] - $pay_row['get_value'] - $pay_row['diff_get_value'] * $pay_row['diff_value_coef'];
     }
     /*خطا : حقوق فرد منفي شده است لذا ساير قسمتها براي او انجام نمي شود*/
     if ($pure_pay < 0 && !$this->backpay) {
         // ماه آخر بود
         if (!$this->__CALC_NEGATIVE_FICHE) {
             $this->log('FAIL', 'حقوق اين شخص به مبلغ ' . CurrencyModulesclass::toCurrency($pure_pay * -1, 'CURRENCY') . ' منفي شده است.');
             ob_clean();
             return;
         } else {
             $this->log('FAIL', 'حقوق اين شخص به مبلغ ' . CurrencyModulesclass::toCurrency($pure_pay * -1, 'CURRENCY') . ' منفي شده است.(فيش اين فرد از بخش چاپ فيش در دسترس است، لطفا پس از انجام كنترلهاي لازم فيشهاي منفي را ابطال كنيد)');
         }
     }
     $file_line = str_replace(',,', ',\\N,', ob_get_clean());
     //براي اصلاح مقادير null
     $file_line = str_replace(',,', ',\\N,', $file_line);
     //براي اصلاح مقادير null
     $pdo = parent::getPdoObject();
     $pdo->beginTransaction();
     //if($this->backpay) //در صورتي که محاسبه backpay صورت مي گيرد نيازي به نوشتن ساير فايلها نيست
     //	return ;
     if (!$this->backpay) {
         //نوشتن آرايه staff_writs در فايل payment_writs
         reset($this->staff_writs);
         //$writ_row = '';
         foreach ($this->staff_writs[$this->cur_staff_id] as $writ) {
             parent::runquery(" insert into hrmstotal.payment_writs (writ_id,writ_ver,staff_id,pay_year,pay_month,payment_type) values \n\t\t\t\t\t\t\t(" . $writ['writ_id'] . "," . $writ['writ_ver'] . "," . $this->cur_staff_id . "," . $this->__YEAR . "," . $this->last_month . "," . NORMAL . ")", array(), $pdo);
             /* echo parent::GetLatestQueryString() ;
                die();*/
             if (parent::AffectedRows() == 0) {
                 $this->log('FAIL', 'خطا در افزودن اطلاعات به جدول احکام مورد استفاده در ماه جاری ');
                 $pdo->rollBack();
                 ob_clean();
                 return;
             }
             /*$writ_row .= $writ['writ_id'] . ',' .
             		$writ['writ_ver'] . ',' .
             		$this->cur_staff_id . ',' .
             		$this->__YEAR . ',' .
             		$this->last_month . ',' .
             		NORMAL . ',' .
             		$this->__MSG.chr(10);*/
         }
         //fwrite($this->payment_writs_file_h,$writ_row);
         //نوشتن payment در فايل
         $payment_row = $this->cur_staff_id . ',' . $this->__YEAR . ',' . $this->__MONTH . ',' . $writ['writ_id'] . ',' . $writ['writ_ver'] . ",'" . $this->month_start . "','" . $this->month_end . "'," . NORMAL . ',' . $this->__MSG . ',' . $this->staffRow['bank_id'] . ',' . $this->staffRow['account_no'] . ',' . PAYMENT_STATE_NORMAL . ",'" . DateModules::NowDateTime() . "'";
         $file_line2 = str_replace(',,', ',\\N,', $payment_row);
         //براي اصلاح مقادير null
         $file_line2 = str_replace(',,', ',\\N,', $file_line2);
         //براي اصلاح مقادير null
         parent::runquery(" insert into payments (staff_id,pay_year,pay_month,writ_id,writ_ver,start_date,end_date,payment_type,message,\n\t\t\t\t\t\t   bank_id,account_no,state ,calc_date ) value (" . $file_line2 . ") ", array(), $pdo);
         //echo parent::GetLatestQueryString() ; die();
         if (parent::AffectedRows() == 0) {
             $this->log('FAIL', 'خطا در افزودن اطلاعات به جدول پرداختها ');
             $pdo->rollBack();
             ob_clean();
             return;
         }
     }
     //fwrite($this->payment_file_h,$file_line);
     //if($this->backpay)
     //	$tblName =  "back_payment_items" ;
     //else
     $tblName = "corrective_payment_items";
     $file_line = substr($file_line, 0, strlen($file_line) - 2);
     parent::runquery("insert into " . $tblName . " (diff_get_value, diff_pay_value, pay_year, pay_month, staff_id,\n                        salary_item_type_id, pay_value, get_value, param1, param2, param3,param4, param5, param6, param7, param8, param9,\n                        diff_param1,diff_param2,diff_param3,diff_param4,diff_param5,diff_param6,diff_param7,diff_param8,diff_param9,\n                        cost_center_id, payment_type, diff_value_coef ) values " . $file_line . " ", array(), $pdo);
     //echo parent::GetLatestQueryString() ; die() ;
     if (parent::AffectedRows() == 0) {
         $this->log('FAIL', 'خطا در افزودن اطلاعات به جدول اقلام حقوقی');
         $pdo->rollBack();
         ob_clean();
         return;
     }
     $this->log('SUCCESS', $pure_pay);
     $pdo->commit();
     return true;
 }
Exemple #2
0
 function __construct($ouid = "")
 {
     if ($ouid == "") {
         return;
     }
     parent::FillObject($this, "select * from org_new_units where ouid=?", array($ouid));
     if (parent::AffectedRows() == 0) {
         $this->PushException("کد وارد شده معتبر نمی باشد.");
         return;
     }
 }
Exemple #3
0
function RegisterStartDoc()
{
    $dt = PdoDataAccess::runquery("select * from ACC_docs where DocType=" . DOCTYPE_STARTCYCLE . "\n\t\tAND BranchID=? AND CycleID=?", array($_SESSION["accounting"]["CycleID"], $_SESSION["accounting"]["BranchID"]));
    if (count($dt) > 0) {
        echo Response::createObjectiveResponse(false, "سند افتتاحیه در این دوره قبلا صادر شده است");
        die;
    }
    $LocalNo = $_POST["LocalNo"];
    if ($LocalNo != "") {
        $dt = PdoDataAccess::runquery("select * from ACC_docs \n\t\t\twhere BranchID=? AND CycleID=? AND LocalNo=?", array($_SESSION["accounting"]["BranchID"], $_SESSION["accounting"]["CycleID"], $LocalNo));
        if (count($dt) > 0) {
            echo Response::createObjectiveResponse(false, "شماره سند وارد شده موجود می باشد");
            die;
        }
    }
    $dt = PdoDataAccess::runquery("select * from ACC_cycles where CycleID<" . $_SESSION["accounting"]["CycleID"]);
    if (count($dt) == 0) {
        Response::createObjectiveResponse(false, "دوره ایی قبل این دوره برای صدور سند افتتاحیه موجود نمی باشد");
        die;
    }
    $pdo = PdoDataAccess::getPdoObject();
    $pdo->beginTransaction();
    //---------------- account header doc --------------------
    $obj = new ACC_docs();
    $obj->LocalNo = $LocalNo;
    $obj->RegDate = PDONOW;
    $obj->regPersonID = $_SESSION['USER']["PersonID"];
    $obj->DocDate = PDONOW;
    $obj->CycleID = $_SESSION["accounting"]["CycleID"];
    $obj->BranchID = $_SESSION["accounting"]["BranchID"];
    $obj->description = "سند افتتاحیه";
    $obj->DocType = DOCTYPE_STARTCYCLE;
    $result = $obj->Add($pdo);
    if (!$result) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        echo Response::createObjectiveResponse(false, "");
        die;
    }
    PdoDataAccess::runquery("\n\t\tinsert into ACC_DocItems(DocID,CostID,TafsiliType,TafsiliID,DebtorAmount,CreditorAmount,locked)\n\t\tselect {$obj->DocID},CostID,TafsiliType,TafsiliID,\n\t\t\tif( sum(DebtorAmount-CreditorAmount)>0, sum(DebtorAmount-CreditorAmount), 0 ),\n\t\t\tif( sum(CreditorAmount-DebtorAmount)>0, sum(CreditorAmount-DebtorAmount), 0 ),\n\t\t\t1\n\t\tfrom ACC_DocItems i\n\t\tjoin ACC_docs using(DocID)\n\t\twhere CycleID=" . $_SESSION["accounting"]["CycleID"] - 1 . "\n\t\t\tAND BranchID = " . $_SESSION["accounting"]["BranchID"] . "\n\t\tgroup by CostID,TafsiliID\t\n\t\thaving sum(CreditorAmount-DebtorAmount)<>0\n\t", array(), $pdo);
    if (ExceptionHandler::GetExceptionCount() > 0) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        echo Response::createObjectiveResponse(false, "");
        die;
    }
    if (PdoDataAccess::AffectedRows($pdo) == 0) {
        $pdo->rollBack();
        echo Response::createObjectiveResponse(false, "ردیفی برای صدور سند افتتاحیه یافت نشد");
        die;
    }
    $pdo->commit();
    echo Response::createObjectiveResponse(true, "");
    die;
}
Exemple #4
0
function merging($main,$sub){
	
	$dtmain = PdoDataAccess::runquery("select PersonID,concat_ws(' ',fname,lname,CompanyName) fullname from BSC_persons where PersonID=?",array($main));
	$dtsub = PdoDataAccess::runquery("select PersonID,concat_ws(' ',fname,lname,CompanyName) fullname from BSC_persons where PersonID=?",array($sub));
	
	if(count($dtmain) == 0 || count($dtsub) == 0)
	{
		echo "یکی از کد ها نا معتبر است";
	}
	else
	{
		$PersonID1 = $main; 
		$PersonID2 = $sub;
		echo $dtmain[0]["fullname"] . "<br>" . $dtsub[0]["fullname"] . "<br>";
				
		PdoDataAccess::runquery("update LON_requests set LoanPersonID=? where LoanPersonID=?", 	array($PersonID1, $PersonID2));
		echo "update LON_requests : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update BSC_OrgSigners set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update BSC_OrgSigners : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update BSC_PersonExpertDomain set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update BSC_PersonExpertDomain : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update BSC_licenses set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update BSC_licenses : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update CNT_contracts set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update CNT_contracts : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update DMS_packages set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update DMS_packages : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update PLN_experts set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update PLN_experts : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update PLN_plans set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update PLN_plans : " . PdoDataAccess::AffectedRows() . "<br>";
		PdoDataAccess::runquery("update DataAudit set PersonID=? where PersonID=?", array($PersonID1, $PersonID2));
		echo "update DataAudit : " . PdoDataAccess::AffectedRows() . "<br>";
		
		PdoDataAccess::runquery("update DMS_documents set ObjectID=? where ObjectType='person' AND ObjectID=?", array($PersonID1, $PersonID2));
		echo "update DMS_documents : " . PdoDataAccess::AffectedRows() . "<br>";
		
		require_once 'framework/person/persons.class.php';
		$obj = new BSC_persons($PersonID1);
		$obj2 = new BSC_persons($PersonID2);
		PdoDataAccess::FillObjectByObject($obj, $obj2);
		$obj->PersonID = $PersonID1;
		$result = $obj->EditPerson();
		echo "copy persons properties : " . ($result ? "true" : "false") . "<br>";
				
		PdoDataAccess::runquery("delete from BSC_persons where PersonID=?", array($PersonID2));
			echo "delete BSC_persons : " . PdoDataAccess::AffectedRows() . "<br>";

		
		$TafsiliID1 = PdoDataAccess::runquery("select * from ACC_tafsilis where TafsiliType=1 AND ObjectID=?",array($main));
		$TafsiliID2 = PdoDataAccess::runquery("select * from ACC_tafsilis where TafsiliType=1 AND ObjectID=?",array($sub));
		if(count($TafsiliID1) == 0 || count($TafsiliID2) == 0)
		{
			echo "یکی از کد ها فاقد تفصیلی است";
		}
		else
		{
			$TafsiliID1 = $TafsiliID1[0]["TafsiliID"];
			$TafsiliID2 = $TafsiliID2[0]["TafsiliID"];
			
			
			PdoDataAccess::runquery("update ACC_DocItems set TafsiliID=? where TafsiliID=?", 
				array($TafsiliID1, $TafsiliID2));
			echo "update ACC_DocItems : " . PdoDataAccess::AffectedRows() . "<br>";
			PdoDataAccess::runquery("update ACC_DocItems set TafsiliID2=? where TafsiliID2=?", 
				array($TafsiliID1, $TafsiliID2));		
			echo "update ACC_DocItems : " . PdoDataAccess::AffectedRows() . "<br>";
			PdoDataAccess::runquery("delete from ACC_tafsilis where TafsiliID=?", array($TafsiliID2));
			echo "delete ACC_tafsilis : " . PdoDataAccess::AffectedRows() . "<br>";
		}
		
		print_r(ExceptionHandler::PopAllExceptions());
	}
}
Exemple #5
0
 function DeleteBank()
 {
     $res = parent::delete("ACC_banks", 'BankID=:BId', array(':BId' => $this->BankID));
     if ($res === false) {
         return false;
     }
     if (parent::AffectedRows()) {
         $daObj = new DataAudit();
         $daObj->ActionType = DataAudit::Action_delete;
         $daObj->MainObjectID = $this->BankID;
         $daObj->TableName = "ACC_banks";
         $daObj->execute();
     }
     return true;
 }
Exemple #6
0
 /**
  * اين تابع وضعيت حکم را تغيير مي دهد
  * اگر در تاريخ اجراي حکم، احکام ديگري با وضعيت جديد وجود داشته باشند ثبت سابقه می شوند
  * اگر در تاريخ اجراي حکم، احکام ديگري با وضعيت قبلي وجود داشته باشند که ثبت سابقه هستند فعال می شوند
  */
 static function change_writ_state($old_state, $new_state, $writ_id, $writ_ver, $staff_id, $execute_date, $DB = "")
 {
     if ($DB == "") {
         $pdo = PdoDataAccess::getPdoObject();
         /*@var $pdo PDO*/
         $pdo->beginTransaction();
     } else {
         $pdo = $DB;
     }
     if ($old_state > $new_state) {
         //_______________________________________________
         // تغيير وضعيت حکم
         $query = "UPDATE HRM_writs\n\t\t\t\t\t\tSET state = " . $new_state . "\n\t\t\t\t\t\tWHERE writ_id=" . $writ_id . " AND\n\t\t\t\t\t\t\t  writ_ver=" . $writ_ver . " AND\n\t\t\t\t\t\t\t  staff_id=" . $staff_id;
         PdoDataAccess::runquery($query, array());
         //..................................................
         if ($new_state == 2) {
             $qry = " UPDATE HRM_writs\n                                SET writ_recieve_date = NULL\n                        WHERE writ_id=" . $writ_id . " AND\n\t\t\t\t\t\t\t  writ_ver=" . $writ_ver . " AND\n\t\t\t\t\t\t\t  staff_id=" . $staff_id;
             PdoDataAccess::runquery($qry, array());
         }
         if ($new_state == 1) {
             $qry = " UPDATE HRM_writs\n                                SET writ_transfer_date = NULL\n                        WHERE writ_id=" . $writ_id . " AND\n\t\t\t\t\t\t\t  writ_ver=" . $writ_ver . " AND\n\t\t\t\t\t\t\t  staff_id=" . $staff_id;
             PdoDataAccess::runquery($qry, array());
         }
         //..................................................
         if (ExceptionHandler::GetExceptionCount() != 0) {
             if ($DB == "") {
                 $pdo->rollBack();
             }
             return false;
         }
         //_______________________________________________
         // فعال کردن نسخه قبلي حکم
         $query = "UPDATE HRM_writs\n\t\t\t\t\t\tSET history_only=0\n\t\t\t\t\t\tWHERE staff_id=" . $staff_id . "\n\t\t\t\t\t\t\t  AND execute_date='" . $execute_date . "'\n\t\t\t\t\t\t\t  AND state=" . $old_state . "\n\t\t\t\t\t\t\t  AND (writ_id=" . $writ_id . " OR writ_ver<" . $writ_ver . ")";
         PdoDataAccess::runquery($query, array());
         if (ExceptionHandler::GetExceptionCount() != 0) {
             if ($DB == "") {
                 $pdo->rollBack();
             }
             return false;
         }
         if (PdoDataAccess::AffectedRows() != 0) {
             if ($DB == "") {
                 $pdo->commit();
             }
             return true;
         }
         //_______________________________________________
         //پيدا کردن حکم قبلی و فعال کردن آن
         $query = "SELECT writ_id , writ_ver , staff_id\n\t\t\t\t\t\tFROM writs\n\t\t\t\t\t\tWHERE \tstaff_id = " . $staff_id . "\n\t\t\t\t\t\t\t\tAND execute_date = '" . $execute_date . "'\n\t\t\t\t\t\t\t\tAND corrective = 0\n\t\t\t\t\t\t\t\tAND state = " . $old_state . "\n\t\t\t\t\t\t\t\tAND (writ_id <> " . $writ_id . ")\n\t\t\t\t\t\tORDER BY writ_id DESC , writ_ver DESC";
         $temp = PdoDataAccess::runquery($query, array());
         if (count($temp) != 0) {
             $query = "UPDATE writs\n\t\t\t\t\t\t\tSET history_only = 0\n\t\t\t\t\t\t\tWHERE writ_id = :wid AND writ_ver = :wver AND staff_id = :stid";
             PdoDataAccess::runquery($query, array(":wid" => $temp[0]["writ_id"], ":wver" => $temp[0]["writ_ver"], ":stid" => $temp[0]["staff_id"]));
             if (ExceptionHandler::GetExceptionCount() != 0) {
                 if ($DB == "") {
                     $pdo->rollBack();
                 }
                 return false;
             }
         }
         if ($DB == "") {
             $pdo->commit();
         }
     } else {
         $temp = PdoDataAccess::runquery("SELECT staff_id , writ_id , writ_ver , execute_date\n\t\t\t\tFROM writs\n\t\t\t\tWHERE (history_only=0 OR history_only IS NULL)\n \t\t\t    \tAND (dont_transfer = 0 OR dont_transfer IS NULL)\n  \t\t\t    \tAND (correct_completed !=" . WRIT_CORRECTING . ")\n  \t\t\t     \tAND writ_id=" . $writ_id . " AND writ_ver=" . $writ_ver . " AND staff_id=" . $staff_id);
         if (count($temp) == 0) {
             if ($DB == "") {
                 $pdo->commit();
             }
             return true;
         }
         $return = PdoDataAccess::runquery("update writs set state=" . $new_state . " where writ_id=" . $writ_id . " AND writ_ver=" . $writ_ver . " AND staff_id=" . $staff_id);
         //..................................................
         if ($new_state == 2) {
             $qry = " UPDATE writs\n                                SET writ_transfer_date = now()\n                        WHERE writ_id=" . $writ_id . " AND\n\t\t\t\t\t\t\t  writ_ver=" . $writ_ver . " AND\n\t\t\t\t\t\t\t  staff_id=" . $staff_id;
             PdoDataAccess::runquery($qry, array());
         }
         if ($new_state == 3) {
             $qry = " UPDATE writs\n                                SET writ_recieve_date =  now()\n                        WHERE writ_id=" . $writ_id . " AND\n\t\t\t\t\t\t\t  writ_ver=" . $writ_ver . " AND\n\t\t\t\t\t\t\t  staff_id=" . $staff_id;
             PdoDataAccess::runquery($qry, array());
             //......................بررسی جهت خالی کردن مرکز هزینه ..............
             $obj = new manage_writ($writ_id, $writ_ver, $staff_id);
             $PrevItm = $obj->get_prior_writ("", true);
             if ($PrevItm == 0 && manage_writ_item::compute_writ_items_sum($writ_id, $writ_ver, $staff_id) > 0) {
                 $qry = " UPDATE writs\n                                SET cost_center_id = null\n                        WHERE writ_id=" . $writ_id . " AND\n\t\t\t\t\t\t\t  writ_ver=" . $writ_ver . " AND\n\t\t\t\t\t\t\t  staff_id=" . $staff_id;
                 PdoDataAccess::runquery($qry, array());
             }
             //......................
         }
         //..................................................
         if (ExceptionHandler::GetExceptionCount() != 0) {
             if ($DB == "") {
                 $pdo->rollBack();
             }
             return false;
         }
         $return = PdoDataAccess::runquery("UPDATE writs\n\t\t\t\tSET history_only=1\n\t\t\t\tWHERE staff_id = " . $temp[0]["staff_id"] . " AND\n\t\t\t\t\t\texecute_date = '" . $temp[0]["execute_date"] . "' AND\n\t\t\t\t\t\t((writ_id = " . $temp[0]["writ_id"] . " AND " . $temp[0]["writ_ver"] . ">writ_ver) OR\n\t\t\t\t\t\t\t" . $temp[0]["writ_id"] . ">writ_id) AND\n\t\t\t\t\t\t(history_only=0 OR history_only IS NULL) AND state =" . $new_state);
         if (ExceptionHandler::GetExceptionCount() != 0) {
             if ($DB == "") {
                 $pdo->rollBack();
             }
             return false;
         }
         if ($DB == "") {
             $pdo->commit();
         }
         return true;
     }
     return true;
 }
    private function remove_payments($PayType = "")
    {
        if ($PayType != "" && $PayType > 1) {
            parent::runquery('DELETE FROM payments
							
							  WHERE payments.state = 1 AND 
									payments.pay_year = ' . $this->year . ' AND
				    		 	    payments.pay_month = ' . $this->month . ' AND
				    		 	    payments.payment_type = ' . $this->payment_type);
        } else {
            if ($PayType == "") {
                parent::runquery('DELETE FROM payments
								 USING  temp_cancel_limit_staff ls
										INNER JOIN payments
											ON(ls.staff_id = payments.staff_id)		
								 WHERE payments.pay_year = ' . $this->year . ' AND
									   payments.pay_month = ' . $this->month . ' AND
									   payments.payment_type = ' . $this->payment_type);
            }
        }
        $this->success_count['FICH'] = parent::AffectedRows();
    }