diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 1a1bbd1a745c..c3c3dd10eda9 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -13,6 +13,7 @@ namespace App\Http\Controllers\ClientPortal; use App\Filters\InvoiceFilters; use App\Http\Controllers\Controller; +use App\Http\Requests\ClientPortal\ShowInvoiceRequest; use App\Jobs\Entity\ActionEntity; use App\Models\Invoice; use App\Repositories\BaseRepository; @@ -83,10 +84,13 @@ class InvoiceController extends Controller * * @return \Illuminate\Http\Response */ - public function show(Invoice $invoice) + public function show(ShowInvoiceRequest $request, Invoice $invoice) { - - + $data = [ + 'invoice' => $invoice + ]; + + return view('portal.default.invoices.show', $invoice); } /** diff --git a/app/Http/Requests/ClientPortal/ShowInvoiceRequest.php b/app/Http/Requests/ClientPortal/ShowInvoiceRequest.php new file mode 100644 index 000000000000..d36b264ce5a0 --- /dev/null +++ b/app/Http/Requests/ClientPortal/ShowInvoiceRequest.php @@ -0,0 +1,30 @@ +user()->client->id === $this->invoice->client_id; + } + +} \ No newline at end of file diff --git a/app/Listeners/Invoice/CreateInvoicePdf.php b/app/Listeners/Invoice/CreateInvoicePdf.php new file mode 100644 index 000000000000..3ef7f5a5de84 --- /dev/null +++ b/app/Listeners/Invoice/CreateInvoicePdf.php @@ -0,0 +1,75 @@ +invoice; + $path = $invoice->client->client_hash . '/invoices/'; + $file = $path . $invoice->invoice_number . '.pdf'; + //get invoice template + + $html = $this->generateInvoiceHtml($invoice->settings->template, $invoice) + + //todo - move this to the client creation stage so we don't keep hitting this unnecessarily + Storage::makeDirectory('public/' . $path, 0755); + + //create pdf + $this->makePdf(null,null,$html,$file) + + //store pdf + //$path = Storage::putFile('public/' . $path, $this->file); + //$url = Storage::url($path); + } + + + private function makePdf($header, $footer, $html, $pdf) + { + Browsershot::html($html) + //->showBrowserHeaderAndFooter() + //->headerHtml($header) + //->footerHtml($footer) + ->waitUntilNetworkIdle() + //->margins(10,10,10,10) + ->savePdf($pdf); + } + + private function generateInvoiceHtml($template, $invoice) + { + + } +} diff --git a/app/Models/Country.php b/app/Models/Country.php index 3d221bf8e336..bbd494a6f751 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -17,4 +17,13 @@ class Country extends Model { public $timestamps = false; + /** + * Localizes the country name for the clients language. + * + * @return string The translated country name + */ + public function getName() :string + { + return trans('texts.country_' . $this->name); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 7ca1e32be9c6..38298b43bb56 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Log; +use Laracasts\Presenter\PresentableTrait; class Invoice extends BaseModel { @@ -26,6 +27,9 @@ class Invoice extends BaseModel use Filterable; use NumberFormatter; use MakesDates; + use PresentableTrait; + + protected $presenter = 'App\Models\Presenters\InvoicePresenter'; protected $hidden = [ 'id', diff --git a/app/Models/Presenters/EntityPresenter.php b/app/Models/Presenters/EntityPresenter.php index 25b4fc99da1a..84754355a8ee 100644 --- a/app/Models/Presenters/EntityPresenter.php +++ b/app/Models/Presenters/EntityPresenter.php @@ -113,6 +113,22 @@ class EntityPresenter extends Presenter } } + public function getShippingCityState() + { + $client = $this->entity; + $swap = $client->shipping_country && $client->shipping_country->swap_postal_code; + + $city = e($client->shipping_city); + $state = e($client->shipping_state); + $postalCode = e($client->shipping_postal_code); + + if ($city || $state || $postalCode) { + return $this->cityStateZip($city, $state, $postalCode, $swap); + } else { + return false; + } + } + public function cityStateZip($city, $state, $postalCode, $swap) { $str = $city; diff --git a/app/Models/Presenters/InvoicePresenter.php b/app/Models/Presenters/InvoicePresenter.php new file mode 100644 index 000000000000..cdfb0874c5b7 --- /dev/null +++ b/app/Models/Presenters/InvoicePresenter.php @@ -0,0 +1,43 @@ +client->present()->name(); + } + + public function address() + { + return $this->client->present()->address(); + } + + pubic function shipping_address() + { + return $this->client->present()->shipping_address(); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 40dd43bd605b..9197afb97e3d 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -24,6 +24,7 @@ use App\Listeners\Activity\PaymentCreatedActivity; use App\Listeners\Contact\UpdateContactLastLogin; use App\Listeners\Invoice\CreateInvoiceActivity; use App\Listeners\Invoice\CreateInvoiceInvitations; +use App\Listeners\Invoice\CreateInvoicePdf; use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\SendVerificationNotification; use App\Listeners\User\UpdateUserLastLogin; @@ -76,9 +77,11 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasUpdated::class => [ UpdateInvoiceActivity::class, + CreateInvoicePdf::class, ], InvoiceWasCreated::class => [ CreateInvoiceActivity::class, + CreateInvoicePdf::class, ], ]; diff --git a/resources/views/pdf/design1.blade.php b/resources/views/pdf/design1.blade.php new file mode 100644 index 000000000000..b36d65722faf --- /dev/null +++ b/resources/views/pdf/design1.blade.php @@ -0,0 +1,515 @@ + + + + + A simple, clean, and responsive HTML invoice template + + + + + +
+ + + + + + + + +
+ + + + + + +
+ + + Invoice #: {{ $invoice->invoice_number }}
+ Created: {{ $invoice->invoice_date }}
+ Due: {{ $invoice->due_date }} +
+
+ + + + + + +
+ Sparksuite, Inc.
+ 12345 Sunny Road
+ Sunnyville, CA 12345 +
+ Acme Corp.
+ John Doe
+ john@example.com +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Item + + Price +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Website design + + $300.00 +
+ Hosting (3 months) + + $75.00 +
+ Domain name (1 year) + + $10.00 +
+ Total: $385.00 +
+
+ + \ No newline at end of file diff --git a/resources/views/portal/default/invoices/show.blade.php b/resources/views/portal/default/invoices/show.blade.php new file mode 100644 index 000000000000..897dc00b9e9b --- /dev/null +++ b/resources/views/portal/default/invoices/show.blade.php @@ -0,0 +1,14 @@ +@extends('portal.default.layouts.master') +@section('body') +
+
+ + + + +
+
+ +@endsection \ No newline at end of file diff --git a/routes/client.php b/routes/client.php index 013762e61e43..4fbfe12fc07c 100644 --- a/routes/client.php +++ b/routes/client.php @@ -18,6 +18,8 @@ Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'c Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index'); Route::post('invoices/payment', 'ClientPortal\InvoiceController@bulk')->name('invoices.bulk'); + Route::get('invoice/{invoice}', 'ClientPortal\InvoiceController@show')->name('invoice.show'); + Route::get('invoice/{invoice_invitation}', 'ClientPortal\InvoiceController@show')->name('invoice.show_invitation'); Route::get('recurring_invoices', 'ClientPortal\RecurringInvoiceController@index')->name('recurring_invoices.index');