Files
bruno/app/dist/spa/assets/IncomeStep-RKJ4eG2Y.js
2026-02-18 21:04:57 +01:00

2 lines
13 KiB
JavaScript

import{$ as G,r as F,Z as ce,a as O,w as B,o as W,a9 as re,a3 as A,a5 as E,a8 as $,a4 as U,a1 as V,a0 as x,af as N,a6 as q,aq as Y,a7 as me,ac as c,as as ue,ae as de,am as pe,ah as fe}from"./index-0B2sgEyA.js";import{u as ye,d as X,b as he,f as ge,e as ve,Q as we,a as be}from"./userstore-DBCughIu.js";import{u as Z}from"./vue-i18n.runtime-DPKkE7zN.js";import{_ as ee}from"./IndexPage-CwM_myNb.js";import{P as H}from"./LocalStorage-7Uw3xG9P.js";import"./QList-CHwmSUjA.js";const Ce="http://localhost:8082";class d extends Error{status;constructor(o,n){super(o),this.name="ApiError",this.status=n}}function M(t,o){const n=(t||Ce).replace(/\/+$/,""),u=o.startsWith("/")?o:`/${o}`;return`${n}${u}`}async function J(t){const o=await t.text();if(!o)return null;try{return JSON.parse(o)}catch{return o}}function Se(t){if(!t||typeof t!="object")return[];const o=t.files;if(!o)return[];if(Array.isArray(o)){const n=[];for(const u of o){if(typeof u=="string"){n.push(u);continue}if(u&&typeof u=="object"){const s=u,i=typeof s.storedName=="string"&&s.storedName||typeof s.originalName=="string"&&s.originalName||typeof s.name=="string"&&s.name||"";i&&n.push(i)}}return n}return[]}async function Ae(t){const{user:o,session:n,prop:u,file:s,baseUrl:i,onProgress:r,signal:p}=t;if(!o)throw new d("missing user");if(!n)throw new d("missing session");if(!s)throw new d("missing file");const b=M(i,"/upload");return await new Promise((e,S)=>{const l=new XMLHttpRequest;if(p){if(p.aborted){S(new d("aborted"));return}p.addEventListener("abort",()=>{try{l.abort()}catch{}},{once:!0})}l.upload.onprogress=h=>{if(!r||!h.lengthComputable)return;const T=h.total>0?h.loaded/h.total:0;r(Math.max(0,Math.min(1,T)))},l.onload=()=>{const h=l.status>=200&&l.status<300;let T=null;try{T=l.responseText?JSON.parse(l.responseText):null}catch{T=l.responseText}if(!h){S(new d(`Upload failed (HTTP ${l.status})`,l.status));return}const P=Se(T);e({ok:!0,files:P})},l.onerror=()=>{S(new d("Upload failed (network error)"))},l.onabort=()=>{S(new d("Upload cancelled"))};const f=new FormData;f.append("user",o),f.append("session",n),u&&f.append("prop",u),f.append("documents",s),l.open("POST",b),l.send(f)})}async function Te(t){const{id:o,session:n,prop:u,baseUrl:s}=t;if(!o)throw new d("missing id");if(!n)throw new d("missing session");const i=await fetch(M(s,"/loadattachments"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:o,session:n,prop:u})});if(!i.ok){const p=await J(i),b=typeof p=="string"?p:`Load attachments failed (HTTP ${i.status})`;throw new d(b,i.status)}const r=await i.json();return Array.isArray(r)&&r.every(p=>typeof p=="string")?r:[]}async function xe(t){const{id:o,session:n,prop:u,filename:s,baseUrl:i}=t;if(!o)throw new d("missing id");if(!n)throw new d("missing session");if(!s)throw new d("missing filename");const r=await fetch(M(i,"/deleteattachment"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:o,session:n,prop:u,filename:s})});if(!r.ok){const b=await J(r),e=typeof b=="string"?b:`Delete attachment failed (HTTP ${r.status})`;throw new d(e,r.status)}const p=await r.json();return p&&typeof p=="object"?p:{}}async function Ee(t){const{id:o,session:n,prop:u,baseUrl:s}=t;if(!o)throw new d("missing id");if(!n)throw new d("missing session");if(u)throw new d("prop is not supported for loadAttachmentsList");const i=await fetch(M(s,"/loadattachmentslist"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:o,session:n})});if(!i.ok){const b=await J(i),e=typeof b=="string"?b:`Load attachments list failed (HTTP ${i.status})`;throw new d(e,i.status)}const r=await i.json();if(!r||typeof r!="object"||Array.isArray(r))return{};const p={};for(const[b,e]of Object.entries(r))b&&Array.isArray(e)&&e.every(S=>typeof S=="string")&&(p[b]=e);return p}const Ue=["data-id"],ke={class:"row q-ml-md full-width items-center no-wrap"},_e={class:"col q-ml-md"},Ve={class:"row items-center no-wrap full-width"},Pe={class:"ellipsis"},K=".pdf, .docx, .txt, .md",Ne=G({__name:"SimpleAttachment",props:{modelValue:{},label:{},title:{},session:{},id:{},autoload:{type:Boolean},disable:{type:Boolean}},emits:["update:modelValue"],setup(t,{emit:o}){const n=t,u=o,{t:s}=Z(),i=ye(),r=X(),p=F(null),b=n.modelValue?.attachments,e=ce({comments:n.modelValue?.comments||"",attachments:Array.isArray(b)?[...b]:[]}),S=F(e.comments),l=F(null),f=F(!1),h=F([]),T=new Set(["pdf","docx","txt","md"]);function P(a){const m=(a.name||"").trim().toLowerCase(),w=m.includes(".")?m.split(".").pop():"";return!!w&&T.has(w)}const Q=O(()=>!!l.value),g=O(()=>{const a=l.value;return a?.name?a.name:(e.attachments.length>0?e.attachments[e.attachments.length-1]:"")||""}),v=O(()=>!l.value&&e.attachments.length>0);function y(a){for(;h.value.length<=a;)h.value.push({percent:0,color:"primary",icon:"attach_file"});const m=h.value[a];if(!m){const w={percent:0,color:"primary",icon:"attach_file"};return h.value[a]=w,w}return m}function k(){u("update:modelValue",{comments:e.comments||"",attachments:[...e.attachments]})}function I(a){if(a&&!P(a)){i.notify({type:"negative",message:s("fileTypeNotAllowed",{allowed:K})}),l.value=null,f.value=!1,h.value=[];return}l.value=a,f.value=!1,h.value=a?[{percent:0,color:"primary",icon:"attach_file"}]:[]}function te(a){const m=h.value;l.value=null;const w=[...m];w.splice(a,1),h.value=w}function ae(){te(0)}async function se(){const a=e.attachments.length>0?e.attachments[e.attachments.length-1]:"";if(!a)return;const m=n.session,w=n.id,D=r.id;if(!m||!D){e.attachments=[],k();return}try{await xe({id:D,session:m,...w?{prop:w}:{},filename:a}),e.attachments=[],k(),i.notify({type:"positive",message:s("fileDeleted")})}catch(C){i.notify({type:"negative",message:C instanceof Error?C.message:s("deleteFailed")})}}function ne(){if(!n.disable){if(l.value){ae();return}se()}}async function oe(){if(n.disable)return;const a=l.value;if(!a)return;if(!P(a)){i.notify({type:"negative",message:s("fileTypeNotAllowed",{allowed:K})});return}const m=n.session,w=n.id,D=r.id;if(!m||!D){i.notify({type:"warning",message:s("missingUserOrSession")});return}f.value=!0;try{const C=await Ae({user:D,session:m,...w?{prop:w}:{},file:a,onProgress:le=>{y(0).percent=le}}),_=y(0);_.percent=1,_.color="positive",_.icon="check";const j=C.files?.[0]??a.name;e.attachments.push(j),k(),i.notify({type:"positive",message:s("fileUploaded")})}catch(C){const _=y(0);_.color=C instanceof d&&C.message.includes("cancel")?"warning":"negative",_.icon=C instanceof d&&C.message.includes("cancel")?"close":"error";const j=C instanceof d&&C.message.includes("cancel");i.notify({type:_.color==="warning"?"warning":"negative",message:j?s("uploadCancelled"):C instanceof Error?C.message:s("uploadFailed")})}l.value=null,h.value=[],f.value=!1}B(()=>n.modelValue,a=>{a&&typeof a.comments=="string"?e.comments=a.comments:a===null&&(e.comments=""),a&&Array.isArray(a.attachments)?e.attachments=[...a.attachments]:a===null&&(e.attachments=[]),S.value=e.comments},{deep:!0});function ie(a){return Array.isArray(a)&&a.every(m=>typeof m=="string")}return W(async()=>{if(n.autoload===!1)return;const a=n.session,m=r.id;if(!(!a||!m))try{const w=await Te({id:m,session:a,...n.id?{prop:n.id}:{}});ie(w)&&(e.attachments=[...w],k())}catch{}}),(a,m)=>(A(),re("div",{class:"comment-attachment column full-width shadow-1 q-pa-sm bg-white","data-id":t.id},[E("div",null,$(t.title||t.label),1),E("div",ke,[E("div",_e,[U(ve,{ref_key:"fileRef",ref:p,"model-value":l.value,"onUpdate:modelValue":I,disable:!!t.disable,accept:".pdf,.docx,.txt,.md",dense:"",borderless:"","hide-bottom-space":"",clearable:!1,"input-style":"display: none",style:{"max-width":"400px"}},{prepend:V(()=>[E("div",Ve,[l.value?(A(),x(q,{key:1,round:"",dense:"",flat:"",color:"primary",icon:"cloud_upload",disable:!!t.disable||!Q.value||f.value,loading:f.value,onClick:Y(oe,["stop","prevent"])},null,8,["disable","loading"])):(A(),x(q,{key:0,round:"",dense:"",flat:"",color:"primary",icon:"attach_file",disable:!!t.disable||f.value,onClick:m[0]||(m[0]=Y(w=>p.value?.pickFiles(),["stop","prevent"]))},{default:V(()=>[U(he,null,{default:V(()=>[me($(c(s)("pickFiles")),1)]),_:1})]),_:1},8,["disable"])),g.value?(A(),x(ge,{key:2,dense:"",removable:!t.disable,class:"q-ml-sm comment-attachment__file-chip",color:v.value?"positive":void 0,"text-color":v.value?"white":void 0,onRemove:ne},{default:V(()=>[E("span",Pe,$(g.value),1)]),_:1},8,["removable","color","text-color"])):N("",!0)])]),_:1},8,["model-value","disable"])])])],8,Ue))}}),L=ee(Ne,[["__scopeId","data-v-a11712e8"]]),z="income:v1",R={employType:null,attachments:{salaryCertificate:{comments:"",attachments:[]},accountingDocuments:{comments:"",attachments:[]},avsCertificate:{comments:"",attachments:[]},lppCertificate:{comments:"",attachments:[]},unemploymentCertificate:{comments:"",attachments:[]}}};function De(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}const Fe=ue("incomestore",{state:()=>{try{let t=H.getItem(z);if(typeof t=="string")try{t=JSON.parse(t)}catch{t=null}if(De(t))return{data:{...R,...t}}}catch{}return{data:{...R}}},actions:{persist(){try{H.set(z,this.data)}catch(t){console.error("income.store: persist error",t)}},getIncome(){return this.data},setIncome(t){this.data={...this.data,...t},this.persist()},replaceIncome(t){this.data=t,this.persist()},resetIncome(){this.data={...R},this.persist()}}}),Le={class:"row items-center"},Oe={class:"col"},Ie={class:"text-h5"},$e={class:"col-auto"},qe=G({__name:"IncomeStep",props:{step:{}},emits:["next","prev"],setup(t,{emit:o}){const n=t,u=o,{t:s}=Z(),i=X(),r=Fe(),p=["EMPLOYED","SELF_EMPLOYED","PENSIONER","UNEMPLOYED"],b={EMPLOYED:{activeFields:["salaryCertificate","accountingDocuments"],nextStep:"marital"},SELF_EMPLOYED:{activeFields:["accountingDocuments"],nextStep:"marital"},PENSIONER:{activeFields:["accountingDocuments","avsCertificate","lppCertificate"],nextStep:"marital"},UNEMPLOYED:{activeFields:["unemploymentCertificate"],nextStep:"marital"}},e=r.data,S=["salaryCertificate","accountingDocuments","avsCertificate","lppCertificate","unemploymentCertificate"],l=O(()=>{const g=e.employType;if(!g)return new Set;const y=b[g]?.activeFields??[];return new Set(y)});function f(g){return l.value.has(g)}function h(){for(const g of S)f(g)||(e.attachments[g].comments="",e.attachments[g].attachments=[])}B(()=>e.employType,()=>{h()}),B(()=>e,()=>{r.persist()},{deep:!0});const T=O(()=>p.map(g=>({label:s(`income.employType.${g}`),value:g})));W(async()=>{const g=i.id;if(!g)return;const v="income";try{const y=await Ee({id:g,session:v});for(const k of S){const I=y[k];Array.isArray(I)&&(e.attachments[k].attachments=[...I])}}catch{}});function P(){u("next",n.step?.next)}function Q(){u("prev",n.step?.prev)}return(g,v)=>(A(),x(fe,{flat:"",class:"full-width q-pa-none"},{default:V(()=>[U(de,{class:"full-width"},{default:V(()=>[E("div",Le,[E("div",Oe,[E("div",Ie,$(c(s)("INC")),1)]),E("div",$e,[U(q,{flat:"",label:c(s)("button.prev"),onClick:Q,class:"q-mr-sm"},null,8,["label"]),U(q,{color:"primary",label:c(s)("button.next"),onClick:P},null,8,["label"])])]),U(pe,{class:"q-my-sm"}),U(we,{class:"q-gutter-md q-mt-md"},{default:V(()=>[U(be,{modelValue:c(e).employType,"onUpdate:modelValue":v[0]||(v[0]=y=>c(e).employType=y),options:T.value,label:c(s)("income.employTypeLabel"),hint:c(e).employType?"":c(s)("income.employTypeHint"),"persistent-hint":!c(e).employType,"emit-value":"","map-options":""},null,8,["modelValue","options","label","hint","persistent-hint"]),f("salaryCertificate")?(A(),x(L,{key:0,modelValue:c(e).attachments.salaryCertificate,"onUpdate:modelValue":v[1]||(v[1]=y=>c(e).attachments.salaryCertificate=y),label:c(s)("income.attachments.salaryCertificate"),session:"income",id:"salaryCertificate",autoload:!1},null,8,["modelValue","label"])):N("",!0),f("accountingDocuments")?(A(),x(L,{key:1,modelValue:c(e).attachments.accountingDocuments,"onUpdate:modelValue":v[2]||(v[2]=y=>c(e).attachments.accountingDocuments=y),label:c(s)("income.attachments.accountingDocuments"),session:"income",id:"accountingDocuments",autoload:!1},null,8,["modelValue","label"])):N("",!0),f("avsCertificate")?(A(),x(L,{key:2,modelValue:c(e).attachments.avsCertificate,"onUpdate:modelValue":v[3]||(v[3]=y=>c(e).attachments.avsCertificate=y),label:c(s)("income.attachments.avsCertificate"),session:"income",id:"avsCertificate",autoload:!1},null,8,["modelValue","label"])):N("",!0),f("lppCertificate")?(A(),x(L,{key:3,modelValue:c(e).attachments.lppCertificate,"onUpdate:modelValue":v[4]||(v[4]=y=>c(e).attachments.lppCertificate=y),label:c(s)("income.attachments.lppCertificate"),session:"income",id:"lppCertificate",autoload:!1},null,8,["modelValue","label"])):N("",!0),f("unemploymentCertificate")?(A(),x(L,{key:4,modelValue:c(e).attachments.unemploymentCertificate,"onUpdate:modelValue":v[5]||(v[5]=y=>c(e).attachments.unemploymentCertificate=y),label:c(s)("income.attachments.unemploymentCertificate"),session:"income",id:"unemploymentCertificate",autoload:!1},null,8,["modelValue","label"])):N("",!0)]),_:1})]),_:1})]),_:1}))}}),Ye=ee(qe,[["__scopeId","data-v-f4f9035e"]]);export{Ye as default};