diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 1f62678daa..edb8b00908 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -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; diff --git a/app/Http/Middleware/UrlSetDb.php b/app/Http/Middleware/UrlSetDb.php index 0e8bb10903..bb0ee5e138 100644 --- a/app/Http/Middleware/UrlSetDb.php +++ b/app/Http/Middleware/UrlSetDb.php @@ -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')); diff --git a/app/Models/DateFormat.php b/app/Models/DateFormat.php new file mode 100644 index 0000000000..80d1a18abf --- /dev/null +++ b/app/Models/DateFormat.php @@ -0,0 +1,24 @@ +format, $date); + } +} diff --git a/app/Models/DatetimeFormat.php b/app/Models/DatetimeFormat.php new file mode 100644 index 0000000000..53c728ed38 --- /dev/null +++ b/app/Models/DatetimeFormat.php @@ -0,0 +1,24 @@ +format, $date); + } +} diff --git a/app/Utils/Traits/MakesHash.php b/app/Utils/Traits/MakesHash.php index 867e8a0a81..9c4c6766cb 100644 --- a/app/Utils/Traits/MakesHash.php +++ b/app/Utils/Traits/MakesHash.php @@ -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); diff --git a/config/ninja.php b/config/ninja.php index 911e0d9fb8..086ec86fdb 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -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), diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 3773e19b34..fdbea76079 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -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'); + }); } /** diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 48b1f962c8..53f70223c6 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -30,6 +30,7 @@ class DatabaseSeeder extends Seeder $this->call('IndustrySeeder'); $this->call('PaymentTypesSeeder'); $this->call('GatewayTypesSeeder'); + $this->call('DateFormatsSeeder'); } } diff --git a/database/seeds/DateFormatsSeeder.php b/database/seeds/DateFormatsSeeder.php new file mode 100644 index 0000000000..5b93873413 --- /dev/null +++ b/database/seeds/DateFormatsSeeder.php @@ -0,0 +1,71 @@ + '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); + } + } + } +}