From eff33fd3862469984ff2f48dba3453b793c61f86 Mon Sep 17 00:00:00 2001 From: Fahim Anzam Dip Date: Wed, 21 Jul 2021 01:06:47 +0600 Subject: [PATCH] Added: Livewire, Barcode Printing & Laravel Snappy --- .../Http/Controllers/BarcodeController.php | 17 ++ .../Resources/views/barcode/index.blade.php | 30 ++ .../Resources/views/products/create.blade.php | 36 +-- .../Resources/views/products/edit.blade.php | 34 +-- .../Resources/views/products/show.blade.php | 11 +- Modules/Product/Routes/web.php | 2 + .../Http/Controllers/UploadController.php | 8 - app/Http/Livewire/Barcode/ProductTable.php | 45 +++ app/Http/Livewire/Barcode/SearchProduct.php | 38 +++ composer.json | 3 + composer.lock | 283 +++++++++++++++++- config/app.php | 6 + config/snappy.php | 52 ++++ database/seeders/SuperUserSeeder.php | 3 +- resources/views/layouts/app.blade.php | 3 + resources/views/layouts/menu.blade.php | 7 + .../livewire/barcode/product-table.blade.php | 48 +++ .../livewire/barcode/search-product.blade.php | 49 +++ 18 files changed, 603 insertions(+), 72 deletions(-) create mode 100644 Modules/Product/Http/Controllers/BarcodeController.php create mode 100644 Modules/Product/Resources/views/barcode/index.blade.php create mode 100644 app/Http/Livewire/Barcode/ProductTable.php create mode 100644 app/Http/Livewire/Barcode/SearchProduct.php create mode 100644 config/snappy.php create mode 100644 resources/views/livewire/barcode/product-table.blade.php create mode 100644 resources/views/livewire/barcode/search-product.blade.php diff --git a/Modules/Product/Http/Controllers/BarcodeController.php b/Modules/Product/Http/Controllers/BarcodeController.php new file mode 100644 index 00000000..534a91e1 --- /dev/null +++ b/Modules/Product/Http/Controllers/BarcodeController.php @@ -0,0 +1,17 @@ + + + + +@endsection + +@section('content') +
+
+
+ +
+
+ +
+
+ +
+
+
+@endsection diff --git a/Modules/Product/Resources/views/products/create.blade.php b/Modules/Product/Resources/views/products/create.blade.php index 3a7891fe..d6bd3b7f 100644 --- a/Modules/Product/Resources/views/products/create.blade.php +++ b/Modules/Product/Resources/views/products/create.blade.php @@ -3,8 +3,7 @@ @section('title', 'Create Product') @section('third_party_stylesheets') - - + @include('includes.filepond-css') @endsection @section('breadcrumb') @@ -75,13 +74,13 @@
- +
- +
@@ -128,7 +127,7 @@
- +
@@ -138,32 +137,7 @@ @endsection -@section('third_party_scripts') - - - - -@endsection - @push('page_scripts') - + @include('includes.filepond-js') @endpush diff --git a/Modules/Product/Resources/views/products/edit.blade.php b/Modules/Product/Resources/views/products/edit.blade.php index 542bba1f..75a2c056 100644 --- a/Modules/Product/Resources/views/products/edit.blade.php +++ b/Modules/Product/Resources/views/products/edit.blade.php @@ -3,8 +3,7 @@ @section('title', 'Edit Product') @section('third_party_stylesheets') - - + @include('includes.filepond-css') @endsection @section('breadcrumb') @@ -75,13 +74,13 @@
- +
- +
@@ -139,32 +138,7 @@ @endsection -@section('third_party_scripts') - - - - -@endsection - @push('page_scripts') - + @include('includes.filepond-js') @endpush diff --git a/Modules/Product/Resources/views/products/show.blade.php b/Modules/Product/Resources/views/products/show.blade.php index cc44dadb..fe58fc43 100644 --- a/Modules/Product/Resources/views/products/show.blade.php +++ b/Modules/Product/Resources/views/products/show.blade.php @@ -12,16 +12,25 @@ @section('content')
+
+
+ {!! \Milon\Barcode\Facades\DNS1DFacade::getBarCodeSVG($product->product_code, $product->product_barcode_symbology, 2, 110) !!} +
+
- +
+ + + + diff --git a/Modules/Product/Routes/web.php b/Modules/Product/Routes/web.php index 2102ccdc..3cc1ffe0 100644 --- a/Modules/Product/Routes/web.php +++ b/Modules/Product/Routes/web.php @@ -7,6 +7,8 @@ */ Route::group(['middleware' => 'auth'], function () { + //Print Barcode + Route::get('/products/print-barcode', 'BarcodeController@printBarcode')->name('barcode.print'); //Product Route::resource('products', 'ProductController'); //Product Category diff --git a/Modules/Upload/Http/Controllers/UploadController.php b/Modules/Upload/Http/Controllers/UploadController.php index 37d582ab..9766a498 100644 --- a/Modules/Upload/Http/Controllers/UploadController.php +++ b/Modules/Upload/Http/Controllers/UploadController.php @@ -13,10 +13,6 @@ class UploadController extends Controller { public function filepondUpload(Request $request) { - if (!$request->ajax()) { - return back(); - } - $request->validate([ 'image' => 'required|image|mimes:png,jpeg,jpg' ]); @@ -42,10 +38,6 @@ class UploadController extends Controller } public function filepondDelete(Request $request) { - if (!$request->ajax()) { - return back(); - } - $upload = Upload::where('folder', $request->getContent())->first(); Storage::deleteDirectory('public/temp/' . $upload->folder); diff --git a/app/Http/Livewire/Barcode/ProductTable.php b/app/Http/Livewire/Barcode/ProductTable.php new file mode 100644 index 00000000..4868f3e8 --- /dev/null +++ b/app/Http/Livewire/Barcode/ProductTable.php @@ -0,0 +1,45 @@ +product = ''; + $this->quantity = 0; + $this->barcodes = []; + } + + public function render() { + return view('livewire.barcode.product-table'); + } + + public function productSelected(Product $product) { + $this->product = $product; + $this->quantity = 1; + $this->barcodes = []; + } + + public function generateBarcodes(Product $product, $quantity) { + $this->barcodes = []; + + for ($i = 1; $i <= $quantity; $i++) { + $barcode = DNS1DFacade::getBarCodeSVG($product->product_code, $product->product_barcode_symbology,2 , 60); + array_push($this->barcodes, $barcode); + } + } + + public function updatedQuantity() { + $this->barcodes = []; + } +} diff --git a/app/Http/Livewire/Barcode/SearchProduct.php b/app/Http/Livewire/Barcode/SearchProduct.php new file mode 100644 index 00000000..dcb63265 --- /dev/null +++ b/app/Http/Livewire/Barcode/SearchProduct.php @@ -0,0 +1,38 @@ +query = ''; + $this->searchResults = Collection::empty(); + } + + public function render() { + return view('livewire.barcode.search-product'); + } + + public function updatedQuery() { + $this->searchResults = Product::where('product_name', 'like', '%' . $this->query . '%') + ->orWhere('product_code', 'like', '%' . $this->query . '%') + ->get(); + } + + public function resetQuery() { + $this->query = ''; + $this->searchResults = Collection::empty(); + } + + public function selectProduct($product) { + $this->emit('productSelected', $product); + } +} diff --git a/composer.json b/composer.json index 940a4063..f4c672eb 100644 --- a/composer.json +++ b/composer.json @@ -6,12 +6,15 @@ "license": "MIT", "require": { "php": "^7.3|^8.0", + "barryvdh/laravel-snappy": "^0.4.8", "fideloper/proxy": "^4.4", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", "infyomlabs/laravel-ui-coreui": "^3.0", "laravel/framework": "^8.40", "laravel/tinker": "^2.5", + "livewire/livewire": "^2.5", + "milon/barcode": "^8.0", "nwidart/laravel-modules": "^8.2", "realrashid/sweet-alert": "^4.0", "spatie/laravel-medialibrary": "^9.0.0", diff --git a/composer.lock b/composer.lock index cd926497..5d8bd637 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0529f25855530902932a9ae4f2f8d0ba", + "content-hash": "53badb2a324d9caf89ceed410177f49b", "packages": [ { "name": "asm89/stack-cors", @@ -62,6 +62,71 @@ }, "time": "2021-03-11T06:42:03+00:00" }, + { + "name": "barryvdh/laravel-snappy", + "version": "v0.4.8", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-snappy.git", + "reference": "1903ab84171072b6bff8d98eb58d38b2c9aaf645" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-snappy/zipball/1903ab84171072b6bff8d98eb58d38b2c9aaf645", + "reference": "1903ab84171072b6bff8d98eb58d38b2c9aaf645", + "shasum": "" + }, + "require": { + "illuminate/filesystem": "^5.5|^6|^7|^8", + "illuminate/support": "^5.5|^6|^7|^8", + "knplabs/knp-snappy": "^1", + "php": ">=7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.4-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Snappy\\ServiceProvider" + ], + "aliases": { + "PDF": "Barryvdh\\Snappy\\Facades\\SnappyPdf", + "SnappyImage": "Barryvdh\\Snappy\\Facades\\SnappyImage" + } + } + }, + "autoload": { + "psr-4": { + "Barryvdh\\Snappy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Snappy PDF/Image for Laravel", + "keywords": [ + "image", + "laravel", + "pdf", + "snappy", + "wkhtmltoimage", + "wkhtmltopdf" + ], + "support": { + "issues": "https://github.com/barryvdh/laravel-snappy/issues", + "source": "https://github.com/barryvdh/laravel-snappy/tree/master" + }, + "time": "2020-09-07T12:33:10+00:00" + }, { "name": "brick/math", "version": "0.9.2", @@ -1095,6 +1160,76 @@ ], "time": "2021-07-06T13:35:54+00:00" }, + { + "name": "knplabs/knp-snappy", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/snappy.git", + "reference": "7bac60fb729147b7ccd8532c07df3f52a4afa8a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/snappy/zipball/7bac60fb729147b7ccd8532c07df3f52a4afa8a4", + "reference": "7bac60fb729147b7ccd8532c07df3f52a4afa8a4", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/log": "^1.0", + "symfony/process": "~3.4||~4.3||~5.0" + }, + "require-dev": { + "phpunit/phpunit": "~7.4" + }, + "suggest": { + "h4cc/wkhtmltoimage-amd64": "Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltoimage-i386": "Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-i386": "Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "wemersonjanuario/wkhtmltopdf-windows": "Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Snappy\\": "src/Knp/Snappy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/snappy/contributors" + } + ], + "description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.", + "homepage": "http://github.com/KnpLabs/snappy", + "keywords": [ + "knp", + "knplabs", + "pdf", + "snapshot", + "thumbnail", + "wkhtmltopdf" + ], + "support": { + "issues": "https://github.com/KnpLabs/snappy/issues", + "source": "https://github.com/KnpLabs/snappy/tree/master" + }, + "time": "2020-01-20T08:30:30+00:00" + }, { "name": "laravel/framework", "version": "v8.50.0", @@ -1845,6 +1980,78 @@ ], "time": "2021-01-18T20:58:21+00:00" }, + { + "name": "livewire/livewire", + "version": "v2.5.5", + "source": { + "type": "git", + "url": "https://github.com/livewire/livewire.git", + "reference": "de192292d68276d831e5fd9824c80c3b78a21ddf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/livewire/livewire/zipball/de192292d68276d831e5fd9824c80c3b78a21ddf", + "reference": "de192292d68276d831e5fd9824c80c3b78a21ddf", + "shasum": "" + }, + "require": { + "illuminate/database": "^7.0|^8.0", + "illuminate/support": "^7.0|^8.0", + "illuminate/validation": "^7.0|^8.0", + "php": "^7.2.5|^8.0", + "symfony/http-kernel": "^5.0" + }, + "require-dev": { + "calebporzio/sushi": "^2.1", + "laravel/framework": "^7.0|^8.0", + "mockery/mockery": "^1.3.1", + "orchestra/testbench": "^5.0|^6.0", + "orchestra/testbench-dusk": "^5.2|^6.0", + "phpunit/phpunit": "^8.4|^9.0", + "psy/psysh": "@stable" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Livewire\\LivewireServiceProvider" + ], + "aliases": { + "Livewire": "Livewire\\Livewire" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Livewire\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Caleb Porzio", + "email": "calebporzio@gmail.com" + } + ], + "description": "A front-end framework for Laravel.", + "support": { + "issues": "https://github.com/livewire/livewire/issues", + "source": "https://github.com/livewire/livewire/tree/v2.5.5" + }, + "funding": [ + { + "url": "https://github.com/calebporzio", + "type": "github" + } + ], + "time": "2021-07-13T05:03:28+00:00" + }, { "name": "maatwebsite/excel", "version": "3.1.32", @@ -2163,6 +2370,80 @@ }, "time": "2021-05-25T15:42:17+00:00" }, + { + "name": "milon/barcode", + "version": "8.0.1", + "source": { + "type": "git", + "url": "https://github.com/milon/barcode.git", + "reference": "a1b1ee1a743c1368597f1742e6ee4765333a15a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/milon/barcode/zipball/a1b1ee1a743c1368597f1742e6ee4765333a15a1", + "reference": "a1b1ee1a743c1368597f1742e6ee4765333a15a1", + "shasum": "" + }, + "require": { + "illuminate/support": "^8.0", + "php": "^7.3 | ^8.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Milon\\Barcode\\BarcodeServiceProvider" + ], + "aliases": { + "DNS1D": "Milon\\Barcode\\Facades\\DNS1DFacade", + "DNS2D": "Milon\\Barcode\\Facades\\DNS2DFacade" + } + } + }, + "autoload": { + "psr-0": { + "Milon\\Barcode": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Nuruzzaman Milon", + "email": "contact@milon.im" + } + ], + "description": "Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)", + "keywords": [ + "CODABAR", + "CODE 128", + "CODE 39", + "barcode", + "datamatrix", + "ean", + "laravel", + "pdf417", + "qr code", + "qrcode" + ], + "support": { + "issues": "https://github.com/milon/barcode/issues", + "source": "https://github.com/milon/barcode/tree/8.0.1" + }, + "funding": [ + { + "url": "https://paypal.me/tomilon", + "type": "custom" + }, + { + "url": "https://github.com/milon", + "type": "github" + } + ], + "time": "2021-01-08T11:36:07+00:00" + }, { "name": "monolog/monolog", "version": "2.3.0", diff --git a/config/app.php b/config/app.php index 4550b238..d81eeeed 100644 --- a/config/app.php +++ b/config/app.php @@ -167,6 +167,8 @@ return [ */ RealRashid\SweetAlert\SweetAlertServiceProvider::class, Spatie\Permission\PermissionServiceProvider::class, + Milon\Barcode\BarcodeServiceProvider::class, + Barryvdh\Snappy\ServiceProvider::class, /* * Application Service Providers... */ @@ -230,6 +232,10 @@ return [ 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, 'Alert' => RealRashid\SweetAlert\Facades\Alert::class, + 'DNS1D' => Milon\Barcode\Facades\DNS1DFacade::class, + 'DNS2D' => Milon\Barcode\Facades\DNS2DFacade::class, + 'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class, + 'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class, ], ]; diff --git a/config/snappy.php b/config/snappy.php new file mode 100644 index 00000000..b95745ab --- /dev/null +++ b/config/snappy.php @@ -0,0 +1,52 @@ + [ + 'enabled' => true, + 'binary' => env('WKHTML_PDF_BINARY', '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"'), + 'timeout' => false, + 'options' => [], + 'env' => [], + ], + + 'image' => [ + 'enabled' => true, + 'binary' => env('WKHTML_IMG_BINARY', '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"'), + 'timeout' => false, + 'options' => [], + 'env' => [], + ], + +]; diff --git a/database/seeders/SuperUserSeeder.php b/database/seeders/SuperUserSeeder.php index b52858e5..402f4487 100644 --- a/database/seeders/SuperUserSeeder.php +++ b/database/seeders/SuperUserSeeder.php @@ -19,7 +19,8 @@ class SuperUserSeeder extends Seeder $user = User::create([ 'name' => 'Administrator', 'email' => 'admin@gmail.com', - 'password' => Hash::make(12345678) + 'password' => Hash::make(12345678), + 'is_active' => 1 ]); $superAdmin = Role::create([ diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 7436e584..7448dc24 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -14,6 +14,7 @@ @stack('page_css') + @livewireStyles
Product Code {{ $product->product_code }}
Barcode Symbology{{ $product->product_barcode_symbology }}
Name {{ $product->product_name }}