Fixes for tests

This commit is contained in:
David Bomba 2019-09-11 13:46:23 +10:00
parent e329c24879
commit af28b02fae
10 changed files with 52 additions and 40 deletions

View File

@ -31,8 +31,7 @@ class PaymentFilters extends QueryFilters
* *
*/ */
public function filter(string $filter = '') : Builder public function filter(string $filter = '') : Builder
{Log::error('ewwo'); {
Log::error($filter);
if(strlen($filter) == 0) if(strlen($filter) == 0)
return $this->builder; return $this->builder;

View File

@ -62,9 +62,9 @@ class InvoiceController extends Controller
})->editColumn('due_date', function ($invoice){ })->editColumn('due_date', function ($invoice){
return $this->formatDate($invoice->due_date, $invoice->client->date_format()); return $this->formatDate($invoice->due_date, $invoice->client->date_format());
})->editColumn('balance', function ($invoice) { })->editColumn('balance', function ($invoice) {
return Number::formatMoney($invoice->balance, $invoice->client->currency, $invoice->client->country, $invoice->client->getMergedSettings()); return Number::formatMoney($invoice->balance, $invoice->client);
})->editColumn('amount', function ($invoice) { })->editColumn('amount', function ($invoice) {
return Number::formatMoney($invoice->amount, $invoice->client->currency, $invoice->client->country, $invoice->client->getMergedSettings()); return Number::formatMoney($invoice->amount, $invoice->client);
}) })
->rawColumns(['checkbox', 'action', 'status_id']) ->rawColumns(['checkbox', 'action', 'status_id'])
->make(true); ->make(true);
@ -125,7 +125,7 @@ class InvoiceController extends Controller
$invoices->filter(function ($invoice){ $invoices->filter(function ($invoice){
return $invoice->isPayable(); return $invoice->isPayable();
})->map(function ($invoice){ })->map(function ($invoice){
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client->currency, $invoice->client->country, $invoice->client->getMergedSettings()); $invoice->balance = Number::formatMoney($invoice->balance, $invoice->client;
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format()); $invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
return $invoice; return $invoice;

View File

@ -47,7 +47,7 @@ class QueryLogging
$count = count($queries); $count = count($queries);
$timeEnd = microtime(true); $timeEnd = microtime(true);
$time = $timeEnd - $timeStart; $time = $timeEnd - $timeStart;
//Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time); Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
// if($count > 16) // if($count > 16)
// Log::info($queries); // Log::info($queries);

View File

@ -49,7 +49,7 @@ class StoreClientRequest extends Request
} }
Log::error($rules); // Log::error($rules);
return $rules; return $rules;

View File

@ -154,16 +154,28 @@ class Client extends BaseModel
public function getSetting($setting) public function getSetting($setting)
{ {
// Log::error('does prop exist? = ' . property_exists($this->settings, $setting));
// Log::error('does prop have val? = ' . isset($this->settings->{str_replace("'","",$setting)}));
// Log::error('client');
// Log::error(print_r($this,1));
// Log::error('company');
// Log::error(print_r($this->company,1));
// Log::error('company settings');
// Log::error(print_r($this->company->settings,1));
// Log::error('cli = '.$this->settings->{$setting});
// Log::error('co = '.$this->company->settings->{$setting});
//check client level first //check client level first
if(property_exists($this->settings, $setting) && isset($this->settings->{$setting})) if($this->settings && isset($this->settings->{$setting}) && property_exists($this->settings, $setting))
return $this->settings->{$setting}; return $this->settings->{$setting};
//check group level (if a group is assigned) //check group level (if a group is assigned)
if($this->group_settings && property_exists($this->group_settings, $setting) && isset($this->group_settings->{$setting})) if($this->group_settings && isset($this->group_settings->{$setting}) && property_exists($this->group_settings, $setting))
return $this->group_settings->{$setting}; return $this->group_settings->{$setting};
//check company level //check company level
if(isset($this->company->settings->{$setting}) && property_exists($this->company->settings, $setting))
return $this->company->settings->{$setting};
} }

View File

@ -58,30 +58,31 @@ class Number
* *
* @return string The formatted value * @return string The formatted value
*/ */
public static function formatMoney($value, $currency, $country, $settings) :string //public static function formatMoney($value, $currency, $country, $settings) :string
public static function formatMoney($value, $client) :string
{ {
$thousand = $currency->thousand_separator; $thousand = $client->currency->thousand_separator;
$decimal = $currency->decimal_separator; $decimal = $client->currency->decimal_separator;
$precision = $currency->precision; $precision = $client->currency->precision;
$code = $currency->code; $code = $client->currency->code;
$swapSymbol = $country->swap_currency_symbol; $swapSymbol = $client->country->swap_currency_symbol;
/* Country settings override client settings */ /* Country settings override client settings */
if ($country->thousand_separator) if ($client->country->thousand_separator)
$thousand = $country->thousand_separator; $thousand = $client->country->thousand_separator;
if ($country->decimal_separator) if ($client->country->decimal_separator)
$decimal = $country->decimal_separator; $decimal = $client->country->decimal_separator;
$value = number_format($value, $precision, $decimal, $thousand); $value = number_format($value, $precision, $decimal, $thousand);
$symbol = $currency->symbol; $symbol = $client->currency->symbol;
if ($settings->show_currency_code == "TRUE") { if ($client->getSetting('show_currency_code') == "TRUE") {
return "{$value} {$code}"; return "{$value} {$code}";
} elseif ($swapSymbol) { } elseif ($swapSymbol) {
return "{$value} " . trim($symbol); return "{$value} " . trim($symbol);
} elseif ($settings->show_currency_symbol == "TRUE") { } elseif ($client->getSetting('show_currency_symbol') == "TRUE") {
return "{$symbol}{$value}"; return "{$symbol}{$value}";
} else { } else {
return self::formatValue($value, $currency); return self::formatValue($value, $currency);

View File

@ -167,13 +167,13 @@ trait MakesInvoiceValues
// $data['$quantity'] = ; // $data['$quantity'] = ;
// $data['$line_total'] = ; // $data['$line_total'] = ;
// $data['$paid_to_date'] = ; // $data['$paid_to_date'] = ;
$data['$discount'] = Number::formatMoney($this->calc()->getTotalDiscount(), $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $data['$discount'] = Number::formatMoney($this->calc()->getTotalDiscount(), $this->client);
$data['$subtotal'] = Number::formatMoney($this->calc()->getSubTotal(), $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $data['$subtotal'] = Number::formatMoney($this->calc()->getSubTotal(), $this->client);
$data['$balance_due'] = Number::formatMoney($this->balance, $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $data['$balance_due'] = Number::formatMoney($this->balance, $this->client);
$data['$partial_due'] = Number::formatMoney($this->partial, $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $data['$partial_due'] = Number::formatMoney($this->partial, $this->client);
$data['$total'] = Number::formatMoney($this->calc()->getTotal(), $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $data['$total'] = Number::formatMoney($this->calc()->getTotal(), $this->client);
$data['$balance'] = Number::formatMoney($this->calc()->getBalance(), $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $data['$balance'] = Number::formatMoney($this->calc()->getBalance(), $this->client);
$data['$taxes'] = Number::formatMoney($this->calc()->getTotalTaxes(), $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $data['$taxes'] = Number::formatMoney($this->calc()->getTotalTaxes(), $this->client);
$data['$terms'] = $this->terms; $data['$terms'] = $this->terms;
// $data['$your_invoice'] = ; // $data['$your_invoice'] = ;
// $data['$quote'] = ; // $data['$quote'] = ;
@ -365,14 +365,14 @@ trait MakesInvoiceValues
foreach($items as $item) foreach($items as $item)
{ {
$item->cost = Number::formatMoney($item->cost, $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $item->cost = Number::formatMoney($item->cost, $this->client);
$item->line_total = Number::formatMoney($item->line_total, $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $item->line_total = Number::formatMoney($item->line_total, $this->client);
if(isset($item->discount) && $item->discount > 0) if(isset($item->discount) && $item->discount > 0)
{ {
if($item->is_amount_discount) if($item->is_amount_discount)
$item->discount = Number::formatMoney($item->discount, $this->client->currency, $this->client->country, $this->client->getMergedSettings()); $item->discount = Number::formatMoney($item->discount, $this->client);
else else
$item->discount = $item->discount . '%'; $item->discount = $item->discount . '%';
} }
@ -403,7 +403,7 @@ trait MakesInvoiceValues
{ {
$data .= '<tr class="line_taxes">'; $data .= '<tr class="line_taxes">';
$data .= '<td>'. $tax['name'] .'</td>'; $data .= '<td>'. $tax['name'] .'</td>';
$data .= '<td>'. Number::formatMoney($tax['total'], $this->client->currency, $this->client->country, $this->client->getMergedSettings()) .'</td></tr>'; $data .= '<td>'. Number::formatMoney($tax['total'], $this->client) .'</td></tr>';
} }
return $data; return $data;

View File

@ -187,7 +187,7 @@ class InvoiceTest extends TestCase
$this->assertNotNull($invoice->settings); $this->assertNotNull($invoice->settings);
$this->assertTrue(property_exists($invoice->settings, 'custom_taxes1')); $this->assertTrue(property_exists($invoice->settings, 'custom_taxes1'));
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $token, 'X-API-TOKEN' => $token,
@ -203,4 +203,4 @@ class InvoiceTest extends TestCase
} }
} }

View File

@ -44,7 +44,7 @@ class RecurringInvoicesCronTest extends TestCase
//spin up 5 valid and 1 invalid recurring invoices //spin up 5 valid and 1 invalid recurring invoices
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', Carbon::now()->addMinutes(30))->get(); $recurring_invoices = RecurringInvoice::where('next_send_date', '<=', Carbon::now()->addMinutes(30))->get();
Log::error(Carbon::now()->addMinutes(30)->format(config('ninja.date_time_format'))); // Log::error(Carbon::now()->addMinutes(30)->format(config('ninja.date_time_format')));
$recurring_invoices->each(function ($inv, $key) { $recurring_invoices->each(function ($inv, $key) {

View File

@ -17,9 +17,9 @@ class BaseSettingsTest extends TestCase
public function setUp() :void public function setUp() :void
{ {
parent::setUp(); parent::setUp();
$this->settings = new ClientSettings(ClientSettings::defaults()); $this->settings = new ClientSettings(ClientSettings::defaults());
} }