mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Add deleted_at column to paymentables
This commit is contained in:
parent
a1119f9bbe
commit
4b240b05ca
@ -322,8 +322,8 @@ class CheckData extends Command
|
||||
$total_invoice_payments = 0;
|
||||
|
||||
foreach ($client->invoices->where('is_deleted', false) as $invoice) {
|
||||
$total_amount = $invoice->payments->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->sum('pivot.refunded');
|
||||
$total_amount = $invoice->payments->whereNull('deleted_at')->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded');
|
||||
|
||||
$total_invoice_payments += ($total_amount - $total_refund);
|
||||
}
|
||||
|
@ -438,11 +438,13 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyPaymentRequest $request, Payment $payment)
|
||||
{
|
||||
$payment->service()->reversePayment();
|
||||
// $payment->service()->deletePayment();
|
||||
|
||||
$payment->is_deleted = true;
|
||||
$payment->save();
|
||||
$payment->delete();
|
||||
// $payment->is_deleted = true;
|
||||
// $payment->save();
|
||||
// $payment->delete();
|
||||
|
||||
$this->payment_repo->delete($payment);
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
}
|
||||
|
@ -12,9 +12,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Paymentable extends Pivot
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'paymentables';
|
||||
|
||||
//protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||
|
@ -40,6 +40,7 @@ class DeletePayment
|
||||
->updateCreditables() //return the credits first
|
||||
->adjustInvoices()
|
||||
->updateClient()
|
||||
->deletePaymentables()
|
||||
->save();
|
||||
}
|
||||
|
||||
@ -51,6 +52,13 @@ class DeletePayment
|
||||
|
||||
//set applied amount to 0
|
||||
|
||||
private function deletePaymentables()
|
||||
{
|
||||
$this->payment->paymentables()->update(['deleted_at' => now()]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function updateClient()
|
||||
{
|
||||
$this->payment->client->service()->updatePaidToDate(-1 * $this->payment->amount)->save();
|
||||
@ -66,7 +74,7 @@ class DeletePayment
|
||||
$paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount)->save();
|
||||
$paymentable_invoice->client->service()->updateBalance($paymentable_invoice->pivot->amount)->save();
|
||||
|
||||
if (floatval($paymentable_invoice->balance) == 0) {
|
||||
if ($paymentable_invoice->balance == $paymentable_invoice->amount) {
|
||||
$paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save();
|
||||
} else {
|
||||
$paymentable_invoice->service()->setStatus(Invoice::STATUS_PARTIAL)->save();
|
||||
|
@ -46,6 +46,7 @@ class PaymentableTransformer extends EntityTransformer
|
||||
'refunded' => (float) $paymentable->refunded,
|
||||
'created_at' => (int) $paymentable->created_at,
|
||||
'updated_at' => (int) $paymentable->updated_at,
|
||||
'archived_at' => (int) $paymentable->deleted_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SoftDeletePaymentables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('paymentables', function(Blueprint $table){
|
||||
$table->softDeletes('deleted_at', 6);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user