? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/rms/application/models/

Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
Upload File :
Current File : /home1/savoy/public_html/savoyglobal.net/rms/application/models/inventorymodel.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Inventorymodel extends CI_Model
{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function deletedata($table,$id,$field)
    {
        $data=array();
        $inventory_id=array();
        $inventory_qty=array();
        $limit='0';
        $this->db->trans_begin();
        $details=$this->mastermodel->get_data('vendor_purchase_details',$id,'vendor_purchase_id');
        
        foreach($details as $row)
        {
            $inventory_id[$limit]=$row['vendor_purchase_inventory_id'];
            $inventory_qty[$limit]=$row['vendor_purchase_inventory_qty'];
            $limit++;
        }
            $row=array();
            $amt=array();
                         
                            
        for($i=0;$i<$limit;$i++)
        {
          $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
            if(in_array($inventory_id[$i], $row))
            {
            $quantity=$amt[$inventory_id[$i]]-$inventory_qty[$i];
                $tblValues=array(
                    'stock_inventory_qty'=>$quantity,                            
                );
                    $this->db->where('stock_inventory_id',$inventory_id[$i]);
                    $this->db->update('stock',$tblValues); 
            }
        } 
        $this->db->delete($table,array($field=>$id));
        $this->db->trans_status();
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Unable to delete record because of associated data';
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Data Deleted Successfully';
        }
        return $data;
    }

    /*functions for vendor purchase */
    
     function search_vendor_purchase($pagenum)
    {
        $data=array();     
        $this->db->select('*');
        $this->db->from('vendor_purchase');
        $this->db->join('master','master_id=vendor_purchase_id');
        $this->db->join('vendor','vendor_purchase.vendor_id=vendor.vendor_id');
        $this->db->where('master.login_type_id',$_SESSION['login_type']);
        $this->db->order_by('vendor_purchase_id','desc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function insert_vendor_purchase($postdata)
    {
        $data=array();       
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();
        $code=$this->mastermodel->get_master_code('vendor_purchase','Vendor Purchase','vendor_purchase_code','vendor_purchase_id');
        $date=$this->mastermodel->convertdateformat($postdata['vendor_purchase_date']);        
        $tblValues=array(
                        'vendor_purchase_id'=>$masterid,
                        'vendor_purchase_code'=>$code,
                        'vendor_id'=>$postdata['vendor_id'],
                        'vendor_purchase_date'=>$date,                        
                        'vendor_purchase_invoice_no'=>$postdata['vendor_purchase_invoice_no'],
                        'vendor_purchase_remarks'=>$postdata['vendor_purchase_remarks']                       
            );
        $this->db->insert('vendor_purchase', $tblValues);
        
     
        $i=1;
        
        while(isset($postdata['vendor_purchase_inventory_id'.$i]))
        {
            $inventory_id=$postdata['vendor_purchase_inventory_id'.$i];
            if($inventory_id!="")
            {
                
                $row=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
                $tblValues=array(
                        'vendor_purchase_id'=>$masterid,
                        'vendor_purchase_inventory_id'=>$inventory_id,
                        'vendor_purchase_inventory_qty'=>$postdata['vendor_purchase_inventory_qty'.$i],
                        'vendor_purchase_inventory_amount'=>$postdata['vendor_purchase_inventory_amount'.$i],
                        'vendor_purchase_discount'=>$postdata['vendor_purchase_discount'.$i]
                );                
                $this->db->insert('vendor_purchase_details',$tblValues);
            
                if(in_array($inventory_id,$row))
                {  
                   $quantity=$amt[$inventory_id];
                   $quantity=$quantity+$postdata['vendor_purchase_inventory_qty'.$i];
                     
                   $tblValues=array(
                         'stock_inventory_qty'=>$quantity                         
                         );
                     $this->db->where('stock_inventory_id',$inventory_id);
                     $this->db->update('stock',$tblValues);
                }
                else {
                  $masterid2 = $this->mastermodel->insertmasterdata();
                  $tblValues=array(
                      'stock_id'=>$masterid2,
                      'stock_inventory_id'=>$inventory_id,
                      'stock_inventory_qty'=>$postdata['vendor_purchase_inventory_qty'.$i]
                  );  
                  $this->db->insert('stock',$tblValues);
                }
            }
            $i++;
        }
                        
        $data['resfunction']='search_vendor_purchase';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Added Successfully';
            return $data;
        }
    } 
    
    function update_vendor_purchase($postdata)
    {        
        $data=array();       
        $this->db->trans_begin();             
        $date=$this->mastermodel->convertdateformat($postdata['vendor_purchase_date']);   
        $id=$postdata['vendor_purchase_id'];
        $tblValues=array(                       
                        'vendor_id'=>$postdata['vendor_id'],
                        'vendor_purchase_date'=>$date,                        
                        'vendor_purchase_invoice_no'=>$postdata['vendor_purchase_invoice_no'],
                        'vendor_purchase_remarks'=>$postdata['vendor_purchase_remarks']                       
            );
        $this->db->where('vendor_purchase_id',$id);
        $this->db->update('vendor_purchase', $tblValues);
        $amt=array();       
        $row=array();
        $invetory_id=explode(',',$postdata['inventory_id']);
        $inventory_qty=explode(',',$postdata['inventory_qty']);
        $limit=$postdata['limit'];
        for($i=0;$i<$limit;$i++)
        {
            $this->db->select('*');
            $this->db->from('stock');              
            $value=$this->db->get();
            if ($value->num_rows() > 0)
            {
                foreach($value->result_array() as $ar)
                {
                    $row[]=$ar['stock_inventory_id']; 
                    $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                }
            }                         
            if(in_array($invetory_id[$i], $row))
            {
            $quantity=$amt[$invetory_id[$i]]-$inventory_qty[$i];
                $tblValues=array(
                    'stock_inventory_qty'=>$quantity                            
                );
                $this->db->where('stock_inventory_id',$invetory_id[$i]);
                $this->db->update('stock',$tblValues); 
            }
        } 
        $this->db->where('vendor_purchase_id',$id);
        $this->db->delete('vendor_purchase_details');   
        $i=1;
        while(isset($postdata['vendor_purchase_inventory_id'.$i]))
        {
            $inventory_id=$postdata['vendor_purchase_inventory_id'.$i];
            if($inventory_id!="")
            {
                
                $row=array();
                $amt=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
                $tblValues=array(
                        'vendor_purchase_id'=>$id,
                        'vendor_purchase_inventory_id'=>$inventory_id,
                        'vendor_purchase_inventory_qty'=>$postdata['vendor_purchase_inventory_qty'.$i],
                        'vendor_purchase_inventory_amount'=>$postdata['vendor_purchase_inventory_amount'.$i],
                        'vendor_purchase_discount'=>$postdata['vendor_purchase_discount'.$i]
                );                
                $this->db->insert('vendor_purchase_details',$tblValues);
            
                if(in_array($inventory_id,$row))
                {  
                   $quantity=$amt[$inventory_id];
                   $quantity=$quantity+$postdata['vendor_purchase_inventory_qty'.$i];                        
                   $tblValues=array(
                         'stock_inventory_qty'=>$quantity                         
                         );
                     $this->db->where('stock_inventory_id',$inventory_id);
                     $this->db->update('stock',$tblValues);
                }
                else {
                  $masterid2 = $this->mastermodel->insertmasterdata();
                  $tblValues=array(
                      'stock_id'=>$masterid2,
                      'stock_inventory_id'=>$inventory_id,
                      'stock_inventory_qty'=>$postdata['vendor_purchase_inventory_qty'.$i]
                  );  
                  $this->db->insert('stock',$tblValues);
                }
            }
            $i++;
        }
        
        $data['resfunction']='search_vendor_purchase';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Updated Successfully';
            return $data;
        }
    }   
    /* functions for vendor payment */
    function search_vendor_payment($pagenum)
    {
        $data=array();     
        $this->db->select('*');
        $this->db->from('vendor_payment');
        $this->db->join('master','master_id=vendor_payment_id');
        $this->db->join('vendor','vendor_payment_vendor_id=vendor.vendor_id');
        $this->db->where('master.login_type_id',$_SESSION['login_type']);
        $this->db->order_by('vendor_payment_id','desc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function insert_vendor_payment($postdata)
    {
        $data=array();       
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();        
        $date=$this->mastermodel->convertdateformat($postdata['vendor_payment_date']);        
        $tblValues=array(
                        'vendor_payment_id'=>$masterid,                        
                        'vendor_payment_vendor_id'=>$postdata['vendor_payment_vendor_id'],
                        'vendor_payment_date'=>$date,                        
                        'vendor_payment_amount'=>$postdata['vendor_payment_amount'],
                        'vendor_payment_type'=>$postdata['vendor_payment_type'],
                        'vendor_payment_remarks'=>$postdata['vendor_payment_remarks']
            );
        $this->db->insert('vendor_payment', $tblValues);
                
        $data['resfunction']='search_vendor_payment';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Added Successfully';
            return $data;
        }
    } 
    function update_vendor_payment($postdata)
    {
        $data=array();       
        $this->db->trans_begin();             
        $date=$this->mastermodel->convertdateformat($postdata['vendor_payment_date']);        
        $tblValues=array(                        
                        'vendor_payment_vendor_id'=>$postdata['vendor_payment_vendor_id'],
                        'vendor_payment_date'=>$date,                        
                        'vendor_payment_amount'=>$postdata['vendor_payment_amount'],
                        'vendor_payment_type'=>$postdata['vendor_payment_type'],
                        'vendor_payment_remarks'=>$postdata['vendor_payment_remarks']
            );
        $this->db->where('vendor_payment_id',$postdata['vendor_payment_id']);
        $this->db->update('vendor_payment', $tblValues);
                
        $data['resfunction']='search_vendor_payment';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Added Successfully';
            return $data;
        }
    } 
    /* functions for stock maintenance */
    
    function search_stock_maintenance($pagenum)
    {
        $data=array();     
        $this->db->select('*');
        $this->db->from('stock_maintenance');
        $this->db->join('master','master_id=stock_maintenance_id');
        $this->db->where('master.login_type_id',$_SESSION['login_type']);
        $this->db->order_by('stock_maintenance_id','desc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function insert_stock_maintenance($postdata)
    {
        $data=array();       
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();     
        $date=$this->mastermodel->convertdateformat($postdata['stock_maintenance_date']);        
        $tblValues=array(
                        'stock_maintenance_id'=>$masterid,   
                        'stock_maintenance_subject'=>$postdata['stock_maintenance_subject'],        
                        'stock_maintenance_date'=>$date,                                                             
            );
        $this->db->insert('stock_maintenance', $tblValues);
                
         $i=1;
        
        while(isset($postdata['stock_maintenance_inventory_id'.$i]))
        {
            $inventory_id=$postdata['stock_maintenance_inventory_id'.$i];
            if($inventory_id!="")
            {
                
                $row=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
                $tblValues=array(
                        'stock_maintenance_id'=>$masterid,
                        'stock_maintenance_inventory_id'=>$inventory_id,
                        'stock_maintenance_inventory_qty'=>$postdata['stock_maintenance_inventory_qty'.$i],
                        'stock_maintenance_remarks'=>$postdata['stock_maintenance_remarks'.$i]
                );                
                $this->db->insert('stock_maintenance_details',$tblValues);
            
                if(in_array($inventory_id,$row))
                {  
                   $quantity=$amt[$inventory_id];
                   $quantity=$quantity+$postdata['stock_maintenance_inventory_qty'.$i];
                     
                   $tblValues=array(
                         'stock_inventory_qty'=>$quantity                         
                         );
                     $this->db->where('stock_inventory_id',$inventory_id);
                     $this->db->update('stock',$tblValues);
                }
                else {
                  $masterid2 = $this->mastermodel->insertmasterdata();
                  $tblValues=array(
                      'stock_id'=>$masterid2,
                      'stock_inventory_id'=>$inventory_id,
                      'stock_inventory_qty'=>$postdata['stock_maintenance_inventory_qty'.$i]
                  );  
                  $this->db->insert('stock',$tblValues);
                }
            }
            $i++;
        }
        
        $data['resfunction']='search_stock_maintenance';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Added Successfully';
            return $data;
        }
    } 
    function update_stock_maintenance($postdata)
    {
        $data=array();       
        $this->db->trans_begin();   
        $id=$postdata['stock_maintenance_id'];
        $date=$this->mastermodel->convertdateformat($postdata['stock_maintenance_date']);        
        $tblValues=array(                                                          
                        'stock_maintenance_date'=>$date,                                                              
            );
        $this->db->where('stock_maintenance_id',$postdata['stock_maintenance_id']);
        $this->db->update('stock_maintenance', $tblValues);
        
        
         $amt=array();       
        $row=array();
        $invetory_id=explode(',',$postdata['inventory_id']);
        $inventory_qty=explode(',',$postdata['inventory_qty']);
        $limit=$postdata['limit'];
        for($i=0;$i<$limit;$i++)
        {
            $this->db->select('*');
            $this->db->from('stock');              
            $value=$this->db->get();
            if ($value->num_rows() > 0)
            {
                foreach($value->result_array() as $ar)
                {
                    $row[]=$ar['stock_inventory_id']; 
                    $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                }
            }                         
            if(in_array($invetory_id[$i], $row))
            {
            $quantity=$amt[$invetory_id[$i]]-$inventory_qty[$i];
                $tblValues=array(
                    'stock_inventory_qty'=>$quantity                            
                );
                $this->db->where('stock_inventory_id',$invetory_id[$i]);
                $this->db->update('stock',$tblValues); 
            }
        } 
        $this->db->where('stock_maintenance_id',$id);
        $this->db->delete('stock_maintenance_details');   
        $i=1;
        while(isset($postdata['stock_maintenance_inventory_id'.$i]))
        {
            $inventory_id=$postdata['stock_maintenance_inventory_id'.$i];
            if($inventory_id!="")
            {
                
                $row=array();
                $amt=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
                $tblValues=array(
                        'stock_maintenance_id'=>$id,
                        'stock_maintenance_inventory_id'=>$inventory_id,
                        'stock_maintenance_inventory_qty'=>$postdata['stock_maintenance_inventory_qty'.$i],
                        'stock_maintenance_remarks'=>$postdata['stock_maintenance_remarks'.$i]
                );                
                $this->db->insert('stock_maintenance_details',$tblValues);
            
                if(in_array($inventory_id,$row))
                {  
                   $quantity=$amt[$inventory_id];
                   $quantity=$quantity+$postdata['stock_maintenance_inventory_qty'.$i];                        
                   $tblValues=array(
                         'stock_inventory_qty'=>$quantity                         
                         );
                     $this->db->where('stock_inventory_id',$inventory_id);
                     $this->db->update('stock',$tblValues);
                }
                else {
                  $masterid2 = $this->mastermodel->insertmasterdata();
                  $tblValues=array(
                      'stock_id'=>$masterid2,
                      'stock_inventory_id'=>$inventory_id,
                      'stock_inventory_qty'=>$postdata['stock_maintenance_inventory_qty'.$i]
                  );  
                  $this->db->insert('stock',$tblValues);
                }
            }
            $i++;
        }
        
        $data['resfunction']='search_stock_maintenance';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Updated Successfully';
            return $data;
        }
    }        
    function deletestockmaintenancedata($table,$id,$field)
    {
        $data=array();
        $inventory_id=array();
        $inventory_qty=array();
        $limit='0';
        $this->db->trans_begin();
        $details=$this->mastermodel->get_data('stock_maintenance_details',$id,'stock_maintenance_id');
        
        foreach($details as $row)
        {
            $inventory_id[$limit]=$row['stock_maintenance_inventory_id'];
            $inventory_qty[$limit]=$row['stock_maintenance_inventory_qty'];
            $limit++;
        }
            $row=array();
            $amt=array();
                         
                            
        for($i=0;$i<$limit;$i++)
        {
          $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
            if(in_array($inventory_id[$i], $row))
            {
            $quantity=$amt[$inventory_id[$i]]-$inventory_qty[$i];
                $tblValues=array(
                    'stock_inventory_qty'=>$quantity,                            
                );
                    $this->db->where('stock_inventory_id',$inventory_id[$i]);
                    $this->db->update('stock',$tblValues); 
            }
        } 
        $this->db->delete($table,array($field=>$id));
        $this->db->trans_status();
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Unable to delete record because of associated data';
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Data Deleted Successfully';
        }
        return $data;
    }
    
    /* functions for inventory utilization */
    
    function search_inventory_utilization($pagenum)
    {
        $data=array();     
        $this->db->select('*');
        $this->db->from('inventory_utilization');
        $this->db->join('master','master_id=inventory_utilization_id');
        $this->db->join('building_details','building_id=inventory_utilization_building_id');
        $this->db->join('employee','employee_id=inventory_utilization_supervisor_id');
        $this->db->where('master.login_type_id',$_SESSION['login_type']);
        $this->db->order_by('inventory_utilization_id','desc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function insert_inventory_utilization($postdata)
    {
       $data=array();       
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();       
        $date=$this->mastermodel->convertdateformat($postdata['inventory_utilization_date']);        
        $tblValues=array(
                        'inventory_utilization_id'=>$masterid,                  
                        'inventory_utilization_building_id'=>$postdata['inventory_utilization_building_id'],
                        'inventory_utilization_date'=>$date,                        
                        'inventory_utilization_supervisor_id'=>$postdata['inventory_utilization_supervisor_id'],
                        'inventory_utilization_remarks'=>$postdata['inventory_utilization_remarks']                       
            );
        $this->db->insert('inventory_utilization', $tblValues);
        
     
        $i=1;
        
        while(isset($postdata['inventory_utilization_stock_id'.$i]))
        {
            $inventory_id=$postdata['inventory_utilization_stock_id'.$i];
            if($inventory_id!="")
            {                
                $row=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
                $tblValues=array(
                        'inventory_utilization_id'=>$masterid,
                        'inventory_utilization_stock_id'=>$inventory_id,
                        'inventory_utilization_stock_qty'=>$postdata['inventory_utilization_stock_qty'.$i],
                        'inventory_utilization_stock_make'=>$postdata['inventory_utilization_stock_make'.$i],
                        'inventory_utilization_stock_sl_no'=>$postdata['inventory_utilization_stock_sl_no'.$i]
                );                
                $this->db->insert('inventory_utilization_details',$tblValues);
            
                if(in_array($inventory_id,$row))
                {  
                   $quantity=$amt[$inventory_id];
                   $quantity=$quantity-$postdata['inventory_utilization_stock_qty'.$i];
                     
                   $tblValues=array(
                         'stock_inventory_qty'=>$quantity                         
                         );
                     $this->db->where('stock_inventory_id',$inventory_id);
                     $this->db->update('stock',$tblValues);
                }
            }
            $i++;
        }
                        
        $data['resfunction']='search_inventory_utilization';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Added Successfully';
            return $data;
        }
 }
function update_inventory_utilization($postdata)
{
        $data=array();       
        $this->db->trans_begin();             
        $date=$this->mastermodel->convertdateformat($postdata['inventory_utilization_date']);   
            $id=$postdata['inventory_utilization_id'];
         $tblValues=array(                               
                        'inventory_utilization_date'=>$date,                        
                        'inventory_utilization_supervisor_id'=>$postdata['inventory_utilization_supervisor_id'],
                        'inventory_utilization_remarks'=>$postdata['inventory_utilization_remarks']                       
            );
        $this->db->where('inventory_utilization_id',$id);
        $this->db->update('inventory_utilization',$tblValues);
       $amt=array();       
       $row=array();                     
       $invetory_id=explode(',',$postdata['inventory_id']);
       $inventory_qty=explode(',',$postdata['inventory_qty']);
        $limit=$postdata['limit'];
        for($i=0;$i<$limit;$i++)
        {
             $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                         
            if(in_array($invetory_id[$i], $row))
            {
            $quantity=$amt[$invetory_id[$i]]+$inventory_qty[$i];          
                $tblValues=array(
                    'stock_inventory_qty'=>$quantity                            
                );
                    $this->db->where('stock_inventory_id',$invetory_id[$i]);
                    $this->db->update('stock',$tblValues); 
            }
        } 
            $this->db->where('inventory_utilization_id',$id);
            $this->db->delete('inventory_utilization_details');   
        $i=1;
        while(isset($postdata['inventory_utilization_stock_id'.$i]))
        {
            $inventory_id=$postdata['inventory_utilization_stock_id'.$i];
            if($inventory_id!="")
            {
                
                $row=array();
                $amt=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
                $tblValues=array(
                        'inventory_utilization_id'=>$id,
                        'inventory_utilization_stock_id'=>$inventory_id,
                        'inventory_utilization_stock_qty'=>$postdata['inventory_utilization_stock_qty'.$i],
                        'inventory_utilization_stock_make'=>$postdata['inventory_utilization_stock_make'.$i],
                        'inventory_utilization_stock_sl_no'=>$postdata['inventory_utilization_stock_sl_no'.$i]
                );                
                $this->db->insert('inventory_utilization_details',$tblValues);
            
                if(in_array($inventory_id,$row))
                {  
                   $quantity=$amt[$inventory_id];
                   $quantity=$quantity-$postdata['inventory_utilization_stock_qty'.$i];                        
                   $tblValues=array(
                         'stock_inventory_qty'=>$quantity                         
                         );
                     $this->db->where('stock_inventory_id',$inventory_id);
                     $this->db->update('stock',$tblValues);
                }
            }
            $i++;
        }
        
        $data['resfunction']='search_inventory_utilization';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Updated Successfully';
            return $data;
        }
}
    function deleteutilization($table,$id,$field)
    {
        $data=array();
        $inventory_id=array();
        $inventory_qty=array();
        $limit='0';
        $this->db->trans_begin();
        $details=$this->mastermodel->get_data('inventory_utilization_details',$id,'inventory_utilization_id');
        
        foreach($details as $row)
        {
            $inventory_id[$limit]=$row['inventory_utilization_stock_id'];
            $inventory_qty[$limit]=$row['inventory_utilization_stock_qty'];
            $limit++;
        }
            $row=array();
            $amt=array();
                         
                            
        for($i=0;$i<$limit;$i++)
        {
          $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
            if(in_array($inventory_id[$i], $row))
            {
            $quantity=$amt[$inventory_id[$i]]+$inventory_qty[$i];
                $tblValues=array(
                    'stock_inventory_qty'=>$quantity,                            
                );
                    $this->db->where('stock_inventory_id',$inventory_id[$i]);
                    $this->db->update('stock',$tblValues); 
            }
        } 
        $this->db->delete($table,array($field=>$id));
        $this->db->trans_status();
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Unable to delete record because of associated data';
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Data Deleted Successfully';
        }
        return $data;
    }
/* functions for inventory return*/
 function search_inventory_return()
 {
   $data=array();     
        $this->db->select('*');
        $this->db->from('inventory_return');
        $this->db->join('master','master_id=inventory_return_id');
        $this->db->join('building_details','building_id=inventory_return_building_id');
        $this->db->join('employee','employee_id=inventory_return_supervisor_id');
        $this->db->where('master.login_type_id',$_SESSION['login_type']);
        $this->db->order_by('inventory_return_id','desc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function insert_inventory_return($postdata)
    {
       $data=array();       
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();       
        $date=$this->mastermodel->convertdateformat($postdata['inventory_return_date']);        
        $tblValues=array(
                        'inventory_return_id'=>$masterid,                  
                        'inventory_return_building_id'=>$postdata['inventory_return_building_id'],
                        'inventory_return_date'=>$date,                        
                        'inventory_return_supervisor_id'=>$postdata['inventory_return_supervisor_id'],
                        'inventory_return_remarks'=>$postdata['inventory_return_remarks']                       
            );
        $this->db->insert('inventory_return', $tblValues);
        
        
         $row=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                      
        $limit=$postdata['limit'];
        for($i=1;$i<$limit;$i++)
        {
            $id=$postdata['inventory_return_stock_id_'.$i];
            $qt=$postdata['inventory_return_stock_qty_'.$i];
          $tblValues=array(
                        'inventory_return_id'=>$masterid,
                        'inventory_return_stock_id'=>$postdata['inventory_return_stock_id_'.$i],
                        'inventory_return_stock_qty'=>$postdata['inventory_return_stock_qty_'.$i],
                        'inventory_return_stock_make'=>$postdata['inventory_return_stock_make_'.$i],
                        'inventory_return_stock_sl_no'=>$postdata['inventory_return_stock_sl_no_'.$i],          
                        'inventory_return_stock_description'=>$postdata['inventory_return_stock_description_'.$i]
                );   
           $this->db->insert('inventory_return_details',$tblValues);
           
           $qty=$amt[$id]+$qt;
           $tblValues=array(
               'stock_inventory_qty'=>$qty
           );
           $this->db->where('stock_inventory_id',$id);
           $this->db->update('stock',$tblValues);
        }
                                
        $data['resfunction']='search_inventory_return';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Adding Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Added Successfully';
            return $data;
        }
    }
    function update_inventory_return($postdata)
    {
        $data=array();       
        $this->db->trans_begin();             
        $date=$this->mastermodel->convertdateformat($postdata['inventory_return_date']);   
        $id=$postdata['inventory_return_id'];
        $tblValues=array(                                                      
                        'inventory_return_date'=>$date,                        
                        'inventory_return_supervisor_id'=>$postdata['inventory_return_supervisor_id'],
                        'inventory_return_remarks'=>$postdata['inventory_return_remarks']                       
            );
        $this->db->where('inventory_return_id',$id);
        $this->db->update('inventory_return',$tblValues);
        $amt=array();       
                $row=array();
                $amt=array();
                $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                  
            $this->db->where('inventory_return_id',$id);
            $this->db->delete('inventory_return_details');   
            
            $limit=$postdata['limit'];
                for($i=1;$i<$limit;$i++)
                {
                    $id=$postdata['inventory_return_stock_id_'.$i];
                    $qt=$postdata['inventory_return_stock_qty_'.$i]-$postdata['inventory_return_old_stock_qty_'.$i];
                    $tblValues=array(
                                'inventory_return_id'=>$postdata['inventory_return_id'],
                                'inventory_return_stock_id'=>$postdata['inventory_return_stock_id_'.$i],
                                'inventory_return_stock_qty'=>$postdata['inventory_return_stock_qty_'.$i],
                                'inventory_return_stock_make'=>$postdata['inventory_return_stock_make_'.$i],
                                'inventory_return_stock_sl_no'=>$postdata['inventory_return_stock_sl_no_'.$i], 
                                'inventory_return_stock_description'=>$postdata['inventory_return_stock_description_'.$i]
                        );   
           $this->db->insert('inventory_return_details',$tblValues);
           
           $qty=$amt[$id]+$qt;
           $tblValues=array(
               'stock_inventory_qty'=>$qty
           );
           $this->db->where('stock_inventory_id',$id);
           $this->db->update('stock',$tblValues);
        }
                    
        $data['resfunction']='search_inventory_return';
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Error On Updating Record';
            return $data;
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Record Updated Successfully';
            return $data;
        }
}
    function deletereturn($table,$id,$field)
    {
        $data=array();
        $inventory_id=array();
        $inventory_qty=array();
        $limit='0';
        $this->db->trans_begin();
        $details=$this->mastermodel->get_data('inventory_return_details',$id,'inventory_return_id');
        
        foreach($details as $row)
        {
            $inventory_id[$limit]=$row['inventory_return_stock_id'];
            $inventory_qty[$limit]=$row['inventory_return_stock_qty'];
            $limit++;
        }
            $row=array();
            $amt=array();
                         
                            
        for($i=0;$i<$limit;$i++)
        {
          $this->db->select('*');
                $this->db->from('stock');              
                $value=$this->db->get();
                if ($value->num_rows() > 0)
                {
                    foreach($value->result_array() as $ar)
                    {
                        $row[]=$ar['stock_inventory_id']; 
                        $amt[$ar['stock_inventory_id']]=$ar['stock_inventory_qty'];
                    }
                }                 
            if(in_array($inventory_id[$i], $row))
            {
            $quantity=$amt[$inventory_id[$i]]-$inventory_qty[$i];
                $tblValues=array(
                    'stock_inventory_qty'=>$quantity,                            
                );
                    $this->db->where('stock_inventory_id',$inventory_id[$i]);
                    $this->db->update('stock',$tblValues); 
            }
        } 
        $this->db->delete($table,array($field=>$id));
        $this->db->trans_status();
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            $data['res']=0;
            $data['msg']='Unable to delete record because of associated data';
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Data Deleted Successfully';
        }
        return $data;
    }

}

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net