CHANGE_purchase-order-module:GWM

This commit is contained in:
bitbucket 2024-04-17 12:08:36 +05:30
parent b0d802ed22
commit 25f0a4f900
4 changed files with 50 additions and 38 deletions

View File

@ -103,8 +103,7 @@ class Purchase extends BaseController
$data['purchase_product']=$purchase_product;
}
// echo "<pre>";
// print_r($data);die;
echo view('purchase_form',$data);
}
@ -133,7 +132,7 @@ class Purchase extends BaseController
'branch_id'=> $this->session->get('logged_user_branch_id'),
];
// print_r($data);die;
$purchase_order_id = $this->request->getPost('purchase_order_id');
// echo $purchase_order_id;die;
if (!empty($purchase_order_id)) {
@ -165,7 +164,7 @@ class Purchase extends BaseController
$status = $this->request->getPost('purchase_status');
foreach ($product_ids as $key => $product_id) {
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
$selected_item= isset($selected_items[$key]) ? $selected_items[$key] : 0;
$selected_item = ($selected_items[$key] == 'checked') ? 1 : 0;
// print_r($selected_item);die;
if ($status == 'Received' && $selected_item == 1) {
$this->addBackProductQuantity($ProductModel, $product_id, $qty);
@ -261,6 +260,10 @@ class Purchase extends BaseController
// $makeId = $this->request->getPost('');
$vendorId = $this->request->getPost('vendor_id');
$VendorModel = new VendorModel();
$VendorData = $VendorModel->where('vendor_id',$vendorId)->first();
// Encode the modelId before searching
$encodedVendorId = json_encode([$vendorId]);
@ -275,10 +278,10 @@ class Purchase extends BaseController
// print_r($product);die;
if($product){
// Send JSON response
return $this->response->setJSON(['product'=>$product] );
return $this->response->setJSON(['product'=>$product , 'VendorData' => $VendorData] );
} else {
// If product is not found, return an empty response or appropriate message
return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]);
return $this->response->setJSON(['product'=>[] , 'VendorData' => $VendorData]);
}
}
public function delete_purchase_product()

View File

@ -91,10 +91,10 @@ class ReturnOrder extends BaseController
public function add_return_purchase()
{
$PurchaseOrderModel = new PurchaseOrderModel();
$ProductModel = new ProductModel();
$PurchaseOrderChildModel = new PurchaseOrderChildModel();
$data = [
'purchase_order_id' => $this->request->getPost('purchase_order_id'),
'vendor_id' => $this->request->getPost('vendor_id'),
'order_date' => $this->request->getPost('order_date'),
'contact_person_name' => $this->request->getPost('contact_person_name'),
@ -112,21 +112,23 @@ class ReturnOrder extends BaseController
'terms_condition' => $this->request->getPost('terms_condition'),
'branch_id'=> $this->session->get('logged_user_branch_id'),
];
print_r($data);die;
$purchase_order_id = $this->request->getPost('purchase_order_id');
echo '<pre>';
print_r($this->request->getPost());
echo '</pre>';
die;
// $return_order_id = $this->request->getPost('return_order_id');
if (!empty($purchase_order_id)) {
// if (!empty($return_order_id)) {
$PurchaseOrderModel->update($purchase_order_id, $data);
} else {
// $this->returnModel->update($return_order_id, $data);
// } else {
$PurchaseOrderModel->insert($data);
$purchase_order_id = $PurchaseOrderModel->getInsertID();
}
$orderNumber = 'RO' . str_pad($purchase_order_id, 8, '0', STR_PAD_LEFT);
// $this->returnModel->insert($data);
// $return_order_id = $this->returnModel->getInsertID();
// }
// $orderNumber = 'RO' . str_pad($return_order_id, 8, '0', STR_PAD_LEFT);
$PurchaseOrderModel->update($purchase_order_id, ['order_number' => $orderNumber]);
// $this->returnModel->update($return_order_id, ['order_number' => $orderNumber]);
$product_ids = $this->request->getPost('item_details');
$quantities = $this->request->getPost('quantity');
@ -147,8 +149,7 @@ class ReturnOrder extends BaseController
$this->addBackProductQuantity($ProductModel, $product_id, $qty);
}
$discount = isset($discounts[$key]) ? $discounts[$key] : 0;
$discount_type = isset($discount_types[$key]) ? $discount_types[$key] : '';
$tax=isset($itemtax[$key]) ? $itemtax[$key] : 0;
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
$amount = isset($amounts[$key]) ? $amounts[$key] : 0;
@ -156,11 +157,9 @@ class ReturnOrder extends BaseController
// $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
// print_r($discount_type);die;
$child_data = [
'purchase_order_id' => $purchase_order_id,
'return_order_id' => $return_order_id,
'product_id' => $product_id,
'qty' => $qty,
// 'discount' => $discount,
// 'discount_type' => $discount_type,
'net_price'=>$rate,
'tax'=>$tax,
'amount' => $amount,

View File

@ -172,7 +172,8 @@
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
</td>
<td style="width:2%;">
<input type="checkbox" class="form-control-check-input" name="selected_items[]" value="<?= ($purchasechild['is_selected']) ? '0' : '1' ?>" <?php echo ($purchasechild['is_selected']) ? 'checked' : '1'; ?>>
<input type="hidden" name="selected_items[]" value="<?= ($purchasechild['is_selected'] == 1) ? 'checked' : 'unchecked' ?>"> <!-- Hidden input for unchecked checkboxes -->
<input type="checkbox" class="form-control-check-input" <?php echo ($purchasechild['is_selected'] == 1) ? 'checked' : ''; ?> >
</td>
<td style="width:5%;">
<input type="number" class="form-control item-quantity" name="amount[]" value="<?= isset($purchasechild['amount']) ? $purchasechild['amount'] : '' ?>">
@ -247,6 +248,8 @@ $(document).ready(function() {
// For example, updating UI or populating a dropdown with products
// Here, I'm just logging the product array to the console
productarray = response.product;
$('#contact_person_name').val(response.VendorData.contact_person_name1);
$('#contact_person_mobile').val(response.VendorData.contact_person_mobile1);
console.log(productarray);
},
error: function(xhr, status, error) {
@ -556,4 +559,21 @@ $('#editaddbutton').click(function() {
// Enable the vendor dropdown
$('#vendor_id').prop('disabled', false);
});
</script>
<script>
$(document).ready(function() {
// Attach change event listener to checkboxes
$('.form-control-check-input').change(function() {
// Check if checkbox is checked
if ($(this).is(':checked')) {
$(this).prev('input[type="hidden"]').val('checked'); // Set value to '1'
} else {
$(this).prev('input[type="hidden"]').val('unchecked'); // Set value to '0'
}
});
});
</script>

View File

@ -63,19 +63,9 @@
(<?= $purchase['status'] ?>)
<?php endif; ?></label>
<select class="form-control status-select" name="purchase_status" required data-toggle="select2">
<?php if (isset($purchase['status'])): ?>
<?php if ($purchase['status'] === 'Cancel'): ?>
<option value="">Select Status</option>
<option value="Released" <?= $purchase['status'] === 'Released' ? 'selected' : '' ?>>Released</option>
<?php else: ?>
<option value="">Select Status</option>
<option value="Released" <?= $purchase['status'] === 'Released' ? 'selected' : '' ?>>Released</option>
<option value="Cancel" <?= $purchase['status'] === 'Cancel' ? 'selected' : '' ?>>Cancel</option>
<?php endif; ?>
<?php else: ?>
<option value="Draft" selected>Draft</option>
<!-- <option value="Paid">Paid</option> -->
<?php endif; ?>
</select>
</div>
@ -162,7 +152,7 @@
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
</td>
<td style="width:7%;">
<input type="checkbox" class="form-control-check-input" name="return_selected_items[]" value="">
<input type="checkbox" class="form-control-check-input" name="return_selected_items[]" value="1">
</td>