Skip to content

Commit

Permalink
Merge pull request #8641 from turbo124/v5-stable
Browse files Browse the repository at this point in the history
v5.6.18
  • Loading branch information
turbo124 committed Jul 12, 2023
2 parents 47fe251 + 0472d18 commit 349e282
Show file tree
Hide file tree
Showing 25 changed files with 604 additions and 114 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.17
5.6.18
1 change: 1 addition & 0 deletions app/Export/CSV/BaseExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ private function resolveInvoiceKey($column, $entity, $transformer)

private function resolvePaymentKey($column, $entity, $transformer)
{

if($entity instanceof Payment){

$transformed_payment = $transformer->transform($entity);
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/ClientPortal/InvitationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ private function genericRouter(string $entity, string $invitation_key)
} else {
$is_silent = 'true';

return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key}), 'silent' => $is_silent]);

return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key}), 'silent' => $is_silent])->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
}
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);

return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})])->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
}
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/ClientPortal/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ private function downloadInvoicePDF(array $ids)

$file = $invoice->service()->getInvoicePdf(auth()->guard('contact')->user());

// return response()->download(file_get_contents(public_path($file)));

return response()->streamDownload(function () use ($file) {
echo Storage::get($file);
}, basename($file), ['Content-Type' => 'application/pdf']);
Expand Down
20 changes: 15 additions & 5 deletions app/Http/Controllers/MigrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class MigrationController extends BaseController
{
use DispatchesJobs;

public bool $silent_migration = false;

public function __construct()
{
parent::__construct();
Expand Down Expand Up @@ -260,6 +262,9 @@ public function startMigration(Request $request)
{
nlog('Starting Migration');

if($request->has('silent_migration'))
$this->silent_migration = true;

if ($request->companies) {
//handle Laravel 5.5 UniHTTP
$companies = json_decode($request->companies, 1);
Expand Down Expand Up @@ -312,7 +317,9 @@ public function startMigration(Request $request)
$nmo->company = $user->account->companies()->first();
$nmo->settings = $user->account->companies()->first()->settings;
$nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo, true);

if(!$this->silent_migration)
NinjaMailerJob::dispatch($nmo, true);

return;
} elseif ($existing_company && $company_count > 10) {
Expand All @@ -321,7 +328,9 @@ public function startMigration(Request $request)
$nmo->company = $user->account->companies()->first();
$nmo->settings = $user->account->companies()->first()->settings;
$nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo, true);

if(!$this->silent_migration)
NinjaMailerJob::dispatch($nmo, true);

return;
}
Expand All @@ -341,7 +350,8 @@ public function startMigration(Request $request)
$nmo->settings = $user->account->companies()->first();
$nmo->to_user = $user;

NinjaMailerJob::dispatch($nmo, true);
if(!$this->silent_migration)
NinjaMailerJob::dispatch($nmo, true);

return response()->json([
'_id' => Str::uuid(),
Expand Down Expand Up @@ -431,9 +441,9 @@ public function startMigration(Request $request)
nlog($migration_file);

if (Ninja::isHosted()) {
StartMigration::dispatch($migration_file, $user, $fresh_company)->onQueue('migration');
StartMigration::dispatch($migration_file, $user, $fresh_company, $this->silent_migration)->onQueue('migration');
} else {
StartMigration::dispatch($migration_file, $user, $fresh_company);
StartMigration::dispatch($migration_file, $user, $fresh_company, $this->silent_migration);
}
}

Expand Down
6 changes: 1 addition & 5 deletions app/Http/Controllers/ProtectedDownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public function index(Request $request)
abort(404, 'File no longer available');
}

UnlinkFile::dispatch(config('filesystems.default'), $hashed_path)->delay(now()->addSeconds(10));

return response()->streamDownload(function () use ($hashed_path) {
echo Storage::get($hashed_path);
}, basename($hashed_path), []);
return response()->download($hashed_path, basename($hashed_path), [])->deleteFileAfterSend(true);

}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/WebCronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct()
* @return Response
*
* @OA\Get(
* path="/api/v1/webcron",
* path="/webcron",
* operationId="webcron",
* tags={"webcron"},
* summary="Executes the task scheduler via a webcron service",
Expand Down
208 changes: 205 additions & 3 deletions app/Http/Livewire/PdfSlot.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@

namespace App\Http\Livewire;

use App\Libraries\MultiDB;
use App\Utils\Number;
use Livewire\Component;
use App\Utils\HtmlEngine;
use App\Libraries\MultiDB;
use App\Models\QuoteInvitation;
use App\Utils\VendorHtmlEngine;
use App\Models\CreditInvitation;
use App\Services\Pdf\PdfBuilder;
use App\Services\Pdf\PdfService;
use App\Models\InvoiceInvitation;
use App\Services\Pdf\PdfDesigner;
use App\Services\Pdf\PdfConfiguration;
use App\Models\PurchaseOrderInvitation;
use App\Models\RecurringInvoiceInvitation;
use App\Jobs\Vendor\CreatePurchaseOrderPdf;

class PdfSlot extends Component
{
Expand All @@ -27,23 +40,212 @@ class PdfSlot extends Component

public $url;

private $settings;

private $html_variables;

private $entity_type;

protected $listeners = ['viewportChanged' => 'getPdf'];

public function mount()
{
MultiDB::setDb($this->db);
}

public function getPdf()
{
$this->pdf = $this->entity->fullscreenPdfViewer($this->invitation);
}

public function downloadPdf()
{

$file_name = $this->entity->numberFormatter().'.pdf';

if($this->entity instanceof \App\Models\PurchaseOrder)
$file = (new CreatePurchaseOrderPdf($this->invitation, $this->invitation->company->db))->rawPdf();
else
$file = (new \App\Jobs\Entity\CreateRawPdf($this->invitation, $this->invitation->company->db))->handle();

$headers = ['Content-Type' => 'application/pdf'];

return response()->streamDownload(function () use ($file) {
echo $file;
}, $file_name, $headers);

}

public function render()
{
$this->entity_type = $this->resolveEntityType();

$this->settings = $this->entity->client ? $this->entity->client->getMergedSettings() : $this->entity->company->settings;

$this->html_variables = $this->entity->client ?
(new HtmlEngine($this->invitation))->generateLabelsAndValues() :
(new VendorHtmlEngine($this->invitation))->generateLabelsAndValues();

return render('components.livewire.pdf-slot', [
'invitation' => $this->invitation,
'entity' => $this->entity,
'data' => $this->invitation->company->settings,
'entity_type' => $this->entity_type,
'products' => $this->getProducts(),
'services' => $this->getServices(),
'amount' => Number::formatMoney($this->entity->amount, $this->entity->client ?: $this->entity->vendor),
'balance' => Number::formatMoney($this->entity->balance, $this->entity->client ?: $this->entity->vendor),
'company_details' => $this->getCompanyDetails(),
'company_address' => $this->getCompanyAddress(),
'entity_details' => $this->getEntityDetails(),
'user_details' => $this->getUserDetails(),
'user_name' => $this->getUserName(),

]);
}

public function getPdf()
private function convertVariables($string): string
{

$html = strtr($string, $this->html_variables['labels']);
$html = strtr($html, $this->html_variables['values']);

return $html;

}

private function getCompanyAddress()
{

$company_address = "";

foreach($this->settings->pdf_variables->company_address as $variable) {
$company_address .= "<p>{$variable}</p>";
}

return $this->convertVariables($company_address);

}

private function getCompanyDetails()
{
$company_details = "";

foreach($this->settings->pdf_variables->company_details as $variable) {
$company_details .= "<p>{$variable}</p>";
}

return $this->convertVariables($company_details);

}

private function getEntityDetails()
{
$entity_details = "";

if($this->entity_type == 'invoice' || $this->entity_type == 'recurring_invoice') {
foreach($this->settings->pdf_variables->invoice_details as $variable)
$entity_details .= "<div class='flex px-3 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-1 w-36 block entity-field'>{$variable}</p></div>";

}
elseif($this->entity_type == 'quote'){
foreach($this->settings->pdf_variables->quote_details as $variable)
$entity_details .= "<div class='flex px-3 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-1 w-36 block entity-field'>{$variable}</p></div>";
}
elseif($this->entity_type == 'credit') {
foreach($this->settings->pdf_variables->credit_details as $variable)
$entity_details .= "<div class='flex px-3 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-1 w-36 block entity-field'>{$variable}</p></div>";
}
elseif($this->entity_type == 'purchase_order'){
foreach($this->settings->pdf_variables->purchase_order_details as $variable)
$entity_details .= "<div class='flex px-3 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-1 w-36 block entity-field'>{$variable}</p></div>";
}

return $this->convertVariables($entity_details);

}

private function getUserName()
{
$name = ctrans('texts.details');

if($this->entity_type == 'purchase_order' && isset($this->settings->pdf_variables->vendor_details[0])) {
$name = $this->settings->pdf_variables->vendor_details[0];

} elseif(isset($this->settings->pdf_variables->client_details[0])) {

$name = $this->settings->pdf_variables->client_details[0];
}

return $this->convertVariables($name);

}

private function getUserDetails()
{
$user_details = "";

if($this->entity_type == 'purchase_order') {
foreach(array_slice($this->settings->pdf_variables->vendor_details,1) as $variable) {
$user_details .= "<p>{$variable}</p>";
}
}
else{
foreach(array_slice($this->settings->pdf_variables->client_details,1) as $variable) {
$user_details .= "<p>{$variable}</p>";
}
}

$this->pdf = $this->entity->fullscreenPdfViewer($this->invitation);
return $this->convertVariables($user_details);
}

private function getProducts()
{
$product_items = collect($this->entity->line_items)->filter(function ($item) {
return $item->type_id == 1 || $item->type_id == 6 || $item->type_id == 5;
})->map(function ($item){
return [
'quantity' => $item->quantity,
'cost' => Number::formatMoney($item->cost, $this->entity->client ?: $this->entity->vendor),
'notes' => $item->notes,
'line_total' => Number::formatMoney($item->line_total, $this->entity->client ?: $this->entity->vendor),
];
});

return $product_items;
}

private function getServices()
{
$task_items = collect($this->entity->line_items)->filter(function ($item) {
return $item->type_id == 2;
})->map(function ($item){
return [
'quantity' => $item->quantity,
'cost' => Number::formatMoney($item->cost, $this->entity->client ?: $this->entity->vendor),
'notes' => $item->notes,
'line_total' => Number::formatMoney($item->line_total, $this->entity->client ?: $this->entity->vendor),
];
});

return $task_items;

}

private function resolveEntityType() :string
{
if ($this->invitation instanceof InvoiceInvitation) {
return 'invoice';
} elseif ($this->invitation instanceof QuoteInvitation) {
return 'quote';
} elseif ($this->invitation instanceof CreditInvitation) {
return 'credit';
} elseif ($this->invitation instanceof RecurringInvoiceInvitation) {
return 'recurring_invoice';
} elseif ($this->invitation instanceof PurchaseOrderInvitation) {
return 'purchase_order';
}

return '';
}
}
2 changes: 1 addition & 1 deletion app/Http/Requests/Invoice/BulkInvoiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function rules()
{
return [
'action' => 'required|string',
'ids' => 'required',
'ids' => 'required|array',
'email_type' => 'sometimes|in:reminder1,reminder2,reminder3,reminder_endless,custom1,custom2,custom3,invoice,quote,credit,payment,payment_partial,statement,purchase_order'
];
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Invoice/BulkInvoiceJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Invoice $invoice, string $reminder_template)
*/
public function handle()
{ //only the reminder should mark the reminder sent field
// $this->invoice->service()->touchReminder($this->reminder_template)->markSent()->save();

$this->invoice->service()->markSent()->save();

$this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) {
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/Subscription/CleanStaleInvoiceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function handle(InvoiceRepository $repo) : void
Invoice::query()
->withTrashed()
->where('status_id', Invoice::STATUS_SENT)
->where('created_at', '<', now()->subHours(2))
->whereBetween('created_at', [now()->subHours(1), now()->subMinutes(10)])
->where('balance', '>', 0)
->cursor()
->each(function ($invoice){
Expand All @@ -77,7 +77,7 @@ public function handle(InvoiceRepository $repo) : void
Invoice::query()
->withTrashed()
->where('is_proforma', 1)
->where('created_at', '<', now()->subHour())
->whereBetween('created_at', [now()->subHours(1), now()->subMinutes(10)])
->cursor()
->each(function ($invoice) use ($repo) {
$invoice->is_proforma = false;
Expand Down

0 comments on commit 349e282

Please sign in to comment.