1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Fixes for query grammar

This commit is contained in:
David Bomba 2023-08-21 11:29:31 +10:00
parent 1182184306
commit 805229f4c0
55 changed files with 164 additions and 141 deletions

View File

@ -564,7 +564,7 @@ class CheckData extends Command
GROUP BY clients.id
HAVING payments_applied != client_paid_to_date
ORDER BY clients.id;
"));
")->getValue(DB::connection()->getQueryGrammar()));
return $results;
}
@ -583,7 +583,7 @@ class CheckData extends Command
AND paymentables.amount > 0
AND payments.is_deleted = 0
AND payments.client_id = ?;
"), [App\Models\Credit::class, $client->id]);
")->getValue(DB::connection()->getQueryGrammar()), [App\Models\Credit::class, $client->id]);
return $results;
}
@ -636,7 +636,7 @@ class CheckData extends Command
->where('clients.updated_at', '>', now()->subDays(2))
->groupBy('clients.id')
->havingRaw('clients.paid_to_date != sum(coalesce(payments.amount - payments.refunded, 0))')
->get(['clients.id', 'clients.paid_to_date', DB::raw('sum(coalesce(payments.amount - payments.refunded, 0)) as amount')]);
->get(['clients.id', 'clients.paid_to_date', DB::raw('sum(coalesce(payments.amount - payments.refunded, 0)) as amount')->getValue(DB::connection()->getQueryGrammar())]);
/* Due to accounting differences we need to perform a second loop here to ensure there actually is an issue */
$clients->each(function ($client_record) use ($credit_total_applied) {
@ -656,7 +656,7 @@ class CheckData extends Command
$p = Payment::where('client_id', $client->id)
->where('is_deleted', 0)
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
->sum(DB::Raw('amount - applied'));
->sum(DB::Raw('amount - applied')->getValue(DB::connection()->getQueryGrammar()));
$total_invoice_payments += $p;
@ -736,7 +736,7 @@ class CheckData extends Command
GROUP BY clients.id
HAVING invoice_balance != clients.balance
ORDER BY clients.id;
"));
")->getValue(DB::connection()->getQueryGrammar()));
return $results;
}
@ -827,7 +827,7 @@ class CheckData extends Command
GROUP BY clients.id
HAVING(invoices_balance != clients.balance)
ORDER BY clients.id;
"));
")->getValue(DB::connection()->getQueryGrammar()));
return $results;
}
@ -961,7 +961,7 @@ class CheckData extends Command
}
$records = DB::table($table)
->join($tableName, "{$tableName}.id", '=', "{$table}.{$field}_id")
->where("{$table}.{$company_id}", '!=', DB::raw("{$tableName}.company_id"))
->where("{$table}.{$company_id}", '!=', DB::raw("{$tableName}.company_id")->getValue(DB::connection()->getQueryGrammar()))
->get(["{$table}.id"]);
if ($records->count()) {

View File

@ -734,7 +734,7 @@ class BaseImport
{
$user = User::where('account_id', $this->company->account->id)
->where(
\DB::raw('CONCAT_WS(" ", first_name, last_name)'),
\DB::raw('CONCAT_WS(" ", first_name, last_name)')->getValue(DB::connection()->getQueryGrammar()),
'like',
'%'.$user_hash.'%'
)

View File

@ -158,17 +158,6 @@ class CheckCompanyData implements ShouldQueue
$total_invoice_payments += ($total_amount - $total_refund);
}
//10/02/21
// foreach ($client->payments as $payment) {
// $credit_total_applied += $payment->paymentables->where('paymentable_type', App\Models\Credit::class)->sum(DB::raw('amount'));
// }
// if ($credit_total_applied < 0) {
// $total_invoice_payments += $credit_total_applied;
// } //todo this is contentious
// nlog("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}");
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
$wrong_paid_to_dates++;
@ -287,7 +276,7 @@ class CheckCompanyData implements ShouldQueue
// $clients->where('clients.id', '=', $this->option('client_id'));
// }
$clients = $clients->get(['clients.id', DB::raw('count(client_contacts.id)')]);
$clients = $clients->get(['clients.id', DB::raw('count(client_contacts.id)')->getValue(DB::connection()->getQueryGrammar())]);
$this->company_data[] = $clients->count().' clients without a single primary contact';
if ($clients->count() > 0) {
@ -326,7 +315,7 @@ class CheckCompanyData implements ShouldQueue
}
$records = DB::table($table)
->join($tableName, "{$tableName}.id", '=', "{$table}.{$field}_id")
->where("{$table}.{$company_id}", '!=', DB::raw("{$tableName}.company_id"))
->where("{$table}.{$company_id}", '!=', DB::raw("{$tableName}.company_id")->getValue(DB::connection()->getQueryGrammar()))
->get(["{$table}.id"]);
if ($records->count()) {

View File

@ -302,7 +302,7 @@ class Import implements ShouldQueue
// 10/02/21
foreach ($client->payments as $payment) {
$credit_total_applied += $payment->paymentables()->where('paymentable_type', \App\Models\Credit::class)->get()->sum(\DB::raw('amount'));
$credit_total_applied += $payment->paymentables()->where('paymentable_type', \App\Models\Credit::class)->get()->sum(\DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
}
if ($credit_total_applied < 0) {

View File

@ -34,7 +34,7 @@ trait ChartQueries
AND (expenses.date BETWEEN :start_date AND :end_date)
{$user_filter}
GROUP BY currency_id
"), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
}
public function getExpenseChartQuery($start_date, $end_date, $currency_id)
@ -54,7 +54,7 @@ trait ChartQueries
{$user_filter}
GROUP BY expenses.date
HAVING currency_id = :currency_id
"), [
")->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => $this->company->settings->currency_id,
'currency_id' => $currency_id,
'company_id' => $this->company->id,
@ -80,7 +80,7 @@ trait ChartQueries
AND payments.company_id = :company_id
AND (payments.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
"), [
")->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => $this->company->settings->currency_id,
'company_id' => $this->company->id,
'start_date' => $start_date,
@ -106,7 +106,7 @@ trait ChartQueries
AND (payments.date BETWEEN :start_date AND :end_date)
GROUP BY payments.date
HAVING currency_id = :currency_id
"), [
")->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => $this->company->settings->currency_id,
'currency_id' => $currency_id,
'company_id' => $this->company->id,
@ -139,7 +139,7 @@ trait ChartQueries
AND invoices.balance > 0
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
"), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
}
public function getRevenueQueryX($start_date, $end_date)
@ -161,7 +161,7 @@ trait ChartQueries
AND invoices.status_id IN (3,4)
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
"), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
}
public function getRevenueQuery($start_date, $end_date)
@ -179,7 +179,7 @@ trait ChartQueries
AND payments.status_id IN (1,4,5,6)
AND (payments.date BETWEEN :start_date AND :end_date)
GROUP BY payments.currency_id
"), ['company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
}
public function getInvoicesQuery($start_date, $end_date)
@ -201,7 +201,7 @@ trait ChartQueries
AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
"), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
}
public function getOutstandingChartQuery($start_date, $end_date, $currency_id)
@ -224,7 +224,7 @@ trait ChartQueries
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY invoices.date
HAVING currency_id = :currency_id
"), [
")->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => (int) $this->company->settings->currency_id,
'currency_id' => $currency_id,
'company_id' => $this->company->id,
@ -254,7 +254,7 @@ trait ChartQueries
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY invoices.date
HAVING currency_id = :currency_id
"), [
")->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => (int) $this->company->settings->currency_id,
'currency_id' => $currency_id,
'company_id' => $this->company->id,

View File

@ -23,6 +23,7 @@ trait ChartQueriesLegacy
*/
public function getExpenseQuery($start_date, $end_date)
{
return DB::select(DB::raw('
SELECT sum(expenses.amount) as amount,
IFNULL(expenses.currency_id, :company_currency) as currency_id
@ -31,7 +32,7 @@ trait ChartQueriesLegacy
AND expenses.company_id = :company_id
AND (expenses.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
'), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
')->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
}
public function getExpenseChartQuery($start_date, $end_date, $currency_id)
@ -47,7 +48,7 @@ trait ChartQueriesLegacy
AND expenses.is_deleted = 0
GROUP BY expenses.date
HAVING currency_id = :currency_id
'), [
')->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => $this->company->settings->currency_id,
'currency_id' => $currency_id,
'company_id' => $this->company->id,
@ -69,7 +70,7 @@ trait ChartQueriesLegacy
AND payments.company_id = :company_id
AND (payments.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
'), [
')->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => $this->company->settings->currency_id,
'company_id' => $this->company->id,
'start_date' => $start_date,
@ -91,7 +92,7 @@ trait ChartQueriesLegacy
AND payments.is_deleted = 0
GROUP BY payments.date
HAVING currency_id = :currency_id
'), [
')->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => $this->company->settings->currency_id,
'currency_id' => $currency_id,
'company_id' => $this->company->id,
@ -119,7 +120,7 @@ trait ChartQueriesLegacy
AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
"), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]);
}
public function getRevenueQuery($start_date, $end_date)
@ -158,7 +159,7 @@ trait ChartQueriesLegacy
AND invoices.is_deleted = 0
GROUP BY invoices.date
HAVING currency_id = :currency_id
"), [
")->getValue(DB::connection()->getQueryGrammar()), [
'company_currency' => (int) $this->company->settings->currency_id,
'currency_id' => $currency_id,
'company_id' => $this->company->id,

View File

@ -96,17 +96,17 @@ class HandleRestore extends AbstractService
$this->adjustment_amount += $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount'));
->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$this->adjustment_amount += $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('refunded'));
->sum(DB::raw('refunded')->getValue(DB::connection()->getQueryGrammar()));
//14/07/2023 - do not include credits in the payment amount
$this->adjustment_amount -= $payment->paymentables
->where('paymentable_type', '=', 'App\Models\Credit')
->sum(DB::raw('amount'));
->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
}

View File

@ -88,17 +88,17 @@ class MarkInvoiceDeleted extends AbstractService
$payment_adjustment = $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount'));
->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$payment_adjustment -= $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('refunded'));
->sum(DB::raw('refunded')->getValue(DB::connection()->getQueryGrammar()));
//14-07-2023 - Do not include credits in the payment adjustment.
$payment_adjustment -= $payment->paymentables
->where('paymentable_type', '=', 'App\Models\Credit')
->sum(DB::raw('amount'));
->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$payment->amount -= $payment_adjustment;
$payment->applied -= $payment_adjustment;

View File

@ -250,7 +250,7 @@ class ProfitLoss
AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
"), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
}
/**
@ -421,7 +421,7 @@ class ProfitLoss
AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
"), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
}
/**
@ -447,7 +447,7 @@ class ProfitLoss
AND (payments.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
ORDER BY currency_id;
'), ['company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
')->getValue(DB::connection()->getQueryGrammar()), ['company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
}
private function expenseData()
@ -553,7 +553,7 @@ class ProfitLoss
AND expenses.company_id = :company_id
AND (expenses.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
'), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
')->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
}
private function setBillingReportType()

View File

@ -28,7 +28,7 @@ class AccountTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
//'default_company',
//'user',
//'company_users'
@ -37,7 +37,7 @@ class AccountTransformer extends EntityTransformer
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'default_company',
'company_users',
'companies',

View File

@ -34,12 +34,12 @@ class ActivityTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [];
protected array $defaultIncludes = [];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'history',
'user',
'client',

View File

@ -24,7 +24,7 @@ class ArraySerializer extends FractalArraySerializer
*
* @return array
*/
public function collection($resourceKey, array $data)
public function collection(?string $resourceKey, array $data): array
{
return $data;
}
@ -35,7 +35,7 @@ class ArraySerializer extends FractalArraySerializer
*
* @return array
*/
public function item($resourceKey, array $data)
public function item(?string $resourceKey, array $data): array
{
return $data;
}

View File

@ -28,7 +28,7 @@ class BankIntegrationTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
//'default_company',
//'user',
//'company_users'
@ -37,7 +37,7 @@ class BankIntegrationTransformer extends EntityTransformer
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'company',
'account',
'bank_transactions',

View File

@ -29,13 +29,13 @@ class BankTransactionRuleTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'company',
'vendor',
'client',

View File

@ -28,13 +28,13 @@ class BankTransactionTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'company',
// 'expense',
'payment',

View File

@ -29,7 +29,7 @@ class ClientTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'contacts',
'documents',
'gateway_tokens',
@ -38,7 +38,7 @@ class ClientTransformer extends EntityTransformer
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'activities',
'ledger',
'system_logs',

View File

@ -29,13 +29,13 @@ class CompanyGatewayTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'system_logs',
'gateway',
];

View File

@ -24,13 +24,13 @@ class CompanyTokenHashedTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
/**

View File

@ -24,13 +24,13 @@ class CompanyTokenTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
/**

View File

@ -59,14 +59,14 @@ class CompanyTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
'documents',
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'documents',
'users',
'designs',

View File

@ -22,14 +22,14 @@ class CompanyUserTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
// 'user',
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'user',
'company',
'token',

View File

@ -19,11 +19,11 @@ class InvoiceTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
// 'invoice_items',
];
protected $availableIncludes = [
protected array $availableIncludes = [
];
public function transform(Invoice $invoice)

View File

@ -24,12 +24,12 @@ class CreditTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'invitations',
'documents',
];
protected $availableIncludes = [
protected array $availableIncludes = [
'activities',
'client',
];

View File

@ -26,13 +26,13 @@ class DesignTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
/**

View File

@ -20,9 +20,9 @@ class DocumentTransformer extends EntityTransformer
protected $serializer;
protected $defaultIncludes = [];
protected array $defaultIncludes = [];
protected $availableIncludes = [];
protected array $availableIncludes = [];
public function __construct($serializer = null)
{

View File

@ -44,7 +44,7 @@ class EntityTransformer extends TransformerAbstract
return $this->item($data, $transformer, $entityType);
}
public function getDefaultIncludes()
public function getDefaultIncludes(): array
{
return $this->defaultIncludes;
}

View File

@ -23,13 +23,13 @@ class ExpenseCategoryTransformer extends EntityTransformer
use MakesHash;
use SoftDeletes;
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
/**

View File

@ -30,14 +30,14 @@ class ExpenseTransformer extends EntityTransformer
use MakesHash;
use SoftDeletes;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'documents',
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'client',
'vendor',
'category',

View File

@ -21,13 +21,13 @@ class GatewayTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
/**

View File

@ -23,14 +23,14 @@ class GroupSettingTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'documents',
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
/**

View File

@ -19,11 +19,11 @@ class InvoiceHistoryTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
// 'activity',
];
protected $availableIncludes = [
protected array $availableIncludes = [
'activity',
];

View File

@ -24,12 +24,12 @@ class InvoiceTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'invitations',
'documents',
];
protected $availableIncludes = [
protected array $availableIncludes = [
'payments',
'client',
'activities',

View File

@ -24,12 +24,12 @@ class PaymentTransformer extends EntityTransformer
protected $serializer;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'paymentables',
'documents',
];
protected $availableIncludes = [
protected array $availableIncludes = [
'client',
'invoices',
];

View File

@ -21,9 +21,9 @@ class PaymentableTransformer extends EntityTransformer
protected $serializer;
protected $defaultIncludes = [];
protected array $defaultIncludes = [];
protected $availableIncludes = [];
protected array $availableIncludes = [];
public function __construct($serializer = null)
{

View File

@ -22,14 +22,14 @@ class ProductTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'documents',
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'company',
'user',
];

View File

@ -25,14 +25,14 @@ class ProjectTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'documents',
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'client',
'tasks',
];

View File

@ -22,12 +22,12 @@ class PurchaseOrderTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'invitations',
'documents'
];
protected $availableIncludes = [
protected array $availableIncludes = [
'expense',
'vendor',
];

View File

@ -24,12 +24,12 @@ class QuoteTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'invitations',
'documents',
];
protected $availableIncludes = [
protected array $availableIncludes = [
'activities',
'client',
];

View File

@ -27,14 +27,14 @@ class RecurringExpenseTransformer extends EntityTransformer
use MakesHash;
use SoftDeletes;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'documents',
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'documents',
'client',
'vendor',

View File

@ -23,12 +23,12 @@ class RecurringInvoiceTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'invitations',
'documents',
];
protected $availableIncludes = [
protected array $availableIncludes = [
'activities',
'client',
];

View File

@ -22,12 +22,12 @@ class RecurringQuoteTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'invitations',
'documents',
];
protected $availableIncludes = [
protected array $availableIncludes = [
'invitations',
'documents',
'activities',

View File

@ -26,13 +26,13 @@ class CompanyShopProfileTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
/**

View File

@ -22,13 +22,13 @@ class SubscriptionTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
];
public function transform(Subscription $subscription): array

View File

@ -9,12 +9,12 @@ class SystemLogTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [];
protected array $defaultIncludes = [];
/**
* @var array
*/
protected $availableIncludes = [];
protected array $availableIncludes = [];
/**
* @param SystemLog $system_log

View File

@ -28,7 +28,7 @@ class TaskTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'documents',
'project',
];
@ -36,7 +36,7 @@ class TaskTransformer extends EntityTransformer
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'client',
'status',
'project',

View File

@ -25,14 +25,14 @@ class UserTransformer extends EntityTransformer
/**
* @var array
*/
protected $defaultIncludes = [
protected array $defaultIncludes = [
//'company_user'
];
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'companies',
'company_users',
'company_user',

View File

@ -25,7 +25,7 @@ class VendorTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
protected array $defaultIncludes = [
'contacts',
'documents',
];
@ -33,7 +33,7 @@ class VendorTransformer extends EntityTransformer
/**
* @var array
*/
protected $availableIncludes = [
protected array $availableIncludes = [
'activities',
];

View File

@ -9,12 +9,12 @@ class WebhookTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [];
protected array $defaultIncludes = [];
/**
* @var array
*/
protected $availableIncludes = [];
protected array $availableIncludes = [];
/**
* @param Webhook $webhook

View File

@ -43,7 +43,7 @@ class Ninja
public static function getDebugInfo()
{
$mysql_version = DB::select(DB::raw('select version() as version'))[0]->version;
$mysql_version = DB::select(DB::raw('select version() as version')->getValue(DB::connection()->getQueryGrammar()))[0]->version;
$version = request()->input('version', 'No Version Supplied.');

View File

@ -23,6 +23,7 @@
<env name="MAIL_MAILER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="DB_STRICT" value="FALSE"/>
</php>
<logging/>
</phpunit>

View File

@ -11,10 +11,12 @@
namespace Tests\Feature\Export;
use App\Utils\Traits\MakesHash;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\MockAccountData;
use Tests\TestCase;
use Tests\MockAccountData;
use App\Utils\Traits\MakesHash;
use Illuminate\Support\Facades\Event;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling;
/**
* @test
@ -23,7 +25,7 @@ class ReportApiTest extends TestCase
{
use MakesHash;
use MockAccountData;
public $faker;
protected function setUp() :void
@ -36,8 +38,7 @@ class ReportApiTest extends TestCase
ThrottleRequests::class
);
$this->withoutExceptionHandling();
// $this->withoutExceptionHandling();
$this->makeTestData();
}

View File

@ -11,18 +11,21 @@
namespace Tests\Feature\Export;
use App\DataMapper\CompanySettings;
use App\Export\CSV\ProductSalesExport;
use App\Factory\InvoiceItemFactory;
use App\Models\Account;
use Tests\TestCase;
use App\Models\User;
use App\Models\Client;
use App\Models\Account;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\User;
use App\Services\Report\UserSalesReport;
use App\Utils\Traits\AppSetup;
use App\Utils\Traits\MakesHash;
use App\DataMapper\CompanySettings;
use App\Factory\InvoiceItemFactory;
use Illuminate\Support\Facades\Cache;
use App\Export\CSV\ProductSalesExport;
use Illuminate\Support\Facades\Schema;
use App\Services\Report\UserSalesReport;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\TestCase;
/**
* @test
@ -44,6 +47,32 @@ class UserSalesReportTest extends TestCase
);
$this->withoutExceptionHandling();
/* Warm up the cache !*/
$cached_tables = config('ninja.cached_tables');
$this->artisan('db:seed --force');
foreach ($cached_tables as $name => $class) {
// check that the table exists in case the migration is pending
if (! Schema::hasTable((new $class())->getTable())) {
continue;
}
if ($name == 'payment_terms') {
$orderBy = 'num_days';
} elseif ($name == 'fonts') {
$orderBy = 'sort_order';
} elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
$orderBy = 'name';
} else {
$orderBy = 'id';
}
$tableData = $class::orderBy($orderBy)->get();
if ($tableData->count()) {
Cache::forever($name, $tableData);
}
}
}
public $company;

View File

@ -57,7 +57,6 @@ use App\Models\VendorContact;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesHash;
use App\Utils\TruthSource;
use Illuminate\Foundation\Testing\WithoutEvents;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
@ -71,7 +70,6 @@ trait MockAccountData
{
use MakesHash;
use GeneratesCounter;
use WithoutEvents;
/**
* @var

View File

@ -2,6 +2,7 @@
namespace Tests;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase

View File

@ -15,10 +15,13 @@ namespace Tests\Unit;
use App\Models\Account;
use App\Models\Company;
use App\Models\Document;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
class WithTypeHelpersTest extends TestCase
{
use DatabaseMigrations;
public function testIsImageHelper(): void
{
$account = Account::factory()->create();