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;
}
$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'];
$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['invoice_date']=date("Y-m-d", strtotime($records['date_created']));
$invoice_data['due_date']=NULL;
$invoice_data['subtotal']=number_format($subtotal, 2);
$invoice_data['tax']=number_format($tax, 2);
$invoice_data['discount']=number_format($lineitems_discount, 2);
$invoice_data['total_amount']= number_format($total, 2);
$invoice_data['subtotal']=(int)$subtotal;
$invoice_data['tax']=(int)$tax;
$invoice_data['discount']=(int)$lineitems_discount;
$invoice_data['total_amount']= $records['total'];
$invoice_data['payment_status']=$records['status'];
$invoice_data['order_number']=$records['order_key'];
$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['billing_address']=$billing_addr;
$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['invoice_type'] = 1;
if ((int)$countAll == 0) {
@ -965,7 +975,7 @@ class ApiIntegration extends ResourceController
$line_item_data[$i]['quantity'] =(float)$ii->quantity;
$line_item_data[$i]['unit_price'] =(float)$ii->price;
$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]['wp_api_line_items_id'] = $ii->id;
$line_item_data[$i]['invoice_id'] = $last_insert_invoice_id;

View File

@ -188,6 +188,7 @@
<div class="form-row">
<div class="form-group col-md-3">
<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>
<option value="">Choose your Country</option>
<?php foreach ($country_details as $value) { ?>
@ -316,7 +317,8 @@
<script>
$("#addressCopiedAsShipping").on("change", function() {
var count = $(".after-shipping-addr-add-more").length;
var counter = $("#counter").val() === "" ? count : parseInt($("#counter").val(), 10);
if ($(this).is(":checked")) {
var customerAddress1 = $("#baddress1").val();
var customerAddress2 = $("#baddress2").val();
@ -328,24 +330,25 @@
$("#saddress1").val(customerAddress1).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') {
$("#sistate"+count).val(customerInputState).css("display", "none").prop("readonly", false);
$("#sdstate"+count).val(customerDropdownState).css("display", "block").prop("readonly", false);
$("#sistate"+counter).val(customerInputState).css("display", "none").prop("readonly", false);
$("#sdstate"+counter).val(customerDropdownState).css("display", "block").prop("readonly", false);
} else {
$("#sistate"+count).val(customerInputState).css("display", "block").prop("readonly", false);
$("#sdstate"+count).val(customerDropdownState).css("display", "none").prop("readonly", false);
$("#sistate"+counter).val(customerInputState).css("display", "block").prop("readonly", false);
$("#sdstate"+counter).val(customerDropdownState).css("display", "none").prop("readonly", false);
}
$("#scity").val(customerCity).prop("readonly", false);
$("#szip").val(customerPostalCode).prop("readonly", false);
$("#counter").val(counter++).prop("readonly", true);
} else {
// Clear the billing address fields when the checkbox is unchecked
$("#saddress1").val("").prop("readonly", false);
$("#saddress2").val("").prop("readonly", false);
$("#scity").val("").prop("readonly", false);
$("#scountry"+count).val("").prop("readonly", false);
$("#sistate"+count).val("").css("display", "block").prop("readonly", false);
$("#sdstate"+count).val("").css("display", "none").prop("readonly", false);
$("#scountry"+counter).val("").prop("readonly", false);
$("#sistate"+counter).val("").css("display", "block").prop("readonly", false);
$("#sdstate"+counter).val("").css("display", "none").prop("readonly", false);
$("#szip").val("").prop("readonly", false);
$("#scustomer_address_id").val("") // Hidden Field ressetted bcoz Adress history
}
@ -411,6 +414,7 @@
html.find('input#scity').val(sarray[i]['city']);
html.find('select#scountry0').val(sarray[i]['country']);
html.find('select#scountry0').attr('id', 'scountry' + j);
html.find('input#counter').val(j).prop("readonly", true);
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).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('input#sistate0').attr('id', 'sistate' + count).css("display", "block").val('');
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.insertAfter(".after-shipping-addr-add-more:last");
toggleButtons();
@ -458,7 +463,7 @@
function toggleButtons() {
var elementCount = $(".after-shipping-addr-add-more").length;
console.log('elementCount == ' + elementCount);
// console.log('elementCount == ' + elementCount);
if (elementCount > 1) {
$(".shipping-addr-remove").show(); // Show the "shipping-addr-remove" buttons
} else {

View File

@ -17,8 +17,13 @@
<select class="form-control" id="customerName" name="customer_name" required data-toggle="select2">
<option value="">Select a customer</option>
<?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"; ?>>
<?= $customer->first_name . ' ' . $customer->last_name; ?></option>
<?php $disabled = ((int)$customer->isactive == 0) ? 'disabled' : ''; ?>
<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; ?>
</select>
<div class="invalid-feedback"> Please select customer. </div>
@ -115,7 +120,7 @@
<?= $book->title ?></option>
<?php endforeach; ?>
</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 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>
@ -123,7 +128,7 @@
</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>
<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 style="width:10%;">
@ -151,13 +156,13 @@
<option value="<?= $book->book_id ?>"><?= $book->title; ?></option>
<?php endif; endforeach; ?>
</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 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:12%;"><input type="text" class="form-control item-amount" id="amount0" name="amount[]" />
</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 style="width:12%;">
@ -217,7 +222,7 @@
<div class="form-group">
<span style="<?= $shippingChargesStyle ?>">
<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>
</div>
@ -225,7 +230,7 @@
<div class="form-group">
<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 class="form-group">
<label for="grandtotal">Total</label>
@ -234,7 +239,7 @@
<div class="form-group">
<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 class="form-group">
@ -322,11 +327,11 @@
</select>`;
// 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 + ')">';
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[]">';
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>';
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();
@ -516,7 +521,7 @@
$("#invoiceNumber").val(inv_number).prop("readonly", true);
}else{
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) {
return item.id === '1';
});