1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/app/Repositories/CreditRepository.php

72 lines
1.5 KiB
PHP
Raw Normal View History

2020-01-03 10:34:10 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2020-01-03 10:34:10 +01:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2020-01-03 10:34:10 +01:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-01-03 10:34:10 +01:00
*/
namespace App\Repositories;
use App\Models\Credit;
use App\Models\CreditInvitation;
use App\Utils\Traits\MakesHash;
2020-01-03 10:34:10 +01:00
/**
* CreditRepository.
2020-01-03 10:34:10 +01:00
*/
class CreditRepository extends BaseRepository
{
use MakesHash;
2020-01-03 10:34:10 +01:00
public function __construct()
{
}
/**
* Saves the client and its contacts.
2020-01-03 10:34:10 +01:00
*
2020-10-28 11:10:49 +01:00
* @param array $data The data
* @param Credit $credit
* @return Credit|Credit|null Credit Object
* @throws \ReflectionException
2020-01-03 10:34:10 +01:00
*/
2024-01-14 05:05:00 +01:00
public function save(array $data, Credit $credit): ?Credit
2020-01-03 10:34:10 +01:00
{
return $this->alternativeSave($data, $credit);
}
2024-01-14 05:05:00 +01:00
public function getInvitationByKey($key): ?CreditInvitation
{
2023-08-06 09:35:19 +02:00
return CreditInvitation::query()->where('key', $key)->first();
2020-01-03 10:34:10 +01:00
}
2022-08-22 02:27:11 +02:00
public function delete($credit)
{
if ($credit->is_deleted) {
return;
}
$credit = $credit->service()->deleteCredit()->save();
2022-08-22 03:07:11 +02:00
return parent::delete($credit);
2022-08-22 02:27:11 +02:00
}
public function restore($credit)
{
//we cannot restore a deleted payment.
2022-08-22 03:21:43 +02:00
if (! $credit->trashed()) {
2022-08-22 02:27:11 +02:00
return;
}
parent::restore($credit);
$credit = $credit->service()->restoreCredit()->save();
return $credit;
}
}