add ticket installment
This commit is contained in:
137
common/components/DetStatProcessor.php
Normal file
137
common/components/DetStatProcessor.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?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 = 33;
|
||||
|
||||
$fej = new GiroDETSTAFej();
|
||||
|
||||
$this->detstatUzenet->fej = $fej;
|
||||
|
||||
$tetel = new GiroDETSTATetel();
|
||||
$tetel->ugyfelAzonosito = 12;
|
||||
$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->ugyfelAzonosito] = $tetel;
|
||||
}
|
||||
|
||||
foreach ($this->megbizasok as $megbizas){
|
||||
if ( array_key_exists($megbizas->id_ticket_installment_request, $mapTetel)){
|
||||
$megbizas->detstaTetel = $mapTetel[$megbizas->id_ticket_installment_request];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
129
common/components/DetStatTetelProcessor.php
Normal file
129
common/components/DetStatTetelProcessor.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -29,11 +29,11 @@ class GiroBase {
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function szovegOlvas($row,$start,$length, $padchar = " "){
|
||||
public static function szovegOlvas($row,$start,$length, $padchar = " "){
|
||||
return rtrim(substr($row, $start,$length),$padchar);
|
||||
}
|
||||
|
||||
public function szamOlvas($row,$start,$length, $padchar = "0"){
|
||||
public static function szamOlvas($row,$start,$length, $padchar = "0"){
|
||||
return ltrim(substr($row, $start,$length),$padchar);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,19 +15,24 @@ class GiroBeszed extends GiroBase {
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
public static function createFileContent($id, $requests) {
|
||||
$s = self::createFej($id);
|
||||
$s .= self::createTetelek($requests);
|
||||
|
||||
|
||||
public static function createFileContent($number,$datum /**összeállítás dátum*/, $requests, $terhelesiDatum = null) {
|
||||
if ( !isset($terhelesiDatum)){
|
||||
$terhelesiDatum = date('Ymd' ,strtotime("+5 day"));
|
||||
}
|
||||
$s = self::createFej($number, $datum);
|
||||
$s .= self::createTetelek($requests,$terhelesiDatum);
|
||||
$s .= self::createLab($requests);
|
||||
return $s;
|
||||
}
|
||||
|
||||
public static function createFej($id) {
|
||||
public static function createFej($number, $daturm) {
|
||||
$fej = new GiroBeszedFej ();
|
||||
$fej->duplumKod = \Yii::$app->params['ugiro_duplom_kod'];
|
||||
$fej->kezdemenyezoAzonosito = \Yii::$app->params['ugiro_kezdemenyezo_azonosito'];//"A25366936T244"; // "66658092128";
|
||||
$fej->uzenetSorszam->osszeallitasDatuma = date('Ymd' );
|
||||
$fej->uzenetSorszam->sorszam = $id;
|
||||
$fej->uzenetSorszam->osszeallitasDatuma = $daturm;
|
||||
$fej->uzenetSorszam->sorszam = $number;
|
||||
$fej->kezdemenyezoBankszamla->szamlaszam = \Yii::$app->params['ugiro_kezdemenyezo_szamlaszam']; // "5860025215371128";
|
||||
// $fej->kezdemenyezoBankszamla->bankszerv = "58600252"; // "TAKBHUHB";
|
||||
$fej->ertesitesiHatarido = "";
|
||||
@@ -36,10 +41,12 @@ class GiroBeszed extends GiroBase {
|
||||
return $fej->toString ();
|
||||
}
|
||||
|
||||
public static function createTetelek($requests){
|
||||
public static function createTetelek($requests,$terhelesiDatum){
|
||||
$s = "";
|
||||
$i = 0;
|
||||
foreach ($requests as $request){
|
||||
$s .= self::createTetel($request);
|
||||
$i++;
|
||||
$s .= self::createTetel($request,$i,$terhelesiDatum);
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
@@ -47,19 +54,19 @@ class GiroBeszed extends GiroBase {
|
||||
/**
|
||||
* @param common\models\TicketInstallmentRequest $request
|
||||
* */
|
||||
public static function createTetel($request) {
|
||||
public static function createTetel($request,$sorszam,$terhelesiDatum) {
|
||||
$tetel = new GiroBeszedTetel ();
|
||||
$customer = $request->customer;
|
||||
$tetel->tetelSorszam = $request->id_ticket_installment_request;
|
||||
$tetel->terhelesiDatum = date('Ymd' ,strtotime("+5 day"));;
|
||||
$tetel->tetelSorszam = $sorszam;
|
||||
$tetel->terhelesiDatum = $terhelesiDatum;
|
||||
$tetel->osszeg = $request->money;
|
||||
// $tetel->kotelezettBankszamla->bankszerv = "58600252";
|
||||
$tetel->kotelezettBankszamla->szamlaszam = $customer->bank_account;
|
||||
$tetel->ugyfelazonositoAKezdemenyezonel = $customer->id_customer;
|
||||
$tetel->ugyfelazonositoAKezdemenyezonel = $request->id_ticket_installment_request;
|
||||
// $tetel->ugyfelNeve = "Schneider Roland";
|
||||
// $tetel->ugyfelCime = "Mosonmagyarovar, Gardonyi 31";
|
||||
$tetel->szamlaTulajdonosNeve = $customer->name;
|
||||
$tetel->kozlemeny = "Berlet :" . $request->id_ticket;
|
||||
$tetel->kozlemeny = "Berlet:" . $request->id_ticket .";MegbizasAzo:" . $request->id_ticket_installment_request;
|
||||
|
||||
return $tetel->toString();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ use common\components\giro\GiroBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property common\components\giro\GiroUzenetsorszam $uzenetSorszam
|
||||
* @property common\components\giro\GiroBankszamla $kezdemenyezoBankszamla
|
||||
* @property common\components\giro\GiroDETSTAFej $fej
|
||||
* @property common\components\giro\GiroDETSTALab $lab
|
||||
* @property common\components\giro\GiroDETSTATetel $tetelek
|
||||
*
|
||||
*/
|
||||
class GiroDETSTA extends GiroBase {
|
||||
@@ -20,14 +21,25 @@ class GiroDETSTA extends GiroBase {
|
||||
}
|
||||
|
||||
|
||||
public function toString(){
|
||||
$s = "";
|
||||
$s .= $this->fej->toString();
|
||||
foreach ($this->tetelek as $tetel ){
|
||||
$s .= $tetel->toString();
|
||||
}
|
||||
$s .= $this->lab->toString();
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
public static function parse($content){
|
||||
$detsta = new GiroDETSTA();
|
||||
$array = preg_split("/\r\n|\n|\r/", $content);
|
||||
$detsta->fej = GiroDETSTAFej::parse($array[0]);
|
||||
$detsta->lab = GiroDETSTALab::parse($array[count($array) -1]);
|
||||
$detsta->lab = GiroDETSTALab::parse($array[count($array) -2]);
|
||||
|
||||
for ( $i = 1 ; $i < count($array) -1; $i++ ){
|
||||
for ( $i = 1 ; $i < count($array) -2; $i++ ){
|
||||
$row = $array[$i];
|
||||
$tetel = GiroDETSTATetel::parse($row);
|
||||
$detsta->tetelek[] = $tetel;
|
||||
|
||||
@@ -43,7 +43,7 @@ class GiroDETSTAFej extends GiroBase{
|
||||
$fej->jelentesJelzo = substr($row, 8,1);
|
||||
$fej->kezdemenyezoAzonosito = substr($row, 9,13);
|
||||
$fej->csoportosUzenetSorszam ->osszeallitasDatuma = substr($row, 22, 8);
|
||||
$fej->csoportosUzenetSorszam->sorszam = substr($row, 30, 4);
|
||||
$fej->csoportosUzenetSorszam->sorszam = static::szamOlvas($row, 30, 4);
|
||||
$fej->detstaUzenetSorszam ->osszeallitasDatuma = substr($row, 34,8);
|
||||
$fej->detstaUzenetSorszam->sorszam = substr($row, 42,4);
|
||||
$fej->ido = substr($row, 46,6);
|
||||
|
||||
@@ -17,8 +17,10 @@ class GiroDETSTALab extends GiroBase {
|
||||
public $visszautasitottTetelekOsszerteke = "0";
|
||||
public $megNemValaszoltTetelekSzama = "0";
|
||||
public $megNemValaszoltTetelekOsszerteke = "0";
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function toString() {
|
||||
return $this->recordTipus
|
||||
. $this->szamKitolt ( $this->teljesitettTetelekSzama, 6 )
|
||||
|
||||
@@ -39,7 +39,17 @@ class GiroDETSTATetel extends GiroBase {
|
||||
$this->detstaUzenetSorszam = new GiroUzenetsorszam ();
|
||||
}
|
||||
public function toString() {
|
||||
return $this->recordTipus . $this->szamKitolt ( $this->tetelSorszam, 6 ) . $this->szamKitolt ( $this->osszeg, 10 ) . $this->eredetiTetelElszamolasiDatuma . $this->visszajelzesInformacio . $this->feldolgozasDatum . $this->terhelesiDatum . $this->szovegKitolt ( $this->valaszHivatkozasiKod, 29 ) . $this->szovegKitolt ( $this->eredetiHivatkozasiKod, 29 ) . $this->szovegKitolt ( $this->ugyfelAzonosito, 29 );
|
||||
return $this->recordTipus
|
||||
. $this->szamKitolt ( $this->tetelSorszam, 6 )
|
||||
. $this->szamKitolt ( $this->osszeg, 10 )
|
||||
. $this->eredetiTetelElszamolasiDatuma
|
||||
. $this->visszajelzesInformacio
|
||||
. $this->feldolgozasDatum
|
||||
. $this->terhelesiDatum
|
||||
. $this->szovegKitolt ( $this->valaszHivatkozasiKod, 29 )
|
||||
. $this->szovegKitolt ( $this->eredetiHivatkozasiKod, 29 )
|
||||
. $this->szovegKitolt ( $this->ugyfelAzonosito, 24 )
|
||||
. $this->rekordVege();
|
||||
}
|
||||
|
||||
public static function parse($row) {
|
||||
|
||||
Reference in New Issue
Block a user