diff --git a/Mechanics.txt b/Mechanics.txt new file mode 100644 index 0000000..2c1fd20 --- /dev/null +++ b/Mechanics.txt @@ -0,0 +1,32 @@ +Mechanics + +Sales order +1.vehicle id readonly issue +2.add more item in edit +3.default qty should be 1 .amount should be qty*rate+tax (calculation changes) +4.Sales order list client mobile tax subtotal should remove +status cancel in red,create in blue and paid in green +5.status label bracket hide in creat +6.In edit make and model not show + +Product +1.model handle(reload existing selcted id should not remove) + + +vehicle +1.adding new client mobille number not populate + + +Purchase order +1.to set vendor read only +2.add more item in edit +3.STYLE IN ITEM SELCT +4.Search in selct vendor column +5.calculation should be removed only qty product name +6.qty add in product when status is release is based on checkbox slected .only update will done if checked +7.Pdf same as sales order + +Return Products +1.Same as purchase model .user can selct the product to be returned +2.initially status is in draft nothing happens +3.when status is returned qty should be decrease diff --git a/app/Config/Routes.php b/app/Config/Routes.php index feabbab..61f9d1f 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -145,5 +145,15 @@ $routes->get("new_purchase/(:any)", "Purchase::new_purchase/$1"); $routes->get('get_vendor/(:any)', 'Purchase::get_vendor/$1'); $routes->post("add_purchase", "Purchase::add_purchase"); $routes->get("delete_purchase/(:any)", "Purchase::delete_purchase/$1"); +$routes->post("getVendorProducts", "Purchase::getVendorProducts"); +$routes->post("delete_purchase_product", "Purchase::delete_purchase_product"); +$routes->get("download_purchase_invoice/(:any)", "Purchase::download_purchase_invoice/$1"); // 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'); +$routes->get("new_return/(:any)", "ReturnOrder::new_return/$1"); +$routes->get('get_vendor/(:any)', 'Purchase::get_vendor/$1'); +$routes->post("add_purchase", "Purchase::add_purchase"); diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index c93149b..5053650 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -313,10 +313,14 @@ public function save_model() { ]; - $BikemodelsModel->insert($modelData); + $model_id = $BikemodelsModel->insert($modelData); + + $modelData = $BikemodelsModel->where('make_id',$make_id)->findAll(); $response['success'] = true; + $response['model_id'] = $model_id; + $response['model_value'] = $model; } else { $response['success'] = false; diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php index 7920bb7..ad1d7d2 100644 --- a/app/Controllers/Purchase.php +++ b/app/Controllers/Purchase.php @@ -7,6 +7,8 @@ use App\Models\PurchaseOrderModel; use App\Models\VendorModel; use App\Models\BranchModel; use App\Models\BusinessModel; + use App\Models\PurchaseOrderChildModel; + use Mpdf\Mpdf; class Purchase extends BaseController @@ -21,10 +23,12 @@ class Purchase extends BaseController { $PurchaseOrderModel = new PurchaseOrderModel(); - $purchase = $PurchaseOrderModel->where('purchase_order.branch_id', $this->session->get('logged_user_business_id')) - ->select('purchase_order.*, vendor.vendor_name') - ->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id') - ->findAll(); + // $purchase = $PurchaseOrderModel->where('purchase_order.branch_id', $this->session->get('logged_user_business_id')) + // ->select('purchase_order.*, vendor.vendor_name') + // ->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id') + // ->findAll(); + + $purchase = $PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id')); // echo "
";
         // print_r($product);die;
         $data['purchase']=$purchase;
@@ -45,11 +49,16 @@ class Purchase extends BaseController
             $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->select('vendor_id,vendor_name')->findAll();
 
 
+
             $BranchModel = new BranchModel();
             $BusinessModel = new BusinessModel();
             $branch = $BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
             $business = $BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
-    
+            $ProductModel = new ProductModel();
+            $product=$ProductModel
+            ->where('isactive',1)
+            ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+            $data['product']=$product;   
             $data['branch'] = $branch;  
             $data['business'] = $business;  
 
@@ -66,8 +75,32 @@ class Purchase extends BaseController
             $VendorModel = new VendorModel();
             $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))->select('vendor_id,vendor_name')->findAll();
             $data['vendor']=$vendor;
+
             $data['purchase'] = $purchase;
+               
+            
+            
+            $VendorModel = new VendorModel();
+            $vendor = $VendorModel->findAll();
+            $data['vendor'] = $vendor;
+
             $data['vendor_id'] = $purchase['vendor_id'];
+// print_r($vendor);die;
+            $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;
+// print_r($product);die;
+
+
+
+            $PurchaseOrderChildModel = new PurchaseOrderChildModel();
+            $purchase_product=$PurchaseOrderChildModel->where('purchase_order_id', $purchase_order_id)->findAll();
+            $data['purchase_product']=$purchase_product;
 
         }
         // echo "
";
@@ -78,6 +111,8 @@ class Purchase extends BaseController
     public function add_purchase()
     {
         $PurchaseOrderModel = new PurchaseOrderModel();
+        $ProductModel = new ProductModel();
+        $PurchaseOrderChildModel = new PurchaseOrderChildModel(); 
         $data = [
             'vendor_id' => $this->request->getPost('vendor_id'),
             'order_date' => $this->request->getPost('order_date'),
@@ -92,23 +127,100 @@ class Purchase extends BaseController
             'shipping_state' => $this->request->getPost('shipping_state'), 
             'shipping_city' =>$this->request->getPost('shipping_city'),
             'shipping_postal_code' => $this->request->getPost('shipping_postal_code'),
-            'description' => $this->request->getPost('description'),
+            'bill_number' => $this->request->getPost('bill_number')? $this->request->getPost('bill_number') : '',
+            'return_date' => $this->request->getPost('return_date') ? $this->request->getPost('return_date') : '',         
+            'terms_condition' => $this->request->getPost('terms_condition'),
+            'branch_id'=> $this->session->get('logged_user_branch_id'),
         ];
-        // echo "
";
-        // print_r($this->request->getPost());die;
+
+    //  print_r($data);die;
         $purchase_order_id = $this->request->getPost('purchase_order_id');
-    
+        //  echo  $purchase_order_id;die;
         if (!empty($purchase_order_id)) {
         
             $PurchaseOrderModel->update($purchase_order_id, $data);
         } else {
             
             $PurchaseOrderModel->insert($data);
+            $purchase_order_id = $PurchaseOrderModel->getInsertID(); 
         }
-    
+        $orderNumber = 'PO' .  str_pad($purchase_order_id, 8, '0', STR_PAD_LEFT);
+        // print_r($orderNumber);die;
+            // Update sales order with generated order number
+            $PurchaseOrderModel->update($purchase_order_id, ['order_number' => $orderNumber]);
+        //  print_r();die;
+            // Prepare data for sales order product
+            $product_ids = $this->request->getPost('item_details');
+            $quantities = $this->request->getPost('quantity');
+            // $discounts = $this->request->getPost('discount_amount');
+            // $discount_types = $this->request->getPost('discount_type');
+            $amounts = $this->request->getPost('amount');
+            $itemtax=$this->request->getPost('item-tax');
+            $unitprice=$this->request->getPost('unit-price');
+            $selected_items=$this->request->getPost('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 == 'Received' && $selected_item == 1) {
+                    $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;
+              
+                // $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
+                // print_r($discount_type);die;
+                $child_data = [
+                    'purchase_order_id' => $purchase_order_id,
+                    'product_id' => $product_id,
+                    'qty' => $qty,
+                    // 'discount' => $discount,
+                    // 'discount_type' => $discount_type,
+                    '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);
+                   
+                }
+               
+                
+            }
+            
         
         return redirect()->to('purchase_index');
     }
+    private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
+{
+  
+    // Fetch current product quantity
+    $product = $ProductModel->find($product_id);
+    $current_qty = $product['qty_stock'];
+
+    // Calculate updated quantity
+    $new_qty = $current_qty + $sold_qty;
+
+    // Update quantity in Product table
+    $ProductModel->update($product_id, ['qty_stock' => $new_qty]);
+}
 
     public function delete_purchase($purchase_order_id)
     {
@@ -143,5 +255,114 @@ class Purchase extends BaseController
         return json_encode($products);
 
     }
+    public function getVendorProducts()
+{
+    // Retrieve make_id and model_id from the request
+    // $makeId = $this->request->getPost('');
+    $vendorId = $this->request->getPost('vendor_id');
 
+    // Encode the modelId before searching
+    $encodedVendorId = json_encode([$vendorId]);
+
+    // Load the ProductModel
+    $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();
+
+    // print_r($product);die;
+    if($product){
+        // Send JSON response
+        return $this->response->setJSON(['product'=>$product] );
+    } else {
+        // If product is not found, return an empty response or appropriate message
+        return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]);
+    }
+}
+public function delete_purchase_product()
+{
+    $purchase_order_child_id = $this->request->getPost('purchase_order_child_id');
+    
+    if (!empty($purchase_order_child_id)) {
+        $PurchaseOrderChildModel = new PurchaseOrderChildModel();
+        $data['isactive'] = 0;
+        
+        if ($PurchaseOrderChildModel->update($purchase_order_child_id, $data)) {
+            // Return success response
+            return $this->response->setJSON(['success' => true]);
+        }
+    }
+
+    // Return error response if deletion fails
+    return $this->response->setJSON(['success' => false]);
+}
+public function download_purchase_invoice($purchase_order_id)
+{
+    // echo "hello"; die;
+    // Fetch the invoice data based on $invoice_id
+    $model = new PurchaseOrderModel();
+    $data = $model->getPurchasePdf($purchase_order_id);
+    
+ $items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
+
+    
+    
+    //  print_r($items);die();
+    
+    //  print_r($invoiceItems);die();
+
+    // Create an mPDF object
+    $mpdf = new Mpdf([
+        'mode' => '',
+        'format' => 'A5',
+        'default_font_size' => 0,
+        'default_font' => '',
+        
+        // 'margin_right' => 1,
+        'margin_top' => 6,
+        'margin_bottom' => 6,
+        'margin_header' => 6,
+        'margin_footer' =>-30,
+        'orientation' => 'P',
+    ]);
+
+   
+
+    $mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
+    // Set PDF properties 
+    $mpdf->SetTitle('Invoice');
+    $mpdf->SetAuthor($data[0]->branch_name);
+    $mpdf->SetCreator('');
+  
+  
+
+    // Generate the PDF content (HTML)
+    // if ($data[0]->status === 'Draft') {
+    //     // Set the watermark text and options
+    //     $mpdf->SetWatermarkText('Draft');
+    //     $mpdf->showWatermarkText = true;
+    // }
+    // if ($data[0]->status === 'Cancelled') {
+    //     // Set the watermark text and options
+    //     $mpdf->SetWatermarkText('Cancelled');
+    //     $mpdf->showWatermarkText = true;
+    // }
+    // if ($data[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_purchase_template', ['sales' => $data,'items'=>$items]);
+// 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');
+}
 }
\ No newline at end of file
diff --git a/app/Controllers/Reorderlevel.php b/app/Controllers/Reorderlevel.php
index 4a67041..1266a82 100644
--- a/app/Controllers/Reorderlevel.php
+++ b/app/Controllers/Reorderlevel.php
@@ -3,6 +3,7 @@
 namespace App\Controllers;
 
 use App\Models\ProductModel;
+use App\Models\VendorModel;
 
 
 class Reorderlevel extends BaseController
@@ -28,5 +29,15 @@ class Reorderlevel extends BaseController
        
         return view('reorder_level_list',$data);
     }
+    public function rise_order($product_id)
+    {
+        $ProductModel = new ProductModel();
+        $products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
+        $data['products']=$products;
+       $vendorid= $products['prefered_vendor'];
+       $VendorModel = new VendorModel();
+       $vendor=$VendorModel->where('vendor_id',$vendorid)->findAll();
+       print_r($vendor);die;
+    }
 }
 ?>
\ No newline at end of file
diff --git a/app/Controllers/ReturnOrder.php b/app/Controllers/ReturnOrder.php
new file mode 100644
index 0000000..1f8a318
--- /dev/null
+++ b/app/Controllers/ReturnOrder.php
@@ -0,0 +1,375 @@
+session = session();
+    }
+ 
+    public function return_order_index()
+    {
+        $PurchaseOrderModel = new PurchaseOrderModel();
+
+        $purchase = $PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id'));
+        // echo "
";
+        // print_r($product);die;
+        $data['purchase']=$purchase;
+        
+        $ReturnModel = new ReturnModel();
+
+        $return = $ReturnModel->findAll();
+        $data['return']=$return;
+        // echo "
";
+        // print_r($data);die;
+        return view('return_order_liist',$data);
+    }
+         
+    public function return_order()
+    {
+        $PurchaseOrderModel = new PurchaseOrderModel();
+
+        $purchase = $PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id'));
+        // echo "
";
+        // print_r($product);die;
+        $data['purchase']=$purchase;
+    
+        // echo "
";
+        // print_r($data);die;
+        return view('return_list',$data);
+    }
+    public function new_return($purchase_order_id)
+    {
+        if ($purchase_order_id === '0') {
+           
+           
+            $PurchaseOrderModel = new PurchaseOrderModel();
+            $data['purchase'] =$PurchaseOrderModel->getdata($this->session->get('logged_user_branch_id'));
+            // print_r($data);die;
+            $VendorModel = new VendorModel();
+            $vendor = $VendorModel->findAll();
+
+
+            $BranchModel = new BranchModel();
+            $BusinessModel = new BusinessModel();
+            $branch = $BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
+            $business = $BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
+            $ProductModel = new ProductModel();
+            $product=$ProductModel
+            ->where('isactive',1)
+            ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+            $data['product']=$product;   
+            $data['branch'] = $branch;  
+            $data['business'] = $business;  
+
+            $data['page_name']="Add Purchase Order";
+            $data['vendor']=$vendor;
+
+            $data['vendor_id'] = [];
+        } else if ($purchase_order_id !== '0') {
+            $data['page_name']="Edit Purchase Order";
+
+            $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'];
+// print_r($vendor);die;
+            $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;
+// print_r($product);die;
+
+
+
+            $PurchaseOrderChildModel = new PurchaseOrderChildModel();
+            $purchase_product=$PurchaseOrderChildModel->where('purchase_order_id', $purchase_order_id)->findAll();
+            $data['purchase_product']=$purchase_product;
+
+        }
+        // echo "
";
+        // print_r($data);die;
+        echo view('return_order_form',$data);
+    }
+
+    public function add_purchase()
+    {
+        $PurchaseOrderModel = new PurchaseOrderModel();
+        $ProductModel = new ProductModel();
+        $PurchaseOrderChildModel = new PurchaseOrderChildModel(); 
+        $data = [
+            'vendor_id' => $this->request->getPost('vendor_id'),
+            'order_date' => $this->request->getPost('order_date'),
+            'contact_person_name' => $this->request->getPost('contact_person_name'),
+            'contact_person_mobile'=> $this->request->getPost('contact_person_mobile'),
+            'status'=> $this->request->getPost('purchase_status'),
+            'billing_address' => $this->request->getPost('billing_address'),
+            'billing_state' => $this->request->getPost('billing_state'),
+            'billing_city' => $this->request->getPost('billing_city'),
+            'billing_postal_code' => $this->request->getPost('billing_postal_code'), 
+            'shipping_address' => $this->request->getPost('shipping_address'), 
+            'shipping_state' => $this->request->getPost('shipping_state'), 
+            'shipping_city' =>$this->request->getPost('shipping_city'),
+            'shipping_postal_code' => $this->request->getPost('shipping_postal_code'),
+            'return_date' => $this->request->getPost('return_date') ? $this->request->getPost('return_date') : '',         
+            '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  $purchase_order_id;die;
+        if (!empty($purchase_order_id)) {
+        
+            $PurchaseOrderModel->update($purchase_order_id, $data);
+        } else {
+            
+            $PurchaseOrderModel->insert($data);
+            $purchase_order_id = $PurchaseOrderModel->getInsertID(); 
+        }
+        $orderNumber = 'PO' .  str_pad($purchase_order_id, 8, '0', STR_PAD_LEFT);
+        // print_r($orderNumber);die;
+            // Update sales order with generated order number
+            $PurchaseOrderModel->update($purchase_order_id, ['order_number' => $orderNumber]);
+        //  print_r();die;
+            // Prepare data for sales order product
+            $product_ids = $this->request->getPost('item_details');
+            $quantities = $this->request->getPost('quantity');
+            // $discounts = $this->request->getPost('discount_amount');
+            // $discount_types = $this->request->getPost('discount_type');
+            $amounts = $this->request->getPost('amount');
+            $itemtax=$this->request->getPost('item-tax');
+            $unitprice=$this->request->getPost('unit-price');
+            $selected_items=$this->request->getPost('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);
+                }
+              
+                $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;
+              
+                // $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
+                // print_r($discount_type);die;
+                $child_data = [
+                    'purchase_order_id' => $purchase_order_id,
+                    'product_id' => $product_id,
+                    'qty' => $qty,
+                    // 'discount' => $discount,
+                    // 'discount_type' => $discount_type,
+                    '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);
+                   
+                }
+               
+                
+            }
+            
+        
+        return redirect()->to('purchase_index');
+    }
+    private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
+{
+  
+    // Fetch current product quantity
+    $product = $ProductModel->find($product_id);
+    $current_qty = $product['qty_stock'];
+
+    // Calculate updated quantity
+    $new_qty = $current_qty + $sold_qty;
+
+    // Update quantity in Product table
+    $ProductModel->update($product_id, ['qty_stock' => $new_qty]);
+}
+
+    public function delete_purchase($purchase_order_id)
+    {
+        $PurchaseOrderModel = new PurchaseOrderModel();
+        $where = ['purchase_order_id' => $purchase_order_id, 'isactive' => 1 ]; // Assuming 'isactive' is a column in your database
+        $existingPurchase = $PurchaseOrderModel->where($where)->first();
+    
+        if ($existingPurchase) {
+            $data['isactive'] = 0;
+            
+            if ($PurchaseOrderModel->update($purchase_order_id, $data)) {
+                session()->setFlashdata('success', 'Deleted successfully.');
+                $this->logger->info("Purchase Order: has been Inactivated successfully. Inactivated ID = ".$purchase_order_id); 
+            }
+        }
+    
+       
+        return redirect()->to('purchase_index');
+    }
+  
+ 
+
+
+    public function get_vendor($vendor_id)
+    {
+
+        $VendorModel = new VendorModel();
+
+        $products =$VendorModel->where('vendor_id',$vendor_id)->select('vendor_name,contact_person_name1,contact_person_mobile1')->get()->getRowArray(); 
+
+
+        return json_encode($products);
+
+    }
+    public function getVendorProducts()
+{
+    // Retrieve make_id and model_id from the request
+    // $makeId = $this->request->getPost('');
+    $vendorId = $this->request->getPost('vendor_id');
+
+    // Encode the modelId before searching
+    $encodedVendorId = json_encode([$vendorId]);
+
+    // Load the ProductModel
+    $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();
+
+    // print_r($product);die;
+    if($product){
+        // Send JSON response
+        return $this->response->setJSON(['product'=>$product] );
+    } else {
+        // If product is not found, return an empty response or appropriate message
+        return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]);
+    }
+}
+public function delete_purchase_product()
+{
+    $purchase_order_child_id = $this->request->getPost('purchase_order_child_id');
+    
+    if (!empty($purchase_order_child_id)) {
+        $PurchaseOrderChildModel = new PurchaseOrderChildModel();
+        $data['isactive'] = 0;
+        
+        if ($PurchaseOrderChildModel->update($purchase_order_child_id, $data)) {
+            // Return success response
+            return $this->response->setJSON(['success' => true]);
+        }
+    }
+
+    // Return error response if deletion fails
+    return $this->response->setJSON(['success' => false]);
+}
+public function download_purchase_invoice($purchase_order_id)
+{
+    // echo "hello"; die;
+    // Fetch the invoice data based on $invoice_id
+    $model = new PurchaseOrderModel();
+    $data = $model->getPurchasePdf($purchase_order_id);
+    
+ $items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
+
+    
+    
+    //  print_r($items);die();
+    
+    //  print_r($invoiceItems);die();
+
+    // Create an mPDF object
+    $mpdf = new Mpdf([
+        'mode' => '',
+        'format' => 'A5',
+        'default_font_size' => 0,
+        'default_font' => '',
+        
+        // 'margin_right' => 1,
+        'margin_top' => 6,
+        'margin_bottom' => 6,
+        'margin_header' => 6,
+        'margin_footer' =>-30,
+        'orientation' => 'P',
+    ]);
+
+   
+
+    $mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
+    // Set PDF properties 
+    $mpdf->SetTitle('Invoice');
+    $mpdf->SetAuthor($data[0]->branch_name);
+    $mpdf->SetCreator('');
+  
+  
+
+    // Generate the PDF content (HTML)
+    // if ($data[0]->status === 'Draft') {
+    //     // Set the watermark text and options
+    //     $mpdf->SetWatermarkText('Draft');
+    //     $mpdf->showWatermarkText = true;
+    // }
+    // if ($data[0]->status === 'Cancelled') {
+    //     // Set the watermark text and options
+    //     $mpdf->SetWatermarkText('Cancelled');
+    //     $mpdf->showWatermarkText = true;
+    // }
+    // if ($data[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_purchase_template', ['sales' => $data,'items'=>$items]);
+// 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');
+}
+}
\ No newline at end of file
diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index a746dc4..428e09f 100644
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -69,6 +69,7 @@ class Sales extends BaseController
 $SalesOrderModel = new SalesOrderModel(); 
 $sales=$SalesOrderModel->where('sales_order_id', $sales_order_id)->get()->getRowArray();
 $data['sales']=$sales;
+
 $VehicleModel = new VehicleModel();
 $vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$sales['vehicle_id'])
                         ->where('branch_id',$this->session->get('logged_user_branch_id'))
@@ -133,7 +134,7 @@ $VehicleModel = new VehicleModel();
         'isactive' => 1, // Assuming this is a default value or handled separately
         'branch_id'=> $this->session->get('logged_user_branch_id'),
     ];
-//  print_r($data);die;
+// print_r($data);die;
     // Insert or update sales order
     $sales_order_id = $this->request->getPost('sales_order_id');
     if (!empty($sales_order_id)) {
@@ -143,7 +144,7 @@ $VehicleModel = new VehicleModel();
         $SalesOrderModel->insert($data);
         $sales_order_id = $SalesOrderModel->getInsertID(); // Get the last inserted ID
     }
-    $orderNumber = 'SO-' . date('md') . '-' . str_pad($sales_order_id, 5, '0', STR_PAD_LEFT);
+    $orderNumber = 'SO' .  str_pad($sales_order_id, 8, '0', STR_PAD_LEFT);
 // print_r($orderNumber);die;
     // Update sales order with generated order number
     $SalesOrderModel->update($sales_order_id, ['order_number' => $orderNumber]);
diff --git a/app/Models/PurchaseOrderChildModel.php b/app/Models/PurchaseOrderChildModel.php
new file mode 100644
index 0000000..0473c36
--- /dev/null
+++ b/app/Models/PurchaseOrderChildModel.php
@@ -0,0 +1,11 @@
+select('purchase_order.*, COUNT(purchase_order_child.purchase_order_id) AS product_count,vendor.vendor_name');
+        
+        // Join the sales_order_product table based on sales_order_id
+        $this->join('purchase_order_child', 'purchase_order_child.purchase_order_id = purchase_order.purchase_order_id');
+        $this ->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id');
+        // Group by sales_order_id to get count of products per sales order
+        $this->groupBy('purchase_order.purchase_order_id');
     
+        // Add condition to fetch only active sales orders
+        $this->where('purchase_order_child.isactive', 1);
+        $this ->where('purchase_order.branch_id',$logged_user_branch_id);
+        $this->orderBy('purchase_order.purchase_order_id','DESC');
+        // Get the results
+        return $this->findAll();
+    } 
+    public function getPurchasePdf($purchase_order_id){
+        return $this->db->table('purchase_order')
+        ->where('purchase_order_id', $purchase_order_id)
+      
+        ->join('branches as B','B.branch_id = purchase_order.branch_id','left')
+        ->join('vendor as V','V.vendor_id = purchase_order.vendor_id','left')
+        ->select('purchase_order.*')
+        ->select('V.vendor_name,V.contact_person_mobile1,V.address as vendor_address,V.city as vendor_city,V.state,V.postal_code as vendor_postal,B.branch_name ,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.mobile_no as company_mobile_no')
+        
+        ->get()
+        ->getResult();
+    }
+    public function getPurchaseOrderProductsForPdf($purchase_order_id)
+    {
+        // Select required fields from the sales_order_product table
+        $result = $this->db->table('purchase_order_child')
+            ->where('purchase_order_child.purchase_order_id', $purchase_order_id)
+            ->join('products', 'products.product_id = purchase_order_child.product_id')
+            ->select('purchase_order_child.*, products.product_name')
+            ->get()
+            ->getResult();
+    
+        return $result;
+    }
+    public function getdata($logged_user_branch_id)
+    {
+        $result = $this->db->table('purchase_order')
+      
+        ->join('purchase_order_child','purchase_order_child.product_id=purchase_order_child.product_id')
+        ->join('products', 'products.product_id = purchase_order_child.product_id')
+        ->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id')
+        ->select('purchase_order_child.*,vendor.*, products.product_name')
+        ->get()
+        ->getResult();
+
+    return $result;
+    }
 }
\ No newline at end of file
diff --git a/app/Models/ReturnModel.php b/app/Models/ReturnModel.php
new file mode 100644
index 0000000..6d3d8c6
--- /dev/null
+++ b/app/Models/ReturnModel.php
@@ -0,0 +1,9 @@
+order_number) ? 'Order # ' . $value->order_number : 'Invoice # ' . $value->invoice_number; ?>
                         
                         
-                        Invoice Date : created_at)) ?>
+                        Date : created_at)) ?>
 
                         
                       
diff --git a/app/Views/invoice_purchase_template.php b/app/Views/invoice_purchase_template.php
new file mode 100644
index 0000000..c3267e4
--- /dev/null
+++ b/app/Views/invoice_purchase_template.php
@@ -0,0 +1,302 @@
+
+
+
+
+    
+
+
+    
+        
+            
+            
+        
+    
+ + + + + + + + + + +
+ THE MECHANIC + + +
+

company_address ?>,
+ company_city ?>, + company_state ?> + company_postal_code ?>.

+ +

company_mobile_no ?>

+
+
+ + + + + + + + + + + + + +
order_number) ? 'Order # ' . $value->order_number : 'Invoice # ' . $value->invoice_number; ?>
Date : created_at)) ?>
Status :status ?>
+
+ + + + + + + + + + + +
Vendor AddressShipping Address
+ + + vendor_name ?>
+ vendor_address != '' ? $value->vendor_address." ,
" : ''; ?> + vendor_city ?> + vendor_postal!=0): ?> + vendor_postal ?>
+ + contact_person_mobile1." ." ?> + + +
+ + + billing_address != '' ? $value->vendor_address." ,
" : ''; ?> + billing_city ?> + billing_postal_code!=0): ?> + billing_postal_code ?>
+ + + + +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +status === 'Approved'): ?> + + + + + +
Paid :   ₹total_amount, 2, '.', ',') ?>
+ +
+ +
+ + +
+ + +

terms_condition;?>

+ +
+ + + + + + + + + + + + + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 768947e..6a338d9 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -124,6 +124,8 @@ + + get('logged_user_role') == 'Floor Manager' || session()->get('logged_user_role') == 'Job Card Manager' || @@ -147,7 +149,7 @@ Vendor
  • - Purchase + Purchase Order
  • @@ -159,18 +161,7 @@ - - - - - -
  • - - - Make & Models - -
  • - +
  • @@ -178,10 +169,21 @@
  • + + + Reorder Level Products +
  • +
  • + + + Return Products + +
  • + @@ -209,20 +211,18 @@ - - + diff --git a/app/Views/product_form.php b/app/Views/product_form.php index 1db817f..ceb66cb 100644 --- a/app/Views/product_form.php +++ b/app/Views/product_form.php @@ -26,59 +26,62 @@
    - + + ' ?> + + + +
    +
    - - -
    + + '; ?> + +
    - - -
    -
    - - -
    + + + +
    + + +
    -
    +
    @@ -230,9 +233,9 @@ +
    + + + + + + + + + + + + - - - - - +function initializeSelect2() { + $('.SelExample').select2({ + width: '249px' // Adjust width as needed + }); + } + \ No newline at end of file + .select2-container--default .select2-selection--single .select2-selection__arrow{ + top:4px; + } + + + diff --git a/app/Views/purchase_list.php b/app/Views/purchase_list.php index 4ca0f97..c171e8e 100644 --- a/app/Views/purchase_list.php +++ b/app/Views/purchase_list.php @@ -1,4 +1,25 @@ +
    @@ -23,15 +44,18 @@ - + - - + + + + @@ -41,19 +65,32 @@ + - - - - - + + + + + + " class="edit-button" title="Edit">      + " class="delete-button" title="Delete">      + " class="edit-button" title="Download"> + + @@ -67,4 +104,52 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/app/Views/reorder_level_form.php b/app/Views/reorder_level_form.php new file mode 100644 index 0000000..7852a4a --- /dev/null +++ b/app/Views/reorder_level_form.php @@ -0,0 +1,716 @@ + + + +
    +
    +
    +
    +

    +
    " method="post"> + +

    Purchase Details :


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

    Billing Addresss :


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

    +

    Shipping Addresss :


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

    + +
    +
    +

    Item Details

    +
    + +
    Order Number Vendor Name Order DateContact Person NameContact Person MobileContact Person DetailsQuantityStatus Actions
    %%%
    + +
    + + - " class="edit-button"> - " - class="delete-button"> -
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Item DetailsQtyRateTaxAmount
    + + + + + + + + + + +
    +
    + + + +
    +
    +
    +
    +
    +

    Calculation

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

    Terms & Condition :


    +
    +
    + + + + + +
    +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/reorder_level_list.php b/app/Views/reorder_level_list.php index 69aa925..af458bd 100644 --- a/app/Views/reorder_level_list.php +++ b/app/Views/reorder_level_list.php @@ -42,13 +42,15 @@ + - - + + " class="edit-button">Rise + diff --git a/app/Views/return_list.php b/app/Views/return_list.php new file mode 100644 index 0000000..6ca6ecd --- /dev/null +++ b/app/Views/return_list.php @@ -0,0 +1,129 @@ + + +
    +
    +
    +
    +

    Return Order List

    + +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Order NumberVendor NameOrder DateContact Person DetailsQuantityStatusActions
    +
    + +
    +
    +
    + +
    + + \ No newline at end of file diff --git a/app/Views/return_order_form.php b/app/Views/return_order_form.php new file mode 100644 index 0000000..c683f97 --- /dev/null +++ b/app/Views/return_order_form.php @@ -0,0 +1,555 @@ + + + +
    +
    +
    +
    +

    +
    " method="post"> + +

    Purchase Details :


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

    Billing Addresss :


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

    +

    Shipping Addresss :


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

    + +
    +
    +

    Item Details

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Item DetailsQtyReturned
    + + + + + + > + + > + + > + +
    +
    + + + + + +
    +
    + +

    Terms & Condition :


    +
    +
    + + + + + +
    +
    + + + + +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + diff --git a/app/Views/return_order_liist.php b/app/Views/return_order_liist.php new file mode 100644 index 0000000..5484025 --- /dev/null +++ b/app/Views/return_order_liist.php @@ -0,0 +1,155 @@ + + +
    +
    +
    +
    +

    Return Order List

    +
    + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Order NumberVendor NameOrder DateContact Person DetailsQuantityStatusActions

    + +
    + + + " class="edit-button" title="Return">      + " class="delete-button" title="Delete">      + " class="edit-button" title="Download"> +
    +
    + +
    +
    +
    + +
    + + \ No newline at end of file diff --git a/app/Views/sales_list.php b/app/Views/sales_list.php index 8b81ebb..214b0a9 100644 --- a/app/Views/sales_list.php +++ b/app/Views/sales_list.php @@ -8,6 +8,18 @@ .dataTables_wrapper .dt-buttons{ float:left; } + .cancelled-status { + color: red; +} + +.created-status { + color: blue; +} + +.paid-status { + color: green; +} +
    @@ -42,10 +54,9 @@ Order Number Reg No Client Name - Client Mobile + Quantity - Subtotal - Tax + Total Status Actions @@ -64,19 +75,28 @@ - + - - + - - - " class="edit-button"> - - " class="edit-button"> - - " class="delete-button"> - + + + + + + " class="edit-button" title="Edit">      + " class="delete-button" title="Delete">      + " class="edit-button" title="Download"> + + diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 6a238cd..62ad729 100644 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -28,7 +28,7 @@ ' ?> - > Select a vehicle' ?> @@ -55,23 +55,27 @@
    - - + + - - + + + - + - - - + + + -
    +

    @@ -141,7 +145,7 @@ - + @@ -225,7 +229,7 @@ - + @@ -345,51 +349,77 @@ productarray = []; $(document).ready(function() { + // Function to fetch make and model information based on make and model IDs + function fetchMakeAndModel(makeId, modelId) { + // Make sure makeId and modelId are valid + if (makeId !== '' && modelId !== '') { + // Perform AJAX request to fetch product information + $.ajax({ + url: '', // Replace with the actual backend endpoint + method: 'POST', // or 'GET' based on your server implementation + dataType: 'json', + data: { + make_id: makeId, + model_id: modelId + }, + success: function(response) { + console.log(response); + // Populate make and model in the input field + var makeAndModel = response.makeName + ' ' + response.modelName; + $('#makeAndModel').val(makeAndModel); + + console.log(response); + productarray = response.product; + + + }, + error: function(xhr, status, error) { + // Handle error + console.error('Error fetching product information:', error); + } + }); + } else { + console.error('Make ID or Model ID not found for the selected vehicle'); + } + } + // Event listener for vehicle selection change $('.vehicle-select').change(function() { var vehicleId = $(this).val(); - + if (vehicleId !== '') { // Find the selected vehicle var selectedVehicle = vehicles.find(function(vehicle) { return vehicle.vehicle_id == vehicleId; }); - - // Extract makeId from the selected vehicle + + // Extract makeId and modelId from the selected vehicle var makeId = selectedVehicle.make; var modelId = selectedVehicle.model; - console.log(modelId); - - // Make sure makeId exists - if (makeId !== undefined) { - // Perform AJAX request to fetch product information - $.ajax({ - url: '', // Replace with the actual backend endpoint - method: 'POST', // or 'GET' based on your server implementation - dataType: 'json', - data: { - make_id: makeId, - model_id:modelId, - vehicle_id: vehicleId - }, - success: function(response) { - console.log(response); - productarray = response.product; - makeAndModel = response.makeName+' '+response.modelName; - $('#makeAndModel').val(makeAndModel); - }, - error: function(xhr, status, error) { - // Handle error - console.error('Error fetching product information:', error); - } - }); - } else { - console.error('Make ID not found for the selected vehicle'); - } + + // Fetch make and model information + fetchMakeAndModel(makeId, modelId); } }); + + // Edit scenario: Populate make and model based on stored vehicle ID + var storedVehicleId = ""; + if (storedVehicleId !== '') { + // Find the selected vehicle from the vehicles array + var selectedVehicle = vehicles.find(function(vehicle) { + return vehicle.vehicle_id == storedVehicleId; + }); + + // Extract makeId and modelId from the selected vehicle + var makeId = selectedVehicle.make; + var modelId = selectedVehicle.model; + + // Fetch make and model information + fetchMakeAndModel(makeId, modelId); + } }); + @@ -416,10 +446,7 @@ $(document).ready(function() { // Function to calculate amount based on rate and quantity function calculateAmount(row) { - var rate = $(row).find('.item-rate').val(); - var quantity = $(row).find('.item-quantity').val(); - var amount = rate * quantity; - $(row).find('.item-amount').val(amount); + // Retrieve CGST and SGST values from the database for the selected product var productId = $(row).find('select[name="item_details[]"]').val(); @@ -432,12 +459,22 @@ $(document).ready(function() { // Calculate total tax by adding CGST and SGST var tax = cgst + sgst; $(row).find('.item-tax').val(tax.toFixed(2)); + var rate = $(row).find('.item-rate').val(); + var quantity = $(row).find('.item-quantity').val(); + + var amount = rate * quantity; + console.log(amount); + var taxamount = amount * tax/100; + var finalamt=amount + taxamount; + console.log("samount".samount); + $(row).find('.item-amount').val(finalamt); } // Event listener for product selection $(document).on('change', 'select[name="item_details[]"]', function() { var productId = $(this).val(); - var quantity = $(this).closest('tr').find('.item-quantity').val(0); + var quantity = $(this).closest('tr').find('.item-quantity').val(1); + // Find product details from JSON var product = products.find(function(item) { @@ -450,6 +487,7 @@ $(document).ready(function() { // Calculate amount and update amount input field calculateAmount($(this).closest('tr')); + updateCalculations(); }); // Event listener for quantity change @@ -472,11 +510,18 @@ $(document).ready(function() { var tax = 0; $('.item-tax').each(function() { - var taxPercentage = parseFloat($(this).val()) || 0; - var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0; - var taxValue = (taxPercentage / 100) * amount; // Convert percentage to absolute value - tax += taxValue; - }); + var taxPercentage = parseFloat($(this).val()) || 0; + // console.log(taxPercentage); + var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0; + // console.log(amount); + var qty=parseFloat($(this).closest('tr').find('.item-quantity').val()) || 0; + // console.log(qty); + var rate=parseFloat($(this).closest('tr').find('.item-rate').val()) || 0; + var taxamount=rate * qty; + // console.log(taxamount); + var taxValue = (taxPercentage / 100) * taxamount; // Convert percentage to absolute value + tax += taxValue; + }); return tax; } @@ -502,9 +547,9 @@ $(document).ready(function() { // Function to calculate total function calculateTotal() { var subtotal = calculateSubtotal(); - var tax = calculateTax(); + var discount = calculateDiscount(); - var total = subtotal + tax - discount; + var total = subtotal - discount; // return total; return Math.round(total); } @@ -548,7 +593,8 @@ $(document).ready(function() { $('#itemTable tbody').append(newRow); initializeSelect2(); - + updateCalculations(); + initializeRowCalculations(row); }); @@ -559,6 +605,10 @@ $(document).ready(function() { }); }); +function initializeRowCalculations(row) { + calculateAmount(row); + updateCalculations(); +} @@ -782,6 +832,7 @@ document.getElementById('reg_no').addEventListener('input', function(event) { $('#formType').val('create'); $('#clientName').val(''); + // $('.select2-selection__rendered').html(''); $('#clientMobile').val(''); @@ -815,4 +866,11 @@ document.getElementById('reg_no').addEventListener('input', function(event) { .select2-container--default .select2-selection--single .select2-selection__arrow{ top:4px; } - \ No newline at end of file + + \ No newline at end of file diff --git a/app/Views/vehicle_form.php b/app/Views/vehicle_form.php index db18049..6ea4495 100644 --- a/app/Views/vehicle_form.php +++ b/app/Views/vehicle_form.php @@ -23,7 +23,8 @@

    Vehicle Details :

    - + + ' ?>
    - + + ' ?> - +
    @@ -249,6 +251,10 @@ $(document).ready(function() { // Event listener for change in make select dropdown $("#make").on('change', function() { var selected_makes = $(this).val(); // Get an array of selected make IDs + make_value = $('option:selected', this).text(); + $('#makeSelect').empty(); + $('#makeSelect').append(''); + $('#makeSelectMessage').hide(); // AJAX request to fetch models based on selected make IDs $.ajax({ url: '', // URL to your controller method for fetching models @@ -316,7 +322,8 @@ $(document).ready(function() { console.log(response.clientData); $("#clientData").append(''); // Manually select the newly added option - $("#clientData").val(response.clientData.client_id).trigger('change'); + $("#clientData").val(response.clientData.client_id); + $('input[name="mobile_no"]').val(response.clientData.mobile_no); } else { // Client save operation failed, display error message toastr.warning("Failed to save client. Please try again"); @@ -384,7 +391,8 @@ function populateMakeDropdown() { type: 'GET', dataType: 'json', success: function(response) { - $('#makeSelect').empty().append(''); + $('#makeSelect').empty(); + $('#makeSelect').append(''); response.forEach(function(make) { $('#makeSelect').append(''); }); @@ -397,7 +405,7 @@ function populateMakeDropdown() { // Call the function to populate make dropdown initially $(document).ready(function() { - populateMakeDropdown(); + //populateMakeDropdown(); }); // Save model function @@ -417,7 +425,7 @@ console.log(model); if (response.success) { $('#addModelModal').modal('hide'); toastr.success("Model saved successfully"); - window.location.reload(); + $('#model').append(''); } else { toastr.error("Failed to save model"); } diff --git a/app/Views/vendor_form.php b/app/Views/vendor_form.php index bd643c5..299fca6 100644 --- a/app/Views/vendor_form.php +++ b/app/Views/vendor_form.php @@ -39,12 +39,12 @@
    -
    +
    -
    +
    -
    +