137 lines
3.1 KiB
PHP
137 lines
3.1 KiB
PHP
<?php
|
|
namespace common\components;
|
|
|
|
|
|
use yii\base\Object;
|
|
use common\models\TicketInstallmentRequest;
|
|
use common\components\giro\GiroDETSTATetel;
|
|
use backend\models\TicketInstallmentMarkForSendForm;
|
|
use common\models\Ugiro;
|
|
use yii\db\Query;
|
|
use common\components\giro\GiroDETSTA;
|
|
use common\components\giro\GiroDETSTAFej;
|
|
use common\components\giro\GiroDETSTALab;
|
|
|
|
|
|
/**
|
|
* This is the model class for table "ticket".
|
|
*
|
|
* @property common\components\giro\GiroDETSTA $detstatUzenet
|
|
* @property common\models\UGiro $koteg
|
|
*
|
|
* */
|
|
class DetStatProcessor extends Object{
|
|
|
|
|
|
/**aktuális koteg, config paraméterként kapju*/
|
|
public $koteg;
|
|
public $idKoteg;
|
|
public $detstatUzenet;
|
|
public $megbizasok;
|
|
|
|
public $errors = [];
|
|
|
|
public function run(){
|
|
// $this->readKoteg();
|
|
$this->readKotegMegbizasok();
|
|
$this->readDetstaUzenet();
|
|
$this->createMegbizasTetelHozzarendelesek();
|
|
$this->processMegbizasok();
|
|
$this->markKotegFinished();
|
|
}
|
|
|
|
public function markKotegFinished(){
|
|
$this->koteg->status = Ugiro::$STATUS_FINISHED;
|
|
$this->koteg->save();
|
|
}
|
|
|
|
public function processMegbizasok(){
|
|
foreach ($this->megbizasok as $megbizas){
|
|
$processor = new DetStatTetelProcessor(
|
|
[
|
|
'tetel' => $megbizas->detstaTetel,
|
|
'megbizas' => $megbizas
|
|
]
|
|
);
|
|
$processor->run();
|
|
$this->errors = $this->errors + $processor->errors;
|
|
}
|
|
}
|
|
|
|
public function readDetstaUzenet(){
|
|
|
|
$filename = \Yii::getAlias("@webroot") ."/" .$this->koteg->desta_path;
|
|
$content = file_get_contents($filename);
|
|
$this->detstatUzenet = GiroDETSTA::parse($content);
|
|
|
|
|
|
|
|
|
|
$this->detstatUzenet = new GiroDETSTA();
|
|
$this->idKoteg = 37;
|
|
|
|
$fej = new GiroDETSTAFej();
|
|
|
|
$this->detstatUzenet->fej = $fej;
|
|
|
|
$tetel = new GiroDETSTATetel();
|
|
$tetel->tetelSorszam = 1;
|
|
$tetel->visszajelzesInformacio = "00";
|
|
// $tetel->visszajelzesInformacio = "02";
|
|
|
|
$this->detstatUzenet->tetelek[] = $tetel;
|
|
|
|
$lab = new GiroDETSTALab();
|
|
$this->detstatUzenet->lab = $lab;
|
|
|
|
}
|
|
|
|
public function createMegbizasTetelHozzarendelesek(){
|
|
$mapTetel = [];
|
|
foreach ($this->detstatUzenet->tetelek as $tetel ){
|
|
$mapTetel[$tetel->tetelSorszam] = $tetel;
|
|
}
|
|
|
|
foreach ($this->megbizasok as $megbizas){
|
|
if ( array_key_exists($megbizas->number, $mapTetel)){
|
|
$megbizas->detstaTetel = $mapTetel[$megbizas->number];
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public function readKoteg(){
|
|
$this->koteg = Ugiro::findOne($this->idKoteg );
|
|
if ( !isset($this->koteg) ){
|
|
$this->errors [] = "Kötege nem található! (".$this->detstatUzenet->fej." )";
|
|
}
|
|
}
|
|
public function readKotegMegbizasok(){
|
|
$this->megbizasok = $this->koteg->requests;
|
|
}
|
|
|
|
public function applyNewMegbizasState(){
|
|
$kod = $this->tetel->valaszHivatkozasiKod;
|
|
|
|
if ( $kod == GiroDETSTATetel::$INFORMACIO_TELJESITETT){
|
|
$this->megbizas->status = TicketInstallmentRequest::$STATUS_ACCEPTED;
|
|
}else{
|
|
$this->megbizas->status = TicketInstallmentRequest::$STATUS_REJECTED;
|
|
}
|
|
$this->megbizas->save(false);
|
|
}
|
|
|
|
public function applyNewTicketState(){
|
|
$this->ticket->applyTicketInstallmentRequest($this->megbizas);
|
|
$this->ticket->save(false);
|
|
}
|
|
|
|
|
|
public function hasError(){
|
|
return count($this->errors) > 0;
|
|
}
|
|
|
|
|
|
} |