<?php
namespace App\EventListener;
use Pimcore\Controller\FrontendController;
use \Pimcore\Model\DataObject;
use App\Library\EmailLibrary;
use Symfony\Component\Workflow\Event\EnteredEvent;
use Symfony\Component\Workflow\Event\EnterEvent;
use Symfony\Component\Workflow\Event\AnnounceEvent;
use Pimcore\Model\Comment;
use Symfony\Component\Workflow\Event\CompletedEvent;
use Symfony\Component\Workflow\Event\LeaveEvent;
class WorkflowEvents extends FrontendController {
private $executePreviousEvents = true;
private $team = '';
private $sendComment = false;
private $commonId = '';
public function demandPlanningEmail($objectData) {
$division = $objectData->getdivision();
$productName = $objectData->getname();
$escalationEmail = new DataObject\EscalationEmails\Listing();
$escalationEmail->setCondition(" division = '$division' ");
$escalationEmail = $escalationEmail->getdata();
if(count($escalationEmail) && !empty($escalationEmail[0])) {
$escalationEmail = $escalationEmail[0];
$productId = $objectData->getId();
$emailIds = $escalationEmail->getdemandPlanningTeam();
if(!empty($emailIds)) {
$emailParam = array();
$emailParam['to'] = $emailIds;
$emailParam['subject'] = 'ITC - Product YVBYMARA';
// $emailParam['isDebug'] = true;
$templateData['product'] = $objectData;
$templateData['url'] = \Pimcore\Tool::getHostUrl().'/admin/login/deeplink?object_'.$productId.'_object';
$user = \Pimcore\Tool\Session::getReadonly()->get("user");
if (empty($user)) {
$templateData['userInfo'] = \Pimcore\Model\User::getById($user->getId());
}
$templateData['productName'] = $productName;
$emailParam['message'] = $this->render('default/email/demand_planning/yvbymara.html.twig', $templateData)->getContent();
$emailLib = new EmailLibrary();
$sendEmail = $emailLib->sendEmailNotification($emailParam);
}
}
}
public function sendEmail($team,$objectData,$wfPlace = 'correction') {
$division = $objectData->getdivision();
$productName = $objectData->getname();
$escalationEmail = new DataObject\EscalationEmails\Listing();
$escalationEmail->setCondition(" division = '$division' ");
$escalationEmail = $escalationEmail->getdata();
if(count($escalationEmail) && !empty($escalationEmail[0])) {
$escalationEmail = $escalationEmail[0];
$productId = $objectData->getId();
$attachment = array();
if($team == 'snop') {
$emailIds = $escalationEmail->getsnopTeam();
} else if($team == 'finance') {
$emailIds = $escalationEmail->getfinanceTeam();
} else if($team == 'brand') {
$emailIds = $escalationEmail->getbrandTeam();
} else if($team == 'packaging') {
$emailIds = $escalationEmail->getpackagingTeam();
} else if($team == 'indirectTax') {
$emailIds = $escalationEmail->getindirecttaxTeam();
} else if($team == 'operationsTeam') {
$emailIds = $escalationEmail->getoperationsTeam();
} else if($team == 'demandPlanningTeam') {
$emailIds = $escalationEmail->getdemandPlanningTeam();
} else if($team == 'smisTeam') {
$emailIds = $escalationEmail->getsmisTeam();
} else if($team == 'sapTeam') {
$emailIds = $escalationEmail->getsapTeam();
}
if(!empty($emailIds)) {
$emailParam = array();
$emailParam['to'] = $emailIds;
$emailParam['subject'] = 'ITC - Product Approval';
// $emailParam['isDebug'] = true;
$templateData['product'] = $objectData;
$templateData['teamEmail'] = $team;
$correction = false;
$sendBackToSnop = false;
if($wfPlace == 'correction') {
$correction = true;
$this->sendComment = true;
} else if ($wfPlace == 'sendBackToSnop') {
$sendBackToSnop = true;
}
$projectId = '';
$productId = '';
$projectTitle = '';
if (!empty($this->commonId)) {
$projectId = $this->commonId;
} else {
$projectId = $objectData->getprojectName();
}
if (!empty($projectId)) {
$projectData = DataObject\ProductByName::getById($projectId);
if (!empty($projectData)) {
$projectId = $projectData->getId();
$projectTitle = $projectData->getproductName();
} else {
$projectId = '';
}
} else {
$productId = $objectData->getId();
}
if($team == 'sapTeam' && (!empty($projectId) || !empty($productId))) {
$objId = (!empty($projectId)) ? $projectId : $productId;
$isProduct = (!empty($projectId)) ? false : true;
$lsmw = $this->saveLsmwSheetAction($objId,$isProduct);
if (!empty($lsmw)) {
$attachment[] = $lsmw;
}
$adtional = $this->saveAdditionalDataAction($objId,$isProduct);
if (!empty($adtional)) {
$attachment[] = $adtional;
}
$yvbymara = $this->saveYvbymaraAction($objId,$isProduct);
if (!empty($yvbymara)) {
$attachment[] = $yvbymara;
}
}
$templateData['url'] = \Pimcore\Tool::getHostUrl().'/admin/login/deeplink?object_'.$productId.'_object';
$templateData['projectUrl'] = (!empty($projectId)) ? \Pimcore\Tool::getHostUrl().'/admin/login/deeplink?object_'.$projectId.'_object' : '';
$templateData['productUrl'] = (!empty($productId)) ? \Pimcore\Tool::getHostUrl().'/admin/login/deeplink?object_'.$productId.'_object' : '';
$templateData['downloadUrl'] = (!empty($projectId)) ? \Pimcore\Tool::getHostUrl().'/export/teamdata?t='.md5($team).'&i='.md5($projectId) : '';
if (!empty($this->sendComment)) {
$cid = (!empty($this->commonId)) ? $this->commonId : $productId;
$dbConnection = \Pimcore\Db::get();
$notes = $dbConnection->fetchAssoc("SELECT * FROM `notes` WHERE cid = '$cid' ORDER BY `id` DESC LIMIT 1");
if(!empty($notes['description'])) {
$templateData['notes'] = nl2br($notes['description']);
}
}
$user = \Pimcore\Tool\Session::getReadonly()->get("user");
if (empty($user)) {
$templateData['userInfo'] = \Pimcore\Model\User::getById($user->getId());
}
$templateData['correction'] = $correction;
$templateData['sendBackToSnop'] = $sendBackToSnop;
$templateData['productName'] = $productName;
$templateData['team'] = $this->team;
$templateData['projectTitle'] = $projectTitle;
$emailParam['message'] = $this->render('default/escalation_email_template.html.twig', $templateData)->getContent();
$emailParam['attachment'] = (count($attachment)) ? $attachment : array();
$emailLib = new EmailLibrary();
$sendEmail = $emailLib->sendEmailNotification($emailParam);
}
}
$objectData->save();
}
public function snopCorrection($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('snop',$objectData);
}
}
public function financeCorrection($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('finance',$objectData);
}
}
public function brandCorrection($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('brand',$objectData,'correction');
}
}
public function packagingCorrection($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('packaging',$objectData);
}
}
public function indirectTaxCorrection($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('indirectTax',$objectData);
}
}
public function operationteamCorrection($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('operationsTeam',$objectData);
}
}
public function demandPlanningTeam($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('demandPlanningTeam',$objectData);
}
}
public function smisTeam($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('smisTeam',$objectData);
}
}
public function financeAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('finance',$objectData,'Finance');
}
}
public function brandAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('brand',$objectData,'Brand');
}
}
public function packagingAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('packaging',$objectData,'Packaging');
}
}
public function indirectTaxAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('indirectTax',$objectData,'Indirect Tax');
}
}
public function operationsAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('operationsTeam',$objectData,'Operations Team');
}
}
public function demandPlanningAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('demandPlanningTeam',$objectData,'Demand Planning Team');
}
}
public function smisAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('smisTeam',$objectData,'SMIS');
}
}
public function sapAction($objectData) {
if ($this->executePreviousEvents) {
$this->sendEmail('sapTeam',$objectData,'sap');
$this->demandPlanningEmail($objectData);
}
}
public function packagingToSnop($objectData) {
if ($this->executePreviousEvents) {
$this->team = 'Packaging Team';
$this->sendEmail('snop',$objectData,'sendBackToSnop');
}
}
public function financeToSnop($objectData) {
if ($this->executePreviousEvents) {
$this->team = 'Finance Team';
$this->sendEmail('snop',$objectData,'sendBackToSnop');
}
}
public function brandToSnop($objectData) {
if ($this->executePreviousEvents) {
$this->team = 'Brand Team';
$this->sendEmail('snop',$objectData,'sendBackToSnop');
}
}
public function indirectTaxToSnop($objectData) {
if ($this->executePreviousEvents) {
$this->team = 'Indirect Tax Team';
$this->sendEmail('snop',$objectData,'sendBackToSnop');
}
}
public function operationsToSnop($objectData) {
if ($this->executePreviousEvents) {
$this->team = 'Operations Team';
$this->sendEmail('snop',$objectData,'sendBackToSnop');
}
}
public function demandPlanningToSnop($objectData) {
if ($this->executePreviousEvents) {
$this->team = 'Demand Planning Team';
$this->sendEmail('snop',$objectData,'sendBackToSnop');
}
}
public function smisToSnop($objectData) {
if ($this->executePreviousEvents) {
$this->team = 'SMIS Team';
$this->sendEmail('snop',$objectData,'sendBackToSnop');
}
}
public function sapApproved($objectData) {
$folder = DataObject\Service::createFolderByPath('/Products/SAP/Approved/');
$folderId = $folder->getId();
$objectData->setParentId($folderId);
$objectData->setisProductApproved('yes');
$objectData->save();
$this->createMarketPlaceProduct($objectData);
}
public function createMarketPlaceProduct($productObj) {
$key = $productObj->getkey();
// Create Amazon DataObject
// $size = $productObj->getsize();
// $product_type = $productObj->getproduct_type();
$newObject = new DataObject\ProductAmazon();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('A_'.$key, 'object'));
// $newObject->setproduct_type($size);
// $newObject->setsize($product_type);
$newObject->setstoreProduct($productObj);
$newObject->seto_parentId('1');
$newObject->save(["versionNote" => "Product created from SAP"]);
// Create Big Basket DataObject
// $how_to_use = $productObj->gethow_to_use();
// $product_description = $productObj->getproduct_description();
$hsn_code = $productObj->gethsn_code();
if (!empty($hsn_code)) {
$hsn_code = floatval($hsn_code);
}
$newObject = new DataObject\ProductBigBasket();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('BB_'.$key, 'object'));
// $newObject->sethow_to_use($how_to_use);
// $newObject->setproduct_description($product_description);
$newObject->sethsn_code($hsn_code);
$newObject->seto_parentId('1');
$newObject->setstoreProduct($productObj);
$newObject->save(["versionNote" => "Product created from SAP"]);
// Create Blinkit DataObject
// $key_features = $productObj->getkey_features();
// $product_type = $productObj->getproduct_type();
// $price = $productObj->getprice();
// $ingredients = $productObj->getingredients();
$newObject = new DataObject\ProductBlinkit();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('BI_'.$key, 'object'));
// $newObject->setkey_features($key_features);
// $newObject->setproduct_type($product_type);
// $newObject->setprice($price);
// $newObject->setingredients($ingredients);
$newObject->seto_parentId('1');
$newObject->setstoreProduct($productObj);
$newObject->save(["versionNote" => "Product created from SAP"]);
$newObject = new DataObject\ProductFlipkart();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('FK_'.$key, 'object'));
$newObject->seto_parentId('1');
$newObject->setstoreProduct($productObj);
$newObject->save(["versionNote" => "Product created from SAP"]);
// Create JioMart DataObject
$hsn_code = $productObj->gethsn_code();
// $how_to_use = $productObj->gethow_to_use();
// $product_type = $productObj->getproduct_type();
// $ingredients = $productObj->getingredients();
// $size = $productObj->getsize();
// $food_type = $productObj->getfood_type();
$newObject = new DataObject\ProductJioMart();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('JM_'.$key, 'object'));
$newObject->sethsn_code($hsn_code);
// $newObject->sethow_to_use($how_to_use);
// $newObject->setproduct_type($product_type);
// $newObject->setingredients($ingredients);
// $newObject->setsize($size);
// $newObject->setfood_type($food_type);
$newObject->seto_parentId('1');
$newObject->setstoreProduct($productObj);
$newObject->save(["versionNote" => "Product created from SAP"]);
// Create Swiggy DataObject
$sku_name = $productObj->getmaterial_number();
$weight = $productObj->getpack_weight();
if (!empty($weight)) {
$weight = floatval($weight);
}
$newObject = new DataObject\ProductSwiggy();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('SG_'.$key, 'object'));
$newObject->setsku_name($sku_name);
$newObject->setweight($weight);
$newObject->seto_parentId('1');
$newObject->setstoreProduct($productObj);
$newObject->save(["versionNote" => "Product created from SAP"]);
// Create Zepto DataObject
$newObject = new DataObject\ProductZepto();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('Zepto_'.$key, 'object'));
$newObject->sethsn_code($hsn_code);
$newObject->seto_parentId('1');
$newObject->setstoreProduct($productObj);
$newObject->save(["versionNote" => "Product created from SAP"]);
$msku = $productObj->getold_material_number();
$sku_name = $productObj->getname();
if (!empty($msku)) {
$msku = floatval($msku);
}
$newObject = new DataObject\ProductITCStore();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('Store_'.$key, 'object'));
$newObject->seto_parentId('1');
$newObject->setmsku_itcstore($msku);
$newObject->setsku_name($sku_name);
$newObject->setproduct_title($sku_name);
$newObject->setstoreProduct($productObj);
$newObject->save(["versionNote" => "Product created from SAP"]);
// $productSyncKey = "enlwq7pkg6t2od9blt93coomo7g6p9p0"; // Live Integration
$productSyncKey = "qzgg1vbpgwk6pjctbv6ku2a65906ocpb"; // Local
// $productUpdatedUrl = 'https://integration-5ojmyuq-23txbi6folvo6.ap-3.magentosite.cloud/rest/V1/bridge/catalog/product/add';
// $productUpdatedUrl = 'http://local.itc.com/rest/V1/bridge/catalog/product/add';
// $data = array( "product_id" => $productObj->getId(),"store_view_id" => "0", );
// $data_json = json_encode(array("data" => $data));
// $curl = curl_init();
// curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
// curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
// curl_setopt($curl, CURLOPT_URL, $productUpdatedUrl);
// curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $productSyncKey, 'Accept: application/json', 'Content-Type:application/json', ));
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// $result = curl_exec($curl);
// $resultArray = json_decode($result);
// curl_close($curl);
}
public function snopEmailNotification(EnterEvent $e) {
$objectData = $e->getSubject();
$productId = $objectData->getId();
$transition = $e->getTransition();
$toPlace = $transition->getTos();
foreach ($toPlace as $key => $value) {
if($objectData->getpreviousWorkflowPlace() != 'sap_action') {
$objectData->setpreviousWorkflowPlace($value);
}
switch ($value) {
case 'packaging_to_snop':
$this->packagingToSnop($objectData);
break;
case 'finance_to_snop':
$this->financeToSnop($objectData);
break;
case 'brand_to_snop':
$this->brandToSnop($objectData);
break;
case 'indirectTax_to_snop':
$this->indirectTaxToSnop($objectData);
break;
case 'operations_to_snop':
$this->operationsToSnop($objectData);
break;
case 'demandPlanning_to_snop':
$this->demandPlanningToSnop($objectData);
break;
case 'smis_to_snop':
$this->smisToSnop($objectData);
break;
default:
# code...
break;
}
}
}
public function sapCorrectionEmails(AnnounceEvent $e) {
if ($this->executePreviousEvents) {
$this->sendComment = true;
$objectData = $e->getSubject();
$className = $objectData->getClassName();
$objectId = $objectData->getId();
$transition = $e->getTransition();
$toPlace = $transition->getTos();
if ($className == 'ProductByName') {
$products = $objectData->getproducts();
$this->commonId = $objectId;
foreach ($products as $key => $value) {
if ($key == 0) {
$this->applyTransition($value,$toPlace,true);
}
$value->setpreviousWorkflowPlace(implode(',',$toPlace));
$value->save();
$objectData->setpreviousPlace(implode(',',$toPlace));
}
} else {
$this->applyTransition($objectData,$toPlace,true);
}
$this->executePreviousEvents = false;
}
}
public function correctionEmails(CompletedEvent $e) {
if ($this->executePreviousEvents) {
$this->sendComment = true;
$objectData = $e->getSubject();
$className = $objectData->getClassName();
$objectId = $objectData->getId();
$transition = $e->getTransition();
$toPlace = $transition->getTos();
if ($className == 'ProductByName') {
$products = $objectData->getproducts();
$this->commonId = $objectId;
foreach ($products as $key => $value) {
if ($key == 0) {
$this->applyTransition($value,$toPlace,true);
}
$value->setpreviousWorkflowPlace(implode(',',$toPlace));
$value->save();
$objectData->setpreviousPlace(implode(',',$toPlace));
}
} else {
$this->applyTransition($objectData,$toPlace,true);
}
$this->executePreviousEvents = false;
}
}
public function emailNotification(EnterEvent $e) {
if ($this->executePreviousEvents) {
$objectData = $e->getSubject();
$className = $objectData->getClassName();
$transition = $e->getTransition();
$toPlace = $transition->getTos();
if ($className == 'ProductByName') {
$products = $objectData->getproducts();
$this->commonId = $objectData->getId();
foreach ($products as $key => $value) {
if ($key == 0) {
$this->applyTransition($value,$toPlace,true);
}
$value->setpreviousWorkflowPlace(implode(',',$toPlace));
$value->save();
$objectData->setpreviousPlace(implode(',',$toPlace));
}
} else {
$this->applyTransition($objectData,$toPlace,true);
}
$this->executePreviousEvents = false;
}
}
public function saveLsmwSheetAction($projectId = false,$isProduct = false) {
require_once('third_party/vendor/autoload.php');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$xlsHead = array('Material Number','Industry sector','Material type','Plant','Storage location','Sales Organization','Distribution Channel','Indicator: include first Work Schedu','Include Accounting View','Indicator: consider MRP 1 view','Indicator: consider "MRP 2"','Indicator: Consider Purchasing view','Indicator: consider Purchase Order T','Include Basic Data View','Indicator: consider "Storage" view','Indicator: consider "forecasting" vi','Include "Warehouse Management" View','Indicator: consider Sales 1 view','Indicator: consider Sales Text view','Indicator: consider Sales/Plant Data view','Indicator: take Production Resources/Tools view into acc','Indicator: consider "quality assurance" view','Indicator: Take "Costing" view into account','Indicator: take Classification view into account','Indicator: Take "Work Scheduling 2" View into Account','Indicator: Take "MRP 3" view into account','UOM','Material description','Material group','product hieararchy','Old material number','Gross weight (BTCI)','Net weight','Weight Unit','Volume','Volume unit','Ind.Std.Descr','basic material','Size/dimensions','Division','Delivering Plant','Minimum order quantity in base unit of measure (B','Cash discount indicator','Material statistics group','Item category group from material master','Product hierarchy','material group1','material group2','material group3','material group4','material group5','Pricing reference material','Material Pricing Group','Account assignment group for this material','Tax category (sales tax, federal sales tax,...)','Tax classification material','Batch management','Transportation group','Loading group','Text','Order unit','Purchasing value key','Purchasing group','Tax indicator for material (Purchasing)','Control code','Post to inspection stock','Spcial procurement key','MRP group','Valid from','MRP Type','Procurement type','Backflush','Prod. stor. location','In-house production','SchedMargin key','Planning strategy group','Consumption mode','Bwd consumption per.','MRP controller','Planned delivery time','Fiscal year variant','Safety stock','ss days','Lot size (materials planning)','Minimum lot size','Maximum lot size','Fixed lot size','Rounding value for purchase order quantity','Checking Group for Availability Check','material freight group','Period indicator','Selection method','Dependent requirements ind. for individual and coll.','prod sched profile','Under delivery','Over delivery','unltd over delivery','Production scheduler','Processing time (BTCI)','Setup time (BTCI)','Interoperation time (BTCI)','Base quantity (BTCI)','STORAGE CONDITION','Unit of issue','Price control indicator','Moving average price (BTCI)','Standard price','Price unit (BTCI)','Valuation Class','Profit Center','Origin Group as Subdivision of Cost Element','Lot Size of Product Cost Estimate (BTCI)','Material Is Costed with Quantity Structure','QM in Procurement is Active','Ind.: Repetitive mfg allowed','Certificate Type','Control Key for Quality Management in Procurement','Documentation required indicator','Variance Key','Repetitive manufacturing profile','GR processing time','Catalog Profile','Minimum Remaining Shelf Life (BTCI)','Total shelf life in days (BTCI)','Discontinuation indicator','Effective-Out Date (BTCI)','Follow-up material','Material-related origin','Interval to next periodic inspection (BTCI)','Fair share rule','Period indicator for shelf life expiration date','Selection method','Component Scrap %');
$projectName = '';
if ($projectId) {
if ($isProduct) {
$products = DataObject\Products::getById($projectId);
if (!empty($products)) {
$projectName = $products->getname().'_';
$products = array($products);
} else {
return '';
}
} else {
$products = new DataObject\ProductByName\Listing();
$products->setCondition(" o_id = $projectId ");
if (!empty($products->getdata())) {
$products = $products->getdata()[0];
$projectName = $products->getproductName().'_';
$products = $products->getproducts();
} else {
return '';
}
}
}
$col = 'A';
foreach ($xlsHead as $key => $value) {
$colIndex = $col;
$sheet->setCellValue($col++.'1', $value);
$sheet->getColumnDimension($colIndex)->setWidth(30);
}
$index = 2;
$col = 'A';
$saldistData = new DataObject\SalesAndDistribution\Listing();
$so = array(); $ds = array();
foreach ($saldistData as $key => $value) {
$so[] = $value->getsalesOrganization();
$ds[] = $value->getdistributionChannel();
}
foreach ($products as $key => $value) {
// $so = (!empty($value->getsales_organization())) ? $value->getsales_organization() : array();
// $ds = (!empty($value->getdistribution_channel())) ? $value->getdistribution_channel() : array();
$plants = array();
if (is_array($value->getplant())) {
$plants = $value->getplant();
} else {
$plants[] = $value->getplant();
}
$division = trim(strtolower($value->getdivision()));
$arrayLength = count($plants);
for ($i = 0; $i < $arrayLength; $i++) {
$plantValue = $plants[$i % count($plants)];
$soValue = $so[$i % count($so)];
$dsValue = $ds[$i % count($ds)];
$sheet->setCellValue('A'.$index, $value->getmaterial_number());
$sheet->setCellValue('B'.$index, (!empty($value->getindustry_sector()) ? $value->getindustry_sector() : 'F'));
$sheet->setCellValue('C'.$index, $value->getmaterial_type());
$sheet->setCellValue('D'.$index, $plantValue);
$storage_location = (!empty($value->getstorage_location())) ? implode(',',$value->getstorage_location()) : 'BRND';
$sheet->setCellValue('E'.$index, $storage_location);
$sheet->setCellValue('F'.$index, $soValue);
$sheet->setCellValue('G'.$index, $dsValue);
$sheet->setCellValue('H'.$index, 'X');
$sheet->setCellValue('I'.$index, 'X');
$sheet->setCellValue('J'.$index, 'X');
$sheet->setCellValue('K'.$index, 'X');
$sheet->setCellValue('L'.$index, 'X');
$sheet->setCellValue('M'.$index, 'X');
$sheet->setCellValue('N'.$index, 'X');
$sheet->setCellValue('O'.$index, 'X');
$sheet->setCellValue('P'.$index, 'X');
$sheet->setCellValue('Q'.$index, 'X');
$sheet->setCellValue('R'.$index, 'X');
$sheet->setCellValue('S'.$index, 'X');
$sheet->setCellValue('T'.$index, 'X');
$sheet->setCellValue('U'.$index, 'X');
$sheet->setCellValue('V'.$index, 'X');
$sheet->setCellValue('W'.$index, 'X');
$sheet->setCellValue('X'.$index, 'X');
$sheet->setCellValue('Y'.$index, 'X');
$sheet->setCellValue('Z'.$index, 'X');
$sheet->setCellValue('AA'.$index, $value->getuom());
$sheet->setCellValue('AB'.$index, $value->getmaterial_description());
$sheet->setCellValue('AC'.$index, $value->getmaterial_group());
$sheet->setCellValue('AD'.$index, $value->getproduct_hieararchy());
$sheet->setCellValue('AE'.$index, $value->getold_material_number());
$net_weight = (!empty($value->getnet_weight())) ? $value->getnet_weight() : 1.000;
$wu = $net_weight;
if ($division == 'ss') {
$sheet->setCellValue('AF'.$index, $value->getpack_weight());
$sheet->setCellValue('AG'.$index, $value->getpack_weight());
} else {
$sheet->setCellValue('AF'.$index, $wu);
$sheet->setCellValue('AG'.$index, $net_weight);
}
$sheet->setCellValue('AH'.$index, (!empty($value->getweight_unit()) ? $value->getweight_unit() : 'KG'));
$vlume = '';
if(!empty($value->getlength()) && !empty($value->getbreadth()) && !empty($value->getheight()) && !empty($value->getcfcweightgross())) {
$vlume = ($value->getlength() * $value->getbreadth() * $value->getheight()) / $value->getcfcweightgross();
$vlume = round($vlume,3);
}
$sheet->setCellValue('AI'.$index, $vlume);
$sheet->setCellValue('AJ'.$index, (!empty($value->getvolume_unit()) ? $value->getvolume_unit() : 'M3'));
$sheet->setCellValue('AK'.$index, '');
$sheet->setCellValue('AL'.$index, '');
$sheet->setCellValue('AM'.$index, '');
$sheet->setCellValue('AN'.$index, $value->getdivision());
$sheet->setCellValue('AO'.$index, '');
$gw = $value->getcfcweightgross();
if(!empty($gw)) {
$gw = number_format((float)$gw, 3, '.', '');
}
if ($division == 'ss') {
$sheet->setCellValue('AP'.$index, '');
} else {
$sheet->setCellValue('AP'.$index, $gw);
}
$sheet->setCellValue('AQ'.$index, (!empty($value->getcash_discount_indicator()) ? $value->getcash_discount_indicator() : "X"));
$sheet->setCellValue('AR'.$index, (!empty($value->getmaterial_statistics_group()) ? $value->getmaterial_statistics_group() : '1'));
$sheet->setCellValue('AS'.$index, (!empty($value->getitem_category_group()) ? $value->getitem_category_group() : 'NORM'));
$sheet->setCellValue('AT'.$index, $value->getproduct_hieararchy());
$sheet->setCellValue('AU'.$index, (!empty($value->getmaterial_group1()) ? $value->getmaterial_group1() : 'GFP'));
$sheet->setCellValue('AV'.$index, $value->getmaterial_group2());
$sheet->setCellValue('AW'.$index, $value->getmaterial_group3());
$sheet->setCellValue('AX'.$index, $value->getmaterial_group4());
$sheet->setCellValue('AY'.$index, $value->getmaterial_group5());
$sheet->setCellValue('AZ'.$index, '');
$sheet->setCellValue('BA'.$index, $value->getmaterial_pricing_group());
$sheet->setCellValue('BB'.$index, $value->getaccount_assignment());
$sheet->setCellValue('BC'.$index, (!empty($value->gettax_category()) ? $value->gettax_category() : 'JOIG'));
$sheet->setCellValue('BD'.$index, (!empty($value->gettax_classification_material()) ? $value->gettax_classification_material() : '0'));
$sheet->setCellValue('BE'.$index, (!empty($value->getbatch_management()) ? $value->getbatch_management() : 'X'));
$sheet->setCellValue('BF'.$index, (!empty($value->gettransportation_group()) ? $value->gettransportation_group() : 'Z001'));
$sheet->setCellValue('BG'.$index, (!empty($value->getloading_group()) ? $value->getloading_group() : '0001'));
$sheet->setCellValue('BH'.$index, '');
$sheet->setCellValue('BI'.$index, '');
$sheet->setCellValue('BJ'.$index, '');
$sheet->setCellValue('BK'.$index, $value->getpurchasing_group());
$sheet->setCellValue('BL'.$index, '');
$sheet->setCellValue('BM'.$index, $value->gethsn_code());
$sheet->setCellValue('BN'.$index, '');
$sheet->setCellValue('BO'.$index, '');
$sheet->setCellValue('BP'.$index, '');
$sheet->setCellValue('BQ'.$index, '');
$sheet->setCellValue('BR'.$index, (!empty($value->getmrp_type()) ? $value->getmrp_type() : 'X0'));
if ($division == 'ss') {
$sheet->setCellValue('BS'.$index, '');
$sheet->setCellValue('BU'.$index, '');
} else {
$sheet->setCellValue('BS'.$index, $value->getprocurement_type());
$sheet->setCellValue('BU'.$index, $value->getproduction_storage_location());
}
$sheet->setCellValue('BT'.$index, '');
$sheet->setCellValue('BV'.$index, '');
$sheet->setCellValue('BW'.$index, (!empty($value->getschedmargin_key()) ? $value->getschedmargin_key() : '000'));
$sheet->setCellValue('BX'.$index, '');
$sheet->setCellValue('BY'.$index, '');
$sheet->setCellValue('BZ'.$index, '');
$sheet->setCellValue('CA'.$index, $value->getmrp_controller());
$sheet->setCellValue('CB'.$index, '');
$sheet->setCellValue('CC'.$index, '');
$sheet->setCellValue('CD'.$index, '');
if ($division == 'ss') {
$sheet->setCellValue('CE'.$index, '');
} else {
$sheet->setCellValue('CE'.$index, (!empty($value->getss_days()) ? $value->getss_days() : '4'));
}
$sheet->setCellValue('CF'.$index, (!empty($value->getlot_size()) ? $value->getlot_size() : 'EX'));
$minimum_lot_size = (!empty($value->getminimum_lot_size()) ? $value->getminimum_lot_size() : $value->getcfcweightgross());
if ($division == 'ss') {
$sheet->setCellValue('CG'.$index, '');
} else {
$sheet->setCellValue('CG'.$index, $minimum_lot_size); // fixed value = CFC wt
}
$mls = (!empty($value->getmaximum_lot_size()) ? $value->getmaximum_lot_size() : $value->getcfcweightgross()*10000);
if ($division == 'ss') {
$sheet->setCellValue('CH'.$index, '');
} else {
$sheet->setCellValue('CH'.$index, $mls); // fixed value = CFC wt *10000
}
$sheet->setCellValue('CI'.$index, '');
$rv = (!empty($value->getrounding_value()) ? $value->getrounding_value() : $value->getcfcweightgross());
if ($division == 'ss') {
$sheet->setCellValue('CJ'.$index, '');
} else {
$sheet->setCellValue('CJ'.$index, $rv); //fixed value = CFC wt
}
$sheet->setCellValue('CK'.$index, '02');
$sheet->setCellValue('CL'.$index, (!empty($value->getmaterial_freight_group()) ? $value->getmaterial_freight_group() : '0'));
$sheet->setCellValue('CM'.$index, (!empty($value->getperiod_indicator()) ? $value->getperiod_indicator() : 'M'));
$sheet->setCellValue('CN'.$index, (!empty($value->getselection_method()) ? $value->getselection_method() : '2'));
$sheet->setCellValue('CO'.$index, '');
$sheet->setCellValue('CP'.$index, '');
$sheet->setCellValue('CQ'.$index, '');
$sheet->setCellValue('CR'.$index, '');
$sheet->setCellValue('CS'.$index, '');
$sheet->setCellValue('CT'.$index, '');
$sheet->setCellValue('CU'.$index, '');
$sheet->setCellValue('CV'.$index, '');
$sheet->setCellValue('CW'.$index, '');
$sheet->setCellValue('CX'.$index, '');
$sheet->setCellValue('CY'.$index, '01');
$sheet->setCellValue('CZ'.$index, '');
$sheet->setCellValue('DA'.$index, 'V');
$sheet->setCellValue('DB'.$index, '');
$sheet->setCellValue('DC'.$index, '');
$sheet->setCellValue('DD'.$index, '1');
$sheet->setCellValue('DE'.$index, $value->getvaluation_class());
$sheet->setCellValue('DF'.$index, $value->getprofit_center());
$sheet->setCellValue('DG'.$index, $value->getvaluation_class());
$sheet->setCellValue('DH'.$index, '1000'); //$value->getlot_size_of_product_cost()
$sheet->setCellValue('DI'.$index, 'X'); //$value->getmaterial_cost()
$sheet->setCellValue('DJ'.$index, '');
$sheet->setCellValue('DK'.$index, '');
$sheet->setCellValue('DL'.$index, '');
$sheet->setCellValue('DM'.$index, '');
$sheet->setCellValue('DN'.$index, 'X');
$sheet->setCellValue('DO'.$index, '000001'); //$value->getvariance_key()
$sheet->setCellValue('DP'.$index, '');
$sheet->setCellValue('DQ'.$index, '');
$sheet->setCellValue('DR'.$index, 'FBD000001'); //$value->getcatalog_profile()
$sheet->setCellValue('DS'.$index, $value->getminimum_remaining_shelf_life());
$sheet->setCellValue('DT'.$index, $value->gettotal_shelf_life());
$sheet->setCellValue('DU'.$index, '');
$sheet->setCellValue('DV'.$index, '');
$sheet->setCellValue('DW'.$index, '');
$mro = (!empty($value->getmaterial_related_origin())) ? implode(',',$value->getmaterial_related_origin()) : 'X';
$sheet->setCellValue('DX'.$index, $mro);
$sheet->setCellValue('DY'.$index, '');
$sheet->setCellValue('DZ'.$index, '');
$sheet->setCellValue('EA'.$index, 'D');
$sheet->setCellValue('EB'.$index, '2');
$sheet->setCellValue('EC'.$index, '');
// $sheet->setCellValue('ED'.$index, $value->getpack_weight());
// $sheet->setCellValue('EE'.$index, $value->getcfcweight());
$index++;
$col++;
}
}
$xlsName = $projectName.'LSMW_';
$fileName = (!empty($xlsName)) ? $xlsName.date('d M').'.xlsx' : 'Products'.date('d M').'.xlsx';
$folderName = '';
try {
if (!is_dir('product')) {
mkdir('product/',0777);
$folderName = 'product/';
} else if (is_dir('product')) {
$folderName = 'product/';
} else {
$folderName = '';
}
} catch (\Throwable $th) {
$folderName = '';
}
try {
unlink($folderName.$fileName);
} catch (\Throwable $th) {
}
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($folderName.$fileName);
return $folderName.$fileName;
}
public function saveYvbymaraAction($projectId,$isProduct = false) {
require_once('third_party/vendor/autoload.php');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
if ($projectId) {
if ($isProduct) {
$products = DataObject\Products::getById($projectId);
if (!empty($products)) {
$projectName = $products->getname().'_';
$products = array($products);
} else {
return '';
}
} else {
$products = new DataObject\ProductByName\Listing();
$products->setCondition(" o_id = $projectId ");
if (!empty($products->getdata())) {
$products = $products->getdata()[0];
$projectName = $products->getproductName().'_';
$products = $products->getproducts();
} else {
return '';
}
}
}
$xlsHead = array('MSKU','Material','DISCRIPTION','VARIANT','VARIANT_DESCR','SUBCAT','SUBCAT_DESCR','BRAND','CROSSPROMOITC','CROSSPROMONON_ITC','NICHE_NON_NICHE','ATTRIBUTE_Y');
$col = 'A';
foreach ($xlsHead as $key => $value) {
$colIndex = $col;
$sheet->setCellValue($col++.'1', $value);
$sheet->getColumnDimension($colIndex)->setWidth(30);
}
$index = 2;
$col = 'A';
foreach ($products as $key => $value) {
$sheet->setCellValue('A'.$index, $value->getold_material_number());
$sheet->setCellValue('B'.$index, $value->getmaterial_number());
$sheet->setCellValue('C'.$index, $value->getmaterial_description());
$sheet->setCellValue('D'.$index, $value->getvariant());
$sheet->setCellValue('E'.$index, $value->getvariant_description());
$sheet->setCellValue('F'.$index, $value->getsubcat());
$sheet->setCellValue('G'.$index, $value->getsubcat_descr());
$sheet->setCellValue('H'.$index, $value->getbrand());
$sheet->setCellValue('I'.$index, $value->getcross_promo_itc());
$sheet->setCellValue('J'.$index, $value->getcross_promo_nonitc());
$sheet->setCellValue('K'.$index, $value->getniche_non_niche());
$sheet->setCellValue('L'.$index, $value->getattribute_y());
$index++;
}
$xlsName = $projectName.'YVBYMARA_'.date('d M').'.xlsx';
$fileName = $xlsName;
$folderName = '';
try {
if (!is_dir('product')) {
mkdir('product/',0777);
$folderName = 'product/';
} else if (is_dir('product')) {
$folderName = 'product/';
} else {
$folderName = '';
}
} catch (\Throwable $th) {
$folderName = '';
}
try {
unlink($folderName.$fileName);
} catch (\Throwable $th) {
//echo $th; exit;
}
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($folderName.$fileName);
return $folderName.$fileName;
}
public function saveAdditionalDataAction($projectId = false, $isProduct = false) {
require_once('third_party/vendor/autoload.php');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$xlsHead = array('Material','view','EAN','Z1','BG','Z1 DISC','BG DISC','ST Denominator','PAC Denominator','CFC Denominator','ST','PAC','CFC','ST Numerator','PAC Numerator','CFC Numerator','L','B','H','M','M3','M3/KG Denominator','M3/KG','M3/KG Numerator','HE','vajra');
if ($projectId) {
if ($isProduct) {
$products = DataObject\Products::getById($projectId);
if (!empty($products)) {
$projectName = $products->getname().'_';
$products = array($products);
} else {
return '';
}
} else {
$products = new DataObject\ProductByName\Listing();
$products->setCondition(" o_id = $projectId ");
if (!empty($products->getdata())) {
$products = $products->getdata()[0];
$projectName = $products->getproductName().'_';
$products = $products->getproducts();
} else {
return '';
}
}
}
$col = 'A';
foreach ($xlsHead as $key => $value) {
$colIndex = $col;
$sheet->setCellValue($col++.'1', $value);
$sheet->getColumnDimension($colIndex)->setWidth(30);
}
$index = 2;
$col = 'A';
foreach ($products as $key => $value) {
$sheet->setCellValue('A'.$index, $value->getmaterial_number());
$sheet->setCellValue('B'.$index, 'X');
$sheet->setCellValue('C'.$index, $value->getean_number());
$sheet->setCellValue('D'.$index, 'Z1');
$sheet->setCellValue('E'.$index, "BG");
$sheet->setCellValue('F'.$index, $value->getzi_disc());
$sheet->setCellValue('G'.$index, $value->getbg_disc());
$sheet->setCellValue('H'.$index, '1');
$sheet->setCellValue('I'.$index, '1000');
$sheet->setCellValue('J'.$index, '1000');
$sheet->setCellValue('K'.$index, 'ST');
$sheet->setCellValue('L'.$index, 'PAC');
$sheet->setCellValue('M'.$index, 'CFC');
$sheet->setCellValue('N'.$index, '1');
$sheet->setCellValue('O'.$index, $value->getpack_weight());
$gw = $value->getcfcweightgross();
if(!empty($gw)) {
$gw = number_format((float)$gw, 3, '.', '');
}
$sheet->setCellValue('P'.$index, $gw);
$sheet->setCellValue('Q'.$index, $value->getlength());
$sheet->setCellValue('R'.$index, $value->getbreadth());
$sheet->setCellValue('S'.$index, $value->getheight());
$sheet->setCellValue('T'.$index, 'M');
$sheet->setCellValue('U'.$index, 'M3');
$v = '';
if(!empty($value->getlength()) && !empty($value->getbreadth()) * !empty($value->getheight())) {
$v = round(($value->getlength()*$value->getbreadth()*$value->getheight()),3);
}
$sheet->setCellValue('V'.$index, $v);
$sheet->setCellValue('W'.$index, 'M3');
$sheet->setCellValue('X'.$index, $gw);
$sheet->setCellValue('Y'.$index, 'HE');
$sheet->setCellValue('Z'.$index, $value->getvajra_description());
$index++;
}
$xlsName = $projectName.'Additional_Data_';
$fileName = (!empty($xlsName)) ? $xlsName.date('d M').'.xlsx' : 'Additional_Data'.date('d M').'.xlsx';
$folderName = '';
try {
if (!is_dir('product')) {
mkdir('product/',0777);
$folderName = 'product/';
} else if (is_dir('product')) {
$folderName = 'product/';
} else {
$folderName = '';
}
} catch (\Throwable $th) {
$folderName = '';
}
try {
unlink($folderName.$fileName);
} catch (\Throwable $th) {
//echo $th; exit;
}
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($folderName.$fileName);
return $folderName.$fileName;
}
public function applyTransition($objectData,$toPlace,$isProductClass = true) {
foreach ($toPlace as $key => $value) {
if ($isProductClass) {
// if($objectData->getpreviousWorkflowPlace() != 'sap_action' || $value != 'sap_action') {
$objectData->setpreviousWorkflowPlace($value);
// }
}
switch ($value) {
case 'finance_action':
$this->financeAction($objectData);
break;
case 'brand_action':
$this->brandAction($objectData);
break;
case 'packaging_action':
$this->packagingAction($objectData);
break;
case 'indirect_tax_action':
$this->indirectTaxAction($objectData);
break;
case 'operations_action':
$this->operationsAction($objectData);
break;
case 'demand_planning_action':
$this->demandPlanningAction($objectData);
break;
case 'smis_action':
$this->smisAction($objectData);
break;
case 'sap_action':
$this->sapAction($objectData);
break;
case 'packaging_to_snop':
$this->packagingToSnop($objectData);
break;
case 'finance_to_snop':
$this->financeToSnop($objectData);
break;
case 'brand_to_snop':
$this->brandToSnop($objectData);
break;
case 'indirectTax_to_snop':
$this->indirectTaxToSnop($objectData);
break;
case 'operations_to_snop':
$this->operationsToSnop($objectData);
break;
case 'demandPlanning_to_snop':
$this->demandPlanningToSnop($objectData);
break;
case 'smis_to_snop':
$this->smisToSnop($objectData);
break;
case 'packaging_correction':
$this->packagingCorrection($objectData);
break;
case 'finance_correction':
$this->financeCorrection($objectData);
break;
case 'brand_correction':
$this->brandCorrection($objectData);
break;
case 'indirectTax_correction':
$this->indirectTaxCorrection($objectData);
break;
case 'operations_correction':
$this->operationteamCorrection($objectData);
break;
case 'demandPlanning_correction':
$this->demandPlanningTeam($objectData);
break;
case 'smis_correction':
$this->smisTeam($objectData);
break;
case 'snop_correction':
$this->snopCorrection($objectData);
break;
case 'sap_approved':
$this->sapApproved($objectData);
break;
case 'snop_packaging_correction':
$this->packagingCorrection($objectData);
break;
case 'snop_finance_correction':
$this->financeCorrection($objectData);
break;
case 'snop_brand_correction':
$this->brandCorrection($objectData);
break;
case 'snop_indirectTax_correction':
$this->indirectTaxCorrection($objectData);
break;
case 'snop_operations_correction':
$this->operationteamCorrection($objectData);
break;
case 'snop_demandPlanning_correction':
$this->demandPlanningTeam($objectData);
break;
case 'snop_smis_correction':
$this->smisTeam($objectData);
break;
default:
# code...
break;
}
}
}
}