mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on the template action
This commit is contained in:
parent
2e4447fdf2
commit
52cdf610c7
@ -34,6 +34,7 @@ use Illuminate\Support\Facades\Storage;
|
||||
use App\Transformers\InvoiceTransformer;
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Services\Template\TemplateAction;
|
||||
use App\Factory\CloneInvoiceToQuoteFactory;
|
||||
use App\Http\Requests\Invoice\BulkInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\EditInvoiceRequest;
|
||||
@ -537,6 +538,16 @@ class InvoiceController extends BaseController
|
||||
}, 'print.pdf', ['Content-Type' => 'application/pdf']);
|
||||
}
|
||||
|
||||
if($action == 'template' && $user->can('view', $invoices->first())){
|
||||
|
||||
|
||||
$hash_or_response = $request->boolean('send_email') ? 'email sent' : \Illuminate\Support\Str::uuid();
|
||||
|
||||
TemplateAction::dispatch($request->ids, $request->template, Invoice::class, $user->id, $user->company(), $user->company()->db, $hash_or_response, $request->boolean('send_email'));
|
||||
|
||||
return response()->json(['message' => $hash_or_response], 200);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send the other actions to the switch
|
||||
*/
|
||||
@ -718,8 +729,7 @@ class InvoiceController extends BaseController
|
||||
return response()->json(['message' => 'email sent'], 200);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
default:
|
||||
return response()->json(['message' => ctrans('texts.action_unavailable', ['action' => $action])], 400);
|
||||
}
|
||||
|
52
app/Http/Controllers/TemplatePreviewController.php
Normal file
52
app/Http/Controllers/TemplatePreviewController.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Http\Requests\Report\ReportPreviewRequest;
|
||||
|
||||
class TemplatePreviewController extends BaseController
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
private string $path_prefix = 'templates/';
|
||||
|
||||
private string $path_suffix = '.pdf';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __invoke(ReportPreviewRequest $request, ?string $hash)
|
||||
{
|
||||
|
||||
$report = Storage::disk(config('filesystems.default'))->exists($this->path_prefix.$hash.$this->path_suffix);
|
||||
|
||||
if(!$report) {
|
||||
return response()->json(['message' => 'Still working.....'], 409);
|
||||
}
|
||||
|
||||
Cache::forget($hash);
|
||||
|
||||
return response()->streamDownload(function () use ($hash) {
|
||||
|
||||
echo Storage::get($this->path_prefix.$hash.$this->path_suffix);
|
||||
Storage::delete($this->path_prefix.$hash.$this->path_suffix);
|
||||
|
||||
}, 'template.pdf', ['Content-Type' => 'application/pdf']);
|
||||
|
||||
}
|
||||
}
|
@ -25,7 +25,10 @@ class BulkInvoiceRequest extends Request
|
||||
return [
|
||||
'action' => 'required|string',
|
||||
'ids' => 'required|array',
|
||||
'email_type' => 'sometimes|in:reminder1,reminder2,reminder3,reminder_endless,custom1,custom2,custom3,invoice,quote,credit,payment,payment_partial,statement,purchase_order'
|
||||
'email_type' => 'sometimes|in:reminder1,reminder2,reminder3,reminder_endless,custom1,custom2,custom3,invoice,quote,credit,payment,payment_partial,statement,purchase_order',
|
||||
'template' => 'sometimes|string',
|
||||
'template_id' => 'sometimes|string',
|
||||
'send_email' => 'sometimes|bool'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,7 @@ class PreviewReport implements ShouldQueue
|
||||
/** @var \App\Export\CSV\CreditExport $export */
|
||||
$export = new $this->report_class($this->company, $this->request);
|
||||
$report = $export->returnJson();
|
||||
nlog($report);
|
||||
nlog($this->report_class);
|
||||
// nlog($report);
|
||||
|
||||
Cache::put($this->hash, $report, 60 * 60);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ use Illuminate\Bus\Queueable;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Models\RecurringInvoice;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@ -59,6 +60,7 @@ class TemplateAction implements ShouldQueue
|
||||
private int $user_id,
|
||||
private Company $company,
|
||||
private string $db,
|
||||
private string $hash,
|
||||
private bool $send_email = false)
|
||||
{
|
||||
}
|
||||
@ -94,13 +96,18 @@ class TemplateAction implements ShouldQueue
|
||||
|
||||
if($this->send_email)
|
||||
$this->sendEmail($pdf);
|
||||
else
|
||||
return $pdf;
|
||||
else {
|
||||
|
||||
$filename = "templates/{$this->hash}.pdf";
|
||||
Storage::disk(config('filesystems.default'))->put($filename, $pdf);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function sendEmail(mixed $pdf): mixed
|
||||
{
|
||||
//send the email.
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,7 @@ use App\Http\Controllers\ExportController;
|
||||
use App\Http\Controllers\FilterController;
|
||||
use App\Http\Controllers\ImportController;
|
||||
use App\Http\Controllers\LogoutController;
|
||||
use App\Http\Controllers\SearchController;
|
||||
use App\Http\Controllers\StaticController;
|
||||
use App\Http\Controllers\StripeController;
|
||||
use App\Http\Controllers\TwilioController;
|
||||
@ -73,6 +74,7 @@ use App\Http\Controllers\BankTransactionController;
|
||||
use App\Http\Controllers\ClientStatementController;
|
||||
use App\Http\Controllers\ExpenseCategoryController;
|
||||
use App\Http\Controllers\HostedMigrationController;
|
||||
use App\Http\Controllers\TemplatePreviewController;
|
||||
use App\Http\Controllers\ConnectedAccountController;
|
||||
use App\Http\Controllers\RecurringExpenseController;
|
||||
use App\Http\Controllers\RecurringInvoiceController;
|
||||
@ -111,7 +113,6 @@ use App\Http\Controllers\Reports\ClientContactReportController;
|
||||
use App\Http\Controllers\Reports\PurchaseOrderReportController;
|
||||
use App\Http\Controllers\Reports\RecurringInvoiceReportController;
|
||||
use App\Http\Controllers\Reports\PurchaseOrderItemReportController;
|
||||
use App\Http\Controllers\SearchController;
|
||||
|
||||
Route::group(['middleware' => ['throttle:api', 'api_secret_check']], function () {
|
||||
Route::post('api/v1/signup', [AccountController::class, 'store'])->name('signup.submit');
|
||||
@ -318,6 +319,7 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale']
|
||||
Route::post('reports/tax_summary_report', TaxSummaryReportController::class);
|
||||
Route::post('reports/user_sales_report', UserSalesReportController::class);
|
||||
Route::post('reports/preview/{hash}', ReportPreviewController::class);
|
||||
Route::post('templates/preview/{hash}', TemplatePreviewController::class);
|
||||
Route::post('search', SearchController::class);
|
||||
|
||||
Route::resource('task_schedulers', TaskSchedulerController::class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user