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 = [ $reportTypes = [
'client',
'product',
'invoice',
'invoice_details',
'aging', 'aging',
'profit_and_loss', 'client',
'payment',
'expense', 'expense',
'invoice',
'payment',
'product',
'profit_and_loss',
'task', 'task',
'tax_rate', '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', 'client',
'invoice_number', 'invoice_number',
'invoice_date', 'invoice_date',
'quantity',
'product', 'product',
'qty',
'cost',
//'tax_rate1',
//'tax_rate2',
]; ];
public function run() public function run()
{ {
$account = Auth::user()->account; $account = Auth::user()->account;
$status = $this->options['invoice_status'];
$clients = Client::scope() $clients = Client::scope()
->withTrashed() ->withArchived()
->with('contacts') ->with('contacts')
->where('is_deleted', '=', false) ->with(['invoices' => function ($query) use ($status) {
->with(['invoices' => function ($query) { if ($status == 'draft') {
$query->where('invoice_date', '>=', $this->startDate) $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('invoice_date', '<=', $this->endDate)
->where('is_deleted', '=', false) ->with(['invoice_items']);
->where('is_recurring', '=', false)
->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->with(['invoice_items'])
->withTrashed();
}]); }]);
foreach ($clients->get() as $client) { foreach ($clients->get() as $client) {
foreach ($client->invoices as $invoice) { foreach ($client->invoices as $invoice) {
foreach ($invoice->invoice_items as $invoiceItem) { foreach ($invoice->invoice_items as $item) {
$this->data[] = [ $this->data[] = [
$this->isExport ? $client->getDisplayName() : $client->present()->link, $this->isExport ? $client->getDisplayName() : $client->present()->link,
$this->isExport ? $invoice->invoice_number : $invoice->present()->link, $this->isExport ? $invoice->invoice_number : $invoice->present()->link,
$invoice->present()->invoice_date, $invoice->present()->invoice_date,
round($invoiceItem->qty, 2), $item->product_key,
$invoiceItem->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); //$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0);
//$reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'balance', $invoice->balance); //$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> </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') {!! Former::select('invoice_status')->label('status')
->addOption(trans('texts.all'), 'all') ->addOption(trans('texts.all'), 'all')
->addOption(trans('texts.draft'), 'draft') ->addOption(trans('texts.draft'), 'draft')
@ -256,7 +256,7 @@
} else { } else {
$('#dateField').fadeOut(); $('#dateField').fadeOut();
} }
if (val == '{{ ENTITY_INVOICE }}' || val == 'invoice_details') { if (val == '{{ ENTITY_INVOICE }}' || val == '{{ ENTITY_PRODUCT }}') {
$('#statusField').fadeIn(); $('#statusField').fadeIn();
} else { } else {
$('#statusField').fadeOut(); $('#statusField').fadeOut();