From 236505cbf9fd229539e4e2031af3b08833c46848 Mon Sep 17 00:00:00 2001 From: heama Date: Sat, 6 Apr 2024 18:19:53 +0530 Subject: [PATCH] product-client-sales --- app/Config/Routes.php | 7 ++ app/Controllers/Client.php | 2 +- app/Controllers/Sales.php | 38 +++++++++- app/Controllers/Vendor.php | 109 +++++++++++++++++++++++++++ app/Models/VendorModel.php | 2 +- app/Views/client_form.php | 13 ++-- app/Views/invoice_pdf_template.php | 34 +++++---- app/Views/layout/header.php | 5 +- app/Views/sales_order_form.php | 115 ++++++++++++++++++++++++----- app/Views/vendor_form.php | 89 ++++++++++++++++++++++ app/Views/vendor_list.php | 72 ++++++++++++++++++ 11 files changed, 441 insertions(+), 45 deletions(-) create mode 100644 app/Controllers/Vendor.php create mode 100644 app/Views/vendor_form.php create mode 100644 app/Views/vendor_list.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 2a491a7..0ddab8a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -48,6 +48,7 @@ $routes->get("new_sale/(:any)", "Sales::new_sale/$1"); $routes->get("delete_sale/(:any)", "Sales::delete_sale/$1"); $routes->post("delete_sales_product", "Sales::delete_sales_product"); $routes->get("download_invoice/(:any)", "Sales::download_invoice/$1"); +$routes->post("save_client", "Sales::save_client"); //end salle order// //Client// @@ -56,6 +57,12 @@ $routes->post("add_client", "Client::add_client"); $routes->get("new_client/(:any)", "Client::new_client/$1"); $routes->get("delete_client/(:any)", "Client::delete_client/$1"); //end clent +//Vendor// +$routes->get('vendor_index/', 'Vendor::vendor_index'); +$routes->post("add_vendor", "Vendor::add_vendor"); +$routes->get("new_vendor/(:any)", "Vendor::new_vendor/$1"); +$routes->get("delete_vendor/(:any)", "Vendor::delete_vendor/$1"); +//end Vendor //Vehicle// $routes->get('vehicle_index/', 'Vehicle::vehicle_index'); diff --git a/app/Controllers/Client.php b/app/Controllers/Client.php index a971e4d..13c171b 100644 --- a/app/Controllers/Client.php +++ b/app/Controllers/Client.php @@ -65,7 +65,7 @@ class Client extends BaseController 'city' => $this->request->getPost('city'), 'state' => $this->request->getPost('state'), 'postal_code' => $this->request->getPost('postalcode'), - 'country' => $this->request->getPost('country'), + 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id') ]; diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 9bb3ae2..5fb89fe 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -84,7 +84,7 @@ $data['product']=$product; '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'), + // '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'), @@ -273,12 +273,46 @@ public function delete_sales_product() // Generate the PDF content (HTML) with data $html = view('invoice_pdf_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 save_client(){ + // Load ClientModel + $ClientModel = new ClientModel(); + + // Validate inputs + $validationRules = [ + 'client_name' => 'required|max_length[100]', + 'mobile_no' => 'required' // Assuming mobile number is 10 digits long + ]; + + if (!$this->validate($validationRules)) { + // If validation fails, return validation errors + return $this->response->setJSON(['success' => false, 'errors' => $this->validator->getErrors()]); + } + + // If validation passes, proceed to save the client + $data = [ + 'client_name' => $this->request->getPost('client_name'), + 'mobile_no' => $this->request->getPost('mobile_no'), + 'branch_id'=> $this->session->get('logged_user_branch_id'), + 'city'=>'Chennai', + 'state'=>'Tamil Nadu', + 'isactive' => 1 + ]; + + // Attempt to insert the client data + if ($ClientModel->insert($data)) { + // If insertion succeeds, return success response + return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']); + } else { + // If insertion fails, return error response + return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']); + } + } } \ No newline at end of file diff --git a/app/Controllers/Vendor.php b/app/Controllers/Vendor.php new file mode 100644 index 0000000..14aed1d --- /dev/null +++ b/app/Controllers/Vendor.php @@ -0,0 +1,109 @@ +session = session(); + $this->UsersModel = new UsersModel(); + } + + public function vendor_index() + { + // print_r("hi");die; + $VendorModel = new VendorModel(); + $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); + $data['vendor']=$vendor; + + return view('vendor_list',$data); + } + + + public function new_vendor($vendor_id) + { + + + if ($vendor_id === '0') { + + $data['vendor'] = []; + $data['page_name']="Add Vendor"; + } else if ($vendor_id !== '0') { + $data['page_name']="Edit Vendor"; + $VendorModel = new VendorModel(); + + $vendor=$VendorModel->where('vendor_id', $vendor_id)->get()->getRowArray(); + + $data['vendor']=$vendor; + } + $data['vendor_id'] = $vendor_id; + + return view('vendor_form',$data); + } + + + public function add_vendor() + { + + $VendorModel = new VendorModel(); + + + $data = [ + 'vendor_name' => $this->request->getPost('vendor_name'), + 'vendor_email' => $this->request->getPost('email'), + 'address' => $this->request->getPost('address'), + 'vendor_mobile' => $this->request->getPost('mobile'), + 'city' => $this->request->getPost('city'), + 'state' => $this->request->getPost('state'), + 'postal_code' => $this->request->getPost('postalcode'), + 'country' => $this->request->getPost('country'), + 'category' => $this->request->getPost('category'), + 'website' => $this->request->getPost('website'), + 'isactive' => 1 , + 'branch_id' => $this->session->get('logged_user_branch_id') + ]; + // print_r($data);die; + + $vendor_id = $this->request->getPost('vendor_id'); + + + if (!empty($vendor_id)) { + + $VendorModel->update($vendor_id, $data); + } else { + + $VendorModel->insert($data); + } + + + return redirect()->to('vendor_index'); + } + public function delete_vendor($vendor_id) + { + $model = new VendorModel(); + $where = ['vendor_id' => $vendor_id, 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id')]; // Assuming 'isactive' is a column in your database + $existingBusiness = $model->where($where)->first(); + + if ($existingBusiness) { + $data['isactive'] = 0; + + if ($model->update($vendor_id, $data)) { + session()->setFlashdata('success', 'Deleted successfully.'); + $this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$vendor_id); + } + } + + + return redirect()->to('vendor_index'); + } + +} \ No newline at end of file diff --git a/app/Models/VendorModel.php b/app/Models/VendorModel.php index cc79be0..13549f9 100644 --- a/app/Models/VendorModel.php +++ b/app/Models/VendorModel.php @@ -5,7 +5,7 @@ class VendorModel extends Model { protected $table = 'vendor'; protected $primaryKey = 'vendor_id'; - protected $allowedFields = ['vendor_id','vendor_name','vendor_email','vendor_mobile','website','gl_account','category','address','state','posta_code','city','country','description','isactive']; + protected $allowedFields = ['vendor_id','branch_id','vendor_name','vendor_email','vendor_mobile','website','gl_account','category','address','state','posta_code','city','country','description','isactive']; } \ No newline at end of file diff --git a/app/Views/client_form.php b/app/Views/client_form.php index 0e07428..cb19780 100644 --- a/app/Views/client_form.php +++ b/app/Views/client_form.php @@ -47,17 +47,14 @@
- +
-
+
- +
-
- - -
-
+ +
diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index 6b772fa..a331c52 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -145,9 +145,10 @@ p { - + + THE MECHANIC - THE MECHANIC + @@ -187,13 +188,14 @@ p { + client_name ?>
- address." ," ?>
- city ?> state?> - billing_postal_code ." - "?> - billing_country ? $value->billing_country . "." : $value->billing_country ?>
- + billing_address != '' ? $value->billing_address." ,
" : ''; ?> + billing_city ?> billing_state." "?> + billing_postal_code!=0): ?> + billing_postal_code ?>
+ mobile_no." ." ?> @@ -210,8 +212,9 @@ p { S.no Item Name - Rate + MRP Qty + Discount Total @@ -227,7 +230,7 @@ p { product_name ?> ₹net_price, 2, '.', ',') ?> qty ?> - + discount_type == '₹' ? $item->discount_type.$item->discount : $item->discount.$item->discount_type; ?> ₹amount, 2, '.', ',') ?> @@ -273,11 +276,14 @@ p {
-

Thank you!

- - + + discount!=0): ?> +

"You have saved ₹discount; ?>- in this purchase"


+ + + +

terms_condition;?>

+
diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index e1aa20b..42c1ddc 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -2,7 +2,7 @@ - Mechanics + Mechanic @@ -116,6 +116,9 @@
  • Sales Order
  • +
    diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 061eae3..a823b64 100644 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -26,6 +26,8 @@
    + + + +
    - - + +
    - - -
    -
    - - -
    -
    - - + +
    -
    +
    + + +
    + +
    @@ -195,8 +194,10 @@ - + +
    @@ -210,6 +211,35 @@
    + + + + + + + + +