FIX_Product CC Implement

This commit is contained in:
venba-Inspriron-3558 2025-10-30 14:24:14 +05:30
parent c725f80529
commit 2c0ba2e438
16 changed files with 439 additions and 319 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
/writable /writable
vendor/* vendor
.env .env
!vendor/.gitkeep !vendor/.gitkeep
composer.lock composer.lock

View File

@ -460,7 +460,7 @@ class Jobcard extends BaseController
$vehicle = $this->VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id')); $vehicle = $this->VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
$product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id') ->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id','left')
->where('products.isactive',1) ->where('products.isactive',1)
->where('products.branch_id',$this->session->get('logged_user_branch_id')) ->where('products.branch_id',$this->session->get('logged_user_branch_id'))
->findAll(); ->findAll();
@ -505,7 +505,7 @@ class Jobcard extends BaseController
$product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name') $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id') ->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->whereIn('job_card_product.job_card_product_id', $product_ids)->findAll(); ->whereIn('job_card_product.job_card_product_id', $product_ids)->findAll();
$value['product'] = $product; $value['product'] = $product;
@ -526,7 +526,7 @@ class Jobcard extends BaseController
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0]; $product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
$product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock,manufacturer.manufacturer_name') $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock,manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id') ->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->whereIn('job_card_product_id', $product_ids) ->whereIn('job_card_product_id', $product_ids)
->findAll(); ->findAll();
$value['product'] = $product; $value['product'] = $product;
@ -540,7 +540,7 @@ class Jobcard extends BaseController
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0]; $product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
$product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name') $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id') ->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->whereIn('job_card_product_id', $product_ids) ->whereIn('job_card_product_id', $product_ids)
->findAll(); ->findAll();
$value['product'] = $product; $value['product'] = $product;
@ -554,7 +554,7 @@ class Jobcard extends BaseController
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0]; $product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
$product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name') $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id') ->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->whereIn('job_card_product_id', $product_ids) ->whereIn('job_card_product_id', $product_ids)
->findAll(); ->findAll();
$value['product'] = $product; $value['product'] = $product;
@ -595,20 +595,29 @@ class Jobcard extends BaseController
$model_name = $this->BikemodelsModel->where('model_id',$modelId)->select('model_name')->first(); $model_name = $this->BikemodelsModel->where('model_id',$modelId)->select('model_name')->first();
$data['make_model'] = $make_name['make'].' ' . $model_name['model_name']; $data['make_model'] = $make_name['make'].' ' . $model_name['model_name'];
// Encode the modelId before searching // Encode the modelId before searching
$encodedModelId = json_encode([$makeId]); // $encodedModelId = json_encode([$makeId]);
$encoded_make_id = json_encode(['0']); // $encoded_make_id = json_encode(['0']);
$product1 = $this->ProductModel->select('products.* , manufacturer.manufacturer_name') // $product1 = $this->ProductModel->select('products.* , manufacturer.manufacturer_name')
->where('JSON_CONTAINS(make_id, \'' . $encodedModelId . '\')', null, false) // ->where('JSON_CONTAINS(make_id, \'' . $encodedModelId . '\')', null, false)
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') // ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('qty_stock >',0) // ->where('qty_stock >',0)
->findAll(); // ->findAll();
$product2 = $this->ProductModel->select('products.* , manufacturer.manufacturer_name') // $product2 = $this->ProductModel->select('products.* , manufacturer.manufacturer_name')
->orWhere('JSON_CONTAINS(make_id, \'' . $encoded_make_id . '\')', null, false) // ->orWhere('JSON_CONTAINS(make_id, \'' . $encoded_make_id . '\')', null, false)
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') // ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('qty_stock >',0) // ->where('qty_stock >',0)
->findAll(); // ->findAll();
$product = array_merge($product1, $product2); // $product = array_merge($product1, $product2);
// $data['product']=$product; // $data['product']=$product;
$encodedCCId = json_encode([(string)$ccId]);
$product = $this->ProductModel
->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id', 'left')
->where('products.isactive', 1)
->where('qty_stock >',0)
->where('JSON_VALID(products.cubic_centimeter_id) > 0', null, false)
->where("JSON_CONTAINS(products.cubic_centimeter_id, '{$encodedCCId}')", null, false)
->findAll();
$data['product']=$product; $data['product']=$product;
$encodedMakeId = json_encode([$makeId]); $encodedMakeId = json_encode([$makeId]);

View File

@ -9,6 +9,7 @@ use App\Models\BikemodelsModel;
use App\Models\ManufacturerModel; use App\Models\ManufacturerModel;
use App\Models\ProductCategoryModel; use App\Models\ProductCategoryModel;
use App\Models\AdditionalProductNameModal; use App\Models\AdditionalProductNameModal;
use App\Models\ComplaintModel;
use CodeIgniter\API\ResponseTrait; use CodeIgniter\API\ResponseTrait;
@ -22,6 +23,7 @@ class Products extends BaseController
protected $VendorModel; protected $VendorModel;
protected $ManufacturerModel; protected $ManufacturerModel;
protected $ProductCategoryModel; protected $ProductCategoryModel;
protected $ComplaintModel;
public $session; public $session;
use ResponseTrait; use ResponseTrait;
@ -36,6 +38,7 @@ class Products extends BaseController
$this->ManufacturerModel = new ManufacturerModel(); $this->ManufacturerModel = new ManufacturerModel();
$this->ProductCategoryModel = new ProductCategoryModel(); $this->ProductCategoryModel = new ProductCategoryModel();
$this->additionalProductNameModal = new AdditionalProductNameModal(); $this->additionalProductNameModal = new AdditionalProductNameModal();
$this->ComplaintModel = new ComplaintModel();
} }
public function product_categories() public function product_categories()
@ -98,7 +101,7 @@ class Products extends BaseController
$data['tax']=$tax; $data['tax']=$tax;
$data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll(); $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll();
$data['capacity'] = $this->ComplaintModel->getCubicCapacityName();
$data['vendors'] = $this->VendorModel->orderBy('vendor_name')->findAll(); $data['vendors'] = $this->VendorModel->orderBy('vendor_name')->findAll();
@ -129,23 +132,23 @@ class Products extends BaseController
$products = $this->ProductModel->where('product_id', $product_id)->get()->getRowArray(); $products = $this->ProductModel->where('product_id', $product_id)->get()->getRowArray();
$products['make_id'] = json_decode($products['make_id'], true); // $products['make_id'] = json_decode($products['make_id'], true);
$products['models_id'] = json_decode($products['models_id'], true); // $products['models_id'] = json_decode($products['models_id'], true);
$data['products'] = $products; $data['products'] = $products;
$data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll(); // $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll();
$make_id = $products['make_id']; // $make_id = $products['make_id'];
$models = []; // $models = [];
if( $products['make_id'] != null) { // if( $products['make_id'] != null) {
foreach ($products['make_id'] as $make_id) { // foreach ($products['make_id'] as $make_id) {
$models[] = $this->BikemodelsModel->where('make_id', $make_id)->orderBy('model_name')->findAll(); // $models[] = $this->BikemodelsModel->where('make_id', $make_id)->orderBy('model_name')->findAll();
} // }
} // }
$data['models'] = $models; // $data['models'] = $models;
$tax = $this->ProductModel->getTax(); $tax = $this->ProductModel->getTax();
$data['tax']=$tax; $data['tax']=$tax;
@ -153,16 +156,18 @@ class Products extends BaseController
$data['vendors'] = $this->VendorModel->orderBy('vendor_name')->findAll(); $data['vendors'] = $this->VendorModel->orderBy('vendor_name')->findAll();
$data['manufacturers'] = $this->ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name', 'ASC')->findAll(); $data['manufacturers'] = $this->ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name', 'ASC')->findAll();
// dd($data['vendors']);
$vendorIds = json_decode($products['vendor'], true); $vendorIds = json_decode($products['vendor'], true);
$vendors = []; $vendors = [];
if($vendorIds){
foreach ($vendorIds as $vendorId) { foreach ($vendorIds as $vendorId) {
$vendor = $this->VendorModel->find($vendorId); $vendor = $this->VendorModel->find($vendorId);
if ($vendor) { if ($vendor) {
$vendors[] = ['id' => $vendor['vendor_id'], 'name' => $vendor['vendor_name']]; $vendors[] = ['id' => $vendor['vendor_id'], 'name' => $vendor['vendor_name']];
} }
} }}
$data['vendorsProduct'] = $vendors; $data['vendorsProduct'] = $vendors;
$preferredVendorId = $products['prefered_vendor']; $preferredVendorId = $products['prefered_vendor'];
@ -180,6 +185,7 @@ class Products extends BaseController
->findAll(); ->findAll();
$data['productcategory'] = $productcategory; $data['productcategory'] = $productcategory;
$data['additionalProdutName'] = $additionalProdutName; $data['additionalProdutName'] = $additionalProdutName;
$data['capacity'] = $this->ComplaintModel->getCubicCapacityName();
echo view('product_form',$data); echo view('product_form',$data);
} }
@ -217,8 +223,8 @@ class Products extends BaseController
'purchase_order_level' => $this->request->getPost('purchase_order_level'), 'purchase_order_level' => $this->request->getPost('purchase_order_level'),
'reorder_level' => $this->request->getPost('reorder_level'), 'reorder_level' => $this->request->getPost('reorder_level'),
'quality' => $this->request->getPost('quality'), 'quality' => $this->request->getPost('quality'),
'make_id' => json_encode($this->request->getPost('make')), // 'make_id' => json_encode($this->request->getPost('make')),
'models_id' => json_encode($this->request->getPost('model')), // 'models_id' => json_encode($this->request->getPost('model')),
'rack_number' => $this->request->getPost('rack_number'), 'rack_number' => $this->request->getPost('rack_number'),
'manufacturer_id' => $this->request->getPost('manufacturer'), 'manufacturer_id' => $this->request->getPost('manufacturer'),
'prefered_vendor' => $this->request->getPost('prefered_vendor'), 'prefered_vendor' => $this->request->getPost('prefered_vendor'),
@ -233,12 +239,13 @@ class Products extends BaseController
'box' => $box, 'box' => $box,
'qty_per_box' => $qty_per_box, 'qty_per_box' => $qty_per_box,
'barrel' => $barrel, 'barrel' => $barrel,
'ltr_per_barrel' => $ltr_per_barrel 'ltr_per_barrel' => $ltr_per_barrel,
'cubic_centimeter_id' => json_encode($this->request->getPost('cubic_centimeter_id')),
]; ];
$product_id = $this->request->getPost('product_id'); $product_id = $this->request->getPost('product_id');
$additional_product_name = $this->request->getPost('additional_product_name'); // $additional_product_name = $this->request->getPost('additional_product_name');
$product_names_id = $this->request->getPost('product_names_id'); // $product_names_id = $this->request->getPost('product_names_id');
$model_ids = $this->request->getPost('fk_model_id'); $model_ids = $this->request->getPost('fk_model_id');
// print_r($data);die; // print_r($data);die;
@ -250,7 +257,7 @@ class Products extends BaseController
} }
//for insert or update Additional Product Names //for insert or update Additional Product Names
$this->insertOrUpdateAdditionalProductName($additional_product_name, $product_names_id, $model_ids, $product_id, $data['product_name']); // $this->insertOrUpdateAdditionalProductName($additional_product_name, $product_names_id, $model_ids, $product_id, $data['product_name']);
$orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT); $orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT);
@ -488,7 +495,7 @@ class Products extends BaseController
// Assuming you have a model for products and one for manufacturers // Assuming you have a model for products and one for manufacturers
$products = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') $products = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('products.isactive', 1) ->where('products.isactive', 1)
->findAll(); ->findAll();
@ -670,13 +677,19 @@ class Products extends BaseController
$ltr_per_barrel = floatval($this->request->getPost('ltr_per_barrel') ?? 0); $ltr_per_barrel = floatval($this->request->getPost('ltr_per_barrel') ?? 0);
} }
$qty_in_stock = floatval($this->request->getPost('qty_stock') ?: 0); // Get qty_stock from POST
$purchase_order_level = floor($qty_in_stock / 2); // Calculate purchase reorder level (half of qty in stock)
$purchase_order_level = is_nan($purchase_order_level) ? '' : $purchase_order_level; // Safely assign values (handle invalid numbers)
$reorder_level = is_nan($qty_in_stock) ? '' : $qty_in_stock;
$data = [ $data = [
'cubic_centimeter_id' => json_encode($this->request->getPost('cubic_centimeter_id')), 'cubic_centimeter_id' => json_encode($this->request->getPost('cubic_centimeter_id')),
'product_name' => $this->request->getPost('productname'), 'product_name' => $this->request->getPost('productname'),
'product_category' => $this->request->getPost('productcategory'), 'product_category' => $this->request->getPost('productcategory'),
'total_amount' => $this->request->getPost('total_amount'), 'total_amount' => $this->request->getPost('total_amount'),
'unit_price' => $this->request->getPost('unit_price'), 'unit_price' => $this->request->getPost('unit_price'),
'qty_stock' => $this->request->getPost('qty_stock'), 'qty_stock' => $qty_in_stock,
'sgst' => $tax, 'sgst' => $tax,
'cgst' => $tax, 'cgst' => $tax,
'per' => $per, 'per' => $per,
@ -687,6 +700,8 @@ class Products extends BaseController
'ltr_per_barrel' => $ltr_per_barrel, 'ltr_per_barrel' => $ltr_per_barrel,
'isactive' => 1, 'isactive' => 1,
'branch_id' => $bid, 'branch_id' => $bid,
'purchase_order_level'=> $purchase_order_level,
'reorder_level' => $reorder_level,
'manufacturer_id' => $this->request->getPost('manufacturer'), 'manufacturer_id' => $this->request->getPost('manufacturer'),
]; ];

View File

@ -107,13 +107,14 @@ class Purchase extends BaseController
$encodedVendorId = json_encode([$vendorId]); $encodedVendorId = json_encode([$vendorId]);
// Query the database to find the product based on make_id and model_id // Query the database to find the product based on make_id and model_id
$product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') // $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') // ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false) // ->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
->findAll(); // ->findAll();
$data['product']=$product;
// print_r($product);die; $data['product']=$this->gatherVendorProducts($encodedVendorId);
// echo "<pre>";
// print_r($data['product']);die;
@ -123,7 +124,7 @@ class Purchase extends BaseController
} }
$productAll = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') $productAll = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('products.isactive',1) ->where('products.isactive',1)
->findAll(); ->findAll();
$data['productAll']= json_encode($productAll); $data['productAll']= json_encode($productAll);
@ -188,7 +189,7 @@ class Purchase extends BaseController
$business = $this->BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray(); $business = $this->BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
$product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('products.isactive',1) ->where('products.isactive',1)
->where('products.branch_id',$this->session->get('logged_user_branch_id'))->findAll(); ->where('products.branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['product']=$product; $data['product']=$product;
@ -210,7 +211,7 @@ class Purchase extends BaseController
$data['purchase_product'] = $purchase_product; $data['purchase_product'] = $purchase_product;
$productAll = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') $productAll = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('products.isactive',1) ->where('products.isactive',1)
->findAll(); ->findAll();
$data['productAll']= json_encode($productAll); $data['productAll']= json_encode($productAll);
@ -413,21 +414,29 @@ public function getVendorProducts()
// Query the database to find the product based on make_id and model_id // Query the database to find the product based on make_id and model_id
$product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') $product = $this->gatherVendorProducts($encodedVendorId);
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') $CrossVerify = "";
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false) // $CrossVerify = $this->ProductModel->getLastQuery()->getQuery();
->where('products.isactive',1)
->findAll();
// print_r($product);die; // print_r($product);die;
if($product){ return $this->response->setJSON([
// Send JSON response 'product' => $product ?: [],
return $this->response->setJSON(['product'=>$product , 'VendorData' => $VendorData] ); 'VendorData' => $VendorData ?: [],
} else { 'CrossVerify' => $CrossVerify ?: ''
// If product is not found, return an empty response or appropriate message ]);
return $this->response->setJSON(['product'=>[] , 'VendorData' => $VendorData]);
} }
public function gatherVendorProducts($encodedVendorId)
{
$product = $this->ProductModel
->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id', 'left')
->where('products.isactive', 1)
->where('JSON_VALID(products.vendor) > 0', null, false)
->where("JSON_CONTAINS(products.vendor, '{$encodedVendorId}')", null, false)
->findAll();
return $product;
} }
public function delete_purchase_product() public function delete_purchase_product()
{ {
$purchase_order_child_id = $this->request->getPost('purchase_order_child_id'); $purchase_order_child_id = $this->request->getPost('purchase_order_child_id');

View File

@ -65,7 +65,7 @@ class Reorderlevel extends BaseController
$data['page_name']="Rise Order"; $data['page_name']="Rise Order";
$ProductModel = new ProductModel(); $ProductModel = new ProductModel();
$products=$ProductModel->select('products.*, manufacturer.manufacturer_name') $products=$ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('prefered_vendor', $prefered_vendor) ->where('prefered_vendor', $prefered_vendor)
->where('qty_stock <= purchase_order_level') ->where('qty_stock <= purchase_order_level')
->findAll(); ->findAll();
@ -76,7 +76,7 @@ class Reorderlevel extends BaseController
$vendorid= $prefered_vendor; $vendorid= $prefered_vendor;
$product_data = $ProductModel->select('products.*, manufacturer.manufacturer_name') $product_data = $ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('prefered_vendor', $vendorid)->findAll(); ->where('prefered_vendor', $vendorid)->findAll();
// echo json_encode($product_data);die; // echo json_encode($product_data);die;
$data['product_data'] = $product_data; $data['product_data'] = $product_data;

View File

@ -86,7 +86,7 @@ class ReturnOrder extends BaseController
// Query the database to find the product based on make_id and model_id // Query the database to find the product based on make_id and model_id
$product = $productModel->select('products.*, manufacturer.manufacturer_name') $product = $productModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false) ->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
->findAll(); ->findAll();
$data['product']=$product; $data['product']=$product;
@ -308,7 +308,7 @@ class ReturnOrder extends BaseController
// Query the database to find the product based on make_id and model_id // Query the database to find the product based on make_id and model_id
$product = $productModel->select('products.*, manufacturer.manufacturer_name') $product = $productModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false) ->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
->findAll(); ->findAll();
@ -436,7 +436,7 @@ public function download_purchase_invoice($purchase_order_id)
// Query the database to find the product based on make_id and model_id // Query the database to find the product based on make_id and model_id
$product = $productModel->select('products.*, manufacturer.manufacturer_name') $product = $productModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false) ->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
->findAll(); ->findAll();
$data['product']=$product; $data['product']=$product;

View File

@ -72,17 +72,14 @@ class Sales extends BaseController
$data['vehicle'] = $this->VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id')); $data['vehicle'] = $this->VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
$data['product'] = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') $data['product'] = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id') ->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id', 'left')
->where('products.isactive', 1) ->where('products.isactive', 1)
->where('products.qty_stock >',0)
->where('products.branch_id', $this->session->get('logged_user_branch_id')) ->where('products.branch_id', $this->session->get('logged_user_branch_id'))
->where('products.isactive', 1)
->findAll(); ->findAll();
} else if ($sales_order_id !== '0') { } else if ($sales_order_id !== '0') {
@ -97,46 +94,49 @@ class Sales extends BaseController
$vehicles = $this->VehicleModel->where('isactive',1)->where('vehicle_id',$data['sales']['vehicle_id']) $vehicles = $this->VehicleModel->where('isactive',1)->where('vehicle_id',$data['sales']['vehicle_id'])
->where('branch_id',$this->session->get('logged_user_branch_id')) ->where('branch_id',$this->session->get('logged_user_branch_id'))
->first(); ->first();
$makeId = $vehicles['make']; // $makeId = $vehicles['make'];
$modelId = $vehicles['model']; // $modelId = $vehicles['model'];
// Encode the modelId before searching // Encode the modelId before searching
$encodedMakeId = json_encode([$makeId]); // $encodedMakeId = json_encode([$makeId]);
$encodedModelId = json_encode([$modelId]); // $encodedModelId = json_encode([$modelId]);
// Query the database to find the product based on make_id and model_id // Query the database to find the product based on make_id and model_id
$makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name') // $makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
->join('products', 'products.product_id = product_names.product_id') // ->join('products', 'products.product_id = product_names.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') // ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false) // ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) // ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->where('qty_stock >',0) // ->where('qty_stock >',0)
// ->where('products.isactive', 1)
// ->findAll();
// $encodedMakeId = json_encode(['0']);
// $encodedModelId = json_encode(['0']);
// $common_product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
// ->join('products', 'products.product_id = product_names.product_id')
// ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
// ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
// ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
// ->where('qty_stock >',0)
// ->where('products.isactive', 1)
// ->findAll();
// $product = array_merge($common_product, $makeproduct);
// $data['product']=$product;
$data['product'] = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id', 'left')
->where('products.isactive', 1) ->where('products.isactive', 1)
->where('products.qty_stock >',0)
->where('products.branch_id', $this->session->get('logged_user_branch_id'))
->findAll(); ->findAll();
$encodedMakeId = json_encode(['0']);
$encodedModelId = json_encode(['0']);
$common_product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
->join('products', 'products.product_id = product_names.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->where('qty_stock >',0)
->where('products.isactive', 1)
->findAll();
$product = array_merge($common_product, $makeproduct);
$data['product']=$product;
$sales_product = $this->SalesOrderProductModel->where('sales_order_id', $sales_order_id)->findAll(); $sales_product = $this->SalesOrderProductModel->where('sales_order_id', $sales_order_id)->findAll();
$data['sales_product']=$sales_product; $data['sales_product']=$sales_product;
$data['vehicle'] = $this->VehicleModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $data['vehicle'] = $this->VehicleModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
@ -517,14 +517,20 @@ class Sales extends BaseController
$modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name; $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
$makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make; $makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make;
$product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name') $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('products', 'products.product_id = product_names.product_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id','left')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->where('products.qty_stock >',0)
->whereIn('product_names.model_id',[$modelId, 0]) ->where('products.isactive', 1)
->where('qty_stock >',0)
->where('product_names.isactive', 1)
->findAll(); ->findAll();
// $product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
// ->join('products', 'products.product_id = product_names.product_id')
// ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
// ->whereIn('product_names.model_id',[$modelId, 0])
// ->where('qty_stock >',0)
// ->where('product_names.isactive', 1)
// ->findAll();
if($product){ if($product){
// Send JSON response // Send JSON response
return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] ); return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] );

View File

@ -91,11 +91,11 @@ class Service extends BaseController
public function new_service($service_id) public function new_service($service_id)
{ {
$data['product'] = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') // $data['product'] = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') // ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(products.models_id, \'["0"]\')', null, false) // ->where('JSON_CONTAINS(products.models_id, \'["0"]\')', null, false)
->where('products.isactive', 1) // ->where('products.isactive', 1)
->findAll(); // ->findAll();
$data['tax'] = $this->ServicesModel->getTax(); $data['tax'] = $this->ServicesModel->getTax();
$data['cubiccapacity']= $this->ComplaintModel->getCubicCapacityName(); $data['cubiccapacity']= $this->ComplaintModel->getCubicCapacityName();
@ -107,6 +107,7 @@ class Service extends BaseController
$data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll(); $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
$data['models'] = []; $data['models'] = [];
$data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['product'] = [];
} else if ($service_id !== '0') { } else if ($service_id !== '0') {
@ -126,10 +127,12 @@ class Service extends BaseController
// $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll(); // $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
$data['services'] = $services; $data['services'] = $services;
$data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$ccid = json_decode($services['cubic_capacity_id'], true);
$data['product'] = $this->get_product_by_cc($ccid);
// dd($data['service']); // dd($data['service']);
} }
$data['service_id'] = $service_id; $data['service_id'] = $service_id;
echo view('service_form',$data); echo view('service_form',$data);
} }
@ -220,29 +223,56 @@ class Service extends BaseController
} }
} }
public function get_product_by_cc(){ // be carefully we used in add-ajax call and edit - directphp array
$cc_id = $this->request->getPost('cc_id'); public function get_product_by_cc($id = null)
$products = []; {
$model_ids = $this->BikemodelsModel->select('model_id')->where('cubic_capacity_id', $cc_id)->asArray()->findAll();
$mid[] = 0; // default zero. because general.. $cc_id = $this->request->isAJAX()
foreach($model_ids as $model){ ? $this->request->getPost('cc_id')
$mid[] = $model['model_id']; : $id;
}
$products = []; // $encodedCCId = json_encode([$cc_id]);
foreach ($mid as $id) { $encodedCCId = json_encode([(string)$cc_id]);
$sql = "SELECT products.*, manufacturer.manufacturer_name // $encodedCCId = json_encode(["2"]);
FROM products // echo $encodedCCId;die;
JOIN manufacturer ON manufacturer.manufacturer_id = products.manufacturer_id
WHERE JSON_CONTAINS(products.models_id, ?) $product = $this->ProductModel
AND products.isactive = 1"; ->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id', 'left')
->where('products.isactive', 1)
->where('JSON_VALID(products.cubic_centimeter_id) > 0', null, false)
->where("JSON_CONTAINS(products.cubic_centimeter_id, '{$encodedCCId}')", null, false)
->findAll();
// $this->ProductModel->getLastQuery()->getQuery();
return $this->request->isAJAX()
? $this->response->setJSON($product)
: $product;
$result = $this->ProductModel->query($sql, ['"' . $id . '"'])->getResult();
$products = array_merge($products, $result);
} }
return $this->response->setJSON($products); // public function get_product_by_cc(){
} // $cc_id = $this->request->getPost('cc_id');
// $products = [];
// $model_ids = $this->BikemodelsModel->select('model_id')->where('cubic_capacity_id', $cc_id)->asArray()->findAll();
// $mid[] = 0; // default zero. because general..
// foreach($model_ids as $model){
// $mid[] = $model['model_id'];
// }
// $products = [];
// foreach ($mid as $id) {
// $sql = "SELECT products.*, manufacturer.manufacturer_name
// FROM products
// JOIN manufacturer ON manufacturer.manufacturer_id = products.manufacturer_id
// WHERE JSON_CONTAINS(products.models_id, ?)
// AND products.isactive = 1";
// $result = $this->ProductModel->query($sql, ['"' . $id . '"'])->getResult();
// $products = array_merge($products, $result);
// }
// return $this->response->setJSON($products);
// }
// public function get_product_by_models(){ // public function get_product_by_models(){
// $make_id = $this->request->getPost('make_id'); // $make_id = $this->request->getPost('make_id');

View File

@ -89,21 +89,21 @@
$bp = trim($invoice[0]->billing_postal_code ?? ''); $bp = trim($invoice[0]->billing_postal_code ?? '');
if ($bp === '0' || $bp === 0) {$bp = '';} if ($bp === '0' || $bp === 0) {$bp = '';}
$address = ''; $address = '';
if ($ba && $bc && $bs && $bp) { $address = "$ba, $bc, $bs - $bp."; if ($ba && $bc && $bs && $bp) { $address = "$ba, $bc, $bs - $bp,";
} elseif ($ba && $bc && $bs) { $address = "$ba, $bc, $bs."; } elseif ($ba && $bc && $bs) { $address = "$ba, $bc, $bs,";
} elseif ($ba && $bc && $bp) { $address = "$ba, $bc - $bp."; } elseif ($ba && $bc && $bp) { $address = "$ba, $bc - $bp,";
} elseif ($ba && $bs && $bp) { $address = "$ba, $bs - $bp."; } elseif ($ba && $bs && $bp) { $address = "$ba, $bs - $bp,";
} elseif ($ba && $bc) { $address = "$ba, $bc."; } elseif ($ba && $bc) { $address = "$ba, $bc,";
} elseif ($ba && $bs) { $address = "$ba, $bs."; } elseif ($ba && $bs) { $address = "$ba, $bs,";
} elseif ($ba && $bp) { $address = "$ba - $bp."; } elseif ($ba && $bp) { $address = "$ba - $bp,";
} elseif ($bc && $bs && $bp) { $address = "$bc, $bs - $bp."; } elseif ($bc && $bs && $bp) { $address = "$bc, $bs - $bp,";
} elseif ($bc && $bs) { $address = "$bc, $bs."; } elseif ($bc && $bs) { $address = "$bc, $bs,";
} elseif ($bc && $bp) { $address = "$bc - $bp."; } elseif ($bc && $bp) { $address = "$bc - $bp,";
} elseif ($bs && $bp) { $address = "$bs - $bp."; } elseif ($bs && $bp) { $address = "$bs - $bp,";
} elseif ($ba) { $address = "$ba."; } elseif ($ba) { $address = "$ba,";
} elseif ($bc) { $address = "$bc."; } elseif ($bc) { $address = "$bc,";
} elseif ($bs) { $address = "$bs."; } elseif ($bs) { $address = "$bs,";
} elseif ($bp) { $address = "$bp."; } elseif ($bp) { $address = "$bp,";
} else { $address = '-';} } else { $address = '-';}
echo $address; echo $address;
?> ?>

View File

@ -79,21 +79,21 @@
$bp = trim($sales[0]->billing_postal_code ?? ''); $bp = trim($sales[0]->billing_postal_code ?? '');
if ($bp === '0' || $bp === 0) {$bp = '';} if ($bp === '0' || $bp === 0) {$bp = '';}
$address = ''; $address = '';
if ($ba && $bc && $bs && $bp) { $address = "$ba, $bc, $bs - $bp."; if ($ba && $bc && $bs && $bp) { $address = "$ba, $bc, $bs - $bp,";
} elseif ($ba && $bc && $bs) { $address = "$ba, $bc, $bs."; } elseif ($ba && $bc && $bs) { $address = "$ba, $bc, $bs,";
} elseif ($ba && $bc && $bp) { $address = "$ba, $bc - $bp."; } elseif ($ba && $bc && $bp) { $address = "$ba, $bc - $bp,";
} elseif ($ba && $bs && $bp) { $address = "$ba, $bs - $bp."; } elseif ($ba && $bs && $bp) { $address = "$ba, $bs - $bp,";
} elseif ($ba && $bc) { $address = "$ba, $bc."; } elseif ($ba && $bc) { $address = "$ba, $bc,";
} elseif ($ba && $bs) { $address = "$ba, $bs."; } elseif ($ba && $bs) { $address = "$ba, $bs,";
} elseif ($ba && $bp) { $address = "$ba - $bp."; } elseif ($ba && $bp) { $address = "$ba - $bp,";
} elseif ($bc && $bs && $bp) { $address = "$bc, $bs - $bp."; } elseif ($bc && $bs && $bp) { $address = "$bc, $bs - $bp,";
} elseif ($bc && $bs) { $address = "$bc, $bs."; } elseif ($bc && $bs) { $address = "$bc, $bs,";
} elseif ($bc && $bp) { $address = "$bc - $bp."; } elseif ($bc && $bp) { $address = "$bc - $bp,";
} elseif ($bs && $bp) { $address = "$bs - $bp."; } elseif ($bs && $bp) { $address = "$bs - $bp,";
} elseif ($ba) { $address = "$ba."; } elseif ($ba) { $address = "$ba,";
} elseif ($bc) { $address = "$bc."; } elseif ($bc) { $address = "$bc,";
} elseif ($bs) { $address = "$bs."; } elseif ($bs) { $address = "$bs,";
} elseif ($bp) { $address = "$bp."; } elseif ($bp) { $address = "$bp,";
} else { $address = '';} } else { $address = '';}
echo $address; echo $address;
?> ?>

View File

@ -55,7 +55,33 @@
<td style="width: 18.5039%; height: 18px; text-align: right; font-size: small;"><?= date("d-m-Y", strtotime($job_card[0]['created_at'])); ?></td> <td style="width: 18.5039%; height: 18px; text-align: right; font-size: small;"><?= date("d-m-Y", strtotime($job_card[0]['created_at'])); ?></td>
</tr> </tr>
<tr style="height: 18px;"> <tr style="height: 18px;">
<td style="width: 49.4096%; height: 18px; font-size: small;"><?= $job_card[0]['billing_address']; ?>,<?= $job_card[0]['billing_city']; ?>,<?= $job_card[0]['billing_state']; ?>-<?= $job_card[0]['billing_postal_code']; ?>,</td> <td style="width: 49.4096%; height: 18px; font-size: small;">
<?php
$ba = trim($job_card[0]['billing_address'] ?? '');
$bc = trim($job_card[0]['billing_city'] ?? '');
$bs = trim($job_card[0]['billing_state'] ?? '');
$bp = trim($job_card[0]['billing_postal_code'] ?? '');
if ($bp === '0' || $bp === 0) {$bp = '';}
$address = '';
if ($ba && $bc && $bs && $bp) { $address = "$ba, $bc, $bs - $bp,";
} elseif ($ba && $bc && $bs) { $address = "$ba, $bc, $bs,";
} elseif ($ba && $bc && $bp) { $address = "$ba, $bc - $bp,";
} elseif ($ba && $bs && $bp) { $address = "$ba, $bs - $bp,";
} elseif ($ba && $bc) { $address = "$ba, $bc,";
} elseif ($ba && $bs) { $address = "$ba, $bs,";
} elseif ($ba && $bp) { $address = "$ba - $bp,";
} elseif ($bc && $bs && $bp) { $address = "$bc, $bs - $bp,";
} elseif ($bc && $bs) { $address = "$bc, $bs,";
} elseif ($bc && $bp) { $address = "$bc - $bp,";
} elseif ($bs && $bp) { $address = "$bs - $bp,";
} elseif ($ba) { $address = "$ba,";
} elseif ($bc) { $address = "$bc,";
} elseif ($bs) { $address = "$bs,";
} elseif ($bp) { $address = "$bp,";
} else { $address = '-';}
echo $address;
?>
</td>
<td style="width: 1.9685%; height: 18px;">&nbsp;</td> <td style="width: 1.9685%; height: 18px;">&nbsp;</td>
<td style="width: 30.3148%; height: 18px; text-align: right; font-size: small;">Payment Mode:</td> <td style="width: 30.3148%; height: 18px; text-align: right; font-size: small;">Payment Mode:</td>
<td style="width: 18.5039%; height: 18px; text-align: right; font-size: small;"><?= $job_card[0]['mode_of_payment']; ?></td> <td style="width: 18.5039%; height: 18px; text-align: right; font-size: small;"><?= $job_card[0]['mode_of_payment']; ?></td>

View File

@ -52,35 +52,24 @@
<h4 class="header-title">Product Details :</h4><br> <h4 class="header-title">Product Details :</h4><br>
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-4"> <div class="form-group col-md-8">
<label for="make" class="col-form-label">Make<span class="text-danger">*</span></label> <label for="cubic_centimeter_id" class="col-form-label">Capacity in Cubic Centimeter (C.C.)<span class="text-danger">*</span></label>
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addMakeModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addMakeModal" title="Add Make"></i>' ?> <select class="form-control SelExample" id="CCselect" name="cubic_centimeter_id[]" required multiple>
<select class="form-control SelExample" id="make" name="make[]" required multiple> <!-- <option value="">Select a Capacity in Cubic Centimeter (C.C.)</option> -->
<option value="">Select a Make</option> <!-- Options for CC -->
<!-- Options for make --> <?php $cubic_ids = isset($products['cubic_centimeter_id'])
<?php foreach ($make as $value): ?> ? json_decode($products['cubic_centimeter_id'], true)
<option value="<?= $value['make_id'] ?>" <?= isset($products['make_id']) && in_array($value['make_id'], $products['make_id']) ? 'selected' : '' ?>> : [];
<?= $value['make'] ?> ?>
<?php foreach ($capacity as $cc): ?>
<option value="<?= $cc['id'] ?>"
<?= in_array($cc['id'], (array)$cubic_ids) ? 'selected' : '' ?>>
<?= $cc['value'] ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
<div class="form-group col-md-4">
<label for="model" class="col-form-label">Model<span class="text-danger">*</span></label>
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addModelModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addModelModal" title="Add Modal"></i>'; ?>
<select class="form-control SelExample" id="model" name="model[]" required multiple>
<!-- Options for model will be populated dynamically via AJAX -->
<?php if(isset($models) && !empty($models)): ?>
<?php foreach ($models as $make_models): ?>
<?php foreach ($make_models as $model): ?>
<option value="<?= $model['model_id'] ?>" <?= isset($products['models_id']) && in_array($model['model_id'], $products['models_id']) ? 'selected' : '' ?>><?= $model['model_name'] ?></option>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label for="inputEmail4" class="col-form-label">Product Name<span class="text-danger">*</span></label> <label for="inputEmail4" class="col-form-label">Product Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="productname" placeholder="Product Name" value="<?= isset($products['product_name']) ? $products['product_name'] : '' ?>" required> <input type="text" class="form-control" name="productname" placeholder="Product Name" value="<?= isset($products['product_name']) ? $products['product_name'] : '' ?>" required>
@ -124,9 +113,13 @@
<select class="form-control SelExample" id="vendor" name="vendor[]" required multiple> <select class="form-control SelExample" id="vendor" name="vendor[]" required multiple>
<!-- Placeholder option --> <!-- Placeholder option -->
<option value="">Select Vendor</option> <option value="">Select Vendor</option>
<?php $vendor_ids = isset($products['vendor'])
? json_decode($products['vendor'], true)
: [];
?>
<?php foreach ($vendors as $vendor): ?> <?php foreach ($vendors as $vendor): ?>
<option value="<?= $vendor['vendor_id'] ?>" <?= isset($products['vendor']) && in_array($vendor['vendor_id'], json_decode($products['vendor'], true)) ? 'selected' : '' ?>> <option value="<?= $vendor['vendor_id'] ?>"
<?= in_array($vendor['vendor_id'], (array)$vendor_ids) ? 'selected' : '' ?>>
<?= $vendor['vendor_name'] ?> <?= $vendor['vendor_name'] ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
@ -273,7 +266,7 @@
</div> </div>
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label class="col-form-label">Purchase Re-Order Level<span class="text-danger"></span></label> <label class="col-form-label">Purchase Re-Order Level<span class="text-danger"></span></label>
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" class="form-control" id="purchase_reorder_level" name="reorder_level" placeholder="Purchase Re-Order Level" value="<?= isset($products['reorder_level']) ? $products['reorder_level'] : '' ?>" required> <input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" class="form-control" id="purchase_reorder_level" name="reorder_level" placeholder="Purchase Re-Order Level" value="<?= isset($products['reorder_level']) ? $products['reorder_level'] : '0' ?>" required>
</div> </div>
</div><br> </div><br>
<h4 class="header-title">Description Details :</h4><br> <h4 class="header-title">Description Details :</h4><br>
@ -553,95 +546,93 @@ $(document).ready(function(){
}); });
</script> </script>
<script> <script>
// $(document).ready(function() {
// var makeData = <?php // echo json_encode($make); ?>;
// $('#make').change(function() {
// var make_id = $(this).val(); // Get the selected make ID
// make_value = $('option:selected', this).text();
// var models_id = $('#model').val();
// if (make_id.includes('0')) {
// $('#make').empty();
// $('#make').append('<option value="" disabled > Select a Make </option>')
// if (makeData.length > 0) {
// makeData.forEach(function(make) {
// if(make.make_id == 0){
// $('#make').append('<option value="' + make.make_id + '" selected >' + make.make + '</option>')
// }else{
// $('#make').append('<option value="' + make.make_id + '" disabled >' + make.make + '</option>');
// }
// });
// $('#model').trigger('change');
// }
// make_id = ['0'];
// } else {
// // Enable all options if 'General' is not selected
// $('#make option').each(function () {
// $(this).prop('disabled', false); // Enable the option
// });
// }
// $('#makeSelect').empty(); // Clear existing options
// console.log(make_id);
$(document).ready(function() { // // Assuming make is an array of objects
var makeData = <?php echo json_encode($make); ?>; // var filteredMakes = makeData.filter(function(item) {
$('#make').change(function() { // return make_id.includes(String(item.make_id)); // Check if make_id matches in the array
var make_id = $(this).val(); // Get the selected make ID // });
make_value = $('option:selected', this).text();
var models_id = $('#model').val();
if (make_id.includes('0')) {
$('#make').empty(); // // Check if filteredMakes has any results
$('#make').append('<option value="" disabled > Select a Make </option>') // if (filteredMakes.length > 0) {
if (makeData.length > 0) { // filteredMakes.forEach(function(make) {
makeData.forEach(function(make) { // $('#makeSelect').append('<option value="' + make.make_id + '">' + make.make + '</option>');
if(make.make_id == 0){ // });
$('#make').append('<option value="' + make.make_id + '" selected >' + make.make + '</option>') // } else {
}else{ // console.log('No matching makes found!');
$('#make').append('<option value="' + make.make_id + '" disabled >' + make.make + '</option>'); // }
}
});
$('#model').trigger('change');
}
make_id = ['0'];
} else {
// Enable all options if 'General' is not selected
$('#make option').each(function () {
$(this).prop('disabled', false); // Enable the option
});
}
$('#makeSelect').empty(); // Clear existing options
console.log(make_id);
// Assuming make is an array of objects // // $('#makeSelect').append('<option value="' + make_id + '">' + make_value + '</option>');
var filteredMakes = makeData.filter(function(item) { // $('#makeSelectMessage').hide();
return make_id.includes(String(item.make_id)); // Check if make_id matches in the array
});
// Check if filteredMakes has any results // // AJAX request to get models based on the selected make ID
if (filteredMakes.length > 0) { // $('#loader').show();
filteredMakes.forEach(function(make) { // $.ajax({
$('#makeSelect').append('<option value="' + make.make_id + '">' + make.make + '</option>'); // url: '<?php echo base_url('get_models') ?>', // URL to your CodeIgniter controller method
}); // type: 'POST',
} else { // dataType: 'json',
console.log('No matching makes found!'); // data: { make_id: make_id }, // Send the selected make ID to the controller
} // success: function(response) {
// // Update models dropdown based on the response
// if (response.length > 0) {
// // Clear existing options
// $('#model').empty();
// // Iterate through response and models_id
// $.each(response, function(index, model) {
// var count =0;
// $.each(models_id, function(index, model_id) {
// if (model.model_id == model_id) {
// // Append option for the model
// $('#model').append('<option value="' + model.model_id + '" selected>' + model.model_name + '</option>');
// count =1;
// }
// });
// if (count == 0) {
// $('#model').append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
// }
// $('#makeSelect').append('<option value="' + make_id + '">' + make_value + '</option>'); // });
$('#makeSelectMessage').hide(); // } else {
// // Handle case when no models are found
// AJAX request to get models based on the selected make ID // $('#model').empty().append('<option value="">No models found</option>');
$('#loader').show(); // }
$.ajax({ // $('#loader').hide();
url: '<?php echo base_url('get_models') ?>', // URL to your CodeIgniter controller method // },
type: 'POST', // error: function(xhr, status, error) {
dataType: 'json', // // Handle error
data: { make_id: make_id }, // Send the selected make ID to the controller // console.error(xhr.responseText);
success: function(response) { // }
// Update models dropdown based on the response // });
if (response.length > 0) { // });
// Clear existing options // });
$('#model').empty();
// Iterate through response and models_id
$.each(response, function(index, model) {
var count =0;
$.each(models_id, function(index, model_id) {
if (model.model_id == model_id) {
// Append option for the model
$('#model').append('<option value="' + model.model_id + '" selected>' + model.model_name + '</option>');
count =1;
}
});
if (count == 0) {
$('#model').append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
}
});
} else {
// Handle case when no models are found
$('#model').empty().append('<option value="">No models found</option>');
}
$('#loader').hide();
},
error: function(xhr, status, error) {
// Handle error
console.error(xhr.responseText);
}
});
});
});
</script> </script>
<script> <script>
$('#qty_in_stock').on('keyup change', function() { $('#qty_in_stock').on('keyup change', function() {

View File

@ -175,7 +175,10 @@
<select class="form-control book-select SelExample purchase_order_product_edit" name="item_details[]" required data-toggle="select2" id="" style="width: 280px !important;" readonly> <select class="form-control book-select SelExample purchase_order_product_edit" name="item_details[]" required data-toggle="select2" id="" style="width: 280px !important;" readonly>
<option value="">Select a Product</option> <option value="">Select a Product</option>
<?php foreach ($product as $value) : ?> <?php foreach ($product as $value) : ?>
<?php if ($value['per'] == 'ml') { <?php
$value_name = $value["product_name"];
$value_manufacturer_name = (!empty($value["manufacturer_name"]) ? ' - ' . $value["manufacturer_name"] : '') ;
if ($value['per'] == 'ml') {
$value_ml = ' ('.$value['ml'].$value['per'].')'; $value_ml = ' ('.$value['ml'].$value['per'].')';
} else { } else {
$value_ml = ''; $value_ml = '';
@ -183,7 +186,7 @@
?> ?>
<?php if ((int)$value["isactive"] === 1) : ?> <?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["product_id"] ?>" <?= isset($purchasechild['product_id']) && $purchasechild['product_id'] == $value["product_id"] ? 'selected' : '' ?>> <option value="<?= $value["product_id"] ?>" <?= isset($purchasechild['product_id']) && $purchasechild['product_id'] == $value["product_id"] ? 'selected' : '' ?>>
<?= $value["product_name"].$value_ml.' - '.$value["manufacturer_name"]; ?> <?= $value_name . $value_ml . $value_manufacturer_name ?>
</option> </option>
<?php endif; ?> <?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
@ -504,7 +507,9 @@ $(document).ready(function() {
} }
if (valuesArray.indexOf(product.product_id.toString()) === -1) { if (valuesArray.indexOf(product.product_id.toString()) === -1) {
newRow += '<option value="' + product.product_id + '">' + product.product_name + value_ml +" - " + product.manufacturer_name + '</option>'; newRow += '<option value="' + product.product_id + '">' + product.product_name + value_ml +
(product.manufacturer_name ? ' - ' + product.manufacturer_name : '') +
'</option>';
} }
} }
newRow += '</select></td>' + newRow += '</select></td>' +

View File

@ -18,7 +18,23 @@
<tr style="height: 18px;"> <tr style="height: 18px;">
<td style="width: 33.3333%; font-size: small;"><?= "Date ". date("d-m-Y", strtotime($purchase[0]->order_date)); ?></td> <td style="width: 33.3333%; font-size: small;"><?= "Date ". date("d-m-Y", strtotime($purchase[0]->order_date)); ?></td>
<td style="width: 4.98683%;">&nbsp;</td> <td style="width: 4.98683%;">&nbsp;</td>
<td style="width: 61.6798%; text-align: right; font-size: small;"><?= $purchase[0]->company_city; ?>,<?= $purchase[0]->company_state; ?>-<?= $purchase[0]->company_postal_code; ?></td> <td style="width: 61.6798%; text-align: right; font-size: small;">
<?php
$c = trim($purchase[0]->company_city ?? '');
$s = trim($purchase[0]->company_state ?? '');
$p = trim($purchase[0]->company_postal_code ?? '');
if ($p === '0' || $p === 0) { $p = ''; }
$output = '';
if ($c && $s && $p) { $output = "$c, $s - $p.";
} elseif ($c && $s) { $output = "$c, $s.";
} elseif ($c && $p) { $output = "$c - $p.";
} elseif ($s && $p) { $output = "$s - $p.";
} elseif ($c) { $output = "$c.";
} elseif ($s) { $output = "$s.";
} elseif ($p) { $output = "$p."; }
echo $output;
?>
</td>
</tr> </tr>
<tr style="height: 18px;"> <tr style="height: 18px;">

View File

@ -166,6 +166,7 @@
</div> </div>
<div class="form-row" id="itemTableContainer"> <div class="form-row" id="itemTableContainer">
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<h4>Item Details</h4> <h4>Item Details</h4>
@ -206,9 +207,9 @@
} }
?> ?>
<?php if ((int)$value["isactive"] === 1) : ?> <?php if ((int)$value["isactive"] === 1) : ?>
<option data-id="<?= $value["product_names_id"] ?>" value="<?= $value["product_id"] ?>" <option value="<?= $value["product_id"] ?>"
<?= isset($salechild['product_id']) && $salechild['product_names_id'] == $value["product_names_id"] ? 'selected' : '' ?>> <?= isset($salechild['product_id']) && $salechild['product_id'] == $value["product_id"] ? 'selected' : '' ?>>
<?= $value["additional_product_name"].$value_ml.' - '.$value["manufacturer_name"]; ?> <?= $value["product_name"].$value_ml.($value["manufacturer_name"] ? ' - '.$value["manufacturer_name"] : ''); ?>
</option> </option>
<?php endif; ?> <?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
@ -396,7 +397,7 @@
<option value="">Select a Client</option> <option value="">Select a Client</option>
<?php foreach ($client as $value) : ?> <?php foreach ($client as $value) : ?>
<option value="<?= $value["client_id"] ?>"> <option value="<?= $value["client_id"] ?>">
<?= $value["mobile_no"] .' - '. $value["client_name"]; ?> <?= $value["client_name"]; ?> <!-- $value["mobile_no"] .' - '. $value["client_name"]; -->
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@ -456,7 +457,7 @@ $(document).ready(function() {
var vehicleId = $(this).val(); var vehicleId = $(this).val();
console.log("**"); console.log("**");
console.log(vehicleId); console.log(vehicleId);
$('input[id="makeAndModel"],input[name="client_id"], input[name="client_name"], textarea[name="billing_address"], input[name="city"], input[name="state"], input[name="country"], input[name="mobile_no"], input[name="email"], input[name="postalcode"]').val('');
if (vehicleId !== '') { if (vehicleId !== '') {
// Find the selected vehicle // Find the selected vehicle
var selectedVehicle = vehicles.find(function(vehicle) { var selectedVehicle = vehicles.find(function(vehicle) {
@ -752,8 +753,11 @@ $(document).ready(function() {
var product = productarray[i]; var product = productarray[i];
if(!selected_pr.includes(product.product_id)) if(!selected_pr.includes(product.product_id))
{ {
newRow += '<option data-id="'+ product.product_names_id +'" value="' + product.product_id + '" >' + product.additional_product_name + value_ml + " - " + product.manufacturer_name+ newRow += '<option value="' + product.product_id + '" >' +
+ value_ml +
(product.manufacturer_name ? ' - ' + product.manufacturer_name : '') +
'</option>'; '</option>';
} }
} }
newRow += '</select></td>' + newRow += '</select></td>' +
@ -831,12 +835,11 @@ $(document).ready(function() {
var selectedClient = vehicles.find(function(vehicle) { var selectedClient = vehicles.find(function(vehicle) {
return vehicle.vehicle_id == vehicleId; return vehicle.vehicle_id == vehicleId;
}); });
console.log(":( ",selectedClient);// sad
$('input[name="client_id"]').val(selectedClient.client_name); $('input[name="client_id"]').val(selectedClient.client_name);
$('input[name="billing_address"]').val(selectedClient.address); $('textarea[name="billing_address"]').val(selectedClient.address);
$('input[name="billing_address"]').val(selectedClient.address); // $('input[name="billing_address"]').val(selectedClient.address);
$('input[name="city"]').val(selectedClient.city); $('input[name="city"]').val(selectedClient.city);
$('input[name="state"]').val(selectedClient.state); $('input[name="state"]').val(selectedClient.state);
$('input[name="country"]').val(selectedClient.country); $('input[name="country"]').val(selectedClient.country);
@ -1129,34 +1132,40 @@ $(document).on('click', '#selectClient', function() {
$(window).on('load', function() { $(window).on('load', function() {
// This code will execute after the page has been reloaded
vehicle_id = localStorage.getItem('vehicle_id'); var vehicle_id = localStorage.getItem('vehicle_id');
localStorage.removeItem('vehicle_id');
if (vehicle_id) { if (vehicle_id) {
var vehicleId = vehicle_id;
if (vehicleId !== '') { $('#vehicle_id').val(vehicle_id).trigger('change');
// Find the selected client in the client data localStorage.removeItem('vehicle_id');
var selectedClient = vehicles.find(function(vehicle) {
return vehicle.vehicle_id == vehicleId; $('input[id="makeAndModel"], input[name="client_id"], textarea[name="billing_address"], input[name="city"], input[name="state"], input[name="country"], input[name="mobile_no"], input[name="email"], input[name="postalcode"]').val('');
// Find the selected vehicle details
var selectedVehicle = vehicles.find(function(vehicle) {
return vehicle.vehicle_id == vehicle_id;
}); });
var makeId = selectedClient.make;
var modelId = selectedClient.model;
if (selectedVehicle) {
var makeId = selectedVehicle.make;
var modelId = selectedVehicle.model;
fetchMakeAndModel(makeId, modelId); fetchMakeAndModel(makeId, modelId);
console.log(selectedClient);
$('input[name="client_id"]').val(selectedClient.client_name); // Fill client & vehicle info fields
$('input[name="billing_address"]').val(selectedClient.address); $('input[name="client_id"]').val(selectedVehicle.client_id);
$('textarea[name="billing_address"]').val(selectedVehicle.address);
// $('input[name="billing_address"]').val(selectedClient.address); // $('input[name="billing_address"]').val(selectedClient.address);
$('input[name="city"]').val(selectedClient.city); $('input[name="city"]').val(selectedVehicle.city);
$('input[name="state"]').val(selectedClient.state); $('input[name="state"]').val(selectedVehicle.state);
$('input[name="country"]').val(selectedClient.country); $('input[name="country"]').val(selectedVehicle.country);
$('input[name="mobile_no"]').val(selectedClient.mobile_no); $('input[name="mobile_no"]').val(selectedVehicle.mobile_no);
$('input[name="postalcode"]').val(selectedClient.postal_code); $('input[name="email"]').val(selectedVehicle.email);
$('input[name="postalcode"]').val(selectedVehicle.postal_code);
} else {
console.warn("⚠️ Vehicle not found in 'vehicles' list for ID:", vehicle_id);
} }
$('#vehicle_name').val(vehicle_id).trigger('change');
} }
}); });
@ -1176,7 +1185,7 @@ $(document).on('click', '#selectClient', function() {
success: function(response) { success: function(response) {
// console.log(response); // console.log(response);
// Populate make and model in the input field // Populate make and model in the input field
var makeAndModel = response.makeName + ' ' + response.modelName; var makeAndModel = response.makeName + ' - ' + response.modelName;
$('#makeAndModel').val(makeAndModel); $('#makeAndModel').val(makeAndModel);
if(response.product.length){ if(response.product.length){
@ -1202,8 +1211,9 @@ $(document).on('click', '#selectClient', function() {
<script> <script>
function addProductNamesId(selectElement) { function addProductNamesId(selectElement) {
var product_names_id = $(selectElement).find('option:selected').attr('data-id'); if (!selectElement) return; // safety
$(selectElement).closest('tr').find('input[name="product_names_id[]"]').val(product_names_id); // var product_names_id = $(selectElement).find('option:selected').attr('data-id');
// $(selectElement).closest('tr').find('input[name="product_names_id[]"]').val(product_names_id);
} }
// Prevent multiple submissions by disabling the button on first click // Prevent multiple submissions by disabling the button on first click

View File

@ -292,7 +292,10 @@ $(document).ready(function() {
// Update vendor dropdown based on the response // Update vendor dropdown based on the response
if (response) { if (response) {
$.each(response, function(index, product) { $.each(response, function(index, product) {
$('#productSelect').append('<option value="' + product.product_id + '">' + product.product_name +' - '+ product.manufacturer_name + '</option>'); $('#productSelect').append('<option value="' + product.product_id + '">' +
product.product_name +
(product.manufacturer_name ? ' - ' + product.manufacturer_name : '') +
'</option>');
}); });
} else { } else {
// Handle case when no vendors are found for the selected model // Handle case when no vendors are found for the selected model