mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Reporting Season
This commit is contained in:
parent
043f854a37
commit
bb6f7b25b2
@ -110,7 +110,7 @@ class BaseExport
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildHeader() :array
|
||||
public function buildHeader() :array
|
||||
{
|
||||
$header = [];
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace App\Services\Report;
|
||||
|
||||
class ARDetail
|
||||
class ARDetailReport
|
||||
{
|
||||
//Date
|
||||
//Invoice #
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace App\Services\Report;
|
||||
|
||||
class ARSummary
|
||||
class ARSummaryReport
|
||||
{
|
||||
//name
|
||||
//total
|
120
app/Services/Report/ClientBalanceReport.php
Normal file
120
app/Services/Report/ClientBalanceReport.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Services\Report;
|
||||
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Client;
|
||||
use League\Csv\Writer;
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Export\CSV\BaseExport;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class ClientBalanceReport extends BaseExport
|
||||
{
|
||||
use MakesDates;
|
||||
//Name
|
||||
//Invoice count
|
||||
//Amount
|
||||
//Amount with Tax
|
||||
public Writer $csv;
|
||||
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
public array $report_keys = [
|
||||
'client_name',
|
||||
'client_number',
|
||||
'id_number',
|
||||
'invoices',
|
||||
'amount',
|
||||
'balance',
|
||||
'total_taxes',
|
||||
];
|
||||
|
||||
/**
|
||||
@param array $input
|
||||
[
|
||||
'date_range',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'clients',
|
||||
'client_id',
|
||||
]
|
||||
*/
|
||||
public function __construct(public Company $company, public array $input)
|
||||
{
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
App::forgetInstance('translator');
|
||||
App::setLocale($this->company->locale());
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||
|
||||
$this->csv = Writer::createFromString();
|
||||
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([]);
|
||||
$this->csv->insertOne([ctrans('texts.customer_balance_report')]);
|
||||
$this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]);
|
||||
|
||||
$this->csv->insertOne($this->buildHeader());
|
||||
|
||||
Client::query()
|
||||
->where('company_id', $this->company->id)
|
||||
->where('is_deleted', 0)
|
||||
->orderBy('balance', 'desc')
|
||||
->cursor()
|
||||
->each(function ($client){
|
||||
|
||||
$this->csv->insertOne($this->buildRow($client));
|
||||
|
||||
});
|
||||
|
||||
return $this->csv->toString();
|
||||
|
||||
}
|
||||
|
||||
public function buildHeader(): array
|
||||
{
|
||||
$headers = [];
|
||||
|
||||
foreach($this->report_keys as $key)
|
||||
$headers[] = ctrans("texts.{$key}");
|
||||
|
||||
return $headers;
|
||||
|
||||
}
|
||||
private function buildRow(Client $client): array
|
||||
{
|
||||
$query = Invoice::where('client_id', $client->id)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
||||
|
||||
$query = $this->addDateRange($query);
|
||||
|
||||
return [
|
||||
$client->present()->name(),
|
||||
$client->number,
|
||||
$client->id_number,
|
||||
$query->count(),
|
||||
$query->sum('amount'),
|
||||
$query->sum('balance'),
|
||||
$query->sum('total_taxes'),
|
||||
];
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace App\Services\Report;
|
||||
|
||||
class ClientSales
|
||||
class ClientSalesReport
|
||||
{
|
||||
//Name
|
||||
//Invoice count
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Services\Report;
|
||||
|
||||
class CustomerBalance
|
||||
{
|
||||
//name
|
||||
//invoice balance
|
||||
//credit balance
|
||||
//balance
|
||||
}
|
@ -22,7 +22,7 @@ use App\Export\CSV\BaseExport;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class UserSales extends BaseExport
|
||||
class UserSalesReport extends BaseExport
|
||||
{
|
||||
use MakesDates;
|
||||
//Name
|
@ -27,7 +27,10 @@ class EmailRecord
|
||||
{
|
||||
$class = 'App\\Models\\' . Str::camel($this->scheduler->parameters['entity']);
|
||||
|
||||
$class::find($this->decodePrimaryKey($this->scheduler->parameters['entity_id']))->service()->sendEmail();
|
||||
$entity = $class::find($this->decodePrimaryKey($this->scheduler->parameters['entity_id']));
|
||||
|
||||
if($entity)
|
||||
$entity->service()->sendEmail();
|
||||
|
||||
$this->scheduler->forceDelete();
|
||||
}
|
||||
|
@ -5033,6 +5033,9 @@ $LANG = array(
|
||||
'vendors' => 'Vendors',
|
||||
'product_sales' => 'Product Sales',
|
||||
'sales_report_header' => 'User sales report for client/s :client from :start_date to :end_date',
|
||||
'customer_balance_report' => 'Customer balance report',
|
||||
'user_sales_report' => 'User sales report',
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user