1!function(){try{var e="u">typeof window?window:"u">typeof global?global:"u">typeof globalThis?globalThis:"u">typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="1d0b074e-0ff5-46a6-941e-22c5f3eff1b9",e._sentryDebugIdIdentifier="sentry-dbid-1d0b074e-0ff5-46a6-941e-22c5f3eff1b9")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[49897],{49897:(e,t,a)=>{a.r(t),a.d(t,{createMillesimalTable:()=>d,createMillesimalVersion:()=>p,deleteMillesimalTable:()=>f,getMillesimalTable:()=>u,getMillesimalTables:()=>c,isGeneralType:()=>n,listMillesimalVersions:()=>y,restoreMillesimalVersion:()=>v,updateMillesimalTable:()=>m,validateMillesimalTable:()=>b});var r=a(91531),l=a(89674),i=a(40980);function n(e){return"generale"===e||"proprieta"===e}function o(e){return(0,r.collection)(l.db,"organizations",e,"millesimalTables")}function s(e,t){return(0,r.H9)(l.db,"organizations",e,"millesimalTables",t)}async function d(e,t){try{let a={...t,organizationId:e};if(a.voci){let e=b(a);if(!e.valid)return{data:null,error:`Totale millesimi ${e.total} diverso da ${e.targetTotal} per tabella ${a.tipo}`}}return{data:{id:(await (0,r.gS)(o(e),(0,i.Pc)(a))).id,...a},error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to create millesimal table"}}}async function u(e,t){try{let a=await (0,r.getDoc)(s(e,t));if(!a.exists())return{data:null,error:"Millesimal table not found"};return{data:{id:a.id,...a.data()},error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to get millesimal table"}}}async function c(e,t,a){try{let l=[(0,r.where)("condominiumId","==",t)];a&&l.push((0,r.where)("tipo","==",a));let i=(0,r.query)(o(e),...l);return{data:(await (0,r.getDocs)(i)).docs.map(e=>({id:e.id,...e.data()})),error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to get millesimal tables"}}}async function m(e,t,a){try{if(a.voci){let l=a.tipo;if(!l){let a=await (0,r.getDoc)(s(e,t));if(!a.exists())return{data:null,error:"Millesimal table not found"};l=a.data().tipo}let i=b({tipo:l,voci:a.voci});if(!i.valid)return{data:null,error:`Totale millesimi ${i.total} diverso da ${i.targetTotal} per tabella ${l}`}}return await (0,r.mZ)(s(e,t),(0,i.Pc)({...a})),{data:null,error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to update millesimal table"}}}async function f(e,t){try{return await (0,r.kd)(s(e,t)),{data:null,error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to delete millesimal table"}}}function b(e,t){let a=e.voci.reduce((e,t)=>e+t.millesimi,0),r=t??(n(e.tipo)?1e3:null);return null===r?{valid:!0,total:a,targetTotal:null}:{valid:.01>Math.abs(a-r),total:a,targetTotal:r}}function g(e,t){return(0,r.collection)(l.db,"organizations",e,"millesimalTables",t,"versions")}async function p(e,t,a){try{let l=a.voci.reduce((e,t)=>e+(t.millesimi||0),0),n={tableId:t,voci:a.voci,createdAt:(0,r.O5)(),createdBy:a.createdBy,deliberaId:a.deliberaId||null,assembleaData:a.assembleaData||null,note:a.note||null,totale:l};return{data:{id:(await (0,r.gS)(g(e,t),(0,i.Pc)(n))).id,...n,createdAt:new Date},error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to create millesimal version"}}}async function y(e,t,a=50){try{let l=(0,r.query)(g(e,t),(0,r.My)("createdAt","desc"),(0,r.limit)(a));return{data:(await (0,r.getDocs)(l)).docs.map(e=>({id:e.id,...e.data()})),error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to list versions"}}}async function v(e,t,o,d){try{let u=await (0,r.getDoc)((0,r.H9)(l.db,"organizations",e,"millesimalTables",t,"versions",o));if(!u.exists())return{data:null,error:"Version not found"};let c=u.data(),m=await (0,r.getDoc)(s(e,t));if(!m.exists())return{data:null,error:"Millesimal table not found"};let f=m.data(),g=b({tipo:f.tipo,voci:c.voci});if(!g.valid)return{data:null,error:`Totale millesimi ${g.total} diverso da ${g.targetTotal} per tabella ${f.tipo}: ripristino versione ${o} annullato`};let y=await p(e,t,{voci:f.voci,createdBy:d,note:`Snapshot automatico prima del ripristino versione ${o}`});if(y.error)return{data:null,error:`Impossibile creare lo snapshot dello stato corrente: ${y.error}. Ripristino annullato per non perdere dati.`};
1if(await (0,r.mZ)(s(e,t),(0,i.Pc)({voci:c.voci})),n(f.tipo))try{let{syncUnitMillesimiFromGeneral:t}=await a.e(43471).then(a.bind(a,43471));await t(e,c.voci.map(e=>({unitId:e.unitId,millesimi:e.millesimi})))}catch{}return{data:null,error:null}}catch(e){return{data:null,error:e instanceof Error?e.message:"Failed to restore version"}}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.