diff --git a/app/Export/CSV/QuoteExport.php b/app/Export/CSV/QuoteExport.php index 8c4cca0a4821..71a179b6a993 100644 --- a/app/Export/CSV/QuoteExport.php +++ b/app/Export/CSV/QuoteExport.php @@ -20,14 +20,16 @@ use App\Utils\Ninja; use Illuminate\Support\Facades\App; use League\Csv\Writer; -class QuoteExport +class QuoteExport extends BaseExport { - private $company; + private Company $company; - private $report_keys; + protected array $input; private $quote_transformer; + protected string $date_key = 'date'; + private array $entity_keys = [ 'amount' => 'amount', 'balance' => 'balance', @@ -71,10 +73,10 @@ class QuoteExport 'invoice' ]; - public function __construct(Company $company, array $report_keys) + public function __construct(Company $company, array $input) { $this->company = $company; - $this->report_keys = $report_keys; + $this->input = $input; $this->quote_transformer = new QuoteTransformer(); } @@ -93,14 +95,18 @@ class QuoteExport //insert the header $this->csv->insertOne($this->buildHeader()); - Quote::with('client')->where('company_id', $this->company->id) - ->where('is_deleted',0) - ->cursor() - ->each(function ($quote){ + $query = Quote::query() + ->with('client')->where('company_id', $this->company->id) + ->where('is_deleted',0); - $this->csv->insertOne($this->buildRow($quote)); + $query = $this->addDateRange($query); - }); + $query->cursor() + ->each(function ($quote){ + + $this->csv->insertOne($this->buildRow($quote)); + + }); return $this->csv->toString(); @@ -112,7 +118,7 @@ class QuoteExport $header = []; - foreach(array_keys($this->report_keys) as $key) + foreach(array_keys($this->input['report_keys']) as $key) $header[] = ctrans("texts.{$key}"); return $header; @@ -125,7 +131,7 @@ class QuoteExport $entity = []; - foreach(array_values($this->report_keys) as $key){ + foreach(array_values($this->input['report_keys']) as $key){ $entity[$key] = $transformed_quote[$key]; } diff --git a/app/Http/Controllers/Reports/InvoiceItemReportController.php b/app/Http/Controllers/Reports/InvoiceItemReportController.php index f6191b1a739e..2bba0e0694ff 100644 --- a/app/Http/Controllers/Reports/InvoiceItemReportController.php +++ b/app/Http/Controllers/Reports/InvoiceItemReportController.php @@ -30,11 +30,11 @@ class InvoiceItemReportController extends BaseController /** * @OA\Post( - * path="/api/v1/reports/invoices", - * operationId="getInvoiceReport", + * path="/api/v1/reports/invoice_items", + * operationId="getInvoiceItemReport", * tags={"reports"}, - * summary="Invoice reports", - * description="Export invoice reports", + * summary="Invoice item reports", + * description="Export invoice item reports", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), * @OA\RequestBody( diff --git a/app/Http/Controllers/Reports/QuoteReportController.php b/app/Http/Controllers/Reports/QuoteReportController.php new file mode 100644 index 000000000000..0d57f71fd449 --- /dev/null +++ b/app/Http/Controllers/Reports/QuoteReportController.php @@ -0,0 +1,84 @@ +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); + + } + + + +} diff --git a/routes/api.php b/routes/api.php index e95d9eb1660d..9d5f2f392f07 100644 --- a/routes/api.php +++ b/routes/api.php @@ -161,6 +161,7 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale Route::post('reports/expenses', 'Reports\ExpenseReportController'); Route::post('reports/invoices', 'Reports\InvoiceReportController'); Route::post('reports/invoice_items', 'Reports\InvoiceItemReportController'); + Route::post('reports/quotes', 'Reports\QuoteReportController'); Route::get('scheduler', 'SchedulerController@index');