mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Working on report previews
This commit is contained in:
parent
3650d2527f
commit
7128bd434b
@ -13,6 +13,7 @@ namespace App\Export\CSV;
|
||||
|
||||
use App\Utils\Number;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Utils\Helpers;
|
||||
use App\Models\Company;
|
||||
use App\Models\Expense;
|
||||
@ -1028,4 +1029,35 @@ class BaseExport
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
public function processMetaData(array $row, $resource): array
|
||||
{
|
||||
$class = get_class($resource);
|
||||
|
||||
match ($class) {
|
||||
Invoice::class => $entity = 'invoice',
|
||||
Expense::class => $entity = 'expense',
|
||||
ClientContact::class => $entity = 'contact',
|
||||
default => $entity = 'invoice',
|
||||
};
|
||||
|
||||
$clean_row = [];
|
||||
|
||||
foreach (array_values($this->input['report_keys']) as $key => $value) {
|
||||
|
||||
$report_keys = explode(".", $value);
|
||||
|
||||
$column_key = $value;
|
||||
$clean_row[$key]['entity'] = $report_keys[0];
|
||||
$clean_row[$key]['id'] = $report_keys[1] ?? $report_keys[0];
|
||||
$clean_row[$key]['hashed_id'] = $report_keys[0] == $entity ? null : $resource->{$report_keys[0]}->hashed_id ?? null;
|
||||
$clean_row[$key]['value'] = $row[$column_key];
|
||||
$clean_row[$key]['identifier'] = $value;
|
||||
$clean_row[$key]['display_value'] = $row[$column_key];
|
||||
|
||||
}
|
||||
|
||||
return $clean_row;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,15 +11,16 @@
|
||||
|
||||
namespace App\Export\CSV;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Transformers\ClientContactTransformer;
|
||||
use App\Transformers\ClientTransformer;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use App\Utils\Number;
|
||||
use App\Models\Client;
|
||||
use League\Csv\Writer;
|
||||
use App\Models\Company;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use App\Transformers\ClientTransformer;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Transformers\ClientContactTransformer;
|
||||
|
||||
class ClientExport extends BaseExport
|
||||
{
|
||||
@ -93,7 +94,8 @@ class ClientExport extends BaseExport
|
||||
|
||||
$report = $query->cursor()
|
||||
->map(function ($client) {
|
||||
return $this->buildRow($client);
|
||||
$row = $this->buildRow($client);
|
||||
return $this->processMetaData($row, $client);
|
||||
})->toArray();
|
||||
|
||||
return array_merge(['columns' => $header], $report);
|
||||
@ -171,6 +173,30 @@ class ClientExport extends BaseExport
|
||||
return $this->decorateAdvancedFields($client, $entity);
|
||||
}
|
||||
|
||||
public function processMetaData(array $row, $resource): array
|
||||
{
|
||||
$clean_row = [];
|
||||
foreach (array_values($this->input['report_keys']) as $key => $value) {
|
||||
|
||||
$report_keys = explode(".", $value);
|
||||
|
||||
$column_key = $value;
|
||||
$clean_row[$key]['entity'] = $report_keys[0];
|
||||
$clean_row[$key]['id'] = $report_keys[1] ?? $report_keys[0];
|
||||
$clean_row[$key]['hashed_id'] = $report_keys[0] == 'client' ? null : $resource->{$report_keys[0]}->hashed_id ?? null;
|
||||
$clean_row[$key]['value'] = $row[$column_key];
|
||||
$clean_row[$key]['identifier'] = $value;
|
||||
|
||||
if(in_array($clean_row[$key]['id'], ['paid_to_date', 'balance', 'credit_balance','payment_balance']))
|
||||
$clean_row[$key]['display_value'] = Number::formatMoney($row[$column_key], $resource);
|
||||
else
|
||||
$clean_row[$key]['display_value'] = $row[$column_key];
|
||||
|
||||
}
|
||||
|
||||
return $clean_row;
|
||||
}
|
||||
|
||||
private function decorateAdvancedFields(Client $client, array $entity) :array
|
||||
{
|
||||
if (in_array('client.user', $this->input['report_keys'])) {
|
||||
|
@ -94,7 +94,8 @@ class ContactExport extends BaseExport
|
||||
|
||||
$report = $query->cursor()
|
||||
->map(function ($contact) {
|
||||
return $this->buildRow($contact);
|
||||
$row = $this->buildRow($contact);
|
||||
return $this->processMetaData($row, $contact);
|
||||
})->toArray();
|
||||
|
||||
return array_merge(['columns' => $header], $report);
|
||||
|
@ -56,7 +56,7 @@ class CreditExport extends BaseExport
|
||||
return array_merge(['columns' => $header], $report);
|
||||
}
|
||||
|
||||
private function processMetaData(array $row, Credit $credit): array
|
||||
public function processMetaData(array $row, $resource): array
|
||||
{
|
||||
$clean_row = [];
|
||||
foreach (array_values($this->input['report_keys']) as $key => $value) {
|
||||
|
@ -56,11 +56,33 @@ class DocumentExport extends BaseExport
|
||||
$report = $query->cursor()
|
||||
->map(function ($document) {
|
||||
$row = $this->buildRow($document);
|
||||
return $this->processMetaData($row, $document);
|
||||
})->toArray();
|
||||
|
||||
return array_merge(['columns' => $header], $report);
|
||||
}
|
||||
|
||||
private function processMetaData(array $row, Document $document): array
|
||||
{
|
||||
$clean_row = [];
|
||||
foreach (array_values($this->input['report_keys']) as $key => $value) {
|
||||
|
||||
$report_keys = explode(".", $value);
|
||||
|
||||
$column_key = $value;
|
||||
$clean_row[$key]['entity'] = $report_keys[0];
|
||||
$clean_row[$key]['id'] = $report_keys[1] ?? $report_keys[0];
|
||||
$clean_row[$key]['hashed_id'] = $report_keys[0] == 'document' ? null : $document->{$report_keys[0]}->hashed_id ?? null;
|
||||
$clean_row[$key]['value'] = $row[$column_key];
|
||||
$clean_row[$key]['identifier'] = $value;
|
||||
|
||||
$clean_row[$key]['display_value'] = $row[$column_key];
|
||||
|
||||
}
|
||||
|
||||
return $clean_row;
|
||||
}
|
||||
|
||||
private function init(): Builder
|
||||
{
|
||||
|
||||
|
@ -49,7 +49,8 @@ class ExpenseExport extends BaseExport
|
||||
|
||||
$report = $query->cursor()
|
||||
->map(function ($resource) {
|
||||
return $this->buildRow($resource);
|
||||
$row = $this->buildRow($resource);
|
||||
return $this->processMetaData($row, $resource);
|
||||
})->toArray();
|
||||
|
||||
return array_merge(['columns' => $header], $report);
|
||||
|
@ -78,7 +78,8 @@ class InvoiceExport extends BaseExport
|
||||
|
||||
$report = $query->cursor()
|
||||
->map(function ($resource) {
|
||||
return $this->buildRow($resource);
|
||||
$row = $this->buildRow($resource);
|
||||
return $this->processMetaData($row, $resource);
|
||||
})->toArray();
|
||||
|
||||
return array_merge(['columns' => $header], $report);
|
||||
|
@ -188,13 +188,6 @@ class InvoiceItemExport extends BaseExport
|
||||
$entity['tax_category'] = $invoice->taxTypeString($entity['tax_category']);
|
||||
}
|
||||
|
||||
// if($this->force_keys) {
|
||||
// $entity['client'] = $invoice->client->present()->name();
|
||||
// $entity['client_id_number'] = $invoice->client->id_number;
|
||||
// $entity['client_number'] = $invoice->client->number;
|
||||
// $entity['status'] = $invoice->stringStatus($invoice->status_id);
|
||||
// }
|
||||
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,13 @@
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Jobs\Report\SendToAdmin;
|
||||
use App\Export\CSV\DocumentExport;
|
||||
use App\Jobs\Report\PreviewReport;
|
||||
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;
|
||||
|
||||
class DocumentReportController extends BaseController
|
||||
{
|
||||
@ -62,14 +63,27 @@ class DocumentReportController extends BaseController
|
||||
*/
|
||||
public function __invoke(GenericReportRequest $request)
|
||||
{
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
if ($request->has('send_email') && $request->get('send_email')) {
|
||||
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), DocumentExport::class, $this->filename);
|
||||
SendToAdmin::dispatch($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());
|
||||
if($request->has('output') && $request->input('output') == 'json') {
|
||||
|
||||
$hash = \Illuminate\Support\Str::uuid();
|
||||
|
||||
PreviewReport::dispatch($user->company(), $request->all(), DocumentExport::class, $hash);
|
||||
|
||||
return response()->json(['message' => $hash], 200);
|
||||
}
|
||||
|
||||
$export = new DocumentExport($user->company(), $request->all());
|
||||
|
||||
$csv = $export->run();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user