PEEL Shopping
Open source ecommerce : PEEL Shopping
order.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: order.php 47245 2015-10-08 16:47:28Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
26 function get_bill_number($bill_number_format, $id, $generate_bill_number_if_empty = true)
27 {
28  if(empty($bill_number_format) && $generate_bill_number_if_empty){
29  // on récupère le format de numéro dans la base, si pas déjà spécifié lors de l'appel (pour édition dans l'administration par exemple)
30  $bill_number_format = vb($GLOBALS['site_parameters']['format_numero_facture']);
31  }
32  if (!empty($bill_number_format) && !empty($id)) {
33  // On remplace les tags standards gérés directement par template_tags_replace(...)
34  $bill_number_format = template_tags_replace($bill_number_format);
35  preg_match_all('#\[(.*?)\]#', $bill_number_format, $matches);
36  $tag_names = $matches[1];
37  if (!empty($tag_names)) {
38  // tag_name : représente le tag à l'intérieur des crochets, à savoir par exemple : ++,5 ou id ou id,5
39  // column : le nom de la colonne, ou ++
40  foreach($tag_names as $this_key => $this_item) {
41  // On traite les valeurs du type [xxx,N]
42  $temp = explode(',', $this_item);
43  // $tag_full_names_by_colum contient un tableau des différents tags faisant appel à une colonne de la table
44  $tag_full_names_by_colum[$temp[0]][] = $this_item;
45  if (!empty($temp[1])) {
46  $number_zero_fill_by_tag_name[$this_item] = $temp[1];
47  }
48  if ($temp[0] != '++') {
49  // Liste des colonnes de la table, donc les valeurs de columns qui ne sont pas ++
50  $column_names[] = $temp[0];
51  }
52  }
53  if (!empty($column_names)) {
54  $custom_template_tags = array();
55  // On va chercher les valeurs dans les champ de la table qui correspondent aux texte entre crochet du format de facture.
56  $sql = "SELECT " . implode(',', word_real_escape_string($column_names)) . "
57  FROM peel_commandes
58  WHERE id='" . intval($id) . "' AND " . get_filter_site_cond('commandes') . "";
59  $q = query($sql, false, null, true);
60  if ($result = fetch_assoc($q)) {
61  foreach($result as $this_column => $this_value) {
62  foreach($tag_full_names_by_colum[$this_column] as $this_tag_name) {
63  if (!empty($number_zero_fill_by_tag_name[$this_tag_name])) {
64  // On formatte les champs du type [xxx,N]
65  $this_value = str_pad($this_value, intval($number_zero_fill_by_tag_name[$this_tag_name]), 0, STR_PAD_LEFT);
66  }
67  $custom_template_tags[$this_tag_name] = $this_value;
68  }
69  }
70  }
71  // On remplace les tags trouvés ci-dessus
72  $bill_number_format = template_tags_replace($bill_number_format, $custom_template_tags);
73  }
74  // On ne gère qu'un seul tag du type ++ dans la formule globale, on ne peut pas en mettre plusieurs (ce qui serait par ailleurs très peu utile concrètement)
75  if (!empty($tag_full_names_by_colum['++'])) {
76  // On gère l'incrémentation du numéro si utilisation de [++]
77  // Par exemple pour TEST43[++]ACD : on cherche les numéros déjà enregistrés commençant par TEST43
78  // Si on en trouve un qui est TEST43538ACD, on va donc donner TEST43 concaténé avec 538+1 puis ACD => ça donne TEST43539ACD
79  $bill_number_format_begin = String::substr($bill_number_format, 0, String::strpos($bill_number_format, '[++'));
80  $bill_number_format_end = String::substr($bill_number_format, String::strpos($bill_number_format, ']') + 1);
81  $sql = "SELECT MAX(0+SUBSTRING(numero,1+" . String::strlen($bill_number_format_begin) . ",LENGTH(numero)-" . (String::strlen($bill_number_format_begin) + String::strlen($bill_number_format_end)) . ")) AS max_numero_part
82  FROM peel_commandes
83  WHERE id<>'" . intval($id) . "' AND " . get_filter_site_cond('commandes') . " AND numero LIKE '" . real_escape_string($bill_number_format_begin) . "%" . real_escape_string($bill_number_format_end) . "' AND SUBSTRING(numero,1+" . String::strlen($bill_number_format_begin) . ",LENGTH(numero)-" . (String::strlen($bill_number_format_begin) + String::strlen($bill_number_format_end)) . ") REGEXP ('^([0-9]+)$')";
84  $q = query($sql);
85  if ($result = fetch_assoc($q)) {
86  $last_number = $result['max_numero_part'];
87  } else {
88  $last_number = 0;
89  }
90  $bill_number_format_incremented_part = 1 + $last_number;
91  foreach($tag_full_names_by_colum['++'] as $this_tag_name) {
92  // NB : on ne gère qu'un seul tag du type ++ au maximum
93  if (!empty($number_zero_fill_by_tag_name[$this_tag_name])) {
94  // On formatte les champs du type [xxx,N]
95  $bill_number_format_incremented_part = str_pad($bill_number_format_incremented_part, $number_zero_fill_by_tag_name[$this_tag_name], 0, STR_PAD_LEFT);
96  }
97  }
98  $bill_number_format = $bill_number_format_begin . $bill_number_format_incremented_part . $bill_number_format_end;
99  }
100  }
101  }
102  return $bill_number_format;
103 }
104 
113 function accounting_insert_transaction($order_id, $technical_code, $data) {
114  // Si la REF de la transaction est vide, on vérifie qu'on a le même libellé
115  // et quoiqu'il arrive on teste la date pour être sûr qu'on ne modifie pas de vieilles transactions
116  $allowed_fields = get_table_field_names('peel_transactions');
117  if(empty($data['datetime'])) {
118  $data['datetime'] = date('Y-m-d H:i:s', time());
119  } else {
120  $data['datetime'] = get_mysql_date_from_user_input($data['datetime']);
121  }
122  $data['orders_id'] = $order_id;
123  // date (ddmmyyyy) + plateforme (dto, dinn, dfun, dexpe, dsale, dinve) => corrigé uniquement sur 3 lettres
124  // + heure (hhmmss) + 3 lettres aléatoires de l'alphabet + un nombre aléatoire compris entre 00000 et 99999. => Corrigé en 8 lettres différentes
125  // Exemple final : 30072014dex210738ihz16794
126  $data['reference'] = date('dmY') . vb($GLOBALS['site_parameters']['transaction_reference_site_part'], MDP(3)) . date('His') . MDP(8);
127  foreach($data as $item => $value) {
128  if(in_array($item, $allowed_fields)) {
129  $sql_set[$item] = word_real_escape_string($item) . "='" . str_replace(array("\n", "\r"), ' ', real_escape_string($value)) . "'";
130  }
131  }
132  // Sécurité : ne pas imposer l'id
133  unset($sql_set['id']);
134  $query = query("SELECT t.id
135  FROM peel_transactions t
136  WHERE REF='" . real_escape_string(vb($data['REF'])) . "'" . (true || (empty($data['REF']) || $data['REF'] == '_______' || strpos(vb($data['LIBELLE_OPERATION']), ' AP') !== false)?" AND LIBELLE_OPERATION='" . real_escape_string(vb($data['LIBELLE_OPERATION'])) . "' AND MONTANT_DEBIT='".real_escape_string(vb($data['MONTANT_DEBIT']))."' AND MONTANT_CREDIT='".real_escape_string(vb($data['MONTANT_CREDIT']))."'":"") . " AND (TO_DAYS(datetime) BETWEEN TO_DAYS('" . real_escape_string($data['datetime']) . "')-2 AND TO_DAYS('" . real_escape_string($data['datetime']) . "')+2)
137  ");
138  if ($result_query = fetch_assoc($query)) {
139  query("UPDATE peel_transactions
140  SET " . implode(',', $sql_set) . "
141  WHERE id='" . real_escape_string($result_query['id']) . "' AND bank='" . real_escape_string($result_query['bank']) . "'");
142  } else {
143  query("INSERT INTO peel_transactions
144  SET " . implode(',', $sql_set) . "");
145  $inserted_id = insert_id();
146  // Traitement des alertes par email
147  if (!empty($sql_set['reimbursement']) && vb($data['MONTANT_DEBIT']) > 0) {
148  $template_technical_code = 'reimbursement_debit';
149  } elseif (!empty($sql_set['cash']) && vb($data['MONTANT_CREDIT']) > 0) {
150  $template_technical_code = 'cash_credit';
151  } elseif (!empty($sql_set['wire']) && vb($data['MONTANT_CREDIT']) > 0) {
152  $template_technical_code = 'wire_credit';
153  } elseif (!empty($sql_set['wire']) && vb($data['MONTANT_DEBIT']) > 0) {
154  $template_technical_code = 'wire_debit';
155  }
156  if (!empty($template_technical_code)) {
157  // Envoi des emails d'information
158  send_email($GLOBALS['support'], null, null, $template_technical_code, $data);
159  }
160  }
161  unset($sql_set);
162  call_module_hook('accounting_insert_transaction', array('order_id' => $order_id, 'technical_code' => $technical_code, 'data' => $data));
163  return true;
164 }
165 
178 function update_order_payment_status($order_id, $status_or_is_payment_validated, $allow_update_paid_orders = true, $statut_livraison_new = null, $delivery_tracking = null, $no_stock_decrement_already_done = false, $payment_technical_code=null)
179 {
180  $output = '';
181  $sql_set_array = array();
182  // Payment status
183  if ($status_or_is_payment_validated === true) {
184  // Commande payée
185  $statut_paiement_new = 'completed';
186  if (check_if_module_active('download')) {
187  send_mail_product_download($order_id);
188  }
189  } elseif ($status_or_is_payment_validated === false) {
190  // Commande à annuler
191  $statut_paiement_new = 'cancelled';
192  } elseif(is_numeric($status_or_is_payment_validated)) {
193  // conversion de l'id du statut de paiement par son technical_code pour sa bonne prise en compte par update_order_payment_status
194  $sql = 'SELECT p.technical_code
195  FROM peel_statut_paiement p
196  WHERE technical_code!="" AND id=' . intval($status_or_is_payment_validated) . ' AND ' . get_filter_site_cond('statut_paiement', 'p');
197  $query = query($sql);
198  if ($result = fetch_assoc($query) ) {
199  $statut_paiement_new = $result['technical_code'];
200  } else {
201  $payment_status_by_legacy_id_compatibility_array = array(0 => "discussed", 1 => "pending", 2 => "being_checked", 3 => "completed", 6 => "cancelled", 9 => "refunded");
202  $statut_paiement_new = $payment_status_by_legacy_id_compatibility_array[intval($status_or_is_payment_validated)];
203  }
204  } elseif(!empty($status_or_is_payment_validated)) {
205  $statut_paiement_new = $status_or_is_payment_validated;
206  } else {
207  $statut_paiement_new = null;
208  }
209  $sql = 'SELECT p.id, p.technical_code
210  FROM peel_statut_paiement p
211  WHERE ' . get_filter_site_cond('statut_paiement', 'p');
212  $query = query($sql);
213  while ($result = fetch_assoc($query)) {
214  $payment_status_id_by_technical_code_array[$result['technical_code']] = $result['id'];
215  }
216 
217  // Delivery status
218  if(is_numeric($statut_livraison_new)) {
219  // conversion de l'id du statut de paiement par son technical_code pour sa bonne prise en compte par update_order_payment_status
220  $sql = 'SELECT l.technical_code
221  FROM peel_statut_livraison l
222  WHERE technical_code!="" AND id=' . intval($statut_livraison_new) . ' AND ' . get_filter_site_cond('statut_livraison', 'l');
223  $query = query($sql);
224  if ($result = fetch_assoc($query) ) {
225  $statut_livraison_new = $result['technical_code'];
226  } else {
227  $livraison_status_by_legacy_id_compatibility_array = array(0 => "discussed", 1 => "processing", 3 => "dispatched", 6 => "cancelled", 9 => "waiting_for_supply");
228  $statut_livraison_new = $livraison_status_by_legacy_id_compatibility_array[intval($statut_livraison_new)];
229  }
230  }
231  $sql = 'SELECT l.id, l.technical_code
232  FROM peel_statut_livraison l
233  WHERE ' . get_filter_site_cond('statut_livraison', 'l');
234  $query = query($sql);
235  while ($result = fetch_assoc($query)) {
236  $delivery_status_id_by_technical_code_array[$result['technical_code']] = $result['id'];
237  }
238  // Handling order
239  // defined('IN_PEEL_ADMIN') paramètre $use_admin_rights : Si on est dans l'admin, le site associé à la commande n'est pas obligatoirement le site_id associé au nom de domaine, mais le site_id défini pour l'administrateur par session_admin_multisite
240  $sql = "SELECT c.*, sp.technical_code AS statut_paiement, sl.technical_code AS statut_livraison
241  FROM peel_commandes c
242  LEFT JOIN peel_statut_paiement sp ON sp.id=c.id_statut_paiement AND " . get_filter_site_cond('statut_paiement', 'sp') . "
243  LEFT JOIN peel_statut_livraison sl ON sl.id=c.id_statut_livraison AND " . get_filter_site_cond('statut_livraison', 'sl') . "
244  WHERE c.id='" . intval($order_id) . "' AND " . get_filter_site_cond('commandes', 'c') . "";
245  $query = query($sql);
246  // On vérifie si la commande existe déjà
247  if ($commande = fetch_assoc($query)) {
248  if (empty($GLOBALS['site_parameters']['payment_status_create_bill']) || in_array($statut_paiement_new, explode(',', $GLOBALS['site_parameters']['payment_status_create_bill']))) {
249  // Quel que soit l'ancien statut, si la facture est souhaitée dans un statut qui doit avoir la génération de facture, alors on s'assure que le numéro et la date sont bien remplis
250  // get_bill_number crée un numéro de facture si il n'existe pas déjà à partir de $GLOBALS['site_parameters']['format_numero_facture']
251  // Si il existe déjà, get_bill_number le transforme en remplaçant les tags si pas déjà remplacés auparavant, et si il n'y en a pas alors le numéro sera inchangé au final
252  query("UPDATE peel_commandes
253  SET numero = '" . nohtml_real_escape_string(get_bill_number($commande['numero'], $order_id, true)) . "'
254  WHERE id = '" . intval($order_id) . "' AND " . get_filter_site_cond('commandes') . "");
255  // f_datetime contient la date d'émission de facture, et est éditable en back office.
256  // On la remplie si elle est vide
257  query("UPDATE peel_commandes
258  SET f_datetime = '" . date('Y-m-d H:i:s', time()) . "'
259  WHERE id = '" . intval($order_id) . "' AND f_datetime LIKE '0000-00-00%' AND " . get_filter_site_cond('commandes') . "");
260  }
261  if (!empty($payment_technical_code)) {
262  // Changement du moyen de paiement si celui ci est renseigné et que la commande est payé (statut 2 ou 3), même si elle était déjà en payé avant, ou si l'info paiement était vide avant
263  $sql="UPDATE peel_commandes
264  SET paiement='" . word_real_escape_string($payment_technical_code) . "'
265  WHERE id='" . intval($order_id) . "' AND " . get_filter_site_cond('commandes') . "";
266  if(!in_array($statut_paiement_new, array('being_checked', 'completed'))){
267  $sql.=" AND paiement=''";
268  }
269  query($sql);
270  }
271  if ($statut_paiement_new !== null && in_array($statut_paiement_new, array('being_checked', 'completed')) && !in_array($commande['statut_paiement'], array('being_checked','completed'))) {
272  if (check_if_module_active('gift_check')) {
273  $output .= cree_cheque_cadeau($order_id);
274  }
275  if (!empty($GLOBALS['fonctionsfianet_sac']) && file_exists($GLOBALS['fonctionsfianet_sac'])) {
276  require_once($GLOBALS['fonctionsfianet_sac']);
277  // envoi des informations sur la commande au service d'analyse des commande FIANET
278  send_fianet_sac($order_id);
279  }
280  // Mise à jour de la date de paiement si le statut est en réglé (et ne l'était pas avant)
281  $sql_set_array[] = "a_timestamp='" . date('Y-m-d H:i:s', time()) . "'";
282  if (check_if_module_active('annonces')) {
283  // On gère les crédits d'annonces GOLD
284  $sql = "SELECT pp.technical_code, pca.attributs_list, pca.reference, pca.quantite
285  FROM peel_produits pp
286  INNER JOIN peel_commandes_articles pca ON pca.produit_id = pp.id AND " . get_filter_site_cond('commandes_articles', 'pca') . "
287  INNER JOIN peel_commandes pc ON pc.id = pca.commande_id AND " . get_filter_site_cond('commandes', 'pc') . "
288  WHERE pc.id = " . intval($order_id) . " AND " . get_filter_site_cond('produits', 'pp') . "";
289  $query_t = query($sql);
290  while ($product_ordered_infos = fetch_assoc($query_t)) {
291  if (substr($product_ordered_infos['technical_code'], 0, strlen('annonce_g_')) == 'annonce_g_' || substr($product_ordered_infos['technical_code'], 0, strlen('gold_credit_')) == 'gold_credit_') {
292  if(substr($product_ordered_infos['technical_code'], 0, strlen('gold_credit_separated_')) == 'gold_credit_separated_') {
293  // Quand il y a _separated_ dans le nom, on considère que chaque crédit doit être mis sur une ligne séparée. Comme ça on pourra l'utiliser quand on veut
294  // (on aurait pu aussi ne mettre qu'une ligne mais diminuer le Xc en (X-1)x à chaque usage, mais c'est plus simple de mettre des lignes séparées
295  $temp = end(explode('_', $product_ordered_infos['technical_code']));
296  $lines_by_credit = String::substr($temp,0, String::strlen($temp)-1);
297  if($lines_by_credit == '*') {
298  // On n'insère qu'une ligne car illimité - dans ce cas, on ne la supprimera pas
299  $lines_by_credit = 1;
300  }
301  } else {
302  $lines_by_credit = 1;
303  }
304  for($i=1;$i<=$product_ordered_infos['quantite']*$lines_by_credit;$i++) {
305  // Format : annonce_g_12m_1c ou credit_gold_sales_6m_3c
306  add_credit_gold_user($commande['id_utilisateur'], $product_ordered_infos['technical_code'], $commande['id']);
307  }
308  } elseif (substr($product_ordered_infos['technical_code'], 0, strlen('ad_')) == 'ad_' && $product_ordered_infos['quantite']>=1) {
309  // On ajoute les attributs commandés à l'annonce
310  $update_attributs = 'UPDATE peel_lot_vente
311  SET attributs_list=CONCAT(attributs_list,IF(attributs_list="", "", "§"), "'.nohtml_real_escape_string($product_ordered_infos['attributs_list']).'")
312  WHERE ref ="' . intval($product_ordered_infos['reference']) . '" ' . get_filter_site_cond('lot_vente');
313  query($update_attributs);
314  }
315  }
316  }
317  if (!empty($GLOBALS['activate_platinum_auto']) && check_if_module_active('abonnement')) {
318  // On gère les crédits d'abonnement platinum
319  $sql = 'SELECT technical_code
320  FROM peel_produits pp
321  INNER JOIN peel_commandes_articles pca ON pca.produit_id = pp.id AND ' . get_filter_site_cond('commandes_articles', 'pca') . '
322  INNER JOIN peel_commandes pc ON pc.id = pca.commande_id AND ' . get_filter_site_cond('commandes', 'pc') . '
323  WHERE pc.id = ' . intval($order_id). " AND " . get_filter_site_cond('produits', 'pp') . "";
324  $query_t = query($sql);
325  while ($product_ordered_infos = fetch_assoc($query_t)) {
326  if (substr($product_ordered_infos['technical_code'], 0, strlen('forfait_p_')) == 'forfait_p_') {
327  // Format : forfait_p_3
328  $n_days = 30 * substr($product_ordered_infos['technical_code'], strlen('forfait_p_'));
329  $update_credit = 'UPDATE peel_utilisateurs
330  SET platinum_status ="YES", platinum_activation_date ="' . date('Y-m-d H:i:s') . '", platinum_until =GREATEST(' . time() . ',platinum_until)+' . (3600 * 24 * $n_days).'
331  WHERE id_utilisateur ="' . intval($commande['id_utilisateur']) . '" AND ' . get_filter_site_cond('utilisateurs') . '';
332  query($update_credit);
333  }
334  }
335  }
336  }
337  if (!empty($payment_status_id_by_technical_code_array[$statut_paiement_new])) {
338  $sql_set_array[] = "id_statut_paiement='" . intval($payment_status_id_by_technical_code_array[$statut_paiement_new]) . "'";
339  }
340  if (!empty($delivery_status_id_by_technical_code_array[$statut_livraison_new])) {
341  $sql_set_array[] = "id_statut_livraison='" . intval($delivery_status_id_by_technical_code_array[$statut_livraison_new]) . "'";
342  }
343  if ($delivery_tracking !==null) {
344  // Attention, il faut pouvoir forcer la mise à "" => ne pas faire de test !empty
345  $sql_set_array[] = "delivery_tracking='" . nohtml_real_escape_string($delivery_tracking) . "'";
346  } elseif(!empty($commande['delivery_tracking'])) {
347  $delivery_tracking = $commande['delivery_tracking'];
348  }
349  if (!empty($sql_set_array) && ($allow_update_paid_orders || !in_array($commande['statut_paiement'], array('being_checked', 'completed')))) {
350  query('UPDATE peel_commandes
351  SET ' . implode(', ', $sql_set_array) . '
352  WHERE id="' . intval($order_id) . '" AND ' . get_filter_site_cond('commandes'));
353  }
354  if ($statut_paiement_new !== null && $commande['statut_paiement'] != $statut_paiement_new) {
355  // On vérifie le statut paiement avant la mise à jour de la base avec celui du formulaire. Ils doivent être différents,
356  // afin d'éviter un doublon d'incrémentation des stocks lorsque l'utilisateur choisit l'annulation de livraison.
357  if (in_array($statut_paiement_new, array('cancelled', 'refunded')) && !in_array($commande['statut_paiement'], array('cancelled', 'refunded'))) {
358  // La commande passe en annulé ou remboursé
359  if ($statut_paiement_new === null || $statut_paiement_new === '') {
360  // Changement aussi du statut de livraison en annulé s'il n'était pas déjà en statut livré
361  query("UPDATE peel_commandes
362  SET id_statut_livraison=" . intval($delivery_status_id_by_technical_code_array['cancelled']) . "
363  WHERE id='" . intval($order_id) . "' AND id_statut_livraison!=" . intval($delivery_status_id_by_technical_code_array['dispatched']) . " AND " . get_filter_site_cond('commandes') . "");
364  }
365  // Dans le cas particulier d'une commande contenant des produits cadeaux commandés avec des points puis annulée
366  // On devrait gérer ici le fait de recréditer les points de la commande de cadeaux, mais ça nécessite de stocker en BDD les informations de points dépensés des commandes
367  // => ça nécessite actuellement une intervention manuelle par un administrateur pour recréditer le compte utilisateur
368  }
369  }
370  if(check_if_module_active('stock_advanced') && $statut_paiement_new !== null) {
371  // Les stocks sont gérés sur le site, et un statut de paiement est spécifié => Il faut éventuellement modifier les stocks des produits de la commande.
372  // (Si statut_paiement est vide, il n'est pas nécessaire de faire le calcul).
373  $payment_status_decrement_stock_array = explode(',', $GLOBALS['site_parameters']['payment_status_decrement_stock']);
374  // $payment_status_decrement_stock_array vaut : pending,being_checked,completed ou being_checked,completed
375  $want_decrement = in_array($statut_paiement_new, $payment_status_decrement_stock_array);
376  $ex_decrement = in_array($commande['statut_paiement'], $payment_status_decrement_stock_array);
377  // Quand on appelle cette fonction à partir de create_or_update_order
378  // on a remis à 0 la prise en compte des stocks des produits, puisqu'on est susceptible d'avoir changé les produits de la commande
379  // donc on arrive ici avec $no_stock_decrement_already_done=true
380  // Dans les autres cas, $no_stock_decrement_already_done=false
381  $already_decrement = (!$no_stock_decrement_already_done && $ex_decrement);
382  if(($want_decrement && !$already_decrement) || (!$want_decrement && $already_decrement)){
383  $product_infos_array = get_product_infos_array_in_order($order_id);
384  if (!empty($product_infos_array)) {
385  foreach ($product_infos_array as $this_ordered_product) {
386  if ($this_ordered_product['etat_stock'] == 1) {
387  if ($want_decrement && !$already_decrement) {
388  // Décrémentation des stocks (par exemple en cas de commande qui était en statut paiement annulé et qui finalement ne doit pas être annulée)
389  // si le statut passe dans un statut où on doit décrémenter le stock, alors qu'il ne l'était pas avant
390  // $this_order_stock contient le montant à réapprovisionner
391  $this_order_stock = decremente_stock($this_ordered_product['produit_id'], $this_ordered_product['couleur_id'], $this_ordered_product['taille_id'], $this_ordered_product['quantite']);
392  }elseif (!$want_decrement && $already_decrement) {
393  // on réincrémente de quantite-order_stock
394  incremente_stock($this_ordered_product['quantite']-$this_ordered_product['order_stock'], $this_ordered_product['produit_id'], $this_ordered_product['couleur_id'], $this_ordered_product['taille_id']);
395  // On annule la demande de réapprovisionnement
396  $this_order_stock = 0;
397  }
398  if(isset($this_order_stock)){
399  query("UPDATE peel_commandes_articles
400  SET order_stock='".intval($this_order_stock)."'
401  WHERE id='" . intval($this_ordered_product['id']) . "' AND " . get_filter_site_cond('commandes_articles'));
402  unset($this_order_stock);
403  }
404  }
405  }
406  }
407  }
408  }
409  if ($statut_livraison_new == 'dispatched' && $commande['statut_livraison'] != $statut_livraison_new && !empty($GLOBALS['site_parameters']['mode_transport'])) {
410  // Le statut de livraison passe à expédié pour la première fois
411  // => on envoie l'email d'expédition (avec ou sans les infos de delivery_tracking qui peut être vide)
412  send_avis_expedition($order_id, $delivery_tracking);
413  // Création de la date d'expédition pour la commande. Cette date est administrable par l'administrateur en back office.
414  query("UPDATE peel_commandes
415  SET e_datetime = '" . date('Y-m-d H:i:s', time()) . "'
416  WHERE id = '" . intval($order_id) . "' AND " . get_filter_site_cond('commandes') . "");
417  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_DELIVERY_EMAIL_SENT'], $commande['email'])))->fetch();
418  }
419  }
420  return $output;
421 }
422 
430 {
431  $_SESSION['session_commande']['societe1'] = vb($frm['societe1']);
432  $_SESSION['session_commande']['client1'] = vb($frm['client1']);
433  $_SESSION['session_commande']['nom1'] = vb($frm['nom1']);
434  $_SESSION['session_commande']['prenom1'] = vb($frm['prenom1']);
435  $_SESSION['session_commande']['email1'] = vb($frm['email1']);
436  $_SESSION['session_commande']['contact1'] = vb($frm['contact1']);
437  $_SESSION['session_commande']['adresse1'] = vb($frm['adresse1']);
438  $_SESSION['session_commande']['code_postal1'] = vb($frm['code_postal1']);
439  $_SESSION['session_commande']['ville1'] = vb($frm['ville1']);
440  $_SESSION['session_commande']['pays1'] = vb($frm['pays1']);
441 
442  if (!empty($GLOBALS['site_parameters']['mode_transport']) && is_delivery_address_necessary_for_delivery_type(vn($_SESSION['session_caddie']->typeId))) {
443  if (empty($_SESSION['session_commande']['is_socolissimo_order'])) {
444  // Quand on vient de SoColissimo, on ne change pas les variables de livraison
445  $_SESSION['session_commande']['societe2'] = vb($frm['societe2']);
446  $_SESSION['session_commande']['nom2'] = (empty($frm['nom2'])? $frm['nom1']:$frm['nom2']);
447  $_SESSION['session_commande']['prenom2'] = (empty($frm['prenom2'])? $frm['prenom1']:$frm['prenom2']);
448  $_SESSION['session_commande']['contact2'] = (empty($frm['contact2'])? $frm['contact1']:$frm['contact2']);
449  $_SESSION['session_commande']['email2'] = (empty($frm['email2'])? $frm['email1']:$frm['email2']);
450  $_SESSION['session_commande']['adresse2'] = (empty($frm['adresse2'])? $frm['adresse1']:$frm['adresse2']);
451  $_SESSION['session_commande']['code_postal2'] = (empty($frm['code_postal2'])? $frm['code_postal1']:$frm['code_postal2']);
452  $_SESSION['session_commande']['ville2'] = (empty($frm['ville2'])? $frm['ville1']:$frm['ville2']);
453  $_SESSION['session_commande']['pays2'] = (empty($frm['pays2'])? $frm['pays1']:$frm['pays2']);
454  }
455  }
456 
457  if (!empty($GLOBALS['site_parameters']['order_specific_field_titles'])) {
458  foreach($GLOBALS['site_parameters']['order_specific_field_titles'] as $this_field => $this_title) {
459  if (isset($frm[$this_field])) {
460  // On a ajouté dans la table utilisateurs un champ qui concerne l'adresse de facturation => Il faut préremplir les champs du formulaire d'adresse de facturation avec ces infos.
461  $_SESSION['session_commande'][$this_field] = $frm[$this_field];
462  }
463  }
464  }
465  $_SESSION['session_commande']['commande_interne'] = vb($frm['commande_interne']);
466  $_SESSION['session_commande']['commentaires'] = vb($frm['commentaires']);
467  $_SESSION['session_commande']['payment_technical_code'] = vb($frm['payment_technical_code']);
468  if ($_SESSION['session_commande']['payment_technical_code'] == 'moneybookers') {
469  $_SESSION['session_commande']['moneybookers_payment_methods'] = vb($frm['moneybookers_payment_methods']);
470  } else {
471  $_SESSION['session_commande']['moneybookers_payment_methods'] = '';
472  }
473  $_SESSION['session_commande']['cgv'] = vn($frm['cgv']);
474 }
475 
483 function create_or_update_order(&$order_infos, &$articles_array)
484 {
485  $output = '';
486  // "nom du champ dans la BDD" => "nom du champ dans $order_infos"
487  $name_compatibility_array = array(
488  "paiement" => "payment_technical_code"
489  , "zone_tva" => "apply_vat"
490  , "zone_franco" => "zoneFranco"
491  , "produit_id" => "product_id"
492  , "couleur_id" => "couleurId"
493  , "taille_id" => "tailleId"
494  , "nom_produit" => "product_name"
495  , "option" => "prix_option"
496  , "option_ht" => "prix_option_ht");
497 
498  // Si tous les produits ont été supprimés de la commande, on initialise le tableau
499  if (empty($articles_array)) {
500  $articles_array = array();
501  }
502  // Verifie si id statut existe
503  if (!isset($order_infos['statut_paiement'])) {
504  $order_infos['statut_paiement'] = 'pending';
505  }
506  if (!isset($order_infos['statut_livraison'])) {
507  $order_infos['statut_livraison'] = 'discussed';
508  }
509 
510  foreach($name_compatibility_array as $key => $value) {
511  // On rend compatible des entrées du tableau order_infos
512  if (isset($order_infos[$key])) {
513  // Nécessite une conversion du nom de l'index.
514  $order_infos[$value] = $order_infos[$key];
515  // On ne laisse pas d'index inutile, ça complique la lecture lors du débogage
516  unset($order_infos[$key]);
517  }
518  }
519  handle_specific_fields($order_infos, 'order');
520  foreach(vb($order_infos['adresses_fields_array'], array()) as $this_item) {
521  // En complément de name_compatibility_array
522  if ($this_item == 'zip') {
523  $this_field = 'code_postal';
524  } elseif($this_item == 'telephone') {
525  $this_field = 'contact';
526  } else {
527  $this_field = $this_item;
528  }
529  if (!empty($order_infos[$this_item . '_bill'])) {
530  $order_infos[$this_field . '1'] = $order_infos[$this_item . '_bill'];
531  }
532  if (!empty($order_infos[$this_item . '_ship'])) {
533  $order_infos[$this_field . '2'] = $order_infos[$this_item . '_ship'];
534  }
535  }
536  // On complète les données si nécessaire
537  if (!empty($GLOBALS['site_parameters']['mode_transport']) && (empty($order_infos['typeId']) || is_delivery_address_necessary_for_delivery_type($order_infos['typeId']))) {
538  foreach(vb($order_infos['adresses_fields_array'], array()) as $this_item) {
539  if (empty($order_infos[$this_item . '2']) && isset($order_infos[$this_item . '1'])) {
540  $order_infos[$this_item . '2'] = $order_infos[$this_item . '1'];
541  }
542  }
543  }
544  // Avant de mettre à jour la commande, on récupère l'ancienne valeur du statut de paiement
545  if (!empty($order_infos['id'])) {
546  $statut_q = query('SELECT c.id_statut_paiement, c.total_points, c.points_etat, c.o_timestamp, sp.technical_code AS statut_paiement
547  FROM peel_commandes c
548  LEFT JOIN peel_statut_paiement sp ON sp.id=c.id_statut_paiement AND ' . get_filter_site_cond('statut_paiement', 'sp') . '
549  WHERE c.id=' . intval($order_infos['id']) . ' AND ' . get_filter_site_cond('commandes', 'c') . '');
550  $order_infos_ex = fetch_assoc($statut_q);
551  } else {
552  $order_infos_ex = null;
553  }
554  if (empty($order_infos['devise'])) {
555  // Par exemple si !check_if_module_active('devises') : on prend la devise de la boutique
556  $order_infos['devise'] = $GLOBALS['site_parameters']['code'];
557  }
558  if (empty($order_infos['lang'])) {
559  $order_infos['lang'] = $_SESSION['session_langue'];
560  }
561  $old_id_utilisateur = $order_infos['id_utilisateur'];
562  if(empty($order_infos['email'])) {
563  $order_infos['email'] = vb($order_infos['email1']);
564  }
565  if(!isset($order_infos['site_id'])) {
566  // Si pas de site_id précisé (problème de paramétrage), alors la valeur du champ site_id sera celle du site en cours de consultation
567  $order_infos['site_id'] = $GLOBALS['site_id'];
568  }
569  $set_sql = "email = '" . nohtml_real_escape_string(vb($order_infos['email'])) . "'
570  ";
571  if(!empty($order_infos['email1'])){
572  // Si on change l'email associé à une commande, et qu'il correspond à un utilisateur en BDD, on ajuste l'id_utilisateur
573  // Sinon, on laisse l'id_utilisateur comme il était (0 si la commande avait préalablement été créée sans association à un utilisateur, ou l'id d'un compte quelconque dont l'email n'est peut-être pas à jour)
574  $searched_id_utilisateur = get_user_id_from_email($order_infos['email']);
575  if(!empty($searched_id_utilisateur)) {
576  $order_infos['id_utilisateur'] = $searched_id_utilisateur;
577  }
578  }
579  if (isset($order_infos['commande_interne'])) {
580  $set_sql .= ", commande_interne = '" . nohtml_real_escape_string($order_infos['commande_interne']) . "'";
581  }
582  if (isset($order_infos['id_utilisateur'])) {
583  $set_sql .= ", id_utilisateur = '" . nohtml_real_escape_string($order_infos['id_utilisateur']) . "'";
584  }
585  if (isset($order_infos['commentaires'])) {
586  $set_sql .= ", commentaires = '" . nohtml_real_escape_string($order_infos['commentaires']) . "'";
587  }
588  if (isset($order_infos['commentaires_admin'])) {
589  $set_sql .= ", commentaires_admin = '" . nohtml_real_escape_string($order_infos['commentaires_admin']) . "'";
590  }
591  $set_sql .= ", montant = '" . nohtml_real_escape_string($order_infos['montant']) . "'
592  , montant_ht = '" . nohtml_real_escape_string($order_infos['montant_ht']) . "'";
593  if (isset($order_infos['total_option'])) {
594  $set_sql .= ", total_option = '" . nohtml_real_escape_string(vb($order_infos['total_option'])) . "'";
595  }
596  if (isset($order_infos['a_timestamp'])) {
597  $set_sql .= ", a_timestamp = '" . nohtml_real_escape_string(get_mysql_date_from_user_input(vb($order_infos['a_timestamp']))) . "'";
598  }
599  if (isset($order_infos['e_datetime'])) {
600  $set_sql .= ", e_datetime = '" . nohtml_real_escape_string(get_mysql_date_from_user_input(vb($order_infos['e_datetime']))) . "'";
601  }
602  if (isset($order_infos['f_datetime'])) {
603  $set_sql .= ", f_datetime = '" . nohtml_real_escape_string(get_mysql_date_from_user_input(vb($order_infos['f_datetime']))) . "'";
604  }
605  if (isset($order_infos['tva_total_option'])) {
606  $set_sql .= ", tva_total_option = '" . nohtml_real_escape_string(vb($order_infos['tva_total_option'])) . "'";
607  }
608  $set_sql .= ", total_produit = '" . nohtml_real_escape_string($order_infos['total_produit']) . "'
609  , total_produit_ht = '" . nohtml_real_escape_string($order_infos['total_produit_ht']) . "'
610  , tva_total_produit = '" . nohtml_real_escape_string($order_infos['tva_total_produit']) . "'";
611  if (isset($order_infos['code_promo'])) {
612  $set_sql .= ", code_promo = '" . nohtml_real_escape_string(vb($order_infos['code_promo'])) . "'";
613  }
614  if (isset($order_infos['percent_remise_user'])) {
615  $set_sql .= ", percent_remise_user = '" . nohtml_real_escape_string(vb($order_infos['percent_remise_user'])) . "'";
616  }
617  if (isset($order_infos['percent_code_promo'])) {
618  $set_sql .= ", percent_code_promo = '" . nohtml_real_escape_string(vb($order_infos['percent_code_promo'])) . "'";
619  }
620  if (isset($order_infos['valeur_code_promo'])) {
621  $set_sql .= ", valeur_code_promo = '" . nohtml_real_escape_string(vb($order_infos['valeur_code_promo'])) . "'";
622  }
623  if (isset($order_infos['total_remise'])) {
624  $set_sql .= ", total_remise = '" . nohtml_real_escape_string(vb($order_infos['total_remise'])) . "'";
625  }
626  if (isset($order_infos['total_remise_ht'])) {
627  $set_sql .= ", total_remise_ht = '" . nohtml_real_escape_string(vb($order_infos['total_remise_ht'])) . "'";
628  }
629  if (isset($order_infos['tva_total_remise'])) {
630  $set_sql .= ", tva_total_remise = '" . nohtml_real_escape_string(vb($order_infos['tva_total_remise'])) . "'";
631  }
632  $set_sql .= ", total_tva = '" . nohtml_real_escape_string($order_infos['total_tva']) . "'";
633  if (isset($order_infos['transport'])) {
634  $set_sql .= ", transport = '" . nohtml_real_escape_string(vb($order_infos['transport'])) . "'";
635  }
636  $set_sql .= ", cout_transport = '" . nohtml_real_escape_string(vn($order_infos['cout_transport'])) . "'
637  , cout_transport_ht = '" . nohtml_real_escape_string(vn($order_infos['cout_transport_ht'])) . "'
638  , tva_cout_transport = '" . nohtml_real_escape_string(vn($order_infos['tva_cout_transport'])) . "'
639  , lang = '" . nohtml_real_escape_string($order_infos['lang']) . "'";
640  if (isset($order_infos['total_points'])) {
641  $set_sql .= ", total_points = '" . nohtml_real_escape_string(vb($order_infos['total_points'])) . "'";
642  }
643  if (isset($order_infos['total_poids'])) {
644  $set_sql .= ", total_poids = '" . nohtml_real_escape_string(vb($order_infos['total_poids'])) . "'";
645  }
646  if (isset($order_infos['affilie'])) {
647  $set_sql .= ", affilie = '" . nohtml_real_escape_string(vb($order_infos['affilie'])) . "'";
648  }
649  if (isset($order_infos['montant_affilie'])) {
650  $set_sql .= ", montant_affilie = '" . nohtml_real_escape_string(vb($order_infos['montant_affilie'])) . "'";
651  }
652  if (isset($order_infos['statut_affilie'])) {
653  $set_sql .= ", statut_affilie = '" . nohtml_real_escape_string(vb($order_infos['statut_affilie'])) . "'";
654  }
655  if (isset($order_infos['id_affilie'])) {
656  $set_sql .= ", id_affilie = '" . nohtml_real_escape_string(vb($order_infos['id_affilie'])) . "'";
657  }
658  $set_sql .= "
659  , total_ecotaxe_ttc = '" . nohtml_real_escape_string(vb($order_infos['total_ecotaxe_ttc'])) . "'
660  , total_ecotaxe_ht = '" . nohtml_real_escape_string(vb($order_infos['total_ecotaxe_ht'])) . "'
661  , tva_total_ecotaxe = '" . nohtml_real_escape_string(vb($order_infos['tva_total_ecotaxe'])) . "'";
662  if (isset($order_infos['avoir'])) {
663  $set_sql .= ", avoir = '" . nohtml_real_escape_string(vb($order_infos['avoir'])) . "'";
664  }
665  $set_sql .= ", paiement = '" . nohtml_real_escape_string(vb($order_infos['payment_technical_code'])) . "'
666  , tarif_paiement = '" . nohtml_real_escape_string(vb($order_infos['tarif_paiement'])) . "'
667  , tarif_paiement_ht = '" . nohtml_real_escape_string(vb($order_infos['tarif_paiement_ht'])) . "'
668  , tva_tarif_paiement = '" . nohtml_real_escape_string(vb($order_infos['tva_tarif_paiement'])) . "'
669  , prenom_bill = '" . nohtml_real_escape_string(vb($order_infos['prenom1'])) . "'
670  , nom_bill = '" . nohtml_real_escape_string(vb($order_infos['nom1'])) . "'
671  , societe_bill = '" . nohtml_real_escape_string(vb($order_infos['societe1'])) . "'
672  , adresse_bill = '" . nohtml_real_escape_string(vb($order_infos['adresse1'])) . "'
673  , zip_bill = '" . nohtml_real_escape_string(vb($order_infos['code_postal1'])) . "'
674  , ville_bill = '" . nohtml_real_escape_string(vb($order_infos['ville1'])) . "'
675  , pays_bill = '" . nohtml_real_escape_string(vb($order_infos['pays1'])) . "'
676  , email_bill = '" . nohtml_real_escape_string(vb($order_infos['email1'])) . "'
677  , telephone_bill = '" . nohtml_real_escape_string(vb($order_infos['contact1'])) . "'
678  , prenom_ship = '" . nohtml_real_escape_string(vb($order_infos['prenom2'])) . "'";
679  if (isset($order_infos['nom2'])) {
680  $set_sql .= ", nom_ship = '" . nohtml_real_escape_string(vb($order_infos['nom2'])) . "'";
681  }
682  if (isset($order_infos['societe2'])) {
683  $set_sql .= ", societe_ship = '" . nohtml_real_escape_string(vb($order_infos['societe2'])) . "'";
684  }
685  if (isset($order_infos['adresse2'])) {
686  $set_sql .= ", adresse_ship = '" . nohtml_real_escape_string(vb($order_infos['adresse2'])) . "'";
687  }
688  if (isset($order_infos['code_postal2'])) {
689  $set_sql .= ", zip_ship = '" . nohtml_real_escape_string(vb($order_infos['code_postal2'])) . "'";
690  }
691  if (isset($order_infos['ville2'])) {
692  $set_sql .= ", ville_ship = '" . nohtml_real_escape_string(vb($order_infos['ville2'])) . "'";
693  }
694  if (isset($order_infos['pays2'])) {
695  $set_sql .= ", pays_ship = '" . nohtml_real_escape_string(vb($order_infos['pays2'])) . "'";
696  }
697  if (isset($order_infos['email2'])) {
698  $set_sql .= ", email_ship = '" . nohtml_real_escape_string(vb($order_infos['email2'])) . "'";
699  }
700  if (isset($order_infos['contact2'])) {
701  $set_sql .= ", telephone_ship = '" . nohtml_real_escape_string(vb($order_infos['contact2'])) . "'";
702  }
703  if (isset($order_infos['id_parrain'])) {
704  $set_sql .= ", id_parrain = '" . nohtml_real_escape_string(vn($order_infos['id_parrain'])) . "'";
705  }
706  if (isset($order_infos['parrain'])) {
707  $set_sql .= ", parrain = '" . nohtml_real_escape_string(vb($order_infos['parrain'])) . "'";
708  }
709  $set_sql .= "
710  , currency_rate = '" . nohtml_real_escape_string($order_infos['currency_rate']) . "'
711  , zone_tva = '" . nohtml_real_escape_string(!empty($order_infos['apply_vat'])?1:0) . "'";
712  if (isset($order_infos['zoneFranco'])) {
713  $set_sql .= ", zone_franco = '" . nohtml_real_escape_string($order_infos['zoneFranco']) . "'";
714  }
715  $set_sql .= "
716  , small_order_overcost_amount = '" . nohtml_real_escape_string(vb($order_infos['small_order_overcost_amount'])) . "'
717  , tva_small_order_overcost = '" . nohtml_real_escape_string(vb($order_infos['tva_small_order_overcost'])) . "'
718  , pays = '" . nohtml_real_escape_string($order_infos['pays']) . "'
719  , zone = '" . nohtml_real_escape_string($order_infos['zoneId']) . "'
720  , type = '" . nohtml_real_escape_string(vb($order_infos['type'])) . "'
721  , typeId = '" . intval(vn($order_infos['typeId'])) . "'
722  , delivery_orderid = '" . nohtml_real_escape_string(vb($_SESSION['session_caddie']->delivery_orderid)) . "'
723  , devise = '" . nohtml_real_escape_string($order_infos['devise']) . "'";
724  if (isset($order_infos['moneybookers_payment_methods'])) {
725  $set_sql .= ", moneybookers_payment_methods = '" . real_escape_string(vb($order_infos['moneybookers_payment_methods'])) . "'";
726  }
727  $set_sql .= ", delivery_infos = '" . real_escape_string(vb($order_infos['delivery_infos'])) . "'
728  , delivery_locationid = '" . nohtml_real_escape_string(vb($order_infos['delivery_locationid'])) . "'
729  , site_id = '" . nohtml_real_escape_string(get_site_id_sql_set_value(vn($order_infos['site_id']))) . "'";
730  if (check_if_module_active('tnt')) {
731  if(!empty($_SESSION['session_commande']['xETTCode'])) {
732  $set_sql .= ", xETTCode = '" . word_real_escape_string(vb($_SESSION['session_commande']['xETTCode'])) . "'";
733  }
734  $set_sql .= "
735  , expedition_date = '" . nohtml_real_escape_string(vb($GLOBALS['web_service_tnt']->shippingDate)) . "'
736  , shipping_date = '" . nohtml_real_escape_string(vb($GLOBALS['web_service_tnt']->shippingDate)) . "'";
737  }
738  if (!empty($order_infos['specific_field_sql_set'])) {
739  $set_sql .= ',' . implode(',', $order_infos['specific_field_sql_set']);
740  }
741  if (!empty($order_infos['commandeid'])) {
742  // On met à jour la commande
743  $sql = "UPDATE peel_commandes
744  SET " . $set_sql . "
745  WHERE id_utilisateur='" . intval($old_id_utilisateur) . "' AND id='" . intval($order_infos['commandeid']) . "' AND " . get_filter_site_cond('commandes', null, false, $order_infos['site_id'], true) . "";
746  $order_infos['o_timestamp'] = $order_infos_ex['o_timestamp'];
747  } else {
748  // On crée la commande - pour cela, on définit le code facture, et l'id utilisateur
749  $code_facture = vb($order_infos['code_facture']);
750  while (empty($code_facture) || (isset($qid_commande) && num_rows($qid_commande))) {
751  // On s'assure que le code facture généré n'existe pas encore
752  $code_facture = MDP(10);
753  $qid_commande = query("SELECT *
754  FROM peel_commandes
755  WHERE code_facture = '" . nohtml_real_escape_string($code_facture) . "' AND " . get_filter_site_cond('commandes', null, false, $order_infos['site_id'], true) . "");
756  }
757  // Attention : on ne doit pas mettre de "a_timestamp" ici, car ça dépend de si la commande est à passer en payer ou non => c'est géré dans update_order_payment_status
758  $sql = "INSERT INTO peel_commandes
759  SET " . $set_sql . "
760  , order_id = '" . intval(get_order_id()) . "'
761  , code_facture = '" . nohtml_real_escape_string($code_facture) . "'
762  , o_timestamp = '" . date('Y-m-d H:i:s', time()) . "' ";
763  $order_infos['o_timestamp'] = date('Y-m-d H:i:s', time());
764  }
765  query($sql);
766  if (empty($order_infos['commandeid'])) {
767  $order_infos['commandeid'] = insert_id();
768  }
769  $order_id = $order_infos['commandeid'];
770  if(!empty($order_infos['numero']) && $order_infos['numero']!=vb($GLOBALS['site_parameters']['format_numero_facture'])) {
771  // Si un numéro est spécifié par l'admin (donc n'est pas le format par défaut), alors on le met ici, sinon la création de numéro sera gérée dans update_order_payment_status car dépendant du status
772  $numero = get_bill_number($order_infos['numero'], $order_id, false);
773  } else {
774  $numero = '';
775  }
776  // Qu'il soit vide ou non, on met à jour la colonne numero
777  query("UPDATE peel_commandes
778  SET numero = '" . nohtml_real_escape_string($numero) . "'
779  WHERE id = '" . intval($order_id) . "' AND " . get_filter_site_cond('commandes', null, false, $order_infos['site_id'], true) . "");
780  // On va enregistrer l'ensemble des produits commandés pour la commande $order_id
781  // Tout d'abord on supprime ce qui existait en BDD pour cette commande
782  if (!empty($order_infos_ex)) {
783  if(check_if_module_active('stock_advanced')) {
784  // On réincrémente les stocks si il y avait des articles précédemment stockés, puisqu'on fait comme si les produits commandés étaient tous annulés
785  // On gèrera plus tard les stocks dans update_order_payment_status() appelé à la fin de cette fonction
786  $product_infos_array = get_product_infos_array_in_order($order_id);
787  foreach ($product_infos_array as $this_ordered_product) {
788  // On réincrémente le stock uniquement pour les articles onstock=1, c'est-à-dire dont le stock est géré
789  if ($this_ordered_product['etat_stock'] == 1 && in_array($order_infos_ex['statut_paiement'], explode(',', $GLOBALS['site_parameters']['payment_status_decrement_stock'])) ) {
790  incremente_stock($this_ordered_product['quantite'] - $this_ordered_product['order_stock'], $this_ordered_product['produit_id'], $this_ordered_product['couleur_id'], $this_ordered_product['taille_id']);
791  // On initialise les demande de réassort de stock lié à ce produit commandé en supprimant ensuite les lignes de peel_commandes_articles, donc pas besoin de faire :
792  // query("UPDATE peel_commandes_articles
793  // SET order_stock='0'
794  // WHERE id='" . intval($this_ordered_product['id']) . "' AND " . get_filter_site_cond('commandes_articles') . "");
795  }
796  }
797  }
798  if(check_if_module_active('gifts')) {
799  // On retire les points attribués préalablement, pour redonner les nouveaux points ensuite
800  update_points($order_infos['total_points'], vn($order_infos['points_etat']), $order_id, null);
801  }
802  }
803  query("DELETE FROM peel_commandes_articles
804  WHERE commande_id='" . intval($order_id) . "' AND " . get_filter_site_cond('commandes_articles'));
805  // On ajoute les articles à la table commandes_articles
806  foreach ($articles_array as $article_infos) {
807  // On rend compatible des entrées du tableau
808  foreach($name_compatibility_array as $key => $value) {
809  // On rend compatible des entrées du tableau article_infos
810  if (isset($article_infos[$key])) {
811  // Nécessite une conversion du nom de l'index.
812  $article_infos[$value] = $article_infos[$key];
813  // On ne laisse pas d'index inutile, ça complique la lecture lors du débogage;
814  unset($article_infos[$key]);
815  }
816  }
817  // On construit un objet product à partir des informations de $article_infos.
818  // On l'utilise pour des informations diverses, mais surtout pas pour les prix par exemple, qui doivent être ceux imposés par $article_infos
819  // L'objet produit n'a pas besoin d'être initialisé avec toute les informations de $article_infos car on ne l'utilise que pour les parties sur lesquelles on n'a pas d'information dans $article_infos
820  $product_infos = null;
821  $product_object = new Product($article_infos['product_id'], $product_infos, false, null, true, !check_if_module_active('micro_entreprise'));
822  // On n'a pas à indiquer si l'utilisateur est un revendeur ou non car on ne va pas utiliser les prix des configurations ci-après, on utilisera $article_infos
823  $product_object->set_configuration(vn($article_infos['couleurId']), vn($article_infos['tailleId']), vb($article_infos['id_attribut']), false, true);
824  // Dans le cas d'une création de commande, l'id attribut est renseigné dans la session caddie => On peut configurer les attributs de ce produit avec la classe Product.
825  // En revanche, dans le cas d'une modification d'une commande existante, l'id de l'attribut n'est pas disponible, car elle n'est pas sauvegardée lors du passage de la commande.
826  // Le nom de l'attribut est stocké dans la table peel_commandes_articles pour que cette information n'évolue pas dans le temps.
827  if (!empty($article_infos['id_attribut'])) {
828  $attribut = $product_object->configuration_attributs_description;
829  } elseif (!empty($article_infos['nom_attribut'])) {
830  $attribut = $article_infos['nom_attribut'];
831  } else {
832  $attribut = '';
833  }
834  $statut_envoi = ($product_object->on_download == 1) ? "En attente" : "";
835  // Il faut que la couleur et la taille soient gardés tels quels lorsqu'une commande est éditée
836  // et que la couleur et la taille ne sont plus disponibles => get_color et get_size ne pourraient pas les donner
837  // => dans ce cas ces informations sont dans $article_infos['couleur'] et $article_infos['taille']
838  if (empty($article_infos['couleur'])) {
839  $article_infos['couleur'] = $product_object->get_color();
840  }
841  if (empty($article_infos['taille'])) {
842  $article_infos['taille'] = $product_object->get_size();
843  }
844  if (!empty($article_infos['nom_produit'])) {
845  $article_infos['product_name'] = $article_infos['nom_produit'];
846  }
847  if (empty($article_infos['product_name'])) {
848  $article_infos['product_name'] = $product_object->name;
849  }
850  if (empty($article_infos['reference'])) {
851  $article_infos['reference'] = $product_object->reference;
852  }
853  $sql = "INSERT INTO peel_commandes_articles SET
854  site_id = '" . nohtml_real_escape_string(get_site_id_sql_set_value($order_infos['site_id'])) . "'
855  , commande_id = '" . intval($order_id) . "'
856  , produit_id = '" . intval($product_object->id) . "'
857  , categorie_id = '" . intval($product_object->categorie_id) . "'";
858  if (isset($article_infos['reference'])) {
859  $sql .= ", reference = '" . nohtml_real_escape_string($article_infos['reference']) . "'";
860  }
861  $sql .= "
862  , nom_produit = '" . nohtml_real_escape_string($article_infos['product_name']) . "'";
863  if (isset($article_infos['couleur'])) {
864  $sql .= ", couleur = '" . nohtml_real_escape_string($article_infos['couleur']) . "'";
865  }
866  if (isset($article_infos['taille'])) {
867  $sql .= ", taille = '" . nohtml_real_escape_string($article_infos['taille']) . "'";
868  }
869  if (isset($article_infos['couleurId'])) {
870  $sql .= ", couleur_id = '" . nohtml_real_escape_string($article_infos['couleurId']) . "'";
871  }
872  if (isset($article_infos['tailleId'])) {
873  $sql .= ", taille_id = '" . nohtml_real_escape_string($article_infos['tailleId']) . "'";
874  }
875  $sql .= "
876  , prix_cat = '" . nohtml_real_escape_string(vb($article_infos['prix_cat'])) . "'
877  , prix_cat_ht = '" . nohtml_real_escape_string(vb($article_infos['prix_cat_ht'])) . "'
878  , prix = '" . nohtml_real_escape_string($article_infos['prix']) . "'
879  , prix_ht = '" . nohtml_real_escape_string($article_infos['prix_ht']) . "'
880  , prix_achat_ht = '" . nohtml_real_escape_string($product_object->get_supplier_price(false)) . "'";
881  if (isset($article_infos['percent_remise_produit'])) {
882  $sql .= ", percent_remise_produit = '" . nohtml_real_escape_string(vn($article_infos['percent_remise_produit'])) . "'";
883  }
884  if (isset($article_infos['remise'])) {
885  $sql .= ", remise = '" . nohtml_real_escape_string(vn($article_infos['remise'])) . "'";
886  }
887  if (isset($article_infos['remise_ht'])) {
888  $sql .= ", remise_ht = '" . nohtml_real_escape_string(vn($article_infos['remise_ht'])) . "'";
889  }
890  $sql .= "
891  , total_prix = '" . nohtml_real_escape_string($article_infos['total_prix']) . "'
892  , total_prix_ht = '" . nohtml_real_escape_string($article_infos['total_prix_ht']) . "'
893  , quantite = '" . nohtml_real_escape_string($article_infos['quantite']) . "'
894  , tva = '" . nohtml_real_escape_string($article_infos['tva']) . "'
895  , tva_percent = '" . nohtml_real_escape_string($article_infos['tva_percent']) . "'";
896  if (isset($article_infos['points'])) {
897  $sql .= ", points = '" . nohtml_real_escape_string(vn($article_infos['points'])) . "'";
898  }
899  if (isset($article_infos['poids'])) {
900  $sql .= ", poids = '" . nohtml_real_escape_string(vn($article_infos['poids'])) . "'";
901  }
902  // Email_check correspond à l'email d'envoi de chèque cadeau qui peut être différent
903  if (isset($article_infos['email_check'])) {
904  $sql .= ", email_check = '" . nohtml_real_escape_string(vb($article_infos['email_check'])) . "'";
905  }
906  if (isset($product_object->on_download)) {
907  $sql .= ", on_download = '" . intval($product_object->on_download) . "'
908  , statut_envoi = '" . nohtml_real_escape_string($statut_envoi) . "'";
909  }
910  $sql .= "
911  , nb_envoi = '0'
912  , nb_download = '0'
913  , ecotaxe_ttc = '" . nohtml_real_escape_string(vb($article_infos['ecotaxe_ttc'])) . "'
914  , ecotaxe_ht = '" . nohtml_real_escape_string(vb($article_infos['ecotaxe_ht'])) . "'
915  , prix_option = '" . nohtml_real_escape_string(vn($article_infos['option'])) . "'
916  , prix_option_ht = '" . nohtml_real_escape_string(vn($article_infos['option_ht'])) . "'";
917  if (check_if_module_active('stock_advanced')) {
918  $sql .= "
919  , etat_stock = '" . nohtml_real_escape_string(vb($article_infos['etat_stock'])) . "'
920  , delai_stock = '" . nohtml_real_escape_string(vb($article_infos['delai_stock'])) . "'";
921  }
922  if (check_if_module_active('listecadeau') && !empty($article_infos['giftlist_owners'])) {
923  $sql .= "
924  , listcadeaux_owner = '" . nohtml_real_escape_string(vn($article_infos['giftlist_owners'])) . "'";
925  }
926  if (check_if_module_active('conditionnement')) {
927  // Les produits sont conditionnés sous forme de lot => ici on sauvegarde la taille des lots de conditionnement
928  $sql .= "
929  , conditionnement = '" . nohtml_real_escape_string(vb($product_object->conditionnement)) . "'";
930  }
931  if (check_if_module_active('tnt')) {
932  $sql .= "
933  , tnt_parcel_number = '" . nohtml_real_escape_string(vb($article_infos['tnt_parcel_number'])) . "'";
934  }
935  $sql .= "
936  , attributs_list = '" . nohtml_real_escape_string(vb($article_infos['id_attribut'])) . "'
937  , nom_attribut = '" . nohtml_real_escape_string(str_replace('<br />', "\r\n", $attribut)) . "'
938  , total_prix_attribut = '" . nohtml_real_escape_string(vb($article_infos['total_prix_attribut'])) . "'";
939  query($sql);
940 
941  unset($product_object);
942  }
943  if (is_numeric($order_infos['statut_livraison'])) {
944  // conversion de l'id du statut de livraison par son technical_code pour sa bonne prise en compte par update_order_payment_status
945  $sql = 'SELECT l.technical_code
946  FROM peel_statut_livraison l
947  WHERE id=' . intval($order_infos['statut_livraison']) . ' AND ' . get_filter_site_cond('statut_livraison', 'l');
948  $query = query($sql);
950  $order_infos['statut_livraison'] = $result['technical_code'];
951  }
952  // Tout est maintenant en BDD, sauf les statuts qui n'ont pas été modifiés
953  // On met à jour les status, ET on incrémente ou décremente les stocks en fonction des id's (il fallait attendre d'avoir bien les produits mis en BDD ci-dessus)
954  // NB : delivery_tracking vaut null habituellement, et n'est pas null que si la demande de modification vient de l'administration => ne pas mettre de vb() sur delivery_tracking
955  // output_create_or_update_order sera afficher dans le fichier admin_haut.
956  $GLOBALS['output_create_or_update_order'] = update_order_payment_status($order_id, $order_infos['statut_paiement'], true, $order_infos['statut_livraison'], vb($order_infos['delivery_tracking']), true, vb($order_infos['payment_technical_code']));
957  if(check_if_module_active('nexway')) {
958  include_once($GLOBALS['dirroot'] . '/modules/nexway/fonctions.php');
959  Nexway::create_order($order_infos, $articles_array);
960  }
961  return $order_id;
962 }
963 
970 function email_commande($order_id)
971 {
972  $result = query("SELECT c.*, sp.technical_code AS statut_paiement
973  FROM peel_commandes c
974  LEFT JOIN peel_statut_paiement sp ON sp.id=c.id_statut_paiement AND " . get_filter_site_cond('statut_paiement', 'sp') . "
975  WHERE c.id ='" . intval($order_id) . "' AND " . get_filter_site_cond('commandes', 'c'));
976  if($order_object = fetch_object($result)){
977  $order_infos = get_order_infos_array($order_object);
978  $user = get_user_information($order_object->id_utilisateur);
979 
980  $custom_template_tags['ORDER_ID'] = $order_id;
981  $custom_template_tags['NOM_FAMILLE'] = String::htmlspecialchars_decode($user['nom_famille'], ENT_QUOTES);
982  $custom_template_tags['CIVILITE'] = $user['civilite'];
983  $custom_template_tags['PRENOM'] = String::htmlspecialchars_decode($user['prenom'], ENT_QUOTES);
984  $custom_template_tags['TYPE'] = $order_object->type;
985  $custom_template_tags['COLIS'] = $order_object->delivery_tracking;
986  $custom_template_tags['DATE'] = get_formatted_date($order_object->o_timestamp, 'short', 'long');
987  $custom_template_tags['MONTANT'] = fprix($order_object->montant, true);
988  $custom_template_tags['PAIEMENT'] = get_payment_name($order_object->paiement);
989  $custom_template_tags['CLIENT_INFOS_BILL'] = String::htmlspecialchars_decode($order_infos['client_infos_bill'], ENT_QUOTES);
990  $custom_template_tags['CLIENT_INFOS_SHIP'] = String::htmlspecialchars_decode($order_infos['client_infos_ship'], ENT_QUOTES);
991  $custom_template_tags['COUT_TRANSPORT'] = (display_prices_with_taxes_active()? fprix($order_object->cout_transport, true) . " " . $GLOBALS['STR_TTC'] : fprix($order_object->cout_transport_ht, true) . " " .$GLOBALS['STR_HT']);
992  $custom_template_tags['BOUGHT_ITEMS'] = '';
993  $custom_template_tags['COMMENT'] = $order_object->commentaires;
994 
995  $product_infos_array = get_product_infos_array_in_order($order_id, $order_object->devise, $order_object->currency_rate);
996  foreach ($product_infos_array as $this_ordered_product) {
997  $custom_template_tags['BOUGHT_ITEMS'] .= $this_ordered_product["product_text"] . "\n";
998  $custom_template_tags['BOUGHT_ITEMS'] .= $GLOBALS['STR_QUANTITY'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . $this_ordered_product["quantite"] . "\n";
999  $custom_template_tags['BOUGHT_ITEMS'] .= $GLOBALS['STR_PRICE'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . (display_prices_with_taxes_active()? fprix($this_ordered_product["total_prix"], true) . ' ' . $GLOBALS['STR_TTC'] : fprix($this_ordered_product["total_prix_ht"], true) . ' ' . $GLOBALS['STR_HT']) . "\n\n";
1000  }
1001  foreach ($product_infos_array as $this_ordered_product) {
1002  if(!empty($this_ordered_product['technical_code'])) {
1003  send_email($order_object->email, '', '', 'confirm_ordered_'.$this_ordered_product['technical_code'], $custom_template_tags, null, $GLOBALS['support_commande']);
1004  send_email($GLOBALS['support_commande'], '', '', 'confirm_ordered_'.$this_ordered_product['technical_code'], $custom_template_tags, null, $GLOBALS['support_commande']);
1005  }
1006  }
1007  $template_technical_codes_array = array('email_commande_' . $order_object->paiement, 'email_commande');
1008  send_email($order_object->email, '', '', $template_technical_codes_array, $custom_template_tags, null, $GLOBALS['support_commande']);
1009  send_email($GLOBALS['support_commande'], '', '', $template_technical_codes_array, $custom_template_tags, null, $GLOBALS['support_commande']);
1010  if(!defined('IN_PEEL_ADMIN') || (defined('IN_PEEL_ADMIN') && !empty($GLOBALS['site_parameters']['send_email_order_in_admin']))) {
1011  // Envoi de l'email pour l'administrateur en plus de la copie de ce qui est envoyé au client. L'envoi de cet email si l'on est en back office est paramétrable.
1012  send_mail_order_admin($order_id);
1013  }
1014  }
1015 }
1016 
1023 function send_mail_order_admin($order_id)
1024 {
1025  $result = query("SELECT *
1026  FROM peel_commandes
1027  WHERE id ='" . intval($order_id) . "' AND " . get_filter_site_cond('commandes') . "");
1028  $order_object = fetch_object($result);
1029  $custom_template_tags['ORDER_ID'] = $order_id;
1030  $custom_template_tags['EMAIL'] = $order_object->email;
1031  $custom_template_tags['SITE'] = $GLOBALS['site'];
1032  $custom_template_tags['MONTANT'] = fprix($order_object->montant, true);
1033  $custom_template_tags['O_TIMESTAMP'] = get_formatted_date($order_object->o_timestamp);
1034  $custom_template_tags['PAIEMENT'] = get_payment_name($order_object->paiement);
1035  $custom_template_tags['COMMENT'] = $order_object->commentaires;
1036 
1037  send_email($GLOBALS['support_commande'], '', '', 'send_mail_order_admin', $custom_template_tags, null, $GLOBALS['support_commande']);
1038 }
1039 
1046 function get_payment_name($id_or_code)
1047 {
1048  $sql_paiement = 'SELECT p.nom_' . $_SESSION['session_langue'] . ' AS nom
1049  FROM peel_paiement p
1050  WHERE (p.id="' . intval($id_or_code) . '" OR p.technical_code="' . nohtml_real_escape_string($id_or_code) . '") AND ' . get_filter_site_cond('paiement', 'p') . '';
1051  $res_paiement = query($sql_paiement);
1052  if ($tab_paiement = fetch_assoc($res_paiement)) {
1053  return $tab_paiement['nom'];
1054  } else {
1055  return '';
1056  }
1057 }
1058 
1066 {
1067  static $payment_status_name_by_id;
1068  if (!isset($payment_status_name_by_id[$id])) {
1069  $sql_paiement = 'SELECT p.nom_' . $_SESSION['session_langue'] . ' AS nom
1070  FROM peel_statut_paiement p
1071  WHERE p.id="' . intval($id) . '" AND ' . get_filter_site_cond('statut_paiement', 'p');
1072  $res_paiement = query($sql_paiement);
1073  if ($tab_paiement = fetch_assoc($res_paiement)) {
1074  $payment_status_name_by_id[$id] = String::html_entity_decode_if_needed($tab_paiement['nom']);
1075  } else {
1076  $payment_status_name_by_id[$id] = $id;
1077  }
1078  }
1079  return $payment_status_name_by_id[$id];
1080 }
1081 
1089 {
1090  $sql_livraison = 'SELECT nom_' . $_SESSION['session_langue'] . ' AS nom
1091  FROM peel_statut_livraison
1092  WHERE id="' . intval($id) . '" AND ' . get_filter_site_cond('statut_livraison');
1093  $res_livraison = query($sql_livraison);
1094  if ($tab_livraison = fetch_assoc($res_livraison)) {
1095  return String::html_entity_decode_if_needed($tab_livraison['nom']);
1096  } elseif (!empty($GLOBALS['site_parameters']['mode_transport'])) {
1097  return $id;
1098  } else {
1099  return '-';
1100  }
1101 }
1102 
1110 {
1111  $sql_delivery = 'SELECT nom_' . $_SESSION['session_langue'] . ' AS nom
1112  FROM peel_types
1113  WHERE id="' . intval($id) . '" AND ' . get_filter_site_cond('types');
1114  $res_delivery = query($sql_delivery);
1115  if ($tab_delivery = fetch_assoc($res_delivery)) {
1116  return $tab_delivery['nom'];
1117  } else {
1118  return false;
1119  }
1120 }
1121 
1132 function get_needed_for_free_delivery($total_weight, $total_price, $type_id = null, $zone_id = null, $nb_product = 1)
1133 {
1134  $add_for_free_delivery = array();
1135  // Frais de port gratuits si le total principal (TTC ou HT suivant configuration boutique) des produits est > au seuil.
1136  if (!empty($GLOBALS['site_parameters']['nb_product']) && $GLOBALS['site_parameters']['nb_product'] <= $nb_product) {
1137  // Frais de port gratuits si plus de nb_product commandés
1138  return null;
1139  }elseif (!empty($GLOBALS['site_parameters']['nb_product'])) {
1140  $add_for_free_delivery['products'] = $GLOBALS['site_parameters']['nb_product'] - $nb_product;
1141  }
1142 
1143  if (!empty($zone_id)) {
1144  $query = query('SELECT z.on_franco, z.on_franco_amount, z.on_franco_reseller_amount, z.on_franco_nb_products
1145  FROM peel_zones z
1146  WHERE id = "' . intval($zone_id) . '" AND ' . get_filter_site_cond('zones', 'z') . '
1147  LIMIT 1');
1148  $result_zones = fetch_assoc($query);
1149  if (!empty($result_zones['on_franco'])) {
1150  $amount_used = floatval((check_if_module_active('reseller') && is_reseller()) ? $result_zones['on_franco_reseller_amount'] : $result_zones['on_franco_amount']);
1151  // Zone franco de port
1152  if ($amount_used <= round($total_price, 2)) {
1153  return null;
1154  } else {
1155  $add_for_free_delivery['amount'] = $amount_used - round($total_price, 2);
1156  }
1157  }
1158  if (!empty($result_zones['on_franco_nb_products'])) {
1159  // Zone franco de port
1160  if($result_zones['on_franco_nb_products'] <= $nb_product) {
1161  return null;
1162  } else {
1163  $add_for_free_delivery['products'] = $result_zones['on_franco_nb_products'] - $nb_product;
1164  }
1165  }
1166  }
1167  // Le seuil d'exonération de frais de port de la zone est prioritaire sur le seuil d'exonération de frais de port généraux.
1168  // Don con ne teste ici les exonérations générales que si il n'y a pas de configuration d'exonération par zone
1169  if (empty($add_for_free_delivery['amount'])) {
1170  // Cas où un seuil de commande minimal est défini pour l'utilisateur de manière globale au niveau de la configuration du site
1171  $seuil_total_used = floatval((check_if_module_active('reseller') && is_reseller()) ? $GLOBALS['site_parameters']['seuil_total_reve'] : $GLOBALS['site_parameters']['seuil_total']);
1172  if (round($seuil_total_used, 2) > 0) {
1173  if(round($total_price, 2) >= round($seuil_total_used, 2)) {
1174  // Si le seuil défini pour le franco de port pour la zone n'est pas atteint par le montant de la commande, l'exénoration des frais de port ne s'applique pas
1175  return null;
1176  } else {
1177  // Pour atteindre frais de ports gratuit, il faut une commande plus importante
1178  $add_for_free_delivery['amount'] = round($seuil_total_used, 2) - round($total_price, 2);
1179  }
1180  }
1181  }
1182  return $add_for_free_delivery;
1183 }
1184 
1199 function get_delivery_cost_infos($total_weight, $total_price, $type_id = null, $zone_id = null, $nb_product = 1)
1200 {
1201  static $delivery_cost_infos_by_weight_and_price_array;
1202  $delivery_cost_infos = array('cost_ht' => 0, 'tva' => 0);
1203  if (empty($nb_product)) {
1204  // si nb_product est vide, on ne cherche pas à calculer les frais de ports.
1205  return $delivery_cost_infos;
1206  }
1207  $key_weight_and_price = $type_id . $zone_id . $total_weight . $total_price;
1208  $add_for_free_delivery = get_needed_for_free_delivery($total_weight, $total_price, $type_id, $zone_id, $nb_product);
1209  if ($add_for_free_delivery !== null && !empty($GLOBALS['site_parameters']['mode_transport'])) {
1210  if (!isset($delivery_cost_infos_by_weight_and_price_array[$key_weight_and_price])) {
1211  // Frais de port calculés en fonction du poids total et du montant total
1212  if($GLOBALS['site_parameters']['delivery_cost_calculation_mode'] == 'nearest'){
1213  // On ne prend pas les frais de port les moins chers trouvés, mais ceux correspondant à la tranche la plus proche : par poids en priorité, et par tarif
1214  // => Permet d'avoir des frais de port dégressifs
1215  $order_by = 'IF(poids_max>0, poids_max, 100000000) ASC, IF(total_max>0, total_max, 100000000) ASC, tarif ASC';
1216  } else {
1217  // Par défaut : On prend le tarif le moins cher pour un poids et un montant donné
1218  // Cela permet d'avoir des règles complexes entre poids et montant du caddie, mais oblige à définir des tranches précises qui ne se recouvrent pas si on veut configurer des frais progressifs (frais qui montent en fonction du poids et/ou du montant)
1219  $order_by = 'tarif ASC';
1220  }
1221  $tarifs_sql = 'SELECT tarif, poidsmax, totalmax, tva
1222  FROM peel_tarifs
1223  WHERE ' . get_filter_site_cond('tarifs') . ' AND ' . (!empty($type_id)?'type="' . intval($type_id) . '"':'tarif>0') . (!empty($zone_id)?' AND zone = "' . intval($zone_id) . '"':'') . ' AND (poidsmin<="' . floatval($total_weight) . '" OR poidsmin=0) AND (poidsmax>="' . floatval($total_weight) . '" OR poidsmax=0) AND (totalmin<="' . floatval($total_price) . '" OR totalmin=0) AND (totalmax>="' . floatval($total_price) . '" OR totalmax=0)
1224  ORDER BY ' . $order_by . '
1225  LIMIT 1';
1226  $req = query($tarifs_sql);
1227  if ($this_tarif = fetch_assoc($req)) {
1228  $delivery_cost_infos['cost_ht'] = $this_tarif['tarif'] / (1 + $this_tarif['tva'] / 100);
1229  if (!check_if_module_active('micro_entreprise')) {
1230  $delivery_cost_infos['tva'] = $this_tarif['tva'];
1231  } else {
1232  $delivery_cost_infos['tva'] = 0;
1233  }
1234  } elseif (!empty($type_id)) {
1235  // par défaut : pas de frais de port trouvé => mode de livraison indisponible
1236  $delivery_cost_infos = false;
1237  }
1238  $delivery_cost_infos_by_weight_and_price_array[$key_weight_and_price] = $delivery_cost_infos;
1239  } else {
1240  $delivery_cost_infos = $delivery_cost_infos_by_weight_and_price_array[$key_weight_and_price];
1241  }
1242  }
1243 
1244  return $delivery_cost_infos;
1245 }
1246 
1253 function get_payment_technical_code($id_or_code)
1254 {
1255  $sql_paiement = 'SELECT technical_code
1256  FROM peel_paiement
1257  WHERE (id="' . intval($id_or_code) . '" OR technical_code="' . nohtml_real_escape_string($id_or_code) . '") AND ' . get_filter_site_cond('paiement') . '';
1258  $res_paiement = query($sql_paiement);
1259  if ($tab_paiement = fetch_assoc($res_paiement)) {
1260  return $tab_paiement['technical_code'];
1261  } else {
1262  return false;
1263  }
1264 }
1265 
1272 function get_vat_array($code_facture)
1273 {
1274  $sql = 'SELECT SUM(pca.tva) AS products_tva_for_this_percent, pca.tva_percent, pc.tva_cout_transport, ROUND(pc.tva_cout_transport/pc.cout_transport_ht*100,2) AS cout_transport_tva_percent, pc.tva_tarif_paiement, ROUND(pc.tva_tarif_paiement/pc.tarif_paiement_ht*100,2) AS tarif_paiement_tva_percent, tva_small_order_overcost, ROUND(tva_small_order_overcost/(small_order_overcost_amount-tva_small_order_overcost)*100,2) AS small_order_overcost_tva_percent
1275  FROM peel_commandes_articles pca
1276  INNER JOIN peel_commandes pc ON pca.commande_id = pc.id AND ' . get_filter_site_cond('commandes', 'pc') . '
1277  WHERE pc.code_facture = "' . nohtml_real_escape_string($code_facture) . '" AND ' . get_filter_site_cond('commandes_articles', 'pca') . '
1278  GROUP BY pc.id, pca.tva_percent';
1279  $query = query($sql);
1280  $total_tva = array();
1281  $i = 0;
1282  if (!empty($query)) {
1283  while ($result = fetch_assoc($query)) {
1284  if (empty($total_tva[$result['tva_percent']])) {
1285  $total_tva[$result['tva_percent']] = 0;
1286  }
1287  $total_tva[$result['tva_percent']] += $result['products_tva_for_this_percent'];
1288  if (empty($i)) {
1289  // Avec la jointure, on peut avoir N lignes pour une commande si il y a N taux de TVA produits différents
1290  // On prend ici en compte une seule fois ce qui est spécifique à la commande et non aux divers produits
1291  if ($result['tva_cout_transport'] > 0) {
1292  $total_tva['transport ' . $result['cout_transport_tva_percent']] = $result['tva_cout_transport'];
1293  }
1294  if ($result['tva_tarif_paiement'] > 0) {
1295  if (empty($total_tva[$result['tarif_paiement_tva_percent']])) {
1296  $total_tva[$result['tarif_paiement_tva_percent']] = 0;
1297  }
1298  $total_tva[$result['tarif_paiement_tva_percent']] += $result['tva_tarif_paiement'];
1299  }
1300  if ($result['tva_small_order_overcost'] > 0) {
1301  if (empty($total_tva[$result['small_order_overcost_tva_percent']])) {
1302  $total_tva[$result['small_order_overcost_tva_percent']] = 0;
1303  }
1304  $total_tva[$result['small_order_overcost_tva_percent']] += $result['tva_small_order_overcost'];
1305  }
1306  }
1307  $i++;
1308  }
1309  }
1310  ksort($total_tva);
1311  return $total_tva;
1312 }
1313 
1320 function get_order_infos_array($order_object)
1321 {
1322  if(empty($order_object)){
1323  return array();
1324  }
1325  if (!empty($order_object->a_timestamp) && $order_object->a_timestamp != '0000-00-00' && in_array($order_object->statut_paiement, array('discussed', 'completed'))) {
1326  $order_infos['displayed_paiement_date'] = get_formatted_date($order_object->a_timestamp);
1327  } else {
1328  $order_infos['displayed_paiement_date'] = null;
1329  }
1330  // Limitation du nombre de lignes de l'adresse
1331  $separator_before_country = "\n";
1332  $separator_before_email = "\n";
1333  if(String::substr_count($order_object->adresse_bill, "\n")>0) {
1334  if(String::strlen($order_object->adresse_bill)<40) {
1335  // Adresse courte mais sur plusieurs lignes : on gagne de la place en retirant les sauts de ligne
1336  $order_object->adresse_bill = str_replace("\n", ' - ', $order_object->adresse_bill);
1337  } else {
1338  // Adresse longue sur plusieurs lignes : on gagne de la place en mettant le pays à côté de la ville
1339  $separator_before_country = ' - ';
1340  if(String::substr_count($order_object->adresse_bill, "\n") >= 2) {
1341  $separator_before_email = ' - ';
1342  }
1343  }
1344  }
1345  $order_infos['client_infos_bill'] = (!empty($order_object->societe_bill)?$order_object->societe_bill . "\n":'')
1346  . trim($order_object->nom_bill . " " . $order_object->prenom_bill)
1347  . "\n" . $order_object->adresse_bill;
1348  if (!empty($GLOBALS['site_parameters']['order_specific_field_titles'])) {
1349  foreach($GLOBALS['site_parameters']['order_specific_field_titles'] as $this_field => $this_title) {
1350  if(String::substr($this_title, 0, 4) == 'STR_' && isset($GLOBALS[$this_title])) {
1351  $this_text = $GLOBALS[$this_title];
1352  } else {
1353  $this_text = $this_title;
1354  }
1355  if ((String::substr($this_field, -5) == '_bill') && !empty($order_object->$this_field)) {
1356  // On a ajouté dans la table utilisateurs un champ qui concerne l'adresse de facturation => Il faut préremplir les champs du formulaire d'adresse de facturation avec ces infos.
1357  $order_infos['client_infos_bill'] .= "\n" . $this_title . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . vb($order_object->$this_field);
1358  }
1359  }
1360  }
1361  $order_infos['client_infos_bill'] .= "\n" . trim($order_object->zip_bill . " " . $order_object->ville_bill)
1362  . $separator_before_country . $order_object->pays_bill
1363  . "\n" . get_formatted_phone_number($order_object->telephone_bill)
1364  . $separator_before_email . $order_object->email_bill;
1365 
1366  $order_infos['client_infos_bill'] = trim(str_replace(array("\n ", "\n\n\n\n", "\n\n\n", "\n\n"), "\n", $order_infos['client_infos_bill']));
1367 
1368  // Limitation du nombre de lignes de l'adresse
1369  $separator_before_country = "\n";
1370  $separator_before_email = "\n";
1371  if(String::substr_count($order_object->adresse_ship, "\n")>0) {
1372  if(String::strlen($order_object->adresse_ship)<40) {
1373  // Adresse courte mais sur plusieurs lignes : on gagne de la place en retirant les sauts de ligne
1374  $order_object->adresse_ship = str_replace("\n", ' - ', $order_object->adresse_ship);
1375  } else {
1376  // Adresse longue sur plusieurs lignes : on gagne de la place en mettant le pays à côté de la ville
1377  $separator_before_country = ' - ';
1378  if(String::substr_count($order_object->adresse_ship, "\n") >= 2) {
1379  $separator_before_email = ' - ';
1380  }
1381  }
1382  }
1383  $order_infos['client_infos_ship'] = (!empty($order_object->societe_ship)?$order_object->societe_ship . "\n":'')
1384  . trim($order_object->nom_ship . " " . $order_object->prenom_ship)
1385  . "\n" . $order_object->adresse_ship;
1386  if (!empty($GLOBALS['site_parameters']['order_specific_field_titles'])) {
1387  foreach($GLOBALS['site_parameters']['order_specific_field_titles'] as $this_field => $this_title) {
1388  if(String::substr($this_title, 0, 4) == 'STR_' && isset($GLOBALS[$this_title])) {
1389  $this_text = $GLOBALS[$this_title];
1390  } else {
1391  $this_text = $this_title;
1392  }
1393  if ((String::substr($this_field, -5) == '_ship') && !empty($order_object->$this_field)) {
1394  // On a ajouté dans la table utilisateurs un champ qui concerne l'adresse de facturation => Il faut préremplir les champs du formulaire d'adresse de facturation avec ces infos.
1395  $order_infos['client_infos_ship'] .= "\n" . $this_text . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . vb($order_object->$this_field);
1396  }
1397  }
1398  }
1399  $order_infos['client_infos_ship'] .= "\n" . trim($order_object->zip_ship . " " . $order_object->ville_ship)
1400  . $separator_before_country . $order_object->pays_ship
1401  . "\n" . get_formatted_phone_number($order_object->telephone_ship)
1402  . $separator_before_email . $order_object->email_ship;
1403  if (String::strpos($order_infos['client_infos_bill'], 'TVA') === false) {
1404  $client = get_user_information($order_object->id_utilisateur);
1405  if (!empty($client) && !empty($client['intracom_for_billing'])) {
1406  // Ajout du numéro de TVA intracommunautaire qui n'est pas dans $client_infos_bill
1407  $order_infos['client_infos_bill'] .= "\n" . $GLOBALS['STR_VAT_INTRACOM'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . $client['intracom_for_billing'];
1408  }
1409  }
1410  $order_infos['client_infos_ship'] = trim(str_replace(array("\n ", "\n\n\n\n", "\n\n\n", "\n\n"), "\n", $order_infos['client_infos_ship']));
1411 
1412  $order_infos['net_infos_array'] = array("avoir" => fprix($order_object->avoir, true, $order_object->devise, true, $order_object->currency_rate, true),
1413  "total_remise" => fprix($order_object->total_remise, true, $order_object->devise, true, $order_object->currency_rate, true),
1414  "cout_transport" => fprix($order_object->cout_transport, true, $order_object->devise, true, $order_object->currency_rate, true),
1415  "totalttc" => fprix($order_object->montant+$order_object->avoir, true, $order_object->devise, true, $order_object->currency_rate, true),
1416  "montant" => fprix($order_object->montant, true, $order_object->devise, true, $order_object->currency_rate, true),
1417  "total_tva" => fprix($order_object->total_tva, true, $order_object->devise, true, $order_object->currency_rate, true),
1418  "montant_ht" => fprix($order_object->montant_ht, true, $order_object->devise, true, $order_object->currency_rate, true),
1419  "tarif_paiement" => fprix($order_object->tarif_paiement, true, $order_object->devise, true, $order_object->currency_rate, true),
1420  "cout_transport_ht" => fprix($order_object->cout_transport_ht, true, $order_object->devise, true, $order_object->currency_rate, true),
1421  "small_order_overcost_amount" => fprix($order_object->small_order_overcost_amount, true, $order_object->devise, true, $order_object->currency_rate, true),
1422  "total_ecotaxe_ht" => fprix($order_object->total_ecotaxe_ht, true, $order_object->devise, true, $order_object->currency_rate, true)
1423  );
1424  if ($order_object->cout_transport != 0) {
1425  $order_infos['net_infos_array']['displayed_cout_transport'] = fprix($order_object->cout_transport, true, $order_object->devise, true, $order_object->currency_rate) . " " . $GLOBALS['STR_TTC'];
1426  } else {
1427  $order_infos['net_infos_array']['displayed_cout_transport'] = $GLOBALS['STR_OFFERED'];
1428  }
1429  $order_infos['tva_infos_array'] = array("total_tva" => fprix($order_object->total_tva, true, $order_object->devise, true, $order_object->currency_rate, true));
1430  $distinct_total_vat = get_vat_array($order_object->code_facture);
1431  foreach($distinct_total_vat as $vat_percent_name => $value) {
1432  if (String::substr($vat_percent_name, 0, strlen('transport')) == 'transport') {
1433  // La variable $vat_percent_name contient la valeur qui sera affichée en face du montant de la TVA sur la facture
1434  // Dans le cas de la TVA sur le transport, le mot "tranport" est présent dans le nom. Pour connaitre le taux de TVA dans ce cas, il faut supprimer le mot "transport" du nom, et supprimer les espaces.
1435  $vat_percent = trim(String::substr($vat_percent_name, strlen('transport')));
1436  } else {
1437  // Dans tous les autres cas, le nom de la TVA est le taux de la TVA, il n'y a pas d'information supplémentaire dans le nom.
1438  $vat_percent = $vat_percent_name;
1439  }
1440  if ($vat_percent>0 && $value>0) {
1441  $order_infos['tva_infos_array']["distinct_total_vat"][$vat_percent_name] = fprix($value, true, $order_object->devise, true, $order_object->currency_rate, true);
1442  }
1443  }
1444  if (!empty($order_object->code_promo)) {
1445  $order_infos['code_promo_text'] = $GLOBALS['STR_CODE_PROMO_REMISE'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . $order_object->code_promo;
1446  $code_promo_query = query('SELECT code_promo, valeur_code_promo, percent_code_promo
1447  FROM peel_commandes pc
1448  WHERE code_promo="' . nohtml_real_escape_string($order_object->code_promo) . '" AND ' . get_filter_site_cond('commandes', 'pc') . '');
1449  if ($cp = fetch_assoc($code_promo_query)) {
1450  $order_infos['code_promo_text'] .= ' - ' . get_discount_text($cp['valeur_code_promo'], $cp['percent_code_promo'], true) . '';
1451  }
1452  } else {
1453  $order_infos['code_promo_text'] = '';
1454  }
1455  $order_infos['delivery_infos'] = $order_object->type;
1456  return $order_infos;
1457 }
1458 
1469 function get_product_infos_array_in_order($order_id, $devise = null, $currency_rate = null, $order_by = null, $add_total_prix_attribut = false)
1470 {
1471  if(empty($order_by) && !empty($GLOBALS['site_parameters']['order_article_order_by']) && $GLOBALS['site_parameters']['order_article_order_by'] == 'name') {
1472  $order_by = 'oi.nom_produit ASC';
1473  } elseif(!empty($GLOBALS['site_parameters']['order_article_order_by']) && $GLOBALS['site_parameters']['order_article_order_by'] == 'reference') {
1474  $order_by = 'oi.reference ASC';
1475  } else {
1476  $order_by = 'oi.id ASC';
1477  }
1478 
1479  $product_infos_array = array();
1480  $sql = "SELECT oi.*, p.technical_code, c.nom_".$_SESSION['session_langue']." AS category_name, m.nom_".$_SESSION['session_langue']." AS brand_name
1481  FROM peel_commandes_articles oi
1482  LEFT JOIN peel_produits p ON p.id=oi.produit_id AND " . get_filter_site_cond('produits', 'p') . "
1483  LEFT JOIN peel_produits_categories pc ON p.id = pc.produit_id
1484  LEFT JOIN peel_categories c ON c.id = pc.categorie_id AND " . get_filter_site_cond('categories', 'c') . "
1485  LEFT JOIN peel_marques m ON m.id = p.id_marque AND " . get_filter_site_cond('marques', 'm') . "
1486  WHERE commande_id='" . intval($order_id) . "' AND " . get_filter_site_cond('commandes_articles', 'oi') . "
1487  GROUP BY oi.nom_attribut, oi.attributs_list, oi.produit_id, oi.reference, oi.nom_produit, oi.prix, oi.couleur_id, oi.taille_id
1488  ORDER BY " . $order_by;
1489  $qid_items = query($sql);
1490  while ($prod = fetch_assoc($qid_items)) {
1491  // On crée la description d'un produit facturé
1492  $category_text = (!empty($prod['category_name']) && !empty($GLOBALS['site_parameters']['display_category_name_in_product_infos_in_order']) ? "\r\n" . $GLOBALS['STR_CATEGORY'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . String::htmlspecialchars_decode($prod["category_name"], ENT_QUOTES) : "");
1493  $brand_text = (!empty($prod['brand_name']) && !empty($GLOBALS['site_parameters']['display_brand_name_in_product_infos_in_order']) ? "\r\n" . $GLOBALS['STR_BRAND'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . String::htmlspecialchars_decode($prod["brand_name"], ENT_QUOTES) : "");
1494  $reference_text = (!empty($prod['reference']) ? "\r\n" . $GLOBALS['STR_REFERENCE'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . String::htmlspecialchars_decode($prod["reference"], ENT_QUOTES) : "");
1495  $couleur_text = (!empty($prod['couleur']) ? "\r\n" . $GLOBALS['STR_COLOR'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . String::html_entity_decode_if_needed($prod['couleur']) : "");
1496  $taille_text = (!empty($prod['taille']) ? "\r\n" . $GLOBALS['STR_SIZE'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . String::html_entity_decode_if_needed($prod['taille']) : "");
1497  if ($prod['nom_attribut'] != '') {
1498  $attribut_text = "\r\n" . trim(String::html_entity_decode_if_needed($prod['nom_attribut']));
1499  if($add_total_prix_attribut) {
1500  $attribut_text .= ($prod['total_prix_attribut'] > 0 ? "\r\n" . $GLOBALS['STR_OPTIONS_COST'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ': ' . fprix($prod['total_prix_attribut'], true) . ' ' . $GLOBALS['STR_TTC'] : '');
1501  }
1502  } else {
1503  $attribut_text = '';
1504  }
1505  $delai_text = (!empty($prod['delai_stock']) ? "\r\n" . $GLOBALS['STR_DELIVERY_STOCK'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . get_formatted_duration((intval($prod['delai_stock']) * 24 * 3600), false, true) : "");
1506  // Attention : un test !empty ne marche pas sur prix_option, percent_remise_produit et ecotaxe_ttc car au format "0.00"
1507  $option_text = ($prod['prix_option'] != 0 ? "\r\n" . $GLOBALS['STR_OPTION_PRIX'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . fprix($prod['prix_option'], true, $devise, true, $currency_rate) . "" : "");
1508  // ATTENTION : ne pas utiliser ici $prod['percent_remise_produit']
1509  // - Dans $prod['percent_remise_produit'] il y a l'ensemble des pourcentages de remise qui est indiqué, que ce soit liés au produit ou à l'utilisateur, ce qui a un intérêt technique et de déboguage.
1510  // Ce pourcentage ne prend pas en considération des réductions par montant effectuées, donc ça n'est pas le total de réduction en pourcentage
1511  // - $prod['remise'] est quant à lui la remise totale effectuée, donc c'est une information compréhensible par l'utilisateur.
1512  $remise_text = ($prod['remise'] > 0 ? "\r\n" . $GLOBALS['STR_PROMOTION_INCLUDE'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . get_discount_text((display_prices_with_taxes_active()?$prod['remise']:$prod['remise_ht']), $prod['percent_remise_produit'] , display_prices_with_taxes_active()) : "");
1513  if (check_if_module_active('ecotaxe')) {
1514  // On affiche le montant de l'écotaxe dans la colonne dénomination du produit et non pas prix pour des raisons de largeur de colonne
1515  $ecotaxe_text = ($prod['ecotaxe_ttc'] > 0) ? "\r\n" . $GLOBALS['STR_ECOTAXE_INCLUDE'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . fprix($prod['ecotaxe_ttc'], true, $devise, true, $currency_rate) : "";
1516  }
1517  $prod['product_technical_text'] = String::html_entity_decode_if_needed($prod['nom_produit'] . vb($category_text) . vb($brand_text) . vb($reference_text) . vb($couleur_text) . vb($taille_text) . vb($attribut_text));
1518  $prod['product_text'] = String::html_entity_decode_if_needed($prod['nom_produit'] . vb($category_text) . vb($brand_text) . vb($reference_text) . vb($couleur_text) . vb($taille_text) . vb($attribut_text) . vb($option_text) . vb($remise_text) . vb($ecotaxe_text) . vb($delai_text));
1519  $product_infos_array[] = $prod;
1520  }
1521  return $product_infos_array;
1522 }
1523 
1534 function get_payment_form($order_id, $forced_type = null, $send_admin_email = false, $amount_to_pay = 0, $allow_autosend = true)
1535 {
1536  $output = '';
1537  $result = query('SELECT *
1538  FROM peel_commandes
1539  WHERE id="' . intval($order_id) . '" AND ' . get_filter_site_cond('commandes') . '');
1541  if(empty($com)) {
1542  return null;
1543  }
1544  if (empty($amount_to_pay)) {
1545  $amount_to_pay = floatval($com->montant);
1546  }
1547  if($amount_to_pay == 0 || !is_order_modification_allowed($com->o_timestamp)) {
1548  return null;
1549  }
1550  if (!empty($forced_type)) {
1551  $type = $forced_type;
1552  } else {
1553  // In $com->payment_technical_code is stored the "technical_code" found in peel_paiement
1554  $type = $com->paiement;
1555  }
1556  if (empty($type)) {
1557  // Affichage de tous les modes de paiement si aucun défini (seulement si commande passée dans l'administration)
1558  $sql_paiement = 'SELECT p.technical_code
1559  FROM peel_paiement p
1560  WHERE p.etat = "1" AND ' . get_filter_site_cond('paiement', 'p') . '
1561  ORDER BY p.position';
1562  $res_paiement = query($sql_paiement);
1563  while ($tab_paiement = fetch_assoc($res_paiement)) {
1564  if (!empty($tab_paiement['technical_code'])) {
1565  $this_output = get_payment_form($order_id, $tab_paiement['technical_code'], $send_admin_email, $amount_to_pay, $allow_autosend);
1566  if(!empty($this_output)) {
1567  $output_array[] = $this_output;
1568  }
1569  }
1570  }
1571  return implode('<hr />', $output_array);
1572  }
1573  $tpl = $GLOBALS['tplEngine']->createTemplate('payment_form.tpl');
1574  $tpl->assign('type', $type);
1575  $tpl->assign('commande_pdf_href', get_site_wwwroot($com->site_id) . '/factures/commande_pdf.php?code_facture=' . $com->code_facture . '&mode=bdc');
1576  $tpl->assign('amount_to_pay_formatted', fprix($amount_to_pay, true, $com->devise, true, get_float_from_user_input(vn($com->currency_rate))));
1577  $tpl->assign('disable_address_payment_by_check', !empty($GLOBALS['site_parameters']['disable_address_payment_by_check']));
1578  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
1579  $tpl->assign('STR_FOR_A_CHECK_PAYMENT', $GLOBALS['STR_FOR_A_CHECK_PAYMENT']);
1580  $tpl->assign('STR_SEND_CHECK', $GLOBALS['STR_SEND_CHECK']);
1581  $tpl->assign('STR_SEND_TRANSFER', $GLOBALS['STR_SEND_TRANSFER']);
1582  $tpl->assign('STR_FOR_A_TRANSFERT', $GLOBALS['STR_FOR_A_TRANSFERT']);
1583  $tpl->assign('STR_PRINT_PROFORMA', $GLOBALS['STR_PRINT_PROFORMA']);
1584  $tpl->assign('STR_FOLLOWING_ADDRESS', $GLOBALS['STR_FOLLOWING_ADDRESS']);
1585  $tpl->assign('STR_FOLLOWING_ACCOUNT', $GLOBALS['STR_FOLLOWING_ACCOUNT']);
1586  switch ($type) {
1587  case 'check':
1588  $tpl->assign('societe', print_societe(true));
1589  break;
1590 
1591  case 'transfer':
1592  $tpl->assign('rib', print_rib(true));
1593  break;
1594 
1595  case 'cmcic' :
1596  if (file_exists($GLOBALS['fonctionscmcic'])) {
1597  require_once($GLOBALS['fonctionscmcic']);
1598  $js_action = 'document.getElementById("PaymentRequest").submit()';
1599  $tpl->assign('form', getCMCICForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, ''));
1600  $send_admin_template_email = 'admin_info_payment_credit_card';
1601  }
1602  break;
1603 
1604  case 'cmcic_by_3' :
1605  if (file_exists($GLOBALS['fonctionscmcic'])) {
1606  require_once($GLOBALS['fonctionscmcic']);
1607  $js_action = 'document.getElementById("PaymentRequest").submit()';
1608  $tpl->assign('form', getCMCICForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 3, ''));
1609  $send_admin_template_email = 'admin_info_payment_credit_card_3_times';
1610  }
1611  break;
1612 
1613  case 'atos' :
1614  if (file_exists($GLOBALS['fonctionsatos']) && !empty($GLOBALS['site_parameters']['atos_solution_name']['atos'])) {
1615  require_once($GLOBALS['fonctionsatos']);
1616  // la validation automatique ne fonctionne pas avec atos.
1617  $tpl->assign('form', getATOSForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $GLOBALS['site_parameters']['atos_solution_name']['atos']));
1618  $send_admin_template_email = 'admin_info_payment_credit_card';
1619  }
1620  break;
1621 
1622  case 'atos_by_3' :
1623  if (file_exists($GLOBALS['fonctionsatos']) && !empty($GLOBALS['site_parameters']['atos_solution_name']['atos_by_3'])) {
1624  require_once($GLOBALS['fonctionsatos']);
1625  // la validation automatique ne fonctionne pas avec atos.
1626  $tpl->assign('form', getATOSForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 3, '', $GLOBALS['site_parameters']['atos_solution_name']['atos_by_3']));
1627  $send_admin_template_email = 'admin_info_payment_credit_card_3_times';
1628  }
1629  break;
1630 
1631  case 'cetelem' :
1632  if (file_exists($GLOBALS['fonctionsatos']) && !empty($GLOBALS['site_parameters']['atos_solution_name']['cetelem'])) {
1633  require_once($GLOBALS['fonctionsatos']);
1634  // la validation automatique ne fonctionne pas avec atos.
1635  $tpl->assign('form', getATOSForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $GLOBALS['site_parameters']['atos_solution_name']['cetelem']));
1636  $send_admin_template_email = 'admin_info_payment_credit_card_3_times';
1637  }
1638  break;
1639 
1640  case 'systempay' :
1641  if (file_exists($GLOBALS['fonctionssystempay'])) {
1642  require_once($GLOBALS['fonctionssystempay']);
1643  $js_action = 'document.getElementById("SystempayForm").submit()';
1644  $tpl->assign('form', getSystempayForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $com->adresse_bill, $com->zip_bill, $com->ville_bill, $com->pays_bill, $com->id_utilisateur, $com->nom_bill, $com->prenom_bill, $com->telephone_bill));
1645  $send_admin_template_email = 'admin_info_payment_credit_card';
1646  }
1647  break;
1648 
1649  case 'systempay_3x' :
1650  if (file_exists($GLOBALS['fonctionssystempay'])) {
1651  require_once($GLOBALS['fonctionssystempay']);
1652  $js_action = 'document.getElementById("SystempayForm").submit()';
1653  $tpl->assign('form', getSystempayForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, vn($GLOBALS['site_parameters']['systempay_payment_count'], 1), '', $com->adresse_bill, $com->zip_bill, $com->ville_bill, $com->pays_bill, $com->id_utilisateur, $com->nom_bill, $com->prenom_bill, $com->telephone_bill));
1654  $send_admin_template_email = 'admin_info_payment_credit_card';
1655  }
1656  break;
1657 
1658  case 'spplus' :
1659  if (file_exists($GLOBALS['fonctionsspplus'])) {
1660  require_once($GLOBALS['fonctionsspplus']);
1661  // la validation automatique ne fonctionne pas avec spplus.
1662  // => pas de possibilité de mettre js_action
1663  $tpl->assign('form', getSPPlusForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, ''));
1664  $send_admin_template_email = 'admin_info_payment_credit_card';
1665  }
1666  break;
1667 
1668  case 'paybox' :
1669  if (file_exists($GLOBALS['fonctionspaybox'])) {
1670  require_once($GLOBALS['fonctionspaybox']);
1671  $js_action = 'document.TheForm.submit()';
1672  $tpl->assign('form', givePayboxForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', vb($GLOBALS['site_parameters']['paybox_cgi']), vb($GLOBALS['site_parameters']['paybox_site']), vb($GLOBALS['site_parameters']['paybox_rang']), vb($GLOBALS['site_parameters']['paybox_identifiant'])));
1673  $send_admin_template_email = 'admin_info_payment_credit_card';
1674  }
1675  break;
1676 
1677  case 'bluepaid' :
1678  if (file_exists($GLOBALS['fonctionsbluepaid'])) {
1679  require_once($GLOBALS['fonctionsbluepaid']);
1680  $js_action = 'document.TheForm.submit()';
1681  $tpl->assign('form', getBluepaidForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $com->id_utilisateur, $com->pays_bill));
1682  $send_admin_template_email = 'admin_info_payment_credit_card';
1683  }
1684  break;
1685 
1686  case 'bluepaid_abonnement' :
1687  if (file_exists($GLOBALS['fonctionsbluepaid'])) {
1688  require_once($GLOBALS['fonctionsbluepaid']);
1689  $js_action = 'document.TheForm.submit()';
1690  $tpl->assign('form', getBluepaidForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $com->id_utilisateur, $com->pays_bill, true));
1691  $send_admin_template_email = 'admin_info_payment_credit_card';
1692  }
1693  break;
1694 
1695  case 'kwixo':
1696  if (file_exists($GLOBALS['fonctionsfianet'])) {
1697  echo $GLOBALS['STR_THANKS_FIANET'];
1698  // Librairie de fonctions PEEL pour Fianet
1699  require_once($GLOBALS['fonctionsfianet']);
1700  $tpl->assign('form', getKwixoForm($order_id, 'comptant'));
1701  $send_admin_template_email = 'admin_info_payment_credit_card';
1702  }
1703  break;
1704 
1705  case 'kwixo_rnp':
1706  if (file_exists($GLOBALS['fonctionsfianet'])) {
1707  echo $GLOBALS['STR_THANKS_FIANET'];
1708  // Librairie de fonctions PEEL pour Fianet
1709  require_once($GLOBALS['fonctionsfianet']);
1710  $tpl->assign('form', getKwixoForm($order_id, 'rnp'));
1711  $send_admin_template_email = 'admin_info_payment_credit_card';
1712  }
1713  break;
1714 
1715  case 'kwixo_credit':
1716  if (file_exists($GLOBALS['fonctionsfianet'])) {
1717  echo $GLOBALS['STR_THANKS_FIANET'];
1718  // Librairie de fonctions PEEL pour Fianet
1719  require_once($GLOBALS['fonctionsfianet']);
1720  $tpl->assign('form', getKwixoForm($order_id, 'credit'));
1721  $send_admin_template_email = 'admin_info_payment_credit_card';
1722  }
1723  break;
1724 
1725  case 'ogone' :
1726  case 'postfinance' :
1727  if (file_exists($GLOBALS['fonctionsogone'])) {
1728  require_once($GLOBALS['fonctionsogone']);
1729  $js_action = 'document.getElementById("ogoneForm").submit()';
1730  $tpl->assign('form', giveOgoneForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $com->adresse_bill, $com->zip_bill, $com->ville_bill, $com->pays_bill, $com->prenom_bill . ' ' . $com->nom_bill, $com->telephone_bill, $type));
1731  $send_admin_template_email = 'admin_info_payment_credit_card';
1732  }
1733  break;
1734 
1735  case 'worldpay' :
1736  if (file_exists($GLOBALS['dirroot'] . '/modules/worldpay/fonctions.php')) {
1737  require_once($GLOBALS['dirroot'] . '/modules/worldpay/fonctions.php');
1738  $js_action = 'document.getElementById("worldpayForm").submit()';
1739  $tpl->assign('form', giveWorldpayForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $com->adresse_bill, $com->zip_bill, $com->ville_bill, $com->pays_bill, $com->prenom_bill . ' ' . $com->nom_bill, $com->telephone_bill));
1740  $send_admin_template_email = 'admin_info_payment_credit_card';
1741  }
1742  break;
1743 
1744  case 'omnikassa' :
1745  if (file_exists($GLOBALS['fonctionsomnikassa'])) {
1746  require_once($GLOBALS['fonctionsomnikassa']);
1747  $js_action = 'document.getElementById("omnikassaForm").submit()';
1748  $tpl->assign('form', giveOmnikassaForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $com->adresse_bill, $com->zip_bill, $com->ville_bill, $com->pays_bill, $com->prenom_bill . ' ' . $com->nom_bill, $com->telephone_bill));
1749  $send_admin_template_email = 'admin_info_payment_credit_card';
1750  }
1751  break;
1752 
1753  case 'moneybookers' :
1754  if (file_exists($GLOBALS['fonctionsmoneybookers']) && !empty($GLOBALS['site_parameters']['email_moneybookers'])) {
1755  require_once($GLOBALS['fonctionsmoneybookers']);
1756  $js_action = 'document.getElementById("MoneyBookersForm").submit()';
1757  $tpl->assign('form', getMoneyBookersForm(vb($GLOBALS['site_parameters']['email_moneybookers']), $order_id, $_SESSION['session_langue'], $com->id_utilisateur, $com->email, fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->prenom_bill, $com->nom_bill, $com->adresse_bill, $com->zip_bill, $com->ville_bill, $com->pays_bill, fprix($com->total_tva, false, $com->devise, true, $com->currency_rate, false, false), $com->moneybookers_payment_methods));
1758  $send_admin_template_email = 'admin_info_payment_credit_card';
1759  }
1760  break;
1761 
1762  case 'paypal':
1763  if (file_exists($GLOBALS['fonctionspaypal']) && !empty($GLOBALS['site_parameters']['email_paypal'])) {
1764  require_once($GLOBALS['fonctionspaypal']);
1765  $js_action = 'document.getElementById("paypalForm").submit()';
1766  $tpl->assign('form', getPaypalForm($order_id, $_SESSION['session_langue'], fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), $com->devise, $com->email, 1, '', $com->id_utilisateur, $com->prenom_ship, $com->nom_ship, $com->adresse_ship, $com->zip_ship, $com->ville_ship, $com->pays_ship, $com->telephone_ship, $com->prenom_bill, $com->nom_bill, $com->adresse_bill, $com->zip_bill, $com->ville_bill, $com->pays_bill, $com->telephone_bill));
1767  $tpl->assign('STR_FOR_A_PAYPAL_PAYMENT', $GLOBALS['STR_FOR_A_PAYPAL_PAYMENT']);
1768  $tpl->assign('paypal_img_html', $GLOBALS['STR_PAYPAL_IMG']);
1769  $send_admin_template_email = 'admin_info_payment_credit_card';
1770  }
1771  break;
1772 
1773  default :
1774  if (function_exists('get_payment_form_'.$type)) {
1775  $function_name = 'get_payment_form_'.$type;
1776  $tpl->assign('form', $function_name(array('order_id' => $order_id, 'lang' => $_SESSION['session_langue'], 'amount' => fprix($amount_to_pay, false, $com->devise, true, $com->currency_rate, false, false), 'currency_code' => $com->devise, 'user_email' => $com->email, 'payment_times' => 1, 'sTexteLibre' => '', 'prenom_ship' => $com->prenom_ship, 'nom_ship' => $com->nom_ship, 'adresse_ship' => $com->adresse_ship, 'zip_ship' => $com->zip_ship, 'ville_ship' => $com->ville_ship, 'pays_ship' => $com->pays_ship, 'prenom_bill' => $com->prenom_bill, 'nom_bill' => $com->nom_bill, 'adresse_bill' => $com->adresse_bill, 'zip_bill' => $com->zip_bill, 'ville_bill' => $com->ville_bill, 'pays_bill' => $com->pays_bill, 'fullname_bill' => $com->prenom_bill . ' ' . $com->nom_bill, 'telephone_bill' => $com->telephone_bill, 'type' => $type)));
1777  $send_admin_template_email = 'admin_info_payment_credit_card';
1778  }
1779  break;
1780  }
1781  if ($send_admin_email && !empty($send_admin_template_email)) {
1782  unset($custom_template_tags);
1783  $custom_template_tags['ORDER_ID'] = $order_id;
1784  send_email($GLOBALS['support_commande'], '', '', $send_admin_template_email, $custom_template_tags, null, $GLOBALS['support_commande']);
1785  }
1786  if($allow_autosend && !empty($js_action) && (vn($GLOBALS['site_parameters']['module_autosend']) == 1)) {
1787  $GLOBALS['js_content_array'][] = '
1788  setTimeout("' . filtre_javascript($js_action, true, false, true, true, false) . '", ' . vn($GLOBALS['site_parameters']['module_autosend_delay']) * 1000 . ');
1789 ';
1790  }
1791  $output .= $tpl->fetch();
1792  return $output;
1793 }
1794 
1801 function is_order_modification_allowed($order_datetime)
1802 {
1803  $allowed = false;
1804  if (empty($order_datetime) || substr($order_datetime, 0, 10) == '0000-00-00') {
1805  $allowed = true;
1806  } elseif (empty($GLOBALS['site_parameters']['keep_old_orders_intact']) || $GLOBALS['site_parameters']['keep_old_orders_intact'] == '0') {
1807  $allowed = true;
1808  } elseif ($GLOBALS['site_parameters']['keep_old_orders_intact'] == '1') {
1809  if (intval(date('m')) > 6) {
1810  // Année <= N-1 bloquées
1811  $reference_date = date('Y-12-31', time() - 24 * 3600 * 365);
1812  } else {
1813  // Année <= N-2 bloquées
1814  $reference_date = date('Y-12-31', time() - 24 * 3600 * 365 * 2);
1815  }
1816  } else {
1817  // keep_old_orders_intact est alors un timestamp
1818  $reference_date = date('Y-m-d H:i:s', $GLOBALS['site_parameters']['keep_old_orders_intact']);
1819  }
1820  if (!empty($reference_date) && $order_datetime > $reference_date) {
1821  $allowed = true;
1822  }
1823  return $allowed;
1824 }
1825 
1832 function get_order_id($id = null)
1833 {
1834  if (!empty($id)) {
1835  // Recherche si le numéro de commande est déjà défini.
1836  $query = query('SELECT order_id
1837  FROM peel_commandes
1838  WHERE id='.intval($id).' AND '. get_filter_site_cond('commandes'));
1839  if($result = fetch_assoc($query)) {
1840  if (!empty($result['order_id'])) {
1841  // order_id est déjà défini pour la commande, la fonction retourne la valeur déjà calculée
1842  return $result['order_id'];
1843  }
1844  } else {
1845  // commande introuvable.
1846  return false;
1847  }
1848  }
1849  if (empty($result['order_id']) || empty($id)) {
1850  // La recherche du numéro dans la commande n'a rien donnée, ou $id est vide.
1851  // Récuperation du numéro de commande le plus élevé pour le site.
1852  $query = query('SELECT MAX(order_id) as max_order_id
1853  FROM peel_commandes
1854  WHERE ' . get_filter_site_cond('commandes'));
1856  return $result['max_order_id']+1;
1857  }
1858 }
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
Definition: chart-data.php:29
get_delivery_cost_infos($total_weight, $total_price, $type_id=null, $zone_id=null, $nb_product=1)
Calcul des frais de livraison Si type_id est vide, on récupère les tarifs en excluant les tarifs=0 qu...
Definition: order.php:1199
put_session_commande(&$frm)
Récupère les informations du tableau $frm pour les mettre de manière standardisée dans $_SESSION['ses...
Definition: order.php:429
get_payment_status_name($id)
get_payment_status_name()
Definition: order.php:1065
$product_infos
if(!empty($GLOBALS['site_parameters']['order_specific_field_titles'])) if(check_if_module_active('socolissimo')&&!empty($_REQUEST)&&!empty($_REQUEST['PUDOFOID'])&&!empty($_REQUEST['CEEMAIL'])&&!empty($_REQUEST['SIGNATURE'])&&!empty($_REQUEST['ORDERID'])) elseif(!empty($_POST)) elseif(check_if_module_active('socolissimo')&&!empty($_SESSION['session_commande']['is_socolissimo_order'])) foreach(array('bill'=> 1, 'ship'=> 2) as $address_type=> $session_commande_address_id) $frm['societe1']
static htmlspecialchars_decode($string, $style=ENT_COMPAT)
This function is String::htmlspecialchars_decode with php4 compatibility.
Definition: String.php:500
$result
get_discount_text($remise_valeur, $remise_percent, $is_remise_valeur_including_taxe)
Retourne la remise d'un code promotionnel (en % dans le cas d'une remise en pourcentage ou dans le fo...
Definition: fonctions.php:421
get_user_information($user_id=null, $get_full_infos=false)
Chargement des détails de l'utilisateur.
Definition: user.php:906
static strpos($haystack, $needle, $offset=0)
Returns the numeric position of the first occurrence of needle in the haystack string.
Definition: String.php:54
get_delivery_type_name($id)
get_delivery_type_name()
Definition: order.php:1109
if(!defined('IN_PEEL')) get_bill_number($bill_number_format, $id, $generate_bill_number_if_empty=true)
Fonction qui génère le numéro de facture pour la facture n° $id à partir du format défini dans les pa...
Definition: order.php:26
get_product_infos_array_in_order($order_id, $devise=null, $currency_rate=null, $order_by=null, $add_total_prix_attribut=false)
get_product_infos_array_in_order()
Definition: order.php:1469
get_delivery_status_name($id)
get_delivery_status_name()
Definition: order.php:1088
get_vat_array($code_facture)
Fonction permettant l'affichage des taux de TVA dans les factures.
Definition: order.php:1272
handle_specific_fields(&$frm, $form_usage= 'user')
Traite la réception de champs spécifiques venant d'un formulaire, et l'identification de tous les cha...
Definition: fonctions.php:5286
static html_entity_decode_if_needed($string)
String::html_entity_decode_if_needed()
Definition: String.php:533
is_order_modification_allowed($order_datetime)
Renvoie si il est autorisé de modifier une commande.
Definition: order.php:1801
$qid_commande
word_real_escape_string($value)
Applique real_escape_string dans le cas où on n'insère qu'un seul mot, de moins de 30 caractères...
Definition: database.php:424
get_order_id($id=null)
Fonction qui génère le numéro de commande comptable.
Definition: order.php:1832
get_needed_for_free_delivery($total_weight, $total_price, $type_id=null, $zone_id=null, $nb_product=1)
get_needed_for_free_delivery()
Definition: order.php:1132
insert_id($database_object=null)
insert_id()
Definition: database.php:339
static strlen($string)
Returns the length of the given string.
Definition: String.php:36
nohtml_real_escape_string($value, $allowed_tags=null)
Protège les données pour insertion dans MySQL ET supprime les tags HTML pour protéger de toute sorte ...
Definition: database.php:400
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
get_formatted_duration($total_seconds, $show_seconds=false, $display_mode= 'day')
Affiche une durée en jours / heures / minutes / secondes.
Definition: format.php:533
if(empty($_GET['id'])) if(!empty($GLOBALS['site_parameters']['allow_multiple_product_url_with_category'])) $product_object
get_float_from_user_input($string, $from_currency_rate=1)
Transforme tout nombre formaté en un float au format PHP Exemples : 12 004,34 ou 12,324.50.
Definition: format.php:196
real_escape_string($value)
real_escape_string()
Definition: database.php:374
if(!defined('PAYPAL_SANDBOX')) getPaypalForm($order_id, $lang, $amount, $currency_code, $user_email, $payment_times=1, $sTexteLibre= '', $user_id, $prenom_ship, $nom_ship, $adresse_ship, $zip_ship, $ville_ship, $pays_ship, $telephone_ship, $prenom_bill=null, $nom_bill=null, $adresse_bill=null, $zip_bill=null, $ville_bill=null, $pays_bill=null, $telephone_bill=null)
Génère le formulaire de paiement Paypal.
Definition: fonctions.php:46
$com
getMoneyBookersForm($pay_to_email, $order_id, $lang, $user_id, $user_email, $amount, $currency, $user_firstname, $user_familyname, $user_address, $user_zip, $user_town, $user_country_name, $total_tva, $payment_methods)
getMoneyBookersForm()
Definition: fonctions.php:32
get_formatted_phone_number($phone_number)
Supprime les caractères entre et autour des chiffres dans un numéro de téléphone. ...
Definition: format.php:1155
get_filter_site_cond($table_technical_code, $table_alias=null, $use_strict_rights_if_in_admin=false, $specific_site_id=null, $exclude_public_items=false, $admin_force_multisite_if_allowed=false)
Retourne la condition SQL permettant de filtrer les données pour une table.
Definition: fonctions.php:4643
get_user_id_from_email($email)
Fonction de recherche d'id utilisateur par l'email.
Definition: user.php:1016
if(!defined('IN_PEEL')) display_prices_with_taxes_active()
display_prices_with_taxes_active()
Definition: fonctions.php:23
query($query, $die_if_error=false, $database_object=null, $silent_if_error=false, $security_sql_filter=true)
The query() function is meant to be called anywhere you want to make a query.
Definition: database.php:158
create_or_update_order(&$order_infos, &$articles_array)
Crée ou modifie une commande en base de données, ainsi que les produits commandés.
Definition: order.php:483
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
num_rows($query_result)
num_rows()
Definition: database.php:321
if(!defined('IN_PEEL')) send_email($to, $mail_subject= '', $mail_content= '', $template_technical_code=null, $template_tags=null, $format=null, $sender=null, $html_add_structure=true, $html_correct_conformity=false, $html_convert_url_to_links=true, $reply_to=null, $attached_files_infos_array=null, $lang=null, $additional_infos_array=array(), $attachment_not_sent_by_email=false)
Envoi d'un email à un utilisateur.
Definition: emails.php:38
get_table_field_names($table_name, $link_identifier=null, $silent_if_error=false)
get_table_field_names()
Definition: database.php:495
fetch_object($query_result)
fetch_object()
Definition: database.php:302
send_mail_order_admin($order_id)
send_mail_order_admin()
Definition: order.php:1023
accounting_insert_transaction($order_id, $technical_code, $data)
Crée une transaction d'encaissement.
Definition: order.php:113
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
call_module_hook($hook, $params, $mode= 'boolean')
Appelle la fonction correspondant au $hook pour chaque module installé La fonction doit s'appeler : [...
get_formatted_date($datetime_or_timestamp=null, $mode= 'short', $hour_minute=false)
Afficher une date formatée, en évitant les problèmes liés aux noms de mois sur les serveurs qui ne so...
Definition: format.php:440
get_payment_form($order_id, $forced_type=null, $send_admin_email=false, $amount_to_pay=0, $allow_autosend=true)
Renvoie le formulaire de paiement.
Definition: order.php:1534
is_delivery_address_necessary_for_delivery_type($selected_delivery_type_id=null)
is_delivery_address_necessary_for_delivery_type()
Definition: fonctions.php:1140
$GLOBALS['page_columns_count']
get_mysql_date_from_user_input($string, $use_current_hour_min_sec_if_missing=false)
Transforme une date formattée par get_formatted_date() en date MySQL Si la date est vide...
Definition: format.php:496
filtre_javascript($string, $addslashes=true, $allow_escape_single_quote=true, $allow_escape_double_quote=true, $skip_endline=true, $inside_html=true)
Formatte une chaine de caractère pour insertion dans du javascript.
Definition: format.php:237
email_commande($order_id)
email_commande()
Definition: order.php:970
get_payment_technical_code($id_or_code)
get_payment_technical_code()
Definition: order.php:1253
$currency_rate
Definition: rpc.php:35
get_site_wwwroot($site_id, $lang=null)
Renvoie l'URL d'un site donné
Definition: fonctions.php:4873
vn(&$var, $default=0)
Variable nulle if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:110
get_site_id_sql_set_value($site_ids)
Retourne la valeur SQL d'un champ INT ou SET suivant que ce soit un entier ou un tableau.
Definition: fonctions.php:4747
$req
Definition: ipn.php:30
MDP($chrs=8)
Fonction utilisée pour générer un mot aléatoire (sert par exemple pour le renommage des fichiers imag...
Definition: fonctions.php:49
get_order_infos_array($order_object)
get_order_infos_array()
Definition: order.php:1320
$id
Definition: articles.php:22
fprix($price, $display_currency=false, $currency_code_or_default=null, $convertion_needed_into_currency=true, $currency_rate=null, $display_iso_currency_code=false, $format=true, $force_format_separator=null, $add_rdfa_properties=false, $round_even_if_no_format=false)
fprix formatte le prix donné en le convertissant si nécessaire au préalable et en ajoutant éventuelle...
Definition: fonctions.php:242
get_payment_name($id_or_code)
get_payment_name()
Definition: order.php:1046
static substr($string, $start, $length=null)
Returns the portion of string specified by the start and length parameters.
Definition: String.php:112
$total_tva
static substr_count($string, $searched)
Returns the number of times the needle substring occurs in the haystack string.
Definition: String.php:194
check_if_module_active($module_name, $specific_file_name=null)
Renvoie si un module est présent et activé ou non - Peut être appelé avant ou après le chargement d'u...
template_tags_replace($text, $custom_template_tags=array(), $replace_only_custom_tags=false, $format=null, $lang=null, $avoid_load_urls=false)
Remplace les tags d'un texte au format [TAG] par les valeurs correspondantes.
Definition: format.php:599
update_order_payment_status($order_id, $status_or_is_payment_validated, $allow_update_paid_orders=true, $statut_livraison_new=null, $delivery_tracking=null, $no_stock_decrement_already_done=false, $payment_technical_code=null)
Met à jour le status de paiement et/ou de livraison d'une commande, et gère les stocks suivant le sta...
Definition: order.php:178
if(defined('IN_PEEL_ADMIN')||IN_INSTALLATION) $_SESSION['session_langue']
send_avis_expedition($commandeid, $delivery_tracking)
send_avis_expedition()

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:31:24 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.