D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
gre
/
Views
/
Cotacao
/
Filename :
downloadFatura.php
back
Copy
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); //ob_clean(); // flush(); $Lanc = new \App\gre\Models\Cotacao\ModCtRespondeNegociacaoLer(); $arr = $Lanc->listarNegociacao($this->Dados); //var_dump($arr); //die; $nome = $arr[0]['nome_forn']; $repres_id = $arr[0]['repres_id']; //$sugestao_id = $arr[0]['sugestao_id']; date_default_timezone_set ("America/Sao_Paulo"); $datahoje = date("YmdHis"); require "vendor/autoload.php"; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getColumnDimension('A')->setWidth(100,'px'); $sheet->getColumnDimension('B')->setWidth(100,'px'); $sheet->getColumnDimension('C')->setWidth(70,'px'); $sheet->getColumnDimension('D')->setWidth(100,'px'); $sheet->getColumnDimension('E')->setWidth(400,'px'); $sheet->getColumnDimension('F')->setWidth(100,'px'); $sheet->getColumnDimension('G')->setWidth(100,'px'); $sheet->setCellValue('A2', 'ID SUGESTAO'); $sheet->setCellValue('B2', 'COD INTERNO'); $sheet->setCellValue('C2', 'QTDE'); $sheet->setCellValue('D2', 'CODIGO EAN'); $sheet->setCellValue('E2', 'DESCRIÇÃO'); $sheet->setCellValue('F2', $nome); $sheet->setCellValue('G2', 'TENHO PREÇO'); $sn=3; $total_preco_cotado = 0; $total_preco_tenho = 0; foreach ($arr as $data) { extract($data); $sheet->setCellValue('A'.$sn, $sugestao_id); $sheet->setCellValue('B'.$sn, $prod_cod); $sheet->setCellValue('C'.$sn, $qtde); $sheet->getStyle('D'.$sn)->getNumberFormat()->setFormatCode('0000000000000'); $sheet->setCellValue('D'.$sn, $ean); $sheet->setCellValue('E'.$sn, $prod_nome); $sheet->getStyle('E'.$sn)->getNumberFormat()->setFormatCode('##,###,###,##0.00'); $sheet->setCellValue('F'.$sn, $preco_cotado); $sheet->getStyle('F'.$sn)->getNumberFormat()->setFormatCode('##,###,###,##0.00'); $sheet->setCellValue('G'.$sn, $tenho_preco); $total_preco_cotado += ($preco_cotado * $qtde); $total_preco_tenho += ($tenho_preco * $qtde); $sn++; } $fim = $sn -1; $sheet->getStyle('E'.$sn)->getFont()->setBold(true); $sheet->setCellValue('E'.$sn, 'TOTAIS'); $sheet->getStyle('F'.$sn)->getFont()->setBold(true); $sheet->getStyle('F'.$sn)->getNumberFormat()->setFormatCode('##,###,###,##0.00'); $sheet->setCellValue('F'.$sn, '=SUMPRODUCT(C3:C'.$fim.',F3:F'.$fim.')'); $sheet->getStyle('G'.$sn)->getFont()->setBold(true); $sheet->getStyle('G'.$sn)->getNumberFormat()->setFormatCode('##,###,###,##0.00'); $sheet->setCellValue('G'.$sn, '=SUMPRODUCT(C3:C'.$fim.',G3:G'.$fim.')'); $fim = $sn; $sn++; $sheet->getStyle('E'.$sn)->getFont()->setBold(true); $sheet->setCellValue('E'.$sn, 'DIFERENÇA'); $sheet->getStyle('F'.$sn)->getFont()->setBold(true); $sheet->getStyle('F'.$sn)->getNumberFormat()->setFormatCode('##,###,###,##0.00'); $sheet->setCellValue('F'.$sn, '=(F'.$fim.'-G'.$fim.')'); $sheet->getStyle('A2:G'.$sn)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); $sheet->getStyle('F2:G'.$sn)->getProtection()->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED); $nomeplanilha = 'negociacao_'.$repres_id.'_'.$datahoje.'.xls'; $writer = new Xlsx($spreadsheet); $writer->save($nomeplanilha); $fileName = 'negociacao_'.$repres_id.'_'.$datahoje.'.zip'; /* $path = 'C:/wamp64/www/rosario/adm'; //__DIR__ ; $fullPath = $path.'/'.$fileName; //var_dump($fullPath); //if (!file_exists($fullPath)){ // var_dump($fullPath); //die('Arquivo não existe!'); //} $tipo="application/vnd.ms-excel"; header("Content-Type: ".$tipo); // informa o tipo do arquivo ao navegador header("Content-Disposition: attachment; filename=".$nomeplanilha); // informa ao navegador que é tipo anexo e faz abrir a janela de download, //tambem informa o nome do arquivo readfile($fullPath); // lê o arquivo /* $fileLocation = $nomeplanilha; header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename='.$fileLocation); header('Cache-Control: max-age=0'); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); $writer->save('php://output'); //flush(); */ $fileName = 'negociacao_'.$repres_id.'_'.$datahoje.'.zip'; $path = 'C:/wamp64/www/rosario/adm'; //__DIR__ ; $fullPath = $path.'/'.$fileName; $diretorio = dir($path); $zip = new \ZipArchive(); if( $zip->open($fullPath, \ZipArchive::CREATE) ){ while($arquivo = $diretorio->read()){ $extensao = substr($arquivo,strlen($arquivo)-3,3); if($extensao == 'xls'){ //var_dump($path.'/'.$arquivo); $zip->addFile($path.'/'.$arquivo, $arquivo); } } $zip->close(); } if(file_exists($fullPath)){ // Forçamos o donwload do arquivo. header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="'.$fileName.'"'); readfile($fullPath); $path = 'C:/wamp64/www/rosario/adm/'; //__DIR__ ; $fileDelz = 'negociacao_'.$repres_id.'_'.$datahoje.'.zip'; $fullPathDelz = $path.'/'.$fileDelz; $fileDelx = 'negociacao_'.$repres_id.'_'.$datahoje.'.xls'; $fullPathDelx = $path.'/'.$fileDelx; $diretorio = dir($path); unlink($fullPathDelz); unlink($fullPathDelx); } ?>