From 405799a2960905a3d71d62342bd69b64d20244a8 Mon Sep 17 00:00:00 2001 From: Smart Date: Sat, 5 Oct 2024 08:56:52 +0530 Subject: [PATCH] jc file sales module inv-no : GWM --- app/Controllers/Jobcard.php | 190 ++++---- app/Controllers/Sales.php | 20 +- app/Helpers/InvNoHelper.php | 61 +++ app/Models/SalesOrderModel.php | 4 +- app/Views/invoice_pdf_template.php | 2 +- app/Views/invoice_pdf_template_jobcard.php | 4 +- app/Views/jobcard_pdf_template.php | 489 ++++++++------------- app/Views/jobs_list.php | 40 +- app/Views/layout/header.php | 10 +- app/Views/sales_order_form.php | 10 +- 10 files changed, 409 insertions(+), 421 deletions(-) create mode 100644 app/Helpers/InvNoHelper.php diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 1bc2a2e..dc99af2 100755 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -26,7 +26,7 @@ use App\Models\JobcardFileModel; use Mpdf\Mpdf; use DateTime; use CodeIgniter\API\ResponseTrait; - +use App\Helpers\InvNoHelper; class Jobcard extends BaseController { @@ -67,28 +67,10 @@ class Jobcard extends BaseController return view('jobs_list',$data); } - public function getCurrentFinancialYear() { - // Get the current month and year - $currentMonth = date('n'); - $currentYear = date('Y'); - - // Determine the start date of the financial year - if ($currentMonth >= 4) { - $startYear = $currentYear; - } else { - $startYear = $currentYear - 1; - } - - // Determine the end date of the financial year - $endYear = $startYear + 1; - - // Format the financial year string - $financialYear = $startYear . '/' . substr($endYear, -2); - - return $financialYear; - } + - public function preview_jobcard_invoice($job_card_id) { + public function preview_jobcard_invoice($job_card_id) + { $logged_user = $this->session->get('logged_user'); try { @@ -101,16 +83,7 @@ class Jobcard extends BaseController $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); // echo json_encode($productdata);die; - if($data['job_card'][0]['inv_no'] == '') - { - /** GENERATE INV NO */ - $count = $this->JobcardModel->where('status', 'Paid')->countAllResults(); - $formattedCount = str_pad($count+1, 5, '0', STR_PAD_LEFT); - $currentFinancialYear = $this->getCurrentFinancialYear(); - $invoiceNumber = 'MECH-' . $currentFinancialYear. '/' . $formattedCount; - $this->JobcardModel->update($job_card_id,['inv_no' => $invoiceNumber]); - $data['job_card'][0]['inv_no'] = $invoiceNumber; - } + $servicedata = $this->JobcardModel->get_jobcard_service($job_card_id); $complaintdata = $this->JobcardModel->get_jobcard_complaint($job_card_id); @@ -135,6 +108,7 @@ class Jobcard extends BaseController // Create single output array $labour_data[0] = [ "name" => "Labour Cost", + "product_name" => "Labour Cost", "qty" => "-", "per" => "-", "tax" => number_format($totalTax, 2), @@ -165,50 +139,42 @@ class Jobcard extends BaseController $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); // echo json_encode($productdata);die; - if($data['job_card'][0]['inv_no'] == '') - { - /** GENERATE INV NO */ - $count = $this->JobcardModel->where('status', 'Paid')->countAllResults(); - $formattedCount = str_pad($count+1, 5, '0', STR_PAD_LEFT); - $currentFinancialYear = $this->getCurrentFinancialYear(); - $invoiceNumber = 'MECH-' . $currentFinancialYear. '/' . $formattedCount; - $this->JobcardModel->update($job_card_id,['inv_no' => $invoiceNumber]); - $data['job_card'][0]['inv_no'] = $invoiceNumber; - } + $servicedata = $this->JobcardModel->get_jobcard_service($job_card_id); $complaintdata = $this->JobcardModel->get_jobcard_complaint($job_card_id); $osdata = $this->JobcardModel->get_jobcard_os($job_card_id); $customcomplaintdata = $this->JobcardModel->get_jobcard_custom_complaint($job_card_id); $labourcost = array_merge($servicedata, $complaintdata,$customcomplaintdata,$osdata); - /** CALCULATE LABOURCOST WITH TAX */ - $totalAmount = 0; - $totalTax = 0; - - // Calculate total amount and total tax - foreach ($labourcost as $product) { - $totalAmount += $product["labour_amount"]; - $totalTax = $product["tax"]; - } - // Calculate total - $total = $totalAmount + $totalTax; - - $discount = ($data['job_card'][0]['is_rework'] == 1) ? 0 : $data['job_card'][0]['discount'] ; - $amt_with_tax = $totalAmount + ($totalAmount * $totalTax / 100); - $totalAmount = ($amt_with_tax - (float)$discount) / (1 + ($totalTax/100)); - // Create single output array - $labour_data[0] = [ - "name" => "Labour Cost", - "qty" => '-', - "per" => '-', - "tax" => number_format($totalTax, 2), - "amount" => number_format($totalAmount, 2), - "custom_tax" => number_format($totalTax, 2), - "custom_total" => number_format($total, 2) - ]; - $data['job_card_products'] = array_merge($productdata, $labour_data); - // echo json_encode($complaintdata);die; + /** CALCULATE LABOURCOST WITH TAX */ + $totalAmount = 0; + $totalTax = 0; + + // Calculate total amount and total tax + foreach ($labourcost as $product) { + $totalAmount += $product["labour_amount"]; + $totalTax = $product["tax"]; + } + // Calculate total + $total = $totalAmount + $totalTax; + + $discount = ($data['job_card'][0]['is_rework'] == 1) ? 0 : $data['job_card'][0]['discount'] ; + $amt_with_tax = $totalAmount + ($totalAmount * $totalTax / 100); + $totalAmount = ($amt_with_tax - (float)$discount) / (1 + ($totalTax/100)); + // Create single output array + $labour_data[0] = [ + "name" => "Labour Cost", + "product_name" => "Labour Cost", + "qty" => '-', + "per" => '-', + "tax" => number_format($totalTax, 2), + "amount" => number_format($totalAmount, 2), + "custom_tax" => number_format($totalTax, 2), + "custom_total" => number_format($total, 2) + ]; + $data['job_card_products'] = array_merge($productdata, $labour_data); + // Create an mPDF object $mpdf = new Mpdf([ 'mode' => '', @@ -252,11 +218,41 @@ class Jobcard extends BaseController $bus_id = $this->session->get('logged_user_business_id'); $data['job_card'] = $this->JobcardModel->where('job_card_id',$job_card_id)->findAll(); $data['company_address'] = $this->BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->where('business_id', $bus_id)->where('isactive', 1)->findAll(); - $data['job_card_products'] = $this->JobcardModel->get_jobcard_products_details($job_card_id); + $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); $data['service'] = $this->JobcardModel->get_jobcard_service($job_card_id); - $complaint = $this->JobcardModel->get_jobcard_complaint($job_card_id); - $customcomplaint = $this->JobcardModel->get_jobcard_custom_complaint($job_card_id); - $data['complaint'] = array_merge($complaint,$customcomplaint); + $data['complaint'] = $this->JobcardModel->get_jobcard_complaint($job_card_id); + $data['customcomplaint'] = $this->JobcardModel->get_jobcard_custom_complaint($job_card_id); + $data['osdata'] = $this->JobcardModel->get_jobcard_os($job_card_id); + $labourcost = array_merge($data['service'], $data['complaint'],$data['customcomplaint'],$data['osdata']); + + /** CALCULATE LABOURCOST WITH TAX */ + $totalAmount = 0; + $totalTax = 0; + + // Calculate total amount and total tax + foreach ($labourcost as $product) { + $totalAmount += $product["labour_amount"]; + $totalTax = $product["tax"]; + } + // Calculate total + $total = $totalAmount + $totalTax; + + $discount = ($data['job_card'][0]['is_rework'] == 1) ? 0 : $data['job_card'][0]['discount'] ; + $amt_with_tax = $totalAmount + ($totalAmount * $totalTax / 100); + $totalAmount = ($amt_with_tax - (float)$discount) / (1 + ($totalTax/100)); + // Create single output array + $labour_data[0] = [ + "name" => "Labour Cost", + "product_name" => "Labour Cost", + "qty" => 0, + "per" => '-', + "tax" => number_format($totalTax, 2), + "amount" => number_format($totalAmount, 2), + "custom_tax" => number_format($totalTax, 2), + "custom_total" => number_format($total, 2) + ]; + $data['job_card_products'] = array_merge($productdata, $labour_data); + $html = view('jobcard_pdf_template', $data); return $this->respond(['status' => 'success','code' => 200,'data' => $html],200); @@ -271,17 +267,46 @@ class Jobcard extends BaseController $bus_id = $this->session->get('logged_user_business_id'); $data['job_card'] = $this->JobcardModel->where('job_card_id',$job_card_id)->findAll(); $data['company_address'] = $this->BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->where('business_id', $bus_id)->where('isactive', 1)->findAll(); - $data['job_card_products'] = $this->JobcardModel->get_jobcard_products_details($job_card_id); + $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); $data['service'] = $this->JobcardModel->get_jobcard_service($job_card_id); - $complaint = $this->JobcardModel->get_jobcard_complaint($job_card_id); - $customcomplaint = $this->JobcardModel->get_jobcard_custom_complaint($job_card_id); - $data['complaint'] = array_merge($complaint,$customcomplaint); + $data['complaint'] = $this->JobcardModel->get_jobcard_complaint($job_card_id); + $data['customcomplaint'] = $this->JobcardModel->get_jobcard_custom_complaint($job_card_id); + $data['osdata'] = $this->JobcardModel->get_jobcard_os($job_card_id); + $labourcost = array_merge($data['service'], $data['complaint'],$data['customcomplaint'],$data['osdata']); + + /** CALCULATE LABOURCOST WITH TAX */ + $totalAmount = 0; + $totalTax = 0; + + // Calculate total amount and total tax + foreach ($labourcost as $product) { + $totalAmount += $product["labour_amount"]; + $totalTax = $product["tax"]; + } + // Calculate total + $total = $totalAmount + $totalTax; + + $discount = ($data['job_card'][0]['is_rework'] == 1) ? 0 : $data['job_card'][0]['discount'] ; + $amt_with_tax = $totalAmount + ($totalAmount * $totalTax / 100); + $totalAmount = ($amt_with_tax - (float)$discount) / (1 + ($totalTax/100)); + // Create single output array + $labour_data[0] = [ + "name" => "Labour Cost", + "product_name" => "Labour Cost", + "qty" => 0, + "per" => '-', + "tax" => number_format($totalTax, 2), + "amount" => number_format($totalAmount, 2), + "custom_tax" => number_format($totalTax, 2), + "custom_total" => number_format($total, 2) + ]; + $data['job_card_products'] = array_merge($productdata, $labour_data); // Create an mPDF object $mpdf = new Mpdf([ 'mode' => '', - 'format' => 'A5', + 'format' => 'A4', 'default_font_size' => 0, 'default_font' => '', @@ -710,7 +735,6 @@ class Jobcard extends BaseController public function add_jobs() { - // dd($this->request->getPost()); $JobcardModel = new JobcardModel(); if($this->session->get('logged_user_role') == "Store Manager") { $data['status'] = $this->request->getPost('status'); @@ -730,7 +754,7 @@ class Jobcard extends BaseController $this->delete_items($this->request->getPost('delete_items')); $rework = $this->request->getPost('rework'); // Job card INSERT - $deliveryDate = $this->request->getPost('delivery_date'); + // Retrieve and validate the delivery date $deliveryDate = $this->request->getPost('delivery_date'); @@ -775,6 +799,8 @@ class Jobcard extends BaseController } $JobcardModel->update($job_card_id, $job_card_data); } else { + + $job_card_data['inv_no'] = InvNoHelper::generateInvoiceNumber(); $JobcardModel->insert($job_card_data); $job_card_id = $JobcardModel->getInsertID(); // Get the last inserted ID @@ -798,8 +824,8 @@ class Jobcard extends BaseController $service['service_id'] = $item->service_id; $service['qty'] = $item->quality; $service['tax'] = (int)$item->tax; - $service['labour_cost'] = $item->labour_cost; //(isset($rework) ? 0 : $item->labour_cost ); - $service['amount'] = $item->amount; //(isset($rework) ? 0 : $item->amount ); + $service['labour_cost'] = $item->labour_cost; + $service['amount'] = $item->amount; if(empty($item->id)) { $JobcardServiceModel->insert($service); diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 598da70..8795558 100755 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -13,6 +13,7 @@ use App\Models\BusinessModel; use App\Models\BranchModel; use Mpdf\Mpdf; use CodeIgniter\API\ResponseTrait; +use App\Helpers\InvNoHelper; class Sales extends BaseController { public $session; @@ -45,17 +46,16 @@ class Sales extends BaseController { if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + if ($sales_order_id === '0') { - $data['page_name']="Create Sales Order"; + $data['page_name']="Create Sales Order"; $data['sales'] = []; $ClientModel = new ClientModel(); - $client=$ClientModel - ->where('isactive',1) - ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); + $client = $ClientModel->where('isactive',1) + ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $VehicleModel = new VehicleModel(); $vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id')); - // ->where('isactive',1) - // ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); + $ProductModel = new ProductModel(); $product=$ProductModel->select('products.*, manufacturer.manufacturer_name') @@ -64,8 +64,7 @@ class Sales extends BaseController ->where('products.branch_id', $this->session->get('logged_user_branch_id')) ->where('products.isactive', 1) ->findAll(); - // echo "
";
-            // print_r($product);die;
+
             $data['product']=$product;   
             $data['client']=$client;  
             $data['vehicle']=$vehicle; 
@@ -178,8 +177,11 @@ class Sales extends BaseController
             }
             $SalesOrderModel->update($sales_order_id, $data);
         } else {
+            $data['inv_no'] = InvNoHelper::generateInvoiceNumber(); 
+
+            // dd($data);
             $SalesOrderModel->insert($data);
-            $sales_order_id = $SalesOrderModel->getInsertID(); // Get the last inserted ID
+            $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);
diff --git a/app/Helpers/InvNoHelper.php b/app/Helpers/InvNoHelper.php
new file mode 100644
index 0000000..48d9609
--- /dev/null
+++ b/app/Helpers/InvNoHelper.php
@@ -0,0 +1,61 @@
+orderBy('sales_order_id', 'DESC')->first();
+        $SaleslastFiveDigits = $Sales && isset($Sales['inv_no']) ? substr($Sales['inv_no'], -5) : 0;
+
+        $Jobs = $JobcardModel->orderBy('job_card_id', 'DESC')->first();
+        $JobslastFiveDigits = $Jobs && isset($Jobs['inv_no']) ? substr($Jobs['inv_no'], -5) : 0;
+
+
+
+        $largerNumber = max((int)$SaleslastFiveDigits, (int)$JobslastFiveDigits);
+        $formattedCount = str_pad($largerNumber+1, 5, '0', STR_PAD_LEFT);
+        $currentFinancialYear = SELF::getCurrentFinancialYear();
+        $invoiceNumber = 'MECH-' . $currentFinancialYear. '/' . $formattedCount;
+
+        
+        return $invoiceNumber;
+
+    }
+
+    public static function getCurrentFinancialYear() {
+        // Get the current month and year
+        $currentMonth = date('n');
+        $currentYear = date('Y');
+        
+        // Determine the start date of the financial year
+        if ($currentMonth >= 4) {
+            $startYear = $currentYear;
+        } else {
+            $startYear = $currentYear - 1;
+        }
+        
+        // Determine the end date of the financial year
+        $endYear = $startYear + 1;
+        
+        // Format the financial year string
+        $financialYear = $startYear . '-' . substr($endYear, -2);
+        
+        return $financialYear;
+    }
+
+  
+
+}
+?>
\ No newline at end of file
diff --git a/app/Models/SalesOrderModel.php b/app/Models/SalesOrderModel.php
index 8c898a8..7af6d1a 100755
--- a/app/Models/SalesOrderModel.php
+++ b/app/Models/SalesOrderModel.php
@@ -5,8 +5,8 @@ class SalesOrderModel extends Model
 {
     protected $table = 'sales_order';
     protected $primaryKey = 'sales_order_id';
-    protected $allowedFields = ['sales_order_id','client_name','vehicle_id','order_number','branch_id','status','mode_of_payment','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
-// 
+    protected $allowedFields = ['sales_order_id','inv_no','client_name','vehicle_id','order_number','branch_id','status','mode_of_payment','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
+
     public function getSalesPdf($sales_order_id){
         return $this->db->table('sales_order')
         ->where('sales_order_id', $sales_order_id)
diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php
index af1a156..697965e 100644
--- a/app/Views/invoice_pdf_template.php
+++ b/app/Views/invoice_pdf_template.php
@@ -10,7 +10,7 @@
     
-    
+    
diff --git a/app/Views/invoice_pdf_template_jobcard.php b/app/Views/invoice_pdf_template_jobcard.php
index 88f3068..f423439 100755
--- a/app/Views/invoice_pdf_template_jobcard.php
+++ b/app/Views/invoice_pdf_template_jobcard.php
@@ -112,7 +112,7 @@
 
         
-        
+        
@@ -158,7 +158,7 @@
 
-
+
inv_no; ?>    
  Grand Total₹ ₹ 
diff --git a/app/Views/jobcard_pdf_template.php b/app/Views/jobcard_pdf_template.php index 591509f..01c6bb6 100755 --- a/app/Views/jobcard_pdf_template.php +++ b/app/Views/jobcard_pdf_template.php @@ -1,311 +1,192 @@ - - - - - - - - - - - -
DATE: format('d/m/Y') ?>

JOB CARD

JOB NO:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - - - - -
- - - - -
- - - - - - - - - - $item) : ?> - - - - - - - -
- - - - - - - - - - $item) : ?> - - - - - - - -
- -
- - - - - - - - - - + + + + + + + + + - - $item) : ?> - - - - - - - - -
JOB CARD
Date :
- -
- - - - - - - +

 

+ - - - + + + + + + +
 Vehicle No:  Make:  Fuel:
+

 

+ + + + + + + + + + +
 Name:  Model:  Meter:
+

 

+ + + + + + + + + + +
 Mobile:  Colour:  Expected Delivery:
+

 

+ + + + + + +
Service Type:                      General | Outsource | Restoration +
+

 

+ + + + + + + + + + +
 JCM:Gowtham  TM:Surendar  FM:Venkatesh
+

 

+ + + + + + + + + + + + + + + +
Customer ComplaintsMechanic Observation
+
+
    + $Svalue) { ?> +
  • - ₹
  • + + $Cvalue) { ?> +
  • - ₹
  • + +
+
+
+
+
    + $CCvalue) { ?> +
  • - ₹
  • + +
+
+
+ + + + + + - - + $value) + { + + if((int)$value['qty'] != 0 ){ $amount = ((int)$value['amount'] + ((int)$value['amount'] * (int)$value['tax'] / 100)) * (int)$value['qty']; }else{ $amount = ((int)$value['amount'] + ((int)$value['amount'] * (int)$value['tax'] / 100)) ; } + $Total += $amount; + ?> + + + + + + + + + + + + +
   Products  Estimation
              +                                                                                      Approx. Total Estimation₹ 
+

 

+ + + + + + + $OSvalue) { ?> + + + + + + +
   Outsourcing   Remarks
    - ₹
+

 

+

 

+

 

+

 

+ + + + + + + + +
+

  S.A Signature:

+

 

+
  +

  Customer Signature:

+

 

+
\ No newline at end of file diff --git a/app/Views/jobs_list.php b/app/Views/jobs_list.php index 513150a..3fc42ae 100755 --- a/app/Views/jobs_list.php +++ b/app/Views/jobs_list.php @@ -139,7 +139,7 @@ @@ -451,12 +454,7 @@ Make & Models -
  • - - - Product Category - -
  • + diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 3232f95..27946e1 100755 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -7,6 +7,9 @@ /* left: 50px; Adjust as needed */ width: 300px; /* Adjust as needed */ } + .form-control{ + padding: 5px !important; + }
    @@ -73,11 +76,12 @@ minlength="6" onkeypress="return onlyNumbers(event)" readonly>
    -