From 0ac449d097b5f887cfbd5226bc06deffb6f25eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 9 Mar 2023 17:04:53 +0100 Subject: [PATCH] Refactor number format to Toolbox SYNC 47 --- app/Http/Controllers/Fo/OrderController.php | 4 +-- app/Lib/Helpers/ToolboxHelper.php | 28 ++++++++++++++++++ app/Models/Merchandise/Product.php | 29 ------------------- resources/theme | 2 +- .../views/pages/discounts/indexList.blade.php | 4 +-- resources/views/pages/orders/form.blade.php | 4 +-- .../views/pages/orders/indexList.blade.php | 2 +- .../views/pages/products/indexList.blade.php | 2 +- 8 files changed, 37 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/Fo/OrderController.php b/app/Http/Controllers/Fo/OrderController.php index 32f190d..12b25b6 100644 --- a/app/Http/Controllers/Fo/OrderController.php +++ b/app/Http/Controllers/Fo/OrderController.php @@ -17,9 +17,9 @@ use App\Http\Requests\Fo\Orders\SetOrderTimeSlotRequest; use App\Http\Requests\Fo\Orders\ShippingFormRequest; use App\Http\Requests\Fo\Orders\ShippingModeFormRequest; use App\Http\Resources\ShopResource; +use App\Lib\Helpers\ToolboxHelper; use App\Mail\NewOrderIncome; use App\Models\Customer\Customer; -use App\Models\Merchandise\Product; use App\Models\Payment\Transaction; use App\Models\Shop\DeliveryMode; use App\Models\Site\GeneralConfig; @@ -721,7 +721,7 @@ class OrderController extends Controller if ($sampleOrder->total_ttc < $minAmountForTransaction) { \redirect()->route('home') ->with('warning', trans('Le montant minimal pour une commande est de :minAmount', [ - 'minAmount' => Product::fmtCurrency($minAmountForTransaction) + 'minAmount' => ToolboxHelper::fmtCurrency($minAmountForTransaction) ]))->throwResponse(); } } diff --git a/app/Lib/Helpers/ToolboxHelper.php b/app/Lib/Helpers/ToolboxHelper.php index bce4eec..80744c3 100644 --- a/app/Lib/Helpers/ToolboxHelper.php +++ b/app/Lib/Helpers/ToolboxHelper.php @@ -12,10 +12,38 @@ use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; +use Money\Money; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class ToolboxHelper { + /** + * Get displayable price value + * + * @param mixed $value Amount in cents. + * @param string $suffix Append some text. + * @return string + */ + public static function fmtCurrency($value, string $suffix = 'TTC'): string + { + return \trim(sprintf( + '%s %s', + app('phpMoneyFormatter')->format(new Money($value, app('phpMoneyCurrency'))), + $suffix + )); + } + + /** + * Get displayable price value + * + * @param mixed $value + * @return string + */ + public static function fmtSellUnit($value): string + { + return !empty($value) ? "/ {$value}" : ''; + } + /** * Generate an unique reference from model on reference column by default * diff --git a/app/Models/Merchandise/Product.php b/app/Models/Merchandise/Product.php index 380a13d..9bccc5e 100644 --- a/app/Models/Merchandise/Product.php +++ b/app/Models/Merchandise/Product.php @@ -692,33 +692,4 @@ class Product extends Model implements Buyable // @phpcs:enable return $this->weight; } - - // * METHODS - - /** - * Get displayable price value - * - * @param mixed $value - * @param string $suffix - * @return string - */ - public static function fmtCurrency($value, string $suffix = 'TTC'): string - { - return sprintf( - '%s € %s', - number_format(\intval($value) / 100, 2, ',', ' '), - $suffix - ); - } - - /** - * Get displayable price value - * - * @param mixed $value - * @return string - */ - public static function fmtSellUnit($value): string - { - return !empty($value) ? "/ {$value}" : ''; - } } diff --git a/resources/theme b/resources/theme index c8038a6..bd61a50 160000 --- a/resources/theme +++ b/resources/theme @@ -1 +1 @@ -Subproject commit c8038a68ea57e586160ddcf902606b520d140727 +Subproject commit bd61a507a675d85be6ac7d3c80f915ddb2195211 diff --git a/resources/views/pages/discounts/indexList.blade.php b/resources/views/pages/discounts/indexList.blade.php index 233118e..8e5b5e4 100644 --- a/resources/views/pages/discounts/indexList.blade.php +++ b/resources/views/pages/discounts/indexList.blade.php @@ -57,8 +57,8 @@ src="{{ asset(resize($product->picture, 'boStickers')) }}" alt="{{ Str::limit($product->name, 15) }}">
- {{ \App\Models\Merchandise\Product::fmtCurrency($product->price)}} - {{ \App\Models\Merchandise\Product::fmtCurrency($product->discounted_price) }} + {{ \App\Lib\Helpers\ToolboxHelper::fmtCurrency($product->price)}} + {{ \App\Lib\Helpers\ToolboxHelper::fmtCurrency($product->discounted_price) }}
diff --git a/resources/views/pages/orders/form.blade.php b/resources/views/pages/orders/form.blade.php index f3c0bf8..ceb7ffd 100644 --- a/resources/views/pages/orders/form.blade.php +++ b/resources/views/pages/orders/form.blade.php @@ -14,8 +14,8 @@ }, 0), 2, ',', '') ]) }}
@endif - {{ __('TVA : :total', ['total' => \App\Models\Merchandise\Product::fmtCurrency($order->total_ttc - $order->total_ht)]) }} - {{ __('Total TTC : :total', ['total' => \App\Models\Merchandise\Product::fmtCurrency($order->total_ttc)]) }} + {{ __('TVA : :total', ['total' => \App\Lib\Helpers\ToolboxHelper::fmtCurrency($order->total_ttc - $order->total_ht)]) }} + {{ __('Total TTC : :total', ['total' => \App\Lib\Helpers\ToolboxHelper::fmtCurrency($order->total_ttc)]) }} {{ __('Payé : :total', ['total' => app('phpMoneyFormatter')->format($order->getTotalPayed())]) }} {{ __('Reboursé : :total', ['total' => app('phpMoneyFormatter')->format($order->getTotalRefunded())]) }} diff --git a/resources/views/pages/orders/indexList.blade.php b/resources/views/pages/orders/indexList.blade.php index c8955a5..ab85fed 100644 --- a/resources/views/pages/orders/indexList.blade.php +++ b/resources/views/pages/orders/indexList.blade.php @@ -29,7 +29,7 @@ {{ $orderModel->reference }} {{ $orderModel->created_at->isoFormat('\L\e DD/MM/YYYY \à HH:mm') }} - {{ \App\Models\Merchandise\Product::fmtCurrency($orderModel->total_ttc, '') }} + {{ \App\Lib\Helpers\ToolboxHelper::fmtCurrency($orderModel->total_ttc, '') }} @include('back::pages.orders.parts.badges.validation-status', ['order' => $orderModel]) @include('back::pages.orders.parts.badges.payment-status', ['order' => $orderModel]) @include('back::pages.orders.parts.badges.delivery-status', ['order' => $orderModel]) diff --git a/resources/views/pages/products/indexList.blade.php b/resources/views/pages/products/indexList.blade.php index 35a64b5..27ee523 100644 --- a/resources/views/pages/products/indexList.blade.php +++ b/resources/views/pages/products/indexList.blade.php @@ -45,7 +45,7 @@ - {{ \App\Models\Merchandise\Product::fmtCurrency($productModel->price, 'HT') }} + {{ \App\Lib\Helpers\ToolboxHelper::fmtCurrency($productModel->price, 'HT') }} {{ Str::limit(strip_tags($productModel->description)) }}