1145 lines
56 KiB
PHP
Executable File
1145 lines
56 KiB
PHP
Executable File
<?php include('layout/header.php'); ?>
|
|
<style>
|
|
.select2-container--default .select2-results__option--highlighted[aria-selected]{
|
|
color:#ffffff;
|
|
background: #526dee!important;
|
|
}
|
|
.select2-container .select2-selection--single{
|
|
height: 36px;
|
|
border:1px solid #ced4da;
|
|
}
|
|
.select2-container--default .select2-selection--single .select2-selection__rendered{
|
|
line-height: 36px;
|
|
}
|
|
.select2-container--default .select2-selection--single .select2-selection__arrow{
|
|
top:4px;
|
|
}
|
|
|
|
.select2-container .select2-selection--multiple .select2-selection__choice{
|
|
padding: 5px 7px 5px 0 !important;
|
|
color: #000000;
|
|
|
|
}
|
|
.select2-container--default .select2-results__option{
|
|
border-bottom: 1px solid #dddddd;
|
|
}
|
|
.select2-container--default .select2-results__option[aria-selected=true]{
|
|
color: #000000;
|
|
background-color: #3efba4;
|
|
font-weight: 500;
|
|
border-bottom: 1px solid #747474;
|
|
}
|
|
</style>
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box page-title-box-alt">
|
|
<h4 class="page-title"><?php echo $page_name?></h4>
|
|
<div class="page-title-right">
|
|
<a href="<?= base_url() . "product_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
|
<ol class="breadcrumb m-0">
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h4 class="header-title"></h4>
|
|
<form action="<?= base_url() . "add_product"; ?>" id="productForm" method="post">
|
|
<h4 class="header-title">Product Details :</h4><br>
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-8">
|
|
<label for="cubic_centimeter_id" class="col-form-label">Capacity in Cubic Centimeter (C.C.)<span class="text-danger">*</span></label>
|
|
<select class="form-control SelExample" id="CCselect" name="cubic_centimeter_id[]" required multiple>
|
|
<!-- <option value="">Select a Capacity in Cubic Centimeter (C.C.)</option> -->
|
|
<!-- Options for CC -->
|
|
<?php $cubic_ids = isset($products['cubic_centimeter_id'])
|
|
? json_decode($products['cubic_centimeter_id'], true)
|
|
: [];
|
|
?>
|
|
<?php foreach ($capacity as $cc): ?>
|
|
<option value="<?= $cc['id'] ?>"
|
|
<?= in_array($cc['id'], (array)$cubic_ids) ? 'selected' : '' ?>>
|
|
<?= $cc['value'] ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="inputEmail4" class="col-form-label">Product Name<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" name="productname" placeholder="Product Name" value="<?= isset($products['product_name']) ? $products['product_name'] : '' ?>" required>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="dynamic-form-container">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="manufacturer" class="col-form-label">Manufacturer<span class="text-danger">*</span></label>
|
|
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addManufacturerButton" style="font-size: 18px;" data-toggle="modal" data-target="#manufacturer_login-modal" title="Add Manufacturer"></i>' ?>
|
|
<select class="form-control SelExample" id="manufacturer" name="manufacturer" required>
|
|
<option value="">Select a Manufacturer</option>
|
|
<?php foreach ($manufacturers as $value): ?>
|
|
<option value="<?= $value['manufacturer_id'] ?>" <?= isset($products['manufacturer_id']) && $products['manufacturer_id'] == $value['manufacturer_id'] ? 'selected' : '' ?>>
|
|
<?= $value['manufacturer_name'] ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="quality" class="col-form-label">Quality<span class="text-danger">*</span></label>
|
|
<select class="form-control" name="quality" id="quality" required data-toggle="select2">
|
|
<!-- Options for quality will be populated dynamically via JavaScript -->
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="inputAddress" class="col-form-label">Manfacturer Part Number</label>
|
|
<input type="text" class="form-control" name="mfr_part_no" placeholder="Manfacturer Part Number" value="<?= isset($products['mfr_part_no']) ? $products['mfr_part_no'] : '' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-8">
|
|
<label for="vendor" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
|
<select class="form-control SelExample" id="vendor" name="vendor[]" required multiple>
|
|
<!-- Placeholder option -->
|
|
<option value="">Select Vendor</option>
|
|
<?php $vendor_ids = isset($products['vendor'])
|
|
? json_decode($products['vendor'], true)
|
|
: [];
|
|
?>
|
|
<?php foreach ($vendors as $vendor): ?>
|
|
<option value="<?= $vendor['vendor_id'] ?>"
|
|
<?= in_array($vendor['vendor_id'], (array)$vendor_ids) ? 'selected' : '' ?>>
|
|
<?= $vendor['vendor_name'] ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="preferred_vendor" class="col-form-label">Preferred Vendor<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="preferred_vendor" name="prefered_vendor" required>
|
|
<!-- Loop through vendors and set selected attribute if ID matches preferredVendorId -->
|
|
<?php foreach ($vendorsProduct as $vendor): ?>
|
|
<option value="<?= $vendor['id'] ?>" <?= (isset($preferredVendorId) && $vendor['id'] == $preferredVendorId) ? 'selected' : '' ?>>
|
|
<?= $vendor['name'] ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputEmail4" class="col-form-label">HSN/SAC<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" name="hsn_sac" placeholder="HSN/SAC" value="<?= isset($products['hsn_sac']) ? $products['hsn_sac'] : '' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputEmail4" class="col-form-label">Product Category<span class="text-danger">*</span></label>
|
|
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" style="font-size: 18px;" data-toggle="modal" id="addProductCategoryButton" data-target="#add_product_category" title="Add Product Category"></i>' ?>
|
|
<select class="form-control status-select SelExample" id="PCselect" name="productcategory" required data-toggle="select2">
|
|
<option value="">Select Category</option>
|
|
<?php
|
|
if (isset($products['product_id']) && $products['product_id']) {
|
|
foreach ($productcategory as $category) :
|
|
$isDisabled = ((int)$category['isactive'] == 0);
|
|
$isSelected = (isset($products['product_category']) && $products['product_category'] === $category['product_category_name']); ?>
|
|
|
|
<option value="<?= $category['product_category_name'] ?>"
|
|
<?php if ($isSelected) echo "selected"; ?>
|
|
<?= $isDisabled ? 'disabled' : ''; ?>>
|
|
<?= $category['product_category_name'] . ($isDisabled ? " (Disabled)" : ""); ?>
|
|
</option>
|
|
|
|
<?php endforeach;
|
|
} else {
|
|
foreach ($productcategory as $category) :
|
|
if ((int)$category['isactive'] == 1) { ?>
|
|
<option value="<?= $category['product_category_name'] ?>">
|
|
<?= $category['product_category_name']; ?>
|
|
</option>
|
|
<?php }
|
|
endforeach;
|
|
}
|
|
?>
|
|
</select>
|
|
<input type="hidden" class="form-control" name="hiddenproductcategory" value="<?= isset($products['product_category']) ? $products['product_category'] : '' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputEmail4" class="col-form-label">Specification<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" name="specification" placeholder="Specification" value="<?= isset($products['specification']) ? $products['specification'] : '' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputEmail4" class="col-form-label">Rack Number<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" name="rack_number" placeholder="Rack Number" value="<?= isset($products['rack_number']) ? $products['rack_number'] : '' ?>" >
|
|
</div>
|
|
</div>
|
|
<input type="hidden" id="product_id" name="product_id" value="<?= isset($products['product_id']) ? $products['product_id'] : '' ?>"><br>
|
|
<h4 class="header-title">Pricing Information :</h4><br>
|
|
<div class="form-row">
|
|
<!-- <div class="form-group col-md-3">
|
|
<label class="col-form-label">Purchase Cost<span class="text-danger">*</span></label>
|
|
<input type="number" class="form-control" name="purchase_cost" placeholder="Purchase Cost"value="<?= isset($products['purchase_cost']) ? $products['purchase_cost'] : '' ?>" required>
|
|
</div> -->
|
|
|
|
<div class="form-group col-md-3">
|
|
<label class="col-form-label">Unit Price (Including Tax)<span class="text-danger">*</span></label>
|
|
<input type="number" step="0.01" class="form-control" name="total_amount" placeholder="Total Price" value="<?= isset($products['total_amount']) ? $products['total_amount'] : '' ?>" required >
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label class="col-form-label">Tax<span class="text-danger">*</span></label>
|
|
<select class="form-control status-select" name="tax" required data-toggle="select2">
|
|
<?php
|
|
$sgst = isset($products['sgst']) ? $products['sgst'] : 0; // SGST value (half of the tax amount)
|
|
$cgst = isset($products['cgst']) ? $products['cgst'] : 0; // CGST value (half of the tax amount)
|
|
$tax = $sgst + $cgst; // Total tax (sum of SGST and CGST)
|
|
?>
|
|
<option value="0" <?= ($tax == 0) ? 'selected' : '' ?>>Select Tax</option>
|
|
<option value="18" <?= ($tax == 18) ?'selected' : '' ?>>18%</option>
|
|
<option value="28" <?= ($tax == 28) ? 'selected' : '' ?>>28%</option>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group col-md-3">
|
|
<label class="col-form-label">Unit Price<span class="text-danger">*</span></label>
|
|
<input type="test" class="form-control" name="unit_price" placeholder="Price" value="<?= isset($products['unit_price']) ? $products['unit_price'] : '' ?>" required readonly>
|
|
</div>
|
|
</div><br>
|
|
<h4 class="header-title">Stock Information :</h4><br>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-3">
|
|
<label class="col-form-label">Unit of Measurement<span class="text-danger">*</span></label>
|
|
<select class="form-control status-select" id="per" name="per" required data-toggle="select2">
|
|
<option value="" <?= (isset($products['per']) && $products['per'] == '') ? 'selected' : '' ?>>Select</option>
|
|
<option value="Nos" <?= (isset($products['per']) && $products['per'] == 'Nos') ?'selected' : '' ?>>No's</option>
|
|
<option value="ml" <?= (isset($products['per']) && $products['per'] == 'ml') ? 'selected' : '' ?>>ML</option>
|
|
<option value="litre" <?= (isset($products['per']) && $products['per'] == 'litre') ? 'selected' : '' ?>>Litre</option>
|
|
<option value="barrel" <?= (isset($products['per']) && $products['per'] == 'barrel') ? 'selected' : '' ?>>Barrel</option>
|
|
<option value="box" <?= (isset($products['per']) && $products['per'] == 'box') ? 'selected' : '' ?>>Box</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-3" id="ml_div" <?= (isset($products['per']) && $products['per'] == 'ml') ? '' : 'hidden' ?> >
|
|
<label class="col-form-label">ML<span class="text-danger">*</span></label>
|
|
<select name="ml" id="ml" class="form-control SelExample select2-hidden-accessible" <?= (isset($products['per']) && $products['per'] == 'ml') ? 'required' : '' ?>>
|
|
<option value>Select ML</option>
|
|
<?php
|
|
$selectedValue = isset($products['ml']) ? $products['ml'] : 0;
|
|
for ($i = 25; $i <= 950; $i += 25) {
|
|
$selected = ($selectedValue == $i) ? 'selected' : '';
|
|
echo "<option value=\"$i\" $selected>$i</option>";
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-3" id="box_div" <?= (isset($products['per']) && $products['per'] == 'box') ? '' : 'hidden' ?> >
|
|
<label class="col-form-label">No Of Box<span class="text-danger">*</span></label>
|
|
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" name="box" id="box" class="form-control" value="<?= isset($products['box']) ? $products['box'] : '' ?>" <?= (isset($products['per']) && $products['per'] == 'box') ? 'required' : '' ?>>
|
|
</div>
|
|
<div class="form-group col-md-3" id="qty_per_box_div" <?= (isset($products['per']) && $products['per'] == 'box') ? '' : 'hidden' ?> >
|
|
<label class="col-form-label">Qty In Box<span class="text-danger">*</span></label>
|
|
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" name="qty_per_box" id="qty_per_box" class="form-control" value="<?= isset($products['qty_per_box']) ? $products['qty_per_box'] : '' ?>" <?= (isset($products['per']) && $products['per'] == 'box') ? 'required' : '' ?>>
|
|
</div>
|
|
<div class="form-group col-md-3" id="barrel_div" <?= (isset($products['per']) && $products['per'] == 'barrel') ? '' : 'hidden' ?> >
|
|
<label class="col-form-label">No Of Barrel<span class="text-danger">*</span></label>
|
|
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" name="barrel" id="barrel" class="form-control" value="<?= isset($products['barrel']) ? $products['barrel'] : '' ?>" <?= (isset($products['per']) && $products['per'] == 'barrel') ? 'required' : '' ?>>
|
|
</div>
|
|
<div class="form-group col-md-3" id="ltr_per_barrel_div" <?= (isset($products['per']) && $products['per'] == 'barrel') ? '' : 'hidden' ?> >
|
|
<label class="col-form-label">Liters In Barrel<span class="text-danger">*</span></label>
|
|
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" name="ltr_per_barrel" id="ltr_per_barrel" class="form-control" value="<?= isset($products['ltr_per_barrel']) ? $products['ltr_per_barrel'] : '' ?>" <?= (isset($products['per']) && $products['per'] == 'barrel') ? 'required' : '' ?>>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label class="col-form-label">Qty in Stock<span class="text-danger">*</span></label>
|
|
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" class="form-control" id="qty_in_stock" name="qty_in_stock" placeholder="Qty in Stock" value="<?= isset($products['qty_stock']) ? $products['qty_stock'] : '' ?>" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label class="col-form-label">Purchase Order Level<span class="text-danger"></span></label>
|
|
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" class="form-control" id="purchase_order_level" name="purchase_order_level" placeholder="Purchase Order Level" value="<?= isset($products['purchase_order_level']) ? $products['purchase_order_level'] : '' ?>" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label class="col-form-label">Purchase Re-Order Level<span class="text-danger"></span></label>
|
|
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')" class="form-control" id="purchase_reorder_level" name="reorder_level" placeholder="Purchase Re-Order Level" value="<?= isset($products['reorder_level']) ? $products['reorder_level'] : '0' ?>" required>
|
|
</div>
|
|
</div><br>
|
|
<h4 class="header-title">Description Details :</h4><br>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-12">
|
|
<label for="description" class="col-form-label">Description</label>
|
|
<textarea class="form-control" name="description" placeholder="Description"value="<?= isset($products['description']) ? $products['description'] : '' ?>" ></textarea>
|
|
</div>
|
|
</div><br>
|
|
|
|
<button type="submit" class="btn btn-primary" style="float:right;">Submit</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include('layout/footer.php'); ?>
|
|
<!-- Make popup -->
|
|
<div class="modal fade" id="addMakeModal" tabindex="-1" role="dialog" aria-labelledby="addMakeModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addMakeModalLabel">Add New Make</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="addClientForm">
|
|
<div class="form-group">
|
|
<label for="clientName">Make</label>
|
|
<input type="text" class="form-control" id="makes" placeholder="Enter Make"required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="clientMobile">Model</label>
|
|
<input type="text" class="form-control" id="models" placeholder="Enter Model"required>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
<button type="button" class="btn btn-primary" id="saveMakeBtn">Save Make</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- Modal popup -->
|
|
<div class="modal fade" id="addModelModal" tabindex="-1" role="dialog" aria-labelledby="addModelModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addModelModalLabel">Add New Model</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="addModelForm">
|
|
<div class="form-group">
|
|
<label for="makeSelect">Make</label><span id="makeSelectMessage" style="color: red;font-size: 12px; padding-left: 10px;"> (Please select Make from Product Form)</span>
|
|
<select class="form-control" id="makeSelect" required>
|
|
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="modelInput">Model</label>
|
|
<input type="text" class="form-control" id="modelInput" placeholder="Enter Model" required>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
<button type="button" class="btn btn-primary" id="saveModelBtn">Save Model</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Start Biake Mnufacturer Create Pop-UP -->
|
|
<div id="manufacturer_login-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-body">
|
|
<div class="text-center mt-2 mb-4">
|
|
<h4 id="form_add_edit">Add Manufacturer</h4>
|
|
</div>
|
|
|
|
|
|
<div class="form-group">
|
|
<label for="manufacturername">Manufacturer Name </label>
|
|
<input type="text" id="manufacturer_id" hidden>
|
|
<input class="form-control" type="text" id="manufacturer_name" required="" placeholder="Manufacturer Name....">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="manufacturername">Quality</label>
|
|
<select name="quality" id="manufacturer_quality" class="form-control" style="border-color: lightgray;color: #6c757d;" required="true">
|
|
<option value="Q1">Q1</option>
|
|
<option value="Q2">Q2</option>
|
|
<option value="Q3">Q3</option>
|
|
<option value="Q4">Q4</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group text-center">
|
|
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitManufacturers(this)" id="saveManufacturersBtn">Save Manufacturers</button>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div><!-- /.modal-content -->
|
|
</div><!-- /.modal-dialog -->
|
|
</div><!-- /.modal -->
|
|
<!-- End Bike Make Create Pop-UP -->
|
|
|
|
<!-- Start Product Category Add/edit Pop-UP -->
|
|
<div id="add_product_category" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-body">
|
|
<div class="text-center mt-2 mb-4">
|
|
<h4 id="form_add_edit">Add Product Category</h4>
|
|
</div>
|
|
|
|
|
|
<div class="form-group">
|
|
<label for="productcategoryname">Product Category Name </label>
|
|
<input type="text" id="product_category_id" hidden>
|
|
<input class="form-control" type="text" id="product_category_name" required="" placeholder="Product Category Name....">
|
|
</div>
|
|
|
|
<div class="form-group text-center">
|
|
<button class="btn btn-rounded btn-primary" type="submit" id="pcBtn" onclick="submitproductcategory(this)">Save Product Category</button>
|
|
</div>
|
|
|
|
</div>
|
|
</div><!-- /.modal-content -->
|
|
</div><!-- /.modal-dialog -->
|
|
</div><!-- /.modal -->
|
|
<!-- End Product Category Add/edit Pop-UP -->
|
|
|
|
<script>
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
function unitPriceReverseCalculation() {
|
|
var tax = parseFloat($("select[name='tax']").val());
|
|
if(tax == ''){
|
|
toastr.warning('Please select Tax', 'Warning');
|
|
}else{
|
|
var total_amount = parseFloat($("input[name='total_amount']").val());
|
|
var unitPrice = total_amount / parseFloat((tax / 100) + 1);
|
|
if (isNaN(unitPrice)) unitPrice = 0;
|
|
$("input[name='unit_price']").val(unitPrice.toFixed(2));
|
|
}
|
|
|
|
}
|
|
|
|
$("input[name='total_amount'], select[name='tax']").change(function() {
|
|
unitPriceReverseCalculation();
|
|
});
|
|
$("select[name='productcategory']").change(function() {
|
|
// alert($(this).val());
|
|
$("input[name='hiddenproductcategory']").val($(this).val());
|
|
});
|
|
|
|
//---------VENKAT-----------------------------------------------------------------------------------
|
|
|
|
// for Additional Product Name Edit Purpose
|
|
// var additionalProductName = <?= json_encode($additionalProdutName) ?>;
|
|
// if (Array.isArray(additionalProductName) && additionalProductName.length > 0) {
|
|
|
|
// var firstProductName = '<?= isset($products['product_name']) ? $products['product_name'] : '' ?>';
|
|
// console.log('firstProductName', firstProductName);
|
|
// additionalProductName.forEach(function(item) {
|
|
// if (firstProductName !== item.additional_product_name) {
|
|
// addHTMLInput(item); // for if edit
|
|
// }
|
|
// });
|
|
// if(additionalProductName.length == 1){
|
|
// addHTMLInput()
|
|
// }
|
|
// } else {
|
|
// addHTMLInput(); // for else add
|
|
// }
|
|
// end of Additional Product Name Edit Purpose
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
});
|
|
|
|
const $dynamicContainer = $("#dynamic-form-container");
|
|
|
|
$("#model").change(function () {
|
|
const selectedOptions = $(this).find("option:selected");
|
|
|
|
// Loop through the selected options
|
|
selectedOptions.each(function () {
|
|
const modelId = $(this).val(); // Value of the make option
|
|
const modelName = $(this).text(); // Name of the make option
|
|
|
|
// Check if the field already exists
|
|
if (!$(`#field_${modelId}`).length) {
|
|
// Fields to append
|
|
const fieldSet = `
|
|
<div id="field_${modelId}" class="form-row">
|
|
<input type="hidden" class="form-control" id="product_names_id_${modelId}" name="product_names_id[]" >
|
|
<div class="form-group col-md-6">
|
|
<label for="fk_model_id_${modelId}">Model Options:</label>
|
|
<select class="form-control" id="fk_model_id_${modelId}" name="fk_model_id[]">
|
|
<option value="${modelId}">${modelName}</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-6">
|
|
<label for="additional_product_name_${modelId}">Additional Product Name:</label>
|
|
<input type="text" class="form-control" id="additional_product_name_${modelId}" name="additional_product_name[]" placeholder="Enter Additional Product Name">
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
// Append the new field
|
|
$("#dynamic-form-container").append(fieldSet);
|
|
}
|
|
});
|
|
|
|
// Remove fields for deselected options
|
|
$("#dynamic-form-container").find(".form-row").each(function () {
|
|
const fieldId = $(this).attr("id");
|
|
const modelId = fieldId.split("_")[1]; // Extract modelId from the field's id
|
|
|
|
// If the model is no longer selected, remove the field
|
|
if (!$(`#model option[value='${modelId}']`).is(":selected")) {
|
|
$(this).remove();
|
|
}
|
|
});
|
|
|
|
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
// Check SGST checkbox by default
|
|
$('#sgstCheckbox').prop('checked', true);
|
|
$('#sgstValue').removeClass('d-none');
|
|
|
|
// Check CGST checkbox by default
|
|
$('#cgstCheckbox').prop('checked', true);
|
|
$('#cgstValue').removeClass('d-none');
|
|
|
|
// Handle change event for SGST checkbox
|
|
$('#sgstCheckbox').change(function() {
|
|
if ($(this).is(":checked")) {
|
|
$('#sgstValue').removeClass('d-none');
|
|
} else {
|
|
$('#sgstValue').addClass('d-none');
|
|
}
|
|
});
|
|
|
|
// Handle change event for CGST checkbox
|
|
$('#cgstCheckbox').change(function() {
|
|
if ($(this).is(":checked")) {
|
|
$('#cgstValue').removeClass('d-none');
|
|
} else {
|
|
$('#cgstValue').addClass('d-none');
|
|
}
|
|
});
|
|
});
|
|
|
|
</script>
|
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet">
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
|
|
<script>
|
|
$(document).ready(function(){
|
|
// Initialize select2
|
|
$(".SelExample").select2();
|
|
});
|
|
</script>
|
|
<script>
|
|
// $(document).ready(function() {
|
|
// var makeData = <?php // echo json_encode($make); ?>;
|
|
// $('#make').change(function() {
|
|
// var make_id = $(this).val(); // Get the selected make ID
|
|
// make_value = $('option:selected', this).text();
|
|
// var models_id = $('#model').val();
|
|
// if (make_id.includes('0')) {
|
|
|
|
// $('#make').empty();
|
|
// $('#make').append('<option value="" disabled > Select a Make </option>')
|
|
// if (makeData.length > 0) {
|
|
// makeData.forEach(function(make) {
|
|
// if(make.make_id == 0){
|
|
// $('#make').append('<option value="' + make.make_id + '" selected >' + make.make + '</option>')
|
|
// }else{
|
|
// $('#make').append('<option value="' + make.make_id + '" disabled >' + make.make + '</option>');
|
|
// }
|
|
// });
|
|
// $('#model').trigger('change');
|
|
// }
|
|
// make_id = ['0'];
|
|
// } else {
|
|
// // Enable all options if 'General' is not selected
|
|
// $('#make option').each(function () {
|
|
// $(this).prop('disabled', false); // Enable the option
|
|
// });
|
|
// }
|
|
// $('#makeSelect').empty(); // Clear existing options
|
|
// console.log(make_id);
|
|
|
|
// // Assuming make is an array of objects
|
|
// var filteredMakes = makeData.filter(function(item) {
|
|
// return make_id.includes(String(item.make_id)); // Check if make_id matches in the array
|
|
// });
|
|
|
|
// // Check if filteredMakes has any results
|
|
// if (filteredMakes.length > 0) {
|
|
// filteredMakes.forEach(function(make) {
|
|
// $('#makeSelect').append('<option value="' + make.make_id + '">' + make.make + '</option>');
|
|
// });
|
|
// } else {
|
|
// console.log('No matching makes found!');
|
|
// }
|
|
|
|
// // $('#makeSelect').append('<option value="' + make_id + '">' + make_value + '</option>');
|
|
// $('#makeSelectMessage').hide();
|
|
|
|
// // AJAX request to get models based on the selected make ID
|
|
// $('#loader').show();
|
|
// $.ajax({
|
|
// url: '<?php echo base_url('get_models') ?>', // URL to your CodeIgniter controller method
|
|
// type: 'POST',
|
|
// dataType: 'json',
|
|
// data: { make_id: make_id }, // Send the selected make ID to the controller
|
|
// success: function(response) {
|
|
// // Update models dropdown based on the response
|
|
// if (response.length > 0) {
|
|
// // Clear existing options
|
|
// $('#model').empty();
|
|
// // Iterate through response and models_id
|
|
// $.each(response, function(index, model) {
|
|
// var count =0;
|
|
// $.each(models_id, function(index, model_id) {
|
|
// if (model.model_id == model_id) {
|
|
// // Append option for the model
|
|
// $('#model').append('<option value="' + model.model_id + '" selected>' + model.model_name + '</option>');
|
|
// count =1;
|
|
// }
|
|
// });
|
|
// if (count == 0) {
|
|
// $('#model').append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
|
|
// }
|
|
|
|
// });
|
|
// } else {
|
|
// // Handle case when no models are found
|
|
// $('#model').empty().append('<option value="">No models found</option>');
|
|
// }
|
|
// $('#loader').hide();
|
|
// },
|
|
// error: function(xhr, status, error) {
|
|
// // Handle error
|
|
// console.error(xhr.responseText);
|
|
// }
|
|
// });
|
|
// });
|
|
// });
|
|
</script>
|
|
<script>
|
|
$('#qty_in_stock').on('keyup change', function() {
|
|
var qtyInStockInput = document.getElementById('qty_in_stock');
|
|
var purchaseOrderLevelInput = document.getElementById('purchase_order_level');
|
|
var purchaseReorderLevelInput = document.getElementById('purchase_reorder_level');
|
|
|
|
var qtyInStock = parseFloat(qtyInStockInput.value);
|
|
purchaseorderLevel = qtyInStock / 2; // Calculate the purchase reorder level (half of qty in stock)
|
|
purchaseOrderLevel = Math.floor(purchaseorderLevel);
|
|
// Update the value of purchase reorder level input
|
|
purchaseOrderLevelInput.value = isNaN(purchaseOrderLevel) ? '' : purchaseOrderLevel;
|
|
purchaseReorderLevelInput.value = isNaN(qtyInStock) ? '' : qtyInStock;
|
|
|
|
});
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
// Function to update the quality dropdown based on selected manufacturer
|
|
function updateQualityDropdown(manufacturerId) {
|
|
// Clear existing options
|
|
$('#quality').empty();
|
|
// Find the selected manufacturer
|
|
var selectedManufacturer = <?= json_encode($manufacturers) ?>.find(function(manufacturer) {
|
|
return manufacturer.manufacturer_id == manufacturerId;
|
|
});
|
|
// Populate quality options based on all manufacturers
|
|
var allQualities = <?= json_encode($manufacturers) ?>.map(function(manufacturer) {
|
|
return manufacturer.quality.split(',');
|
|
}).flat().filter(function(item, index, self) {
|
|
return self.indexOf(item) === index;
|
|
}).sort();
|
|
allQualities.forEach(function(quality) {
|
|
$('#quality').append('<option value="' + quality.trim() + '" ' + (selectedManufacturer && selectedManufacturer.quality.includes(quality.trim()) ? 'selected' : '') + '>' + quality.trim() + '</option>');
|
|
});
|
|
}
|
|
|
|
// Call the function initially
|
|
$(document).ready(function() {
|
|
// Get the selected manufacturer ID
|
|
var selectedManufacturerId = $('#manufacturer').val();
|
|
// Update the quality dropdown initially
|
|
updateQualityDropdown(selectedManufacturerId);
|
|
|
|
// Update the quality dropdown when manufacturer selection changes
|
|
$('#manufacturer').change(function() {
|
|
var manufacturerId = $(this).val();
|
|
updateQualityDropdown(manufacturerId);
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
// Set selected manufacturer and quality for editing
|
|
$(document).ready(function() {
|
|
// Check if products data is available (for editing)
|
|
var productsData = <?= isset($products) ? json_encode($products) : '' ?>;
|
|
var addtProductsData = <?= isset($additionalProdutName) ? json_encode($additionalProdutName) : '' ?>;
|
|
|
|
if (productsData) {
|
|
// Set selected manufacturer
|
|
$('#manufacturer').val(productsData.manufacturer_id);
|
|
// Trigger change event to update quality dropdown
|
|
$('#manufacturer').trigger('change');
|
|
// Set selected quality
|
|
|
|
$('#quality').val(productsData.quality);
|
|
// ******************* //
|
|
if (productsData.make_id) {
|
|
if (productsData.make_id.includes('0')) {
|
|
// Set the value of the select element to '0'
|
|
$('#make').val('0');
|
|
|
|
// Disable all other options except the selected one
|
|
$('#make option').each(function () {
|
|
if ($(this).val() !== '0') {
|
|
$(this).prop('disabled', true);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
// ******************* //
|
|
if(productsData.models_id){
|
|
$('#model').trigger('change');
|
|
if(addtProductsData){
|
|
addtProductsData.forEach(function(product) {
|
|
$('#additional_product_name_' + product.model_id).val(product.additional_product_name);
|
|
$('#product_names_id_' + product.model_id).val(product.product_names_id);
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
});
|
|
</script>
|
|
<script>
|
|
// Function to update the preferred vendor dropdown based on selected vendors
|
|
function updatePreferredVendorDropdown() {
|
|
var selectedVendors = $('#vendor').val();
|
|
// Clear existing options
|
|
$('#preferred_vendor').empty();
|
|
// Populate preferred vendor options based on selected vendors
|
|
selectedVendors.forEach(function(vendorId) {
|
|
var vendorName = $('#vendor option[value="' + vendorId + '"]').text();
|
|
$('#preferred_vendor').append('<option value="' + vendorId + '" selected>' + vendorName + '</option>');
|
|
});
|
|
}
|
|
|
|
// Call the function initially
|
|
$(document).ready(function() {
|
|
|
|
// Update the preferred vendor dropdown when vendors selection changes
|
|
$('#vendor').change(function() {
|
|
updatePreferredVendorDropdown();
|
|
});
|
|
});
|
|
|
|
|
|
</script>
|
|
<!-- Save a make and model fun -->
|
|
<script>
|
|
$('#saveMakeBtn').click(function() {
|
|
var make = $('#makes').val();
|
|
var model = $('#models').val();
|
|
const button = $('#saveMakeBtn');
|
|
button.prop('disabled', true).text('Processing...');
|
|
if (make != '' && model != '') {
|
|
$.ajax({
|
|
url: '<?php echo base_url().'save_make'?>',
|
|
method: 'POST',
|
|
data: {
|
|
make: make,
|
|
model: model
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
$('#addMakeModalButton').modal('hide');
|
|
// Handle success here, e.g., show a success message
|
|
toastr.success("Make and model saved successfully");
|
|
window.location.reload();
|
|
} else {
|
|
// Handle failure here, e.g., show an error message
|
|
toastr.error("Failed to save make and model");
|
|
button.prop('disabled', false).text('Save Make');
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Error occurred while saving make and model:', error);
|
|
toastr.error("Failed to save make and model. Please try again");
|
|
button.prop('disabled', false).text('Save Make');
|
|
}
|
|
});
|
|
} else {
|
|
toastr.warning("Please fill in both make and model fields");
|
|
button.prop('disabled', false).text('Save Make');
|
|
}
|
|
});
|
|
</script>
|
|
<!-- Save Modal Funxtion -->
|
|
<script>
|
|
// Populate make dropdown in the add model modal
|
|
function populateMakeDropdown() {
|
|
$.ajax({
|
|
url: '<?php echo base_url('get_makes') ?>', // URL to your CodeIgniter controller method to fetch makes
|
|
type: 'GET',
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
$('#makeSelect').empty();
|
|
$('#makeSelect').append('<option value="">Select Make</option>');
|
|
response.forEach(function(make) {
|
|
$('#makeSelect').append('<option value="' + make.make_id + '">' + make.make + '</option>');
|
|
});
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Call the function to populate make dropdown initially
|
|
$(document).ready(function() {
|
|
// populateMakeDropdown();
|
|
});
|
|
|
|
// Save model function
|
|
$('#saveModelBtn').click(function() {
|
|
var makeId = $('#makeSelect').val();
|
|
var model = $('#modelInput').val();
|
|
const button = $('#saveModelBtn');
|
|
button.prop('disabled', true).text('Processing...');
|
|
if (makeId != '' && model != '') {
|
|
$.ajax({
|
|
url: '<?php echo base_url().'save_model'?>',
|
|
method: 'POST',
|
|
data: {
|
|
make_id: makeId,
|
|
modelvalue: model
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
$('#addModelModal').modal('hide');
|
|
toastr.success("Model saved successfully");
|
|
|
|
$('#model').append('<option value="' + response.model_id + '">' + response.model_value + '</option>');
|
|
|
|
} else {
|
|
toastr.error("Failed to save model");
|
|
}
|
|
$('#model').val(response.model_id);
|
|
button.prop('disabled', false).text('Save Model');
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Error occurred while saving model:', error);
|
|
toastr.error("Failed to save model. Please try again");
|
|
button.prop('disabled', false).text('Save Model');
|
|
}
|
|
});
|
|
} else {
|
|
toastr.warning("Please fill in both make and model fields");
|
|
button.prop('disabled', false).text('Save Model');
|
|
}
|
|
});
|
|
|
|
$('#per').change(function () {
|
|
if ($(this).val() == 'ml')
|
|
{
|
|
hide_box();
|
|
hide_barrel();
|
|
show_ml();
|
|
resetStockDetails();
|
|
}
|
|
else if($(this).val() == 'box')
|
|
{
|
|
hide_ml();
|
|
hide_barrel();
|
|
show_box();
|
|
resetStockDetails();
|
|
}
|
|
else if($(this).val() == 'barrel')
|
|
{
|
|
hide_ml();
|
|
hide_box();
|
|
show_barrel();
|
|
resetStockDetails();
|
|
}
|
|
else
|
|
{
|
|
hide_box();
|
|
hide_barrel();
|
|
hide_ml();
|
|
resetStockDetails();
|
|
}
|
|
});
|
|
|
|
function hide_box()
|
|
{
|
|
$('#box_div').attr('hidden', 'hidden');
|
|
$('#box').removeAttr('required');
|
|
$('#qty_per_box_div').attr('hidden', 'hidden');
|
|
$('#qty_per_box').removeAttr('required');
|
|
}
|
|
function hide_barrel()
|
|
{
|
|
$('#barrel_div').attr('hidden', 'hidden');
|
|
$('#barrel').removeAttr('required');
|
|
$('#ltr_per_barrel_div').attr('hidden', 'hidden');
|
|
$('#ltr_per_barrel').removeAttr('required');
|
|
}
|
|
function hide_ml()
|
|
{
|
|
$('#ml_div').attr('hidden', 'hidden');
|
|
$('#ml').removeAttr('required');
|
|
}
|
|
function show_box()
|
|
{
|
|
$('#box_div').removeAttr('hidden');
|
|
$('#box').attr('required','required');
|
|
$('#qty_per_box_div').removeAttr('hidden');
|
|
$('#qty_per_box').attr('required','required');
|
|
}
|
|
function show_barrel()
|
|
{
|
|
$('#barrel_div').removeAttr('hidden');
|
|
$('#barrel').attr('required','required');
|
|
$('#ltr_per_barrel_div').removeAttr('hidden');
|
|
$('#ltr_per_barrel').attr('required','required');
|
|
}
|
|
function show_ml()
|
|
{
|
|
$('#ml_div').removeAttr('hidden');
|
|
$('#ml').attr('required','required');
|
|
}
|
|
|
|
function resetStockDetails()
|
|
{
|
|
$('#ml').val(null).trigger('change');
|
|
$('#barrel').val('');
|
|
$('#ltr_per_barrel').val('');
|
|
$('#box').val('');
|
|
$('#qty_per_box').val('');
|
|
$('#qty_in_stock').val('');
|
|
$('#purchase_order_level').val('');
|
|
$('#purchase_reorder_level').val('');
|
|
}
|
|
|
|
|
|
$('#box, #qty_per_box').on('keyup', function() {
|
|
|
|
var box = $('#box').val();
|
|
var qtyPerBox = $('#qty_per_box').val();
|
|
if (!isNaN(box) && !isNaN(qtyPerBox) && box !== '' && qtyPerBox !== '') {
|
|
var qtyInStock = box * qtyPerBox;
|
|
$('#qty_in_stock').val(qtyInStock).trigger('keyup');
|
|
} else {
|
|
$('#qty_in_stock').val('').trigger('keyup');
|
|
}
|
|
});
|
|
|
|
$('#barrel, #ltr_per_barrel').on('keyup', function() {
|
|
|
|
var barrel = $('#barrel').val();
|
|
var ltrPerBarrel = $('#ltr_per_barrel').val();
|
|
if (!isNaN(barrel) && !isNaN(ltrPerBarrel) && barrel !== '' && ltrPerBarrel !== '') {
|
|
var qtyInStock = barrel * ltrPerBarrel;
|
|
$('#qty_in_stock').val(qtyInStock).trigger('keyup');
|
|
} else {
|
|
$('#qty_in_stock').val('').trigger('keyup');
|
|
}
|
|
});
|
|
|
|
|
|
function submitManufacturers(params) {
|
|
var formData = {
|
|
manufacturer_name: $('#manufacturer_name').val(),
|
|
quality: $('#manufacturer_quality').val()
|
|
};
|
|
|
|
var edit_manufacturer_id = $('#manufacturer_id').val();
|
|
|
|
if (!edit_manufacturer_id) {
|
|
edit_manufacturer_id =0;
|
|
}
|
|
|
|
|
|
if (!$('#manufacturer_name').val() || !$('#manufacturer_quality').val()) {
|
|
return false;
|
|
}
|
|
const button = $('#saveManufacturersBtn');
|
|
button.prop('disabled', true).text('Processing...');
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url().'save_manufacturer'?>',
|
|
type: 'POST',
|
|
data: formData,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
$('#manufacturer_login-modal').modal('hide');
|
|
$('#manufacturer_name').val('');
|
|
|
|
if(response.modelData){
|
|
$('#manufacturer').empty();
|
|
|
|
response.modelData.forEach(function(manufacturer) {
|
|
$('#manufacturer').append($('<option>', {
|
|
value: manufacturer.manufacturer_id,
|
|
text: manufacturer.manufacturer_name
|
|
}));
|
|
});
|
|
|
|
if(response.manufacturer_id) {
|
|
$('#manufacturer').val(response.manufacturer_id);
|
|
if (response.quality) {
|
|
$('#quality').val(response.quality);
|
|
}
|
|
}
|
|
|
|
}
|
|
button.prop('disabled', false).text('Save Manufacturer');//doubted
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
button.prop('disabled', false).text('Save Manufacturer');
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Script for add multiple product name -->
|
|
<script>
|
|
|
|
function addHTMLInput(data = null)
|
|
{
|
|
const container = document.getElementById('dynamic-form-container');
|
|
const newRow = document.createElement('div');
|
|
newRow.className = 'form-row dynamic-form-row';
|
|
newRow.innerHTML = `
|
|
<input value="${data != null && data.product_names_id != null ? data.product_names_id : ''}" type="hidden" name="product_names_id[]" >
|
|
<div class="form-group col-md-6">
|
|
<input value="${data != null && data.additional_product_name != null ? data.additional_product_name : ''}" type="text" class="form-control" id="additional_product_name" name="additional_product_name[]" placeholder="Enter Additional Product name">
|
|
</div>
|
|
|
|
<div class="form-group col-md-6">
|
|
<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>
|
|
`;
|
|
container.appendChild(newRow);
|
|
}
|
|
|
|
function removeHTMLInput(element)
|
|
{
|
|
const container = document.getElementById('dynamic-form-container');
|
|
const rows = container.querySelectorAll('.dynamic-form-row');
|
|
|
|
if (rows.length > 1) {
|
|
const row = element.closest('.dynamic-form-row');
|
|
row.remove();
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
// Prevent multiple submissions by disabling the button on first click
|
|
document.querySelector('#productForm').addEventListener('submit', function (e) {
|
|
const submitButton = this.querySelector('button[type="submit"]');
|
|
submitButton.disabled = true; // Disable the button
|
|
submitButton.textContent = 'Processing...'; // Optional: Show loading text
|
|
});
|
|
|
|
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...');
|
|
|
|
if (productcategoryname === '') {
|
|
toastr.error('Please enter a Product Category Name.', 'Error');
|
|
pcButton.prop('disabled', false).text('Save Product Category');
|
|
return;
|
|
}
|
|
var formData = {
|
|
product_category_name: $('#product_category_name').val(),
|
|
product_category_id : 0
|
|
};
|
|
|
|
if (productcategoryname !== '') {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: 'create_product_category/0',
|
|
data: formData,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
console.log(response);
|
|
if (response.status == "failed") {
|
|
toastr.warning(response.data, 'Warning');
|
|
pcButton.prop('disabled', false).text('Save Product Category');
|
|
}else{
|
|
|
|
$('#product_category_name').val('');
|
|
toastr.success(response.data, 'Success');
|
|
|
|
$('#PCselect').empty();
|
|
response.product_category_list.forEach(function(PC) {
|
|
$('#PCselect').append($('<option>', {
|
|
value: PC.product_category_id,
|
|
text: PC.product_category_name
|
|
}));
|
|
});
|
|
|
|
$('#PCselect option').each(function() {
|
|
if ($(this).text() === productcategoryname) {
|
|
$(this).prop('selected', true);
|
|
}
|
|
});
|
|
|
|
$('#add_product_category').modal('hide');
|
|
}
|
|
pcButton.prop('disabled', false).text('Save Product Category');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
pcButton.prop('disabled', false).text('Save Product Category');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|