add ticket installment
This commit is contained in:
68
backend/models/DestaUploadForm.php
Normal file
68
backend/models/DestaUploadForm.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\web\UploadedFile;
|
||||
use common\components\giro\GiroDETSTA;
|
||||
use common\models\Ugiro;
|
||||
|
||||
class DestaUploadForm extends Model
|
||||
{
|
||||
/**
|
||||
* @var UploadedFile
|
||||
*/
|
||||
public $destaFile;
|
||||
|
||||
public $koteg;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['destaFile'], 'file', 'skipOnEmpty' => false, ],
|
||||
[['destaFile'], 'validateKoteg', ],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels(){
|
||||
return [
|
||||
"destaFile" => "Desta fájl"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function validateKoteg($attribute,$params){
|
||||
if ( !$this->hasErrors()){
|
||||
$content = file_get_contents($this->destaFile->tempName);
|
||||
$destaUzenet = GiroDETSTA::parse($content);
|
||||
$number = $destaUzenet->fej->csoportosUzenetSorszam->sorszam;
|
||||
$datum = $destaUzenet->fej->csoportosUzenetSorszam->osszeallitasDatuma;
|
||||
$koteg = Ugiro::find()->andWhere(['number' =>$number,'datum' => $datum ])->one();
|
||||
$this->koteg = $koteg;
|
||||
$idKoteg = $this->koteg->id_ugiro;
|
||||
if (!isset($koteg)){
|
||||
$this->addError($attribute,"Nincs ilyen köteg! ( Datum: $datum, Sorszam: $number )");
|
||||
}else{
|
||||
if ( $koteg->status != Ugiro::$STATUS_SENT ){
|
||||
$this->addError($attribute,"A köteg detsta fájl-ja már fel van töltve !( Köteg azonosító: $idKoteg )");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
if ($this->validate()) {
|
||||
$path = 'giro/valasz/' . $this->destaFile->baseName . '.' . $this->destaFile->extension;
|
||||
$this->destaFile->saveAs( $path );
|
||||
$this->koteg->desta_path = $path;
|
||||
$this->koteg->status = Ugiro::$STATUS_RECIEVED;
|
||||
$this->koteg->save(false);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user