diff --git a/.gitignore b/.gitignore index b8349ab..bb04af6 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /writable -/vendor +vendor/* .env +!vendor/.gitkeep +composer.lock \ No newline at end of file diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 273690e..b324ad7 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -76,6 +76,7 @@ $routes->post('status_product', 'Products::status_product'); $routes->get('delete_product_name/(:any)', 'Products::delete_product_name/$1'); $routes->get('get_product_addtional_details/(:any)', 'Products::get_product_addtional_details/$1'); $routes->get('product_categories', 'Products::product_categories'); +$routes->post('quick_add', 'Products::quick_add'); //end products// //Sales order // @@ -247,4 +248,16 @@ $routes->get('product_category_index', 'ProductCategory::index'); $routes->post('create_product_category/(:any)', 'ProductCategory::create_product_category/$1'); $routes->post('status_product_category', 'ProductCategory::status_product_category'); -// product category End's // \ No newline at end of file +// product category End's // + +//Invoice // +$routes->group('invoices', ['namespace' => 'App\Controllers'], function($routes) { + $routes->get('/', 'Invoice::invoices_order_index'); + $routes->get('new/(:any)', 'Invoice::new_invoice/$1'); + $routes->post('save', 'Invoice::add_invoices'); + $routes->get('delete/(:any)', 'Invoice::delete_invoice/$1'); + $routes->post('delete/child', 'Invoice::delete_invoice_child'); + $routes->get('download/(:any)', 'Invoice::download_invoice/$1'); + $routes->get('preview/(:any)', 'Invoice::preview_invoice/$1'); + $routes->post('products', 'Invoice::get_invoice_product'); +}); diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php new file mode 100755 index 0000000..ad8443b --- /dev/null +++ b/app/Controllers/Invoice.php @@ -0,0 +1,543 @@ +session = session(); + $this->BikemodelsModel = new BikemodelsModel(); + $this->BikemakeModel = new BikemakeModel(); + $this->additionalProductNameModal = new AdditionalProductNameModal(); + + $this->ProductModel = new ProductModel(); + $this->ClientModel = new ClientModel(); + $this->VehicleModel = new VehicleModel(); + $this->BranchModel = new BranchModel(); + } + + //for List. + public function invoices_order_index() + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + $InvoiceModel = new InvoiceModel(); + $data['invoices'] = $InvoiceModel->getInvoicesWithProducts($this->session->get('logged_user_branch_id')); + return view('invoice_list',$data); + } + + // Add and Edit data auto fetch. + public function new_invoice($invoice_id) + { + if (!$this->session->has('logged_user')) { + return redirect()->to(base_url()); + } + + $InvoiceModel = new InvoiceModel(); + $ManufacturerModel = new ManufacturerModel(); + $ProductCategoryModel = new ProductCategoryModel(); + $ComplaintModel = new ComplaintModel(); + $InvoiceChildModel = new InvoiceChildModel(); + + $data = [ + 'invoice_id' => $invoice_id, + 'invoice' => [], + 'invoice_child' => [], + 'makeData' => $this->BikemakeModel->findAll(), + 'capacity' => $ComplaintModel->getCubicCapacityName(), + 'productcategory' => $ProductCategoryModel->orderBy('product_category_id')->findAll(), + 'manufacturers' => $ManufacturerModel + ->where('business_id', $this->session->get('logged_user_business_id')) + ->orderBy('manufacturer_name') + ->findAll(), + 'client' => $this->ClientModel->where('isactive', 1) + ->where('branch_id', $this->session->get('logged_user_branch_id')) + ->findAll(), + 'vehicle' => $this->VehicleModel->where('isactive', 1) + ->where('branch_id', $this->session->get('logged_user_branch_id')) + ->findAll(), + 'product' => $this->ProductModel->where('products.isactive', 1) + ->where('products.branch_id', $this->session->get('logged_user_branch_id')) + ->findAll(), + ]; + + if ($invoice_id === '0') { + $data['page_name'] = "Create Invoice"; + $data['vehicle'] = $this->VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id')); + } else { + $data['page_name'] = "Edit Invoice"; + $data['invoice'] = $InvoiceModel->where('invoice_id', $invoice_id)->get()->getRowArray(); + $data['invoice_child'] = $InvoiceChildModel->where('invoice_id', $invoice_id)->findAll(); + } + + return view('invoice_form', $data); + } + + // Insert and Update Invoice Details. + public function add_invoices() + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + $InvoiceModel = new InvoiceModel(); + $InvoiceChildModel = new InvoiceChildModel(); + + $status = $this->request->getPost('status') != '' ? $this->request->getPost('status') : 'Draft'; + + $data = [ + 'type' => $this->request->getPost('type'), + 'client_id' => $this->request->getPost('client_id'), + 'client_name' => $this->request->getPost('client_name'), + 'vehicle_id'=>$this->request->getPost('vehicle_id'), + 'vehicle_reg_no'=>$this->request->getPost('vehicle_reg_no'), + 'billing_address' => $this->request->getPost('billing_address'), + 'billing_city' => $this->request->getPost('city'), + 'mobile_no' => $this->request->getPost('mobile_no'), + 'email' => $this->request->getPost('email'), + 'billing_country' => $this->request->getPost('country'), + 'billing_state' => $this->request->getPost('state'), + 'billing_postal_code' => $this->request->getPost('postalcode'), + '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'=> $status, + 'isactive' => 1, + 'branch_id'=> $this->session->get('logged_user_branch_id'), + ]; + + + // Based on invoice_id Insert or update. + $invoice_id = $this->request->getPost('invoice_id'); + if (!empty($invoice_id)) { + if ($status === "Approved") { + $data['mode_of_payment'] = $this->request->getPost('mode_of_payment'); + } + $InvoiceModel->update($invoice_id, $data); + } else { + $data['invoice_date'] = date('Y-m-d'); + $InvoiceModel->insert($data); + $invoice_id = $InvoiceModel->getInsertID(); + // $invoice_number ='INV'.'-'.date('md').str_pad($invoice_id, 5, '0', STR_PAD_LEFT); + $invoice_number = date('Y') . '/' . date('md') . str_pad($invoice_id, 5, '0', STR_PAD_LEFT); + $InvoiceModel->update($invoice_id, ['invoice_number' => $invoice_number]); + } + + // 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'); + $invoice_child_id = $this->request->getPost('invoice_child_id'); + // $labour_cost = $this->request->getPost('labour_cost'); + + foreach ($product_ids as $key => $product_id) + { + + $qty = isset($quantities[$key]) ? $quantities[$key] : 0; + if ($status == 'Approved') { + $this->subractProductQuantity( $product_id, $qty); + }elseif ($status == 'Cancelled'){ + // $this->addBackProductQuantity( $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( $product_id, $qty); + // print_r($discount_type);die; + $invoice_child_data = [ + 'invoice_id' => $invoice_id, + 'product_id' => $product_id, + 'qty' => $qty, + 'discount' => $discount, + 'discount_type' => $discount_type, + 'net_price'=>$rate, + 'tax'=>$tax, + 'amount' => $amount, + // 'labour_cost' => $labour_cost, + 'isactive'=>1, + ]; + + // print_r($invoice_child_data);die; + if (!empty($invoice_child_id[$key])) { + $InvoiceChildModel->update($invoice_child_id[$key], $invoice_child_data); + } else { + $InvoiceChildModel->insert($invoice_child_data); + } + } + + return redirect()->to('invoices'); + } + + private function addBackProductQuantity($product_id, $sold_qty) + { + // Fetch current product quantity + $product = $this->ProductModel->find($product_id); + + $data['qty_stock'] = $product['qty_stock'] + $sold_qty; + + if($product['per'] == 'barrel') + { + $data['barrel'] = $data['qty_stock'] / $product['ltr_per_barrel']; + } + else if($product['per'] == 'box') + { + $data['box'] = $data['qty_stock'] / $product['qty_per_box']; + } + + // Update quantity in Product table + $this->ProductModel->update($product_id, $data ); + } + + private function subractProductQuantity( $product_id, $sold_qty) + { + + // Fetch current product quantity + $product = $this->ProductModel->find($product_id); + + $data['qty_stock'] = $product['qty_stock'] - $sold_qty; + + if($product['per'] == 'barrel') + { + $data['barrel'] = $data['qty_stock'] / $product['ltr_per_barrel']; + } + else if($product['per'] == 'box') + { + $data['box'] = $data['qty_stock'] / $product['qty_per_box']; + } + + // Update quantity in Product table + $this->ProductModel->update($product_id, $data ); + } + + public function delete_invoice_child() + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + $InvoiceChildModel = new InvoiceChildModel(); + $invoice_child_id = $this->request->getPost('invoice_child_id'); + + if (!empty($invoice_child_id)) { + $data['isactive'] = 0; + + if ($InvoiceChildModel->update($invoice_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 delete_invoice($invoice_id) + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + $InvoiceModel = new InvoiceModel(); + $InvoiceChildModel = new InvoiceChildModel(); + + $where = ['invoice_id' => $invoice_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database + $existing = $InvoiceModel->where($where)->first(); + $existingChild = $InvoiceChildModel->where($where)->first(); + + if ($existing) { + $data['isactive'] = 0; + if($existingChild){ $InvoiceChildModel->update($invoice_id, $data); } + if($InvoiceModel->update($invoice_id, $data)) { + session()->setFlashdata('success', 'Deleted successfully.'); + $this->logger->info("Invoice: has been Inactivated successfully. Inactivated ID = ".$invoice_id); + } + } + + return redirect()->to('invoices'); + } + + + public function download_invoice($invoice_id) + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + // Fetch the invoice data based on $invoice_id + $InvoiceModel = new InvoiceModel(); + $InvoiceChildModel = new InvoiceChildModel(); + + $saleOrderCount = count($InvoiceModel->where('status','Approved')->findAll()); + + + + $data['invoice'] = $InvoiceModel->getInvoicesPdf($invoice_id); + $data['branch'] = $this->BranchModel->where('branch_id', $data['invoice'][0]->branch_id)->first(); + $data['vehicle'] = $this->VehicleModel->select('vehicle.reg_no,vehicle.colour,vehicle.email,vehicle.mobile_no,vehicle.year_of_manufacturing, make.make as make_name, model.model_name') + ->join('model', 'model.model_id = vehicle.model', 'left') + ->join('make', 'make.make_id = vehicle.make', 'left') + ->where('vehicle.vehicle_id', $data['invoice'][0]->vehicle_id) + ->first(); + $data['invoice_child'] = $InvoiceModel->getInvoiceProductsForPdf($invoice_id); + + $mpdf = new Mpdf([ + 'mode' => '', + 'format' => 'A4', + '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['invoice'][0]->branch_name); + $mpdf->SetCreator(''); + + // Generate the PDF content (HTML) + if ($data['invoice'][0]->status === 'Draft') { + $mpdf->SetWatermarkText('Draft'); + $mpdf->showWatermarkText = true; + } + if ($data['invoice'][0]->status === 'Cancelled') { + $mpdf->SetWatermarkText('Cancelled'); + $mpdf->showWatermarkText = true; + } + + + // Generate the PDF content (HTML) with data + $html = view('invoice_pdf_layout', $data); + $mpdf->WriteHTML($html); + date_default_timezone_set('Asia/Kolkata'); + $mpdf->Output($data['invoice'][0]->invoice_number .'_' . date('Y-m-d H-i-s') . '.pdf', 'D'); + } + + + public function preview_invoice($inv_id) + { + + + $InvoiceModel = new InvoiceModel(); + $InvoiceChildModel = new InvoiceChildModel(); + // Fetch the invoice data based on $invoice_id + + $saleOrderCount = count($InvoiceModel->where('status','Approved')->findAll()); + + + + $data['invoice'] = $InvoiceModel->getInvoicesPdf($inv_id); + $data['branch'] = $this->BranchModel->where('branch_id', $data['invoice'][0]->branch_id)->first(); + $data['vehicle'] = $this->VehicleModel->select('vehicle.reg_no,vehicle.colour,vehicle.email,vehicle.mobile_no,vehicle.year_of_manufacturing, make.make as make_name, model.model_name') + ->join('model', 'model.model_id = vehicle.model', 'left') + ->join('make', 'make.make_id = vehicle.make', 'left') + ->where('vehicle.vehicle_id', $data['invoice'][0]->vehicle_id) + ->first(); + $data['invoice_child'] = $InvoiceModel->getInvoiceProductsForPdf($inv_id); + + $html = view('invoice_pdf_layout', $data); + return $this->respond(['status' => 'success','code' => 200,'data' => $html],200); + } + + + public function save_vehicle(){ + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + + if($this->request->getPost('formType') == 'create') + { + $client['client_name'] = $this->request->getPost('createclientName'); + $client['mobile_no'] = $this->request->getPost('createclientMobile'); + $client['client_type'] = $this->request->getPost('createclientType'); + $client['branch_id'] = $this->session->get('logged_user_branch_id'); + $client['isactive'] = 1; + $client['created_by'] = (int)$this->session->get('logged_user'); + $existingClient1 = $this->ClientModel->where('client_name', $client['client_name'])->first(); + if ($existingClient1) { + return $this->response->setJSON([ + 'success' => true, 'code' => 404,'field'=>'create-clientName', + 'message' => 'The client name is already registered. Please use a different Name.' + ]); + } + $existingClient2 = $this->ClientModel->where('mobile_no', $client['mobile_no'])->first(); + if ($existingClient2) { + return $this->response->setJSON([ + 'success' => true,'code' => 404,'field'=>'create-clientMobile', + 'message' => 'The mobile number is already registered. Please use a different number.' + ]); + } + + + + $client_id = $this->ClientModel->insert($client); + + if($client_id){ + + $data = [ + 'client_id' => $client_id, + 'mobile_no' => $this->request->getPost('createclientMobile'), + 'reg_no' => $this->request->getPost('reg_no'), + 'model' => $this->request->getPost('model'), + 'make' => $this->request->getPost('make'), + 'branch_id'=> $this->session->get('logged_user_branch_id'), + 'city'=>'Chennai', + 'state'=>'Tamil Nadu', + 'isactive' => 1, + 'created_by' => (int)$this->session->get('logged_user') + ]; + + } + + + }else{ + + $data = [ + 'client_id' => $this->request->getPost('client_id'), + 'mobile_no' => $this->request->getPost('mobile_no'), + 'reg_no' => $this->request->getPost('reg_no'), + 'model' => $this->request->getPost('model'), + 'make' => $this->request->getPost('make'), + 'branch_id'=> $this->session->get('logged_user_branch_id'), + 'city'=>'Chennai', + 'state'=>'Tamil Nadu', + 'isactive' => 1, + 'created_by' => (int)$this->session->get('logged_user') + ]; + + + } + + // Attempt to insert the client data + $id = $this->VehicleModel->insert($data); + if ($id) { + $vehicleData = $this->VehicleModel->where('vehicle_id',$id)->first(); + // If insertion succeeds, return success response + return $this->response->setJSON(['success' => true,'code' => 200, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData, 'vehicle_id' => $id]); + } else { + // If insertion fails, return error response + return $this->response->setJSON(['success' => false, 'code' => 404,'message' => 'Failed to save client.']); + } + } + + public function get_vehicle_products(){ + + } + + public function get_invoice_product() + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + // Retrieve make_id and model_id from the request + $makeId = $this->request->getPost('make_id'); + $modelId = $this->request->getPost('model_id'); + + + $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name; + $makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make; + + $product = $this->ProductModel->select('products.*') + ->where('products.isactive', 1) + ->findAll(); + + if($product){ + // Send JSON response + return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] ); + } else { + // If product is not found, return an empty response or appropriate message + return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]); + } + } + + + + public function getProducts_old() + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + // Retrieve make_id and model_id from the request + $makeId = $this->request->getPost('make_id'); + $modelId = $this->request->getPost('model_id'); + + // Encode the modelId before searching + $encodedMakeId = json_encode([$makeId]); + $encodedModelId = json_encode([$modelId]); + + + // Query the database to find the product based on make_id and model_id + $makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name') + ->join('products', 'products.product_id = product_names.product_id') + ->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('products.isactive', 1) + ->findAll(); + + $encodedMakeId = json_encode(['0']); + $encodedModelId = json_encode(['0']); + + $common_product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name') + ->join('products', 'products.product_id = product_names.product_id') + ->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('products.isactive', 1) + ->findAll(); + + $product = array_merge($common_product, $makeproduct); + + + $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name; + $makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make; + if($product){ + // Send JSON response + return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] ); + } else { + // If product is not found, return an empty response or appropriate message + return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]); + } + } + // Check if product exists + +} \ No newline at end of file diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 41e9b7b..824fa21 100755 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -646,5 +646,73 @@ class Products extends BaseController return json_encode($data); } - + + public function quick_add() + { + + $tax = floatval($this->request->getPost('tax')) / 2; + $bid = $this->session->get('logged_user_branch_id'); + + $ml = 0; + $box = 0; + $qty_per_box = 0; + $barrel = 0; + $ltr_per_barrel = 0; + + $per = $this->request->getPost('per'); + if ($per === 'ml') { + $ml = floatval($this->request->getPost('ml') ?? 0); + } elseif ($per === 'box') { + $box = floatval($this->request->getPost('box') ?? 0); + $qty_per_box = floatval($this->request->getPost('qty_per_box') ?? 0); + } elseif ($per === 'barrel') { + $barrel = floatval($this->request->getPost('barrel') ?? 0); + $ltr_per_barrel = floatval($this->request->getPost('ltr_per_barrel') ?? 0); + } + + $data = [ + 'cubic_centimeter_id' => json_encode($this->request->getPost('cubic_centimeter_id')), + 'product_name' => $this->request->getPost('productname'), + 'product_category' => $this->request->getPost('productcategory'), + 'total_amount' => $this->request->getPost('total_amount'), + 'unit_price' => $this->request->getPost('unit_price'), + 'qty_stock' => $this->request->getPost('qty_stock'), + 'sgst' => $tax, + 'cgst' => $tax, + 'per' => $per, + 'ml' => $ml, + 'box' => $box, + 'qty_per_box' => $qty_per_box, + 'barrel' => $barrel, + 'ltr_per_barrel' => $ltr_per_barrel, + 'isactive' => 1, + 'branch_id' => $bid, + 'manufacturer_id' => $this->request->getPost('manufacturer'), + ]; + + $insertID = $this->ProductModel->insert($data); + + if ($insertID) { + $orderNumber = 'TM' . str_pad($insertID, 8, '0', STR_PAD_LEFT); + $this->ProductModel->update($insertID, ['sku_id' => $orderNumber]); + $pD = $this->ProductModel + ->select('products.*') + ->where('products.product_id', $insertID) + ->where('products.branch_id', $bid) + ->where('products.isactive', 1) + ->first(); + + + return $this->response->setJSON([ + 'status' => 'success', + 'message' => 'Product added successfully!', + 'data' => $pD + ]); + } else { + return $this->response->setJSON([ + 'status' => 'error', + 'message' => 'Failed to add product.', + ]); + } + } } \ No newline at end of file diff --git a/app/Models/InvoiceChildModel.php b/app/Models/InvoiceChildModel.php new file mode 100755 index 0000000..a7e425a --- /dev/null +++ b/app/Models/InvoiceChildModel.php @@ -0,0 +1,24 @@ +get('logged_user'); + return $data; + } + + protected function setUpdatedBy(array $data) + { + $data['data']['updated_by'] = (int) session()->get('logged_user'); + return $data; + } + +} \ No newline at end of file diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index cc48028..de9bc81 100755 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -5,7 +5,61 @@ class InvoiceModel extends Model { protected $table = 'invoice'; protected $primaryKey = 'invoice_id'; - protected $allowedFields = ['invoice_id','invoice_number','sale_order','invoice_date','sales_commision','client_name','status','vehicle_reg_number','billing_address','billing_city','billing_state','billing_country','billing_postal_code','terms_condition','job_card_id','isactive']; + protected $allowedFields = ['invoice_id','invoice_number','sale_order','invoice_date','sales_commision','client_name','status','vehicle_reg_number','billing_address','billing_city','billing_state','billing_country','billing_postal_code','terms_condition','job_card_id','isactive', + 'type','mobile_no','email','invoice_child_id','order_number','mode_of_payment','subtotal','tax','discount','total','terms_condition','branch_id','vehicle_id' ]; + protected $beforeInsert = ['setCreatedBy']; + protected $beforeUpdate = ['setUpdatedBy']; + protected function setCreatedBy(array $data) + { + $data['data']['created_by'] = (int) session()->get('logged_user'); + return $data; + } + + protected function setUpdatedBy(array $data) + { + $data['data']['updated_by'] = (int) session()->get('logged_user'); + return $data; + } + + public function getInvoicesPdf($invoice_id){ + return $this->db->table('invoice') + ->where('invoice_id', $invoice_id) + ->join('branches as B','B.branch_id = invoice.branch_id','left') + ->join('vehicle as V','V.vehicle_id = invoice.vehicle_id','left') + ->join('client as C','V.client_id = C.client_id','left') + ->select('invoice.*') + ->select('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.contact_1 as company_mobile_no_1,B.contact_2 as company_mobile_no_2,B.gstno as company_gstno') + ->select('C.gstnumber as client_gst') + ->get() + ->getResult(); + } + + public function getInvoiceProductsForPdf($invid) + { + + $result = $this->db->table('invoice_child') + ->where('invoice_child.invoice_id', $invid) + ->where('invoice_child.isactive', 1) + ->join('products', 'products.product_id = invoice_child.product_id') + ->select('invoice_child.*, products.product_name, products.per, products.ml,products.hsn_sac') + ->get() + ->getResult(); + + return $result; + } + + public function getInvoicesWithProducts($logged_user_branch_id) + { + // Select required fields from both tables + $this->select('invoice.*, COUNT(invoice_child.invoice_child_id) AS product_count,vehicle.reg_no,SUM(invoice_child.qty) AS product_qty '); + $this->join('invoice_child', 'invoice_child.invoice_id = invoice.invoice_id AND invoice_child.isactive = 1', 'left'); + $this->join('vehicle', 'vehicle.vehicle_id = invoice.vehicle_id'); + $this->groupBy('invoice.invoice_id'); + $this->where('invoice.branch_id',$logged_user_branch_id); + $this->orderBy('invoice.invoice_id','desc'); + // Get the results + return $this->findAll(); + } } \ No newline at end of file diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index c1486d0..4744e40 100755 --- a/app/Models/ProductModel.php +++ b/app/Models/ProductModel.php @@ -9,8 +9,21 @@ class ProductModel extends Model 'quality','product_name','branch_id','prefered_vendor','product_category','mfr_part_no','purchase_order_level', 'unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level', 'handler','qty_in_demand','product_image','description','specification','hsn_sac','isactive','total_amount', - 'per','ml','box','qty_per_box','barrel','ltr_per_barrel']; - + 'per','ml','box','qty_per_box','barrel','ltr_per_barrel','cubic_centimeter_id']; + protected $beforeInsert = ['setCreatedBy']; + protected $beforeUpdate = ['setUpdatedBy']; + + protected function setCreatedBy(array $data) + { + $data['data']['created_by'] = (int) session()->get('logged_user'); + return $data; + } + + protected function setUpdatedBy(array $data) + { + $data['data']['updated_by'] = (int) session()->get('logged_user'); + return $data; + } public function getTax() { @@ -40,7 +53,7 @@ class ProductModel extends Model $this->orderBy('products.product_name'); return $this->findAll(); } - + } ?> \ No newline at end of file diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php new file mode 100755 index 0000000..92c6635 --- /dev/null +++ b/app/Views/invoice_form.php @@ -0,0 +1,1695 @@ + + + + +
+
+ +
+
+
+
+
+
+ +
" method="post" style="line-height:0.5;" id="invoicesForm"> + + +
+ + + + + +
+ + +
+ + +
+ + ' ?> + + +
+ + +
+ + +
+
+ + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + + +
> +
+ + +
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+ +
+ + + +
+ + + + +
+
+
+

Item Details

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Item DetailsRateQtyAmtTaxTax AmtTot Amt
+ + + + + + + '; + } ?> + + + + + + + + +
+
+ + + +
+
+
+
+
+

Calculation

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

Terms & Condition :


+
+
+ + + + + +
+
+ + + + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/Views/invoice_list.php b/app/Views/invoice_list.php new file mode 100755 index 0000000..0d9ef53 --- /dev/null +++ b/app/Views/invoice_list.php @@ -0,0 +1,271 @@ + + +
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + $value) : + if ($value['isactive'] == 1) : ?> + + + + + + + + + + + + + + +
Invoice IdInvoice NumberVehicle Reg NoClient NameItemsQtyTotalStatusActions
+ + + +
+
+ +
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/app/Views/invoice_pdf_layout.php b/app/Views/invoice_pdf_layout.php new file mode 100755 index 0000000..7013f85 --- /dev/null +++ b/app/Views/invoice_pdf_layout.php @@ -0,0 +1,196 @@ + + + + + + + + +
INVOICE +
+ + + + + + + + +
type; ?>  
+ + + + + + + + + + + + + + + + + + + + + + + + +
  company_address; ?>,
  company_city; ?>,company_state; ?>-company_postal_code; ?>
  Mobile: company_mobile_no_1; ?>
 GSTIN: company_gstno; ?>
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Bill To,   
client_name; ?>   Invoice Date:created_at)); ?>
billing_address; ?>,billing_city; ?>,billing_state; ?>-billing_postal_code; ?>, Payment Mode:mode_of_payment; ?>
Mobile: mobile_no; ?> , GST: client_gst) ? $invoice[0]->client_gst : 'nil'; ?>   
+

 

+ + + + + + + + + + + + + +
 Vehicle No: Model:  invoice No:invoice_number; ?>
+

 

+ + + + + + + + + + + + + + + + + + + + + $value) + { + $subTotal = $subTotal + ($value->net_price * $value->qty); + $tax = (($value->net_price * $value->qty) * $value->tax / 100); + $subTax = $subTax + $tax; + $grandTotal += $value->amount; + ?> + + + + + + + + + + + + + + + + + + +
NoDescriptionHSN/SACRate(₹)QtyTaxable ValuePerGST(%)Total Tax(₹)Total(₹)
product_name; ?> hsn_sac; ?>net_price; ?>qty; ?>net_price * $value->qty); ?>per; ?>tax; ?> amount, 2, '.', ''); ?>
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 Sub Total
 CGST
 SGST
 Total
 Discount0.00
 Grand Total₹ 
+

 

+

 

+ + + + + + + + +
+

  S.A Signature:

+

 

+
  +

  Customer Signature:

+

 

+
\ No newline at end of file diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 7c5f5ce..efa4c3b 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -448,6 +448,27 @@ +
  • + + + Invoices + +
  • + +