public function actionCustum() { $debug = ''; $model = new Mod\Custum(); $prompt = Yii::t('app', 'Select stock'); $arrError = []; if ($model->load(Yii::$app->request->post())) { if (!$model->validate()) { $debug = print_r($model->geterrors(), true); return $this->render('finish', ['debug' => $debug]); } $arrvin = explode("\n", $model->vins); foreach ($arrvin as $vin) { if ($car = Mod\Car::findOne(['vin' => trim($vin)])) { $status = Mod\CarStatus::findOne(['car_id' => $car->id]); $status->custum_date = $model->custum_date; $status->custum_num = $model->custum_num; $status->save(); } else { $arrError[] = $vin . ' не найден VIN'; } } $debug = implode('<br>', $arrError); return $this->render('finish', ['debug' => $debug]); } $arrVars = ['model' => $model, 'prompt' => $prompt, 'selLabel' => 'Склад', 'title' => 'Пакетное ведение деклараций']; return $this->render('custum', $arrVars); }
public static function importData() { $arr_error = []; $timeimport = time(); foreach (ImportRaw::find()->where(['imported' => null])->each() as $rawData) { $data = $rawData->data; $arrayPos = self::getPosArray($rawData->type); // $arrayPos = $$arrayPos; $codmodel = str_ireplace(' ', '', substr($data, $arrayPos['model'], 17)); $codColor = trim(substr($data, $arrayPos['color'], 3)); $codSalon = trim(substr($data, $arrayPos['salon'], 3)); $codEnj = trim(substr($data, $arrayPos['enj'], 12)); $prodOrd = trim(substr($data, $arrayPos['prod_ord'], 5)); $carrier = trim(substr($data, $arrayPos['carrier'], 8)); $keyCode = trim(substr($data, $arrayPos['key_code'], 5)); $dateShipping = trim(substr($data, $arrayPos['date_shipping'], 8)); $shipCode = trim(substr($data, $arrayPos['ship_code'], 3)); $numInvoice = trim(substr($data, $arrayPos['num_invoice'], 16)); $car = new Car(); $car->model_id = CatModel::findOne(['code' => $codmodel])->id; $car->color_id = cats\Color::findOne(['code' => $codColor])->id; $car->color_sal_id = cats\ColorSalon::find()->where(['name' => $codSalon])->one()->id; $car->vin = $rawData->vin; $car->enj_num = $codEnj; if ($car->validate()) { $car->save(); } else { $arr_error[] = $car->getErrorsAsString(); // continue; } if ($sCarmod = Car::findOne(['vin' => $rawData->vin])) { $impData = new ImportPlant(); $impData->production_ord = $prodOrd; $impData->carrier = $carrier; $impData->key_code = $keyCode; $impData->car_id = $sCarmod->id; $impData->date_shipping = $dateShipping; $impData->ship_code = $shipCode; $impData->num_invoice = $numInvoice; if ($impData->validate()) { $impData->save(); $car_status = new CarStatus(); $car_status->car_id = $sCarmod->id; $car_status->status = 'way'; $car_status->imp_data_id = $impData->id; if ($car_status->validate()) { $car_status->save(); } else { $arr_error[] = $car_status->getErrorsAsString(); } } else { $arr_error[] = $impData->getErrorsAsString(); // continue; } } $rawData->imported = $timeimport; $rawData->save(); } return $arr_error; }
/** * Finds the Car model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Car the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Car::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Save user profile * @return boolean whether the user is created successfully */ public function saveProfile() { if (YII_DEBUG) { error_log("[ProfileForm::saveProfile]"); } if (YII_DEBUG) { error_log("[ProfileForm::saveProfile] attributes : " . json_encode($this->getAttributes())); } if ($this->isEditable) { $formData = Yii::$app->request->post('ProfileForm'); if ($formData) { $this->processFileField('photo', $this->_user); $_email = isset($formData['email']) ? strval($formData['email']) : null; if ($_email && $this->_user->email !== $_email) { $v = new EmailValidator(); $err = null; if ($v->validate($_email)) { $u = User::findOne(['email' => $_email]); if (null !== $u) { $err = 'Email already exists'; } else { $this->_user->email = $_email; } } else { $err = 'Not a valid email address'; } if ($err) { Yii::$app->session->addFlash('email', $err); } } $_phone = isset($formData['phone']) ? strval($formData['phone']) : null; if ($_phone && 0 == $this->_user->phone_verified && $this->_user->phone !== $_phone) { $err = User::validatePhone($_phone); if (true === $err) { $u = User::findOne(['phone' => $_phone]); if (null !== $u) { $err = 'Phone already exists'; } else { $this->_user->phone = $_phone; $this->_user->phone_verified = 0; $this->_user->generatePhoneToken(); } } if (is_string($err)) { Yii::$app->session->addFlash('phone', $err); } } $_address = isset($formData['address']) ? strval($formData['address']) : null; if ($_address && 0 < strlen($_address)) { $addr = Address::findOne(['address' => $_address]); if (!$addr) { $addr = new Address(); $addr->address = $_address; $addr->save(); } if (User::$_TYPE_CUSTOMER === $this->_user->user_type) { $rua = RelUserAddress::findOne(['user_id' => $this->_user->id, 'address_id' => $addr->id]); if (!$rua) { $rua = new RelUserAddress(); $rua->user_id = $this->_user->id; $rua->address_id = $addr->id; $rua->save(); } } else { $rua = RelUserAddress::findOne(['user_id' => $this->_user->id]); if (!$rua) { $rua = new RelUserAddress(); $rua->user_id = $this->_user->id; } $rua->address_id = $addr->id; $rua->save(); } } $_fName = isset($formData['firstName']) ? strval($formData['firstName']) : null; if (strlen($_fName) > 0 && $this->_user->first_name !== $_fName) { $this->_user->first_name = $_fName; } $_lName = isset($formData['lastName']) ? strval($formData['lastName']) : null; if (strlen($_lName) > 0 && $this->_user->last_name !== $_lName) { $this->_user->last_name = $_lName; } $_ccInfo = isset($formData['creditCardInfo']) ? strval($formData['creditCardInfo']) : null; if ($this->_user->ccard_info !== $_ccInfo) { $this->_user->ccard_info = $_ccInfo; } if (User::$_TYPE_DRIVER === $this->_user->user_type) { $this->_car = Car::findOne(['driver_id' => $this->_user->id]); if (!$this->_car) { $this->_car = new Car(); $this->_car->driver_id = $this->_user->id; $this->_car->save(); } $this->processFileField('car_photo', $this->_car); $this->processFileField('license_photo', $this->_user); $this->processFileField('insurance_photo', $this->_user); $_priceMile = isset($formData['priceMile']) ? strval($formData['priceMile']) : null; if (strlen($_priceMile) > 0 && $this->_car->price_mile !== $_priceMile) { $this->_car->price_mile = $_priceMile; } $_carMake = isset($formData['carMake']) ? strval($formData['carMake']) : null; if (strlen($_carMake) > 0 && $this->_car->make !== $_carMake) { $this->_car->make = $_carMake; } $_carModel = isset($formData['carModel']) ? strval($formData['carModel']) : null; if (strlen($_carModel) > 0 && $this->_car->model !== $_carModel) { $this->_car->model = $_carModel; } $_carYear = isset($formData['carYear']) ? strval($formData['carYear']) : null; if (strlen($_carYear) > 0 && $this->_car->year !== $_carYear) { $this->_car->year = $_carYear; } $_licensePlateNumber = isset($formData['licensePlateNumber']) ? strval($formData['licensePlateNumber']) : null; $_existing_car = Car::findOne(['license_plate' => $_licensePlateNumber]); if ($_existing_car) { Yii::$app->session->addFlash('license_plate', 'License plate number already registered'); } elseif (strlen($_licensePlateNumber) > 0 && $this->_car->license_plate !== $_licensePlateNumber) { $this->_car->license_plate = $_licensePlateNumber; } $this->_car->save(); } } $this->_user->save(); } $this->loadData(); return true; }
public function beforeSave($insert) { $blnMakeSave = parent::beforeSave($insert); /** @TODO: add checking on profile completion **/ if (!$insert) { $blnIsComplete = true; $rua = RelUserAddress::findOne(['user_id' => $this->id]); if (!$rua || 0 == strlen($this->first_name) || 0 == strlen($this->last_name) || 0 == strlen($this->email) || 0 == strlen($this->phone) || 0 == $this->phone_verified || 0 == strlen($this->photo) || 0 == strlen($this->ccard_info)) { $blnIsComplete = false; } if ($blnIsComplete && User::$_TYPE_DRIVER === $this->user_type) { $_car = Car::findOne(['driver_id' => $this->id]); if (0 == strlen($this->license_photo) || 0 == strlen($this->insurance_photo) || !$_car || 0 == strlen($_car->make) || 0 == strlen($_car->model) || 0 == strlen($_car->year) || 0 == strlen($_car->license_plate) || 0 == strlen($_car->car_photo) || 0 == strlen($_car->price_mile)) { $blnIsComplete = false; } } $this->is_complete = $blnIsComplete ? 1 : 0; } return $blnMakeSave; }