diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 0aa9ac2b18d9..2e7ab6513c67 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -59,28 +59,7 @@ class InvoiceController extends Controller } - $builder->addAction(); - $builder->addCheckbox(); - - /**todo this is redundant, but keep in case we want to build this serverside*/ - $html = $builder->columns([ - ['data' => 'checkbox', 'name' => 'checkbox', 'title' => '', 'searchable' => false, 'orderable' => false], - ['data' => 'invoice_number', 'name' => 'invoice_number', 'title' => trans('texts.invoice_number'), 'visible'=> true], - ['data' => 'invoice_date', 'name' => 'invoice_date', 'title' => trans('texts.invoice_date'), 'visible'=> true], - ['data' => 'amount', 'name' => 'amount', 'title' => trans('texts.total'), 'visible'=> true], - ['data' => 'balance', 'name' => 'balance', 'title' => trans('texts.balance'), 'visible'=> true], - ['data' => 'due_date', 'name' => 'due_date', 'title' => trans('texts.due_date'), 'visible'=> true], - ['data' => 'status', 'name' => 'status', 'title' => trans('texts.status'), 'visible'=> true], - ['data' => 'action', 'name' => 'action', 'title' => '', 'searchable' => false, 'orderable' => false], - ]); - - $builder->ajax([ - 'url' => route('client.invoices.index'), - 'type' => 'GET', - 'data' => 'function(d) { d.key = "value"; }', - ]); - - $data['html'] = $html; + $data['html'] = $builder; return view('portal.default.invoices.index', $data); @@ -100,14 +79,29 @@ class InvoiceController extends Controller } /** - * Perform bulk actions on the list view + * Pay one or more invoices * - * @return Collection + * @return View */ - public function bulk() + public function payment() { + $transformed_ids = $this->transformKeys(request()->input('hashed_ids')); + + $invoices = Invoice::whereIn('id', $transformed_ids) + ->whereClientId(auth()->user()->client->id) + ->get() + ->filter(function ($invoice){ + return $invoice->isPayable(); + }); + + + $data = [ + 'invoices' => $invoices, + ]; + return view('portal.default.invoices.payment', $data); + } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 9c35ae0f5636..c57e46b8066d 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -195,6 +195,11 @@ class Invoice extends BaseModel $this->last_viewed = Carbon::now()->format('Y-m-d H:i'); } + public function isPayable() + { + return ($this->status === Invoice::STATUS_UNPAID || $this->status === Invoice::STATUS_OVERDUE); + } + public static function badgeForStatus(int $status) { switch ($status) { diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index d63f7ee6195c..e733b6edfdb9 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -61,7 +61,7 @@ class AuthServiceProvider extends ServiceProvider public function boot() { $this->registerPolicies(); - +/* Auth::provider('users', function ($app, array $config) { return new MultiDatabaseUserProvider($this->app['hash'], $config['model']); }); @@ -70,7 +70,7 @@ class AuthServiceProvider extends ServiceProvider return new MultiDatabaseUserProvider($this->app['hash'], $config['model']); }); - +*/ Gate::define('view-list', function ($user, $entity) { $entity = strtolower(class_basename($entity)); diff --git a/config/auth.php b/config/auth.php index fa2a042ea431..af8c53f1bc3d 100644 --- a/config/auth.php +++ b/config/auth.php @@ -73,11 +73,14 @@ return [ 'providers' => [ 'users' => [ - 'driver' => env('USER_AUTH_PROVIDER', 'eloquent'), + 'driver' => 'eloquent', + //'driver' => env('USER_AUTH_PROVIDER', 'eloquent'), 'model' => App\Models\User::class, ], 'contacts' => [ - 'driver' => env('CONTACT_AUTH_PROVIDER', 'eloquent'), + 'driver' => 'eloquent', + +// 'driver' => env('CONTACT_AUTH_PROVIDER', 'eloquent'), 'model' => App\Models\ClientContact::class, ], diff --git a/database/factories/InvoiceFactory.php b/database/factories/InvoiceFactory.php index 15acc255a6e3..104361e3af1c 100644 --- a/database/factories/InvoiceFactory.php +++ b/database/factories/InvoiceFactory.php @@ -7,7 +7,7 @@ use Faker\Generator as Faker; $factory->define(App\Models\Invoice::class, function (Faker $faker) { return [ 'status_id' => App\Models\Invoice::STATUS_SENT, - 'invoice_number' => $faker->text(256), + 'invoice_number' => $faker->uuid(), 'discount' => $faker->numberBetween(1,10), 'is_amount_discount' => $faker->boolean(), 'tax_name1' => 'GST', diff --git a/resources/views/portal/default/invoices/index.blade.php b/resources/views/portal/default/invoices/index.blade.php index 3c963bd156e5..12f3b8d437e0 100644 --- a/resources/views/portal/default/invoices/index.blade.php +++ b/resources/views/portal/default/invoices/index.blade.php @@ -20,7 +20,7 @@ Toggle Dropdown @@ -149,11 +149,30 @@ $(document).ready(function() { $(this).closest('table').find(':checkbox:not(:disabled)').prop('checked', this.checked); }); - $('.btn .btn-success .pay_invoices').click(function() { - alert('pay'); + $('#pay_invoices').click(function() { + + $('#pay_invoices').addClass('disabled'); + $('#pay_invoices_drop').addClass('disabled'); + $('#download_invoices').addClass('disabled'); + + $.ajax({ + url: "{{ route('client.invoices.payment')}}", + type: "post", + data: { + _token: '{{ csrf_token() }}', + hashed_ids: selected + }, + success: function (response) { + + // You will get response from your PHP page (what you echo or print) + }, + error: function(jqXHR, textStatus, errorThrown) { + console.log(textStatus, errorThrown); + } + }); }); - $('.download_invoices').click(function() { + $('#download_invoices').click(function() { alert('download'); }); diff --git a/resources/views/portal/default/invoices/payment.blade.php b/resources/views/portal/default/invoices/payment.blade.php new file mode 100644 index 000000000000..8c0b216a4976 --- /dev/null +++ b/resources/views/portal/default/invoices/payment.blade.php @@ -0,0 +1,21 @@ +@extends('portal.default.layouts.master') +@section('header') + +@stop +@section('body') +
+
+
+ + +
+
+
+ +@endsection +@push('scripts') + +@endpush +@section('footer') +@endsection + diff --git a/routes/client.php b/routes/client.php index a1419bac8593..1f6f60bade22 100644 --- a/routes/client.php +++ b/routes/client.php @@ -15,7 +15,8 @@ Route::post('client/password/reset', 'Auth\ContactResetPasswordController@reset' Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'client.'], function () { Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit - Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index'); // name = (dashboard. index / create / show / update / destroy / edit + Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index'); + Route::post('invoices', 'ClientPortal\InvoiceController@payment')->name('invoices.payment'); Route::get('profile/{client_contact}/edit', 'ClientPortal\ProfileController@edit')->name('profile.edit'); Route::put('profile/{client_contact}/edit', 'ClientPortal\ProfileController@update')->name('profile.update'); Route::put('profile/{client_contact}/edit_client', 'ClientPortal\ProfileController@updateClient')->name('profile.edit_client');