Merge branch '95-jo-print' into 'master'
Resolve "JO print" Closes #95 See merge request jankstudio/resq!135
This commit is contained in:
commit
0fdb942134
4 changed files with 334 additions and 14 deletions
|
|
@ -9,6 +9,7 @@
|
|||
"guzzlehttp/guzzle": "^6.3",
|
||||
"predis/predis": "^1.1",
|
||||
"sensio/framework-extra-bundle": "^5.1",
|
||||
"setasign/fpdf": "^1.8",
|
||||
"symfony/console": "^4.0",
|
||||
"symfony/debug": "^4.0",
|
||||
"symfony/filesystem": "^4.0",
|
||||
|
|
|
|||
41
composer.lock
generated
41
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "674d8092785a7a621880a5b8649c6392",
|
||||
"content-hash": "42f6ec2e149ab1bf6f8f2a08d33087b2",
|
||||
"packages": [
|
||||
{
|
||||
"name": "creof/doctrine2-spatial",
|
||||
|
|
@ -1918,6 +1918,45 @@
|
|||
],
|
||||
"time": "2017-12-04T18:33:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "setasign/fpdf",
|
||||
"version": "1.8.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Setasign/FPDF.git",
|
||||
"reference": "2c68c9e6c034ac3187d25968790139a73184cdb1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Setasign/FPDF/zipball/2c68c9e6c034ac3187d25968790139a73184cdb1",
|
||||
"reference": "2c68c9e6c034ac3187d25968790139a73184cdb1",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"fpdf.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"no usage restriction"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Olivier Plathey",
|
||||
"email": "oliver@fpdf.org",
|
||||
"homepage": "http://fpdf.org/"
|
||||
}
|
||||
],
|
||||
"description": "FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.",
|
||||
"homepage": "http://www.fpdf.org",
|
||||
"keywords": [
|
||||
"fpdf",
|
||||
"pdf"
|
||||
],
|
||||
"time": "2016-01-01T17:47:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/cache",
|
||||
"version": "v4.0.2",
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ use Mosquitto\Client as MosquittoClient;
|
|||
use DateTime;
|
||||
use DateInterval;
|
||||
|
||||
use FPDF;
|
||||
|
||||
class JobOrderController extends BaseController
|
||||
{
|
||||
public function getJobOrders(Request $req)
|
||||
|
|
@ -1720,15 +1722,12 @@ class JobOrderController extends BaseController
|
|||
}
|
||||
|
||||
|
||||
public function pdfForm($id)
|
||||
public function pdfForm(Request $req, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_pdf.list', null, 'No access.');
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$params = $this->initParameters('jo_all');
|
||||
$params['mode'] = 'update-all';
|
||||
|
||||
// get row data
|
||||
$obj = $em->getRepository(JobOrder::class)->find($id);
|
||||
|
||||
|
|
@ -1736,16 +1735,297 @@ class JobOrderController extends BaseController
|
|||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The job order does not exist');
|
||||
|
||||
$this->fillDropdownParameters($params);
|
||||
$this->fillFormTags($params);
|
||||
// set output filename
|
||||
$filename = 'job-order-' . $obj->getID() . '.pdf';
|
||||
|
||||
$params['obj'] = $obj;
|
||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||
$params['return_url'] = $this->generateUrl('jo_all');
|
||||
$params['submit_url'] = '';
|
||||
// generate the pdf
|
||||
$pdf = new FPDF('P', 'mm', 'letter');
|
||||
$pdf->AddPage();
|
||||
$pdf->SetTitle('Motolite Res-Q Job Order #' . $obj->getID());
|
||||
$pdf->SetFillColor(211, 211, 211);
|
||||
|
||||
// response
|
||||
return $this->render('job-order/form.pdf.html.twig', $params);
|
||||
// style defaults
|
||||
$margin = 10;
|
||||
$page_width = $pdf->GetPageWidth() - ($margin * 2);
|
||||
$table_col_width = $page_width / 12;
|
||||
$line_height = 5;
|
||||
$jo_line_height = 10;
|
||||
$table_line_height = 7;
|
||||
$font_face = 'Arial';
|
||||
$body_font_size = 9;
|
||||
$header_font_size = 9;
|
||||
$jo_font_size = 16;
|
||||
$col1_x = $margin;
|
||||
$col2_x = 120;
|
||||
$label_width = 35;
|
||||
$val_width = 60;
|
||||
|
||||
// insert the logo
|
||||
$image_path = $this->get('kernel')->getProjectDir() . '/public/assets/images/logo-resq.png';
|
||||
$pdf->Image($image_path, $col1_x, 10);
|
||||
|
||||
// insert JO number
|
||||
$pdf->SetFont($font_face, 'B', $jo_font_size);
|
||||
$pdf->SetX($col2_x);
|
||||
$pdf->Cell($label_width, $jo_line_height, 'JO Number:');
|
||||
$pdf->SetTextColor(9, 65, 150);
|
||||
$pdf->Cell(0, $jo_line_height, $obj->getID());
|
||||
|
||||
// insert customer info
|
||||
$customer = $obj->getCustomer();
|
||||
$pdf->SetFont($font_face, '', $body_font_size);
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
|
||||
$pdf->Ln($line_height * 7);
|
||||
|
||||
// get current Y
|
||||
$y = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col1_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Customer Name:');
|
||||
$pdf->MultiCell($val_width, $line_height, $customer->getFirstName() . ' ' . $customer->getLastName(), 0, 'L');
|
||||
|
||||
// get Y after left cell
|
||||
$y1 = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Mobile Phone:');
|
||||
$pdf->MultiCell(0, $line_height, $customer->getPhoneMobile() ? '+63' . $customer->getPhoneMobile() : '', 0, 'L');
|
||||
|
||||
// get Y after right cell
|
||||
$y2 = $pdf->GetY();
|
||||
|
||||
// get row height
|
||||
$y = max($y1, $y2);
|
||||
|
||||
$pdf->SetXY($col1_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Delivery Date:');
|
||||
$pdf->MultiCell($val_width, $line_height, $obj->getDateSchedule() ? $obj->getDateSchedule()->format("m/d/Y") : '', 0, 'left');
|
||||
|
||||
// get Y after left cell
|
||||
$y1 = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Landline:');
|
||||
$pdf->MultiCell(0, $line_height, $customer->getPhoneLandline() ? '+63' . $customer->getPhoneLandline() : '', 0, 'L');
|
||||
|
||||
// get Y after right cell
|
||||
$y2 = $pdf->GetY();
|
||||
|
||||
// get row height
|
||||
$y = max($y1, $y2);
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Office Phone:');
|
||||
$pdf->MultiCell(0, $line_height, $customer->getPhoneOffice() ? '+63' . $customer->getPhoneOffice() : '', 0, 'L');
|
||||
|
||||
$pdf->SetX($col2_x);
|
||||
$pdf->Cell($label_width, $line_height, 'Fax:');
|
||||
$pdf->MultiCell($val_width, $line_height, $customer->getPhoneFax() ? '+63' . $customer->getPhoneFax() : '', 0, 'L');
|
||||
|
||||
// insert vehicle info
|
||||
$cv = $obj->getCustomerVehicle();
|
||||
$vehicle = $cv->getVehicle();
|
||||
$pdf->Ln();
|
||||
$pdf->SetFont($font_face, 'B', $header_font_size);
|
||||
$pdf->Cell($label_width, $line_height, 'Vehicle Details');
|
||||
$pdf->Ln($line_height * 2);
|
||||
|
||||
// get current Y
|
||||
$y = $pdf->GetY();
|
||||
|
||||
$pdf->SetFont($font_face, '', $body_font_size);
|
||||
$pdf->Cell($label_width, $line_height, 'Plate Number:');
|
||||
$pdf->MultiCell($val_width, $line_height, $cv ? $cv->getPlateNumber() : '', 0, 'L');
|
||||
|
||||
// get Y after left cell
|
||||
$y1 = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Vehicle Color:');
|
||||
$pdf->MultiCell(0, $line_height, $cv ? $cv->getColor() : '', 0, 'L');
|
||||
|
||||
// get Y after right cell
|
||||
$y2 = $pdf->GetY();
|
||||
|
||||
// get row height
|
||||
$y = max($y1, $y2);
|
||||
|
||||
$pdf->SetXY($col1_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Brand:');
|
||||
$pdf->MultiCell($val_width, $line_height, $vehicle ? $vehicle->getManufacturer()->getName() : '', 0, 'L');
|
||||
|
||||
// get Y after left cell
|
||||
$y1 = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Model / Year:');
|
||||
$pdf->MultiCell(0, $line_height, $cv ? $cv->getModelYear() : '', 0, 'L');
|
||||
|
||||
// get Y after right cell
|
||||
$y2 = $pdf->GetY();
|
||||
|
||||
// get row height
|
||||
$y = max($y1, $y2);
|
||||
|
||||
$pdf->SetXY($col1_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Make:');
|
||||
$pdf->MultiCell($val_width, $line_height, $vehicle ? $vehicle->getMake() : '', 0, 'L');
|
||||
|
||||
// insert battery info
|
||||
$battery = $cv->getCurrentBattery();
|
||||
$pdf->Ln();
|
||||
$pdf->SetFont($font_face, 'B', $header_font_size);
|
||||
$pdf->Cell($label_width, $line_height, 'Battery Details');
|
||||
$pdf->Ln($line_height * 2);
|
||||
|
||||
$pdf->SetFont($font_face, '', $body_font_size);
|
||||
|
||||
// get current Y
|
||||
$y = $pdf->GetY();
|
||||
|
||||
$pdf->Cell($label_width, $line_height, 'Current Battery:');
|
||||
$pdf->MultiCell($val_width, $line_height, $battery ? $battery->getManufacturer()->getName() . ' ' . $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' (' . $battery->getProductCode() . ')' : '', 0, 'L');
|
||||
|
||||
// get Y after left cell
|
||||
$y1 = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Serial Number:');
|
||||
$pdf->MultiCell(0, $line_height, $cv ? $cv->getWarrantyCode() : '', 0, 'L');
|
||||
|
||||
// get Y after right cell
|
||||
$y2 = $pdf->GetY();
|
||||
|
||||
// get row height
|
||||
$y = max($y1, $y2);
|
||||
|
||||
$pdf->SetXY($col1_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Wty. Exp. Date:');
|
||||
$pdf->MultiCell($val_width, $line_height, $cv && $cv->getWarrantyExpiration() ? $cv->getWarrantyExpiration()->format("d/m/Y") : '', 0, 'L');
|
||||
|
||||
// insert address info
|
||||
$pdf->Ln();
|
||||
$pdf->SetFont($font_face, 'B', $header_font_size);
|
||||
$pdf->Cell($label_width, $line_height, 'Transaction Details');
|
||||
$pdf->Ln($line_height * 2);
|
||||
|
||||
$pdf->SetFont($font_face, '', $body_font_size);
|
||||
|
||||
// get current Y
|
||||
$y = $pdf->GetY();
|
||||
|
||||
$pdf->Cell($label_width, $line_height, 'Delivery Address:');
|
||||
$pdf->MultiCell($val_width, $line_height, $obj->getDeliveryAddress(), 0, 'L');
|
||||
|
||||
// get Y after left cell
|
||||
$y1 = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Landmark:');
|
||||
$pdf->MultiCell(0, $line_height, $obj->getLandMark(), 0, 'L');
|
||||
|
||||
// get Y after right cell
|
||||
$y2 = $pdf->GetY();
|
||||
|
||||
// get row height
|
||||
$y = max($y1, $y2);
|
||||
|
||||
$pdf->SetXY($col1_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Dispatch Time:');
|
||||
$pdf->MultiCell($val_width, $line_height, $obj->getDateSchedule()->format("g:i A"), 0, 'L');
|
||||
|
||||
// get Y after left cell
|
||||
$y1 = $pdf->GetY();
|
||||
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->Cell($label_width, $line_height, 'Dispatched By:');
|
||||
$pdf->MultiCell(0, $line_height, $obj->getAssignedBy()->getFullName(), 0, 'L');
|
||||
|
||||
// get Y after right cell
|
||||
$y2 = $pdf->GetY();
|
||||
|
||||
// get row height
|
||||
$y = max($y1, $y2);
|
||||
|
||||
// insert delivery instructions
|
||||
$pdf->SetY($y);
|
||||
$pdf->Ln();
|
||||
$pdf->SetFont($font_face, 'B', $header_font_size);
|
||||
$pdf->Cell(0, $line_height, 'Delivery Instructions');
|
||||
$pdf->Ln();
|
||||
|
||||
$pdf->SetFont($font_face, '', $body_font_size);
|
||||
$pdf->MultiCell(0, $line_height, $obj->getDeliveryInstructions(), 1, 'L');
|
||||
|
||||
// insert invoice details
|
||||
$pdf->Ln();
|
||||
$pdf->SetFont($font_face, 'B', $header_font_size);
|
||||
$pdf->Cell($label_width, $line_height, 'Invoice Details');
|
||||
$pdf->Ln();
|
||||
|
||||
// invoice table headers
|
||||
$invoice = $obj->getInvoice();
|
||||
$pdf->SetFont($font_face, 'B', $header_font_size);
|
||||
$pdf->Cell($table_col_width * 6, $table_line_height, 'Item', 1, 0, 'L', 1);
|
||||
$pdf->Cell($table_col_width * 2, $table_line_height, 'Quantity', 1, 0, 'R', 1);
|
||||
$pdf->Cell($table_col_width * 2, $table_line_height, 'Unit Price', 1, 0, 'R', 1);
|
||||
$pdf->Cell($table_col_width * 2, $table_line_height, 'Amount', 1, 1, 'R', 1);
|
||||
$pdf->SetFont($font_face, '', $body_font_size);
|
||||
|
||||
// build invoice items table
|
||||
if ($invoice && !empty($invoice->getItems()))
|
||||
{
|
||||
foreach ($invoice->getItems() as $item)
|
||||
{
|
||||
$pdf->Cell($table_col_width * 6, $table_line_height, $item->getTitle(), 1);
|
||||
$pdf->Cell($table_col_width * 2, $table_line_height, number_format($item->getQuantity()), 1, 0, 'R');
|
||||
$pdf->Cell($table_col_width * 2, $table_line_height, number_format($item->getPrice(), 2), 1, 0, 'R');
|
||||
$pdf->Cell($table_col_width * 2, $table_line_height, number_format($item->getPrice() * $item->getQuantity(), 2), 1, 1, 'R');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$pdf->Cell($table_col_width * 12, 7, 'No items', 1, 1);
|
||||
}
|
||||
|
||||
$pdf->Ln($line_height * 2);
|
||||
|
||||
// get current Y
|
||||
$y = $pdf->GetY();
|
||||
|
||||
$pdf->Cell($label_width, $line_height, 'Transaction Type:');
|
||||
$pdf->MultiCell($val_width, $line_height, ServiceType::getName($obj->getServiceType()), 0, 'L');
|
||||
|
||||
// insert footer totals
|
||||
$pdf->SetXY($col2_x, $y);
|
||||
$pdf->SetFont($font_face, 'B');
|
||||
$pdf->Cell($label_width, $line_height, 'SUBTOTAL:');
|
||||
$pdf->SetFont($font_face, '');
|
||||
$pdf->MultiCell(0, $line_height, number_format($invoice->getVATExclusivePrice(), 2), 0, 'R');
|
||||
|
||||
$pdf->SetX($col2_x);
|
||||
$pdf->SetFont($font_face, 'B');
|
||||
$pdf->Cell($label_width, $line_height, 'TAX:');
|
||||
$pdf->SetFont($font_face, '');
|
||||
$pdf->MultiCell(0, $line_height, number_format($invoice->getVAT(), 2), 0, 'R');
|
||||
|
||||
$pdf->SetX($col2_x);
|
||||
$pdf->SetFont($font_face, 'B');
|
||||
$pdf->Cell($label_width, $line_height, 'DISCOUNT:');
|
||||
$pdf->SetFont($font_face, '');
|
||||
$pdf->MultiCell(0, $line_height, number_format($invoice->getDiscount(), 2), 0, 'R');
|
||||
|
||||
$pdf->SetX($col2_x);
|
||||
$pdf->SetFont($font_face, 'B');
|
||||
$pdf->Cell($label_width, $line_height, 'FINAL AMOUNT:');
|
||||
$pdf->MultiCell(0, $line_height, number_format($invoice->getTotalPrice(), 2), 0, 'R');
|
||||
$pdf->SetFont($font_face, '');
|
||||
|
||||
// return response
|
||||
return new Response($pdf->Output('I', $filename), 200, [
|
||||
'Content-Type' => 'application/pdf'
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancelJobOrder(Request $req, MQTTClient $mclient, $id)
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@
|
|||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="View"><i class="la la-edit"></i></a>';
|
||||
actions += '<a href="' + row.meta.pdf_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="PDF"><i class="la la-file-o"></i></a>';
|
||||
actions += '<a href="' + row.meta.pdf_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="PDF" target="_blank"><i class="la la-file-o"></i></a>';
|
||||
|
||||
return actions;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue