From ad2140b3b0d623fbf6a60c3b797da4498c286db5 Mon Sep 17 00:00:00 2001 From: Erik Campobadal Date: Tue, 17 Apr 2018 22:16:57 +0200 Subject: [PATCH] Fixes --- Classes/Invoice.php | 16 ++++----- Classes/PDF.php | 4 +-- InvoicesServiceProvider.php | 48 ++++++++++++++++++++++++++ README.md | 67 +++++++++++++++++++++++++++++++++++-- composer.json | 9 ++++- 5 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 InvoicesServiceProvider.php diff --git a/Classes/Invoice.php b/Classes/Invoice.php index d569938..a413bb5 100644 --- a/Classes/Invoice.php +++ b/Classes/Invoice.php @@ -305,9 +305,9 @@ public function taxPriceFormatted() * * @return self */ - private function generate($template = 'vendor.invoices.default') + private function generate() { - $this->pdf = PDF::generate($this, $template); + $this->pdf = PDF::generate($this); return $this; } @@ -321,9 +321,9 @@ private function generate($template = 'vendor.invoices.default') * * @return response */ - public function download($name = 'invoice', $template = 'vendor.invoices.default') + public function download($name = 'invoice') { - $this->generate($template); + $this->generate(); return $this->pdf->stream($name); } @@ -336,9 +336,9 @@ public function download($name = 'invoice', $template = 'vendor.invoices.default * @param string $name * */ - public function save($name = 'invoice.pdf', $template = 'vendor.invoices.default') + public function save($name = 'invoice.pdf') { - $invoice = $this->generate($template); + $invoice = $this->generate(); Storage::put($name, $invoice->pdf->output()); } @@ -352,9 +352,9 @@ public function save($name = 'invoice.pdf', $template = 'vendor.invoices.default * * @return response */ - public function show($name = 'invoice', $template = 'vendor.invoices.default') + public function show($name = 'invoice') { - $this->generate($template); + $this->generate(); return $this->pdf->stream($name, ['Attachment' => false]); } diff --git a/Classes/PDF.php b/Classes/PDF.php index b483e04..cafad89 100644 --- a/Classes/PDF.php +++ b/Classes/PDF.php @@ -31,7 +31,7 @@ class PDF * * @return Dompdf\Dompdf */ - public static function generate(Invoice $invoice, $template = 'invoices::default') + public static function generate(Invoice $invoice, $template = 'default') { $template = strtolower($template); @@ -51,7 +51,7 @@ public static function generate(Invoice $invoice, $template = 'invoices::default $pdf->setHttpContext($context); - $pdf->loadHtml(View::make($template, ['invoice' => $invoice])); + $pdf->loadHtml(View::make('invoices::'.$template, ['invoice' => $invoice])); $pdf->render(); return $pdf; diff --git a/InvoicesServiceProvider.php b/InvoicesServiceProvider.php new file mode 100644 index 0000000..215723c --- /dev/null +++ b/InvoicesServiceProvider.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ConsoleTVs\Invoices; + +use Illuminate\Support\ServiceProvider; + +/** + * This is the InvoicesServiceProvider class. + * + * @author Erik Campobadal + */ +class InvoicesServiceProvider extends ServiceProvider +{ + /** + * Bootstrap any application services. + * + * @return void + */ + public function boot() + { + $this->loadViewsFrom(__DIR__.'/Templates', 'invoices'); + + $this->publishes([ + __DIR__.'/Templates' => resource_path('views/vendor/invoices'), + __DIR__.'/Config/invoices.php' => config_path('invoices.php'), + ], 'invoices'); + } + + /** + * Register any application services. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom( + __DIR__.'/Config/invoices.php', 'invoices' + ); + } +} diff --git a/README.md b/README.md index 8376389..6e17387 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+

StyleCI Status @@ -13,4 +13,67 @@ Invoices is a Laravel library that generates a PDF invoice for your customers. The PDF can be either downloaded or streamed in the browser. It's highly customizable and you can modify the whole output view as well. -

+## Sample Invoice + +This is a sample invoice generated using this library: + +![Sample Invoice](https://i.gyazo.com/768f5b59791162e432f9cdfa15f017bc.png) + +```php +$invoice = ConsoleTVs\Invoices\Classes\Invoice::make() + ->addItem('Test Item', 10.25, 2, 1412) + ->addItem('Test Item 2', 5, 2, 923) + ->addItem('Test Item 3', 15.55, 5, 42) + ->addItem('Test Item 4', 1.25, 1, 923) + ->addItem('Test Item 5', 3.12, 1, 3142) + ->addItem('Test Item 6', 6.41, 3, 452) + ->addItem('Test Item 7', 2.86, 1, 1526) + ->number(4021) + ->tax(21) + ->notes('Lrem ipsum dolor sit amet, consectetur adipiscing elit.') + ->customer([ + 'name' => 'Èrik Campobadal Forés', + 'id' => '12345678A', + 'phone' => '+34 123 456 789', + 'location' => 'C / Unknown Street 1st', + 'zip' => '08241', + 'city' => 'Manresa', + 'country' => 'Spain', + ]) + ->download('demo'); + //or save it somewhere + ->save('public/myinvoicename.pdf'); +``` + +## Documentation + +

+ +

+ +## License + +``` +MIT License + +Copyright (c) 2017 Erik Campobadal + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +``` diff --git a/composer.json b/composer.json index f435416..8c9e50d 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "newridetech/invoices", + "name": "consoletvs/invoices", "description": "Generate PDF invoices for your customers in laravel", "type": "library", "keywords": [ @@ -25,5 +25,12 @@ "ConsoleTVs\\Invoices\\": "." } }, + "extra": { + "laravel": { + "providers": [ + "ConsoleTVs\\Invoices\\InvoicesServiceProvider" + ] + } + }, "minimum-stability": "dev" }