mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Bulk download PDF, Client Portal formatting (#3046)
* Update OpenAPI for TemplateController * Add bulk invoice download functionality * Working on Client portal * Move selective queries to cache instead of DB * Fix formatting in Payments table, implement cache for languages, resolve route model for clientcontacts and users
This commit is contained in:
parent
4694675b91
commit
3405b91c64
@ -20,11 +20,14 @@ use App\Repositories\BaseRepository;
|
|||||||
use App\Utils\Number;
|
use App\Utils\Number;
|
||||||
use App\Utils\Traits\MakesDates;
|
use App\Utils\Traits\MakesDates;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Barracuda\ArchiveStream\Archive;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Yajra\DataTables\Facades\DataTables;
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
use Yajra\DataTables\Html\Builder;
|
use Yajra\DataTables\Html\Builder;
|
||||||
|
use ZipStream\Option\Archive;
|
||||||
|
use ZipStream\ZipStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class InvoiceController
|
* Class InvoiceController
|
||||||
@ -168,25 +171,32 @@ class InvoiceController extends Controller
|
|||||||
{
|
{
|
||||||
$invoices = Invoice::whereIn('id', $ids)
|
$invoices = Invoice::whereIn('id', $ids)
|
||||||
->whereClientId(auth()->user()->client->id)
|
->whereClientId(auth()->user()->client->id)
|
||||||
->get()
|
->get();
|
||||||
->filter(function ($invoice){
|
|
||||||
return $invoice->isPayable();
|
|
||||||
});
|
|
||||||
|
|
||||||
//generate pdf's of invoices locally
|
//generate pdf's of invoices locally
|
||||||
|
if(!$invoices || $invoices->count() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
//if only 1 pdf, output to buffer for download
|
//if only 1 pdf, output to buffer for download
|
||||||
|
if($invoices->count() == 1)
|
||||||
|
return response()->download(public_path($invoices->first()->pdf_file_path()));
|
||||||
|
|
||||||
|
|
||||||
//if multiple pdf's, output to zip stream using Barracuda lib
|
# enable output of HTTP headers
|
||||||
|
$options = new Archive();
|
||||||
|
$options->setSendHttpHeaders(true);
|
||||||
|
|
||||||
|
# create a new zipstream object
|
||||||
|
$zip = new ZipStream(date('Y-m-d') . '_' . str_replace(' ', '_', trans('texts.invoices')).".zip", $options);
|
||||||
|
|
||||||
|
foreach($invoices as $invoice){
|
||||||
|
|
||||||
|
$zip->addFileFromPath(basename($invoice->pdf_file_path()), public_path($invoice->pdf_file_path()));
|
||||||
|
}
|
||||||
|
|
||||||
|
# finish the zip stream
|
||||||
|
$zip->finish();
|
||||||
|
|
||||||
/*
|
|
||||||
$zip = Archive::instance_by_useragent(date('Y-m-d') . '_' . str_replace(' ', '_', trans('texts.invoices')));
|
|
||||||
$zip->add_file($name, $document->getRaw());
|
|
||||||
$zip->finish();
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class PaymentController extends Controller
|
|||||||
public function index(PaymentFilters $filters, Builder $builder)
|
public function index(PaymentFilters $filters, Builder $builder)
|
||||||
{
|
{
|
||||||
//$payments = Payment::filter($filters);
|
//$payments = Payment::filter($filters);
|
||||||
$payments = Payment::with('type')->get();
|
$payments = Payment::with('type','client')->get();
|
||||||
|
|
||||||
if (request()->ajax()) {
|
if (request()->ajax()) {
|
||||||
|
|
||||||
@ -58,6 +58,13 @@ class PaymentController extends Controller
|
|||||||
->editColumn('status_id', function ($payment){
|
->editColumn('status_id', function ($payment){
|
||||||
return Payment::badgeForStatus($payment->status_id);
|
return Payment::badgeForStatus($payment->status_id);
|
||||||
})
|
})
|
||||||
|
->editColumn('payment_date', function ($payment){
|
||||||
|
//return $payment->payment_date;
|
||||||
|
return $payment->formatDate($payment->payment_date, $payment->client->date_format());
|
||||||
|
})
|
||||||
|
->editColumn('amount', function ($payment) {
|
||||||
|
return Number::formatMoney($payment->amount, $payment->client);
|
||||||
|
})
|
||||||
->rawColumns(['action', 'status_id','payment_type_id'])
|
->rawColumns(['action', 'status_id','payment_type_id'])
|
||||||
->make(true);
|
->make(true);
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ use App\Http\Requests\ClientPortal\ShowRecurringInvoiceRequest;
|
|||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
use App\Notifications\ClientContactRequestCancellation;
|
use App\Notifications\ClientContactRequestCancellation;
|
||||||
use App\Notifications\ClientContactResetPassword;
|
use App\Notifications\ClientContactResetPassword;
|
||||||
|
use App\Utils\Number;
|
||||||
|
use App\Utils\Traits\MakesDates;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@ -33,7 +35,7 @@ class RecurringInvoiceController extends Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
use MakesDates;
|
||||||
/**
|
/**
|
||||||
* Show the list of Invoices
|
* Show the list of Invoices
|
||||||
*
|
*
|
||||||
@ -46,6 +48,7 @@ class RecurringInvoiceController extends Controller
|
|||||||
$invoices = RecurringInvoice::whereClientId(auth()->user()->client->id)
|
$invoices = RecurringInvoice::whereClientId(auth()->user()->client->id)
|
||||||
->whereIn('status_id', [RecurringInvoice::STATUS_PENDING, RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_COMPLETED])
|
->whereIn('status_id', [RecurringInvoice::STATUS_PENDING, RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_COMPLETED])
|
||||||
->orderBy('status_id', 'asc')
|
->orderBy('status_id', 'asc')
|
||||||
|
->with('client')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
if (request()->ajax()) {
|
if (request()->ajax()) {
|
||||||
@ -58,6 +61,15 @@ class RecurringInvoiceController extends Controller
|
|||||||
->editColumn('status_id', function ($invoice){
|
->editColumn('status_id', function ($invoice){
|
||||||
return RecurringInvoice::badgeForStatus($invoice->status);
|
return RecurringInvoice::badgeForStatus($invoice->status);
|
||||||
})
|
})
|
||||||
|
->editColumn('start_date', function ($invoice){
|
||||||
|
return $this->formatDate($invoice->invoice_date, $invoice->client->date_format());
|
||||||
|
})
|
||||||
|
->editColumn('next_send_date', function ($invoice){
|
||||||
|
return $this->formatDate($invoice->next_send_date, $invoice->client->date_format());
|
||||||
|
})
|
||||||
|
->editColumn('amount', function ($invoice){
|
||||||
|
return Number::formatMoney($invoice->amount, $invoice->client);
|
||||||
|
})
|
||||||
->rawColumns(['action', 'status_id'])
|
->rawColumns(['action', 'status_id'])
|
||||||
->make(true);
|
->make(true);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class TemplateController extends BaseController
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*
|
*
|
||||||
* @OA\Get(
|
* @OA\Post(
|
||||||
* path="/api/v1/templates/{entity}/{entity_id}",
|
* path="/api/v1/templates/{entity}/{entity_id}",
|
||||||
* operationId="getShowTemplate",
|
* operationId="getShowTemplate",
|
||||||
* tags={"templates"},
|
* tags={"templates"},
|
||||||
|
@ -50,7 +50,7 @@ class QueryLogging
|
|||||||
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
|
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
|
||||||
|
|
||||||
// if($count > 50)
|
// if($count > 50)
|
||||||
// Log::info($queries);
|
// Log::info($queries);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
155
app/Jobs/Invoice/CreateInvoicePdf.php
Normal file
155
app/Jobs/Invoice/CreateInvoicePdf.php
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Jobs\Invoice;
|
||||||
|
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use App\Models\PaymentTerm;
|
||||||
|
use App\Repositories\InvoiceRepository;
|
||||||
|
use App\Utils\Traits\NumberFormatter;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Spatie\Browsershot\Browsershot;
|
||||||
|
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||||
|
|
||||||
|
class CreateInvoicePdf implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter;
|
||||||
|
|
||||||
|
public $invoice;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Invoice $invoice)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->invoice = $invoice;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$this->invoice->load('client');
|
||||||
|
$path = 'public/' . $this->invoice->client->client_hash . '/invoices/';
|
||||||
|
$file_path = $path . $this->invoice->invoice_number . '.pdf';
|
||||||
|
|
||||||
|
//get invoice design
|
||||||
|
$html = $this->generateInvoiceHtml($this->invoice->design(), $this->invoice);
|
||||||
|
|
||||||
|
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
|
||||||
|
Storage::makeDirectory($path, 0755);
|
||||||
|
|
||||||
|
//create pdf
|
||||||
|
$pdf = $this->makePdf(null,null,$html);
|
||||||
|
|
||||||
|
$path = Storage::put($file_path, $pdf);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a PDF stream
|
||||||
|
*
|
||||||
|
* @param string $header Header to be included in PDF
|
||||||
|
* @param string $footer Footer to be included in PDF
|
||||||
|
* @param string $html The HTML object to be converted into PDF
|
||||||
|
*
|
||||||
|
* @return string The PDF string
|
||||||
|
*/
|
||||||
|
private function makePdf($header, $footer, $html)
|
||||||
|
{
|
||||||
|
return Browsershot::html($html)
|
||||||
|
//->showBrowserHeaderAndFooter()
|
||||||
|
//->headerHtml($header)
|
||||||
|
//->footerHtml($footer)
|
||||||
|
->waitUntilNetworkIdle(false)->pdf();
|
||||||
|
//->margins(10,10,10,10)
|
||||||
|
//->savePdf('test.pdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the HTML invoice parsing variables
|
||||||
|
* and generating the final invoice HTML
|
||||||
|
*
|
||||||
|
* @param string $design either the path to the design template, OR the full design template string
|
||||||
|
* @param Collection $invoice The invoice object
|
||||||
|
*
|
||||||
|
* @return string The invoice string in HTML format
|
||||||
|
*/
|
||||||
|
private function generateInvoiceHtml($design, $invoice) :string
|
||||||
|
{
|
||||||
|
|
||||||
|
$variables = array_merge($invoice->makeLabels(), $invoice->makeValues());
|
||||||
|
$design = str_replace(array_keys($variables), array_values($variables), $design);
|
||||||
|
|
||||||
|
$data['invoice'] = $invoice;
|
||||||
|
|
||||||
|
return $this->renderView($design, $data);
|
||||||
|
|
||||||
|
//return view($design, $data)->render();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the blade file string and processes the template variables
|
||||||
|
*
|
||||||
|
* @param string $string The Blade file string
|
||||||
|
* @param array $data The array of template variables
|
||||||
|
* @return string The return HTML string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function renderView($string, $data) :string
|
||||||
|
{
|
||||||
|
if (!$data) {
|
||||||
|
$data = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['__env'] = app(\Illuminate\View\Factory::class);
|
||||||
|
|
||||||
|
$php = Blade::compileString($string);
|
||||||
|
|
||||||
|
$obLevel = ob_get_level();
|
||||||
|
ob_start();
|
||||||
|
extract($data, EXTR_SKIP);
|
||||||
|
|
||||||
|
try {
|
||||||
|
eval('?' . '>' . $php);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
while (ob_get_level() > $obLevel) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
while (ob_get_level() > $obLevel) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new FatalThrowableError($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ob_get_clean();
|
||||||
|
}
|
||||||
|
}
|
@ -11,18 +11,13 @@
|
|||||||
|
|
||||||
namespace App\Listeners\Invoice;
|
namespace App\Listeners\Invoice;
|
||||||
|
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Jobs\Invoice\CreateInvoicePdf as PdfCreator;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Support\Facades\Blade;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Spatie\Browsershot\Browsershot;
|
|
||||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
|
||||||
|
|
||||||
class CreateInvoicePdf implements ShouldQueue
|
class CreateInvoicePdf implements ShouldQueue
|
||||||
{
|
{
|
||||||
protected $activity_repo;
|
|
||||||
/**
|
/**
|
||||||
* Create the event listener.
|
* Create the event listener.
|
||||||
*
|
*
|
||||||
@ -40,109 +35,6 @@ class CreateInvoicePdf implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle($event)
|
public function handle($event)
|
||||||
{
|
{
|
||||||
|
PdfCreator::dispatch($event->invoice);
|
||||||
$invoice = $event->invoice;
|
|
||||||
|
|
||||||
$invoice->load('client');
|
|
||||||
$path = 'public/' . $invoice->client->client_hash . '/invoices/';
|
|
||||||
$file_path = $path . $invoice->invoice_number . '.pdf';
|
|
||||||
|
|
||||||
//get invoice design
|
|
||||||
$html = $this->generateInvoiceHtml($invoice->design(), $invoice);
|
|
||||||
|
|
||||||
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
|
|
||||||
Storage::makeDirectory($path, 0755);
|
|
||||||
|
|
||||||
//create pdf
|
|
||||||
$pdf = $this->makePdf(null,null,$html);
|
|
||||||
|
|
||||||
$path = Storage::put($file_path, $pdf);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a PDF stream
|
|
||||||
*
|
|
||||||
* @param string $header Header to be included in PDF
|
|
||||||
* @param string $footer Footer to be included in PDF
|
|
||||||
* @param string $html The HTML object to be converted into PDF
|
|
||||||
*
|
|
||||||
* @return string The PDF string
|
|
||||||
*/
|
|
||||||
private function makePdf($header, $footer, $html)
|
|
||||||
{
|
|
||||||
return Browsershot::html($html)
|
|
||||||
//->showBrowserHeaderAndFooter()
|
|
||||||
//->headerHtml($header)
|
|
||||||
//->footerHtml($footer)
|
|
||||||
->waitUntilNetworkIdle(false)->pdf();
|
|
||||||
//->margins(10,10,10,10)
|
|
||||||
//->savePdf('test.pdf');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the HTML invoice parsing variables
|
|
||||||
* and generating the final invoice HTML
|
|
||||||
*
|
|
||||||
* @param string $design either the path to the design template, OR the full design template string
|
|
||||||
* @param Collection $invoice The invoice object
|
|
||||||
*
|
|
||||||
* @return string The invoice string in HTML format
|
|
||||||
*/
|
|
||||||
private function generateInvoiceHtml($design, $invoice) :string
|
|
||||||
{
|
|
||||||
|
|
||||||
$variables = array_merge($invoice->makeLabels(), $invoice->makeValues());
|
|
||||||
$design = str_replace(array_keys($variables), array_values($variables), $design);
|
|
||||||
|
|
||||||
$data['invoice'] = $invoice;
|
|
||||||
|
|
||||||
return $this->renderView($design, $data);
|
|
||||||
|
|
||||||
//return view($design, $data)->render();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the blade file string and processes the template variables
|
|
||||||
*
|
|
||||||
* @param string $string The Blade file string
|
|
||||||
* @param array $data The array of template variables
|
|
||||||
* @return string The return HTML string
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function renderView($string, $data) :string
|
|
||||||
{
|
|
||||||
if (!$data) {
|
|
||||||
$data = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$data['__env'] = app(\Illuminate\View\Factory::class);
|
|
||||||
|
|
||||||
$php = Blade::compileString($string);
|
|
||||||
|
|
||||||
$obLevel = ob_get_level();
|
|
||||||
ob_start();
|
|
||||||
extract($data, EXTR_SKIP);
|
|
||||||
|
|
||||||
try {
|
|
||||||
eval('?' . '>' . $php);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
while (ob_get_level() > $obLevel) {
|
|
||||||
ob_end_clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
while (ob_get_level() > $obLevel) {
|
|
||||||
ob_end_clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new FatalThrowableError($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ob_get_clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ use App\Utils\Traits\MakesDates;
|
|||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Hashids\Hashids;
|
use Hashids\Hashids;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
use Laracasts\Presenter\PresentableTrait;
|
use Laracasts\Presenter\PresentableTrait;
|
||||||
@ -169,12 +170,25 @@ class Client extends BaseModel
|
|||||||
|
|
||||||
public function date_format()
|
public function date_format()
|
||||||
{
|
{
|
||||||
return DateFormat::find($this->getSetting('date_format_id'))->format;
|
$date_formats = Cache::get('date_formats');
|
||||||
|
|
||||||
|
return $date_formats->filter(function($item) {
|
||||||
|
return $item->id == $this->getSetting('date_format_id');
|
||||||
|
})->first()->format;
|
||||||
|
|
||||||
|
//return DateFormat::find($this->getSetting('date_format_id'))->format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function currency()
|
public function currency()
|
||||||
{
|
{
|
||||||
return Currency::find($this->getSetting('currency_id'));
|
|
||||||
|
$currencies = Cache::get('currencies');
|
||||||
|
|
||||||
|
return $currencies->filter(function($item) {
|
||||||
|
return $item->id == $this->getSetting('currency_id');
|
||||||
|
})->first();
|
||||||
|
|
||||||
|
//return Currency::find($this->getSetting('currency_id'));
|
||||||
//return $this->belongsTo(Currency::class);
|
//return $this->belongsTo(Currency::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +138,28 @@ class ClientContact extends Authenticatable implements HasLocalePreference
|
|||||||
|
|
||||||
public function preferredLocale()
|
public function preferredLocale()
|
||||||
{
|
{
|
||||||
$lang = Language::find($this->client->getSetting('language_id'));
|
$languages = Cache::get('languages');
|
||||||
|
|
||||||
return $lang->locale;
|
return $languages->filter(function($item) {
|
||||||
|
return $item->id == $this->client->getSetting('language_id');
|
||||||
|
})->first()->locale;
|
||||||
|
|
||||||
|
//$lang = Language::find($this->client->getSetting('language_id'));
|
||||||
|
|
||||||
|
//return $lang->locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the model for a bound value.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return \Illuminate\Database\Eloquent\Model|null
|
||||||
|
*/
|
||||||
|
public function resolveRouteBinding($value)
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->withTrashed()
|
||||||
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ namespace App\Models;
|
|||||||
use App\Events\Invoice\InvoiceWasUpdated;
|
use App\Events\Invoice\InvoiceWasUpdated;
|
||||||
use App\Helpers\Invoice\InvoiceSum;
|
use App\Helpers\Invoice\InvoiceSum;
|
||||||
use App\Helpers\Invoice\InvoiceSumInclusive;
|
use App\Helpers\Invoice\InvoiceSumInclusive;
|
||||||
|
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||||
use App\Models\Currency;
|
use App\Models\Currency;
|
||||||
use App\Models\Filterable;
|
use App\Models\Filterable;
|
||||||
use App\Models\PaymentTerm;
|
use App\Models\PaymentTerm;
|
||||||
@ -298,6 +299,17 @@ class Invoice extends BaseModel
|
|||||||
return $public_path;
|
return $public_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pdf_file_path()
|
||||||
|
{
|
||||||
|
$storage_path = 'storage/' . $this->client->client_hash . '/invoices/'. $this->invoice_number . '.pdf';
|
||||||
|
|
||||||
|
if(!Storage::exists($storage_path)) {
|
||||||
|
CreateInvoicePdf::dispatchNow($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $storage_path;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $save
|
* @param bool $save
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Models\Filterable;
|
use App\Models\Filterable;
|
||||||
|
use App\Utils\Traits\MakesDates;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
@ -25,7 +26,7 @@ class RecurringInvoice extends BaseModel
|
|||||||
use MakesHash;
|
use MakesHash;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
use Filterable;
|
use Filterable;
|
||||||
|
use MakesDates;
|
||||||
/**
|
/**
|
||||||
* Invoice Statuses
|
* Invoice Statuses
|
||||||
*/
|
*/
|
||||||
|
@ -361,6 +361,17 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
return $this->email;
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the model for a bound value.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return \Illuminate\Database\Eloquent\Model|null
|
||||||
|
*/
|
||||||
|
public function resolveRouteBinding($value)
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->withTrashed()
|
||||||
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class ClientContactRequestCancellation extends Notification implements ShouldQue
|
|||||||
*/
|
*/
|
||||||
public function via($notifiable)
|
public function via($notifiable)
|
||||||
{
|
{
|
||||||
return ['mail'];
|
return ['mail','slack'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
"laravelcollective/html": "6.0.*",
|
"laravelcollective/html": "6.0.*",
|
||||||
"league/fractal": "^0.17.0",
|
"league/fractal": "^0.17.0",
|
||||||
"league/omnipay": "^3.0",
|
"league/omnipay": "^3.0",
|
||||||
|
"maennchen/zipstream-php": "^1.2",
|
||||||
"nwidart/laravel-modules": "^6.0",
|
"nwidart/laravel-modules": "^6.0",
|
||||||
"omnipay/paypal": "^3.0",
|
"omnipay/paypal": "^3.0",
|
||||||
"omnipay/stripe": "^3.0",
|
"omnipay/stripe": "^3.0",
|
||||||
|
@ -178,7 +178,10 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#download_invoices').click(function() {
|
$('#download_invoices').click(function() {
|
||||||
alert('download');
|
$('#hashed_ids').val(selected);
|
||||||
|
$('#action').val('download');
|
||||||
|
|
||||||
|
$('#payment_form').submit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-responsive-sm table-bordered">
|
<table class="table table-responsive-sm table-bordered">
|
||||||
<tr><td style="text-align: right;">{{ctrans('texts.start_date')}}</td><td>{!! $invoice->start_date !!}</td></tr>
|
<tr><td style="text-align: right;">{{ctrans('texts.start_date')}}</td><td>{!! $invoice->formatDate($invoice->start_date,$invoice->client->date_format()) !!}</td></tr>
|
||||||
<tr><td style="text-align: right;">{{ctrans('texts.next_send_date')}}</td><td>{!! $invoice->next_send_date !!}</td></tr>
|
<tr><td style="text-align: right;">{{ctrans('texts.next_send_date')}}</td><td>{!! $invoice->formatDate($invoice->next_send_date,$invoice->client->date_format()) !!}</td></tr>
|
||||||
<tr><td style="text-align: right;">{{ctrans('texts.frequency')}}</td><td>{!! App\Models\RecurringInvoice::frequencyForKey($invoice->frequency_id) !!}</td></tr>
|
<tr><td style="text-align: right;">{{ctrans('texts.frequency')}}</td><td>{!! App\Models\RecurringInvoice::frequencyForKey($invoice->frequency_id) !!}</td></tr>
|
||||||
<tr><td style="text-align: right;">{{ctrans('texts.cycles_remaining')}}</td><td>{!! $invoice->remaining_cycles !!}</td></tr>
|
<tr><td style="text-align: right;">{{ctrans('texts.cycles_remaining')}}</td><td>{!! $invoice->remaining_cycles !!}</td></tr>
|
||||||
<tr><td style="text-align: right;">{{ctrans('texts.amount')}}</td><td>{!! $invoice->amount !!}</td></tr>
|
<tr><td style="text-align: right;">{{ctrans('texts.amount')}}</td><td>{!! App\Utils\Number::formatMoney($invoice->amount, $invoice->client) !!}</td></tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
39
tests/Integration/CheckCacheTest.php
Normal file
39
tests/Integration/CheckCacheTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Integration;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
class CheckCacheTest extends TestCase
|
||||||
|
{
|
||||||
|
use MockAccountData;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWarmedUpCache()
|
||||||
|
{
|
||||||
|
$date_formats = Cache::get('date_formats');
|
||||||
|
|
||||||
|
$this->assertNotNull($date_formats);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCacheCount()
|
||||||
|
{
|
||||||
|
$date_formats = Cache::get('date_formats');
|
||||||
|
|
||||||
|
$this->assertEquals(13, count($date_formats));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user