diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index e9902d39..d1acb124 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -2,7 +2,6 @@ namespace Crater\Models; -use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -14,6 +13,11 @@ class CustomField extends Model 'id', ]; + protected $dates = [ + 'date_answer', + 'date_time_answer' + ]; + protected $appends = [ 'defaultAnswer', ]; @@ -25,7 +29,7 @@ class CustomField extends Model public function setDateAnswerAttribute($value) { if ($value && $value != null) { - $this->attributes['date_answer'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['date_answer'] = $value; } } @@ -39,7 +43,7 @@ class CustomField extends Model public function setDateTimeAnswerAttribute($value) { if ($value && $value != null) { - $this->attributes['date_time_answer'] = Carbon::createFromFormat('Y-m-d H:i', $value); + $this->attributes['date_time_answer'] = $value; } } diff --git a/app/Models/CustomFieldValue.php b/app/Models/CustomFieldValue.php index 2a862425..8bc26918 100644 --- a/app/Models/CustomFieldValue.php +++ b/app/Models/CustomFieldValue.php @@ -2,7 +2,6 @@ namespace Crater\Models; -use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -10,6 +9,11 @@ class CustomFieldValue extends Model { use HasFactory; + protected $dates = [ + 'date_answer', + 'date_time_answer' + ]; + protected $guarded = [ 'id', ]; @@ -21,7 +25,7 @@ class CustomFieldValue extends Model public function setDateAnswerAttribute($value) { if ($value && $value != null) { - $this->attributes['date_answer'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['date_answer'] = $value; } } @@ -37,7 +41,7 @@ class CustomFieldValue extends Model public function setDateTimeAnswerAttribute($value) { if ($value && $value != null) { - $this->attributes['date_time_answer'] = Carbon::createFromFormat('Y-m-d H:i', $value); + $this->attributes['date_time_answer'] = $value; } $this->attributes['time_answer'] = null; } diff --git a/app/Models/Estimate.php b/app/Models/Estimate.php index deaf1aa8..5fafda8e 100644 --- a/app/Models/Estimate.php +++ b/app/Models/Estimate.php @@ -35,6 +35,8 @@ class Estimate extends Model implements HasMedia 'created_at', 'updated_at', 'deleted_at', + 'estimate_date', + 'expiry_date' ]; protected $appends = [ @@ -54,20 +56,6 @@ class Estimate extends Model implements HasMedia 'exchange_rate' => 'float' ]; - public function setEstimateDateAttribute($value) - { - if ($value) { - $this->attributes['estimate_date'] = Carbon::createFromFormat('Y-m-d', $value); - } - } - - public function setExpiryDateAttribute($value) - { - if ($value) { - $this->attributes['expiry_date'] = Carbon::createFromFormat('Y-m-d', $value); - } - } - public function getEstimatePdfUrlAttribute() { return url('/estimates/pdf/'.$this->unique_hash); diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 93405dd5..de02cc91 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -16,6 +16,10 @@ class Expense extends Model implements HasMedia use InteractsWithMedia; use HasCustomFieldsTrait; + protected $dates = [ + 'expense_date', + ]; + protected $guarded = ['id']; protected $appends = [ @@ -30,13 +34,6 @@ class Expense extends Model implements HasMedia 'exchange_rate' => 'float' ]; - public function setExpenseDateAttribute($value) - { - if ($value) { - $this->attributes['expense_date'] = Carbon::createFromFormat('Y-m-d', $value); - } - } - public function category() { return $this->belongsTo(ExpenseCategory::class, 'expense_category_id'); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index e683c107..e9a59fc7 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -39,6 +39,8 @@ class Invoice extends Model implements HasMedia 'created_at', 'updated_at', 'deleted_at', + 'invoice_date', + 'due_date' ]; protected $casts = [ @@ -61,20 +63,6 @@ class Invoice extends Model implements HasMedia 'invoicePdfUrl', ]; - public function setInvoiceDateAttribute($value) - { - if ($value) { - $this->attributes['invoice_date'] = Carbon::createFromFormat('Y-m-d', $value); - } - } - - public function setDueDateAttribute($value) - { - if ($value) { - $this->attributes['due_date'] = Carbon::createFromFormat('Y-m-d', $value); - } - } - public function emailLogs() { return $this->morphMany('App\Models\EmailLog', 'mailable'); diff --git a/app/Models/Payment.php b/app/Models/Payment.php index d88030d9..d64a9025 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -28,7 +28,7 @@ class Payment extends Model implements HasMedia public const PAYMENT_MODE_CREDIT_CARD = 'CREDIT_CARD'; public const PAYMENT_MODE_BANK_TRANSFER = 'BANK_TRANSFER'; - protected $dates = ['created_at', 'updated_at']; + protected $dates = ['created_at', 'updated_at', 'payment_date']; protected $guarded = ['id']; @@ -54,13 +54,6 @@ class Payment extends Model implements HasMedia }); } - public function setPaymentDateAttribute($value) - { - if ($value) { - $this->attributes['payment_date'] = Carbon::createFromFormat('Y-m-d', $value); - } - } - public function getFormattedCreatedAtAttribute($value) { $dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);