mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-05 04:34:36 -04:00
Finalize Report previews
This commit is contained in:
parent
514bd47da9
commit
154ddbe95d
@ -290,6 +290,7 @@ class BaseExport
|
|||||||
"private_notes" => "quote.private_notes",
|
"private_notes" => "quote.private_notes",
|
||||||
"uses_inclusive_taxes" => "quote.uses_inclusive_taxes",
|
"uses_inclusive_taxes" => "quote.uses_inclusive_taxes",
|
||||||
"is_amount_discount" => "quote.is_amount_discount",
|
"is_amount_discount" => "quote.is_amount_discount",
|
||||||
|
"discount" => "quote.discount",
|
||||||
"partial" => "quote.partial",
|
"partial" => "quote.partial",
|
||||||
"partial_due_date" => "quote.partial_due_date",
|
"partial_due_date" => "quote.partial_due_date",
|
||||||
"surcharge1" => "quote.custom_surcharge1",
|
"surcharge1" => "quote.custom_surcharge1",
|
||||||
|
@ -11,14 +11,15 @@
|
|||||||
|
|
||||||
namespace App\Export\CSV;
|
namespace App\Export\CSV;
|
||||||
|
|
||||||
use App\Libraries\MultiDB;
|
|
||||||
use App\Models\Company;
|
|
||||||
use App\Models\PurchaseOrder;
|
|
||||||
use App\Transformers\PurchaseOrderTransformer;
|
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Number;
|
use App\Utils\Number;
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\PurchaseOrder;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use App\Transformers\PurchaseOrderTransformer;
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||||
|
|
||||||
class PurchaseOrderExport extends BaseExport
|
class PurchaseOrderExport extends BaseExport
|
||||||
{
|
{
|
||||||
@ -81,24 +82,19 @@ class PurchaseOrderExport extends BaseExport
|
|||||||
$this->purchase_order_transformer = new PurchaseOrderTransformer();
|
$this->purchase_order_transformer = new PurchaseOrderTransformer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
|
||||||
|
public function init(): Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
App::setLocale($this->company->locale());
|
App::setLocale($this->company->locale());
|
||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||||
|
|
||||||
//load the CSV document from a string
|
|
||||||
$this->csv = Writer::createFromString();
|
|
||||||
|
|
||||||
if (count($this->input['report_keys']) == 0) {
|
if (count($this->input['report_keys']) == 0) {
|
||||||
$this->input['report_keys'] = array_values($this->entity_keys);
|
$this->input['report_keys'] = array_values($this->purchase_order_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
//insert the header
|
|
||||||
$this->csv->insertOne($this->buildHeader());
|
|
||||||
|
|
||||||
$query = PurchaseOrder::query()
|
$query = PurchaseOrder::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('vendor')
|
->with('vendor')
|
||||||
@ -107,9 +103,38 @@ class PurchaseOrderExport extends BaseExport
|
|||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query);
|
||||||
|
|
||||||
// if(isset($this->input['status'])) {
|
return $query;
|
||||||
// $query = $this->addPurchaseOrderStatusFilter($query, $this->input['status']);
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
public function returnJson()
|
||||||
|
{
|
||||||
|
$query = $this->init();
|
||||||
|
|
||||||
|
$headerdisplay = $this->buildHeader();
|
||||||
|
|
||||||
|
$header = collect($this->input['report_keys'])->map(function ($key, $value) use($headerdisplay){
|
||||||
|
return ['identifier' => $value, 'display_value' => $headerdisplay[$value]];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
$report = $query->cursor()
|
||||||
|
->map(function ($resource) {
|
||||||
|
return $this->buildRow($resource);
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
return array_merge(['columns' => $header], $report);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$query = $this->init();
|
||||||
|
|
||||||
|
//load the CSV document from a string
|
||||||
|
$this->csv = Writer::createFromString();
|
||||||
|
|
||||||
|
//insert the header
|
||||||
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
$query->cursor()
|
$query->cursor()
|
||||||
->each(function ($purchase_order) {
|
->each(function ($purchase_order) {
|
||||||
@ -126,23 +151,16 @@ class PurchaseOrderExport extends BaseExport
|
|||||||
$entity = [];
|
$entity = [];
|
||||||
|
|
||||||
foreach (array_values($this->input['report_keys']) as $key) {
|
foreach (array_values($this->input['report_keys']) as $key) {
|
||||||
$keyval = array_search($key, $this->entity_keys);
|
|
||||||
|
|
||||||
if(!$keyval) {
|
$parts = explode('.', $key);
|
||||||
$keyval = array_search(str_replace("purchase_order.", "", $key), $this->entity_keys) ?? $key;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$keyval) {
|
if (is_array($parts) && $parts[0] == 'purchase_order' && array_key_exists($parts[1], $transformed_purchase_order)) {
|
||||||
$keyval = $key;
|
$entity[$key] = $transformed_purchase_order[$parts[1]];
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists($key, $transformed_purchase_order)) {
|
|
||||||
$entity[$keyval] = $transformed_purchase_order[$key];
|
|
||||||
} elseif (array_key_exists($keyval, $transformed_purchase_order)) {
|
|
||||||
$entity[$keyval] = $transformed_purchase_order[$keyval];
|
|
||||||
} else {
|
} else {
|
||||||
$entity[$keyval] = $this->resolveKey($keyval, $purchase_order, $this->purchase_order_transformer);
|
$entity[$key] = $this->resolveKey($key, $purchase_order, $this->purchase_order_transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->decorateAdvancedFields($purchase_order, $entity);
|
return $this->decorateAdvancedFields($purchase_order, $entity);
|
||||||
|
@ -16,6 +16,7 @@ use App\Models\Company;
|
|||||||
use App\Models\PurchaseOrder;
|
use App\Models\PurchaseOrder;
|
||||||
use App\Transformers\PurchaseOrderTransformer;
|
use App\Transformers\PurchaseOrderTransformer;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
|
|
||||||
@ -30,70 +31,7 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
|
|
||||||
private bool $force_keys = false;
|
private bool $force_keys = false;
|
||||||
|
|
||||||
public array $entity_keys = [
|
private array $storage_array = [];
|
||||||
'amount' => 'amount',
|
|
||||||
'balance' => 'balance',
|
|
||||||
'vendor' => 'vendor_id',
|
|
||||||
'vendor_number' => 'vendor.number',
|
|
||||||
'vendor_id_number' => 'vendor.id_number',
|
|
||||||
// 'custom_surcharge1' => 'custom_surcharge1',
|
|
||||||
// 'custom_surcharge2' => 'custom_surcharge2',
|
|
||||||
// 'custom_surcharge3' => 'custom_surcharge3',
|
|
||||||
// 'custom_surcharge4' => 'custom_surcharge4',
|
|
||||||
// 'custom_value1' => 'custom_value1',
|
|
||||||
// 'custom_value2' => 'custom_value2',
|
|
||||||
// 'custom_value3' => 'custom_value3',
|
|
||||||
// 'custom_value4' => 'custom_value4',
|
|
||||||
'date' => 'date',
|
|
||||||
'discount' => 'discount',
|
|
||||||
'due_date' => 'due_date',
|
|
||||||
'exchange_rate' => 'exchange_rate',
|
|
||||||
'footer' => 'footer',
|
|
||||||
'number' => 'number',
|
|
||||||
'paid_to_date' => 'paid_to_date',
|
|
||||||
'partial' => 'partial',
|
|
||||||
'partial_due_date' => 'partial_due_date',
|
|
||||||
'po_number' => 'po_number',
|
|
||||||
'private_notes' => 'private_notes',
|
|
||||||
'public_notes' => 'public_notes',
|
|
||||||
'status' => 'status_id',
|
|
||||||
'tax_name1' => 'tax_name1',
|
|
||||||
'tax_name2' => 'tax_name2',
|
|
||||||
'tax_name3' => 'tax_name3',
|
|
||||||
'tax_rate1' => 'tax_rate1',
|
|
||||||
'tax_rate2' => 'tax_rate2',
|
|
||||||
'tax_rate3' => 'tax_rate3',
|
|
||||||
'terms' => 'terms',
|
|
||||||
'total_taxes' => 'total_taxes',
|
|
||||||
'currency' => 'currency_id',
|
|
||||||
'quantity' => 'item.quantity',
|
|
||||||
'cost' => 'item.cost',
|
|
||||||
'product_key' => 'item.product_key',
|
|
||||||
'buy_price' => 'item.product_cost',
|
|
||||||
'notes' => 'item.notes',
|
|
||||||
'discount' => 'item.discount',
|
|
||||||
'is_amount_discount' => 'item.is_amount_discount',
|
|
||||||
'tax_rate1' => 'item.tax_rate1',
|
|
||||||
'tax_rate2' => 'item.tax_rate2',
|
|
||||||
'tax_rate3' => 'item.tax_rate3',
|
|
||||||
'tax_name1' => 'item.tax_name1',
|
|
||||||
'tax_name2' => 'item.tax_name2',
|
|
||||||
'tax_name3' => 'item.tax_name3',
|
|
||||||
'line_total' => 'item.line_total',
|
|
||||||
'gross_line_total' => 'item.gross_line_total',
|
|
||||||
'purchase_order1' => 'item.custom_value1',
|
|
||||||
'purchase_order2' => 'item.custom_value2',
|
|
||||||
'purchase_order3' => 'item.custom_value3',
|
|
||||||
'purchase_order4' => 'item.custom_value4',
|
|
||||||
'tax_category' => 'item.tax_id',
|
|
||||||
'type' => 'item.type_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
private array $decorate_keys = [
|
|
||||||
'client',
|
|
||||||
'currency_id',
|
|
||||||
'status'
|
|
||||||
];
|
|
||||||
|
|
||||||
public function __construct(Company $company, array $input)
|
public function __construct(Company $company, array $input)
|
||||||
{
|
{
|
||||||
@ -102,25 +40,20 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
$this->purchase_order_transformer = new PurchaseOrderTransformer();
|
$this->purchase_order_transformer = new PurchaseOrderTransformer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
private function init(): Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
App::setLocale($this->company->locale());
|
App::setLocale($this->company->locale());
|
||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||||
|
|
||||||
//load the CSV document from a string
|
|
||||||
$this->csv = Writer::createFromString();
|
|
||||||
|
|
||||||
if (count($this->input['report_keys']) == 0) {
|
if (count($this->input['report_keys']) == 0) {
|
||||||
$this->force_keys = true;
|
// $this->force_keys = true;
|
||||||
$this->input['report_keys'] = array_values($this->entity_keys);
|
$this->input['report_keys'] = array_values($this->mergeItemsKeys('purchase_order_report_keys'));
|
||||||
}
|
}
|
||||||
|
|
||||||
//insert the header
|
|
||||||
$this->csv->insertOne($this->buildHeader());
|
|
||||||
|
|
||||||
$query = PurchaseOrder::query()
|
$query = PurchaseOrder::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('vendor')->where('company_id', $this->company->id)
|
->with('vendor')->where('company_id', $this->company->id)
|
||||||
@ -128,12 +61,47 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query);
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function returnJson()
|
||||||
|
{
|
||||||
|
$query = $this->init();
|
||||||
|
|
||||||
|
$headerdisplay = $this->buildHeader();
|
||||||
|
|
||||||
|
$header = collect($this->input['report_keys'])->map(function ($key, $value) use($headerdisplay){
|
||||||
|
return ['identifier' => $value, 'display_value' => $headerdisplay[$value]];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
$query->cursor()
|
||||||
|
->each(function ($resource) {
|
||||||
|
$this->iterateItems($resource);
|
||||||
|
});
|
||||||
|
|
||||||
|
return array_merge(['columns' => $header], $this->storage_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
//load the CSV document from a string
|
||||||
|
$this->csv = Writer::createFromString();
|
||||||
|
|
||||||
|
$query = $this->init();
|
||||||
|
|
||||||
|
//insert the header
|
||||||
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
$query->cursor()
|
$query->cursor()
|
||||||
->each(function ($purchase_order) {
|
->each(function ($purchase_order) {
|
||||||
$this->iterateItems($purchase_order);
|
$this->iterateItems($purchase_order);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->csv->insertAll($this->storage_array);
|
||||||
|
|
||||||
return $this->csv->toString();
|
return $this->csv->toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function iterateItems(PurchaseOrder $purchase_order)
|
private function iterateItems(PurchaseOrder $purchase_order)
|
||||||
@ -141,7 +109,7 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
$transformed_purchase_order = $this->buildRow($purchase_order);
|
$transformed_purchase_order = $this->buildRow($purchase_order);
|
||||||
|
|
||||||
$transformed_items = [];
|
$transformed_items = [];
|
||||||
|
nlog($purchase_order->toArray());
|
||||||
foreach ($purchase_order->line_items as $item) {
|
foreach ($purchase_order->line_items as $item) {
|
||||||
$item_array = [];
|
$item_array = [];
|
||||||
|
|
||||||
@ -151,10 +119,6 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
|
|
||||||
$key = str_replace("item.", "", $key);
|
$key = str_replace("item.", "", $key);
|
||||||
|
|
||||||
$keyval = $key;
|
|
||||||
|
|
||||||
$keyval = str_replace("custom_value", "purchase_order", $key);
|
|
||||||
|
|
||||||
if($key == 'type_id') {
|
if($key == 'type_id') {
|
||||||
$keyval = 'type';
|
$keyval = 'type';
|
||||||
}
|
}
|
||||||
@ -164,29 +128,17 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (property_exists($item, $key)) {
|
if (property_exists($item, $key)) {
|
||||||
$item_array[$keyval] = $item->{$key};
|
$item_array[$key] = $item->{$key};
|
||||||
} else {
|
} else {
|
||||||
$item_array[$keyval] = '';
|
$item_array[$key] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity = [];
|
|
||||||
|
|
||||||
foreach (array_values($this->input['report_keys']) as $key) { //create an array of report keys only
|
|
||||||
$keyval = array_search($key, $this->entity_keys);
|
|
||||||
|
|
||||||
if (array_key_exists($key, $transformed_items)) {
|
|
||||||
$entity[$keyval] = $transformed_items[$key];
|
|
||||||
} else {
|
|
||||||
$entity[$keyval] = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$transformed_items = array_merge($transformed_purchase_order, $item_array);
|
$transformed_items = array_merge($transformed_purchase_order, $item_array);
|
||||||
$entity = $this->decorateAdvancedFields($purchase_order, $transformed_items);
|
$entity = $this->decorateAdvancedFields($purchase_order, $transformed_items);
|
||||||
|
|
||||||
$this->csv->insertOne($entity);
|
$this->storage_array[] = $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,22 +149,18 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
$entity = [];
|
$entity = [];
|
||||||
|
|
||||||
foreach (array_values($this->input['report_keys']) as $key) {
|
foreach (array_values($this->input['report_keys']) as $key) {
|
||||||
$keyval = array_search($key, $this->entity_keys);
|
$parts = explode('.', $key);
|
||||||
|
|
||||||
if(!$keyval) {
|
if(is_array($parts) && $parts[0] == 'item') {
|
||||||
$keyval = array_search(str_replace("purchase_order.", "", $key), $this->entity_keys) ?? $key;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$keyval) {
|
if (is_array($parts) && $parts[0] == 'purchase_order' && array_key_exists($parts[1], $transformed_purchase_order)) {
|
||||||
$keyval = $key;
|
$entity[$key] = $transformed_purchase_order[$parts[1]];
|
||||||
}
|
} elseif (array_key_exists($key, $transformed_purchase_order)) {
|
||||||
|
$entity[$key] = $transformed_purchase_order[$key];
|
||||||
if (array_key_exists($key, $transformed_purchase_order)) {
|
|
||||||
$entity[$keyval] = $transformed_purchase_order[$key];
|
|
||||||
} elseif (array_key_exists($keyval, $transformed_purchase_order)) {
|
|
||||||
$entity[$keyval] = $transformed_purchase_order[$keyval];
|
|
||||||
} else {
|
} else {
|
||||||
$entity[$keyval] = $this->resolveKey($keyval, $purchase_order, $this->purchase_order_transformer);
|
$entity[$key] = $this->resolveKey($key, $purchase_order, $this->purchase_order_transformer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use App\Models\Company;
|
|||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
use App\Transformers\QuoteTransformer;
|
use App\Transformers\QuoteTransformer;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
|
|
||||||
@ -28,43 +29,6 @@ class QuoteExport extends BaseExport
|
|||||||
|
|
||||||
public Writer $csv;
|
public Writer $csv;
|
||||||
|
|
||||||
public array $entity_keys = [
|
|
||||||
'amount' => 'amount',
|
|
||||||
'balance' => 'balance',
|
|
||||||
'client' => 'client_id',
|
|
||||||
'custom_surcharge1' => 'custom_surcharge1',
|
|
||||||
'custom_surcharge2' => 'custom_surcharge2',
|
|
||||||
'custom_surcharge3' => 'custom_surcharge3',
|
|
||||||
'custom_surcharge4' => 'custom_surcharge4',
|
|
||||||
'custom_value1' => 'custom_value1',
|
|
||||||
'custom_value2' => 'custom_value2',
|
|
||||||
'custom_value3' => 'custom_value3',
|
|
||||||
'custom_value4' => 'custom_value4',
|
|
||||||
'date' => 'date',
|
|
||||||
'discount' => 'discount',
|
|
||||||
'valid_until' => 'due_date',
|
|
||||||
'exchange_rate' => 'exchange_rate',
|
|
||||||
'footer' => 'footer',
|
|
||||||
'number' => 'number',
|
|
||||||
'paid_to_date' => 'paid_to_date',
|
|
||||||
'partial' => 'partial',
|
|
||||||
'partial_due_date' => 'partial_due_date',
|
|
||||||
'po_number' => 'po_number',
|
|
||||||
'private_notes' => 'private_notes',
|
|
||||||
'public_notes' => 'public_notes',
|
|
||||||
'status' => 'status_id',
|
|
||||||
'tax_name1' => 'tax_name1',
|
|
||||||
'tax_name2' => 'tax_name2',
|
|
||||||
'tax_name3' => 'tax_name3',
|
|
||||||
'tax_rate1' => 'tax_rate1',
|
|
||||||
'tax_rate2' => 'tax_rate2',
|
|
||||||
'tax_rate3' => 'tax_rate3',
|
|
||||||
'terms' => 'terms',
|
|
||||||
'total_taxes' => 'total_taxes',
|
|
||||||
'currency' => 'currency_id',
|
|
||||||
'invoice' => 'invoice_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
private array $decorate_keys = [
|
private array $decorate_keys = [
|
||||||
'client',
|
'client',
|
||||||
'currency',
|
'currency',
|
||||||
@ -78,24 +42,20 @@ class QuoteExport extends BaseExport
|
|||||||
$this->quote_transformer = new QuoteTransformer();
|
$this->quote_transformer = new QuoteTransformer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
private function init(): Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
App::setLocale($this->company->locale());
|
App::setLocale($this->company->locale());
|
||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||||
|
|
||||||
//load the CSV document from a string
|
|
||||||
$this->csv = Writer::createFromString();
|
|
||||||
|
|
||||||
if (count($this->input['report_keys']) == 0) {
|
if (count($this->input['report_keys']) == 0) {
|
||||||
$this->input['report_keys'] = array_values($this->entity_keys);
|
$this->input['report_keys'] = array_values($this->quote_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
//insert the header
|
|
||||||
$this->csv->insertOne($this->buildHeader());
|
|
||||||
|
|
||||||
$query = Quote::query()
|
$query = Quote::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('client')
|
->with('client')
|
||||||
@ -104,6 +64,40 @@ class QuoteExport extends BaseExport
|
|||||||
|
|
||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query);
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function returnJson()
|
||||||
|
{
|
||||||
|
$query = $this->init();
|
||||||
|
|
||||||
|
$headerdisplay = $this->buildHeader();
|
||||||
|
|
||||||
|
$header = collect($this->input['report_keys'])->map(function ($key, $value) use ($headerdisplay) {
|
||||||
|
return ['identifier' => $value, 'display_value' => $headerdisplay[$value]];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
$report = $query->cursor()
|
||||||
|
->map(function ($resource) {
|
||||||
|
return $this->buildRow($resource);
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
return array_merge(['columns' => $header], $report);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
//load the CSV document from a string
|
||||||
|
$this->csv = Writer::createFromString();
|
||||||
|
|
||||||
|
$query = $this->init();
|
||||||
|
|
||||||
|
//insert the header
|
||||||
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
$query->cursor()
|
$query->cursor()
|
||||||
->each(function ($quote) {
|
->each(function ($quote) {
|
||||||
$this->csv->insertOne($this->buildRow($quote));
|
$this->csv->insertOne($this->buildRow($quote));
|
||||||
@ -114,50 +108,42 @@ class QuoteExport extends BaseExport
|
|||||||
|
|
||||||
private function buildRow(Quote $quote) :array
|
private function buildRow(Quote $quote) :array
|
||||||
{
|
{
|
||||||
$transformed_entity = $this->quote_transformer->transform($quote);
|
$transformed_invoice = $this->quote_transformer->transform($quote);
|
||||||
|
|
||||||
$entity = [];
|
$entity = [];
|
||||||
|
|
||||||
foreach (array_values($this->input['report_keys']) as $key) {
|
foreach (array_values($this->input['report_keys']) as $key) {
|
||||||
$keyval = array_search($key, $this->entity_keys);
|
|
||||||
|
|
||||||
if(!$keyval) {
|
$parts = explode('.', $key);
|
||||||
$keyval = array_search(str_replace("invoice.", "", $key), $this->entity_keys) ?? $key;
|
|
||||||
|
if (is_array($parts) && $parts[0] == 'quote' && array_key_exists($parts[1], $transformed_invoice)) {
|
||||||
|
$entity[$key] = $transformed_invoice[$parts[1]];
|
||||||
|
} else {
|
||||||
|
$entity[$key] = $this->resolveKey($key, $quote, $this->quote_transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$keyval) {
|
|
||||||
$keyval = $key;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists($key, $transformed_entity)) {
|
|
||||||
$entity[$keyval] = $transformed_entity[$key];
|
|
||||||
} elseif (array_key_exists($keyval, $transformed_entity)) {
|
|
||||||
$entity[$keyval] = $transformed_entity[$keyval];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$entity[$keyval] = $this->resolveKey($keyval, $quote, $this->quote_transformer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->decorateAdvancedFields($quote, $entity);
|
return $this->decorateAdvancedFields($quote, $entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function decorateAdvancedFields(Quote $quote, array $entity) :array
|
private function decorateAdvancedFields(Quote $quote, array $entity) :array
|
||||||
{
|
{
|
||||||
if (in_array('currency_id', $this->input['report_keys'])) {
|
if (in_array('quote.currency_id', $this->input['report_keys'])) {
|
||||||
$entity['currency'] = $quote->client->currency()->code;
|
$entity['quote.currency'] = $quote->client->currency()->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array('client_id', $this->input['report_keys'])) {
|
if (in_array('quote.client_id', $this->input['report_keys'])) {
|
||||||
$entity['client'] = $quote->client->present()->name();
|
$entity['quote.client'] = $quote->client->present()->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array('status_id', $this->input['report_keys'])) {
|
if (in_array('quote.status', $this->input['report_keys'])) {
|
||||||
$entity['status'] = $quote->stringStatus($quote->status_id);
|
$entity['quote.status'] = $quote->stringStatus($quote->status_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array('invoice_id', $this->input['report_keys'])) {
|
if (in_array('quote.invoice_id', $this->input['report_keys'])) {
|
||||||
$entity['invoice'] = $quote->invoice ? $quote->invoice->number : '';
|
$entity['quote.invoice'] = $quote->invoice ? $quote->invoice->number : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Reports;
|
namespace App\Http\Controllers\Reports;
|
||||||
|
|
||||||
use App\Export\CSV\PurchaseOrderItemExport;
|
|
||||||
use App\Http\Controllers\BaseController;
|
|
||||||
use App\Http\Requests\Report\GenericReportRequest;
|
|
||||||
use App\Jobs\Report\SendToAdmin;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Jobs\Report\SendToAdmin;
|
||||||
|
use App\Jobs\Report\PreviewReport;
|
||||||
|
use App\Http\Controllers\BaseController;
|
||||||
|
use App\Export\CSV\PurchaseOrderItemExport;
|
||||||
|
use App\Http\Requests\Report\GenericReportRequest;
|
||||||
|
|
||||||
class PurchaseOrderItemReportController extends BaseController
|
class PurchaseOrderItemReportController extends BaseController
|
||||||
{
|
{
|
||||||
@ -30,14 +31,26 @@ class PurchaseOrderItemReportController extends BaseController
|
|||||||
|
|
||||||
public function __invoke(GenericReportRequest $request)
|
public function __invoke(GenericReportRequest $request)
|
||||||
{
|
{
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
if ($request->has('send_email') && $request->get('send_email')) {
|
if ($request->has('send_email') && $request->get('send_email')) {
|
||||||
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), PurchaseOrderItemExport::class, $this->filename);
|
SendToAdmin::dispatch($user->company(), $request->all(), PurchaseOrderItemExport::class, $this->filename);
|
||||||
|
|
||||||
return response()->json(['message' => 'working...'], 200);
|
return response()->json(['message' => 'working...'], 200);
|
||||||
}
|
}
|
||||||
// expect a list of visible fields, or use the default
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
$export = new PurchaseOrderItemExport(auth()->user()->company(), $request->all());
|
if($request->has('output') && $request->input('output') == 'json') {
|
||||||
|
|
||||||
|
$hash = \Illuminate\Support\Str::uuid();
|
||||||
|
|
||||||
|
PreviewReport::dispatch($user->company(), $request->all(), PurchaseOrderItemExport::class, $hash);
|
||||||
|
|
||||||
|
return response()->json(['message' => $hash], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$export = new PurchaseOrderItemExport($user->company(), $request->all());
|
||||||
|
|
||||||
$csv = $export->run();
|
$csv = $export->run();
|
||||||
|
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Reports;
|
namespace App\Http\Controllers\Reports;
|
||||||
|
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Jobs\Report\SendToAdmin;
|
||||||
|
use App\Jobs\Report\PreviewReport;
|
||||||
use App\Export\CSV\PurchaseOrderExport;
|
use App\Export\CSV\PurchaseOrderExport;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Requests\Report\GenericReportRequest;
|
use App\Http\Requests\Report\GenericReportRequest;
|
||||||
use App\Jobs\Report\SendToAdmin;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
|
|
||||||
class PurchaseOrderReportController extends BaseController
|
class PurchaseOrderReportController extends BaseController
|
||||||
{
|
{
|
||||||
@ -30,14 +31,29 @@ class PurchaseOrderReportController extends BaseController
|
|||||||
|
|
||||||
public function __invoke(GenericReportRequest $request)
|
public function __invoke(GenericReportRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
|
||||||
if ($request->has('send_email') && $request->get('send_email')) {
|
if ($request->has('send_email') && $request->get('send_email')) {
|
||||||
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), PurchaseOrderExport::class, $this->filename);
|
SendToAdmin::dispatch($user->company(), $request->all(), PurchaseOrderExport::class, $this->filename);
|
||||||
|
|
||||||
return response()->json(['message' => 'working...'], 200);
|
return response()->json(['message' => 'working...'], 200);
|
||||||
}
|
}
|
||||||
// expect a list of visible fields, or use the default
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
$export = new PurchaseOrderExport(auth()->user()->company(), $request->all());
|
if($request->has('output') && $request->input('output') == 'json') {
|
||||||
|
|
||||||
|
$hash = \Illuminate\Support\Str::uuid();
|
||||||
|
|
||||||
|
PreviewReport::dispatch($user->company(), $request->all(), PurchaseOrderExport::class, $hash);
|
||||||
|
|
||||||
|
return response()->json(['message' => $hash], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$export = new PurchaseOrderExport($user->company(), $request->all());
|
||||||
|
|
||||||
$csv = $export->run();
|
$csv = $export->run();
|
||||||
|
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Reports;
|
namespace App\Http\Controllers\Reports;
|
||||||
|
|
||||||
|
use Illuminate\Http\Response;
|
||||||
use App\Export\CSV\QuoteExport;
|
use App\Export\CSV\QuoteExport;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Jobs\Report\SendToAdmin;
|
||||||
|
use App\Jobs\Report\PreviewReport;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Requests\Report\GenericReportRequest;
|
use App\Http\Requests\Report\GenericReportRequest;
|
||||||
use App\Jobs\Report\SendToAdmin;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
|
|
||||||
class QuoteReportController extends BaseController
|
class QuoteReportController extends BaseController
|
||||||
{
|
{
|
||||||
@ -62,14 +63,26 @@ class QuoteReportController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function __invoke(GenericReportRequest $request)
|
public function __invoke(GenericReportRequest $request)
|
||||||
{
|
{
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
if ($request->has('send_email') && $request->get('send_email')) {
|
if ($request->has('send_email') && $request->get('send_email')) {
|
||||||
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), QuoteExport::class, $this->filename);
|
SendToAdmin::dispatch($user->company(), $request->all(), QuoteExport::class, $this->filename);
|
||||||
|
|
||||||
return response()->json(['message' => 'working...'], 200);
|
return response()->json(['message' => 'working...'], 200);
|
||||||
}
|
}
|
||||||
// expect a list of visible fields, or use the default
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
$export = new QuoteExport(auth()->user()->company(), $request->all());
|
if($request->has('output') && $request->input('output') == 'json') {
|
||||||
|
|
||||||
|
$hash = \Illuminate\Support\Str::uuid();
|
||||||
|
|
||||||
|
PreviewReport::dispatch($user->company(), $request->all(), QuoteExport::class, $hash);
|
||||||
|
|
||||||
|
return response()->json(['message' => $hash], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$export = new QuoteExport($user->company(), $request->all());
|
||||||
|
|
||||||
$csv = $export->run();
|
$csv = $export->run();
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ class PreviewReport implements ShouldQueue
|
|||||||
/** @var \App\Export\CSV\CreditExport $export */
|
/** @var \App\Export\CSV\CreditExport $export */
|
||||||
$export = new $this->report_class($this->company, $this->request);
|
$export = new $this->report_class($this->company, $this->request);
|
||||||
$report = $export->returnJson();
|
$report = $export->returnJson();
|
||||||
|
nlog($report);
|
||||||
|
nlog($this->report_class);
|
||||||
// nlog($report);
|
// nlog($report);
|
||||||
Cache::put($this->hash, $report, 60 * 60);
|
Cache::put($this->hash, $report, 60 * 60);
|
||||||
}
|
}
|
||||||
|
@ -1222,15 +1222,15 @@ nlog($csv);
|
|||||||
|
|
||||||
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
|
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
|
||||||
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Purchase Order Number'));
|
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Purchase Order Number'));
|
||||||
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Quantity'));
|
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Item Quantity'));
|
||||||
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Cost'));
|
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Item Cost'));
|
||||||
$this->assertEquals('1000', $this->getFirstValueByColumn($csv, 'Line Total'));
|
$this->assertEquals('1000', $this->getFirstValueByColumn($csv, 'Item Line Total'));
|
||||||
$this->assertEquals('0', $this->getFirstValueByColumn($csv, 'Discount'));
|
$this->assertEquals('0', $this->getFirstValueByColumn($csv, 'Item Discount'));
|
||||||
$this->assertEquals('item notes', $this->getFirstValueByColumn($csv, 'Notes'));
|
$this->assertEquals('item notes', $this->getFirstValueByColumn($csv, 'Item Notes'));
|
||||||
$this->assertEquals('product key', $this->getFirstValueByColumn($csv, 'Product'));
|
$this->assertEquals('product key', $this->getFirstValueByColumn($csv, 'Item Product'));
|
||||||
$this->assertEquals('custom 1', $this->getFirstValueByColumn($csv, 'Item Custom Value 1'));
|
$this->assertEquals('custom 1', $this->getFirstValueByColumn($csv, 'Item Custom Value 1'));
|
||||||
$this->assertEquals('GST', $this->getFirstValueByColumn($csv, 'Tax Name 1'));
|
$this->assertEquals('GST', $this->getFirstValueByColumn($csv, 'Item Tax Name 1'));
|
||||||
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Tax Rate 1'));
|
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Item Tax Rate 1'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1643,29 +1643,31 @@ nlog($csv);
|
|||||||
|
|
||||||
$csv = $response->streamedContent();
|
$csv = $response->streamedContent();
|
||||||
|
|
||||||
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Amount'));
|
nlog($csv);
|
||||||
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Balance'));
|
|
||||||
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Discount'));
|
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Quote Amount'));
|
||||||
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'PO Number'));
|
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Quote Balance'));
|
||||||
$this->assertEquals('Public', $this->getFirstValueByColumn($csv, 'Public Notes'));
|
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Quote Discount'));
|
||||||
$this->assertEquals('Private', $this->getFirstValueByColumn($csv, 'Private Notes'));
|
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Quote PO Number'));
|
||||||
$this->assertEquals('Terms', $this->getFirstValueByColumn($csv, 'Terms'));
|
$this->assertEquals('Public', $this->getFirstValueByColumn($csv, 'Quote Public Notes'));
|
||||||
$this->assertEquals('2020-01-01', $this->getFirstValueByColumn($csv, 'Date'));
|
$this->assertEquals('Private', $this->getFirstValueByColumn($csv, 'Quote Private Notes'));
|
||||||
$this->assertEquals('2020-01-01', $this->getFirstValueByColumn($csv, 'Valid Until'));
|
$this->assertEquals('Terms', $this->getFirstValueByColumn($csv, 'Quote Terms'));
|
||||||
$this->assertEquals('2021-01-03', $this->getFirstValueByColumn($csv, 'Partial Due Date'));
|
$this->assertEquals('2020-01-01', $this->getFirstValueByColumn($csv, 'Quote Date'));
|
||||||
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Partial/Deposit'));
|
$this->assertEquals('2020-01-01', $this->getFirstValueByColumn($csv, 'Quote Valid Until'));
|
||||||
$this->assertEquals('Custom 1', $this->getFirstValueByColumn($csv, 'Custom Value 1'));
|
$this->assertEquals('2021-01-03', $this->getFirstValueByColumn($csv, 'Quote Partial Due Date'));
|
||||||
$this->assertEquals('Custom 2', $this->getFirstValueByColumn($csv, 'Custom Value 2'));
|
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Quote Partial/Deposit'));
|
||||||
$this->assertEquals('Custom 3', $this->getFirstValueByColumn($csv, 'Custom Value 3'));
|
$this->assertEquals('Custom 1', $this->getFirstValueByColumn($csv, 'Quote Custom Value 1'));
|
||||||
$this->assertEquals('Custom 4', $this->getFirstValueByColumn($csv, 'Custom Value 4'));
|
$this->assertEquals('Custom 2', $this->getFirstValueByColumn($csv, 'Quote Custom Value 2'));
|
||||||
$this->assertEquals('Footer', $this->getFirstValueByColumn($csv, 'Footer'));
|
$this->assertEquals('Custom 3', $this->getFirstValueByColumn($csv, 'Quote Custom Value 3'));
|
||||||
$this->assertEquals('Tax 1', $this->getFirstValueByColumn($csv, 'Tax Name 1'));
|
$this->assertEquals('Custom 4', $this->getFirstValueByColumn($csv, 'Quote Custom Value 4'));
|
||||||
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Tax Rate 1'));
|
$this->assertEquals('Footer', $this->getFirstValueByColumn($csv, 'Quote Footer'));
|
||||||
$this->assertEquals('Tax 2', $this->getFirstValueByColumn($csv, 'Tax Name 2'));
|
$this->assertEquals('Tax 1', $this->getFirstValueByColumn($csv, 'Quote Tax Name 1'));
|
||||||
$this->assertEquals('20', $this->getFirstValueByColumn($csv, 'Tax Rate 2'));
|
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Quote Tax Rate 1'));
|
||||||
$this->assertEquals('Tax 3', $this->getFirstValueByColumn($csv, 'Tax Name 3'));
|
$this->assertEquals('Tax 2', $this->getFirstValueByColumn($csv, 'Quote Tax Name 2'));
|
||||||
$this->assertEquals('30', $this->getFirstValueByColumn($csv, 'Tax Rate 3'));
|
$this->assertEquals('20', $this->getFirstValueByColumn($csv, 'Quote Tax Rate 2'));
|
||||||
$this->assertEquals('Expired', $this->getFirstValueByColumn($csv, 'Status'));
|
$this->assertEquals('Tax 3', $this->getFirstValueByColumn($csv, 'Quote Tax Name 3'));
|
||||||
|
$this->assertEquals('30', $this->getFirstValueByColumn($csv, 'Quote Tax Rate 3'));
|
||||||
|
$this->assertEquals('Expired', $this->getFirstValueByColumn($csv, 'Quote Status'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use App\Models\Client;
|
|||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Models\Document;
|
use App\Models\Document;
|
||||||
use Tests\MockAccountData;
|
use Tests\MockAccountData;
|
||||||
|
use App\Export\CSV\QuoteExport;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Export\CSV\ClientExport;
|
use App\Export\CSV\ClientExport;
|
||||||
use App\Export\CSV\CreditExport;
|
use App\Export\CSV\CreditExport;
|
||||||
@ -28,6 +29,7 @@ use App\Export\CSV\ActivityExport;
|
|||||||
use App\Export\CSV\DocumentExport;
|
use App\Export\CSV\DocumentExport;
|
||||||
use App\Jobs\Report\PreviewReport;
|
use App\Jobs\Report\PreviewReport;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use App\Export\CSV\PurchaseOrderExport;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,6 +119,72 @@ class ReportPreviewTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testPurchaseOrderItemJsonExport()
|
||||||
|
{
|
||||||
|
\App\Models\PurchaseOrder::factory()->count(5)->create([
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'vendor_id' => $this->vendor->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'send_email' => false,
|
||||||
|
'date_range' => 'all',
|
||||||
|
'report_keys' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/reports/purchase_order_items?output=json', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$p = (new PreviewReport($this->company, $data, \App\Export\CSV\PurchaseOrderItemExport::class, '123'))->handle();
|
||||||
|
|
||||||
|
$this->assertNull($p);
|
||||||
|
|
||||||
|
$r = Cache::pull('123');
|
||||||
|
|
||||||
|
$this->assertNotNull($r);
|
||||||
|
|
||||||
|
//nlog($r);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testQuoteItemJsonExport()
|
||||||
|
{
|
||||||
|
\App\Models\Quote::factory()->count(5)->create([
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'send_email' => false,
|
||||||
|
'date_range' => 'all',
|
||||||
|
'report_keys' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/reports/quote_items?output=json', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$p = (new PreviewReport($this->company, $data, \App\Export\CSV\QuoteItemExport::class, '123'))->handle();
|
||||||
|
|
||||||
|
$this->assertNull($p);
|
||||||
|
|
||||||
|
$r = Cache::pull('123');
|
||||||
|
|
||||||
|
$this->assertNotNull($r);
|
||||||
|
|
||||||
|
//nlog($r);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testInvoiceItemJsonExport()
|
public function testInvoiceItemJsonExport()
|
||||||
{
|
{
|
||||||
\App\Models\Invoice::factory()->count(5)->create([
|
\App\Models\Invoice::factory()->count(5)->create([
|
||||||
@ -150,6 +218,67 @@ class ReportPreviewTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function testPurchaseOrderJsonExport()
|
||||||
|
{
|
||||||
|
\App\Models\PurchaseOrder::factory()->count(5)->create([
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'vendor_id' => $this->vendor->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'send_email' => false,
|
||||||
|
'date_range' => 'all',
|
||||||
|
'report_keys' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/reports/purchase_orders?output=json', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$p = (new PreviewReport($this->company, $data, PurchaseOrderExport::class, '123'))->handle();
|
||||||
|
|
||||||
|
$this->assertNull($p);
|
||||||
|
|
||||||
|
$r = Cache::pull('123');
|
||||||
|
|
||||||
|
$this->assertNotNull($r);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testQuoteJsonExport()
|
||||||
|
{
|
||||||
|
\App\Models\Quote::factory()->count(5)->create([
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'send_email' => false,
|
||||||
|
'date_range' => 'all',
|
||||||
|
'report_keys' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/reports/quotes?output=json', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$p = (new PreviewReport($this->company, $data, QuoteExport::class, '123'))->handle();
|
||||||
|
|
||||||
|
$this->assertNull($p);
|
||||||
|
|
||||||
|
$r = Cache::pull('123');
|
||||||
|
|
||||||
|
$this->assertNotNull($r);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testInvoiceJsonExport()
|
public function testInvoiceJsonExport()
|
||||||
{
|
{
|
||||||
\App\Models\Invoice::factory()->count(5)->create([
|
\App\Models\Invoice::factory()->count(5)->create([
|
||||||
|
@ -574,6 +574,8 @@ trait MockAccountData
|
|||||||
$this->purchase_order->tax_rate2 = 0;
|
$this->purchase_order->tax_rate2 = 0;
|
||||||
$this->purchase_order->tax_rate3 = 0;
|
$this->purchase_order->tax_rate3 = 0;
|
||||||
|
|
||||||
|
$this->purchase_order->line_items = InvoiceItemFactory::generate(5);
|
||||||
|
|
||||||
$this->purchase_order->uses_inclusive_taxes = false;
|
$this->purchase_order->uses_inclusive_taxes = false;
|
||||||
$this->purchase_order->save();
|
$this->purchase_order->save();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user