<?php
/**
* Created by PhpStorm.
* Date: 11/6/20
* Time: 10:26 AM
*/
namespace DevelopmentBundle\EventListener;
use DevelopmentBundle\Compliance\AssociateCompliance;
use DevelopmentBundle\Development\Development;
use DevelopmentBundle\Development\Generate\DevelopmentSku;
use DevelopmentBundle\Product\Product;
use DevelopmentBundle\Validation\Validate;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Model\Asset;
use Pimcore\Model\DataObject;
use Pimcore\Model\Element\ValidationException;
use Pimcore\Tool\Admin;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\Registry;
class WorkflowListener implements EventSubscriberInterface
{
protected $workflowRegistry;
const DEVELOPMENT_DIRECTORY = PIMCORE_PROJECT_ROOT . '/var/pdf/';
const PDF_DIRECTORY = PIMCORE_PROJECT_ROOT . '/public/var/assets';
/**
* WorkflowListener constructor.
* @param Registry $workflowRegistry
*/
public function __construct(
Registry $workflowRegistry
)
{
$this->workflowRegistry = $workflowRegistry;
}
/**
* @param GuardEvent $event
*/
public function guardPublish(GuardEvent $event): void
{
$objects = $event->getSubject();
if ('variant' == $objects->gettype()) { // Workflow action is blocked on variant level
$event->setBlocked(true);
}
if ($objects->getModel() == null || $objects->getTier3() == null) {
$event->setBlocked(true);
}
}
public function onLeave(Event $event): void
{
/** @var \Pimcore\Model\DataObject\Development $object */
$object = $event->getSubject();
$eventTransition = $event->getTransition();
$transitionName = $eventTransition->getName();
if ($transitionName == "set_compliances") {
$compliance = new AssociateCompliance();
$compliance->processAssociateCompliance($object);
}
if ($transitionName == "review_ready") {
$this->checkComplianceValidation($object);
}
if ($transitionName == 'create_sku') {
$this->checkComplianceValidation($object);
$this->checkProductValidation($object);
$this->developmentSku($object);
$this->getProductTierTree($object);
}
if ($transitionName == 'create_paf') {
$this->checkComplianceValidation($object);
}
if ($transitionName == "create_paf") {
$html = $this->createPDFHTML($object);
$pdf = \Pimcore\Web2Print\Processor::getInstance()->getPdfFromString($html);
$finalPdf = "";
$filename = $this->generatePDFFilename($object->getDevelopmentNumber()) . ".pdf";
foreach ($object->getAnnexRelation() as $annex) {
$finalPdf = $annex->getFullPath();
}
if ($finalPdf != null || !empty($finalPdf)) {
file_put_contents(
self::DEVELOPMENT_DIRECTORY . $filename,
$pdf
);
$pdf = new \Clegginabox\PDFMerger\PDFMerger;
$pdf->addPDF(self::DEVELOPMENT_DIRECTORY . $filename, 'all');
$pdf->addPDF(self::PDF_DIRECTORY . $finalPdf, 'all');
$pdf->merge('file', self::DEVELOPMENT_DIRECTORY . $filename, 'P');
$newAsset = new \Pimcore\Model\Asset();
$newAsset->setFilename($filename);
$newAsset->setData(file_get_contents(self::DEVELOPMENT_DIRECTORY . $filename));
$newAsset->setParent(\Pimcore\Model\Asset::getByPath("/Epaf"));
$newAsset->save();
} else {
$newAsset = new \Pimcore\Model\Asset();
$newAsset->setFilename($filename);
$newAsset->setData($pdf);
$newAsset->setParent(\Pimcore\Model\Asset::getByPath("/Epaf"));
$newAsset->save();
file_put_contents(
self::DEVELOPMENT_DIRECTORY . $filename,
$pdf
);
}
}
}
/**
* @return array|\string[][]
*/
public static function getSubscribedEvents()
{
return [
'workflow.Development_Workflow.guard' => ['guardPublish'],
'workflow.Development_Workflow.leave' => ['onLeave'],
];
}
/**
* @param ElementEventInterface $event
*
* @throws \Pimcore\Model\Element\ValidationException
*/
public function onPreUpdate(ElementEventInterface $event): void
{
if ($event instanceof DataObjectEvent) {
$object = $event->getObject();
if ($object instanceof DataObject\Development) {
/** @var \Pimcore\Model\DataObject\Development $object */
$this->checkValidation($object);
$user = Admin::getCurrentUser();
if ($user != null) {
$user = \Pimcore\Tool\Session::getReadonly()->get("user");
$devObj = $object->setCategoryManager(strtok($user->getEmail(), '@'));
// $object->save();
}
}
}
}
/**
* @param ElementEventInterface $event
* Set inital workflow state to sku_created to avoid further workflow on variant
*/
public function postAdd(ElementEventInterface $event): void
{
if ($event instanceof DataObjectEvent) {
// do something with the object
$object = $event->getObject();
// if ($object instanceof DataObject\Labels) {
// $newObj = $object->setLabelName(basename($object->getFullPath()));
// $object->save();
// }
// if ($object instanceof DataObject\BillOfMaterials) {
// $billObj = $object->setDescription(basename($object->getFullPath()));
// $object->save();
// }
// if ($object instanceof DataObject\Components) {
// $comObj = $object->setDescription(basename($object->getFullPath()));
// $object->save();
// }
}
}
/**
* @param $objects
*/
public function checkValidation($objects): void
{
if ($objects instanceof DataObject\Development and 'variant' != $objects->gettype()) {
if ($objects->getSkipValidation()) {
if ($objects instanceof DataObject\Development and 'variant' != $objects->gettype()) {
if (($objects->getDevelopmentNumber() != null || $objects->getDevelopmentNumber() != "")) {
$objects->setSkipValidation(false);
$objects->setOmitMandatoryCheck(true);
} else {
$complianceValidation = new Validate();
$complianceValidation->preCheckValidate($objects);
}
}
} else {
$complianceValidation = new Validate();
$complianceValidation->preUpdateValidate($objects);
}
if ('variant' != $objects->gettype()) {
if (($objects->getDevelopmentNumber() != null && $objects->getDevelopmentNumber() != "")) {
$this->getDevelopmentName($objects);
}
}
}
}
/**
* @param $objects
* @throws ValidationException
*/
public function checkComplianceValidation($objects): void
{
$complianceValidation = new Validate();
$complianceValidation->complianceValidation($objects);
}
/**
* @param $object
* @throws ValidationException
*/
public function checkProductValidation($object): void
{
$productValidation = new Validate();
$productValidation->productCreateValidation($object);
}
/**
* @param $objects
*/
public function getDevelopmentName($objects): void
{
$developmentKey = new Development();
$developmentKey->developmentKey($objects);
// $compliance = new AssociateCompliance();
// $compliance->processAssociateCompliance($objects);
}
/**
* @param $object
*/
public function developmentSku($object): void
{
$developmentSku = new DevelopmentSku();
$developmentSku->processDevelopmentSku($object);
}
/**
* @param $object
*/
public function getProductTierTree($object): void
{
$productCreate = new Product();
$productCreate->processProduct($object);
}
/**
* @param $object
* @return string
*/
public function getWorkflowStatus($object): string
{
$workflow = $this->workflowRegistry->get($object, 'Development_Workflow');
return implode(', ', array_keys($workflow->getMarking($object)->getPlaces()));
}
public function preSendData(GenericEvent $event): void
{
$object = $event->getArgument("object");
$data = $event->getArgument("data");
if ($object instanceof DataObject\Development && !($object instanceof DataObject\Folder)) {
$layout = json_encode($data["layout"]);
$new_layout = $this->getPdfData($object, $layout);
if ($object->getDevelopmentNumber() != null && $object->getModel() != null && $object->getTier3() != null && $object->getBillOfMaterials() != null) {
$cloneObj = $this->getCloneData($object);
$new_layout = preg_replace('/' . $cloneObj['from'] . '/', $cloneObj['to'], $new_layout, 1);
}
$data['layout'] = json_decode($new_layout);
$event->setArgument("data", $data);
}
}
private function getPdfData($object, $new_layout): string|array|null
{
$workflow = $this->workflowRegistry->get($object, 'Development_Workflow');
$workflowState = array_keys($workflow->getMarking($object)->getPlaces());
if ($object->getDevelopmentNumber() != null && $workflowState[0] == "PAF_Created") {
$pdfFileName = $this->generatePDFFilename($object->getDevelopmentNumber());
if (file_exists(self::DEVELOPMENT_DIRECTORY . $pdfFileName . '.pdf')) {
$from_man_property = '"handler":""';
$to_man_property = '"handler":"(function() {\nExt.Ajax.request({\nurl: \"development\/downloadepaf\",\nbinary: true,\nmethod: \"POST\",\nparams: {dev_no: \"' . $pdfFileName . '\"},\nsuccess: function (response) {\nvar blob=new Blob([response.responseBytes], {type: \'arraybuffer\'});\nvar link=document.createElement(\'a\');\nlink.href=window.URL.createObjectURL(blob);\nlink.download=\"' . $pdfFileName . '.pdf\";\nlink.click();\nconsole.log(response);\n}\n});\n});"';
} else {
$from_man_property = '"handler":""';
$to_man_property = '"handler":"(function() {\nalert(\"PDF document is not found\");\n});"';
}
} else {
$from_man_property = '"handler":""';
$to_man_property = '"handler":"(function() {\nalert(\"Epaf document is not generated yet\");\n});"';
}
$new_layout = preg_replace('/' . $from_man_property . '/', $to_man_property, $new_layout, 1);
return $new_layout;
}
private function getCloneData($object): void
{
$cloneObj = [];
$developmentNo = $object->getDevelopmentNumber();
$clone_property = '"handler":"hello"';
// $to_clone_property = '"handler":"(function() {\nExt.Ajax.request({\nurl: \"development\/cloneobject\",\nmethod: \"POST\",\nparams: {dev_no: \"' . $developmentNo . '\"},\nsuccess: function (response) {\nconsole.log(response);\n}\n});\n});"';
// $cloneObj['from'] = $clone_property;
// $cloneObj['to'] = $to_clone_property;
// return $cloneObj;
}
private function createPDFHTML($object): string
{
$html = "<html lang=\"en\"> <head><base href=\'" . \Pimcore\Tool::getHostUrl() . "\'> <meta charset=\"utf-8\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"> <title>Tables</title> <style> .container{ width: 960px; margin: 50px auto; } </style> </head> <body> <div class=\"container\"> <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-width: 1px 1px 0 1px; border-collapse: collapse; margin: 0 0 30px 0;\">";
$html .= "<thead> <tr> <th colspan=\"6\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap;\"><img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . "/Developments/headLogo.jpg") . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . "/Developments/headLogo.jpg")) . "alt=\"...\" width=\"120\" height=\"auto\"></th> </tr> </thead> <tbody> <tr> <td colspan=\"6\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 30px; font-weight: bold; color: #000000; text-transform: uppercase;\">Product Approval Form</td> </tr> <tr> <td rowspan=\"" . $this->getRow($object, 'sku') . "\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">SKU/Colour:</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">SKU number</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">";
$html .= "Colour</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">PMS colour/finish</td> <td colspan=\"2\" rowspan=\" " . $this->getRow($object, 'image') . " \" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $this->generateMultipleImages($object) . "</td> </tr>" . $this->getVariantsData($object) . " ";
$html .= "<tr><td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Product Name:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"> " . $object->getProductName() . " </td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Dev't Number:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getDevelopmentNumber() . " </td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Vendor/Factory:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"> " . $object->getVendorFactory() . " </td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Market:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getMarket() . "</td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">TOTAL PRICE(USD):</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\" bgcolor=\"#ebf1de\"> $" . $object->getTotalPriceUSD() . " </td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">FOB Port:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"> " . $object->getFobPort() . " </td> </tr> <tr>";
$html .= "<td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">MOQ:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"> " . $object->getMoq() . " </td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Payment Terms:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"> " . $object->getPaymentTerm() . " </td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Production Time:</td> <td colspan=\"3\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getProductionTime() . "</td> ";
$html .= "<td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Common:</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getCommon() . "</td> </tr> <tr> <td colspan=\"4\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Handling Charge/Vendor Notes:</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Similar</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal; font-style: italic;\">" . $object->getSimilar() . "</td> </tr> <tr> <td colspan=\"4\" style=\"border: solid thin; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\"> " . $this->generateComponentHTML($object) . " </td> <td colspan=\"4\" style=\"border: solid thin; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\"> <table width=\"100%\" border=\"0\" height=\"232\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse;\"> <tbody>";
$html .= " <tr> <td width=\"125\" style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Price Validity:</td> <td align=\"right\" style=\"border: solid thin; border-width: 0 0 1px 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getPriceValidatity() . "</td> </tr> <tr> <td width=\"125\" style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Packaging:</td> <td align=\"right\" style=\"border: solid thin; border-width: 0 0 1px 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getPacking() . "</td> </tr> <tr> <td width=\"125\" style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Instructions:</td> <td align=\"right\" style=\"border: solid thin; border-width: 0 0 1px 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getInstructions() . "</td> </tr> <tr> <td width=\"125\" style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Batterys(s):</td> <td align=\"right\" style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getBattery() . "</td> </tr> </tbody> </table>";
$html .= " </td> </tr> </tbody> </table>" . $this->generateBillOfMaterialsHTML($object) . "</tr></tbody> </table>" . $this->generateProductDecs($object) . " " . $this->generateSpecificationHTML($object) . " ";
$html .= " " . $this->generateComplianceHTML($object) . "</tr><tr><td style=\"border: solid thin; padding: 0.5rem 0.5rem; white - space: nowrap; font - family: Helvetica, Arial, sans - serif; font - size: 14px; font - weight: normal;\"></td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white - space: nowrap; font - family: Helvetica, Arial, sans - serif; font - size: 14px; font - weight: normal;\"></td> <td colspan=\"2\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white - space: nowrap; font - family: Helvetica, Arial, sans - serif; font - size: 14px; font - weight: normal;\">Notified body required?</td></tr></tbody></table> " . $this->generateLabelHTML($object) . " </tbody> </table><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <thead> <tr> <th colspan=\"2\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #000000; text-transform: uppercase;\">Manual</th> </tr> </thead> <tbody> <tr> <td width=\"50%\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"><b>LEGAL TEXT ON MANUAL</b> <i>In " . $this->getManualData($object) . "</i></td> <td width=\"50%\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">PHOTO</td> </tr> <tr> <td width=\"50%\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $this->getLanguageSize($object->getLanguageManual()) . " languages MANUAL<br>" . $object->getSpeficationsManual() . "<br>Techincal specification and safety percautions on manual.</td> <td width=\"50%\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $this->getHideImage($object, $object->getManualImage()) . "</td> </tr> </tbody> </table> <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <thead> <tr> <th colspan=\"4\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #000000; text-transform: uppercase;\">Packaging</th> </tr> </thead> <tbody> <tr> <td colspan=\"2\" width=\"50%\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal; word-wrap: break-word\">Packing Details:<br>" . $object->getPackagingDetails() . "</td> <td colspan=\"2\" rowspan=\"4\" width=\"50%\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"><ul><li>Curabitur laoreet nibh vel dui egestas, sed maximus tellus pellentesque.</li><li>Ut sit amet elit a lorem euismod bibendum.</li><li>Vestibulum a eros in enim consequat dignissim a ut nisi.</li><li>Mauris at ex lacinia lectus tincidunt cursus eu imperdiet turpis.</li><li>Pellentesque facilisis turpis molestie mi sodales, sed tincidunt orci facilisis.</li></ul></td> ";
$html .= "</tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Master Carton Size:</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getMasterCartonSize() . "CM</td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Qty per Carton</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getQuantityPerCarton() . "</td> </tr> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">N.W. / G.W.:</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: break-spaces; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $object->getNettoGrossWeight() . "</td> </tr> </tbody> </table> <!-- Approvals --> <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <thead> <tr> <th colspan=\"4\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #000000; text-transform: uppercase;\">Approvals</th> </tr> </thead> <tbody> <tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Category Manager:<br><br>Date:</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"></td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">PD Merchandiser Stela Cai<br><br>Date: 2020/05/29</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Vendor: Mossloo<br><br>Date: Miya</td> </tr> </tbody> </table> </div> </body></html>";
return $html;
}
private function getLanguageSize($language): int
{
if ($language != null || !empty($language)) {
return sizeof($language);
}
return 0;
}
private function getImageData($object, $image): string
{
if ($image != null || !empty($image)) {
$image = Asset\Image::getByPath($image);
return $image->getFullPath();
}
return '';
}
private function getVariantsData($development): string
{
$skuHTML = " ";
foreach ($development->getChildren([DataObject\AbstractObject::OBJECT_TYPE_VARIANT]) as $child) {
$skuHTML .= "<tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $child->getSku() . "</td><td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $child->getColor1Code() . "</td><td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\"></td></tr>";
}
return $skuHTML;
}
private function generateComponentHTML($object): string
{
$componentData = $object->getComponents();
$counter = 1;
$componentHTML = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse;\"> <tbody> <tr> <td style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Component</td> <td style=\"border: solid thin; border-width: 0 0 1px 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Breakdown</td> <td style=\"border: solid thin; border-width: 0 0 1px 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Weight (gr):</td> <td style=\"border: solid thin; border-width: 0 0 1px 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Price</td> </tr> <tr>";
foreach ($componentData as $component) {
$componentHTML .= "<td style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Component " . $counter . "</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $component->getDescription() . " </td> <td bgcolor=\"#ebf1de\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap;\">" . $component->getWeight() . "</td> <td bgcolor=\"#ebf1de\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">" . $component->getPrice() . "</td> </tr> ";
$counter++;
}
$componentHTML .= "<tr> <td colspan=\"4\" style=\"border: solid thin; border-width: 0; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">Consolidation Fee: " . $object->getConsolidationFeeUSD() . " </td></tr>";
$componentHTML .= "</tbody></table>";
return $componentHTML;
}
private function generateBillOfMaterialsHTML($object): string
{
$BOMData = $object->getBillOfMaterials();
$bomCounter = 1;
$BOMHtml = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <thead> <tr> <th colspan=\"4\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #000000; text-transform: uppercase;\">Bill of Materials</th> </tr> </thead> <tbody><tr>";
foreach ($BOMData as $billOfMaterials) {
$BOMHtml .= "<td width=\"20\" align=\"center\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $bomCounter . "</td> <td width=\"400\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $billOfMaterials->getDescription() . "</td>";
$bomCounter++;
if ($bomCounter % 2 == 1) {
$BOMHtml .= "</tr><tr>";
}
}
return $BOMHtml;
}
private function generateComplianceHTML($object): string
{
$technicalComplianceData = $object->getTechnicalCompliance();
$chemicalComplianceData = $object->getChemicalCompliance();
$conditionData = $object->getConditions();
$arrayCount = 1;
$CompliancesHTML = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <thead> <tr> <th colspan=\"4\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #000000; text-transform: uppercase;\">Compliance Requirements</th> </tr> </thead> <tbody> <tr>";
foreach ($technicalComplianceData as $technicalData) {
if ($technicalData != null || !empty($technicalData)) {
$CompliancesHTML .= "<td width=\"20\" align=\"center\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $arrayCount . "</td> <td width=\"350\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $technicalData->getDescription() . "</td>";
$arrayCount++;
}
if ($arrayCount % 2 == 1) {
$CompliancesHTML .= "</tr><tr>";
}
if ($arrayCount - 1 == sizeof($technicalComplianceData)) {
break;
}
}
foreach ($chemicalComplianceData as $chemicalData) {
if ($chemicalData != null || !empty($chemicalData)) {
$CompliancesHTML .= "<td width=\"20\" align=\"center\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $arrayCount . "</td> <td width=\"350\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $chemicalData->getDescription() . "</td>";
$arrayCount++;
}
if ($arrayCount % 2 == 1) {
$CompliancesHTML .= "</tr><tr>";
}
if ($arrayCount - 1 == sizeof($chemicalComplianceData)) {
break;
}
}
foreach ($conditionData as $condition) {
if ($condition != null || !empty($condition)) {
$CompliancesHTML .= "<td width=\"20\" align=\"center\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $arrayCount . "</td> <td width=\"350\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $condition->getDescription() . "</td>";
$arrayCount++;
}
if ($arrayCount % 2 == 1) {
$CompliancesHTML .= "</tr><tr>";
}
if ($arrayCount - 1 == sizeof($conditionData)) {
break;
}
}
return $CompliancesHTML;
}
private function generateLabelHTML($object): string
{
$labelsData = $object->getLabels();
$labelHTML = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <thead> <tr> <th colspan=\"6\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #000000; text-transform: uppercase;\">Label</th> </tr> </thead> <tbody>";
$labelHTML .= "<tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\"></td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Label Name</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Size (Cm)</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\"></td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Label Name</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold;\">Size (Cm)</td> </tr>";
$labelCount = 1;
if ($labelsData != null || !empty($labelsData)) {
foreach ($labelsData as $label) {
if ($labelCount % 2 == 1) {
$labelHTML .= "<tr> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $labelCount . "</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $label->getLabelName() . "</td>";
$labelCount++;
continue;
}
if ($labelCount % 2 == 0) {
$labelHTML .= "<td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $label->getLabelSize() . "</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $labelCount . "</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $label->getLabelName() . "</td> <td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" . $label->getLabelSize() . "</td> </tr>";
$labelCount++;
continue;
}
}
}
$labelHTML .= "<tr> <td colspan=\"3\" align=\"center\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold; text-transform: uppercase;\">Label Front</td> <td colspan=\"3\" align=\"center\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold; text-transform: uppercase;\">Label Back</td> </tr> ";
$labelHTML .= "<tr> <td colspan=\"3\" height=\"80\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" .
$this->getHideImage($object, $object->getLabelImageFront()) . "
</td>
<td colspan=\"3\" height=\"80\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal;\">" .
$this->getHideImage($object, $object->getLabelImageBack()) . "</td> </tr>";
return $labelHTML;
}
private function getManualData($object): string
{
$manualData = $object->getLanguageManual();
if ($manualData) {
$manual = implode(", ", array_filter($manualData));
$saveManual = $manual;
$last = strrchr($saveManual, ",");
$last_ = str_replace(",", " &", $last);
return str_replace("$last", "$last_", $saveManual);
}
}
private function getRow($object, $field): int
{
if ($field == 'image') {
$value = 9 + sizeof($object->getChildren([DataObject\AbstractObject::OBJECT_TYPE_VARIANT]));
return $value;
}
if ($field == 'sku') {
$value = 1 + sizeof($object->getChildren([DataObject\AbstractObject::OBJECT_TYPE_VARIANT]));
return $value;
}
}
private function generateMultipleImages($object): string
{
$imgHTML = " <img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage1())) . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage1()))) . "alt=\"...\" width=\"190\" height=\"190\"> ";
$imgHTML2 = " <img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage2())) . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage2()))) . "alt=\"...\" width=\"190\" height=\"190\"> ";
$imgHTML3 = " <img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage3())) . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage3()))) . "alt=\"...\" width=\"190\" height=\"190\"> ";
$imgHTML4 = " <img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage4())) . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage4()))) . "alt=\"...\" width=\"190\" height=\"190\"> ";
if (($object->getImage1() != null || !empty($object->getImage1())) && ($object->getImage2() == null || empty($object->getImage2())) && ($object->getImage3() == null || empty($object->getImage3())) && ($object->getImage4() == null || empty($object->getImage4()))) {
return $imgHTML;
} elseif (($object->getImage1() != null || !empty($object->getImage1())) && ($object->getImage2() != null || !empty($object->getImage2())) && ($object->getImage3() == null || empty($object->getImage3())) && ($object->getImage4() == null || empty($object->getImage4()))) {
$allImage = " <img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage1())) . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage1()))) . "alt=\"...\" width=\"410\" height=\"230\"> " . "<br>" .
" <img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage2())) . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . $this->getImageData($object, $object->getImage2()))) . " alt=\"...\" width=\"410\" height=\"230\"> ";
return $allImage;
} else {
$allImage = $imgHTML . $imgHTML2 . "<br>" . $imgHTML3 . $imgHTML4;
return $allImage;
}
}
private function generateSpecificationHTML($object): string
{
if ($object->getSpeficationsManual() != null || !empty($object->getSpeficationsManual())) {
$specificationHTML = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <thead> <tr> <th colspan=\"6\" align=\"center\" bgcolor=\"#c0c0c0\" style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #000000; text-transform: uppercase;\">Specifications:</th> </tr> </thead> <tbody> <tr><td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal; word-wrap: break-word\"> " . $object->getSpeficationsManual() . "</td></tr></tbody></table>";
return $specificationHTML;
}
return '';
}
private function generateProductDecs($object): string
{
if ($object->getProductDescription() != null || !empty($object->getProductDescription())) {
$prodDescHTML = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid thin; border-collapse: collapse; margin: 0 0 30px 0;\"> <tbody> <tr><td style=\"border: solid thin; padding: 0.5rem 0.5rem; white-space: nowrap; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal; word-wrap: break-word\">Description: " . $object->getProductDescription() . " </td></tr></tbody></table>";
return $prodDescHTML;
}
return '';
}
protected function generatePDFFilename($developmentNum): string
{
$pdfFileName = str_replace(":", "_", $developmentNum);
$pdfFileName = str_replace("-", "_", $pdfFileName);
return $pdfFileName;
}
protected function getHideImage($object, $data): string
{
if ($this->getImageData($object, $data) != null || !empty($this->getImageData($object, $data))) {
$imageData = "<img src=\"data: " . mime_content_type(self::PDF_DIRECTORY . $this->getImageData($object, $data)) . ";base64," .
base64_encode(file_get_contents(self::PDF_DIRECTORY . $this->getImageData($object, $data))) . "\" width='400' height='400'>";
} else {
$imageData = '';
}
return $imageData;
}
}