1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Merge pull request #7447 from CirkaN/Cirkovic/INA-3

Cirkovic/INA-3 Support sending csv reports via email
This commit is contained in:
David Bomba 2022-05-18 11:46:59 +10:00 committed by GitHub
commit d7a505546c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 225 additions and 20 deletions

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\ContactExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,8 +63,11 @@ class ClientContactReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), ContactExport::class, $this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new ContactExport(auth()->user()->company(), $request->all());
$csv = $export->run();
@ -76,9 +80,8 @@ class ClientContactReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\ClientExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -63,6 +64,10 @@ class ClientReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),ClientExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new ClientExport(auth()->user()->company(), $request->all());
@ -77,7 +82,7 @@ class ClientReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\CreditExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class CreditReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),CreditExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new CreditExport(auth()->user()->company(), $request->all());
@ -76,7 +81,7 @@ class CreditReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\DocumentExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class DocumentReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),DocumentExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new DocumentExport(auth()->user()->company(), $request->all());
@ -76,7 +81,7 @@ class DocumentReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\ExpenseExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -63,6 +64,10 @@ class ExpenseReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),ExpenseExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new ExpenseExport(auth()->user()->company(), $request->all());
@ -77,7 +82,7 @@ class ExpenseReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\InvoiceItemExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class InvoiceItemReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),InvoiceItemExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new InvoiceItemExport(auth()->user()->company(), $request->all());
@ -76,7 +81,7 @@ class InvoiceItemReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\InvoiceExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class InvoiceReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),InvoiceExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new InvoiceExport(auth()->user()->company(), $request->all());
@ -76,9 +81,8 @@ class InvoiceReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\PaymentExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -63,6 +64,10 @@ class PaymentReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), PaymentExport::class, $this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new PaymentExport(auth()->user()->company(), $request->all());
@ -77,9 +82,8 @@ class PaymentReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\ProductExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -63,6 +64,10 @@ class ProductReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),ProductExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new ProductExport(auth()->user()->company(), $request->all());
@ -77,7 +82,7 @@ class ProductReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\PaymentExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\ProfitLossRequest;
use App\Jobs\Report\SendToAdmin;
use App\Models\Client;
use App\Services\Report\ProfitLoss;
use App\Utils\Traits\MakesHash;
@ -64,13 +65,17 @@ class ProfitAndLossController extends BaseController
*/
public function __invoke(ProfitLossRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),ProfitLoss::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$pnl = new ProfitLoss(auth()->user()->company(), $request->all());
$pnl->build();
$csv = $pnl->getCsv();
$headers = array(
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
@ -79,7 +84,7 @@ class ProfitAndLossController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\QuoteItemExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class QuoteItemReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),QuoteItemExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new QuoteItemExport(auth()->user()->company(), $request->all());
@ -76,7 +81,7 @@ class QuoteItemReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\QuoteExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class QuoteReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),QuoteExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new QuoteExport(auth()->user()->company(), $request->all());
@ -76,7 +81,7 @@ class QuoteReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\RecurringInvoiceExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class RecurringInvoiceReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),RecurringInvoiceExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new RecurringInvoiceExport(auth()->user()->company(), $request->all());
@ -76,7 +81,7 @@ class RecurringInvoiceReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\Reports;
use App\Export\CSV\TaskExport;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
@ -62,6 +63,10 @@ class TaskReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(),$request->all(),TaskExport::class,$this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new TaskExport(auth()->user()->company(), $request->all());
@ -76,7 +81,7 @@ class TaskReportController extends BaseController
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}

View File

@ -0,0 +1,64 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Report;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Libraries\MultiDB;
use App\Mail\DownloadReport;
use App\Models\Company;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendToAdmin implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected Company $company;
protected array $request;
protected string $report_class;
protected string $file_name;
/**
* Create a new job instance.
*
*/
public function __construct(Company $company, array $request, $report_class, $file_name)
{
$this->company = $company;
$this->request = $request;
$this->report_class = $report_class;
$this->file_name = $file_name;
}
public function handle()
{
MultiDB::setDb($this->company->db);
$export = new $this->report_class($this->company, $this->request);
$csv = $export->run();
$nmo = new NinjaMailerObject;
$nmo->mailable = new DownloadReport($this->company, $csv, $this->file_name);
$nmo->company = $this->company;
$nmo->settings = $this->company->settings;
$nmo->to_user = $this->company->owner();
NinjaMailerJob::dispatch($nmo);
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Mail;
use App\Models\Company;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
class DownloadReport extends Mailable
{
use Queueable, SerializesModels;
protected Company $company;
protected $csv;
protected string $file_name;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Company $company, $csv, $file_name)
{
$this->company = $company;
$this->csv = $csv;
$this->file_name = $file_name;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
App::setLocale($this->company->getLocale());
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject(ctrans('texts.download_files'))
->text('email.admin.download_report_text')
->attachData($this->csv, $this->file_name, [
'mime' => 'text/csv',
])
->view('email.admin.download_report', [
'logo' => $this->company->present()->logo,
'whitelabel' => $this->company->account->isPaid() ? true : false,
'settings' => $this->company->settings,
'greeting' => $this->company->present()->name(),
]);
}
}

View File

@ -4583,7 +4583,9 @@ $LANG = array(
'alternate_pdf_viewer' => 'Alternate PDF Viewer',
'alternate_pdf_viewer_help' => 'Improve scrolling over the PDF preview [BETA]',
'currency_cayman_island_dollar' => 'Cayman Island Dollar',
'download_report_description' => 'Please see attached file to check your report.'
);
return $LANG;

View File

@ -0,0 +1,7 @@
@component('email.template.admin', ['logo' => $logo, 'settings' => $settings])
<div class="center">
<h1>{{ ctrans('texts.download_files') }}</h1>
<p>{{ ctrans('texts.download_report_description') }}</p>
</div>
@endcomponent

View File

@ -0,0 +1,4 @@
{!! ctrans('texts.download_files') !!}
{!! ctrans('texts.download_report_description') !!}