1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Models/Payment.php

116 lines
3.1 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Models;
use App\Models\BaseModel;
2019-05-03 09:57:55 +02:00
use App\Models\Filterable;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
class Payment extends BaseModel
{
use MakesHash;
2019-05-03 09:57:55 +02:00
use Filterable;
2019-05-13 08:18:46 +02:00
const STATUS_PENDING = 1;
const STATUS_VOIDED = 2;
const STATUS_FAILED = 3;
const STATUS_COMPLETED = 4;
const STATUS_PARTIALLY_REFUNDED = 5;
const STATUS_REFUNDED = 6;
const TYPE_CREDIT_CARD = 1;
const TYPE_BANK_TRANSFER = 2;
const TYPE_PAYPAL = 3;
const TYPE_BITCOIN = 4;
const TYPE_DWOLLA = 5;
const TYPE_CUSTOM1 = 6;
const TYPE_ALIPAY = 7;
const TYPE_SOFORT = 8;
const TYPE_SEPA = 9;
const TYPE_GOCARDLESS = 10;
const TYPE_APPLE_PAY = 11;
const TYPE_CUSTOM2 = 12;
const TYPE_CUSTOM3 = 13;
const TYPE_TOKEN = 'token';
protected $fillable = [
'client_id',
'payment_type_id',
'amount',
'payment_date',
'transaction_reference'
];
2019-05-03 09:57:55 +02:00
public function client()
{
return $this->belongsTo(Client::class);
}
2019-05-03 09:57:55 +02:00
public function company()
{
2019-05-03 09:57:55 +02:00
return $this->belongsTo(Company::class);
}
2019-05-03 09:57:55 +02:00
public function user()
{
2019-05-03 09:57:55 +02:00
return $this->belongsTo(User::class);
}
2019-04-28 07:31:32 +02:00
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
2019-05-13 08:18:46 +02:00
public function invoices()
{
return $this->morphedByMany(Invoice::class, 'paymentable');
}
2019-05-15 07:03:18 +02:00
public function company_ledger()
{
return $this->morphMany(CompanyLedger::class, 'company_ledgerable');
}
2019-08-16 07:20:28 +02:00
public function type()
2019-08-16 07:20:28 +02:00
{
return $this->hasOne(PaymentType::class,'id','payment_type_id');
2019-08-16 07:20:28 +02:00
}
public static function badgeForStatus(int $status)
{
switch ($status) {
case self::STATUS_PENDING:
2019-08-20 00:29:19 +02:00
return '<h6><span class="badge badge-secondary">'.ctrans('texts.payment_status_1').'</span></h6>';
break;
case self::STATUS_VOIDED:
2019-08-20 00:29:19 +02:00
return '<h6><span class="badge badge-warning">'.ctrans('texts.payment_status_2').'</span></h6>';
break;
case self::STATUS_FAILED:
2019-08-20 00:29:19 +02:00
return '<h6><span class="badge badge-danger">'.ctrans('texts.payment_status_3').'</span></h6>';
break;
case self::STATUS_COMPLETED:
2019-08-20 00:29:19 +02:00
return '<h6><span class="badge badge-info">'.ctrans('texts.payment_status_4').'</span></h6>';
break;
case self::STATUS_PARTIALLY_REFUNDED:
2019-08-20 00:29:19 +02:00
return '<h6><span class="badge badge-success">'.ctrans('texts.payment_status_5').'</span></h6>';
2019-08-16 07:20:28 +02:00
break;
case self::STATUS_REFUNDED:
2019-08-20 00:29:19 +02:00
return '<h6><span class="badge badge-primary">'.ctrans('texts.payment_status_6').'</span></h6>';
break;
2019-08-16 07:20:28 +02:00
default:
# code...
break;
}
}
}