Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic
This commit is contained in:
commit
5091538fc6
@ -74,7 +74,7 @@ $vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$sales['vehic
|
|||||||
->where('branch_id',$this->session->get('logged_user_branch_id'))
|
->where('branch_id',$this->session->get('logged_user_branch_id'))
|
||||||
->first();
|
->first();
|
||||||
$makeId = $vehicles['make'];
|
$makeId = $vehicles['make'];
|
||||||
$modelId = $vehicle['model'];
|
$modelId = $vehicles['model'];
|
||||||
|
|
||||||
// Encode the modelId before searching
|
// Encode the modelId before searching
|
||||||
$encodedModelId = json_encode([$modelId]);
|
$encodedModelId = json_encode([$modelId]);
|
||||||
@ -163,10 +163,14 @@ $VehicleModel = new VehicleModel();
|
|||||||
$status = $this->request->getPost('status');
|
$status = $this->request->getPost('status');
|
||||||
foreach ($product_ids as $key => $product_id) {
|
foreach ($product_ids as $key => $product_id) {
|
||||||
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
|
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
|
||||||
if ($status == 'Paid') {
|
if ($status == 'Created') {
|
||||||
// echo"hello";die;
|
// echo "hello";die;
|
||||||
// Calculate updated quantity and update Product table
|
|
||||||
$this->updateProductQuantity($ProductModel, $product_id, $qty);
|
$this->updateProductQuantity($ProductModel, $product_id, $qty);
|
||||||
|
}elseif ($status == 'Cancelled'){
|
||||||
|
// echo "cancel";die;
|
||||||
|
|
||||||
|
// echo"hello";die;
|
||||||
|
$this->addBackProductQuantity($ProductModel, $product_id, $qty);
|
||||||
}
|
}
|
||||||
|
|
||||||
$discount = isset($discounts[$key]) ? $discounts[$key] : 0;
|
$discount = isset($discounts[$key]) ? $discounts[$key] : 0;
|
||||||
@ -190,7 +194,9 @@ $status = $this->request->getPost('status');
|
|||||||
// print_r($product_data);die;
|
// print_r($product_data);die;
|
||||||
if (!empty($sales_product_id[$key])) {
|
if (!empty($sales_product_id[$key])) {
|
||||||
|
|
||||||
|
|
||||||
$SalesOrderProductModel->update($sales_product_id[$key], $product_data);
|
$SalesOrderProductModel->update($sales_product_id[$key], $product_data);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$SalesOrderProductModel->insert($product_data);
|
$SalesOrderProductModel->insert($product_data);
|
||||||
|
|
||||||
@ -198,11 +204,23 @@ $status = $this->request->getPost('status');
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return redirect()->to('sales_order_index');
|
return redirect()->to('sales_order_index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
|
||||||
|
{
|
||||||
|
// Fetch current product quantity
|
||||||
|
$product = $ProductModel->find($product_id);
|
||||||
|
$current_qty = $product['qty_stock'];
|
||||||
|
|
||||||
|
// Calculate updated quantity
|
||||||
|
$new_qty = $current_qty + $sold_qty;
|
||||||
|
|
||||||
|
// Update quantity in Product table
|
||||||
|
$ProductModel->update($product_id, ['qty_stock' => $new_qty]);
|
||||||
|
}
|
||||||
private function updateProductQuantity($ProductModel, $product_id, $sold_qty)
|
private function updateProductQuantity($ProductModel, $product_id, $sold_qty)
|
||||||
{
|
{
|
||||||
// Fetch current product quantity
|
// Fetch current product quantity
|
||||||
@ -215,6 +233,7 @@ private function updateProductQuantity($ProductModel, $product_id, $sold_qty)
|
|||||||
// Update quantity in Product table
|
// Update quantity in Product table
|
||||||
$ProductModel->update($product_id, ['qty_stock' => $new_qty]);
|
$ProductModel->update($product_id, ['qty_stock' => $new_qty]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete_sales_product()
|
public function delete_sales_product()
|
||||||
{
|
{
|
||||||
$sales_order_product_id = $this->request->getPost('sales_order_product_id');
|
$sales_order_product_id = $this->request->getPost('sales_order_product_id');
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
<label for="inputEmail4" class="col-form-label">Vehicle<span class="text-danger">*</span></label>
|
<label for="inputEmail4" class="col-form-label">Vehicle<span class="text-danger">*</span></label>
|
||||||
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Client"></i>' ?>
|
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Client"></i>' ?>
|
||||||
|
|
||||||
<select class="form-control vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? '' : 'required' ?>>
|
<select class="form-control vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? 'readonly' : 'required' ?>>
|
||||||
|
|
||||||
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
|
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
|
||||||
<?php foreach ($vehicle as $value) : ?>
|
<?php foreach ($vehicle as $value) : ?>
|
||||||
@ -55,13 +55,24 @@
|
|||||||
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($sales['mobile_no']) ? $sales['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" readonly>
|
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($sales['mobile_no']) ? $sales['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-4">
|
||||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span></label>
|
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>(<?php echo isset($sales['status']) ? $sales['status'] : '' ?>)</label>
|
||||||
<select class="form-control status-select" name="status" required data-toggle="select2" >
|
<select class="form-control status-select" name="status" required data-toggle="select2">
|
||||||
<!-- <option value="">Select a Status</option> -->
|
<?php if (isset($sales['status'])): ?>
|
||||||
<option value="Created" <?= isset($sales['status']) && $sales['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
|
<?php if ($sales['status'] === 'Cancelled'): ?>
|
||||||
<option value="Paid" <?= isset($sales['status']) && $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
<option value="Created" <?= $sales['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
|
||||||
</select>
|
<option value="Paid" <?= $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||||
</div>
|
<?php else: ?>
|
||||||
|
<option value="Paid" <?= $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||||
|
<option value="Cancelled" <?= $sales['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<option value="Created" selected>Created</option>
|
||||||
|
<option value="Paid">Paid</option>
|
||||||
|
<?php endif; ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</div><br>
|
</div><br>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user