add ticket installment

This commit is contained in:
2016-01-22 14:45:56 +01:00
parent bb5978c1df
commit a2a6b1f240
51 changed files with 1498 additions and 113 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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',
];
}

View File

@@ -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);
}
}
}

View File

@@ -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",
]
;
}