diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index cbadf4f..a5f7f21 100755 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -153,11 +153,12 @@ class Sales extends BaseController if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } $SalesOrderModel = new SalesOrderModel(); $ProductModel = new ProductModel(); - $SalesOrderProductModel = new SalesOrderProductModel(); // Assuming you have a model for sales_order_product + $SalesOrderProductModel = new SalesOrderProductModel(); // Prepare data for sales order + $status = $this->request->getPost('status') != '' ? $this->request->getPost('status') : 'Draft'; $data = [ 'client_name' => $this->request->getPost('client_id'), 'vehicle_id'=>$this->request->getPost('vehicle_id'), @@ -166,35 +167,38 @@ class Sales extends BaseController 'mobile_no' => $this->request->getPost('mobile_no'), 'billing_state' => $this->request->getPost('state'), 'billing_postal_code' => $this->request->getPost('postalcode'), - // 'billing_country' => $this->request->getPost('country'), 'terms_condition' => $this->request->getPost('terms_condition'), 'subtotal' => $this->request->getPost('sub_total'), 'tax' => $this->request->getPost('invoice_tax'), - 'total'=> $this->request->getPost('grand_total'), - 'status'=> $this->request->getPost('status'), - 'isactive' => 1, // Assuming this is a default value or handled separately + 'status'=> $status, + 'isactive' => 1, 'branch_id'=> $this->session->get('logged_user_branch_id'), ]; + + // Insert or update sales order $sales_order_id = $this->request->getPost('sales_order_id'); - if (!empty($sales_order_id)) { - if ($this->request->getPost('status') === "Paid") { + + //update sales-order + if ($status === "Approved") { $data['mode_of_payment'] = $this->request->getPost('mode_of_payment'); } $SalesOrderModel->update($sales_order_id, $data); - } else { - $data['inv_no'] = InvNoHelper::generateInvoiceNumber(); - // dd($data); + } else { + + //create sales-order + $data['inv_no'] = InvNoHelper::generateInvoiceNumber(); $SalesOrderModel->insert($data); $sales_order_id = $SalesOrderModel->getInsertID(); // Update sales order with generated order number $orderNumber = 'SO-' . date('md') . '-' . str_pad($sales_order_id, 5, '0', STR_PAD_LEFT); $SalesOrderModel->update($sales_order_id, ['order_number' => $orderNumber]); + } @@ -211,22 +215,16 @@ class Sales extends BaseController $product_names_id = $this->request->getPost('product_names_id'); - $status = $this->request->getPost('status'); - foreach ($product_ids as $key => $product_id) { + + foreach ($product_ids as $key => $product_id) + { - - // $product_id = null; - // $product_names_id = null; - - // list($product_id, $product_names_id) = explode('-', $product_string); - $qty = isset($quantities[$key]) ? $quantities[$key] : 0; - if ($status == 'Created') { + if ($status == 'Approved') { $this->subractProductQuantity($ProductModel, $product_id, $qty); }elseif ($status == 'Cancelled'){ $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; @@ -350,7 +348,7 @@ class Sales extends BaseController if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } // Fetch the invoice data based on $invoice_id $model = new SalesOrderModel(); - $saleOrderCount = count($model->where('status','Paid')->findAll()); + $saleOrderCount = count($model->where('status','Approved')->findAll()); $VehicleModel = new VehicleModel(); $BranchModel = new BranchModel(); $BusinessModel = new BusinessModel(); @@ -386,29 +384,19 @@ class Sales extends BaseController // Generate the PDF content (HTML) if ($data['sales'][0]->status === 'Draft') { - // Set the watermark text and options $mpdf->SetWatermarkText('Draft'); $mpdf->showWatermarkText = true; } if ($data['sales'][0]->status === 'Cancelled') { - // Set the watermark text and options $mpdf->SetWatermarkText('Cancelled'); $mpdf->showWatermarkText = true; } - if ($data['sales'][0]->status === 'Void') { - // Set the watermark text and options - $mpdf->SetWatermarkText('Void'); - $mpdf->showWatermarkText = true; - } // Generate the PDF content (HTML) with data $html = view('invoice_pdf_template', $data); - // echo $html;die; - // Load HTML into the mPDF instance $mpdf->WriteHTML($html); date_default_timezone_set('Asia/Kolkata'); - // Output the PDF to the browser for download $mpdf->Output($data['sales'][0]->order_number .'_' . date('Y-m-d H-i-s') . '.pdf', 'D'); } @@ -419,7 +407,7 @@ class Sales extends BaseController // Fetch the invoice data based on $invoice_id $model = new SalesOrderModel(); - $saleOrderCount = count($model->where('status','Paid')->findAll()); + $saleOrderCount = count($model->where('status','Approved')->findAll()); $VehicleModel = new VehicleModel(); $BranchModel = new BranchModel(); $BusinessModel = new BusinessModel(); @@ -539,7 +527,7 @@ class Sales extends BaseController ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false) ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) - ->where('qty_stock >',0) + // ->where('qty_stock >',0) ->where('products.isactive', 1) ->findAll(); @@ -551,7 +539,7 @@ class Sales extends BaseController ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false) ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) - ->where('qty_stock >',0) + // ->where('qty_stock >',0) ->where('products.isactive', 1) ->findAll(); diff --git a/app/Views/sales_list.php b/app/Views/sales_list.php index 88060ec..4ec5a91 100755 --- a/app/Views/sales_list.php +++ b/app/Views/sales_list.php @@ -9,16 +9,16 @@ float:left; } .cancelled-status { - color: red; -} + color: red; + } -.created-status { - color: blue; -} + .Draft-status { + color: blue; + } -.paid-status { - color: green; -} + .Approved-status { + color: green; + }