MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/jrset.ncriptech.com/../ecampus.ncriptech.com/application/models/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/jrset.ncriptech.com/../ecampus.ncriptech.com/application/models/Po_model.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');


/**
 * 
 */
class Po_model extends BaseModel
{
    function __constuct(){
        parent::__construct(); 
    }
    
    public function generatePurchaseOrderCode() {
        // Get the last inserted po_id
        $this->_db->select('po_id');
        $this->_db->from('institute_purchase_orders');
        $this->_db->order_by('po_id', 'DESC');
        $this->_db->limit(1);
        $query = $this->_db->get();
        
        if ($query->num_rows() > 0) {
            $row = $query->row();
            $latest_po_id = $row->po_id;
        } else {
            $latest_po_id = 0;
        }
        
        // Calculate the number of digits in $latest_po_id
        $numDigits = strlen((string)$latest_po_id);
        $numDigits = ($numDigits < 5) ? 5 : $numDigits;

        // Generate the purchase order code
        $next_po_id = $latest_po_id + 1;
             
        // Combine all parts to create the purchase order code
        $purchase_order_code = 'PO' . str_pad($next_po_id, $numDigits, '0', STR_PAD_LEFT);
        
        return $purchase_order_code;
    }


    

    public function store_po_order($data,$batch=FALSE,$return_query=FALSE){
        $this->table='institute_purchase_orders';
        return $this->store($data,$batch,$return_query);
    }

    public function update_po_order($data,$param,$batch=FALSE,$return_query=FALSE){
        $this->table='institute_purchase_orders';
        return $this->modify($data,$param,$batch,$return_query);
    }

    public function delete_po_order($param,$return_query=FALSE){
        $this->table='institute_purchase_orders';
        return $this->remove($param,0,$return_query);
    }

    public function get_po_order($param=null,$single_row=TRUE,$return_query=FALSE){
        $this->table='institute_purchase_orders';
        if($single_row==TRUE){
            return $this->get_one($param,'',$return_query);
        }else if($single_row==FALSE){
            return $this->get_many($param,null,null,$return_query);
        }       
    }


    public function _get_po_order($post=array(),$param=array(),$count=FALSE,$return_query=FALSE){
        $this->_db->select('institute_purchase_orders.*');

        $i = 0;

        if(isset($param['column_search'])){
            foreach ($param['column_search'] as $item)
            {
                if(isset($post['search']['value']) && $post['search']['value'])
                {
                    
                    if($i===0)
                    {
                        $this->_db->group_start();
                        $this->_db->like($item, $post['search']['value']);
                    }
                    else
                    {
                        $this->_db->or_like($item, $post['search']['value']);
                    }

                    if(count($param['column_search']) - 1 == $i)
                        $this->_db->group_end();
                }
                
                $i++;
            }
        }

            
        if(isset($post['order']))
        {
            $column_order=$param['column_order'];
            $this->_db->order_by($column_order[$post['order']['0']['column']], $post['order']['0']['dir']);
        } 
        else if(isset($param['order']))
        {
            $order = $param['order'];
            $this->_db->order_by(key($order), $order[key($order)]);
        }

        if($count==FALSE){
            if(isset($post['length']) && $post['length'] != -1){
                $this->_db->limit($post['length'],$post['start']);   
            }
            
            $query = $this->_db->get('institute_purchase_orders');

            if($return_query==FALSE){
                return $query->result();
            }else if($return_query==TRUE){
                return $this->_db->last_query();
            }       
            
        }else if($count==TRUE){
            $query = $this->_db->get('institute_purchase_orders');
            if($return_query==FALSE){
                return $query->num_rows();
            }else if($return_query==TRUE){
                return $this->_db->last_query();
            }           
        }
    }


    public function store_po_order_data($data,$batch=FALSE,$return_query=FALSE){
        $this->table='institute_purchase_orders_data';
        return $this->store($data,$batch,$return_query);
    }

    public function update_po_order_data($data,$param,$batch=FALSE,$return_query=FALSE){
        $this->table='institute_purchase_orders_data';
        return $this->modify($data,$param,$batch,$return_query);
    }

    public function delete_po_order_data($param,$return_query=FALSE){
        $this->table='institute_purchase_orders_data';
        return $this->remove($param,0,$return_query);
    }

    public function get_po_order_data($param=null,$single_row=TRUE,$return_query=FALSE){
        $this->table='institute_purchase_orders_data';
        if($single_row==TRUE){
            return $this->get_one($param,'',$return_query);
        }else if($single_row==FALSE){
            return $this->get_many($param,null,null,$return_query);
        }       
    }

    

    public function get_po_order_total($field,$as,$param=null,$return_query=FALSE){
        $this->table='institute_purchase_orders_data';
        return $this->get_sum($field,$as,$param,$return_query);
    }


    public function _get_po_order_data($post=array(),$param=array(),$count=FALSE,$return_query=FALSE){
        $this->_db->select('institute_purchase_orders_data.*');

        $i = 0;

        if(isset($param['column_search'])){
            foreach ($param['column_search'] as $item)
            {
                if(isset($post['search']['value']) && $post['search']['value'])
                {
                    
                    if($i===0)
                    {
                        $this->_db->group_start();
                        $this->_db->like($item, $post['search']['value']);
                    }
                    else
                    {
                        $this->_db->or_like($item, $post['search']['value']);
                    }

                    if(count($param['column_search']) - 1 == $i)
                        $this->_db->group_end();
                }
                
                $i++;
            }
        }

            
        if(isset($post['order']))
        {
            $column_order=$param['column_order'];
            $this->_db->order_by($column_order[$post['order']['0']['column']], $post['order']['0']['dir']);
        } 
        else if(isset($param['order']))
        {
            $order = $param['order'];
            $this->_db->order_by(key($order), $order[key($order)]);
        }

        if($count==FALSE){
            if(isset($post['length']) && $post['length'] != -1){
                $this->_db->limit($post['length'],$post['start']);   
            }
            
            $query = $this->_db->get('institute_purchase_orders_data');

            if($return_query==FALSE){
                return $query->result();
            }else if($return_query==TRUE){
                return $this->_db->last_query();
            }       
            
        }else if($count==TRUE){
            $query = $this->_db->get('institute_purchase_orders_data');
            if($return_query==FALSE){
                return $query->num_rows();
            }else if($return_query==TRUE){
                return $this->_db->last_query();
            }           
        }
    }



}

MMCT - 2023