예제 #1
0
 public function beforeSave()
 {
     //nosaka garumu
     if (!empty($this->ecnt_iso_type)) {
         switch (substr($this->ecnt_iso_type, 0, 1)) {
             case '2':
                 $this->ecnt_length = EcntContainer::ECNT_LENGTH_20;
                 break;
             case '4':
                 $this->ecnt_length = EcntContainer::ECNT_LENGTH_40;
                 break;
             default:
                 $error[] = 'Nekorekts ISO TYPR:' . $this->ecnt_iso_type;
                 break;
         }
     }
     //sameklee procesing record
     if (empty($this->ecnt_ecpr_id) && $this->ecnt_operation != EcntContainer::ECNT_OPERATION_TRUCK_IN && $this->ecnt_operation != EcntContainer::ECNT_OPERATION_VESSEL_DISCHARGE) {
         $sql = "\n                SELECT \n                    ecpr_id \n                FROM\n                    ecnt_container \n                    INNER JOIN ecpr_container_procesing \n                      ON ecnt_ecpr_id = ecpr_id \n                      AND ecpr_start_ecnt_id = ecnt_id \n                WHERE ecnt_container_nr = :container\n                    AND ecpr_end_ecnt_id IS NULL \n                    AND ecnt_datetime < :datetime\n                ";
         $rawData = Yii::app()->db->createCommand($sql);
         $container = $this->ecnt_container_nr;
         $datetime = $this->ecnt_datetime;
         $rawData->bindParam(":container", $container, PDO::PARAM_STR);
         $rawData->bindParam(":datetime", $datetime, PDO::PARAM_STR);
         $ecpr_id = $rawData->queryScalar();
         if ($ecpr_id) {
             $this->ecnt_ecpr_id = $ecpr_id;
         }
     }
     //calc movment code
     if ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_VESSEL_DISCHARGE && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_FULL) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_DF;
     } elseif ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_TRUCK_OUT && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_FULL) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_LD;
     } elseif ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_TRUCK_IN && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_EMPTY) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_TE;
     } elseif ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_TRUCK_OUT && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_EMPTY) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_LV;
     } elseif ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_TRUCK_IN && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_FULL) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_TF;
     } elseif ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_VESSEL_LOAD && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_FULL) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_VF;
     } elseif ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_VESSEL_LOAD && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_EMPTY) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_VE;
     } elseif ($this->ecnt_operation == EcntContainer::ECNT_OPERATION_VESSEL_DISCHARGE && $this->ecnt_statuss == EcntContainer::ECNT_STATUSS_EMPTY) {
         $this->ecnt_move_code = EcntContainer::ECNT_MOVE_CODE_DE;
     } else {
         $this->ecnt_move_code = NULL;
     }
     /**
      * search prev moving and analyse move code sqn
      */
     $this->ecnt_error = null;
     //    $this->ecnt_notes = '';
     if (!empty($this->ecnt_move_code) && $this->ecnt_move_code != EcntContainer::ECNT_MOVE_CODE_DF) {
         $prev_ecnt = $this->searchPrevContainer();
         if (!$prev_ecnt) {
             EcerErrors::registreError($this->ecnt_id, 'Can not find previous moving');
         } else {
             $sqn_rules = ['DF' => 'LD', 'LD' => 'TE', 'TE' => 'LV', 'LV' => 'TF', 'TF' => 'VF'];
             if (isset($sqn_rules[$prev_ecnt->ecnt_move_code]) && $sqn_rules[$prev_ecnt->ecnt_move_code] != $this->ecnt_move_code) {
                 $notes = 'Ilegal sequence: ' . $prev_ecnt->ecnt_move_code . '- ' . $this->ecnt_move_code;
                 EcerErrors::registreError($this->ecnt_id, $notes);
             }
         }
     }
     return parent::beforeSave();
 }