FIX_Preview Popup jobcard
This commit is contained in:
parent
597f3c0a32
commit
c2bbd80e14
@ -91,6 +91,8 @@ $routes->get('job_card_index/', 'Jobcard::job_card_index');
|
||||
$routes->post("add_jobs", "Jobcard::add_jobs");
|
||||
$routes->get("new_jobcard/(:any)", "Jobcard::new_jobcard/$1");
|
||||
$routes->get("delete_jobcard/(:any)", "Jobcard::delete_jobcard/$1");
|
||||
$routes->get("preview_jobcard_invoice/(:any)", "Jobcard::preview_jobcard_invoice/$1");
|
||||
$routes->get("preview_jobcard/(:any)", "Jobcard::preview_jobcard/$1");
|
||||
// $routes->post("delete_sales_product", "Jobcard::delete_sales_product");
|
||||
$routes->get("download_jobcard_invoice/(:any)", "Jobcard::download_jobcard_invoice/$1");
|
||||
// $routes->post("save_vehicle", "Jobcard::save_vehicle");
|
||||
|
||||
@ -25,10 +25,13 @@ use App\Models\RoleModel;
|
||||
use App\Models\JobcardFileModel;
|
||||
use Mpdf\Mpdf;
|
||||
use DateTime;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
|
||||
class Jobcard extends BaseController
|
||||
{
|
||||
public $session;
|
||||
use ResponseTrait;
|
||||
public $BikemodelsModel;
|
||||
public $BikemakeModel;
|
||||
public $BusinessModel;
|
||||
@ -85,6 +88,69 @@ class Jobcard extends BaseController
|
||||
return $financialYear;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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] = [
|
||||
"product_name" => "Labour Cost",
|
||||
"qty" => 1,
|
||||
"tax" => number_format($totalTax, 2),
|
||||
"custom_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;
|
||||
$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['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id);
|
||||
@ -175,6 +241,26 @@ 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();
|
||||
$data['job_card_products'] = $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);
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
public function download_jobcard($job_card_id)
|
||||
{
|
||||
$data['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id);
|
||||
|
||||
@ -87,9 +87,10 @@
|
||||
<a href="<?= "new_jobcard/" . $value['job_card_id']; ?>" class="dropdown-item edit-button" onclick="datatableJobCard('job_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
||||
|
||||
<?php if($admins) { ?>
|
||||
<a href="#" data-job-card-id="<?= $value['job_card_id']; ?>" class="dropdown-item preview-invoice" href="#" title="Preview Invoice"><i class="ri-book-read-line mr-2 text-muted font-18 vertical-middle"></i>Preview Invoice</a>
|
||||
<a href="<?= "download_jobcard_invoice/" . $value['job_card_id']; ?>" class="dropdown-item edit-button"><i class="ri-download-2-fill mr-2 text-muted font-18 vertical-middle"></i>Download Invoice</a>
|
||||
<?php } ?>
|
||||
|
||||
<a href="#" data-job-card-id="<?= $value['job_card_id']; ?>" class="dropdown-item preview-jobcard" href="#" title="Preview Jobcard"><i class="ri-book-read-line mr-2 text-muted font-18 vertical-middle"></i>Preview Jobcard</a>
|
||||
<a href="<?= base_url() ."download_jobcard/" . $value['job_card_id']; ?>" class="dropdown-item download-button"><i class="ri-download-2-fill mr-2 text-muted font-18 vertical-middle"></i>Download Jobcard</a>
|
||||
|
||||
<?php if($value['status'] == 'Paid' && $admins && $value['is_rework'] == 0) { ?>
|
||||
@ -114,6 +115,39 @@
|
||||
</div> <!-- end col -->
|
||||
|
||||
</div>
|
||||
<div class="modal fade" id="PreviewInvoiceModal" tabindex="-1" role="dialog" aria-labelledby="PreviewInvoiceModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content" style="width: 794px; height: 1123px;">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="PreviewInvoiceModalLabel"></h5>
|
||||
|
||||
<a href="#" class="ri-download-2-fill ml-3 text-muted font-18" id="downloadInvoiceButton" title="Print Invoice"></a>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="font-size: 27px; margin-bottom: 2px;">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body" style="font-family: Times New Roman, Times, sans-serif !important; font-size: 12px !important;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="PreviewJobcardModal" tabindex="-1" role="dialog" aria-labelledby="PreviewJobcardModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content" style="width: 794px; height: 1123px;">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="PreviewJobcardModalLabel"></h5>
|
||||
<a href="#" class="ri-download-2-fill ml-3 text-muted font-18" id="downloadJobcardButton" title="Print Jobcard"></a>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="font-size: 27px; margin-bottom: 2px;">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body" style="font-family: Times New Roman, Times, sans-serif !important; font-size: 12px !important;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
|
||||
|
||||
@ -192,4 +226,58 @@
|
||||
toastr.warning(msg);
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('click', '.preview-invoice', function() {
|
||||
var jobCardId = $(this).data('job-card-id');
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'preview_jobcard_invoice/'+jobCardId,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.status == "success") {
|
||||
$('#PreviewInvoiceModal').modal('show');
|
||||
$('#PreviewInvoiceModalLabel').text('Preview Invoice Modal');
|
||||
$('#PreviewInvoiceModal .modal-body').html(response.data);
|
||||
$('#downloadInvoiceButton').attr('href', '<?= base_url("download_jobcard_invoice/") ?>' + jobCardId);
|
||||
}else{
|
||||
$('#PreviewInvoiceModal').modal('hide');
|
||||
$('#PreviewInvoiceModalLabel').text('');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
$('#PreviewInvoiceModal').modal('hide');
|
||||
$('#PreviewInvoiceModalLabel').text('');
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).on('click', '.preview-jobcard', function() {
|
||||
var jobCardId = $(this).data('job-card-id');
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'preview_jobcard/'+jobCardId,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.status == "success") {
|
||||
$('#PreviewJobcardModal').modal('show');
|
||||
$('#PreviewJobcardModalLabel').text('Preview Jobcard Modal');
|
||||
$('#PreviewJobcardModal .modal-body').html(response.data);
|
||||
$('#downloadJobcardButton').attr('href', '<?= base_url("download_jobcard/") ?>' + jobCardId);
|
||||
}else{
|
||||
$('#PreviewJobcardModal').modal('hide');
|
||||
$('#PreviewJobcardModalLabel').text('');
|
||||
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
$('#PreviewJobcardModal').modal('hide');
|
||||
$('#PreviewJobcardModalLabel').text('');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user