mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 05:14:36 -04:00
Expose export csv routes
This commit is contained in:
parent
01ecc22d5f
commit
ad3516aa26
@ -20,13 +20,15 @@ use App\Utils\Ninja;
|
|||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
|
|
||||||
class CreditExport
|
class CreditExport extends BaseExport
|
||||||
{
|
{
|
||||||
private $company;
|
private Company $company;
|
||||||
|
|
||||||
private $report_keys;
|
protected array $input;
|
||||||
|
|
||||||
private $credit_transformer;
|
private CreditTransformer $credit_transformer;
|
||||||
|
|
||||||
|
protected string $date_key = 'created_at';
|
||||||
|
|
||||||
private array $entity_keys = [
|
private array $entity_keys = [
|
||||||
'amount' => 'amount',
|
'amount' => 'amount',
|
||||||
@ -73,10 +75,10 @@ class CreditExport
|
|||||||
'currency',
|
'currency',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(Company $company, array $report_keys)
|
public function __construct(Company $company, array $input)
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
$this->report_keys = $report_keys;
|
$this->input = $input;
|
||||||
$this->credit_transformer = new CreditTransformer();
|
$this->credit_transformer = new CreditTransformer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,15 +97,18 @@ class CreditExport
|
|||||||
//insert the header
|
//insert the header
|
||||||
$this->csv->insertOne($this->buildHeader());
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
Credit::with('client')->where('company_id', $this->company->id)
|
$query = Credit::query()
|
||||||
->where('is_deleted',0)
|
->with('client')->where('company_id', $this->company->id)
|
||||||
->cursor()
|
->where('is_deleted',0);
|
||||||
->each(function ($credit){
|
|
||||||
|
|
||||||
$this->csv->insertOne($this->buildRow($credit));
|
$query = $this->addDateRange($query);
|
||||||
|
|
||||||
});
|
$query->cursor()
|
||||||
|
->each(function ($credit){
|
||||||
|
|
||||||
|
$this->csv->insertOne($this->buildRow($credit));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
return $this->csv->toString();
|
return $this->csv->toString();
|
||||||
|
|
||||||
@ -114,7 +119,7 @@ class CreditExport
|
|||||||
|
|
||||||
$header = [];
|
$header = [];
|
||||||
|
|
||||||
foreach(array_keys($this->report_keys) as $key)
|
foreach(array_keys($this->input['report_keys']) as $key)
|
||||||
$header[] = ctrans("texts.{$key}");
|
$header[] = ctrans("texts.{$key}");
|
||||||
|
|
||||||
return $header;
|
return $header;
|
||||||
@ -127,7 +132,7 @@ class CreditExport
|
|||||||
|
|
||||||
$entity = [];
|
$entity = [];
|
||||||
|
|
||||||
foreach(array_values($this->report_keys) as $key){
|
foreach(array_values($this->input['report_keys']) as $key){
|
||||||
|
|
||||||
$entity[$key] = $transformed_credit[$key];
|
$entity[$key] = $transformed_credit[$key];
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,16 @@ use App\Utils\Ninja;
|
|||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
|
|
||||||
class DocumentExport
|
class DocumentExport extends BaseExport
|
||||||
{
|
{
|
||||||
private $company;
|
private Company $company;
|
||||||
|
|
||||||
private $report_keys;
|
protected array $input;
|
||||||
|
|
||||||
private $entity_transformer;
|
private $entity_transformer;
|
||||||
|
|
||||||
|
protected $date_key = 'created_at';
|
||||||
|
|
||||||
private array $entity_keys = [
|
private array $entity_keys = [
|
||||||
'record_type' => 'record_type',
|
'record_type' => 'record_type',
|
||||||
'record_name' => 'record_name',
|
'record_name' => 'record_name',
|
||||||
@ -41,10 +43,10 @@ class DocumentExport
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(Company $company, array $report_keys)
|
public function __construct(Company $company, array $input)
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
$this->report_keys = $report_keys;
|
$this->input = $input;
|
||||||
$this->entity_transformer = new DocumentTransformer();
|
$this->entity_transformer = new DocumentTransformer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,14 +65,16 @@ class DocumentExport
|
|||||||
//insert the header
|
//insert the header
|
||||||
$this->csv->insertOne($this->buildHeader());
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
Document::where('company_id', $this->company->id)
|
$query = Document::query()->where('company_id', $this->company->id);
|
||||||
->cursor()
|
|
||||||
->each(function ($entity){
|
|
||||||
|
|
||||||
$this->csv->insertOne($this->buildRow($entity));
|
$query = $this->addDateRange($query);
|
||||||
|
|
||||||
});
|
$query->cursor()
|
||||||
|
->each(function ($entity){
|
||||||
|
|
||||||
|
$this->csv->insertOne($this->buildRow($entity));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
return $this->csv->toString();
|
return $this->csv->toString();
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ class DocumentExport
|
|||||||
|
|
||||||
$header = [];
|
$header = [];
|
||||||
|
|
||||||
foreach(array_keys($this->report_keys) as $key)
|
foreach(array_keys($this->input['report_keys']) as $key)
|
||||||
$header[] = ctrans("texts.{$key}");
|
$header[] = ctrans("texts.{$key}");
|
||||||
|
|
||||||
return $header;
|
return $header;
|
||||||
@ -94,7 +98,7 @@ class DocumentExport
|
|||||||
|
|
||||||
$entity = [];
|
$entity = [];
|
||||||
|
|
||||||
foreach(array_values($this->report_keys) as $key){
|
foreach(array_values($this->input['report_keys']) as $key){
|
||||||
|
|
||||||
$entity[$key] = $transformed_entity[$key];
|
$entity[$key] = $transformed_entity[$key];
|
||||||
|
|
||||||
|
@ -20,14 +20,16 @@ use App\Utils\Ninja;
|
|||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
|
|
||||||
class ExpenseExport
|
class ExpenseExport extends BaseExport
|
||||||
{
|
{
|
||||||
private $company;
|
private Company $company;
|
||||||
|
|
||||||
private $report_keys;
|
protected array $input;
|
||||||
|
|
||||||
private $expense_transformer;
|
private $expense_transformer;
|
||||||
|
|
||||||
|
protected $date_key = 'date';
|
||||||
|
|
||||||
private array $entity_keys = [
|
private array $entity_keys = [
|
||||||
'amount' => 'amount',
|
'amount' => 'amount',
|
||||||
'category' => 'category_id',
|
'category' => 'category_id',
|
||||||
@ -71,10 +73,10 @@ class ExpenseExport
|
|||||||
'payment_type_id',
|
'payment_type_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(Company $company, array $report_keys)
|
public function __construct(Company $company, array $input)
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
$this->report_keys = $report_keys;
|
$this->input = $input;
|
||||||
$this->expense_transformer = new ExpenseTransformer();
|
$this->expense_transformer = new ExpenseTransformer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,14 +95,19 @@ class ExpenseExport
|
|||||||
//insert the header
|
//insert the header
|
||||||
$this->csv->insertOne($this->buildHeader());
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
Expense::with('client')->where('company_id', $this->company->id)
|
$query = Expense::query()
|
||||||
->where('is_deleted',0)
|
->with('client')
|
||||||
->cursor()
|
->where('company_id', $this->company->id)
|
||||||
->each(function ($expense){
|
->where('is_deleted',0);
|
||||||
|
|
||||||
$this->csv->insertOne($this->buildRow($expense));
|
$query = $this->addDateRange($query);
|
||||||
|
|
||||||
});
|
$query->cursor()
|
||||||
|
->each(function ($expense){
|
||||||
|
|
||||||
|
$this->csv->insertOne($this->buildRow($expense));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return $this->csv->toString();
|
return $this->csv->toString();
|
||||||
@ -112,7 +119,7 @@ class ExpenseExport
|
|||||||
|
|
||||||
$header = [];
|
$header = [];
|
||||||
|
|
||||||
foreach(array_keys($this->report_keys) as $key)
|
foreach(array_keys($this->input['report_keys']) as $key)
|
||||||
$header[] = ctrans("texts.{$key}");
|
$header[] = ctrans("texts.{$key}");
|
||||||
|
|
||||||
return $header;
|
return $header;
|
||||||
@ -125,7 +132,7 @@ class ExpenseExport
|
|||||||
|
|
||||||
$entity = [];
|
$entity = [];
|
||||||
|
|
||||||
foreach(array_values($this->report_keys) as $key){
|
foreach(array_values($this->input['report_keys']) as $key){
|
||||||
|
|
||||||
$entity[$key] = $transformed_expense[$key];
|
$entity[$key] = $transformed_expense[$key];
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @OA\Schema(
|
* @OA\Schema(
|
||||||
* schema="ClientReportSchema",
|
* schema="GenericReportSchema",
|
||||||
* type="object",
|
* type="object",
|
||||||
* @OA\Property(property="date_range", type="string", example="last7", description="The string representation of the date range of data to be returned"),
|
* @OA\Property(property="date_range", type="string", example="last7", description="The string representation of the date range of data to be returned"),
|
||||||
* @OA\Property(property="date_key", type="string", example="created_at", description="The date column to search between."),
|
* @OA\Property(property="date_key", type="string", example="created_at", description="The date column to search between."),
|
@ -13,7 +13,7 @@ namespace App\Http\Controllers\Reports;
|
|||||||
|
|
||||||
use App\Export\CSV\ContactExport;
|
use App\Export\CSV\ContactExport;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Requests\Report\ClientContactReportRequest;
|
use App\Http\Requests\Report\GenericReportSchema;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
@ -30,16 +30,16 @@ class ClientContactReportController extends BaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @OA\Post(
|
* @OA\Post(
|
||||||
* path="/api/v1/reports/clients",
|
* path="/api/v1/reports/contacts",
|
||||||
* operationId="getClientReport",
|
* operationId="getContactReport",
|
||||||
* tags={"reports"},
|
* tags={"reports"},
|
||||||
* summary="Client reports",
|
* summary="Contact reports",
|
||||||
* description="Export client reports",
|
* description="Export contact reports",
|
||||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
* @OA\RequestBody(
|
* @OA\RequestBody(
|
||||||
* required=true,
|
* required=true,
|
||||||
* @OA\JsonContent(ref="#/components/schemas/ClientReportSchema")
|
* @OA\JsonContent(ref="#/components/schemas/GenericReportSchema")
|
||||||
* ),
|
* ),
|
||||||
* @OA\Response(
|
* @OA\Response(
|
||||||
* response=200,
|
* response=200,
|
||||||
@ -60,7 +60,7 @@ class ClientContactReportController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function __invoke(ClientContactReportRequest $request)
|
public function __invoke(GenericReportSchema $request)
|
||||||
{
|
{
|
||||||
// expect a list of visible fields, or use the default
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ namespace App\Http\Controllers\Reports;
|
|||||||
|
|
||||||
use App\Export\CSV\ClientExport;
|
use App\Export\CSV\ClientExport;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Requests\Report\ClientReportRequest;
|
use App\Http\Requests\Report\GenericReportRequest;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
@ -22,6 +22,8 @@ class ClientReportController extends BaseController
|
|||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
|
||||||
|
private string $filename = 'clients.csv';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -59,7 +61,7 @@ class ClientReportController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function __invoke(ClientReportRequest $request)
|
public function __invoke(GenericReportRequest $request)
|
||||||
{
|
{
|
||||||
// expect a list of visible fields, or use the default
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ class ClientReportController extends BaseController
|
|||||||
|
|
||||||
return response()->streamDownload(function () use ($csv) {
|
return response()->streamDownload(function () use ($csv) {
|
||||||
echo $csv;
|
echo $csv;
|
||||||
}, 'clients.csv', $headers);
|
}, $this->filename, $headers);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
84
app/Http/Controllers/Reports/CreditReportController.php
Normal file
84
app/Http/Controllers/Reports/CreditReportController.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?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\Http\Controllers\Reports;
|
||||||
|
|
||||||
|
use App\Export\CSV\CreditExport;
|
||||||
|
use App\Http\Controllers\BaseController;
|
||||||
|
use App\Http\Requests\Report\ClientContactReportRequest;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class CreditReportController extends BaseController
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
private string $filename = 'credits.csv';
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/v1/reports/clients",
|
||||||
|
* operationId="getClientReport",
|
||||||
|
* tags={"reports"},
|
||||||
|
* summary="Client reports",
|
||||||
|
* description="Export client reports",
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
|
* @OA\RequestBody(
|
||||||
|
* required=true,
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/GenericReportSchema")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="success",
|
||||||
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=422,
|
||||||
|
* description="Validation error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="default",
|
||||||
|
* description="Unexpected Error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function __invoke(ClientContactReportRequest $request)
|
||||||
|
{
|
||||||
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
|
$export = new CreditExport(auth()->user()->company(), $request->all());
|
||||||
|
|
||||||
|
$csv = $export->run();
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
'Content-Disposition' => 'attachment',
|
||||||
|
'Content-Type' => 'text/csv',
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->streamDownload(function () use ($csv) {
|
||||||
|
echo $csv;
|
||||||
|
}, $this->filename, $headers);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
84
app/Http/Controllers/Reports/DocumentReportController.php
Normal file
84
app/Http/Controllers/Reports/DocumentReportController.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?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\Http\Controllers\Reports;
|
||||||
|
|
||||||
|
use App\Export\CSV\DocumentExport;
|
||||||
|
use App\Http\Controllers\BaseController;
|
||||||
|
use App\Http\Requests\Report\ClientContactReportRequest;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class DocumentReportController extends BaseController
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
private string $filename = 'documents.csv';
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/v1/reports/documents",
|
||||||
|
* operationId="getDocumentReport",
|
||||||
|
* tags={"reports"},
|
||||||
|
* summary="Document reports",
|
||||||
|
* description="Export document reports",
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
|
* @OA\RequestBody(
|
||||||
|
* required=true,
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/GenericReportSchema")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="success",
|
||||||
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=422,
|
||||||
|
* description="Validation error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="default",
|
||||||
|
* description="Unexpected Error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function __invoke(ClientContactReportRequest $request)
|
||||||
|
{
|
||||||
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
|
$export = new DocumentExport(auth()->user()->company(), $request->all());
|
||||||
|
|
||||||
|
$csv = $export->run();
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
'Content-Disposition' => 'attachment',
|
||||||
|
'Content-Type' => 'text/csv',
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->streamDownload(function () use ($csv) {
|
||||||
|
echo $csv;
|
||||||
|
}, $this->filename, $headers);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
85
app/Http/Controllers/Reports/ExpenseReportController.php
Normal file
85
app/Http/Controllers/Reports/ExpenseReportController.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?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\Http\Controllers\Reports;
|
||||||
|
|
||||||
|
use App\Export\CSV\ExpenseExport;
|
||||||
|
use App\Http\Controllers\BaseController;
|
||||||
|
use App\Http\Requests\Report\GenericReportRequest;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class ExpenseReportController extends BaseController
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
private string $filename = 'expense.csv';
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/v1/reports/expense",
|
||||||
|
* operationId="getExpenseReport",
|
||||||
|
* tags={"reports"},
|
||||||
|
* summary="Expense reports",
|
||||||
|
* description="Export expense reports",
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
|
* @OA\RequestBody(
|
||||||
|
* required=true,
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/GenericReportSchema")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="success",
|
||||||
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=422,
|
||||||
|
* description="Validation error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="default",
|
||||||
|
* description="Unexpected Error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function __invoke(GenericReportRequest $request)
|
||||||
|
{
|
||||||
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
|
$export = new ExpenseExport(auth()->user()->company(), $request->all());
|
||||||
|
|
||||||
|
$csv = $export->run();
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
'Content-Disposition' => 'attachment',
|
||||||
|
'Content-Type' => 'text/csv',
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->streamDownload(function () use ($csv) {
|
||||||
|
echo $csv;
|
||||||
|
}, $this->filename, $headers);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,38 +0,0 @@
|
|||||||
<?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\Http\Requests\Report;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
|
|
||||||
class ClientContactReportRequest extends Request
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize() : bool
|
|
||||||
{
|
|
||||||
return auth()->user()->isAdmin();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'start_date' => 'string|date',
|
|
||||||
'end_date' => 'string|date',
|
|
||||||
'date_key' => 'string',
|
|
||||||
'date_range' => 'string',
|
|
||||||
'report_keys' => 'sometimes|array'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,7 +13,7 @@ namespace App\Http\Requests\Report;
|
|||||||
|
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
|
|
||||||
class ClientReportRequest extends Request
|
class GenericReportRequest extends Request
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
@ -156,6 +156,9 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale
|
|||||||
|
|
||||||
Route::post('reports/clients', 'Reports\ClientReportController');
|
Route::post('reports/clients', 'Reports\ClientReportController');
|
||||||
Route::post('reports/contacts', 'Reports\ClientContactReportController');
|
Route::post('reports/contacts', 'Reports\ClientContactReportController');
|
||||||
|
Route::post('reports/credits', 'Reports\CreditReportController');
|
||||||
|
Route::post('reports/documents', 'Reports\DocumentReportController');
|
||||||
|
Route::post('reports/expenses', 'Reports\ExpenseReportController');
|
||||||
|
|
||||||
|
|
||||||
Route::get('scheduler', 'SchedulerController@index');
|
Route::get('scheduler', 'SchedulerController@index');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user