PageRenderTime 424ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/realizar_venta.php

https://code.google.com/p/zapatillas-4-dsw1/
PHP | 167 lines | 150 code | 14 blank | 3 comment | 11 complexity | cc097095e2a75359254aa8cca0533288 MD5 | raw file
  1. <?php
  2. session_start ();
  3. require_once './php_lib/conexion.php';
  4. require_once('./php_lib/funciones.php');
  5. $rut = "11987646";
  6. if(isset($_POST['prod'])){
  7. $item = "SELECT prod_id, col_descripcion, talla_num, mod_descripcion, prod_valor
  8. FROM Producto,Color,Talla,Modelo
  9. WHERE Producto.col_id = Color.col_id
  10. AND Producto.col_id = Color.col_id
  11. AND Producto.talla_id = Talla.talla_id
  12. AND Producto.mod_id = Modelo.mod_id
  13. AND prod_id=".$_POST['prod'];
  14. $qi = mysql_query($item, $db_zapatos)or die(mysql_error());
  15. $lista = mysql_fetch_assoc($qi);
  16. $lista_e = null;
  17. if(isset($_POST['lista'])){
  18. $lista_e= unserialize(stripslashes($_POST['lista']));
  19. }
  20. if(isset($_GET['d'])){
  21. $lista_e= unserialize(stripslashes($_GET['d']));
  22. echo $lista_e;
  23. }
  24. if(mysql_num_rows($qi)!=0){
  25. $cant = "SELECT `pros_stock` FROM `Pro_Sec`
  26. WHERE `prod_id`=".$_POST['prod']."
  27. AND `sec_id` IN (SELECT `sec_id` FROM `Sector`
  28. WHERE `bod_id` IN (SELECT `bod_id` FROM Bodega
  29. WHERE suc_id = (SELECT suc_id FROM Personal
  30. WHERE per_rut = ".$rut.")))";
  31. $qc = mysql_query($cant, $db_zapatos)or die(mysql_error());
  32. if(mysql_num_rows($qc)!=0){
  33. $qc_r = mysql_fetch_assoc($qc);
  34. if($_POST['cant2']<=$qc_r['pros_stock'] && $_POST['cant2']!=0){
  35. $lista['cant'] = $_POST['cant2'];
  36. $lista['subt'] = $lista['prod_valor']*$lista['cant'];
  37. $lista_e[]=$lista;
  38. }
  39. else{
  40. echo "<script language='JavaScript'>
  41. alert('Cantidad erronea')
  42. </script>";
  43. }
  44. }
  45. else{
  46. echo "<script language='JavaScript'>
  47. alert('Producto no registrado en la sucursal')
  48. </script>";
  49. }
  50. }
  51. else{
  52. echo "<script language='JavaScript'>
  53. alert('No existe el Producto')
  54. </script>";
  55. }
  56. }
  57. ?>
  58. <link href="css/estilos.css" rel="stylesheet" type="text/css" />
  59. <script src="http://code.jquery.com/jquery-latest.js"></script>
  60. <h3><em> ID del producto </em>
  61. </h3>
  62. <form id="form1" name="form1" method="post" action="">
  63. <p>
  64. <label for="prod"></label>
  65. <input type="text" name="prod" id="prod" />
  66. <input type="button" name="button1" id="button1" value="Buscar"/>
  67. <label for="cant2">Cantidad</label>
  68. <input name="cant2" type="text" id="cant2" value="1"/>
  69. <input type="hidden" name="lista" value='<?php
  70. if(isset($lista_e)){
  71. echo serialize($lista_e);
  72. }
  73. ?>' />
  74. </p>
  75. </form>
  76. <p>
  77. <form id="form2" name="form2" method="post" action="">
  78. <table width="500" border="1" cellpadding="1" id="n" class="db_listado">
  79. <tr>
  80. <th width="68">Producto</th>
  81. <th width="44">Color</th>
  82. <th width="47">Talla</th>
  83. <th width="55">Modelo</th>
  84. <th width="57">Valor</th>
  85. <th width="66">Cantidad</th>
  86. <th width="71">Subtotal</th>
  87. </tr>
  88. <?php
  89. if(isset($lista_e) && $lista_e!=null){
  90. $suma =0;
  91. $num=0;
  92. foreach($lista_e as $p){ ?>
  93. <tr>
  94. <td><?php echo $p['prod_id']; ?></td>
  95. <td><?php echo $p['col_descripcion']; ?></td>
  96. <td><?php echo $p['talla_num']; ?></td>
  97. <td><?php echo $p['mod_descripcion']; ?></td>
  98. <td><?php echo $p['prod_valor']; ?></td>
  99. <td><?php echo $p['cant'];?></td>
  100. <td id="subt"><?php echo $p['subt'];
  101. $suma = $suma + $p['subt'];?></td>
  102. <!-- <td><a href="#" class="ico_del" title="Eliminar" </a></td>-->
  103. </tr>
  104. <?php $num++;}
  105. }?>
  106. </table>
  107. <p>
  108. <input type="hidden" name="lista2" value='<?php
  109. if(isset($lista_e)){
  110. echo serialize($lista_e);
  111. }
  112. ?>' />
  113. <input type="hidden" name="rut" value='<?php
  114. echo $rut;
  115. ?>' />
  116. <table width="125" border="1" cellpadding="10" class="db_listado">
  117. <tr>
  118. <td width="45">Total $</td>
  119. <td width="34" id="suma"><?php if(isset($suma))
  120. echo $suma;?></td>
  121. </tr>
  122. </table>
  123. <p>
  124. <input type="button" name="acep" id="acep" value="Realizar Venta"/>
  125. </form>
  126. <script language="javascript">
  127. $('#button1').click(function() {
  128. if($('#prod').val()==""){
  129. alert("Ingrese id del Producto");
  130. }
  131. else{
  132. $.ajax({
  133. type: 'POST',
  134. url: 'realizar_venta.php',
  135. data: $('#form1').serialize(),
  136. // Mostramos un mensaje con la respuesta de PHP
  137. success: function(data) {
  138. $('#mainDiv').html(data);
  139. }})
  140. }
  141. });
  142. $('#acep').click(function() {
  143. // Enviamos el formulario usando AJAX
  144. $.ajax({
  145. type: 'POST',
  146. url: 'venta.php',
  147. data: $('#form2').serialize(),
  148. // Mostramos un mensaje con la respuesta de PHP
  149. success: function(data) {
  150. $('#mainDiv').html(data);
  151. }})
  152. });
  153. </script>