/** Override __construct() because we're not passing user/pass */ public function __construct() { $user = new Customer(); $user->record_type = Customer::GUEST; $user->last_login = new CDbExpression('NOW()'); if ($user->save() === false) { print_r($user->getErrors()); } $this->setState('fullname', 'Guest'); $this->setState('firstname', 'Guest'); $this->_id = $user->id; }
/** * Authenticate user * @return type */ public function authenticate() { $user = Customer::model()->findByAttributes(array('facebook' => $this->password)); if ($user instanceof Customer) { $this->loginHousekeeping($user); } else { //We didn't find the Facebook ID in the database, but let's see if the user has an account already $user = Customer::model()->findByAttributes(array('email' => $this->username)); if ($user instanceof Customer) { //We found an existing account under this email if (is_null($user->facebook)) { //We found an account, merge them $user->facebook = $this->password; $user->save(); $this->loginHousekeeping($user); } else { //Somehow we've found an existing account with an email from facebook but not the same ID //Clear Facebook ID and bail, this is a serious conflict $user->facebook = $this->password; $user->save(); $this->redirect(Yii::app()->homeUrl); } } else { //New user to our site using Facebook, so set up an account $model = new Customer(); $model->scenario = 'createfb'; $results = Yii::app()->facebook->api('/me'); $model->first_name = $results['first_name']; $model->last_name = $results['last_name']; $model->email = $results['email']; $model->email_repeat = $results['email']; $model->record_type = Customer::REGISTERED; $model->newsletter_subscribe = 1; $model->facebook = $results['id']; if (_xls_get_conf('MODERATE_REGISTRATION', 0) == 1) { $this->errorCode = self::ERROR_NOT_APPROVED; $model->allow_login = Customer::UNAPPROVED_USER; } else { $model->allow_login = Customer::NORMAL_USER; if (!$model->save()) { Yii::log("Error creating Facebook account " . print_r($model->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); die("A serious error has occurred creating a Facebook account"); } $this->loginHousekeeping($model); } } } return $this->errorCode; }
public function actionUpload() { parent::actionUpload(); $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/'; // folder for uploaded files $allowedExtensions = array("csv"); $sizeLimit = (int) Yii::app()->params['sizeLimit']; // maximum file size in bytes $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $result = $uploader->handleUpload($folder, true); $row = 0; if (($handle = fopen($folder . $uploader->file->getName(), "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row > 0) { $model = Customer::model()->findByPk((int) $data[0]); if ($model === null) { $model = new Customer(); } $model->addressbookid = (int) $data[0]; $model->fullname = $data[1]; $model->recordstatus = (int) $data[2]; try { if (!$model->save()) { $errormessage = $model->getErrors(); if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage)); } } } catch (Exception $e) { $errormessage = $e->getMessage(); if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage)); } } } $row++; } fclose($handle); } $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES); echo $result; }
public function actionRequestPickUp() { $req = Yii::app()->request; $shipment_id = $req->getQuery('shipment_id'); if (!isset($_POST['Booking'])) { echo CJSON::encode($this->statusError('Must be in POST method')); Yii::app()->end(); } $booking = new Booking(); $booking->setAttributes($_POST['Booking']); $booking->setAttribute('booking_code', dechex(time())); if ($shipment_id != null) { $shipment = Shipment::model()->findByPk($shipment_id); if (!$shipment instanceof Shipment) { echo CJSON::encode($this->statusError('Your Shipment is invalid')); Yii::app()->end(); } } $trans = Yii::app()->db->beginTransaction(); try { if ($booking->save()) { if (isset($shipment) && $shipment instanceof Shipment) { Booking::model()->updateByPk($booking->id, array('customer_id' => $shipment->customer_id)); $shipment->setAttribute('booking_id', $booking->id); if (!$shipment->save()) { throw ServiceControllerException($shipment->getErrors()); } } else { if ($this->token instanceof Token) { $customer = Customer::model()->findByPk($this->token->customer_id); if (!$customer instanceof Customer) { throw new ServiceControllerException('You have to login first'); } else { Booking::model()->updateByPk($booking->id, array('customer_id' => $customer->id)); } } else { $customer = new Customer(); $customer->name = $booking->name; $customer->type = 'personal'; $customer->accountnr = 'WEB' . time(); if ($customer->save()) { $contact = new Contact(); $contact->parent_id = $customer->id; $contact->parent_model = 'Customer'; $contact->full_name = $booking->name; $contact->address = $booking->address; $contact->country = $booking->country; $contact->city = $booking->city; $contact->postal = $booking->postal; if ($contact->save()) { Booking::model()->updateByPk($booking->id, array('customer_id' => $customer->id)); } else { throw new ServiceControllerException($contact->getErrors()); } } else { throw new ServiceControllerException($customer->getErrors()); } } } $data = array('booking_code' => $booking->booking_code); } else { throw ServiceControllerException($booking->getErrors()); } $trans->commit(); } catch (ServiceControllerException $e) { $errors = $e->errors; $trans->rollback(); echo CJSON::encode($this->statusError($errors)); Yii::app()->end(); } echo CJSON::encode($this->statusSuccess($data)); Yii::app()->end(); }
public function actionEditableCreator() { if (isset($_POST['Customer'])) { $model = new Customer(); $model->attributes = $_POST['Customer']; if ($model->save()) { echo CJSON::encode($model->getAttributes()); } else { $errors = array_map(function ($v) { return join(', ', $v); }, $model->getErrors()); echo CJSON::encode(array('errors' => $errors)); } } else { throw new CHttpException(400, 'Invalid request'); } }
/** * 添加顾客 */ public function actionAddCust() { $user_model = new User(); $addr_model = new Address(); $cust_model = new Customer(); $custhi_model = new Cust_Health_Info(); if (isset($_POST["User"]) && isset($_POST["Customer"])) { $user_model->attributes = $_POST["User"]; //设定用户种别为:顾客 $user_model->usr_kind = 2; //设定用户密码为:xyz123456 $user_model->usr_password = md5("xyz123456"); $user_model->user_chg_pwd_old = "oldpassword"; $user_model->user_chg_pwd_new = "newpassword"; $user_model->user_chg_pwd_new_cfm = "newpassword"; //设置用户头像的默认值 if ($user_model->usr_pic_id == '') { $user_model->usr_pic_id = '100000'; } if ($user_model->save()) { $cust_model->attributes = $_POST["Customer"]; //customer表里面的主键是user表的外键,user表的外键又是自增的,所以要先保存完user表才能保存customer表 $cust_model->pk_cust_id = $user_model->pk_usr_id; //将作为用户名的手机号填入顾客信息里 $cust_model->cust_mobile1 = $_POST['User']['usr_username']; //将用户喜爱的项目按位计算并保存 $cust_prefer = 0; //如果啥都没选的话,下记字符串应该为空,否则为数组(内容为数字) if ($_POST['Customer']['cust_prefer'] != '') { for ($i = 0; $i < count($_POST['Customer']['cust_prefer']); $i++) { if ($_POST['Customer']['cust_prefer'][$i]) { $cust_prefer |= (int) $_POST['Customer']['cust_prefer'][$i]; } } } else { $cust_prefer = 0; } $cust_model->cust_prefer = $cust_prefer; //将用户喜爱的美疗师按位计算并保存 $cust_beautician = 0; //如果啥都没选的话,下记字符串应该为空,否则为字符串数组(内容为数字) if ($_POST['Customer']['cust_beautician'] != '') { for ($i = 0; $i < count($_POST['Customer']['cust_beautician']); $i++) { if ($_POST['Customer']['cust_beautician'][$i]) { $cust_beautician |= (int) $_POST['Customer']['cust_beautician'][$i]; } } } else { $cust_beautician = 0; } $cust_model->cust_beautician = $cust_beautician; if ($cust_model->save()) { $addr_model->attributes = $_POST['Address']; $addr_model->addr_cust_id = $user_model->pk_usr_id; if (!$addr_model->save()) { $cust_model->delete(); $user_model->delete(); echo "<script>alert('地址信息添加失败!');</script>"; } $custhi_model->attributes = $_POST['Cust_Health_Info']; $custhi_model->pk_custhi_cust_id = $user_model->pk_usr_id; $custhi_model->custhi_height = (double) $_POST['Cust_Health_Info']['custhi_height']; $custhi_model->custhi_weight = (double) $_POST['Cust_Health_Info']['custhi_weight']; $custhi_model->custhi_date = date("Y-m-d H:i:s", time()); if (!$custhi_model->save()) { $addr_model->delete(); $cust_model->delete(); $user_model->delete(); echo "<script>alert('用户健康信息添加失败!');</script>"; } $this->redirect("./index.php?r=user/showCust"); } else { $user_model->delete(); var_dump($cust_model->getErrors()); echo "<script>alert('顾客信息添加失败!');</script>"; } } else { // var_dump($user_model->getErrors()); echo "<script>alert('用户信息添加失败!');</script>"; } } $this->renderPartial('addCust', array('user_info' => $user_model, 'cust_info' => $cust_model, 'addr_info' => $addr_model, 'custhi_info' => $custhi_model)); }
public static function CreateFromCheckoutForm($checkoutForm) { $obj = new Customer(); $obj->first_name = $checkoutForm->contactFirstName; $obj->last_name = $checkoutForm->contactLastName; $obj->company = $checkoutForm->contactCompany; $obj->mainphone = $checkoutForm->contactPhone; $obj->email = $checkoutForm->contactEmail; $obj->email_repeat = $checkoutForm->contactEmail_repeat; $obj->password = $checkoutForm->createPassword; $obj->password_repeat = $checkoutForm->createPassword_repeat; $obj->newsletter_subscribe = $checkoutForm->receiveNewsletter; $obj->record_type = Customer::NORMAL_USER; $obj->currency = _xls_get_conf('CURRENCY_DEFAULT'); $obj->pricing_level = 1; $obj->allow_login = Customer::NORMAL_USER; $obj->scenario = Customer::SCENARIO_INSERT; if (!$obj->save()) { Yii::log("Error creating user " . print_r($obj->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } else { Yii::log(sprintf("Created user from checkout %s %s id# %d ", $obj->first_name, $obj->last_name, $obj->id), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); } return $obj; }
/** * Extract shipping and billing address information, create address book and map to the carts */ protected function actionConvertAddressBook() { $sql = "select * from xlsws_cart where billaddress_id IS NULL and address_bill IS NOT NULL order by id limit 500"; $arrProducts = Yii::app()->db->createCommand($sql)->query(); while (($result = $arrProducts->read()) !== false) { $result['email'] = strtolower($result['email']); //verify that Customer ID really exists in customer table $objCust = Customer::model()->findByPk($result['customer_id']); if (!$objCust instanceof Customer) { $result['customer_id'] = 0; } if (strlen($result['address_bill']) > 0) { $arrAddress = explode("\n", $result['address_bill']); if (count($arrAddress) == 5) { //old format address, should be 6 pieces $arrAddress[5] = $arrAddress[4]; $strSt = $arrAddress[3]; if ($strSt[0] == " ") { //no state on this address $arrAddress[4] = substr($strSt, 1, 100); $arrAddress[3] = ""; } else { $arrSt = explode(" ", $strSt); $arrAddress[3] = $arrSt[0]; $arrAddress[4] = str_replace($arrSt[0] . " ", "", $strSt); } } $objAddress = new CustomerAddress(); if (count($arrAddress) >= 5) { $objCountry = Country::LoadByCode($arrAddress[5]); if ($objCountry) { $objAddress->country_id = $objCountry->id; $objState = State::LoadByCode($arrAddress[3], $objCountry->id); if ($objState) { $objAddress->state_id = $objState->id; } } $objAddress->address1 = $arrAddress[0]; $objAddress->address2 = $arrAddress[1]; $objAddress->city = $arrAddress[2]; $objAddress->postal = $arrAddress[4]; $objAddress->first_name = $result['first_name']; $objAddress->last_name = $result['last_name']; $objAddress->company = $result['company']; $objAddress->phone = $result['phone']; $objAddress->residential = CustomerAddress::RESIDENTIAL; $objAddress->created = $result['datetime_cre']; $objAddress->modified = $result['datetime_cre']; $objAddress->active = 1; if (empty($objAddress->address2)) { $objAddress->address2 = null; } if (empty($objAddress->company)) { $objAddress->company = null; } $blnFound = false; if ($result['customer_id'] > 0) { //See if this is already in our database $objPriorAddress = CustomerAddress::model()->findByAttributes(array('address1' => $objAddress->address1, 'address2' => $objAddress->address2, 'city' => $objAddress->city, 'postal' => $objAddress->postal, 'first_name' => $objAddress->first_name, 'last_name' => $objAddress->last_name, 'company' => $objAddress->company, 'phone' => $objAddress->phone)); if ($objPriorAddress instanceof CustomerAddress) { Yii::app()->db->createCommand("update xlsws_cart set billaddress_id=" . $objPriorAddress->id . " where id=" . $result['id'])->execute(); $blnFound = true; } else { $objAddress->customer_id = $result['customer_id']; } } else { //We need a shell customer record just for the email $objC = Customer::model()->findByAttributes(array('email' => $result['email'])); if ($objC instanceof Customer) { Yii::app()->db->createCommand("UPDATE xlsws_cart set customer_id=" . $objC->id . " where id=" . $result['id'])->execute(); } else { $objC = new Customer(); $objC->record_type = Customer::GUEST; $objC->email = $result['email']; $objC->first_name = $objAddress->first_name; $objC->last_name = $objAddress->last_name; $objC->company = $objAddress->company; if (!$objC->validate()) { $arrErr = $objC->getErrors(); if (isset($arrErr['email'])) { $objC->email = $result['id'] . "*****@*****.**"; } if (!$objC->validate()) { return print_r($objC->getErrors(), true); } } if (!$objC->save()) { Yii::log("Import Error " . print_r($objC->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); return print_r($objC->getErrors(), true); } else { $cid = $objC->id; } Yii::app()->db->createCommand("UPDATE xlsws_cart set customer_id=" . $cid . " where id=" . $result['id'])->execute(); } $result['customer_id'] = $objC->id; $objAddress->customer_id = $result['customer_id']; } if (!$blnFound) { if (!$objAddress->save()) { //We have a corrupt billing address, just blank it out so import goes on Yii::app()->db->createCommand("update xlsws_cart set address_bill=null where id=" . $result['id'])->execute(); } else { $cid = $objAddress->id; Yii::app()->db->createCommand("update xlsws_cart set billaddress_id=" . $cid . " where id=" . $result['id'])->execute(); } } } else { //We have a corrupt billing address, just blank it out so import goes on Yii::app()->db->createCommand("update xlsws_cart set address_bill=null where id=" . $result['id'])->execute(); } $objAddress = new CustomerAddress(); $objCountry = Country::LoadByCode($result['ship_country']); if ($objCountry) { $objAddress->country_id = $objCountry->id; $objState = State::LoadByCode($result['ship_state'], $objCountry->id); if ($objState) { $objAddress->state_id = $objState->id; } } $objAddress->first_name = $result['ship_firstname']; $objAddress->last_name = $result['ship_lastname']; $objAddress->company = $result['ship_company']; $objAddress->address1 = $result['ship_address1']; $objAddress->address2 = $result['ship_address2']; $objAddress->city = $result['ship_city']; $objAddress->postal = $result['ship_zip']; $objAddress->phone = $result['ship_phone']; $objAddress->residential = CustomerAddress::RESIDENTIAL; $objAddress->created = $result['datetime_cre']; $objAddress->modified = $result['datetime_cre']; $objAddress->active = 1; if (empty($objAddress->address2)) { $objAddress->address2 = null; } if (empty($objAddress->company)) { $objAddress->company = null; } $blnFound = false; if ($result['customer_id'] > 0) { //See if this is already in our database $objPriorAddress = CustomerAddress::model()->findByAttributes(array('address1' => $objAddress->address1, 'city' => $objAddress->city, 'postal' => $objAddress->postal, 'first_name' => $objAddress->first_name, 'last_name' => $objAddress->last_name, 'company' => $objAddress->company, 'phone' => $objAddress->phone)); if ($objPriorAddress instanceof CustomerAddress) { Yii::app()->db->createCommand("update xlsws_cart set shipaddress_id=" . $objPriorAddress->id . " where id=" . $result['id'])->execute(); $blnFound = true; } else { $objAddress->customer_id = $result['customer_id']; } } if (!$blnFound) { if (!$objAddress->save()) { Yii::log("Import Error " . print_r($objAddress->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } else { $cid = $objAddress->id; Yii::app()->db->createCommand("update xlsws_cart set shipaddress_id=" . $cid . " where id=" . $result['id'])->execute(); } } } $objShipping = new CartShipping(); $objShipping->shipping_method = $result['shipping_method']; $objShipping->shipping_module = $result['shipping_module']; $objShipping->shipping_data = $result['shipping_data']; $objShipping->shipping_cost = $result['shipping_cost']; $objShipping->shipping_sell = $result['shipping_sell']; if (!$objShipping->save()) { return print_r($objShipping->getErrors()); } else { $cid = $objShipping->id; } Yii::app()->db->createCommand("update xlsws_cart set shipping_id=" . $cid . " where id=" . $result['id'])->execute(); $objPayment = new CartPayment(); $objPayment->payment_method = $result['payment_method']; $objPayment->payment_module = str_replace(".php", "", $result['payment_module']); $objPayment->payment_data = $result['payment_data']; $objPayment->payment_amount = $result['payment_amount']; $objPayment->datetime_posted = $result['datetime_posted']; if ($result['fk_promo_id'] > 0) { $objPromo = PromoCode::model()->findByPk($result['fk_promo_id']); if ($objPromo) { $objPayment->promocode = $objPromo->code; } } if (!$objPayment->save()) { return print_r($objPayment->getErrors()); } else { $cid = $objPayment->id; } Yii::app()->db->createCommand("update xlsws_cart set payment_id=" . $cid . " where id=" . $result['id'])->execute(); } $results2 = Yii::app()->db->createCommand("select count(*) from xlsws_cart where billaddress_id IS NULL and address_bill IS NOT NULL")->queryScalar(); if ($results2 == 0) { $remain = 8; } else { $remain = 3; } return array('result' => "success", 'makeline' => $remain, 'total' => 50, 'tag' => 'Converting cart addresses, ' . $results2 . ' remaining'); }
private function importCompany($fileNameAndPath) { $allAccounts = array(); $dom = new domDocument(); if (!$dom->load($fileNameAndPath)) { throw new CException(Yii::t('lazy8', 'input file could not be xml parsed')); } $root = $dom->documentElement; if ($root->nodeName != "lazy8webport") { $this->hasErrors = true; $this->errors = array(array(Yii::t('lazy8', 'Upload failed. This is not a valid file.'), Yii::t('lazy8', 'Select a file and try again'))); $this->render('showimport'); return 0; } if ($root->getAttribute('version') > 1.0) { $this->errors = array(array(Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version'), Yii::t('lazy8', 'Select a file and try again'))); } $nodeCompanys = $root->getElementsByTagName('company'); unset($root); unset($dom); $this->lastImportedPeriod = 0; foreach ($nodeCompanys as $nodeCompany) { //make sure the company code is unique $modelCompany = new Company(); $code = $nodeCompany->getAttribute('code'); $code--; //make sure the company code is valid. Change if not. do { $code++; $comptest = Company::model()->find(array('condition' => 'code=' . $code)); } while ($comptest !== null); //create the company $modelCompany = new Company(); $modelCompany->code = $code; $modelCompany->name = $nodeCompany->getAttribute('name'); $modelCompany->lastAbsTransNum = $nodeCompany->getAttribute('lastAbsTransNum'); if (!$modelCompany->save()) { throw new CException(Yii::t('lazy8', 'Could not create the company, bad paramters') . ';' . var_export($modelCompany->getErrors())); } try { $allAccounts = array(); $nodesAccountTypes = $nodeCompany->getElementsByTagName('accounttype'); foreach ($nodesAccountTypes as $nodeAccountType) { $modelAccountType = new AccountType(); $modelAccountType->companyId = $modelCompany->id; $modelAccountType->code = $nodeAccountType->getAttribute('code'); $modelAccountType->name = $nodeAccountType->getAttribute('name'); $modelAccountType->sortOrder = $nodeAccountType->getAttribute('sortorder'); $modelAccountType->isInBalance = $nodeAccountType->getAttribute('isinbalance') == "1" ? 1 : 0; if (!$modelAccountType->save()) { $modelCompany->delete(); throw new CException(Yii::t('lazy8', 'Could not create the AccountType, bad paramters') . ';name=' . $modelAccountType->name . ';' . serialize($modelAccountType->getErrors())); } $nodesAccounts = $nodeAccountType->getElementsByTagName('account'); foreach ($nodesAccounts as $nodeAccount) { $modelAccount = new Account(); $modelAccount->companyId = $modelCompany->id; $modelAccount->code = $nodeAccount->getAttribute('code'); $modelAccount->accountTypeId = $modelAccountType->id; $modelAccount->name = $nodeAccount->getAttribute('name'); if (!$modelAccount->save()) { $modelCompany->delete(); throw new CException(Yii::t('lazy8', 'Could not create the Account, bad paramters') . ';' . serialize($modelAccount->getErrors())); } $allAccounts[$modelAccount->code] = $modelAccount->id; unset($nodeAccount); unset($modelAccount); } unset($modelAccountType); unset($nodeAccountType); } unset($nodesAccountTypes); $allCustomers = array(); $nodesCustomers = $nodeCompany->getElementsByTagName('customer'); foreach ($nodesCustomers as $nodeCustomer) { $modelCustomer = new Customer(); $modelCustomer->companyId = $modelCompany->id; $modelCustomer->code = $nodeCustomer->getAttribute('code'); $modelCustomer->accountId = $this->FindAccountIdFromCode($nodeCustomer->getAttribute('accountcode'), $modelCompany->id, $allAccounts, 'customercode=' . $modelCustomer->code, $this->errors, true); $modelCustomer->name = $nodeCustomer->getAttribute('name'); $modelCustomer->desc = $nodeCustomer->getAttribute('desc'); if (!$modelCustomer->save()) { $modelCompany->delete(); throw new CException(Yii::t('lazy8', 'Could not create the Customer, bad paramters') . ';' . serialize($modelCustomer->getErrors())); } $allCustomers[$modelCustomer->code] = $modelCustomer->id; unset($modelCustomer); unset($nodeCustomer); } unset($nodesCustomers); $nodesPeriods = $nodeCompany->getElementsByTagName('period'); foreach ($nodesPeriods as $nodePeriod) { $modelPeriod = new Period(); $modelPeriod->companyId = $modelCompany->id; $modelPeriod->dateStart = $nodePeriod->getAttribute('datestart'); $modelPeriod->dateEnd = $nodePeriod->getAttribute('dateend'); $modelPeriod->lastPeriodTransNum = $nodePeriod->getAttribute('lastperiodtransnum'); if (!$modelPeriod->save()) { $modelCompany->delete(); throw new CException(Yii::t('lazy8', 'Could not create the period, bad paramters') . ';' . serialize($modelPeriod->getErrors())); } $this->lastImportedPeriod = $modelPeriod->id; $nodesTransactions = $nodePeriod->getElementsByTagName('transaction'); foreach ($nodesTransactions as $nodeTransaction) { $modelTransaction = new Trans(); $modelTransaction->companyId = $modelCompany->id; $modelTransaction->companyNum = $nodeTransaction->getAttribute('code'); $modelTransaction->periodId = $modelPeriod->id; $modelTransaction->periodNum = $nodeTransaction->getAttribute('periodnum'); $modelTransaction->regDate = $nodeTransaction->getAttribute('regdate'); $modelTransaction->invDate = $nodeTransaction->getAttribute('invdate'); $modelTransaction->notes = $nodeTransaction->getAttribute('notes'); $modelTransaction->fileInfo = $nodeTransaction->getAttribute('fileinfo'); if (!$modelTransaction->save()) { $modelCompany->delete(); throw new CException(Yii::t('lazy8', 'Could not create the Transaction, bad paramters') . ';' . serialize($modelTransaction->getErrors())); } $nodesTransactionAmounts = $nodeTransaction->getElementsByTagName('amount'); foreach ($nodesTransactionAmounts as $nodeTransactionAmount) { $modelTransRow = new TransRow(); $modelTransRow->transId = $modelTransaction->id; $modelTransRow->accountId = $this->FindAccountIdFromCode($nodeTransactionAmount->getAttribute('accountcode'), $modelCompany->id, $allAccounts, 'TransCode=' . $modelTransaction->companyNum, $this->errors, true, true); $modelTransRow->customerId = $this->FindCustomerIdFromCode($nodeTransactionAmount->getAttribute('customercode'), $modelCompany->id, $allCustomers, 'TransCode=' . $modelTransaction->companyNum, $this->errors, true); $modelTransRow->notes = $nodeTransactionAmount->getAttribute('notes'); $modelTransRow->amount = $nodeTransactionAmount->getAttribute('amount'); if (!$modelTransRow->save()) { $modelCompany->delete(); throw new CException(Yii::t('lazy8', 'Could not create the TransactionAmount, bad paramters') . ';' . serialize($modelTransRow->getErrors())); } unset($modelTransRow); } unset($modelTransaction); unset($nodesTransactionAmounts); unset($nodeTransaction); } unset($modelPeriod); unset($nodePeriod); unset($nodesTransactions); } unset($nodesPeriods); } catch (Exception $e) { $modelCompany->delete(); throw $e; } $errors = array(); //we ignore the errors... yii::app()->onImport(new Lazy8Event(array('importobject' => 'Company', 'root' => $nodeCompany, 'errors' => $errors), $modelCompany->id)); unset($nodeCompany); } unset($nodeCompanys); ChangeLog::addLog('ADD', 'Company', 'Imported company ' . $modelCompany->toString()); return $modelCompany->id; }