216 lines
6.8 KiB
PHP
Executable File
216 lines
6.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class Department_model extends Model
|
|
{
|
|
/**
|
|
* This function is used to get the user listing count
|
|
* @param string $searchText : This is optional search text
|
|
* @return number $count : This is row count
|
|
*/
|
|
// function departmentListingCount($searchText = '')
|
|
// {
|
|
// ->select('BaseT.DepartmentID, BaseT.SupplierName, BaseT.Address, BaseT.ContactNumber, BaseT.AlternateContactNumber,BaseT.EmailAddress,BaseT.Exiseregistration,BaseT.TIN,BaseT.PAN,BaseT.GSTNO,BaseT.GSTRange,BaseT.CollectrateAddress,BaseT.UANumber,BaseT.PaymentTerms,BaseT.PaymentDays,BaseT.PayableAT');
|
|
// $builder = $this->db->table('t_departmentdetails as BaseT');
|
|
// //->join('tbl_users as users', 'users.userId = BaseT.userId','left');
|
|
// //->join('T_SupplierDetails as ID', 'ID.DepartmentID = BaseT.DepartmentID','left');
|
|
// if(!empty($searchText)) {
|
|
// $likeCriteria = "(BaseT.DepartmentID LIKE '%".$searchText."%'
|
|
// OR BaseT.SupplierName LIKE '%".$searchText."%'
|
|
// OR BaseT.Address LIKE '%".$searchText."%'
|
|
// OR BaseT.ContactNumber LIKE '%".$searchText."%'
|
|
// OR BaseT.AlternateContactNumber LIKE '%".$searchText."%'
|
|
// OR BaseT.EmailAddress LIKE '%".$searchText."%'
|
|
// OR BaseT.Exiseregistration LIKE '%".$searchText."%'
|
|
// OR BaseT.TIN LIKE '%".$searchText."%'
|
|
// OR BaseT.PAN LIKE '%".$searchText."%'
|
|
// OR BaseT.GSTNO LIKE '%".$searchText."%'
|
|
// OR BaseT.GSTRange LIKE '%".$searchText."%'
|
|
// OR BaseT.CollectrateAddress LIKE '%".$searchText."%'
|
|
// OR BaseT.UANumber LIKE '%".$searchText."%'
|
|
// OR BaseT.PaymentTerms LIKE '%".$searchText."%'
|
|
// OR BaseT.PaymentDays LIKE '%".$searchText."%'
|
|
// OR BaseT.PayableAT LIKE '%".$searchText."%')";
|
|
// $this->db->where($likeCriteria);
|
|
// }
|
|
// //$this->db->where('BaseT.isDeleted', 0);
|
|
// //$this->db->where('BaseT.userId !=', 1);
|
|
// $query =$builder->get();
|
|
|
|
// return count($query-getResult());
|
|
// }
|
|
/**
|
|
* 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 departmentListing($isActiveFilter)
|
|
{
|
|
$builder = $this->db->table('t_departmentdetails as BaseT')
|
|
->select('BaseT.CreatedDt,BaseT.DepartmentName, BaseT.DEPCode, BaseT.HeadDept, BaseT.IsActive ,
|
|
BaseT.HeadDept,HeadDept.DepartmentName as headDepartmentName')
|
|
->join('t_departmentdetails as HeadDept', 'BaseT.HeadDept = HeadDept.DEPCode' ,'left')
|
|
->where('BaseT.IsActive',$isActiveFilter)
|
|
->orderBy("BaseT.DEPCode", "desc");
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
// function ($searchText = '')
|
|
// {
|
|
// if(!empty($searchText)) {
|
|
// $likeCriteria = "(BaseT.DepartmentName LIKE '%".$searchText."%'
|
|
// OR BaseT.DEPCode LIKE '%".$searchText."%'
|
|
// OR BaseT.HeadDept LIKE '%".$searchText."%'
|
|
// OR BaseT.IsActive LIKE '%".$searchText."%')";
|
|
// $this->db->where($likeCriteria);
|
|
// }
|
|
// //$this->db->where('BaseT.isDeleted', 0);
|
|
// //$this->db->where('BaseT.userId !=', 1);
|
|
// // $this->db->limit($page, $segment);
|
|
// $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
|
|
*/
|
|
|
|
function savedepartment($department)
|
|
{
|
|
|
|
$builder = $this->db->table('t_departmentdetails');
|
|
$builder->insert($department);
|
|
|
|
$SID = $this->db->affectedRows();
|
|
|
|
return $SID;
|
|
}
|
|
|
|
function getdepcode()
|
|
{
|
|
//$limit = 12;
|
|
$builder = $this->db->table('t_departmentdetails')
|
|
->distinct()
|
|
->select('DEPCode, DepartmentName')
|
|
->where('IsActive =', 1);
|
|
//$this->db->limit($limit);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* This function used to get user information by id
|
|
* @param number $userId : This is user id
|
|
* @return array $result : This is user information
|
|
*/
|
|
function getDeptInfo($DEPCode = '')
|
|
{
|
|
$builder = $this->db->table('t_departmentdetails')
|
|
->select('*')
|
|
->where('DEPCode', $DEPCode);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/* This function to get the Supplier Address on respective Supplier ID */
|
|
|
|
function Updatedepartment($department, $DEPCode)
|
|
{
|
|
$this->db->table('t_departmentdetails')
|
|
->where('DEPCode', $DEPCode)
|
|
->update($department);
|
|
$res = $this->db->affectedRows();
|
|
return $res;
|
|
}
|
|
|
|
function reActivateDepartment($depCode, $updateInfo)
|
|
{
|
|
$this->db->table('t_departmentdetails')
|
|
->where('DEPCode', $depCode)
|
|
->update($updateInfo);
|
|
$res = $this->db->affectedRows();
|
|
return $res;
|
|
}
|
|
|
|
|
|
function deleteDepartment($depCode, $updateInfo)
|
|
{
|
|
$this->db->table('t_departmentdetails')
|
|
->where('DEPCode', $depCode)
|
|
->update($updateInfo);
|
|
$res = $this->db->affectedRows();
|
|
return $res;
|
|
}
|
|
|
|
|
|
function checkDepartmentName($departmentName, $headDepCode, $depCode)
|
|
{
|
|
|
|
$builder = $this->db->table('t_departmentdetails');
|
|
|
|
//post
|
|
if(empty($depCode)) {
|
|
$builder = $builder->where(' HeadDept =', $headDepCode);
|
|
}
|
|
|
|
//put
|
|
if(!empty($depCode)){
|
|
|
|
//allowing current department name to be changed
|
|
//but not other department to get same name
|
|
|
|
$builder = $builder->where(' DEPCode !=', $depCode);
|
|
$builder = $builder->where(' HeadDept =', $headDepCode);
|
|
}
|
|
|
|
$builder = $builder->where('REPLACE(DepartmentName , " ", "") ', $departmentName);
|
|
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResultArray();
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|