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

View File

@ -91,10 +91,10 @@ class ReturnOrder extends BaseController
public function add_return_purchase() public function add_return_purchase()
{ {
$PurchaseOrderModel = new PurchaseOrderModel();
$ProductModel = new ProductModel(); $ProductModel = new ProductModel();
$PurchaseOrderChildModel = new PurchaseOrderChildModel();
$data = [ $data = [
'purchase_order_id' => $this->request->getPost('purchase_order_id'),
'vendor_id' => $this->request->getPost('vendor_id'), 'vendor_id' => $this->request->getPost('vendor_id'),
'order_date' => $this->request->getPost('order_date'), 'order_date' => $this->request->getPost('order_date'),
'contact_person_name' => $this->request->getPost('contact_person_name'), 'contact_person_name' => $this->request->getPost('contact_person_name'),
@ -112,21 +112,23 @@ class ReturnOrder extends BaseController
'terms_condition' => $this->request->getPost('terms_condition'), 'terms_condition' => $this->request->getPost('terms_condition'),
'branch_id'=> $this->session->get('logged_user_branch_id'), 'branch_id'=> $this->session->get('logged_user_branch_id'),
]; ];
echo '<pre>';
print_r($this->request->getPost());
echo '</pre>';
die;
// $return_order_id = $this->request->getPost('return_order_id');
print_r($data);die; // if (!empty($return_order_id)) {
$purchase_order_id = $this->request->getPost('purchase_order_id');
if (!empty($purchase_order_id)) { // $this->returnModel->update($return_order_id, $data);
// } else {
$PurchaseOrderModel->update($purchase_order_id, $data); // $this->returnModel->insert($data);
} else { // $return_order_id = $this->returnModel->getInsertID();
// }
// $orderNumber = 'RO' . str_pad($return_order_id, 8, '0', STR_PAD_LEFT);
$PurchaseOrderModel->insert($data); // $this->returnModel->update($return_order_id, ['order_number' => $orderNumber]);
$purchase_order_id = $PurchaseOrderModel->getInsertID();
}
$orderNumber = 'RO' . str_pad($purchase_order_id, 8, '0', STR_PAD_LEFT);
$PurchaseOrderModel->update($purchase_order_id, ['order_number' => $orderNumber]);
$product_ids = $this->request->getPost('item_details'); $product_ids = $this->request->getPost('item_details');
$quantities = $this->request->getPost('quantity'); $quantities = $this->request->getPost('quantity');
@ -147,8 +149,7 @@ class ReturnOrder extends BaseController
$this->addBackProductQuantity($ProductModel, $product_id, $qty); $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; $tax=isset($itemtax[$key]) ? $itemtax[$key] : 0;
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0; $rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
$amount = isset($amounts[$key]) ? $amounts[$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); // $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
// print_r($discount_type);die; // print_r($discount_type);die;
$child_data = [ $child_data = [
'purchase_order_id' => $purchase_order_id, 'return_order_id' => $return_order_id,
'product_id' => $product_id, 'product_id' => $product_id,
'qty' => $qty, 'qty' => $qty,
// 'discount' => $discount,
// 'discount_type' => $discount_type,
'net_price'=>$rate, 'net_price'=>$rate,
'tax'=>$tax, 'tax'=>$tax,
'amount' => $amount, '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'] : '' ?>"> <input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
</td> </td>
<td style="width:2%;"> <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>
<td style="width:5%;"> <td style="width:5%;">
<input type="number" class="form-control item-quantity" name="amount[]" value="<?= isset($purchasechild['amount']) ? $purchasechild['amount'] : '' ?>"> <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 // For example, updating UI or populating a dropdown with products
// Here, I'm just logging the product array to the console // Here, I'm just logging the product array to the console
productarray = response.product; productarray = response.product;
$('#contact_person_name').val(response.VendorData.contact_person_name1);
$('#contact_person_mobile').val(response.VendorData.contact_person_mobile1);
console.log(productarray); console.log(productarray);
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
@ -556,4 +559,21 @@ $('#editaddbutton').click(function() {
// Enable the vendor dropdown // Enable the vendor dropdown
$('#vendor_id').prop('disabled', false); $('#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> </script>

View File

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