Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.81 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $titulo = "Facturacion";
  5.  
  6. include("../conexion.php");
  7.  
  8. ?>
  9.  
  10.  
  11. <link href="../style.css" rel="stylesheet" type="text/css" />
  12. <div id="derecha" class="fondo">
  13. <h1 class="Estilo1" align="center">Facturacion -- Ferreteria el constructor</h1>
  14.  
  15. <div class='text-border'>
  16. <?php
  17.  
  18. if(isset($_GET['id'])){
  19. $id = $_GET['id'];
  20. }
  21. else
  22. $id = 1;
  23.  
  24. if (isset($_GET['action']))
  25. $action = $_GET['action'];
  26. else
  27. $action = "empty";
  28.  
  29.  
  30. switch($action){
  31.  
  32. case "add":
  33. if(isset($_SESSION['fact'][$id]))
  34. $_SESSION['fact'][$id]++;
  35. else
  36. $_SESSION['fact'][$id]=1;
  37. break;
  38.  
  39. case "remove":
  40. if(isset($_SESSION['fact'][$id]))
  41. {
  42. $_SESSION['fact'][$id]--;
  43. if($_SESSION['fact'][$id]==0)
  44. unset($_SESSION['fact'][$id]);
  45. }
  46.  
  47. break;
  48. case "removeProd":
  49. if(isset($_SESSION['fact'][$id])){
  50. unset($_SESSION['fact'][$id]);
  51. }
  52. break;
  53.  
  54. case "mostrar":
  55. if(isset($_SESSION['fact'][$id])){
  56. continue;
  57. }
  58. break;
  59.  
  60. case "empty":
  61. unset($_SESSION['fact']);
  62.  
  63. break;
  64.  
  65.  
  66. }
  67.  
  68. /*MOSTRAR Factura*/
  69. /*echo "<pre>";
  70. print_r($_SESSION);
  71. echo "</pre>";
  72.  
  73. echo "CANTIDAD: " . $_SESSION['fact'][$id] . "<br>";
  74. echo "ID : " . $id . "<br>";
  75. */
  76.  
  77. if(isset($_SESSION['fact'])){
  78. echo "<form action='comprar.php' method='post'><table border=0 width='700' align='center'>";
  79. $totalcoste = 0;
  80.  
  81. //Inicializamos el contador de productos seleccionados.
  82. $xTotal = 0;
  83.  
  84. echo "<tr>";
  85. echo "<td>Producto</td>";
  86. echo "<td>Precio</td>";
  87. echo "<td align='center'>Cantidad</td>";
  88. echo "<td align='center'>Acción</td>";
  89. echo "<td colspan=2 align=right>Total</td>";
  90. echo "<td ></td>";
  91. echo "</tr>";
  92. echo "<tr><td colspan=5><hr></td></tr>";
  93.  
  94.  
  95. foreach($_SESSION['fact'] as $id => $x){
  96. $resultado = mysql_query("SELECT codigo, nombre, preciov FROM productos WHERE codigo=$id");
  97. $rst_clientes=mysql_query("SELECT * FROM clientes ".$filtro.";",$conexion);
  98.  
  99. $codcli=$rst_clientes['id'];
  100. $nomcli=$rst_clientes['nombre'];
  101. $mifila = mysql_fetch_array($resultado);
  102. $id = $mifila['codigo'];
  103. $preciov = $mifila['preciov'];
  104. $producto = $mifila['nombre'];
  105. //acortamos el nombre del producto a 40 caracteres
  106. $producto = substr($producto,0,40);
  107. $precio = $mifila['preciov'];
  108. //Coste por artículo según la cantidad elegida
  109. $coste = $precio * $x;
  110. //Coste total de los productos
  111. $totalcoste = $totalcoste + $coste;
  112. $totalcoste1 = $totalcoste/100*15;
  113. $descuento = $totalcoste/100*10;
  114. $saldo=$totalcoste-descuento+$totalcoste1;
  115.  
  116. //Contador del total de productos añadidos a la factura
  117. $xTotal = $xTotal + $x;
  118.  
  119.  
  120. echo "<tr>";
  121. echo "<td align='left'> $producto </td>";
  122. echo "<td align='left'> $preciov </td>";
  123. echo "<td align='center'>$x</td>";
  124. echo "<td align='center'>";
  125. echo "<a href='fact.php?id=". $id ."&action=add'><img src='img/add_fact.png' width='50' height='50' style='padding:0 0px 0 5px;' alt='Aumentar cantidad' /></a>";
  126. //Controlamos el display para cuando se vaya a eliminar el producto de la factura o bien
  127. //se vaya a reducir la cantidad.
  128. //if ($x > 1)
  129. echo "<a href='fact.php?id=". $id ."&action=remove' ><img src='img/remove_fact.png' width='50' height='50' alt='Reducir cantidad' /></a>";
  130. //else
  131. echo "<a href='fact.php?id=". $id ."&action=removeProd'><img src='img/close_fact.png' width='50' height='50' alt='Reducir cantidad' /></a></td>";
  132.  
  133. echo "<td align='left'> = </td>";
  134. echo "<td align='right' style='margin-left:10px'>$coste L";
  135. echo "<td ></td>";
  136. echo "</tr>";
  137. }
  138.  
  139. echo "<tr><td colspan='5'><hr></td></tr>";
  140. echo "<tr>";
  141. function generarcodigo($longitud) {
  142. $key = '';
  143. $pattern = '1234567890';
  144. $max = strlen($pattern)-1;
  145. for($i=0;$i < $longitud;$i++) $key .= $pattern{mt_rand(0999,$max)};
  146. return $key;
  147. }?>
  148. <?php { ?><td>Codigo de Factura: <input type='text' name='codigo' placeholder='Codigo de factura' Value='FACT-<?php echo generarcodigo(5);?>' readonly='readonly' required></td>
  149.  
  150.  
  151.  
  152.  
  153. <?php }?><td>Nombre del cliente: <select name="clientes">
  154. <?php
  155. while($fila1=mysql_fetch_array($rst_clientes)){
  156. echo "<option value='".$fila1["nombre"]."'>".$fila1["nombre"]."</option>";
  157. }
  158. mysql_close("$conexion");
  159. ?>
  160. </select></td>
  161.  
  162.  
  163. <td>Direccion del cliente: <input type='text' name='direccion' placeholder='Direccion del cliente' required></td>
  164. <?php
  165. //INPUTS OCULTOS CON VALORES DE FACTURA
  166. echo "<input style='display:none;' value='{$preciov}' name='preciov'/>";
  167. echo "<input style='display:none;' value='{$coste}' name='coste'/>";
  168. echo "<input style='display:none;' value='{$totalcoste1}' name='totalcoste1'/>";
  169. echo "<input style='display:none;' value='{$totalcoste}' name='totalcoste'/>";
  170. echo "<input style='display:none;' value='{$descuento}' name='descuento'/>";
  171. echo "<input style='display:none;' value='{$saldo}' name='saldo'/>";
  172. echo "<input style='display:none;' value='{$x}' name='x'/>";
  173. echo "<input style='display:none;' value='{$producto}' name='producto'/>";
  174.  
  175. echo "<td align='right'>Subtotal = </td>";
  176.  
  177. echo "<td align='right' colspan='3'><b>$totalcoste L</b></td>";
  178. echo "<tr></tr>";
  179. echo "<td></td>";
  180. echo "<td ></td>";
  181.  
  182. echo "<td ></td>";
  183. echo "<td></td>";
  184. echo "<tr></tr>";
  185. echo "<td>RTN <input name='rtn' type='number' placeholder='Ingrese su RTN' required></td>";
  186. echo "<td></td>";
  187. echo "<td></td>";
  188. echo "<td align='right' colspan='2'>Impuesto 15% = </td>";
  189. echo "<td align='right' colspan='3'><b><br>$totalcoste1 L </b> </td>";
  190. echo "</tr>";
  191. echo "<tr></tr>";
  192. echo "<td></td>";
  193.  
  194. echo "<td align='right' colspan='3'>Descuento 10% =</td>";
  195. echo "<td align='right' colspan='2'><b><br> $descuento L </b> </td>";
  196.  
  197. //BOTON COMPRAR
  198. echo "<tr>";
  199. echo "</tr>";
  200. echo "<tr></tr>";
  201. echo "<td></td>";
  202. echo "<td></td>";
  203. echo "<td></td>";
  204. echo "<td align='right'>Total =</td>";
  205. echo "<td align='right' colspan='3'><b><br>$saldo L </b> </td>";
  206. echo "</tr>";
  207. echo "<td align='right'><td align='right'><td align='right'><td align='right'><td align='right'>
  208. <td>
  209. <a href='comprar.php'><input type='submit' value='Finalizar' /></a>
  210. </td>";
  211. echo "</tr>";
  212.  
  213. echo "</table></form>";
  214.  
  215.  
  216. }
  217. else
  218. echo "No hay productos en la factura";
  219.  
  220. //Campos que nos serviran para informar la cesta de lo que llevamos comprados y que se mostrará en
  221. //la página PRODUCTOS.
  222. $_SESSION["totalcoste"] = $totalcoste;
  223. $_SESSION["cantidadTotal"] = $xTotal;
  224. echo "<p><a href='productos.php' ><img src='../logos/volver.png' align='middle'></a>";
  225. echo "<a href='../index.php' ><img src='../logos/inicio.png' width='130' height='55' align='middle'></a></p>";
  226.  
  227. ?>
  228. </div> <!-- Cierro text-border -->
  229. </div>
  230. <p class="fondo">
  231. <!-- Cierro derecha -->
  232.  
  233. <span class="fondo">
  234. <?php
  235. include("estructura/pie.php");
  236. include("estructura/cerrar_etiquetas.php");
  237. ?>
  238. </span></p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement