This commit is contained in:
heama 2024-04-10 10:26:13 +05:30
parent 3a602a4acc
commit cfacb860a0
5 changed files with 138 additions and 31 deletions

View File

@ -6,6 +6,7 @@ use App\Models\ProductModel;
use App\Models\BikemakeModel;
use App\Models\VendorModel;
use App\Models\BikemodelsModel;
use App\Models\ManufacturerModel;
class Products extends BaseController
@ -60,6 +61,8 @@ class Products extends BaseController
$data['make'] = $BikemakeModel->findAll();
$VendorModel = new VendorModel();
$data['vendors']=$VendorModel->findAll();
$ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll();
$data['page_name']="Add Product";
} else if ($product_id !== '0') {
$data['page_name']="Edit Product";
@ -78,9 +81,12 @@ class Products extends BaseController
$data['tax']=$tax;
$VendorModel = new VendorModel();
$data['vendors']=$VendorModel->findAll();
// print_r($data);die;
$ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll();
$preferredVendorId = $products['prefered_vendor'];
// Pass the preferred vendor ID to the view
$data['preferredVendorId'] = $preferredVendorId; // print_r($data);die;
// print_r($data);die;
}
$data['product_id'] = $product_id;
@ -99,7 +105,7 @@ class Products extends BaseController
'product_name' => $this->request->getPost('productname'),
'product_category' => $this->request->getPost('productcategory'),
'mfr_part_no' => $this->request->getPost('mfr_part_no'),
'serial_no' => $this->request->getPost('serial_no'),
'unit_price' => $this->request->getPost('unit_price'),
'commision_rate' => $this->request->getPost('commision_rate'),
'sgst' => $tax,
@ -114,11 +120,14 @@ class Products extends BaseController
'quality' => $this->request->getPost('quality'),
'make_id' => $this->request->getPost('make'),
'models_id' => json_encode($this->request->getPost('model')),
'rack_number' => $this->request->getPost('rack_number'),
'manufacturer_id' => $this->request->getPost('manufacturer'),
'prefered_vendor' => $this->request->getPost('prefered_vendor'),
'isactive' => 1 ,
'branch_id' => $this->session->get('logged_user_branch_id')
];
// print_r($data);die;
// print_r($data);die;
$product_id = $this->request->getPost('product_id');
@ -131,7 +140,7 @@ class Products extends BaseController
$product_id = $ProductModel->getInsertID();
}
$orderNumber = 'SKU-' . date('md') . '-' . str_pad($product_id, 5, '0', STR_PAD_LEFT);
$orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT);
// print_r($orderNumber);die;
// Update sales order with generated order number
$ProductModel->update($product_id, ['sku_id' => $orderNumber]);

View File

@ -5,7 +5,7 @@ class ManufacturerModel extends Model
{
protected $table = 'manufacturer';
protected $primaryKey = 'manufacturer_id';
protected $allowedFields = ['manufacturer_id','manufacturer_name','isactive','quantity'];
protected $allowedFields = ['manufacturer_id','manufacturer_name','isactive','quality'];
}

View File

@ -5,7 +5,7 @@ class ProductModel extends Model
{
protected $table = 'products';
protected $primaryKey = 'product_id';
protected $allowedFields = ['sku_id','product_id','manufacturer_id','make_id','models_id','quality','product_name','branch_id','search_tag','product_category','mfr_part_no','purchase_order_level','serial_no','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive'];
protected $allowedFields = ['sku_id','product_id','rack_number','manufacturer_id','make_id','models_id','quality','product_name','branch_id','prefered_vendor','product_category','mfr_part_no','purchase_order_level','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive'];
public function getTax()

View File

@ -56,6 +56,28 @@
<input type="text" class="form-control" name="productname" placeholder="Product Name" value="<?= isset($products['product_name']) ? $products['product_name'] : '' ?>" required>
</div>
<div class="form-group col-md-4">
<label for="manufacturer" class="col-form-label">Manufacturer<span class="text-danger">*</span></label>
<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-4">
<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 -->
@ -70,27 +92,25 @@
</select>
</div>
<div class="form-group col-md-4">
<label for="vendor" class="col-form-label">Quality<span class="text-danger">*</span></label>
<select class="form-control " name="quality" required data-toggle="select2" >
<!-- <option value="">Select a Status</option> -->
<option value="Q1" <?= isset($products['quality']) && $products['quality'] === 'Q1' ? 'selected' : '' ?>>Q1</option>
<option value="Q2" <?= isset($products['quality']) && $products['quality'] === 'Q2' ? 'selected' : '' ?>>Q2 </option>
<option value="Q3" <?= isset($products['quality']) && $products['quality'] === 'Q3' ? 'selected' : '' ?>>Q3</option>
<option value="Q4" <?= isset($products['quality']) && $products['quality'] === 'Q4' ? 'selected' : '' ?>>Q4</option>
</select>
</div>
<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 ($vendors as $vendor): ?>
<option value="<?= $vendor['vendor_id'] ?>" <?= ( $vendor['vendor_id'] == $preferredVendorId) ? 'selected' : '' ?>>
<?= $vendor['vendor_name'] ?>
</option>
<?php endforeach; ?>
</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'] : '' ?>" >
<label for="inputEmail4" class="col-form-label">Product Category<span class="text-danger"></span></label>
<input type="text" class="form-control" name="productcategory" placeholder="Product Category" value="<?= isset($products['product_category']) ? $products['product_category'] : '' ?>" >
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Serial Number<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="serial_no" placeholder="Serial Number"value="<?= isset($products['serial_no']) ? $products['serial_no'] : '' ?>" required>
</div>
<div class="form-group col-md-4">
<label for="inputEmail4" class="col-form-label">Product Category<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="productcategory" placeholder="Product Category" value="<?= isset($products['product_category']) ? $products['product_category'] : '' ?>" required>
<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>
@ -282,4 +302,82 @@ document.addEventListener('DOMContentLoaded', function() {
font-weight: 500;
border-bottom: 1px solid #747474;
}
</style>
</style>
<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 = <?= json_encode($products) ?>;
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);
}
});
</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 + '" >' + vendorName + '</option>');
});
}
// Call the function initially
$(document).ready(function() {
// Update the preferred vendor dropdown initially
updatePreferredVendorDropdown();
// Update the preferred vendor dropdown when vendors selection changes
$('#vendor').change(function() {
updatePreferredVendorDropdown();
});
});
</script>

View File

@ -30,9 +30,9 @@
<thead>
<tr>
<th>SKU Id</th>
<th>Product Name</th>
<th>Category</th>
<th>Serial Number</th>
<th>Unit Price</th>
<th>Qty in Stock</th>
<th>Sgst</th>
@ -46,10 +46,10 @@
<?php foreach ($products as $value) :
if ($value['isactive'] == 1) : ?>
<tr>
<td><?= $value['sku_id']; ?></td>
<td><?= $value['product_name']; ?></td>
<td><?= $value['product_category']; ?></td>
<td><?= $value['serial_no']; ?></td>
<td><?= number_format($value['unit_price']); ?></td>
<td><?= number_format($value['unit_price']); ?></td>
<td><?= $value['qty_stock']; ?></td>
<td><?= $value['cgst']; ?>%</td>
<td><?= $value['sgst']; ?>%</td>