1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Create more date helpers

This commit is contained in:
David Bomba 2019-08-29 08:13:26 +10:00
parent 17b2bc4e69
commit b7d9ad1808
3 changed files with 22 additions and 4 deletions

View File

@ -44,7 +44,7 @@ class InvoiceController extends Controller
*/
public function index(InvoiceFilters $filters, Builder $builder)
{//
$invoices = Invoice::filter($filters);
$invoices = Invoice::filter($filters)->with('client', 'client.country');
if (request()->ajax()) {
@ -57,9 +57,9 @@ class InvoiceController extends Controller
->editColumn('status_id', function ($invoice){
return Invoice::badgeForStatus($invoice->status);
})->editColumn('invoice_date', function ($invoice){
return $this->createClientDate($invoice->invoice_date, $invoice->client->timezone()->name)->format($invoice->client->date_format());
return $this->formatDate($invoice->invoice_date, $invoice->client->date_format());
})->editColumn('due_date', function ($invoice){
return $this->createClientDate($invoice->due_date, $invoice->client->timezone()->name)->format($invoice->client->date_format());
return $this->formatDate($invoice->due_date, $invoice->client->date_format());
})->editColumn('balance', function ($invoice) {
return Number::formatMoney($invoice->balance, $invoice->client->currency(), $invoice->client->country, $invoice->client->getMergedSettings());
})->editColumn('amount', function ($invoice) {

View File

@ -52,6 +52,22 @@ trait MakesDates
}
/**
* Formats a date
* @param Carbon/String $date Carbon object or date string
* @param string $format The date display format
* @return string The formatted date
*/
public function formatDate($date, string $format) :string
{
if(is_string($date))
$date = $this->convertToDateObject($date);
return $date->format($format);
}
private function convertToDateObject($date)
{
@ -59,4 +75,6 @@ trait MakesDates
}
}

View File

@ -67,7 +67,7 @@ class RandomDataSeeder extends Seeder
ClientContact::create([
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'email' => $faker->email,
'email' => config('ninja.testvars.username'),
'company_id' => $company->id,
'password' => Hash::make(config('ninja.testvars.password')),
'email_verified_at' => now(),