Merge product and invoice details reports

This commit is contained in:
Hillel Coren 2017-02-07 14:10:37 +02:00
parent 44eb7d52f9
commit e8fda5f67e
4 changed files with 30 additions and 85 deletions

View File

@ -63,14 +63,13 @@ class ReportController extends BaseController
}
$reportTypes = [
'client',
'product',
'invoice',
'invoice_details',
'aging',
'profit_and_loss',
'payment',
'client',
'expense',
'invoice',
'payment',
'product',
'profit_and_loss',
'task',
'tax_rate',
];

View File

@ -1,61 +0,0 @@
<?php
namespace App\Ninja\Reports;
use App\Models\Client;
use Auth;
class InvoiceDetailsReport extends AbstractReport
{
public $columns = [
'client',
'invoice_number',
'invoice_date',
'product',
'qty',
'cost',
//'tax_rate1',
//'tax_rate2',
];
public function run()
{
$account = Auth::user()->account;
$status = $this->options['invoice_status'];
$clients = Client::scope()
->withArchived()
->with('contacts')
->with(['invoices' => function ($query) use ($status) {
if ($status == 'draft') {
$query->whereIsPublic(false);
} elseif ($status == 'unpaid' || $status == 'paid') {
$query->whereIsPublic(true);
}
$query->invoices()
->withArchived()
->where('invoice_date', '>=', $this->startDate)
->where('invoice_date', '<=', $this->endDate)
->with(['invoice_items']);
}]);
foreach ($clients->get() as $client) {
foreach ($client->invoices as $invoice) {
foreach ($invoice->invoice_items as $item) {
$this->data[] = [
$this->isExport ? $client->getDisplayName() : $client->present()->link,
$this->isExport ? $invoice->invoice_number : $invoice->present()->link,
$invoice->present()->invoice_date,
$item->product_key,
$item->qty,
$account->formatMoney($item->cost, $client),
];
}
//$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0);
//$this->addToTotals($client->currency_id, 'amount', $invoice->amount);
//$this->addToTotals($client->currency_id, 'balance', $invoice->balance);
}
}
}
}

View File

@ -11,43 +11,50 @@ class ProductReport extends AbstractReport
'client',
'invoice_number',
'invoice_date',
'quantity',
'product',
'qty',
'cost',
//'tax_rate1',
//'tax_rate2',
];
public function run()
{
$account = Auth::user()->account;
$status = $this->options['invoice_status'];
$clients = Client::scope()
->withTrashed()
->withArchived()
->with('contacts')
->where('is_deleted', '=', false)
->with(['invoices' => function ($query) {
$query->where('invoice_date', '>=', $this->startDate)
->with(['invoices' => function ($query) use ($status) {
if ($status == 'draft') {
$query->whereIsPublic(false);
} elseif ($status == 'unpaid' || $status == 'paid') {
$query->whereIsPublic(true);
}
$query->invoices()
->withArchived()
->where('invoice_date', '>=', $this->startDate)
->where('invoice_date', '<=', $this->endDate)
->where('is_deleted', '=', false)
->where('is_recurring', '=', false)
->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->with(['invoice_items'])
->withTrashed();
->with(['invoice_items']);
}]);
foreach ($clients->get() as $client) {
foreach ($client->invoices as $invoice) {
foreach ($invoice->invoice_items as $invoiceItem) {
foreach ($invoice->invoice_items as $item) {
$this->data[] = [
$this->isExport ? $client->getDisplayName() : $client->present()->link,
$this->isExport ? $invoice->invoice_number : $invoice->present()->link,
$invoice->present()->invoice_date,
round($invoiceItem->qty, 2),
$invoiceItem->product_key,
$item->product_key,
$item->qty,
$account->formatMoney($item->cost, $client),
];
//$reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'paid', $payment ? $payment->amount : 0);
}
//$reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'amount', $invoice->amount);
//$reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'balance', $invoice->balance);
//$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0);
//$this->addToTotals($client->currency_id, 'amount', $invoice->amount);
//$this->addToTotals($client->currency_id, 'balance', $invoice->balance);
}
}
}

View File

@ -101,7 +101,7 @@
</div>
</div>
<div id="statusField" style="display:{{ in_array($reportType, ['invoice', 'invoice_details']) ? 'block' : 'none' }}">
<div id="statusField" style="display:{{ in_array($reportType, [ENTITY_INVOICE, ENTITY_PRODUCT]) ? 'block' : 'none' }}">
{!! Former::select('invoice_status')->label('status')
->addOption(trans('texts.all'), 'all')
->addOption(trans('texts.draft'), 'draft')
@ -256,7 +256,7 @@
} else {
$('#dateField').fadeOut();
}
if (val == '{{ ENTITY_INVOICE }}' || val == 'invoice_details') {
if (val == '{{ ENTITY_INVOICE }}' || val == '{{ ENTITY_PRODUCT }}') {
$('#statusField').fadeIn();
} else {
$('#statusField').fadeOut();