diff --git a/app/Controllers/Client.php b/app/Controllers/Client.php index a4388ac..160be64 100644 --- a/app/Controllers/Client.php +++ b/app/Controllers/Client.php @@ -124,6 +124,7 @@ class Client extends BaseController $data = [ 'client_name' => $this->request->getPost('client_name'), 'mobile_no' => $this->request->getPost('mobile_no'), + 'client_type' => $this->request->getPost('client_type'), 'branch_id'=> $this->session->get('logged_user_branch_id'), 'city'=>'Chennai', 'state'=>'Tamil Nadu', diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index af2e330..ad5f4a5 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -6,7 +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\BikemodelsModel; +use App\Models\BikemakeModel; use App\Models\VehicleModel; use Mpdf\Mpdf; class Sales extends BaseController @@ -16,8 +17,10 @@ class Sales extends BaseController { $this->session = session(); + $this->BikemodelsModel = new BikemodelsModel(); + $this->BikemakeModel = new BikemakeModel(); -} + } public function sales_order_index() { @@ -322,13 +325,38 @@ public function delete_sales_product() // Load ClientModel $VehicleModel = new VehicleModel(); - // Validate inputs - - - // If validation passes, proceed to save the client + if($this->request->getPost('formType') == 'create') + { + $ClientModel = new ClientModel(); + + $client['client_name'] = $this->request->getPost('createclientName'); + $client['mobile_no'] = $this->request->getPost('createclientMobile'); + $client['client_type'] = $this->request->getPost('createclientType'); + $client['branch_id'] = $this->session->get('logged_user_branch_id'); + + $client_id = $ClientModel->insert($client); + + if($client_id){ + + $data = [ + 'client_id' => $client_id, + 'mobile_no' => $this->request->getPost('createclientMobile'), + '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 + ]; + + } + + + }else{ + $data = [ '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'), @@ -338,6 +366,12 @@ public function delete_sales_product() 'state'=>'Tamil Nadu', 'isactive' => 1 ]; + + + } + + + // Attempt to insert the client data $id = $VehicleModel->insert($data); @@ -359,7 +393,7 @@ public function get_vehicle_products(){ - public function getProducts() +public function getProducts() { // Retrieve make_id and model_id from the request $makeId = $this->request->getPost('make_id'); @@ -376,13 +410,14 @@ public function get_vehicle_products(){ ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) ->findAll(); - -if($product){ + $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name; + $makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make; + if($product){ // Send JSON response - return $this->response->setJSON($product); + return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] ); } else { // If product is not found, return an empty response or appropriate message - return $this->response->setJSON([]); + return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]); } } // Check if product exists diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 2d132ed..b0e3e89 100644 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -28,37 +28,43 @@ ' ?> - + Select a vehicle' ?> + + + + + + +
+ + +
+ +
-
+
-
- - -
+
+ + +
+

+ -

Billing Address Details :


@@ -228,63 +234,90 @@
- + +
+
+ +
@@ -225,7 +234,8 @@ $(document).ready(function() { var clientName = $('#clientName').val(); var clientMobile = $('#clientMobile').val(); - if(clientName != '' && clientMobile != ''){ + var clientType = $('#clientType').val(); + if(clientName != '' && clientMobile != '' && clientType != ''){ // Send AJAX request to save the client $.ajax({ @@ -233,7 +243,8 @@ $(document).ready(function() { method: 'POST', data: { client_name: clientName, - mobile_no: clientMobile + mobile_no: clientMobile, + client_type : clientType, }, success: function(response) { // Check if the operation was successful @@ -259,7 +270,7 @@ $(document).ready(function() { }); }else{ - toastr.warning("Please Fill Name and Mobile data"); + toastr.warning("Please Fill All Datas"); }