diff --git a/app/Export/CSV/ClientExport.php b/app/Export/CSV/ClientExport.php index 8894f5f2a351..43f1de6bcc02 100644 --- a/app/Export/CSV/ClientExport.php +++ b/app/Export/CSV/ClientExport.php @@ -109,6 +109,7 @@ class ClientExport extends BaseExport $this->csv->insertOne($this->buildHeader()); $query = Client::query()->with('contacts') + ->withTrashed() ->where('company_id', $this->company->id) ->where('is_deleted',0); diff --git a/app/Export/CSV/CreditExport.php b/app/Export/CSV/CreditExport.php index 4391f9f55a43..5cb151f9d8de 100644 --- a/app/Export/CSV/CreditExport.php +++ b/app/Export/CSV/CreditExport.php @@ -98,6 +98,7 @@ class CreditExport extends BaseExport $this->csv->insertOne($this->buildHeader()); $query = Credit::query() + ->withTrashed() ->with('client')->where('company_id', $this->company->id) ->where('is_deleted',0); diff --git a/app/Export/CSV/ExpenseExport.php b/app/Export/CSV/ExpenseExport.php index c4e0eb1afbdf..863a0d3a130f 100644 --- a/app/Export/CSV/ExpenseExport.php +++ b/app/Export/CSV/ExpenseExport.php @@ -97,6 +97,7 @@ class ExpenseExport extends BaseExport $query = Expense::query() ->with('client') + ->withTrashed() ->where('company_id', $this->company->id) ->where('is_deleted',0); diff --git a/app/Export/CSV/InvoiceExport.php b/app/Export/CSV/InvoiceExport.php index 44ff9e4039a4..c3f745a88fca 100644 --- a/app/Export/CSV/InvoiceExport.php +++ b/app/Export/CSV/InvoiceExport.php @@ -20,14 +20,16 @@ use App\Utils\Ninja; use Illuminate\Support\Facades\App; use League\Csv\Writer; -class InvoiceExport +class InvoiceExport extends BaseExport { - private $company; + private Company $company; - private $report_keys; + protected array $input; private $invoice_transformer; + protected string $date_key = 'date'; + private array $entity_keys = [ 'amount' => 'amount', 'balance' => 'balance', @@ -71,10 +73,10 @@ class InvoiceExport 'status', ]; - 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->invoice_transformer = new InvoiceTransformer(); } @@ -93,15 +95,19 @@ class InvoiceExport //insert the header $this->csv->insertOne($this->buildHeader()); - Invoice::with('client')->where('company_id', $this->company->id) - ->where('is_deleted',0) - ->cursor() - ->each(function ($invoice){ + $query = Invoice::query() + ->withTrashed() + ->with('client')->where('company_id', $this->company->id) + ->where('is_deleted',0); - $this->csv->insertOne($this->buildRow($invoice)); + $query = $this->addDateRange($query); - }); + $query->cursor() + ->each(function ($invoice){ + $this->csv->insertOne($this->buildRow($invoice)); + + }); return $this->csv->toString(); @@ -112,7 +118,7 @@ class InvoiceExport $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 InvoiceExport $entity = []; - foreach(array_values($this->report_keys) as $key){ + foreach(array_values($this->input['report_keys']) as $key){ $entity[$key] = $transformed_invoice[$key]; } diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index 28b680f49a8f..6028d5359647 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -20,14 +20,16 @@ use App\Utils\Ninja; use Illuminate\Support\Facades\App; use League\Csv\Writer; -class InvoiceItemExport +class InvoiceItemExport extends BaseExport { - private $company; + private Company $company; - private $report_keys; + protected array $input; private $invoice_transformer; + protected string $date_key = 'date'; + private array $entity_keys = [ 'amount' => 'amount', 'balance' => 'balance', @@ -88,10 +90,10 @@ class InvoiceItemExport 'currency', ]; - 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->invoice_transformer = new InvoiceTransformer(); } @@ -110,14 +112,18 @@ class InvoiceItemExport //insert the header $this->csv->insertOne($this->buildHeader()); - Invoice::with('client')->where('company_id', $this->company->id) - ->where('is_deleted',0) - ->cursor() - ->each(function ($invoice){ + $query = Invoice::query() + ->with('client')->where('company_id', $this->company->id) + ->where('is_deleted',0); - $this->iterateItems($invoice); + $query = $this->addDateRange($query); - }); + $query->cursor() + ->each(function ($invoice){ + + $this->iterateItems($invoice); + + }); return $this->csv->toString(); @@ -128,7 +134,7 @@ class InvoiceItemExport $header = []; - foreach(array_keys($this->report_keys) as $key) + foreach(array_keys($this->input['report_keys']) as $key) $header[] = ctrans("texts.{$key}"); return $header; @@ -144,7 +150,7 @@ class InvoiceItemExport { $item_array = []; - foreach(array_values($this->report_keys) as $key){ + foreach(array_values($this->input['report_keys']) as $key){ if(str_contains($key, "item.")){ @@ -160,7 +166,7 @@ class InvoiceItemExport $transformed_items = $this->decorateAdvancedFields($invoice, $transformed_items); - foreach(array_values($this->report_keys) as $key) + foreach(array_values($this->input['report_keys']) as $key) { $key = str_replace("item.", "", $key); $entity[$key] = $transformed_items[$key]; @@ -179,7 +185,7 @@ class InvoiceItemExport $entity = []; - foreach(array_values($this->report_keys) as $key){ + foreach(array_values($this->input['report_keys']) as $key){ if(!str_contains($key, "item.")) $entity[$key] = $transformed_invoice[$key]; diff --git a/app/Http/Controllers/Reports/CreditReportController.php b/app/Http/Controllers/Reports/CreditReportController.php index 3ebe56d3927e..cc6fdd36e2ed 100644 --- a/app/Http/Controllers/Reports/CreditReportController.php +++ b/app/Http/Controllers/Reports/CreditReportController.php @@ -13,7 +13,7 @@ namespace App\Http\Controllers\Reports; use App\Export\CSV\CreditExport; use App\Http\Controllers\BaseController; -use App\Http\Requests\Report\ClientContactReportRequest; +use App\Http\Requests\Report\GenericReportRequest; use App\Utils\Traits\MakesHash; use Illuminate\Http\Response; @@ -60,7 +60,7 @@ class CreditReportController extends BaseController * ), * ) */ - public function __invoke(ClientContactReportRequest $request) + public function __invoke(GenericReportRequest $request) { // expect a list of visible fields, or use the default diff --git a/app/Http/Controllers/Reports/InvoiceItemReportController.php b/app/Http/Controllers/Reports/InvoiceItemReportController.php new file mode 100644 index 000000000000..f6191b1a739e --- /dev/null +++ b/app/Http/Controllers/Reports/InvoiceItemReportController.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/app/Http/Controllers/Reports/InvoiceReportController.php b/app/Http/Controllers/Reports/InvoiceReportController.php new file mode 100644 index 000000000000..b493bd3609a7 --- /dev/null +++ b/app/Http/Controllers/Reports/InvoiceReportController.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 41df2c8996c6..e95d9eb1660d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -159,6 +159,8 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale Route::post('reports/credits', 'Reports\CreditReportController'); Route::post('reports/documents', 'Reports\DocumentReportController'); Route::post('reports/expenses', 'Reports\ExpenseReportController'); + Route::post('reports/invoices', 'Reports\InvoiceReportController'); + Route::post('reports/invoice_items', 'Reports\InvoiceItemReportController'); Route::get('scheduler', 'SchedulerController@index');