"VER1.0","Compras","Mapa de compras por meses (apaisado)"
;Versio, Categoria, Descripcion
;
; ComprasMesAMes.txt -- 05/10/2026. Una línea por proveedor con lo que se le ha comprado cada mes del año
; en curso (el de la fecha de hoy), de enero a diciembre, y el total del año. Al pie, el total de
; cada mes. Sirve para ver de un vistazo a quién se compra por temporada y a quién se ha dejado de comprar.
;
; POR QUÉ ESTÁ HECHO ASÍ (leer antes de tocar):
; - Un mes sin compras sale en BLANCO (IIF ... Null), no 0,00: con doce columnas los ceros no dejan
;   ver nada.
; - El HAVING quita a los proveedores sin compras este año.
; - El título con el año sale de la consulta de CABECERA, porque DISENY no tiene consulta.
; - Con la fecha de trabajo en vez de la de hoy: cambiar Date() por {FechaTrabajo} cuando el
;   motor lo admita (ver claude/miERP_Motor_Impresos_Funciones_Fecha.md).
; - Letra a 7 puntos: cabe "123.456,78" en los 16 mm de cada mes.
; - Base imponible = BaseImponible1+2+3 de ComFacturas, sin IVA. Las rectificativas restan solas
;   porque se guardan en negativo.
; - Usa Date(), Year(), Month(), DateAdd(), DateDiff(), CStr() y CCur(): hoy SOLO funciona en Access.
;   Funcionará en PostgreSQL sin tocar este fichero cuando el motor haga lo que pide
;   claude/miERP_Motor_Impresos_Funciones_Fecha.md.
; - El nombre sale de la ficha del proveedor y, si está vacío, del de la factura. Va con Max() porque
;   la consulta agrupa, y Max funciona igual en los dos motores (First no).
; - Los importes van alineados a la derecha CON ancho declarado (sin él la caja es de 18 mm).
; - Las ordenaciones con una suma y DESC siguen el patrón de RankingClientesVentas.txt; si alguna
;   diera error, basta con no elegirla.

;Ampla, Llarg, [EspaiCos]     9 = A4
;MargenX,MargenY, EtiLin, EtiPag
[DOCUM]
H, 9, 10
10,8,0,0

[GRUP]
1,"CABECERA", #FALSE#
"SELECT *, 'Compras mes a mes de ' & Year(Date()) AS TituloAnio"
"FROM Configuracion"
""
[CAPSALERA]
0, 0, #FALSE#, 0, #FALSE#, #TRUE#, 0
; RAp(n), Alt(n), SMin(b), Salto(D), GA(b), All(b), Rel(D)
[CAMPS] 2
3,"CABECERA","TituloAnio",0,0,"ARIAL",16,200,0,"1000","","",7
3,"CABECERA","NombreComercial",0,7.5,"ARIAL",9,150,0,"0000","","",9
[FICAP]
[PEU]
0, 8, #TRUE#, 0, #TRUE#, #FALSE#, 0
; RAp(n), Alt(n), SMin(b), Salto(D), GA(b), All(b), Rel(D)
[CAMPS] 15
1,"lineaTot",0,1,277,1,,,
0,"TOTAL",18,2.5,"ARIAL",7,30,0,"1000","","",9
5,0,"TotM01",58.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,1,"TotM02",74.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,2,"TotM03",90.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,3,"TotM04",106.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,4,"TotM05",122.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,5,"TotM06",138.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,6,"TotM07",154.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,7,"TotM08",170.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,8,"TotM09",186.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,9,"TotM10",202.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,10,"TotM11",218.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,11,"TotM12",234.5,2.5,"ARIAL",7,15.5,1,"1000","","",0
5,12,"TotAnio",253,2.5,"ARIAL",7,24,1,"1000","","",7
[FIPEU]
[FIGRUP]

;-----------------------------------------

[GRUP]
0,"DISENY", #FALSE#
""
""
""
[CAPSALERA]
0, 23, #TRUE#, 0, #TRUE#, #TRUE#, 0
; RAp(n), Alt(n), SMin(b), Salto(D), GA(b), All(b), Rel(D)
[CAMPS] 20
0,"Página",263,1.5,"ARIAL",8,12,0,"0000","","",1
6,"Pagina",277,1.5,"ARIAL",8,0,1,"1000","","",7
0,"Base imponible (sin IVA) de cada mes. Los meses sin compras salen en blanco.",0,11.5,"ARIAL",7,200,0,"0000","","",1
1,"lineaSup",0,15,277,15,,,
0,"CÓDIGO",0,16.5,"ARIAL",7,17,0,"1000","","",9
0,"PROVEEDOR",18,16.5,"ARIAL",7,40,0,"1000","","",9
0,"ENE",58.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"FEB",74.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"MAR",90.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"ABR",106.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"MAY",122.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"JUN",138.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"JUL",154.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"AGO",170.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"SEP",186.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"OCT",202.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"NOV",218.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"DIC",234.5,16.5,"ARIAL",7,15.5,1,"1000","","",9
0,"TOTAL",253,16.5,"ARIAL",7,24,1,"1000","","",7
1,"lineaInf",0,21,277,21,,,
[FICAP]
[PEU]
0, 0, #FALSE#, 0, #FALSE#, #FALSE#, 0
; RAp(n), Alt(n), SMin(b), Salto(D), GA(b), All(b), Rel(D)
[CAMPS] 0
[FIPEU]
[FIGRUP]

;-----------------------------------------

[GRUP]
3,"COS", #FALSE#
"SELECT ComFacturas.CodProveedor, IIF(Nz(Max(Proveedores.NombreFiscal),'')='', Max(ComFacturas.NombreFiscal), Max(Proveedores.NombreFiscal)) AS NombreListado, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=1, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=1, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M01, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=2, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=2, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M02, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=3, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=3, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M03, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=4, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=4, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M04, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=5, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=5, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M05, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=6, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=6, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M06, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=7, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=7, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M07, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=8, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=8, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M08, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=9, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=9, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M09, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=10, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=10, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M10, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=11, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=11, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M11, IIF(Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=12, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))=0, Null, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()) AND Month(ComFacturas.FechaFactura)=12, (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0))) AS M12, Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()), (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0)) AS TotalAnio"
"FROM ComFacturas LEFT JOIN Proveedores ON ComFacturas.CodProveedor = Proveedores.CodProveedor"
"GROUP BY ComFacturas.CodProveedor HAVING Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()), (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0)) <> 0"
[CONDICIONS] 2
"ComFacturas.CodProveedor","Proveedor",0,1
"Proveedores.CodGrupo","Grupo de proveedor",0,1

[ORDENACIONS] 3
"Max(Proveedores.NombreFiscal)","Nombre",3
"ComFacturas.CodProveedor","Código proveedor",3
"Sum(IIF(Year(ComFacturas.FechaFactura)=Year(Date()), (Nz(ComFacturas.BaseImponible1,0)+Nz(ComFacturas.BaseImponible2,0)+Nz(ComFacturas.BaseImponible3,0)), 0)) DESC","Más compras del año primero",3

[CAPSALERA]
0, 5, #TRUE#, 0, #TRUE#, #FALSE#, 0
; RAp(n), Alt(n), SMin(b), Salto(D), GA(b), All(b), Rel(D)
[CAMPS] 15
3,"COS","CodProveedor",0,0.8,"ARIAL",7,17,0,"0000","","",7
3,"COS","NombreListado",18,0.8,"ARIAL",7,39,0,"0000","","",0
3,"COS","M01",58.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M02",74.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M03",90.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M04",106.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M05",122.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M06",138.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M07",154.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M08",170.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M09",186.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M10",202.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M11",218.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","M12",234.5,0.8,"ARIAL",7,15.5,1,"0000","","",9
3,"COS","TotalAnio",253,0.8,"ARIAL",7,24,1,"1000","","",7
[FICAP]
[FIGRUP]

;-----------------------------------------

[CALCULS] 13
"TotM01","COS","M01","CABECERA"
"TotM02","COS","M02","CABECERA"
"TotM03","COS","M03","CABECERA"
"TotM04","COS","M04","CABECERA"
"TotM05","COS","M05","CABECERA"
"TotM06","COS","M06","CABECERA"
"TotM07","COS","M07","CABECERA"
"TotM08","COS","M08","CABECERA"
"TotM09","COS","M09","CABECERA"
"TotM10","COS","M10","CABECERA"
"TotM11","COS","M11","CABECERA"
"TotM12","COS","M12","CABECERA"
"TotAnio","COS","TotalAnio","CABECERA"

[FIDOCUM]
