2017-01-22 11:09:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Reports;
|
|
|
|
|
|
|
|
use App\Models\Client;
|
2017-01-30 20:40:43 +01:00
|
|
|
use Auth;
|
2017-08-14 13:06:50 +02:00
|
|
|
use Utils;
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
class ProductReport extends AbstractReport
|
|
|
|
{
|
|
|
|
public $columns = [
|
|
|
|
'client',
|
|
|
|
'invoice_number',
|
|
|
|
'invoice_date',
|
|
|
|
'product',
|
2017-02-07 13:10:37 +01:00
|
|
|
'qty',
|
|
|
|
'cost',
|
|
|
|
//'tax_rate1',
|
|
|
|
//'tax_rate2',
|
2017-01-22 11:09:29 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
2017-02-07 13:10:37 +01:00
|
|
|
$status = $this->options['invoice_status'];
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
$clients = Client::scope()
|
2017-03-31 08:01:07 +02:00
|
|
|
->orderBy('name')
|
2017-02-07 13:10:37 +01:00
|
|
|
->withArchived()
|
2017-01-22 11:09:29 +01:00
|
|
|
->with('contacts')
|
2017-02-07 13:10:37 +01:00
|
|
|
->with(['invoices' => function ($query) use ($status) {
|
|
|
|
if ($status == 'draft') {
|
|
|
|
$query->whereIsPublic(false);
|
2017-05-16 15:56:51 +02:00
|
|
|
} elseif (in_array($status, ['paid', 'unpaid', 'sent'])) {
|
2017-02-07 13:10:37 +01:00
|
|
|
$query->whereIsPublic(true);
|
|
|
|
}
|
|
|
|
$query->invoices()
|
|
|
|
->withArchived()
|
|
|
|
->where('invoice_date', '>=', $this->startDate)
|
2017-01-22 11:09:29 +01:00
|
|
|
->where('invoice_date', '<=', $this->endDate)
|
2017-02-07 13:10:37 +01:00
|
|
|
->with(['invoice_items']);
|
2017-01-22 11:09:29 +01:00
|
|
|
}]);
|
|
|
|
|
|
|
|
foreach ($clients->get() as $client) {
|
|
|
|
foreach ($client->invoices as $invoice) {
|
2017-02-07 13:10:37 +01:00
|
|
|
foreach ($invoice->invoice_items as $item) {
|
2017-01-22 11:09:29 +01:00
|
|
|
$this->data[] = [
|
|
|
|
$this->isExport ? $client->getDisplayName() : $client->present()->link,
|
|
|
|
$this->isExport ? $invoice->invoice_number : $invoice->present()->link,
|
|
|
|
$invoice->present()->invoice_date,
|
2017-02-07 13:10:37 +01:00
|
|
|
$item->product_key,
|
2017-08-14 13:06:50 +02:00
|
|
|
Utils::roundSignificant($item->qty, 0),
|
|
|
|
Utils::roundSignificant($item->cost, 2),
|
2017-01-22 11:09:29 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-02-07 13:10:37 +01:00
|
|
|
//$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);
|
2017-01-22 11:09:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|