]> _ Git - fluidbook-html5.git/commitdiff
wip #6875 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 22 Apr 2024 16:22:27 +0000 (18:22 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 22 Apr 2024 16:22:27 +0000 (18:22 +0200)
js/libs/fluidbook/cart/fluidbook.cart.bastide-resah.js
js/libs/fluidbook/fluidbook.cart.js
js/libs/fluidbook/fluidbook.menu.js
style/cart/bastide-resah-cart.less

index dad3fdd8e04bed43f15b09ebbf1fabf0fd04a3a4..e328558e8b0f37b3509be53d6d912631225797d2 100644 (file)
@@ -31,25 +31,21 @@ FluidbookCartBastideResah.prototype = {
         $(document).on(this.fluidbook.input.clickEvent, '#Bastide_cart [data-validate-cart]', function (event) {
             event.preventDefault();
 
-            // Use the built-in HTML5 validation to make sure all fields are valid in the cart
-            let form = $(this).parents('form');
-            let isValid = form[0].reportValidity();
-
-            if (isValid) {
-                // Originally this was in the link's href but for some reason the validation was
-                // skipped and the URL change would always occur, even when using
-                // event.preventDefault() / event.stopImmediatePropagation / event.stopPropagation();
-                window.location.hash = '/cart/validate';
-            }
+            $.ajax('https://bastide-resah.fluidbook.com/fluidbook/order', {
+                method: 'POST',
+                data: {details:$this.getItems()},
+            });
+
+            $this.fluidbook.menu.quickCloseView();
+            $this.openModal("Merci !", '<div class="cart-sent">Vous recevrez un devis ainsi que les conditions générales de vente de la part du RESAH à l’adresse mail que vous avez mentionnée dans un délai d’environ 72h (pensez à vérifier votre dossier spam).<br><br>' +
+                'La validation de ce devis auprès du RESAH nécessitera l’établissement et l’envoi au RESAH d’un bon de commande valant pour acceptation pleine et entière.<br><br>' +
+                'Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">resah@bastide-medical.fr</a></div>', function () {
+
+            });
+
         });
     },
 
-    // emptyCart: function () {
-    //     this.items = [];
-    //     this.updateCart();
-    //     this.save();
-    //     resize();
-    // },
 
     getCartItemIndex: function (reference) {
         let cartItems = this.getItems();
@@ -115,33 +111,6 @@ FluidbookCartBastideResah.prototype = {
         return this.getItems().length;
     },
 
-    getItemsForXLS: function () {
-        let $this = this;
-        let items = [];
-
-        $.each(this.getItems(), function (index, cart_item) {
-
-            let item = {};
-            let cart_reference = cart_item['reference'];
-            let data = $this.data[cart_reference]; // Source data matched from spreadsheet
-
-            $.each($this.getColumnsForXLS(), function (key, title) {
-
-                switch (key) {
-                    case 'QUANTITY':
-                        item[key] = cart_item['quantity'];
-                        break;
-                    default:
-                        item[key] = data[key];
-                }
-            });
-
-            items.push(item);
-        });
-
-        return items;
-    },
-
     updateCart: function () {
         if ($('#Bastide_cart').length > 0) {
             $('#Bastide_cart .content').html(this.getCartContent());
@@ -161,18 +130,15 @@ FluidbookCartBastideResah.prototype = {
                         </div>
                     </div>`;
         this.fluidbook.menu.viewWrap(view, 'cart');
+        this.fluidbook.menu.openingView(function () {
+
+        }, 'cart');
         callback();
     },
 
     openMenu: function (p1, p2, callback) {
-
         this.fluidbook.menu.quickCloseView();
 
-        // Handle the validation screen when accessed via #/cart/validate
-        if (p1 === 'validate') {
-            return this.openCartUserDetails(callback);
-        }
-
         // The cart opens every time an item is added, so the user can pick a colour and quantity
         // These URLs use the #/cart/add/xxxxx URL to pass the reference across
         if (p1 === 'add' && p2) {
@@ -187,79 +153,26 @@ FluidbookCartBastideResah.prototype = {
         });
     },
 
-    openCartUserDetails: function (callback) {
-        $('html').removeClass('cart-form-visible'); // Make sure forms are hidden initially
-        this.openModal('Mes Coordonnées', this.getCartUserDetailsContent(), function () {
-            callback();
-        });
-    },
-
     getColumns: function () {
-        // Map of data key names to their display labels - this controls the order of the columns
-        // Note: the key names here should match the first row column titles in the spreadsheet
-        // This can be overridden by specifying the cart_columns in the "Paramètres panier" field (cartExtraSettings)
-        // The format for the setting is:
-        // cart_columns=XLS COL NAME|Display label,XLS COL 2|Display label 2
-        if (fluidbook.settings.cartColumns) {
-            return fluidbook.settings.cartColumns;
-        }
-
         return {
-            'ARTICLE CODE': 'Réf',
-            'ARTICLE': 'Article',
-            'CONDITIONNEMENT VENTE': 'Conditionnement',
-            'QUANTITY': 'Quantité', // Special case: not part of the data
-            'DELETE': '', // No column label for delete buttons
+            'CIP': 'CIP',
+            'REF RESAH': 'Référence RESAH',
+            'DESIGNATION': 'DESIGNATION',
+            'PV RESAH HT': 'Prix unitaire HT',
+            'TVA': 'Taux de TVA',
+            'ECOTAXE': 'éco Taxe',
+            'QUANTITY': 'Quantité',
+            'TOTAL_HT': 'Total HT',
+            'DELETE': '',
         };
     },
 
-    getColumnsForXLS: function () {
-        // The columns should be the same as for the cart except we skip "DELETE"
-        let columns = {};
-
-        $.each(this.getColumns(), function (key, title) {
-
-            if (key === 'DELETE') return;
-
-            columns[key] = title;
-        });
-
-        return columns;
+    getMenuHeight: function () {
+        return this.fluidbook.resize.hh * 0.95;
     },
 
-    // This cart was based off CFOC's, so we're keeping the structure where it's possible to have multiple forms
-    getForms: function () {
-        return {
-            'default': {
-                'name': {
-                    'label': "Nom et Prénom",
-                    'type': 'text',
-                    'required': true
-                },
-                'phone': {
-                    'label': "Téléphone",
-                    'type': 'text',
-                    'required': true
-                },
-                'email': {
-                    'label': "Email",
-                    'type': 'email',
-                    'required': true
-                },
-                'billing_address': {
-                    'label': "Adresse de facturation",
-                    'type': 'textarea',
-                    'rows': 2,
-                    'required': false
-                },
-                'message': {
-                    'label': "Message",
-                    'type': 'textarea',
-                    'rows': 3,
-                    'required': false
-                },
-            },
-        }
+    getMenuWidth: function () {
+        return $('.cart-sent').length > 0 ? 440 : 1385;
     },
 
     getCartContent: function () {
@@ -267,19 +180,22 @@ FluidbookCartBastideResah.prototype = {
             return `<div class="cart-empty">${this.fluidbook.l10n.__('your cart is empty')}</div>`;
         }
 
+        let total_ht;
+        let tva;
+        let eco_taxe;
+        let total_ttc = total_ht = tva = eco_taxe = 0;
+
         let $this = this;
         let columns = this.getColumns();
 
-        let content =
-            `<div class="inner-content">
+        let content = `<div class="inner-content">
              <form>
              <table id="bastide-cart-table" class="cart-items">
                <thead style="text-transform:uppercase">
                  <tr>
                    ${Object.entries(columns)
-                .map(heading => `<th data-name="${heading[0]}">${heading[1]}</th>`)
-                .join('')
-            }
+            .map(heading => `<th data-name="${heading[0]}">${heading[1]}</th>`)
+            .join('')}
                  </tr>
                </thead>
                <tbody>`;
@@ -294,10 +210,21 @@ FluidbookCartBastideResah.prototype = {
                 let value = data[key] || '&mdash;'; // Fallback for missing values
                 let output = '';
 
-                switch (key) {
+                let et = $this.parseFloat($this.data[item.reference]['ECOTAXE']);
+                let ht = $this.parseFloat($this.data[item.reference]['PV RESAH HT']) + et;
+                let tht = item.quantity * ht;
+
+                total_ht += tht;
+                eco_taxe += item.quantity * et;
+                tva += $this.parseFloat($this.data[item.reference]['TVA']) * tht * 0.01;
 
-                    case 'PRIX':
-                        output += $this.formatPrice(value);
+                switch (key) {
+                    case 'PV RESAH HT':
+                    case 'ECOTAXE':
+                        output = $this.formatPrice($this.parseFloat(value));
+                        break;
+                    case 'TOTAL_HT':
+                        output += $this.formatPrice(tht);
                         break;
                     case 'QUANTITY':
                         let min_quantity = 1;
@@ -340,72 +267,44 @@ FluidbookCartBastideResah.prototype = {
             content += '</tr>';
         });
 
+        total_ttc = tva + eco_taxe + total_ht;
+
         content += '</tbody>';
         content += '</table>';
 
+
+        content += '</form>';
+
+        content += '<hr>';
+
+        content += '<table class="totals">';
+        content += '<tr><td>Montant HT : </td><td>' + this.formatPrice(total_ht) + '</td></tr>';
+        content += '<tr><td>TVA : </td><td>' + this.formatPrice(tva) + '</td></tr>';
+        content += '<tr><td>éco Taxe : </td><td>' + this.formatPrice(eco_taxe) + '</td></tr>';
+        content += '<tr><td>Montant TTC : </td><td>' + this.formatPrice(total_ttc) + '</td></tr>';
+        content += '</table>';
+
+        content += '<div class="clear"></div>';
+
         content += `<div class="fonctions">
                       <a href="#/closeview" class="close-cart">
                         Compléter ma sélection
                       </a>
                       <a href="#" class="validate-cart" data-validate-cart>
-                        Valider ma Sélection
+                        Envoyer ma demande
                       </a>
                     </div>`;
 
-        content += '</form>';
-        content += '</div><!-- .inner-content -->';
+        content += '<div class="clear"></div>'
 
-        return content;
-    },
-
-    getCartUserDetailsContent: function () {
-
-        let forms = '';
-
-        $.each(this.getForms(), function (name, fields) {
-            forms += `<form data-name="${name}">`;
-
-            $.each(fields, function (field_name, field_details) {
-                let required = field_details.required ? 'required' : '';
-                let label = field_details.required ? `${field_details.label}*` : field_details.label;
-                let field_ID = `${name}_${field_name}`;
-
-                forms += `<label for="${field_ID}">${label}</label>`;
-
-                switch (field_details.type) {
-                    case 'textarea':
-                        forms += `<textarea id="${field_ID}" name="${field_name}" rows="${field_details.rows || 3}" ${required}></textarea>`
-                        break;
-                    default:
-                        forms += `<input id="${field_name}" name="${field_name}" type="${field_details.type}" ${required}>`;
-                }
-            });
-
-            forms += `</form>`;
-        });
-
-        let content =
-            `<div class="inner-content" id="Bastide_user_details">
-            <div class="details-form">
-              ${forms}
-              <div class="required-fields-notice">*Champs obligatoires</div>
-            </div><!-- .details-columns -->
-            <div class="details-footer fonctions">
-              <a href="#/cart" class="back-to-cart">
-                Retour à ma Sélection
-              </a>
-              <a href="#" class="send-cart" data-send-cart>Envoyer ma demande</a>
-            </div><!-- .details-footer -->
-            <div class="server-response" style="display:none"><!-- placeholder for AJAX response --></div>
-          </div><!-- .inner-content -->
-          `;
+        content += '<p class="legal">Ce portail vous permet d’obtenir un document quantitatif estimatif.<br>'
+            + 'Vous recevrez un devis ainsi que les conditions générales de vente de la part du RESAH à l’adresse mail que vous avez mentionné dans un délai d’environ 72H.<br>' + 'La validation de ce devis auprès du RESAH nécessitera l’établissement et l’envoi au RESAH d’un bon de commande valant pour acceptation pleine et entière.<br>'
+            + 'Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">resah@bastide-medical.fr</a></p>';
+        content += '</div><!-- .inner-content -->';
 
         return content;
     },
 
-    getMenuWidth: function () {
-        return window.location.hash === '#/cart/validate' ? 990 : 1190; // Validate modal is narrower than main cart
-    },
 
     formatPrice: function (price) {
 
@@ -414,10 +313,7 @@ FluidbookCartBastideResah.prototype = {
         }
 
         return price.toLocaleString("fr-FR", {
-            style: "currency",
-            currency: "EUR",
-            minimumFractionDigits: 2,
-            maximumFractionDigits: 2
+            style: "currency", currency: "EUR", minimumFractionDigits: 2, maximumFractionDigits: 2
         });
     },
 
@@ -429,6 +325,7 @@ FluidbookCartBastideResah.prototype = {
             return 0;
         }
         s = s.replace(/\s/g, '');
+        s = s.replace(/,/g, '');
         return parseFloat(s);
     },
 };
index a70c0ce91e1b98ad90596977ee9ea128ab8bea29..9343682d85c4365c589bfbeb882390f04e6ad543 100644 (file)
@@ -187,11 +187,24 @@ FluidbookCart.prototype = {
         return 1024;
     },
 
+    getMenuHeight: function () {
+        try {
+            return this.instance.getMenuHeight();
+        } catch (e) {
+
+        }
+        return this.fluidbook.resize.hh * 0.8;
+    },
+
     getSavedData: function () {
         return this.fluidbook.cache.get('cart', {})
-    }, saveData: function (data) {
+    },
+
+    saveData: function (data) {
         this.fluidbook.cache.set('cart', data);
-    }, createInstance: function () {
+    },
+
+    createInstance: function () {
         switch (this.fluidbook.settings.basketManager) {
             case "Remarkable":
                 return new FluidbookCartRemarkable(this);
index e0b1b4e24e1e15843c9a58bd59e35251068bac8c..3708eea59dd228ce8685ef85b5eb3fdb03dec8cc 100644 (file)
@@ -891,6 +891,7 @@ FluidbookMenu.prototype = {
                 break;
             case 'cart':
                 w = this.fluidbook.cart.getMenuWidth();
+                h=this.fluidbook.cart.getMenuHeight();
                 if (ww < w) {
                     fullscreen = true;
                 }
index 2aba15bb4aa16aa651c1e6f5dedfe5022a17b011..5b6d24ca91ccedb968d7a65018099df85433c681 100644 (file)
   min-width: 320px;
   font-size: 18px;
 
+  .cart-sent {
+    padding: 20px 50px;
+    font-size: 16px;
+    text-align: left;
+
+    a {
+      color: @menu-background !important;
+      text-decoration: underline;
+    }
+  }
+
+  * {
+    font-family: 'Roboto Condensed', sans-serif !important;
+  }
+
+
   @media (max-width: 1060px) {
     font-size: 15px;
   }
@@ -45,7 +61,7 @@
   }
 
   .caption {
-    padding: 30px 20px;
+    padding: 30px 35px 30px 35px;
     height: auto;
   }
 
     margin: 0 auto;
     position: relative;
 
+    p.legal {
+      clear: both;
+      font-size: 12px;
+      text-align: left;
+      padding: 30px 0;
+
+      a {
+        color: @menu-background;
+        text-decoration: underline;
+      }
+    }
+
     @media @breakpoint_table {
       width: 90%;
     }
   }
 
+  hr {
+    margin: 20px 0;
+  }
+
+
+  .totals {
+    float: right;
+    width: 33%;
+    font-size: 14px;
+
+    td {
+      text-transform: uppercase;
+      text-align: right;
+      padding: 5px;
+    }
+
+    tr:last-child td {
+      font-weight: bold;
+    }
+  }
+
   // Main table
   table.cart-items {
     width: 100%;
     th {
       color: #fff;
       font-weight: bold;
-      text-align: left;
+      text-align: center;
     }
 
     th, td {
     font-size: 1em;
     width: 100%;
   }
+
   input, select, textarea {
     background-color: #fff;
     font-family: inherit;
 
   }
 
+  .clear {
+    clear: both;
+  }
+
   .fonctions {
+
     display: flex;
     align-items: center;
     justify-content: flex-end;