diff --git a/Gruntfile.js b/Gruntfile.js
index b71e6adb..a06409c4 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -17,6 +17,7 @@ var jsCompat = [
var jsSite = [
jsBase,
jsBootstrap,
+ 'node_modules/jquery-serializejson/jquery.serializejson.min.js',
'node_modules/currency.js/dist/currency.min.js',
'build/js/plugins/smooth_products/js/smoothproducts.min.js',
'build/js/site.js',
diff --git a/app/Datatables/Shop/CustomerOrdersDataTable.php b/app/Datatables/Shop/CustomerOrdersDataTable.php
new file mode 100644
index 00000000..b1b9c36e
--- /dev/null
+++ b/app/Datatables/Shop/CustomerOrdersDataTable.php
@@ -0,0 +1,53 @@
+byCustomer($customer_id)->with(['delivery']);
+ return $this->buildQuery($model);
+ }
+
+ public function modifier($datatables)
+ {
+ $datatables
+ ->editColumn('status', function (Order $order) {
+ return Orders::getStatus($order->status);
+ })
+ ->editColumn('created_at', function (Order $order) {
+ return $order->created_at->toDateTimeString();
+ })
+ ->editColumn('payment_type', function (Order $order) {
+ return InvoicePayments::getPaymentType($order->payment_type);
+ })
+ ->rawColumns(['action']);
+ return parent::modifier($datatables);
+ }
+
+ protected function getColumns()
+ {
+ return [
+ Column::make('ref')->title('Ref'),
+ Column::make('status')->title('Statut'),
+ Column::make('created_at')->title('Date'),
+ Column::make('payment_type')->title('Règlement'),
+ Column::make('total_shipped')->title('Montant')->class('text-right'),
+ $this->makeColumnButtons(),
+ ];
+ }
+}
diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php
index d90d9a34..d0aa6565 100644
--- a/app/Http/Controllers/Shop/CategoryController.php
+++ b/app/Http/Controllers/Shop/CategoryController.php
@@ -64,6 +64,8 @@ class CategoryController extends Controller
]),
'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
];
+ // dump($data);
+ // exit;
return view('Shop.Shelves.shelve', $data);
}
diff --git a/app/Http/Controllers/Shop/CustomerController.php b/app/Http/Controllers/Shop/CustomerController.php
index 4649fdd2..329d2766 100644
--- a/app/Http/Controllers/Shop/CustomerController.php
+++ b/app/Http/Controllers/Shop/CustomerController.php
@@ -25,7 +25,7 @@ class CustomerController extends Controller
public function edit()
{
$id = Auth::id();
- $data['customer'] = Customers::get($id);
+ $data['customer'] = Customers::get($id, 'addresses')->toArray();
return view('Shop.Customers.edit', $data);
}
@@ -35,5 +35,4 @@ class CustomerController extends Controller
$customer = Customers::store($data);
return response()->json(['error' => 0]);
}
-
}
diff --git a/app/Http/Controllers/Shop/InvoiceController.php b/app/Http/Controllers/Shop/InvoiceController.php
index fb3e1de8..ad5d2542 100644
--- a/app/Http/Controllers/Shop/InvoiceController.php
+++ b/app/Http/Controllers/Shop/InvoiceController.php
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Invoices;
+use App\Repositories\Core\PDF;
class InvoiceController extends Controller
{
@@ -15,9 +16,21 @@ class InvoiceController extends Controller
//
}
- public function show($id)
+ public function show($uuid)
{
- $data = Invoices::get($id);
+ $data = Invoices::getByUUID($uuid);
return view('Shop.Invoices.show', $data);
}
+
+ public function pdf($uuid)
+ {
+ \Debugbar::disable();
+ $data['invoice'] = Invoices::getByUUID($uuid);
+ $filename = 'invoice-' . $uuid . '.pdf';
+ $html = view('Shop.Invoices.pdf', $data)->toHtml();
+ // $html = '
Hello world!
';
+ // return PDF::convertHTML($html);
+ // return view('Shop.Invoices.pdf', $data);
+ return PDF::view('Shop.Invoices.pdf', $data, $filename);
+ }
}
diff --git a/app/Http/Controllers/Shop/OrderController.php b/app/Http/Controllers/Shop/OrderController.php
index a94f740d..5b048db5 100644
--- a/app/Http/Controllers/Shop/OrderController.php
+++ b/app/Http/Controllers/Shop/OrderController.php
@@ -26,16 +26,26 @@ class OrderController extends Controller
$data = Orders::getByUUID($uuid);
}
+ public function pdf($uuid)
+ {
+ $data = Orders::getByUUID($uuid);
+ return view('Shop.Orders.pdf', $data);
+ }
+
public function order()
{
- $customer = Customers::getWithAddresses();
- $data = [
- 'customer' => $customer ? $customer->toArray() : false,
- 'basket' => ShopCart::getSummary(),
- 'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
- 'sale_channel' => SaleChannels::getDefault()->toArray(),
- ];
- return view('Shop.Orders.order', $data);
+ if (ShopCart::count()) {
+ $customer = Customers::getWithAddresses();
+ $data = [
+ 'customer' => $customer ? $customer->toArray() : false,
+ 'basket' => ShopCart::getSummary(),
+ 'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
+ 'sale_channel' => SaleChannels::getDefault()->toArray(),
+ ];
+ return view('Shop.Orders.order', $data);
+ } else {
+ return redirect()->route('home');
+ }
}
public function store(Request $request)
diff --git a/app/Mail/Acheminement.php b/app/Mail/Acheminement.php
index 6547b423..0f1faa84 100644
--- a/app/Mail/Acheminement.php
+++ b/app/Mail/Acheminement.php
@@ -3,8 +3,6 @@
namespace App\Mail;
use App\Models\Core\Mail\MailTemplate;
-use App\Repositories\Core\DateTime;
-use App\Repositories\Shop\Customers;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;
diff --git a/app/Mail/Preparation.php b/app/Mail/Preparation.php
index 1a51cc08..f605be0a 100644
--- a/app/Mail/Preparation.php
+++ b/app/Mail/Preparation.php
@@ -9,7 +9,6 @@ use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Spatie\MailTemplates\TemplateMailable;
-
class Preparation extends TemplateMailable
{
use Queueable, SerializesModels;
diff --git a/app/Menu/Shop.php b/app/Menu/Shop.php
index b8adb5c3..85dbca07 100644
--- a/app/Menu/Shop.php
+++ b/app/Menu/Shop.php
@@ -55,6 +55,5 @@ class Shop
$menu->addTo('shop', 'Unités', [
'route' => 'Admin.Shop.Unities.index',
])->activeIfRoute(['Admin.Shop.Unities.*'])->order(14);
-
}
}
diff --git a/app/Models/Shop/Category.php b/app/Models/Shop/Category.php
index f689b176..a6a49aef 100644
--- a/app/Models/Shop/Category.php
+++ b/app/Models/Shop/Category.php
@@ -41,6 +41,11 @@ class Category extends parentCategory
return $this->tags->articles;
}
+ public function Parent()
+ {
+ return $this->hasOne(Category::class, 'id', 'parent_id');
+ }
+
public function categorizables()
{
return $this->hasMany(Categorizable::class);
diff --git a/app/Repositories/Core/DateStats.php b/app/Repositories/Core/DateStats.php
index 9f7f3baf..9d6e6c3f 100644
--- a/app/Repositories/Core/DateStats.php
+++ b/app/Repositories/Core/DateStats.php
@@ -5,7 +5,7 @@ namespace App\Repositories\Core;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
-Trait DateStats
+trait DateStats
{
public static function countByMonth($prev = 0)
{
diff --git a/app/Repositories/Core/PDF.php b/app/Repositories/Core/PDF.php
new file mode 100644
index 00000000..305ba64a
--- /dev/null
+++ b/app/Repositories/Core/PDF.php
@@ -0,0 +1,88 @@
+download($filename);
+ }
+
+ public static function convertHTML($html)
+ {
+ $mpdf = new Mpdf();
+ $mpdf->WriteHTML($html);
+ return $mpdf->Output();
+ }
+
+ public static function convertURL($url)
+ {
+ $pdf = SnappyPdf::loadFile($url);
+ return $pdf->download('invoice.pdf');
+ }
+
+ public static function convertIfNeeded($filename)
+ {
+ if (self::getVersion($filename) > 1.4) {
+ self::downgrade2($filename);
+ }
+ }
+
+ public static function getVersion($filename)
+ {
+ $pdf = fopen($filename, 'r');
+ if ($pdf) {
+ $line_first = fgets($pdf);
+ fclose($pdf);
+ } else {
+ echo 'error opening the file.';
+ }
+ preg_match_all('!\d+!', $line_first, $matches);
+ $version = implode('.', $matches[0]);
+
+ return (float) $version;
+ }
+
+ public static function downgrade($filename)
+ {
+ $new_filename = $filename.'-temp';
+ $ghostscript = new Ghostscript([
+ 'quiet' => false,
+ ]);
+
+ $device = $ghostscript->createPdfDevice($new_filename);
+ $device->setCompatibilityLevel(1.4);
+
+ // dump($device);
+ $process = $device->createProcess($filename);
+ // dump($process);
+ // echo '$ ' . $process->getCommandLine() . PHP_EOL;
+ // exit;
+ $process->run(function ($type, $buffer) {
+ if ($type === Process::ERR) {
+ throw new \RuntimeException($buffer);
+ }
+ // print $buffer;
+ });
+
+ unlink($filename);
+ rename($new_filename, $filename);
+ }
+
+ public static function downgrade2($filename)
+ {
+ $new_filename = $filename.'-temp';
+ shell_exec('gs -dBATCH -dCompatibilityLevel=1.4 -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="'.$new_filename.'" "'.$filename.'"');
+ unlink($filename);
+ rename($new_filename, $filename);
+ }
+}
diff --git a/app/Repositories/Shop/Categories.php b/app/Repositories/Shop/Categories.php
index 59229f52..ec38bf8d 100644
--- a/app/Repositories/Shop/Categories.php
+++ b/app/Repositories/Shop/Categories.php
@@ -34,14 +34,14 @@ class Categories
return Category::orderBy('name', 'asc')->get();
}
- public static function get($id)
+ public static function get($id, $relations = false)
{
- return Category::findOrFail($id);
+ return $relations ? Category::with($relations)->findOrFail($id) : Category::findOrFail($id);
}
public static function getFull($id)
{
- $category = self::get($id);
+ $category = self::get($id, ['Parent']);
$data = $category->toArray();
$data['name'] = $category->name;
$data['description'] = $category->description;
diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php
index 22512f29..4950d62d 100644
--- a/app/Repositories/Shop/Customers.php
+++ b/app/Repositories/Shop/Customers.php
@@ -2,7 +2,7 @@
namespace App\Repositories\Shop;
-use App\Datatables\Shop\OrdersDataTable;
+use App\Datatables\Shop\CustomerOrdersDataTable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
@@ -21,7 +21,7 @@ class Customers
public static function editProfile($id = false)
{
$id = $id ? $id : self::getId();
- $orders_datatable = new OrdersDataTable;
+ $orders_datatable = new CustomerOrdersDataTable;
$data = [
'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(),
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
diff --git a/app/Repositories/Shop/Invoices.php b/app/Repositories/Shop/Invoices.php
index c0257dac..d374b99c 100644
--- a/app/Repositories/Shop/Invoices.php
+++ b/app/Repositories/Shop/Invoices.php
@@ -10,7 +10,7 @@ class Invoices
{
public static function getByUUID($uuid)
{
- return Order::byUUID($uuid)->first();
+ return Invoice::byUUID($uuid)->first();
}
public static function saveInvoice($order_id, $data)
diff --git a/composer.json b/composer.json
index 45efa761..cac2a7f8 100644
--- a/composer.json
+++ b/composer.json
@@ -25,6 +25,7 @@
"darryldecode/cart": "^4.1",
"datatables/datatables": "^1.10",
"ddzobov/laravel-pivot-softdeletes": "^2.1",
+ "dietercoopman/smart": "^1.6",
"dompdf/dompdf": "^2.0.3",
"dyrynda/laravel-cascade-soft-deletes": "^4.1",
"eduardokum/laravel-mail-auto-embed": "^2.0",
@@ -38,6 +39,7 @@
"intervention/image": "^2.5",
"intervention/imagecache": "^2.4",
"jasonlewis/expressive-date": "^1.0",
+ "jdavidbakr/mail-tracker": "6.0",
"jenssegers/date": "^4.0",
"jeroen-g/blade-macro": "^1.0",
"kalnoy/nestedset": "^6.0",
@@ -92,6 +94,7 @@
"staudenmeir/eloquent-has-many-deep": "^1.13",
"stillat/numeral.php": "^2.0",
"symfony/http-client": "^6.2",
+ "tanthammar/laravel-window-size": "^2.1",
"thomasjohnkane/snooze": "^2.2",
"toin0u/geocoder-laravel": "^4.2",
"unicodeveloper/laravel-password": "^1.0",
diff --git a/resources/views/Shop/Customers/edit.blade.php b/resources/views/Shop/Customers/edit.blade.php
index 42872289..612e077c 100644
--- a/resources/views/Shop/Customers/edit.blade.php
+++ b/resources/views/Shop/Customers/edit.blade.php
@@ -11,15 +11,15 @@
- @include('Shop.Customers.partials.addresses')
+ @include('Shop.Customers.partials.addresses', ['addresses' => $customer['addresses']])
@include('Shop.auth.passwords.password_confirmation')
-
+
@endsection
@include('load.layout.modal')
diff --git a/resources/views/Shop/Customers/partials/addresses.blade.php b/resources/views/Shop/Customers/partials/addresses.blade.php
index ba8d223d..e23580a0 100644
--- a/resources/views/Shop/Customers/partials/addresses.blade.php
+++ b/resources/views/Shop/Customers/partials/addresses.blade.php
@@ -1,5 +1,5 @@
@foreach ($addresses ?? [] as $address)
-
+
@endforeach
+
+
+ @include('components.address', ['prefix' => 'deliveries', 'with_country' => false, 'with_tab' => true])
+
+
+
+@push('js')
+
+@endpush
\ No newline at end of file
diff --git a/resources/views/Shop/Customers/partials/deliveries.blade.php b/resources/views/Shop/Customers/partials/deliveries.blade.php
index 9146df02..c34f8ade 100644
--- a/resources/views/Shop/Customers/partials/deliveries.blade.php
+++ b/resources/views/Shop/Customers/partials/deliveries.blade.php
@@ -1,6 +1,6 @@
@foreach ($deliveries as $delivery)
-
-
+
+
@include('components.form.radios.icheck', [
'name' => 'delivery_id',
'id_name' => 'delivery_id_' . $delivery['id'],
@@ -8,7 +8,7 @@
'checked' => $customer['sale_delivery_id'] ?? false,
])
-
+
{{ $delivery['name'] }} - {{ $delivery['sale_channel']['name'] }}
{{ $delivery['description'] }}
diff --git a/resources/views/Shop/auth/passwords/password_confirmation.blade.php b/resources/views/Shop/auth/passwords/password_confirmation.blade.php
index 85483d3d..8fedf357 100644
--- a/resources/views/Shop/auth/passwords/password_confirmation.blade.php
+++ b/resources/views/Shop/auth/passwords/password_confirmation.blade.php
@@ -1,4 +1,4 @@
-