Ejemplo n.º 1
0
 public static function saveEdiData($ecnt_data, $EdiReader, $error, $edifact)
 {
     $error = array_merge($error, $EdiReader->errors());
     $edifact->bgm_1_id = $EdiReader->readEdiDataValueReq('BGM', 1);
     $edifact->error = '';
     if (!empty($error)) {
         $edifact->error = implode(PHP_EOL, $error);
         $edifact->status = Edifact::STATUS_ERROR;
         $edifact->save();
         return false;
     }
     //create model
     $find_attributes = array('ecnt_edifact_id' => $edifact->id, 'ecnt_container_nr' => $ecnt_data['ecnt_container_nr']);
     $ecnt = EcntContainer::model()->findByAttributes($find_attributes);
     if (!$ecnt) {
         $ecnt_data['ecnt_edifact_id'] = $edifact->id;
         $ecnt = new EcntContainer();
     }
     $ecnt->attributes = $ecnt_data;
     if (!$ecnt->save()) {
         $edifact->error = print_r($ecnt->errors, true);
         $edifact->status = Edifact::STATUS_ERROR;
         $edifact->save();
         return false;
     }
     $ecnt->recalc();
     $edifact->error = '';
     $edifact->status = Edifact::STATUS_PROCESSED;
     $edifact->save();
     return true;
 }