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

Add DateFormats to model

This commit is contained in:
David Bomba 2019-09-22 19:30:03 +10:00
parent b6a0350952
commit 50d52c5323
9 changed files with 143 additions and 11 deletions

View File

@ -21,8 +21,8 @@ class CompanySettings extends BaseSettings
{
public $timezone_id = '';
public $date_format = '';
public $datetime_format = '';
public $date_format_id = '';
public $datetime_format_id = '';
public $military_time = false;
public $start_of_week = '';
public $financial_year_start = '';
@ -116,7 +116,6 @@ class CompanySettings extends BaseSettings
public $company_gateways = '';
public $invoice_terms = '';
public $quote_terms = '';
public $invoice_taxes = false;

View File

@ -34,7 +34,7 @@ class UrlSetDb
if (config('ninja.db.multi_db_enabled'))
{
$hashids = new Hashids('', 10); //decoded output is _always_ an array.
$hashids = new Hashids('', 15); //decoded output is _always_ an array.
//parse URL hash and set DB
$segments = explode("-", $request->route('confirmation_code'));

24
app/Models/DateFormat.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Models;
/**
* Class DateFormat.
*/
class DateFormat extends StaticModel
{
/**
* @var bool
*/
public $timestamps = false;
/**
* @return bool|string
*/
public function __toString()
{
$date = mktime(0, 0, 0, 12, 31, date('Y'));
return date($this->format, $date);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models;
/**
* Class DatetimeFormat.
*/
class DatetimeFormat extends StaticModel
{
/**
* @var bool
*/
public $timestamps = false;
/**
* @return bool|string
*/
public function __toString()
{
$date = mktime(0, 0, 0, 12, 31, date('Y'));
return date($this->format, $date);
}
}

View File

@ -46,14 +46,14 @@ trait MakesHash
*/
public function getDbCode($db) : string
{
$hashids = new Hashids('', 10);
$hashids = new Hashids('', 15);
return $hashids->encode( str_replace( MultiDB::DB_PREFIX, "", $db ) );
}
public function encodePrimaryKey($value) : string
{
$hashids = new Hashids('', 10);
$hashids = new Hashids('', 15);
return $hashids->encode($value);
}
@ -61,7 +61,7 @@ trait MakesHash
public function decodePrimaryKey($value) : string
{
try{
$hashids = new Hashids('', 10);
$hashids = new Hashids('', 15);
$decoded_array = $hashids->decode($value);

View File

@ -42,10 +42,8 @@ return [
'country_id' => env('DEFAULT_COUNTRY', 840), // United Stated
'currency_id' => env('DEFAULT_CURRENCY', 1),
'language_id' => env('DEFAULT_LANGUAGE', 1), //en
'date_format' => env('DEFAULT_DATE_FORMAT', 'M j, Y'),
'date_picker_format' => env('DEFAULT_DATE_PICKER_FORMAT', 'M d, yyyy'),
'datetime_format' => env('DEFAULT_DATETIME_FORMAT', 'F j, Y g:i a'),
'datetime_moment_format' => env('DEFAULT_DATETIME_MOMENT_FORMAT', 'MMM D, YYYY h:mm:ss a'),
'date_format_id' => env('DEFAULT_DATE_FORMAT_ID', '1'),
'datetime_format_id' => env('DEFAULT_DATETIME_FORMAT_ID', '1'),
'locale' => env('DEFAULT_LOCALE', 'en'),
'map_zoom' => env('DEFAULT_MAP_ZOOM', 10),
'payment_terms' => env('DEFAULT_PAYMENT_TERMS', 1),

View File

@ -927,6 +927,21 @@ class CreateUsersTable extends Migration
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
});
Schema::create('date_formats', function ($table) {
$table->increments('id');
$table->string('format');
$table->string('picker_format');
$table->string('format_moment');
$table->string('format_dart');
});
Schema::create('datetime_formats', function ($table) {
$table->increments('id');
$table->string('format');
$table->string('format_moment');
$table->string('format_dart');
});
}
/**

View File

@ -30,6 +30,7 @@ class DatabaseSeeder extends Seeder
$this->call('IndustrySeeder');
$this->call('PaymentTypesSeeder');
$this->call('GatewayTypesSeeder');
$this->call('DateFormatsSeeder');
}
}

View File

@ -0,0 +1,71 @@
<?php
use App\Models\DateFormat;
use App\Models\DatetimeFormat;
use Illuminate\Database\Seeder;
class DateFormatsSeeder extends Seeder
{
public function run()
{
Eloquent::unguard();
// Date formats
$formats = [
['format' => 'd/M/Y', 'picker_format' => 'dd/M/yyyy', 'format_moment' => 'DD/MMM/YYYY', 'format_dart' => 'dd/MMM/yyyy'],
['format' => 'd-M-Y', 'picker_format' => 'dd-M-yyyy', 'format_moment' => 'DD-MMM-YYYY', 'format_dart' => 'dd-MMM-yyyy'],
['format' => 'd/F/Y', 'picker_format' => 'dd/MM/yyyy', 'format_moment' => 'DD/MMMM/YYYY', 'format_dart' => 'dd/MMMM/yyyy'],
['format' => 'd-F-Y', 'picker_format' => 'dd-MM-yyyy', 'format_moment' => 'DD-MMMM-YYYY', 'format_dart' => 'dd-MMMM-yyyy'],
['format' => 'M j, Y', 'picker_format' => 'M d, yyyy', 'format_moment' => 'MMM D, YYYY', 'format_dart' => 'MMM d, yyyy'],
['format' => 'F j, Y', 'picker_format' => 'MM d, yyyy', 'format_moment' => 'MMMM D, YYYY', 'format_dart' => 'MMMM d, yyyy'],
['format' => 'D M j, Y', 'picker_format' => 'D MM d, yyyy', 'format_moment' => 'ddd MMM Do, YYYY', 'format_dart' => 'EEE MMM d, yyyy'],
['format' => 'Y-m-d', 'picker_format' => 'yyyy-mm-dd', 'format_moment' => 'YYYY-MM-DD', 'format_dart' => 'yyyy-MM-dd'],
['format' => 'd-m-Y', 'picker_format' => 'dd-mm-yyyy', 'format_moment' => 'DD-MM-YYYY', 'format_dart' => 'dd-MM-yyyy'],
['format' => 'm/d/Y', 'picker_format' => 'mm/dd/yyyy', 'format_moment' => 'MM/DD/YYYY', 'format_dart' => 'MM/dd/yyyy'],
['format' => 'd.m.Y', 'picker_format' => 'dd.mm.yyyy', 'format_moment' => 'D.MM.YYYY', 'format_dart' => 'dd.MM.yyyy'],
['format' => 'j. M. Y', 'picker_format' => 'd. M. yyyy', 'format_moment' => 'DD. MMM. YYYY', 'format_dart' => 'd. MMM. yyyy'],
['format' => 'j. F Y', 'picker_format' => 'd. MM yyyy', 'format_moment' => 'DD. MMMM YYYY', 'format_dart' => 'd. MMMM yyyy'],
];
foreach ($formats as $format) {
// use binary to support case-sensitive search
$record = DateFormat::whereRaw('BINARY `format`= ?', [$format['format']])->first();
if ($record) {
$record->picker_format = $format['picker_format'];
$record->format_moment = $format['format_moment'];
$record->format_dart = $format['format_dart'];
$record->save();
} else {
DateFormat::create($format);
}
}
// Date/time formats
$formats = [
['format' => 'd/M/Y g:i a', 'format_moment' => 'DD/MMM/YYYY h:mm:ss a', 'format_dart' => 'dd/MMM/yyyy h:mm a'],
['format' => 'd-M-Y g:i a', 'format_moment' => 'DD-MMM-YYYY h:mm:ss a', 'format_dart' => 'dd-MMM-yyyy h:mm a'],
['format' => 'd/F/Y g:i a', 'format_moment' => 'DD/MMMM/YYYY h:mm:ss a', 'format_dart' => 'dd/MMMM/yyyy h:mm a'],
['format' => 'd-F-Y g:i a', 'format_moment' => 'DD-MMMM-YYYY h:mm:ss a', 'format_dart' => 'dd-MMMM-yyyy h:mm a'],
['format' => 'M j, Y g:i a', 'format_moment' => 'MMM D, YYYY h:mm:ss a', 'format_dart' => 'MMM d, yyyy h:mm a'],
['format' => 'F j, Y g:i a', 'format_moment' => 'MMMM D, YYYY h:mm:ss a', 'format_dart' => 'MMMM d, yyyy h:mm a'],
['format' => 'D M jS, Y g:i a', 'format_moment' => 'ddd MMM Do, YYYY h:mm:ss a', 'format_dart' => 'EEE MMM d, yyyy h:mm a'],
['format' => 'Y-m-d g:i a', 'format_moment' => 'YYYY-MM-DD h:mm:ss a', 'format_dart' => 'yyyy-MM-dd h:mm a'],
['format' => 'd-m-Y g:i a', 'format_moment' => 'DD-MM-YYYY h:mm:ss a', 'format_dart' => 'dd-MM-yyyy h:mm a'],
['format' => 'm/d/Y g:i a', 'format_moment' => 'MM/DD/YYYY h:mm:ss a', 'format_dart' => 'MM/dd/yyyy h:mm a'],
['format' => 'd.m.Y g:i a', 'format_moment' => 'D.MM.YYYY h:mm:ss a', 'format_dart' => 'dd.MM.yyyy h:mm a'],
['format' => 'j. M. Y g:i a', 'format_moment' => 'DD. MMM. YYYY h:mm:ss a', 'format_dart' => 'd. MMM. yyyy h:mm a'],
['format' => 'j. F Y g:i a', 'format_moment' => 'DD. MMMM YYYY h:mm:ss a', 'format_dart' => 'd. MMMM yyyy h:mm a'],
];
foreach ($formats as $format) {
$record = DatetimeFormat::whereRaw('BINARY `format`= ?', [$format['format']])->first();
if ($record) {
$record->format_moment = $format['format_moment'];
$record->format_dart = $format['format_dart'];
$record->save();
} else {
DatetimeFormat::create($format);
}
}
}
}