/php-ARCHIVOS/exportar_informe_caja_rentabilidad.php

https://github.com/cabenitez/factuweb · PHP · 212 lines · 148 code · 39 blank · 25 comment · 2 complexity · 5d33a4c62c7e7f403f3be7f0915fc2ed MD5 · raw file

  1. <?
  2. //---------------------- Titulo del listado-------------------------------------------------//
  3. $ano = substr($fecha_desde,0,4);
  4. $mes = substr($fecha_desde,4,2);
  5. $dia = substr($fecha_desde,-2);
  6. $fecha_desde_titulo = "$dia/$mes/$ano"; // maqueta la fecha para imprimir
  7. $ano = substr($fecha_hasta,0,4);
  8. $mes = substr($fecha_hasta,4,2);
  9. $dia = substr($fecha_hasta,-2);
  10. $fecha_hasta_titulo = "$dia/$mes/$ano"; // maqueta la fecha para imprimir
  11. $titulo = "INFORME CAJA / RENTABILIDAD - DESDE: ".$fecha_desde_titulo." HASTA ".$fecha_hasta_titulo;
  12. //---------------------- INCLUYE CONEXION A BD -----------------------------------------------//
  13. include("conexion.php");
  14. //---------------------- INCLUYE CONFIGURACION DE PDF --------------------------------------//
  15. include("conf_listados.php");
  16. //----------------------------------- PDF --------------------------------------------------------------------------------------------//
  17. //---------------------- creo los titulos de las columnas-----------------------------------//
  18. $pdf->SetFont('Arial','',8);
  19. $pdf->Cell(6,8,'CONCEPTO');
  20. $pdf->SetX(110);
  21. $pdf->Cell(10,8,'TOTAL SIN IMP.');
  22. $pdf->SetX(145);
  23. $pdf->Cell(10,8,'IVA');
  24. $pdf->SetX(163);
  25. $pdf->Cell(10,8,'OTROS IMP.');
  26. $pdf->SetX(193);
  27. $pdf->Cell(10,8,'TOTAL');
  28. //---------------------- creo la linea -----------------------------------------------------//
  29. $pdf->Line(7,31,205,31); // linea
  30. $pdf->Ln(7); //Salto de línea
  31. //---------------------------------------------------------------------------------------------//
  32. //--------------------------------------CAJA INICIAL-------------------------------------------//
  33. //---------------------------------------------------------------------------------------------//
  34. $consulta ="SELECT fecha, SUM(importe) FROM caja_inicial where fecha >= $fecha_desde and fecha <= $fecha_hasta GROUP BY fecha ORDER BY fecha";
  35. $result = mysql_query($consulta); // hace la consulta
  36. $registro = mysql_fetch_row($result); // toma el registro
  37. $filas = mysql_num_rows ($result); //indica la cantidad de resultados
  38. $pdf->SetFont('Arial','',7);
  39. if($filas > 0){
  40. do{ // obtengo los resultados
  41. $fecha_caja=$registro[0];
  42. $fecha_caja_ano=substr($fecha_caja,0,4);
  43. $fecha_caja_mes=substr($fecha_caja,4,2);
  44. $fecha_caja_dia=substr($fecha_caja,-2);
  45. $fecha_caja = "$fecha_caja_dia/$fecha_caja_mes/$fecha_caja_dia";
  46. $importe = number_format($registro[1],2,'.','');
  47. $pdf->Cell(1,3,'CAJA INICIAL ('.$fecha_caja.')' ,0,0);
  48. $pdf->SetX(-7);
  49. $pdf->Cell(1,3,$importe,0,1,'R');
  50. $total_caja_inicial = $total_caja_inicial + $importe;
  51. }while($registro = mysql_fetch_row($result)); // obtengo los resultados
  52. }
  53. //---------------------------------------------------------------------------------------------//
  54. //--------------------------------------VENTAS-------------------------------------------------//
  55. //---------------------------------------------------------------------------------------------//
  56. // Obtiene el detalle de todos los comprobantes Factura Vta Cliente
  57. $consulta =" select SUM(round(total_sin_impuesto,2)), SUM(round(iva,2)), SUM(round(otros_impuestos,2)), SUM(round(total_general,2))
  58. FROM(
  59. select
  60. $calculo_importe_no_cliente
  61. (factura_vta_no_cliente.num_talonario)talonario
  62. $from_no_cliente
  63. where fecha >= $fecha_desde and fecha <= $fecha_hasta and observacion <> 'ANULADO' and observacion <> 'N/C'
  64. GROUP BY factura_vta_no_cliente_detalle.iva
  65. UNION ALL
  66. select
  67. $calculo_importe_cliente
  68. (factura_vta.num_talonario)as talonario
  69. $from_cliente
  70. where fecha >= $fecha_desde and fecha <= $fecha_hasta and observacion <> 'ANULADO' and observacion <> 'N/C'
  71. GROUP BY factura_vta_detalle.iva
  72. ) AS carga_caja";
  73. $result = mysql_query($consulta); // hace la consulta
  74. $registro = mysql_fetch_row($result); // toma el registro
  75. $pdf->SetFont('Arial','',7);
  76. do{ // obtengo los resultados
  77. $total_sin_imp=number_format($registro[0],2,'.','');
  78. $total_iva=number_format($registro[1],2,'.','');
  79. $total_otros_imp=number_format($registro[2],2,'.','');
  80. $total_factura=number_format($registro[3],2,'.','');
  81. $pdf->Cell(1,3,'VENTAS',0,0);
  82. $pdf->SetX(-80);
  83. $pdf->Cell(1,3,$total_sin_imp,0,0,'R');
  84. $pdf->SetX(-58);
  85. $pdf->Cell(1,3,$total_iva,0,0,'R');
  86. $pdf->SetX(-35);
  87. $pdf->Cell(1,3,$total_otros_imp,0,0,'R');
  88. $pdf->SetX(-7);
  89. $pdf->Cell(1,3,$total_factura,0,1,'R');
  90. $total_venta_sin_imp= $total_venta_sin_imp + $total_sin_imp;
  91. $total_venta_iva = $total_venta_iva + $total_iva;
  92. $total_venta_otros_imp= $total_venta_otros_imp + $total_otros_imp;
  93. $total_venta_factura = $total_venta_factura + $total_factura;
  94. }while($registro = mysql_fetch_array($result)); //end while
  95. //---------------------------------------------------------------------------------------------//
  96. //--------------------------------------COMPRAS------------------------------------------------//
  97. //---------------------------------------------------------------------------------------------//
  98. // Obtiene el detalle de todos los comprobantes Factura Vta Cliente
  99. $consulta ="select SUM(round(subtotal,2)), SUM(round(iva_monto,2)), SUM(round($factura_compra_otros_impuestos,2)), SUM(round(total,2))
  100. from factura_compra
  101. where fecha_fact >= $fecha_desde and fecha_fact <= $fecha_hasta";
  102. $result = mysql_query($consulta); // hace la consulta
  103. $registro = mysql_fetch_row($result); // toma el registro
  104. $pdf->SetFont('Arial','',7);
  105. do{ // obtengo los resultados
  106. $total_sin_imp= number_format($registro[0],2,'.','');
  107. $total_iva=number_format($registro[1],2,'.','');
  108. $total_otros_imp=number_format($registro[2],2,'.','');
  109. $total_factura=number_format($registro[3],2,'.','');
  110. $pdf->Cell(1,3,'COMPRAS',0,0);
  111. $pdf->SetX(-80);
  112. $pdf->Cell(1,3,$total_sin_imp,0,0,'R');
  113. $pdf->SetX(-58);
  114. $pdf->Cell(1,3,$total_iva,0,0,'R');
  115. $pdf->SetX(-35);
  116. $pdf->Cell(1,3,$total_otros_imp,0,0,'R');
  117. $pdf->SetX(-7);
  118. $pdf->Cell(1,3,$total_factura,0,1,'R');
  119. $total_compra_sin_imp = $total_compra_sin_imp + $total_sin_imp;
  120. $total_compra_iva = $total_compra_iva + $total_iva;
  121. $total_compra_otros_imp= $total_compra_otros_imp + $total_otros_imp;
  122. $total_compra_factura = $total_compra_factura + $total_factura;
  123. }while($registro = mysql_fetch_array($result)); //end while
  124. //---------------------------------------------------------------------------------------------//
  125. //--------------------------------------GASTOS-------------------------------------------------//
  126. //---------------------------------------------------------------------------------------------//
  127. // Obtiene el detalle de todos los comprobantes Factura Vta Cliente
  128. $consulta ="SELECT SUM(round(importe,2)), SUM(round(iva,2)), SUM(round(otros_impuestos,2)), SUM(round(total,2)) FROM gastos where fecha >= $fecha_desde and fecha <= $fecha_hasta";
  129. $result = mysql_query($consulta); // hace la consulta
  130. $registro = mysql_fetch_row($result); // toma el registro
  131. $pdf->SetFont('Arial','',7);
  132. do{ // obtengo los resultados
  133. $importe=number_format($registro[0],2,'.','');
  134. $iva=number_format($registro[1],2,'.','');
  135. $otros_imp=number_format($registro[2],2,'.','');
  136. $total=number_format($registro[3],2,'.','');
  137. $pdf->Cell(1,3,'GASTOS',0,0);
  138. $pdf->SetX(-80);
  139. $pdf->Cell(1,3,$importe,0,0,'R');
  140. $pdf->SetX(-58);
  141. $pdf->Cell(1,3,$iva,0,0,'R');
  142. $pdf->SetX(-35);
  143. $pdf->Cell(1,3,$otros_imp,0,0,'R');
  144. $pdf->SetX(-7);
  145. $pdf->Cell(1,3,$total,0,1,'R');
  146. $total_gasto_importe = $total_gasto_importe + $importe;
  147. $total_gasto_iva = $total_gasto_iva + $iva;
  148. $total_gasto_otros_imp= $total_gasto_otros_imp + $otros_imp;
  149. $total_gasto_total = $total_gasto_total + $total;
  150. }while($registro = mysql_fetch_array($result)); //end while
  151. //---------------------- creo el resumen de total de filas------------------------------//
  152. $pdf->SetFont('Arial','',10);
  153. $pdf->Cell(0,0,"_____________________________________________________________________________________________________",0,0,'L');
  154. $pdf->Ln(10); //Salto de línea
  155. $pdf->SetFont('Arial','',8);
  156. //---------------------------------------------------------------------------------------------//
  157. //--------------------------------------CAJA / RENTABILIDAD------------------------------------//
  158. //---------------------------------------------------------------------------------------------//
  159. $caja = number_format($total_caja_inicial + $total_venta_factura - $total_compra_factura - $total_gasto_total,2,'.','');
  160. $rentabilidad = number_format($total_caja_inicial + $total_venta_sin_imp - $total_compra_sin_imp - $total_gasto_importe,2,'.','');
  161. $pdf->SetX(6);
  162. $pdf->Cell(0,3,'CAJA',0,0);
  163. $pdf->SetX(-7);
  164. $pdf->Cell(1,3,$caja,0,1,'R');
  165. $pdf->Cell(0,3,'RENTABILIDAD',0,0);
  166. $pdf->SetX(-7);
  167. $pdf->Cell(1,3,$rentabilidad,0,1,'R');
  168. if(empty($destino)){
  169. $pdf->Output(); // muestra en pantalla
  170. }else{
  171. $pdf->Output('pdf/'.$usuario_sesion.'.pdf','F'); // guarda en el server
  172. }
  173. ?>