PageRenderTime 62ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/cashdesk/facturation.php

https://bitbucket.org/speedealing/speedealing
PHP | 165 lines | 114 code | 22 blank | 29 comment | 25 complexity | 0d86f23f709bb4b6edf800bd899fd596 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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 3 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 (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  30. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  31. 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."'";
  32. $sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
  33. $sql.= " AND p.tosell = 1";
  34. if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
  35. $sql.= " AND (p.ref LIKE '%".$_GET['filtre']."%' OR p.label LIKE '%".$_GET['filtre']."%' ";
  36. if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '%".$_GET['filtre']."%')";
  37. else $sql.= ")";
  38. $sql.= " ORDER BY label";
  39. dol_syslog("facturation.php sql=".$sql);
  40. $resql=$db->query($sql);
  41. if ($resql)
  42. {
  43. while ( $tab = $db->fetch_array($resql) )
  44. {
  45. foreach ( $tab as $cle => $valeur )
  46. {
  47. $ret[$i][$cle] = $valeur;
  48. }
  49. $i++;
  50. }
  51. }
  52. else
  53. {
  54. dol_print_error($db);
  55. }
  56. $tab_designations=$ret;
  57. } else {
  58. // Sans filtre
  59. $ret=array();
  60. $i=0;
  61. $sql = "SELECT p.rowid, ref, label, tva_tx, p.fk_product_type";
  62. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  63. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  64. 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."'";
  65. $sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
  66. $sql.= " AND p.tosell = 1";
  67. if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
  68. $sql.= " ORDER BY p.label";
  69. dol_syslog($sql);
  70. $resql=$db->query($sql);
  71. if ($resql)
  72. {
  73. while ( $tab = $db->fetch_array($resql) )
  74. {
  75. foreach ( $tab as $cle => $valeur )
  76. {
  77. $ret[$i][$cle] = $valeur;
  78. }
  79. $i++;
  80. }
  81. }
  82. else
  83. {
  84. dol_print_error($db);
  85. }
  86. $tab_designations=$ret;
  87. }
  88. $nbr_enreg = count($tab_designations);
  89. if ( $nbr_enreg > 1 )
  90. {
  91. if ( $nbr_enreg > $conf_taille_listes )
  92. {
  93. $top_liste_produits = '----- '.$conf_taille_listes.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
  94. }
  95. else
  96. {
  97. $top_liste_produits = '----- '.$nbr_enreg.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
  98. }
  99. }
  100. else if ( $nbr_enreg == 1 )
  101. {
  102. $top_liste_produits = '----- 1 '.$langs->transnoentitiesnoconv("ProductFound"). ' -----';
  103. }
  104. else
  105. {
  106. $top_liste_produits = '----- '.$langs->transnoentitiesnoconv("NoProductFound"). ' -----';
  107. }
  108. // Recuperation des taux de tva
  109. global $mysoc;
  110. $ret=array();
  111. $i=0;
  112. $sql = "SELECT t.rowid, t.taux";
  113. $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
  114. $sql.= ", ".MAIN_DB_PREFIX."c_pays as p";
  115. $sql.= " WHERE t.fk_pays = p.rowid";
  116. $sql.= " AND t.active = 1";
  117. $sql.= " AND p.code = '".$mysoc->country_code."'";
  118. //print $request;
  119. $res = $db->query($sql);
  120. if ($res)
  121. {
  122. while ( $tab = $db->fetch_array($res) )
  123. {
  124. foreach ( $tab as $cle => $valeur )
  125. {
  126. $ret[$i][$cle] = $valeur;
  127. }
  128. $i++;
  129. }
  130. }
  131. else
  132. {
  133. dol_print_error($db);
  134. }
  135. $tab_tva = $ret;
  136. // Reinitialisation du mode de paiement, en cas de retour aux achats apres validation
  137. $obj_facturation->getSetPaymentMode('RESET');
  138. $obj_facturation->montantEncaisse('RESET');
  139. $obj_facturation->montantRendu('RESET');
  140. $obj_facturation->paiementLe('RESET');
  141. // Affichage des templates
  142. require ('tpl/facturation1.tpl.php');
  143. ?>