bug fixes : ps

This commit is contained in:
VE10-Sanjeev 2023-11-14 13:08:51 +05:30
parent 56f2b02904
commit 32b69272aa
3 changed files with 49 additions and 29 deletions

View File

@ -777,8 +777,17 @@ class ApiIntegration extends ResourceController
} }
$lineitems_total += ((float)$lineitems_subtotal + (float)$lineitems_tax) - (float)$lineitems_discount; $lineitems_total += ((float)$lineitems_subtotal + (float)$lineitems_tax) - (float)$lineitems_discount;
} }
$method_title = '';
$method_total = NULL;
if (count($records['shipping_lines']) > 0) {
$shipping_lines_array = $records['shipping_lines'];
foreach ($shipping_lines_array as $sl) {
$method_title = $sl->method_title;
$method_total = ((float)$sl->total)+((float)$sl->total_tax);
}
}
$subtotal = $lineitems_subtotal + (float)$records['shipping_total']; $subtotal = (float)$lineitems_subtotal + (float)$records['shipping_total'];
$tax = $lineitems_tax + (float)$records['shipping_tax']; $tax = $lineitems_tax + (float)$records['shipping_tax'];
$total = ($lineitems_total)+(float)$records['shipping_total'] + (float)$records['shipping_tax']; $total = ($lineitems_total)+(float)$records['shipping_total'] + (float)$records['shipping_tax'];
@ -789,10 +798,10 @@ class ApiIntegration extends ResourceController
$invoice_data['wp_api_order_id']=$records['id']; $invoice_data['wp_api_order_id']=$records['id'];
$invoice_data['invoice_date']=date("Y-m-d", strtotime($records['date_created'])); $invoice_data['invoice_date']=date("Y-m-d", strtotime($records['date_created']));
$invoice_data['due_date']=NULL; $invoice_data['due_date']=NULL;
$invoice_data['subtotal']=number_format($subtotal, 2); $invoice_data['subtotal']=(int)$subtotal;
$invoice_data['tax']=number_format($tax, 2); $invoice_data['tax']=(int)$tax;
$invoice_data['discount']=number_format($lineitems_discount, 2); $invoice_data['discount']=(int)$lineitems_discount;
$invoice_data['total_amount']= number_format($total, 2); $invoice_data['total_amount']= $records['total'];
$invoice_data['payment_status']=$records['status']; $invoice_data['payment_status']=$records['status'];
$invoice_data['order_number']=$records['order_key']; $invoice_data['order_number']=$records['order_key'];
$invoice_data['payment_method']=$records['payment_method_title']; $invoice_data['payment_method']=$records['payment_method_title'];
@ -803,7 +812,8 @@ class ApiIntegration extends ResourceController
$invoice_data['shipping_address_id']=$shipping_addr_id; $invoice_data['shipping_address_id']=$shipping_addr_id;
$invoice_data['billing_address']=$billing_addr; $invoice_data['billing_address']=$billing_addr;
$invoice_data['billing_address_id'] =$billing_addr_id; $invoice_data['billing_address_id'] =$billing_addr_id;
$invoice_data['shipping_charge'] = isset($records['shipping_total'])?$records['shipping_total']:NULL; $invoice_data['shipping_label'] = !empty($method_title)?$method_title:NULL;
$invoice_data['shipping_charge'] = isset($records['shipping_total'])?$records['shipping_total']: (!empty($method_total)?$method_total:NULL);
$invoice_data['notes'] = isset($records['customer_note'])?$records['customer_note']:NULL; $invoice_data['notes'] = isset($records['customer_note'])?$records['customer_note']:NULL;
$invoice_data['invoice_type'] = 1; $invoice_data['invoice_type'] = 1;
if ((int)$countAll == 0) { if ((int)$countAll == 0) {
@ -965,7 +975,7 @@ class ApiIntegration extends ResourceController
$line_item_data[$i]['quantity'] =(float)$ii->quantity; $line_item_data[$i]['quantity'] =(float)$ii->quantity;
$line_item_data[$i]['unit_price'] =(float)$ii->price; $line_item_data[$i]['unit_price'] =(float)$ii->price;
$line_item_data[$i]['tax'] =(float)$ii->total_tax; $line_item_data[$i]['tax'] =(float)$ii->total_tax;
$line_item_data[$i]['subtotal'] =(float)$ii->total; $line_item_data[$i]['subtotal'] =(int)$ii->total;
$line_item_data[$i]['invoice_child_id'] = $invoiceItemsId; $line_item_data[$i]['invoice_child_id'] = $invoiceItemsId;
$line_item_data[$i]['wp_api_line_items_id'] = $ii->id; $line_item_data[$i]['wp_api_line_items_id'] = $ii->id;
$line_item_data[$i]['invoice_id'] = $last_insert_invoice_id; $line_item_data[$i]['invoice_id'] = $last_insert_invoice_id;

View File

@ -188,6 +188,7 @@
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label for="scountry" class="col-form-label">Country<span class="text-danger"> *</span></label> <label for="scountry" class="col-form-label">Country<span class="text-danger"> *</span></label>
<input type="hidden" id="counter" value=<?= 0; ?> readonly />
<select class="form-control" id="scountry0" name="scountry[]" onchange="changeFields(this)" required> <select class="form-control" id="scountry0" name="scountry[]" onchange="changeFields(this)" required>
<option value="">Choose your Country</option> <option value="">Choose your Country</option>
<?php foreach ($country_details as $value) { ?> <?php foreach ($country_details as $value) { ?>
@ -316,6 +317,7 @@
<script> <script>
$("#addressCopiedAsShipping").on("change", function() { $("#addressCopiedAsShipping").on("change", function() {
var count = $(".after-shipping-addr-add-more").length; var count = $(".after-shipping-addr-add-more").length;
var counter = $("#counter").val() === "" ? count : parseInt($("#counter").val(), 10);
if ($(this).is(":checked")) { if ($(this).is(":checked")) {
var customerAddress1 = $("#baddress1").val(); var customerAddress1 = $("#baddress1").val();
@ -328,24 +330,25 @@
$("#saddress1").val(customerAddress1).prop("readonly", false); $("#saddress1").val(customerAddress1).prop("readonly", false);
$("#saddress2").val(customerAddress2).prop("readonly", false); $("#saddress2").val(customerAddress2).prop("readonly", false);
$("#scountry"+count).val(customerCountry).prop("readonly", false); $("#scountry"+counter).val(customerCountry).prop("readonly", false);
if (customerCountry == 'IN') { if (customerCountry == 'IN') {
$("#sistate"+count).val(customerInputState).css("display", "none").prop("readonly", false); $("#sistate"+counter).val(customerInputState).css("display", "none").prop("readonly", false);
$("#sdstate"+count).val(customerDropdownState).css("display", "block").prop("readonly", false); $("#sdstate"+counter).val(customerDropdownState).css("display", "block").prop("readonly", false);
} else { } else {
$("#sistate"+count).val(customerInputState).css("display", "block").prop("readonly", false); $("#sistate"+counter).val(customerInputState).css("display", "block").prop("readonly", false);
$("#sdstate"+count).val(customerDropdownState).css("display", "none").prop("readonly", false); $("#sdstate"+counter).val(customerDropdownState).css("display", "none").prop("readonly", false);
} }
$("#scity").val(customerCity).prop("readonly", false); $("#scity").val(customerCity).prop("readonly", false);
$("#szip").val(customerPostalCode).prop("readonly", false); $("#szip").val(customerPostalCode).prop("readonly", false);
$("#counter").val(counter++).prop("readonly", true);
} else { } else {
// Clear the billing address fields when the checkbox is unchecked // Clear the billing address fields when the checkbox is unchecked
$("#saddress1").val("").prop("readonly", false); $("#saddress1").val("").prop("readonly", false);
$("#saddress2").val("").prop("readonly", false); $("#saddress2").val("").prop("readonly", false);
$("#scity").val("").prop("readonly", false); $("#scity").val("").prop("readonly", false);
$("#scountry"+count).val("").prop("readonly", false); $("#scountry"+counter).val("").prop("readonly", false);
$("#sistate"+count).val("").css("display", "block").prop("readonly", false); $("#sistate"+counter).val("").css("display", "block").prop("readonly", false);
$("#sdstate"+count).val("").css("display", "none").prop("readonly", false); $("#sdstate"+counter).val("").css("display", "none").prop("readonly", false);
$("#szip").val("").prop("readonly", false); $("#szip").val("").prop("readonly", false);
$("#scustomer_address_id").val("") // Hidden Field ressetted bcoz Adress history $("#scustomer_address_id").val("") // Hidden Field ressetted bcoz Adress history
} }
@ -411,6 +414,7 @@
html.find('input#scity').val(sarray[i]['city']); html.find('input#scity').val(sarray[i]['city']);
html.find('select#scountry0').val(sarray[i]['country']); html.find('select#scountry0').val(sarray[i]['country']);
html.find('select#scountry0').attr('id', 'scountry' + j); html.find('select#scountry0').attr('id', 'scountry' + j);
html.find('input#counter').val(j).prop("readonly", true);
if (sarray[i]['country'] === 'IN') { if (sarray[i]['country'] === 'IN') {
// html.find('select#sdstate0').attr('id','sdstate'+$j).val(sarray[i]['state']); // html.find('select#sdstate0').attr('id','sdstate'+$j).val(sarray[i]['state']);
html.find('select#sdstate0').attr('id', 'sdstate' + j).css("display", "block").val(sarray[i]['state']); html.find('select#sdstate0').attr('id', 'sdstate' + j).css("display", "block").val(sarray[i]['state']);
@ -439,6 +443,7 @@
html.find('select#sdstate0').attr('id', 'sdstate' + count).css("display", "none").val(''); html.find('select#sdstate0').attr('id', 'sdstate' + count).css("display", "none").val('');
html.find('input#sistate0').attr('id', 'sistate' + count).css("display", "block").val(''); html.find('input#sistate0').attr('id', 'sistate' + count).css("display", "block").val('');
html.find('input').val(''); // Clear input values in the cloned element html.find('input').val(''); // Clear input values in the cloned element
html.find('input#counter').val(count).prop("readonly", true);
html.find(".shipping-addr-div-change").html("<a class='btn btn-success waves-effect waves-light mr-1 shipping-addr-add-more'>+ Add More Shipping Address </a><a class='btn btn-danger waves-effect waves-light mr-1 shipping-addr-remove'>- Remove </a>"); html.find(".shipping-addr-div-change").html("<a class='btn btn-success waves-effect waves-light mr-1 shipping-addr-add-more'>+ Add More Shipping Address </a><a class='btn btn-danger waves-effect waves-light mr-1 shipping-addr-remove'>- Remove </a>");
html.insertAfter(".after-shipping-addr-add-more:last"); html.insertAfter(".after-shipping-addr-add-more:last");
toggleButtons(); toggleButtons();
@ -458,7 +463,7 @@
function toggleButtons() { function toggleButtons() {
var elementCount = $(".after-shipping-addr-add-more").length; var elementCount = $(".after-shipping-addr-add-more").length;
console.log('elementCount == ' + elementCount); // console.log('elementCount == ' + elementCount);
if (elementCount > 1) { if (elementCount > 1) {
$(".shipping-addr-remove").show(); // Show the "shipping-addr-remove" buttons $(".shipping-addr-remove").show(); // Show the "shipping-addr-remove" buttons
} else { } else {

View File

@ -17,8 +17,13 @@
<select class="form-control" id="customerName" name="customer_name" required data-toggle="select2"> <select class="form-control" id="customerName" name="customer_name" required data-toggle="select2">
<option value="">Select a customer</option> <option value="">Select a customer</option>
<?php foreach ($customers as $customer) : ?> <?php foreach ($customers as $customer) : ?>
<option value="<?= $customer->customer_id ?>" <?php if (isset($invoice_details['customer_id']) && ($invoice_details['customer_id'] === $customer->customer_id)) echo "selected"; ?>> <?php $disabled = ((int)$customer->isactive == 0) ? 'disabled' : ''; ?>
<?= $customer->first_name . ' ' . $customer->last_name; ?></option> <option value="<?= $customer->customer_id ?>" <?php if (isset($invoice_details['customer_id']) && ($invoice_details['customer_id'] === $customer->customer_id)) echo "selected"; ?> <?= $disabled ?>>
<?= $customer->first_name . ' ' . $customer->last_name; ?>
<?php if ((int)$customer->isactive == 0) : ?>
(Disabled)
<?php endif; ?>
</option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<div class="invalid-feedback"> Please select customer. </div> <div class="invalid-feedback"> Please select customer. </div>
@ -115,7 +120,7 @@
<?= $book->title ?></option> <?= $book->title ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select></td> </select></td>
<td style="width:10%;"><input type="number" class="form-control item-quantity" id="<?= "quantity" . $inx; ?>" name="quantity[]" oninput="calculateInvoice(this,<?= $inx; ?>)" value="<?= isset($ii_details['quantity']) ? $ii_details['quantity'] : '' ?>" /> <td style="width:10%;"><input type="number" class="form-control item-quantity" id="<?= "quantity" . $inx; ?>" name="quantity[]" oninput="calculateInvoice(this,<?= $inx; ?>)" value="<?= isset($ii_details['quantity']) ? $ii_details['quantity'] : '' ?>" min="1" />
</td> </td>
<td style="width:10%;"><input type="text" class="form-control item-rate" id="<?= "rate" . $inx; ?>" name="rate[]" oninput="calculateInvoice(this,<?= $inx; ?>)" value="<?= isset($ii_details['unit_price']) ? $ii_details['unit_price'] : '' ?>" readonly /> <td style="width:10%;"><input type="text" class="form-control item-rate" id="<?= "rate" . $inx; ?>" name="rate[]" oninput="calculateInvoice(this,<?= $inx; ?>)" value="<?= isset($ii_details['unit_price']) ? $ii_details['unit_price'] : '' ?>" readonly />
</td> </td>
@ -123,7 +128,7 @@
</td> </td>
<td style="width:12%;"><input type="text" class="form-control item-amount" id="<?= "amount" . $inx; ?>" name="amount[]" value="<?= isset($ii_details['subtotal']) ? $ii_details['subtotal'] : '' ?>" readonly /> <td style="width:12%;"><input type="text" class="form-control item-amount" id="<?= "amount" . $inx; ?>" name="amount[]" value="<?= isset($ii_details['subtotal']) ? $ii_details['subtotal'] : '' ?>" readonly />
</td> </td>
<td style="width:12%;"><input type="text" class="form-control item-discount-amount" id="<?= "item_discount_amount" . $inx; ?>" name="discount_amount[]" oninput="calculateInvoice(this,<?= $inx; ?>)" value="<?= isset($ii_details['discount_amount']) ? $ii_details['discount_amount'] : '' ?>" /> <td style="width:12%;"><input type="number" class="form-control item-discount-amount" id="<?= "item_discount_amount" . $inx; ?>" name="discount_amount[]" oninput="calculateInvoice(this,<?= $inx; ?>)" value="<?= isset($ii_details['discount_amount']) ? $ii_details['discount_amount'] : '' ?>" min="0"/>
</td> </td>
<td style="width:10%;"> <td style="width:10%;">
@ -151,13 +156,13 @@
<option value="<?= $book->book_id ?>"><?= $book->title; ?></option> <option value="<?= $book->book_id ?>"><?= $book->title; ?></option>
<?php endif; endforeach; ?> <?php endif; endforeach; ?>
</select></td> </select></td>
<td style="width:10%;"><input type="number" class="form-control item-quantity" id="quantity0" name="quantity[]" oninput="calculateInvoice(this,0)" /> <td style="width:10%;"><input type="number" class="form-control item-quantity" id="quantity0" name="quantity[]" oninput="calculateInvoice(this,0)" min="1" />
</td> </td>
<td style="width:10%;"><input type="text" class="form-control item-rate" id="rate0" name="rate[]" oninput="calculateInvoice(this,0)" /></td> <td style="width:10%;"><input type="text" class="form-control item-rate" id="rate0" name="rate[]" oninput="calculateInvoice(this,0)" /></td>
<td style="width:8%;"><input type="text" class="form-control item-tax" id="tax0" name="tax[]" /></td> <td style="width:8%;"><input type="text" class="form-control item-tax" id="tax0" name="tax[]" /></td>
<td style="width:12%;"><input type="text" class="form-control item-amount" id="amount0" name="amount[]" /> <td style="width:12%;"><input type="text" class="form-control item-amount" id="amount0" name="amount[]" />
</td> </td>
<td class="discount-cell" style="width:12%;"><input type="text" class="form-control item-discount-amount" id="item_discount_amount0" name="discount_amount[]" oninput="calculateInvoice(this,0)" /> <td class="discount-cell" style="width:12%;"><input type="number" class="form-control item-discount-amount" id="item_discount_amount0" name="discount_amount[]" oninput="calculateInvoice(this,0)" min="0"/>
</td> </td>
<td style="width:12%;"> <td style="width:12%;">
@ -217,7 +222,7 @@
<div class="form-group"> <div class="form-group">
<span style="<?= $shippingChargesStyle ?>"> <span style="<?= $shippingChargesStyle ?>">
<label for="shippingCharges">Charge Amount </label> <label for="shippingCharges">Charge Amount </label>
<input type="number" class="form-control" id="shippingCharges" name="shippingCharges" placeholder="Charges Amount" value="<?= isset($invoice_details['shipping_charge']) ? $invoice_details['shipping_charge'] : 0 ?>" oninput="calculateOverallTotals()" <?= $shippingChargesHidden ?>> <input type="number" class="form-control" id="shippingCharges" name="shippingCharges" placeholder="Charges Amount" value="<?= isset($invoice_details['shipping_charge']) ? $invoice_details['shipping_charge'] : 0 ?>" oninput="calculateOverallTotals()" <?= $shippingChargesHidden ?> min="1" >
</span> </span>
</div> </div>
@ -225,7 +230,7 @@
<div class="form-group"> <div class="form-group">
<label for="discount">Discount</label> <label for="discount">Discount</label>
<input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" value="<?= isset($invoice_details['discount']) ? $invoice_details['discount'] : 0 ?>"> <input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" value="<?= isset($invoice_details['discount']) ? $invoice_details['discount'] : 0 ?>" min="0">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="grandtotal">Total</label> <label for="grandtotal">Total</label>
@ -234,7 +239,7 @@
<div class="form-group"> <div class="form-group">
<label for="balanceAmount">Balance Amount</label> <label for="balanceAmount">Balance Amount</label>
<input type="number" class="form-control" id="balanceAmount" name="balanceAmount" value="<?= (isset($invoice_details['status']) && $invoice_details['status'] === 'Draft') ? (isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '') : '0' ?>" oninput="calculateOverallTotals()" readonly> <input type="number" class="form-control" id="balanceAmount" name="balanceAmount" value="<?= (isset($invoice_details['status']) && $invoice_details['status'] === 'Draft') ? (isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '') : '0' ?>" oninput="calculateOverallTotals()" readonly min="0">
</div> </div>
<div class="form-group"> <div class="form-group">
@ -322,11 +327,11 @@
</select>`; </select>`;
// cell1.innerHTML = '<input type="text" class="form-control" name="item_details[]">'; // cell1.innerHTML = '<input type="text" class="form-control" name="item_details[]">';
cell2.innerHTML = '<input type="number" class="form-control item-quantity" id="quantity' + counter + '" name="quantity[]" oninput="calculateInvoice(this,' + counter + ')">'; cell2.innerHTML = '<input type="number" class="form-control item-quantity" id="quantity' + counter + '" name="quantity[]" oninput="calculateInvoice(this,' + counter + ')" min="1">';
cell3.innerHTML = '<input type="text" class="form-control item-rate" id="rate' + counter + '" name="rate[]" oninput="calculateInvoice(this,' + counter + ')">'; cell3.innerHTML = '<input type="text" class="form-control item-rate" id="rate' + counter + '" name="rate[]" oninput="calculateInvoice(this,' + counter + ')">';
cell4.innerHTML = '<input type="text" class="form-control item-tax" id="tax' + counter + '" name="tax[]">'; cell4.innerHTML = '<input type="text" class="form-control item-tax" id="tax' + counter + '" name="tax[]">';
cell5.innerHTML = '<input type="text" class="form-control item-amount" id="amount' + counter + '" name="amount[]">'; cell5.innerHTML = '<input type="text" class="form-control item-amount" id="amount' + counter + '" name="amount[]">';
cell6.innerHTML = '<input type="text" class="form-control item-discount-amount" id="item_discount_amount' + counter + '" name="discount_amount[]" oninput="calculateInvoice(this,' + counter + ')">'; cell6.innerHTML = '<input type="number" class="form-control item-discount-amount" id="item_discount_amount' + counter + '" name="discount_amount[]" oninput="calculateInvoice(this,' + counter + ')" min="0">';
cell7.innerHTML = '<select class="form-control item-discount-type" style=""width:12%;" id="item_discount_type' + counter + '" name="discount_type[]" oninput="calculateInvoice(this,' + counter + ')"><option value="₹">₹</option><option value="%">%</option></select>'; cell7.innerHTML = '<select class="form-control item-discount-type" style=""width:12%;" id="item_discount_type' + counter + '" name="discount_type[]" oninput="calculateInvoice(this,' + counter + ')"><option value="₹">₹</option><option value="%">%</option></select>';
cell8.innerHTML = '<input type="hidden" class="form-control" id="hiddenInvoiceChildId' + counter + '" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>'; cell8.innerHTML = '<input type="hidden" class="form-control" id="hiddenInvoiceChildId' + counter + '" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>';
$(newRow.querySelector('.book-select')).select2(); $(newRow.querySelector('.book-select')).select2();
@ -516,7 +521,7 @@
$("#invoiceNumber").val(inv_number).prop("readonly", true); $("#invoiceNumber").val(inv_number).prop("readonly", true);
}else{ }else{
var numbering_arr = <?php echo json_encode($invoice_number_formatting); ?>; var numbering_arr = <?php echo json_encode($invoice_number_formatting); ?>;
console.log(numbering_arr); // console.log(numbering_arr);
var filtered_data = $.grep(numbering_arr, function(item) { var filtered_data = $.grep(numbering_arr, function(item) {
return item.id === '1'; return item.id === '1';
}); });