Formatos
This commit is contained in:
@ -71,7 +71,7 @@ class Contabilidad extends Controller
|
|||||||
$anterior = $contabilidadService->getAnterior($fecha);
|
$anterior = $contabilidadService->getAnterior($fecha);
|
||||||
$yesterday = new DateTimeImmutable('yesterday');
|
$yesterday = new DateTimeImmutable('yesterday');
|
||||||
$siguiente = null;
|
$siguiente = null;
|
||||||
if ($yesterday >= $fecha) {
|
if ($yesterday > $fecha) {
|
||||||
$siguiente = $fecha->add(new DateInterval('P1D'));
|
$siguiente = $fecha->add(new DateInterval('P1D'));
|
||||||
if ($siguiente->format('N') === '6') {
|
if ($siguiente->format('N') === '6') {
|
||||||
$siguiente = $fecha->add(new DateInterval('P3D'));
|
$siguiente = $fecha->add(new DateInterval('P3D'));
|
||||||
|
@ -11,7 +11,7 @@ use Incoviba\Service;
|
|||||||
|
|
||||||
class Excel extends Ideal\Service
|
class Excel extends Ideal\Service
|
||||||
{
|
{
|
||||||
protected const CURRENCY_CODE = '_-$* #,##0_-;-$* #,##0_-;_-$* "-"??_-;_-@_-';
|
protected const CURRENCY_CODE = '_ $* #,##0_ ;_ $* -#,##0_ ;_ $* "-"_ ;_ @_ ';
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger, protected string $folder, protected Service\UF $ufService, protected Service\USD $usdService)
|
public function __construct(LoggerInterface $logger, protected string $folder, protected Service\UF $ufService, protected Service\USD $usdService)
|
||||||
{
|
{
|
||||||
@ -190,6 +190,9 @@ class Excel extends Ideal\Service
|
|||||||
$this->fillTotals($sheet, 7, $finalRow ++);
|
$this->fillTotals($sheet, 7, $finalRow ++);
|
||||||
$sheet->getStyle("E8:N{$finalRow}")->getNumberFormat()
|
$sheet->getStyle("E8:N{$finalRow}")->getNumberFormat()
|
||||||
->setFormatCode(self::CURRENCY_CODE);
|
->setFormatCode(self::CURRENCY_CODE);
|
||||||
|
$conditionalStyles = $sheet->getStyle("E8:N{$finalRow}")->getConditionalStyles();
|
||||||
|
$conditionalStyles []= $this->getConditional();
|
||||||
|
$sheet->getStyle("E8:N{$finalRow}")->setConditionalStyles($conditionalStyles);
|
||||||
|
|
||||||
return $finalRow;
|
return $finalRow;
|
||||||
}
|
}
|
||||||
@ -274,6 +277,8 @@ class Excel extends Ideal\Service
|
|||||||
$rowSaldoAnterior = $rowIndex;
|
$rowSaldoAnterior = $rowIndex;
|
||||||
$rowIndex ++;
|
$rowIndex ++;
|
||||||
|
|
||||||
|
$conditional = $this->getConditional();
|
||||||
|
|
||||||
$styles = [
|
$styles = [
|
||||||
'fill' => [
|
'fill' => [
|
||||||
'fillType' => PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
'fillType' => PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||||
@ -285,7 +290,6 @@ class Excel extends Ideal\Service
|
|||||||
'bold' => true
|
'bold' => true
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$rowDap = null;
|
|
||||||
$rowIngreso = null;
|
$rowIngreso = null;
|
||||||
$rowEgreso = null;
|
$rowEgreso = null;
|
||||||
foreach ($data['movimientos'] as $tipo => $movimientos) {
|
foreach ($data['movimientos'] as $tipo => $movimientos) {
|
||||||
@ -295,7 +299,6 @@ class Excel extends Ideal\Service
|
|||||||
$sheet->getStyle("B{$rowIndex}:V{$rowIndex}")->applyFromArray($styles);
|
$sheet->getStyle("B{$rowIndex}:V{$rowIndex}")->applyFromArray($styles);
|
||||||
$sheet->getCell("V{$rowIndex}")->getStyle()->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
|
$sheet->getCell("V{$rowIndex}")->getStyle()->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
|
||||||
$totalRow = $rowIndex;
|
$totalRow = $rowIndex;
|
||||||
$rowDap = $rowIndex;
|
|
||||||
$rowIndex ++;
|
$rowIndex ++;
|
||||||
if (count($movimientos['ingresos']) === 0 and count($movimientos['egresos']) === 0) {
|
if (count($movimientos['ingresos']) === 0 and count($movimientos['egresos']) === 0) {
|
||||||
$sheet->getCell("V{$totalRow}")->setValue(0);
|
$sheet->getCell("V{$totalRow}")->setValue(0);
|
||||||
@ -314,6 +317,11 @@ class Excel extends Ideal\Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$end = $rowIndex;
|
$end = $rowIndex;
|
||||||
|
|
||||||
|
$conditionalStyles = $sheet->getStyle("D{$start}:D{$end}")->getConditionalStyles();
|
||||||
|
$conditionalStyles []= $conditional;
|
||||||
|
$sheet->getStyle("D{$start}:D{$end}")->setConditionalStyles($conditionalStyles);
|
||||||
|
|
||||||
$sheet->getCell("V{$totalRow}")->setValue("=SUM(C{$start}:D{$end})");
|
$sheet->getCell("V{$totalRow}")->setValue("=SUM(C{$start}:D{$end})");
|
||||||
$sheet->getStyle("C{$start}:D{$end}")->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
|
$sheet->getStyle("C{$start}:D{$end}")->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
|
||||||
continue;
|
continue;
|
||||||
@ -338,7 +346,7 @@ class Excel extends Ideal\Service
|
|||||||
foreach ($movimientos as $movimiento) {
|
foreach ($movimientos as $movimiento) {
|
||||||
$sheet->getCell("B{$rowIndex}")->setValue($movimiento->cuenta->inmobiliaria->razon);
|
$sheet->getCell("B{$rowIndex}")->setValue($movimiento->cuenta->inmobiliaria->razon);
|
||||||
$sheet->getCell("C{$rowIndex}")->setValue($movimiento->abono);
|
$sheet->getCell("C{$rowIndex}")->setValue($movimiento->abono);
|
||||||
$sheet->getCell("D{$rowIndex}")->setValue($movimiento->cargo);
|
$sheet->getCell("D{$rowIndex}")->setValue(-$movimiento->cargo);
|
||||||
$sheet->getCell("E{$rowIndex}")->setValue(PhpSpreadsheet\Shared\Date::PHPToExcel($movimiento->fecha));
|
$sheet->getCell("E{$rowIndex}")->setValue(PhpSpreadsheet\Shared\Date::PHPToExcel($movimiento->fecha));
|
||||||
$sheet->getCell("F{$rowIndex}")->setValue($movimiento->cuenta->banco->nombre);
|
$sheet->getCell("F{$rowIndex}")->setValue($movimiento->cuenta->banco->nombre);
|
||||||
$sheet->getCell("G{$rowIndex}")->setValue($movimiento->glosa);
|
$sheet->getCell("G{$rowIndex}")->setValue($movimiento->glosa);
|
||||||
@ -350,9 +358,18 @@ class Excel extends Ideal\Service
|
|||||||
'egresos' => "=SUM(D{$start}:D{$end})",
|
'egresos' => "=SUM(D{$start}:D{$end})",
|
||||||
default => ''
|
default => ''
|
||||||
};
|
};
|
||||||
|
if ($tipo === 'egresos') {
|
||||||
|
$conditionalStyles = $sheet->getStyle("D{$start}:D{$end}")->getConditionalStyles();
|
||||||
|
$conditionalStyles []= $conditional;
|
||||||
|
$sheet->getStyle("D{$start}:D{$end}")->setConditionalStyles($conditionalStyles);
|
||||||
|
}
|
||||||
$sheet->getCell("V{$totalRow}")->setValue($sumFormula);
|
$sheet->getCell("V{$totalRow}")->setValue($sumFormula);
|
||||||
$sheet->getStyle("C{$start}:D{$end}")->getNumberFormat()
|
$sheet->getStyle("C{$start}:D{$end}")->getNumberFormat()
|
||||||
->setFormatCode(self::CURRENCY_CODE);
|
->setFormatCode(self::CURRENCY_CODE);
|
||||||
|
$sheet->getStyle("E{$start}:E{$end}")->getNumberFormat()->setFormatCode(PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY);
|
||||||
|
$conditionalStyles = $sheet->getStyle("V{$totalRow}")->getConditionalStyles();
|
||||||
|
$conditionalStyles []= $conditional;
|
||||||
|
$sheet->getStyle("V{$totalRow}")->setConditionalStyles($conditionalStyles);
|
||||||
}
|
}
|
||||||
$end = $rowIndex;
|
$end = $rowIndex;
|
||||||
$rowIndex ++;
|
$rowIndex ++;
|
||||||
@ -360,6 +377,9 @@ class Excel extends Ideal\Service
|
|||||||
$sheet->getCell("B{$rowIndex}")->setValue('TOTAL');
|
$sheet->getCell("B{$rowIndex}")->setValue('TOTAL');
|
||||||
$sheet->getCell("C{$rowIndex}")->setValue("=SUM(C{$startRow}:C{$end})");
|
$sheet->getCell("C{$rowIndex}")->setValue("=SUM(C{$startRow}:C{$end})");
|
||||||
$sheet->getCell("D{$rowIndex}")->setValue("=SUM(D{$startRow}:D{$end})");
|
$sheet->getCell("D{$rowIndex}")->setValue("=SUM(D{$startRow}:D{$end})");
|
||||||
|
$conditionalStyles = $sheet->getStyle("D{$rowIndex}")->getConditionalStyles();
|
||||||
|
$conditionalStyles []= $conditional;
|
||||||
|
$sheet->getStyle("D{$rowIndex}")->setConditionalStyles($conditionalStyles);
|
||||||
$sheet->getCell("T{$rowIndex}")->setValue('Saldo final al')
|
$sheet->getCell("T{$rowIndex}")->setValue('Saldo final al')
|
||||||
->getStyle()->applyFromArray([
|
->getStyle()->applyFromArray([
|
||||||
'alignment' => [
|
'alignment' => [
|
||||||
@ -378,7 +398,7 @@ class Excel extends Ideal\Service
|
|||||||
'formatCode' => PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY
|
'formatCode' => PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
$sheet->getCell("V{$rowIndex}")->setValue("=V{$rowSaldoAnterior}+V{$rowDap}+V{$rowIngreso}+V{$rowEgreso}")->getStyle()->applyFromArray([
|
$sheet->getCell("V{$rowIndex}")->setValue("=V{$rowSaldoAnterior}+V{$rowIngreso}+V{$rowEgreso}")->getStyle()->applyFromArray([
|
||||||
'font' => [
|
'font' => [
|
||||||
'bold' => true
|
'bold' => true
|
||||||
],
|
],
|
||||||
@ -386,6 +406,9 @@ class Excel extends Ideal\Service
|
|||||||
'formatCode' => self::CURRENCY_CODE
|
'formatCode' => self::CURRENCY_CODE
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
$conditionalStyles = $sheet->getStyle("V{$rowIndex}")->getConditionalStyles();
|
||||||
|
$conditionalStyles []= $conditional;
|
||||||
|
$sheet->getStyle("V{$rowIndex}")->setConditionalStyles($conditionalStyles);
|
||||||
|
|
||||||
$sheet->getStyle("B{$rowIndex}:V{$rowIndex}")->applyFromArray([
|
$sheet->getStyle("B{$rowIndex}:V{$rowIndex}")->applyFromArray([
|
||||||
'fill' => [
|
'fill' => [
|
||||||
@ -505,4 +528,17 @@ class Excel extends Ideal\Service
|
|||||||
->setView(PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW)
|
->setView(PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW)
|
||||||
->setZoomScale(70);
|
->setZoomScale(70);
|
||||||
}
|
}
|
||||||
|
protected PhpSpreadsheet\Style\Conditional $conditional;
|
||||||
|
protected function getConditional(): PhpSpreadsheet\Style\Conditional
|
||||||
|
{
|
||||||
|
if (!isset($this->conditional)) {
|
||||||
|
$conditional = new PhpSpreadsheet\Style\Conditional();
|
||||||
|
$conditional->setConditionType(PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS);
|
||||||
|
$conditional->setOperatorType(PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN);
|
||||||
|
$conditional->addCondition(0);
|
||||||
|
$conditional->getStyle()->getFont()->getColor()->setARGB(PhpSpreadsheet\Style\Color::COLOR_DARKRED);
|
||||||
|
$this->conditional = $conditional;
|
||||||
|
}
|
||||||
|
return $this->conditional;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user