59 lines
2.0 KiB
PHP
Executable File
59 lines
2.0 KiB
PHP
Executable File
<?php
|
|
namespace App\Models;
|
|
use CodeIgniter\Model;
|
|
class ProductModel extends Model
|
|
{
|
|
protected $table = 'products';
|
|
protected $primaryKey = 'product_id';
|
|
protected $allowedFields = ['sku_id','product_id','rack_number','manufacturer_id','make_id','models_id',
|
|
'quality','product_name','branch_id','prefered_vendor','product_category','mfr_part_no','purchase_order_level',
|
|
'unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level',
|
|
'handler','qty_in_demand','product_image','description','specification','hsn_sac','isactive','total_amount',
|
|
'per','ml','box','qty_per_box','barrel','ltr_per_barrel','cubic_centimeter_id'];
|
|
protected $beforeInsert = ['setCreatedBy'];
|
|
protected $beforeUpdate = ['setUpdatedBy'];
|
|
|
|
protected function setCreatedBy(array $data)
|
|
{
|
|
$data['data']['created_by'] = (int) session()->get('logged_user');
|
|
return $data;
|
|
}
|
|
|
|
protected function setUpdatedBy(array $data)
|
|
{
|
|
$data['data']['updated_by'] = (int) session()->get('logged_user');
|
|
return $data;
|
|
}
|
|
|
|
public function getTax()
|
|
{
|
|
// Get a database instance
|
|
$db = \Config\Database::connect();
|
|
|
|
// Query the tax table
|
|
$query = $db->table('tax')->get();
|
|
|
|
// Check if query returned results
|
|
if ($query->resultID->num_rows > 0) {
|
|
return $query->getResultArray();
|
|
} else {
|
|
return []; // Return an empty array if no tax data found
|
|
}
|
|
}
|
|
|
|
public function get_products($branch_id,$category = null)
|
|
{
|
|
$this->select('products.*, manufacturer.manufacturer_name');
|
|
$this->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left');
|
|
$this->where('products.branch_id', $branch_id);
|
|
if($category != null)
|
|
{
|
|
$this->where('products.product_category', $category);
|
|
}
|
|
$this->orderBy('products.product_name');
|
|
return $this->findAll();
|
|
}
|
|
|
|
|
|
}
|
|
?>
|