/** * Parse sheet * @param \PHPExcel_Worksheet $sheet * @param bool $isEem */ private function parseSheet(\PHPExcel_Worksheet $sheet, $isEem = false) { $this->setActiveWorksheet($sheet); $map = $this->getSheetMap($this->_objExcel->getIndex($sheet)); $this->getMessageService()->addMessage("Start import sheet <i>{$sheet->getTitle()}</i>:", Message::TEXT); for ($startRow = 2; ($orgId = $this->getValueByColAndRow($map['OrganizationID'], $startRow)) == true; $startRow++) { $data = array_map(function ($col) use($startRow, $map) { return $this->getValueByColAndRow($col, $startRow); }, $map); if (isset($data['Action']) && strtoupper($data['Action']) == 'DELETED') { continue; } if (!is_numeric($data['LocationID'])) { $this->getMessageService()->addMessage('Location is not a number at line ' . $startRow, Message::WARNING); continue; } if (!$data['Organization']) { $this->getMessageService()->addMessage('Empty organization name at line ' . $startRow, Message::WARNING); continue; } if (!$data['LocationID']) { $this->getMessageService()->addMessage('Empty location id at line ' . $startRow, Message::WARNING); continue; } if (!isset($this->processedOrganizations[$orgId])) { $this->_em->getFilters()->disable('softdeleteable'); $organization = $this->_em->getRepository('CoreBundle:Organization')->findOneBy(['customerCode' => $orgId, 'customer' => $this->customer->getId()]); $this->_em->getFilters()->enable('softdeleteable'); if (!$organization) { $organization = new Entity\Organization(); $this->counters['createdOrg']++; } $organization->setName($data['Organization'])->setCustomer($this->customer)->setCustomerCode($data['OrganizationID'])->setCustomNumber1(intval($isEem))->setDeletedAt(null); $this->processedOrganizations[$orgId] = $organization; } else { $organization = $this->processedOrganizations[$orgId]; if ($organization->getName() && $this->stripValue($organization->getName()) != $this->stripValue($data['Organization'])) { $this->getMessageService()->addMessage("Different organization name for orgId = {$orgId} at line " . $startRow, Message::ERROR); continue; } } if (isset($data['Sign'])) { $organization->setSign($data['Sign']); } $this->_em->persist($organization); $this->_em->getFilters()->disable('softdeleteable'); $location = $this->_em->getRepository('CoreBundle:OrganizationLocation')->findOneBy(['organization' => $organization->getId(), 'customerCode' => $data['LocationID']]); $this->_em->getFilters()->enable('softdeleteable'); if (!$location) { $location = new Entity\OrganizationLocation(); $this->counters['createdLoc']++; } else { $this->counters['updatedLoc']++; } if (!isset($this->locationsNames[$data['LocationID']])) { $this->locationsNames[$data['LocationID']] = $this->stripValue($data['LocationName']); } else { if ($this->locationsNames[$data['LocationID']] != $this->stripValue($data['LocationName'])) { $this->getMessageService()->addMessage("Different location name for LocationId = {$data['LocationID']} at line " . $startRow, Message::ERROR); continue; } } $location->setAlias($data['LocationName'])->setOrganization($organization)->setCustomer($this->customer)->setCustomerCode((int) $data['LocationID'])->setDeletedAt(null); if (isset($data['LocationDesc'])) { $location->setCustomText1($data['LocationDesc']); } if (isset($data['AgentID'])) { $location->setCustomNumber1((int) $data['AgentID'])->setCustomText2($data['AgentName']); } if (isset($data['TimeBuffer'])) { $location->setCustomNumber2((int) $data['TimeBuffer'])->setCustomNumber3((int) $data['ADP']); } $this->_em->persist($location); //remaining locations will be soft deleted if (isset($this->vendors[$orgId]['locs'][$data['LocationID']])) { unset($this->vendors[$orgId]['locs'][$data['LocationID']]); } } }
private function addOrganizationLocation($organization, $country, $city, $addr1, $addr2, $alias, $postCode) { $orgLoc = new Entity\OrganizationLocation(); $addOrg = trim($city) . ',' . trim($addr1) . ',' . trim($addr2); $orgLoc->setOrganization($organization); $orgLoc->setCountry($this->getCountryByCode($country)); $orgLoc->setDestination($addOrg); $orgLoc->setAddress($alias); $orgLoc->setPostCode(preg_replace('#\\s#', "", $postCode)); $this->_em->persist($orgLoc); return $orgLoc; }