From aeff0b8367d02167e175abefaa4844c59fc088ea Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Wed, 17 Apr 2024 17:01:40 +0530 Subject: [PATCH] CHANGE_RETURN_ORDER : AADHAVAN --- app/Config/Routes.php | 2 + app/Controllers/ReturnOrder.php | 221 +++++++++++++++++++-------- app/Models/ReturnOrderChildModel.php | 10 ++ app/Views/edit_return_order.php | 181 ++++++++++++++++++++++ app/Views/reorder_level_form.php | 1 + app/Views/return_list.php | 19 ++- app/Views/return_order_form.php | 4 +- 7 files changed, 364 insertions(+), 74 deletions(-) create mode 100644 app/Models/ReturnOrderChildModel.php create mode 100644 app/Views/edit_return_order.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 93cb449..03cda40 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -151,6 +151,7 @@ $routes->get("download_purchase_invoice/(:any)", "Purchase::download_purchase_in // Reorder Level// $routes->get('reorder_level_index', 'Reorderlevel::reorder_level_index'); $routes->get('rise_order/(:any)', 'Reorderlevel::rise_order/$1'); + // Return Order// $routes->get('return_order_index', 'ReturnOrder::return_order_index'); $routes->get('return_order', 'ReturnOrder::return_order'); @@ -158,3 +159,4 @@ $routes->get("new_return/(:any)", "ReturnOrder::new_return/$1"); $routes->post("add_return_purchase", "ReturnOrder::add_return_purchase"); $routes->get('get_vendor/(:any)', 'Purchase::get_vendor/$1'); +$routes->get('edit_return_order/(:any)', 'ReturnOrder::edit_return_order/$1'); diff --git a/app/Controllers/ReturnOrder.php b/app/Controllers/ReturnOrder.php index 7d65bd5..fcbd0b1 100644 --- a/app/Controllers/ReturnOrder.php +++ b/app/Controllers/ReturnOrder.php @@ -9,6 +9,7 @@ use App\Models\PurchaseOrderModel; use App\Models\BusinessModel; use App\Models\PurchaseOrderChildModel; use App\Models\ReturnModel; + use App\Models\ReturnOrderChildModel; use Mpdf\Mpdf; @@ -41,9 +42,9 @@ class ReturnOrder extends BaseController public function return_order() { - $PurchaseOrderModel = new PurchaseOrderModel(); + $ReturnModel = new ReturnModel(); - $purchase = $PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id')); + $purchase = $ReturnModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); // echo "
";
         // print_r($product);die;
         $data['purchase']=$purchase;
@@ -91,6 +92,7 @@ class ReturnOrder extends BaseController
 
     public function add_return_purchase()
     {
+
         
         $ProductModel = new ProductModel();
         $data = [
@@ -112,74 +114,112 @@ class ReturnOrder extends BaseController
             'terms_condition' => $this->request->getPost('terms_condition'),
             'branch_id'=> $this->session->get('logged_user_branch_id'),
         ];
-        echo '
';
-        print_r($this->request->getPost());
-        echo '
'; - die; - // $return_order_id = $this->request->getPost('return_order_id'); - - // if (!empty($return_order_id)) { - - // $this->returnModel->update($return_order_id, $data); - // } else { - - // $this->returnModel->insert($data); - // $return_order_id = $this->returnModel->getInsertID(); - // } - // $orderNumber = 'RO' . str_pad($return_order_id, 8, '0', STR_PAD_LEFT); - - // $this->returnModel->update($return_order_id, ['order_number' => $orderNumber]); - - $product_ids = $this->request->getPost('item_details'); - $quantities = $this->request->getPost('quantity'); - $amounts = $this->request->getPost('amount'); - $itemtax=$this->request->getPost('item-tax'); - $unitprice=$this->request->getPost('unit-price'); - $selected_items=$this->request->getPost('return_selected_items'); - $purchase_order_child_id = $this->request->getPost('purchase_order_child_id'); - print_r($selected_items);die; - - // print_r($status);die; - $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; - // print_r($selected_item);die; - if ($status == 'Released' && $selected_item == 1) { - $this->addBackProductQuantity($ProductModel, $product_id, $qty); - } - - $tax=isset($itemtax[$key]) ? $itemtax[$key] : 0; - $rate=isset($unitprice[$key]) ? $unitprice[$key] : 0; - $amount = isset($amounts[$key]) ? $amounts[$key] : 0; - - // $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty); - // print_r($discount_type);die; - $child_data = [ - 'return_order_id' => $return_order_id, - 'product_id' => $product_id, - 'qty' => $qty, - 'net_price'=>$rate, - 'tax'=>$tax, - 'amount' => $amount, - 'is_selected'=>$selected_item, - 'isactive'=>1, - ]; - // print_r($child_data);die; - if (!empty($purchase_order_child_id[$key])) { - - // print_r($purchase_order_child_id[$key]);die; - $PurchaseOrderChildModel->update($purchase_order_child_id[$key], $child_data); - - } else { - $PurchaseOrderChildModel->insert($child_data); - + if ($this->request->getPost('purchase_status') == 'Returned') { + + + + $return_order_id = $this->request->getPost('return_order_id'); + + $ReturnModel = new ReturnModel(); + $ReturnOrderChildModel = new ReturnOrderChildModel(); + + $return = $ReturnModel->where('return_order_id', $return_order_id)->first(); + + + $return_data_update =['status'=>$this->request->getPost('purchase_status')]; + + + if ($return) { + foreach ($item_details as $index => $item_detail) { + foreach ($return_order_child as $child) { + $quantity =$this->request->getPost('quantity'); + + if ($item_detail == $child['product_id']) { + + // $changed_quantity =['qty'=> $child['qty'] - $quantity[$index]]; + + // $purchase_order_child_id = $child['purchase_order_child_id']; + + $PurchaseOrderChildModel->update($purchase_order_child_id, $changed_quantity); + + } + } + } + $ReturnModel->update($return_order_id, $return_data_update); } - + + + return redirect()->to('return_order'); + } else { + $return_order_id = $this->request->getPost('return_order_id'); + + if (!empty($return_order_id)) { - } + $this->returnModel->update($return_order_id, $data); + } else { + + $this->returnModel->insert($data); + $return_order_id = $this->returnModel->getInsertID(); + } + $orderNumber = 'RO' . str_pad($return_order_id, 8, '0', STR_PAD_LEFT); + + $this->returnModel->update($return_order_id, ['order_number' => $orderNumber]); + // die; + $product_ids = $this->request->getPost('item_details'); + $quantities = $this->request->getPost('quantity'); + $amounts = $this->request->getPost('amount'); + $itemtax=$this->request->getPost('item-tax'); + $unitprice=$this->request->getPost('unit-price'); + $selected_items=$this->request->getPost('return_selected_items'); + $purchase_order_child_id = $this->request->getPost('purchase_order_child_id'); + // print_r($selected_items);die; + + $status = $this->request->getPost('purchase_status'); + foreach ($selected_items as $key => $product_id) { + $qty = isset($quantities[$key]) ? $quantities[$key] : 0; + $selected_item= isset($selected_items[$key]) ? $selected_items[$key] : 0; + // print_r($selected_item);die; + if ($status == 'Released' && $selected_item == 1) { + $this->addBackProductQuantity($ProductModel, $product_id, $qty); + } + + + $tax=isset($itemtax[$key]) ? $itemtax[$key] : 0; + $rate=isset($unitprice[$key]) ? $unitprice[$key] : 0; + $amount = isset($amounts[$key]) ? $amounts[$key] : 0; + + // $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty); + // print_r($discount_type);die; + $child_data = [ + 'return_order_id' => $return_order_id, + 'product_id' => $product_id, + 'qty' => $qty, + 'net_price'=>$rate, + 'tax'=>$tax, + 'amount' => $amount, + 'is_selected'=>$selected_item, + 'isactive'=>1, + ]; + // if (!empty($purchase_order_child_id[$key])) { + // print_r("22222222222222222222222222");die; + + $ReturnOrderChildModel = new ReturnOrderChildModel(); + // print_r($purchase_order_child_id[$key]);die; + // $ReturnOrderChildModel->update($purchase_order_child_id[$key], $child_data); + + // } else { + // print_r("11111111111111111111");die; + + $ReturnOrderChildModel->insert($child_data); + + // } + + + } + } + return redirect()->to('purchase_index'); } @@ -335,11 +375,58 @@ public function download_purchase_invoice($purchase_order_id) // Generate the PDF content (HTML) with data $html = view('invoice_purchase_template', ['sales' => $data,'items'=>$items]); -// echo $html;die; + // echo $html;die; // Load HTML into the mPDF instance $mpdf->WriteHTML($html); // Output the PDF to the browser for download $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D'); } + + + public function edit_return_order($return_order_id){ + + $data['page_name']= 'Edit Return Order'; + + + $ReturnModel = new ReturnModel(); + $return_order=$ReturnModel->where('return_order_id', $return_order_id)->first(); + $data['return_order'] = $return_order; + + $purchase_order_id = $return_order['purchase_order_id']; + + $PurchaseOrderModel = new PurchaseOrderModel(); + $purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray(); + $data['purchase'] = $purchase; + + + + $VendorModel = new VendorModel(); + $vendor = $VendorModel->findAll(); + $data['vendor'] = $vendor; + + $data['vendor_id'] = $purchase['vendor_id']; + + $vendorId=$purchase['vendor_id']; + $encodedVendorId = json_encode([$vendorId]); + $productModel = new ProductModel(); + + // Query the database to find the product based on make_id and model_id + $product = $productModel->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false) + ->findAll(); + $data['product']=$product; + + + + + $ReturnOrderChildModel = new ReturnOrderChildModel(); + $return_order_child=$ReturnOrderChildModel->where('return_order_id', $return_order_id)->findAll(); + $data['purchase_product']=$return_order_child; + + // echo"
";
+            // print_r($data);die;
+
+        return view('edit_return_order', $data);
+    }
+
 }
\ No newline at end of file
diff --git a/app/Models/ReturnOrderChildModel.php b/app/Models/ReturnOrderChildModel.php
new file mode 100644
index 0000000..be554ce
--- /dev/null
+++ b/app/Models/ReturnOrderChildModel.php
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+

+
" method="post"> + + +

Purchase Details :


+
+
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ + + +
+
+

Billing Addresss :


+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+

+

Shipping Addresss :


+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+

+ +
+
+

Item Details

+
+ + + + + + + + + + + + + + + + + + + + + + + + +
Item DetailsQty
+ + + + +
+ + + +
+
+ +

Terms & Condition :


+
+
+ + +
+
+ + + +
+
+
+
+
+ + + diff --git a/app/Views/reorder_level_form.php b/app/Views/reorder_level_form.php index 517c4d1..d2d8708 100644 --- a/app/Views/reorder_level_form.php +++ b/app/Views/reorder_level_form.php @@ -163,3 +163,4 @@ + diff --git a/app/Views/return_list.php b/app/Views/return_list.php index 6ca6ecd..43428ca 100644 --- a/app/Views/return_list.php +++ b/app/Views/return_list.php @@ -62,12 +62,21 @@ + - - - - - + + + +
+ + + + + + " class="edit-button" title="Return">      + + + diff --git a/app/Views/return_order_form.php b/app/Views/return_order_form.php index 581beb2..a5dbf34 100644 --- a/app/Views/return_order_form.php +++ b/app/Views/return_order_form.php @@ -135,7 +135,7 @@ - + - +