From: soufiane Date: Thu, 6 Jul 2023 14:19:39 +0000 (+0200) Subject: wip #6106 @3:00 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e8dcb563a7b51a051825761b1c22d3b215670368;p=pmi.git wip #6106 @3:00 --- diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 172c3d8..b1bddb9 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -680,6 +680,20 @@ class AjaxController extends CubistFrontController $currentCartRef = Cart::getRefs($data['products']); $data = Order::fillData($currentCartRef,$data,$productsInfosBase); + $company = array_values(array_filter(json_decode($data['addresses'], true), function($n) { + return intval($n['delivery_address']); + }))[0]['company']; + + $data['company'] = $company; + $data['email'] = Client::getClientConnected()->email; + $data['request_date'] = Carbon::now('Europe/Paris'); + $data['products'] = json_encode(array_map(function($n){ + $exp = explode('|',$n['ref']); + array_shift($exp); + $n['ref'] = sizeof($exp) > 1 ? implode('|', $exp) : $exp; + return $n; + }, json_decode($data['products'],true))); + $data['user'] = Client::getClientConnected()->email; if($data) { $order = Order::create($data); diff --git a/app/Models/Client.php b/app/Models/Client.php index 577d9c0..b1b7e4b 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -105,6 +105,10 @@ class Client extends CubistMagicAbstractModel return Auth::guard('web-clients')->user(); } + public static function getEmailsClientsApproved() { + return self::all()->where('status',1)->pluck('email'); + } + public static function getCategory() { return self::getClientConnected()->discount ?? 'A'; } @@ -130,8 +134,6 @@ class Client extends CubistMagicAbstractModel $discount_array = array_combine($discount_array_save_keys,$discount_array); - dump($categoryProduct); - if(!in_array($categoryProduct, $discount_array)) { $categoryProduct = 'A'; } diff --git a/app/Models/ECommerceCommon.php b/app/Models/ECommerceCommon.php index a3c5fb8..a89a349 100644 --- a/app/Models/ECommerceCommon.php +++ b/app/Models/ECommerceCommon.php @@ -10,25 +10,30 @@ class ECommerceCommon extends CubistMagicAbstractModel [ 'name' => 'user_id', 'label' => 'user_id', - 'type' => 'Text', - 'column' => true + 'type' => 'Hidden', + 'column' => false ], [ 'name' => 'addresses', - 'label' => 'Adresses', - 'type' => 'Text', - 'column' => true + 'label' => 'Adresse', + 'type' => 'BunchOfFieldsMultiple', + 'bunch' => 'App\SubForms\Address', + 'column' => false, + 'tab' => 'Informations', + 'edit_label' => 'Éditer « %city »' ], [ 'name' => 'products', 'label' => 'Produits', - 'type' => 'Text', - 'column' => true + 'type' => 'Hidden', + 'column' => false ], [ 'name' => 'total', - 'type' => 'Text' - ] + 'label' => 'Total TTC', + 'type' => 'Text', + 'column' => true + ], ]; @@ -50,9 +55,10 @@ class ECommerceCommon extends CubistMagicAbstractModel */ foreach ($currentCartRef as $keyRefs => $refs) { $index = $data['products'][$keyRefs]['id']; + $explodeRef = explode("|", $refs); if($productsInfosBase[$index][0]['json']) { $options = json_decode($productsInfosBase[$index][0]['json'], true); - foreach (explode("/", $refs) as $key => $ref) { + foreach ($explodeRef as $key => $ref) { $key -= 1; if ($key > -1) { $options_ = $options[$key]['options']; diff --git a/app/Models/Order.php b/app/Models/Order.php index 38904aa..7be9d27 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -20,25 +20,63 @@ class Order extends ECommerceCommon { parent::setFields(); - foreach ($this->fields as $fields) { - $fields['tab'] = 'Informations'; - $this->addField($fields); - } + $tabOrder = 'Commande'; + + $this->addField(['name' => 'user', + 'label' => 'Utilisateur', + 'type' => 'SelectFromArray', + 'options' => Client::getEmailsClientsApproved(), + 'tab' => 'Informations' + ]); + + $this->addField(['name' => 'company', + 'label' => 'Société', + 'type' => 'Text', + 'column' => true, + 'tab' => 'Informations' + ]); + + $this->addField(['name' => 'email', + 'label' => 'Email', + 'type' => 'Text', + 'column' => true, + 'tab' => 'Informations' + ]); $this->addField(['name' => 'status', - 'label' => 'Statut', + 'label' => 'Status', 'type' => 'SelectFromArray', 'column' => true, 'options' => self::$_optionsForSelect, 'default' => 'new', - 'tab' => 'Informations' + 'tab' => $tabOrder ]); $this->addField(['name' => 'complete_status', - 'label' => 'Indication du statut', + 'label' => 'Indication du status', 'type' => 'Text', - 'tab' => 'Informations' + 'tab' => $tabOrder ]); + + $this->addField(['name' => 'request_date', + 'label' => 'Date', + 'type' => 'Datetime', + 'column' => true, + 'tab' => $tabOrder]); + + foreach ($this->fields as $fields) { + if ($fields['name'] === 'products') { + $fields = ['name' => 'products', + 'label' => 'Produits', + 'type' => 'Table', + 'columns' => ['id' => '#', 'ref' => 'Référence options', 'reference' => 'Référence produit', 'name' => 'Nom de produit', 'quantity' => 'Quantité'], + 'tab' => $tabOrder]; + } + if ($fields['name'] === 'total') { + $fields['tab'] = $tabOrder; + } + $this->addField($fields); + } } public static function getOptionValue($key) { diff --git a/resources/views/components/item-cart-order.blade.php b/resources/views/components/item-cart-order.blade.php index b0d063b..47cd452 100644 --- a/resources/views/components/item-cart-order.blade.php +++ b/resources/views/components/item-cart-order.blade.php @@ -4,7 +4,7 @@

{{ __('Date de commande') }}

-

{{ \Carbon\Carbon::parse($item['created_at'])->isoFormat("D/MM/Y") }}

+

{{ \Carbon\Carbon::parse($item['created_at'])->isoFormat("DD/MM/Y") }}

{{ __('Numéro de commande') }}

@@ -20,7 +20,7 @@
-

{{ $product['ref'] }}

+

{{ $product['reference'].'|'.$product['ref'] }}

{{ $product['name'] }}

@if(isset($product['discount']) && $product['discount'] !== 0) @if(floatval($product['basic_selling_price'])) @@ -73,7 +73,7 @@ @if($item['total'])

{{ __('Montant Total') }}

-

{{ $item['total'] }}€ HT

+

{{ $item['total'] }}€ TTC

@endif
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 409c97c..f0c869b 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -1,5 +1,5 @@ @php - $now = \Carbon\Carbon::now('Europe/Paris')->isoFormat('D/MM/Y'); + $now = \Carbon\Carbon::now('Europe/Paris')->isoFormat('DD/MM/Y'); @endphp @prepend('stylesheets')