public function actionImportAll()
 {
     $arr_error = ImportRaw::importData();
     $mess = implode('<br>', $arr_error);
     $debug = print_r($mess, true);
     return $this->render('final', ['debug' => $debug, 'message' => 'Import complite']);
 }
Example #2
0
 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;
 }