cosmetic fixes, enhance profile, fix mails, ...

This commit is contained in:
Ludovic CANDELLIER
2023-03-14 23:33:14 +01:00
parent 695d23a139
commit 23e6ca35ca
27 changed files with 266 additions and 54 deletions

View File

@@ -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',

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Datatables\Shop;
use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Order;
use App\Repositories\Shop\InvoicePayments;
use App\Repositories\Shop\Orders;
class CustomerOrdersDataTable extends DataTable
{
public $model_name = 'orders';
public $sortedColumn = 1;
public $sortedOrder = 'desc';
public $stateSave = true;
public function query(Order $model)
{
$customer_id = Auth::id();
$model = $model->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(),
];
}
}

View File

@@ -64,6 +64,8 @@ class CategoryController extends Controller
]),
'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
];
// dump($data);
// exit;
return view('Shop.Shelves.shelve', $data);
}

View File

@@ -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]);
}
}

View File

@@ -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 = '<h1>Hello world!</h1>';
// return PDF::convertHTML($html);
// return view('Shop.Invoices.pdf', $data);
return PDF::view('Shop.Invoices.pdf', $data, $filename);
}
}

View File

@@ -26,8 +26,15 @@ 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()
{
if (ShopCart::count()) {
$customer = Customers::getWithAddresses();
$data = [
'customer' => $customer ? $customer->toArray() : false,
@@ -36,6 +43,9 @@ class OrderController extends Controller
'sale_channel' => SaleChannels::getDefault()->toArray(),
];
return view('Shop.Orders.order', $data);
} else {
return redirect()->route('home');
}
}
public function store(Request $request)

View File

@@ -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;

View File

@@ -9,7 +9,6 @@ use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Spatie\MailTemplates\TemplateMailable;
class Preparation extends TemplateMailable
{
use Queueable, SerializesModels;

View File

@@ -55,6 +55,5 @@ class Shop
$menu->addTo('shop', 'Unités', [
'route' => 'Admin.Shop.Unities.index',
])->activeIfRoute(['Admin.Shop.Unities.*'])->order(14);
}
}

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Repositories\Core;
use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
use GravityMedia\Ghostscript\Ghostscript;
use Mpdf\Mpdf;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Symfony\Component\Process\Process;
class PDF
{
public static function view($view, $data, $filename = 'file.pdf')
{
\Debugbar::disable();
$pdf = DomPDF::loadView($view, $data);
return $pdf->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);
}
}

View File

@@ -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;

View File

@@ -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(),

View File

@@ -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)

View File

@@ -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",

View File

@@ -11,15 +11,15 @@
</div>
<div class="col-6">
<x-card title="Mes adresses de livraison" class="gradient-green1 mb-3">
@include('Shop.Customers.partials.addresses')
@include('Shop.Customers.partials.addresses', ['addresses' => $customer['addresses']])
</x-card>
<x-card title="Mon mot de passe" class="gradient-green1">
@include('Shop.auth.passwords.password_confirmation')
</x-card>
</div>
</div>
<x-save />
@endsection
@include('load.layout.modal')

View File

@@ -1,5 +1,5 @@
@foreach ($addresses ?? [] as $address)
<div class="row">
<div class="row mt-3">
<div class="col-1">
<x-form.radios.icheck name="address_id" val="{{ $address['id'] }}" id="address_{{ $address['id'] }}"/>
</div>
@@ -13,9 +13,22 @@
</div>
@endforeach
<div id="add_address_container" class="green-dark d-none mb-3 mt-3">
<x-card classBody="bg-green-dark yellow" title="Nouvelle adresse">
@include('components.address', ['prefix' => 'deliveries', 'with_country' => false, 'with_tab' => true])
</x-card>
</div>
<div class="row">
<div class="col-12 text-right">
<x-form.button id="add_address" icon="fa-plus" txt="Ajouter une adresse" class="btn-warning btn-sm" />
</div>
</div>
@push('js')
<script>
$('#add_address').click(function() {
$('#add_address_container').toggleClass('d-none');
})
</script>
@endpush

View File

@@ -1,6 +1,6 @@
@foreach ($deliveries as $delivery)
<div class="row mt-3 mb-3">
<div class="col-1 text-right">
<div class="row">
<div class="col-1 text-right pt-1">
@include('components.form.radios.icheck', [
'name' => 'delivery_id',
'id_name' => 'delivery_id_' . $delivery['id'],
@@ -8,7 +8,7 @@
'checked' => $customer['sale_delivery_id'] ?? false,
])
</div>
<div class="col-11 pt-1">
<div class="col-11 pt-3">
<strong>{{ $delivery['name'] }} - {{ $delivery['sale_channel']['name'] }}</strong><br/>
<p>{{ $delivery['description'] }}</p>
</div>

View File

@@ -1,4 +1,4 @@
<div class="row mb-3">
<div class="row mb-3 mt-3">
<label for="new-password" class="col-md-6 control-label text-right">Mot de passe actuel</label>
<div class="col-md-6">
<input id="current-password" type="password" class="form-control" name="current-password" required>

View File

@@ -3,7 +3,7 @@
@endphp
<div class="container p-0">
<div class="row m-0 shadow bg-white p-2 w-100 @if ( in_array($menu['id'], [$category['id'], $category['parent_id']])) active @endif">
<div class="row m-0 shadow bg-white p-2 w-100 @if ( in_array($menu['id'], [$category['id'] ?? false, $category['parent_id'] ?? false])) active @endif">
<div class="col mb-4">
<a class="green-dark" href="{{ route('Shop.Categories.show', ['id' => $menu['id']]) }}">
<div class="w-100"><strong>Tous les articles</strong></div>

View File

@@ -1,5 +1,5 @@
<a class="green-dark" href="{{ route('Shop.Categories.show', ['id' => $menu_children['id']]) }}">
<div class="w-100 @if (in_array($menu_children['id'], [$category['id'], $category['parent_id']])) active @endif">
<div class="w-100 @if (in_array($menu_children['id'], [$category['id'] ?? false, $category['parent_id'] ?? false])) active @endif">
<strong>{{ $menu_children['name'] }}</strong>
</div>
</a>

View File

@@ -5,7 +5,7 @@
<ul class="navbar-nav w-100">
@foreach ($categories as $menu)
<li class="nav-item dropdown megamenu p-2 col
@if (in_array($menu['id'], [$category['id'], $category['parent_id'], $category['parent']['parent_id'] ?? false])) active @endif">
@if (in_array($menu['id'], [$category['id'] ?? false, $category['parent_id'] ?? false, $category['parent']['parent_id'] ?? false])) active @endif">
@if ($menu['children'] ?? false)
<a id="megamenu_{{ $menu['id'] }}" href="{{ route('Shop.Categories.show', ['id' => $menu['id']]) }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link dropdown-toggle text-uppercase">
{{ $menu['name'] }}

View File

@@ -1,5 +1,5 @@
@if (($mode ?? false) == 'view')
<label class="light" for="{{ $prefix ?? null }}address">{{ __('address') }}</label><br/>
<label class="{{ $classLabel ?? 'light' }}" for="{{ $prefix ?? null }}address">{{ __('address') }}</label><br/>
@if ($item[($prefix ?? null) . 'address'])
{{ $item[($prefix ?? null) . 'address'] ?? null }}<br/>
@endif
@@ -23,34 +23,61 @@
<input type="hidden" name="{{ ($prefix ?? null) . (($with_tab ?? false) ? '[id]' : 'address_id') }}" value="{{ $with_id }}">
@endif
<div class="row mb-3">
<div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}address">{{ __('street') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address]' : 'address'), 'value' => ($with_tab ?? false) ? $item['address'] : ($item[($prefix ?? null) . 'address'] ?? null), 'disabled' => $disabled ?? false ])
<div class="col-12">
@include('components.form.input', [
'label' => __('street'),
'name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address]' : 'address'),
'value' => ($with_tab ?? false) ? $item['address'] ?? null : ($item[($prefix ?? null) . 'address'] ?? null),
'disabled' => $disabled ?? false
])
</div>
<div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}address2">{{ __('street_complement') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address2]' : 'address2'), 'value' => ($with_tab ?? false) ? $item['address2'] : ($item[($prefix ?? null) . 'address2'] ?? null), 'disabled' => $disabled ?? false ])
<div class="col-12">
@include('components.form.input', [
'label' => __('street_complement'),
'name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address2]' : 'address2'),
'value' => ($with_tab ?? false) ? $item['address2'] ?? null : ($item[($prefix ?? null) . 'address2'] ?? null),
'disabled' => $disabled ?? false,
])
</div>
</div>
<div class="row mb-3">
<div class="col-6 form-group">
<label class="light" for="{{ $prefix ?? null }}zipcode">{{ __('zipcode') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[zipcode]' : 'zipcode'), 'value' => ($with_tab ?? false) ? $item['zipcode'] : ($item[($prefix ?? null) . 'zipcode'] ?? null), 'disabled' => $disabled ?? false ])
<div class="col-4">
@include('components.form.input', [
'label' => __('zipcode'),
'name' => ($prefix ?? null) . (($with_tab ?? false) ? '[zipcode]' : 'zipcode'),
'value' => ($with_tab ?? false) ? $item['zipcode'] ?? null : ($item[($prefix ?? null) . 'zipcode'] ?? null),
'disabled' => $disabled ?? false,
])
</div>
<div class="col-6 form-group">
<label class="light" for="{{ $prefix ?? null }}city">{{ __('city') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[city]' : 'city'), 'value' => ($with_tab ?? false) ? $item['city'] : ($item[($prefix ?? null) . 'city'] ?? null), 'disabled' => $disabled ?? false ])
<div class="col-8">
@include('components.form.input', [
'label' => __('city'),
'name' => ($prefix ?? null) . (($with_tab ?? false) ? '[city]' : 'city'),
'value' => ($with_tab ?? false) ? $item['city'] ?? null : ($item[($prefix ?? null) . 'city'] ?? null),
'disabled' => $disabled ?? false,
])
</div>
</div>
@if ($with_country ?? true)
<div class="row mb-3">
<div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}country">{{ __('country') }}</label><br/>
@include('components.form.select', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[country_id]' : 'country_id'), 'list' => $countries ?? null, 'value' => ($with_tab ?? false) ? $item['country_id'] : ($item[($prefix ?? null) . 'country_id'] ?? null), 'with_empty' => '', 'required' => true, 'disabled' => $disabled ?? false ])
<div class="col-12 col-lg-6">
@include('components.form.select', [
'label' => __('country'),
'name' => ($prefix ?? null) . (($with_tab ?? false) ? '[country_id]' : 'country_id'),
'list' => $countries ?? null,
'value' => ($with_tab ?? false) ? $item['country_id'] ?? null : ($item[($prefix ?? null) . 'country_id'] ?? null),
'with_empty' => '',
'required' => true,
'disabled' => $disabled ?? false,
])
</div>
<div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}state">{{ __('state') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[state]' : 'state'), 'value' => ($with_tab ?? false) ? $item['state'] : ($item[($prefix ?? null) . 'state'] ?? null), 'disabled' => $disabled ?? false ])
<div class="col-12 col-lg-6">
@include('components.form.input', [
'label' => çç('state'),
'name' => ($prefix ?? null) . (($with_tab ?? false) ? '[state]' : 'state'),
'value' => ($with_tab ?? false) ? $item['state'] ?? null : ($item[($prefix ?? null) . 'state'] ?? null),
'disabled' => $disabled ?? false,
])
</div>
</div>
@endif

View File

@@ -9,7 +9,7 @@
{!! $tools !!}
</div>
@endisset
<h3 class="card-title {{ $classTitle ?? '' }}">{{ $title ?? false }}</h3>
<h3 class="card-title {{ $classTitle ?? 'mb-0' }}">{{ $title ?? false }}</h3>
@endisset
</div>
@endif

View File

@@ -1,6 +1,7 @@
<?php
Route::prefix('Factures')->name('Invoices.')->group(function () {
Route::get('show/{id}', 'InvoiceController@show')->name('show');
Route::get('show/{uuid?}', 'InvoiceController@show')->name('show');
Route::get('pdf/{uuid?}', 'InvoiceController@pdf')->name('pdf');
});

View File

@@ -6,5 +6,6 @@ Route::prefix('Orders')->name('Orders.')->group(function () {
Route::post('order', 'OrderController@store')->name('store');
Route::any('', 'OrderController@index')->name('index');
Route::get('view/{uuid?}', 'OrderController@view')->name('view');
Route::get('pdf/{uuid?}', 'OrderController@pdf')->name('pdf');
});