mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
Merge branch 'payment-method-delete' into 'master'
solve payment method delete issue See merge request mohit.panjvani/crater-web!1423
This commit is contained in:
@ -102,7 +102,7 @@ class InvoicesController extends Controller
|
||||
{
|
||||
$this->authorize('delete multiple invoices');
|
||||
|
||||
Invoice::destroy($request->ids);
|
||||
Invoice::deleteInvoices($request->ids);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
||||
@ -84,12 +84,14 @@ class PaymentMethodsController extends Controller
|
||||
{
|
||||
$this->authorize('delete', $paymentMethod);
|
||||
|
||||
$payments = $paymentMethod->payments;
|
||||
|
||||
if ($payments->count() > 0) {
|
||||
if ($paymentMethod->payments()->exists()) {
|
||||
return respondJson('payments_attached', 'Payments Attached.');
|
||||
}
|
||||
|
||||
if ($paymentMethod->expenses()->exists()) {
|
||||
return respondJson('payments_attached', 'Expenses Attached.');
|
||||
}
|
||||
|
||||
$paymentMethod->delete();
|
||||
|
||||
return response()->json([
|
||||
|
||||
@ -17,6 +17,8 @@ class DownloadReceiptController extends Controller
|
||||
*/
|
||||
public function __invoke(Expense $expense)
|
||||
{
|
||||
$this->authorize('view', $expense);
|
||||
|
||||
if ($expense) {
|
||||
$media = $expense->getFirstMedia('receipts');
|
||||
if ($media) {
|
||||
|
||||
@ -698,4 +698,19 @@ class Invoice extends Model implements HasMedia
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public static function deleteInvoices($ids)
|
||||
{
|
||||
foreach ($ids as $id) {
|
||||
$invoice = self::find($id);
|
||||
|
||||
if ($invoice->transactions()->exists()) {
|
||||
$invoice->transactions()->delete();
|
||||
}
|
||||
|
||||
$invoice->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,11 @@ class PaymentMethod extends Model
|
||||
return $this->hasMany(Payment::class);
|
||||
}
|
||||
|
||||
public function expenses()
|
||||
{
|
||||
return $this->hasMany(Expense::class);
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
|
||||
Reference in New Issue
Block a user