FIX_SALSE_ORDER_FORM_TABLR APPEND ISSUE : RV

This commit is contained in:
VENKATESHWARAN 2024-10-10 10:56:29 +05:30
parent 0ef0ee496d
commit 6be1d1b703
3 changed files with 40 additions and 18 deletions

View File

@ -208,17 +208,17 @@ class Sales extends BaseController
$itemtax=$this->request->getPost('item-tax');
$unitprice=$this->request->getPost('unit-price');
$sales_product_id = $this->request->getPost('sales_order_product_id');
$product_names_id = $this->request->getPost('product_names_id');
$status = $this->request->getPost('status');
foreach ($product_ids as $key => $product_string) {
foreach ($product_ids as $key => $product_id) {
$product_id = null;
$product_names_id = null;
// $product_id = null;
// $product_names_id = null;
list($product_id, $product_names_id) = explode('-', $product_string);
// list($product_id, $product_names_id) = explode('-', $product_string);
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
if ($status == 'Created') {
@ -237,7 +237,7 @@ class Sales extends BaseController
$product_data = [
'sales_order_id' => $sales_order_id,
'product_id' => $product_id,
'product_names_id' => $product_names_id,
'product_names_id' => $product_names_id[$key],
'qty' => $qty,
'discount' => $discount,
'discount_type' => $discount_type,

View File

@ -909,7 +909,7 @@ function addHTMLInput(data = null)
</div>
<div class="form-group col-md-6">
<a href="<?= isset($products['product_id']) ? base_url('delete_product_name/' . $products['product_id'] . '/') : '#' ?>${data && data.product_names_id ? data.product_names_id : ''}" class="btn btn-danger waves-effect waves-light" onclick="removeHTMLInput(this)">x</a>
<a class="btn btn-danger waves-effect waves-light" onclick="removeHTMLInput(this); deleteProductName(${data != null && data.product_names_id != null ? data.product_names_id : null})">x</a>
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="addHTMLInput(this)">+</a>
</div>
`;
@ -927,4 +927,16 @@ function removeHTMLInput(element)
}
}
function deleteProductName(data) {
console.log(data);
if (data != null) {
// Correctly form the URL by wrapping the ternary operator inside parentheses
var url = "<?= isset($products['product_id']) ? base_url('delete_product_name/' . $products['product_id'] . '/') : '#' ?>" + (data ? data : '');
console.log(url);
window.location.href = url;
}
}
</script>

View File

@ -183,8 +183,9 @@
if ($salechild['isactive'] == 1) : ?>
<tr>
<td style="width:30%;" class="fixed-dropdown-container">
<input type="hidden" name="product_names_id[]" value="<?= isset($salechild['product_names_id']) ? $salechild['product_names_id'] : '' ?>">
<select class="form-control book-select SelExample" name="item_details[]"
required data-toggle="select2" id="" style="width: 249px !important;">
required data-toggle="select2" id="" style="width: 249px !important;" onchange="addProductNamesId(this)">
<option value="">Select a Product</option>
<?php foreach ($product as $value) : ?>
<?php if ($value['per'] == 'ml') {
@ -194,12 +195,8 @@
}
?>
<?php if ((int)$value["isactive"] === 1) : ?>
<?php
$salse_product_ids = $salechild['product_id'].'-'.$salechild['product_names_id'];
$product_ids = $value['product_id'].'-'.$value['product_names_id'];
?>
<option value="<?= $product_ids ?>"
<?= isset($salechild['product_id']) && $salse_product_ids == $product_ids ? 'selected' : '' ?>>
<option data-id="<?= $value["product_names_id"] ?>" value="<?= $value["product_id"] ?>"
<?= isset($salechild['product_id']) && $salechild['product_names_id'] == $value["product_names_id"] ? 'selected' : '' ?>>
<?= $value["additional_product_name"].$value_ml.' - '.$value["manufacturer_name"]; ?>
</option>
<?php endif; ?>
@ -713,7 +710,10 @@ $(document).ready(function() {
toastr.warning("First Add the Product!");
}else if (productarray.length > 0) {
var newRow = '<tr>' +
'<td style="width:30%" class="fixed-dropdown-container"><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 2px !important;"><option value="">Select a Product</option>';
`<td style="width:30%" class="fixed-dropdown-container">
<input type="hidden" name="product_names_id[]">
<select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 2px !important;" onchange="addProductNamesId(this)">
<option value="">Select a Product</option>`;
for (var i = 0; i < productarray.length; i++) {
var product = productarray[i];
@ -725,10 +725,8 @@ $(document).ready(function() {
var product = productarray[i];
if(!selected_pr.includes(product.product_id))
{
newRow += '<option value="' + product.product_id + '-' + product.product_names_id + '">'
+ product.additional_product_name + value_ml + " - " + product.manufacturer_name +
newRow += '<option data-id="'+ product.product_names_id +'" value="' + product.product_id + '" >' + product.additional_product_name + value_ml + " - " + product.manufacturer_name+
'</option>';
}
}
newRow += '</select></td>' +
@ -1122,4 +1120,16 @@ $(document).on('click', '#selectClient', function() {
}
});
</script>
<!-- script for set the product name id -->
<script>
function addProductNamesId(selectElement) {
var product_names_id = $(selectElement).find('option:selected').attr('data-id');
$(selectElement).closest('tr').find('input[name="product_names_id[]"]').val(product_names_id);
console.log('product_names_id', product_names_id);
}
</script>