Formatos
This commit is contained in:
@ -71,7 +71,7 @@ class Contabilidad extends Controller
|
||||
$anterior = $contabilidadService->getAnterior($fecha);
|
||||
$yesterday = new DateTimeImmutable('yesterday');
|
||||
$siguiente = null;
|
||||
if ($yesterday >= $fecha) {
|
||||
if ($yesterday > $fecha) {
|
||||
$siguiente = $fecha->add(new DateInterval('P1D'));
|
||||
if ($siguiente->format('N') === '6') {
|
||||
$siguiente = $fecha->add(new DateInterval('P3D'));
|
||||
|
@ -11,7 +11,7 @@ use Incoviba\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)
|
||||
{
|
||||
@ -190,6 +190,9 @@ class Excel extends Ideal\Service
|
||||
$this->fillTotals($sheet, 7, $finalRow ++);
|
||||
$sheet->getStyle("E8:N{$finalRow}")->getNumberFormat()
|
||||
->setFormatCode(self::CURRENCY_CODE);
|
||||
$conditionalStyles = $sheet->getStyle("E8:N{$finalRow}")->getConditionalStyles();
|
||||
$conditionalStyles []= $this->getConditional();
|
||||
$sheet->getStyle("E8:N{$finalRow}")->setConditionalStyles($conditionalStyles);
|
||||
|
||||
return $finalRow;
|
||||
}
|
||||
@ -274,6 +277,8 @@ class Excel extends Ideal\Service
|
||||
$rowSaldoAnterior = $rowIndex;
|
||||
$rowIndex ++;
|
||||
|
||||
$conditional = $this->getConditional();
|
||||
|
||||
$styles = [
|
||||
'fill' => [
|
||||
'fillType' => PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
@ -285,7 +290,6 @@ class Excel extends Ideal\Service
|
||||
'bold' => true
|
||||
]
|
||||
];
|
||||
$rowDap = null;
|
||||
$rowIngreso = null;
|
||||
$rowEgreso = null;
|
||||
foreach ($data['movimientos'] as $tipo => $movimientos) {
|
||||
@ -295,7 +299,6 @@ class Excel extends Ideal\Service
|
||||
$sheet->getStyle("B{$rowIndex}:V{$rowIndex}")->applyFromArray($styles);
|
||||
$sheet->getCell("V{$rowIndex}")->getStyle()->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
|
||||
$totalRow = $rowIndex;
|
||||
$rowDap = $rowIndex;
|
||||
$rowIndex ++;
|
||||
if (count($movimientos['ingresos']) === 0 and count($movimientos['egresos']) === 0) {
|
||||
$sheet->getCell("V{$totalRow}")->setValue(0);
|
||||
@ -314,6 +317,11 @@ class Excel extends Ideal\Service
|
||||
}
|
||||
}
|
||||
$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->getStyle("C{$start}:D{$end}")->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
|
||||
continue;
|
||||
@ -338,7 +346,7 @@ class Excel extends Ideal\Service
|
||||
foreach ($movimientos as $movimiento) {
|
||||
$sheet->getCell("B{$rowIndex}")->setValue($movimiento->cuenta->inmobiliaria->razon);
|
||||
$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("F{$rowIndex}")->setValue($movimiento->cuenta->banco->nombre);
|
||||
$sheet->getCell("G{$rowIndex}")->setValue($movimiento->glosa);
|
||||
@ -350,9 +358,18 @@ class Excel extends Ideal\Service
|
||||
'egresos' => "=SUM(D{$start}:D{$end})",
|
||||
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->getStyle("C{$start}:D{$end}")->getNumberFormat()
|
||||
->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;
|
||||
$rowIndex ++;
|
||||
@ -360,6 +377,9 @@ class Excel extends Ideal\Service
|
||||
$sheet->getCell("B{$rowIndex}")->setValue('TOTAL');
|
||||
$sheet->getCell("C{$rowIndex}")->setValue("=SUM(C{$startRow}:C{$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')
|
||||
->getStyle()->applyFromArray([
|
||||
'alignment' => [
|
||||
@ -378,7 +398,7 @@ class Excel extends Ideal\Service
|
||||
'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' => [
|
||||
'bold' => true
|
||||
],
|
||||
@ -386,6 +406,9 @@ class Excel extends Ideal\Service
|
||||
'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([
|
||||
'fill' => [
|
||||
@ -505,4 +528,17 @@ class Excel extends Ideal\Service
|
||||
->setView(PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW)
|
||||
->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