2018-10-15 14:40:34 +02:00
|
|
|
<?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
|
|
|
|
*/
|
2018-10-15 14:40:34 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-08-19 08:50:33 +02:00
|
|
|
use App\Models\BaseModel;
|
2019-10-04 00:06:38 +02:00
|
|
|
use App\Models\DateFormat;
|
2019-05-03 09:57:55 +02:00
|
|
|
use App\Models\Filterable;
|
2019-12-16 12:34:38 +01:00
|
|
|
use App\Models\Paymentable;
|
2019-10-03 23:51:54 +02:00
|
|
|
use App\Utils\Number;
|
2019-10-04 00:06:38 +02:00
|
|
|
use App\Utils\Traits\MakesDates;
|
2018-11-20 05:36:56 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-10-15 14:40:34 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-11-18 11:46:01 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2018-10-15 14:40:34 +02:00
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
class Payment extends BaseModel
|
2018-10-15 14:40:34 +02:00
|
|
|
{
|
2018-11-20 05:36:56 +01:00
|
|
|
use MakesHash;
|
2019-05-03 09:57:55 +02:00
|
|
|
use Filterable;
|
2019-10-04 00:06:38 +02:00
|
|
|
use MakesDates;
|
2019-11-18 11:46:01 +01:00
|
|
|
use SoftDeletes;
|
|
|
|
|
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;
|
|
|
|
|
2019-08-19 08:50:33 +02:00
|
|
|
const TYPE_CREDIT_CARD = 1;
|
|
|
|
const TYPE_BANK_TRANSFER = 2;
|
|
|
|
const TYPE_PAYPAL = 3;
|
2019-11-27 10:47:59 +01:00
|
|
|
const TYPE_CRYPTO = 4;
|
2019-08-19 08:50:33 +02:00
|
|
|
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';
|
|
|
|
|
2019-06-26 06:04:10 +02:00
|
|
|
protected $fillable = [
|
|
|
|
'client_id',
|
2019-12-16 12:34:38 +01:00
|
|
|
'type_id',
|
2019-06-26 06:04:10 +02:00
|
|
|
'amount',
|
2019-12-16 12:34:38 +01:00
|
|
|
'date',
|
2019-06-26 06:04:10 +02:00
|
|
|
'transaction_reference'
|
2018-11-20 05:36:56 +01:00
|
|
|
];
|
|
|
|
|
2019-09-02 07:08:26 +02:00
|
|
|
protected $casts = [
|
2019-09-26 00:27:26 +02:00
|
|
|
'settings' => 'object',
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-11-19 22:06:48 +01:00
|
|
|
'is_deleted' => 'bool',
|
2019-09-02 07:08:26 +02:00
|
|
|
];
|
|
|
|
|
2019-05-03 09:57:55 +02:00
|
|
|
public function client()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->belongsTo(Client::class)->withTrashed();
|
2019-05-03 09:57:55 +02:00
|
|
|
}
|
2018-11-20 05:36:56 +01:00
|
|
|
|
2019-05-03 09:57:55 +02:00
|
|
|
public function company()
|
2018-11-20 05:36:56 +01:00
|
|
|
{
|
2019-05-03 09:57:55 +02:00
|
|
|
return $this->belongsTo(Company::class);
|
2018-11-20 05:36:56 +01:00
|
|
|
}
|
|
|
|
|
2019-05-03 09:57:55 +02:00
|
|
|
public function user()
|
2018-11-20 05:36:56 +01:00
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
2018-11-20 05:36:56 +01:00
|
|
|
}
|
2019-04-28 07:31:32 +02:00
|
|
|
|
2019-11-05 11:16:38 +01:00
|
|
|
public function assigned_user()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->belongsTo(User::class ,'assigned_user_id', 'id')->withTrashed();
|
2019-11-05 11:16:38 +01:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2019-11-19 11:23:56 +01:00
|
|
|
return $this->morphedByMany(Invoice::class, 'paymentable')->withPivot('amount');
|
2019-05-13 08:18:46 +02:00
|
|
|
}
|
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
|
|
|
|
2019-08-19 08:50:33 +02:00
|
|
|
public function type()
|
2019-08-16 07:20:28 +02:00
|
|
|
{
|
2019-12-16 12:34:38 +01:00
|
|
|
return $this->hasOne(PaymentType::class,'id','type_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function paymentables()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Paymentable::class);
|
2019-08-16 07:20:28 +02:00
|
|
|
}
|
|
|
|
|
2019-10-03 23:51:54 +02:00
|
|
|
public function formattedAmount()
|
|
|
|
{
|
|
|
|
return Number::formatMoney($this->amount, $this->client);
|
|
|
|
}
|
|
|
|
|
2019-10-04 00:06:38 +02:00
|
|
|
public function clientPaymentDate()
|
|
|
|
{
|
2019-12-16 12:34:38 +01:00
|
|
|
if(!$this->date)
|
2019-10-08 01:05:41 +02:00
|
|
|
return '';
|
|
|
|
|
2019-10-04 00:06:38 +02:00
|
|
|
$date_format = DateFormat::find($this->client->getSetting('date_format_id'));
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
return $this->createClientDate($this->date, $this->client->timezone()->name)->format($date_format->format);
|
2019-10-04 00:06:38 +02:00
|
|
|
}
|
|
|
|
|
2019-08-16 07:20:28 +02:00
|
|
|
public static function badgeForStatus(int $status)
|
|
|
|
{
|
|
|
|
switch ($status) {
|
2019-08-19 08:50:33 +02:00
|
|
|
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>';
|
2019-08-19 08:50:33 +02:00
|
|
|
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>';
|
2019-08-19 08:50:33 +02:00
|
|
|
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>';
|
2019-08-19 08:50:33 +02:00
|
|
|
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>';
|
2019-08-19 08:50:33 +02:00
|
|
|
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;
|
2019-08-19 08:50:33 +02:00
|
|
|
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>';
|
2019-08-19 08:50:33 +02:00
|
|
|
break;
|
2019-08-16 07:20:28 +02:00
|
|
|
default:
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-12 05:41:02 +01:00
|
|
|
|
|
|
|
public function resolveRouteBinding($value)
|
|
|
|
{
|
|
|
|
return $this
|
2019-11-18 11:46:01 +01:00
|
|
|
->withTrashed()
|
2019-11-12 05:41:02 +01:00
|
|
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
|
|
|
}
|
2018-10-15 14:40:34 +02:00
|
|
|
}
|