diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 743f59445e7f..c940e5f3e397 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -85,7 +85,7 @@ class ProductController extends BaseController $data = [ 'account' => $account, 'taxRates' => $account->invoice_item_taxes ? TaxRate::scope()->get(['id', 'name', 'rate']) : null, - 'product' => Product::scope($publicId)->firstOrFail(), + 'product' => Product::scope($publicId)->withTrashed()->firstOrFail(), 'method' => 'PUT', 'url' => 'products/'.$publicId, 'title' => trans('texts.edit_product'), @@ -137,7 +137,7 @@ class ProductController extends BaseController private function save($productPublicId = false) { if ($productPublicId) { - $product = Product::scope($productPublicId)->firstOrFail(); + $product = Product::scope($productPublicId)->withTrashed()->firstOrFail(); } else { $product = Product::createNew(); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 1d504978c665..cec0bbcba861 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -66,7 +66,9 @@ class UserController extends BaseController public function edit($publicId) { $user = User::where('account_id', '=', Auth::user()->account_id) - ->where('public_id', '=', $publicId)->firstOrFail(); + ->where('public_id', '=', $publicId) + ->withTrashed() + ->firstOrFail(); $data = [ 'user' => $user, @@ -157,7 +159,9 @@ class UserController extends BaseController if ($userPublicId) { $user = User::where('account_id', '=', Auth::user()->account_id) - ->where('public_id', '=', $userPublicId)->firstOrFail(); + ->where('public_id', '=', $userPublicId) + ->withTrashed() + ->firstOrFail(); $rules['email'] = 'required|email|unique:users,email,'.$user->id.',id'; } else { diff --git a/app/Http/Requests/UpdateTaxRateRequest.php b/app/Http/Requests/UpdateTaxRateRequest.php index 381990f32b97..e0a741ee968b 100644 --- a/app/Http/Requests/UpdateTaxRateRequest.php +++ b/app/Http/Requests/UpdateTaxRateRequest.php @@ -4,7 +4,6 @@ class UpdateTaxRateRequest extends TaxRateRequest { - // Expenses /** * Determine if the user is authorized to make this request. * diff --git a/app/Listeners/ActivityListener.php b/app/Listeners/ActivityListener.php index 91e327454db7..81810ffd2df2 100644 --- a/app/Listeners/ActivityListener.php +++ b/app/Listeners/ActivityListener.php @@ -123,7 +123,9 @@ class ActivityListener return; } - $backupInvoice = Invoice::with('invoice_items', 'client.account', 'client.contacts')->find($event->invoice->id); + $backupInvoice = Invoice::with('invoice_items', 'client.account', 'client.contacts') + ->withArchived() + ->find($event->invoice->id); $activity = $this->activityRepo->create( $event->invoice, diff --git a/app/Ninja/Datatables/PaymentDatatable.php b/app/Ninja/Datatables/PaymentDatatable.php index 5e7adc519210..faa9733ca9da 100644 --- a/app/Ninja/Datatables/PaymentDatatable.php +++ b/app/Ninja/Datatables/PaymentDatatable.php @@ -89,7 +89,11 @@ class PaymentDatatable extends EntityDatatable [ 'payment_date', function ($model) { - return Utils::dateToString($model->payment_date); + if ($model->is_deleted) { + return Utils::dateToString($model->payment_date); + } else { + return link_to("payments/{$model->public_id}/edit", Utils::dateToString($model->payment_date))->toHtml(); + } } ], [ diff --git a/app/Ninja/Repositories/ClientRepository.php b/app/Ninja/Repositories/ClientRepository.php index 7bf9676359aa..48788de3a97d 100644 --- a/app/Ninja/Repositories/ClientRepository.php +++ b/app/Ninja/Repositories/ClientRepository.php @@ -80,6 +80,10 @@ class ClientRepository extends BaseRepository $client = Client::scope($publicId)->with('contacts')->firstOrFail(); } + if ($client->is_deleted) { + return $client; + } + // convert currency code to id if (isset($data['currency_code'])) { $currencyCode = strtolower($data['currency_code']); diff --git a/app/Ninja/Repositories/ExpenseRepository.php b/app/Ninja/Repositories/ExpenseRepository.php index b692e03c0ebd..e58d942942a1 100644 --- a/app/Ninja/Repositories/ExpenseRepository.php +++ b/app/Ninja/Repositories/ExpenseRepository.php @@ -118,11 +118,17 @@ class ExpenseRepository extends BaseRepository // do nothing } elseif ($publicId) { $expense = Expense::scope($publicId)->firstOrFail(); - \Log::warning('Entity not set in expense repo save'); + if (Utils::isNinjaDev()) { + \Log::warning('Entity not set in expense repo save'); + } } else { $expense = Expense::createNew(); } + if ($expense->is_deleted) { + return $expense; + } + // First auto fill $expense->fill($input); diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 78aed0e59eff..d92573deea5a 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -280,7 +280,13 @@ class InvoiceRepository extends BaseRepository } } else { $invoice = Invoice::scope($publicId)->firstOrFail(); - \Log::warning('Entity not set in invoice repo save'); + if (Utils::isNinjaDev()) { + \Log::warning('Entity not set in invoice repo save'); + } + } + + if ($invoice->is_deleted) { + return $invoice; } $invoice->fill($data); diff --git a/app/Ninja/Repositories/PaymentRepository.php b/app/Ninja/Repositories/PaymentRepository.php index 1e3ac8a930b9..f13419f3020c 100644 --- a/app/Ninja/Repositories/PaymentRepository.php +++ b/app/Ninja/Repositories/PaymentRepository.php @@ -150,11 +150,17 @@ class PaymentRepository extends BaseRepository // do nothing } elseif ($publicId) { $payment = Payment::scope($publicId)->firstOrFail(); - \Log::warning('Entity not set in payment repo save'); + if (Utils::isNinjaDev()) { + \Log::warning('Entity not set in payment repo save'); + } } else { $payment = Payment::createNew(); } + if ($payment->is_deleted) { + return $payment; + } + $paymentTypeId = false; if (isset($input['payment_type_id'])) { $paymentTypeId = $input['payment_type_id'] ? $input['payment_type_id'] : null; diff --git a/app/Ninja/Repositories/TaskRepository.php b/app/Ninja/Repositories/TaskRepository.php index 8742a286ec99..8cace32b830c 100644 --- a/app/Ninja/Repositories/TaskRepository.php +++ b/app/Ninja/Repositories/TaskRepository.php @@ -67,11 +67,15 @@ class TaskRepository if ($task) { // do nothing } elseif ($publicId) { - $task = Task::scope($publicId)->firstOrFail(); + $task = Task::scope($publicId)->withTrashed()->firstOrFail(); } else { $task = Task::createNew(); } + if ($task->is_deleted) { + return $task; + } + if (isset($data['client']) && $data['client']) { $task->client_id = Client::getPrivateId($data['client']); } diff --git a/app/Ninja/Repositories/VendorRepository.php b/app/Ninja/Repositories/VendorRepository.php index 1f848e0a0b9a..0dbb43ebd814 100644 --- a/app/Ninja/Repositories/VendorRepository.php +++ b/app/Ninja/Repositories/VendorRepository.php @@ -1,5 +1,6 @@ with('vendor_contacts')->firstOrFail(); - \Log::warning('Entity not set in vendor repo save'); + if (Utils::isNinjaDev()) { + \Log::warning('Entity not set in vendor repo save'); + } + } + + if ($vendor->is_deleted) { + return $vendor; } $vendor->fill($data); diff --git a/app/Services/DatatableService.php b/app/Services/DatatableService.php index 977ca0c7d0cf..82223ffc324f 100644 --- a/app/Services/DatatableService.php +++ b/app/Services/DatatableService.php @@ -77,6 +77,7 @@ class DatatableService if (!$model->deleted_at || $model->deleted_at == '0000-00-00') { foreach ($datatable->actions() as $action) { if (count($action)) { + // if show function isn't set default to true if (count($action) == 2) { $action[] = function() { return true; @@ -84,11 +85,10 @@ class DatatableService } list($value, $url, $visible) = $action; if ($visible($model)) { - if($value == '--divider--'){ + if ($value == '--divider--') { $dropdown_contents .= '
'; $lastIsDivider = true; - } - else { + } else { $urlVal = $url($model); $urlStr = is_string($urlVal) ? $urlVal : $urlVal['url']; $attributes = ''; diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index c1a7c36f04bb..3c90be9e8a2e 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -131,7 +131,7 @@ class PaymentService extends BaseService if(!Utils::hasPermission('view_all')){ $query->where('payments.user_id', '=', Auth::user()->id); } - + return $this->datatableService->createDatatable($datatable, $query); } diff --git a/resources/views/accounts/user_details.blade.php b/resources/views/accounts/user_details.blade.php index 3e46c44740e5..5b62dbc21c7f 100644 --- a/resources/views/accounts/user_details.blade.php +++ b/resources/views/accounts/user_details.blade.php @@ -4,6 +4,8 @@ @parent {!! Former::open_for_files()->addClass('warn-on-exit')->rules(array( + 'first_name' => 'required', + 'last_name' => 'required', 'email' => 'email|required' )) !!} diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index ceb1b5c6c82b..690ed29ec206 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -44,26 +44,34 @@ ->withAttributes(['target' => '_blank']) !!} @endif + @if ( ! $client->is_deleted) + @can('edit', $client) + {!! DropdownButton::normal(trans('texts.edit_client')) + ->withAttributes(['class'=>'normalDropDown']) + ->withContents([ + ($client->trashed() ? false : ['label' => trans('texts.archive_client'), 'url' => "javascript:onArchiveClick()"]), + ['label' => trans('texts.delete_client'), 'url' => "javascript:onDeleteClick()"], + ] + )->split() !!} + @endcan + @if ( ! $client->trashed()) + @can('create', ENTITY_INVOICE) + {!! DropdownButton::primary(trans('texts.new_invoice')) + ->withAttributes(['class'=>'primaryDropDown']) + ->withContents($actionLinks)->split() !!} + @endcan + @endif + @endif + @if ($client->trashed()) @can('edit', $client) - {!! Button::primary(trans('texts.restore_client'))->withAttributes(['onclick' => 'onRestoreClick()']) !!} - @endcan - @else - @can('edit', $client) - {!! DropdownButton::normal(trans('texts.edit_client')) - ->withAttributes(['class'=>'normalDropDown']) - ->withContents([ - ['label' => trans('texts.archive_client'), 'url' => "javascript:onArchiveClick()"], - ['label' => trans('texts.delete_client'), 'url' => "javascript:onDeleteClick()"], - ] - )->split() !!} - @endcan - @can('create', ENTITY_INVOICE) - {!! DropdownButton::primary(trans('texts.new_invoice')) - ->withAttributes(['class'=>'primaryDropDown']) - ->withContents($actionLinks)->split() !!} + {!! Button::primary(trans('texts.restore_client')) + ->appendIcon(Icon::create('cloud-download')) + ->withAttributes(['onclick' => 'onRestoreClick()']) !!} @endcan @endif + + {!! Former::close() !!} diff --git a/resources/views/expenses/edit.blade.php b/resources/views/expenses/edit.blade.php index 265680378bb3..b56d8b8183d6 100644 --- a/resources/views/expenses/edit.blade.php +++ b/resources/views/expenses/edit.blade.php @@ -171,28 +171,38 @@ - @if (Auth::user()->canCreateOrEdit(ENTITY_EXPENSE, $expense)) -