PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/cashdesk/facturation.php

https://github.com/asterix14/dolibarr
PHP | 163 lines | 112 code | 22 blank | 29 comment | 25 complexity | 3d5de22c59c4f00ccf635e16e9eb96bb MD5 | raw file
Possible License(s): LGPL-2.0
  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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/cashdesk/facturation.php
  21. * \ingroup cashdesk
  22. * \brief Include to show main page for cashdesk module
  23. */
  24. // Get list of articles (in warehouse '$conf_fkentrepot' if defined and stock module enabled)
  25. if ( $_GET['filtre'] ) {
  26. // Avec filtre
  27. $ret=array(); $i=0;
  28. $sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx, p.fk_product_type";
  29. if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  30. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  31. if ($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."'";
  32. $sql.= " WHERE p.tosell = 1";
  33. if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
  34. $sql.= " AND (p.ref LIKE '%".$_GET['filtre']."%' OR p.label LIKE '%".$_GET['filtre']."%' ";
  35. if ($conf->barcode->enabled) $sql.= " OR p.barcode LIKE '%".$_GET['filtre']."%')";
  36. else $sql.= ")";
  37. $sql.= " ORDER BY label";
  38. dol_syslog("facturation.php sql=".$sql);
  39. $resql=$db->query($sql);
  40. if ($resql)
  41. {
  42. while ( $tab = $db->fetch_array($resql) )
  43. {
  44. foreach ( $tab as $cle => $valeur )
  45. {
  46. $ret[$i][$cle] = $valeur;
  47. }
  48. $i++;
  49. }
  50. }
  51. else
  52. {
  53. dol_print_error($db);
  54. }
  55. $tab_designations=$ret;
  56. } else {
  57. // Sans filtre
  58. $ret=array();
  59. $i=0;
  60. $sql = "SELECT p.rowid, ref, label, tva_tx, p.fk_product_type";
  61. if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  62. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  63. if ($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."'";
  64. $sql.= " WHERE p.tosell = 1";
  65. if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
  66. $sql.= " ORDER BY p.label";
  67. dol_syslog($sql);
  68. $resql=$db->query($sql);
  69. if ($resql)
  70. {
  71. while ( $tab = $db->fetch_array($resql) )
  72. {
  73. foreach ( $tab as $cle => $valeur )
  74. {
  75. $ret[$i][$cle] = $valeur;
  76. }
  77. $i++;
  78. }
  79. }
  80. else
  81. {
  82. dol_print_error($db);
  83. }
  84. $tab_designations=$ret;
  85. }
  86. $nbr_enreg = count($tab_designations);
  87. if ( $nbr_enreg > 1 )
  88. {
  89. if ( $nbr_enreg > $conf_taille_listes )
  90. {
  91. $top_liste_produits = '----- '.$conf_taille_listes.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
  92. }
  93. else
  94. {
  95. $top_liste_produits = '----- '.$nbr_enreg.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
  96. }
  97. }
  98. else if ( $nbr_enreg == 1 )
  99. {
  100. $top_liste_produits = '----- 1 '.$langs->transnoentitiesnoconv("ProductFound"). ' -----';
  101. }
  102. else
  103. {
  104. $top_liste_produits = '----- '.$langs->transnoentitiesnoconv("NoProductFound"). ' -----';
  105. }
  106. // Recuperation des taux de tva
  107. global $mysoc;
  108. $ret=array();
  109. $i=0;
  110. $sql = "SELECT t.rowid, t.taux";
  111. $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
  112. $sql.= ", ".MAIN_DB_PREFIX."c_pays as p";
  113. $sql.= " WHERE t.fk_pays = p.rowid";
  114. $sql.= " AND t.active = 1";
  115. $sql.= " AND p.code = '".$mysoc->pays_code."'";
  116. //print $request;
  117. $res = $db->query($sql);
  118. if ($res)
  119. {
  120. while ( $tab = $db->fetch_array($res) )
  121. {
  122. foreach ( $tab as $cle => $valeur )
  123. {
  124. $ret[$i][$cle] = $valeur;
  125. }
  126. $i++;
  127. }
  128. }
  129. else
  130. {
  131. dol_print_error($db);
  132. }
  133. $tab_tva = $ret;
  134. // Reinitialisation du mode de paiement, en cas de retour aux achats apres validation
  135. $obj_facturation->mode_reglement('RESET');
  136. $obj_facturation->montant_encaisse('RESET');
  137. $obj_facturation->montant_rendu('RESET');
  138. $obj_facturation->paiement_le('RESET');
  139. // Affichage des templates
  140. require ('tpl/facturation1.tpl.php');
  141. ?>