mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Add DateFormats to model
This commit is contained in:
parent
b6a0350952
commit
50d52c5323
@ -21,8 +21,8 @@ class CompanySettings extends BaseSettings
|
|||||||
{
|
{
|
||||||
|
|
||||||
public $timezone_id = '';
|
public $timezone_id = '';
|
||||||
public $date_format = '';
|
public $date_format_id = '';
|
||||||
public $datetime_format = '';
|
public $datetime_format_id = '';
|
||||||
public $military_time = false;
|
public $military_time = false;
|
||||||
public $start_of_week = '';
|
public $start_of_week = '';
|
||||||
public $financial_year_start = '';
|
public $financial_year_start = '';
|
||||||
@ -116,7 +116,6 @@ class CompanySettings extends BaseSettings
|
|||||||
|
|
||||||
public $company_gateways = '';
|
public $company_gateways = '';
|
||||||
|
|
||||||
|
|
||||||
public $invoice_terms = '';
|
public $invoice_terms = '';
|
||||||
public $quote_terms = '';
|
public $quote_terms = '';
|
||||||
public $invoice_taxes = false;
|
public $invoice_taxes = false;
|
||||||
|
@ -34,7 +34,7 @@ class UrlSetDb
|
|||||||
|
|
||||||
if (config('ninja.db.multi_db_enabled'))
|
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
|
//parse URL hash and set DB
|
||||||
$segments = explode("-", $request->route('confirmation_code'));
|
$segments = explode("-", $request->route('confirmation_code'));
|
||||||
|
24
app/Models/DateFormat.php
Normal file
24
app/Models/DateFormat.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
24
app/Models/DatetimeFormat.php
Normal file
24
app/Models/DatetimeFormat.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -46,14 +46,14 @@ trait MakesHash
|
|||||||
*/
|
*/
|
||||||
public function getDbCode($db) : string
|
public function getDbCode($db) : string
|
||||||
{
|
{
|
||||||
$hashids = new Hashids('', 10);
|
$hashids = new Hashids('', 15);
|
||||||
|
|
||||||
return $hashids->encode( str_replace( MultiDB::DB_PREFIX, "", $db ) );
|
return $hashids->encode( str_replace( MultiDB::DB_PREFIX, "", $db ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function encodePrimaryKey($value) : string
|
public function encodePrimaryKey($value) : string
|
||||||
{
|
{
|
||||||
$hashids = new Hashids('', 10);
|
$hashids = new Hashids('', 15);
|
||||||
|
|
||||||
return $hashids->encode($value);
|
return $hashids->encode($value);
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ trait MakesHash
|
|||||||
public function decodePrimaryKey($value) : string
|
public function decodePrimaryKey($value) : string
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
$hashids = new Hashids('', 10);
|
$hashids = new Hashids('', 15);
|
||||||
|
|
||||||
$decoded_array = $hashids->decode($value);
|
$decoded_array = $hashids->decode($value);
|
||||||
|
|
||||||
|
@ -42,10 +42,8 @@ return [
|
|||||||
'country_id' => env('DEFAULT_COUNTRY', 840), // United Stated
|
'country_id' => env('DEFAULT_COUNTRY', 840), // United Stated
|
||||||
'currency_id' => env('DEFAULT_CURRENCY', 1),
|
'currency_id' => env('DEFAULT_CURRENCY', 1),
|
||||||
'language_id' => env('DEFAULT_LANGUAGE', 1), //en
|
'language_id' => env('DEFAULT_LANGUAGE', 1), //en
|
||||||
'date_format' => env('DEFAULT_DATE_FORMAT', 'M j, Y'),
|
'date_format_id' => env('DEFAULT_DATE_FORMAT_ID', '1'),
|
||||||
'date_picker_format' => env('DEFAULT_DATE_PICKER_FORMAT', 'M d, yyyy'),
|
'datetime_format_id' => env('DEFAULT_DATETIME_FORMAT_ID', '1'),
|
||||||
'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'),
|
|
||||||
'locale' => env('DEFAULT_LOCALE', 'en'),
|
'locale' => env('DEFAULT_LOCALE', 'en'),
|
||||||
'map_zoom' => env('DEFAULT_MAP_ZOOM', 10),
|
'map_zoom' => env('DEFAULT_MAP_ZOOM', 10),
|
||||||
'payment_terms' => env('DEFAULT_PAYMENT_TERMS', 1),
|
'payment_terms' => env('DEFAULT_PAYMENT_TERMS', 1),
|
||||||
|
@ -927,6 +927,21 @@ class CreateUsersTable extends Migration
|
|||||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
$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');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
$this->call('IndustrySeeder');
|
$this->call('IndustrySeeder');
|
||||||
$this->call('PaymentTypesSeeder');
|
$this->call('PaymentTypesSeeder');
|
||||||
$this->call('GatewayTypesSeeder');
|
$this->call('GatewayTypesSeeder');
|
||||||
|
$this->call('DateFormatsSeeder');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
71
database/seeds/DateFormatsSeeder.php
Normal file
71
database/seeds/DateFormatsSeeder.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user