diff --git a/app/Http/Controllers/PaymentApiController.php b/app/Http/Controllers/PaymentApiController.php index d6f623aab881..f61bb53908fc 100644 --- a/app/Http/Controllers/PaymentApiController.php +++ b/app/Http/Controllers/PaymentApiController.php @@ -46,7 +46,7 @@ class PaymentApiController extends BaseAPIController { $paginator = Payment::scope(); $payments = Payment::scope() - ->with('client.contacts', 'invitation', 'user', 'invoice'); + ->with('client.contacts', 'invitation', 'user', 'invoice')->withTrashed(); if ($clientPublicId = Input::get('client_id')) { $filter = function($query) use ($clientPublicId) { @@ -95,23 +95,23 @@ class PaymentApiController extends BaseAPIController $error = false; if ($request->action == ACTION_ARCHIVE) { - $payment = Payment::scope($publicId)->firstOrFail(); + $payment = Payment::scope($publicId)->withTrashed()->firstOrFail(); $this->paymentRepo->archive($payment); - $invoice = Invoice::scope($data['invoice_id'])->with('client')->first(); + $invoice = Invoice::scope($data['invoice_id'])->with('client','payments')->withTrashed()->first(); $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); $data = $this->createItem($invoice, $transformer, 'invoice'); return $this->response($data); } - $this->paymentRepo->save($data); + $payment = $this->paymentRepo->save($data); if ($error) { return $error; } - $invoice = Invoice::scope($data['invoice_id'])->with('client', 'invoice_items', 'invitations','payments')->first(); + $invoice = Invoice::scope($data['invoice_id'])->with('client', 'invoice_items', 'invitations','payments')->withTrashed()->first(); $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); $data = $this->createItem($invoice, $transformer, 'invoice'); return $this->response($data); @@ -208,11 +208,14 @@ class PaymentApiController extends BaseAPIController public function destroy($publicId) { + $payment = Payment::scope($publicId)->withTrashed()->first(); - $invoice = Invoice::scope($payment->invoice->public_id)->first(); + $invoiceId = $payment->invoice->public_id; $this->paymentRepo->delete($payment); + $invoice = Invoice::scope($invoiceId)->with('payments')->withTrashed()->first(); + $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); $data = $this->createItem($invoice, $transformer, 'invoice'); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 349b650e0f01..e93c8d3b07f5 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -179,7 +179,7 @@ class Invoice extends EntityModel implements BalanceAffecting public function payments() { - return $this->hasMany('App\Models\Payment', 'invoice_id', 'id')->withTrashed(); + return $this->hasMany('App\Models\Payment', 'invoice_id', 'id'); } public function recurring_invoice()