%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/loslex/demo/app/Models/
Upload File :
Create Path :
Current File : /www/loslex/demo/app/Models/Registration.php

<?php

namespace App\Models;

use App\Models\Contest;
use App\Models\ContestDivision;
use App\Models\User;
use App\Workers\AccountNote;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Sunfox\Spayd\Model\CzechAccount;
use Sunfox\Spayd\Spayd;
use Sunfox\Spayd\Utilities\IbanUtilities;


class Registration extends Model
{
    protected $fillable = [
        'contest_id',
        'user_id',
        'licence_number',
        'contest_division_id',
        'squad',
        'note',
    ];

    protected $hidden = [
        'canceltoken',
    ];

    /* Get the user that owns the Registration */
    /* @return \Illuminate\Database\Eloquent\Relations\BelongsTo */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /* Get the Contest related to the Registration */
    /* @return \Illuminate\Database\Eloquent\Relations\BelongsTo */
    public function contest(): BelongsTo
    {
        return $this->belongsTo(Contest::class);
    }

    public function division(): BelongsTo
    {
        return $this->belongsTo(ContestDivision::class, 'contest_division_id');
    }

    public function paymentnote(): Attribute
    {
        return Attribute::make(
            get: function () {
                $paymentnote = new AccountNote($this->contest->accnote, $this->user);
                return $paymentnote->getPaymentNote();
            }
        );
    }

    public function qrpaymentnote(): Attribute
    {
        return Attribute::make(
            get: function () {
                $paymentnote = new AccountNote($this->contest->accnote ?? "", $this->user);
                return $paymentnote->getQRPaymentNote();
            }
        );
    }

    public function spayd(): Attribute
    {
        return Attribute::make(
            get: function() {
                $spayd = new Spayd;
                $spayd->add('AM', $this->user->is_valid_member($this->contest->date) > 0 ? $this->contest->feelex : $this->contest->feeothers);
                $spayd->add('CC', 'CZK');
                if ($this->qrpaymentnote->isNotEmpty()) { $spayd->add('MSG', $this->qrpaymentnote); }



                $account = new CzechAccount($this->contest->accountnumber);
                $spayd->add('ACC', IbanUtilities::computeIbanFromBankAccount($account));

                if (isset($this->contest->accvarsym)) { $spayd->add('X-VS', $this->contest->accvarsym); }

                return (string) $spayd;
            }
        );
    }

    public function qr(): Attribute
    {
        return Attribute::make(
            get: function() {
                return QrCode::size(200)->margin(2)->generate($this->spayd);
            }
        );
    }

    public function qrimg(): Attribute
    {
        return Attribute::make(
            get: function() {
                return QrCode::size(200)->margin(2)->format('png')->generate($this->spayd);
            }
        );
    }
}

Zerion Mini Shell 1.0