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) {
|
||||
|
||||
@@ -233,7 +233,8 @@ class AccountState extends \common\models\BaseFitnessActiveRecord
|
||||
$this->prev_state = $lastOpen->id_account_state;
|
||||
$this->prev_money = $lastOpen->money;
|
||||
}
|
||||
$end = date("Y-m-d H:i:s");
|
||||
$end = date('Y-m-d H:i:s' );
|
||||
// $end = Yii::$app->formatter->asDatetime(strtotime("now"), "php:Y-m-d H:i:s");
|
||||
$this->collection_money = Transfer::readPaid($start, $end, Yii::$app->user->id);
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
const TYPE_OUT = 10;
|
||||
const TYPE_IN = 20;
|
||||
|
||||
const STATUS_PAID = 20;
|
||||
const STATUS_STORNO = 30;
|
||||
|
||||
public $_account;
|
||||
|
||||
/**
|
||||
@@ -140,4 +143,23 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
return self::typeName($this->type);
|
||||
}
|
||||
|
||||
public static function statuses( ) {
|
||||
return [
|
||||
MoneyMovement::STATUS_PAID => 'Fizetve',
|
||||
MoneyMovement::STATUS_STORNO => 'Törölve',
|
||||
];
|
||||
}
|
||||
|
||||
public static function toStatusName($id_status){
|
||||
$result = "Ismeretlen";
|
||||
$statuses = Ticket::statuses();
|
||||
if ( array_key_exists($id_status, $statuses)){
|
||||
$result = $statuses[$id_status];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getStatusName(){
|
||||
return static::toStatusName($this->status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class Sale extends \yii\db\ActiveRecord
|
||||
|
||||
const STATUS_NOT_PAID = 10;
|
||||
const STATUS_PAID = 20;
|
||||
const STATUS_DELETED= 30;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -140,4 +141,26 @@ class Sale extends \yii\db\ActiveRecord
|
||||
return $sale;
|
||||
}
|
||||
|
||||
|
||||
public static function statuses( ) {
|
||||
return [
|
||||
Sale::STATUS_PAID => 'Aktív',
|
||||
Sale::STATUS_DELETED => 'Törölve',
|
||||
Sale::STATUS_NOT_PAID => 'Nincs fizetve',
|
||||
];
|
||||
}
|
||||
|
||||
public static function toStatusName($id_status){
|
||||
$result = "Ismeretlen";
|
||||
$statuses = Sale::statuses();
|
||||
if ( array_key_exists($id_status, $statuses)){
|
||||
$result = $statuses[$id_status];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getStatusName(){
|
||||
return static::toStatusName($this->status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ use common\components\Helper;
|
||||
* @property integer $usage_count
|
||||
* @property integer $status
|
||||
* @property integer $price_brutto
|
||||
* @property integer $part eddig a részletig kell kifizetve lenni
|
||||
* @property integer $part_count ennyi részlet van összesen
|
||||
* @property integer $part_paid ennyi részlet van kifizetve
|
||||
* @property string $comment
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
@@ -31,6 +34,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
const STATUS_DELETED = 0;
|
||||
const STATUS_ACTIVE = 10;
|
||||
const STATUS_INACTIVE = 20;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -200,10 +204,10 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
new Expression( 'ticket_type.name as name'),
|
||||
new Expression( 'coalesce( count(ticket.id_ticket),0) as total'),
|
||||
|
||||
new Expression( "coalesce( sum( case when ". Helper::sqlValidRule('ticket.start', 'ticket.end', ':start', ':end') . " then 1 else 0 end) , 0) as valid" ), //valid
|
||||
new Expression( "coalesce( sum( case when ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then 1 else 0 end) , 0) as created" ),//created
|
||||
new Expression( "coalesce( sum( case when ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then transfer.money else 0 end) , 0) as created_money" ),//created_money
|
||||
new Expression( "coalesce( sum( case when " . Helper::sqlExpireRule('ticket.start', 'ticket.end', ':start', ":end") . " then 1 else 0 end) , 0) as expired" ),
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND ". Helper::sqlValidRule('ticket.start', 'ticket.end', ':start', ':end') . " then 1 else 0 end) , 0) as valid" ), //valid
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then 1 else 0 end) , 0) as created" ),//created
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then transfer.money else 0 end) , 0) as created_money" ),//created_money
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND " . Helper::sqlExpireRule('ticket.start', 'ticket.end', ':start', ":end") . " then 1 else 0 end) , 0) as expired" ),
|
||||
|
||||
|
||||
]);
|
||||
@@ -237,6 +241,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
return [
|
||||
Ticket::STATUS_ACTIVE => 'Aktív',
|
||||
Ticket::STATUS_DELETED => 'Törölve',
|
||||
Ticket::STATUS_INACTIVE => 'Inaktív',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -249,4 +254,62 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getStatusName(){
|
||||
return static::toStatusName($this->status);
|
||||
}
|
||||
|
||||
public function isDeleted(){
|
||||
return $this->status == Ticket::STATUS_DELETED;
|
||||
}
|
||||
|
||||
/**csoportos beszedéses a bérlet*/
|
||||
public function isInstallmentTicket(){
|
||||
return ( isset($this->part_count) && $this->part_count > 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply request
|
||||
*
|
||||
* @var common\models\TicketInstallmentRequest $request megbízás
|
||||
* */
|
||||
public function applyTicketInstallmentRequest( $request ) {
|
||||
//ha csoportos beszedéses
|
||||
if ( $this->isInstallmentTicket() ){
|
||||
if ( $request->isStatusAccepted() ){
|
||||
if ( $this->part_paid < $request->priority ){
|
||||
$this->part_paid = $request->priority;
|
||||
}
|
||||
$this->recalclulate();
|
||||
}else if ( $request->isStatusRejected() ){
|
||||
$this->status = static::STATUS_INACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* *
|
||||
* @param common\models\TicketInstallmentRequest $request megbízás
|
||||
*/
|
||||
public function setPartRequired($request){
|
||||
// ha keveseb a részlet sorszám mint a bérlet max sorszáma
|
||||
if ( $request->priority <= $this->part_count ){
|
||||
//ha az aktuális elvárt részlet kisebb , mint a megbízása
|
||||
if ( $this->part < $request-> priority ){
|
||||
$this->part = $request->priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Csoportos beszedéses bérlet érvényességének újraszámolása
|
||||
* */
|
||||
public function recalclulate( ) {
|
||||
if ( $this->isInstallmentTicket() ){
|
||||
$enabled = $this->part_paid >= $this->part;
|
||||
if ( $enabled == true ){
|
||||
$this->status = static::STATUS_ACTIVE;
|
||||
}else{
|
||||
$this->status = static::STATUS_INACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use yii\behaviors\TimestampBehavior;
|
||||
* @property string $request_target_time_at
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property common\components\giro\GiroDETSTATetel $detstaTetel GiroDetstaTetel record a DetSta fájlból
|
||||
*/
|
||||
class TicketInstallmentRequest extends \yii\db\ActiveRecord
|
||||
{
|
||||
@@ -36,6 +37,12 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
|
||||
public static $STATUS_CANCELED = 30;
|
||||
public static $STATUS_REJECTED = 40;
|
||||
public static $STATUS_ACCEPTED = 50;
|
||||
public static $STATUS_ACCEPTED_MANUAL = 60;
|
||||
|
||||
/**
|
||||
* GiroDetstaTetel record a DetSta fájlból
|
||||
* */
|
||||
public $detstaTetel;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -98,6 +105,90 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
|
||||
return $this->hasOne( Customer::className(), ["id_customer" =>"id_customer" ] );
|
||||
}
|
||||
|
||||
public function getTicket(){
|
||||
return $this->hasOne( Ticket::className(), ["id_ticket" =>"id_ticket", ] ) ;
|
||||
}
|
||||
|
||||
public function getUgiro()
|
||||
{
|
||||
return $this->hasOne(Ugiro::className(), [ 'id_ugiro' => 'id_ugiro' ])
|
||||
->viaTable('ugiro_request_assignment', [ 'id_request' => 'id_ticket_installment_request' ]);
|
||||
}
|
||||
|
||||
public function isStatusAccepted(){
|
||||
return $this->status == static::$STATUS_ACCEPTED || $this->status == static::$STATUS_ACCEPTED_MANUAL;
|
||||
}
|
||||
public function isStatusRejected(){
|
||||
return $this->status == static::$STATUS_REJECTED ;
|
||||
}
|
||||
|
||||
public function getIdGiro(){
|
||||
$result = null;
|
||||
$giro = $this->ugiro;
|
||||
if ( isset($giro) ){
|
||||
$result = $giro->id_ugiro;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Megbízás státuszának beállítása
|
||||
*
|
||||
* Létrehozza a szükséges ticket/transfer objectumokat
|
||||
*
|
||||
* @param boolean $partRequired ha igaz, a bérleten a part mezőt változtatjuk
|
||||
* */
|
||||
public function applyStatus($status, $partRequired = false, $visszajelzes = "", $comment = ""){
|
||||
if ( $status == static::$STATUS_ACCEPTED || $status == static::$STATUS_ACCEPTED_MANUAL){
|
||||
if ( !$this->isStatusAccepted() ){
|
||||
$this->status = $status;
|
||||
$tranfer = $this->addTransfer();
|
||||
$this->id_transfer = $tranfer->id_transfer;
|
||||
$this->save(false);
|
||||
$this->applyNewTicketState($partRequired);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
$this->status = $status;
|
||||
$this->save(false);
|
||||
$this->applyNewTicketState($partRequired);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyNewTicketState($partRequired = false){
|
||||
if ( $partRequired ){
|
||||
$this->ticket->setPartRequired($this);
|
||||
}
|
||||
$this->ticket->applyTicketInstallmentRequest($this);
|
||||
$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->money;
|
||||
$transfer->comment = "Csoportos beszedes";
|
||||
$transfer->id_user = \Yii::$app->user->id;
|
||||
$transfer->id_customer = $this->ticket->card->customer->id_customer;
|
||||
$transfer->save(false);
|
||||
return $transfer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param common\models\Ticket $ticket
|
||||
* @param common\models\TicketType $type
|
||||
@@ -107,8 +198,12 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
|
||||
$result = [];
|
||||
if ( $type->isInstallment() ){
|
||||
$count = $type->installment_count;
|
||||
$ticketCreatedAt = time();
|
||||
$discount = $ticket->discount;
|
||||
$money = $type->price_brutto;
|
||||
if ( isset($discount ) ){
|
||||
$money = Discount::applyDiscount($money, $discount);
|
||||
}
|
||||
$ticketCreatedAt = time();
|
||||
for ( $i = 1; $i <= $count; $i++){
|
||||
$request = TicketInstallmentRequest::createInstallment($ticket, $type, $customer, $money, $ticketCreatedAt, $i);
|
||||
$result[] = $request;
|
||||
@@ -140,6 +235,7 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
|
||||
TicketInstallmentRequest::$STATUS_CANCELED=> 'Törölve',
|
||||
TicketInstallmentRequest::$STATUS_REJECTED=> 'Visszautasítva',
|
||||
TicketInstallmentRequest::$STATUS_ACCEPTED=> 'Sikeresen végrehajtva',
|
||||
TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL=> 'Manuálisan elfogadva',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
const STATUS_NOT_PAID = 10;
|
||||
const STATUS_PAID = 20;
|
||||
const STATUS_STORNO = 30;
|
||||
|
||||
const DIRECTION_OUT = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY )
|
||||
const DIRECTION_IN = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY )
|
||||
@@ -477,6 +478,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
return [
|
||||
self::STATUS_NOT_PAID => Yii::t('common/transfer','Nincs fizetve'),
|
||||
self::STATUS_PAID => Yii::t('common/transfer','Fizetve'),
|
||||
self::STATUS_STORNO => Yii::t('common/transfer','Törölve'),
|
||||
];
|
||||
}
|
||||
public function getStatusName( ) {
|
||||
@@ -751,6 +753,28 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function storno(){
|
||||
$this->status = Transfer::STATUS_STORNO;
|
||||
$this->save(false);
|
||||
if ( $this->type == Transfer::TYPE_TICKET){
|
||||
$ticket = $this->ticket;
|
||||
$ticket->status = Ticket::STATUS_DELETED;
|
||||
$ticket->save(false);
|
||||
|
||||
TicketInstallmentRequest::updateAll(
|
||||
['status' => TicketInstallmentRequest::$STATUS_CANCELED ],
|
||||
['id_ticket' => $this->ticket->id_ticket ]
|
||||
);
|
||||
|
||||
}else if ( $this->type == Transfer::TYPE_PRODUCT ){
|
||||
$sale = $this->sale;
|
||||
$sale->status = Sale::STATUS_DELETED;
|
||||
$sale->save(false);
|
||||
}else if ( $this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT ){
|
||||
$mm = $this->moneyMovement;
|
||||
$mm->status = MoneyMovement::STATUS_STORNO;
|
||||
$mm->save(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ use yii\helpers\ArrayHelper;
|
||||
*
|
||||
* @property integer $id_ugiro
|
||||
* @property integer $id_user
|
||||
* @property string $path
|
||||
* @property string $desta_path
|
||||
* @property string $datum
|
||||
* @property integer $number
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
*/
|
||||
@@ -18,8 +22,10 @@ class Ugiro extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
public static $PATH_MEGBIZAS = "giro/megbizas";
|
||||
public static $PATH_VALASZ = "giro/valasz";
|
||||
public static $STATUS_SENT = 0;
|
||||
public static $STATUS_FINISHED = 1;
|
||||
public static $STATUS_RECIEVED = 10;
|
||||
public static $STATUS_FINISHED = 20;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -66,10 +72,19 @@ class Ugiro extends \yii\db\ActiveRecord
|
||||
return $this->hasOne( User::className(), ["id" =>"id_user" ] );
|
||||
}
|
||||
|
||||
|
||||
public function getRequests()
|
||||
{
|
||||
return $this->hasMany(TicketInstallmentRequest::className(), ['id_ticket_installment_request' => 'id_request'])
|
||||
->viaTable('ugiro_request_assignment', ['id_ugiro' => 'id_ugiro']);
|
||||
}
|
||||
|
||||
|
||||
public static function statuses() {
|
||||
return [
|
||||
static::$STATUS_SENT =>"Folyamatban",
|
||||
static::$STATUS_FINISHED =>"Befejezve",
|
||||
static::$STATUS_RECIEVED =>"Detsta fájl feltöltve",
|
||||
]
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user