]> _ Git - pmi.git/commitdiff
wip #6106 @3:00
authorsoufiane <soufiane@cubedesigners.com>
Thu, 6 Jul 2023 14:19:39 +0000 (16:19 +0200)
committersoufiane <soufiane@cubedesigners.com>
Thu, 6 Jul 2023 14:19:39 +0000 (16:19 +0200)
app/Http/Controllers/AjaxController.php
app/Models/Client.php
app/Models/ECommerceCommon.php
app/Models/Order.php
resources/views/components/item-cart-order.blade.php
resources/views/layouts/app.blade.php

index 172c3d80d28e832580cce188a8b07b120ec91895..b1bddb9630209ed15d8327b3c53a92bb20ded320 100644 (file)
@@ -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);
index 577d9c098995703efe4e77cbea245c19b9d5c48c..b1b7e4b60bf5bab6da03dfbe14f8dd43b7b187b3 100644 (file)
@@ -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';
         }
index a3c5fb83e98e703f9ba8684c85716f2ae543a8bd..a89a349ca42d2e6957e8c31bb5f5f9a6b13f1b92 100644 (file)
@@ -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'];
index 38904aa61ccaf208945b2924314a9965c13e16ee..7be9d27ee12be8c88161dfc70f9ec579824c767d 100644 (file)
@@ -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) {
index b0d063b7a816c498f4baeb580efe5f55583e195f..47cd452a7c35c6d0a06c3970866855db3ad4968f 100644 (file)
@@ -4,7 +4,7 @@
             <div class="flex justify-between">
                 <div>
                     <p class="no-m">{{ __('Date de commande') }}</p>
-                    <p class="no-m text-navy">{{ \Carbon\Carbon::parse($item['created_at'])->isoFormat("D/MM/Y") }}</p>
+                    <p class="no-m text-navy">{{ \Carbon\Carbon::parse($item['created_at'])->isoFormat("DD/MM/Y") }}</p>
                 </div>
                 <div class="text-right">
                     <p class="no-m">{{ __('Numéro de commande') }}</p>
@@ -20,7 +20,7 @@
                     </div>
                     <div class="product-infos flex justify-between items-center">
                         <div>
-                            <p class="no-m">{{ $product['ref'] }}</p>
+                            <p class="no-m">{{ $product['reference'].'|'.$product['ref'] }}</p>
                             <p class="no-m text-navy">{{ $product['name'] }}</p>
                             @if(isset($product['discount']) && $product['discount'] !== 0)
                                 @if(floatval($product['basic_selling_price']))
@@ -73,7 +73,7 @@
                 @if($item['total'])
                     <div class="text-right pb-6">
                         <p class="no-m">{{ __('Montant Total') }}</p>
-                        <p class="no-m">{{ $item['total'] }}€ HT</p>
+                        <p class="no-m">{{ $item['total'] }}€ TTC</p>
                     </div>
                 @endif
             </div>
index 409c97c667ca003e8f02973b4bbb72664b16767b..f0c869bfad2fbdabf6f8fa15234dd98edc877bbc 100644 (file)
@@ -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')