cosmetic fixes, enhance profile, fix mails, ...
This commit is contained in:
53
app/Datatables/Shop/CustomerOrdersDataTable.php
Normal file
53
app/Datatables/Shop/CustomerOrdersDataTable.php
Normal 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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,8 @@ class CategoryController extends Controller
|
||||
]),
|
||||
'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
|
||||
];
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Shop.Shelves.shelve', $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -9,7 +9,6 @@ use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Spatie\MailTemplates\TemplateMailable;
|
||||
|
||||
|
||||
class Preparation extends TemplateMailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
@@ -55,6 +55,5 @@ class Shop
|
||||
$menu->addTo('shop', 'Unités', [
|
||||
'route' => 'Admin.Shop.Unities.index',
|
||||
])->activeIfRoute(['Admin.Shop.Unities.*'])->order(14);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
88
app/Repositories/Core/PDF.php
Normal file
88
app/Repositories/Core/PDF.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user