Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. <?php
  2. //configurações do banco
  3. ini_set('max_execution_time', 300);
  4. include_once("../../function/conexao.php");
  5. include_once '../../Classes/PHPExcel/IOFactory.php';
  6. $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  7. $objPHPExcel = $objReader->load("../../Templates/PedidoCompra.xlsx");
  8. // Create new PHPExcel object
  9. //$objPHPExcel = new PHPExcel();
  10. // Set document properties
  11.  
  12. if(isset($_POST['PDC'])){
  13. $Dados = $_POST['PDC'];
  14. //atualização dos dados do pedido
  15. $data1 = explode("/",$Dados[10]);
  16. $Dados[10] = substr($data1[2],0,4)."/$data1[1]/$data1[0]";
  17. if(empty($Dados[16])){
  18. $Dados[16]="0.00";
  19. }
  20. if(empty($Dados[9])){
  21. $Dados[9]="0.00";
  22. }
  23. if(empty($Dados[16])){
  24. $Dados[16]="0.00";
  25. }
  26. if(empty($Dados[17])){
  27. $Dados[17]="0.00";
  28. }
  29. //if($_POST['btPDC']=="ATUALIZAR"){
  30. $sql_up = "update financeiro_pedido_compra set
  31. pgto = '$Dados[12]',
  32. contato='$Dados[3]',
  33. data='$Dados[10]',
  34. desconto='$Dados[16]',
  35. IPI='$Dados[9]',
  36. FRETE='$Dados[17]',
  37. status='GERADO',
  38. data_modif=now(),
  39. usuario='$_SESSION[Usuario]' where pedidopk = $Dados[1]";
  40. mysql_query($sql_up);
  41. //echo $sql_up;
  42. if ($error = mysql_errno()) die("<script>alert("1 - Erro UP, informe ao atualizar Administrador");history.back();</script>");
  43. //}
  44. $sql = "select nome,endereco1,num_end1,bairro1,cep1,cidade1,uf1,cgc,insc_est,concat(ddd1,'-',num1) as tel,cond_pgfk from financeiro_cliente where cgc='".$Dados[0]."'";
  45. $DadosCliente = mysql_fetch_assoc(mysql_query($sql,$conexao));
  46. // SELECIONAR OS DADOS PARA PLANILHA
  47. $query = mysql_query($sql,$conexao);
  48. // INICIAMOS A CRIAÇÃO DA TABELA
  49. $TotIPI = ($Dados[9]/100)*$Dados[8];
  50. $TotIPI = number_format($TotIPI, 2, ',', ' ');
  51. $Total = $Dados[8] + $TotIPI;
  52. $Dados[11] = strtoupper($Dados[11]);
  53. $Dados[6] = strtoupper($Dados[6]);
  54. $objPHPExcel->setActiveSheetIndex(0)
  55. ->setCellValue("C3", "$DadosCliente[nome]")
  56. ->setCellValue("C4", "$DadosCliente[endereco1], N°: $DadosCliente[num_end1]")
  57. ->setCellValue("C5", "$DadosCliente[bairro1]")
  58. ->setCellValue("C6", "$DadosCliente[cep1]")
  59. ->setCellValue("I4", "$DadosCliente[cidade1]")
  60. ->setCellValue("I5", "$DadosCliente[uf1]")
  61. ->setCellValue("I6", "$DadosCliente[cgc]")
  62. ->setCellValue("I7", "$DadosCliente[insc_est]")
  63. ->setCellValue("I8", "$DadosCliente[tel]")
  64. ->setCellValue("C10", "$Dados[1]") //pcn
  65. ->setCellValue("F10", "$Dados[2]")//data emissao
  66. ->setCellValue("I10", "$Dados[12]")
  67. ->setCellValue("C7", "$Dados[3]");//ordem
  68. $select=mysql_query("select item,concat(substr(mpfk,3,2),codigo),descricao,qtd,un,vlrun,vlrtot from financeiro_pedido_compra_item where pedidofk = '$Dados[1]' order by item") ;
  69. $row =14;
  70. $Total=0;
  71. $data1 = explode("/",$Dados[10]);
  72. $Dados[10] = substr($data1[2],0,4)."/$data1[1]/$data1[0]";
  73. while($Itens = mysql_fetch_array($select)){
  74. $objPHPExcel->setActiveSheetIndex(0)
  75. ->setCellValue("A$row", "$Itens[0]")//codigo
  76. ->setCellValue("C$row", "$Itens[1]")//codigo
  77. ->setCellValue("E$row", "$Itens[2]]")//descricao
  78. ->setCellValue("J$row", "$Itens[3]")//qtd
  79. ->setCellValue("K$row", "$Itens[4]")//un
  80. ->setCellValue("L$row", "$Itens[5]")//Val Un
  81. ->setCellValue("N$row", "$Itens[6]")//Total
  82. ->setCellValue("O$row", "$Dados[9]")//ipi
  83. ->setCellValue("P$row", "$Itens[3]")//qtd
  84. ->setCellValue("Q$row", "$Dados[10]");//data entrega
  85. $objPHPExcel->getActiveSheet()->mergeCells("C$row:D$row");
  86. $objPHPExcel->getActiveSheet()->mergeCells("L$row:M$row");
  87. $Char = strlen($Itens[2]);
  88. if($Char>43){
  89. $IntDiv=(int)($Char/43);
  90. $row2=$row+$IntDiv;
  91. $objPHPExcel->getActiveSheet()->mergeCells("E$row:I$row2");
  92. $row+=$IntDiv+1;
  93. }else{
  94. $objPHPExcel->getActiveSheet()->mergeCells("E$row:I$row");
  95. $row++;
  96. }
  97. //$objPHPExcel->getActiveSheet()->getStyle("E$row")->getAlignment()->setWrapText(false);
  98. $Total+=$Itens[6];
  99. }
  100. //}/*
  101. $TotIPI = $Total * ($Dados[9]/100);
  102. $TotalGeral = $Total+$TotIPI+$Dados[17];
  103. $TotalGeral=$TotalGeral-$Dados[16];
  104. $objPHPExcel->setActiveSheetIndex(0)
  105. ->setCellValue("L38", "$Total")//codigo
  106. ->setCellValue("P38", "$TotIPI")
  107. ->setCellValue("Q38", $TotalGeral)
  108. ->setCellValue("N38", "$Dados[17]");//codigo
  109. $objPHPExcel->getActiveSheet()->getRowDimension('3')->setRowHeight(12);
  110. $objPHPExcel->getActiveSheet()->getRowDimension('4')->setRowHeight(12);
  111. $objPHPExcel->getActiveSheet()->getRowDimension('5')->setRowHeight(12);
  112. $objPHPExcel->getActiveSheet()->getRowDimension('6')->setRowHeight(12);
  113. $objPHPExcel->getActiveSheet()->getRowDimension('7')->setRowHeight(12);
  114. $objPHPExcel->getActiveSheet()->getRowDimension('8')->setRowHeight(12);
  115. $arquivo = 'PedidoCompra'.date("Ymd")."_ $Dados[1]";
  116. // Criamos uma tabela HTML com o formato da planilha
  117. }
  118. $objPHPExcel->getActiveSheet()->setTitle('Custo');
  119. $objPHPExcel->setActiveSheetIndex(0);
  120. header('Content-Type: application/vnd.openxmlformats-officedocument.SpreadsheetML.Sheet');
  121. header("Content-Disposition: attachment;filename="$arquivo.xlsx"");
  122. header('Cache-Control: max-age=0');
  123. // If you're serving to IE 9, then the following may be needed
  124. header('Cache-Control: max-age=1');
  125. // If you're serving to IE over SSL, then the following may be needed
  126. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  127. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  128. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  129. header ('Pragma: public'); // HTTP/1.0
  130. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  131. $objWriter->save('php://output');
  132. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement