ria/app/Models/Config_model.php

358 lines
12 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('*')
->where('Config_ID', $ConfigID);
$query = $builder->get();
return $query->getResult();
}
function GetConfigCenterDetails($ConfigID = '',$isActiveFilter)
{
//echo $ConfigID ;die();
$builder = $this->db->table('t_configmaster COM')
->select('COM.*,
con.*,
creator_emp.FirstName AS created_by,
updater_emp.FirstName AS updated_by
')
->join('t_configdetails con', 'con.Config_ID = COM.Config_ID', 'left')
// Join for Created By
->join('tbl_users creator', 'creator.userId = con.created_by', 'left')
->join('t_employee_details creator_emp', 'creator_emp.EmpID = creator.EmpID', 'left')
// Join for Updated By
->join('tbl_users updater', 'updater.userId = con.updated_by', 'left')
->join('t_employee_details updater_emp', 'updater_emp.EmpID = updater.EmpID', 'left')
->where('COM.Config_ID', $ConfigID)
->where('con.isActive', $isActiveFilter)
->orderBy('con.Key', 'desc');
$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);
$builder = $builder->where('REPLACE(configValue , " ", "") ',$configValue);
$query = $builder->get();
return $query->getResultArray();
}
public function activeInactiveConfigValue($key, $value){
$builder = $this->db->table('t_configdetails')
->where('Key',$key)
->update($value);
$res = $this->db->affectedRows();
return $res;
}
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;
}
public function getPONOcreatedBasedOnConfig($key_id){
// $builder = $this->db->table('t_purchaseorder_lineitem PL')
// ->select('PL.PONO, MM.MaterialName, CD.ConfigValue as CategoryName')
// ->join('t_materialmaster MM', 'MM.MaterialCode = PL.MaterialCode', 'left')
// ->join('t_configdetails CD', 'CD.Key = MM.Category', 'left')
// ->where('CD.Key', $key_id);
// $query = $builder->get();
// $result = $query->getResultArray();
// return $result;
// return $this->db->table('t_purchaseorder_lineitem as pl')
// ->select('DISTINCT po.PONO, DATE_FORMAT(po.PODate, "%d-%m-%Y") as PODate, mm.MaterialName, CD.Key, CD.ConfigValue as CategoryName, s.StatusName, s.statusCode, po.POType, po.CapitalRange')
// ->join('t_purchaseorder_master po', 'po.PONO = pl.PONO')
// ->join('t_materialmaster mm', 'mm.MaterialCode = pl.MaterialCode')
// ->join('t_configdetails CD', 'CD.Key = mm.Category')
// ->join('t_status s', 's.statusCode = po.Status', 'left') // Left join
// ->where('CD.Key', $key_id)
// ->whereIn('po.Status', ['ST014', 'ST015', 'ST005', 'ST026', 'ST024', 'ST074', 'ST073'])
// ->orderBy('po.CreatedDate', 'DESC')
// ->get()
// ->getResultArray();
$subQuery = "SELECT DISTINCT po.PONO, DATE_FORMAT(po.PODate, '%d-%m-%Y') as PODate,
mm.MaterialName, CD.Key, CD.ConfigValue as CategoryName,
s.StatusName, s.statusCode, po.POType, po.CapitalRange,
CASE
WHEN s.statusCode = 'ST073' THEN 'OPEN ORDER PO'
WHEN s.statusCode = 'ST074' THEN 'IGR DRAFT'
WHEN s.statusCode = 'ST027' THEN 'IGR CREATED'
WHEN s.statusCode = 'ST024' THEN s.StatusName
WHEN s.statusCode = 'ST014' THEN 'PO DRAFT'
WHEN s.statusCode = 'ST015' THEN 'PO CREATED'
WHEN s.statusCode = 'ST005' THEN s.StatusName
WHEN s.statusCode = 'ST026' THEN 'PO RELEASED'
ELSE s.StatusName
END AS statusDescription
FROM t_purchaseorder_lineitem pl
JOIN t_purchaseorder_master po ON po.PONO = pl.PONO
JOIN t_materialmaster mm ON mm.MaterialCode = pl.MaterialCode
JOIN t_configdetails CD ON CD.Key = mm.Category
LEFT JOIN t_status s ON s.statusCode = po.Status
WHERE CD.Key = ?
AND po.Status IN (?, ?, ?, ?, ?, ?, ?)
ORDER BY po.CreatedDate DESC";
$query = $this->db->query($subQuery, [$key_id, 'ST014', 'ST015', 'ST005', 'ST026', 'ST024', 'ST074', 'ST073']);
$result = $query->getResultArray();
return $result;
// 'OPEN_ORDER_PO','ST073'
// 'IGR_DRAFT','ST074'
// 'IGR_CREATED','ST027'
// 'REQITEM_Emergency_PO_CREATED','ST024'
// 'PO_DRAFT','ST014'
// 'PO_CREATED','ST015'
// 'REQ_PO_CREATED','ST005'
// 'PO_RELEASED','ST026'
}
public function saveConfigValue($key,$configId, $configValue,$userId){
if(!empty($key)){
$builder = $this->db->table('t_configdetails')
->where('Config_ID', $configId)
->where('key',$key)
->update([
'ConfigValue'=> $configValue,
'updated_by' => $userId
]);
$res = $this->db->affectedRows();
return $res;
}else{
$builder = $this->db->table('t_configdetails');
$builder->insert(
[
'ConfigValue'=>$configValue,
'Config_ID'=>$configId,
'created_by'=> $userId,
'isActive'=> 1]);
$res = $this->db->affectedRows();
return $res;
}
}
public function getMaterialCategoryList(){
$result = $this->db->table('t_configdetails')
->where('Config_ID','C023')
->where('isActive',1)
->get()
->getResultArray();
return $result;
}
}