From 9652e3bdf58265d3a623b0459a01e514a9731da3 Mon Sep 17 00:00:00 2001 From: harshjagad20 Date: Sat, 18 Dec 2021 12:43:20 +0530 Subject: [PATCH 1/3] fix parse condition --- app/Models/CustomField.php | 2 +- app/Models/CustomFieldValue.php | 2 +- app/Models/Estimate.php | 4 ++-- app/Models/Expense.php | 2 +- app/Models/Invoice.php | 4 ++-- app/Models/Payment.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index e9902d39..871f7278 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -25,7 +25,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'] = Carbon::parse($value)->format('Y-m-d'); } } diff --git a/app/Models/CustomFieldValue.php b/app/Models/CustomFieldValue.php index 2a862425..2b593a3a 100644 --- a/app/Models/CustomFieldValue.php +++ b/app/Models/CustomFieldValue.php @@ -21,7 +21,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'] = Carbon::parse($value)->format('Y-m-d'); } } diff --git a/app/Models/Estimate.php b/app/Models/Estimate.php index deaf1aa8..78f8c56d 100644 --- a/app/Models/Estimate.php +++ b/app/Models/Estimate.php @@ -57,14 +57,14 @@ class Estimate extends Model implements HasMedia public function setEstimateDateAttribute($value) { if ($value) { - $this->attributes['estimate_date'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['estimate_date'] = Carbon::parse($value)->format('Y-m-d'); } } public function setExpiryDateAttribute($value) { if ($value) { - $this->attributes['expiry_date'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['expiry_date'] = Carbon::parse($value)->format('Y-m-d'); } } diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 93405dd5..21326058 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -33,7 +33,7 @@ class Expense extends Model implements HasMedia public function setExpenseDateAttribute($value) { if ($value) { - $this->attributes['expense_date'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['expense_date'] = Carbon::parse($value)->format('Y-m-d'); } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index e683c107..f7133036 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -64,14 +64,14 @@ class Invoice extends Model implements HasMedia public function setInvoiceDateAttribute($value) { if ($value) { - $this->attributes['invoice_date'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['invoice_date'] = Carbon::parse($value)->format('Y-m-d'); } } public function setDueDateAttribute($value) { if ($value) { - $this->attributes['due_date'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['due_date'] = Carbon::parse($value)->format('Y-m-d'); } } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index d88030d9..b7a751e1 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -57,7 +57,7 @@ class Payment extends Model implements HasMedia public function setPaymentDateAttribute($value) { if ($value) { - $this->attributes['payment_date'] = Carbon::createFromFormat('Y-m-d', $value); + $this->attributes['payment_date'] = Carbon::parse($value)->format('Y-m-d'); } } From 2765f35f98f0f5cbf7bf56f88da04db3e5079a4b Mon Sep 17 00:00:00 2001 From: harshjagad20 Date: Sat, 18 Dec 2021 13:14:46 +0530 Subject: [PATCH 2/3] refactor parse condition --- app/Models/CustomField.php | 10 +++++++--- app/Models/CustomFieldValue.php | 10 +++++++--- app/Models/Estimate.php | 6 ++++-- app/Models/Expense.php | 6 +++++- app/Models/Invoice.php | 6 ++++-- app/Models/Payment.php | 4 ++-- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 871f7278..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::parse($value)->format('Y-m-d'); + $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 2b593a3a..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::parse($value)->format('Y-m-d'); + $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 78f8c56d..dcd084e4 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 = [ @@ -57,14 +59,14 @@ class Estimate extends Model implements HasMedia public function setEstimateDateAttribute($value) { if ($value) { - $this->attributes['estimate_date'] = Carbon::parse($value)->format('Y-m-d'); + $this->attributes['estimate_date'] = $value; } } public function setExpiryDateAttribute($value) { if ($value) { - $this->attributes['expiry_date'] = Carbon::parse($value)->format('Y-m-d'); + $this->attributes['expiry_date'] = $value; } } diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 21326058..4b7eb93c 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 = [ @@ -33,7 +37,7 @@ class Expense extends Model implements HasMedia public function setExpenseDateAttribute($value) { if ($value) { - $this->attributes['expense_date'] = Carbon::parse($value)->format('Y-m-d'); + $this->attributes['expense_date'] = $value; } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index f7133036..5f67ed6d 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 = [ @@ -64,14 +66,14 @@ class Invoice extends Model implements HasMedia public function setInvoiceDateAttribute($value) { if ($value) { - $this->attributes['invoice_date'] = Carbon::parse($value)->format('Y-m-d'); + $this->attributes['invoice_date'] = $value; } } public function setDueDateAttribute($value) { if ($value) { - $this->attributes['due_date'] = Carbon::parse($value)->format('Y-m-d'); + $this->attributes['due_date'] = $value; } } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index b7a751e1..0582e152 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']; @@ -57,7 +57,7 @@ class Payment extends Model implements HasMedia public function setPaymentDateAttribute($value) { if ($value) { - $this->attributes['payment_date'] = Carbon::parse($value)->format('Y-m-d'); + $this->attributes['payment_date'] = $value; } } From 2fd8d8a5f4da9a8dc36f55527dc55f85d434180a Mon Sep 17 00:00:00 2001 From: harshjagad20 Date: Sat, 18 Dec 2021 15:08:05 +0530 Subject: [PATCH 3/3] solve trailing data error --- app/Models/Estimate.php | 14 -------------- app/Models/Expense.php | 7 ------- app/Models/Invoice.php | 14 -------------- app/Models/Payment.php | 7 ------- 4 files changed, 42 deletions(-) diff --git a/app/Models/Estimate.php b/app/Models/Estimate.php index dcd084e4..5fafda8e 100644 --- a/app/Models/Estimate.php +++ b/app/Models/Estimate.php @@ -56,20 +56,6 @@ class Estimate extends Model implements HasMedia 'exchange_rate' => 'float' ]; - public function setEstimateDateAttribute($value) - { - if ($value) { - $this->attributes['estimate_date'] = $value; - } - } - - public function setExpiryDateAttribute($value) - { - if ($value) { - $this->attributes['expiry_date'] = $value; - } - } - public function getEstimatePdfUrlAttribute() { return url('/estimates/pdf/'.$this->unique_hash); diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 4b7eb93c..de02cc91 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -34,13 +34,6 @@ class Expense extends Model implements HasMedia 'exchange_rate' => 'float' ]; - public function setExpenseDateAttribute($value) - { - if ($value) { - $this->attributes['expense_date'] = $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 5f67ed6d..e9a59fc7 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -63,20 +63,6 @@ class Invoice extends Model implements HasMedia 'invoicePdfUrl', ]; - public function setInvoiceDateAttribute($value) - { - if ($value) { - $this->attributes['invoice_date'] = $value; - } - } - - public function setDueDateAttribute($value) - { - if ($value) { - $this->attributes['due_date'] = $value; - } - } - public function emailLogs() { return $this->morphMany('App\Models\EmailLog', 'mailable'); diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 0582e152..d64a9025 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -54,13 +54,6 @@ class Payment extends Model implements HasMedia }); } - public function setPaymentDateAttribute($value) - { - if ($value) { - $this->attributes['payment_date'] = $value; - } - } - public function getFormattedCreatedAtAttribute($value) { $dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);