facturation.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
  3. * Copyright (C) 2008-2011 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2013 Adolfo Segura <adolfo.segura@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/cashdesk/facturation.php
  23. * \ingroup cashdesk
  24. * \brief Include to show main page for cashdesk module
  25. */
  26. /*
  27. * View
  28. */
  29. $form=new Form($db);
  30. // Get list of articles (in warehouse '$conf_fkentrepot' if defined and stock module enabled)
  31. if ( GETPOST('filtre','alpha') ) {
  32. // Avec filtre
  33. $ret=array(); $i=0;
  34. $sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx, p.fk_product_type";
  35. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  36. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  37. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'";
  38. $sql.= " WHERE p.entity IN (".getEntity('product').")";
  39. $sql.= " AND p.tosell = 1";
  40. if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
  41. $sql.= " AND (";
  42. $sql.= "p.ref LIKE '%".$db->escape(GETPOST('filtre'))."%' OR p.label LIKE '%".$db->escape(GETPOST('filtre'))."%'";
  43. if (! empty($conf->barcode->enabled))
  44. {
  45. $filtre = GETPOST('filtre','alpha');
  46. //If the barcode looks like an EAN13 format and the last digit is included in it,
  47. //then whe look for the 12-digit too
  48. //As the twelve-digit string will also hit the 13-digit code, we only look for this one
  49. if (strlen($filtre) == 13) {
  50. $crit_12digit = substr($filtre, 0, 12);
  51. $sql .= " OR p.barcode LIKE '%".$db->escape($crit_12digit)."%'";
  52. } else {
  53. $sql.= " OR p.barcode LIKE '%".$db->escape($filtre)."%'";
  54. }
  55. }
  56. $sql.= ")";
  57. $sql.= " ORDER BY label";
  58. dol_syslog("facturation.php", LOG_DEBUG);
  59. $resql=$db->query($sql);
  60. if ($resql)
  61. {
  62. $nbr_enreg = $db->num_rows($resql);
  63. while ($i < $conf_taille_listes && $tab = $db->fetch_array($resql) )
  64. {
  65. foreach ( $tab as $cle => $valeur )
  66. {
  67. $ret[$i][$cle] = $valeur;
  68. }
  69. $i++;
  70. }
  71. $db->free($resql);
  72. }
  73. else
  74. {
  75. dol_print_error($db);
  76. }
  77. $tab_designations=$ret;
  78. } else {
  79. // Sans filtre
  80. $ret=array();
  81. $i=0;
  82. $sql = "SELECT p.rowid, ref, label, tva_tx, p.fk_product_type";
  83. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  84. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  85. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'";
  86. $sql.= " WHERE p.entity IN (".getEntity('product').")";
  87. $sql.= " AND p.tosell = 1";
  88. if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
  89. $sql.= " ORDER BY p.label";
  90. dol_syslog($sql);
  91. $resql=$db->query($sql);
  92. if ($resql)
  93. {
  94. $nbr_enreg = $db->num_rows($resql);
  95. while ($i < $conf_taille_listes && $tab = $db->fetch_array($resql))
  96. {
  97. foreach ( $tab as $cle => $valeur )
  98. {
  99. $ret[$i][$cle] = $valeur;
  100. }
  101. $i++;
  102. }
  103. $db->free($resql);
  104. }
  105. else
  106. {
  107. dol_print_error($db);
  108. }
  109. $tab_designations=$ret;
  110. }
  111. //$nbr_enreg = count($tab_designations);
  112. if ( $nbr_enreg > 1 )
  113. {
  114. if ( $nbr_enreg > $conf_taille_listes )
  115. {
  116. $top_liste_produits = '----- '.$conf_taille_listes.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
  117. }
  118. else
  119. {
  120. $top_liste_produits = '----- '.$nbr_enreg.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
  121. }
  122. }
  123. elseif ( $nbr_enreg == 1 )
  124. {
  125. $top_liste_produits = '----- 1 '.$langs->transnoentitiesnoconv("ProductFound"). ' -----';
  126. }
  127. else
  128. {
  129. $top_liste_produits = '----- '.$langs->transnoentitiesnoconv("NoProductFound"). ' -----';
  130. }
  131. // Recuperation des taux de tva
  132. global $mysoc;
  133. $ret=array();
  134. $i=0;
  135. // Reinitialisation du mode de paiement, en cas de retour aux achats apres validation
  136. $obj_facturation->getSetPaymentMode('RESET');
  137. $obj_facturation->montantEncaisse('RESET');
  138. $obj_facturation->montantRendu('RESET');
  139. $obj_facturation->paiementLe('RESET');
  140. // Affichage des templates
  141. require 'tpl/facturation1.tpl.php';