From 8f29c15a2b7d5e0cbc91528c55d8c320b6b5f386 Mon Sep 17 00:00:00 2001 From: Kevin Adametz Date: Mon, 28 Oct 2019 11:31:16 +0100 Subject: [PATCH] Change 10.2019 --- .idea/workspace.xml | 241 +-------------------------- app/Models/Booking.php | 4 - app/Models/BookingDraftItem.php | 15 +- app/Models/DraftItem.php | 14 +- app/Models/TravelUserBookingFewo.php | 21 +-- app/Services/Util.php | 9 + 6 files changed, 27 insertions(+), 277 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 68277fc..61d0d10 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,241 +2,22 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -280,26 +61,6 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/app/Models/Booking.php b/app/Models/Booking.php index 1bebfb1..3c81b87 100644 --- a/app/Models/Booking.php +++ b/app/Models/Booking.php @@ -163,10 +163,6 @@ class Booking extends Model } - public function _format_number($value){ - return preg_replace("/[^0-9,]/", "", $value); - } - public function getPriceAttribute() { // 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator diff --git a/app/Models/BookingDraftItem.php b/app/Models/BookingDraftItem.php index 8e45f04..3ec9026 100644 --- a/app/Models/BookingDraftItem.php +++ b/app/Models/BookingDraftItem.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Services\Util; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; @@ -140,10 +141,7 @@ class BookingDraftItem extends Model return ['adult'=>$adult, 'children'=>$children]; } - public function _format_number($value){ - return preg_replace("/[^0-9,]/", "", $value); - } - + public function getStartDateAttribute(){ return isset($this->attributes['start_date']) ? Carbon::parse($this->attributes['start_date'])->format("d.m.Y") : ''; } @@ -170,8 +168,7 @@ class BookingDraftItem extends Model //price_adult public function setPriceAdultAttribute($value) { - $value = $this->_format_number($value); - $this->attributes['price_adult'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_adult'] = Util::_clean_float($value); } public function getPriceAdultAttribute() { @@ -190,8 +187,7 @@ class BookingDraftItem extends Model //price_children public function setPriceChildrenAttribute($value) { - $value = $this->_format_number($value); - $this->attributes['price_children'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_children'] = Util::_clean_float($value); } public function getPriceChildrenAttribute() { @@ -210,8 +206,7 @@ class BookingDraftItem extends Model //price public function setPriceAttribute($value) { - $value = $this->_format_number($value); - $this->attributes['price'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price'] = Util::_clean_float($value); } public function getPriceAttribute() { diff --git a/app/Models/DraftItem.php b/app/Models/DraftItem.php index 9792e72..f5ecee1 100644 --- a/app/Models/DraftItem.php +++ b/app/Models/DraftItem.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Services\Util; use Illuminate\Database\Eloquent\Model; /** @@ -72,14 +73,9 @@ class DraftItem extends Model } - public function _format_number($value){ - return preg_replace("/[^0-9,]/", "", $value); - } - public function setPriceAdultAttribute($value) { - $value = $this->_format_number($value); - $this->attributes['price_adult'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_adult'] = Util::_clean_float($value); } public function getPriceAdultAttribute() @@ -95,8 +91,7 @@ class DraftItem extends Model public function setPriceChildrenAttribute($value) { - $value = $this->_format_number($value); - $this->attributes['price_children'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_children'] = Util::_clean_float($value); } public function getPriceChildrenAttribute() @@ -112,8 +107,7 @@ class DraftItem extends Model public function setPriceAttribute($value) { - $value = $this->_format_number($value); - $this->attributes['price'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price'] = Util::_clean_float($value); } public function getPriceAttribute() diff --git a/app/Models/TravelUserBookingFewo.php b/app/Models/TravelUserBookingFewo.php index 4d8a056..cbe74df 100644 --- a/app/Models/TravelUserBookingFewo.php +++ b/app/Models/TravelUserBookingFewo.php @@ -304,8 +304,7 @@ class TravelUserBookingFewo extends Model //price_travel public function setPriceTravelAttribute($value) { - $value = Util::_format_number($value); - $this->attributes['price_travel'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_travel'] = Util::_clean_float($value); } public function getPriceTravelAttribute($value) @@ -322,8 +321,7 @@ class TravelUserBookingFewo extends Model //price_extra public function setPriceExtraAttribute($value) { - $value = Util::_format_number($value); - $this->attributes['price_extra'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_extra'] = Util::_clean_float($value); } public function getPriceExtraAttribute($value) { @@ -339,8 +337,7 @@ class TravelUserBookingFewo extends Model //price_balance public function setPriceBalanceAttribute($value) { - $value = Util::_format_number($value); - $this->attributes['price_balance'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_balance'] = Util::_clean_float($value); } public function getPriceBalanceAttribute($value) { @@ -356,8 +353,7 @@ class TravelUserBookingFewo extends Model //price_travel_total public function setPriceTravelTotalAttribute($value) { - $value = Util::_format_number($value); - $this->attributes['price_travel_total'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_travel_total'] = Util::_clean_float($value); } public function getPriceTravelTotalAttribute($value) { @@ -377,8 +373,7 @@ class TravelUserBookingFewo extends Model //price_deposit public function setPriceDepositAttribute($value) { - $value = Util::_format_number($value); - $this->attributes['price_deposit'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_deposit'] = Util::_clean_float($value); } public function getPriceDepositAttribute($value) @@ -395,8 +390,7 @@ class TravelUserBookingFewo extends Model //price_service public function setPriceServiceAttribute($value) { - $value = Util::_format_number($value); - $this->attributes['price_service'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_service'] = Util::_clean_float($value); } public function getPriceServiceAttribute($value) @@ -414,8 +408,7 @@ class TravelUserBookingFewo extends Model //price_total public function setPriceTotalAttribute($value) { - $value = Util::_format_number($value); - $this->attributes['price_total'] = floatval(str_replace(',', '.', $value)); + $this->attributes['price_total'] = Util::_clean_float($value); } public function getPriceTotalAttribute($value) diff --git a/app/Services/Util.php b/app/Services/Util.php index f32dd26..b6fc714 100644 --- a/app/Services/Util.php +++ b/app/Services/Util.php @@ -31,8 +31,17 @@ class Util public static function _format_number($value){ return preg_replace("/[^0-9,]/", "", $value); + } + public static function _clean_float($value){ + $groups = explode(".", preg_replace("/[^0-9.]/", "", str_replace(',', '.', $value))); + $lastGroup = array_pop($groups); + $number = implode('', $groups); + return (strlen($lastGroup) < 3) ? floatval($number.'.'.$lastGroup) : floatval($number.$lastGroup); + } + + public static function sanitize($string, $force_lowercase = true, $anal = false, $substr = false) { $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",