diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index bc7a75f..1529673 100755
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -425,18 +425,32 @@ class Sales extends BaseController
public function save_vehicle(){
- if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
-
-
-
+ if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
+
if($this->request->getPost('formType') == 'create')
{
-
-
$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['isactive'] = 1;
+ $client['created_by'] = (int)$this->session->get('logged_user');
+ $existingClient1 = $this->ClientModel->where('client_name', $client['client_name'])->first();
+ if ($existingClient1) {
+ return $this->response->setJSON([
+ 'success' => true, 'code' => 404,'field'=>'create-clientName',
+ 'message' => 'The client name is already registered. Please use a different Name.'
+ ]);
+ }
+ $existingClient2 = $this->ClientModel->where('mobile_no', $client['mobile_no'])->first();
+ if ($existingClient2) {
+ return $this->response->setJSON([
+ 'success' => true,'code' => 404,'field'=>'create-clientMobile',
+ 'message' => 'The mobile number is already registered. Please use a different number.'
+ ]);
+ }
+
+
$client_id = $this->ClientModel->insert($client);
@@ -451,7 +465,8 @@ class Sales extends BaseController
'branch_id'=> $this->session->get('logged_user_branch_id'),
'city'=>'Chennai',
'state'=>'Tamil Nadu',
- 'isactive' => 1
+ 'isactive' => 1,
+ 'created_by' => (int)$this->session->get('logged_user')
];
}
@@ -468,25 +483,22 @@ class Sales extends BaseController
'branch_id'=> $this->session->get('logged_user_branch_id'),
'city'=>'Chennai',
'state'=>'Tamil Nadu',
- 'isactive' => 1
+ 'isactive' => 1,
+ 'created_by' => (int)$this->session->get('logged_user')
];
}
-
-
-
-
+
// Attempt to insert the client data
$id = $this->VehicleModel->insert($data);
if ($id) {
$vehicleData = $this->VehicleModel->where('vehicle_id',$id)->first();
-
// If insertion succeeds, return success response
- return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData, 'vehicle_id' => $id]);
+ return $this->response->setJSON(['success' => true,'code' => 200, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData, 'vehicle_id' => $id]);
} else {
// If insertion fails, return error response
- return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);
+ return $this->response->setJSON(['success' => false, 'code' => 404,'message' => 'Failed to save client.']);
}
}
diff --git a/app/Controllers/Vendor.php b/app/Controllers/Vendor.php
index 9744196..f882b4f 100755
--- a/app/Controllers/Vendor.php
+++ b/app/Controllers/Vendor.php
@@ -95,7 +95,7 @@ class Vendor extends BaseController
'address' => $this->request->getPost('address'),
'city' => $this->request->getPost('city'),
'state' => $this->request->getPost('state'),
- 'postal_code' => $this->request->getPost('postalcode'),
+ 'postal_code' => $this->request->getPost('postalcode') != '' ? $this->request->getPost('postalcode') : NULL,
'country' => $this->request->getPost('country'),
'vendortype' => $this->request->getPost('vendortype'),
'category' => $this->request->getPost('category'),
diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php
index 0ce1660..b62b139 100755
--- a/app/Views/job_card_form.php
+++ b/app/Views/job_card_form.php
@@ -88,7 +88,7 @@
- = isset($sales['vehicle_id']) ? '' : '' ?>
+ = isset($sales['vehicle_id']) ? '' : '' ?>
-
+
-
+
@@ -111,11 +111,13 @@
function submitproductcategory(params) {
// Get the value of the Product Category Name input field
var productcategoryname = $('#product_category_name').val().trim();
-
+ const pcButton = $('#pcBtn');
+ pcButton.prop('disabled', true).text('Processing...');
// Check if Product Category Name is empty
if (productcategoryname === '') {
// Display error message
toastr.error('Please enter a Product Category Name.', 'Error');
+ pcButton.prop('disabled', false).text('Submit');
return; // Stop further execution of the function
}
var formData = {
@@ -135,6 +137,7 @@
console.log(response);
if (response.status == "failed") {
toastr.warning(response.data, 'Warning');
+ pcButton.prop('disabled', false).text('Submit');
}else{
$('#product_category_modal').modal('hide');
$('#product_category_name').val('');
@@ -147,6 +150,7 @@
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
+ pcButton.prop('disabled', false).text('Submit');
}
});
}
diff --git a/app/Views/product_form.php b/app/Views/product_form.php
index 99e9c94..6abadf2 100755
--- a/app/Views/product_form.php
+++ b/app/Views/product_form.php
@@ -54,7 +54,7 @@
diff --git a/app/Views/vehicle_form.php b/app/Views/vehicle_form.php
index 8f2bfe1..63c0c22 100755
--- a/app/Views/vehicle_form.php
+++ b/app/Views/vehicle_form.php
@@ -23,7 +23,7 @@
- = isset($vehicle['client_id']) ? '' : '' ?>
+ = isset($vehicle['client_id']) ? '' : '' ?>
- = isset($vehicle['client_id']) ? '' : '' ?>
+ = isset($vehicle['client_id']) ? '' : '' ?>