mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Enabled restoring deleted invoices and payments
This commit is contained in:
parent
ea6cd9e012
commit
0b2705b943
@ -189,6 +189,7 @@ class AppController extends BaseController
|
||||
Artisan::call('db:seed', array('--force' => true, '--class' => 'PaymentLibrariesSeeder'));
|
||||
Artisan::call('optimize', array('--force' => true));
|
||||
Cache::flush();
|
||||
Session::flush();
|
||||
Event::fire(new UserSettingsChanged());
|
||||
Session::flash('message', trans('texts.processed_updates'));
|
||||
} catch (Exception $e) {
|
||||
|
@ -101,9 +101,6 @@ class InvoiceController extends BaseController
|
||||
->addColumn('end_date', function ($model) { return Utils::fromSqlDate($model->end_date); })
|
||||
->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id); })
|
||||
->addColumn('dropdown', function ($model) {
|
||||
if ($model->is_deleted) {
|
||||
return '<div style="height:38px"/>';
|
||||
}
|
||||
|
||||
$str = '<div class="btn-group tr-action" style="visibility:hidden;">
|
||||
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
|
||||
|
@ -71,7 +71,7 @@ class PaymentController extends BaseController
|
||||
return $table->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id); })
|
||||
->addColumn('payment_date', function ($model) { return Utils::dateToString($model->payment_date); })
|
||||
->addColumn('dropdown', function ($model) {
|
||||
if ($model->is_deleted || $model->invoice_is_deleted) {
|
||||
if ($model->invoice_is_deleted) {
|
||||
return '<div style="height:38px"/>';
|
||||
}
|
||||
|
||||
@ -89,6 +89,10 @@ class PaymentController extends BaseController
|
||||
$str .= '<li><a href="javascript:restoreEntity('.$model->public_id.')">'.trans('texts.restore_payment').'</a></li>';
|
||||
}
|
||||
|
||||
if ($model->is_deleted) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
return $str.'<li><a href="javascript:deleteEntity('.$model->public_id.')">'.trans('texts.delete_payment').'</a></li></ul>
|
||||
</div>';
|
||||
})
|
||||
|
@ -158,6 +158,7 @@ Route::group(['middleware' => 'auth'], function() {
|
||||
Route::get('recurring_invoices', 'RecurringInvoiceController@index');
|
||||
Route::get('invoices/{public_id}/clone', 'InvoiceController@cloneInvoice');
|
||||
Route::post('invoices/bulk', 'InvoiceController@bulk');
|
||||
Route::post('recurring_invoices/bulk', 'InvoiceController@bulk');
|
||||
|
||||
Route::get('quotes/create/{client_id?}', 'QuoteController@create');
|
||||
Route::get('quotes/{public_id}/clone', 'InvoiceController@cloneInvoice');
|
||||
|
@ -295,11 +295,13 @@ class ActivityListener
|
||||
|
||||
public function deletedPayment(PaymentWasDeleted $event)
|
||||
{
|
||||
$payment = $event->payment;
|
||||
|
||||
$this->activityRepo->create(
|
||||
$event->payment,
|
||||
$payment,
|
||||
ACTIVITY_TYPE_DELETE_PAYMENT,
|
||||
$event->payment->amount,
|
||||
$event->payment->amount * -1
|
||||
$payment->amount,
|
||||
$payment->amount * -1
|
||||
);
|
||||
}
|
||||
|
||||
@ -317,9 +319,13 @@ class ActivityListener
|
||||
|
||||
public function restoredPayment(PaymentWasRestored $event)
|
||||
{
|
||||
$payment = $event->payment;
|
||||
|
||||
$this->activityRepo->create(
|
||||
$event->payment,
|
||||
ACTIVITY_TYPE_RESTORE_PAYMENT
|
||||
$payment,
|
||||
ACTIVITY_TYPE_RESTORE_PAYMENT,
|
||||
$event->fromDeleted ? $payment->amount * -1 : 0,
|
||||
$event->fromDeleted ? $payment->amount : 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use App\Events\InvoiceWasEmailed;
|
||||
use App\Events\InvoiceWasUpdated;
|
||||
use App\Events\PaymentWasCreated;
|
||||
use App\Events\PaymentWasDeleted;
|
||||
use App\Events\PaymentWasRestored;
|
||||
use App\Events\InvoiceInvitationWasViewed;
|
||||
|
||||
class InvoiceListener
|
||||
@ -40,4 +41,18 @@ class InvoiceListener
|
||||
$invoice->updateBalances($adjustment);
|
||||
$invoice->updatePaidStatus();
|
||||
}
|
||||
|
||||
public function restoredPayment(PaymentWasRestored $event)
|
||||
{
|
||||
if ( ! $event->fromDeleted) {
|
||||
return;
|
||||
}
|
||||
|
||||
$payment = $event->payment;
|
||||
$invoice = $payment->invoice;
|
||||
$adjustment = $payment->amount * -1;
|
||||
|
||||
$invoice->updateBalances($adjustment);
|
||||
$invoice->updatePaidStatus();
|
||||
}
|
||||
}
|
||||
|
@ -197,6 +197,10 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
|
||||
public function updateBalances($balanceAdjustment, $partial = 0)
|
||||
{
|
||||
if ($this->is_deleted) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->balance = $this->balance + $balanceAdjustment;
|
||||
|
||||
if ($this->partial > 0) {
|
||||
|
@ -151,10 +151,6 @@ class InvoiceRepository extends BaseRepository
|
||||
->addColumn('invoice_status_name', function ($model) { return $model->quote_invoice_id ? link_to("invoices/{$model->quote_invoice_id}/edit", trans('texts.converted')) : self::getStatusLabel($model->invoice_status_id, $model->invoice_status_name); })
|
||||
->addColumn('dropdown', function ($model) use ($entityType) {
|
||||
|
||||
if ($model->is_deleted) {
|
||||
return '<div style="height:38px"/>';
|
||||
}
|
||||
|
||||
$str = '<div class="btn-group tr-action" style="visibility:hidden;">
|
||||
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
|
||||
'.trans('texts.select').' <span class="caret"></span>
|
||||
@ -188,11 +184,14 @@ class InvoiceRepository extends BaseRepository
|
||||
}
|
||||
|
||||
$str .= '<li class="divider"></li>
|
||||
<li><a href="javascript:archiveEntity('.$model->public_id.')">'.trans("texts.archive_{$entityType}").'</a></li>
|
||||
<li><a href="javascript:deleteEntity('.$model->public_id.')">'.trans("texts.delete_{$entityType}").'</a></li>';
|
||||
<li><a href="javascript:archiveEntity('.$model->public_id.')">'.trans("texts.archive_{$entityType}").'</a></li>';
|
||||
|
||||
} else {
|
||||
$str .= '<li><a href="javascript:restoreEntity('.$model->public_id.')">'.trans("texts.restore_{$entityType}").'</a></li>
|
||||
<li><a href="javascript:deleteEntity('.$model->public_id.')">'.trans("texts.delete_{$entityType}").'</a></li>';
|
||||
$str .= '<li><a href="javascript:restoreEntity('.$model->public_id.')">'.trans("texts.restore_{$entityType}").'</a></li>';
|
||||
}
|
||||
|
||||
if (!$model->is_deleted) {
|
||||
$str .= '<li><a href="javascript:deleteEntity('.$model->public_id.')">'.trans("texts.delete_{$entityType}").'</a></li>';
|
||||
}
|
||||
|
||||
return $str.'</ul>
|
||||
|
@ -27,11 +27,29 @@ class PaymentRepository extends BaseRepository
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->where('contacts.deleted_at', '=', null)
|
||||
->select('payments.public_id', 'payments.transaction_reference', 'clients.name as client_name', 'clients.public_id as client_public_id', 'payments.amount', 'payments.payment_date', 'invoices.public_id as invoice_public_id', 'invoices.invoice_number', 'clients.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email', 'payment_types.name as payment_type', 'payments.account_gateway_id', 'payments.deleted_at', 'payments.is_deleted', 'invoices.is_deleted as invoice_is_deleted', 'gateways.name as gateway_name');
|
||||
->where('invoices.deleted_at', '=', null)
|
||||
->select('payments.public_id',
|
||||
'payments.transaction_reference',
|
||||
'clients.name as client_name',
|
||||
'clients.public_id as client_public_id',
|
||||
'payments.amount',
|
||||
'payments.payment_date',
|
||||
'invoices.public_id as invoice_public_id',
|
||||
'invoices.invoice_number',
|
||||
'clients.currency_id',
|
||||
'contacts.first_name',
|
||||
'contacts.last_name',
|
||||
'contacts.email',
|
||||
'payment_types.name as payment_type',
|
||||
'payments.account_gateway_id',
|
||||
'payments.deleted_at',
|
||||
'payments.is_deleted',
|
||||
'invoices.is_deleted as invoice_is_deleted',
|
||||
'gateways.name as gateway_name'
|
||||
);
|
||||
|
||||
if (!\Session::get('show_trash:payment')) {
|
||||
$query->where('payments.deleted_at', '=', null)
|
||||
->where('invoices.deleted_at', '=', null);
|
||||
$query->where('payments.deleted_at', '=', null);
|
||||
}
|
||||
|
||||
if ($clientPublicId) {
|
||||
@ -127,4 +145,24 @@ class PaymentRepository extends BaseRepository
|
||||
|
||||
return $payment;
|
||||
}
|
||||
|
||||
public function delete($payment)
|
||||
{
|
||||
if ($payment->invoice->is_deleted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::delete($payment);
|
||||
}
|
||||
|
||||
public function restore($payment)
|
||||
{
|
||||
if ($payment->invoice->is_deleted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::restore($payment);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ class EventServiceProvider extends ServiceProvider {
|
||||
],
|
||||
'App\Events\PaymentWasRestored' => [
|
||||
'App\Listeners\ActivityListener@restoredPayment',
|
||||
'App\Listeners\InvoiceListener@restoredPayment',
|
||||
],
|
||||
|
||||
// Credits
|
||||
|
@ -389,7 +389,7 @@
|
||||
->dropup() !!}
|
||||
@endif
|
||||
|
||||
@elseif ($invoice && $invoice->trashed() && !$invoice->is_deleted == '1')
|
||||
@elseif ($invoice->trashed())
|
||||
{!! Button::success(trans('texts.restore'))->withAttributes(['onclick' => 'submitBulkAction("restore")'])->appendIcon(Icon::create('cloud-download')) !!}
|
||||
@endif
|
||||
|
||||
|
@ -82,5 +82,13 @@ class CheckBalanceCest
|
||||
$I->amOnPage("/clients/{$clientId}");
|
||||
$I->see('Balance $0.00');
|
||||
$I->see('Paid to Date $0.00');
|
||||
|
||||
// restore the invoice
|
||||
$I->amOnPage('/invoices/' . $invoiceId);
|
||||
$I->executeJS('submitBulkAction("restore")');
|
||||
$I->wait(1);
|
||||
$I->amOnPage("/clients/{$clientId}");
|
||||
$I->see('Balance $0.00');
|
||||
$I->see('Paid to Date $' . ($productPrice * 2));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user