Exemple #1
0
function SaveTemplate()
{
    $pdo = PdoDataAccess::getPdoObject();
    $pdo->beginTransaction();
    $CorrectContent = CNT_templates::CorrectTemplateContentItems($_POST['TemplateContent']);
    $obj = new CNT_templates();
    $obj->TemplateContent = $CorrectContent;
    $obj->TemplateTitle = $_POST['TemplateTitle'];
    if ($_POST['TemplateID'] > 0) {
        $obj->TemplateID = $_POST['TemplateID'];
        $result = $obj->Edit($pdo);
    } else {
        $result = $obj->Add($pdo);
    }
    if (!$result) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        //echo PdoDataAccess::GetLatestQueryString();
        echo Response::createObjectiveResponse(false, ExceptionHandler::GetExceptionsToString());
        die;
    }
    $pdo->commit();
    echo Response::createObjectiveResponse(true, $obj->TemplateID);
    die;
}
Exemple #2
0
function SaveContract()
{
    $pdo = PdoDataAccess::getPdoObject();
    $pdo->beginTransaction();
    $CntObj = new CNT_contracts();
    PdoDataAccess::FillObjectByArray($CntObj, $_POST);
    if ($_POST["ContractID"] == "") {
        $CntObj->RegPersonID = $_SESSION['USER']["PersonID"];
        $CntObj->RegDate = PDONOW;
        $result = $CntObj->Add($pdo);
    } else {
        $result = $CntObj->Edit($pdo);
        /* removing values of contract items */
        CNT_ContractItems::RemoveAll($CntObj->ContractID, $pdo);
    }
    if (!$result) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        //echo PdoDataAccess::GetLatestQueryString();
        echo Response::createObjectiveResponse(false, ExceptionHandler::GetExceptionsToString());
        die;
    }
    /* Adding the values of Contract items */
    foreach ($_POST as $PostData => $val) {
        if (empty($val)) {
            continue;
        }
        if (!(substr($PostData, 0, 8) == "TplItem_")) {
            continue;
        }
        $items = explode('_', $PostData);
        $TemplateItemID = $items[1];
        $CntItemsObj = new CNT_ContractItems();
        $CntItemsObj->ContractID = $CntObj->ContractID;
        $CntItemsObj->TemplateItemID = $TemplateItemID;
        $TplItemObj = new CNT_TemplateItems($CntItemsObj->TemplateItemID);
        switch ($TplItemObj->ItemType) {
            case 'shdatefield':
                $CntItemsObj->ItemValue = DateModules::shamsi_to_miladi($val);
                break;
            default:
                $CntItemsObj->ItemValue = $val;
        }
        $result = $CntItemsObj->Add($pdo);
    }
    if (!$result) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        //echo PdoDataAccess::GetLatestQueryString();
        echo Response::createObjectiveResponse(false, ExceptionHandler::GetExceptionsToString());
        die;
    }
    $pdo->commit();
    echo Response::createObjectiveResponse(true, $CntObj->ContractID);
    die;
}
 function AddEducation()
 {
     $this->row_no = manage_person_education::LastID($this->PersonID) + 1;
     if (parent::insert("HRM_person_educations", $this) === false) {
         print_r(ExceptionHandler::PopAllExceptions());
         die;
         return false;
     }
     $daObj = new DataAudit();
     $daObj->ActionType = DataAudit::Action_add;
     $daObj->RelatedPersonType = 3;
     $daObj->RelatedPersonID = $this->PersonID;
     $daObj->MainObjectID = $this->row_no;
     $daObj->TableName = "HRM_person_educations";
     $daObj->execute();
     return true;
 }
Exemple #4
0
function SelectCostCode()
{
    $param = array();
    $where = isset($_REQUEST["All"]) ? "1=1" : "cc.IsActive='YES' ";
    if (!empty($_REQUEST['query'])) {
        if (isset($_REQUEST['fields'])) {
            if (strpos($_REQUEST['fields'], "LevelTitle") !== false) {
                $where .= " AND " . str_replace("LevelTitle", "b", $_REQUEST['fields']) . ".BlockDesc like :f1";
                $param[":f1"] = "%" . $_REQUEST['query'] . "%";
            } else {
                if ($_REQUEST["fields"] == "CostCode") {
                    $where .= " AND CostCode like :f3";
                    $param[":f3"] = $_REQUEST['query'] . "%";
                }
            }
        } else {
            $where .= " AND ( concat_ws(' ',b1.BlockDesc,b2.BlockDesc,b3.BlockDesc) like :f4";
            $where .= " OR CostCode like :f5 )";
            $param[":f4"] = "%" . $_REQUEST['query'] . "%";
            $param[":f5"] = $_REQUEST['query'] . "%";
        }
    }
    if (!empty($_REQUEST['CostID'])) {
        $where .= " and cc.CostID=:CostID ";
        $param[':CostID'] = $_REQUEST['CostID'];
    }
    $where .= dataReader::makeOrder();
    $list = ACC_CostCodes::SelectCost($where, $param);
    print_r(ExceptionHandler::PopAllExceptions());
    $count = $list->RowCount();
    $list = PdoDataAccess::fetchAll($list, $_GET["start"], $_GET["limit"]);
    /*for ($i = 0; $i < count($list); $i++) {
            $remainderRecord = CostCode::GetCostRemainder($_SESSION["ACCUSER"]['UnitID'], $_SESSION["ACCUSER"]['PeriodID'], $list[$i]['CostID']);
            $difference = $remainderRecord["amount"];
            if ($remainderRecord["essence"] == "CREDITOR")
                $difference = (-1) * $difference;
            if (empty($difference) || $difference == 0)
                $list[$i]['CostRemain'] = '0';
            else {
    
                if ($difference < 0) {
                    $list[$i]['CostRemain'] = number_format($difference * -1);
                    $list[$i]['SignRemain'] = 1;
                } else {
                    $list[$i]['CostRemain'] = number_format($difference);
                    $list[$i]['SignRemain'] = 0;
                }
            }
        }*/
    echo dataReader::getJsonData($list, $count, $_GET['callback']);
    die;
}
 public function run()
 {
     $pdo = parent::getPdoObject();
     $pdo->beginTransaction();
     if ($this->payment_type == 1) {
         $this->prepare_wheres();
         $this->init();
         $this->ins_commited_staff();
         $this->ins_last_flow_not_fich();
         $this->fail_log();
         $this->remove_from_limit_staff();
         $this->remove_payment_items();
         $this->remove_payment_writs();
         $this->remove_payments();
         $this->remove_temp_subtract_flow();
         $this->update_person_dependent_support();
     } else {
         $this->remove_payment_items($this->payment_type);
         $this->remove_payments($this->payment_type);
     }
     if (parent::GetExceptionCount() > 0) {
         print_r(ExceptionHandler::PopAllExceptions());
         echo "----";
         die;
         $pdo->rollBack();
         return false;
     } else {
         $pdo->commit();
         return true;
     }
 }
Exemple #6
0
function DeletePost()
{
    $query = "select * from `position` where parent_post_id=" . $_REQUEST["post_id"];
    $temp = PdoDataAccess::runquery($query);
    if (count($temp) != 0) {
        echo "ChildError";
        die;
    }
    manage_posts::RemovePost($_POST["post_id"]);
    print_r(ExceptionHandler::PopAllExceptions());
    echo "true";
    die;
}
Exemple #7
0
function SelectOperations()
{
    $param = array();
    $where = "";
    if (isset($_REQUEST['fields']) && isset($_REQUEST['query'])) {
        $field = $_REQUEST['fields'];
        $where .= ' and ' . $field . ' like :fld';
        $param[':fld'] = '%' . $_REQUEST['query'] . '%';
    }
    $dt = NTC_operations::Get($where . dataReader::makeOrder(), $param);
    print_r(ExceptionHandler::PopAllExceptions());
    //echo PdoDataAccess::GetLatestQueryString();
    $count = $dt->rowCount();
    $dt = PdoDataAccess::fetchAll($dt, $_GET["start"], $_GET["limit"]);
    echo dataReader::getJsonData($dt, $count, $_GET["callback"]);
    die;
}
Exemple #8
0
function ArrearTransferAction()
{
    $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 (PdoDataAccess::runquery(" update writs set arrear = " . $new_state . "\n\t\t\t\t\t\t\t\t\t\twhere writ_id = " . $selected_writs[$i]["writ_id"] . " and  writ_ver = " . $selected_writs[$i]["writ_ver"] . " and \n\t\t\t\t\t\t\t\t\t\t\t\tstaff_id = " . $selected_writs[$i]["staff_id"] . " and execute_date = '" . $selected_writs[$i]["execute_date"] . "'") === false) {
            $return = false;
        }
    }
    if ($return) {
        echo "true";
    } else {
        print_r(ExceptionHandler::PopAllExceptions());
    }
    die;
}
Exemple #9
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 #10
0
			},
			method: 'POST',
			form: form,

			success: function(response,option){
				mask.hide();
				//Ext.getCmp("j1").collapse();

				document.getElementById("result").innerHTML = response.responseText;
			},
			failure: function(){}
		});
	}
	</script>
<?
print_r(ExceptionHandler::PopAllExceptions());
ExceptionHandler::showExceptionPanel('result'); ?>
</head>
<body dir="rtl">
	<form method="post" id="mainForm">
		<center>
		<br>
		<div id="issuePayment_DIV" style="width: 750px">
			<table id="issuePayment_TBL" style="width: 100%">
				<tr>
					<td width="20%">واحد محل خدمت :</td>
					<td width="30%"><?php 
echo $drp_units;
?>
</td>
					<td width="20%">جستجو در زیر واحد ها :</td>
Exemple #11
0
		$ACC_pt = ImportSalary::PERSON_TYPE_Contract;
		$AccDocObj->AddItem($ACC_UnitID, $CostCodesArray[$ACC_pt]["salary"], $gh_hoghoogh, $ACC_pt);
		$AccDocObj->AddItem($ACC_UnitID, $CostCodesArray[$ACC_pt]["overtime"], $gh_ezafeKar + $OverTimeGharardadi, $ACC_pt);
		$AccDocObj->AddItem($ACC_UnitID, $CostCodesArray[$ACC_pt]["OrgInsurance"], round($gh_bimeh_dastgah), $ACC_pt);
		$AccDocObj->AddItem($ACC_UnitID, $CostCodesArray[$ACC_pt]["GovInsurance"], $gh_bimeh_dolat, $ACC_pt);
		$AccDocObj->AddItem($ACC_UnitID, $CostCodesArray[$ACC_pt]["27"], ($gh_made_kharej_Az_shomool27 + $ExtraGharardadi), $ACC_pt);
		$AccDocObj->AddItem($ACC_UnitID, $CostCodesArray[$ACC_pt]["38"], ($gh_made_kharej_Az_shomool38 + $ExtraGharardadi), $ACC_pt);
		$AccDocObj->AddItem($ACC_UnitID, $CostCodesArray[$ACC_pt]["extra"], $gh_jazb_omana, $ACC_pt);

		if(ExceptionHandler::GetExceptionCount() > 0)
		{
			echo "مرکز هزینه : " . $title . "<br><hr><br>";
			echo "<span style=color:red><h3>" . ExceptionHandler::GetExceptionsToString ("<br>") . "</h3></span>";
			$AccError = true;
		}
		ExceptionHandler::PopAllExceptions();
	}
	//</editor-fold>

	echo '<tr>
			<td>علمی مشروط</td>
			<td>' . $mp_hoghoogh . '</td>
			<td>' . ($mp_ezafeKar + $OverTimeMProf) . '</td>
			<td>' . round($mp_bimeh_dastgah) . '</td>
			<td>' . $mp_bimeh_dolat . '</td>
			<td>' . ($mp_made_kharej_Az_shomool + $ExtraMProf) . '</td>
			<td>' . $mp_jazb_omana . '</td>
			<td>' . ($mp_sum + $ExtraMProf + $OverTimeMProf) . '</td>			
		  </tr>
		  <tr>
			 <td>هیات علمی</td>
Exemple #12
0
function delete()
{
    $ret = manage_professor_exe_posts::Remove($_POST["staff_id"], $_POST["row_no"]);
    echo Response::createObjectiveResponse($ret, implode(ExceptionHandler::PopAllExceptions()));
    die;
}
Exemple #13
0
function saveMessage()
{
    $obj = new LON_messages();
    if (isset($_POST["record"])) {
        PdoDataAccess::FillObjectByJsonData($obj, $_POST["record"]);
    } else {
        PdoDataAccess::FillObjectByArray($obj, $_POST);
        $obj->MsgStatus = "DONE";
    }
    if (isset($_POST["DoneDesc"])) {
        $obj->DoneDate = PDONOW;
    }
    if ($obj->MessageID != "") {
        $result = $obj->Edit();
    } else {
        $obj->RegPersonID = $_SESSION["USER"]["PersonID"];
        $obj->CreateDate = PDONOW;
        $result = $obj->Add();
    }
    print_r(ExceptionHandler::PopAllExceptions());
    Response::createObjectiveResponse($result, "");
    die;
}
Exemple #14
0
function saveDepSupport()
{
    $obj = new manage_dependent_support();
    PdoDataAccess::FillObjectByJsonData($obj, $_POST["record"]);
    if ($obj->row_no == "") {
        $return = $obj->Add();
    } else {
        $return = $obj->Edit();
    }
    echo $return ? "true" : "false";
    print_r(ExceptionHandler::PopAllExceptions());
    die;
}
Exemple #15
0
function RegisterWarrantyDoc($ReqObj, $WageCost, $BankTafsili, $AccountTafsili, $Block_CostID, $DocID, $pdo)
{
    /*@var $ReqObj WAR_requests */
    //------------- get CostCodes --------------------
    $CostCode_warrenty = FindCostID("300");
    $CostCode_warrenty_commitment = FindCostID("700");
    $CostCode_wage = FindCostID("750-07");
    $CostCode_FutureWage = FindCostID("760-07");
    $CostCode_fund = FindCostID("100");
    $CostCode_seporde = FindCostID("690");
    $CostCode_pasandaz = FindCostID("209-10");
    $CostCode_guaranteeAmount_zemanati = FindCostID("904-02");
    $CostCode_guaranteeAmount_daryafti = FindCostID("904-04");
    $CostCode_guaranteeAmount2_zemanati = FindCostID("905-02");
    $CostCode_guaranteeAmount2_daryafti = FindCostID("905-04");
    //------------------------------------------------
    $CycleID = substr(DateModules::miladi_to_shamsi($ReqObj->StartDate), 0, 4);
    //------------------ find tafsilis ---------------
    $PersonTafsili = FindTafsiliID($ReqObj->PersonID, TAFTYPE_PERSONS);
    if (!$PersonTafsili) {
        ExceptionHandler::PushException("تفصیلی مربوطه یافت نشد.[" . $ReqObj->PersonID . "]");
        return false;
    }
    //------------------- compute wage ------------------
    $days = DateModules::GDateMinusGDate($ReqObj->EndDate, $ReqObj->StartDate);
    //if(DateModules::YearIsLeap($CycleID));
    $days -= 1;
    $TotalWage = round($days * $ReqObj->amount * 0.9 * $ReqObj->wage / 36500) + $ReqObj->RegisterAmount * 1;
    $years = SplitYears(DateModules::miladi_to_shamsi($ReqObj->StartDate), DateModules::miladi_to_shamsi($ReqObj->EndDate), $TotalWage);
    //--------------- check pasandaz remaindar -----------------
    $dt = PdoDataAccess::runquery("select sum(CreditorAmount-DebtorAmount) remain\r\n\t\tfrom ACC_DocItems join ACC_docs using(DocID) where CycleID=? AND CostID=?\r\n\t\t\tAND TafsiliType=? AND TafsiliID=? AND BranchID=?", array($CycleID, $CostCode_pasandaz, TAFTYPE_PERSONS, $PersonTafsili, $ReqObj->BranchID));
    if ($WageCost == "209-10" && $dt[0][0] * 1 < $ReqObj->amount * 0.1) {
        ExceptionHandler::PushException("مانده حساب پس انداز مشتری کمتر از 10% مبلغ ضمانت نامه می باشد");
        return false;
    }
    if ($WageCost == "209-10" && $dt[0][0] * 1 < $ReqObj->amount * 0.1 + $TotalWage) {
        ExceptionHandler::PushException("مانده حساب پس انداز مشتری کمتر از مبلغ کارمزد می باشد");
        return false;
    }
    if ($ReqObj->IsBlock == "YES") {
        if ($Block_CostID != "" && $Block_CostID != $CostCode_pasandaz) {
            $dt = PdoDataAccess::runquery("select sum(CreditorAmount-DebtorAmount) remain\r\n\t\t\tfrom ACC_DocItems join ACC_docs using(DocID) where CycleID=? AND CostID=?\r\n\t\t\t\tAND TafsiliType=? AND TafsiliID=? AND BranchID=?", array($CycleID, $Block_CostID, TAFTYPE_PERSONS, $PersonTafsili, $ReqObj->BranchID));
        }
        $amount = $ReqObj->amount * 1;
        if ($WageCost == "209-10") {
            $amount += $ReqObj->amount * 0.1 + $TotalWage;
        }
        if ($dt[0][0] * 1 < $amount) {
            ExceptionHandler::PushException("مانده حساب انتخابی جهت بلوکه کمتر از مبلغ ضمانت نامه می باشد");
            return false;
        }
    }
    //---------------- add doc header --------------------
    if ($DocID == null) {
        $DocObj = new ACC_docs();
        $DocObj->RegDate = PDONOW;
        $DocObj->regPersonID = $_SESSION['USER']["PersonID"];
        $DocObj->DocDate = PDONOW;
        $DocObj->CycleID = $CycleID;
        $DocObj->BranchID = $ReqObj->BranchID;
        $DocObj->DocType = DOCTYPE_WARRENTY;
        $DocObj->description = "ضمانت نامه " . $ReqObj->_TypeDesc . " به شماره " . $ReqObj->RequestID . " به نام " . $ReqObj->_fullname;
        if (!$DocObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد سند");
            return false;
        }
    } else {
        $DocObj = new ACC_docs($DocID);
    }
    //----------------- add Doc items ------------------------
    $itemObj = new ACC_DocItems();
    $itemObj->DocID = $DocObj->DocID;
    $itemObj->TafsiliType = TAFTYPE_PERSONS;
    $itemObj->TafsiliID = $PersonTafsili;
    $itemObj->SourceType = DOCTYPE_WARRENTY;
    $itemObj->SourceID = $ReqObj->RequestID;
    $itemObj->SourceID2 = $ReqObj->ReqVersion;
    $itemObj->locked = "YES";
    $itemObj->CostID = $CostCode_warrenty;
    $itemObj->DebtorAmount = $ReqObj->amount;
    $itemObj->CreditorAmount = 0;
    if (!$itemObj->Add($pdo)) {
        ExceptionHandler::PushException("خطا در ثبت ردیف ضمانت نامه");
        return false;
    }
    unset($itemObj->ItemID);
    $itemObj->CostID = $CostCode_warrenty_commitment;
    $itemObj->DebtorAmount = 0;
    $itemObj->CreditorAmount = $ReqObj->amount;
    if (!$itemObj->Add($pdo)) {
        ExceptionHandler::PushException("خطا در ثبت ردیف تعهد ضمانت نامه");
        return false;
    }
    //------------------- compute wage -----------------------
    $curYear = substr(DateModules::miladi_to_shamsi($ReqObj->StartDate), 0, 4) * 1;
    foreach ($years as $Year => $amount) {
        if ($amount == 0) {
            continue;
        }
        $YearTafsili = FindTafsiliID($Year, TAFTYPE_YEARS);
        if (!$YearTafsili) {
            ExceptionHandler::PushException("تفصیلی مربوطه یافت نشد.[" . $Year . "]");
            return false;
        }
        unset($itemObj->ItemID);
        $itemObj->details = "کارمزد ضمانت نامه شماره " . $ReqObj->RequestID;
        $itemObj->CostID = $Year == $curYear ? $CostCode_wage : $CostCode_FutureWage;
        $itemObj->DebtorAmount = 0;
        $itemObj->CreditorAmount = $amount;
        $itemObj->TafsiliType = TAFTYPE_YEARS;
        $itemObj->TafsiliID = $YearTafsili;
        $itemObj->Add($pdo);
    }
    //---------------------------- block Cost ----------------------------
    if ($ReqObj->IsBlock == "YES") {
        $blockObj = new ACC_CostBlocks();
        $blockObj->CostID = !empty($Block_CostID) ? $Block_CostID : $CostCode_pasandaz;
        $blockObj->TafsiliType = TAFTYPE_PERSONS;
        $blockObj->TafsiliID = $PersonTafsili;
        $blockObj->BlockAmount = $ReqObj->amount;
        $blockObj->IsLock = "YES";
        $blockObj->SourceType = DOCTYPE_WARRENTY;
        $blockObj->SourceID = $ReqObj->RequestID;
        $blockObj->details = "بابت ضمانت نامه شماره " . $ReqObj->RequestID;
        if (!$blockObj->Add()) {
            print_r(ExceptionHandler::PopAllExceptions());
            ExceptionHandler::PushException("خطا در بلوکه کردن حساب پس انداز");
            return false;
        }
    }
    // ---------------------- Warrenty costs -----------------------------
    $totalCostAmount = 0;
    $dt = PdoDataAccess::runquery("select * from WAR_costs where RequestID=?", array($ReqObj->RequestID));
    foreach ($dt as $row) {
        $totalCostAmount += ($row["CostType"] == "DEBTOR" ? 1 : -1) * $row["CostAmount"] * 1;
        unset($itemObj->ItemID);
        $itemObj->SourceID2 = $row["CostID"];
        $itemObj->details = $row["CostDesc"];
        $itemObj->CostID = $row["CostCodeID"];
        $itemObj->DebtorAmount = $row["CostType"] == "DEBTOR" ? $row["CostAmount"] : 0;
        $itemObj->CreditorAmount = $row["CostType"] == "CREDITOR" ? $row["CostAmount"] : 0;
        $itemObj->Add($pdo);
    }
    // ----------------------------- bank --------------------------------
    unset($itemObj->ItemID);
    unset($itemObj->TafsiliType);
    unset($itemObj->TafsiliID);
    $itemObj->details = "بابت 10% سپرده ضمانت نامه شماره " . $ReqObj->RequestID;
    $itemObj->CostID = $CostCode_seporde;
    $itemObj->DebtorAmount = 0;
    $itemObj->CreditorAmount = $ReqObj->amount * 0.1;
    $itemObj->Add($pdo);
    unset($itemObj->ItemID);
    $itemObj->details = "بابت کارمزد ضمانت نامه شماره " . $ReqObj->RequestID;
    $itemObj->CostID = FindCostID($WageCost);
    $itemObj->DebtorAmount = $TotalWage + $ReqObj->amount * 0.1 - $totalCostAmount;
    $itemObj->CreditorAmount = 0;
    if ($WageCost == "101") {
        $itemObj->TafsiliType = TAFTYPE_BANKS;
        if ($BankTafsili != "") {
            $itemObj->TafsiliID = $BankTafsili;
        }
        $itemObj->TafsiliType2 = TAFTYPE_ACCOUNTS;
        if ($AccountTafsili != "") {
            $itemObj->TafsiliID2 = $AccountTafsili;
        }
    }
    $itemObj->Add($pdo);
    //---------- ردیف های تضمین  ----------
    $SumAmount = 0;
    $countAmount = 0;
    $dt = PdoDataAccess::runquery("\r\n\t\tSELECT DocumentID, ParamValue, InfoDesc as DocTypeDesc\r\n\t\t\tFROM DMS_DocParamValues\r\n\t\t\tjoin DMS_DocParams using(ParamID)\r\n\t\t\tjoin DMS_documents d using(DocumentID)\r\n\t\t\tjoin BaseInfo b on(InfoID=d.DocType AND TypeID=8)\r\n\t\t\tleft join ACC_DocItems on(SourceType=" . DOCTYPE_DOCUMENT . " AND SourceID=DocumentID)\r\n\t\twhere ItemID is null AND b.param1=1 AND \r\n\t\t\tparamType='currencyfield' AND ObjectType='warrenty' AND ObjectID=?", array($ReqObj->RequestID), $pdo);
    foreach ($dt as $row) {
        unset($itemObj->ItemID);
        $itemObj->CostID = $CostCode_guaranteeAmount_zemanati;
        $itemObj->DebtorAmount = $row["ParamValue"];
        $itemObj->CreditorAmount = 0;
        $itemObj->TafsiliType = TAFTYPE_PERSONS;
        $itemObj->TafsiliID = $PersonTafsili;
        $itemObj->SourceType = DOCTYPE_DOCUMENT;
        $itemObj->SourceID = $row["DocumentID"];
        $itemObj->details = $row["DocTypeDesc"];
        $itemObj->Add($pdo);
        $SumAmount += $row["ParamValue"] * 1;
        $countAmount++;
    }
    if ($SumAmount > 0) {
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliID);
        unset($itemObj->details);
        $itemObj->CostID = $CostCode_guaranteeAmount2_zemanati;
        $itemObj->DebtorAmount = 0;
        $itemObj->CreditorAmount = $SumAmount;
        $itemObj->Add($pdo);
    }
    if (ExceptionHandler::GetExceptionCount() > 0) {
        return false;
    }
    return $DocObj->DocID;
}
Exemple #16
0
function importStudent()
{
    $dt = PdoDataAccess::runquery("select * from StudentPersonMap where StNo=?", array($_POST["StNo"]));
    if (count($dt) > 0) {
        echo Response::createObjectiveResponse(false, "Duplicate");
        die;
    }
    $pdo = PdoDataAccess::getPdoObject();
    $pdo->beginTransaction();
    $query = "insert into \n\t\tpersons(person_type,pfname,plname,efname,elname,father_name,idcard_no,birth_date,national_code,\n\t\t\t\tsex,address1,home_phone1,mobile_phone,email,comment)\n\t\tselect " . $_POST["person_type"] . ",PFName,PLName,EFName,ELName,DadName,BCN,BirthDate,NID,\n\t\t\t\tsex,address1,PhoneNo,mobile,EMail,concat('انتقال اطلاعات دانشجو با شماره دانشجویی', StNo)\n\t\tfrom students where StNo=?";
    PdoDataAccess::runquery($query, array($_POST["StNo"]), $pdo);
    if (ExceptionHandler::GetExceptionCount() > 0) {
        $pdo->rollBack();
        echo Response::createObjectiveResponse(false, "1");
        //print_r(ExceptionHandler::PopAllExceptions());
        die;
    }
    //--------------------------------------------------------------------------
    $personID = PdoDataAccess::InsertID();
    $staff_id = PdoDataAccess::GetLastID("staff", "staff_id", "", array(), $pdo) + 1;
    PdoDataAccess::runquery("insert into staff(staff_id,PersonID,person_type) \n\t\t\tvalues({$staff_id}, {$personID}, " . $_POST["person_type"] . ")", array(), $pdo);
    if (ExceptionHandler::GetExceptionCount() > 0) {
        $pdo->rollBack();
        echo Response::createObjectiveResponse(false, "2");
        //print_r(ExceptionHandler::PopAllExceptions());
        die;
    }
    //--------------------------------------------------------------------------
    $query = "insert into StudentPersonMap\tvalues({$personID}," . $_POST["StNo"] . ")";
    PdoDataAccess::runquery($query, array(), $pdo);
    if (ExceptionHandler::GetExceptionCount() > 0) {
        $pdo->rollBack();
        //print_r(ExceptionHandler::PopAllExceptions());
        echo Response::createObjectiveResponse(false, "5");
        die;
    }
    //--------------------------------------------------------------------------
    $query = "select RFID from educ.StudentSpecs where StNo=?";
    $dt = PdoDataAccess::runquery($query, array($_POST["StNo"]), $pdo);
    if (ExceptionHandler::GetExceptionCount() > 0) {
        $pdo->rollBack();
        echo Response::createObjectiveResponse(false, "3");
        //print_r(ExceptionHandler::PopAllExceptions());
        die;
    }
    if (count($dt) > 0 && $dt[0][0] != "") {
        $id = PdoDataAccess::GetLastID("pas.PersonSettings", "PersonSettingsID");
        $query = "insert into pas.PersonSettings(PersonSettingsID,PersonID,CardStatus,CardNumber,WorkGroupID,CalendarID)\n\t\t\tvalues(" . ($id + 1) . ",{$personID},'ENABLE',NULL,0,0)";
        PdoDataAccess::runquery($query, array(), $pdo);
        if (ExceptionHandler::GetExceptionCount() > 0) {
            $pdo->rollBack();
            print_r(ExceptionHandler::PopAllExceptions());
            echo Response::createObjectiveResponse(false, "4");
            die;
        }
    }
    //--------------------------------------------------------------------------
    $pdo->commit();
    $result = ExceptionHandler::GetExceptionCount() == 0 ? "true" : "false";
    echo Response::createObjectiveResponse($result, "");
    die;
}
Exemple #17
0
function SelectMyMessages()
{
    if ($_REQUEST["mode"] == "receive") {
        $query = "select m.*,r.* ,concat(fname,' ',lname) FromPersonName, substr(MsgDate,1,10) _MsgDate\n\t\t\tfrom OFC_messages m join OFC_MessageReceivers r using(MessageID)\n\t\t\t\tjoin BSC_persons p on(m.PersonID=p.PersonID)\n\t\t\twhere r.PersonID=:p";
        $query .= isset($_REQUEST["deleted"]) && $_REQUEST["deleted"] == "true" ? " AND r.IsDeleted='YES'" : " AND r.IsDeleted='NO'";
    } else {
        $query = "select m.*,r.* ,concat(fname,' ',lname) ToPersonName, substr(MsgDate,1,10) _MsgDate\n\t\t\tfrom OFC_messages m join OFC_MessageReceivers r using(MessageID)\n\t\t\tjoin BSC_persons p on(r.PersonID=p.PersonID)\n\t\t\twhere m.PersonID=:p";
        $query .= isset($_REQUEST["deleted"]) && $_REQUEST["deleted"] == "true" ? " AND m.IsDeleted='YES'" : " AND m.IsDeleted='NO'";
    }
    $param = array(":p" => $_SESSION["USER"]["PersonID"]);
    $dt = PdoDataAccess::runquery_fetchMode($query, $param);
    print_r(ExceptionHandler::PopAllExceptions());
    $cnt = $dt->rowCount();
    $dt = PdoDataAccess::fetchAll($dt, $_GET["start"], $_GET["limit"]);
    echo dataReader::getJsonData($dt, $cnt, $_GET["callback"]);
    die;
}
Exemple #18
0
function SaveLoanCheque()
{
    $pdo = PdoDataAccess::getPdoObject();
    $pdo->beginTransaction();
    $DocID = "";
    $cheques = json_decode($_POST["cheques"]);
    foreach ($cheques as $cheque) {
        $obj = new ACC_IncomeCheques();
        PdoDataAccess::FillObjectByJsonData($obj, $cheque);
        $obj->ChequeStatus = INCOMECHEQUE_NOTVOSUL;
        if (!$obj->Add($pdo)) {
            echo Response::createObjectiveResponse(false, ExceptionHandler::GetExceptionsToString());
            die;
        }
        //................. add back pays ........................
        $bobj = new LON_BackPays();
        $bobj->PayDate = $obj->ChequeDate;
        $bobj->IncomeChequeID = $obj->IncomeChequeID;
        $bobj->RequestID = $_POST["RequestID"];
        $bobj->PayAmount = $obj->ChequeAmount;
        $bobj->PayType = BACKPAY_PAYTYPE_CHEQUE;
        $bobj->Add($pdo);
        //.......................................................
        ACC_IncomeCheques::AddToHistory($obj->IncomeChequeID, $obj->ChequeStatus, $pdo);
        //--------------------------------------------
        $DocID = RegisterOuterCheque($DocID, $obj, $pdo);
        if (!$DocID) {
            print_r(ExceptionHandler::PopAllExceptions());
            echo Response::createObjectiveResponse(false, ExceptionHandler::GetExceptionsToString());
            die;
        }
    }
    $pdo->commit();
    echo Response::createObjectiveResponse(true, "");
    die;
}
Exemple #19
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 #20
0
function SaveFilledForm()
{
    $pdo = PdoDataAccess::getPdoObject();
    $pdo->beginTransaction();
    PdoDataAccess::runquery("insert into VOT_FilledForms values(?,?," . PDONOW . ")", array($_POST["FormID"], $_SESSION["USER"]["PersonID"]), $pdo);
    $arr = array_keys($_POST);
    for ($i = 0; $i < count($arr); $i++) {
        if (strpos($arr[$i], "elem_") === false) {
            continue;
        }
        $ItemID = str_replace("elem_", "", $arr[$i]);
        $value = $_POST[$arr[$i]];
        PdoDataAccess::runquery("insert into VOT_FilledItems values(?,?,?,?)", array($_POST["FormID"], $_SESSION["USER"]["PersonID"], $ItemID, $value), $pdo);
    }
    if (ExceptionHandler::GetExceptionCount() > 0) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        echo Response::createObjectiveResponse(false, "");
        die;
    }
    $pdo->commit();
    echo Response::createObjectiveResponse(true, "");
    die;
}
Exemple #21
0
function registerDoc()
{
    require_once '../../../../accountancy/import/salary/salary.class.php';
    $AccDocObj = new ImportSalary($_POST["pay_year"], $_POST["pay_month"]);
    if ($AccDocObj->InitialImportance($_POST["PersonType"] == "contract") === false) {
        echo Response::createObjectiveResponse(false, ExceptionHandler::GetExceptionsToString("<br>"));
        die;
    }
    $query = "\t\n\t\tselect  c.CostCenterID,\n\t\t\t\tc.Title,\n\t\t\t\tsit.CostID,\n\t\t\t\tsit.CostType,\n\t\t\t\tcase s.person_type when 1 then if(w.emp_state=11, 'ConditionalProf', 'Prof')\n\t\t\t\t\t\t\t\t   when 2 then 'Staff'\n\t\t\t\t\t\t\t\t   when 3 then 'Worker'\n\t\t\t\t\t\t\t\t   when 5 then 'Contract' end PersonType, \n\t\t\t\ts.last_retired_pay,\n\t\t\t\tw.emp_state,\n\t\t\t\tc.AccUnitID,\t\t\t\t\n\t\t\t\tpit.salary_item_type_id,\n\t\t\t\tsum(pit.pay_value) pay_value,\n\t\t\t\tsum(pit.diff_value_coef * pit.diff_pay_value) diff_pay_value,\n\t\t\t\tsum(param7) param7,\n\t\t\t\tsum(diff_param7_coef * diff_param7) diff_param7,\n\t\t\t\tsum(param2) param2,\n\t\t\t\tsum(diff_param2_coef * diff_param2) diff_param2,\n\t\t\t\tsum(param3) param3,\n\t\t\t\tsum(diff_param3_coef * diff_param3) diff_param3\n\t\t\t\t\n\t\tFROM payments p \n\t\t\tJOIN staff s ON s.staff_id = p.staff_id\n\t\t\tJOIN writs w\n\t\t\t\tON(p.writ_id = w.writ_id AND\n\t\t\t\t   p.writ_ver = w.writ_ver AND\n\t\t\t\t   p.staff_id = w.staff_id AND w.state=3)\n\n\t\t\tJOIN payment_items pit \n\t\t\t\tON(p.pay_year = pit.pay_year AND p.pay_month = pit.pay_month AND\n\t\t\t\t   p.staff_id = pit.staff_id AND p.payment_type = pit.payment_type)\n\n\t\t\tJOIN persons per ON (per.personid = s.personid )\n\t\t\tJOIN banks b ON b.bank_id = p.bank_id\n\t\t\tJOIN CostCenterPlan c ON c.CostCenterID = w.CostCenterID\n\t\t\tJOIN salary_item_types sit using(salary_item_type_id)\n\t\t\t\n\t\tWHERE p.pay_year = :py and p.pay_month = :pm and p.payment_type = 1 \n\t\t\tand s.person_type in(" . ($_POST["PersonType"] == "contract" ? "5" : "1,2,3") . ") AND sit.CostID>0\n\n\t\tgroup by c.CostCenterID , s.person_type , p.payment_type , pit.salary_item_type_id\n\t\torder by c.CostCenterID,pit.salary_item_type_id";
    $dt = PdoDataAccess::runquery_fetchMode($query, array(":py" => $_POST["pay_year"], ":pm" => $_POST["pay_month"]));
    $AccError = "";
    while ($row = $dt->fetch()) {
        $amount = 0;
        switch ($row["salary_item_type_id"]) {
            case 44:
                if ($row["PersonType"] == "ConditionalProf") {
                    $row["CostID"] = 19023;
                }
                $amount = $row["pay_value"] + $row["diff_pay_value"];
                break;
                //..................................................................
            //..................................................................
            case 143:
            case 38:
                $coef_dolat = 1.7 / 1.65;
                $amount = $row["param7"] + $row["diff_param7"] + ($row["param7"] + $row["diff_param7"]) * $coef_dolat;
                break;
                //..................................................................
            //..................................................................
            case 9920:
            case 144:
                $amount = $row["param2"] + $row["diff_param2"];
                break;
            case 145:
                $amount = $row["param2"] + $row["diff_param2"] + $row["param3"] + $row["diff_param3"];
                break;
            case 744:
                $amount = $row["param2"] + $row["diff_param2"];
                break;
                //..................................................................
            //..................................................................
            case 149:
            case 150:
            case 750:
                $amount = $row["param3"] + $row["diff_param3"];
                break;
                //..................................................................
            //..................................................................
            case 9931:
                if ($row["PersonType"] == "Staff" || $row["PersonType"] == "Contract") {
                    $row["CostID"] = 341;
                }
                if ($row["PersonType"] == "Worker") {
                    $row["CostID"] = 342;
                }
                $amount = $row["pay_value"] + $row["diff_pay_value"];
                break;
                //..................................................................
            //..................................................................
            default:
                $amount = $row["pay_value"] + $row["diff_pay_value"];
        }
        $AccDocObj->AddItem($row["AccUnitID"], $row["CostID"], $amount, $row["PersonType"]);
        if (ExceptionHandler::GetExceptionCount() > 0) {
            $AccError .= "مرکز هزینه : " . $row["Title"] . "<br><hr><br>";
            $AccError .= "<span style=color:red><h3>" . ExceptionHandler::GetExceptionsToString("<br>") . "</h3></span>";
        }
        ExceptionHandler::PopAllExceptions();
    }
    $AccDocObj->CommitImportance();
    echo Response::createObjectiveResponse($AccError == "", $AccError);
    die;
}
function deleteItem()
{
    $ret = management_extra_bylaw_items::Remove($_POST["bylaw_id"], $_POST["post_id"]);
    echo Response::createObjectiveResponse($ret, implode(ExceptionHandler::PopAllExceptions()));
    die;
}
Exemple #23
0
function GetPlanExperts()
{
    $temp = PLN_experts::Get("AND PlanID=?", array($_REQUEST["PlanID"]));
    print_r(ExceptionHandler::PopAllExceptions());
    $res = $temp->fetchAll();
    echo dataReader::getJsonData($res, $temp->rowCount(), $_GET["callback"]);
    die;
}
Exemple #24
0
function saveReport()
{
    $summaryNames = array("sum" => "مجموع", "count" => "تعداد", "avg" => "میانگین", "max" => "ماکزیمم", "min" => "مینیمم");
    //-------------------- Add or Edit report header ---------------------------
    $rptobj = new rp_reports();
    $rptobj->report_title = $_POST["report_title"];
    $rptobj->conditions = stripslashes($_POST["conditions"]);
    $rptobj->refer_page = $_POST["refer_page"];
    if (empty($_POST["report_id"])) {
        $result = $rptobj->Add();
        $rptobj->report_id = rp_reports::LastID();
    } else {
        $rptobj->report_id = $_POST["report_id"];
        $result = $rptobj->Edit();
    }
    if (!$result) {
        print_r(ExceptionHandler::PopAllExceptions());
        die;
    }
    //------------------------ insert all used columns -------------------------
    PdoDataAccess::runquery("delete from rp_report_columns where report_id=" . $rptobj->report_id . " AND used_type in('group','separation','filter','order')");
    $variables = array("groupColumns", "separationColumns", "filterColumns", "orderColumns");
    $query = "insert into rp_report_columns(report_id,parent_path,column_id,used_type) values";
    foreach ($variables as $var) {
        $st = preg_split('/,/', $_POST[$var]);
        for ($i = 0; $i < count($st) - 1; $i++) {
            $id = $st[$i];
            $parent_path = $id;
            $tmp = preg_split('/_/', $id);
            $column_id = $tmp[count($tmp) - 1];
            $query .= "(" . $rptobj->report_id . ",'" . $parent_path . "'," . $column_id . ",'" . str_replace("Columns", "", $var) . "'),";
        }
    }
    $st = array();
    preg_match_all("|\\[[^\\]]+(.*)+\\]|U", $_POST["conditions"], $st, PREG_PATTERN_ORDER);
    if ($st && $st[0]) {
        for ($i = 0; $i < count($st[0]); $i++) {
            $tmp = preg_replace("/\\[|\\]/", "", $st[0][$i]);
            $parent_path = $tmp;
            $tmp = preg_split('/_/', $parent_path);
            $column_id = $tmp[count($tmp) - 1];
            $query .= "(" . $rptobj->report_id . ",'" . $parent_path . "'," . $column_id . ",'condition'),";
        }
    }
    $query = substr($query, 0, strlen($query) - 1);
    $query .= " ON DUPLICATE KEY UPDATE row_id=row_id";
    PdoDataAccess::runquery($query);
    //-------------- make All tables name/value Collection ---------------------
    $temp = PdoDataAccess::runquery("select * from rp_tables order by table_id");
    $allMasters = "";
    for ($i = 0; $i < count($temp); $i++) {
        $allMasters[$temp[$i]["table_id"]] = $temp[$i];
    }
    //----------------------  extract all used relations -----------------------
    $columns = PdoDataAccess::runquery("\r\n\t\tselect rc.*,c.*,rt.join_text from rp_report_columns rc\r\n\t\t\tjoin rp_columns c using(column_id)\r\n\t\t\tleft join rp_tables as rt on(rt.table_id=c.basic_info_table)\r\n\t\twhere report_id=" . $rptobj->report_id . " and used_type<>'formula'");
    global $ALIAS_counter;
    $ALIAS_counter = 0;
    $tables = array();
    $allRelations = array();
    $EXTRA_QUERY_FROM = "";
    for ($i = 0; $i < count($columns); $i++) {
        $tmp = preg_split('/_/', $columns[$i]["parent_path"]);
        $parent = "";
        $cur_column_alias = "";
        for ($j = 0; $j < count($tmp) - 1; $j++) {
            if (array_search($tmp[$j], $allRelations) === false) {
                array_push($allRelations, $tmp[$j]);
            }
            if (isset($tables[$tmp[$j]])) {
                for ($k = 0; $k < count($tables[$tmp[$j]]["parents"]); $k++) {
                    if ($tables[$tmp[$j]]["parents"][$k][0] == $parent) {
                        $cur_column_alias = $tables[$tmp[$j]]["parents"][$k][1];
                        break;
                    }
                }
                if ($k < count($tables[$tmp[$j]]["parents"])) {
                    $parent .= $parent == "" ? $tmp[$j] : "_" . $tmp[$j];
                    continue;
                }
                $tables[$tmp[$j]]["parents"][] = array($parent, $ALIAS_counter++);
                $cur_column_alias = $ALIAS_counter - 1;
            } else {
                $tables[$tmp[$j]] = array("parents" => array(array($parent, $ALIAS_counter++)));
                $cur_column_alias = $ALIAS_counter - 1;
            }
            $parent .= $parent == "" ? $tmp[$j] : "_" . $tmp[$j];
        }
        //.............................
        $parent_path = $columns[$i]["parent_path"];
        $tmp = preg_split('/_/', $parent_path);
        $column_id = $columns[$i]["column_id"];
        $alias = "tbl" . $cur_column_alias;
        $field = $alias . "." . $columns[$i]["field_name"];
        $base_field = $alias . "." . $columns[$i]["field_name"];
        if ($columns[$i]["basic_type_id"] != "" && $columns[$i]["basic_type_id"] != "0") {
            $EXTRA_QUERY_FROM .= "\n left join Basic_Info as tbl" . $ALIAS_counter . " on(tbl{$ALIAS_counter}.TypeID=" . $columns[$i]["basic_type_id"] . " AND tbl{$ALIAS_counter}.InfoID=" . $alias . "." . $columns[$i]["field_name"] . ")";
            $field = "tbl" . $ALIAS_counter . ".Title";
            $ALIAS_counter++;
        }
        if ($columns[$i]["basic_info_table"] != "" && $columns[$i]["basic_info_table"] != "0") {
            $result = AddInfoTable($allMasters, $allMasters[$columns[$i]["basic_info_table"]], $alias, $columns[$i]["field_name"]);
            $EXTRA_QUERY_FROM .= "\n" . $result["from"];
            $field = addslashes($result["field"]);
        }
        PdoDataAccess::runquery("update rp_report_columns\r\n\t\t\tset field = '" . $field . "', base_field = '" . $base_field . "'\r\n\t\t\twhere row_id=" . $columns[$i]["row_id"]);
    }
    //--------------------------- make from clause -----------------------------
    $relations = PdoDataAccess::runquery("\r\n\t\tselect relation_id,t1.table_name as parent_table_name,t2.table_name as table_name, join_text\r\n\t\tfrom rp_relations r\r\n\t\t\tleft join rp_base_tables t1 on(r.parent_table_id=t1.table_id)\r\n\t\t\tleft join rp_base_tables t2 on(r.table_id=t2.table_id)\r\n\t\twhere relation_id in(" . implode(",", $allRelations) . ") order by relation_id");
    $QUERY_FROM = "\n from " . $relations[0]["table_name"] . " as tbl" . $tables[$relations[0]["relation_id"]]["parents"][0][1];
    for ($i = 1; $i < count($relations); $i++) {
        $relation_id = $relations[$i]["relation_id"];
        for ($j = 0; $j < count($tables[$relation_id]["parents"]); $j++) {
            $on = $relations[$i]["join_text"];
            $on = str_replace("ALIAS2", "tbl" . $tables[$relation_id]["parents"][$j][1], $on);
            $parent = preg_split('/_/', $tables[$relation_id]["parents"][$j][0]);
            $last_parent = $parent[count($parent) - 1];
            unset($parent[count($parent) - 1]);
            $path_parent = implode("_", $parent);
            for ($k = 0; $k < count($tables[$last_parent]["parents"]); $k++) {
                if ($path_parent == $tables[$last_parent]["parents"][$k][0]) {
                    $on = str_replace("ALIAS1", "tbl" . $tables[$last_parent]["parents"][$k][1], $on);
                    break;
                }
            }
            $QUERY_FROM .= "\n left join " . $relations[$i]["table_name"] . " as tbl" . $tables[$relation_id]["parents"][$j][1] . " on(" . $on . ")";
        }
    }
    //--------------------------------------------------------------------------
    $rptobj->query = $QUERY_FROM . $EXTRA_QUERY_FROM;
    $result = $rptobj->Edit();
    if ($result) {
        echo Response::createObjectiveResponse(true, $rptobj->report_id);
    } else {
        print_r(ExceptionHandler::PopAllExceptions());
    }
    die;
    //--------------------- extract all used relations -------------------------
    $columns = PdoDataAccess::runquery("\r\n\t\tselect rc.*,c.*,rt.join_text from rp_report_columns rc\r\n\t\t\tjoin rp_columns c using(column_id)\r\n\t\t\tleft join rp_tables as rt on(rt.table_id=c.basic_info_table)\r\n\t\twhere report_id=" . $rptobj->report_id . " and used_type<>'formula'");
    $allRelations = array();
    $EXTRA_QUERY_FROM = "";
    global $ALIAS_counter;
    $ALIAS_counter = 0;
    $aliases = array();
    for ($i = 0; $i < count($columns); $i++) {
        $tmp = preg_split('/_/', $columns[$i]["parent_path"]);
        for ($j = 0; $j < count($tmp) - 1; $j++) {
            if (array_search($tmp[$j], $allRelations) === false) {
                array_push($allRelations, $tmp[$j]);
            }
        }
        //.............................
        $parent_path = $columns[$i]["parent_path"];
        $tmp = preg_split('/_/', $parent_path);
        $column_id = $columns[$i]["column_id"];
        $relation_id = $tmp[count($tmp) - 2];
        $aliases[$relation_id] = "tbl" . $ALIAS_counter++;
        $alias = $aliases[$relation_id];
        $field = $alias . "." . $columns[$i]["field_name"];
        $base_field = $alias . "." . $columns[$i]["field_name"];
        if ($columns[$i]["basic_type_id"] != "" && $columns[$i]["basic_type_id"] != "0") {
            $EXTRA_QUERY_FROM .= "\n left join Basic_Info as tbl" . $ALIAS_counter . " on(tbl{$ALIAS_counter}.TypeID=" . $columns[$i]["basic_type_id"] . " AND tbl{$ALIAS_counter}.InfoID=" . $alias . "." . $columns[$i]["field_name"] . ")";
            $field = "tbl" . $ALIAS_counter . ".Title";
            $ALIAS_counter++;
        }
        if ($columns[$i]["basic_info_table"] != "" && $columns[$i]["basic_info_table"] != "0") {
            $result = AddInfoTable($allMasters, $allMasters[$columns[$i]["basic_info_table"]], $alias, $columns[$i]["field_name"]);
            $EXTRA_QUERY_FROM .= "\n" . $result["from"];
            $field = addslashes($result["field"]);
        }
        PdoDataAccess::runquery("update rp_report_columns \r\n\t\t\tset field = '" . $field . "', base_field = '" . $base_field . "'\r\n\t\t\twhere row_id=" . $columns[$i]["row_id"]);
    }
    array_multisort($allRelations);
    //--------------------------- make from clause -----------------------------
    $relations = PdoDataAccess::runquery("\r\n\t\tselect relation_id,t1.table_name as parent_table_name,t2.table_name as table_name, join_text\r\n\t\tfrom rp_relations r\r\n\t\t\tleft join rp_base_tables t1 on(r.parent_table_id=t1.table_id)\r\n\t\t\tleft join rp_base_tables t2 on(r.table_id=t2.table_id)\r\n\t\twhere relation_id in(" . implode(",", $allRelations) . ") order by relation_id");
    //$QUERY_FROM = "\n from " . $relations[0]["table_name"] . " as tbl" . $relations[0]["relation_id"];
    $QUERY_FROM = "\n from " . $relations[0]["table_name"] . " as " . $aliases[$relations[0]["relation_id"]];
    //$aliases = array();
    //$aliases[$relations[0]["table_name"]] = "tbl" . $relations[0]["relation_id"];
    $aliases[$relations[0]["table_name"]] = $aliases[$relations[0]["relation_id"]];
    for ($i = 1; $i < count($relations); $i++) {
        $on = $relations[$i]["join_text"];
        $on = str_replace("ALIAS1", $aliases[$relations[$i]["parent_table_name"]], $on);
        //$on = str_replace("ALIAS2", "tbl" . $relations[$i]["relation_id"], $on);
        $on = str_replace("ALIAS2", $aliases[$relations[0]["relation_id"]], $on);
        //$QUERY_FROM .= "\n left join " . $relations[$i]["table_name"] . " as tbl" . $relations[$i]["relation_id"] . " on(" . $on . ")";
        $QUERY_FROM .= "\n left join " . $relations[$i]["table_name"] . " as " . $aliases[$relations[0]["relation_id"]] . " on(" . $on . ")";
        //$aliases[$relations[$i]["table_name"]] = "tbl" . $relations[$i]["relation_id"];
    }
    //--------------------------------------------------------------------------
    $rptobj->query = $QUERY_FROM . $EXTRA_QUERY_FROM;
    $result = $rptobj->Edit();
    if ($result) {
        echo Response::createObjectiveResponse(true, $rptobj->report_id);
    } else {
        print_r(ExceptionHandler::PopAllExceptions());
    }
    die;
}