facturation_verif.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
  3. * Copyright (C) 2008-2010 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/cashdesk/facturation_verif.php
  20. * \ingroup cashdesk
  21. * \brief facturation_verif.php
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php';
  25. require_once DOL_DOCUMENT_ROOT.'/cashdesk/class/Facturation.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. $obj_facturation = unserialize($_SESSION['serObjFacturation']);
  29. unset ($_SESSION['serObjFacturation']);
  30. switch ( $_GET['action'] )
  31. {
  32. default:
  33. if ( $_POST['hdnSource'] != 'NULL' )
  34. {
  35. $sql = "SELECT p.rowid, p.ref, p.price, p.tva_tx";
  36. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  37. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  38. 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;
  39. $sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
  40. // Recuperation des donnees en fonction de la source (liste deroulante ou champ texte) ...
  41. if ( $_POST['hdnSource'] == 'LISTE' )
  42. {
  43. $sql.= " AND p.rowid = ".$_POST['selProduit'];
  44. }
  45. else if ( $_POST['hdnSource'] == 'REF' )
  46. {
  47. $sql.= " AND p.ref = '".$_POST['txtRef']."'";
  48. }
  49. $result = $db->query($sql);
  50. if ($result)
  51. {
  52. // ... et enregistrement dans l'objet
  53. if ( $db->num_rows($result) )
  54. {
  55. $ret=array();
  56. $tab = $db->fetch_array($result);
  57. foreach ( $tab as $key => $value )
  58. {
  59. $ret[$key] = $value;
  60. }
  61. /** add Ditto for MultiPrix*/
  62. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  63. {
  64. $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
  65. $productid = $ret['rowid'];
  66. $societe = new Societe($db);
  67. $societe->fetch($thirdpartyid);
  68. $product = new Product($db);
  69. $product->fetch($productid);
  70. if(isset($product->multiprices[$societe->price_level]))
  71. {
  72. $ret['price'] = $product->multiprices[$societe->price_level];
  73. $ret['price_ttc'] = $product->multiprices_ttc[$societe->price_level];
  74. // $product->multiprices_min[$societe->price_level];
  75. // $product->multiprices_min_ttc[$societe->price_level];
  76. // $product->multiprices_base_type[$societe->price_level];
  77. $ret['tva_tx'] = $product->multiprices_tva_tx[$societe->price_level];
  78. }
  79. }
  80. /** end add Ditto */
  81. $obj_facturation->id($ret['rowid']);
  82. $obj_facturation->ref($ret['ref']);
  83. $obj_facturation->stock($ret['reel']);
  84. $obj_facturation->prix($ret['price']);
  85. $obj_facturation->tva($ret['tva_tx']);
  86. // Definition du filtre pour n'afficher que le produit concerne
  87. if ( $_POST['hdnSource'] == 'LISTE' )
  88. {
  89. $filtre = $ret['ref'];
  90. }
  91. else if ( $_POST['hdnSource'] == 'REF' )
  92. {
  93. $filtre = $_POST['txtRef'];
  94. }
  95. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$filtre;
  96. }
  97. else
  98. {
  99. $obj_facturation->raz();
  100. if ( $_POST['hdnSource'] == 'REF' )
  101. {
  102. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$_POST['txtRef'];
  103. }
  104. else
  105. {
  106. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  107. }
  108. }
  109. }
  110. else
  111. {
  112. dol_print_error($db);
  113. }
  114. }
  115. else
  116. {
  117. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  118. }
  119. break;
  120. case 'ajout_article': // We have clicked on button "Add product"
  121. //var_dump($obj_facturation);
  122. //exit;
  123. if (! empty($obj_facturation->id)) // A product has been selected and stored in session
  124. {
  125. $obj_facturation->qte($_POST['txtQte']);
  126. $obj_facturation->tva($_POST['selTva']);
  127. $obj_facturation->remisePercent($_POST['txtRemise']);
  128. $obj_facturation->ajoutArticle();
  129. }
  130. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  131. break;
  132. case 'suppr_article':
  133. $obj_facturation->supprArticle($_GET['suppr_id']);
  134. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  135. break;
  136. }
  137. $_SESSION['serObjFacturation'] = serialize($obj_facturation);
  138. header('Location: '.$redirection);
  139. exit;