Move generate PDF form to the job order service. #270
This commit is contained in:
parent
7de72e2ca3
commit
2f555483be
4 changed files with 759 additions and 352 deletions
|
|
@ -890,364 +890,22 @@ class JobOrderController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function pdfForm(Request $req, $id, TranslatorInterface $translator)
|
public function pdfForm(Request $req, $id, JobOrderHandlerInterface $jo_handler)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('jo_pdf.list', null, 'No access.');
|
$this->denyAccessUnlessGranted('jo_pdf.list', null, 'No access.');
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
try
|
||||||
|
|
||||||
// get row data
|
|
||||||
$obj = $em->getRepository(JobOrder::class)->find($id);
|
|
||||||
|
|
||||||
// make sure this row exists
|
|
||||||
if (empty($obj))
|
|
||||||
throw $this->createNotFoundException('The job order does not exist');
|
|
||||||
|
|
||||||
// set output filename
|
|
||||||
$filename = 'job-order-' . $obj->getID() . '.pdf';
|
|
||||||
|
|
||||||
// translate the title and the logo for the pdf
|
|
||||||
$translated_title = $translator->trans('jo_title_pdf');
|
|
||||||
$translated_logo = $translator->trans('image_jo_pdf');
|
|
||||||
|
|
||||||
// generate the pdf
|
|
||||||
$pdf = new FPDF('P', 'mm', 'letter');
|
|
||||||
$pdf->AddPage();
|
|
||||||
$pdf->setTitle($translated_title . ' #' . $obj->getID());
|
|
||||||
$pdf->SetFillColor(211, 211, 211);
|
|
||||||
|
|
||||||
// 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 = 40;
|
|
||||||
$val_width = 60;
|
|
||||||
|
|
||||||
// insert the logo
|
|
||||||
$image_path = $this->get('kernel')->getProjectDir() . $translated_logo;
|
|
||||||
$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 ? $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 && $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 && $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 && $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 && $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() ? $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() && $battery->getModel() && $battery->getSize() ? $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 transaction details
|
|
||||||
$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, 'Warranty Class:');
|
|
||||||
$pdf->MultiCell($val_width, $line_height, WarrantyClass::getName($obj->getWarrantyClass()), 0, 'L');
|
|
||||||
|
|
||||||
// get Y after left cell
|
|
||||||
$y1 = $pdf->GetY();
|
|
||||||
|
|
||||||
$pdf->SetXY($col2_x, $y);
|
|
||||||
$pdf->Cell($label_width, $line_height, 'Mode of Payment:');
|
|
||||||
$pdf->MultiCell(0, $line_height, ModeOfPayment::getName($obj->getModeOfPayment()), 0, 'L');
|
|
||||||
|
|
||||||
// get Y after right cell
|
|
||||||
$y2 = $pdf->GetY();
|
|
||||||
|
|
||||||
// get row height
|
|
||||||
$y = max($y1, $y2);
|
|
||||||
|
|
||||||
$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() ? $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->getProcessedBy() ? $obj->getProcessedBy()->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)
|
$proj_path = $this->get('kernel')->getProjectDir();
|
||||||
{
|
$params = $jo_handler->generatePDFForm($req, $id, $proj_path);
|
||||||
$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
|
catch (NotFoundHttpException $e)
|
||||||
{
|
{
|
||||||
$pdf->Cell($table_col_width * 12, 7, 'No items', 1, 1);
|
throw $this->createNotFoundException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$pdf->Ln($line_height * 2);
|
$pdf = $params['obj'];
|
||||||
|
$filename = $params['filename'];
|
||||||
// get current Y
|
|
||||||
$y = $pdf->GetY();
|
|
||||||
|
|
||||||
// insert invoice footer details
|
|
||||||
$pdf->Cell($label_width, $line_height, 'Transaction Type:');
|
|
||||||
$pdf->MultiCell($val_width, $line_height, ServiceType::getName($obj->getServiceType()), 0, 'L');
|
|
||||||
|
|
||||||
// get Y after left cell
|
|
||||||
$y1 = $pdf->GetY();
|
|
||||||
|
|
||||||
$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, $invoice ? number_format($invoice->getVATExclusivePrice(), 2) : '', 0, 'R');
|
|
||||||
|
|
||||||
// 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, 'OR Name:');
|
|
||||||
$pdf->MultiCell($val_width, $line_height, $obj->getORName(), 0, 'L');
|
|
||||||
|
|
||||||
// get Y after left cell
|
|
||||||
$y1 = $pdf->GetY();
|
|
||||||
|
|
||||||
$pdf->SetXY($col2_x, $y);
|
|
||||||
$pdf->SetFont($font_face, 'B');
|
|
||||||
$pdf->Cell($label_width, $line_height, 'TAX:');
|
|
||||||
$pdf->SetFont($font_face, '');
|
|
||||||
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getVAT(), 2) : '', 0, 'R');
|
|
||||||
|
|
||||||
// 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, 'Emp. ID/Card No./Ref. By:');
|
|
||||||
$pdf->MultiCell($val_width, $line_height, $obj->getPromoDetail(), 0, 'L');
|
|
||||||
|
|
||||||
// get Y after left cell
|
|
||||||
$y1 = $pdf->GetY();
|
|
||||||
|
|
||||||
$pdf->SetXY($col2_x, $y);
|
|
||||||
$pdf->SetFont($font_face, 'B');
|
|
||||||
$pdf->Cell($label_width, $line_height, 'DISCOUNT:');
|
|
||||||
$pdf->SetFont($font_face, '');
|
|
||||||
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getDiscount(), 2) : '', 0, 'R');
|
|
||||||
|
|
||||||
// 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, 'Discount Type:');
|
|
||||||
$pdf->MultiCell($val_width, $line_height, $invoice && $invoice->getPromo() ? $invoice->getPromo()->getName() : '', 0, 'L');
|
|
||||||
|
|
||||||
$pdf->SetXY($col2_x, $y);
|
|
||||||
$pdf->SetFont($font_face, 'B');
|
|
||||||
$pdf->Cell($label_width, $line_height, 'FINAL AMOUNT:');
|
|
||||||
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getTotalPrice(), 2) : '', 0, 'R');
|
|
||||||
$pdf->SetFont($font_face, '');
|
|
||||||
|
|
||||||
// return response
|
// return response
|
||||||
return new Response($pdf->Output('I', $filename), 200, [
|
return new Response($pdf->Output('I', $filename), 200, [
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Service\JobOrderHandler;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
@ -49,18 +50,25 @@ use Mosquitto\Client as MosquittoClient;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
|
|
||||||
|
use FPDF;
|
||||||
|
|
||||||
class CMBJobOrderHandler implements JobOrderHandlerInterface
|
class CMBJobOrderHandler implements JobOrderHandlerInterface
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $ic;
|
protected $ic;
|
||||||
|
protected $security;
|
||||||
|
protected $validator;
|
||||||
|
protected $translator;
|
||||||
|
|
||||||
public function __construct(Security $security, EntityManagerInterface $em,
|
public function __construct(Security $security, EntityManagerInterface $em,
|
||||||
InvoiceGeneratorInterface $ic, ValidatorInterface $validator)
|
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
||||||
|
TranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->ic = $ic;
|
$this->ic = $ic;
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates/updates job order
|
// creates/updates job order
|
||||||
|
|
@ -1357,6 +1365,371 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generate pdf form for job order
|
||||||
|
public function generatePDFForm($req, $id, $proj_path)
|
||||||
|
{
|
||||||
|
$em = $this->em;
|
||||||
|
$translator = $this->translator;
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$obj = $em->getRepository(JobOrder::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw new NotFoundHttpException('The job order does not exist');
|
||||||
|
|
||||||
|
// set output filename
|
||||||
|
$filename = 'job-order-' . $obj->getID() . '.pdf';
|
||||||
|
|
||||||
|
// translate the title and the logo for the pdf
|
||||||
|
$translated_title = $translator->trans('jo_title_pdf');
|
||||||
|
$translated_logo = $translator->trans('image_jo_pdf');
|
||||||
|
|
||||||
|
// generate the pdf
|
||||||
|
$pdf = new FPDF('P', 'mm', 'letter');
|
||||||
|
$pdf->AddPage();
|
||||||
|
$pdf->setTitle($translated_title . ' #' . $obj->getID());
|
||||||
|
$pdf->SetFillColor(211, 211, 211);
|
||||||
|
|
||||||
|
// 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 = 40;
|
||||||
|
$val_width = 60;
|
||||||
|
|
||||||
|
// insert the logo
|
||||||
|
$image_path = $proj_path . $translated_logo;
|
||||||
|
$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 ? $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 && $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 && $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 && $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 && $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() ? $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() && $battery->getModel() && $battery->getSize() ? $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 transaction details
|
||||||
|
$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, 'Warranty Class:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, WarrantyClass::getName($obj->getWarrantyClass()), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->Cell($label_width, $line_height, 'Mode of Payment:');
|
||||||
|
$pdf->MultiCell(0, $line_height, ModeOfPayment::getName($obj->getModeOfPayment()), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after right cell
|
||||||
|
$y2 = $pdf->GetY();
|
||||||
|
|
||||||
|
// get row height
|
||||||
|
$y = max($y1, $y2);
|
||||||
|
|
||||||
|
$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() ? $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->getProcessedBy() ? $obj->getProcessedBy()->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();
|
||||||
|
|
||||||
|
// insert invoice footer details
|
||||||
|
$pdf->Cell($label_width, $line_height, 'Transaction Type:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, ServiceType::getName($obj->getServiceType()), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$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, $invoice ? number_format($invoice->getVATExclusivePrice(), 2) : '', 0, 'R');
|
||||||
|
|
||||||
|
// 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, 'OR Name:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, $obj->getORName(), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->SetFont($font_face, 'B');
|
||||||
|
$pdf->Cell($label_width, $line_height, 'TAX:');
|
||||||
|
$pdf->SetFont($font_face, '');
|
||||||
|
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getVAT(), 2) : '', 0, 'R');
|
||||||
|
|
||||||
|
// 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, 'Emp. ID/Card No./Ref. By:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, $obj->getPromoDetail(), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->SetFont($font_face, 'B');
|
||||||
|
$pdf->Cell($label_width, $line_height, 'DISCOUNT:');
|
||||||
|
$pdf->SetFont($font_face, '');
|
||||||
|
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getDiscount(), 2) : '', 0, 'R');
|
||||||
|
|
||||||
|
// 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, 'Discount Type:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, $invoice && $invoice->getPromo() ? $invoice->getPromo()->getName() : '', 0, 'L');
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->SetFont($font_face, 'B');
|
||||||
|
$pdf->Cell($label_width, $line_height, 'FINAL AMOUNT:');
|
||||||
|
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getTotalPrice(), 2) : '', 0, 'R');
|
||||||
|
$pdf->SetFont($font_face, '');
|
||||||
|
|
||||||
|
$params['obj'] = $pdf;
|
||||||
|
$params['filename'] = $filename;
|
||||||
|
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
protected function fillDropdownParameters(&$params)
|
protected function fillDropdownParameters(&$params)
|
||||||
{
|
{
|
||||||
$em = $this->em;
|
$em = $this->em;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Service\JobOrderHandler;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
@ -49,18 +50,25 @@ use Mosquitto\Client as MosquittoClient;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
|
|
||||||
|
use FPDF;
|
||||||
|
|
||||||
class ResqJobOrderHandler implements JobOrderHandlerInterface
|
class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $ic;
|
protected $ic;
|
||||||
|
protected $security;
|
||||||
|
protected $validator;
|
||||||
|
protected $translator;
|
||||||
|
|
||||||
public function __construct(Security $security, EntityManagerInterface $em,
|
public function __construct(Security $security, EntityManagerInterface $em,
|
||||||
InvoiceGeneratorInterface $ic, ValidatorInterface $validator)
|
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
||||||
|
TranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->ic = $ic;
|
$this->ic = $ic;
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates/updates job order
|
// creates/updates job order
|
||||||
|
|
@ -1357,6 +1365,371 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generate pdf form for job order
|
||||||
|
public function generatePDFForm($req, $id, $proj_path)
|
||||||
|
{
|
||||||
|
$em = $this->em;
|
||||||
|
$translator = $this->translator;
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$obj = $em->getRepository(JobOrder::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw new NotFoundHttpException('The job order does not exist');
|
||||||
|
|
||||||
|
// set output filename
|
||||||
|
$filename = 'job-order-' . $obj->getID() . '.pdf';
|
||||||
|
|
||||||
|
// translate the title and the logo for the pdf
|
||||||
|
$translated_title = $translator->trans('jo_title_pdf');
|
||||||
|
$translated_logo = $translator->trans('image_jo_pdf');
|
||||||
|
|
||||||
|
// generate the pdf
|
||||||
|
$pdf = new FPDF('P', 'mm', 'letter');
|
||||||
|
$pdf->AddPage();
|
||||||
|
$pdf->setTitle($translated_title . ' #' . $obj->getID());
|
||||||
|
$pdf->SetFillColor(211, 211, 211);
|
||||||
|
|
||||||
|
// 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 = 40;
|
||||||
|
$val_width = 60;
|
||||||
|
|
||||||
|
// insert the logo
|
||||||
|
$image_path = $proj_path . $translated_logo;
|
||||||
|
$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 ? $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 && $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 && $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 && $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 && $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() ? $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() && $battery->getModel() && $battery->getSize() ? $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 transaction details
|
||||||
|
$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, 'Warranty Class:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, WarrantyClass::getName($obj->getWarrantyClass()), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->Cell($label_width, $line_height, 'Mode of Payment:');
|
||||||
|
$pdf->MultiCell(0, $line_height, ModeOfPayment::getName($obj->getModeOfPayment()), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after right cell
|
||||||
|
$y2 = $pdf->GetY();
|
||||||
|
|
||||||
|
// get row height
|
||||||
|
$y = max($y1, $y2);
|
||||||
|
|
||||||
|
$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() ? $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->getProcessedBy() ? $obj->getProcessedBy()->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();
|
||||||
|
|
||||||
|
// insert invoice footer details
|
||||||
|
$pdf->Cell($label_width, $line_height, 'Transaction Type:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, ServiceType::getName($obj->getServiceType()), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$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, $invoice ? number_format($invoice->getVATExclusivePrice(), 2) : '', 0, 'R');
|
||||||
|
|
||||||
|
// 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, 'OR Name:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, $obj->getORName(), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->SetFont($font_face, 'B');
|
||||||
|
$pdf->Cell($label_width, $line_height, 'TAX:');
|
||||||
|
$pdf->SetFont($font_face, '');
|
||||||
|
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getVAT(), 2) : '', 0, 'R');
|
||||||
|
|
||||||
|
// 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, 'Emp. ID/Card No./Ref. By:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, $obj->getPromoDetail(), 0, 'L');
|
||||||
|
|
||||||
|
// get Y after left cell
|
||||||
|
$y1 = $pdf->GetY();
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->SetFont($font_face, 'B');
|
||||||
|
$pdf->Cell($label_width, $line_height, 'DISCOUNT:');
|
||||||
|
$pdf->SetFont($font_face, '');
|
||||||
|
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getDiscount(), 2) : '', 0, 'R');
|
||||||
|
|
||||||
|
// 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, 'Discount Type:');
|
||||||
|
$pdf->MultiCell($val_width, $line_height, $invoice && $invoice->getPromo() ? $invoice->getPromo()->getName() : '', 0, 'L');
|
||||||
|
|
||||||
|
$pdf->SetXY($col2_x, $y);
|
||||||
|
$pdf->SetFont($font_face, 'B');
|
||||||
|
$pdf->Cell($label_width, $line_height, 'FINAL AMOUNT:');
|
||||||
|
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getTotalPrice(), 2) : '', 0, 'R');
|
||||||
|
$pdf->SetFont($font_face, '');
|
||||||
|
|
||||||
|
$params['obj'] = $pdf;
|
||||||
|
$params['filename'] = $filename;
|
||||||
|
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
protected function fillDropdownParameters(&$params)
|
protected function fillDropdownParameters(&$params)
|
||||||
{
|
{
|
||||||
$em = $this->em;
|
$em = $this->em;
|
||||||
|
|
|
||||||
|
|
@ -66,4 +66,7 @@ interface JobOrderHandlerInterface
|
||||||
|
|
||||||
// initialize rider form
|
// initialize rider form
|
||||||
public function initializeRiderForm(int $id);
|
public function initializeRiderForm(int $id);
|
||||||
|
|
||||||
|
// generate pdf form for job order
|
||||||
|
public function generatePDFForm(Request $req, int $id, string $proj_path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue