public function createAction() { $params = $this->getRequest()->getParams(); $existance = $this->checkSupplierExistanceByNameAndRfc(null, $params['name'], $params['rfc']); if ($existance['exists']) { $this->setFlash('warning', $existance['message']); $this->_redirect('supplier/list'); } $cardcode = $this->createCardcode($params['Currency']); $connectorClient = new SAPConnectorClient(); $sapSupplier = SapSupplierFactory::createFromArray($params); $sapSupplier->setCardCode($cardcode); //die("<pre>".print_r($sapSupplier, true)."</pre"); $array = array(); $sapSupplierContactEmployeeCollection = new SapSupplierContactEmployeeCollection($array); $sapSupplierAddressCollection = new SapSupplierAddressCollection($array); foreach ($params['contact'] as $contact) { if (!empty($contact['FirstName'])) { $sapSupplierContactEmployee = SapSupplierContactEmployeeFactory::createFromArray($contact); $sapSupplierContactEmployee->setCardCode($cardcode); $sapSupplierContactEmployeeCollection->append($sapSupplierContactEmployee); } } if (!empty($params['Street'])) { $sapSupplierAddress = SapSupplierAddressFactory::createFromArray($params); $sapSupplierAddress->setCardcode($cardcode); $sapSupplierAddressCollection->append($sapSupplierAddress); } $sapSupplier->setContacts($sapSupplierContactEmployeeCollection); $sapSupplier->setAddresses($sapSupplierAddressCollection); $result = $connectorClient->createSupplier($sapSupplier); if ($result->SapProveedorResult->success) { $setupForm = 'SetupForm'; $profileForm = 'ProfileForm'; $auditReport = 'AuditReport'; $this->getSupplierCatalog()->beginTransaction(); $this->savefileAction($setupForm, SapSupplier::$FileTypes[$setupForm], $sapSupplier->getCardcode()); $this->savefileAction($profileForm, SapSupplier::$FileTypes[$profileForm], $sapSupplier->getCardcode()); $this->savefileAction($auditReport, SapSupplier::$FileTypes[$auditReport], $sapSupplier->getCardcode()); // print_r(SupplierFileQuery::create()->whereAdd(SupplierFile::ID_SUPPLIER, $sapSupplier->getCardcode())->find()->toArray()); $this->getSupplierCatalog()->commit(); $this->setFlash("ok", $this->i18n->_($result->SapProveedorResult->message)); } else { $this->setFlash("error", $this->i18n->_($result->SapProveedorResult->message)); $this->_redirect('supplier/list'); } $this->setFlash("ok", $this->i18n->_("The supplier {$cardcode} has been created")); $this->_redirect('supplier/list'); }