fitness-web/common/components/DetStatTetelProcessor.php

129 lines
3.7 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\Transfer;
use common\models\Account;
use common\models\Discount;
/**
* This is the model class for table "ticket".
*
* @property common\components\giro\GiroDETSTATetel $tetel
* @property common\models\TicketInstallmentRequest $megbizas
* @property common\models\Ticket $ticket
*
*
*/
class DetStatTetelProcessor extends Object {
public $tetel; // config
public $megbizas; // config
public $ticket;
public $errors = [ ];
public $dryRun = false; // for testing, to not to persist the changes
public function run() {
// $this->readMegbizas();
if ($this->megbizas->isStatusAccepted()) {
// return;
}
$status = TicketInstallmentRequest::$STATUS_REJECTED;
$kod = 'xx';
$comment = "";
if (isset ( $this->tetel )) {
$kod = $this->tetel->visszajelzesInformacio;
}
if ($kod == GiroDETSTATetel::$INFORMACIO_TELJESITETT) {
$status = TicketInstallmentRequest::$STATUS_ACCEPTED;
} else {
$status = TicketInstallmentRequest::$STATUS_REJECTED;
if ( $kod == "xx"){
$comment = "Nem található a detsta fájlban a tétel válasza";
}else{
if ( array_key_exists($kod, GiroDETSTATetel::$INFORMACIOK)){
$comment = "Hiba kód: ".$kod ." - " .GiroDETSTATetel::$INFORMACIOK[$kod];
}else{
$comment = "Ismeretlen hiba kód: " .$kod;
}
}
}
$this->megbizas->applyStatus($status,true,$kod,$comment);
// $this->readTicket();
// if ( !$this->hasError() ){
// $this->applyNewMegbizasState();
// $this->applyNewTicketState();
// $this->addTransfer();
// }
}
// public function readMegbizas(){
// $this->megbizas = TicketInstallmentRequest::findOne($this->tetel->ugyfelAzonosito);
// if ( !isset($this->megbizas) ){
// $this->errors [] = "Válaszban jelölt megbízás nem található! (".$this->tetel->ugyfelAzonosito." )";
// }
// }
// public function readTicket(){
// $this->ticket = $this->megbizas->ticket;
// if ( !isset($this->ticket) ){
// $this->errors [] = "Válaszban jelölt bérlet nem található! (".$this->megbizas->id_ticket." )";
// }
// }
// public function applyNewMegbizasState(){
// $kod = 'xx';
// if ( isset($this->tetel ) ) {
// $kod = $this->tetel->visszajelzesInformacio;
// }
// if ( $kod == GiroDETSTATetel::$INFORMACIO_TELJESITETT){
// $this->megbizas->status = TicketInstallmentRequest::$STATUS_ACCEPTED;
// }else{
// $this->megbizas->status = TicketInstallmentRequest::$STATUS_REJECTED;
// }
// if ( !$this->isDryRun() ){
// $this->megbizas->save(false);
// }
// }
// public function applyNewTicketState(){
// $this->ticket->applyTicketInstallmentRequest($this->megbizas);
// if ( !$this->isDryRun() ){
// $this->ticket->save(false);
// }
// }
// protected function addTransfer(){
// $account = Account::findOne($this->ticket->id_account);
// $discount = null;
// if ( isset($this->ticket->id_account)){
// $discount = Discount::findOne( $this->ticket->id_discount );
// }
// $transfer = Transfer::createTicketTransfer($account, $discount, null, 1, $this->ticket);
// $transfer->status = Transfer::STATUS_PAID;
// $transfer->paid_at = date('Y-m-d H:i:s' ) ;
// $transfer->paid_by = \Yii::$app->user->id;
// $transfer->payment_method = Transfer::PAYMENT_METHOD_TRANSFER;
// $transfer->money = $this->megbizas->money;
// $transfer->comment = "Csoportos beszedes";
// $transfer->id_user = \Yii::$app->user->id;
// $transfer->id_customer = $this->ticket->id_customer;
// $transfer->save(false);
// }
public function hasError() {
return count ( $this->errors ) > 0;
}
public function isDryRun() {
return $this->dryRun;
}
}