Ejemplo n.º 1
0
 public function save($runValidation = true, $attributes = NULL)
 {
     $class = get_class($this);
     if ($class == 'Accounts') {
         if (Accounts::findOne($this->id)) {
             $this->isNewRecord = false;
         }
     }
     $a = parent::save($runValidation, $attributes);
     if ($a) {
         //if (isset($_POST['Files'])) {
         //$this->attributes = $_POST['Files'];
         $tmps = \yii\web\UploadedFile::getInstancesByName('Files');
         // proceed if the images have been set
         if (isset($tmps) && count($tmps) > 0) {
             \Yii::info('saved');
             // go through each uploaded image
             $configPath = \app\helpers\Linet3Helper::getSetting("company.path");
             foreach ($tmps as $image => $pic) {
                 $img_add = new Files();
                 $img_add->name = $pic->name;
                 //it might be $img_add->name for you, filename is just what I chose to call it in my model
                 $img_add->path = "files/";
                 $img_add->parent_type = get_class($this);
                 $img_add->parent_id = $this->id;
                 // this links your picture model to the main model (like your user, or profile model)
                 $img_add->save();
                 // DONE
                 if ($pic->saveAs($img_add->getFullFilePath())) {
                     // add it to the main model now
                 } else {
                     echo 'Cannot upload!';
                 }
             }
             if (isset($_FILES)) {
                 Yii::info(print_r($_FILES, true));
                 unset($_FILES);
                 $tmps = \yii\web\UploadedFile::reset();
             }
             //}
         }
     }
     //endFile
     return $a;
 }
Ejemplo n.º 2
0
 public function save($runValidation = true, $attributes = NULL)
 {
     //var_dump($this->iTotalVat);
     //exit;
     if ($this->iItem == null) {
         if ($this->iTotalVat !== null) {
             $this->CalcPriceWithVat();
         } else {
             if ($this->iTotal !== null) {
                 $this->CalcPriceWithOutVat();
             }
         }
         //qty,rate,totalw/oVat
     } else {
         $this->CalcPrice();
     }
     //adam this is not good for open format at all:
     //$this->iVatRate = 0;
     return parent::save($runValidation, $attributes);
 }
Ejemplo n.º 3
0
 public function save($runValidation = false, $attributes = NULL)
 {
     parent::save($runValidation, $attributes);
     if ($this->refnum2 === null) {
         $this->refnum2 = '';
     }
     return $this->num;
 }
Ejemplo n.º 4
0
 public function save($runValidation = true, $attributes = NULL)
 {
     //adam:
     if ($this->eavType == 'boolean') {
         if ($this->value == '1') {
             $this->value = 'true';
         } else {
             $this->value = 'false';
         }
     } else {
         if ($this->eavType == 'file') {
             $configPath = Linet3Helper::getSetting("company.path");
             $a = \yii\web\UploadedFile::getInstanceByName('Settings[' . $this->id . '][value]');
             //var_dump($a);
             //exit;
             if ($a) {
                 $this->value = $a;
                 $ext = $this->value->extension;
                 //$fileName = $yiiBasepath."/files/".$configPath."/settings/".$this->id.".".$ext;
                 //echo $this->id.get_class($this);
                 $logo = new \app\models\Files();
                 $logo->name = $this->id . "." . $ext;
                 //it might be $img_add->name for you, filename is just what I chose to call it in my model
                 $logo->path = "settings/";
                 $logo->parent_type = get_class($this);
                 $logo->parent_id = $this->id;
                 // this links your picture model to the main model (like your user, or profile model)
                 $logo->public = true;
                 $id = $logo->save();
                 // DONE
                 //echo $logo->id;
                 //Yii::$app->end();
                 if ($this->value->saveAs($logo->getFullFilePath())) {
                     $this->value = $logo->hash;
                     //"/files/".$configPath."/settings/".$this->id.".".$ext;
                 }
                 //Yii::$app->end();
             }
         }
     }
     return parent::save($runValidation, $attributes);
 }