diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index dc99af2..d1c2e55 100755 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -67,85 +67,20 @@ class Jobcard extends BaseController return view('jobs_list',$data); } - - public function preview_jobcard_invoice($job_card_id) - { - $logged_user = $this->session->get('logged_user'); - try { - - $data['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id); - $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(); - // echo json_encode($data['company_address']);die; - $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); - // echo json_encode($productdata);die; - - - - $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", - "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); - - - - $html = view('invoice_pdf_template_jobcard', $data); - return $this->respond(['status' => 'success','code' => 200,'data' => $html],200); - - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e],500); - } - } - - public function download_jobcard_invoice($job_card_id) + public function getJobCardData($job_card_id) { $data['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id); $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(); - // echo json_encode($data['company_address']);die; $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); - // echo json_encode($productdata);die; - - - - $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); + $data['service'] = $this->JobcardModel->get_jobcard_service($job_card_id); + $data['sub_service'] = $this->JobcardModel->get_jobcard_sub_service($job_card_id); + $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['sub_service'],$data['complaint'],$data['customcomplaint'],$data['osdata']); /** CALCULATE LABOURCOST WITH TAX */ $totalAmount = 0; @@ -168,12 +103,60 @@ class Jobcard extends BaseController "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) + "tax" => $totalTax, + "amount" => $totalAmount, + "custom_tax" => $totalTax, + "custom_total" => $total ]; $data['job_card_products'] = array_merge($productdata, $labour_data); + + $data['sum_of_tax'] = 0; + $data['sum_of_sub_total'] = 0; + $data['sum_of_total'] = 0; + + foreach ($data['job_card_products'] as $key=> $value) { + $qty = $value['qty'] == '-' ? 1 : $value['qty']; + $amount = $value['amount'] * $qty; + $tax = ($amount * $value['tax'] / 100); + $total = $amount + $tax; + + //asign values to same array + $data['job_card_products'][$key]['tax_amount'] = $tax; + $data['job_card_products'][$key]['total_amount'] = $total; + + //calculate sum + $data['sum_of_tax'] += $tax; + $data['sum_of_sub_total'] += $amount; + $data['sum_of_total'] += $total; + + } + + // dd($data); + return $data; + } + + + + public function preview_jobcard_invoice($job_card_id) + { + + try { + + $data = $this->getJobCardData($job_card_id); + + $html = view('invoice_pdf_template_jobcard', $data); + + return $this->respond(['status' => 'success','code' => 200,'data' => $html],200); + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e],500); + } + } + + public function download_jobcard_invoice($job_card_id) + { + + $data = $this->getJobCardData($job_card_id); // Create an mPDF object $mpdf = new Mpdf([ @@ -181,7 +164,6 @@ class Jobcard extends BaseController 'format' => 'A4', 'default_font_size' => 0, 'default_font' => '', - // 'margin_right' => 1, 'margin_top' => 6, 'margin_bottom' => 6, @@ -194,16 +176,9 @@ class Jobcard extends BaseController $mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true; - // Set PDF properties $mpdf->SetTitle('Invoice'); - // $mpdf->SetAuthor($data[0]->branch_name); - $mpdf->SetCreator(''); - // echo"
";
- // print_r($data['job_card_products']);die;
- // Generate the PDF content (HTML) with data
$html = view('invoice_pdf_template_jobcard', $data);
- // echo $html;die;
- // Load HTML into the mPDF instance
+
$mpdf->WriteHTML($html);
// Output the PDF to the browser for download
@@ -214,48 +189,13 @@ class Jobcard extends BaseController
public function preview_jobcard($job_card_id)
{
try {
- $data['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id);
- $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();
- $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id);
- $data['service'] = $this->JobcardModel->get_jobcard_service($job_card_id);
- $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']);
+
+ $data = $this->getJobCardData($job_card_id);
- /** CALCULATE LABOURCOST WITH TAX */
- $totalAmount = 0;
- $totalTax = 0;
+ $html = view('jobcard_pdf_template', $data);
- // 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);
+
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e],500);
}
@@ -263,44 +203,7 @@ class Jobcard extends BaseController
public function download_jobcard($job_card_id)
{
- $data['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id);
- $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();
- $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id);
- $data['service'] = $this->JobcardModel->get_jobcard_service($job_card_id);
- $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);
+ $data = $this->getJobCardData($job_card_id);
// Create an mPDF object
@@ -309,7 +212,6 @@ class Jobcard extends BaseController
'format' => 'A4',
'default_font_size' => 0,
'default_font' => '',
-
// 'margin_right' => 1,
'margin_top' => 6,
'margin_bottom' => 6,
@@ -322,16 +224,8 @@ class Jobcard extends BaseController
$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) with data
$html = view('jobcard_pdf_template', $data);
- // echo $html;die;
- // Load HTML into the mPDF instance
$mpdf->WriteHTML($html);
// Output the PDF to the browser for download
diff --git a/app/Models/JobcardModel.php b/app/Models/JobcardModel.php
index 25caa33..1844692 100755
--- a/app/Models/JobcardModel.php
+++ b/app/Models/JobcardModel.php
@@ -100,6 +100,15 @@ class JobcardModel extends Model
$this->where('job_card.job_card_id', $job_id);
return $this->findAll();
}
+ public function get_jobcard_sub_service($job_id)
+ {
+ $this->select('job_card_sub_service.*, services.service_name as product_name , services.labour_cost as labour_amount');
+ $this->join('job_card_sub_service', 'job_card_sub_service.job_card_id = job_card.job_card_id');
+ $this->join('services', 'services.service_id = job_card_sub_service.sub_service_id');
+ $this->where('job_card.isactive', 1);
+ $this->where('job_card.job_card_id', $job_id);
+ return $this->findAll();
+ }
public function get_jobcard_complaint($job_id)
{
diff --git a/app/Views/invoice_pdf_template_jobcard.php b/app/Views/invoice_pdf_template_jobcard.php
index f423439..d7a07c8 100755
--- a/app/Views/invoice_pdf_template_jobcard.php
+++ b/app/Views/invoice_pdf_template_jobcard.php
@@ -102,13 +102,7 @@
- $value)
- {
- $subTotal = $subTotal + $value['amount'];
- $tax = ($value['amount'] * $value['tax'] / 100);
- $subTax = $subTax + $tax;
- ?>
+ $value) { ?>
= $key+1; ?>
@@ -117,8 +111,8 @@
= $value['qty']; ?>
= $value['per']; ?>
= $value['tax']; ?>
-
-
+
+
@@ -133,22 +127,22 @@
Sub Total
-= $subTotal; ?>
+= $sum_of_sub_total; ?>
CGST
-= number_format($subTax/2, 2, '.', ''); ?>
+= number_format($sum_of_tax/2, 2, '.', ''); ?>
SGST
-= number_format($subTax/2, 2, '.', ''); ?>
+= number_format($sum_of_tax/2, 2, '.', ''); ?>
Total
-= number_format($subTotal+$subTax, 2, '.', ''); ?>
+= number_format($sum_of_total, 2, '.', ''); ?>
@@ -158,7 +152,7 @@
Grand Total
-₹
+₹
diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php
index 40212d0..522d3cb 100755
--- a/app/Views/job_card_form.php
+++ b/app/Views/job_card_form.php
@@ -1,4 +1,5 @@
+
+
+
+
-
+
+
@@ -1659,11 +1661,11 @@ $(document).ready(function() {
var product = productarray[i];
if(!selected_pr.includes(product.product_id))
{
- newRow += '';
+ newRow += '';
}
}
- newRow += '' +
+ newRow += '' +
' ' +
' ' +
' ' +
@@ -1672,7 +1674,7 @@ $(document).ready(function() {
' ' +
' ' +
' ' +
- ' ' +
+ ' ' +
'';
// $('#productItemTable tbody').append(newRow);
diff --git a/app/Views/jobcard_pdf_template.php b/app/Views/jobcard_pdf_template.php
index 01c6bb6..a864ef0 100755
--- a/app/Views/jobcard_pdf_template.php
+++ b/app/Views/jobcard_pdf_template.php
@@ -96,6 +96,9 @@
$Svalue) { ?>
- ₹
+ $SSvalue) { ?>
+ - ₹
+
$Cvalue) { ?>
- ₹
@@ -129,22 +132,16 @@
-
+
Products
Estimation
- $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;
- ?>
+ $value) { ?>
+
= $value['product_name']; ?>
- = number_format($amount, 2, '.', ''); ?>
+ = number_format($value['total_amount'], 2, '.', ''); ?>
@@ -152,7 +149,7 @@
Approx. Total Estimation
- ₹ = number_format($Total, 2, '.', ''); ?>
+ ₹ = number_format($sum_of_total, 2, '.', ''); ?>
diff --git a/app/Views/outsourcing_list.php b/app/Views/outsourcing_list.php
index 12b67e6..e67ea2d 100755
--- a/app/Views/outsourcing_list.php
+++ b/app/Views/outsourcing_list.php
@@ -76,7 +76,7 @@
- Billing Address Details :
+