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
c90d930f89
commit
043f854a37
@ -91,6 +91,10 @@ class BaseExport
|
||||
$this->start_date = (new \Carbon\Carbon('-6 months'))->firstOfQuarter()->format('Y-m-d');
|
||||
$this->end_date = (new \Carbon\Carbon('-6 months'))->lastOfQuarter()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [(new \Carbon\Carbon('-6 months'))->firstOfQuarter(), (new \Carbon\Carbon('-6 months'))->lastOfQuarter()])->orderBy($this->date_key, 'ASC');
|
||||
case 'last365_days':
|
||||
$this->start_date = now()->startOfDay()->subDays(365)->format('Y-m-d');
|
||||
$this->end_date = now()->startOfDay()->format('Y-m-d');
|
||||
return $query->whereBetween($this->date_key, [now()->subDays(365), now()])->orderBy($this->date_key, 'ASC');
|
||||
case 'this_year':
|
||||
$this->start_date = now()->startOfYear()->format('Y-m-d');
|
||||
$this->end_date = now()->format('Y-m-d');
|
||||
|
24
app/Services/Report/ARDetail.php
Normal file
24
app/Services/Report/ARDetail.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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 ARDetail
|
||||
{
|
||||
//Date
|
||||
//Invoice #
|
||||
//Status
|
||||
//Customer
|
||||
//Age - Days
|
||||
//Amount
|
||||
//Balance
|
||||
|
||||
}
|
23
app/Services/Report/ARSummary.php
Normal file
23
app/Services/Report/ARSummary.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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 ARSummary
|
||||
{
|
||||
//name
|
||||
//total
|
||||
//current
|
||||
//0-30
|
||||
//30-60
|
||||
//60-90
|
||||
//90+
|
||||
}
|
21
app/Services/Report/ClientSales.php
Normal file
21
app/Services/Report/ClientSales.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?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 ClientSales
|
||||
{
|
||||
//Name
|
||||
//Invoice count
|
||||
//Amount
|
||||
//Amount with Tax
|
||||
|
||||
}
|
20
app/Services/Report/CustomerBalance.php
Normal file
20
app/Services/Report/CustomerBalance.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?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
|
||||
}
|
108
app/Services/Report/UserSales.php
Normal file
108
app/Services/Report/UserSales.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?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\Models\User;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
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 UserSales extends BaseExport
|
||||
{
|
||||
use MakesDates;
|
||||
//Name
|
||||
//Invoice count
|
||||
//Amount
|
||||
//Amount with Tax
|
||||
public Writer $csv;
|
||||
|
||||
public string $date_key = 'created_at';
|
||||
|
||||
/**
|
||||
@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();
|
||||
|
||||
$query = Invoice::query()
|
||||
->withTrashed()
|
||||
->where('company_id', $this->company->id)
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]);
|
||||
|
||||
$query = $this->addDateRange($query);
|
||||
|
||||
$query = $this->filterByClients($query);
|
||||
|
||||
$this->csv->insertOne([ctrans('texts.sales_report_header', ['client' => $this->client_description, 'start_date' => $this->start_date, 'end_date' => $this->end_date])]);
|
||||
$this->csv->insertOne($this->buildHeader());
|
||||
|
||||
$users = $this->company->users;
|
||||
|
||||
$report = $users->map(function ($user) use($query){
|
||||
|
||||
$new_query = $query;
|
||||
$new_query->where('user_id', $user->id);
|
||||
|
||||
return [
|
||||
$user->present()->name(),
|
||||
$new_query->count(),
|
||||
Number::formatMoney($new_query->sum('amount'), $this->company),
|
||||
Number::formatMoney($new_query->sum('total_taxes'), $this->company),
|
||||
];
|
||||
|
||||
})->toArray();
|
||||
|
||||
$key_values = array_column($report, 1);
|
||||
array_multisort($key_values, SORT_DESC, $report);
|
||||
|
||||
$this->csv->insertAll($report);
|
||||
|
||||
return $this->csv->toString();
|
||||
|
||||
}
|
||||
|
||||
public function buildHeader(): array
|
||||
{
|
||||
return [
|
||||
ctrans('texts.name'),
|
||||
ctrans('texts.invoices'),
|
||||
ctrans('texts.invoice_amount'),
|
||||
ctrans('texts.total_taxes'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -5032,6 +5032,7 @@ $LANG = array(
|
||||
'quote_product_columns' => 'Quote Product Columns',
|
||||
'vendors' => 'Vendors',
|
||||
'product_sales' => 'Product Sales',
|
||||
'sales_report_header' => 'User sales report for client/s :client from :start_date to :end_date',
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user