PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/cashdesk/facturation_verif.php

https://github.com/asterix14/dolibarr
PHP | 165 lines | 108 code | 29 blank | 28 comment | 24 complexity | 2946353c6161a1e15bee1ef1615efd65 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-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 2 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. require('../main.inc.php');
  19. require_once(DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php');
  20. require_once(DOL_DOCUMENT_ROOT.'/cashdesk/class/Facturation.class.php');
  21. /** add Ditto */
  22. require_once(DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php');
  23. require_once(DOL_DOCUMENT_ROOT.'/product/class/product.class.php');
  24. /** end add Ditto */
  25. $obj_facturation = unserialize($_SESSION['serObjFacturation']);
  26. unset ($_SESSION['serObjFacturation']);
  27. switch ( $_GET['action'] )
  28. {
  29. default:
  30. if ( $_POST['hdnSource'] != 'NULL' )
  31. {
  32. $sql = "SELECT p.rowid, p.ref, p.price, p.tva_tx";
  33. if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  34. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  35. 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;
  36. // Recuperation des donnees en fonction de la source (liste deroulante ou champ texte) ...
  37. if ( $_POST['hdnSource'] == 'LISTE' )
  38. {
  39. $sql.= " WHERE p.rowid = ".$_POST['selProduit'];
  40. }
  41. else if ( $_POST['hdnSource'] == 'REF' )
  42. {
  43. $sql.= " WHERE p.ref = '".$_POST['txtRef']."'";
  44. }
  45. $result = $db->query($sql);
  46. if ($result)
  47. {
  48. // ... et enregistrement dans l'objet
  49. if ( $db->num_rows($result) )
  50. {
  51. $ret=array();
  52. $tab = $db->fetch_array($result);
  53. foreach ( $tab as $key => $value )
  54. {
  55. $ret[$key] = $value;
  56. }
  57. /** add Ditto for MultiPrix*/
  58. if ($conf->global->PRODUIT_MULTIPRICES)
  59. {
  60. $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
  61. $productid = $ret['rowid'];
  62. $societe = new Societe($db);
  63. $societe->fetch($thirdpartyid);
  64. $product = new Product($db);
  65. $product->fetch($productid);
  66. if(isset($product->multiprices[$societe->price_level]))
  67. {
  68. $ret['price'] = $product->multiprices[$societe->price_level];
  69. $ret['price_ttc'] = $product->multiprices_ttc[$societe->price_level];
  70. // $product->multiprices_min[$societe->price_level];
  71. // $product->multiprices_min_ttc[$societe->price_level];
  72. // $product->multiprices_base_type[$societe->price_level];
  73. $ret['tva_tx'] = $product->multiprices_tva_tx[$societe->price_level];
  74. }
  75. }
  76. /** end add Ditto */
  77. $obj_facturation->id($ret['rowid']);
  78. $obj_facturation->ref($ret['ref']);
  79. $obj_facturation->stock($ret['reel']);
  80. $obj_facturation->prix($ret['price']);
  81. $obj_facturation->tva($ret['tva_tx']);
  82. // Definition du filtre pour n'afficher que le produit concerne
  83. if ( $_POST['hdnSource'] == 'LISTE' )
  84. {
  85. $filtre = $ret['ref'];
  86. }
  87. else if ( $_POST['hdnSource'] == 'REF' )
  88. {
  89. $filtre = $_POST['txtRef'];
  90. }
  91. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$filtre;
  92. }
  93. else
  94. {
  95. $obj_facturation->raz();
  96. if ( $_POST['hdnSource'] == 'REF' )
  97. {
  98. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$_POST['txtRef'];
  99. }
  100. else
  101. {
  102. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  103. }
  104. }
  105. }
  106. else
  107. {
  108. dol_print_error($db);
  109. }
  110. }
  111. else
  112. {
  113. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  114. }
  115. break;
  116. case 'ajout_article': // We have clicked on button "Add product"
  117. //var_dump($obj_facturation);
  118. //exit;
  119. if (! empty($obj_facturation->id)) // A product has been selected and stored in session
  120. {
  121. $obj_facturation->qte($_POST['txtQte']);
  122. $obj_facturation->tva($_POST['selTva']);
  123. $obj_facturation->remise_percent($_POST['txtRemise']);
  124. $obj_facturation->ajoutArticle();
  125. }
  126. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  127. break;
  128. case 'suppr_article':
  129. $obj_facturation->supprArticle($_GET['suppr_id']);
  130. $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
  131. break;
  132. }
  133. $_SESSION['serObjFacturation'] = serialize($obj_facturation);
  134. header('Location: '.$redirection);
  135. exit;
  136. ?>