FIX_Invoice Address Add : ps
This commit is contained in:
parent
f8fea6eac0
commit
2ce29a61d4
@ -178,7 +178,7 @@ $routes->post('api/(:any)', 'ApiIntegration::api_integration/$1');
|
||||
# Get Country List
|
||||
|
||||
$routes->get('get_country', 'Customer::get_country_list');
|
||||
$routes->post('save_address_from_model', 'Customer::save_address_from_model');
|
||||
$routes->post('qucik_add_addresses', 'Customer::qucik_add_addresses');
|
||||
|
||||
|
||||
|
||||
|
||||
@ -633,45 +633,40 @@ class Customer extends BaseController
|
||||
}
|
||||
|
||||
|
||||
public function save_address_from_model(){
|
||||
// print_r($this->request->getPost());die;
|
||||
|
||||
|
||||
$requestDataBilling = $this->request->getPost('billing');
|
||||
$requestDataShipping = $this->request->getPost('shipping');
|
||||
|
||||
$customer_id_for_addresses = $this->request->getPost('customer_id');
|
||||
|
||||
// $bill_addr = $this->save_customer_addresses_model($customer_id_for_addresses, $requestDataBilling, 'b');
|
||||
// $ship_addr = $this->save_customer_addresses_model($customer_id_for_addresses, $requestDataBilling, 's');
|
||||
public function qucik_add_addresses(){
|
||||
|
||||
$billingData = [
|
||||
'customer_id' => $this->request->getPost('customer_id'),
|
||||
'first_name' => $this->request->getPost('first_name'),
|
||||
'last_name' => $this->request->getPost('last_name'),
|
||||
'address_1'=> $requestDataBilling['address'],
|
||||
'address_2'=> '',
|
||||
'country' => $requestDataBilling['country'],
|
||||
'state' => $requestDataBilling['state'],
|
||||
'city' => $requestDataBilling['state'],
|
||||
'postal_code' => $requestDataBilling['postalCode'],
|
||||
'billing_address1'=> $this->request->getPost('QB_address'),
|
||||
'billing_address2'=> '',
|
||||
'billing_country' => $this->request->getPost('QB_country'),
|
||||
'billing_state' => $this->request->getPost('QB_state'),
|
||||
'billing_city' => $this->request->getPost('QB_city'),
|
||||
'billing_pincode' => $this->request->getPost('QB_zip'),
|
||||
];
|
||||
|
||||
$shippingData = [
|
||||
'customer_id' => $this->request->getPost('customer_id'),
|
||||
'first_name' => $this->request->getPost('first_name'),
|
||||
'last_name' => $this->request->getPost('last_name'),
|
||||
'address_1'=> $requestDataShipping['address'],
|
||||
'address_2'=> '',
|
||||
'country' => $requestDataShipping['country'],
|
||||
'state' => $requestDataShipping['state'],
|
||||
'city' => $requestDataShipping['state'],
|
||||
'postal_code' => $requestDataShipping['postalCode'],
|
||||
'shipping_address1'=> $this->request->getPost('QS_address'),
|
||||
'shipping_address2'=> '',
|
||||
'shipping_country' => $this->request->getPost('QS_country'),
|
||||
'shipping_state' => $this->request->getPost('QS_state'),
|
||||
'shipping_city' => $this->request->getPost('QS_city'),
|
||||
'shipping_pincode' => $this->request->getPost('QS_zip'),
|
||||
];
|
||||
|
||||
$model = new CustomerModel();
|
||||
|
||||
$insertedId = $model->updateAddress($customer_id_for_addresses, $billingData, 'b');
|
||||
$insertedId = $model->updateAddress($customer_id_for_addresses, $shippingData, 's');
|
||||
$result = $model->storeCustomerAddresses($billingData, $shippingData);
|
||||
|
||||
if (!empty($result['billing_addr_id']) && !empty($result['shipping_addr_id'])) {
|
||||
$results = ['status' => true, 'message' => 'New addresses saved successfully', 'cus_id' =>$this->request->getPost('customer_id'),"billing_addr_id"=>$result['billing_addr_id'],"shipping_addr_id"=>$result['shipping_addr_id']];
|
||||
} else {
|
||||
$results = ['status' => false, 'message' => 'Failed to save New addresses'];
|
||||
}
|
||||
return $this->response->setJSON(['data' => $results]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<h4 class="header-title"><?= $page_name; ?></h4>
|
||||
<br>
|
||||
<form method="POST" enctype="multipart/form-data" action="<?= base_url() . "save_invoice"; ?>" id="myForm">
|
||||
<input type="hidden" id="customer_id_set" >
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-row">
|
||||
@ -74,7 +74,7 @@
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="storeBillingAddress"> Billing Address  ( <input type="checkbox" id="editAddressesCheckbox" /> Do you want to edit/change addresses?)</label>
|
||||
<label for="storeBillingAddress"> Billing Address  ( <input type="checkbox" id="editAddressesCheckbox" /> Do you want to change addresses?)</label>
|
||||
<input type="hidden" id="hiddenBillingAddressId" name="billing_address_id" placeholder="hidden for billing address id" value="<?= isset($invoice_details['billing_address_id']) ? $invoice_details['billing_address_id'] : '' ?>" />
|
||||
<textarea class="form-control" id="storeBillingAddress" name="billing_address" rows="4" readonly><?= isset($invoice_details['billing_address']) ? $invoice_details['billing_address'] : '' ?></textarea>
|
||||
</div>
|
||||
@ -648,34 +648,34 @@
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="form-group">
|
||||
<label for="billingAddress"> Address</label>
|
||||
<input class="form-control" type="text" id="billing_address" required="" placeholder="Billing Address....">
|
||||
<label for="quick_billing_address"> Address<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_billing_address" required placeholder="Billing Address">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="billingCountry"> Country</label>
|
||||
<select class="form-control" name="billing_country" id="billing_country">
|
||||
<option >Select Country</option>
|
||||
<label for="quick_billing_country"> Country</label>
|
||||
<select class="form-control" id="quick_billing_country">
|
||||
<option value="">Select Country</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="billingAddress"> State</label>
|
||||
<input class="form-control" type="text" id="billing_state" required="" placeholder="State">
|
||||
<label for="quick_billing_state"> State<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_billing_state" required placeholder="State">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="billingAddress"> City</label>
|
||||
<input class="form-control" type="text" id="billing_city" required="" placeholder="City">
|
||||
<label for="quick_billing_city"> City<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_billing_city" required placeholder="City">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="billingAddress"> Postal Code</label>
|
||||
<input class="form-control" type="text" id="billing_postal_code" required="" placeholder="Postal Code">
|
||||
<label for="quick_billing_postal_code"> Postal Code<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_billing_postal_code" required placeholder="Postal Code">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12 text-right">
|
||||
@ -690,39 +690,39 @@
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="form-group">
|
||||
<label for="shippingAddress"> Address</label>
|
||||
<input class="form-control" type="text" id="shipping_address" required="" placeholder="Shipping Address">
|
||||
<label for="quick_shipping_address"> Address<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_shipping_address" required placeholder="Shipping Address">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="shippingCountry"> Country</label>
|
||||
<select class="form-control" name="shipping_country" id="shipping_country">
|
||||
<option >Select Country</option>
|
||||
<label for="quick_shipping_country"> Country</label>
|
||||
<select class="form-control" id="quick_shipping_country">
|
||||
<option value="">Select Country</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="shippingAddress"> State</label>
|
||||
<input class="form-control" type="text" id="shipping_state" required="" placeholder="State">
|
||||
<label for="quick_shipping_state"> State<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_shipping_state" required placeholder="State">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="shippingAddress"> City</label>
|
||||
<input class="form-control" type="text" id="shipping_city" required="" placeholder="City">
|
||||
<label for="quick_shipping_city"> City<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_shipping_city" required placeholder="City">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="shippingAddress"> Postal Code</label>
|
||||
<input class="form-control" type="text" id="shipping_postal_code" required="" placeholder="Postal Code">
|
||||
<label for="quick_shipping_postal_code"> Postal Code<span class="text-danger"> *</span></label>
|
||||
<input class="form-control" type="text" id="quick_shipping_postal_code" required placeholder="Postal Code">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group text-center">
|
||||
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitAddress(this)">Submit</button>
|
||||
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitAddress()">Submit</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@ -1129,8 +1129,8 @@
|
||||
// Loop through the countries array
|
||||
$.each(countries, function(index, country) {
|
||||
// Append an <option> element for each country
|
||||
$('#billing_country').append('<option value="' + country.country_short_name + '">' + country.country_name + '</option>');
|
||||
$('#shipping_country').append('<option value="' + country.country_short_name + '">' + country.country_name + '</option>');
|
||||
$('#quick_billing_country').append('<option value="' + country.country_short_name + '">' + country.country_name + '</option>');
|
||||
$('#quick_shipping_country').append('<option value="' + country.country_short_name + '">' + country.country_name + '</option>');
|
||||
}); },
|
||||
error: function() {
|
||||
alert("Error fetching address.");
|
||||
@ -1588,8 +1588,7 @@ function saveInvoiceCustomer() {
|
||||
success: function(response) {
|
||||
console.log(response['data']);
|
||||
if (response['data']['status']) {
|
||||
$('#customer_id_set').val(response['data']['cus_id']);
|
||||
console.log($('#customer_id_set'));
|
||||
|
||||
// Handle success response
|
||||
alert(response['data']['message']);
|
||||
|
||||
@ -1929,108 +1928,161 @@ function saveInvoiceCustomer() {
|
||||
|
||||
$("#addressCopiedAsShippingModel").on("change", function() {
|
||||
if ($(this).is(":checked")) {
|
||||
var customerAddress1 = $("#billing_address").val();
|
||||
var customerCountry = $("#billing_country").val();
|
||||
var customerState = $("#billing_state").val();
|
||||
var customerCity = $("#billing_city").val();
|
||||
var customerPostalCode = $("#billing_postal_code").val();
|
||||
|
||||
var quick_customerAddress1 = $("#quick_billing_address").val();
|
||||
var quick_customerCountry = $("#quick_billing_country").val();
|
||||
var quick_customerState = $("#quick_billing_state").val();
|
||||
var quick_customerCity = $("#quick_billing_city").val();
|
||||
var quick_customerPostalCode = $("#quick_billing_postal_code").val();
|
||||
|
||||
$("#shipping_address").val(customerAddress1).prop("readonly", false);
|
||||
$("#shipping_country").val(customerCountry).prop("readonly", false);
|
||||
$("#shipping_state").val(customerState).prop("readonly", false);
|
||||
$("#shipping_city").val(customerCity).prop("readonly", false);
|
||||
$("#shipping_postal_code").val(customerPostalCode).prop("readonly", false);
|
||||
$("#quick_shipping_address").val(quick_customerAddress1).prop("readonly", false);
|
||||
$("#quick_shipping_country").val(quick_customerCountry).prop("readonly", false);
|
||||
$("#quick_shipping_state").val(quick_customerState).prop("readonly", false);
|
||||
$("#quick_shipping_city").val(quick_customerCity).prop("readonly", false);
|
||||
$("#quick_shipping_postal_code").val(quick_customerPostalCode).prop("readonly", false);
|
||||
|
||||
} else {
|
||||
// Clear the billing address fields when the checkbox is unchecked
|
||||
$("#shipping_address").val("").prop("readonly", false);
|
||||
$("#shipping_country").val("").prop("readonly", false);
|
||||
$("#shipping_state").val("").prop("readonly", false);
|
||||
$("#shipping_city").val("").prop("readonly", false);
|
||||
$("#shipping_postal_code").val("").prop("readonly", false);
|
||||
$("#quick_shipping_address").val("").prop("readonly", false);
|
||||
$("#quick_shipping_country").val("").prop("readonly", false);
|
||||
$("#quick_shipping_state").val("").prop("readonly", false);
|
||||
$("#quick_shipping_city").val("").prop("readonly", false);
|
||||
$("#quick_shipping_postal_code").val("").prop("readonly", false);
|
||||
}
|
||||
});
|
||||
|
||||
function submitAddress(params) {
|
||||
function submitAddress() {
|
||||
$('#storeBillingAddress').val("").prop('readonly',false);
|
||||
$('#storeShippingAddress').val("").prop('readonly',false);
|
||||
var cus_id = $('#customer_name').val();
|
||||
console.log("Qucik add Addresses - customer id = ",cus_id);
|
||||
var last_name = $("#last_name").val();
|
||||
var first_name = $("#first_name").val();
|
||||
var bAddress = $("#billing_address").val();
|
||||
var bCountry = $("#billing_country").val();
|
||||
var bState = $("#billing_state").val();
|
||||
var bCity = $("#billing_city").val();
|
||||
var bPostalCode = $("#billing_postal_code").val();
|
||||
var sAddress = $("#shipping_address").val();
|
||||
var sCountry = $("#shipping_country").val();
|
||||
var sState = $("#shipping_state").val();
|
||||
var sCity = $("#shipping_city").val();
|
||||
var sPostalCode = $("#shipping_postal_code").val();
|
||||
|
||||
var cus_id = 0 ;
|
||||
if ($('#customer_name').val()) {
|
||||
cus_id = $('#customer_name').val();
|
||||
}else{
|
||||
cus_id = $('#customer_id_set').val();
|
||||
var QB_AddressLine = $("#quick_billing_address").val();
|
||||
var QB_Country = $("#quick_billing_country").val();
|
||||
var QB_State = $("#quick_billing_state").val();
|
||||
var QB_City = $("#quick_billing_city").val();
|
||||
var QB_PostalCode = $("#quick_billing_postal_code").val();
|
||||
var QS_AddressLine = $("#quick_shipping_address").val();
|
||||
var QS_Country = $("#quick_shipping_country").val();
|
||||
var QS_State = $("#quick_shipping_state").val();
|
||||
var QS_City = $("#quick_shipping_city").val();
|
||||
var QS_PostalCode = $("#quick_shipping_postal_code").val();
|
||||
|
||||
var isValid = true;
|
||||
var errorMessage = '';
|
||||
if (cus_id === '') {
|
||||
errorMessage += 'Please Select the Customer.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QB_AddressLine === '') {
|
||||
errorMessage += 'Billing address is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QB_Country === '') {
|
||||
errorMessage += 'Billing country is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QB_State === '') {
|
||||
errorMessage += 'Billing state is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QB_City === '') {
|
||||
errorMessage += 'Billing city is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QB_PostalCode === '') {
|
||||
errorMessage += 'Billing postal code is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QS_AddressLine === '') {
|
||||
errorMessage += 'Shipping address is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QS_Country === '') {
|
||||
errorMessage += 'Shipping country is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QS_State === '') {
|
||||
errorMessage += 'Shipping state is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QS_City === '') {
|
||||
errorMessage += 'Shipping city is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (QS_PostalCode === '') {
|
||||
errorMessage += 'Shipping postal code is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
console.log("customer_name",cus_id);
|
||||
|
||||
var formData = {
|
||||
customer_id :cus_id,
|
||||
last_name: last_name,
|
||||
first_name: first_name,
|
||||
billing: {
|
||||
address: bAddress,
|
||||
country: bCountry,
|
||||
state: bState,
|
||||
city: bCity,
|
||||
postalCode: bPostalCode
|
||||
},
|
||||
shipping: {
|
||||
address: sAddress,
|
||||
country: sCountry,
|
||||
state: sState,
|
||||
city: sCity,
|
||||
postalCode: sPostalCode
|
||||
}
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "<?php echo base_url('save_address_from_model'); ?>",
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
// Handle success response
|
||||
console.log("11111111111111111");
|
||||
console.log(response);
|
||||
$('#billing_shipping_addresses_modal').modal('hide');
|
||||
|
||||
var billing_Address = bAddress + ','+bCity + ',' + bCountry + '-' +bPostalCode + ',' + bState + '.' ;
|
||||
var shipping_Address = sAddress + ','+sCity + ',' + sCountry + '-' +sPostalCode + ',' + sState + '.' ;
|
||||
|
||||
console.log(billing_Address);
|
||||
if (!isValid) {
|
||||
alert(errorMessage);
|
||||
} else {
|
||||
var formData = {
|
||||
customer_id :cus_id,
|
||||
last_name: last_name,
|
||||
first_name: first_name,
|
||||
QB_address: QB_AddressLine,
|
||||
QB_country: QB_Country,
|
||||
QB_state: QB_State,
|
||||
QB_city: QB_City,
|
||||
QB_zip: QB_PostalCode,
|
||||
QS_address: QS_AddressLine,
|
||||
QS_country: QS_Country,
|
||||
QS_state: QS_State,
|
||||
QS_city: QS_City,
|
||||
QS_zip: QS_PostalCode
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "<?php echo base_url('qucik_add_addresses'); ?>",
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
if (response['data']['status']) {
|
||||
|
||||
alert(response['data']['message']);
|
||||
$('#billing_shipping_addresses_modal').modal('hide');
|
||||
|
||||
var customerId = response['data']['cus_id'];
|
||||
var QB_AddressId = response['data']['billing_addr_id'];
|
||||
var QS_AddressId = response['data']['shipping_addr_id'];
|
||||
|
||||
if(QB_AddressId !== null ){
|
||||
var quick_billing_Address = QB_AddressLine + ','+QB_City + ',' + QB_State + ',' +QB_Country + '-' + QB_PostalCode + '.' ;
|
||||
$('#storeBillingAddress').empty();
|
||||
$('#storeBillingAddress').html(billing_Address);
|
||||
$('#storeBillingAddress').val(billing_Address);
|
||||
$('#storeShippingAddress').empty();
|
||||
$('#storeShippingAddress').html(shipping_Address);
|
||||
$('#storeShippingAddress').val(shipping_Address);
|
||||
|
||||
// $('#editAddressesCheckbox').prop('checked', false).trigger('change');
|
||||
|
||||
$('#storeBillingAddress').val(quick_billing_Address).prop("readonly", true);
|
||||
$('#hiddenBillingAddressId').val(QB_AddressId);
|
||||
}
|
||||
|
||||
if(QS_AddressId !== null ){
|
||||
var quick_shipping_Address = QS_AddressLine + ','+QS_City + ',' + QS_State + '-' +QS_Country + '-' + QS_PostalCode + '.' ;
|
||||
$('#storeShippingAddress').empty();
|
||||
var new_QS_ShippingAddrOption = $('<option>', {
|
||||
value: QS_AddressId,
|
||||
text: QS_AddressLine,
|
||||
selected: true
|
||||
});
|
||||
$('#storeShippingAddress').val(quick_shipping_Address).prop("readonly", true);
|
||||
$('#loadShippingDropdown').empty().append(new_QS_ShippingAddrOption);
|
||||
}
|
||||
} else {
|
||||
// Handle error response
|
||||
alert(response['data']['message']);
|
||||
}
|
||||
},
|
||||
|
||||
error: function() {
|
||||
// Handle error
|
||||
alert("Error saving address.");
|
||||
alert("Error occurred while saving Addresses.");
|
||||
}
|
||||
});
|
||||
|
||||
$('#storeBillingAddress').val("").prop('readonly',true);
|
||||
$('#storeShippingAddress').val("").prop('readonly',true);
|
||||
$('#editAddressesCheckbox').click();
|
||||
});
|
||||
|
||||
$('#storeBillingAddress').prop('readonly',true);
|
||||
$('#storeShippingAddress').prop('readonly',true);
|
||||
$('#editAddressesCheckbox').click();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user