mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
fixes for jobs breaking with massive payloads
This commit is contained in:
parent
fb5b2882d3
commit
d7084785fe
@ -277,11 +277,13 @@ class CompanyImport implements ShouldQueue
|
|||||||
'errors' => []
|
'errors' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$_company = Company::find($this->company->id);
|
||||||
|
|
||||||
$nmo = new NinjaMailerObject;
|
$nmo = new NinjaMailerObject;
|
||||||
$nmo->mailable = new ImportCompleted($this->company, $data);
|
$nmo->mailable = new ImportCompleted($_company, $data);
|
||||||
$nmo->company = $this->company;
|
$nmo->company = $_company;
|
||||||
$nmo->settings = $this->company->settings;
|
$nmo->settings = $_company->settings;
|
||||||
$nmo->to_user = $this->company->owner();
|
$nmo->to_user = $_company->owner();
|
||||||
NinjaMailerJob::dispatchNow($nmo);
|
NinjaMailerJob::dispatchNow($nmo);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1528,10 +1530,9 @@ class CompanyImport implements ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! array_key_exists($resource, $this->ids)) {
|
if (! array_key_exists($resource, $this->ids)) {
|
||||||
nlog($resource);
|
|
||||||
|
|
||||||
$this->sendImportMail("The Import failed due to missing data in the import file. Resource {$resource} not available.");
|
$this->sendImportMail("The Import failed due to missing data in the import file. Resource {$resource} not available.");
|
||||||
nlog($this->ids);
|
|
||||||
throw new \Exception("Resource {$resource} not available.");
|
throw new \Exception("Resource {$resource} not available.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1561,8 +1562,10 @@ class CompanyImport implements ShouldQueue
|
|||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||||
|
|
||||||
|
$_company = Company::find($this->company->id);
|
||||||
|
|
||||||
$nmo = new NinjaMailerObject;
|
$nmo = new NinjaMailerObject;
|
||||||
$nmo->mailable = new CompanyImportFailure($this->company, $message);
|
$nmo->mailable = new CompanyImportFailure($_company, $message);
|
||||||
$nmo->company = $this->company;
|
$nmo->company = $this->company;
|
||||||
$nmo->settings = $this->company->settings;
|
$nmo->settings = $this->company->settings;
|
||||||
$nmo->to_user = $this->company->owner();
|
$nmo->to_user = $this->company->owner();
|
||||||
|
@ -58,6 +58,22 @@ class ImportCompleted extends Mailable
|
|||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
'settings' => $this->company->settings,
|
'settings' => $this->company->settings,
|
||||||
'company' => $this->company,
|
'company' => $this->company,
|
||||||
|
'client_count' => $this->company->clients()->count(),
|
||||||
|
'product_count' => $this->company->products()->count(),
|
||||||
|
'invoice_count' => $this->company->invoices()->count(),
|
||||||
|
'quote_count' => $this->company->quotes()->count(),
|
||||||
|
'credit_count' => $this->company->credits()->count(),
|
||||||
|
'project_count' => $this->company->projects()->count(),
|
||||||
|
'task_count' => $this->company->tasks()->count(),
|
||||||
|
'vendor_count' => $this->company->vendors()->count(),
|
||||||
|
'payment_count' => $this->company->payments()->count(),
|
||||||
|
'recurring_invoice_count' => $this->company->recurring_invoices()->count(),
|
||||||
|
'expense_count' => $this->company->expenses()->count(),
|
||||||
|
'company_gateway_count' => $this->company->company_gateways()->count(),
|
||||||
|
'client_gateway_token_count' => $this->company->client_gateway_tokens()->count(),
|
||||||
|
'tax_rate_count' => $this->company->tax_rates()->count(),
|
||||||
|
'document_count' => $this->company->documents()->count(),
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this
|
return $this
|
||||||
|
@ -118,9 +118,7 @@ class Company extends BaseModel
|
|||||||
'client_registration_fields' => 'array',
|
'client_registration_fields' => 'array',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $with = [
|
protected $with = [];
|
||||||
// 'tokens'
|
|
||||||
];
|
|
||||||
|
|
||||||
public static $modules = [
|
public static $modules = [
|
||||||
self::ENTITY_RECURRING_INVOICE => 1,
|
self::ENTITY_RECURRING_INVOICE => 1,
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Services\Report;
|
namespace App\Services\Report;
|
||||||
|
|
||||||
use App\Libraries\Currency\Conversion\CurrencyApi;
|
use App\Libraries\Currency\Conversion\CurrencyApi;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
@ -28,6 +29,14 @@ class ProfitLoss
|
|||||||
|
|
||||||
private $end_date;
|
private $end_date;
|
||||||
|
|
||||||
|
private float $income = 0;
|
||||||
|
|
||||||
|
private float $income_taxes = 0;
|
||||||
|
|
||||||
|
private array $expenses;
|
||||||
|
|
||||||
|
private array $income_map;
|
||||||
|
|
||||||
protected CurrencyApi $currency_api;
|
protected CurrencyApi $currency_api;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -45,8 +54,8 @@ class ProfitLoss
|
|||||||
last_quarter
|
last_quarter
|
||||||
this_year
|
this_year
|
||||||
custom
|
custom
|
||||||
income_billed - true = Invoiced || false = Payments
|
is_income_billed - true = Invoiced || false = Payments
|
||||||
expense_billed - true = Expensed || false = Expenses marked as paid
|
is_expense_billed - true = Expensed || false = Expenses marked as paid
|
||||||
include_tax - true tax_included || false - tax_excluded
|
include_tax - true tax_included || false - tax_excluded
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -68,15 +77,66 @@ class ProfitLoss
|
|||||||
|
|
||||||
public function build()
|
public function build()
|
||||||
{
|
{
|
||||||
//get income
|
MultiDB::setDb($this->company->db);
|
||||||
|
|
||||||
//sift foreign currencies - calculate both converted foreign amounts to native currency and also also group amounts by currency.
|
if($this->is_income_billed){ //get invoiced amounts
|
||||||
|
|
||||||
//get expenses
|
$this->filterIncome();
|
||||||
|
|
||||||
|
}else {
|
||||||
|
|
||||||
|
$this->filterPaymentIncome();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->expenseData();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIncome() :float
|
||||||
|
{
|
||||||
|
return round($this->income,2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIncomeMap() :array
|
||||||
|
{
|
||||||
|
return $this->income_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIncomeTaxes() :float
|
||||||
|
{
|
||||||
|
return round($this->income_taxes,2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExpenses() :array
|
||||||
|
{
|
||||||
|
return $this->expenses;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function filterIncome()
|
||||||
|
{
|
||||||
|
$invoices = $this->invoiceIncome();
|
||||||
|
|
||||||
|
$this->income = 0;
|
||||||
|
$this->income_taxes = 0;
|
||||||
|
$this->income_map = $invoices;
|
||||||
|
|
||||||
|
foreach($invoices as $invoice){
|
||||||
|
$this->income += $invoice->net_converted_amount;
|
||||||
|
$this->income_taxes += $invoice->net_converted_taxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function filterPaymentIncome()
|
||||||
|
{
|
||||||
|
$payments = $this->paymentIncome();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//returns an array of objects
|
//returns an array of objects
|
||||||
@ -86,27 +146,31 @@ class ProfitLoss
|
|||||||
+"total_taxes": "35.950000",
|
+"total_taxes": "35.950000",
|
||||||
+"currency_id": ""1"",
|
+"currency_id": ""1"",
|
||||||
+"net_converted_amount": "670.5300000000",
|
+"net_converted_amount": "670.5300000000",
|
||||||
|
+"net_converted_taxes": "10"
|
||||||
},
|
},
|
||||||
{#2444
|
{#2444
|
||||||
+"amount": "200.000000",
|
+"amount": "200.000000",
|
||||||
+"total_taxes": "0.000000",
|
+"total_taxes": "0.000000",
|
||||||
+"currency_id": ""23"",
|
+"currency_id": ""23"",
|
||||||
+"net_converted_amount": "1.7129479802",
|
+"net_converted_amount": "1.7129479802",
|
||||||
|
+"net_converted_taxes": "10"
|
||||||
},
|
},
|
||||||
{#2654
|
{#2654
|
||||||
+"amount": "140.000000",
|
+"amount": "140.000000",
|
||||||
+"total_taxes": "40.000000",
|
+"total_taxes": "40.000000",
|
||||||
+"currency_id": ""12"",
|
+"currency_id": ""12"",
|
||||||
+"net_converted_amount": "69.3275024282",
|
+"net_converted_amount": "69.3275024282",
|
||||||
|
+"net_converted_taxes": "10"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
private function invoiceIncome()
|
private function invoiceIncome()
|
||||||
{
|
{ nlog(['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date] );
|
||||||
return \DB::select( \DB::raw("
|
return \DB::select( \DB::raw("
|
||||||
SELECT
|
SELECT
|
||||||
sum(invoices.amount) as amount,
|
sum(invoices.amount) as amount,
|
||||||
sum(invoices.total_taxes) as total_taxes,
|
sum(invoices.total_taxes) as total_taxes,
|
||||||
|
(sum(invoices.total_taxes) / IFNULL(invoices.exchange_rate, 1)) AS net_converted_taxes,
|
||||||
sum(invoices.amount - invoices.total_taxes) as net_amount,
|
sum(invoices.amount - invoices.total_taxes) as net_amount,
|
||||||
IFNULL(JSON_EXTRACT( settings, '$.currency_id' ), :company_currency) AS currency_id,
|
IFNULL(JSON_EXTRACT( settings, '$.currency_id' ), :company_currency) AS currency_id,
|
||||||
(sum(invoices.amount - invoices.total_taxes) / IFNULL(invoices.exchange_rate, 1)) AS net_converted_amount
|
(sum(invoices.amount - invoices.total_taxes) / IFNULL(invoices.exchange_rate, 1)) AS net_converted_amount
|
||||||
@ -130,12 +194,19 @@ class ProfitLoss
|
|||||||
// }, 0);
|
// }, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
+"payments": "12260.870000",
|
||||||
|
+"payments_converted": "12260.870000000000",
|
||||||
|
+"currency_id": 1,
|
||||||
|
*/
|
||||||
private function paymentIncome()
|
private function paymentIncome()
|
||||||
{
|
{
|
||||||
return \DB::select( \DB::raw("
|
return \DB::select( \DB::raw("
|
||||||
SELECT
|
SELECT
|
||||||
SUM(coalesce(payments.amount - payments.refunded,0)) as payments,
|
SUM(coalesce(payments.amount - payments.refunded,0)) as payments,
|
||||||
SUM(coalesce(payments.amount - payments.refunded,0)) * IFNULL(payments.exchange_rate ,1) as payments_converted
|
SUM(coalesce(payments.amount - payments.refunded,0)) * IFNULL(payments.exchange_rate ,1) as payments_converted,
|
||||||
|
payments.currency_id as currency_id
|
||||||
FROM clients
|
FROM clients
|
||||||
INNER JOIN
|
INNER JOIN
|
||||||
payments ON
|
payments ON
|
||||||
@ -145,14 +216,14 @@ class ProfitLoss
|
|||||||
AND payments.is_deleted = false
|
AND payments.is_deleted = false
|
||||||
AND payments.company_id = :company_id
|
AND payments.company_id = :company_id
|
||||||
AND (payments.date BETWEEN :start_date AND :end_date)
|
AND (payments.date BETWEEN :start_date AND :end_date)
|
||||||
GROUP BY payments.currency_id
|
GROUP BY currency_id
|
||||||
ORDER BY payments.currency_id;
|
ORDER BY currency_id;
|
||||||
"), ['company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
|
"), ['company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function expenseCalc()
|
private function expenseData()
|
||||||
{
|
{
|
||||||
|
|
||||||
$expenses = Expense::where('company_id', $this->company->id)
|
$expenses = Expense::where('company_id', $this->company->id)
|
||||||
@ -186,6 +257,8 @@ class ProfitLoss
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->expenses = $data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTax($expense)
|
private function getTax($expense)
|
||||||
@ -247,22 +320,26 @@ class ProfitLoss
|
|||||||
private function setBillingReportType()
|
private function setBillingReportType()
|
||||||
{
|
{
|
||||||
|
|
||||||
if(array_key_exists('income_billed', $this->payload))
|
if(array_key_exists('is_income_billed', $this->payload))
|
||||||
$this->is_income_billed = boolval($this->payload['income_billed']);
|
$this->is_income_billed = boolval($this->payload['is_income_billed']);
|
||||||
|
|
||||||
if(array_key_exists('expense_billed', $this->payload))
|
if(array_key_exists('is_expense_billed', $this->payload))
|
||||||
$this->is_expense_billed = boolval($this->payload['expense_billed']);
|
$this->is_expense_billed = boolval($this->payload['is_expense_billed']);
|
||||||
|
|
||||||
if(array_key_exists('include_tax', $this->payload))
|
if(array_key_exists('include_tax', $this->payload))
|
||||||
$this->is_tax_included = boolval($this->payload['include_tax']);
|
$this->is_tax_included = boolval($this->payload['include_tax']);
|
||||||
|
|
||||||
|
$this->addDateRange();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addDateRange($query)
|
private function addDateRange()
|
||||||
{
|
{
|
||||||
|
$date_range = 'this_year';
|
||||||
|
|
||||||
|
if(array_key_exists('date_range', $this->payload))
|
||||||
$date_range = $this->payload['date_range'];
|
$date_range = $this->payload['date_range'];
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -323,6 +400,8 @@ class ProfitLoss
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,18 +40,6 @@ class CompanyFactory extends Factory
|
|||||||
'default_password_timeout' => 30*60000,
|
'default_password_timeout' => 30*60000,
|
||||||
'enabled_modules' => config('ninja.enabled_modules'),
|
'enabled_modules' => config('ninja.enabled_modules'),
|
||||||
'custom_fields' => (object) [
|
'custom_fields' => (object) [
|
||||||
//'invoice1' => 'Custom Date|date',
|
|
||||||
// 'invoice2' => '2|switch',
|
|
||||||
// 'invoice3' => '3|',
|
|
||||||
// 'invoice4' => '4',
|
|
||||||
// 'client1'=>'1',
|
|
||||||
// 'client2'=>'2',
|
|
||||||
// 'client3'=>'3|date',
|
|
||||||
// 'client4'=>'4|switch',
|
|
||||||
// 'company1'=>'1|date',
|
|
||||||
// 'company2'=>'2|switch',
|
|
||||||
// 'company3'=>'3',
|
|
||||||
// 'company4'=>'4',
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -5,66 +5,66 @@
|
|||||||
|
|
||||||
<p><b>If your logo imported correctly it will display below. If it didn't import, you'll need to reupload your logo</b></p>
|
<p><b>If your logo imported correctly it will display below. If it didn't import, you'll need to reupload your logo</b></p>
|
||||||
|
|
||||||
<p><img src="{{ $company->present()->logo() }}"></p>
|
<p><img src="{{ $logo }}"></p>
|
||||||
|
|
||||||
@if(isset($company) && $company->clients->count() >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.clients') }}:</b> {{ $company->clients->count() }} </p>
|
<p><b>{{ ctrans('texts.clients') }}:</b> {{ $client_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->products) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.products') }}:</b> {{ count($company->products) }} </p>
|
<p><b>{{ ctrans('texts.products') }}:</b> {{ $product_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->invoices) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.invoices') }}:</b> {{ count($company->invoices) }} </p>
|
<p><b>{{ ctrans('texts.invoices') }}:</b> {{ $invoice_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->payments) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.payments') }}:</b> {{ count($company->payments) }} </p>
|
<p><b>{{ ctrans('texts.payments') }}:</b> {{ $payment_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->recurring_invoices) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.recurring_invoices') }}:</b> {{ count($company->recurring_invoices) }} </p>
|
<p><b>{{ ctrans('texts.recurring_invoices') }}:</b> {{ $recurring_invoice_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->quotes) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.quotes') }}:</b> {{ count($company->quotes) }} </p>
|
<p><b>{{ ctrans('texts.quotes') }}:</b> {{ $quote_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->credits) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.credits') }}:</b> {{ count($company->credits) }} </p>
|
<p><b>{{ ctrans('texts.credits') }}:</b> {{ $credit_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->projects) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.projects') }}:</b> {{ count($company->projects) }} </p>
|
<p><b>{{ ctrans('texts.projects') }}:</b> {{ $project_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->tasks) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.tasks') }}:</b> {{ count($company->tasks) }} </p>
|
<p><b>{{ ctrans('texts.tasks') }}:</b> {{ $task_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->vendors) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.vendors') }}:</b> {{ count($company->vendors) }} </p>
|
<p><b>{{ ctrans('texts.vendors') }}:</b> {{ $vendor_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->expenses) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.expenses') }}:</b> {{ count($company->expenses) }} </p>
|
<p><b>{{ ctrans('texts.expenses') }}:</b> {{ $expense_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->company_gateways) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.gateways') }}:</b> {{ count($company->company_gateways) }} </p>
|
<p><b>{{ ctrans('texts.gateways') }}:</b> {{ $company_gateway_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->client_gateway_tokens) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.tokens') }}:</b> {{ count($company->client_gateway_tokens) }} </p>
|
<p><b>{{ ctrans('texts.tokens') }}:</b> {{ $client_gateway_token_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->tax_rates) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.tax_rates') }}:</b> {{ count($company->tax_rates) }} </p>
|
<p><b>{{ ctrans('texts.tax_rates') }}:</b> {{ $tax_rate_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($company) && count($company->documents) >=1)
|
@if(isset($company))
|
||||||
<p><b>{{ ctrans('texts.documents') }}:</b> {{ count($company->documents) }} </p>
|
<p><b>{{ ctrans('texts.documents') }}:</b> {{ $document_count }} </p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(isset($check_data))
|
@if(isset($check_data))
|
||||||
|
@ -10,8 +10,12 @@
|
|||||||
*/
|
*/
|
||||||
namespace Tests\Feature\Export;
|
namespace Tests\Feature\Export;
|
||||||
|
|
||||||
|
use App\Factory\InvoiceFactory;
|
||||||
|
use App\Models\Account;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Models\User;
|
||||||
use App\Services\Report\ProfitLoss;
|
use App\Services\Report\ProfitLoss;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
@ -27,18 +31,19 @@ use Tests\TestCase;
|
|||||||
class ProfitAndLossReportTest extends TestCase
|
class ProfitAndLossReportTest extends TestCase
|
||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
use MockAccountData;
|
|
||||||
|
public $faker;
|
||||||
|
|
||||||
public function setUp() :void
|
public function setUp() :void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->faker = \Faker\Factory::create();
|
||||||
|
|
||||||
$this->withoutMiddleware(
|
$this->withoutMiddleware(
|
||||||
ThrottleRequests::class
|
ThrottleRequests::class
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->makeTestData();
|
|
||||||
|
|
||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
|
|
||||||
$this->buildData();
|
$this->buildData();
|
||||||
@ -46,6 +51,8 @@ class ProfitAndLossReportTest extends TestCase
|
|||||||
|
|
||||||
public $company;
|
public $company;
|
||||||
|
|
||||||
|
public $user;
|
||||||
|
|
||||||
public $payload;
|
public $payload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +69,7 @@ class ProfitAndLossReportTest extends TestCase
|
|||||||
last_quarter
|
last_quarter
|
||||||
this_year
|
this_year
|
||||||
custom
|
custom
|
||||||
income_billed - true = Invoiced || false = Payments
|
is_income_billed - true = Invoiced || false = Payments
|
||||||
expense_billed - true = Expensed || false = Expenses marked as paid
|
expense_billed - true = Expensed || false = Expenses marked as paid
|
||||||
include_tax - true tax_included || false - tax_excluded
|
include_tax - true tax_included || false - tax_excluded
|
||||||
|
|
||||||
@ -70,15 +77,31 @@ class ProfitAndLossReportTest extends TestCase
|
|||||||
|
|
||||||
private function buildData()
|
private function buildData()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$account = Account::factory()->create([
|
||||||
|
'hosted_client_count' => 1000,
|
||||||
|
'hosted_company_count' => 1000
|
||||||
|
]);
|
||||||
|
|
||||||
|
$account->num_users = 3;
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
$this->user = User::factory()->create([
|
||||||
|
'account_id' => $account->id,
|
||||||
|
'confirmation_code' => 'xyz123',
|
||||||
|
'email' => $this->faker->unique()->safeEmail,
|
||||||
|
]);
|
||||||
|
|
||||||
$this->company = Company::factory()->create([
|
$this->company = Company::factory()->create([
|
||||||
'account_id' => $this->account->id,
|
'account_id' => $account->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->payload = [
|
$this->payload = [
|
||||||
'start_date' => '2000-01-01',
|
'start_date' => '2000-01-01',
|
||||||
'end_date' => '2030-01-11',
|
'end_date' => '2030-01-11',
|
||||||
'date_range' => 'custom',
|
'date_range' => 'custom',
|
||||||
'income_billed' => true,
|
'is_income_billed' => true,
|
||||||
'include_tax' => false
|
'include_tax' => false
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -92,4 +115,53 @@ class ProfitAndLossReportTest extends TestCase
|
|||||||
$this->assertInstanceOf(ProfitLoss::class, $pl);
|
$this->assertInstanceOf(ProfitLoss::class, $pl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInvoiceIncome()
|
||||||
|
{
|
||||||
|
|
||||||
|
$client = Client::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'is_deleted' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Invoice::factory()->create([
|
||||||
|
// 'client_id' => $client->id,
|
||||||
|
// 'user_id' => $this->user->id,
|
||||||
|
// 'company_id' => $this->company->id,
|
||||||
|
// 'amount' => 10,
|
||||||
|
// 'balance' => 10,
|
||||||
|
// 'status_id' => 2,
|
||||||
|
// 'total_taxes' => 1,
|
||||||
|
// 'date' => '2022-01-01',
|
||||||
|
// 'terms' => 'nada',
|
||||||
|
// 'discount' => 0,
|
||||||
|
// 'tax_rate1' => 0,
|
||||||
|
// 'tax_rate2' => 0,
|
||||||
|
// 'tax_rate3' => 0,
|
||||||
|
// 'tax_name1' => '',
|
||||||
|
// 'tax_name2' => '',
|
||||||
|
// 'tax_name3' => '',
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
$i = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||||
|
$i->client_id = $client->id;
|
||||||
|
$i->amount = 10;
|
||||||
|
$i->balance = 10;
|
||||||
|
$i->status_id = 2;
|
||||||
|
$i->terms = "nada";
|
||||||
|
$i->total_taxes = 1;
|
||||||
|
$i->save();
|
||||||
|
|
||||||
|
nlog(Invoice::where('company_id', $this->company->id)->get()->toArray());
|
||||||
|
|
||||||
|
$pl = new ProfitLoss($this->company, $this->payload);
|
||||||
|
$pl->build();
|
||||||
|
|
||||||
|
|
||||||
|
$this->assertEquals(9.0, $pl->getIncome());
|
||||||
|
$this->assertEquals(1, $pl->getIncomeTaxes());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
namespace Tests\Unit\ValidationRules;
|
||||||
|
|
||||||
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||||
|
use App\Http\ValidationRules\Account\BlackListRule;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
class UniqueInvoiceNumberValidationTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use MakesHash;
|
||||||
|
use MockAccountData;
|
||||||
|
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(
|
||||||
|
ThrottleRequests::class
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testValidEmailRule()
|
||||||
|
{
|
||||||
|
auth()->login($this->user);
|
||||||
|
auth()->user()->setCompany($this->company);
|
||||||
|
|
||||||
|
Invoice::factory()->create([
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'paid_to_date' => 100,
|
||||||
|
'status_id' => 4,
|
||||||
|
'date' => now(),
|
||||||
|
'due_date'=> now(),
|
||||||
|
'number' => 'db_record'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
'paid_to_date' => 100,
|
||||||
|
'status_id' => 4,
|
||||||
|
'date' => now(),
|
||||||
|
'due_date'=> now(),
|
||||||
|
'number' => 'db_record'
|
||||||
|
];
|
||||||
|
|
||||||
|
$rules = (new StoreInvoiceRequest())->rules();
|
||||||
|
|
||||||
|
$validator = Validator::make($data, $rules);
|
||||||
|
|
||||||
|
$this->assertFalse($validator->passes());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user