108 lines
2.3 KiB
PHP
108 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace backend\models;
|
|
|
|
use yii\base\Model;
|
|
use yii\web\UploadedFile;
|
|
use common\components\giro\GiroDETSTA;
|
|
use common\models\Ugiro;
|
|
use common\components\DetStatProcessor;
|
|
use common\components\Helper;
|
|
|
|
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;
|
|
if (!isset($koteg)){
|
|
$this->addError($attribute,"Nincs ilyen köteg! ( Datum: $datum, Sorszam: $number )");
|
|
}
|
|
|
|
// else{
|
|
// if ( $koteg->status != Ugiro::$STATUS_SENT ){
|
|
// $idKoteg = $this->koteg->id_ugiro;
|
|
// $this->addError($attribute,"A köteg detsta fájl-ja már fel van töltve !( Köteg azonosító: $idKoteg )");
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// public function saveMessageDetsta($filename){
|
|
// $uzenetSzoveg = $this->readDetstaUzenet($filename);
|
|
// $saver = new DetStaDBSave(
|
|
// [
|
|
// 'giroDETSTA' => $this->detstatUzenet,
|
|
// 'koteg' => $this->koteg,
|
|
// 'idUser' =>\Yii::$app->user->id
|
|
// ]);
|
|
// $saver->run();
|
|
// }
|
|
|
|
|
|
// public function readDetstaUzenet($filename){
|
|
|
|
// // $filename = \Yii::getAlias("@webroot") ."/" .$this->koteg->desta_path;
|
|
// $content = file_get_contents($filename);
|
|
// return GiroDETSTA::parse($content);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
public function upload()
|
|
{
|
|
if ($this->validate()) {
|
|
$path = 'giro/valasz/' . $this->destaFile->baseName . '.' . $this->destaFile->extension;
|
|
$this->destaFile->saveAs( $path );
|
|
|
|
|
|
set_time_limit ( 1200 ); // 20 perc
|
|
$processor = new DetStatProcessor( [
|
|
'koteg' => $this->koteg,
|
|
'path' => $path
|
|
] );
|
|
$processor->run ();
|
|
|
|
Helper::flash("success", "Detsta fájl feldolgozva!");
|
|
|
|
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|