ria/app/Models/Config_model.php
2024-12-19 16:05:39 +05:30

223 lines
6.7 KiB
PHP
Executable File

<?php
namespace App\Models;
use CodeIgniter\Model;
class Config_model extends Model
{
/**
* This function is used to get the user listing count
* @param string $searchText : This is optional search text
* @param number $page : This is pagination offset
* @param number $segment : This is pagination limit
* @return array $result : This is result
*/
function Configlisting()
{
$builder = $this->db->table('t_configmaster as Config')
->select('Config.Config_ID, Config.ConfigName ,Config.Comments,Config.CreatedDate,Config.isActive')
// ->join('t_configdetails as Con','Con.Config_ID=Config.Config_ID')
->orderBy('Config.CreatedDate', 'desc');
//->orderBy('hourlyid','desc');
$query = $builder->get();
$result = $query->getResult();
return $result;
}
/**
* This function used to get user information by id
* @param number $userId : This is user id
* @return array $result : This is user information
*/
public function addconfigmaster($config)
{
$this->db->transStart();
$builder = $this->db->table('t_configmaster');
$builder->insert($config);
$aff_row = $this->db->affectedRows();
$this->db->transComplete();
$sql = 'SELECT MAX(Config_ID) as Config_ID FROM t_configmaster';
$row = $this->db->query($sql)->getRow();
$res = ($aff_row && $row !== null) ? $row->Config_ID : 0;
return $res;
// $logFile = WRITEPATH . 'logs/query.log';
// $lastInsertQuery = $this->db->getLastQuery();
// file_put_contents($logFile, $lastInsertQuery . PHP_EOL, FILE_APPEND);
}
function addconfigdetails($configvalue)
{
//print_r($configvalue);
$this->db->transStart();
$builder = $this->db->table('t_configdetails');
$builder->insert($configvalue);
$res = $this->db->affectedRows();
$this->db->transComplete();
return $res;
}
/* This function used to Department list which is not available in the Costcenter master
* @param number $CostCenterCode : CostCenterCode as Parameter
* @return array $result : This is user information
*/
function GetBudgetTypeNotinCostCenter($CostCenterCode, $ConfigID)
{
$subQuery = 'select ConfigValue from t_configdetails Bud where ConfigValue not in
(select BudgetType from t_costcenter_budget where CostCenterCode=? and BudgetYear=(select max(BudgetYear) from t_costcenter_budget)) and Config_ID=?';
$query = $this->db->query($subQuery, array($CostCenterCode, $ConfigID));
return $query->getResult();
}
function GetConfigCenterMaster($ConfigID = '')
{
$builder = $this->db->table('t_configmaster')
->select('*')
//->join('t_configdetails con','con.Config_ID = COM.Config_ID','left')
->where('Config_ID', $ConfigID);
$query = $builder->get();
return $query->getResult();
}
function GetConfigCenterDetails($ConfigID = '')
{
//echo $ConfigID ;die();
$builder = $this->db->table('t_configmaster COM')
->select('*')
->join('t_configdetails con', 'con.Config_ID = COM.Config_ID', 'left')
->where('COM.Config_ID', $ConfigID);
$query = $builder->get();
return $query->getResult();
}
function updateconfig($config, $Configid)
{
$this->db->table('t_configmaster')
->where('Config_ID', $Configid)
->update($config);
$res = $this->db->affectedRows();
return $res;
}
function updateconfigdetails($configval, $Key)
{
$this->db->table('t_configdetails')
->where('Key', $Key)
->update($configval);
$res = $this->db->affectedRows();
return $res;
}
function EditBudget($Budget)
{
$this->db->transStart();
$builder = $this->db->table('t_costcenter_budget');
$builder->insert($Budget);
$insert_id = $this->db->affectedRows();
$this->db->transComplete();
return $insert_id;
}
function DeleteBudget($BudgetType = '', $BudgetYear = '', $CostCenterCode = '')
{
$this->db->table('t_costcenter_budget')->delete(['BudgetType' => $BudgetType, 'BudgetYear' => $BudgetYear, 'CostCenterCode' => $CostCenterCode]);
}
function DeleteDepartment($DepCode = '', $CostCode = '')
{
$this->db->table('t_costcenter_departments')->delete(['DEPCode' => $DepCode, 'CostCenterCode' => $CostCode]);
}
function checkDeptCostExists($DepCode = '', $CostCode = '')
{
$builder = $this->db->table('t_costcenter_departments')
->select('CostCenterCode,DEPCode')
->where('DEPCode', $DepCode)
->where('CostCenterCode', $CostCode);
$query = $builder->get();
if ($query->getNumRows() > 0) {
return $query->getResultArray();
}
}
/**
* This function is used to get the Config value from configuration table
* @return array $result : This is result of the query
*/
function getConfigValue($ConfigID)
{
$builder = $this->db->table('t_configdetails')
->select('ConfigValue')
->where('Config_id ', $ConfigID);
$query = $builder->get();
return $query->getResult();
}
public function configNameCheck($configId,$configName){
$builder = $this->db->table('t_configmaster');
if(!empty($configId)){
$builder = $builder -> where('Config_ID !=' ,$configId);
}
$builder = $builder->where('REPLACE(ConfigName , " ", "") ',$configName);
$query = $builder->get();
return $query->getResultArray();
}
public function configValueCheck($configId , $configValue){
$builder = $this->db->table('t_configdetails')
->where('Config_ID',$configId)
->where('configValue ', $configValue);
$query = $builder->get();
// dd( $this->db->getLastQuery());
return $query->getResultArray();
}
public function deleteConfigValue($configId, $configValue){
$builder = $this->db->table('t_configdetails')
->where('Config_ID',$configId)
->where('configValue ', $configValue)
->update(['isActive'=> 0]);
$res = $this->db->affectedRows();
return $res;
}
public function reActivateConfigValue($configId, $configValue){
$builder = $this->db->table('t_configdetails')
->where('Config_ID',$configId)
->where('configValue ', $configValue)
->update(['isActive'=> 1]);
$res = $this->db->affectedRows();
return $res;
}
}