diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php index ad1d7d2..ac68d25 100644 --- a/app/Controllers/Purchase.php +++ b/app/Controllers/Purchase.php @@ -103,8 +103,7 @@ class Purchase extends BaseController $data['purchase_product']=$purchase_product; } - // echo "
";
- // 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()
diff --git a/app/Controllers/ReturnOrder.php b/app/Controllers/ReturnOrder.php
index 6ec864d..7d65bd5 100644
--- a/app/Controllers/ReturnOrder.php
+++ b/app/Controllers/ReturnOrder.php
@@ -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 '';
+ print_r($this->request->getPost());
+ echo '
';
+ 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,
diff --git a/app/Views/purchase_form.php b/app/Views/purchase_form.php
index 05592a4..9b6907d 100644
--- a/app/Views/purchase_form.php
+++ b/app/Views/purchase_form.php
@@ -172,7 +172,8 @@
- >
+
+ >
@@ -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);
});
+
+
+
+
+
+
diff --git a/app/Views/return_order_form.php b/app/Views/return_order_form.php
index b6c412c..581beb2 100644
--- a/app/Views/return_order_form.php
+++ b/app/Views/return_order_form.php
@@ -63,19 +63,9 @@
(= $purchase['status'] ?>)
@@ -162,7 +152,7 @@
-
+