ok
Direktori : /home2/selectio/www/mm-tailor-billing/app/models/ |
Current File : /home2/selectio/www/mm-tailor-billing/app/models/Material_usage_model.php |
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } class Material_usage_model extends CI_Model { public function __construct() { parent::__construct(); } public function getAllUnits() { $q = $this->db->get_where('units'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getMaterialUsgaeByID($id) { $q = $this->db->get_where('material_usage', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } /* ************************************************start select units******************************************************/ public function getAllmaterial($material) { $this->db->select("tec_products.name,units,units.name as unit_name") ->join('units', 'tec_products.units=units.id', 'left'); $q = $this->db->get_where('tec_products', ['tec_products.id' => $material]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } /* ************************************************end select units******************************************************/ public function addMaterialUsageRowBased($date,$material,$quantity,$remarks,$created_by,$unit) { for($m=0;$m<count($date);$m++) { error_log($unit[$m]); $this->db->insert('tec_material_usage', ['date' => $date[$m], 'material' => $material[$m],'unit'=>$unit[$m], 'qty' => $quantity[$m], 'remarks' => $remarks[$m], 'created_by' => $created_by]); $material_usage_id = $this->db->insert_id(); if ($material[$m] > 0 && $product = $this->site->getProductByID($material[$m])) { if ($product->type == 'standard') { error_log("Quantity Minus Success"); $this->db->update('product_store_qty', ['quantity' => ($product->quantity - $quantity[$m])], ['product_id' => $material[$m]]); } } } return true; } public function UpdateMaterialUsage($date,$material,$quantity,$remarks,$created_by,$unit, $already_updated_qty, $id) { $this->db->update('tec_material_usage', ['date' => $date, 'material' => $material,'unit'=>$unit, 'qty' => $quantity, 'remarks' => $remarks, 'created_by' => $created_by], ['id' => $id]); if ($material > 0 && $product = $this->site->getProductByID($material)) { $stock_quantity = $product->quantity; $old_material_quantity = $already_updated_qty; $new_quantity = $quantity; error_log("Stock Quantity: ".$stock_quantity); error_log("Material Already Quantity: ".$old_material_quantity); error_log("Material New Quantity: ".$new_quantity); if ($product->type == 'standard') { error_log("Quantity Minus Success"); if($new_quantity<$old_material_quantity){ error_log($old_material_quantity-$new_quantity); $value = $old_material_quantity-$new_quantity; error_log("value new_quantity<old_material_quantity: ".$value); $db_value_now = $stock_quantity+$value; error_log("Already Stock $stock_quantity Now Minus Quantity is $value So Now DB VALUE IS $db_value_now"); $this->db->update('product_store_qty', ['quantity' => ($product->quantity + $value)], ['product_id' => $material]); error_log("IF Plus Updated"); }else if($new_quantity==$old_material_quantity){ error_log("Old value is '.$old_material_quantity.' and New value is '.$new_quantity.' So, 2 Values are Equal So No Updates"); }else{ error_log($old_material_quantity-$new_quantity); $value = $new_quantity-$old_material_quantity; error_log("value else part: ".$value); $db_value_now = $stock_quantity-$value; error_log("Already Stock $stock_quantity Now Minus Quantity is $value So Now DB VALUE IS $db_value_now"); $this->db->update('product_store_qty', ['quantity' => ($product->quantity - $value)], ['product_id' => $material]); error_log("Else Minus Updated"); } /*$this->db->update('product_store_qty', ['quantity' => ($product->quantity - $quantity)], ['product_id' => $material]);*/ } } /*for($m=0;$m<count($date);$m++) { error_log($unit[$m]); $this->db->insert('tec_material_usage', ['date' => $date[$m], 'material' => $material[$m],'unit'=>$unit[$m], 'qty' => $quantity[$m], 'remarks' => $remarks[$m], 'created_by' => $created_by]); $material_usage_id = $this->db->insert_id(); if ($material[$m] > 0 && $product = $this->site->getProductByID($material[$m])) { if ($product->type == 'standard') { error_log("Quantity Minus Success"); $this->db->update('product_store_qty', ['quantity' => ($product->quantity - $quantity[$m])], ['product_id' => $material[$m]]); } } }*/ return true; } public function getAllServiceProducts() { $q = $this->db->get_where('products', ['type' => 'standard']); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllStaff() { $q = $this->db->get('users'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllProductCategory() { $q = $this->db->get('categories'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function add_extra_option($data = []) { if ($this->db->insert_batch('extra_option', $data)) { return true; } return false; } /* ------ Units Section Starts Here -------- */ public function addUnits($name,$description) { if ($this->db->insert('units', ['name' => $name, 'description' => $description])) { return true; } return false; } public function editUnits($name,$description) { if ($this->db->update('units', ['name' => $name, 'description' => $description])) { return true; } return false; } public function updateUnits($id, $data = null) { if ($this->db->update('units', $data, ['id' => $id])) { return true; } return false; } public function deleteUnits($id) { if ($this->db->delete('units', ['id' => $id])) { return true; } return false; } public function materialUsageDelete($id, $material, $qty) { if ($this->db->delete('material_usage', ['id' => $id])) { if ($material > 0 && $product = $this->site->getProductByID($material)) { error_log("Quantity: ".$product->quantity); error_log("Delete Quantity: ".$qty); $value=$product->quantity-$qty; error_log($value); $this->db->update('product_store_qty', ['quantity' => ($product->quantity - $qty)], ['product_id' => $material]); } return true; } error_log("Delete Working"); error_log("Material Usage ID: $id"); error_log("Material Product ID: $material"); error_log("Material Quantity ID: $qty"); /*$this->db->update('product_store_qty', ['quantity' => ($product->quantity - $value)], ['product_id' => $material]);*/ return false; } public function getUnitsByID($id) { $q = $this->db->get_where('units', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } /* ------ Units Section Endss Here -------- */ public function addExtraOption($data) { if ($this->db->insert('extra_option', $data)) { return true; } return false; } public function deleteExtraOption($id) { if ($this->db->delete('extra_option', ['id' => $id])) { return true; } return false; } public function updateExtraOption($id, $data = null) { if ($this->db->update('extra_option', $data, ['id' => $id])) { return true; } return false; } public function getExtraoptionByID($id) { $q = $this->db->get_where('extra_option', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getExpenseByID($id) { $q = $this->db->get_where('material_usage', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getMaterialUsageByID($id) { $this->db->select("material_usage.id,material, date, unit, qty, remarks, products.name as product_name") ->join('products', 'tec_products.id=material_usage.material', 'left'); $q = $this->db->get_where('material_usage', ['material_usage.id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } // New One public function getShirtCategory() { $q = $this->db->get_where('extra_option', ['category' => 1]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getcategoryBasedProducts($category) { $q = $this->db->get_where('products', ['category_id' => $category]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } }