]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7957
authorsoufiane <soufiane@cubedesigners.com>
Thu, 29 Jan 2026 13:48:05 +0000 (14:48 +0100)
committersoufiane <soufiane@cubedesigners.com>
Thu, 29 Jan 2026 13:48:05 +0000 (14:48 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/NewHeidiOperation.php

index 1c9a897981260a2f421768fbc74a3d2ecd1a1017..4fee8faab337bddb3f09578bb5cfc5866348087b 100644 (file)
@@ -54,6 +54,7 @@ trait NewHeidiOperation
             'Email' => request('mail'),
             'Téléphone' => request('phone'),
             'Adresse' => request('address'),
+            'Date de livraison souhaitée' => request('delivery_date'),
             'Message' => request('message'),
         ];
 
@@ -62,17 +63,33 @@ trait NewHeidiOperation
         }
 
         $cart_items = json_decode(request('cart_items'), true);
-        $file = $this->getCsv($cart_items, $formData);
-        $this->sendMail($file, request('mail'));
+        $totals = $this->calcTotals($cart_items);
+        $file = $this->getCsvNewHeidi($cart_items, $formData, $totals);
+        $this->sendMailNewHeidi($file, request('mail'));
     }
 
-    public function getCsvNewHeidi($cart_items, $user_details)
+    public function calcTotals($cart_items) {
+        $prices = array_map(function($n) { return $n['price'] * intval($n['quantity']); }, $cart_items);
+        $totalHT = array_reduce($prices, function($carry, $item) { $carry += $item; return $carry;});
+        $tva = $totalHT * 20 / 100;
+        $totalTTC = floatval($totalHT + $tva);
+
+        return [
+            'Total HT' => $totalHT,
+            'TVA' => $tva,
+            'Total TTC' => $totalTTC
+        ];
+    }
+
+    public function getCsvNewHeidi($cart_items, $user_details, $totals)
     {
         $column_headings = [
             'ref' => 'Réference',
             'name' => 'Désignation',
-            'quantity' => 'Quantité',
-            'comment' => 'Commentaire'
+            'batch' => 'Unités par lot',
+            'price' => 'Prix du lot (EUR HT)',
+            'quantity' => 'Quantité (Lots)',
+            'sub_total' => 'Sous-total (EUR HT)'
         ];
 
         $excel = new Spreadsheet();
@@ -118,6 +135,15 @@ trait NewHeidiOperation
                         $sheet->setCellValueByColumnAndRow($column_index + 1, $current_row, $cart_item[$column_key]);
                         $current_cell_style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER);
                         break;
+                    case 'sub_total':
+                        $subtotal = floatval($cart_item['price']) * intval($cart_item['quantity']);
+                        $sheet->setCellValueByColumnAndRow($column_index + 1, $current_row, $subtotal);
+                        $current_cell_style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
+                        break;
+                    case 'price':
+                        $sheet->setCellValueByColumnAndRow($column_index + 1, $current_row, $cart_item[$column_key]);
+                        $current_cell_style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
+                        break;
                     default:
                         $sheet->setCellValueByColumnAndRow($column_index + 1, $current_row, $cart_item[$column_key]);
                 }
@@ -130,8 +156,22 @@ trait NewHeidiOperation
             $sheet->getColumnDimensionByColumn($i)->setAutoSize(true);
         }
 
-        $details_sheet = $excel->addSheet(new Worksheet($excel, 'Coordonnées'), 0); // Setting index to zero will put this sheet first in the workbook
+        $sheet->insertNewRowBefore($current_row+=1);
 
+        foreach ($totals as $key => $value) {
+            $current_row++;
+
+            $details_label_style = $sheet->getStyleByColumnAndRow(1, $current_row);
+            $details_label_style->getFont()->setBold(true);
+
+            $details_value_style = $sheet->getStyleByColumnAndRow(2, $current_row);
+            $details_value_style->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
+
+            $sheet->setCellValueByColumnAndRow(1, $current_row, $key . ' :');
+            $sheet->setCellValueByColumnAndRow(2, $current_row, $value . ' €');
+        }
+
+        $details_sheet = $excel->addSheet(new Worksheet($excel, 'Coordonnées'), 0); // Setting index to zero will put this sheet first in the workbook
         $current_row = 1;
         foreach ($user_details as $key => $value) {
             // User details are displayed as Label: Value in the A & B columns
@@ -178,21 +218,20 @@ trait NewHeidiOperation
 
     public function sendMailNewHeidi($xls_file, $user_email)
     {
-
         $admin = 'test@fluidbook.com';
 
         $email_for_newheidi = $admin;
         $return_address = 'toolbox@fluidbook.com';
-        $email_from_name = "Kim'Play";
+        $email_from_name = "New Heidi";
         $email_reply_to = $admin;
-        $email_newheidi_subject = 'Demande catalogue Kim\'Play';
-        $email_user_subject = 'Récapitulatif de votre demande Kim\'Play';
-        $email_to_user_body = "Bonjour,<br><br>Votre demande est en cours de traitement (récapitulatif en pièce jointe). Nous vous recontacterons dans les meilleurs délais. D’ici là nous restons joignables pour toute question à l’adresse : info@cofalu.com<br><br>Cordialement,<br><br>L'équipe commerciale";
-        $email_to_newheidi_body = "Bonjour,<br><br>Une commande a été passée (récapitulatif en pièce jointe).<br><br>Cordialement<br><br>";
+        $email_newheidi_subject = 'Commande B2B (catalogue fluidbook)';
+        $email_user_subject = 'Votre commande New Heidi';
+        $email_to_user_body = "Bonjour,<br><br>Votre demande est en cours de traitement (récapitulatif en pièce jointe). Nous vous recontacterons dans les meilleurs délais. D’ici là nous restons joignables pour toute question à l’adresse : info@newheidi.com<br><br>Merci !";
+        $email_to_newheidi_body = "Récapitulatif en pièce jointe.<br><br>";
 
         // Filename for attachment (without extension)
         $orderId = date('YmdHis');
-        $attachment_basename = "Kim'Play" . $orderId;
+        $attachment_basename = "New_Heidi" . $orderId;
 
         //=== Send the email
         // There are two almost identical e-mails sent: