From 517276da1d76b66f462f53ea42062f68eefcd5e3 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 7 Mar 2022 22:38:29 -0300 Subject: [PATCH] FIX: format in excel --- app/Service/Informe/Contabilidad/Resumen.php | 10 ++++------ app/Service/Informe/Informe.php | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Service/Informe/Contabilidad/Resumen.php b/app/Service/Informe/Contabilidad/Resumen.php index 0d39df0..3503e1f 100644 --- a/app/Service/Informe/Contabilidad/Resumen.php +++ b/app/Service/Informe/Contabilidad/Resumen.php @@ -119,10 +119,6 @@ class Resumen }); } - protected function formatValue(float $value) - { - return number_format($value, 0, ',', '.'); - } protected function buildLibro(Venta $venta, DateTimeInterface $up_to) { $pagos = $this->getPagos($venta, $up_to); @@ -131,11 +127,11 @@ class Resumen $haber = 0; foreach ($pagos as $pago) { if ($pago->valor > 0) { - $output []= ['', $pago->fecha->format('d/m/Y'), '', $this->formatValue($pago->valor)]; + $output []= ['', $pago->fecha->format('d/m/Y'), '', $pago->valor]; $debe += $pago->valor; } else { - $output []= ['', $pago->fecha->format('d/m/Y'), $this->formatValue(-$pago->valor), '']; + $output []= ['', $pago->fecha->format('d/m/Y'), -$pago->valor, '']; $haber -= $pago->valor; } } @@ -156,6 +152,8 @@ class Resumen $informe = new Informe(); $informe->createSpreadsheet() ->addArray($output) + ->formatColumn('C') + ->formatColumn('D') ->send($filename); return; diff --git a/app/Service/Informe/Informe.php b/app/Service/Informe/Informe.php index 96af23c..656ebf4 100644 --- a/app/Service/Informe/Informe.php +++ b/app/Service/Informe/Informe.php @@ -38,6 +38,11 @@ class Informe $this->spreadsheet->getActiveSheet()->fromArray($this->formatArray($data), null, $start); return $this; } + public function formatColumn(string $column) + { + $this->spreadsheet->getActiveSheet()->getStyle("{$column}:{$column}")->setFormatCode('#,##0'); + return $this; + } public function send(string $filename) { header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');