PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/cashdesk/facturation_verif.php

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