From 6e4a86c7f4a15bc6bdbe9d0631b93d84990e9dd7 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Tue, 9 Apr 2024 10:39:12 +0530 Subject: [PATCH 1/4] GWM:CHANGES-in-product-module --- app/Controllers/Products.php | 23 +++++++------------- app/Models/ProductModel.php | 2 +- app/Views/client_form.php | 28 +++++++++++------------- app/Views/product_form.php | 42 +++++++++++++++++++----------------- app/Views/vehicle_form.php | 22 ++++++++++--------- 5 files changed, 56 insertions(+), 61 deletions(-) diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 9ade4f0..4918b0d 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -65,7 +65,7 @@ class Products extends BaseController $ProductModel = new ProductModel(); $tax= $this->request->getPost('tax')/2; - + // print_r($this->request->getPost());die; $data = [ 'product_name' => $this->request->getPost('productname'), 'product_category' => $this->request->getPost('productcategory'), @@ -82,6 +82,8 @@ class Products extends BaseController 'vendor' => $this->request->getPost('vendor'), 'purchase_order_level' => $this->request->getPost('purchase_order_level'), 'quality' => $this->request->getPost('quality'), + 'make_id' => $this->request->getPost('make'), + 'models_id' => json_encode($this->request->getPost('model')), 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id') ]; @@ -124,26 +126,17 @@ class Products extends BaseController // Retrieve the make_id from the AJAX request public function get_vendors_by_model() { - $make_id = $this->request->getPost('make_id'); + $model_ids = $this->request->getPost('model_ids'); - // print_r( $model_ids);die; - - // If make_id or model_ids is not provided, return an empty response - - // Create an instance of VendorModel $vendorModel = new VendorModel(); - - // Call the get_vendors_by_model method from the model - $vendors = $vendorModel->get_vendors_by_model($make_id, $model_ids); - // print_r($vendors); - // Return the response as JSON - // return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']); + $vendors = $vendorModel->get_vendors_by_model( $model_ids); + if ($vendors) { - // Return the retrieved vendors as JSON response + return $this->response->setJSON($vendors); } else { - // If no vendors were found, return an empty response or handle the error accordingly + return $this->response->setJSON([]); } } diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index a0f7a1f..63c54ff 100644 --- a/app/Models/ProductModel.php +++ b/app/Models/ProductModel.php @@ -5,7 +5,7 @@ class ProductModel extends Model { protected $table = 'products'; protected $primaryKey = 'product_id'; - protected $allowedFields = ['product_id','quality','product_name','branch_id','search_tag','product_category','mfr_part_no','purchase_order_level','serial_no','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive']; + protected $allowedFields = ['product_id','make_id','models_id','quality','product_name','branch_id','search_tag','product_category','mfr_part_no','purchase_order_level','serial_no','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive']; public function getTax() diff --git a/app/Views/client_form.php b/app/Views/client_form.php index a8c072a..e962a9a 100644 --- a/app/Views/client_form.php +++ b/app/Views/client_form.php @@ -21,6 +21,7 @@
" method="post"> +

Client Details :

@@ -30,6 +31,16 @@
+
+ + +
@@ -38,23 +49,10 @@
-
- - -
- - - - +
-

Address Information :

+

Address Information :

diff --git a/app/Views/product_form.php b/app/Views/product_form.php index e79bb74..237b6aa 100644 --- a/app/Views/product_form.php +++ b/app/Views/product_form.php @@ -26,6 +26,7 @@
- - -
-
- - -
- + + +
+
+ + +
+
@@ -200,6 +201,7 @@ $(document).ready(function() { // Clear existing options $('#model').empty(); // Append new options + $("#model").append(''); $.each(response, function(index, model) { $('#model').append(''); }); @@ -218,7 +220,7 @@ $(document).ready(function() { $(document).ready(function() { $('#model').change(function() { - var make_id = $(this).val(); // Get the selected make ID + var model_ids = $('#model').val(); // Get the selected model IDs console.log(model_ids); @@ -227,14 +229,14 @@ console.log(model_ids); url: '', // URL to your CodeIgniter controller method type: 'POST', dataType: 'json', - data: { make_id: make_id, model_ids: model_ids }, // Send the selected make ID and model IDs to the controller + data: { model_ids: model_ids }, // Send the selected make ID and model IDs to the controller success: function(response) { // Update vendor dropdown based on the response if (response) { // Clear existing options $('#vendor').empty(); // Append new options - $('#vendor').append(''); + $('#vendor').append(''); $.each(response, function(index, vendor) { $('#vendor').append(''); }); diff --git a/app/Views/vehicle_form.php b/app/Views/vehicle_form.php index 41b984d..588e1a2 100644 --- a/app/Views/vehicle_form.php +++ b/app/Views/vehicle_form.php @@ -20,10 +20,10 @@ " method="post"> -

Vehicle Details :


+

Vehicle Details :

- +
- +
- +
@@ -58,10 +58,11 @@
-

Client Details :


+
+

Client Details :

- + ' ?>
+
+ + +
-
- - -
+
From 6b69034ee379cae9a1e96ddce3655d4ea5c09e51 Mon Sep 17 00:00:00 2001 From: heama Date: Tue, 9 Apr 2024 10:46:59 +0530 Subject: [PATCH 2/4] sales --- app/Config/Routes.php | 2 +- app/Controllers/Sales.php | 57 +++++--- app/Models/SalesOrderModel.php | 10 +- app/Models/VehicleModel.php | 2 +- app/Views/invoice_pdf_template.php | 18 +-- app/Views/sales_list.php | 2 + app/Views/sales_order_form.php | 223 ++++++++++++++++++++++------- 7 files changed, 218 insertions(+), 96 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 88f06db..74b30de 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -50,7 +50,7 @@ $routes->get("new_sale/(:any)", "Sales::new_sale/$1"); $routes->get("delete_sale/(:any)", "Sales::delete_sale/$1"); $routes->post("delete_sales_product", "Sales::delete_sales_product"); $routes->get("download_invoice/(:any)", "Sales::download_invoice/$1"); -$routes->post("save_client", "Sales::save_client"); +$routes->post("save_vehicle", "Sales::save_vehicle"); //end salle order// //Client// diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 9f2895e..376bcf3 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -6,6 +6,8 @@ use App\Models\SalesOrderModel; use App\Models\SalesOrderProductModel; use App\Models\ProductModel; use App\Models\ClientModel; +use App\Models\BikeMakeModel; +use App\Models\VehicleModel; use Mpdf\Mpdf; class Sales extends BaseController { @@ -23,7 +25,7 @@ class Sales extends BaseController $SalesOrderModel = new SalesOrderModel(); $sales=$SalesOrderModel->getSalesOrdersWithProducts($this->session->get('logged_user_branch_id')); $data['sales']=$sales; - +// print_r($sales);die; return view('sales_list',$data); } @@ -39,13 +41,18 @@ class Sales extends BaseController $client=$ClientModel ->where('isactive',1) ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); -// print_r($client);die; + $VehicleModel = new VehicleModel(); + $vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id')); + // ->where('isactive',1) + // ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); +// print_r($vehicle);die; $ProductModel = new ProductModel(); $product=$ProductModel ->where('isactive',1) ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $data['product']=$product; $data['client']=$client; + $data['vehicle']=$vehicle; } else if ($sales_order_id !== '0') { $data['page_name']="Edit Sale Order"; $ClientModel = new ClientModel(); @@ -58,14 +65,19 @@ $sales_product=$SalesProductOrderModel->where('sales_order_id', $sales_order_id) $data['sales_product']=$sales_product; $data['client']=$client; // print_r($sales_product);die; - +$VehicleModel = new VehicleModel(); + $vehicle=$VehicleModel + ->where('isactive',1) + ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); + $data['vehicle']=$vehicle; $ProductModel = new ProductModel(); $product=$ProductModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $data['product']=$product; } // print_r($data);die; $data['sales_order_id'] = $sales_order_id; - + $bikeMakeModel = new BikeMakeModel(); + $data['makeData'] =$bikeMakeModel->findAll(); return view('sales_order_form',$data); } @@ -78,7 +90,8 @@ $data['product']=$product; // Prepare data for sales order $data = [ - 'client_id' => $this->request->getPost('client_id'), + 'client_name' => $this->request->getPost('client_id'), + 'vehicle_id'=>$this->request->getPost('vehicle_id'), 'billing_address' => $this->request->getPost('billing_address'), 'billing_city' => $this->request->getPost('city'), 'mobile_no' => $this->request->getPost('mobile_no'), @@ -88,13 +101,13 @@ $data['product']=$product; 'terms_condition' => $this->request->getPost('terms_condition'), 'subtotal' => $this->request->getPost('sub_total'), 'tax' => $this->request->getPost('invoice_tax'), - 'discount'=> $this->request->getPost('discount'), + 'total'=> $this->request->getPost('grand_total'), 'status'=> $this->request->getPost('status'), 'isactive' => 1, // Assuming this is a default value or handled separately 'branch_id'=> $this->session->get('logged_user_branch_id'), ]; -// print_r($data);die; +// print_r($data);die; // Insert or update sales order $sales_order_id = $this->request->getPost('sales_order_id'); if (!empty($sales_order_id)) { @@ -280,38 +293,36 @@ public function delete_sales_product() // Output the PDF to the browser for download $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D'); } - public function save_client(){ + + + public function save_vehicle(){ // Load ClientModel - $ClientModel = new ClientModel(); + $VehicleModel = new VehicleModel(); // Validate inputs - $validationRules = [ - 'client_name' => 'required|max_length[100]', - 'mobile_no' => 'required' // Assuming mobile number is 10 digits long - ]; - - if (!$this->validate($validationRules)) { - // If validation fails, return validation errors - return $this->response->setJSON(['success' => false, 'errors' => $this->validator->getErrors()]); - } + // If validation passes, proceed to save the client $data = [ - 'client_name' => $this->request->getPost('client_name'), + 'client_id' => $this->request->getPost('client_id'), + 'mobile_no' => $this->request->getPost('mobile_no'), + 'reg_no' => $this->request->getPost('reg_no'), + 'model' => $this->request->getPost('model'), + 'make' => $this->request->getPost('make'), 'branch_id'=> $this->session->get('logged_user_branch_id'), 'city'=>'Chennai', 'state'=>'Tamil Nadu', 'isactive' => 1 ]; - + // Attempt to insert the client data - $id = $ClientModel->insert($data); + $id = $VehicleModel->insert($data); if ($id) { - $clientData = $ClientModel->where('client_id',$id)->first(); + $vehicleData = $VehicleModel->where('vehicle_id',$id)->first(); // If insertion succeeds, return success response - return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','clientData'=>$clientData]); + return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData]); } else { // If insertion fails, return error response return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']); diff --git a/app/Models/SalesOrderModel.php b/app/Models/SalesOrderModel.php index 48855f6..8edbadc 100644 --- a/app/Models/SalesOrderModel.php +++ b/app/Models/SalesOrderModel.php @@ -5,14 +5,14 @@ class SalesOrderModel extends Model { protected $table = 'sales_order'; protected $primaryKey = 'sales_order_id'; - protected $allowedFields = ['sales_order_id','client_id','order_number','branch_id','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive']; + protected $allowedFields = ['sales_order_id','client_name','vehicle_id','order_number','branch_id','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive']; // public function getSalesPdf($sales_order_id){ return $this->db->table('sales_order') ->where('sales_order_id', $sales_order_id) - ->join('client as C','C.client_id= sales_order.client_id','left') + ->join('branches as B','B.branch_id = sales_order.branch_id','left') - ->select('sales_order.*,C.client_name,C.mobile_no,C.address,C.city,C.state') + ->select('sales_order.*') ->select('B.branch_name ,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.mobile_no as company_mobile_no') ->get() @@ -22,11 +22,11 @@ class SalesOrderModel extends Model public function getSalesOrdersWithProducts($logged_user_branch_id) { // Select required fields from both tables - $this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,client.client_name'); + $this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,vehicle.reg_no'); // Join the sales_order_product table based on sales_order_id $this->join('sales_order_product', 'sales_order_product.sales_order_id = sales_order.sales_order_id'); - $this->join('client', 'client.client_id = sales_order.client_id'); + $this->join('vehicle', 'vehicle.vehicle_id = sales_order.vehicle_id'); // Group by sales_order_id to get count of products per sales order $this->groupBy('sales_order.sales_order_id'); diff --git a/app/Models/VehicleModel.php b/app/Models/VehicleModel.php index 23d716b..9f6b2fd 100644 --- a/app/Models/VehicleModel.php +++ b/app/Models/VehicleModel.php @@ -12,7 +12,7 @@ class VehicleModel extends Model public function getCustomerandVehicle($branch_id) { // Select required fields from both tables - $this->select('vehicle.*, client.client_name , make.make as make_name , model.model_name as model_name'); + $this->select('vehicle.*, client.client_name ,client.address,client.city,client.state,client.postal_code, make.make as make_name , model.model_name as model_name'); $this->join('client', 'client.client_id = vehicle.client_id'); $this->join('make', 'make.make_id = vehicle.make'); $this->join('model', 'model.model_id = vehicle.model'); diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index a331c52..1c611eb 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -214,7 +214,7 @@ p { MRP Qty - Discount + Total @@ -230,7 +230,7 @@ p { product_name ?> ₹net_price, 2, '.', ',') ?> qty ?> - discount_type == '₹' ? $item->discount_type.$item->discount : $item->discount.$item->discount_type; ?> + ₹amount, 2, '.', ',') ?> @@ -252,13 +252,7 @@ p { - discount!=0): ?> - - - Discount :   ₹discount, 2, '.', ',') ?> - - - + Total :   ₹total, 2, '.', ',') ?> @@ -277,11 +271,7 @@ p {
- discount!=0): ?> -

"You have saved ₹discount; ?>- in this purchase"


- - - +

terms_condition;?>

diff --git a/app/Views/sales_list.php b/app/Views/sales_list.php index e0c1157..8b81ebb 100644 --- a/app/Views/sales_list.php +++ b/app/Views/sales_list.php @@ -40,6 +40,7 @@ Order Number + Reg No Client Name Client Mobile Quantity @@ -61,6 +62,7 @@ if ($value['isactive'] == 1) : ?> + diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 7b1ef4c..408b5a5 100644 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -25,23 +25,31 @@
- - ' ?> + + ' ?> - > - Select a Client' ?> - + Select a vehicle' ?> + -
+ + +
+
+ + +
+
@@ -61,24 +69,21 @@ -
+
-
+
-
+
-
- - -
+
@@ -93,7 +98,7 @@ Qty Rate Tax - Discount + Amount @@ -127,7 +132,7 @@ - + - +
@@ -177,10 +182,10 @@ -
+
@@ -213,30 +218,79 @@
-