cosmetic fixes, enhance profile, fix mails, ...
This commit is contained in:
@@ -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