<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Stock_model extends CI_Model {

	var $table = 'db_stock';
	var $column_order = array('item_id','category_id','color_id','size_id','sku','stock_qty','cost_price','ins','unit_sales_price_01','unit_sales_price_02','unit_sales_price_03'); //set column field database for datatable orderable
	var $column_search = array('item_id','category_id','color_id','size_id','sku','stock_qty','cost_price','ins','unit_sales_price_01','unit_sales_price_02','unit_sales_price_03'); //set column field database for datatable searchable 
	var $order = array('id' => 'desc'); // default order 

    public function stock_edit($e_st_id,$e_stockQty,$e_costPrice,$e_salePrice_1,$e_salePrice_2,$e_salePrice_3){
		
        $query1="update db_stock set stock_qty = '$e_stockQty', cost_price = '$e_costPrice', unit_sales_price_01 = '$e_salePrice_1', unit_sales_price_02 = '$e_salePrice_2', unit_sales_price_03 = '$e_salePrice_3' where id='$e_st_id'";
        $q_rs = $this->db->simple_query($query1);

        $max_ID =$this->db->query("SELECT MAX(id) AS max_ID FROM stock_edit WHERE stock_id='$e_st_id'")->row()->max_ID;

        $query2 ="UPDATE stock_edit SET stock_qty_new='$e_stockQty',cost_price_new='$e_costPrice',sale_price_1_new='$e_salePrice_1',sale_price_2_new='$e_salePrice_2',sale_price_3_new='$e_salePrice_3' WHERE id ='$max_ID';";
        $this->db->simple_query($query2);

        if ($q_rs!=""){
            return "success";
        }
        else{
            return "failed";
        }
	}
}
