Changeset 3155896
- Timestamp:
- 09/22/2024 11:29:07 AM (17 months ago)
- Location:
- my-easy-compta/trunk
- Files:
-
- 6 edited
-
assets/dist/app.min.css (modified) (3 diffs)
-
assets/dist/index.min.js (modified) (1 diff)
-
includes/Modules/Invoices.php (modified) (1 diff)
-
includes/Modules/Payments.php (modified) (3 diffs)
-
my-easy-compta.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
my-easy-compta/trunk/assets/dist/app.min.css
r3144896 r3155896 3265 3265 border-start-end-radius: inherit; 3266 3266 } 3267 .select- sm{3268 height: 2rem;3269 min-height: 2rem;3270 padding-left: 0.75rem;3271 padding-right: 2 rem;3267 .select-md{ 3268 height: 3rem; 3269 min-height: 3rem; 3270 padding-left: 1rem; 3271 padding-right: 2.5rem; 3272 3272 font-size: 0.875rem; 3273 line-height: 2rem; 3274 } 3275 [dir="rtl"] .select-sm{ 3276 padding-left: 2rem; 3277 padding-right: 0.75rem; 3273 line-height: 1.25rem; 3274 line-height: 2; 3275 } 3276 [dir="rtl"] .select-md{ 3277 padding-left: 2.5rem; 3278 padding-right: 1rem; 3278 3279 } 3279 3280 .select-xs{ … … 3663 3664 margin-right: 0.5rem; 3664 3665 } 3666 .mx-auto{ 3667 margin-left: auto; 3668 margin-right: auto; 3669 } 3665 3670 .my-1{ 3666 3671 margin-top: 0.25rem; … … 4350 4355 } 4351 4356 } 4352 4353 .invalid\:\[\&\:not\(\:-moz-placeholder-shown\)\:not\(\:focus\)\]\:border-red-500:not(:-moz-placeholder-shown):not(:focus):invalid{4354 --tw-border-opacity: 1;4355 border-color: rgb(239 68 68 / var(--tw-border-opacity));4356 }4357 4358 .invalid\:\[\&\:not\(\:placeholder-shown\)\:not\(\:focus\)\]\:border-red-500:not(:placeholder-shown):not(:focus):invalid{4359 --tw-border-opacity: 1;4360 border-color: rgb(239 68 68 / var(--tw-border-opacity));4361 } -
my-easy-compta/trunk/assets/dist/index.min.js
r3155882 r3155896 1 import{s as Ps,u as ut,q as js,x as Ms,y as Jn,z as qs,A as yt,B as Ce,h as Kn,C as Kt,D as Os,E as Vs,_ as oe,d as M,o as c,c as d,n as k,a as i,t as l,g,e as P,p as re,i as F,v as J,j as Ie,m as w,w as K,F as X,r as U,G as Zn,H as Rs}from"./plugin-vue_export-helper.min.js";import{C as Ue,R as xt}from"./RemoveAlert.min.js";import{T as Lt}from"./VueSearchSelect.min.js";import{V as It}from"./vue-datepicker.min.js";import{f as zt,c as $n,a as es,g as ts,b as ns,s as ss}from"./api.min.js";import{v as Et}from"./vue3-editor.common.min.js";/*!1 import{s as Ps,u as ut,q as Ms,x as js,y as Jn,z as qs,A as yt,B as Ce,h as Kn,C as Kt,D as Os,E as Vs,_ as oe,d as j,o as r,c,n as k,a as i,t as l,g as _,e as P,p as re,i as B,v as J,j as ve,m as w,w as K,F as W,r as U,G as Zn,H as Rs}from"./plugin-vue_export-helper.min.js";import{C as Ue,R as xt}from"./RemoveAlert.min.js";import{T as Lt}from"./VueSearchSelect.min.js";import{V as It}from"./vue-datepicker.min.js";import{f as zt,c as $n,a as es,g as ts,b as ns,s as ss}from"./api.min.js";import{v as Et}from"./vue3-editor.common.min.js";/*! 2 2 * vue-router v4.4.0 3 3 * (c) 2024 Eduardo San Martin Morote 4 4 * @license MIT 5 */const Ke=typeof document!="undefined";function Ns(t){return t.__esModule||t[Symbol.toStringTag]==="Module"}const Q=Object.assign;function Zt(t,e){const s={};for(const a in e){const n=e[a];s[a]=Ee(n)?n.map(t):t(n)}return s}const ht=()=>{},Ee=Array.isArray,os=/#/g,Bs=/&/g,Fs=/\//g,Ws=/=/g,Xs=/\?/g,is=/\+/g,Us=/%5B/g,Qs=/%5D/g,as=/%5E/g,Ls=/%60/g,ls=/%7B/g,zs=/%7C/g,rs=/%7D/g,Hs=/%20/g;function vn(t){return encodeURI(""+t).replace(zs,"|").replace(Us,"[").replace(Qs,"]")}function Gs(t){return vn(t).replace(ls,"{").replace(rs,"}").replace(as,"^")}function un(t){return vn(t).replace(is,"%2B").replace(Hs,"+").replace(os,"%23").replace(Bs,"%26").replace(Ls,"`").replace(ls,"{").replace(rs,"}").replace(as,"^")}function Ys(t){return un(t).replace(Ws,"%3D")}function Js(t){return vn(t).replace(os,"%23").replace(Xs,"%3F")}function Ks(t){return t==null?"":Js(t).replace(Fs,"%2F")}function bt(t){try{return decodeURIComponent(""+t)}catch{}return""+t}const Zs=/\/$/,$s=t=>t.replace(Zs,"");function $t(t,e,s="/"){let a,n={},o="", f="";const h=e.indexOf("#");let m=e.indexOf("?");return h<m&&h>=0&&(m=-1),m>-1&&(a=e.slice(0,m),o=e.slice(m+1,h>-1?h:e.length),n=t(o)),h>-1&&(a=a||e.slice(0,h),f=e.slice(h,e.length)),a=so(a!=null?a:e,s),{fullPath:a+(o&&"?")+o+f,path:a,query:n,hash:bt(f)}}function eo(t,e){const s=e.query?t(e.query):"";return e.path+(s&&"?")+s+(e.hash||"")}function Cn(t,e){return!e||!t.toLowerCase().startsWith(e.toLowerCase())?t:t.slice(e.length)||"/"}function to(t,e,s){const a=e.matched.length-1,n=s.matched.length-1;return a>-1&&a===n&&tt(e.matched[a],s.matched[n])&&cs(e.params,s.params)&&t(e.query)===t(s.query)&&e.hash===s.hash}function tt(t,e){return(t.aliasOf||t)===(e.aliasOf||e)}function cs(t,e){if(Object.keys(t).length!==Object.keys(e).length)return!1;for(const s in t)if(!no(t[s],e[s]))return!1;return!0}function no(t,e){return Ee(t)?kn(t,e):Ee(e)?kn(e,t):t===e}function kn(t,e){return Ee(e)?t.length===e.length&&t.every((s,a)=>s===e[a]):t.length===1&&t[0]===e}function so(t,e){if(t.startsWith("/"))return t;if(!t)return e;const s=e.split("/"),a=t.split("/"),n=a[a.length-1];(n===".."||n===".")&&a.push("");let o=s.length-1,f,h;for(f=0;f<a.length;f++)if(h=a[f],h!==".")if(h==="..")o>1&&o--;else break;return s.slice(0,o).join("/")+"/"+a.slice(f).join("/")}const Ne={path:"/",name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0};var wt;(function(t){t.pop="pop",t.push="push"})(wt||(wt={}));var mt;(function(t){t.back="back",t.forward="forward",t.unknown=""})(mt||(mt={}));function oo(t){if(!t)if(Ke){const e=document.querySelector("base");t=e&&e.getAttribute("href")||"/",t=t.replace(/^\w+:\/\/[^\/]+/,"")}else t="/";return t[0]!=="/"&&t[0]!=="#"&&(t="/"+t),$s(t)}const io=/^[^#]+#/;function ao(t,e){return t.replace(io,"#")+e}function lo(t,e){const s=document.documentElement.getBoundingClientRect(),a=t.getBoundingClientRect();return{behavior:e.behavior,left:a.left-s.left-(e.left||0),top:a.top-s.top-(e.top||0)}}const Ht=()=>({left:window.scrollX,top:window.scrollY});function ro(t){let e;if("el"in t){const s=t.el,a=typeof s=="string"&&s.startsWith("#"),n=typeof s=="string"?a?document.getElementById(s.slice(1)):document.querySelector(s):s;if(!n)return;e=lo(n,t)}else e=t;"scrollBehavior"in document.documentElement.style?window.scrollTo(e):window.scrollTo(e.left!=null?e.left:window.scrollX,e.top!=null?e.top:window.scrollY)}function Tn(t,e){return(history.state?history.state.position-e:-1)+t}const hn=new Map;function co(t,e){hn.set(t,e)}function uo(t){const e=hn.get(t);return hn.delete(t),e}let ho=()=>location.protocol+"//"+location.host;function ds(t,e){const{pathname:s,search:a,hash:n}=e,o=t.indexOf("#");if(o>-1){let h=n.includes(t.slice(o))?t.slice(o).length:1,m=n.slice(h);return m[0]!=="/"&&(m="/"+m),Cn(m,"")}return Cn(s,t)+a+n}function mo(t,e,s,a){let n=[],o=[],f=null;const h=({state:_})=>{const v=ds(t,location),I=s.value,C=e.value;let V=0;if(_){if(s.value=v,e.value=_,f&&f===I){f=null;return}V=C?_.position-C.position:0}else a(v);n.forEach(B=>{B(s.value,I,{delta:V,type:wt.pop,direction:V?V>0?mt.forward:mt.back:mt.unknown})})};function m(){f=s.value}function r(_){n.push(_);const v=()=>{const I=n.indexOf(_);I>-1&&n.splice(I,1)};return o.push(v),v}function u(){const{history:_}=window;!_.state||_.replaceState(Q({},_.state,{scroll:Ht()}),"")}function p(){for(const _ of o)_();o=[],window.removeEventListener("popstate",h),window.removeEventListener("beforeunload",u)}return window.addEventListener("popstate",h),window.addEventListener("beforeunload",u,{passive:!0}),{pauseListeners:m,listen:r,destroy:p}}function An(t,e,s,a=!1,n=!1){return{back:t,current:e,forward:s,replaced:a,position:window.history.length,scroll:n?Ht():null}}function fo(t){const{history:e,location:s}=window,a={value:ds(t,s)},n={value:e.state};n.value||o(a.value,{back:null,current:a.value,forward:null,position:e.length-1,replaced:!0,scroll:null},!0);function o(m,r,u){const p=t.indexOf("#"),_=p>-1?(s.host&&document.querySelector("base")?t:t.slice(p))+m:ho()+t+m;try{e[u?"replaceState":"pushState"](r,"",_),n.value=r}catch(v){console.error(v),s[u?"replace":"assign"](_)}}function f(m,r){const u=Q({},e.state,An(n.value.back,m,n.value.forward,!0),r,{position:n.value.position});o(m,u,!0),a.value=m}function h(m,r){const u=Q({},n.value,e.state,{forward:m,scroll:Ht()});o(u.current,u,!0);const p=Q({},An(a.value,m,null),{position:u.position+1},r);o(m,p,!1),a.value=m}return{location:a,state:n,push:h,replace:f}}function po(t){t=oo(t);const e=fo(t),s=mo(t,e.state,e.location,e.replace);function a(o,f=!0){f||s.pauseListeners(),history.go(o)}const n=Q({location:"",base:t,go:a,createHref:ao.bind(null,t)},e,s);return Object.defineProperty(n,"location",{enumerable:!0,get:()=>e.location.value}),Object.defineProperty(n,"state",{enumerable:!0,get:()=>e.state.value}),n}function _o(t){return t=location.host?t||location.pathname+location.search:"",t.includes("#")||(t+="#"),po(t)}function go(t){return typeof t=="string"||t&&typeof t=="object"}function us(t){return typeof t=="string"||typeof t=="symbol"}const hs=Symbol("");var Sn;(function(t){t[t.aborted=4]="aborted",t[t.cancelled=8]="cancelled",t[t.duplicated=16]="duplicated"})(Sn||(Sn={}));function nt(t,e){return Q(new Error,{type:t,[hs]:!0},e)}function je(t,e){return t instanceof Error&&hs in t&&(e==null||!!(t.type&e))}const Dn="[^/]+?",vo={sensitive:!1,strict:!1,start:!0,end:!0},yo=/[.+*?^${}()[\]/\\]/g;function bo(t,e){const s=Q({},vo,e),a=[];let n=s.start?"^":"";const o=[];for(const r of t){const u=r.length?[]:[90];s.strict&&!r.length&&(n+="/");for(let p=0;p<r.length;p++){const _=r[p];let v=40+(s.sensitive?.25:0);if(_.type===0)p||(n+="/"),n+=_.value.replace(yo,"\\$&"),v+=40;else if(_.type===1){const{value:I,repeatable:C,optional:V,regexp:B}=_;o.push({name:I,repeatable:C,optional:V});const D=B||Dn;if(D!==Dn){v+=10;try{new RegExp(`(${D})`)}catch(z){throw new Error(`Invalid custom RegExp for param "${I}" (${D}): `+z.message)}}let q=C?`((?:${D})(?:/(?:${D}))*)`:`(${D})`;p||(q=V&&r.length<2?`(?:/${q})`:"/"+q),V&&(q+="?"),n+=q,v+=20,V&&(v+=-8),C&&(v+=-20),D===".*"&&(v+=-50)}u.push(v)}a.push(u)}if(s.strict&&s.end){const r=a.length-1;a[r][a[r].length-1]+=.7000000000000001}s.strict||(n+="/?"),s.end?n+="$":s.strict&&(n+="(?:/|$)");const f=new RegExp(n,s.sensitive?"":"i");function h(r){const u=r.match(f),p={};if(!u)return null;for(let _=1;_<u.length;_++){const v=u[_]||"",I=o[_-1];p[I.name]=v&&I.repeatable?v.split("/"):v}return p}function m(r){let u="",p=!1;for(const _ of t){(!p||!u.endsWith("/"))&&(u+="/"),p=!1;for(const v of _)if(v.type===0)u+=v.value;else if(v.type===1){const{value:I,repeatable:C,optional:V}=v,B=I in r?r[I]:"";if(Ee(B)&&!C)throw new Error(`Provided param "${I}" is an array but it is not repeatable (* or + modifiers)`);const D=Ee(B)?B.join("/"):B;if(!D)if(V)_.length<2&&(u.endsWith("/")?u=u.slice(0,-1):p=!0);else throw new Error(`Missing required param "${I}"`);u+=D}}return u||"/"}return{re:f,score:a,keys:o,parse:h,stringify:m}}function wo(t,e){let s=0;for(;s<t.length&&s<e.length;){const a=e[s]-t[s];if(a)return a;s++}return t.length<e.length?t.length===1&&t[0]===40+40?-1:1:t.length>e.length?e.length===1&&e[0]===40+40?1:-1:0}function ms(t,e){let s=0;const a=t.score,n=e.score;for(;s<a.length&&s<n.length;){const o=wo(a[s],n[s]);if(o)return o;s++}if(Math.abs(n.length-a.length)===1){if(Pn(a))return 1;if(Pn(n))return-1}return n.length-a.length}function Pn(t){const e=t[t.length-1];return t.length>0&&e[e.length-1]<0}const xo={type:0,value:""},Io=/[a-zA-Z0-9_]/;function Eo(t){if(!t)return[[]];if(t==="/")return[[xo]];if(!t.startsWith("/"))throw new Error(`Invalid path "${t}"`);function e(v){throw new Error(`ERR (${s})/"${r}": ${v}`)}let s=0,a=s;const n=[];let o;function f(){o&&n.push(o),o=[]}let h=0,m,r="",u="";function p(){!r||(s===0?o.push({type:0,value:r}):s===1||s===2||s===3?(o.length>1&&(m==="*"||m==="+")&&e(`A repeatable param (${r}) must be alone in its segment. eg: '/:ids+.`),o.push({type:1,value:r,regexp:u,repeatable:m==="*"||m==="+",optional:m==="*"||m==="?"})):e("Invalid state to consume buffer"),r="")}function _(){r+=m}for(;h<t.length;){if(m=t[h++],m==="\\"&&s!==2){a=s,s=4;continue}switch(s){case 0:m==="/"?(r&&p(),f()):m===":"?(p(),s=1):_();break;case 4:_(),s=a;break;case 1:m==="("?s=2:Io.test(m)?_():(p(),s=0,m!=="*"&&m!=="?"&&m!=="+"&&h--);break;case 2:m===")"?u[u.length-1]=="\\"?u=u.slice(0,-1)+m:s=3:u+=m;break;case 3:p(),s=0,m!=="*"&&m!=="?"&&m!=="+"&&h--,u="";break;default:e("Unknown state");break}}return s===2&&e(`Unfinished custom RegExp for param "${r}"`),p(),f(),n}function Co(t,e,s){const a=bo(Eo(t.path),s),n=Q(a,{record:t,parent:e,children:[],alias:[]});return e&&!n.record.aliasOf==!e.record.aliasOf&&e.children.push(n),n}function ko(t,e){const s=[],a=new Map;e=qn({strict:!1,end:!0,sensitive:!1},e);function n(p){return a.get(p)}function o(p,_,v){const I=!v,C=To(p);C.aliasOf=v&&v.record;const V=qn(e,p),B=[C];if("alias"in p){const z=typeof p.alias=="string"?[p.alias]:p.alias;for(const ce of z)B.push(Q({},C,{components:v?v.record.components:C.components,path:ce,aliasOf:v?v.record:C}))}let D,q;for(const z of B){const{path:ce}=z;if(_&&ce[0]!=="/"){const ne=_.record.path,Z=ne[ne.length-1]==="/"?"":"/";z.path=_.record.path+(ce&&Z+ce)}if(D=Co(z,_,V),v?v.alias.push(D):(q=q||D,q!==D&&q.alias.push(D),I&&p.name&&!Mn(D)&&f(p.name)),fs(D)&&m(D),C.children){const ne=C.children;for(let Z=0;Z<ne.length;Z++)o(ne[Z],D,v&&v.children[Z])}v=v||D}return q?()=>{f(q)}:ht}function f(p){if(us(p)){const _=a.get(p);_&&(a.delete(p),s.splice(s.indexOf(_),1),_.children.forEach(f),_.alias.forEach(f))}else{const _=s.indexOf(p);_>-1&&(s.splice(_,1),p.record.name&&a.delete(p.record.name),p.children.forEach(f),p.alias.forEach(f))}}function h(){return s}function m(p){const _=Do(p,s);s.splice(_,0,p),p.record.name&&!Mn(p)&&a.set(p.record.name,p)}function r(p,_){let v,I={},C,V;if("name"in p&&p.name){if(v=a.get(p.name),!v)throw nt(1,{location:p});V=v.record.name,I=Q(jn(_.params,v.keys.filter(q=>!q.optional).concat(v.parent?v.parent.keys.filter(q=>q.optional):[]).map(q=>q.name)),p.params&&jn(p.params,v.keys.map(q=>q.name))),C=v.stringify(I)}else if(p.path!=null)C=p.path,v=s.find(q=>q.re.test(C)),v&&(I=v.parse(C),V=v.record.name);else{if(v=_.name?a.get(_.name):s.find(q=>q.re.test(_.path)),!v)throw nt(1,{location:p,currentLocation:_});V=v.record.name,I=Q({},_.params,p.params),C=v.stringify(I)}const B=[];let D=v;for(;D;)B.unshift(D.record),D=D.parent;return{name:V,path:C,params:I,matched:B,meta:So(B)}}t.forEach(p=>o(p));function u(){s.length=0,a.clear()}return{addRoute:o,resolve:r,removeRoute:f,clearRoutes:u,getRoutes:h,getRecordMatcher:n}}function jn(t,e){const s={};for(const a of e)a in t&&(s[a]=t[a]);return s}function To(t){return{path:t.path,redirect:t.redirect,name:t.name,meta:t.meta||{},aliasOf:void 0,beforeEnter:t.beforeEnter,props:Ao(t),children:t.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},components:"components"in t?t.components||null:t.component&&{default:t.component}}}function Ao(t){const e={},s=t.props||!1;if("component"in t)e.default=s;else for(const a in t.components)e[a]=typeof s=="object"?s[a]:s;return e}function Mn(t){for(;t;){if(t.record.aliasOf)return!0;t=t.parent}return!1}function So(t){return t.reduce((e,s)=>Q(e,s.meta),{})}function qn(t,e){const s={};for(const a in t)s[a]=a in e?e[a]:t[a];return s}function Do(t,e){let s=0,a=e.length;for(;s!==a;){const o=s+a>>1;ms(t,e[o])<0?a=o:s=o+1}const n=Po(t);return n&&(a=e.lastIndexOf(n,a-1)),a}function Po(t){let e=t;for(;e=e.parent;)if(fs(e)&&ms(t,e)===0)return e}function fs({record:t}){return!!(t.name||t.components&&Object.keys(t.components).length||t.redirect)}function jo(t){const e={};if(t===""||t==="?")return e;const a=(t[0]==="?"?t.slice(1):t).split("&");for(let n=0;n<a.length;++n){const o=a[n].replace(is," "),f=o.indexOf("="),h=bt(f<0?o:o.slice(0,f)),m=f<0?null:bt(o.slice(f+1));if(h in e){let r=e[h];Ee(r)||(r=e[h]=[r]),r.push(m)}else e[h]=m}return e}function On(t){let e="";for(let s in t){const a=t[s];if(s=Ys(s),a==null){a!==void 0&&(e+=(e.length?"&":"")+s);continue}(Ee(a)?a.map(o=>o&&un(o)):[a&&un(a)]).forEach(o=>{o!==void 0&&(e+=(e.length?"&":"")+s,o!=null&&(e+="="+o))})}return e}function Mo(t){const e={};for(const s in t){const a=t[s];a!==void 0&&(e[s]=Ee(a)?a.map(n=>n==null?null:""+n):a==null?a:""+a)}return e}const qo=Symbol(""),Vn=Symbol(""),yn=Symbol(""),ps=Symbol(""),mn=Symbol("");function lt(){let t=[];function e(a){return t.push(a),()=>{const n=t.indexOf(a);n>-1&&t.splice(n,1)}}function s(){t=[]}return{add:e,list:()=>t.slice(),reset:s}}function Be(t,e,s,a,n,o=f=>f()){const f=a&&(a.enterCallbacks[n]=a.enterCallbacks[n]||[]);return()=>new Promise((h,m)=>{const r=_=>{_===!1?m(nt(4,{from:s,to:e})):_ instanceof Error?m(_):go(_)?m(nt(2,{from:e,to:_})):(f&&a.enterCallbacks[n]===f&&typeof _=="function"&&f.push(_),h())},u=o(()=>t.call(a&&a.instances[n],e,s,r));let p=Promise.resolve(u);t.length<3&&(p=p.then(r)),p.catch(_=>m(_))})}function en(t,e,s,a,n=o=>o()){const o=[];for(const f of t)for(const h in f.components){let m=f.components[h];if(!(e!=="beforeRouteEnter"&&!f.instances[h]))if(Oo(m)){const u=(m.__vccOpts||m)[e];u&&o.push(Be(u,s,a,f,h,n))}else{let r=m();o.push(()=>r.then(u=>{if(!u)return Promise.reject(new Error(`Couldn't resolve component "${h}" at "${f.path}"`));const p=Ns(u)?u.default:u;f.components[h]=p;const v=(p.__vccOpts||p)[e];return v&&Be(v,s,a,f,h,n)()}))}}return o}function Oo(t){return typeof t=="object"||"displayName"in t||"props"in t||"__vccOpts"in t}function Rn(t){const e=yt(yn),s=yt(ps),a=Ce(()=>{const m=ut(t.to);return e.resolve(m)}),n=Ce(()=>{const{matched:m}=a.value,{length:r}=m,u=m[r-1],p=s.matched;if(!u||!p.length)return-1;const _=p.findIndex(tt.bind(null,u));if(_>-1)return _;const v=Nn(m[r-2]);return r>1&&Nn(u)===v&&p[p.length-1].path!==v?p.findIndex(tt.bind(null,m[r-2])):_}),o=Ce(()=>n.value>-1&&Bo(s.params,a.value.params)),f=Ce(()=>n.value>-1&&n.value===s.matched.length-1&&cs(s.params,a.value.params));function h(m={}){return No(m)?e[ut(t.replace)?"replace":"push"](ut(t.to)).catch(ht):Promise.resolve()}return{route:a,href:Ce(()=>a.value.href),isActive:o,isExactActive:f,navigate:h}}const Vo=Jn({name:"RouterLink",compatConfig:{MODE:3},props:{to:{type:[String,Object],required:!0},replace:Boolean,activeClass:String,exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},useLink:Rn,setup(t,{slots:e}){const s=qs(Rn(t)),{options:a}=yt(yn),n=Ce(()=>({[Bn(t.activeClass,a.linkActiveClass,"router-link-active")]:s.isActive,[Bn(t.exactActiveClass,a.linkExactActiveClass,"router-link-exact-active")]:s.isExactActive}));return()=>{const o=e.default&&e.default(s);return t.custom?o:Kn("a",{"aria-current":s.isExactActive?t.ariaCurrentValue:null,href:s.href,onClick:s.navigate,class:n.value},o)}}}),Ro=Vo;function No(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)&&!t.defaultPrevented&&!(t.button!==void 0&&t.button!==0)){if(t.currentTarget&&t.currentTarget.getAttribute){const e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function Bo(t,e){for(const s in e){const a=e[s],n=t[s];if(typeof a=="string"){if(a!==n)return!1}else if(!Ee(n)||n.length!==a.length||a.some((o,f)=>o!==n[f]))return!1}return!0}function Nn(t){return t?t.aliasOf?t.aliasOf.path:t.path:""}const Bn=(t,e,s)=>t!=null?t:e!=null?e:s,Fo=Jn({name:"RouterView",inheritAttrs:!1,props:{name:{type:String,default:"default"},route:Object},compatConfig:{MODE:3},setup(t,{attrs:e,slots:s}){const a=yt(mn),n=Ce(()=>t.route||a.value),o=yt(Vn,0),f=Ce(()=>{let r=ut(o);const{matched:u}=n.value;let p;for(;(p=u[r])&&!p.components;)r++;return r}),h=Ce(()=>n.value.matched[f.value]);Kt(Vn,Ce(()=>f.value+1)),Kt(qo,h),Kt(mn,n);const m=Os();return Vs(()=>[m.value,h.value,t.name],([r,u,p],[_,v,I])=>{u&&(u.instances[p]=r,v&&v!==u&&r&&r===_&&(u.leaveGuards.size||(u.leaveGuards=v.leaveGuards),u.updateGuards.size||(u.updateGuards=v.updateGuards))),r&&u&&(!v||!tt(u,v)||!_)&&(u.enterCallbacks[p]||[]).forEach(C=>C(r))},{flush:"post"}),()=>{const r=n.value,u=t.name,p=h.value,_=p&&p.components[u];if(!_)return Fn(s.default,{Component:_,route:r});const v=p.props[u],I=v?v===!0?r.params:typeof v=="function"?v(r):v:null,V=Kn(_,Q({},I,e,{onVnodeUnmounted:B=>{B.component.isUnmounted&&(p.instances[u]=null)},ref:m}));return Fn(s.default,{Component:V,route:r})||V}}});function Fn(t,e){if(!t)return null;const s=t(e);return s.length===1?s[0]:s}const Wo=Fo;function Xo(t){const e=ko(t.routes,t),s=t.parseQuery||jo,a=t.stringifyQuery||On,n=t.history,o=lt(),f=lt(),h=lt(),m=Ps(Ne);let r=Ne;Ke&&t.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const u=Zt.bind(null,y=>""+y),p=Zt.bind(null,Ks),_=Zt.bind(null,bt);function v(y,E){let x,T;return us(y)?(x=e.getRecordMatcher(y),T=E):T=y,e.addRoute(T,x)}function I(y){const E=e.getRecordMatcher(y);E&&e.removeRoute(E)}function C(){return e.getRoutes().map(y=>y.record)}function V(y){return!!e.getRecordMatcher(y)}function B(y,E){if(E=Q({},E||m.value),typeof y=="string"){const O=$t(s,y,E.path),se=e.resolve({path:O.path},E),at=n.createHref(O.fullPath);return Q(O,se,{params:_(se.params),hash:bt(O.hash),redirectedFrom:void 0,href:at})}let x;if(y.path!=null)x=Q({},y,{path:$t(s,y.path,E.path).path});else{const O=Q({},y.params);for(const se in O)O[se]==null&&delete O[se];x=Q({},y,{params:p(O)}),E.params=p(E.params)}const T=e.resolve(x,E),L=y.hash||"";T.params=u(_(T.params));const $=eo(a,Q({},y,{hash:Gs(L),path:T.path})),R=n.createHref($);return Q({fullPath:$,hash:L,query:a===On?Mo(y.query):y.query||{}},T,{redirectedFrom:void 0,href:R})}function D(y){return typeof y=="string"?$t(s,y,m.value.path):Q({},y)}function q(y,E){if(r!==y)return nt(8,{from:E,to:y})}function z(y){return Z(y)}function ce(y){return z(Q(D(y),{replace:!0}))}function ne(y){const E=y.matched[y.matched.length-1];if(E&&E.redirect){const{redirect:x}=E;let T=typeof x=="function"?x(y):x;return typeof T=="string"&&(T=T.includes("?")||T.includes("#")?T=D(T):{path:T},T.params={}),Q({query:y.query,hash:y.hash,params:T.path!=null?{}:y.params},T)}}function Z(y,E){const x=r=B(y),T=m.value,L=y.state,$=y.force,R=y.replace===!0,O=ne(x);if(O)return Z(Q(D(O),{state:typeof O=="object"?Q({},L,O.state):L,force:$,replace:R}),E||x);const se=x;se.redirectedFrom=E;let at;return!$&&to(a,T,x)&&(at=nt(16,{to:se,from:T}),ot(T,T,!0,!1)),(at?Promise.resolve(at):Ve(se,T)).catch(he=>je(he)?je(he,2)?he:Tt(he):Pe(he,se,T)).then(he=>{if(he){if(je(he,2))return Z(Q({replace:R},D(he.to),{state:typeof he.to=="object"?Q({},L,he.to.state):L,force:$}),E||se)}else he=Re(se,T,!0,R,L);return ve(se,T,he),he})}function Qe(y,E){const x=q(y,E);return x?Promise.reject(x):Promise.resolve()}function ie(y){const E=At.values().next().value;return E&&typeof E.runWithContext=="function"?E.runWithContext(y):y()}function Ve(y,E){let x;const[T,L,$]=Uo(y,E);x=en(T.reverse(),"beforeRouteLeave",y,E);for(const O of T)O.leaveGuards.forEach(se=>{x.push(Be(se,y,E))});const R=Qe.bind(null,y,E);return x.push(R),Ge(x).then(()=>{x=[];for(const O of o.list())x.push(Be(O,y,E));return x.push(R),Ge(x)}).then(()=>{x=en(L,"beforeRouteUpdate",y,E);for(const O of L)O.updateGuards.forEach(se=>{x.push(Be(se,y,E))});return x.push(R),Ge(x)}).then(()=>{x=[];for(const O of $)if(O.beforeEnter)if(Ee(O.beforeEnter))for(const se of O.beforeEnter)x.push(Be(se,y,E));else x.push(Be(O.beforeEnter,y,E));return x.push(R),Ge(x)}).then(()=>(y.matched.forEach(O=>O.enterCallbacks={}),x=en($,"beforeRouteEnter",y,E,ie),x.push(R),Ge(x))).then(()=>{x=[];for(const O of f.list())x.push(Be(O,y,E));return x.push(R),Ge(x)}).catch(O=>je(O,8)?O:Promise.reject(O))}function ve(y,E,x){h.list().forEach(T=>ie(()=>T(y,E,x)))}function Re(y,E,x,T,L){const $=q(y,E);if($)return $;const R=E===Ne,O=Ke?history.state:{};x&&(T||R?n.replace(y.fullPath,Q({scroll:R&&O&&O.scroll},L)):n.push(y.fullPath,L)),m.value=y,ot(y,E,x,R),Tt()}let de;function Ae(){de||(de=n.listen((y,E,x)=>{if(!En.listening)return;const T=B(y),L=ne(T);if(L){Z(Q(L,{replace:!0}),T).catch(ht);return}r=T;const $=m.value;Ke&&co(Tn($.fullPath,x.delta),Ht()),Ve(T,$).catch(R=>je(R,12)?R:je(R,2)?(Z(R.to,T).then(O=>{je(O,20)&&!x.delta&&x.type===wt.pop&&n.go(-1,!1)}).catch(ht),Promise.reject()):(x.delta&&n.go(-x.delta,!1),Pe(R,T,$))).then(R=>{R=R||Re(T,$,!1),R&&(x.delta&&!je(R,8)?n.go(-x.delta,!1):x.type===wt.pop&&je(R,20)&&n.go(-1,!1)),ve(T,$,R)}).catch(ht)}))}let Se=lt(),ye=lt(),De;function Pe(y,E,x){Tt(y);const T=ye.list();return T.length?T.forEach(L=>L(y,E,x)):console.error(y),Promise.reject(y)}function Yt(){return De&&m.value!==Ne?Promise.resolve():new Promise((y,E)=>{Se.add([y,E])})}function Tt(y){return De||(De=!y,Ae(),Se.list().forEach(([E,x])=>y?x(y):E()),Se.reset()),y}function ot(y,E,x,T){const{scrollBehavior:L}=t;if(!Ke||!L)return Promise.resolve();const $=!x&&uo(Tn(y.fullPath,0))||(T||!x)&&history.state&&history.state.scroll||null;return Ms().then(()=>L(y,E,$)).then(R=>R&&ro(R)).catch(R=>Pe(R,y,E))}const it=y=>n.go(y);let Jt;const At=new Set,En={currentRoute:m,listening:!0,addRoute:v,removeRoute:I,clearRoutes:e.clearRoutes,hasRoute:V,getRoutes:C,resolve:B,options:t,push:z,replace:ce,go:it,back:()=>it(-1),forward:()=>it(1),beforeEach:o.add,beforeResolve:f.add,afterEach:h.add,onError:ye.add,isReady:Yt,install(y){const E=this;y.component("RouterLink",Ro),y.component("RouterView",Wo),y.config.globalProperties.$router=E,Object.defineProperty(y.config.globalProperties,"$route",{enumerable:!0,get:()=>ut(m)}),Ke&&!Jt&&m.value===Ne&&(Jt=!0,z(n.location).catch(L=>{}));const x={};for(const L in Ne)Object.defineProperty(x,L,{get:()=>m.value[L],enumerable:!0});y.provide(yn,E),y.provide(ps,js(x)),y.provide(mn,m);const T=y.unmount;At.add(y),y.unmount=function(){At.delete(y),At.size<1&&(r=Ne,de&&de(),de=null,m.value=Ne,Jt=!1,De=!1),T()}}};function Ge(y){return y.reduce((E,x)=>E.then(()=>ie(x)),Promise.resolve())}return En}function Uo(t,e){const s=[],a=[],n=[],o=Math.max(e.matched.length,t.matched.length);for(let f=0;f<o;f++){const h=e.matched[f];h&&(t.matched.find(r=>tt(r,h))?a.push(h):s.push(h));const m=t.matched[f];m&&(e.matched.find(r=>tt(r,m))||n.push(m))}return[s,a,n]}const Qo={name:"QuoteEdit",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{quote:{quote_number:"",due_date:"",provisional_start_date:"",client_id:"",client:null,status:""},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchQuoteDetails()},methods:{cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.quote.client_id&&this.setClientById(this.quote.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchQuoteDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?(this.quote=e,this.setClientById(this.quote.client_id)):(console.error("Error fetching quote details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching quote details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.quote.client=this.clients.find(e=>e.id===t)||null,this.quote.client_id=t},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting quote:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Lo={class:"pt-2 pr-4"},zo={class:"flex justify-between items-center mb-4"},Ho={class:"card-title"},Go=i("div",{class:"divider mt-2"},null,-1),Yo={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Jo={class:"grid grid-cols-3 gap-4"},Ko={class:"ecwp-group form-group mb-4"},Zo={for:"quoteNumber",class:"ecwp-label"},$o={class:"ecwp-group form-group mb-4"},ei={for:"quoteDate",class:"ecwp-label"},ti={class:"ecwp-group form-group mb-4"},ni={for:"quoteProvisanalDate",class:"ecwp-label"},si={class:"grid grid-cols-2 gap-4"},oi={class:"ecwp-group form-group mb-4"},ii={for:"client",class:"ecwp-label"},ai={class:"ecwp-group form-group mb-4"},li={for:"status",class:"ecwp-label"},ri={value:"draft"},ci={value:"pending"},di={value:"approved"},ui={value:"rejected"},hi={class:"flex justify-between"},mi=["disabled"],fi={key:0,class:"loading loading-spinner loading-sm"};function pi(t,e,s,a,n,o){const f=M("VueDatePicker"),h=M("model-select"),m=M("Card");return c(),d("div",Lo,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),P(m,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:re(()=>[i("div",zo,[i("h2",Ho,l(o.translations.edit_quote),1)]),Go,n.loading?(c(),d("div",Yo)):g("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...r)=>o.submitQuote&&o.submitQuote(...r),["prevent"]))},[i("div",Jo,[i("div",Ko,[i("label",Zo,l(o.translations.quote_number),1),F(i("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=r=>n.quote.quote_number=r),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[J,n.quote.quote_number]])]),i("div",$o,[i("label",ei,l(o.translations.due_date),1),P(f,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=r=>n.quote.due_date=r),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])]),i("div",ti,[i("label",ni,l(o.translations.provisional_date),1),P(f,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteProvisanalDate",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=r=>n.quote.provisional_start_date=r),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])])]),i("div",si,[i("div",oi,[i("label",ii,l(o.translations.company_name),1),P(h,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[3]||(e[3]=r=>n.quote.client_id=r),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",ai,[i("label",li,l(o.translations.status),1),F(i("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=r=>n.quote.status=r),required:"",class:k(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[i("option",ri,l(o.translations.draft),1),i("option",ci,l(o.translations.pending),1),i("option",di,l(o.translations.approved),1),i("option",ui,l(o.translations.rejected),1)],2),[[Ie,n.quote.status]])])]),i("div",hi,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...r)=>o.cancelAction&&o.cancelAction(...r))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(c(),d("span",fi)):g("",!0)],8,mi)])],32)]),_:1})])}var _s=oe(Qo,[["render",pi]]);const _i={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm").close()}}},gi=["open"],vi={class:"modal-box"},yi={class:"font-bold text-lg"},bi=i("div",{class:"text-center text-red-400 mb-2"},[i("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),wi={class:"text-lg font-semibold text-center"},xi={class:"my-4 text-center text-xl"},Ii={class:"flex justify-between space-x-4"};function Ei(t,e,s,a,n,o){return c(),d("div",null,[i("dialog",{id:"modal_confirm",class:"modal",open:t.showModal},[i("div",vi,[i("h3",yi,l(t.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...f)=>o.closeModal&&o.closeModal(...f))}," \u2715 "),bi,i("h2",wi,l(s.title),1),i("p",xi,l(s.message),1),i("div",Ii,[i("button",{onClick:e[1]||(e[1]=(...f)=>o.onCancel&&o.onCancel(...f)),class:"btn btn-secondary rounded-full"},l(s.cancelText),1),i("button",{onClick:e[2]||(e[2]=(...f)=>o.onConfirm&&o.onConfirm(...f)),class:"btn rounded-full btn-error text-white"},l(s.confirmText),1)])])],8,gi)])}var bn=oe(_i,[["render",Ei]]);const Ci={name:"QuotesList",components:{Card:Ue,QuoteEditModal:_s,ConfirmModal:bn,RemoveModal:xt},data(){return{quotes:[],showQuoteDetailsModal:!1,editQuoteModal:!1,selectedQuote:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchQuotes(),this.loadSettings()},methods:{fetchQuotes(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/quotes?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.quotes=s.quotes,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching quotes:",s)}).finally(()=>{this.loading=!1})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return $n(t,this.default_vat.rate)},calculateWithoutVAT(t){return es(t)},generatePaginationButtons(){this.paginationButtons=ts(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchQuotes(t)},perPageChanged(){this.fetchQuotes()},formatAmount(t,e){return ns(t,e,this.settings.currency_position)},confirmDuplicateQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},duplicateQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/duplicate/${t}`,{method:"POST",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotes(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error duplicate quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},confirmDeleteQuote(t){this.selectedQuote=t,modal_remove.showModal(),this.showRemoveModal=!0},deleteQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotes(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},showToast(t,e){ss(this.toast,t,e)}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},ki={class:"pt-2 pr-4"},Ti={class:"flex justify-between items-center"},Ai={class:"card-title"},Si={class:"btn btn-primary rounded-full"},Di=i("i",{class:"fas fa-plus-circle"},null,-1),Pi={key:0,class:"ms-2"},ji={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab2"},Mi=i("i",{class:"fas fa-file-export"},null,-1),qi=["data-tip"],Oi={class:"btn btn-outline btn-accent rounded-full",disabled:""},Vi=i("i",{class:"fas fa-file-export"},null,-1),Ri=i("div",{class:"divider mt-2"},null,-1),Ni={class:"flex items-center mb-4"},Bi={for:"perPageSelect",class:"mr-2"},Fi=["value"],Wi={class:"overflow-x-auto"},Xi={key:0,class:"table w-full"},Ui={class:"flex justify-center"},Qi={key:0,class:"badge badge-warning badge-outline badge-sm"},Li={key:1,class:"badge badge-secondary badge-outline badge-sm"},zi={key:2,class:"badge badge-success badge-outline badge-sm"},Hi={key:3,class:"badge badge-error badge-outline badge-sm"},Gi={key:0},Yi={key:0},Ji={key:0},Ki={key:1},Zi={key:1},$i={key:0},ea={key:1},ta={key:1},na=i("span",{class:"loading loading-bars loading-sm"},null,-1),sa=[na],oa={key:0},ia={key:1},aa=i("span",{class:"loading loading-bars loading-sm"},null,-1),la=[aa],ra={key:0},ca={key:1},da=i("span",{class:"loading loading-bars loading-sm"},null,-1),ua=[da],ha={class:"flex justify-end"},ma=["data-tip"],fa=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"far fa-eye"})],-1),pa=["data-tip"],_a=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"fas fa-pencil-alt"})],-1),ga=["data-tip"],va=["onClick"],ya=i("i",{class:"far fa-copy"},null,-1),ba=[ya],wa=["data-tip"],xa=["onClick"],Ia=i("i",{class:"far fa-trash-alt"},null,-1),Ea=[Ia],Ca={key:1},ka=i("div",{class:"flex gap-4 items-center"},[i("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),i("div",{class:"flex flex-col gap-4 w-full"},[i("div",{class:"skeleton h-4 w-full"}),i("div",{class:"skeleton h-4 w-full"})])],-1),Ta=i("div",{class:"divider my-1"},null,-1),Aa=[ka,Ta],Sa={class:"join ecwp_pagination mt-6 pt-4"},Da=["onClick"];function Pa(t,e,s,a,n,o){const f=M("confirm-modal"),h=M("remove-modal"),m=M("router-link"),r=M("Card");return c(),d("div",ki,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),P(f,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=u=>this.duplicateQuote(n.selectedQuote)),onCancel:e[1]||(e[1]=u=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(h,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[2]||(e[2]=u=>this.deleteQuote(n.selectedQuote)),onCancel:e[3]||(e[3]=u=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(r,{topMargin:"mt-8"},{default:re(()=>[i("div",Ti,[i("h2",Ai,l(o.translations.quotes),1),i("div",null,[P(m,{to:{name:"QuoteNew"}},{default:re(()=>[i("button",Si,[w(l(o.translations.add)+" ",1),Di])]),_:1}),n.settings.easy_compta_export_addon_active==1?(c(),d("span",Pi,[i("a",ji,[w(l(o.translations.export)+" ",1),Mi])])):(c(),d("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[i("button",Oi,[w(l(o.translations.export)+" ",1),Vi])],8,qi))])]),Ri,i("div",Ni,[i("label",Bi,l(o.translations.display_per_page),1),F(i("select",{id:"perPageSelect","onUpdate:modelValue":e[4]||(e[4]=u=>n.perPage=u),onChange:e[5]||(e[5]=(...u)=>o.perPageChanged&&o.perPageChanged(...u))},[(c(!0),d(X,null,U(n.perPageOptions,u=>(c(),d("option",{key:u,value:u},l(u),9,Fi))),128))],544),[[Ie,n.perPage]])]),i("div",Wi,[n.loading?(c(),d("div",Ca,[(c(!0),d(X,null,U(n.skeletonRows,u=>(c(),d("div",{key:u,class:"flex flex-col gap-4 w-full"},Aa))),128))])):(c(),d("table",Xi,[i("thead",null,[i("tr",null,[i("th",null,l(o.translations.quote_number),1),i("th",null,l(o.translations.client),1),i("th",null,l(o.translations.status),1),i("th",null,l(o.translations.total),1),i("th",null,l(o.translations.due_date),1),i("th",null,l(o.translations.created_at),1),i("th",Ui,l(o.translations.actions),1)])]),i("tbody",null,[(c(!0),d(X,null,U(n.quotes,u=>(c(),d("tr",{key:u.id},[i("td",null,l(u.quote_number),1),i("td",null,l(u.client_name),1),i("td",null,[u.status=="draft"?(c(),d("span",Qi,l(o.translations.draft),1)):g("",!0),u.status=="pending"?(c(),d("span",Li,l(o.translations.pending),1)):g("",!0),u.status=="approved"?(c(),d("span",zi,l(o.translations.approved),1)):g("",!0),u.status=="rejected"?(c(),d("span",Hi,l(o.translations.rejected),1)):g("",!0)]),i("td",null,[n.loadingPrice?(c(),d("div",ta,sa)):(c(),d("div",Gi,[n.settings.vat_active==1?(c(),d("div",Yi,[n.default_currency_symbol==u.client_currency||u.client_currency==null?(c(),d("span",Ji,l(o.formatAmount(u.total_amount,n.default_currency_symbol)),1)):(c(),d("span",Ki,l(o.formatAmount(u.total_amount,u.client_currency)),1))])):(c(),d("div",Zi,[n.default_currency_symbol==u.client_currency||u.client_currency==null?(c(),d("span",$i,l(o.formatAmount(u.total_amount,n.default_currency_symbol)),1)):(c(),d("span",ea,l(o.formatAmount(u.total_amount,u.client_currency)),1))]))]))]),i("td",null,[n.loadingPrice?(c(),d("div",ia,la)):(c(),d("div",oa,l(u.due_date),1))]),i("td",null,[n.loadingPrice?(c(),d("div",ca,ua)):(c(),d("div",ra,l(u.created),1))]),i("td",ha,[i("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(m,{to:{name:"QuoteViewDetail",params:{id:u.id}}},{default:re(()=>[fa]),_:2},1032,["to"])],8,ma),i("span",{class:"lg:tooltip","data-tip":o.translations.edit},[P(m,{to:{name:"QuoteEdit",params:{id:u.id}}},{default:re(()=>[_a]),_:2},1032,["to"])],8,pa),i("span",{class:"lg:tooltip","data-tip":o.translations.duplicate},[i("button",{onClick:p=>o.confirmDuplicateQuote(u.id),class:"btn btn-circle text-purple-600 hover:text-purple-900 mx-1"},ba,8,va)],8,ga),i("span",{class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:p=>o.confirmDeleteQuote(u.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},Ea,8,xa)],8,wa)])]))),128))])]))]),i("div",Sa,[(c(!0),d(X,null,U(n.paginationButtons,u=>(c(),d("button",{key:u,class:k(["join-item btn",{"btn-disabled":u==="..."||u===n.currentPage}]),onClick:p=>o.goToPage(u)},l(u),11,Da))),128))])]),_:1})])}var ja=oe(Ci,[["render",Pa]]);const Ma={name:"sendQuote",components:{VueEditor:Et.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,quoteId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"quote",id:this.quoteId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},qa=["id","open"],Oa={class:"modal-box"},Va={class:"font-bold text-lg"},Ra={key:0},Na={class:"grid grid-cols-1 gap-4"},Ba=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),Fa=i("div",{class:"skeleton h-4 w-full"},null,-1),Wa=[Ba,Fa],Xa={class:"grid grid-cols-1 gap-4"},Ua=["type"],Qa=["for"],La=["id","value","disabled","onInput"],za={key:1},Ha=["for"],Ga={class:"form-group mt-4 flex justify-end"},Ya=["disabled"],Ja={key:0,class:"loading loading-spinner loading-sm"};function Ka(t,e,s,a,n,o){const f=M("vue-editor");return c(),d("div",null,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",Oa,[i("h3",Va,l(o.translations.send_quote),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(c(),d("div",Ra,[i("div",Na,[(c(!0),d(X,null,U(o.skeletonItems,h=>(c(),d("div",{key:h,class:"py-2"},Wa))),128))])])):(c(),d("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",Xa,[(c(!0),d(X,null,U(n.fields,(h,m)=>(c(),d("div",{key:m,class:"ecwp-group form-group"},[h.type!=="textarea"?(c(),d("div",{key:0,type:h.type||"text"},[i("label",{for:m,class:"ecwp-label form-label"},l(h.label),9,Qa),i("input",{id:m,class:k(["ecwp-input input input-bordered",h.class||"w-full"]),value:h.value,disabled:h.disabled,onInput:r=>o.updateFieldValue(m,r.target.value)},null,42,La)],8,Ua)):(c(),d("div",za,[i("label",{for:m,class:"form-label"},l(h.label),9,Ha),P(f,{modelValue:h.value,"onUpdate:modelValue":r=>h.value=r,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",Ga,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.send)+" ",1),n.loadingBtn?(c(),d("span",Ja)):g("",!0)],8,Ya)])],32))])],8,qa)])}var Za=oe(Ma,[["render",Ka]]);const $a={components:{VueDatePicker:It},props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},totalAmount:{type:String,required:!0},currency:{type:String,required:!0},advanceSold:{type:String,required:!0},quoteId:{type:Number,required:!0}},data(){return{showError:!1,selectedType:"",inputValue:0,due_date:"",invoiceSolded:!1,establishedAdvances:[],loading:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}},remainingAmount(){this.loading=!0;const t=this.establishedAdvances.reduce((e,s)=>{const a=parseFloat(s.advance_amount);return isNaN(a)?(console.error("Erreur: advance_amount n'est pas un nombre valide",s.advance_amount),e):e+a},0);return this.totalAmount-t},inputValueExceeds(){return this.remainingAmount==0?!0:this.selectedType==="percentage"?this.calculatedAmount>this.remainingAmount:this.selectedType==="fixed"?this.inputValue>this.remainingAmount:!1},calculatedAmount(){return this.selectedType==="percentage"?this.inputValue/100*this.remainingAmount:this.inputValue}},created(){this.fetchEstablishedAdvances(this.quoteId)},methods:{fetchEstablishedAdvances(t){const e=`/wp-json/my-easy-compta/v1/advance/${t}`;fetch(e,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.establishedAdvances=s}).catch(s=>{console.error("Error fetching advances:",s)})},onConfirm(){if(!this.inputValueExceeds){if(this.advanceSold=="no_sold"){if(!this.inputValue||!this.due_date||this.advanceSold=="no_sold"&&!this.selectedType){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:this.selectedType,value:this.inputValue,date:this.due_date})}else{if(!this.due_date){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:"fixed",value:this.remainingAmount,date:this.due_date})}this.closeModal()}},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_advance").close()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},el=["open"],tl={class:"modal-box overflow-visible"},nl={class:"font-bold text-lg"},sl={class:"text-lg font-semibold text-center"},ol={class:"my-4 text-center text-xl"},il={key:0,class:"text-red-500 text-sm"},al={class:"grid grid-cols-2 gap-4"},ll={key:0},rl={class:"flex ecwp-group form-group mb-4"},cl=i("label",{for:"advance-type",class:"ecwp-label"},"Type",-1),dl=i("option",{value:"percentage"},"Pourcentage",-1),ul=i("option",{value:"fixed"},"Montant fixe",-1),hl=[dl,ul],ml={key:1},fl={class:"flex ecwp-group form-group mb-4"},pl=i("label",{for:"advance-type",class:"ecwp-label"},"Valeur",-1),_l={class:"absolute items-center border rounded-md right-0 top-6"},gl={class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"},vl={key:0},yl={key:1},bl={key:1,class:"mt-2"},wl={class:"text-sm"},xl={key:2,class:"flex ecwp-group form-group mb-4"},Il={for:"quoteDate",class:"ecwp-label"},El={key:3},Cl={class:"flex justify-between space-x-4 mt-4"},kl=["disabled"];function Tl(t,e,s,a,n,o){const f=M("VueDatePicker");return c(),d("div",null,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),i("dialog",{id:"modal_advance",class:"modal",open:s.isVisible},[i("div",tl,[i("h3",nl,l(t.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...h)=>o.closeModal&&o.closeModal(...h))}," \u2715 "),i("h2",sl,l(s.title),1),i("p",ol," Montant total restant : "+l(o.remainingAmount)+" "+l(s.currency),1),o.inputValueExceeds&&!n.invoiceSolded?(c(),d("p",il," Le montant s\xE9lectionn\xE9 d\xE9passe le montant total du devis. ")):g("",!0),i("div",al,[s.advanceSold=="no_sold"&&!n.invoiceSolded?(c(),d("div",ll,[i("div",rl,[cl,F(i("select",{"onUpdate:modelValue":e[1]||(e[1]=h=>n.selectedType=h),id:"advance-type",class:k(["ecwp-select ecwp-input input input-bordered w-full",{"input-error":!n.selectedType&&n.showError}])},hl,2),[[Ie,n.selectedType]])])])):g("",!0),n.selectedType&&s.advanceSold=="no_sold"&&!n.invoiceSolded?(c(),d("div",ml,[i("div",fl,[pl,F(i("input",{"onUpdate:modelValue":e[2]||(e[2]=h=>n.inputValue=h),type:"text",id:"advance-value",class:k([{"input-error":!n.inputValue&&n.showError},"ecwp-input input input-bordered w-full"])},null,2),[[J,n.inputValue]]),i("div",_l,[i("div",gl,[n.selectedType==="percentage"?(c(),d("span",vl,"%")):(c(),d("span",yl,l(s.currency),1))])])])])):g("",!0)]),n.selectedType==="percentage"&&!o.inputValueExceeds&!n.invoiceSolded?(c(),d("div",bl,[i("p",wl," Montant bas\xE9 sur le pourcentage: "+l(o.calculatedAmount)+" "+l(s.currency),1)])):g("",!0),n.invoiceSolded?g("",!0):(c(),d("div",xl,[i("label",Il,l(o.translations.due_date),1),P(f,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.inputValue&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.due_date,"onUpdate:modelValue":e[3]||(e[3]=h=>n.due_date=h),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr",required:""},null,8,["modelValue","format","min-date","class"])])),n.invoiceSolded?(c(),d("div",El,"Facture d\xE9j\xE0 sold\xE9")):g("",!0),i("div",Cl,[i("button",{onClick:e[4]||(e[4]=(...h)=>o.onCancel&&o.onCancel(...h)),class:"btn btn-secondary rounded-full"},l(s.cancelText),1),i("button",{onClick:e[5]||(e[5]=(...h)=>o.onConfirm&&o.onConfirm(...h)),disabled:o.inputValueExceeds,class:"btn rounded-full btn-error text-white"},l(s.confirmText),9,kl)])])],8,el)])}var Al=oe($a,[["render",Tl]]);const Sl={name:"QuoteNavBar",components:{SendQuoteModal:Za,ConfirmModal:bn,AdvanceModal:Al},props:{quoteInfo:Object,emailActive:Number,advanceActive:Number,currency:String,noItems:Boolean},data(){return{selectedQuote:null,advanceSold:!1,sendQuoteModal:!1,loadingModal:!1,loadingPdf:!1,loading:!1,client_detail:null,subject:"",content:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{async changeQuoteStatus(t){try{const s=await(await fetch("/wp-json/my-easy-compta/v1/quotes/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.quoteInfo.id,status:t})})).json();s.success?(this.quoteInfo.status=t,this.quoteInfo.total_amount=s.total_amount,this.showToast(s.message,"alert-success")):(console.error("Failed to update quote status:",s.message),this.showToast(s.message,"alert-error"))}catch(e){console.error("An error occurred while updating quote status:",e),this.showToast(e,"alert-error")}},convertToInvoice(t){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-quote/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e.success?(this.showToast(e.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:e.id}})):this.showToast(e.message,"alert-error")}).catch(e=>{console.error("Error converting quote:",e),this.showToast(e.message,"alert-error")})},handleAdvanceInvoiceConfirm(t){const{type:e,value:s,date:a}=t;this.convertAdvanceInvoice(this.selectedQuote,e,s,a)},convertAdvanceInvoice(t,e,s,a){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-advance/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({advance_type:e,advance_value:s,advance_date:a})}).then(n=>n.json()).then(n=>{n.success?(this.showToast(n.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:n.id}})):this.showToast(n.message,"alert-error")}).catch(n=>{console.error("Error converting quote:",n),this.showToast(n.message,"alert-error")})},confirmConvertQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},ConvertAdvanceQuote(t,e){this.selectedQuote=t,this.advanceSold=e,modal_advance.showModal(),this.showRemoveModal=!0},exportToPDF(){this.loadingPdf=!0;const t=this.quoteInfo.id;fetch(`/wp-json/my-easy-compta/v1/quotes/pdf/${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return this.loadingPdf=!1,e.blob()}).then(e=>{const s=URL.createObjectURL(e);window.open(s),this.loadingPdf=!1}).catch(e=>{console.error("There was a problem with the fetch operation:",e),this.loadingPdf=!1})},sendQuote(t){this.loadingModal=!0,this.sendQuoteModal=!0,modal_send_quote.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(t.ok){const e=await t.json();this.subject=e.email_quote_subject,this.content=e.email_quote_content,this.loading=!1}else{const e=await t.json();this.showToast(e.message,"alert-error"),this.loading=!1}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Dl={key:0},Pl={key:1},jl={key:3,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Ml=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),ql=[Ml],Ol={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},Vl=i("div",{class:"dropdown"},[i("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),i("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[i("li",null,[i("a",null,"Item 1")]),i("li",null,[i("a",null,"Parent"),i("ul",{class:"p-2"},[i("li",null,[i("a",null,"Submenu 1")]),i("li",null,[i("a",null,"Submenu 2")])])]),i("li",null,[i("a",null,"Item 3")])])],-1),Rl={class:"hidden lg:flex gap-2"},Nl={class:"btn btn-sm"},Bl=i("i",{class:"far fa-edit"},null,-1),Fl=i("i",{class:"fa fa-check"},null,-1),Wl=["data-tip"],Xl={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Ul=i("i",{class:"fas fa-check"},null,-1),Ql=i("i",{class:"fa fa-check"},null,-1),Ll=i("i",{class:"fa fa-times"},null,-1),zl={key:4},Hl={class:"dropdown"},Gl={tabindex:"0",role:"button",class:"btn btn-sm"},Yl=i("i",{class:"fas fa-exchange-alt"},null,-1),Jl={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},Kl={key:0},Zl={key:5},$l=i("i",{class:"fas fa-exchange-alt"},null,-1),er={class:"flex gap-2"},tr=i("i",{class:"fas fa-paper-plane"},null,-1),nr={key:0,class:"far fa-envelope"},sr=["data-tip"],or={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},ir=i("i",{class:"fas fa-paper-plane"},null,-1),ar=["data-tip"],lr={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},rr=i("i",{class:"fas fa-paper-plane"},null,-1),cr=["disabled"],dr=i("i",{class:"far fa-file-pdf"},null,-1),ur={key:0,class:"loading loading-spinner loading-sm"};function hr(t,e,s,a,n,o){const f=M("send-quote-modal"),h=M("confirm-modal"),m=M("advance-modal"),r=M("router-link");return c(),d("div",null,[s.emailActive==1?(c(),d("div",Dl,[P(f,{loading:n.loadingModal,"show-modal":n.sendQuoteModal,"modal-id":"modal_send_quote",client:n.client_detail,"quote-id":s.quoteInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=u=>n.sendQuoteModal=!1)},null,8,["loading","show-modal","client","quote-id","subject","content"])])):g("",!0),P(h,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[1]||(e[1]=u=>this.convertToInvoice(n.selectedQuote)),onCancel:e[2]||(e[2]=u=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),s.advanceActive==1?(c(),d("div",Pl,[P(m,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,"total-amount":s.quoteInfo.total_amount,currency:s.currency,quoteId:s.quoteInfo.id,"advance-sold":n.advanceSold,onConfirm:o.handleAdvanceInvoiceConfirm,onCancel:e[3]||(e[3]=u=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","total-amount","currency","quoteId","advance-sold","onConfirm"])])):g("",!0),n.toast.visible?(c(),d("div",{key:2,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),n.loading?(c(),d("div",jl,ql)):g("",!0),i("div",Ol,[i("div",null,[Vl,i("div",Rl,[P(r,{to:{name:"QuoteEdit",params:{id:s.quoteInfo.id}}},{default:re(()=>[i("button",Nl,[Bl,w(l(o.translations.edit_quote),1)])]),_:1},8,["to"]),s.quoteInfo.status=="draft"&&!s.noItems?(c(),d("button",{key:0,class:"btn btn-outline btn-success btn-sm",onClick:e[4]||(e[4]=u=>o.changeQuoteStatus("pending"))},[Fl,w(" "+l(o.translations.validate_quote),1)])):g("",!0),s.quoteInfo.status=="draft"&&s.noItems?(c(),d("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.min_article},[i("button",Xl,[Ul,w(" "+l(o.translations.validate_quote),1)])],8,Wl)):g("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="rejected")&&!s.noItems?(c(),d("button",{key:2,class:"btn btn-outline btn-success btn-sm",onClick:e[5]||(e[5]=u=>o.changeQuoteStatus("approved"))},[Ql,w(" "+l(o.translations.mark_as_accepted),1)])):g("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="approved")&&!s.noItems?(c(),d("button",{key:3,class:"btn btn-outline btn-error btn-sm",onClick:e[6]||(e[6]=u=>o.changeQuoteStatus("rejected"))},[Ll,w(" "+l(o.translations.mark_as_rejected),1)])):g("",!0),s.advanceActive==1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(c(),d("div",zl,[i("div",Hl,[i("div",Gl,[Yl,w(" "+l(o.translations.convertToInvoice),1)]),i("ul",Jl,[s.quoteInfo.advance!=1?(c(),d("li",Kl,[i("a",{href:"#",onClick:e[7]||(e[7]=K(u=>o.confirmConvertQuote(s.quoteInfo.id),["prevent"]))}," Facture global ")])):g("",!0),i("li",null,[i("a",{href:"#",onClick:e[8]||(e[8]=K(u=>o.ConvertAdvanceQuote(s.quoteInfo.id,"no_sold"),["prevent"]))}," Facture d'acompte "),s.quoteInfo.advance!=0?(c(),d("a",{key:0,href:"#",onClick:e[9]||(e[9]=K(u=>o.ConvertAdvanceQuote(s.quoteInfo.id,"sold"),["prevent"]))}," Facture du solde ")):g("",!0)])])])])):g("",!0),s.advanceActive!=1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(c(),d("div",Zl,[i("button",{onClick:e[10]||(e[10]=u=>o.confirmConvertQuote(s.quoteInfo.id)),class:"btn btn-sm"},[$l,w(" "+l(o.translations.convertToInvoice),1)])])):g("",!0)])]),i("div",er,[s.emailActive==1&&!s.noItems?(c(),d("button",{key:0,onClick:e[11]||(e[11]=K(u=>o.sendQuote(s.quoteInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[tr,w(" "+l(o.translations.send_quote)+" ",1),s.quoteInfo.sent==1?(c(),d("i",nr)):g("",!0)])):s.emailActive==0?(c(),d("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[i("button",or,[ir,w(" "+l(o.translations.send_quote),1)])],8,sr)):s.emailActive==1&&s.noItems?(c(),d("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.min_article},[i("button",lr,[rr,w(" "+l(o.translations.send_quote),1)])],8,ar)):g("",!0),i("button",{onClick:e[12]||(e[12]=(...u)=>o.exportToPDF&&o.exportToPDF(...u)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[dr,w(" "+l(o.translations.exportToPDF)+" ",1),n.loadingPdf?(c(),d("span",ur)):g("",!0)],8,cr)])])])}var mr=oe(Sl,[["render",hr]]);const fr={components:{VueEditor:Et.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:t.item_name},item_description:{label:t.description,type:"textarea"},quantity:{label:t.quantity,type:"number"},vat_rate:{label:"Taux de TVA",type:"number"},unit_price:{label:t.unit_price,type:"number"},discount:{label:t.discount,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/quotes/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},pr=["id","open"],_r={class:"modal-box"},gr={class:"font-bold text-lg"},vr={key:0},yr={class:"grid grid-cols-1 gap-4"},br=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),wr=i("div",{class:"skeleton h-4 w-full"},null,-1),xr=[br,wr],Ir={class:"grid grid-cols-1 gap-4"},Er=["type"],Cr=["for"],kr=["id","onUpdate:modelValue"],Tr={key:1},Ar=["for"],Sr={class:"form-group mt-4 flex justify-end"},Dr=["disabled"],Pr={key:0,class:"loading loading-spinner loading-sm"};function jr(t,e,s,a,n,o){const f=M("vue-editor");return c(),d("div",null,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",_r,[i("h3",gr,l(s.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(c(),d("div",vr,[i("div",yr,[(c(!0),d(X,null,U(o.skeletonItems,h=>(c(),d("div",{key:h,class:"py-2"},xr))),128))])])):(c(),d("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",Ir,[(c(!0),d(X,null,U(n.fields,(h,m)=>(c(),d("div",{key:m,class:"ecwp-group form-group"},[h.type!=="textarea"?(c(),d("div",{key:0,type:h.type||"text"},[i("label",{for:m,class:"ecwp-label form-label"},l(h.label),9,Cr),F(i("input",{id:m,"onUpdate:modelValue":r=>n.editedItem[m]=r,class:k(["ecwp-input input input-bordered",h.class||"w-full"])},null,10,kr),[[J,n.editedItem[m]]])],8,Er)):(c(),d("div",Tr,[i("label",{for:m,class:"form-label"},l(h.label),9,Ar),P(f,{id:m,modelValue:n.editedItem[m],"onUpdate:modelValue":r=>n.editedItem[m]=r,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",Sr,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(c(),d("span",Pr)):g("",!0)],8,Dr)])],32))])],8,pr)])}var Mr=oe(fr,[["render",jr]]);/**!5 */const Ke=typeof document!="undefined";function Ns(t){return t.__esModule||t[Symbol.toStringTag]==="Module"}const Q=Object.assign;function Zt(t,e){const s={};for(const a in e){const n=e[a];s[a]=Ee(n)?n.map(t):t(n)}return s}const ht=()=>{},Ee=Array.isArray,os=/#/g,Bs=/&/g,Fs=/\//g,Ws=/=/g,Xs=/\?/g,is=/\+/g,Us=/%5B/g,Qs=/%5D/g,as=/%5E/g,Ls=/%60/g,ls=/%7B/g,zs=/%7C/g,rs=/%7D/g,Hs=/%20/g;function vn(t){return encodeURI(""+t).replace(zs,"|").replace(Us,"[").replace(Qs,"]")}function Gs(t){return vn(t).replace(ls,"{").replace(rs,"}").replace(as,"^")}function un(t){return vn(t).replace(is,"%2B").replace(Hs,"+").replace(os,"%23").replace(Bs,"%26").replace(Ls,"`").replace(ls,"{").replace(rs,"}").replace(as,"^")}function Ys(t){return un(t).replace(Ws,"%3D")}function Js(t){return vn(t).replace(os,"%23").replace(Xs,"%3F")}function Ks(t){return t==null?"":Js(t).replace(Fs,"%2F")}function bt(t){try{return decodeURIComponent(""+t)}catch{}return""+t}const Zs=/\/$/,$s=t=>t.replace(Zs,"");function $t(t,e,s="/"){let a,n={},o="",m="";const h=e.indexOf("#");let f=e.indexOf("?");return h<f&&h>=0&&(f=-1),f>-1&&(a=e.slice(0,f),o=e.slice(f+1,h>-1?h:e.length),n=t(o)),h>-1&&(a=a||e.slice(0,h),m=e.slice(h,e.length)),a=so(a!=null?a:e,s),{fullPath:a+(o&&"?")+o+m,path:a,query:n,hash:bt(m)}}function eo(t,e){const s=e.query?t(e.query):"";return e.path+(s&&"?")+s+(e.hash||"")}function Cn(t,e){return!e||!t.toLowerCase().startsWith(e.toLowerCase())?t:t.slice(e.length)||"/"}function to(t,e,s){const a=e.matched.length-1,n=s.matched.length-1;return a>-1&&a===n&&tt(e.matched[a],s.matched[n])&&cs(e.params,s.params)&&t(e.query)===t(s.query)&&e.hash===s.hash}function tt(t,e){return(t.aliasOf||t)===(e.aliasOf||e)}function cs(t,e){if(Object.keys(t).length!==Object.keys(e).length)return!1;for(const s in t)if(!no(t[s],e[s]))return!1;return!0}function no(t,e){return Ee(t)?kn(t,e):Ee(e)?kn(e,t):t===e}function kn(t,e){return Ee(e)?t.length===e.length&&t.every((s,a)=>s===e[a]):t.length===1&&t[0]===e}function so(t,e){if(t.startsWith("/"))return t;if(!t)return e;const s=e.split("/"),a=t.split("/"),n=a[a.length-1];(n===".."||n===".")&&a.push("");let o=s.length-1,m,h;for(m=0;m<a.length;m++)if(h=a[m],h!==".")if(h==="..")o>1&&o--;else break;return s.slice(0,o).join("/")+"/"+a.slice(m).join("/")}const Ne={path:"/",name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0};var wt;(function(t){t.pop="pop",t.push="push"})(wt||(wt={}));var mt;(function(t){t.back="back",t.forward="forward",t.unknown=""})(mt||(mt={}));function oo(t){if(!t)if(Ke){const e=document.querySelector("base");t=e&&e.getAttribute("href")||"/",t=t.replace(/^\w+:\/\/[^\/]+/,"")}else t="/";return t[0]!=="/"&&t[0]!=="#"&&(t="/"+t),$s(t)}const io=/^[^#]+#/;function ao(t,e){return t.replace(io,"#")+e}function lo(t,e){const s=document.documentElement.getBoundingClientRect(),a=t.getBoundingClientRect();return{behavior:e.behavior,left:a.left-s.left-(e.left||0),top:a.top-s.top-(e.top||0)}}const Ht=()=>({left:window.scrollX,top:window.scrollY});function ro(t){let e;if("el"in t){const s=t.el,a=typeof s=="string"&&s.startsWith("#"),n=typeof s=="string"?a?document.getElementById(s.slice(1)):document.querySelector(s):s;if(!n)return;e=lo(n,t)}else e=t;"scrollBehavior"in document.documentElement.style?window.scrollTo(e):window.scrollTo(e.left!=null?e.left:window.scrollX,e.top!=null?e.top:window.scrollY)}function Tn(t,e){return(history.state?history.state.position-e:-1)+t}const hn=new Map;function co(t,e){hn.set(t,e)}function uo(t){const e=hn.get(t);return hn.delete(t),e}let ho=()=>location.protocol+"//"+location.host;function ds(t,e){const{pathname:s,search:a,hash:n}=e,o=t.indexOf("#");if(o>-1){let h=n.includes(t.slice(o))?t.slice(o).length:1,f=n.slice(h);return f[0]!=="/"&&(f="/"+f),Cn(f,"")}return Cn(s,t)+a+n}function mo(t,e,s,a){let n=[],o=[],m=null;const h=({state:g})=>{const v=ds(t,location),I=s.value,C=e.value;let V=0;if(g){if(s.value=v,e.value=g,m&&m===I){m=null;return}V=C?g.position-C.position:0}else a(v);n.forEach(F=>{F(s.value,I,{delta:V,type:wt.pop,direction:V?V>0?mt.forward:mt.back:mt.unknown})})};function f(){m=s.value}function d(g){n.push(g);const v=()=>{const I=n.indexOf(g);I>-1&&n.splice(I,1)};return o.push(v),v}function u(){const{history:g}=window;!g.state||g.replaceState(Q({},g.state,{scroll:Ht()}),"")}function p(){for(const g of o)g();o=[],window.removeEventListener("popstate",h),window.removeEventListener("beforeunload",u)}return window.addEventListener("popstate",h),window.addEventListener("beforeunload",u,{passive:!0}),{pauseListeners:f,listen:d,destroy:p}}function An(t,e,s,a=!1,n=!1){return{back:t,current:e,forward:s,replaced:a,position:window.history.length,scroll:n?Ht():null}}function fo(t){const{history:e,location:s}=window,a={value:ds(t,s)},n={value:e.state};n.value||o(a.value,{back:null,current:a.value,forward:null,position:e.length-1,replaced:!0,scroll:null},!0);function o(f,d,u){const p=t.indexOf("#"),g=p>-1?(s.host&&document.querySelector("base")?t:t.slice(p))+f:ho()+t+f;try{e[u?"replaceState":"pushState"](d,"",g),n.value=d}catch(v){console.error(v),s[u?"replace":"assign"](g)}}function m(f,d){const u=Q({},e.state,An(n.value.back,f,n.value.forward,!0),d,{position:n.value.position});o(f,u,!0),a.value=f}function h(f,d){const u=Q({},n.value,e.state,{forward:f,scroll:Ht()});o(u.current,u,!0);const p=Q({},An(a.value,f,null),{position:u.position+1},d);o(f,p,!1),a.value=f}return{location:a,state:n,push:h,replace:m}}function po(t){t=oo(t);const e=fo(t),s=mo(t,e.state,e.location,e.replace);function a(o,m=!0){m||s.pauseListeners(),history.go(o)}const n=Q({location:"",base:t,go:a,createHref:ao.bind(null,t)},e,s);return Object.defineProperty(n,"location",{enumerable:!0,get:()=>e.location.value}),Object.defineProperty(n,"state",{enumerable:!0,get:()=>e.state.value}),n}function _o(t){return t=location.host?t||location.pathname+location.search:"",t.includes("#")||(t+="#"),po(t)}function go(t){return typeof t=="string"||t&&typeof t=="object"}function us(t){return typeof t=="string"||typeof t=="symbol"}const hs=Symbol("");var Sn;(function(t){t[t.aborted=4]="aborted",t[t.cancelled=8]="cancelled",t[t.duplicated=16]="duplicated"})(Sn||(Sn={}));function nt(t,e){return Q(new Error,{type:t,[hs]:!0},e)}function Me(t,e){return t instanceof Error&&hs in t&&(e==null||!!(t.type&e))}const Dn="[^/]+?",vo={sensitive:!1,strict:!1,start:!0,end:!0},yo=/[.+*?^${}()[\]/\\]/g;function bo(t,e){const s=Q({},vo,e),a=[];let n=s.start?"^":"";const o=[];for(const d of t){const u=d.length?[]:[90];s.strict&&!d.length&&(n+="/");for(let p=0;p<d.length;p++){const g=d[p];let v=40+(s.sensitive?.25:0);if(g.type===0)p||(n+="/"),n+=g.value.replace(yo,"\\$&"),v+=40;else if(g.type===1){const{value:I,repeatable:C,optional:V,regexp:F}=g;o.push({name:I,repeatable:C,optional:V});const D=F||Dn;if(D!==Dn){v+=10;try{new RegExp(`(${D})`)}catch(z){throw new Error(`Invalid custom RegExp for param "${I}" (${D}): `+z.message)}}let q=C?`((?:${D})(?:/(?:${D}))*)`:`(${D})`;p||(q=V&&d.length<2?`(?:/${q})`:"/"+q),V&&(q+="?"),n+=q,v+=20,V&&(v+=-8),C&&(v+=-20),D===".*"&&(v+=-50)}u.push(v)}a.push(u)}if(s.strict&&s.end){const d=a.length-1;a[d][a[d].length-1]+=.7000000000000001}s.strict||(n+="/?"),s.end?n+="$":s.strict&&(n+="(?:/|$)");const m=new RegExp(n,s.sensitive?"":"i");function h(d){const u=d.match(m),p={};if(!u)return null;for(let g=1;g<u.length;g++){const v=u[g]||"",I=o[g-1];p[I.name]=v&&I.repeatable?v.split("/"):v}return p}function f(d){let u="",p=!1;for(const g of t){(!p||!u.endsWith("/"))&&(u+="/"),p=!1;for(const v of g)if(v.type===0)u+=v.value;else if(v.type===1){const{value:I,repeatable:C,optional:V}=v,F=I in d?d[I]:"";if(Ee(F)&&!C)throw new Error(`Provided param "${I}" is an array but it is not repeatable (* or + modifiers)`);const D=Ee(F)?F.join("/"):F;if(!D)if(V)g.length<2&&(u.endsWith("/")?u=u.slice(0,-1):p=!0);else throw new Error(`Missing required param "${I}"`);u+=D}}return u||"/"}return{re:m,score:a,keys:o,parse:h,stringify:f}}function wo(t,e){let s=0;for(;s<t.length&&s<e.length;){const a=e[s]-t[s];if(a)return a;s++}return t.length<e.length?t.length===1&&t[0]===40+40?-1:1:t.length>e.length?e.length===1&&e[0]===40+40?1:-1:0}function ms(t,e){let s=0;const a=t.score,n=e.score;for(;s<a.length&&s<n.length;){const o=wo(a[s],n[s]);if(o)return o;s++}if(Math.abs(n.length-a.length)===1){if(Pn(a))return 1;if(Pn(n))return-1}return n.length-a.length}function Pn(t){const e=t[t.length-1];return t.length>0&&e[e.length-1]<0}const xo={type:0,value:""},Io=/[a-zA-Z0-9_]/;function Eo(t){if(!t)return[[]];if(t==="/")return[[xo]];if(!t.startsWith("/"))throw new Error(`Invalid path "${t}"`);function e(v){throw new Error(`ERR (${s})/"${d}": ${v}`)}let s=0,a=s;const n=[];let o;function m(){o&&n.push(o),o=[]}let h=0,f,d="",u="";function p(){!d||(s===0?o.push({type:0,value:d}):s===1||s===2||s===3?(o.length>1&&(f==="*"||f==="+")&&e(`A repeatable param (${d}) must be alone in its segment. eg: '/:ids+.`),o.push({type:1,value:d,regexp:u,repeatable:f==="*"||f==="+",optional:f==="*"||f==="?"})):e("Invalid state to consume buffer"),d="")}function g(){d+=f}for(;h<t.length;){if(f=t[h++],f==="\\"&&s!==2){a=s,s=4;continue}switch(s){case 0:f==="/"?(d&&p(),m()):f===":"?(p(),s=1):g();break;case 4:g(),s=a;break;case 1:f==="("?s=2:Io.test(f)?g():(p(),s=0,f!=="*"&&f!=="?"&&f!=="+"&&h--);break;case 2:f===")"?u[u.length-1]=="\\"?u=u.slice(0,-1)+f:s=3:u+=f;break;case 3:p(),s=0,f!=="*"&&f!=="?"&&f!=="+"&&h--,u="";break;default:e("Unknown state");break}}return s===2&&e(`Unfinished custom RegExp for param "${d}"`),p(),m(),n}function Co(t,e,s){const a=bo(Eo(t.path),s),n=Q(a,{record:t,parent:e,children:[],alias:[]});return e&&!n.record.aliasOf==!e.record.aliasOf&&e.children.push(n),n}function ko(t,e){const s=[],a=new Map;e=qn({strict:!1,end:!0,sensitive:!1},e);function n(p){return a.get(p)}function o(p,g,v){const I=!v,C=To(p);C.aliasOf=v&&v.record;const V=qn(e,p),F=[C];if("alias"in p){const z=typeof p.alias=="string"?[p.alias]:p.alias;for(const ce of z)F.push(Q({},C,{components:v?v.record.components:C.components,path:ce,aliasOf:v?v.record:C}))}let D,q;for(const z of F){const{path:ce}=z;if(g&&ce[0]!=="/"){const ne=g.record.path,Z=ne[ne.length-1]==="/"?"":"/";z.path=g.record.path+(ce&&Z+ce)}if(D=Co(z,g,V),v?v.alias.push(D):(q=q||D,q!==D&&q.alias.push(D),I&&p.name&&!jn(D)&&m(p.name)),fs(D)&&f(D),C.children){const ne=C.children;for(let Z=0;Z<ne.length;Z++)o(ne[Z],D,v&&v.children[Z])}v=v||D}return q?()=>{m(q)}:ht}function m(p){if(us(p)){const g=a.get(p);g&&(a.delete(p),s.splice(s.indexOf(g),1),g.children.forEach(m),g.alias.forEach(m))}else{const g=s.indexOf(p);g>-1&&(s.splice(g,1),p.record.name&&a.delete(p.record.name),p.children.forEach(m),p.alias.forEach(m))}}function h(){return s}function f(p){const g=Do(p,s);s.splice(g,0,p),p.record.name&&!jn(p)&&a.set(p.record.name,p)}function d(p,g){let v,I={},C,V;if("name"in p&&p.name){if(v=a.get(p.name),!v)throw nt(1,{location:p});V=v.record.name,I=Q(Mn(g.params,v.keys.filter(q=>!q.optional).concat(v.parent?v.parent.keys.filter(q=>q.optional):[]).map(q=>q.name)),p.params&&Mn(p.params,v.keys.map(q=>q.name))),C=v.stringify(I)}else if(p.path!=null)C=p.path,v=s.find(q=>q.re.test(C)),v&&(I=v.parse(C),V=v.record.name);else{if(v=g.name?a.get(g.name):s.find(q=>q.re.test(g.path)),!v)throw nt(1,{location:p,currentLocation:g});V=v.record.name,I=Q({},g.params,p.params),C=v.stringify(I)}const F=[];let D=v;for(;D;)F.unshift(D.record),D=D.parent;return{name:V,path:C,params:I,matched:F,meta:So(F)}}t.forEach(p=>o(p));function u(){s.length=0,a.clear()}return{addRoute:o,resolve:d,removeRoute:m,clearRoutes:u,getRoutes:h,getRecordMatcher:n}}function Mn(t,e){const s={};for(const a of e)a in t&&(s[a]=t[a]);return s}function To(t){return{path:t.path,redirect:t.redirect,name:t.name,meta:t.meta||{},aliasOf:void 0,beforeEnter:t.beforeEnter,props:Ao(t),children:t.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},components:"components"in t?t.components||null:t.component&&{default:t.component}}}function Ao(t){const e={},s=t.props||!1;if("component"in t)e.default=s;else for(const a in t.components)e[a]=typeof s=="object"?s[a]:s;return e}function jn(t){for(;t;){if(t.record.aliasOf)return!0;t=t.parent}return!1}function So(t){return t.reduce((e,s)=>Q(e,s.meta),{})}function qn(t,e){const s={};for(const a in t)s[a]=a in e?e[a]:t[a];return s}function Do(t,e){let s=0,a=e.length;for(;s!==a;){const o=s+a>>1;ms(t,e[o])<0?a=o:s=o+1}const n=Po(t);return n&&(a=e.lastIndexOf(n,a-1)),a}function Po(t){let e=t;for(;e=e.parent;)if(fs(e)&&ms(t,e)===0)return e}function fs({record:t}){return!!(t.name||t.components&&Object.keys(t.components).length||t.redirect)}function Mo(t){const e={};if(t===""||t==="?")return e;const a=(t[0]==="?"?t.slice(1):t).split("&");for(let n=0;n<a.length;++n){const o=a[n].replace(is," "),m=o.indexOf("="),h=bt(m<0?o:o.slice(0,m)),f=m<0?null:bt(o.slice(m+1));if(h in e){let d=e[h];Ee(d)||(d=e[h]=[d]),d.push(f)}else e[h]=f}return e}function On(t){let e="";for(let s in t){const a=t[s];if(s=Ys(s),a==null){a!==void 0&&(e+=(e.length?"&":"")+s);continue}(Ee(a)?a.map(o=>o&&un(o)):[a&&un(a)]).forEach(o=>{o!==void 0&&(e+=(e.length?"&":"")+s,o!=null&&(e+="="+o))})}return e}function jo(t){const e={};for(const s in t){const a=t[s];a!==void 0&&(e[s]=Ee(a)?a.map(n=>n==null?null:""+n):a==null?a:""+a)}return e}const qo=Symbol(""),Vn=Symbol(""),yn=Symbol(""),ps=Symbol(""),mn=Symbol("");function lt(){let t=[];function e(a){return t.push(a),()=>{const n=t.indexOf(a);n>-1&&t.splice(n,1)}}function s(){t=[]}return{add:e,list:()=>t.slice(),reset:s}}function Be(t,e,s,a,n,o=m=>m()){const m=a&&(a.enterCallbacks[n]=a.enterCallbacks[n]||[]);return()=>new Promise((h,f)=>{const d=g=>{g===!1?f(nt(4,{from:s,to:e})):g instanceof Error?f(g):go(g)?f(nt(2,{from:e,to:g})):(m&&a.enterCallbacks[n]===m&&typeof g=="function"&&m.push(g),h())},u=o(()=>t.call(a&&a.instances[n],e,s,d));let p=Promise.resolve(u);t.length<3&&(p=p.then(d)),p.catch(g=>f(g))})}function en(t,e,s,a,n=o=>o()){const o=[];for(const m of t)for(const h in m.components){let f=m.components[h];if(!(e!=="beforeRouteEnter"&&!m.instances[h]))if(Oo(f)){const u=(f.__vccOpts||f)[e];u&&o.push(Be(u,s,a,m,h,n))}else{let d=f();o.push(()=>d.then(u=>{if(!u)return Promise.reject(new Error(`Couldn't resolve component "${h}" at "${m.path}"`));const p=Ns(u)?u.default:u;m.components[h]=p;const v=(p.__vccOpts||p)[e];return v&&Be(v,s,a,m,h,n)()}))}}return o}function Oo(t){return typeof t=="object"||"displayName"in t||"props"in t||"__vccOpts"in t}function Rn(t){const e=yt(yn),s=yt(ps),a=Ce(()=>{const f=ut(t.to);return e.resolve(f)}),n=Ce(()=>{const{matched:f}=a.value,{length:d}=f,u=f[d-1],p=s.matched;if(!u||!p.length)return-1;const g=p.findIndex(tt.bind(null,u));if(g>-1)return g;const v=Nn(f[d-2]);return d>1&&Nn(u)===v&&p[p.length-1].path!==v?p.findIndex(tt.bind(null,f[d-2])):g}),o=Ce(()=>n.value>-1&&Bo(s.params,a.value.params)),m=Ce(()=>n.value>-1&&n.value===s.matched.length-1&&cs(s.params,a.value.params));function h(f={}){return No(f)?e[ut(t.replace)?"replace":"push"](ut(t.to)).catch(ht):Promise.resolve()}return{route:a,href:Ce(()=>a.value.href),isActive:o,isExactActive:m,navigate:h}}const Vo=Jn({name:"RouterLink",compatConfig:{MODE:3},props:{to:{type:[String,Object],required:!0},replace:Boolean,activeClass:String,exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},useLink:Rn,setup(t,{slots:e}){const s=qs(Rn(t)),{options:a}=yt(yn),n=Ce(()=>({[Bn(t.activeClass,a.linkActiveClass,"router-link-active")]:s.isActive,[Bn(t.exactActiveClass,a.linkExactActiveClass,"router-link-exact-active")]:s.isExactActive}));return()=>{const o=e.default&&e.default(s);return t.custom?o:Kn("a",{"aria-current":s.isExactActive?t.ariaCurrentValue:null,href:s.href,onClick:s.navigate,class:n.value},o)}}}),Ro=Vo;function No(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)&&!t.defaultPrevented&&!(t.button!==void 0&&t.button!==0)){if(t.currentTarget&&t.currentTarget.getAttribute){const e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function Bo(t,e){for(const s in e){const a=e[s],n=t[s];if(typeof a=="string"){if(a!==n)return!1}else if(!Ee(n)||n.length!==a.length||a.some((o,m)=>o!==n[m]))return!1}return!0}function Nn(t){return t?t.aliasOf?t.aliasOf.path:t.path:""}const Bn=(t,e,s)=>t!=null?t:e!=null?e:s,Fo=Jn({name:"RouterView",inheritAttrs:!1,props:{name:{type:String,default:"default"},route:Object},compatConfig:{MODE:3},setup(t,{attrs:e,slots:s}){const a=yt(mn),n=Ce(()=>t.route||a.value),o=yt(Vn,0),m=Ce(()=>{let d=ut(o);const{matched:u}=n.value;let p;for(;(p=u[d])&&!p.components;)d++;return d}),h=Ce(()=>n.value.matched[m.value]);Kt(Vn,Ce(()=>m.value+1)),Kt(qo,h),Kt(mn,n);const f=Os();return Vs(()=>[f.value,h.value,t.name],([d,u,p],[g,v,I])=>{u&&(u.instances[p]=d,v&&v!==u&&d&&d===g&&(u.leaveGuards.size||(u.leaveGuards=v.leaveGuards),u.updateGuards.size||(u.updateGuards=v.updateGuards))),d&&u&&(!v||!tt(u,v)||!g)&&(u.enterCallbacks[p]||[]).forEach(C=>C(d))},{flush:"post"}),()=>{const d=n.value,u=t.name,p=h.value,g=p&&p.components[u];if(!g)return Fn(s.default,{Component:g,route:d});const v=p.props[u],I=v?v===!0?d.params:typeof v=="function"?v(d):v:null,V=Kn(g,Q({},I,e,{onVnodeUnmounted:F=>{F.component.isUnmounted&&(p.instances[u]=null)},ref:f}));return Fn(s.default,{Component:V,route:d})||V}}});function Fn(t,e){if(!t)return null;const s=t(e);return s.length===1?s[0]:s}const Wo=Fo;function Xo(t){const e=ko(t.routes,t),s=t.parseQuery||Mo,a=t.stringifyQuery||On,n=t.history,o=lt(),m=lt(),h=lt(),f=Ps(Ne);let d=Ne;Ke&&t.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const u=Zt.bind(null,y=>""+y),p=Zt.bind(null,Ks),g=Zt.bind(null,bt);function v(y,E){let x,T;return us(y)?(x=e.getRecordMatcher(y),T=E):T=y,e.addRoute(T,x)}function I(y){const E=e.getRecordMatcher(y);E&&e.removeRoute(E)}function C(){return e.getRoutes().map(y=>y.record)}function V(y){return!!e.getRecordMatcher(y)}function F(y,E){if(E=Q({},E||f.value),typeof y=="string"){const O=$t(s,y,E.path),se=e.resolve({path:O.path},E),at=n.createHref(O.fullPath);return Q(O,se,{params:g(se.params),hash:bt(O.hash),redirectedFrom:void 0,href:at})}let x;if(y.path!=null)x=Q({},y,{path:$t(s,y.path,E.path).path});else{const O=Q({},y.params);for(const se in O)O[se]==null&&delete O[se];x=Q({},y,{params:p(O)}),E.params=p(E.params)}const T=e.resolve(x,E),L=y.hash||"";T.params=u(g(T.params));const $=eo(a,Q({},y,{hash:Gs(L),path:T.path})),R=n.createHref($);return Q({fullPath:$,hash:L,query:a===On?jo(y.query):y.query||{}},T,{redirectedFrom:void 0,href:R})}function D(y){return typeof y=="string"?$t(s,y,f.value.path):Q({},y)}function q(y,E){if(d!==y)return nt(8,{from:E,to:y})}function z(y){return Z(y)}function ce(y){return z(Q(D(y),{replace:!0}))}function ne(y){const E=y.matched[y.matched.length-1];if(E&&E.redirect){const{redirect:x}=E;let T=typeof x=="function"?x(y):x;return typeof T=="string"&&(T=T.includes("?")||T.includes("#")?T=D(T):{path:T},T.params={}),Q({query:y.query,hash:y.hash,params:T.path!=null?{}:y.params},T)}}function Z(y,E){const x=d=F(y),T=f.value,L=y.state,$=y.force,R=y.replace===!0,O=ne(x);if(O)return Z(Q(D(O),{state:typeof O=="object"?Q({},L,O.state):L,force:$,replace:R}),E||x);const se=x;se.redirectedFrom=E;let at;return!$&&to(a,T,x)&&(at=nt(16,{to:se,from:T}),ot(T,T,!0,!1)),(at?Promise.resolve(at):Ve(se,T)).catch(he=>Me(he)?Me(he,2)?he:Tt(he):Pe(he,se,T)).then(he=>{if(he){if(Me(he,2))return Z(Q({replace:R},D(he.to),{state:typeof he.to=="object"?Q({},L,he.to.state):L,force:$}),E||se)}else he=Re(se,T,!0,R,L);return ye(se,T,he),he})}function Qe(y,E){const x=q(y,E);return x?Promise.reject(x):Promise.resolve()}function ie(y){const E=At.values().next().value;return E&&typeof E.runWithContext=="function"?E.runWithContext(y):y()}function Ve(y,E){let x;const[T,L,$]=Uo(y,E);x=en(T.reverse(),"beforeRouteLeave",y,E);for(const O of T)O.leaveGuards.forEach(se=>{x.push(Be(se,y,E))});const R=Qe.bind(null,y,E);return x.push(R),Ge(x).then(()=>{x=[];for(const O of o.list())x.push(Be(O,y,E));return x.push(R),Ge(x)}).then(()=>{x=en(L,"beforeRouteUpdate",y,E);for(const O of L)O.updateGuards.forEach(se=>{x.push(Be(se,y,E))});return x.push(R),Ge(x)}).then(()=>{x=[];for(const O of $)if(O.beforeEnter)if(Ee(O.beforeEnter))for(const se of O.beforeEnter)x.push(Be(se,y,E));else x.push(Be(O.beforeEnter,y,E));return x.push(R),Ge(x)}).then(()=>(y.matched.forEach(O=>O.enterCallbacks={}),x=en($,"beforeRouteEnter",y,E,ie),x.push(R),Ge(x))).then(()=>{x=[];for(const O of m.list())x.push(Be(O,y,E));return x.push(R),Ge(x)}).catch(O=>Me(O,8)?O:Promise.reject(O))}function ye(y,E,x){h.list().forEach(T=>ie(()=>T(y,E,x)))}function Re(y,E,x,T,L){const $=q(y,E);if($)return $;const R=E===Ne,O=Ke?history.state:{};x&&(T||R?n.replace(y.fullPath,Q({scroll:R&&O&&O.scroll},L)):n.push(y.fullPath,L)),f.value=y,ot(y,E,x,R),Tt()}let de;function Ae(){de||(de=n.listen((y,E,x)=>{if(!En.listening)return;const T=F(y),L=ne(T);if(L){Z(Q(L,{replace:!0}),T).catch(ht);return}d=T;const $=f.value;Ke&&co(Tn($.fullPath,x.delta),Ht()),Ve(T,$).catch(R=>Me(R,12)?R:Me(R,2)?(Z(R.to,T).then(O=>{Me(O,20)&&!x.delta&&x.type===wt.pop&&n.go(-1,!1)}).catch(ht),Promise.reject()):(x.delta&&n.go(-x.delta,!1),Pe(R,T,$))).then(R=>{R=R||Re(T,$,!1),R&&(x.delta&&!Me(R,8)?n.go(-x.delta,!1):x.type===wt.pop&&Me(R,20)&&n.go(-1,!1)),ye(T,$,R)}).catch(ht)}))}let Se=lt(),be=lt(),De;function Pe(y,E,x){Tt(y);const T=be.list();return T.length?T.forEach(L=>L(y,E,x)):console.error(y),Promise.reject(y)}function Yt(){return De&&f.value!==Ne?Promise.resolve():new Promise((y,E)=>{Se.add([y,E])})}function Tt(y){return De||(De=!y,Ae(),Se.list().forEach(([E,x])=>y?x(y):E()),Se.reset()),y}function ot(y,E,x,T){const{scrollBehavior:L}=t;if(!Ke||!L)return Promise.resolve();const $=!x&&uo(Tn(y.fullPath,0))||(T||!x)&&history.state&&history.state.scroll||null;return js().then(()=>L(y,E,$)).then(R=>R&&ro(R)).catch(R=>Pe(R,y,E))}const it=y=>n.go(y);let Jt;const At=new Set,En={currentRoute:f,listening:!0,addRoute:v,removeRoute:I,clearRoutes:e.clearRoutes,hasRoute:V,getRoutes:C,resolve:F,options:t,push:z,replace:ce,go:it,back:()=>it(-1),forward:()=>it(1),beforeEach:o.add,beforeResolve:m.add,afterEach:h.add,onError:be.add,isReady:Yt,install(y){const E=this;y.component("RouterLink",Ro),y.component("RouterView",Wo),y.config.globalProperties.$router=E,Object.defineProperty(y.config.globalProperties,"$route",{enumerable:!0,get:()=>ut(f)}),Ke&&!Jt&&f.value===Ne&&(Jt=!0,z(n.location).catch(L=>{}));const x={};for(const L in Ne)Object.defineProperty(x,L,{get:()=>f.value[L],enumerable:!0});y.provide(yn,E),y.provide(ps,Ms(x)),y.provide(mn,f);const T=y.unmount;At.add(y),y.unmount=function(){At.delete(y),At.size<1&&(d=Ne,de&&de(),de=null,f.value=Ne,Jt=!1,De=!1),T()}}};function Ge(y){return y.reduce((E,x)=>E.then(()=>ie(x)),Promise.resolve())}return En}function Uo(t,e){const s=[],a=[],n=[],o=Math.max(e.matched.length,t.matched.length);for(let m=0;m<o;m++){const h=e.matched[m];h&&(t.matched.find(d=>tt(d,h))?a.push(h):s.push(h));const f=t.matched[m];f&&(e.matched.find(d=>tt(d,f))||n.push(f))}return[s,a,n]}const Qo={name:"QuoteEdit",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{quote:{quote_number:"",due_date:"",provisional_start_date:"",client_id:"",client:null,status:""},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchQuoteDetails()},methods:{cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.quote.client_id&&this.setClientById(this.quote.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchQuoteDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?(this.quote=e,this.setClientById(this.quote.client_id)):(console.error("Error fetching quote details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching quote details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.quote.client=this.clients.find(e=>e.id===t)||null,this.quote.client_id=t},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting quote:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Lo={class:"pt-2 pr-4"},zo={class:"flex justify-between items-center mb-4"},Ho={class:"card-title"},Go=i("div",{class:"divider mt-2"},null,-1),Yo={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Jo={class:"grid grid-cols-3 gap-4"},Ko={class:"ecwp-group form-group mb-4"},Zo={for:"quoteNumber",class:"ecwp-label"},$o={class:"ecwp-group form-group mb-4"},ei={for:"quoteDate",class:"ecwp-label"},ti={class:"ecwp-group form-group mb-4"},ni={for:"quoteProvisanalDate",class:"ecwp-label"},si={class:"grid grid-cols-2 gap-4"},oi={class:"ecwp-group form-group mb-4"},ii={for:"client",class:"ecwp-label"},ai={class:"ecwp-group form-group mb-4"},li={for:"status",class:"ecwp-label"},ri={value:"draft"},ci={value:"pending"},di={value:"approved"},ui={value:"rejected"},hi={class:"flex justify-between"},mi=["disabled"],fi={key:0,class:"loading loading-spinner loading-sm"};function pi(t,e,s,a,n,o){const m=j("VueDatePicker"),h=j("model-select"),f=j("Card");return r(),c("div",Lo,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),P(f,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:re(()=>[i("div",zo,[i("h2",Ho,l(o.translations.edit_quote),1)]),Go,n.loading?(r(),c("div",Yo)):_("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...d)=>o.submitQuote&&o.submitQuote(...d),["prevent"]))},[i("div",Jo,[i("div",Ko,[i("label",Zo,l(o.translations.quote_number),1),B(i("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=d=>n.quote.quote_number=d),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[J,n.quote.quote_number]])]),i("div",$o,[i("label",ei,l(o.translations.due_date),1),P(m,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=d=>n.quote.due_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])]),i("div",ti,[i("label",ni,l(o.translations.provisional_date),1),P(m,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteProvisanalDate",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=d=>n.quote.provisional_start_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])])]),i("div",si,[i("div",oi,[i("label",ii,l(o.translations.company_name),1),P(h,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[3]||(e[3]=d=>n.quote.client_id=d),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",ai,[i("label",li,l(o.translations.status),1),B(i("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=d=>n.quote.status=d),required:"",class:k(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[i("option",ri,l(o.translations.draft),1),i("option",ci,l(o.translations.pending),1),i("option",di,l(o.translations.approved),1),i("option",ui,l(o.translations.rejected),1)],2),[[ve,n.quote.status]])])]),i("div",hi,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...d)=>o.cancelAction&&o.cancelAction(...d))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(r(),c("span",fi)):_("",!0)],8,mi)])],32)]),_:1})])}var _s=oe(Qo,[["render",pi]]);const _i={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm").close()}}},gi=["open"],vi={class:"modal-box"},yi={class:"font-bold text-lg"},bi=i("div",{class:"text-center text-red-400 mb-2"},[i("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),wi={class:"text-lg font-semibold text-center"},xi={class:"my-4 text-center text-xl"},Ii={class:"flex justify-between space-x-4"};function Ei(t,e,s,a,n,o){return r(),c("div",null,[i("dialog",{id:"modal_confirm",class:"modal",open:t.showModal},[i("div",vi,[i("h3",yi,l(t.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...m)=>o.closeModal&&o.closeModal(...m))}," \u2715 "),bi,i("h2",wi,l(s.title),1),i("p",xi,l(s.message),1),i("div",Ii,[i("button",{onClick:e[1]||(e[1]=(...m)=>o.onCancel&&o.onCancel(...m)),class:"btn btn-secondary rounded-full"},l(s.cancelText),1),i("button",{onClick:e[2]||(e[2]=(...m)=>o.onConfirm&&o.onConfirm(...m)),class:"btn rounded-full btn-error text-white"},l(s.confirmText),1)])])],8,gi)])}var bn=oe(_i,[["render",Ei]]);const Ci={name:"QuotesList",components:{Card:Ue,QuoteEditModal:_s,ConfirmModal:bn,RemoveModal:xt},data(){return{quotes:[],showQuoteDetailsModal:!1,editQuoteModal:!1,selectedQuote:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchQuotes(),this.loadSettings()},methods:{fetchQuotes(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/quotes?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.quotes=s.quotes,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching quotes:",s)}).finally(()=>{this.loading=!1})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return $n(t,this.default_vat.rate)},calculateWithoutVAT(t){return es(t)},generatePaginationButtons(){this.paginationButtons=ts(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchQuotes(t)},perPageChanged(){this.fetchQuotes()},formatAmount(t,e){return ns(t,e,this.settings.currency_position)},confirmDuplicateQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},duplicateQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/duplicate/${t}`,{method:"POST",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotes(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error duplicate quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},confirmDeleteQuote(t){this.selectedQuote=t,modal_remove.showModal(),this.showRemoveModal=!0},deleteQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotes(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},showToast(t,e){ss(this.toast,t,e)}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},ki={class:"pt-2 pr-4"},Ti={class:"flex justify-between items-center"},Ai={class:"card-title"},Si={class:"btn btn-primary rounded-full"},Di=i("i",{class:"fas fa-plus-circle"},null,-1),Pi={key:0,class:"ms-2"},Mi={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab2"},ji=i("i",{class:"fas fa-file-export"},null,-1),qi=["data-tip"],Oi={class:"btn btn-outline btn-accent rounded-full",disabled:""},Vi=i("i",{class:"fas fa-file-export"},null,-1),Ri=i("div",{class:"divider mt-2"},null,-1),Ni={class:"flex items-center mb-4"},Bi={for:"perPageSelect",class:"mr-2"},Fi=["value"],Wi={class:"overflow-x-auto"},Xi={key:0,class:"table w-full"},Ui={class:"flex justify-center"},Qi={key:0,class:"badge badge-warning badge-outline badge-sm"},Li={key:1,class:"badge badge-secondary badge-outline badge-sm"},zi={key:2,class:"badge badge-success badge-outline badge-sm"},Hi={key:3,class:"badge badge-error badge-outline badge-sm"},Gi={key:0},Yi={key:0},Ji={key:0},Ki={key:1},Zi={key:1},$i={key:0},ea={key:1},ta={key:1},na=i("span",{class:"loading loading-bars loading-sm"},null,-1),sa=[na],oa={key:0},ia={key:1},aa=i("span",{class:"loading loading-bars loading-sm"},null,-1),la=[aa],ra={key:0},ca={key:1},da=i("span",{class:"loading loading-bars loading-sm"},null,-1),ua=[da],ha={class:"flex justify-end"},ma=["data-tip"],fa=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"far fa-eye"})],-1),pa=["data-tip"],_a=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"fas fa-pencil-alt"})],-1),ga=["data-tip"],va=["onClick"],ya=i("i",{class:"far fa-copy"},null,-1),ba=[ya],wa=["data-tip"],xa=["onClick"],Ia=i("i",{class:"far fa-trash-alt"},null,-1),Ea=[Ia],Ca={key:1},ka=i("div",{class:"flex gap-4 items-center"},[i("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),i("div",{class:"flex flex-col gap-4 w-full"},[i("div",{class:"skeleton h-4 w-full"}),i("div",{class:"skeleton h-4 w-full"})])],-1),Ta=i("div",{class:"divider my-1"},null,-1),Aa=[ka,Ta],Sa={class:"join ecwp_pagination mt-6 pt-4"},Da=["onClick"];function Pa(t,e,s,a,n,o){const m=j("confirm-modal"),h=j("remove-modal"),f=j("router-link"),d=j("Card");return r(),c("div",ki,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),P(m,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=u=>this.duplicateQuote(n.selectedQuote)),onCancel:e[1]||(e[1]=u=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(h,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[2]||(e[2]=u=>this.deleteQuote(n.selectedQuote)),onCancel:e[3]||(e[3]=u=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(d,{topMargin:"mt-8"},{default:re(()=>[i("div",Ti,[i("h2",Ai,l(o.translations.quotes),1),i("div",null,[P(f,{to:{name:"QuoteNew"}},{default:re(()=>[i("button",Si,[w(l(o.translations.add)+" ",1),Di])]),_:1}),n.settings.easy_compta_export_addon_active==1?(r(),c("span",Pi,[i("a",Mi,[w(l(o.translations.export)+" ",1),ji])])):(r(),c("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[i("button",Oi,[w(l(o.translations.export)+" ",1),Vi])],8,qi))])]),Ri,i("div",Ni,[i("label",Bi,l(o.translations.display_per_page),1),B(i("select",{id:"perPageSelect","onUpdate:modelValue":e[4]||(e[4]=u=>n.perPage=u),onChange:e[5]||(e[5]=(...u)=>o.perPageChanged&&o.perPageChanged(...u))},[(r(!0),c(W,null,U(n.perPageOptions,u=>(r(),c("option",{key:u,value:u},l(u),9,Fi))),128))],544),[[ve,n.perPage]])]),i("div",Wi,[n.loading?(r(),c("div",Ca,[(r(!0),c(W,null,U(n.skeletonRows,u=>(r(),c("div",{key:u,class:"flex flex-col gap-4 w-full"},Aa))),128))])):(r(),c("table",Xi,[i("thead",null,[i("tr",null,[i("th",null,l(o.translations.quote_number),1),i("th",null,l(o.translations.client),1),i("th",null,l(o.translations.status),1),i("th",null,l(o.translations.total),1),i("th",null,l(o.translations.due_date),1),i("th",null,l(o.translations.created_at),1),i("th",Ui,l(o.translations.actions),1)])]),i("tbody",null,[(r(!0),c(W,null,U(n.quotes,u=>(r(),c("tr",{key:u.id},[i("td",null,l(u.quote_number),1),i("td",null,l(u.client_name),1),i("td",null,[u.status=="draft"?(r(),c("span",Qi,l(o.translations.draft),1)):_("",!0),u.status=="pending"?(r(),c("span",Li,l(o.translations.pending),1)):_("",!0),u.status=="approved"?(r(),c("span",zi,l(o.translations.approved),1)):_("",!0),u.status=="rejected"?(r(),c("span",Hi,l(o.translations.rejected),1)):_("",!0)]),i("td",null,[n.loadingPrice?(r(),c("div",ta,sa)):(r(),c("div",Gi,[n.settings.vat_active==1?(r(),c("div",Yi,[n.default_currency_symbol==u.client_currency||u.client_currency==null?(r(),c("span",Ji,l(o.formatAmount(u.total_amount,n.default_currency_symbol)),1)):(r(),c("span",Ki,l(o.formatAmount(u.total_amount,u.client_currency)),1))])):(r(),c("div",Zi,[n.default_currency_symbol==u.client_currency||u.client_currency==null?(r(),c("span",$i,l(o.formatAmount(u.total_amount,n.default_currency_symbol)),1)):(r(),c("span",ea,l(o.formatAmount(u.total_amount,u.client_currency)),1))]))]))]),i("td",null,[n.loadingPrice?(r(),c("div",ia,la)):(r(),c("div",oa,l(u.due_date),1))]),i("td",null,[n.loadingPrice?(r(),c("div",ca,ua)):(r(),c("div",ra,l(u.created),1))]),i("td",ha,[i("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(f,{to:{name:"QuoteViewDetail",params:{id:u.id}}},{default:re(()=>[fa]),_:2},1032,["to"])],8,ma),i("span",{class:"lg:tooltip","data-tip":o.translations.edit},[P(f,{to:{name:"QuoteEdit",params:{id:u.id}}},{default:re(()=>[_a]),_:2},1032,["to"])],8,pa),i("span",{class:"lg:tooltip","data-tip":o.translations.duplicate},[i("button",{onClick:p=>o.confirmDuplicateQuote(u.id),class:"btn btn-circle text-purple-600 hover:text-purple-900 mx-1"},ba,8,va)],8,ga),i("span",{class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:p=>o.confirmDeleteQuote(u.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},Ea,8,xa)],8,wa)])]))),128))])]))]),i("div",Sa,[(r(!0),c(W,null,U(n.paginationButtons,u=>(r(),c("button",{key:u,class:k(["join-item btn",{"btn-disabled":u==="..."||u===n.currentPage}]),onClick:p=>o.goToPage(u)},l(u),11,Da))),128))])]),_:1})])}var Ma=oe(Ci,[["render",Pa]]);const ja={name:"sendQuote",components:{VueEditor:Et.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,quoteId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"quote",id:this.quoteId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},qa=["id","open"],Oa={class:"modal-box"},Va={class:"font-bold text-lg"},Ra={key:0},Na={class:"grid grid-cols-1 gap-4"},Ba=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),Fa=i("div",{class:"skeleton h-4 w-full"},null,-1),Wa=[Ba,Fa],Xa={class:"grid grid-cols-1 gap-4"},Ua=["type"],Qa=["for"],La=["id","value","disabled","onInput"],za={key:1},Ha=["for"],Ga={class:"form-group mt-4 flex justify-end"},Ya=["disabled"],Ja={key:0,class:"loading loading-spinner loading-sm"};function Ka(t,e,s,a,n,o){const m=j("vue-editor");return r(),c("div",null,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",Oa,[i("h3",Va,l(o.translations.send_quote),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(r(),c("div",Ra,[i("div",Na,[(r(!0),c(W,null,U(o.skeletonItems,h=>(r(),c("div",{key:h,class:"py-2"},Wa))),128))])])):(r(),c("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",Xa,[(r(!0),c(W,null,U(n.fields,(h,f)=>(r(),c("div",{key:f,class:"ecwp-group form-group"},[h.type!=="textarea"?(r(),c("div",{key:0,type:h.type||"text"},[i("label",{for:f,class:"ecwp-label form-label"},l(h.label),9,Qa),i("input",{id:f,class:k(["ecwp-input input input-bordered",h.class||"w-full"]),value:h.value,disabled:h.disabled,onInput:d=>o.updateFieldValue(f,d.target.value)},null,42,La)],8,Ua)):(r(),c("div",za,[i("label",{for:f,class:"form-label"},l(h.label),9,Ha),P(m,{modelValue:h.value,"onUpdate:modelValue":d=>h.value=d,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",Ga,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.send)+" ",1),n.loadingBtn?(r(),c("span",Ja)):_("",!0)],8,Ya)])],32))])],8,qa)])}var Za=oe(ja,[["render",Ka]]);const $a={components:{VueDatePicker:It},props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},totalAmount:{type:String,required:!0},currency:{type:String,required:!0},advanceSold:{type:String,required:!0},quoteId:{type:Number,required:!0}},data(){return{showError:!1,selectedType:"",inputValue:0,due_date:"",invoiceSolded:!1,establishedAdvances:[],loading:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}},remainingAmount(){this.loading=!0;const t=this.establishedAdvances.reduce((e,s)=>{const a=parseFloat(s.advance_amount);return isNaN(a)?(console.error("Erreur: advance_amount n'est pas un nombre valide",s.advance_amount),e):e+a},0);return this.totalAmount-t},inputValueExceeds(){return this.remainingAmount==0?!0:this.selectedType==="percentage"?this.calculatedAmount>this.remainingAmount:this.selectedType==="fixed"?this.inputValue>this.remainingAmount:!1},calculatedAmount(){return this.selectedType==="percentage"?this.inputValue/100*this.remainingAmount:this.inputValue}},created(){this.fetchEstablishedAdvances(this.quoteId)},methods:{fetchEstablishedAdvances(t){const e=`/wp-json/my-easy-compta/v1/advance/${t}`;fetch(e,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.establishedAdvances=s}).catch(s=>{console.error("Error fetching advances:",s)})},onConfirm(){if(!this.inputValueExceeds){if(this.advanceSold=="no_sold"){if(!this.inputValue||!this.due_date||this.advanceSold=="no_sold"&&!this.selectedType){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:this.selectedType,value:this.inputValue,date:this.due_date})}else{if(!this.due_date){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:"fixed",value:this.remainingAmount,date:this.due_date})}this.closeModal()}},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_advance").close()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},el=["open"],tl={class:"modal-box overflow-visible"},nl={class:"font-bold text-lg"},sl={class:"text-lg font-semibold text-center"},ol={class:"my-4 text-center text-xl"},il={key:0,class:"text-red-500 text-sm"},al={class:"grid grid-cols-2 gap-4"},ll={key:0},rl={class:"flex ecwp-group form-group mb-4"},cl=i("label",{for:"advance-type",class:"ecwp-label"},"Type",-1),dl=i("option",{value:"percentage"},"Pourcentage",-1),ul=i("option",{value:"fixed"},"Montant fixe",-1),hl=[dl,ul],ml={key:1},fl={class:"flex ecwp-group form-group mb-4"},pl=i("label",{for:"advance-type",class:"ecwp-label"},"Valeur",-1),_l={class:"absolute items-center border rounded-md right-0 top-6"},gl={class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"},vl={key:0},yl={key:1},bl={key:1,class:"mt-2"},wl={class:"text-sm"},xl={key:2,class:"flex ecwp-group form-group mb-4"},Il={for:"quoteDate",class:"ecwp-label"},El={key:3},Cl={class:"flex justify-between space-x-4 mt-4"},kl=["disabled"];function Tl(t,e,s,a,n,o){const m=j("VueDatePicker");return r(),c("div",null,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),i("dialog",{id:"modal_advance",class:"modal",open:s.isVisible},[i("div",tl,[i("h3",nl,l(t.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...h)=>o.closeModal&&o.closeModal(...h))}," \u2715 "),i("h2",sl,l(s.title),1),i("p",ol," Montant total restant : "+l(o.remainingAmount)+" "+l(s.currency),1),o.inputValueExceeds&&!n.invoiceSolded?(r(),c("p",il," Le montant s\xE9lectionn\xE9 d\xE9passe le montant total du devis. ")):_("",!0),i("div",al,[s.advanceSold=="no_sold"&&!n.invoiceSolded?(r(),c("div",ll,[i("div",rl,[cl,B(i("select",{"onUpdate:modelValue":e[1]||(e[1]=h=>n.selectedType=h),id:"advance-type",class:k(["ecwp-select ecwp-input input input-bordered w-full",{"input-error":!n.selectedType&&n.showError}])},hl,2),[[ve,n.selectedType]])])])):_("",!0),n.selectedType&&s.advanceSold=="no_sold"&&!n.invoiceSolded?(r(),c("div",ml,[i("div",fl,[pl,B(i("input",{"onUpdate:modelValue":e[2]||(e[2]=h=>n.inputValue=h),type:"text",id:"advance-value",class:k([{"input-error":!n.inputValue&&n.showError},"ecwp-input input input-bordered w-full"])},null,2),[[J,n.inputValue]]),i("div",_l,[i("div",gl,[n.selectedType==="percentage"?(r(),c("span",vl,"%")):(r(),c("span",yl,l(s.currency),1))])])])])):_("",!0)]),n.selectedType==="percentage"&&!o.inputValueExceeds&!n.invoiceSolded?(r(),c("div",bl,[i("p",wl," Montant bas\xE9 sur le pourcentage: "+l(o.calculatedAmount)+" "+l(s.currency),1)])):_("",!0),n.invoiceSolded?_("",!0):(r(),c("div",xl,[i("label",Il,l(o.translations.due_date),1),P(m,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.inputValue&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.due_date,"onUpdate:modelValue":e[3]||(e[3]=h=>n.due_date=h),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr",required:""},null,8,["modelValue","format","min-date","class"])])),n.invoiceSolded?(r(),c("div",El,"Facture d\xE9j\xE0 sold\xE9")):_("",!0),i("div",Cl,[i("button",{onClick:e[4]||(e[4]=(...h)=>o.onCancel&&o.onCancel(...h)),class:"btn btn-secondary rounded-full"},l(s.cancelText),1),i("button",{onClick:e[5]||(e[5]=(...h)=>o.onConfirm&&o.onConfirm(...h)),disabled:o.inputValueExceeds,class:"btn rounded-full btn-error text-white"},l(s.confirmText),9,kl)])])],8,el)])}var Al=oe($a,[["render",Tl]]);const Sl={name:"QuoteNavBar",components:{SendQuoteModal:Za,ConfirmModal:bn,AdvanceModal:Al},props:{quoteInfo:Object,emailActive:Number,advanceActive:Number,currency:String,noItems:Boolean},data(){return{selectedQuote:null,advanceSold:!1,sendQuoteModal:!1,loadingModal:!1,loadingPdf:!1,loading:!1,client_detail:null,subject:"",content:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{async changeQuoteStatus(t){try{const s=await(await fetch("/wp-json/my-easy-compta/v1/quotes/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.quoteInfo.id,status:t})})).json();s.success?(this.quoteInfo.status=t,this.quoteInfo.total_amount=s.total_amount,this.showToast(s.message,"alert-success")):(console.error("Failed to update quote status:",s.message),this.showToast(s.message,"alert-error"))}catch(e){console.error("An error occurred while updating quote status:",e),this.showToast(e,"alert-error")}},convertToInvoice(t){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-quote/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e.success?(this.showToast(e.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:e.id}})):this.showToast(e.message,"alert-error")}).catch(e=>{console.error("Error converting quote:",e),this.showToast(e.message,"alert-error")})},handleAdvanceInvoiceConfirm(t){const{type:e,value:s,date:a}=t;this.convertAdvanceInvoice(this.selectedQuote,e,s,a)},convertAdvanceInvoice(t,e,s,a){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-advance/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({advance_type:e,advance_value:s,advance_date:a})}).then(n=>n.json()).then(n=>{n.success?(this.showToast(n.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:n.id}})):this.showToast(n.message,"alert-error")}).catch(n=>{console.error("Error converting quote:",n),this.showToast(n.message,"alert-error")})},confirmConvertQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},ConvertAdvanceQuote(t,e){this.selectedQuote=t,this.advanceSold=e,modal_advance.showModal(),this.showRemoveModal=!0},exportToPDF(){this.loadingPdf=!0;const t=this.quoteInfo.id;fetch(`/wp-json/my-easy-compta/v1/quotes/pdf/${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return this.loadingPdf=!1,e.blob()}).then(e=>{const s=URL.createObjectURL(e);window.open(s),this.loadingPdf=!1}).catch(e=>{console.error("There was a problem with the fetch operation:",e),this.loadingPdf=!1})},sendQuote(t){this.loadingModal=!0,this.sendQuoteModal=!0,modal_send_quote.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(t.ok){const e=await t.json();this.subject=e.email_quote_subject,this.content=e.email_quote_content,this.loading=!1}else{const e=await t.json();this.showToast(e.message,"alert-error"),this.loading=!1}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Dl={key:0},Pl={key:1},Ml={key:3,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},jl=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),ql=[jl],Ol={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},Vl=i("div",{class:"dropdown"},[i("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),i("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[i("li",null,[i("a",null,"Item 1")]),i("li",null,[i("a",null,"Parent"),i("ul",{class:"p-2"},[i("li",null,[i("a",null,"Submenu 1")]),i("li",null,[i("a",null,"Submenu 2")])])]),i("li",null,[i("a",null,"Item 3")])])],-1),Rl={class:"hidden lg:flex gap-2"},Nl={class:"btn btn-sm"},Bl=i("i",{class:"far fa-edit"},null,-1),Fl=i("i",{class:"fa fa-check"},null,-1),Wl=["data-tip"],Xl={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Ul=i("i",{class:"fas fa-check"},null,-1),Ql=i("i",{class:"fa fa-check"},null,-1),Ll=i("i",{class:"fa fa-times"},null,-1),zl={key:4},Hl={class:"dropdown"},Gl={tabindex:"0",role:"button",class:"btn btn-sm"},Yl=i("i",{class:"fas fa-exchange-alt"},null,-1),Jl={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},Kl={key:0},Zl={key:5},$l=i("i",{class:"fas fa-exchange-alt"},null,-1),er={class:"flex gap-2"},tr=i("i",{class:"fas fa-paper-plane"},null,-1),nr={key:0,class:"far fa-envelope"},sr=["data-tip"],or={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},ir=i("i",{class:"fas fa-paper-plane"},null,-1),ar=["data-tip"],lr={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},rr=i("i",{class:"fas fa-paper-plane"},null,-1),cr=["disabled"],dr=i("i",{class:"far fa-file-pdf"},null,-1),ur={key:0,class:"loading loading-spinner loading-sm"};function hr(t,e,s,a,n,o){const m=j("send-quote-modal"),h=j("confirm-modal"),f=j("advance-modal"),d=j("router-link");return r(),c("div",null,[s.emailActive==1?(r(),c("div",Dl,[P(m,{loading:n.loadingModal,"show-modal":n.sendQuoteModal,"modal-id":"modal_send_quote",client:n.client_detail,"quote-id":s.quoteInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=u=>n.sendQuoteModal=!1)},null,8,["loading","show-modal","client","quote-id","subject","content"])])):_("",!0),P(h,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[1]||(e[1]=u=>this.convertToInvoice(n.selectedQuote)),onCancel:e[2]||(e[2]=u=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),s.advanceActive==1?(r(),c("div",Pl,[P(f,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,"total-amount":s.quoteInfo.total_amount,currency:s.currency,quoteId:s.quoteInfo.id,"advance-sold":n.advanceSold,onConfirm:o.handleAdvanceInvoiceConfirm,onCancel:e[3]||(e[3]=u=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","total-amount","currency","quoteId","advance-sold","onConfirm"])])):_("",!0),n.toast.visible?(r(),c("div",{key:2,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),n.loading?(r(),c("div",Ml,ql)):_("",!0),i("div",Ol,[i("div",null,[Vl,i("div",Rl,[P(d,{to:{name:"QuoteEdit",params:{id:s.quoteInfo.id}}},{default:re(()=>[i("button",Nl,[Bl,w(l(o.translations.edit_quote),1)])]),_:1},8,["to"]),s.quoteInfo.status=="draft"&&!s.noItems?(r(),c("button",{key:0,class:"btn btn-outline btn-success btn-sm",onClick:e[4]||(e[4]=u=>o.changeQuoteStatus("pending"))},[Fl,w(" "+l(o.translations.validate_quote),1)])):_("",!0),s.quoteInfo.status=="draft"&&s.noItems?(r(),c("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.min_article},[i("button",Xl,[Ul,w(" "+l(o.translations.validate_quote),1)])],8,Wl)):_("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="rejected")&&!s.noItems?(r(),c("button",{key:2,class:"btn btn-outline btn-success btn-sm",onClick:e[5]||(e[5]=u=>o.changeQuoteStatus("approved"))},[Ql,w(" "+l(o.translations.mark_as_accepted),1)])):_("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="approved")&&!s.noItems?(r(),c("button",{key:3,class:"btn btn-outline btn-error btn-sm",onClick:e[6]||(e[6]=u=>o.changeQuoteStatus("rejected"))},[Ll,w(" "+l(o.translations.mark_as_rejected),1)])):_("",!0),s.advanceActive==1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(r(),c("div",zl,[i("div",Hl,[i("div",Gl,[Yl,w(" "+l(o.translations.convertToInvoice),1)]),i("ul",Jl,[s.quoteInfo.advance!=1?(r(),c("li",Kl,[i("a",{href:"#",onClick:e[7]||(e[7]=K(u=>o.confirmConvertQuote(s.quoteInfo.id),["prevent"]))}," Facture global ")])):_("",!0),i("li",null,[i("a",{href:"#",onClick:e[8]||(e[8]=K(u=>o.ConvertAdvanceQuote(s.quoteInfo.id,"no_sold"),["prevent"]))}," Facture d'acompte "),s.quoteInfo.advance!=0?(r(),c("a",{key:0,href:"#",onClick:e[9]||(e[9]=K(u=>o.ConvertAdvanceQuote(s.quoteInfo.id,"sold"),["prevent"]))}," Facture du solde ")):_("",!0)])])])])):_("",!0),s.advanceActive!=1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(r(),c("div",Zl,[i("button",{onClick:e[10]||(e[10]=u=>o.confirmConvertQuote(s.quoteInfo.id)),class:"btn btn-sm"},[$l,w(" "+l(o.translations.convertToInvoice),1)])])):_("",!0)])]),i("div",er,[s.emailActive==1&&!s.noItems?(r(),c("button",{key:0,onClick:e[11]||(e[11]=K(u=>o.sendQuote(s.quoteInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[tr,w(" "+l(o.translations.send_quote)+" ",1),s.quoteInfo.sent==1?(r(),c("i",nr)):_("",!0)])):s.emailActive==0?(r(),c("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[i("button",or,[ir,w(" "+l(o.translations.send_quote),1)])],8,sr)):s.emailActive==1&&s.noItems?(r(),c("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.min_article},[i("button",lr,[rr,w(" "+l(o.translations.send_quote),1)])],8,ar)):_("",!0),i("button",{onClick:e[12]||(e[12]=(...u)=>o.exportToPDF&&o.exportToPDF(...u)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[dr,w(" "+l(o.translations.exportToPDF)+" ",1),n.loadingPdf?(r(),c("span",ur)):_("",!0)],8,cr)])])])}var mr=oe(Sl,[["render",hr]]);const fr={components:{VueEditor:Et.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:t.item_name},item_description:{label:t.description,type:"textarea"},quantity:{label:t.quantity,type:"number"},vat_rate:{label:"Taux de TVA",type:"number"},unit_price:{label:t.unit_price,type:"number"},discount:{label:t.discount,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/quotes/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},pr=["id","open"],_r={class:"modal-box"},gr={class:"font-bold text-lg"},vr={key:0},yr={class:"grid grid-cols-1 gap-4"},br=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),wr=i("div",{class:"skeleton h-4 w-full"},null,-1),xr=[br,wr],Ir={class:"grid grid-cols-1 gap-4"},Er=["type"],Cr=["for"],kr=["id","onUpdate:modelValue"],Tr={key:1},Ar=["for"],Sr={class:"form-group mt-4 flex justify-end"},Dr=["disabled"],Pr={key:0,class:"loading loading-spinner loading-sm"};function Mr(t,e,s,a,n,o){const m=j("vue-editor");return r(),c("div",null,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",_r,[i("h3",gr,l(s.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(r(),c("div",vr,[i("div",yr,[(r(!0),c(W,null,U(o.skeletonItems,h=>(r(),c("div",{key:h,class:"py-2"},xr))),128))])])):(r(),c("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",Ir,[(r(!0),c(W,null,U(n.fields,(h,f)=>(r(),c("div",{key:f,class:"ecwp-group form-group"},[h.type!=="textarea"?(r(),c("div",{key:0,type:h.type||"text"},[i("label",{for:f,class:"ecwp-label form-label"},l(h.label),9,Cr),B(i("input",{id:f,"onUpdate:modelValue":d=>n.editedItem[f]=d,class:k(["ecwp-input input input-bordered",h.class||"w-full"])},null,10,kr),[[J,n.editedItem[f]]])],8,Er)):(r(),c("div",Tr,[i("label",{for:f,class:"form-label"},l(h.label),9,Ar),P(m,{id:f,modelValue:n.editedItem[f],"onUpdate:modelValue":d=>n.editedItem[f]=d,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",Sr,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(r(),c("span",Pr)):_("",!0)],8,Dr)])],32))])],8,pr)])}var jr=oe(fr,[["render",Mr]]);/**! 6 6 * Sortable 1.15.2 7 7 * @author RubaXa <[email protected]> 8 8 * @author owenm <[email protected]> 9 9 * @license MIT 10 */function Wn(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),s.push.apply(s,a)}return s}function Te(t){for(var e=1;e<arguments.length;e++){var s=arguments[e]!=null?arguments[e]:{};e%2?Wn(Object(s),!0).forEach(function(a){qr(t,a,s[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):Wn(Object(s)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(s,a))})}return t}function Mt(t){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Mt=function(e){return typeof e}:Mt=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Mt(t)}function qr(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function qe(){return qe=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(t[a]=s[a])}return t},qe.apply(this,arguments)}function Or(t,e){if(t==null)return{};var s={},a=Object.keys(t),n,o;for(o=0;o<a.length;o++)n=a[o],!(e.indexOf(n)>=0)&&(s[n]=t[n]);return s}function Vr(t,e){if(t==null)return{};var s=Or(t,e),a,n;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)a=o[n],!(e.indexOf(a)>=0)&&(!Object.prototype.propertyIsEnumerable.call(t,a)||(s[a]=t[a]))}return s}var Rr="1.15.2";function Me(t){if(typeof window!="undefined"&&window.navigator)return!!navigator.userAgent.match(t)}var Oe=Me(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),Ct=Me(/Edge/i),Xn=Me(/firefox/i),ft=Me(/safari/i)&&!Me(/chrome/i)&&!Me(/android/i),gs=Me(/iP(ad|od|hone)/i),vs=Me(/chrome/i)&&Me(/android/i),ys={capture:!1,passive:!1};function W(t,e,s){t.addEventListener(e,s,!Oe&&ys)}function N(t,e,s){t.removeEventListener(e,s,!Oe&&ys)}function Nt(t,e){if(!!e){if(e[0]===">"&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch{return!1}return!1}}function Nr(t){return t.host&&t!==document&&t.host.nodeType?t.host:t.parentNode}function xe(t,e,s,a){if(t){s=s||document;do{if(e!=null&&(e[0]===">"?t.parentNode===s&&Nt(t,e):Nt(t,e))||a&&t===s)return t;if(t===s)break}while(t=Nr(t))}return null}var Un=/\s+/g;function fe(t,e,s){if(t&&e)if(t.classList)t.classList[s?"add":"remove"](e);else{var a=(" "+t.className+" ").replace(Un," ").replace(" "+e+" "," ");t.className=(a+(s?" "+e:"")).replace(Un," ")}}function S(t,e,s){var a=t&&t.style;if(a){if(s===void 0)return document.defaultView&&document.defaultView.getComputedStyle?s=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(s=t.currentStyle),e===void 0?s:s[e];!(e in a)&&e.indexOf("webkit")===-1&&(e="-webkit-"+e),a[e]=s+(typeof s=="string"?"":"px")}}function et(t,e){var s="";if(typeof t=="string")s=t;else do{var a=S(t,"transform");a&&a!=="none"&&(s=a+" "+s)}while(!e&&(t=t.parentNode));var n=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return n&&new n(s)}function bs(t,e,s){if(t){var a=t.getElementsByTagName(e),n=0,o=a.length;if(s)for(;n<o;n++)s(a[n],n);return a}return[]}function ke(){var t=document.scrollingElement;return t||document.documentElement}function te(t,e,s,a,n){if(!(!t.getBoundingClientRect&&t!==window)){var o,f,h,m,r,u,p;if(t!==window&&t.parentNode&&t!==ke()?(o=t.getBoundingClientRect(),f=o.top,h=o.left,m=o.bottom,r=o.right,u=o.height,p=o.width):(f=0,h=0,m=window.innerHeight,r=window.innerWidth,u=window.innerHeight,p=window.innerWidth),(e||s)&&t!==window&&(n=n||t.parentNode,!Oe))do if(n&&n.getBoundingClientRect&&(S(n,"transform")!=="none"||s&&S(n,"position")!=="static")){var _=n.getBoundingClientRect();f-=_.top+parseInt(S(n,"border-top-width")),h-=_.left+parseInt(S(n,"border-left-width")),m=f+o.height,r=h+o.width;break}while(n=n.parentNode);if(a&&t!==window){var v=et(n||t),I=v&&v.a,C=v&&v.d;v&&(f/=C,h/=I,p/=I,u/=C,m=f+u,r=h+p)}return{top:f,left:h,bottom:m,right:r,width:p,height:u}}}function Qn(t,e,s){for(var a=Xe(t,!0),n=te(t)[e];a;){var o=te(a)[s],f=void 0;if(s==="top"||s==="left"?f=n>=o:f=n<=o,!f)return a;if(a===ke())break;a=Xe(a,!1)}return!1}function st(t,e,s,a){for(var n=0,o=0,f=t.children;o<f.length;){if(f[o].style.display!=="none"&&f[o]!==A.ghost&&(a||f[o]!==A.dragged)&&xe(f[o],s.draggable,t,!1)){if(n===e)return f[o];n++}o++}return null}function wn(t,e){for(var s=t.lastElementChild;s&&(s===A.ghost||S(s,"display")==="none"||e&&!Nt(s,e));)s=s.previousElementSibling;return s||null}function ge(t,e){var s=0;if(!t||!t.parentNode)return-1;for(;t=t.previousElementSibling;)t.nodeName.toUpperCase()!=="TEMPLATE"&&t!==A.clone&&(!e||Nt(t,e))&&s++;return s}function Ln(t){var e=0,s=0,a=ke();if(t)do{var n=et(t),o=n.a,f=n.d;e+=t.scrollLeft*o,s+=t.scrollTop*f}while(t!==a&&(t=t.parentNode));return[e,s]}function Br(t,e){for(var s in t)if(!!t.hasOwnProperty(s)){for(var a in e)if(e.hasOwnProperty(a)&&e[a]===t[s][a])return Number(s)}return-1}function Xe(t,e){if(!t||!t.getBoundingClientRect)return ke();var s=t,a=!1;do if(s.clientWidth<s.scrollWidth||s.clientHeight<s.scrollHeight){var n=S(s);if(s.clientWidth<s.scrollWidth&&(n.overflowX=="auto"||n.overflowX=="scroll")||s.clientHeight<s.scrollHeight&&(n.overflowY=="auto"||n.overflowY=="scroll")){if(!s.getBoundingClientRect||s===document.body)return ke();if(a||e)return s;a=!0}}while(s=s.parentNode);return ke()}function Fr(t,e){if(t&&e)for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t}function tn(t,e){return Math.round(t.top)===Math.round(e.top)&&Math.round(t.left)===Math.round(e.left)&&Math.round(t.height)===Math.round(e.height)&&Math.round(t.width)===Math.round(e.width)}var pt;function ws(t,e){return function(){if(!pt){var s=arguments,a=this;s.length===1?t.call(a,s[0]):t.apply(a,s),pt=setTimeout(function(){pt=void 0},e)}}}function Wr(){clearTimeout(pt),pt=void 0}function xs(t,e,s){t.scrollLeft+=e,t.scrollTop+=s}function Is(t){var e=window.Polymer,s=window.jQuery||window.Zepto;return e&&e.dom?e.dom(t).cloneNode(!0):s?s(t).clone(!0)[0]:t.cloneNode(!0)}function Es(t,e,s){var a={};return Array.from(t.children).forEach(function(n){var o,f,h,m;if(!(!xe(n,e.draggable,t,!1)||n.animated||n===s)){var r=te(n);a.left=Math.min((o=a.left)!==null&&o!==void 0?o:1/0,r.left),a.top=Math.min((f=a.top)!==null&&f!==void 0?f:1/0,r.top),a.right=Math.max((h=a.right)!==null&&h!==void 0?h:-1/0,r.right),a.bottom=Math.max((m=a.bottom)!==null&&m!==void 0?m:-1/0,r.bottom)}}),a.width=a.right-a.left,a.height=a.bottom-a.top,a.x=a.left,a.y=a.top,a}var _e="Sortable"+new Date().getTime();function Xr(){var t=[],e;return{captureAnimationState:function(){if(t=[],!!this.options.animation){var a=[].slice.call(this.el.children);a.forEach(function(n){if(!(S(n,"display")==="none"||n===A.ghost)){t.push({target:n,rect:te(n)});var o=Te({},t[t.length-1].rect);if(n.thisAnimationDuration){var f=et(n,!0);f&&(o.top-=f.f,o.left-=f.e)}n.fromRect=o}})}},addAnimationState:function(a){t.push(a)},removeAnimationState:function(a){t.splice(Br(t,{target:a}),1)},animateAll:function(a){var n=this;if(!this.options.animation){clearTimeout(e),typeof a=="function"&&a();return}var o=!1,f=0;t.forEach(function(h){var m=0,r=h.target,u=r.fromRect,p=te(r),_=r.prevFromRect,v=r.prevToRect,I=h.rect,C=et(r,!0);C&&(p.top-=C.f,p.left-=C.e),r.toRect=p,r.thisAnimationDuration&&tn(_,p)&&!tn(u,p)&&(I.top-p.top)/(I.left-p.left)===(u.top-p.top)/(u.left-p.left)&&(m=Qr(I,_,v,n.options)),tn(p,u)||(r.prevFromRect=u,r.prevToRect=p,m||(m=n.options.animation),n.animate(r,I,p,m)),m&&(o=!0,f=Math.max(f,m),clearTimeout(r.animationResetTimer),r.animationResetTimer=setTimeout(function(){r.animationTime=0,r.prevFromRect=null,r.fromRect=null,r.prevToRect=null,r.thisAnimationDuration=null},m),r.thisAnimationDuration=m)}),clearTimeout(e),o?e=setTimeout(function(){typeof a=="function"&&a()},f):typeof a=="function"&&a(),t=[]},animate:function(a,n,o,f){if(f){S(a,"transition",""),S(a,"transform","");var h=et(this.el),m=h&&h.a,r=h&&h.d,u=(n.left-o.left)/(m||1),p=(n.top-o.top)/(r||1);a.animatingX=!!u,a.animatingY=!!p,S(a,"transform","translate3d("+u+"px,"+p+"px,0)"),this.forRepaintDummy=Ur(a),S(a,"transition","transform "+f+"ms"+(this.options.easing?" "+this.options.easing:"")),S(a,"transform","translate3d(0,0,0)"),typeof a.animated=="number"&&clearTimeout(a.animated),a.animated=setTimeout(function(){S(a,"transition",""),S(a,"transform",""),a.animated=!1,a.animatingX=!1,a.animatingY=!1},f)}}}}function Ur(t){return t.offsetWidth}function Qr(t,e,s,a){return Math.sqrt(Math.pow(e.top-t.top,2)+Math.pow(e.left-t.left,2))/Math.sqrt(Math.pow(e.top-s.top,2)+Math.pow(e.left-s.left,2))*a.animation}var Ye=[],nn={initializeByDefault:!0},kt={mount:function(e){for(var s in nn)nn.hasOwnProperty(s)&&!(s in e)&&(e[s]=nn[s]);Ye.forEach(function(a){if(a.pluginName===e.pluginName)throw"Sortable: Cannot mount plugin ".concat(e.pluginName," more than once")}),Ye.push(e)},pluginEvent:function(e,s,a){var n=this;this.eventCanceled=!1,a.cancel=function(){n.eventCanceled=!0};var o=e+"Global";Ye.forEach(function(f){!s[f.pluginName]||(s[f.pluginName][o]&&s[f.pluginName][o](Te({sortable:s},a)),s.options[f.pluginName]&&s[f.pluginName][e]&&s[f.pluginName][e](Te({sortable:s},a)))})},initializePlugins:function(e,s,a,n){Ye.forEach(function(h){var m=h.pluginName;if(!(!e.options[m]&&!h.initializeByDefault)){var r=new h(e,s,e.options);r.sortable=e,r.options=e.options,e[m]=r,qe(a,r.defaults)}});for(var o in e.options)if(!!e.options.hasOwnProperty(o)){var f=this.modifyOption(e,o,e.options[o]);typeof f!="undefined"&&(e.options[o]=f)}},getEventProperties:function(e,s){var a={};return Ye.forEach(function(n){typeof n.eventProperties=="function"&&qe(a,n.eventProperties.call(s[n.pluginName],e))}),a},modifyOption:function(e,s,a){var n;return Ye.forEach(function(o){!e[o.pluginName]||o.optionListeners&&typeof o.optionListeners[s]=="function"&&(n=o.optionListeners[s].call(e[o.pluginName],a))}),n}};function Lr(t){var e=t.sortable,s=t.rootEl,a=t.name,n=t.targetEl,o=t.cloneEl,f=t.toEl,h=t.fromEl,m=t.oldIndex,r=t.newIndex,u=t.oldDraggableIndex,p=t.newDraggableIndex,_=t.originalEvent,v=t.putSortable,I=t.extraEventProperties;if(e=e||s&&s[_e],!!e){var C,V=e.options,B="on"+a.charAt(0).toUpperCase()+a.substr(1);window.CustomEvent&&!Oe&&!Ct?C=new CustomEvent(a,{bubbles:!0,cancelable:!0}):(C=document.createEvent("Event"),C.initEvent(a,!0,!0)),C.to=f||s,C.from=h||s,C.item=n||s,C.clone=o,C.oldIndex=m,C.newIndex=r,C.oldDraggableIndex=u,C.newDraggableIndex=p,C.originalEvent=_,C.pullMode=v?v.lastPutMode:void 0;var D=Te(Te({},I),kt.getEventProperties(a,e));for(var q in D)C[q]=D[q];s&&s.dispatchEvent(C),V[B]&&V[B].call(e,C)}}var zr=["evt"],me=function(e,s){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},n=a.evt,o=Vr(a,zr);kt.pluginEvent.bind(A)(e,s,Te({dragEl:b,parentEl:Y,ghostEl:j,rootEl:H,nextEl:He,lastDownEl:qt,cloneEl:G,cloneHidden:We,dragStarted:rt,putSortable:ae,activeSortable:A.active,originalEvent:n,oldIndex:$e,oldDraggableIndex:_t,newIndex:pe,newDraggableIndex:Fe,hideGhostForTarget:As,unhideGhostForTarget:Ss,cloneNowHidden:function(){We=!0},cloneNowShown:function(){We=!1},dispatchSortableEvent:function(h){ue({sortable:s,name:h,originalEvent:n})}},o))};function ue(t){Lr(Te({putSortable:ae,cloneEl:G,targetEl:b,rootEl:H,oldIndex:$e,oldDraggableIndex:_t,newIndex:pe,newDraggableIndex:Fe},t))}var b,Y,j,H,He,qt,G,We,$e,pe,_t,Fe,St,ae,Ze=!1,Bt=!1,Ft=[],Le,be,sn,on,zn,Hn,rt,Je,gt,vt=!1,Dt=!1,Ot,le,an=[],fn=!1,Wt=[],Gt=typeof document!="undefined",Pt=gs,Gn=Ct||Oe?"cssFloat":"float",Hr=Gt&&!vs&&!gs&&"draggable"in document.createElement("div"),Cs=function(){if(!!Gt){if(Oe)return!1;var t=document.createElement("x");return t.style.cssText="pointer-events:auto",t.style.pointerEvents==="auto"}}(),ks=function(e,s){var a=S(e),n=parseInt(a.width)-parseInt(a.paddingLeft)-parseInt(a.paddingRight)-parseInt(a.borderLeftWidth)-parseInt(a.borderRightWidth),o=st(e,0,s),f=st(e,1,s),h=o&&S(o),m=f&&S(f),r=h&&parseInt(h.marginLeft)+parseInt(h.marginRight)+te(o).width,u=m&&parseInt(m.marginLeft)+parseInt(m.marginRight)+te(f).width;if(a.display==="flex")return a.flexDirection==="column"||a.flexDirection==="column-reverse"?"vertical":"horizontal";if(a.display==="grid")return a.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(o&&h.float&&h.float!=="none"){var p=h.float==="left"?"left":"right";return f&&(m.clear==="both"||m.clear===p)?"vertical":"horizontal"}return o&&(h.display==="block"||h.display==="flex"||h.display==="table"||h.display==="grid"||r>=n&&a[Gn]==="none"||f&&a[Gn]==="none"&&r+u>n)?"vertical":"horizontal"},Gr=function(e,s,a){var n=a?e.left:e.top,o=a?e.right:e.bottom,f=a?e.width:e.height,h=a?s.left:s.top,m=a?s.right:s.bottom,r=a?s.width:s.height;return n===h||o===m||n+f/2===h+r/2},Yr=function(e,s){var a;return Ft.some(function(n){var o=n[_e].options.emptyInsertThreshold;if(!(!o||wn(n))){var f=te(n),h=e>=f.left-o&&e<=f.right+o,m=s>=f.top-o&&s<=f.bottom+o;if(h&&m)return a=n}}),a},Ts=function(e){function s(o,f){return function(h,m,r,u){var p=h.options.group.name&&m.options.group.name&&h.options.group.name===m.options.group.name;if(o==null&&(f||p))return!0;if(o==null||o===!1)return!1;if(f&&o==="clone")return o;if(typeof o=="function")return s(o(h,m,r,u),f)(h,m,r,u);var _=(f?h:m).options.group.name;return o===!0||typeof o=="string"&&o===_||o.join&&o.indexOf(_)>-1}}var a={},n=e.group;(!n||Mt(n)!="object")&&(n={name:n}),a.name=n.name,a.checkPull=s(n.pull,!0),a.checkPut=s(n.put),a.revertClone=n.revertClone,e.group=a},As=function(){!Cs&&j&&S(j,"display","none")},Ss=function(){!Cs&&j&&S(j,"display","")};Gt&&!vs&&document.addEventListener("click",function(t){if(Bt)return t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation(),Bt=!1,!1},!0);var ze=function(e){if(b){e=e.touches?e.touches[0]:e;var s=Yr(e.clientX,e.clientY);if(s){var a={};for(var n in e)e.hasOwnProperty(n)&&(a[n]=e[n]);a.target=a.rootEl=s,a.preventDefault=void 0,a.stopPropagation=void 0,s[_e]._onDragOver(a)}}},Jr=function(e){b&&b.parentNode[_e]._isOutsideThisEl(e.target)};function A(t,e){if(!(t&&t.nodeType&&t.nodeType===1))throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=qe({},e),t[_e]=this;var s={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return ks(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(f,h){f.setData("Text",h.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:A.supportPointer!==!1&&"PointerEvent"in window&&!ft,emptyInsertThreshold:5};kt.initializePlugins(this,t,s);for(var a in s)!(a in e)&&(e[a]=s[a]);Ts(e);for(var n in this)n.charAt(0)==="_"&&typeof this[n]=="function"&&(this[n]=this[n].bind(this));this.nativeDraggable=e.forceFallback?!1:Hr,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?W(t,"pointerdown",this._onTapStart):(W(t,"mousedown",this._onTapStart),W(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(W(t,"dragover",this),W(t,"dragenter",this)),Ft.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),qe(this,Xr())}A.prototype={constructor:A,_isOutsideThisEl:function(e){!this.el.contains(e)&&e!==this.el&&(Je=null)},_getDirection:function(e,s){return typeof this.options.direction=="function"?this.options.direction.call(this,e,s,b):this.options.direction},_onTapStart:function(e){if(!!e.cancelable){var s=this,a=this.el,n=this.options,o=n.preventOnFilter,f=e.type,h=e.touches&&e.touches[0]||e.pointerType&&e.pointerType==="touch"&&e,m=(h||e).target,r=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||m,u=n.filter;if(oc(a),!b&&!(/mousedown|pointerdown/.test(f)&&e.button!==0||n.disabled)&&!r.isContentEditable&&!(!this.nativeDraggable&&ft&&m&&m.tagName.toUpperCase()==="SELECT")&&(m=xe(m,n.draggable,a,!1),!(m&&m.animated)&&qt!==m)){if($e=ge(m),_t=ge(m,n.draggable),typeof u=="function"){if(u.call(this,e,m,this)){ue({sortable:s,rootEl:r,name:"filter",targetEl:m,toEl:a,fromEl:a}),me("filter",s,{evt:e}),o&&e.cancelable&&e.preventDefault();return}}else if(u&&(u=u.split(",").some(function(p){if(p=xe(r,p.trim(),a,!1),p)return ue({sortable:s,rootEl:p,name:"filter",targetEl:m,fromEl:a,toEl:a}),me("filter",s,{evt:e}),!0}),u)){o&&e.cancelable&&e.preventDefault();return}n.handle&&!xe(r,n.handle,a,!1)||this._prepareDragStart(e,h,m)}}},_prepareDragStart:function(e,s,a){var n=this,o=n.el,f=n.options,h=o.ownerDocument,m;if(a&&!b&&a.parentNode===o){var r=te(a);if(H=o,b=a,Y=b.parentNode,He=b.nextSibling,qt=a,St=f.group,A.dragged=b,Le={target:b,clientX:(s||e).clientX,clientY:(s||e).clientY},zn=Le.clientX-r.left,Hn=Le.clientY-r.top,this._lastX=(s||e).clientX,this._lastY=(s||e).clientY,b.style["will-change"]="all",m=function(){if(me("delayEnded",n,{evt:e}),A.eventCanceled){n._onDrop();return}n._disableDelayedDragEvents(),!Xn&&n.nativeDraggable&&(b.draggable=!0),n._triggerDragStart(e,s),ue({sortable:n,name:"choose",originalEvent:e}),fe(b,f.chosenClass,!0)},f.ignore.split(",").forEach(function(u){bs(b,u.trim(),ln)}),W(h,"dragover",ze),W(h,"mousemove",ze),W(h,"touchmove",ze),W(h,"mouseup",n._onDrop),W(h,"touchend",n._onDrop),W(h,"touchcancel",n._onDrop),Xn&&this.nativeDraggable&&(this.options.touchStartThreshold=4,b.draggable=!0),me("delayStart",this,{evt:e}),f.delay&&(!f.delayOnTouchOnly||s)&&(!this.nativeDraggable||!(Ct||Oe))){if(A.eventCanceled){this._onDrop();return}W(h,"mouseup",n._disableDelayedDrag),W(h,"touchend",n._disableDelayedDrag),W(h,"touchcancel",n._disableDelayedDrag),W(h,"mousemove",n._delayedDragTouchMoveHandler),W(h,"touchmove",n._delayedDragTouchMoveHandler),f.supportPointer&&W(h,"pointermove",n._delayedDragTouchMoveHandler),n._dragStartTimer=setTimeout(m,f.delay)}else m()}},_delayedDragTouchMoveHandler:function(e){var s=e.touches?e.touches[0]:e;Math.max(Math.abs(s.clientX-this._lastX),Math.abs(s.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){b&&ln(b),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;N(e,"mouseup",this._disableDelayedDrag),N(e,"touchend",this._disableDelayedDrag),N(e,"touchcancel",this._disableDelayedDrag),N(e,"mousemove",this._delayedDragTouchMoveHandler),N(e,"touchmove",this._delayedDragTouchMoveHandler),N(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,s){s=s||e.pointerType=="touch"&&e,!this.nativeDraggable||s?this.options.supportPointer?W(document,"pointermove",this._onTouchMove):s?W(document,"touchmove",this._onTouchMove):W(document,"mousemove",this._onTouchMove):(W(b,"dragend",this),W(H,"dragstart",this._onDragStart));try{document.selection?Vt(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch{}},_dragStarted:function(e,s){if(Ze=!1,H&&b){me("dragStarted",this,{evt:s}),this.nativeDraggable&&W(document,"dragover",Jr);var a=this.options;!e&&fe(b,a.dragClass,!1),fe(b,a.ghostClass,!0),A.active=this,e&&this._appendGhost(),ue({sortable:this,name:"start",originalEvent:s})}else this._nulling()},_emulateDragOver:function(){if(be){this._lastX=be.clientX,this._lastY=be.clientY,As();for(var e=document.elementFromPoint(be.clientX,be.clientY),s=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(be.clientX,be.clientY),e!==s);)s=e;if(b.parentNode[_e]._isOutsideThisEl(e),s)do{if(s[_e]){var a=void 0;if(a=s[_e]._onDragOver({clientX:be.clientX,clientY:be.clientY,target:e,rootEl:s}),a&&!this.options.dragoverBubble)break}e=s}while(s=s.parentNode);Ss()}},_onTouchMove:function(e){if(Le){var s=this.options,a=s.fallbackTolerance,n=s.fallbackOffset,o=e.touches?e.touches[0]:e,f=j&&et(j,!0),h=j&&f&&f.a,m=j&&f&&f.d,r=Pt&&le&&Ln(le),u=(o.clientX-Le.clientX+n.x)/(h||1)+(r?r[0]-an[0]:0)/(h||1),p=(o.clientY-Le.clientY+n.y)/(m||1)+(r?r[1]-an[1]:0)/(m||1);if(!A.active&&!Ze){if(a&&Math.max(Math.abs(o.clientX-this._lastX),Math.abs(o.clientY-this._lastY))<a)return;this._onDragStart(e,!0)}if(j){f?(f.e+=u-(sn||0),f.f+=p-(on||0)):f={a:1,b:0,c:0,d:1,e:u,f:p};var _="matrix(".concat(f.a,",").concat(f.b,",").concat(f.c,",").concat(f.d,",").concat(f.e,",").concat(f.f,")");S(j,"webkitTransform",_),S(j,"mozTransform",_),S(j,"msTransform",_),S(j,"transform",_),sn=u,on=p,be=o}e.cancelable&&e.preventDefault()}},_appendGhost:function(){if(!j){var e=this.options.fallbackOnBody?document.body:H,s=te(b,!0,Pt,!0,e),a=this.options;if(Pt){for(le=e;S(le,"position")==="static"&&S(le,"transform")==="none"&&le!==document;)le=le.parentNode;le!==document.body&&le!==document.documentElement?(le===document&&(le=ke()),s.top+=le.scrollTop,s.left+=le.scrollLeft):le=ke(),an=Ln(le)}j=b.cloneNode(!0),fe(j,a.ghostClass,!1),fe(j,a.fallbackClass,!0),fe(j,a.dragClass,!0),S(j,"transition",""),S(j,"transform",""),S(j,"box-sizing","border-box"),S(j,"margin",0),S(j,"top",s.top),S(j,"left",s.left),S(j,"width",s.width),S(j,"height",s.height),S(j,"opacity","0.8"),S(j,"position",Pt?"absolute":"fixed"),S(j,"zIndex","100000"),S(j,"pointerEvents","none"),A.ghost=j,e.appendChild(j),S(j,"transform-origin",zn/parseInt(j.style.width)*100+"% "+Hn/parseInt(j.style.height)*100+"%")}},_onDragStart:function(e,s){var a=this,n=e.dataTransfer,o=a.options;if(me("dragStart",this,{evt:e}),A.eventCanceled){this._onDrop();return}me("setupClone",this),A.eventCanceled||(G=Is(b),G.removeAttribute("id"),G.draggable=!1,G.style["will-change"]="",this._hideClone(),fe(G,this.options.chosenClass,!1),A.clone=G),a.cloneId=Vt(function(){me("clone",a),!A.eventCanceled&&(a.options.removeCloneOnHide||H.insertBefore(G,b),a._hideClone(),ue({sortable:a,name:"clone"}))}),!s&&fe(b,o.dragClass,!0),s?(Bt=!0,a._loopId=setInterval(a._emulateDragOver,50)):(N(document,"mouseup",a._onDrop),N(document,"touchend",a._onDrop),N(document,"touchcancel",a._onDrop),n&&(n.effectAllowed="move",o.setData&&o.setData.call(a,n,b)),W(document,"drop",a),S(b,"transform","translateZ(0)")),Ze=!0,a._dragStartId=Vt(a._dragStarted.bind(a,s,e)),W(document,"selectstart",a),rt=!0,ft&&S(document.body,"user-select","none")},_onDragOver:function(e){var s=this.el,a=e.target,n,o,f,h=this.options,m=h.group,r=A.active,u=St===m,p=h.sort,_=ae||r,v,I=this,C=!1;if(fn)return;function V(Pe,Yt){me(Pe,I,Te({evt:e,isOwner:u,axis:v?"vertical":"horizontal",revert:f,dragRect:n,targetRect:o,canSort:p,fromSortable:_,target:a,completed:D,onMove:function(ot,it){return jt(H,s,b,n,ot,te(ot),e,it)},changed:q},Yt))}function B(){V("dragOverAnimationCapture"),I.captureAnimationState(),I!==_&&_.captureAnimationState()}function D(Pe){return V("dragOverCompleted",{insertion:Pe}),Pe&&(u?r._hideClone():r._showClone(I),I!==_&&(fe(b,ae?ae.options.ghostClass:r.options.ghostClass,!1),fe(b,h.ghostClass,!0)),ae!==I&&I!==A.active?ae=I:I===A.active&&ae&&(ae=null),_===I&&(I._ignoreWhileAnimating=a),I.animateAll(function(){V("dragOverAnimationComplete"),I._ignoreWhileAnimating=null}),I!==_&&(_.animateAll(),_._ignoreWhileAnimating=null)),(a===b&&!b.animated||a===s&&!a.animated)&&(Je=null),!h.dragoverBubble&&!e.rootEl&&a!==document&&(b.parentNode[_e]._isOutsideThisEl(e.target),!Pe&&ze(e)),!h.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),C=!0}function q(){pe=ge(b),Fe=ge(b,h.draggable),ue({sortable:I,name:"change",toEl:s,newIndex:pe,newDraggableIndex:Fe,originalEvent:e})}if(e.preventDefault!==void 0&&e.cancelable&&e.preventDefault(),a=xe(a,h.draggable,s,!0),V("dragOver"),A.eventCanceled)return C;if(b.contains(e.target)||a.animated&&a.animatingX&&a.animatingY||I._ignoreWhileAnimating===a)return D(!1);if(Bt=!1,r&&!h.disabled&&(u?p||(f=Y!==H):ae===this||(this.lastPutMode=St.checkPull(this,r,b,e))&&m.checkPut(this,r,b,e))){if(v=this._getDirection(e,a)==="vertical",n=te(b),V("dragOverValid"),A.eventCanceled)return C;if(f)return Y=H,B(),this._hideClone(),V("revert"),A.eventCanceled||(He?H.insertBefore(b,He):H.appendChild(b)),D(!0);var z=wn(s,h.draggable);if(!z||ec(e,v,this)&&!z.animated){if(z===b)return D(!1);if(z&&s===e.target&&(a=z),a&&(o=te(a)),jt(H,s,b,n,a,o,e,!!a)!==!1)return B(),z&&z.nextSibling?s.insertBefore(b,z.nextSibling):s.appendChild(b),Y=s,q(),D(!0)}else if(z&&$r(e,v,this)){var ce=st(s,0,h,!0);if(ce===b)return D(!1);if(a=ce,o=te(a),jt(H,s,b,n,a,o,e,!1)!==!1)return B(),s.insertBefore(b,ce),Y=s,q(),D(!0)}else if(a.parentNode===s){o=te(a);var ne=0,Z,Qe=b.parentNode!==s,ie=!Gr(b.animated&&b.toRect||n,a.animated&&a.toRect||o,v),Ve=v?"top":"left",ve=Qn(a,"top","top")||Qn(b,"top","top"),Re=ve?ve.scrollTop:void 0;Je!==a&&(Z=o[Ve],vt=!1,Dt=!ie&&h.invertSwap||Qe),ne=tc(e,a,o,v,ie?1:h.swapThreshold,h.invertedSwapThreshold==null?h.swapThreshold:h.invertedSwapThreshold,Dt,Je===a);var de;if(ne!==0){var Ae=ge(b);do Ae-=ne,de=Y.children[Ae];while(de&&(S(de,"display")==="none"||de===j))}if(ne===0||de===a)return D(!1);Je=a,gt=ne;var Se=a.nextElementSibling,ye=!1;ye=ne===1;var De=jt(H,s,b,n,a,o,e,ye);if(De!==!1)return(De===1||De===-1)&&(ye=De===1),fn=!0,setTimeout(Zr,30),B(),ye&&!Se?s.appendChild(b):a.parentNode.insertBefore(b,ye?Se:a),ve&&xs(ve,0,Re-ve.scrollTop),Y=b.parentNode,Z!==void 0&&!Dt&&(Ot=Math.abs(Z-te(a)[Ve])),q(),D(!0)}if(s.contains(b))return D(!1)}return!1},_ignoreWhileAnimating:null,_offMoveEvents:function(){N(document,"mousemove",this._onTouchMove),N(document,"touchmove",this._onTouchMove),N(document,"pointermove",this._onTouchMove),N(document,"dragover",ze),N(document,"mousemove",ze),N(document,"touchmove",ze)},_offUpEvents:function(){var e=this.el.ownerDocument;N(e,"mouseup",this._onDrop),N(e,"touchend",this._onDrop),N(e,"pointerup",this._onDrop),N(e,"touchcancel",this._onDrop),N(document,"selectstart",this)},_onDrop:function(e){var s=this.el,a=this.options;if(pe=ge(b),Fe=ge(b,a.draggable),me("drop",this,{evt:e}),Y=b&&b.parentNode,pe=ge(b),Fe=ge(b,a.draggable),A.eventCanceled){this._nulling();return}Ze=!1,Dt=!1,vt=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),pn(this.cloneId),pn(this._dragStartId),this.nativeDraggable&&(N(document,"drop",this),N(s,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),ft&&S(document.body,"user-select",""),S(b,"transform",""),e&&(rt&&(e.cancelable&&e.preventDefault(),!a.dropBubble&&e.stopPropagation()),j&&j.parentNode&&j.parentNode.removeChild(j),(H===Y||ae&&ae.lastPutMode!=="clone")&&G&&G.parentNode&&G.parentNode.removeChild(G),b&&(this.nativeDraggable&&N(b,"dragend",this),ln(b),b.style["will-change"]="",rt&&!Ze&&fe(b,ae?ae.options.ghostClass:this.options.ghostClass,!1),fe(b,this.options.chosenClass,!1),ue({sortable:this,name:"unchoose",toEl:Y,newIndex:null,newDraggableIndex:null,originalEvent:e}),H!==Y?(pe>=0&&(ue({rootEl:Y,name:"add",toEl:Y,fromEl:H,originalEvent:e}),ue({sortable:this,name:"remove",toEl:Y,originalEvent:e}),ue({rootEl:Y,name:"sort",toEl:Y,fromEl:H,originalEvent:e}),ue({sortable:this,name:"sort",toEl:Y,originalEvent:e})),ae&&ae.save()):pe!==$e&&pe>=0&&(ue({sortable:this,name:"update",toEl:Y,originalEvent:e}),ue({sortable:this,name:"sort",toEl:Y,originalEvent:e})),A.active&&((pe==null||pe===-1)&&(pe=$e,Fe=_t),ue({sortable:this,name:"end",toEl:Y,originalEvent:e}),this.save()))),this._nulling()},_nulling:function(){me("nulling",this),H=b=Y=j=He=G=qt=We=Le=be=rt=pe=Fe=$e=_t=Je=gt=ae=St=A.dragged=A.ghost=A.clone=A.active=null,Wt.forEach(function(e){e.checked=!0}),Wt.length=sn=on=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":b&&(this._onDragOver(e),Kr(e));break;case"selectstart":e.preventDefault();break}},toArray:function(){for(var e=[],s,a=this.el.children,n=0,o=a.length,f=this.options;n<o;n++)s=a[n],xe(s,f.draggable,this.el,!1)&&e.push(s.getAttribute(f.dataIdAttr)||sc(s));return e},sort:function(e,s){var a={},n=this.el;this.toArray().forEach(function(o,f){var h=n.children[f];xe(h,this.options.draggable,n,!1)&&(a[o]=h)},this),s&&this.captureAnimationState(),e.forEach(function(o){a[o]&&(n.removeChild(a[o]),n.appendChild(a[o]))}),s&&this.animateAll()},save:function(){var e=this.options.store;e&&e.set&&e.set(this)},closest:function(e,s){return xe(e,s||this.options.draggable,this.el,!1)},option:function(e,s){var a=this.options;if(s===void 0)return a[e];var n=kt.modifyOption(this,e,s);typeof n!="undefined"?a[e]=n:a[e]=s,e==="group"&&Ts(a)},destroy:function(){me("destroy",this);var e=this.el;e[_e]=null,N(e,"mousedown",this._onTapStart),N(e,"touchstart",this._onTapStart),N(e,"pointerdown",this._onTapStart),this.nativeDraggable&&(N(e,"dragover",this),N(e,"dragenter",this)),Array.prototype.forEach.call(e.querySelectorAll("[draggable]"),function(s){s.removeAttribute("draggable")}),this._onDrop(),this._disableDelayedDragEvents(),Ft.splice(Ft.indexOf(this.el),1),this.el=e=null},_hideClone:function(){if(!We){if(me("hideClone",this),A.eventCanceled)return;S(G,"display","none"),this.options.removeCloneOnHide&&G.parentNode&&G.parentNode.removeChild(G),We=!0}},_showClone:function(e){if(e.lastPutMode!=="clone"){this._hideClone();return}if(We){if(me("showClone",this),A.eventCanceled)return;b.parentNode==H&&!this.options.group.revertClone?H.insertBefore(G,b):He?H.insertBefore(G,He):H.appendChild(G),this.options.group.revertClone&&this.animate(b,G),S(G,"display",""),We=!1}}};function Kr(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move"),t.cancelable&&t.preventDefault()}function jt(t,e,s,a,n,o,f,h){var m,r=t[_e],u=r.options.onMove,p;return window.CustomEvent&&!Oe&&!Ct?m=new CustomEvent("move",{bubbles:!0,cancelable:!0}):(m=document.createEvent("Event"),m.initEvent("move",!0,!0)),m.to=e,m.from=t,m.dragged=s,m.draggedRect=a,m.related=n||e,m.relatedRect=o||te(e),m.willInsertAfter=h,m.originalEvent=f,t.dispatchEvent(m),u&&(p=u.call(r,m,f)),p}function ln(t){t.draggable=!1}function Zr(){fn=!1}function $r(t,e,s){var a=te(st(s.el,0,s.options,!0)),n=Es(s.el,s.options,j),o=10;return e?t.clientX<n.left-o||t.clientY<a.top&&t.clientX<a.right:t.clientY<n.top-o||t.clientY<a.bottom&&t.clientX<a.left}function ec(t,e,s){var a=te(wn(s.el,s.options.draggable)),n=Es(s.el,s.options,j),o=10;return e?t.clientX>n.right+o||t.clientY>a.bottom&&t.clientX>a.left:t.clientY>n.bottom+o||t.clientX>a.right&&t.clientY>a.top}function tc(t,e,s,a,n,o,f,h){var m=a?t.clientY:t.clientX,r=a?s.height:s.width,u=a?s.top:s.left,p=a?s.bottom:s.right,_=!1;if(!f){if(h&&Ot<r*n){if(!vt&&(gt===1?m>u+r*o/2:m<p-r*o/2)&&(vt=!0),vt)_=!0;else if(gt===1?m<u+Ot:m>p-Ot)return-gt}else if(m>u+r*(1-n)/2&&m<p-r*(1-n)/2)return nc(e)}return _=_||f,_&&(m<u+r*o/2||m>p-r*o/2)?m>u+r/2?1:-1:0}function nc(t){return ge(b)<ge(t)?1:-1}function sc(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,s=e.length,a=0;s--;)a+=e.charCodeAt(s);return a.toString(36)}function oc(t){Wt.length=0;for(var e=t.getElementsByTagName("input"),s=e.length;s--;){var a=e[s];a.checked&&Wt.push(a)}}function Vt(t){return setTimeout(t,0)}function pn(t){return clearTimeout(t)}Gt&&W(document,"touchmove",function(t){(A.active||Ze)&&t.cancelable&&t.preventDefault()});A.utils={on:W,off:N,css:S,find:bs,is:function(e,s){return!!xe(e,s,e,!1)},extend:Fr,throttle:ws,closest:xe,toggleClass:fe,clone:Is,index:ge,nextTick:Vt,cancelNextTick:pn,detectDirection:ks,getChild:st};A.get=function(t){return t[_e]};A.mount=function(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];e[0].constructor===Array&&(e=e[0]),e.forEach(function(a){if(!a.prototype||!a.prototype.constructor)throw"Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(a));a.utils&&(A.utils=Te(Te({},A.utils),a.utils)),kt.mount(a)})};A.create=function(t,e){return new A(t,e)};A.version=Rr;var ee=[],ct,_n,gn=!1,rn,cn,Xt,dt;function ic(){function t(){this.defaults={scroll:!0,forceAutoScrollFallback:!1,scrollSensitivity:30,scrollSpeed:10,bubbleScroll:!0};for(var e in this)e.charAt(0)==="_"&&typeof this[e]=="function"&&(this[e]=this[e].bind(this))}return t.prototype={dragStarted:function(s){var a=s.originalEvent;this.sortable.nativeDraggable?W(document,"dragover",this._handleAutoScroll):this.options.supportPointer?W(document,"pointermove",this._handleFallbackAutoScroll):a.touches?W(document,"touchmove",this._handleFallbackAutoScroll):W(document,"mousemove",this._handleFallbackAutoScroll)},dragOverCompleted:function(s){var a=s.originalEvent;!this.options.dragOverBubble&&!a.rootEl&&this._handleAutoScroll(a)},drop:function(){this.sortable.nativeDraggable?N(document,"dragover",this._handleAutoScroll):(N(document,"pointermove",this._handleFallbackAutoScroll),N(document,"touchmove",this._handleFallbackAutoScroll),N(document,"mousemove",this._handleFallbackAutoScroll)),Yn(),Rt(),Wr()},nulling:function(){Xt=_n=ct=gn=dt=rn=cn=null,ee.length=0},_handleFallbackAutoScroll:function(s){this._handleAutoScroll(s,!0)},_handleAutoScroll:function(s,a){var n=this,o=(s.touches?s.touches[0]:s).clientX,f=(s.touches?s.touches[0]:s).clientY,h=document.elementFromPoint(o,f);if(Xt=s,a||this.options.forceAutoScrollFallback||Ct||Oe||ft){dn(s,this.options,h,a);var m=Xe(h,!0);gn&&(!dt||o!==rn||f!==cn)&&(dt&&Yn(),dt=setInterval(function(){var r=Xe(document.elementFromPoint(o,f),!0);r!==m&&(m=r,Rt()),dn(s,n.options,r,a)},10),rn=o,cn=f)}else{if(!this.options.bubbleScroll||Xe(h,!0)===ke()){Rt();return}dn(s,this.options,Xe(h,!1),!1)}}},qe(t,{pluginName:"scroll",initializeByDefault:!0})}function Rt(){ee.forEach(function(t){clearInterval(t.pid)}),ee=[]}function Yn(){clearInterval(dt)}var dn=ws(function(t,e,s,a){if(!!e.scroll){var n=(t.touches?t.touches[0]:t).clientX,o=(t.touches?t.touches[0]:t).clientY,f=e.scrollSensitivity,h=e.scrollSpeed,m=ke(),r=!1,u;_n!==s&&(_n=s,Rt(),ct=e.scroll,u=e.scrollFn,ct===!0&&(ct=Xe(s,!0)));var p=0,_=ct;do{var v=_,I=te(v),C=I.top,V=I.bottom,B=I.left,D=I.right,q=I.width,z=I.height,ce=void 0,ne=void 0,Z=v.scrollWidth,Qe=v.scrollHeight,ie=S(v),Ve=v.scrollLeft,ve=v.scrollTop;v===m?(ce=q<Z&&(ie.overflowX==="auto"||ie.overflowX==="scroll"||ie.overflowX==="visible"),ne=z<Qe&&(ie.overflowY==="auto"||ie.overflowY==="scroll"||ie.overflowY==="visible")):(ce=q<Z&&(ie.overflowX==="auto"||ie.overflowX==="scroll"),ne=z<Qe&&(ie.overflowY==="auto"||ie.overflowY==="scroll"));var Re=ce&&(Math.abs(D-n)<=f&&Ve+q<Z)-(Math.abs(B-n)<=f&&!!Ve),de=ne&&(Math.abs(V-o)<=f&&ve+z<Qe)-(Math.abs(C-o)<=f&&!!ve);if(!ee[p])for(var Ae=0;Ae<=p;Ae++)ee[Ae]||(ee[Ae]={});(ee[p].vx!=Re||ee[p].vy!=de||ee[p].el!==v)&&(ee[p].el=v,ee[p].vx=Re,ee[p].vy=de,clearInterval(ee[p].pid),(Re!=0||de!=0)&&(r=!0,ee[p].pid=setInterval(function(){a&&this.layer===0&&A.active._onTouchMove(Xt);var Se=ee[this.layer].vy?ee[this.layer].vy*h:0,ye=ee[this.layer].vx?ee[this.layer].vx*h:0;typeof u=="function"&&u.call(A.dragged.parentNode[_e],ye,Se,t,Xt,ee[this.layer].el)!=="continue"||xs(ee[this.layer].el,ye,Se)}.bind({layer:p}),24))),p++}while(e.bubbleScroll&&_!==m&&(_=Xe(_,!1)));gn=r}},30),Ds=function(e){var s=e.originalEvent,a=e.putSortable,n=e.dragEl,o=e.activeSortable,f=e.dispatchSortableEvent,h=e.hideGhostForTarget,m=e.unhideGhostForTarget;if(!!s){var r=a||o;h();var u=s.changedTouches&&s.changedTouches.length?s.changedTouches[0]:s,p=document.elementFromPoint(u.clientX,u.clientY);m(),r&&!r.el.contains(p)&&(f("spill"),this.onSpill({dragEl:n,putSortable:a}))}};function xn(){}xn.prototype={startIndex:null,dragStart:function(e){var s=e.oldDraggableIndex;this.startIndex=s},onSpill:function(e){var s=e.dragEl,a=e.putSortable;this.sortable.captureAnimationState(),a&&a.captureAnimationState();var n=st(this.sortable.el,this.startIndex,this.options);n?this.sortable.el.insertBefore(s,n):this.sortable.el.appendChild(s),this.sortable.animateAll(),a&&a.animateAll()},drop:Ds};qe(xn,{pluginName:"revertOnSpill"});function In(){}In.prototype={onSpill:function(e){var s=e.dragEl,a=e.putSortable,n=a||this.sortable;n.captureAnimationState(),s.parentNode&&s.parentNode.removeChild(s),n.animateAll()},drop:Ds};qe(In,{pluginName:"removeOnSpill"});A.mount(new ic);A.mount(In,xn);const ac={name:"QuoteViewDetail",components:{Card:Ue,QuoteNavBar:mr,EditItemModal:Mr,RemoveModal:xt},data(){return{selectedItem:null,selectedInvoiceId:null,editItemsModal:!1,no_items:!0,loading:!0,loading_add:!1,quote:[],quoteItems:[],newItem:{loading_del:!1,item_ref:"",item_name:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},vatRate:0,settings:[],list_vats:[],client_detail:[],client_email:null,client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},articles:[],categories:[],showDropdown:!1,refs:[],showDropdownRef:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isQuoteExpired(){const t=new Date().getTime(),e=this.quote.due_date?new Date(this.quote.due_date).getTime():null;return e&&e<t},totalAmountWithoutDiscount(){const t=this.quoteItems.reduce((e,s)=>{const a=s.quantity*s.unit_price;return e+a},0);return this.formatCurrency(t)},totalAmount(){const t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.quoteItems.reduce((a,n)=>a+parseFloat(n.total_amount),0)*this.quote.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)},signatureImageUrl(){const t="/wp-json/my-easy-compta/v1/signature-image/",e=myEasyComptaAdmin.nonce;return`${t}${this.quote.file_sign}?_wpnonce=${e}`}},methods:{getUniqueVATRates(){const t=new Set;return this.quoteItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.quoteItems.forEach(s=>{if(s.vat_rate===t){const a=s.quantity*s.unit_price,n=a*s.discount/100;e+=(a-n)*t/100}}),this.formatCurrency(e)},calculateTotalAmountWithVAT(){let t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.formatCurrency(t)},fetchQuote(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.quote=t,this.fetchClientInfo(t.client_id)):console.error("Quote not found")}).catch(t=>{console.error("Error fetching quote:",t),this.loading=!1})},fetchClientInfo(t){fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.client_email=e.email;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.quoteItems=[],this.loading=!1,this.no_items=!0):(this.quoteItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var a=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;a=s+n}else a=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(a)},calculateTotalWithVat(t,e,s,a){const n=t*e,o=n*a/100,f=n-o,h=f*s/100,m=f+h;return this.formatCurrency(m)},calculateTotal(t,e,s){const a=t*e,n=a*s/100,f=a-n;return this.formatCurrency(f)},submitItems(){this.updateTotal();const t={...this.newItem,quote_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/quotes/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.selectedInvoiceId=e,modal_remove.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.quoteItems.find(a=>a.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({quote_id:e})}).then(a=>a.json()).then(a=>{a.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(a.message,"alert-error"),console.error("Error removing item:",a.message),s.loading_del=!1)}).catch(a=>{this.showToast(a.message,"alert-error"),console.error("Error removing item:",a),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/quotes/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,a){const o=t*e*a/100,f=o*s/100,h=o+f;return this.formatCurrency(h)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.quoteItems[t.oldIndex];this.quoteItems.splice(t.oldIndex,1),this.quoteItems.splice(t.newIndex,0,e);const s=this.quoteItems.map(a=>a.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/quotes/update-quote-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.articles=t}).catch(t=>console.error("Error fetching articles:",t))},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loading=!0,this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:a}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=a,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1,this.loading=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1,this.loading=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchQuote(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");A.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},lc={class:"pt-2 pr-4"},rc={key:1,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},cc=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),dc=[cc],uc={key:2},hc={role:"alert",class:"alert alert-warning"},mc=i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),fc={key:0,class:"relative"},pc={class:"ecwp-watermark"},_c={class:"grid grid-cols-2"},gc={class:"md:col-span-1"},vc=["src"],yc={class:"md:col-span-1 text-right"},bc={class:"text-lg font-semibold"},wc={key:0,class:"badge badge-warning text-white"},xc={key:1,class:"badge badge-secondary text-white"},Ic={key:2,class:"badge badge-success text-white"},Ec={key:3,class:"badge badge-error text-white"},Cc={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},kc=i("br",null,null,-1),Tc=i("br",null,null,-1),Ac=i("br",null,null,-1),Sc=["href"],Dc=i("br",null,null,-1),Pc=i("br",null,null,-1),jc=i("br",null,null,-1),Mc=["href"],qc=i("br",null,null,-1),Oc=["href"],Vc={class:"table mt-8"},Rc=i("th",null,null,-1),Nc={width:"5%"},Bc={width:"19%"},Fc={width:"21%"},Wc={width:"10%",class:"text-center"},Xc={width:"8%",class:"text-center"},Uc={key:0,width:"5%",class:"text-center"},Qc={key:1,width:"5%"},Lc={width:"10%",class:"text-center"},zc={width:"10%",class:"text-right"},Hc=i("th",{width:"18%",class:"text-right inv-actions"},null,-1),Gc=i("td",{class:"draggable-item drag-handle px-2"},[i("i",{class:"fas fa-bars"})],-1),Yc={key:0,class:"badge badge-ghost badge-xs"},Jc=["innerHTML"],Kc={class:"text-center"},Zc={class:"text-center"},$c={key:0},ed={key:1},td={key:0,class:"text-center"},nd={key:1},sd={key:2,class:"text-center"},od=i("br",null,null,-1),id={key:3,class:"text-center"},ad=i("br",null,null,-1),ld={class:"text-right"},rd={key:0},cd={key:1},dd=["data-tip"],ud=["onClick"],hd=i("i",{class:"far fa-edit"},null,-1),md=[hd],fd=["data-tip"],pd=["onClick"],_d={key:0,class:"far fa-trash-alt"},gd={key:1,class:"loading loading-spinner loading-xs"},vd={key:0},yd=i("td",{class:"px-2"},null,-1),bd={class:"align-top px-2"},wd={class:"flex items-center border rounded-md relative"},xd=["placeholder"],Id={key:0,class:"autocomplete-dropdown bg-base-300"},Ed=["onClick","innerHTML"],Cd={class:"align-top px-2"},kd=i("option",{disabled:"",selected:""},"Type",-1),Td=["value"],Ad={class:"flex items-center border rounded-md relative"},Sd=["placeholder"],Dd={key:0,class:"autocomplete-dropdown bg-base-300"},Pd=["onClick","innerHTML"],jd={class:"align-top"},Md={class:"flex items-center rounded-md"},qd=["placeholder"],Od={class:"align-top"},Vd={class:"flex items-center border rounded-lg"},Rd={class:"inline-flex"},Nd=["placeholder"],Bd={class:"align-top"},Fd={class:"flex items-center border rounded-md"},Wd=["placeholder"],Xd={key:0,class:"align-top"},Ud=["value"],Qd={key:1,class:"align-top"},Ld={class:"align-top"},zd={class:"flex items-center border rounded-md"},Hd=["placeholder"],Gd=i("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),Yd={key:2,class:"text-right"},Jd={key:3,class:"text-right"},Kd=["data-tip"],Zd={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},$d={key:0,class:"fa fa-plus"},eu={key:1,class:"loading loading-spinner loading-xs"},tu={colspan:"8",class:"text-right no-border"},nu={class:"text-right"},su={key:0,class:"line-through"},ou=i("td",null,null,-1),iu={colspan:"8",class:"text-right no-border"},au={class:"text-right"},lu=i("td",null,null,-1),ru={colspan:"8",class:"text-right no-border font-bold text-xl"},cu={class:"text-right no-border font-bold text-xl"},du=i("td",null,null,-1),uu={key:2},hu={colspan:"8",class:"text-right no-border"},mu={class:"text-right no-border"},fu={key:3},pu={colspan:"8",class:"text-right no-border"},_u={class:"text-right no-border font-bold text-xl"},gu={key:1,class:"relative"},vu={class:"flex justify-end mt-4"},yu={class:"border-2 border-slate-300 max-w-md"},bu=["src"];function wu(t,e,s,a,n,o){const f=M("QuoteNavBar"),h=M("remove-modal"),m=M("edit-item-modal"),r=M("Card");return c(),d("div",lc,[P(f,{quoteInfo:n.quote,emailActive:n.settings.easy_compta_email_addon_active,advanceActive:n.settings.easy_compta_advance_addon_active,currency:n.default_currency_symbol,noItems:n.no_items},null,8,["quoteInfo","emailActive","advanceActive","currency","noItems"]),n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),P(h,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=u=>this.removeItem(n.selectedItem,n.selectedInvoiceId)),onCancel:e[1]||(e[1]=u=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.loading?(c(),d("div",rc,dc)):g("",!0),o.isQuoteExpired&&n.quote.status=="pending"?(c(),d("div",uc,[i("div",hc,[mc,i("span",null,l(o.translations.quote_expired),1)])])):g("",!0),P(r,{topMargin:"mt-8",id:"quote-content"},{default:re(()=>[n.settings.easy_compta_signature_addon_active&&n.quote.signed==1?(c(),d("div",fc,[i("span",pc,l(o.translations.signed),1)])):g("",!0),i("div",_c,[i("div",gc,[i("div",null,[i("img",{src:n.settings.logo_url,style:Zn({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,vc)])]),i("div",yc,[i("p",bc,l(n.quote.quote_number),1),i("div",null,[w(l(o.translations.created_at)+": ",1),i("strong",null,l(n.quote.created_at),1)]),i("div",null,[w(l(o.translations.due_date)+": ",1),i("strong",null,l(n.quote.due_date),1)]),i("div",null,[w(l(o.translations.provisional_date)+": ",1),i("strong",null,l(n.quote.provisional_start_date),1)]),i("div",null,[w(l(o.translations.status)+": ",1),n.quote.status=="draft"?(c(),d("span",wc,l(o.translations.draft),1)):g("",!0),n.quote.status=="pending"?(c(),d("span",xc,l(o.translations.pending),1)):g("",!0),n.quote.status=="approved"?(c(),d("span",Ic,l(o.translations.approved),1)):g("",!0),n.quote.status=="rejected"?(c(),d("span",Ec,l(o.translations.rejected),1)):g("",!0)])])]),i("div",Cc,[i("div",null,[i("strong",null,l(o.translations.bill_to)+":",1),i("h4",null,[i("strong",null,l(n.client_detail.company_name),1)]),i("p",null,[w(l(n.client_detail.address),1),kc,w(" "+l(n.client_detail.postal_code)+", "+l(n.client_detail.city)+" ",1),Tc,w(" "+l(n.client_detail.country),1),Ac,n.client_detail.phone?(c(),d("a",{key:0,href:"tel:"+n.client_detail.phone},l(n.client_detail.phone),9,Sc)):g("",!0)])]),i("div",null,[i("strong",null,l(o.translations.received_from)+":",1),i("h4",null,[i("strong",null,l(n.settings.company_name),1)]),i("p",null,[w(l(n.settings.company_address),1),Dc,w(" "+l(n.settings.postal_code)+", "+l(n.settings.city)+" ",1),Pc,w(" "+l(n.settings.country),1),jc,n.settings.company_phone?(c(),d("a",{key:0,href:"tel:"+n.settings.company_phone},l(n.settings.company_phone),9,Mc)):g("",!0),qc,n.settings.mobile_phone?(c(),d("a",{key:1,href:"tel:"+n.settings.mobile_phone},l(n.settings.mobile_phone),9,Oc)):g("",!0)])])]),P(m,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[2]||(e[2]=u=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),i("form",{onSubmit:e[22]||(e[22]=K((...u)=>o.submitItems&&o.submitItems(...u),["prevent"]))},[i("table",Vc,[i("thead",null,[i("tr",null,[Rc,i("th",Nc,l(o.translations.item_ref),1),i("th",Bc,l(o.translations.item_name),1),i("th",Fc,l(o.translations.description),1),i("th",Wc,l(o.translations.quantity),1),i("th",Xc,l(o.translations.unit_price),1),n.settings.vat_active==1?(c(),d("th",Uc,l(o.translations.vat),1)):(c(),d("th",Qc)),i("th",Lc,l(o.translations.discount),1),i("th",zc,l(o.translations.total),1),Hc])]),i("tbody",null,[(c(!0),d(X,null,U(n.quoteItems,(u,p)=>(c(),d("tr",{key:u.id||p},[Gc,i("td",null,l(u.item_ref),1),i("td",null,[u.category_name?(c(),d("div",Yc,l(u.category_name),1)):g("",!0),i("div",null,l(u.item_name),1)]),i("td",{innerHTML:o.nl2br(u.item_description)},null,8,Jc),i("td",Kc,l(u.quantity),1),i("td",Zc,[w(l(u.unit_price),1),n.default_currency_symbol==n.client_currency?(c(),d("span",$c,l(n.default_currency_symbol),1)):(c(),d("span",ed,l(n.client_currency),1))]),n.settings.vat_active==1?(c(),d("td",td,l(u.vat_rate)+"%",1)):(c(),d("td",nd)),n.settings.vat_active==1?(c(),d("td",sd,[w(l(u.discount)+"% ",1),od,w(" "+l(o.calculateDiscountAmountWithVAT(u.quantity,u.unit_price,u.vat_rate,u.discount)),1)])):(c(),d("td",id,[w(l(u.discount)+"% ",1),ad,w(" "+l(o.calculateDiscountAmount(u.quantity,u.unit_price,u.discount)),1)])),i("td",ld,[w(l(u.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(c(),d("span",rd,l(n.default_currency_symbol),1)):(c(),d("span",cd,l(n.client_currency),1))]),i("td",null,[n.quote.status=="draft"||n.quote.status=="pending"?(c(),d("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[i("button",{onClick:K(_=>o.editItem(u.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},md,8,ud)],8,dd)):g("",!0),n.quote.status=="draft"||n.quote.status=="pending"?(c(),d("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:K(_=>o.confirmremoveItem(u.id,n.quote.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[u.loading_del?g("",!0):(c(),d("i",_d)),u.loading_del?(c(),d("span",gd)):g("",!0)],8,pd)],8,fd)):g("",!0)])]))),128)),n.quote.status=="draft"||n.quote.status=="pending"?(c(),d("tr",vd,[yd,i("td",bd,[i("div",wd,[F(i("input",{type:"text","onUpdate:modelValue":e[3]||(e[3]=u=>n.newItem.item_ref=u),onInput:e[4]||(e[4]=(...u)=>o.fetchRefs&&o.fetchRefs(...u)),onFocus:e[5]||(e[5]=u=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,xd),[[J,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(c(),d("ul",Id,[(c(!0),d(X,null,U(n.refs,u=>(c(),d("li",{key:u.ref,onClick:p=>o.selectItem(u),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(u.ref)},null,8,Ed))),128))])):g("",!0)])]),i("td",Cd,[F(i("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[6]||(e[6]=u=>n.newItem.item_category=u)},[kd,(c(!0),d(X,null,U(n.categories,u=>(c(),d("option",{key:u.id,value:u.id},l(u.name),9,Td))),128))],512),[[Ie,n.newItem.item_category]]),i("div",Ad,[F(i("input",{type:"text","onUpdate:modelValue":e[7]||(e[7]=u=>n.newItem.item_name=u),onInput:e[8]||(e[8]=(...u)=>o.fetchArticles&&o.fetchArticles(...u)),onFocus:e[9]||(e[9]=u=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,Sd),[[J,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(c(),d("ul",Dd,[(c(!0),d(X,null,U(n.articles,u=>(c(),d("li",{key:u.name,onClick:p=>o.selectItem(u),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(u.name)},null,8,Pd))),128))])):g("",!0)])]),i("td",jd,[i("div",Md,[F(i("textarea",{"onUpdate:modelValue":e[10]||(e[10]=u=>n.newItem.item_description=u),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[11]||(e[11]=u=>o.resize()),ref:"textarea"},null,40,qd),[[J,n.newItem.item_description]])])]),i("td",Od,[i("div",Vd,[i("div",Rd,[i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[12]||(e[12]=(...u)=>o.decrease&&o.decrease(...u))}," - "),F(i("input",{type:"number",min:"1","onUpdate:modelValue":e[13]||(e[13]=u=>n.newItem.quantity=u),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[14]||(e[14]=(...u)=>o.updateTotal&&o.updateTotal(...u))},null,40,Nd),[[J,n.newItem.quantity]]),i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[15]||(e[15]=(...u)=>o.increase&&o.increase(...u))}," + ")])])]),i("td",Bd,[i("div",Fd,[F(i("input",{type:"number","onUpdate:modelValue":e[16]||(e[16]=u=>n.newItem.unit_price=u),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[17]||(e[17]=(...u)=>o.updateTotal&&o.updateTotal(...u))},null,40,Wd),[[J,n.newItem.unit_price]])])]),n.settings.vat_active==1?(c(),d("td",Xd,[F(i("select",{"onUpdate:modelValue":e[18]||(e[18]=u=>n.newItem.vat_rate=u),onChange:e[19]||(e[19]=(...u)=>o.updateTotal&&o.updateTotal(...u)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(c(!0),d(X,null,U(n.list_vats,u=>(c(),d("option",{key:u,value:u.rate},l(u.rate)+"% ",9,Ud))),128))],544),[[Ie,n.newItem.vat_rate]])])):(c(),d("td",Qd)),i("td",Ld,[i("div",zd,[F(i("input",{type:"number",min:"0",max:"100","onUpdate:modelValue":e[20]||(e[20]=u=>n.newItem.discount=u),placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[21]||(e[21]=(...u)=>o.updateTotal&&o.updateTotal(...u))},null,40,Hd),[[J,n.newItem.discount]]),Gd])]),n.settings.vat_active==1?(c(),d("td",Yd,l(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(c(),d("td",Jd,l(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),i("td",null,[i("span",{class:"lg:tooltip","data-tip":o.translations.add},[i("button",Zd,[n.loading_add?g("",!0):(c(),d("i",$d)),n.loading_add?(c(),d("span",eu)):g("",!0)])],8,Kd)])])):g("",!0),i("tr",null,[i("td",tu,[i("strong",null,l(o.translations.subtotal),1)]),i("td",nu,[o.totalAmount!==o.totalAmountWithoutDiscount?(c(),d("span",su,l(o.totalAmountWithoutDiscount),1)):g("",!0),w(" "+l(o.totalAmount),1)]),ou]),n.settings.vat_active==1?(c(!0),d(X,{key:1},U(o.getUniqueVATRates(),(u,p)=>(c(),d("tr",{key:p},[i("td",iu,[i("strong",null,l(o.translations.tax)+" ("+l(u)+"%) ",1)]),i("td",au,l(o.calculateVATForRate(u)),1),lu]))),128)):g("",!0),i("tr",null,[i("td",ru,[i("strong",null,l(o.translations.total),1)]),i("td",cu,l(o.calculateTotalAmountWithVAT()),1),du]),n.client_currency!=n.default_currency_symbol?(c(),d("tr",uu,[i("td",hu,[i("strong",null,l(o.translations.exchange_rate),1)]),i("td",mu,l(n.quote.exchange_rate),1)])):g("",!0),n.client_currency!=n.default_currency_symbol?(c(),d("tr",fu,[i("td",pu,[i("strong",null,l(o.translations.total)+" "+l(n.default_currency_symbol),1)]),i("td",_u,l(o.totalAmountDefaultCurrency)+l(n.default_currency_symbol),1)])):g("",!0)])])],32),n.settings.easy_compta_signature_addon_active&&n.quote.signed==1&&n.quote.file_sign?(c(),d("div",gu,[i("div",vu,[i("span",yu,[i("img",{src:o.signatureImageUrl,alt:"Signature"},null,8,bu)])])])):g("",!0)]),_:1})])}var xu=oe(ac,[["render",wu]]);const Iu={name:"QuoteNew",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{clientOptions:[],clients:[],quote:{number:"",due_date:"",provisional_start_date:"",client_id:"",status:""},showError:!1,loading:!1,loadingBtn:!1,settings:[],last_quote_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},customLabel(t){return t.text},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.quote_prefix}_${String(this.settings.last_quote_id).padStart(4,"0")}`;this.quote.number=s}else{const e=await t.json()}}catch{this.loading=!1}},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/quotes",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting quote:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Eu={class:"pt-2 pr-4"},Cu={class:"flex justify-between items-center mb-4"},ku={class:"card-title"},Tu=i("div",{class:"divider mt-2"},null,-1),Au={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Su={class:"grid grid-cols-3 gap-4"},Du={class:"ecwp-group form-group mb-4"},Pu={for:"quoteNumber",class:"ecwp-label"},ju={class:"ecwp-group form-group mb-4"},Mu={for:"quoteDate",class:"ecwp-label"},qu={class:"ecwp-group form-group mb-4"},Ou={for:"quoteDatePr",class:"ecwp-label"},Vu={class:"grid grid-cols-2 gap-4"},Ru={class:"ecwp-group form-group mb-4"},Nu={for:"client",class:"ecwp-label"},Bu={class:"ecwp-group form-group mb-4"},Fu={for:"status",class:"ecwp-label"},Wu={value:"draft",selected:""},Xu={value:"pending"},Uu={value:"approved"},Qu={value:"rejected"},Lu={class:"flex justify-between"},zu=["disabled"],Hu={key:0,class:"loading loading-spinner loading-sm"};function Gu(t,e,s,a,n,o){const f=M("VueDatePicker"),h=M("model-select"),m=M("Card");return c(),d("div",Eu,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),P(m,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:re(()=>[i("div",Cu,[i("h2",ku,l(o.translations.new_quote),1)]),Tu,n.loading?(c(),d("div",Au)):g("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...r)=>o.submitQuote&&o.submitQuote(...r),["prevent"]))},[i("div",Su,[i("div",Du,[i("label",Pu,l(o.translations.quote_number),1),F(i("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=r=>n.quote.number=r),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[J,n.quote.number]])]),i("div",ju,[i("label",Mu,l(o.translations.due_date),1),P(f,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=r=>n.quote.due_date=r),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),i("div",qu,[i("label",Ou,l(o.translations.provisional_date),1),P(f,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteDatePr",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=r=>n.quote.provisional_start_date=r),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])])]),i("div",Vu,[i("div",Ru,[i("label",Nu,l(o.translations.company_name),1),P(h,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[3]||(e[3]=r=>n.quote.client_id=r),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",Bu,[i("label",Fu,l(o.translations.status),1),F(i("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=r=>n.quote.status=r),class:k(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[i("option",Wu,l(o.translations.draft),1),i("option",Xu,l(o.translations.pending),1),i("option",Uu,l(o.translations.approved),1),i("option",Qu,l(o.translations.rejected),1)],2),[[Ie,n.quote.status]])])]),i("div",Lu,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...r)=>o.cancelAction&&o.cancelAction(...r))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.submit)+" ",1),n.loadingBtn?(c(),d("span",Hu)):g("",!0)],8,zu)])],32)]),_:1})])}var Yu=oe(Iu,[["render",Gu]]);const Ju={name:"InvoicesList",components:{Card:Ue,RemoveModal:xt},data(){return{invoices:[],showInvoiceDetailsModal:!1,editInvoiceModal:!1,selectedInvoice:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchInvoices(),this.loadSettings()},methods:{fetchInvoices(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/invoices?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.invoices=s.invoices,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching invoices:",s)}).finally(()=>{this.loading=!1})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return $n(t,this.default_vat.rate)},calculateWithoutVAT(t){return es(t)},generatePaginationButtons(){this.paginationButtons=ts(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchInvoices(t)},perPageChanged(){this.fetchInvoices()},formatAmount(t,e){return ns(t,e,this.settings.currency_position)},showToast(t,e){ss(this.toast,t,e)},confirmDeleteInvoice(t){this.selectedInvoice=t,modal_remove.showModal(),this.showRemoveModal=!0},deleteInvoice(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchInvoices(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting invoice:",e.statusText))}).catch(e=>{console.log(e.message);const s=e&&e.message?e.message:"Error deleting client";s==="This client cannot be deleted because it has associated data."?this.showToast(s,"alert-error"):console.error("Error deleting client:",e)})}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},Ku={class:"pt-2 pr-4"},Zu={class:"flex justify-between items-center"},$u={class:"card-title"},eh={class:"btn btn-primary rounded-full"},th=i("i",{class:"fas fa-plus-circle"},null,-1),nh={key:0,class:"ms-2"},sh={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab3"},oh=i("i",{class:"fas fa-file-export"},null,-1),ih=["data-tip"],ah={class:"btn btn-outline btn-accent rounded-full",disabled:""},lh=i("i",{class:"fas fa-file-export"},null,-1),rh=i("div",{class:"divider mt-2"},null,-1),ch={class:"flex items-center mb-4"},dh={for:"perPageSelect",class:"mr-2"},uh=["value"],hh={class:"overflow-x-auto"},mh={key:0,class:"table w-full"},fh={class:"flex justify-center"},ph={key:0,class:"badge badge-primary badge-outline badge-sm mr-2"},_h={key:0,class:"badge badge-scondary badge-outline badge-sm"},gh={key:1,class:"badge badge-warning badge-outline badge-sm"},vh={key:2,class:"badge badge-success badge-outline badge-sm"},yh={key:3,class:"badge badge-error badge-outline badge-sm ms-2"},bh={key:0},wh={key:0},xh={key:0},Ih={key:1},Eh={key:0},Ch={key:1},kh={key:1},Th=i("span",{class:"loading loading-bars loading-sm"},null,-1),Ah=[Th],Sh={key:0},Dh={key:1},Ph=i("span",{class:"loading loading-bars loading-sm"},null,-1),jh=[Ph],Mh={key:0},qh={key:1},Oh=i("span",{class:"loading loading-bars loading-sm"},null,-1),Vh=[Oh],Rh={class:"flex justify-end"},Nh=["data-tip"],Bh=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"far fa-eye"})],-1),Fh=["data-tip"],Wh=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"fas fa-pencil-alt"})],-1),Xh=["data-tip"],Uh=["onClick"],Qh=i("i",{class:"far fa-trash-alt"},null,-1),Lh=[Qh],zh={key:1},Hh=i("div",{class:"flex gap-4 items-center"},[i("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),i("div",{class:"flex flex-col gap-4 w-full"},[i("div",{class:"skeleton h-4 w-full"}),i("div",{class:"skeleton h-4 w-full"})])],-1),Gh=i("div",{class:"divider my-1"},null,-1),Yh=[Hh,Gh],Jh={class:"join ecwp_pagination mt-6 pt-4"},Kh=["onClick"];function Zh(t,e,s,a,n,o){const f=M("remove-modal"),h=M("router-link"),m=M("Card");return c(),d("div",Ku,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),P(f,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=r=>this.deleteInvoice(n.selectedInvoice)),onCancel:e[1]||(e[1]=r=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(m,{topMargin:"mt-8"},{default:re(()=>[i("div",Zu,[i("h2",$u,l(o.translations.invoices),1),i("div",null,[P(h,{to:{name:"InvoiceNew"}},{default:re(()=>[i("button",eh,[w(l(o.translations.add)+" ",1),th])]),_:1}),n.settings.easy_compta_export_addon_active==1?(c(),d("span",nh,[i("a",sh,[w(l(o.translations.export)+" ",1),oh])])):(c(),d("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[i("button",ah,[w(l(o.translations.export)+" ",1),lh])],8,ih))])]),rh,i("div",ch,[i("label",dh,l(o.translations.display_per_page),1),F(i("select",{id:"perPageSelect","onUpdate:modelValue":e[2]||(e[2]=r=>n.perPage=r),onChange:e[3]||(e[3]=(...r)=>o.perPageChanged&&o.perPageChanged(...r))},[(c(!0),d(X,null,U(n.perPageOptions,r=>(c(),d("option",{key:r,value:r},l(r),9,uh))),128))],544),[[Ie,n.perPage]])]),i("div",hh,[n.loading?(c(),d("div",zh,[(c(!0),d(X,null,U(n.skeletonRows,r=>(c(),d("div",{key:r,class:"flex flex-col gap-4 w-full"},Yh))),128))])):(c(),d("table",mh,[i("thead",null,[i("tr",null,[i("th",null,l(o.translations.invoice_number),1),i("th",null,l(o.translations.client),1),i("th",null,l(o.translations.status),1),i("th",null,l(o.translations.total),1),i("th",null,l(o.translations.due_date),1),i("th",null,l(o.translations.created_at),1),i("th",fh,l(o.translations.actions),1)])]),i("tbody",null,[(c(!0),d(X,null,U(n.invoices,r=>(c(),d("tr",{key:r.id},[i("td",null,[r.advance==1?(c(),d("span",ph,l(o.translations.advance),1)):g("",!0),w(l(r.invoice_number),1)]),i("td",null,l(r.client_name),1),i("td",null,[r.status=="draft"?(c(),d("span",_h,l(o.translations.draft),1)):g("",!0),r.status=="unpaid"?(c(),d("span",gh,l(o.translations.unpaid),1)):g("",!0),r.status=="paid"?(c(),d("span",vh,l(o.translations.paid),1)):g("",!0),r.credit=="1"?(c(),d("span",yh,l(o.translations.credit),1)):g("",!0)]),i("td",null,[n.loadingPrice?(c(),d("div",kh,Ah)):(c(),d("div",bh,[n.settings.easy_compta_advance_addon_active&&r.advance==1?(c(),d("div",wh,l(o.formatAmount(r.advance_amount,r.client_currency||n.default_currency_symbol)),1)):g("",!0),n.settings.vat_active==1?(c(),d("div",{key:1,class:k({"text-xs":r.advance==1})},[n.default_currency_symbol==r.client_currency||r.client_currency==null?(c(),d("span",xh,l(o.formatAmount(r.total_amount,n.default_currency_symbol)),1)):(c(),d("span",Ih,l(o.formatAmount(r.total_amount,r.client_currency)),1))],2)):(c(),d("div",{key:2,class:k({"text-xs":r.advance==1})},[n.default_currency_symbol==r.client_currency||r.client_currency==null?(c(),d("span",Eh,l(o.formatAmount(r.total_amount,n.default_currency_symbol)),1)):(c(),d("span",Ch,l(o.formatAmount(r.total_amount,r.client_currency)),1))],2))]))]),i("td",null,[n.loadingPrice?(c(),d("div",Dh,jh)):(c(),d("div",Sh,l(r.due_date),1))]),i("td",null,[n.loadingPrice?(c(),d("div",qh,Vh)):(c(),d("div",Mh,l(r.created),1))]),i("td",Rh,[i("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(h,{to:{name:"InvoiceViewDetail",params:{id:r.id}}},{default:re(()=>[Bh]),_:2},1032,["to"])],8,Nh),r.status=="draft"?(c(),d("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[P(h,{to:{name:"InvoiceEdit",params:{id:r.id}}},{default:re(()=>[Wh]),_:2},1032,["to"])],8,Fh)):g("",!0),r.status=="draft"?(c(),d("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:u=>o.confirmDeleteInvoice(r.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},Lh,8,Uh)],8,Xh)):g("",!0)])]))),128))])]))]),i("div",Jh,[(c(!0),d(X,null,U(n.paginationButtons,r=>(c(),d("button",{key:r,class:k(["join-item btn",{"btn-disabled":r==="..."||r===n.currentPage}]),onClick:u=>o.goToPage(r)},l(r),11,Kh))),128))])]),_:1})])}var $h=oe(Ju,[["render",Zh]]);const em={name:"sendInvoice",components:{VueEditor:Et.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"invoice",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},tm=["id","open"],nm={class:"modal-box"},sm={class:"font-bold text-lg"},om={key:0},im={class:"grid grid-cols-1 gap-4"},am=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),lm=i("div",{class:"skeleton h-4 w-full"},null,-1),rm=[am,lm],cm={class:"grid grid-cols-1 gap-4"},dm=["type"],um=["for"],hm=["id","value","disabled","onInput"],mm={key:1},fm=["for"],pm={class:"form-group mt-4 flex justify-end"},_m=["disabled"],gm={key:0,class:"loading loading-spinner loading-sm"};function vm(t,e,s,a,n,o){const f=M("vue-editor");return c(),d("div",null,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",nm,[i("h3",sm,l(o.translations.send_invoice),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(c(),d("div",om,[i("div",im,[(c(!0),d(X,null,U(o.skeletonItems,h=>(c(),d("div",{key:h,class:"py-2"},rm))),128))])])):(c(),d("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",cm,[(c(!0),d(X,null,U(n.fields,(h,m)=>(c(),d("div",{key:m,class:"ecwp-group form-group"},[h.type!=="textarea"?(c(),d("div",{key:0,type:h.type||"text"},[i("label",{for:m,class:"ecwp-label form-label"},l(h.label),9,um),i("input",{id:m,class:k(["ecwp-input input input-bordered",h.class||"w-full"]),value:h.value,disabled:h.disabled,onInput:r=>o.updateFieldValue(m,r.target.value)},null,42,hm)],8,dm)):(c(),d("div",mm,[i("label",{for:m,class:"form-label"},l(h.label),9,fm),P(f,{modelValue:h.value,"onUpdate:modelValue":r=>h.value=r,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",pm,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.send)+" ",1),n.loadingBtn?(c(),d("span",gm)):g("",!0)],8,_m)])],32))])],8,tm)])}var ym=oe(em,[["render",vm]]);const bm={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm_credit").close()}}},wm=["open"],xm={class:"modal-box"},Im={class:"font-bold text-lg"},Em=i("div",{class:"text-center text-red-400 mb-2"},[i("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),Cm={class:"text-lg font-semibold text-center"},km={class:"my-4 text-center text-xl"},Tm={class:"flex justify-between space-x-4"};function Am(t,e,s,a,n,o){return c(),d("div",null,[i("dialog",{id:"modal_confirm_credit",class:"modal",open:t.showModal},[i("div",xm,[i("h3",Im,l(t.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...f)=>o.closeModal&&o.closeModal(...f))}," \u2715 "),Em,i("h2",Cm,l(s.title),1),i("p",km,l(s.message),1),i("div",Tm,[i("button",{onClick:e[1]||(e[1]=(...f)=>o.onCancel&&o.onCancel(...f)),class:"btn btn-secondary rounded-full"},l(s.cancelText),1),i("button",{onClick:e[2]||(e[2]=(...f)=>o.onConfirm&&o.onConfirm(...f)),class:"btn rounded-full btn-error text-white"},l(s.confirmText),1)])])],8,wm)])}var Sm=oe(bm,[["render",Am]]);const Dm={name:"InvoiceNavBar",components:{SendInvoiceModal:ym,RemoveModal:xt,ConfirmModal:bn,ConfirmModalCredit:Sm},props:{invoiceInfo:Object,currencyDefault:Object,currencyClient:Object,emailActive:String,noItems:Boolean},data(){return{showConfirmModal:!1,showConfirmCreditModal:!1,loading:!1,sendInvoiceModal:!1,loadingModal:!1,loadingPdf:!1,client_detail:null,selectedStatus:null,subject:"",content:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{async changeInvoiceStatus(t,e){this.loading=!0;try{const a=await(await fetch("/wp-json/my-easy-compta/v1/invoices/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id,status:t,method:e})})).json();a.success?(this.invoiceInfo.status=t,this.loading=!1):(console.error("Failed to update invoice status:",a.message),this.loading=!1)}catch(s){console.error("An error occurred while updating invoice status:",s)}},async addCreditInvoice(){this.loading=!0;try{const e=await(await fetch("/wp-json/my-easy-compta/v1/invoices/credit",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id})})).json();e.success?(this.invoiceInfo.credit=1,this.loading=!1):(console.error("Failed to update invoice status:",e.message),this.loading=!1)}catch(t){console.error("An error occurred while updating invoice status:",t)}},exportToPDF(t){this.loadingPdf=!0;let s=`/wp-json/my-easy-compta/v1/invoices/pdf/${this.invoiceInfo.id}?currency_id=${t}`;fetch(s,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(a=>{if(!a.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return a.blob()}).then(a=>{const n=URL.createObjectURL(a);window.open(n),this.loadingPdf=!1}).catch(a=>{console.error("There was a problem with the fetch operation:",a),this.loadingPdf=!1})},sendInvoice(t){this.loadingModal=!0,this.sendInvoiceModal=!0,modal_send_invoice.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.subject=e.email_invoice_subject,this.content=e.email_invoice_content}else{const e=await t.json();this.showToast(e.message,"alert-error")}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},confirmValidateInvoice(t){this.selectedStatus=t,modal_confirm.showModal(),this.showConfirmModal=!0},confirmCreditInvoice(){modal_confirm_credit.showModal(),this.showConfirmCreditModal=!0}}},Pm={key:0},jm={key:1,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Mm=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),qm=[Mm],Om={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},Vm=i("div",{class:"dropdown"},[i("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),i("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[i("li",null,[i("a",null,"Item")]),i("li",null,[i("a",null,"Parent"),i("ul",{class:"p-2"},[i("li",null,[i("a",null,"Submenu")]),i("li",null,[i("a",null,"Submenu")])])]),i("li",null,[i("a",null,"Item")])])],-1),Rm={class:"hidden lg:flex gap-2"},Nm={class:"btn btn-sm"},Bm=i("i",{class:"far fa-edit"},null,-1),Fm={key:1},Wm={class:"btn btn-sm",disabled:""},Xm=i("i",{class:"far fa-edit"},null,-1),Um={key:2},Qm=i("i",{class:"fa fa-check"},null,-1),Lm={class:"btn btn-outline btn-success btn-sm hover:text-white",disabled:""},zm=i("i",{class:"fa fa-check"},null,-1),Hm={key:0},Gm={class:"btn btn-sm ms-2",disabled:""},Ym=i("i",{class:"fas fa-undo"},null,-1),Jm={key:1},Km=i("i",{class:"fas fa-undo"},null,-1),Zm=["disabled"],$m=i("i",{class:"far fa-file-pdf"},null,-1),ef={key:0,class:"loading loading-spinner loading-sm"},tf={class:"flex gap-2"},nf=i("i",{class:"fas fa-paper-plane"},null,-1),sf={key:0},of={key:1},af={key:2,class:"far fa-envelope"},lf=["data-tip"],rf={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},cf=i("i",{class:"fas fa-paper-plane"},null,-1),df=["data-tip"],uf={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},hf=i("i",{class:"fas fa-paper-plane"},null,-1),mf={key:3},ff={key:0,class:"dropdown dropdown-end"},pf={tabindex:"0",role:"button",class:"btn btn-outline btn-success btn-sm"},_f=i("i",{class:"far fa-file-pdf"},null,-1),gf={key:0,class:"loading loading-spinner loading-sm"},vf={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},yf=["disabled"],bf=["disabled"],wf={key:4},xf=["disabled"],If=i("i",{class:"far fa-file-pdf"},null,-1),Ef={key:0},Cf={key:1},kf={key:2,class:"loading loading-spinner loading-sm"},Tf=i("i",{class:"fas fa-check"},null,-1),Af=["data-tip"],Sf={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Df=i("i",{class:"fas fa-check"},null,-1);function Pf(t,e,s,a,n,o){const f=M("send-invoice-modal"),h=M("confirm-modal"),m=M("confirm-modal-credit"),r=M("router-link");return c(),d("div",null,[s.emailActive==1?(c(),d("div",Pm,[P(f,{loading:n.loadingModal,"show-modal":n.sendInvoiceModal,"modal-id":"modal_send_invoice",client:n.client_detail,"invoice-id":s.invoiceInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=u=>n.sendInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):g("",!0),P(h,{"show-modal":n.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,status:n.selectedStatus,onConfirm:e[1]||(e[1]=u=>this.changeInvoiceStatus(n.selectedStatus)),onCancel:e[2]||(e[2]=u=>n.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","status"]),P(m,{"show-modal":n.showConfirmCreditModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[3]||(e[3]=u=>this.addCreditInvoice()),onCancel:e[4]||(e[4]=u=>n.showConfirmCreditModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.loading?(c(),d("div",jm,qm)):g("",!0),i("div",Om,[i("div",null,[Vm,i("div",Rm,[s.invoiceInfo.status=="draft"?(c(),Rs(r,{key:0,to:{name:"InvoiceEdit",params:{id:s.invoiceInfo.id}}},{default:re(()=>[i("button",Nm,[Bm,w(" "+l(o.translations.edit_invoice),1)])]),_:1},8,["to"])):(c(),d("div",Fm,[i("button",Wm,[Xm,w(" "+l(o.translations.edit_invoice),1)])])),s.invoiceInfo.status=="unpaid"&&!s.noItems?(c(),d("div",Um,[i("button",{class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[5]||(e[5]=u=>o.confirmValidateInvoice("paid"))},[Qm,w(" "+l(o.translations.mark_as_paid),1)])])):(c(),d(X,{key:3},[i("div",null,[i("button",Lm,[zm,w(" "+l(o.translations.mark_as_paid),1)])]),s.invoiceInfo.credit!=0&&s.invoiceInfo.status=="paid"&&!s.noItems?(c(),d("div",Hm,[i("button",Gm,[Ym,w(" "+l(o.translations.credit_invoice),1)])])):g("",!0),s.invoiceInfo.credit==0&&s.invoiceInfo.status=="paid"&&!s.noItems?(c(),d("div",Jm,[i("button",{class:"btn btn-sm ms-2",onClick:e[6]||(e[6]=u=>o.confirmCreditInvoice())},[Km,w(" "+l(o.translations.credit_invoice),1)])])):g("",!0)],64))])]),s.invoiceInfo.status=="draft"?(c(),d("button",{key:0,onClick:e[7]||(e[7]=u=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-secondary btn-sm",disabled:n.loadingPdf},[$m,i("span",null,l(o.translations.previewPDF),1),n.loadingPdf?(c(),d("span",ef)):g("",!0)],8,Zm)):g("",!0),i("div",tf,[s.emailActive==1&&s.invoiceInfo.status!="draft"?(c(),d("button",{key:0,onClick:e[8]||(e[8]=K(u=>o.sendInvoice(s.invoiceInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[nf,s.invoiceInfo.sent==1?(c(),d("span",sf,l(o.translations.resend_invoice),1)):(c(),d("span",of,l(o.translations.send_invoice),1)),s.invoiceInfo.sent==1?(c(),d("i",af)):g("",!0)])):s.emailActive==1&&s.invoiceInfo.status=="draft"?(c(),d("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.draft_cannot_send},[i("button",rf,[cf,w(" "+l(o.translations.send_invoice),1)])],8,lf)):(c(),d("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[i("button",uf,[hf,w(" "+l(o.translations.send_invoice),1)])],8,df)),s.currencyDefault.currency_id!==s.currencyClient.currency_id?(c(),d("div",mf,[s.invoiceInfo.status!="draft"?(c(),d("div",ff,[i("div",pf,[_f,w(" "+l(o.translations.exportToPDF)+" ",1),n.loadingPdf?(c(),d("span",gf)):g("",!0)]),i("ul",vf,[i("li",null,[i("a",{onClick:e[9]||(e[9]=u=>o.exportToPDF(s.currencyDefault.currency_id)),disabled:n.loadingPdf},l(o.translations.invoice_in)+" "+l(s.currencyDefault.currency_symbol),9,yf)]),i("li",null,[i("a",{onClick:e[10]||(e[10]=u=>o.exportToPDF(s.currencyClient.currency_id)),disabled:n.loadingPdf},l(o.translations.invoice_in)+" "+l(s.currencyClient.currency_symbol),9,bf)])])])):g("",!0)])):(c(),d("div",wf,[s.invoiceInfo.status!="draft"?(c(),d("button",{key:0,onClick:e[11]||(e[11]=u=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[If,s.invoiceInfo.status!="draft"?(c(),d("span",Ef,l(o.translations.exportToPDF),1)):(c(),d("span",Cf,l(o.translations.previewPDF),1)),n.loadingPdf?(c(),d("span",kf)):g("",!0)],8,xf)):g("",!0)])),s.invoiceInfo.status=="draft"&&!s.noItems?(c(),d("button",{key:5,class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[12]||(e[12]=u=>o.confirmValidateInvoice("unpaid"))},[Tf,w(" "+l(o.translations.validateInvoice),1)])):g("",!0),s.invoiceInfo.status=="draft"&&s.noItems?(c(),d("div",{key:6,class:"tooltip tooltip-left tooltip-warning","data-tip":o.translations.min_article},[i("button",Sf,[Df,w(" "+l(o.translations.validateInvoice),1)])],8,Af)):g("",!0)])])])}var jf=oe(Dm,[["render",Pf]]);const Mf={components:{VueEditor:Et.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:"Nom de l'item"},item_description:{label:"Description de l'item",type:"textarea"},quantity:{label:"Quantit\xE9",type:"number"},vat_rate:{label:"Taux de TVA",type:"number"},unit_price:{label:"Prix unitaire",type:"number"},discount:{label:"Remise",type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/invoices/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},qf=["id","open"],Of={class:"modal-box"},Vf={class:"font-bold text-lg"},Rf={key:0},Nf={class:"grid grid-cols-1 gap-4"},Bf=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),Ff=i("div",{class:"skeleton h-4 w-full"},null,-1),Wf=[Bf,Ff],Xf={class:"grid grid-cols-1 gap-4"},Uf=["type"],Qf=["for"],Lf=["id","onUpdate:modelValue"],zf={key:1},Hf=["for"],Gf={class:"form-group mt-4 flex justify-end"},Yf=["disabled"],Jf={key:0,class:"loading loading-spinner loading-sm"};function Kf(t,e,s,a,n,o){const f=M("vue-editor");return c(),d("div",null,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",Of,[i("h3",Vf,l(s.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(c(),d("div",Rf,[i("div",Nf,[(c(!0),d(X,null,U(o.skeletonItems,h=>(c(),d("div",{key:h,class:"py-2"},Wf))),128))])])):(c(),d("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",Xf,[(c(!0),d(X,null,U(n.fields,(h,m)=>(c(),d("div",{key:m,class:"ecwp-group form-group"},[h.type!=="textarea"?(c(),d("div",{key:0,type:h.type||"text"},[i("label",{for:m,class:"ecwp-label form-label"},l(h.label),9,Qf),F(i("input",{id:m,"onUpdate:modelValue":r=>n.editedItem[m]=r,class:k(["ecwp-input input input-bordered",h.class||"w-full"])},null,10,Lf),[[J,n.editedItem[m]]])],8,Uf)):(c(),d("div",zf,[i("label",{for:m,class:"form-label"},l(h.label),9,Hf),P(f,{id:m,modelValue:n.editedItem[m],"onUpdate:modelValue":r=>n.editedItem[m]=r,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",Gf,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(c(),d("span",Jf)):g("",!0)],8,Yf)])],32))])],8,qf)])}var Zf=oe(Mf,[["render",Kf]]);const $f={name:"sendRemind",components:{VueEditor:Et.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"remind",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},ep=["id","open"],tp={class:"modal-box"},np={class:"font-bold text-lg"},sp={key:0},op={class:"grid grid-cols-1 gap-4"},ip=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),ap=i("div",{class:"skeleton h-4 w-full"},null,-1),lp=[ip,ap],rp={class:"grid grid-cols-1 gap-4"},cp=["type"],dp=["for"],up=["id","value","disabled","onInput"],hp={key:1},mp=["for"],fp={class:"form-group mt-4 flex justify-end"},pp=["disabled"],_p={key:0,class:"loading loading-spinner loading-sm"};function gp(t,e,s,a,n,o){const f=M("vue-editor");return c(),d("div",null,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",tp,[i("h3",np,l(o.translations.remind_invoice),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(c(),d("div",sp,[i("div",op,[(c(!0),d(X,null,U(o.skeletonItems,h=>(c(),d("div",{key:h,class:"py-2"},lp))),128))])])):(c(),d("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",rp,[(c(!0),d(X,null,U(n.fields,(h,m)=>(c(),d("div",{key:m,class:"ecwp-group form-group"},[h.type!=="textarea"?(c(),d("div",{key:0,type:h.type||"text"},[i("label",{for:m,class:"ecwp-label form-label"},l(h.label),9,dp),i("input",{id:m,class:k(["ecwp-input input input-bordered",h.class||"w-full"]),value:h.value,disabled:h.disabled,onInput:r=>o.updateFieldValue(m,r.target.value)},null,42,up)],8,cp)):(c(),d("div",hp,[i("label",{for:m,class:"form-label"},l(h.label),9,mp),P(f,{modelValue:h.value,"onUpdate:modelValue":r=>h.value=r,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",fp,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.send)+" ",1),n.loadingBtn?(c(),d("span",_p)):g("",!0)],8,pp)])],32))])],8,ep)])}var vp=oe($f,[["render",gp]]);const yp={name:"InvoiceViewDetail",components:{Card:Ue,InvoiceNavBar:jf,EditItemModal:Zf,RemoveModal:xt,RemindInvoiceModal:vp},data(){return{selectedItem:null,SelectedInvoiceId:null,editItemsModal:!1,RemindInvoiceModal:!1,no_items:!0,loading:!1,loading_add:!1,invoice:[],invoiceItems:[],newItem:{loading_del:!1,item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},settings:[],client_detail:[],list_vats:[],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",articles:[],categories:[],refs:[],showDropdown:!1,showDropdownRef:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isInvoiceOverdue(){const t=new Date().getTime(),e=this.invoice.due_date?new Date(this.invoice.due_date).getTime():null;return e&&e<t},defaultCurrency(){return{currency_id:this.settings.default_currency,currency_symbol:this.default_currency_symbol}},clientCurrency(){return{currency_id:this.client_detail.currency_id,currency_symbol:this.client_currency}},totalAmountWithoutDiscount(){const t=this.invoiceItems.reduce((e,s)=>{const a=s.quantity*s.unit_price;return e+a},0);return this.formatCurrency(t)},totalAmount(){const t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.invoiceItems.reduce((a,n)=>a+parseFloat(n.total_amount),0)*this.invoice.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)}},methods:{getUniqueVATRates(){const t=new Set;return this.invoiceItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.invoiceItems.forEach(s=>{if(s.vat_rate===t){const a=s.quantity*s.unit_price,n=a*s.discount/100;e+=(a-n)*t/100}}),this.formatCurrency(e)},calculateTotalAmountWithVAT(){let t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.formatCurrency(t)},fetchInvoice(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.invoice=t,this.fetchClientInfo(t.client_id)):console.error("Invoice not found")}).catch(t=>{console.error("Error fetching invoice:",t),this.loading=!1})},fetchClientInfo(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.invoiceItems=[],this.loading=!1,this.no_items=!0):(this.invoiceItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loading=!1,new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var a=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;a=s+n}else a=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(a)},calculateTotalWithVat(t,e,s,a){const n=t*e,o=n*a/100,f=n-o,h=f*s/100,m=f+h;return this.formatCurrency(m)},calculateTotal(t,e,s){const a=t*e,n=a*s/100,f=a-n;return this.formatCurrency(f)},submitItems(){this.updateTotal();const t={...this.newItem,invoice_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/invoices/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.SelectedInvoiceId=e,modal_remove.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.invoiceItems.find(a=>a.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:e})}).then(a=>a.json()).then(a=>{a.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(a.message,"alert-error"),console.error("Error removing item:",a.message),s.loading_del=!1)}).catch(a=>{this.showToast(a.message,"alert-error"),console.error("Error removing item:",a),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/invoices/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,a){const o=t*e*a/100,f=o*s/100,h=o+f;return this.formatCurrency(h)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.invoiceItems[t.oldIndex];this.invoiceItems.splice(t.oldIndex,1),this.invoiceItems.splice(t.newIndex,0,e);const s=this.invoiceItems.map(a=>a.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/invoices/update-invoice-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.articles=t}).catch(t=>console.error("Error fetching articles:",t))},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:a}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=a,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)},sendRemind(t){this.loadingModal=!0,this.RemindInvoiceModal=!0,modal_send_remind.showModal(),this.fetchClientInfo(t),this.loadSettings()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchInvoice(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");A.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},bp={class:"pt-2 pr-4"},wp={key:0},xp={key:2,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Ip=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),Ep=[Ip],Cp={key:3},kp={role:"alert",class:"alert alert-warning"},Tp=i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),Ap={key:0},Sp=["data-tip"],Dp={class:"btn btn-sm btn-primary",disabled:""},Pp={class:"grid grid-cols-2"},jp={class:"md:col-span-1"},Mp=["src"],qp={class:"md:col-span-1 text-right"},Op={class:"text-lg font-semibold"},Vp={key:0,class:"badge badge-error text-white"},Rp={key:1,class:"badge badge-error text-white"},Np={key:2,class:"badge badge-success text-white"},Bp={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},Fp=i("br",null,null,-1),Wp=i("br",null,null,-1),Xp=i("br",null,null,-1),Up=["href"],Qp=i("br",null,null,-1),Lp=i("br",null,null,-1),zp=i("br",null,null,-1),Hp=["href"],Gp=i("br",null,null,-1),Yp=["href"],Jp={class:"table mt-8"},Kp=i("th",null,null,-1),Zp={width:"5%"},$p={width:"19%"},e_={width:"21%"},t_={width:"10%",class:"text-center"},n_={width:"8%",class:"text-center"},s_={key:0,width:"5%",class:"text-center"},o_={key:1,width:"5%"},i_={width:"10%",class:"text-center"},a_={width:"10%",class:"text-right"},l_=i("th",{width:"18%",class:"text-right inv-actions"},null,-1),r_=i("td",{class:"draggable-item drag-handle px-2"},[i("i",{class:"fas fa-bars"})],-1),c_={key:0,class:"badge badge-ghost badge-xs"},d_=["innerHTML"],u_={class:"text-center"},h_={class:"text-center"},m_={key:0},f_={key:1},p_={key:0,class:"text-center"},__={key:1},g_={key:2,class:"text-center"},v_=i("br",null,null,-1),y_={key:3,class:"text-center"},b_=i("br",null,null,-1),w_={class:"text-right"},x_={key:0},I_={key:1},E_={key:0},C_=["data-tip"],k_=["onClick"],T_=i("i",{class:"far fa-edit"},null,-1),A_=[T_],S_=["data-tip"],D_=["onClick"],P_={key:0,class:"far fa-trash-alt"},j_={key:1,class:"loading loading-spinner loading-xs"},M_={key:0},q_=i("td",{class:"px-2"},null,-1),O_={class:"align-top px-2"},V_={class:"flex items-center border rounded-md relative"},R_=["placeholder"],N_={key:0,class:"autocomplete-dropdown bg-base-100"},B_=["onClick","innerHTML"],F_={class:"align-top px-2"},W_=i("option",{disabled:"",selected:""},"Type",-1),X_=["value"],U_={class:"flex items-center border rounded-md relative"},Q_=["placeholder"],L_={key:0,class:"autocomplete-dropdown bg-base-100"},z_=["onClick","innerHTML"],H_={class:"align-top"},G_={class:"flex items-center rounded-md"},Y_=["placeholder"],J_={class:"align-top"},K_={class:"flex items-center border rounded-lg"},Z_={class:"inline-flex"},$_=["placeholder"],eg={class:"align-top"},tg={class:"flex items-center border rounded-md"},ng=["placeholder"],sg={key:0,class:"align-top"},og=["value"],ig={key:1,class:"align-top"},ag={class:"align-top"},lg={class:"flex items-center border rounded-md"},rg=["placeholder"],cg=i("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),dg={key:2,class:"text-right"},ug={key:3,class:"text-right"},hg=["data-tip"],mg={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},fg={key:0,class:"fa fa-plus"},pg={key:1,class:"loading loading-spinner loading-xs"},_g={colspan:"8",class:"text-right no-border"},gg={class:"text-right"},vg={key:0,class:"line-through"},yg=i("td",null,null,-1),bg={colspan:"8",class:"text-right no-border"},wg={class:"text-right"},xg=i("td",null,null,-1),Ig={colspan:"8",class:"text-right no-border font-bold text-xl"},Eg={class:"text-right no-border font-bold text-xl"},Cg=i("td",null,null,-1),kg={key:2},Tg={colspan:"8",class:"text-right no-border"},Ag={class:"text-right no-border"},Sg={key:3},Dg={colspan:"8",class:"text-right no-border"},Pg={class:"text-right no-border font-bold text-xl"};function jg(t,e,s,a,n,o){const f=M("InvoiceNavBar"),h=M("remove-modal"),m=M("remind-invoice-modal"),r=M("edit-item-modal"),u=M("Card");return c(),d("div",bp,[P(f,{invoiceInfo:n.invoice,currencyDefault:o.defaultCurrency,currencyClient:o.clientCurrency,emailActive:n.settings.easy_compta_email_addon_active,noItems:n.no_items},null,8,["invoiceInfo","currencyDefault","currencyClient","emailActive","noItems"]),P(h,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=p=>this.removeItem(n.selectedItem,n.SelectedInvoiceId)),onCancel:e[1]||(e[1]=p=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.settings.easy_compta_email_addon_active==1?(c(),d("div",wp,[P(m,{loading:t.loadingModal,"show-modal":n.RemindInvoiceModal,"modal-id":"modal_send_remind",client:n.client_detail,"invoice-id":n.invoice.id,subject:n.settings.remind_invoice_subject,content:n.settings.remind_invoice_content,onClose:e[2]||(e[2]=p=>n.RemindInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):g("",!0),n.toast.visible?(c(),d("div",{key:1,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),n.loading?(c(),d("div",xp,Ep)):g("",!0),o.isInvoiceOverdue&&n.invoice.status=="unpaid"?(c(),d("div",Cp,[i("div",kp,[Tp,i("span",null,l(o.translations.invoice_overdue),1),n.settings.easy_compta_email_addon_active==1?(c(),d("div",Ap,[i("button",{onClick:e[3]||(e[3]=K(p=>o.sendRemind(n.invoice.client_id),["prevent"])),class:"btn btn-sm btn-primary"},l(o.translations.remind_invoice),1)])):(c(),d("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[i("button",Dp,l(o.translations.remind_invoice),1)],8,Sp))])])):g("",!0),P(u,{topMargin:"mt-8",id:"invoice-content"},{default:re(()=>[i("div",Pp,[i("div",jp,[i("div",null,[i("img",{src:n.settings.logo_url,style:Zn({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,Mp)])]),i("div",qp,[i("p",Op,l(n.invoice.invoice_number),1),i("div",null,[w(l(o.translations.created_at)+": ",1),i("strong",null,l(n.invoice.created_at),1)]),i("div",null,[w(l(o.translations.due_date)+": ",1),i("strong",null,l(n.invoice.due_date),1)]),i("div",null,[w(l(o.translations.status)+": ",1),n.invoice.status=="draft"?(c(),d("span",Vp,l(o.translations.draft),1)):g("",!0),n.invoice.status=="unpaid"?(c(),d("span",Rp,l(o.translations.unpaid),1)):g("",!0),n.invoice.status=="paid"?(c(),d("span",Np,l(o.translations.paid),1)):g("",!0)])])]),i("div",Bp,[i("div",null,[i("strong",null,l(o.translations.bill_to)+":",1),i("h4",null,[i("strong",null,l(n.client_detail.company_name),1)]),i("p",null,[w(l(n.client_detail.address),1),Fp,w(" "+l(n.client_detail.postal_code)+", "+l(n.client_detail.city)+" ",1),Wp,w(" "+l(n.client_detail.country),1),Xp,n.client_detail.phone?(c(),d("a",{key:0,href:"tel:"+n.client_detail.phone},l(n.client_detail.phone),9,Up)):g("",!0)])]),i("div",null,[i("strong",null,l(o.translations.received_from)+":",1),i("h4",null,[i("strong",null,l(n.settings.company_name),1)]),i("p",null,[w(l(n.settings.company_address),1),Qp,w(" "+l(n.settings.postal_code)+", "+l(n.settings.city)+" ",1),Lp,w(" "+l(n.settings.country),1),zp,n.settings.company_phone?(c(),d("a",{key:0,href:"tel:"+n.settings.company_phone},l(n.settings.company_phone),9,Hp)):g("",!0),Gp,n.settings.mobile_phone?(c(),d("a",{key:1,href:"tel:"+n.settings.mobile_phone},l(n.settings.mobile_phone),9,Yp)):g("",!0)])])]),P(r,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[4]||(e[4]=p=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),i("form",{onSubmit:e[24]||(e[24]=K((...p)=>o.submitItems&&o.submitItems(...p),["prevent"]))},[i("table",Jp,[i("thead",null,[i("tr",null,[Kp,i("th",Zp,l(o.translations.item_ref),1),i("th",$p,l(o.translations.item_name),1),i("th",e_,l(o.translations.description),1),i("th",t_,l(o.translations.quantity),1),i("th",n_,l(o.translations.unit_price),1),n.settings.vat_active==1?(c(),d("th",s_,l(o.translations.vat),1)):(c(),d("th",o_)),i("th",i_,l(o.translations.discount),1),i("th",a_,l(o.translations.total),1),l_])]),i("tbody",null,[(c(!0),d(X,null,U(n.invoiceItems,(p,_)=>(c(),d("tr",{key:p.id||_},[r_,i("td",null,l(p.item_ref),1),i("td",null,[p.category_name?(c(),d("div",c_,l(p.category_name),1)):g("",!0),i("div",null,l(p.item_name),1)]),i("td",{innerHTML:o.nl2br(p.item_description)},null,8,d_),i("td",u_,l(p.quantity),1),i("td",h_,[w(l(p.unit_price),1),n.default_currency_symbol==n.client_currency?(c(),d("span",m_,l(n.default_currency_symbol),1)):(c(),d("span",f_,l(n.client_currency),1))]),n.settings.vat_active==1?(c(),d("td",p_,l(p.vat_rate)+"%",1)):(c(),d("td",__)),n.settings.vat_active==1?(c(),d("td",g_,[w(l(p.discount)+"% ",1),v_,w(" "+l(o.calculateDiscountAmountWithVAT(p.quantity,p.unit_price,p.vat_rate,p.discount)),1)])):(c(),d("td",y_,[w(l(p.discount)+"% ",1),b_,w(" "+l(o.calculateDiscountAmount(p.quantity,p.unit_price,p.discount)),1)])),i("td",w_,[w(l(p.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(c(),d("span",x_,l(n.default_currency_symbol),1)):(c(),d("span",I_,l(n.client_currency),1))]),i("td",null,[n.invoice.status=="draft"?(c(),d("div",E_,[i("span",{class:"lg:tooltip","data-tip":o.translations.edit},[i("button",{onClick:K(v=>o.editItem(p.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},A_,8,k_)],8,C_),i("span",{class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:K(v=>o.confirmremoveItem(p.id,n.invoice.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[p.loading_del?g("",!0):(c(),d("i",P_)),p.loading_del?(c(),d("span",j_)):g("",!0)],8,D_)],8,S_)])):g("",!0)])]))),128)),n.invoice.status=="draft"?(c(),d("tr",M_,[q_,i("td",O_,[i("div",V_,[F(i("input",{type:"text","onUpdate:modelValue":e[5]||(e[5]=p=>n.newItem.item_ref=p),onInput:e[6]||(e[6]=(...p)=>o.fetchRefs&&o.fetchRefs(...p)),onFocus:e[7]||(e[7]=p=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 input-xs outline-none"},null,40,R_),[[J,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(c(),d("ul",N_,[(c(!0),d(X,null,U(n.refs,p=>(c(),d("li",{key:p.ref,onClick:_=>o.selectItem(p),class:"autocomplete-item",innerHTML:o.highlightMatch(p.ref)},null,8,B_))),128))])):g("",!0)])]),i("td",F_,[F(i("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[8]||(e[8]=p=>n.newItem.item_category=p)},[W_,(c(!0),d(X,null,U(n.categories,p=>(c(),d("option",{key:p.id,value:p.id},l(p.name),9,X_))),128))],512),[[Ie,n.newItem.item_category]]),i("div",U_,[F(i("input",{type:"text","onUpdate:modelValue":e[9]||(e[9]=p=>n.newItem.item_name=p),onInput:e[10]||(e[10]=(...p)=>o.fetchArticles&&o.fetchArticles(...p)),onFocus:e[11]||(e[11]=p=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,Q_),[[J,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(c(),d("ul",L_,[(c(!0),d(X,null,U(n.articles,p=>(c(),d("li",{key:p.name,onClick:_=>o.selectItem(p),class:"autocomplete-item bt-primary",innerHTML:o.highlightMatch(p.name)},null,8,z_))),128))])):g("",!0)])]),i("td",H_,[i("div",G_,[F(i("textarea",{"onUpdate:modelValue":e[12]||(e[12]=p=>n.newItem.item_description=p),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[13]||(e[13]=p=>o.resize()),ref:"textarea"},null,40,Y_),[[J,n.newItem.item_description]])])]),i("td",J_,[i("div",K_,[i("div",Z_,[i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[14]||(e[14]=(...p)=>o.decrease&&o.decrease(...p))}," - "),F(i("input",{type:"number",min:"1","onUpdate:modelValue":e[15]||(e[15]=p=>n.newItem.quantity=p),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[16]||(e[16]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,$_),[[J,n.newItem.quantity]]),i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[17]||(e[17]=(...p)=>o.increase&&o.increase(...p))}," + ")])])]),i("td",eg,[i("div",tg,[F(i("input",{type:"number","onUpdate:modelValue":e[18]||(e[18]=p=>n.newItem.unit_price=p),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[19]||(e[19]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,ng),[[J,n.newItem.unit_price]])])]),n.settings.vat_active==1?(c(),d("td",sg,[F(i("select",{"onUpdate:modelValue":e[20]||(e[20]=p=>n.newItem.vat_rate=p),onChange:e[21]||(e[21]=(...p)=>o.updateTotal&&o.updateTotal(...p)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(c(!0),d(X,null,U(n.list_vats,p=>(c(),d("option",{key:p,value:p.rate},l(p.rate)+"% ",9,og))),128))],544),[[Ie,n.newItem.vat_rate]])])):(c(),d("td",ig)),i("td",ag,[i("div",lg,[F(i("input",{type:"number","onUpdate:modelValue":e[22]||(e[22]=p=>n.newItem.discount=p),min:"0",max:"100",placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[23]||(e[23]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,rg),[[J,n.newItem.discount]]),cg])]),n.settings.vat_active==1?(c(),d("td",dg,l(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(c(),d("td",ug,l(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),i("td",null,[i("span",{class:"lg:tooltip","data-tip":o.translations.add},[i("button",mg,[n.loading_add?g("",!0):(c(),d("i",fg)),n.loading_add?(c(),d("span",pg)):g("",!0)])],8,hg)])])):g("",!0),i("tr",null,[i("td",_g,[i("strong",null,l(o.translations.subtotal),1)]),i("td",gg,[o.totalAmount!==o.totalAmountWithoutDiscount?(c(),d("span",vg,l(o.totalAmountWithoutDiscount),1)):g("",!0),w(" "+l(o.totalAmount),1)]),yg]),n.settings.vat_active==1?(c(!0),d(X,{key:1},U(o.getUniqueVATRates(),(p,_)=>(c(),d("tr",{key:_},[i("td",bg,[i("strong",null,l(o.translations.tax)+" ("+l(p)+"%) ",1)]),i("td",wg,l(o.calculateVATForRate(p)),1),xg]))),128)):g("",!0),i("tr",null,[i("td",Ig,[i("strong",null,l(o.translations.total),1)]),i("td",Eg,l(o.calculateTotalAmountWithVAT()),1),Cg]),n.client_currency!=n.default_currency_symbol?(c(),d("tr",kg,[i("td",Tg,[i("strong",null,l(o.translations.exchange_rate),1)]),i("td",Ag,l(n.invoice.exchange_rate),1)])):g("",!0),n.client_currency!=n.default_currency_symbol?(c(),d("tr",Sg,[i("td",Dg,[i("strong",null,l(o.translations.total)+" "+l(n.default_currency_symbol),1)]),i("td",Pg,l(o.totalAmountDefaultCurrency)+l(n.default_currency_symbol),1)])):g("",!0)])])],32)]),_:1})])}var Mg=oe(yp,[["render",jg]]);const qg={name:"InvoiceNew",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],last_invoice_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.invoice_prefix}_${String(this.settings.last_invoice_id).padStart(4,"0")}`;this.invoice.number=s}else{const e=await t.json()}}catch{this.loading=!1}},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/invoices",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting invoice:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Og={class:"pt-2 pr-4"},Vg={class:"flex justify-between items-center mb-4"},Rg={class:"card-title"},Ng=i("div",{class:"divider mt-2"},null,-1),Bg={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Fg={class:"grid grid-cols-2 gap-4"},Wg={class:"ecwp-group form-group mb-4"},Xg={for:"invoiceNumber",class:"ecwp-label"},Ug={class:"ecwp-group form-group mb-4"},Qg={for:"invoiceDate",class:"ecwp-label"},Lg={class:"ecwp-group form-group mb-4"},zg={for:"client",class:"ecwp-label"},Hg={class:"ecwp-group form-group mb-4"},Gg={for:"status",class:"ecwp-label"},Yg={value:"draft"},Jg={key:0,class:"ecwp-group form-group mb-4"},Kg={for:"exchangeRate",class:"ecwp-label"},Zg={class:"flex justify-between"},$g=["disabled"],ev={key:0,class:"loading loading-spinner loading-sm"};function tv(t,e,s,a,n,o){const f=M("VueDatePicker"),h=M("model-select"),m=M("Card");return c(),d("div",Og,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),P(m,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:re(()=>[i("div",Vg,[i("h2",Rg,l(o.translations.new_invoice),1)]),Ng,n.loading?(c(),d("div",Bg)):g("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...r)=>o.submitInvoice&&o.submitInvoice(...r),["prevent"]))},[i("div",Fg,[i("div",Wg,[i("label",Xg,l(o.translations.invoice_number),1),F(i("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=r=>n.invoice.number=r),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[J,n.invoice.number]])]),i("div",Ug,[i("label",Qg,l(o.translations.due_date),1),P(f,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=r=>n.invoice.due_date=r),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),i("div",Lg,[i("label",zg,l(o.translations.company_name),1),P(h,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[2]||(e[2]=r=>n.invoice.client_id=r),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",Hg,[i("label",Gg,l(o.translations.status),1),F(i("select",{id:"status","onUpdate:modelValue":e[3]||(e[3]=r=>n.invoice.status=r),class:k(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[i("option",Yg,l(o.translations.draft),1)],2),[[Ie,n.invoice.status]])]),o.currencyMismatch?(c(),d("div",Jg,[i("label",Kg,l(o.translations.exchange_rate),1),F(i("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[4]||(e[4]=r=>n.invoice.exchange_rate=r),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[J,n.invoice.exchange_rate]])])):g("",!0)]),i("div",Zg,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...r)=>o.cancelAction&&o.cancelAction(...r))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.submit)+" ",1),n.loadingBtn?(c(),d("span",ev)):g("",!0)],8,$g)])],32)]),_:1})])}var nv=oe(qg,[["render",tv]]);const sv={name:"invoiceEdit",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"paid",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchInvoiceDetails()},methods:{cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.invoice.client_id&&this.setClientById(this.invoice.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchInvoiceDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?this.invoice=e:(console.error("Error fetching invoice details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching invoice details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.invoice.client=this.clients.find(e=>e.id===t)||null},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting invoice:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},ov={class:"pt-2 pr-4"},iv={class:"flex justify-between items-center mb-4"},av={class:"card-title"},lv=i("div",{class:"divider mt-2"},null,-1),rv={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},cv={class:"grid grid-cols-2 gap-4"},dv={class:"ecwp-group form-group mb-4"},uv={for:"invoiceNumber",class:"ecwp-label"},hv={class:"ecwp-group form-group mb-4"},mv={for:"invoiceDate",class:"ecwp-label"},fv={class:"ecwp-group form-group mb-4"},pv={for:"client",class:"ecwp-label"},_v={class:"ecwp-group form-group mb-4"},gv={for:"status",class:"ecwp-label"},vv={value:"draft",selected:""},yv={value:"unpaid"},bv={value:"paid"},wv={key:0,class:"ecwp-group form-group mb-4"},xv={for:"exchangeRate",class:"ecwp-label"},Iv={class:"flex justify-between"},Ev=["disabled"],Cv={key:0,class:"loading loading-spinner loading-sm"};function kv(t,e,s,a,n,o){const f=M("VueDatePicker"),h=M("model-select"),m=M("Card");return c(),d("div",ov,[n.toast.visible?(c(),d("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):g("",!0),P(m,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:re(()=>[i("div",iv,[i("h2",av,l(o.translations.edit_invoice),1)]),lv,n.loading?(c(),d("div",rv)):g("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...r)=>o.submitInvoice&&o.submitInvoice(...r),["prevent"]))},[i("div",cv,[i("div",dv,[i("label",uv,l(o.translations.invoice_number),1),F(i("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=r=>n.invoice.invoice_number=r),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[J,n.invoice.invoice_number]])]),i("div",hv,[i("label",mv,l(o.translations.due_date),1),P(f,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=r=>n.invoice.due_date=r),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),i("div",fv,[i("label",pv,l(o.translations.company_name),1),P(h,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[2]||(e[2]=r=>n.invoice.client_id=r),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",_v,[i("label",gv,l(o.translations.status),1),F(i("select",{id:"status","onUpdate:modelValue":e[3]||(e[3]=r=>n.invoice.status=r),class:k(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[i("option",vv,l(o.translations.draft),1),i("option",yv,l(o.translations.unpaid),1),i("option",bv,l(o.translations.paid),1)],2),[[Ie,n.invoice.status]])]),o.currencyMismatch?(c(),d("div",wv,[i("label",xv,l(o.translations.exchange_rate),1),F(i("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[4]||(e[4]=r=>n.invoice.exchange_rate=r),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[J,n.invoice.exchange_rate]])])):g("",!0)]),i("div",Iv,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...r)=>o.cancelAction&&o.cancelAction(...r))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(c(),d("span",Cv)):g("",!0)],8,Ev)])],32)]),_:1})])}var Tv=oe(sv,[["render",kv]]);const we=Qt;(function(t,e){const s=Qt,a=t();for(;[];)try{if(parseInt(s(353))/1+parseInt(s(336))/2*(-parseInt(s(340))/3)+parseInt(s(338))/4*(parseInt(s(342))/5)+parseInt(s(344))/6*(parseInt(s(355))/7)+parseInt(s(348))/8+parseInt(s(341))/9*(-parseInt(s(345))/10)+parseInt(s(350))/11*(-parseInt(s(352))/12)===e)break;a.push(a.shift())}catch{a.push(a.shift())}})(Ut,347969);function Ut(){const t=["441583qMNFVP","InvoiceNew","3377682uCiSVP","Quote","/invoice/detail/:id","InvoiceViewDetail","2amEBit","/quote/detail/:id","4MdSzOn","/quote/edit/:id","895119FtyMfL","162BLVpZn","2831455SaAzsC","QuoteEdit","6dpZVDv","247550HSKaXY","Invoice","QuoteViewDetail","4071216MjUAJK","/invoice/edit/:id","1705IAGfBM","/quotes","70248XdLfXe"];return Ut=function(){return t},Ut()}function Qt(t,e){const s=Ut();return Qt=function(a,n){return a=a-335,s[a]},Qt(t,e)}const Av=[{path:we(351),name:we(356),component:ja},{path:we(337),name:we(347),component:xu},{path:"/quote/new",name:"QuoteNew",component:Yu},{path:we(339),name:we(343),component:_s},{path:"/invoices",name:we(346),component:$h},{path:we(357),name:we(335),component:Mg},{path:we(349),name:"InvoiceEdit",component:Tv},{path:"/invoice/new",name:we(354),component:nv}],Ov=Xo({history:_o(),routes:Av});export{Ov as r};10 */function Wn(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),s.push.apply(s,a)}return s}function Te(t){for(var e=1;e<arguments.length;e++){var s=arguments[e]!=null?arguments[e]:{};e%2?Wn(Object(s),!0).forEach(function(a){qr(t,a,s[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):Wn(Object(s)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(s,a))})}return t}function jt(t){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?jt=function(e){return typeof e}:jt=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},jt(t)}function qr(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function qe(){return qe=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(t[a]=s[a])}return t},qe.apply(this,arguments)}function Or(t,e){if(t==null)return{};var s={},a=Object.keys(t),n,o;for(o=0;o<a.length;o++)n=a[o],!(e.indexOf(n)>=0)&&(s[n]=t[n]);return s}function Vr(t,e){if(t==null)return{};var s=Or(t,e),a,n;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)a=o[n],!(e.indexOf(a)>=0)&&(!Object.prototype.propertyIsEnumerable.call(t,a)||(s[a]=t[a]))}return s}var Rr="1.15.2";function je(t){if(typeof window!="undefined"&&window.navigator)return!!navigator.userAgent.match(t)}var Oe=je(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),Ct=je(/Edge/i),Xn=je(/firefox/i),ft=je(/safari/i)&&!je(/chrome/i)&&!je(/android/i),gs=je(/iP(ad|od|hone)/i),vs=je(/chrome/i)&&je(/android/i),ys={capture:!1,passive:!1};function X(t,e,s){t.addEventListener(e,s,!Oe&&ys)}function N(t,e,s){t.removeEventListener(e,s,!Oe&&ys)}function Nt(t,e){if(!!e){if(e[0]===">"&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch{return!1}return!1}}function Nr(t){return t.host&&t!==document&&t.host.nodeType?t.host:t.parentNode}function Ie(t,e,s,a){if(t){s=s||document;do{if(e!=null&&(e[0]===">"?t.parentNode===s&&Nt(t,e):Nt(t,e))||a&&t===s)return t;if(t===s)break}while(t=Nr(t))}return null}var Un=/\s+/g;function fe(t,e,s){if(t&&e)if(t.classList)t.classList[s?"add":"remove"](e);else{var a=(" "+t.className+" ").replace(Un," ").replace(" "+e+" "," ");t.className=(a+(s?" "+e:"")).replace(Un," ")}}function S(t,e,s){var a=t&&t.style;if(a){if(s===void 0)return document.defaultView&&document.defaultView.getComputedStyle?s=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(s=t.currentStyle),e===void 0?s:s[e];!(e in a)&&e.indexOf("webkit")===-1&&(e="-webkit-"+e),a[e]=s+(typeof s=="string"?"":"px")}}function et(t,e){var s="";if(typeof t=="string")s=t;else do{var a=S(t,"transform");a&&a!=="none"&&(s=a+" "+s)}while(!e&&(t=t.parentNode));var n=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return n&&new n(s)}function bs(t,e,s){if(t){var a=t.getElementsByTagName(e),n=0,o=a.length;if(s)for(;n<o;n++)s(a[n],n);return a}return[]}function ke(){var t=document.scrollingElement;return t||document.documentElement}function te(t,e,s,a,n){if(!(!t.getBoundingClientRect&&t!==window)){var o,m,h,f,d,u,p;if(t!==window&&t.parentNode&&t!==ke()?(o=t.getBoundingClientRect(),m=o.top,h=o.left,f=o.bottom,d=o.right,u=o.height,p=o.width):(m=0,h=0,f=window.innerHeight,d=window.innerWidth,u=window.innerHeight,p=window.innerWidth),(e||s)&&t!==window&&(n=n||t.parentNode,!Oe))do if(n&&n.getBoundingClientRect&&(S(n,"transform")!=="none"||s&&S(n,"position")!=="static")){var g=n.getBoundingClientRect();m-=g.top+parseInt(S(n,"border-top-width")),h-=g.left+parseInt(S(n,"border-left-width")),f=m+o.height,d=h+o.width;break}while(n=n.parentNode);if(a&&t!==window){var v=et(n||t),I=v&&v.a,C=v&&v.d;v&&(m/=C,h/=I,p/=I,u/=C,f=m+u,d=h+p)}return{top:m,left:h,bottom:f,right:d,width:p,height:u}}}function Qn(t,e,s){for(var a=Xe(t,!0),n=te(t)[e];a;){var o=te(a)[s],m=void 0;if(s==="top"||s==="left"?m=n>=o:m=n<=o,!m)return a;if(a===ke())break;a=Xe(a,!1)}return!1}function st(t,e,s,a){for(var n=0,o=0,m=t.children;o<m.length;){if(m[o].style.display!=="none"&&m[o]!==A.ghost&&(a||m[o]!==A.dragged)&&Ie(m[o],s.draggable,t,!1)){if(n===e)return m[o];n++}o++}return null}function wn(t,e){for(var s=t.lastElementChild;s&&(s===A.ghost||S(s,"display")==="none"||e&&!Nt(s,e));)s=s.previousElementSibling;return s||null}function ge(t,e){var s=0;if(!t||!t.parentNode)return-1;for(;t=t.previousElementSibling;)t.nodeName.toUpperCase()!=="TEMPLATE"&&t!==A.clone&&(!e||Nt(t,e))&&s++;return s}function Ln(t){var e=0,s=0,a=ke();if(t)do{var n=et(t),o=n.a,m=n.d;e+=t.scrollLeft*o,s+=t.scrollTop*m}while(t!==a&&(t=t.parentNode));return[e,s]}function Br(t,e){for(var s in t)if(!!t.hasOwnProperty(s)){for(var a in e)if(e.hasOwnProperty(a)&&e[a]===t[s][a])return Number(s)}return-1}function Xe(t,e){if(!t||!t.getBoundingClientRect)return ke();var s=t,a=!1;do if(s.clientWidth<s.scrollWidth||s.clientHeight<s.scrollHeight){var n=S(s);if(s.clientWidth<s.scrollWidth&&(n.overflowX=="auto"||n.overflowX=="scroll")||s.clientHeight<s.scrollHeight&&(n.overflowY=="auto"||n.overflowY=="scroll")){if(!s.getBoundingClientRect||s===document.body)return ke();if(a||e)return s;a=!0}}while(s=s.parentNode);return ke()}function Fr(t,e){if(t&&e)for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t}function tn(t,e){return Math.round(t.top)===Math.round(e.top)&&Math.round(t.left)===Math.round(e.left)&&Math.round(t.height)===Math.round(e.height)&&Math.round(t.width)===Math.round(e.width)}var pt;function ws(t,e){return function(){if(!pt){var s=arguments,a=this;s.length===1?t.call(a,s[0]):t.apply(a,s),pt=setTimeout(function(){pt=void 0},e)}}}function Wr(){clearTimeout(pt),pt=void 0}function xs(t,e,s){t.scrollLeft+=e,t.scrollTop+=s}function Is(t){var e=window.Polymer,s=window.jQuery||window.Zepto;return e&&e.dom?e.dom(t).cloneNode(!0):s?s(t).clone(!0)[0]:t.cloneNode(!0)}function Es(t,e,s){var a={};return Array.from(t.children).forEach(function(n){var o,m,h,f;if(!(!Ie(n,e.draggable,t,!1)||n.animated||n===s)){var d=te(n);a.left=Math.min((o=a.left)!==null&&o!==void 0?o:1/0,d.left),a.top=Math.min((m=a.top)!==null&&m!==void 0?m:1/0,d.top),a.right=Math.max((h=a.right)!==null&&h!==void 0?h:-1/0,d.right),a.bottom=Math.max((f=a.bottom)!==null&&f!==void 0?f:-1/0,d.bottom)}}),a.width=a.right-a.left,a.height=a.bottom-a.top,a.x=a.left,a.y=a.top,a}var _e="Sortable"+new Date().getTime();function Xr(){var t=[],e;return{captureAnimationState:function(){if(t=[],!!this.options.animation){var a=[].slice.call(this.el.children);a.forEach(function(n){if(!(S(n,"display")==="none"||n===A.ghost)){t.push({target:n,rect:te(n)});var o=Te({},t[t.length-1].rect);if(n.thisAnimationDuration){var m=et(n,!0);m&&(o.top-=m.f,o.left-=m.e)}n.fromRect=o}})}},addAnimationState:function(a){t.push(a)},removeAnimationState:function(a){t.splice(Br(t,{target:a}),1)},animateAll:function(a){var n=this;if(!this.options.animation){clearTimeout(e),typeof a=="function"&&a();return}var o=!1,m=0;t.forEach(function(h){var f=0,d=h.target,u=d.fromRect,p=te(d),g=d.prevFromRect,v=d.prevToRect,I=h.rect,C=et(d,!0);C&&(p.top-=C.f,p.left-=C.e),d.toRect=p,d.thisAnimationDuration&&tn(g,p)&&!tn(u,p)&&(I.top-p.top)/(I.left-p.left)===(u.top-p.top)/(u.left-p.left)&&(f=Qr(I,g,v,n.options)),tn(p,u)||(d.prevFromRect=u,d.prevToRect=p,f||(f=n.options.animation),n.animate(d,I,p,f)),f&&(o=!0,m=Math.max(m,f),clearTimeout(d.animationResetTimer),d.animationResetTimer=setTimeout(function(){d.animationTime=0,d.prevFromRect=null,d.fromRect=null,d.prevToRect=null,d.thisAnimationDuration=null},f),d.thisAnimationDuration=f)}),clearTimeout(e),o?e=setTimeout(function(){typeof a=="function"&&a()},m):typeof a=="function"&&a(),t=[]},animate:function(a,n,o,m){if(m){S(a,"transition",""),S(a,"transform","");var h=et(this.el),f=h&&h.a,d=h&&h.d,u=(n.left-o.left)/(f||1),p=(n.top-o.top)/(d||1);a.animatingX=!!u,a.animatingY=!!p,S(a,"transform","translate3d("+u+"px,"+p+"px,0)"),this.forRepaintDummy=Ur(a),S(a,"transition","transform "+m+"ms"+(this.options.easing?" "+this.options.easing:"")),S(a,"transform","translate3d(0,0,0)"),typeof a.animated=="number"&&clearTimeout(a.animated),a.animated=setTimeout(function(){S(a,"transition",""),S(a,"transform",""),a.animated=!1,a.animatingX=!1,a.animatingY=!1},m)}}}}function Ur(t){return t.offsetWidth}function Qr(t,e,s,a){return Math.sqrt(Math.pow(e.top-t.top,2)+Math.pow(e.left-t.left,2))/Math.sqrt(Math.pow(e.top-s.top,2)+Math.pow(e.left-s.left,2))*a.animation}var Ye=[],nn={initializeByDefault:!0},kt={mount:function(e){for(var s in nn)nn.hasOwnProperty(s)&&!(s in e)&&(e[s]=nn[s]);Ye.forEach(function(a){if(a.pluginName===e.pluginName)throw"Sortable: Cannot mount plugin ".concat(e.pluginName," more than once")}),Ye.push(e)},pluginEvent:function(e,s,a){var n=this;this.eventCanceled=!1,a.cancel=function(){n.eventCanceled=!0};var o=e+"Global";Ye.forEach(function(m){!s[m.pluginName]||(s[m.pluginName][o]&&s[m.pluginName][o](Te({sortable:s},a)),s.options[m.pluginName]&&s[m.pluginName][e]&&s[m.pluginName][e](Te({sortable:s},a)))})},initializePlugins:function(e,s,a,n){Ye.forEach(function(h){var f=h.pluginName;if(!(!e.options[f]&&!h.initializeByDefault)){var d=new h(e,s,e.options);d.sortable=e,d.options=e.options,e[f]=d,qe(a,d.defaults)}});for(var o in e.options)if(!!e.options.hasOwnProperty(o)){var m=this.modifyOption(e,o,e.options[o]);typeof m!="undefined"&&(e.options[o]=m)}},getEventProperties:function(e,s){var a={};return Ye.forEach(function(n){typeof n.eventProperties=="function"&&qe(a,n.eventProperties.call(s[n.pluginName],e))}),a},modifyOption:function(e,s,a){var n;return Ye.forEach(function(o){!e[o.pluginName]||o.optionListeners&&typeof o.optionListeners[s]=="function"&&(n=o.optionListeners[s].call(e[o.pluginName],a))}),n}};function Lr(t){var e=t.sortable,s=t.rootEl,a=t.name,n=t.targetEl,o=t.cloneEl,m=t.toEl,h=t.fromEl,f=t.oldIndex,d=t.newIndex,u=t.oldDraggableIndex,p=t.newDraggableIndex,g=t.originalEvent,v=t.putSortable,I=t.extraEventProperties;if(e=e||s&&s[_e],!!e){var C,V=e.options,F="on"+a.charAt(0).toUpperCase()+a.substr(1);window.CustomEvent&&!Oe&&!Ct?C=new CustomEvent(a,{bubbles:!0,cancelable:!0}):(C=document.createEvent("Event"),C.initEvent(a,!0,!0)),C.to=m||s,C.from=h||s,C.item=n||s,C.clone=o,C.oldIndex=f,C.newIndex=d,C.oldDraggableIndex=u,C.newDraggableIndex=p,C.originalEvent=g,C.pullMode=v?v.lastPutMode:void 0;var D=Te(Te({},I),kt.getEventProperties(a,e));for(var q in D)C[q]=D[q];s&&s.dispatchEvent(C),V[F]&&V[F].call(e,C)}}var zr=["evt"],me=function(e,s){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},n=a.evt,o=Vr(a,zr);kt.pluginEvent.bind(A)(e,s,Te({dragEl:b,parentEl:Y,ghostEl:M,rootEl:H,nextEl:He,lastDownEl:qt,cloneEl:G,cloneHidden:We,dragStarted:rt,putSortable:ae,activeSortable:A.active,originalEvent:n,oldIndex:$e,oldDraggableIndex:_t,newIndex:pe,newDraggableIndex:Fe,hideGhostForTarget:As,unhideGhostForTarget:Ss,cloneNowHidden:function(){We=!0},cloneNowShown:function(){We=!1},dispatchSortableEvent:function(h){ue({sortable:s,name:h,originalEvent:n})}},o))};function ue(t){Lr(Te({putSortable:ae,cloneEl:G,targetEl:b,rootEl:H,oldIndex:$e,oldDraggableIndex:_t,newIndex:pe,newDraggableIndex:Fe},t))}var b,Y,M,H,He,qt,G,We,$e,pe,_t,Fe,St,ae,Ze=!1,Bt=!1,Ft=[],Le,we,sn,on,zn,Hn,rt,Je,gt,vt=!1,Dt=!1,Ot,le,an=[],fn=!1,Wt=[],Gt=typeof document!="undefined",Pt=gs,Gn=Ct||Oe?"cssFloat":"float",Hr=Gt&&!vs&&!gs&&"draggable"in document.createElement("div"),Cs=function(){if(!!Gt){if(Oe)return!1;var t=document.createElement("x");return t.style.cssText="pointer-events:auto",t.style.pointerEvents==="auto"}}(),ks=function(e,s){var a=S(e),n=parseInt(a.width)-parseInt(a.paddingLeft)-parseInt(a.paddingRight)-parseInt(a.borderLeftWidth)-parseInt(a.borderRightWidth),o=st(e,0,s),m=st(e,1,s),h=o&&S(o),f=m&&S(m),d=h&&parseInt(h.marginLeft)+parseInt(h.marginRight)+te(o).width,u=f&&parseInt(f.marginLeft)+parseInt(f.marginRight)+te(m).width;if(a.display==="flex")return a.flexDirection==="column"||a.flexDirection==="column-reverse"?"vertical":"horizontal";if(a.display==="grid")return a.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(o&&h.float&&h.float!=="none"){var p=h.float==="left"?"left":"right";return m&&(f.clear==="both"||f.clear===p)?"vertical":"horizontal"}return o&&(h.display==="block"||h.display==="flex"||h.display==="table"||h.display==="grid"||d>=n&&a[Gn]==="none"||m&&a[Gn]==="none"&&d+u>n)?"vertical":"horizontal"},Gr=function(e,s,a){var n=a?e.left:e.top,o=a?e.right:e.bottom,m=a?e.width:e.height,h=a?s.left:s.top,f=a?s.right:s.bottom,d=a?s.width:s.height;return n===h||o===f||n+m/2===h+d/2},Yr=function(e,s){var a;return Ft.some(function(n){var o=n[_e].options.emptyInsertThreshold;if(!(!o||wn(n))){var m=te(n),h=e>=m.left-o&&e<=m.right+o,f=s>=m.top-o&&s<=m.bottom+o;if(h&&f)return a=n}}),a},Ts=function(e){function s(o,m){return function(h,f,d,u){var p=h.options.group.name&&f.options.group.name&&h.options.group.name===f.options.group.name;if(o==null&&(m||p))return!0;if(o==null||o===!1)return!1;if(m&&o==="clone")return o;if(typeof o=="function")return s(o(h,f,d,u),m)(h,f,d,u);var g=(m?h:f).options.group.name;return o===!0||typeof o=="string"&&o===g||o.join&&o.indexOf(g)>-1}}var a={},n=e.group;(!n||jt(n)!="object")&&(n={name:n}),a.name=n.name,a.checkPull=s(n.pull,!0),a.checkPut=s(n.put),a.revertClone=n.revertClone,e.group=a},As=function(){!Cs&&M&&S(M,"display","none")},Ss=function(){!Cs&&M&&S(M,"display","")};Gt&&!vs&&document.addEventListener("click",function(t){if(Bt)return t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation(),Bt=!1,!1},!0);var ze=function(e){if(b){e=e.touches?e.touches[0]:e;var s=Yr(e.clientX,e.clientY);if(s){var a={};for(var n in e)e.hasOwnProperty(n)&&(a[n]=e[n]);a.target=a.rootEl=s,a.preventDefault=void 0,a.stopPropagation=void 0,s[_e]._onDragOver(a)}}},Jr=function(e){b&&b.parentNode[_e]._isOutsideThisEl(e.target)};function A(t,e){if(!(t&&t.nodeType&&t.nodeType===1))throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=qe({},e),t[_e]=this;var s={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return ks(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(m,h){m.setData("Text",h.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:A.supportPointer!==!1&&"PointerEvent"in window&&!ft,emptyInsertThreshold:5};kt.initializePlugins(this,t,s);for(var a in s)!(a in e)&&(e[a]=s[a]);Ts(e);for(var n in this)n.charAt(0)==="_"&&typeof this[n]=="function"&&(this[n]=this[n].bind(this));this.nativeDraggable=e.forceFallback?!1:Hr,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?X(t,"pointerdown",this._onTapStart):(X(t,"mousedown",this._onTapStart),X(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(X(t,"dragover",this),X(t,"dragenter",this)),Ft.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),qe(this,Xr())}A.prototype={constructor:A,_isOutsideThisEl:function(e){!this.el.contains(e)&&e!==this.el&&(Je=null)},_getDirection:function(e,s){return typeof this.options.direction=="function"?this.options.direction.call(this,e,s,b):this.options.direction},_onTapStart:function(e){if(!!e.cancelable){var s=this,a=this.el,n=this.options,o=n.preventOnFilter,m=e.type,h=e.touches&&e.touches[0]||e.pointerType&&e.pointerType==="touch"&&e,f=(h||e).target,d=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||f,u=n.filter;if(oc(a),!b&&!(/mousedown|pointerdown/.test(m)&&e.button!==0||n.disabled)&&!d.isContentEditable&&!(!this.nativeDraggable&&ft&&f&&f.tagName.toUpperCase()==="SELECT")&&(f=Ie(f,n.draggable,a,!1),!(f&&f.animated)&&qt!==f)){if($e=ge(f),_t=ge(f,n.draggable),typeof u=="function"){if(u.call(this,e,f,this)){ue({sortable:s,rootEl:d,name:"filter",targetEl:f,toEl:a,fromEl:a}),me("filter",s,{evt:e}),o&&e.cancelable&&e.preventDefault();return}}else if(u&&(u=u.split(",").some(function(p){if(p=Ie(d,p.trim(),a,!1),p)return ue({sortable:s,rootEl:p,name:"filter",targetEl:f,fromEl:a,toEl:a}),me("filter",s,{evt:e}),!0}),u)){o&&e.cancelable&&e.preventDefault();return}n.handle&&!Ie(d,n.handle,a,!1)||this._prepareDragStart(e,h,f)}}},_prepareDragStart:function(e,s,a){var n=this,o=n.el,m=n.options,h=o.ownerDocument,f;if(a&&!b&&a.parentNode===o){var d=te(a);if(H=o,b=a,Y=b.parentNode,He=b.nextSibling,qt=a,St=m.group,A.dragged=b,Le={target:b,clientX:(s||e).clientX,clientY:(s||e).clientY},zn=Le.clientX-d.left,Hn=Le.clientY-d.top,this._lastX=(s||e).clientX,this._lastY=(s||e).clientY,b.style["will-change"]="all",f=function(){if(me("delayEnded",n,{evt:e}),A.eventCanceled){n._onDrop();return}n._disableDelayedDragEvents(),!Xn&&n.nativeDraggable&&(b.draggable=!0),n._triggerDragStart(e,s),ue({sortable:n,name:"choose",originalEvent:e}),fe(b,m.chosenClass,!0)},m.ignore.split(",").forEach(function(u){bs(b,u.trim(),ln)}),X(h,"dragover",ze),X(h,"mousemove",ze),X(h,"touchmove",ze),X(h,"mouseup",n._onDrop),X(h,"touchend",n._onDrop),X(h,"touchcancel",n._onDrop),Xn&&this.nativeDraggable&&(this.options.touchStartThreshold=4,b.draggable=!0),me("delayStart",this,{evt:e}),m.delay&&(!m.delayOnTouchOnly||s)&&(!this.nativeDraggable||!(Ct||Oe))){if(A.eventCanceled){this._onDrop();return}X(h,"mouseup",n._disableDelayedDrag),X(h,"touchend",n._disableDelayedDrag),X(h,"touchcancel",n._disableDelayedDrag),X(h,"mousemove",n._delayedDragTouchMoveHandler),X(h,"touchmove",n._delayedDragTouchMoveHandler),m.supportPointer&&X(h,"pointermove",n._delayedDragTouchMoveHandler),n._dragStartTimer=setTimeout(f,m.delay)}else f()}},_delayedDragTouchMoveHandler:function(e){var s=e.touches?e.touches[0]:e;Math.max(Math.abs(s.clientX-this._lastX),Math.abs(s.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){b&&ln(b),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;N(e,"mouseup",this._disableDelayedDrag),N(e,"touchend",this._disableDelayedDrag),N(e,"touchcancel",this._disableDelayedDrag),N(e,"mousemove",this._delayedDragTouchMoveHandler),N(e,"touchmove",this._delayedDragTouchMoveHandler),N(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,s){s=s||e.pointerType=="touch"&&e,!this.nativeDraggable||s?this.options.supportPointer?X(document,"pointermove",this._onTouchMove):s?X(document,"touchmove",this._onTouchMove):X(document,"mousemove",this._onTouchMove):(X(b,"dragend",this),X(H,"dragstart",this._onDragStart));try{document.selection?Vt(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch{}},_dragStarted:function(e,s){if(Ze=!1,H&&b){me("dragStarted",this,{evt:s}),this.nativeDraggable&&X(document,"dragover",Jr);var a=this.options;!e&&fe(b,a.dragClass,!1),fe(b,a.ghostClass,!0),A.active=this,e&&this._appendGhost(),ue({sortable:this,name:"start",originalEvent:s})}else this._nulling()},_emulateDragOver:function(){if(we){this._lastX=we.clientX,this._lastY=we.clientY,As();for(var e=document.elementFromPoint(we.clientX,we.clientY),s=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(we.clientX,we.clientY),e!==s);)s=e;if(b.parentNode[_e]._isOutsideThisEl(e),s)do{if(s[_e]){var a=void 0;if(a=s[_e]._onDragOver({clientX:we.clientX,clientY:we.clientY,target:e,rootEl:s}),a&&!this.options.dragoverBubble)break}e=s}while(s=s.parentNode);Ss()}},_onTouchMove:function(e){if(Le){var s=this.options,a=s.fallbackTolerance,n=s.fallbackOffset,o=e.touches?e.touches[0]:e,m=M&&et(M,!0),h=M&&m&&m.a,f=M&&m&&m.d,d=Pt&&le&&Ln(le),u=(o.clientX-Le.clientX+n.x)/(h||1)+(d?d[0]-an[0]:0)/(h||1),p=(o.clientY-Le.clientY+n.y)/(f||1)+(d?d[1]-an[1]:0)/(f||1);if(!A.active&&!Ze){if(a&&Math.max(Math.abs(o.clientX-this._lastX),Math.abs(o.clientY-this._lastY))<a)return;this._onDragStart(e,!0)}if(M){m?(m.e+=u-(sn||0),m.f+=p-(on||0)):m={a:1,b:0,c:0,d:1,e:u,f:p};var g="matrix(".concat(m.a,",").concat(m.b,",").concat(m.c,",").concat(m.d,",").concat(m.e,",").concat(m.f,")");S(M,"webkitTransform",g),S(M,"mozTransform",g),S(M,"msTransform",g),S(M,"transform",g),sn=u,on=p,we=o}e.cancelable&&e.preventDefault()}},_appendGhost:function(){if(!M){var e=this.options.fallbackOnBody?document.body:H,s=te(b,!0,Pt,!0,e),a=this.options;if(Pt){for(le=e;S(le,"position")==="static"&&S(le,"transform")==="none"&&le!==document;)le=le.parentNode;le!==document.body&&le!==document.documentElement?(le===document&&(le=ke()),s.top+=le.scrollTop,s.left+=le.scrollLeft):le=ke(),an=Ln(le)}M=b.cloneNode(!0),fe(M,a.ghostClass,!1),fe(M,a.fallbackClass,!0),fe(M,a.dragClass,!0),S(M,"transition",""),S(M,"transform",""),S(M,"box-sizing","border-box"),S(M,"margin",0),S(M,"top",s.top),S(M,"left",s.left),S(M,"width",s.width),S(M,"height",s.height),S(M,"opacity","0.8"),S(M,"position",Pt?"absolute":"fixed"),S(M,"zIndex","100000"),S(M,"pointerEvents","none"),A.ghost=M,e.appendChild(M),S(M,"transform-origin",zn/parseInt(M.style.width)*100+"% "+Hn/parseInt(M.style.height)*100+"%")}},_onDragStart:function(e,s){var a=this,n=e.dataTransfer,o=a.options;if(me("dragStart",this,{evt:e}),A.eventCanceled){this._onDrop();return}me("setupClone",this),A.eventCanceled||(G=Is(b),G.removeAttribute("id"),G.draggable=!1,G.style["will-change"]="",this._hideClone(),fe(G,this.options.chosenClass,!1),A.clone=G),a.cloneId=Vt(function(){me("clone",a),!A.eventCanceled&&(a.options.removeCloneOnHide||H.insertBefore(G,b),a._hideClone(),ue({sortable:a,name:"clone"}))}),!s&&fe(b,o.dragClass,!0),s?(Bt=!0,a._loopId=setInterval(a._emulateDragOver,50)):(N(document,"mouseup",a._onDrop),N(document,"touchend",a._onDrop),N(document,"touchcancel",a._onDrop),n&&(n.effectAllowed="move",o.setData&&o.setData.call(a,n,b)),X(document,"drop",a),S(b,"transform","translateZ(0)")),Ze=!0,a._dragStartId=Vt(a._dragStarted.bind(a,s,e)),X(document,"selectstart",a),rt=!0,ft&&S(document.body,"user-select","none")},_onDragOver:function(e){var s=this.el,a=e.target,n,o,m,h=this.options,f=h.group,d=A.active,u=St===f,p=h.sort,g=ae||d,v,I=this,C=!1;if(fn)return;function V(Pe,Yt){me(Pe,I,Te({evt:e,isOwner:u,axis:v?"vertical":"horizontal",revert:m,dragRect:n,targetRect:o,canSort:p,fromSortable:g,target:a,completed:D,onMove:function(ot,it){return Mt(H,s,b,n,ot,te(ot),e,it)},changed:q},Yt))}function F(){V("dragOverAnimationCapture"),I.captureAnimationState(),I!==g&&g.captureAnimationState()}function D(Pe){return V("dragOverCompleted",{insertion:Pe}),Pe&&(u?d._hideClone():d._showClone(I),I!==g&&(fe(b,ae?ae.options.ghostClass:d.options.ghostClass,!1),fe(b,h.ghostClass,!0)),ae!==I&&I!==A.active?ae=I:I===A.active&&ae&&(ae=null),g===I&&(I._ignoreWhileAnimating=a),I.animateAll(function(){V("dragOverAnimationComplete"),I._ignoreWhileAnimating=null}),I!==g&&(g.animateAll(),g._ignoreWhileAnimating=null)),(a===b&&!b.animated||a===s&&!a.animated)&&(Je=null),!h.dragoverBubble&&!e.rootEl&&a!==document&&(b.parentNode[_e]._isOutsideThisEl(e.target),!Pe&&ze(e)),!h.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),C=!0}function q(){pe=ge(b),Fe=ge(b,h.draggable),ue({sortable:I,name:"change",toEl:s,newIndex:pe,newDraggableIndex:Fe,originalEvent:e})}if(e.preventDefault!==void 0&&e.cancelable&&e.preventDefault(),a=Ie(a,h.draggable,s,!0),V("dragOver"),A.eventCanceled)return C;if(b.contains(e.target)||a.animated&&a.animatingX&&a.animatingY||I._ignoreWhileAnimating===a)return D(!1);if(Bt=!1,d&&!h.disabled&&(u?p||(m=Y!==H):ae===this||(this.lastPutMode=St.checkPull(this,d,b,e))&&f.checkPut(this,d,b,e))){if(v=this._getDirection(e,a)==="vertical",n=te(b),V("dragOverValid"),A.eventCanceled)return C;if(m)return Y=H,F(),this._hideClone(),V("revert"),A.eventCanceled||(He?H.insertBefore(b,He):H.appendChild(b)),D(!0);var z=wn(s,h.draggable);if(!z||ec(e,v,this)&&!z.animated){if(z===b)return D(!1);if(z&&s===e.target&&(a=z),a&&(o=te(a)),Mt(H,s,b,n,a,o,e,!!a)!==!1)return F(),z&&z.nextSibling?s.insertBefore(b,z.nextSibling):s.appendChild(b),Y=s,q(),D(!0)}else if(z&&$r(e,v,this)){var ce=st(s,0,h,!0);if(ce===b)return D(!1);if(a=ce,o=te(a),Mt(H,s,b,n,a,o,e,!1)!==!1)return F(),s.insertBefore(b,ce),Y=s,q(),D(!0)}else if(a.parentNode===s){o=te(a);var ne=0,Z,Qe=b.parentNode!==s,ie=!Gr(b.animated&&b.toRect||n,a.animated&&a.toRect||o,v),Ve=v?"top":"left",ye=Qn(a,"top","top")||Qn(b,"top","top"),Re=ye?ye.scrollTop:void 0;Je!==a&&(Z=o[Ve],vt=!1,Dt=!ie&&h.invertSwap||Qe),ne=tc(e,a,o,v,ie?1:h.swapThreshold,h.invertedSwapThreshold==null?h.swapThreshold:h.invertedSwapThreshold,Dt,Je===a);var de;if(ne!==0){var Ae=ge(b);do Ae-=ne,de=Y.children[Ae];while(de&&(S(de,"display")==="none"||de===M))}if(ne===0||de===a)return D(!1);Je=a,gt=ne;var Se=a.nextElementSibling,be=!1;be=ne===1;var De=Mt(H,s,b,n,a,o,e,be);if(De!==!1)return(De===1||De===-1)&&(be=De===1),fn=!0,setTimeout(Zr,30),F(),be&&!Se?s.appendChild(b):a.parentNode.insertBefore(b,be?Se:a),ye&&xs(ye,0,Re-ye.scrollTop),Y=b.parentNode,Z!==void 0&&!Dt&&(Ot=Math.abs(Z-te(a)[Ve])),q(),D(!0)}if(s.contains(b))return D(!1)}return!1},_ignoreWhileAnimating:null,_offMoveEvents:function(){N(document,"mousemove",this._onTouchMove),N(document,"touchmove",this._onTouchMove),N(document,"pointermove",this._onTouchMove),N(document,"dragover",ze),N(document,"mousemove",ze),N(document,"touchmove",ze)},_offUpEvents:function(){var e=this.el.ownerDocument;N(e,"mouseup",this._onDrop),N(e,"touchend",this._onDrop),N(e,"pointerup",this._onDrop),N(e,"touchcancel",this._onDrop),N(document,"selectstart",this)},_onDrop:function(e){var s=this.el,a=this.options;if(pe=ge(b),Fe=ge(b,a.draggable),me("drop",this,{evt:e}),Y=b&&b.parentNode,pe=ge(b),Fe=ge(b,a.draggable),A.eventCanceled){this._nulling();return}Ze=!1,Dt=!1,vt=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),pn(this.cloneId),pn(this._dragStartId),this.nativeDraggable&&(N(document,"drop",this),N(s,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),ft&&S(document.body,"user-select",""),S(b,"transform",""),e&&(rt&&(e.cancelable&&e.preventDefault(),!a.dropBubble&&e.stopPropagation()),M&&M.parentNode&&M.parentNode.removeChild(M),(H===Y||ae&&ae.lastPutMode!=="clone")&&G&&G.parentNode&&G.parentNode.removeChild(G),b&&(this.nativeDraggable&&N(b,"dragend",this),ln(b),b.style["will-change"]="",rt&&!Ze&&fe(b,ae?ae.options.ghostClass:this.options.ghostClass,!1),fe(b,this.options.chosenClass,!1),ue({sortable:this,name:"unchoose",toEl:Y,newIndex:null,newDraggableIndex:null,originalEvent:e}),H!==Y?(pe>=0&&(ue({rootEl:Y,name:"add",toEl:Y,fromEl:H,originalEvent:e}),ue({sortable:this,name:"remove",toEl:Y,originalEvent:e}),ue({rootEl:Y,name:"sort",toEl:Y,fromEl:H,originalEvent:e}),ue({sortable:this,name:"sort",toEl:Y,originalEvent:e})),ae&&ae.save()):pe!==$e&&pe>=0&&(ue({sortable:this,name:"update",toEl:Y,originalEvent:e}),ue({sortable:this,name:"sort",toEl:Y,originalEvent:e})),A.active&&((pe==null||pe===-1)&&(pe=$e,Fe=_t),ue({sortable:this,name:"end",toEl:Y,originalEvent:e}),this.save()))),this._nulling()},_nulling:function(){me("nulling",this),H=b=Y=M=He=G=qt=We=Le=we=rt=pe=Fe=$e=_t=Je=gt=ae=St=A.dragged=A.ghost=A.clone=A.active=null,Wt.forEach(function(e){e.checked=!0}),Wt.length=sn=on=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":b&&(this._onDragOver(e),Kr(e));break;case"selectstart":e.preventDefault();break}},toArray:function(){for(var e=[],s,a=this.el.children,n=0,o=a.length,m=this.options;n<o;n++)s=a[n],Ie(s,m.draggable,this.el,!1)&&e.push(s.getAttribute(m.dataIdAttr)||sc(s));return e},sort:function(e,s){var a={},n=this.el;this.toArray().forEach(function(o,m){var h=n.children[m];Ie(h,this.options.draggable,n,!1)&&(a[o]=h)},this),s&&this.captureAnimationState(),e.forEach(function(o){a[o]&&(n.removeChild(a[o]),n.appendChild(a[o]))}),s&&this.animateAll()},save:function(){var e=this.options.store;e&&e.set&&e.set(this)},closest:function(e,s){return Ie(e,s||this.options.draggable,this.el,!1)},option:function(e,s){var a=this.options;if(s===void 0)return a[e];var n=kt.modifyOption(this,e,s);typeof n!="undefined"?a[e]=n:a[e]=s,e==="group"&&Ts(a)},destroy:function(){me("destroy",this);var e=this.el;e[_e]=null,N(e,"mousedown",this._onTapStart),N(e,"touchstart",this._onTapStart),N(e,"pointerdown",this._onTapStart),this.nativeDraggable&&(N(e,"dragover",this),N(e,"dragenter",this)),Array.prototype.forEach.call(e.querySelectorAll("[draggable]"),function(s){s.removeAttribute("draggable")}),this._onDrop(),this._disableDelayedDragEvents(),Ft.splice(Ft.indexOf(this.el),1),this.el=e=null},_hideClone:function(){if(!We){if(me("hideClone",this),A.eventCanceled)return;S(G,"display","none"),this.options.removeCloneOnHide&&G.parentNode&&G.parentNode.removeChild(G),We=!0}},_showClone:function(e){if(e.lastPutMode!=="clone"){this._hideClone();return}if(We){if(me("showClone",this),A.eventCanceled)return;b.parentNode==H&&!this.options.group.revertClone?H.insertBefore(G,b):He?H.insertBefore(G,He):H.appendChild(G),this.options.group.revertClone&&this.animate(b,G),S(G,"display",""),We=!1}}};function Kr(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move"),t.cancelable&&t.preventDefault()}function Mt(t,e,s,a,n,o,m,h){var f,d=t[_e],u=d.options.onMove,p;return window.CustomEvent&&!Oe&&!Ct?f=new CustomEvent("move",{bubbles:!0,cancelable:!0}):(f=document.createEvent("Event"),f.initEvent("move",!0,!0)),f.to=e,f.from=t,f.dragged=s,f.draggedRect=a,f.related=n||e,f.relatedRect=o||te(e),f.willInsertAfter=h,f.originalEvent=m,t.dispatchEvent(f),u&&(p=u.call(d,f,m)),p}function ln(t){t.draggable=!1}function Zr(){fn=!1}function $r(t,e,s){var a=te(st(s.el,0,s.options,!0)),n=Es(s.el,s.options,M),o=10;return e?t.clientX<n.left-o||t.clientY<a.top&&t.clientX<a.right:t.clientY<n.top-o||t.clientY<a.bottom&&t.clientX<a.left}function ec(t,e,s){var a=te(wn(s.el,s.options.draggable)),n=Es(s.el,s.options,M),o=10;return e?t.clientX>n.right+o||t.clientY>a.bottom&&t.clientX>a.left:t.clientY>n.bottom+o||t.clientX>a.right&&t.clientY>a.top}function tc(t,e,s,a,n,o,m,h){var f=a?t.clientY:t.clientX,d=a?s.height:s.width,u=a?s.top:s.left,p=a?s.bottom:s.right,g=!1;if(!m){if(h&&Ot<d*n){if(!vt&&(gt===1?f>u+d*o/2:f<p-d*o/2)&&(vt=!0),vt)g=!0;else if(gt===1?f<u+Ot:f>p-Ot)return-gt}else if(f>u+d*(1-n)/2&&f<p-d*(1-n)/2)return nc(e)}return g=g||m,g&&(f<u+d*o/2||f>p-d*o/2)?f>u+d/2?1:-1:0}function nc(t){return ge(b)<ge(t)?1:-1}function sc(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,s=e.length,a=0;s--;)a+=e.charCodeAt(s);return a.toString(36)}function oc(t){Wt.length=0;for(var e=t.getElementsByTagName("input"),s=e.length;s--;){var a=e[s];a.checked&&Wt.push(a)}}function Vt(t){return setTimeout(t,0)}function pn(t){return clearTimeout(t)}Gt&&X(document,"touchmove",function(t){(A.active||Ze)&&t.cancelable&&t.preventDefault()});A.utils={on:X,off:N,css:S,find:bs,is:function(e,s){return!!Ie(e,s,e,!1)},extend:Fr,throttle:ws,closest:Ie,toggleClass:fe,clone:Is,index:ge,nextTick:Vt,cancelNextTick:pn,detectDirection:ks,getChild:st};A.get=function(t){return t[_e]};A.mount=function(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];e[0].constructor===Array&&(e=e[0]),e.forEach(function(a){if(!a.prototype||!a.prototype.constructor)throw"Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(a));a.utils&&(A.utils=Te(Te({},A.utils),a.utils)),kt.mount(a)})};A.create=function(t,e){return new A(t,e)};A.version=Rr;var ee=[],ct,_n,gn=!1,rn,cn,Xt,dt;function ic(){function t(){this.defaults={scroll:!0,forceAutoScrollFallback:!1,scrollSensitivity:30,scrollSpeed:10,bubbleScroll:!0};for(var e in this)e.charAt(0)==="_"&&typeof this[e]=="function"&&(this[e]=this[e].bind(this))}return t.prototype={dragStarted:function(s){var a=s.originalEvent;this.sortable.nativeDraggable?X(document,"dragover",this._handleAutoScroll):this.options.supportPointer?X(document,"pointermove",this._handleFallbackAutoScroll):a.touches?X(document,"touchmove",this._handleFallbackAutoScroll):X(document,"mousemove",this._handleFallbackAutoScroll)},dragOverCompleted:function(s){var a=s.originalEvent;!this.options.dragOverBubble&&!a.rootEl&&this._handleAutoScroll(a)},drop:function(){this.sortable.nativeDraggable?N(document,"dragover",this._handleAutoScroll):(N(document,"pointermove",this._handleFallbackAutoScroll),N(document,"touchmove",this._handleFallbackAutoScroll),N(document,"mousemove",this._handleFallbackAutoScroll)),Yn(),Rt(),Wr()},nulling:function(){Xt=_n=ct=gn=dt=rn=cn=null,ee.length=0},_handleFallbackAutoScroll:function(s){this._handleAutoScroll(s,!0)},_handleAutoScroll:function(s,a){var n=this,o=(s.touches?s.touches[0]:s).clientX,m=(s.touches?s.touches[0]:s).clientY,h=document.elementFromPoint(o,m);if(Xt=s,a||this.options.forceAutoScrollFallback||Ct||Oe||ft){dn(s,this.options,h,a);var f=Xe(h,!0);gn&&(!dt||o!==rn||m!==cn)&&(dt&&Yn(),dt=setInterval(function(){var d=Xe(document.elementFromPoint(o,m),!0);d!==f&&(f=d,Rt()),dn(s,n.options,d,a)},10),rn=o,cn=m)}else{if(!this.options.bubbleScroll||Xe(h,!0)===ke()){Rt();return}dn(s,this.options,Xe(h,!1),!1)}}},qe(t,{pluginName:"scroll",initializeByDefault:!0})}function Rt(){ee.forEach(function(t){clearInterval(t.pid)}),ee=[]}function Yn(){clearInterval(dt)}var dn=ws(function(t,e,s,a){if(!!e.scroll){var n=(t.touches?t.touches[0]:t).clientX,o=(t.touches?t.touches[0]:t).clientY,m=e.scrollSensitivity,h=e.scrollSpeed,f=ke(),d=!1,u;_n!==s&&(_n=s,Rt(),ct=e.scroll,u=e.scrollFn,ct===!0&&(ct=Xe(s,!0)));var p=0,g=ct;do{var v=g,I=te(v),C=I.top,V=I.bottom,F=I.left,D=I.right,q=I.width,z=I.height,ce=void 0,ne=void 0,Z=v.scrollWidth,Qe=v.scrollHeight,ie=S(v),Ve=v.scrollLeft,ye=v.scrollTop;v===f?(ce=q<Z&&(ie.overflowX==="auto"||ie.overflowX==="scroll"||ie.overflowX==="visible"),ne=z<Qe&&(ie.overflowY==="auto"||ie.overflowY==="scroll"||ie.overflowY==="visible")):(ce=q<Z&&(ie.overflowX==="auto"||ie.overflowX==="scroll"),ne=z<Qe&&(ie.overflowY==="auto"||ie.overflowY==="scroll"));var Re=ce&&(Math.abs(D-n)<=m&&Ve+q<Z)-(Math.abs(F-n)<=m&&!!Ve),de=ne&&(Math.abs(V-o)<=m&&ye+z<Qe)-(Math.abs(C-o)<=m&&!!ye);if(!ee[p])for(var Ae=0;Ae<=p;Ae++)ee[Ae]||(ee[Ae]={});(ee[p].vx!=Re||ee[p].vy!=de||ee[p].el!==v)&&(ee[p].el=v,ee[p].vx=Re,ee[p].vy=de,clearInterval(ee[p].pid),(Re!=0||de!=0)&&(d=!0,ee[p].pid=setInterval(function(){a&&this.layer===0&&A.active._onTouchMove(Xt);var Se=ee[this.layer].vy?ee[this.layer].vy*h:0,be=ee[this.layer].vx?ee[this.layer].vx*h:0;typeof u=="function"&&u.call(A.dragged.parentNode[_e],be,Se,t,Xt,ee[this.layer].el)!=="continue"||xs(ee[this.layer].el,be,Se)}.bind({layer:p}),24))),p++}while(e.bubbleScroll&&g!==f&&(g=Xe(g,!1)));gn=d}},30),Ds=function(e){var s=e.originalEvent,a=e.putSortable,n=e.dragEl,o=e.activeSortable,m=e.dispatchSortableEvent,h=e.hideGhostForTarget,f=e.unhideGhostForTarget;if(!!s){var d=a||o;h();var u=s.changedTouches&&s.changedTouches.length?s.changedTouches[0]:s,p=document.elementFromPoint(u.clientX,u.clientY);f(),d&&!d.el.contains(p)&&(m("spill"),this.onSpill({dragEl:n,putSortable:a}))}};function xn(){}xn.prototype={startIndex:null,dragStart:function(e){var s=e.oldDraggableIndex;this.startIndex=s},onSpill:function(e){var s=e.dragEl,a=e.putSortable;this.sortable.captureAnimationState(),a&&a.captureAnimationState();var n=st(this.sortable.el,this.startIndex,this.options);n?this.sortable.el.insertBefore(s,n):this.sortable.el.appendChild(s),this.sortable.animateAll(),a&&a.animateAll()},drop:Ds};qe(xn,{pluginName:"revertOnSpill"});function In(){}In.prototype={onSpill:function(e){var s=e.dragEl,a=e.putSortable,n=a||this.sortable;n.captureAnimationState(),s.parentNode&&s.parentNode.removeChild(s),n.animateAll()},drop:Ds};qe(In,{pluginName:"removeOnSpill"});A.mount(new ic);A.mount(In,xn);const ac={name:"QuoteViewDetail",components:{Card:Ue,QuoteNavBar:mr,EditItemModal:jr,RemoveModal:xt},data(){return{selectedItem:null,selectedInvoiceId:null,editItemsModal:!1,no_items:!0,loading:!0,loading_add:!1,quote:[],quoteItems:[],newItem:{loading_del:!1,item_ref:"",item_name:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},vatRate:0,settings:[],list_vats:[],client_detail:[],client_email:null,client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},articles:[],categories:[],showDropdown:!1,refs:[],showDropdownRef:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isQuoteExpired(){const t=new Date().getTime(),e=this.quote.due_date?new Date(this.quote.due_date).getTime():null;return e&&e<t},totalAmountWithoutDiscount(){const t=this.quoteItems.reduce((e,s)=>{const a=s.quantity*s.unit_price;return e+a},0);return this.formatCurrency(t)},totalAmount(){const t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.quoteItems.reduce((a,n)=>a+parseFloat(n.total_amount),0)*this.quote.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)},signatureImageUrl(){const t="/wp-json/my-easy-compta/v1/signature-image/",e=myEasyComptaAdmin.nonce;return`${t}${this.quote.file_sign}?_wpnonce=${e}`}},methods:{getUniqueVATRates(){const t=new Set;return this.quoteItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.quoteItems.forEach(s=>{if(s.vat_rate===t){const a=s.quantity*s.unit_price,n=a*s.discount/100;e+=(a-n)*t/100}}),this.formatCurrency(e)},calculateTotalAmountWithVAT(){let t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.formatCurrency(t)},fetchQuote(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.quote=t,this.fetchClientInfo(t.client_id)):console.error("Quote not found")}).catch(t=>{console.error("Error fetching quote:",t),this.loading=!1})},fetchClientInfo(t){fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.client_email=e.email;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.quoteItems=[],this.loading=!1,this.no_items=!0):(this.quoteItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var a=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;a=s+n}else a=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(a)},calculateTotalWithVat(t,e,s,a){const n=t*e,o=n*a/100,m=n-o,h=m*s/100,f=m+h;return this.formatCurrency(f)},calculateTotal(t,e,s){const a=t*e,n=a*s/100,m=a-n;return this.formatCurrency(m)},submitItems(){this.updateTotal();const t={...this.newItem,quote_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/quotes/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.selectedInvoiceId=e,modal_remove.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.quoteItems.find(a=>a.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({quote_id:e})}).then(a=>a.json()).then(a=>{a.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(a.message,"alert-error"),console.error("Error removing item:",a.message),s.loading_del=!1)}).catch(a=>{this.showToast(a.message,"alert-error"),console.error("Error removing item:",a),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/quotes/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,a){const o=t*e*a/100,m=o*s/100,h=o+m;return this.formatCurrency(h)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.quoteItems[t.oldIndex];this.quoteItems.splice(t.oldIndex,1),this.quoteItems.splice(t.newIndex,0,e);const s=this.quoteItems.map(a=>a.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/quotes/update-quote-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.articles=t}).catch(t=>console.error("Error fetching articles:",t))},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loading=!0,this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:a}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=a,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1,this.loading=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1,this.loading=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchQuote(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");A.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},lc={class:"pt-2 pr-4"},rc={key:1,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},cc=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),dc=[cc],uc={key:2},hc={role:"alert",class:"alert alert-warning"},mc=i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),fc={key:0,class:"relative"},pc={class:"ecwp-watermark"},_c={class:"grid grid-cols-2"},gc={class:"md:col-span-1"},vc=["src"],yc={class:"md:col-span-1 text-right"},bc={class:"text-lg font-semibold"},wc={key:0,class:"badge badge-warning text-white"},xc={key:1,class:"badge badge-secondary text-white"},Ic={key:2,class:"badge badge-success text-white"},Ec={key:3,class:"badge badge-error text-white"},Cc={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},kc=i("br",null,null,-1),Tc=i("br",null,null,-1),Ac=i("br",null,null,-1),Sc=["href"],Dc=i("br",null,null,-1),Pc=i("br",null,null,-1),Mc=i("br",null,null,-1),jc=["href"],qc=i("br",null,null,-1),Oc=["href"],Vc={class:"table mt-8"},Rc=i("th",null,null,-1),Nc={width:"5%"},Bc={width:"19%"},Fc={width:"21%"},Wc={width:"10%",class:"text-center"},Xc={width:"8%",class:"text-center"},Uc={key:0,width:"5%",class:"text-center"},Qc={key:1,width:"5%"},Lc={width:"10%",class:"text-center"},zc={width:"10%",class:"text-right"},Hc=i("th",{width:"18%",class:"text-right inv-actions"},null,-1),Gc=i("td",{class:"draggable-item drag-handle px-2"},[i("i",{class:"fas fa-bars"})],-1),Yc={key:0,class:"badge badge-ghost badge-xs"},Jc=["innerHTML"],Kc={class:"text-center"},Zc={class:"text-center"},$c={key:0},ed={key:1},td={key:0,class:"text-center"},nd={key:1},sd={key:2,class:"text-center"},od=i("br",null,null,-1),id={key:3,class:"text-center"},ad=i("br",null,null,-1),ld={class:"text-right"},rd={key:0},cd={key:1},dd=["data-tip"],ud=["onClick"],hd=i("i",{class:"far fa-edit"},null,-1),md=[hd],fd=["data-tip"],pd=["onClick"],_d={key:0,class:"far fa-trash-alt"},gd={key:1,class:"loading loading-spinner loading-xs"},vd={key:0},yd=i("td",{class:"px-2"},null,-1),bd={class:"align-top px-2"},wd={class:"flex items-center border rounded-md relative"},xd=["placeholder"],Id={key:0,class:"autocomplete-dropdown bg-base-300"},Ed=["onClick","innerHTML"],Cd={class:"align-top px-2"},kd=i("option",{disabled:"",selected:""},"Type",-1),Td=["value"],Ad={class:"flex items-center border rounded-md relative"},Sd=["placeholder"],Dd={key:0,class:"autocomplete-dropdown bg-base-300"},Pd=["onClick","innerHTML"],Md={class:"align-top"},jd={class:"flex items-center rounded-md"},qd=["placeholder"],Od={class:"align-top"},Vd={class:"flex items-center border rounded-lg"},Rd={class:"inline-flex"},Nd=["placeholder"],Bd={class:"align-top"},Fd={class:"flex items-center border rounded-md"},Wd=["placeholder"],Xd={key:0,class:"align-top"},Ud=["value"],Qd={key:1,class:"align-top"},Ld={class:"align-top"},zd={class:"flex items-center border rounded-md"},Hd=["placeholder"],Gd=i("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),Yd={key:2,class:"text-right"},Jd={key:3,class:"text-right"},Kd=["data-tip"],Zd={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},$d={key:0,class:"fa fa-plus"},eu={key:1,class:"loading loading-spinner loading-xs"},tu={colspan:"8",class:"text-right no-border"},nu={class:"text-right"},su={key:0,class:"line-through"},ou=i("td",null,null,-1),iu={colspan:"8",class:"text-right no-border"},au={class:"text-right"},lu=i("td",null,null,-1),ru={colspan:"8",class:"text-right no-border font-bold text-xl"},cu={class:"text-right no-border font-bold text-xl"},du=i("td",null,null,-1),uu={key:2},hu={colspan:"8",class:"text-right no-border"},mu={class:"text-right no-border"},fu={key:3},pu={colspan:"8",class:"text-right no-border"},_u={class:"text-right no-border font-bold text-xl"},gu={key:1,class:"relative"},vu={class:"flex justify-end mt-4"},yu={class:"border-2 border-slate-300 max-w-md"},bu=["src"];function wu(t,e,s,a,n,o){const m=j("QuoteNavBar"),h=j("remove-modal"),f=j("edit-item-modal"),d=j("Card");return r(),c("div",lc,[P(m,{quoteInfo:n.quote,emailActive:n.settings.easy_compta_email_addon_active,advanceActive:n.settings.easy_compta_advance_addon_active,currency:n.default_currency_symbol,noItems:n.no_items},null,8,["quoteInfo","emailActive","advanceActive","currency","noItems"]),n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),P(h,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=u=>this.removeItem(n.selectedItem,n.selectedInvoiceId)),onCancel:e[1]||(e[1]=u=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.loading?(r(),c("div",rc,dc)):_("",!0),o.isQuoteExpired&&n.quote.status=="pending"?(r(),c("div",uc,[i("div",hc,[mc,i("span",null,l(o.translations.quote_expired),1)])])):_("",!0),P(d,{topMargin:"mt-8",id:"quote-content"},{default:re(()=>[n.settings.easy_compta_signature_addon_active&&n.quote.signed==1?(r(),c("div",fc,[i("span",pc,l(o.translations.signed),1)])):_("",!0),i("div",_c,[i("div",gc,[i("div",null,[i("img",{src:n.settings.logo_url,style:Zn({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,vc)])]),i("div",yc,[i("p",bc,l(n.quote.quote_number),1),i("div",null,[w(l(o.translations.created_at)+": ",1),i("strong",null,l(n.quote.created_at),1)]),i("div",null,[w(l(o.translations.due_date)+": ",1),i("strong",null,l(n.quote.due_date),1)]),i("div",null,[w(l(o.translations.provisional_date)+": ",1),i("strong",null,l(n.quote.provisional_start_date),1)]),i("div",null,[w(l(o.translations.status)+": ",1),n.quote.status=="draft"?(r(),c("span",wc,l(o.translations.draft),1)):_("",!0),n.quote.status=="pending"?(r(),c("span",xc,l(o.translations.pending),1)):_("",!0),n.quote.status=="approved"?(r(),c("span",Ic,l(o.translations.approved),1)):_("",!0),n.quote.status=="rejected"?(r(),c("span",Ec,l(o.translations.rejected),1)):_("",!0)])])]),i("div",Cc,[i("div",null,[i("strong",null,l(o.translations.bill_to)+":",1),i("h4",null,[i("strong",null,l(n.client_detail.company_name),1)]),i("p",null,[w(l(n.client_detail.address),1),kc,w(" "+l(n.client_detail.postal_code)+", "+l(n.client_detail.city)+" ",1),Tc,w(" "+l(n.client_detail.country),1),Ac,n.client_detail.phone?(r(),c("a",{key:0,href:"tel:"+n.client_detail.phone},l(n.client_detail.phone),9,Sc)):_("",!0)])]),i("div",null,[i("strong",null,l(o.translations.received_from)+":",1),i("h4",null,[i("strong",null,l(n.settings.company_name),1)]),i("p",null,[w(l(n.settings.company_address),1),Dc,w(" "+l(n.settings.postal_code)+", "+l(n.settings.city)+" ",1),Pc,w(" "+l(n.settings.country),1),Mc,n.settings.company_phone?(r(),c("a",{key:0,href:"tel:"+n.settings.company_phone},l(n.settings.company_phone),9,jc)):_("",!0),qc,n.settings.mobile_phone?(r(),c("a",{key:1,href:"tel:"+n.settings.mobile_phone},l(n.settings.mobile_phone),9,Oc)):_("",!0)])])]),P(f,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[2]||(e[2]=u=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),i("form",{onSubmit:e[22]||(e[22]=K((...u)=>o.submitItems&&o.submitItems(...u),["prevent"]))},[i("table",Vc,[i("thead",null,[i("tr",null,[Rc,i("th",Nc,l(o.translations.item_ref),1),i("th",Bc,l(o.translations.item_name),1),i("th",Fc,l(o.translations.description),1),i("th",Wc,l(o.translations.quantity),1),i("th",Xc,l(o.translations.unit_price),1),n.settings.vat_active==1?(r(),c("th",Uc,l(o.translations.vat),1)):(r(),c("th",Qc)),i("th",Lc,l(o.translations.discount),1),i("th",zc,l(o.translations.total),1),Hc])]),i("tbody",null,[(r(!0),c(W,null,U(n.quoteItems,(u,p)=>(r(),c("tr",{key:u.id||p},[Gc,i("td",null,l(u.item_ref),1),i("td",null,[u.category_name?(r(),c("div",Yc,l(u.category_name),1)):_("",!0),i("div",null,l(u.item_name),1)]),i("td",{innerHTML:o.nl2br(u.item_description)},null,8,Jc),i("td",Kc,l(u.quantity),1),i("td",Zc,[w(l(u.unit_price),1),n.default_currency_symbol==n.client_currency?(r(),c("span",$c,l(n.default_currency_symbol),1)):(r(),c("span",ed,l(n.client_currency),1))]),n.settings.vat_active==1?(r(),c("td",td,l(u.vat_rate)+"%",1)):(r(),c("td",nd)),n.settings.vat_active==1?(r(),c("td",sd,[w(l(u.discount)+"% ",1),od,w(" "+l(o.calculateDiscountAmountWithVAT(u.quantity,u.unit_price,u.vat_rate,u.discount)),1)])):(r(),c("td",id,[w(l(u.discount)+"% ",1),ad,w(" "+l(o.calculateDiscountAmount(u.quantity,u.unit_price,u.discount)),1)])),i("td",ld,[w(l(u.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(r(),c("span",rd,l(n.default_currency_symbol),1)):(r(),c("span",cd,l(n.client_currency),1))]),i("td",null,[n.quote.status=="draft"||n.quote.status=="pending"?(r(),c("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[i("button",{onClick:K(g=>o.editItem(u.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},md,8,ud)],8,dd)):_("",!0),n.quote.status=="draft"||n.quote.status=="pending"?(r(),c("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:K(g=>o.confirmremoveItem(u.id,n.quote.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[u.loading_del?_("",!0):(r(),c("i",_d)),u.loading_del?(r(),c("span",gd)):_("",!0)],8,pd)],8,fd)):_("",!0)])]))),128)),n.quote.status=="draft"||n.quote.status=="pending"?(r(),c("tr",vd,[yd,i("td",bd,[i("div",wd,[B(i("input",{type:"text","onUpdate:modelValue":e[3]||(e[3]=u=>n.newItem.item_ref=u),onInput:e[4]||(e[4]=(...u)=>o.fetchRefs&&o.fetchRefs(...u)),onFocus:e[5]||(e[5]=u=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,xd),[[J,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(r(),c("ul",Id,[(r(!0),c(W,null,U(n.refs,u=>(r(),c("li",{key:u.ref,onClick:p=>o.selectItem(u),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(u.ref)},null,8,Ed))),128))])):_("",!0)])]),i("td",Cd,[B(i("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[6]||(e[6]=u=>n.newItem.item_category=u)},[kd,(r(!0),c(W,null,U(n.categories,u=>(r(),c("option",{key:u.id,value:u.id},l(u.name),9,Td))),128))],512),[[ve,n.newItem.item_category]]),i("div",Ad,[B(i("input",{type:"text","onUpdate:modelValue":e[7]||(e[7]=u=>n.newItem.item_name=u),onInput:e[8]||(e[8]=(...u)=>o.fetchArticles&&o.fetchArticles(...u)),onFocus:e[9]||(e[9]=u=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,Sd),[[J,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(r(),c("ul",Dd,[(r(!0),c(W,null,U(n.articles,u=>(r(),c("li",{key:u.name,onClick:p=>o.selectItem(u),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(u.name)},null,8,Pd))),128))])):_("",!0)])]),i("td",Md,[i("div",jd,[B(i("textarea",{"onUpdate:modelValue":e[10]||(e[10]=u=>n.newItem.item_description=u),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[11]||(e[11]=u=>o.resize()),ref:"textarea"},null,40,qd),[[J,n.newItem.item_description]])])]),i("td",Od,[i("div",Vd,[i("div",Rd,[i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[12]||(e[12]=(...u)=>o.decrease&&o.decrease(...u))}," - "),B(i("input",{type:"number",min:"1","onUpdate:modelValue":e[13]||(e[13]=u=>n.newItem.quantity=u),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[14]||(e[14]=(...u)=>o.updateTotal&&o.updateTotal(...u))},null,40,Nd),[[J,n.newItem.quantity]]),i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[15]||(e[15]=(...u)=>o.increase&&o.increase(...u))}," + ")])])]),i("td",Bd,[i("div",Fd,[B(i("input",{type:"number","onUpdate:modelValue":e[16]||(e[16]=u=>n.newItem.unit_price=u),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[17]||(e[17]=(...u)=>o.updateTotal&&o.updateTotal(...u))},null,40,Wd),[[J,n.newItem.unit_price]])])]),n.settings.vat_active==1?(r(),c("td",Xd,[B(i("select",{"onUpdate:modelValue":e[18]||(e[18]=u=>n.newItem.vat_rate=u),onChange:e[19]||(e[19]=(...u)=>o.updateTotal&&o.updateTotal(...u)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(r(!0),c(W,null,U(n.list_vats,u=>(r(),c("option",{key:u,value:u.rate},l(u.rate)+"% ",9,Ud))),128))],544),[[ve,n.newItem.vat_rate]])])):(r(),c("td",Qd)),i("td",Ld,[i("div",zd,[B(i("input",{type:"number",min:"0",max:"100","onUpdate:modelValue":e[20]||(e[20]=u=>n.newItem.discount=u),placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[21]||(e[21]=(...u)=>o.updateTotal&&o.updateTotal(...u))},null,40,Hd),[[J,n.newItem.discount]]),Gd])]),n.settings.vat_active==1?(r(),c("td",Yd,l(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(r(),c("td",Jd,l(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),i("td",null,[i("span",{class:"lg:tooltip","data-tip":o.translations.add},[i("button",Zd,[n.loading_add?_("",!0):(r(),c("i",$d)),n.loading_add?(r(),c("span",eu)):_("",!0)])],8,Kd)])])):_("",!0),i("tr",null,[i("td",tu,[i("strong",null,l(o.translations.subtotal),1)]),i("td",nu,[o.totalAmount!==o.totalAmountWithoutDiscount?(r(),c("span",su,l(o.totalAmountWithoutDiscount),1)):_("",!0),w(" "+l(o.totalAmount),1)]),ou]),n.settings.vat_active==1?(r(!0),c(W,{key:1},U(o.getUniqueVATRates(),(u,p)=>(r(),c("tr",{key:p},[i("td",iu,[i("strong",null,l(o.translations.tax)+" ("+l(u)+"%) ",1)]),i("td",au,l(o.calculateVATForRate(u)),1),lu]))),128)):_("",!0),i("tr",null,[i("td",ru,[i("strong",null,l(o.translations.total),1)]),i("td",cu,l(o.calculateTotalAmountWithVAT()),1),du]),n.client_currency!=n.default_currency_symbol?(r(),c("tr",uu,[i("td",hu,[i("strong",null,l(o.translations.exchange_rate),1)]),i("td",mu,l(n.quote.exchange_rate),1)])):_("",!0),n.client_currency!=n.default_currency_symbol?(r(),c("tr",fu,[i("td",pu,[i("strong",null,l(o.translations.total)+" "+l(n.default_currency_symbol),1)]),i("td",_u,l(o.totalAmountDefaultCurrency)+l(n.default_currency_symbol),1)])):_("",!0)])])],32),n.settings.easy_compta_signature_addon_active&&n.quote.signed==1&&n.quote.file_sign?(r(),c("div",gu,[i("div",vu,[i("span",yu,[i("img",{src:o.signatureImageUrl,alt:"Signature"},null,8,bu)])])])):_("",!0)]),_:1})])}var xu=oe(ac,[["render",wu]]);const Iu={name:"QuoteNew",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{clientOptions:[],clients:[],quote:{number:"",due_date:"",provisional_start_date:"",client_id:"",status:""},showError:!1,loading:!1,loadingBtn:!1,settings:[],last_quote_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},customLabel(t){return t.text},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.quote_prefix}_${String(this.settings.last_quote_id).padStart(4,"0")}`;this.quote.number=s}else{const e=await t.json()}}catch{this.loading=!1}},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/quotes",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting quote:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Eu={class:"pt-2 pr-4"},Cu={class:"flex justify-between items-center mb-4"},ku={class:"card-title"},Tu=i("div",{class:"divider mt-2"},null,-1),Au={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Su={class:"grid grid-cols-3 gap-4"},Du={class:"ecwp-group form-group mb-4"},Pu={for:"quoteNumber",class:"ecwp-label"},Mu={class:"ecwp-group form-group mb-4"},ju={for:"quoteDate",class:"ecwp-label"},qu={class:"ecwp-group form-group mb-4"},Ou={for:"quoteDatePr",class:"ecwp-label"},Vu={class:"grid grid-cols-2 gap-4"},Ru={class:"ecwp-group form-group mb-4"},Nu={for:"client",class:"ecwp-label"},Bu={class:"ecwp-group form-group mb-4"},Fu={for:"status",class:"ecwp-label"},Wu={value:"draft",selected:""},Xu={value:"pending"},Uu={value:"approved"},Qu={value:"rejected"},Lu={class:"flex justify-between"},zu=["disabled"],Hu={key:0,class:"loading loading-spinner loading-sm"};function Gu(t,e,s,a,n,o){const m=j("VueDatePicker"),h=j("model-select"),f=j("Card");return r(),c("div",Eu,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),P(f,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:re(()=>[i("div",Cu,[i("h2",ku,l(o.translations.new_quote),1)]),Tu,n.loading?(r(),c("div",Au)):_("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...d)=>o.submitQuote&&o.submitQuote(...d),["prevent"]))},[i("div",Su,[i("div",Du,[i("label",Pu,l(o.translations.quote_number),1),B(i("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=d=>n.quote.number=d),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[J,n.quote.number]])]),i("div",Mu,[i("label",ju,l(o.translations.due_date),1),P(m,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=d=>n.quote.due_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),i("div",qu,[i("label",Ou,l(o.translations.provisional_date),1),P(m,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteDatePr",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=d=>n.quote.provisional_start_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])])]),i("div",Vu,[i("div",Ru,[i("label",Nu,l(o.translations.company_name),1),P(h,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[3]||(e[3]=d=>n.quote.client_id=d),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",Bu,[i("label",Fu,l(o.translations.status),1),B(i("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=d=>n.quote.status=d),class:k(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[i("option",Wu,l(o.translations.draft),1),i("option",Xu,l(o.translations.pending),1),i("option",Uu,l(o.translations.approved),1),i("option",Qu,l(o.translations.rejected),1)],2),[[ve,n.quote.status]])])]),i("div",Lu,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...d)=>o.cancelAction&&o.cancelAction(...d))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.submit)+" ",1),n.loadingBtn?(r(),c("span",Hu)):_("",!0)],8,zu)])],32)]),_:1})])}var Yu=oe(Iu,[["render",Gu]]);const Ju={name:"InvoicesList",components:{Card:Ue,RemoveModal:xt},data(){return{invoices:[],showInvoiceDetailsModal:!1,editInvoiceModal:!1,selectedInvoice:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchInvoices(),this.loadSettings()},methods:{fetchInvoices(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/invoices?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.invoices=s.invoices,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching invoices:",s)}).finally(()=>{this.loading=!1})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return $n(t,this.default_vat.rate)},calculateWithoutVAT(t){return es(t)},generatePaginationButtons(){this.paginationButtons=ts(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchInvoices(t)},perPageChanged(){this.fetchInvoices()},formatAmount(t,e){return ns(t,e,this.settings.currency_position)},showToast(t,e){ss(this.toast,t,e)},confirmDeleteInvoice(t){this.selectedInvoice=t,modal_remove.showModal(),this.showRemoveModal=!0},deleteInvoice(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchInvoices(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting invoice:",e.statusText))}).catch(e=>{console.log(e.message);const s=e&&e.message?e.message:"Error deleting client";s==="This client cannot be deleted because it has associated data."?this.showToast(s,"alert-error"):console.error("Error deleting client:",e)})}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},Ku={class:"pt-2 pr-4"},Zu={class:"flex justify-between items-center"},$u={class:"card-title"},eh={class:"btn btn-primary rounded-full"},th=i("i",{class:"fas fa-plus-circle"},null,-1),nh={key:0,class:"ms-2"},sh={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab3"},oh=i("i",{class:"fas fa-file-export"},null,-1),ih=["data-tip"],ah={class:"btn btn-outline btn-accent rounded-full",disabled:""},lh=i("i",{class:"fas fa-file-export"},null,-1),rh=i("div",{class:"divider mt-2"},null,-1),ch={class:"flex items-center mb-4"},dh={for:"perPageSelect",class:"mr-2"},uh=["value"],hh={class:"overflow-x-auto"},mh={key:0,class:"table w-full"},fh={class:"flex justify-center"},ph={key:0,class:"badge badge-primary badge-outline badge-sm mr-2"},_h={key:0,class:"badge badge-scondary badge-outline badge-sm"},gh={key:1,class:"badge badge-warning badge-outline badge-sm"},vh={key:2,class:"badge badge-success badge-outline badge-sm"},yh={key:3,class:"badge badge-error badge-outline badge-sm ms-2"},bh={key:0},wh={key:0},xh={key:0},Ih={key:1},Eh={key:0},Ch={key:1},kh={key:1},Th=i("span",{class:"loading loading-bars loading-sm"},null,-1),Ah=[Th],Sh={key:0},Dh={key:1},Ph=i("span",{class:"loading loading-bars loading-sm"},null,-1),Mh=[Ph],jh={key:0},qh={key:1},Oh=i("span",{class:"loading loading-bars loading-sm"},null,-1),Vh=[Oh],Rh={class:"flex justify-end"},Nh=["data-tip"],Bh=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"far fa-eye"})],-1),Fh=["data-tip"],Wh=i("button",{class:"btn btn-circle mx-1"},[i("i",{class:"fas fa-pencil-alt"})],-1),Xh=["data-tip"],Uh=["onClick"],Qh=i("i",{class:"far fa-trash-alt"},null,-1),Lh=[Qh],zh={key:1},Hh=i("div",{class:"flex gap-4 items-center"},[i("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),i("div",{class:"flex flex-col gap-4 w-full"},[i("div",{class:"skeleton h-4 w-full"}),i("div",{class:"skeleton h-4 w-full"})])],-1),Gh=i("div",{class:"divider my-1"},null,-1),Yh=[Hh,Gh],Jh={class:"join ecwp_pagination mt-6 pt-4"},Kh=["onClick"];function Zh(t,e,s,a,n,o){const m=j("remove-modal"),h=j("router-link"),f=j("Card");return r(),c("div",Ku,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),P(m,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=d=>this.deleteInvoice(n.selectedInvoice)),onCancel:e[1]||(e[1]=d=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(f,{topMargin:"mt-8"},{default:re(()=>[i("div",Zu,[i("h2",$u,l(o.translations.invoices),1),i("div",null,[P(h,{to:{name:"InvoiceNew"}},{default:re(()=>[i("button",eh,[w(l(o.translations.add)+" ",1),th])]),_:1}),n.settings.easy_compta_export_addon_active==1?(r(),c("span",nh,[i("a",sh,[w(l(o.translations.export)+" ",1),oh])])):(r(),c("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[i("button",ah,[w(l(o.translations.export)+" ",1),lh])],8,ih))])]),rh,i("div",ch,[i("label",dh,l(o.translations.display_per_page),1),B(i("select",{id:"perPageSelect","onUpdate:modelValue":e[2]||(e[2]=d=>n.perPage=d),onChange:e[3]||(e[3]=(...d)=>o.perPageChanged&&o.perPageChanged(...d))},[(r(!0),c(W,null,U(n.perPageOptions,d=>(r(),c("option",{key:d,value:d},l(d),9,uh))),128))],544),[[ve,n.perPage]])]),i("div",hh,[n.loading?(r(),c("div",zh,[(r(!0),c(W,null,U(n.skeletonRows,d=>(r(),c("div",{key:d,class:"flex flex-col gap-4 w-full"},Yh))),128))])):(r(),c("table",mh,[i("thead",null,[i("tr",null,[i("th",null,l(o.translations.invoice_number),1),i("th",null,l(o.translations.client),1),i("th",null,l(o.translations.status),1),i("th",null,l(o.translations.total),1),i("th",null,l(o.translations.due_date),1),i("th",null,l(o.translations.created_at),1),i("th",fh,l(o.translations.actions),1)])]),i("tbody",null,[(r(!0),c(W,null,U(n.invoices,d=>(r(),c("tr",{key:d.id},[i("td",null,[d.advance==1?(r(),c("span",ph,l(o.translations.advance),1)):_("",!0),w(l(d.invoice_number),1)]),i("td",null,l(d.client_name),1),i("td",null,[d.status=="draft"?(r(),c("span",_h,l(o.translations.draft),1)):_("",!0),d.status=="unpaid"?(r(),c("span",gh,l(o.translations.unpaid),1)):_("",!0),d.status=="paid"?(r(),c("span",vh,l(o.translations.paid),1)):_("",!0),d.credit=="1"?(r(),c("span",yh,l(o.translations.credit),1)):_("",!0)]),i("td",null,[n.loadingPrice?(r(),c("div",kh,Ah)):(r(),c("div",bh,[n.settings.easy_compta_advance_addon_active&&d.advance==1?(r(),c("div",wh,l(o.formatAmount(d.advance_amount,d.client_currency||n.default_currency_symbol)),1)):_("",!0),n.settings.vat_active==1?(r(),c("div",{key:1,class:k({"text-xs":d.advance==1})},[n.default_currency_symbol==d.client_currency||d.client_currency==null?(r(),c("span",xh,l(o.formatAmount(d.total_amount,n.default_currency_symbol)),1)):(r(),c("span",Ih,l(o.formatAmount(d.total_amount,d.client_currency)),1))],2)):(r(),c("div",{key:2,class:k({"text-xs":d.advance==1})},[n.default_currency_symbol==d.client_currency||d.client_currency==null?(r(),c("span",Eh,l(o.formatAmount(d.total_amount,n.default_currency_symbol)),1)):(r(),c("span",Ch,l(o.formatAmount(d.total_amount,d.client_currency)),1))],2))]))]),i("td",null,[n.loadingPrice?(r(),c("div",Dh,Mh)):(r(),c("div",Sh,l(d.due_date),1))]),i("td",null,[n.loadingPrice?(r(),c("div",qh,Vh)):(r(),c("div",jh,l(d.created),1))]),i("td",Rh,[i("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(h,{to:{name:"InvoiceViewDetail",params:{id:d.id}}},{default:re(()=>[Bh]),_:2},1032,["to"])],8,Nh),d.status=="draft"?(r(),c("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[P(h,{to:{name:"InvoiceEdit",params:{id:d.id}}},{default:re(()=>[Wh]),_:2},1032,["to"])],8,Fh)):_("",!0),d.status=="draft"?(r(),c("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:u=>o.confirmDeleteInvoice(d.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},Lh,8,Uh)],8,Xh)):_("",!0)])]))),128))])]))]),i("div",Jh,[(r(!0),c(W,null,U(n.paginationButtons,d=>(r(),c("button",{key:d,class:k(["join-item btn",{"btn-disabled":d==="..."||d===n.currentPage}]),onClick:u=>o.goToPage(d)},l(d),11,Kh))),128))])]),_:1})])}var $h=oe(Ju,[["render",Zh]]);const em={name:"sendInvoice",components:{VueEditor:Et.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"invoice",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},tm=["id","open"],nm={class:"modal-box"},sm={class:"font-bold text-lg"},om={key:0},im={class:"grid grid-cols-1 gap-4"},am=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),lm=i("div",{class:"skeleton h-4 w-full"},null,-1),rm=[am,lm],cm={class:"grid grid-cols-1 gap-4"},dm=["type"],um=["for"],hm=["id","value","disabled","onInput"],mm={key:1},fm=["for"],pm={class:"form-group mt-4 flex justify-end"},_m=["disabled"],gm={key:0,class:"loading loading-spinner loading-sm"};function vm(t,e,s,a,n,o){const m=j("vue-editor");return r(),c("div",null,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",nm,[i("h3",sm,l(o.translations.send_invoice),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(r(),c("div",om,[i("div",im,[(r(!0),c(W,null,U(o.skeletonItems,h=>(r(),c("div",{key:h,class:"py-2"},rm))),128))])])):(r(),c("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",cm,[(r(!0),c(W,null,U(n.fields,(h,f)=>(r(),c("div",{key:f,class:"ecwp-group form-group"},[h.type!=="textarea"?(r(),c("div",{key:0,type:h.type||"text"},[i("label",{for:f,class:"ecwp-label form-label"},l(h.label),9,um),i("input",{id:f,class:k(["ecwp-input input input-bordered",h.class||"w-full"]),value:h.value,disabled:h.disabled,onInput:d=>o.updateFieldValue(f,d.target.value)},null,42,hm)],8,dm)):(r(),c("div",mm,[i("label",{for:f,class:"form-label"},l(h.label),9,fm),P(m,{modelValue:h.value,"onUpdate:modelValue":d=>h.value=d,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",pm,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.send)+" ",1),n.loadingBtn?(r(),c("span",gm)):_("",!0)],8,_m)])],32))])],8,tm)])}var ym=oe(em,[["render",vm]]);const bm={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:"",paymentMethods:[],hasPaymentMethodError:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},mounted(){this.fetchPaymentMethods()},methods:{async fetchPaymentMethods(){try{const t=await fetch("/wp-json/my-easy-compta/v1/payments/methods",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(!t.ok)throw new Error(`Erreur : ${t.status}`);const e=await t.json();this.paymentMethods=e}catch(t){console.error("Erreur lors de la r\xE9cup\xE9ration des m\xE9thodes de paiement :",t)}},onConfirm(){if(!this.selectedPaymentMethod){this.hasPaymentMethodError=!0;return}this.hasPaymentMethodError=!1,this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm_paid").close()}}},wm=["open"],xm={class:"modal-box"},Im={class:"font-bold text-lg"},Em=i("div",{class:"text-center text-red-400 mb-2"},[i("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),Cm={class:"text-lg font-semibold text-center"},km={class:"my-4 text-center text-xl"},Tm={key:0,class:"mt-4 mb-4"},Am={class:"ecwp-group form-group"},Sm={for:"payment_method",class:"ecwp-label form-label"},Dm={value:""},Pm=["value"],Mm={class:"flex justify-between space-x-4"};function jm(t,e,s,a,n,o){return r(),c("div",null,[i("dialog",{id:"modal_confirm_paid",class:"modal",open:t.showModal},[i("div",xm,[i("h3",Im,l(t.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...m)=>o.closeModal&&o.closeModal(...m))}," \u2715 "),Em,i("h2",Cm,l(s.title),1),i("p",km,l(s.message),1),s.status==="paid"?(r(),c("div",Tm,[i("div",Am,[i("label",Sm,l(o.translations.payment_method),1),B(i("select",{id:"payment_method","onUpdate:modelValue":e[1]||(e[1]=m=>n.selectedPaymentMethod=m),class:k([{"input-error":n.hasPaymentMethodError},"ecwp-input input input-bordered w-full"])},[i("option",Dm,l(o.translations.select),1),(r(!0),c(W,null,U(n.paymentMethods,m=>(r(),c("option",{key:m.id,value:m.id},l(m.method_name),9,Pm))),128))],2),[[ve,n.selectedPaymentMethod]])])])):_("",!0),i("div",Mm,[i("button",{onClick:e[2]||(e[2]=(...m)=>o.onCancel&&o.onCancel(...m)),class:"btn btn-secondary rounded-full"},l(s.cancelText),1),i("button",{onClick:e[3]||(e[3]=(...m)=>o.onConfirm&&o.onConfirm(...m)),class:"btn rounded-full btn-error text-white"},l(s.confirmText),1)])])],8,wm)])}var qm=oe(bm,[["render",jm]]);const Om={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm_credit").close()}}},Vm=["open"],Rm={class:"modal-box"},Nm={class:"font-bold text-lg"},Bm=i("div",{class:"text-center text-red-400 mb-2"},[i("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),Fm={class:"text-lg font-semibold text-center"},Wm={class:"my-4 text-center text-xl"},Xm={class:"flex justify-between space-x-4"};function Um(t,e,s,a,n,o){return r(),c("div",null,[i("dialog",{id:"modal_confirm_credit",class:"modal",open:t.showModal},[i("div",Rm,[i("h3",Nm,l(t.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...m)=>o.closeModal&&o.closeModal(...m))}," \u2715 "),Bm,i("h2",Fm,l(s.title),1),i("p",Wm,l(s.message),1),i("div",Xm,[i("button",{onClick:e[1]||(e[1]=(...m)=>o.onCancel&&o.onCancel(...m)),class:"btn btn-secondary rounded-full"},l(s.cancelText),1),i("button",{onClick:e[2]||(e[2]=(...m)=>o.onConfirm&&o.onConfirm(...m)),class:"btn rounded-full btn-error text-white"},l(s.confirmText),1)])])],8,Vm)])}var Qm=oe(Om,[["render",Um]]);const Lm={name:"InvoiceNavBar",components:{SendInvoiceModal:ym,RemoveModal:xt,ConfirmModal:bn,ConfirmModalPaid:qm,ConfirmModalCredit:Qm},props:{invoiceInfo:Object,currencyDefault:Object,currencyClient:Object,emailActive:String,noItems:Boolean},data(){return{showConfirmModal:!1,showConfirmCreditModal:!1,loading:!1,sendInvoiceModal:!1,loadingModal:!1,loadingPdf:!1,client_detail:null,selectedStatus:null,subject:"",content:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{changeInvoiceStatusWithPaymentMethod(t){const e=this.selectedStatus;this.changeInvoiceStatus(e,t),this.showConfirmModal=!1},async changeInvoiceStatus(t,e){this.loading=!0;try{const a=await(await fetch("/wp-json/my-easy-compta/v1/invoices/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id,status:t,method:e})})).json();a.success?(this.invoiceInfo.status=t,this.loading=!1):(console.error("Failed to update invoice status:",a.message),this.loading=!1)}catch(s){console.error("An error occurred while updating invoice status:",s)}},async addCreditInvoice(){this.loading=!0;try{const e=await(await fetch("/wp-json/my-easy-compta/v1/invoices/credit",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id})})).json();e.success?(this.invoiceInfo.credit=1,this.loading=!1):(console.error("Failed to update invoice status:",e.message),this.loading=!1)}catch(t){console.error("An error occurred while updating invoice status:",t)}},exportToPDF(t){this.loadingPdf=!0;let s=`/wp-json/my-easy-compta/v1/invoices/pdf/${this.invoiceInfo.id}?currency_id=${t}`;fetch(s,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(a=>{if(!a.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return a.blob()}).then(a=>{const n=URL.createObjectURL(a);window.open(n),this.loadingPdf=!1}).catch(a=>{console.error("There was a problem with the fetch operation:",a),this.loadingPdf=!1})},sendInvoice(t){this.loadingModal=!0,this.sendInvoiceModal=!0,modal_send_invoice.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.subject=e.email_invoice_subject,this.content=e.email_invoice_content}else{const e=await t.json();this.showToast(e.message,"alert-error")}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},confirmValidateInvoice(t){this.selectedStatus=t,modal_confirm_paid.showModal(),this.showConfirmModal=!0},confirmCreditInvoice(){modal_confirm_credit.showModal(),this.showConfirmCreditModal=!0}}},zm={key:0},Hm={key:1,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Gm=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),Ym=[Gm],Jm={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},Km=i("div",{class:"dropdown"},[i("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),i("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[i("li",null,[i("a",null,"Item")]),i("li",null,[i("a",null,"Parent"),i("ul",{class:"p-2"},[i("li",null,[i("a",null,"Submenu")]),i("li",null,[i("a",null,"Submenu")])])]),i("li",null,[i("a",null,"Item")])])],-1),Zm={class:"hidden lg:flex gap-2"},$m={class:"btn btn-sm"},ef=i("i",{class:"far fa-edit"},null,-1),tf={key:1},nf={class:"btn btn-sm",disabled:""},sf=i("i",{class:"far fa-edit"},null,-1),of={key:2},af=i("i",{class:"fa fa-check"},null,-1),lf={class:"btn btn-outline btn-success btn-sm hover:text-white",disabled:""},rf=i("i",{class:"fa fa-check"},null,-1),cf={key:0},df={class:"btn btn-sm ms-2",disabled:""},uf=i("i",{class:"fas fa-undo"},null,-1),hf={key:1},mf=i("i",{class:"fas fa-undo"},null,-1),ff=["disabled"],pf=i("i",{class:"far fa-file-pdf"},null,-1),_f={key:0,class:"loading loading-spinner loading-sm"},gf={class:"flex gap-2"},vf=i("i",{class:"fas fa-paper-plane"},null,-1),yf={key:0},bf={key:1},wf={key:2,class:"far fa-envelope"},xf=["data-tip"],If={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Ef=i("i",{class:"fas fa-paper-plane"},null,-1),Cf=["data-tip"],kf={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Tf=i("i",{class:"fas fa-paper-plane"},null,-1),Af={key:3},Sf={key:0,class:"dropdown dropdown-end"},Df={tabindex:"0",role:"button",class:"btn btn-outline btn-success btn-sm"},Pf=i("i",{class:"far fa-file-pdf"},null,-1),Mf={key:0,class:"loading loading-spinner loading-sm"},jf={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},qf=["disabled"],Of=["disabled"],Vf={key:4},Rf=["disabled"],Nf=i("i",{class:"far fa-file-pdf"},null,-1),Bf={key:0},Ff={key:1},Wf={key:2,class:"loading loading-spinner loading-sm"},Xf=i("i",{class:"fas fa-check"},null,-1),Uf=["data-tip"],Qf={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Lf=i("i",{class:"fas fa-check"},null,-1);function zf(t,e,s,a,n,o){const m=j("send-invoice-modal"),h=j("confirm-modal-paid"),f=j("confirm-modal-credit"),d=j("router-link");return r(),c("div",null,[s.emailActive==1?(r(),c("div",zm,[P(m,{loading:n.loadingModal,"show-modal":n.sendInvoiceModal,"modal-id":"modal_send_invoice",client:n.client_detail,"invoice-id":s.invoiceInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=u=>n.sendInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):_("",!0),P(h,{"show-modal":n.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,status:n.selectedStatus,onConfirm:o.changeInvoiceStatusWithPaymentMethod,onCancel:e[1]||(e[1]=u=>n.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","status","onConfirm"]),P(f,{"show-modal":n.showConfirmCreditModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[2]||(e[2]=u=>this.addCreditInvoice()),onCancel:e[3]||(e[3]=u=>n.showConfirmCreditModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.loading?(r(),c("div",Hm,Ym)):_("",!0),i("div",Jm,[i("div",null,[Km,i("div",Zm,[s.invoiceInfo.status=="draft"?(r(),Rs(d,{key:0,to:{name:"InvoiceEdit",params:{id:s.invoiceInfo.id}}},{default:re(()=>[i("button",$m,[ef,w(" "+l(o.translations.edit_invoice),1)])]),_:1},8,["to"])):(r(),c("div",tf,[i("button",nf,[sf,w(" "+l(o.translations.edit_invoice),1)])])),s.invoiceInfo.status=="unpaid"&&!s.noItems?(r(),c("div",of,[i("button",{class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[4]||(e[4]=u=>o.confirmValidateInvoice("paid"))},[af,w(" "+l(o.translations.mark_as_paid),1)])])):(r(),c(W,{key:3},[i("div",null,[i("button",lf,[rf,w(" "+l(o.translations.mark_as_paid),1)])]),s.invoiceInfo.credit!=0&&s.invoiceInfo.status=="paid"&&!s.noItems?(r(),c("div",cf,[i("button",df,[uf,w(" "+l(o.translations.credit_invoice),1)])])):_("",!0),s.invoiceInfo.credit==0&&s.invoiceInfo.status=="paid"&&!s.noItems?(r(),c("div",hf,[i("button",{class:"btn btn-sm ms-2",onClick:e[5]||(e[5]=u=>o.confirmCreditInvoice())},[mf,w(" "+l(o.translations.credit_invoice),1)])])):_("",!0)],64))])]),s.invoiceInfo.status=="draft"?(r(),c("button",{key:0,onClick:e[6]||(e[6]=u=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-secondary btn-sm",disabled:n.loadingPdf},[pf,i("span",null,l(o.translations.previewPDF),1),n.loadingPdf?(r(),c("span",_f)):_("",!0)],8,ff)):_("",!0),i("div",gf,[s.emailActive==1&&s.invoiceInfo.status!="draft"?(r(),c("button",{key:0,onClick:e[7]||(e[7]=K(u=>o.sendInvoice(s.invoiceInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[vf,s.invoiceInfo.sent==1?(r(),c("span",yf,l(o.translations.resend_invoice),1)):(r(),c("span",bf,l(o.translations.send_invoice),1)),s.invoiceInfo.sent==1?(r(),c("i",wf)):_("",!0)])):s.emailActive==1&&s.invoiceInfo.status=="draft"?(r(),c("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.draft_cannot_send},[i("button",If,[Ef,w(" "+l(o.translations.send_invoice),1)])],8,xf)):(r(),c("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[i("button",kf,[Tf,w(" "+l(o.translations.send_invoice),1)])],8,Cf)),s.currencyDefault.currency_id!==s.currencyClient.currency_id?(r(),c("div",Af,[s.invoiceInfo.status!="draft"?(r(),c("div",Sf,[i("div",Df,[Pf,w(" "+l(o.translations.exportToPDF)+" ",1),n.loadingPdf?(r(),c("span",Mf)):_("",!0)]),i("ul",jf,[i("li",null,[i("a",{onClick:e[8]||(e[8]=u=>o.exportToPDF(s.currencyDefault.currency_id)),disabled:n.loadingPdf},l(o.translations.invoice_in)+" "+l(s.currencyDefault.currency_symbol),9,qf)]),i("li",null,[i("a",{onClick:e[9]||(e[9]=u=>o.exportToPDF(s.currencyClient.currency_id)),disabled:n.loadingPdf},l(o.translations.invoice_in)+" "+l(s.currencyClient.currency_symbol),9,Of)])])])):_("",!0)])):(r(),c("div",Vf,[s.invoiceInfo.status!="draft"?(r(),c("button",{key:0,onClick:e[10]||(e[10]=u=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[Nf,s.invoiceInfo.status!="draft"?(r(),c("span",Bf,l(o.translations.exportToPDF),1)):(r(),c("span",Ff,l(o.translations.previewPDF),1)),n.loadingPdf?(r(),c("span",Wf)):_("",!0)],8,Rf)):_("",!0)])),s.invoiceInfo.status=="draft"&&!s.noItems?(r(),c("button",{key:5,class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[11]||(e[11]=u=>o.confirmValidateInvoice("unpaid"))},[Xf,w(" "+l(o.translations.validateInvoice),1)])):_("",!0),s.invoiceInfo.status=="draft"&&s.noItems?(r(),c("div",{key:6,class:"tooltip tooltip-left tooltip-warning","data-tip":o.translations.min_article},[i("button",Qf,[Lf,w(" "+l(o.translations.validateInvoice),1)])],8,Uf)):_("",!0)])])])}var Hf=oe(Lm,[["render",zf]]);const Gf={components:{VueEditor:Et.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:"Nom de l'item"},item_description:{label:"Description de l'item",type:"textarea"},quantity:{label:"Quantit\xE9",type:"number"},vat_rate:{label:"Taux de TVA",type:"number"},unit_price:{label:"Prix unitaire",type:"number"},discount:{label:"Remise",type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/invoices/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},Yf=["id","open"],Jf={class:"modal-box"},Kf={class:"font-bold text-lg"},Zf={key:0},$f={class:"grid grid-cols-1 gap-4"},ep=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),tp=i("div",{class:"skeleton h-4 w-full"},null,-1),np=[ep,tp],sp={class:"grid grid-cols-1 gap-4"},op=["type"],ip=["for"],ap=["id","onUpdate:modelValue"],lp={key:1},rp=["for"],cp={class:"form-group mt-4 flex justify-end"},dp=["disabled"],up={key:0,class:"loading loading-spinner loading-sm"};function hp(t,e,s,a,n,o){const m=j("vue-editor");return r(),c("div",null,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",Jf,[i("h3",Kf,l(s.modalTitle),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(r(),c("div",Zf,[i("div",$f,[(r(!0),c(W,null,U(o.skeletonItems,h=>(r(),c("div",{key:h,class:"py-2"},np))),128))])])):(r(),c("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",sp,[(r(!0),c(W,null,U(n.fields,(h,f)=>(r(),c("div",{key:f,class:"ecwp-group form-group"},[h.type!=="textarea"?(r(),c("div",{key:0,type:h.type||"text"},[i("label",{for:f,class:"ecwp-label form-label"},l(h.label),9,ip),B(i("input",{id:f,"onUpdate:modelValue":d=>n.editedItem[f]=d,class:k(["ecwp-input input input-bordered",h.class||"w-full"])},null,10,ap),[[J,n.editedItem[f]]])],8,op)):(r(),c("div",lp,[i("label",{for:f,class:"form-label"},l(h.label),9,rp),P(m,{id:f,modelValue:n.editedItem[f],"onUpdate:modelValue":d=>n.editedItem[f]=d,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",cp,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(r(),c("span",up)):_("",!0)],8,dp)])],32))])],8,Yf)])}var mp=oe(Gf,[["render",hp]]);const fp={name:"sendRemind",components:{VueEditor:Et.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"remind",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},pp=["id","open"],_p={class:"modal-box"},gp={class:"font-bold text-lg"},vp={key:0},yp={class:"grid grid-cols-1 gap-4"},bp=i("div",{class:"skeleton h-4 w-full mb-2"},null,-1),wp=i("div",{class:"skeleton h-4 w-full"},null,-1),xp=[bp,wp],Ip={class:"grid grid-cols-1 gap-4"},Ep=["type"],Cp=["for"],kp=["id","value","disabled","onInput"],Tp={key:1},Ap=["for"],Sp={class:"form-group mt-4 flex justify-end"},Dp=["disabled"],Pp={key:0,class:"loading loading-spinner loading-sm"};function Mp(t,e,s,a,n,o){const m=j("vue-editor");return r(),c("div",null,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),i("dialog",{id:s.modalId,class:"modal",open:s.showModal},[i("div",_p,[i("h3",gp,l(o.translations.remind_invoice),1),i("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=h=>o.closeModal())}," \u2715 "),n.loading?(r(),c("div",vp,[i("div",yp,[(r(!0),c(W,null,U(o.skeletonItems,h=>(r(),c("div",{key:h,class:"py-2"},xp))),128))])])):(r(),c("form",{key:1,onSubmit:e[1]||(e[1]=K((...h)=>o.submitForm&&o.submitForm(...h),["prevent"])),class:"form"},[i("div",Ip,[(r(!0),c(W,null,U(n.fields,(h,f)=>(r(),c("div",{key:f,class:"ecwp-group form-group"},[h.type!=="textarea"?(r(),c("div",{key:0,type:h.type||"text"},[i("label",{for:f,class:"ecwp-label form-label"},l(h.label),9,Cp),i("input",{id:f,class:k(["ecwp-input input input-bordered",h.class||"w-full"]),value:h.value,disabled:h.disabled,onInput:d=>o.updateFieldValue(f,d.target.value)},null,42,kp)],8,Ep)):(r(),c("div",Tp,[i("label",{for:f,class:"form-label"},l(h.label),9,Ap),P(m,{modelValue:h.value,"onUpdate:modelValue":d=>h.value=d,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),i("div",Sp,[i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.send)+" ",1),n.loadingBtn?(r(),c("span",Pp)):_("",!0)],8,Dp)])],32))])],8,pp)])}var jp=oe(fp,[["render",Mp]]);const qp={name:"InvoiceViewDetail",components:{Card:Ue,InvoiceNavBar:Hf,EditItemModal:mp,RemoveModal:xt,RemindInvoiceModal:jp},data(){return{selectedItem:null,SelectedInvoiceId:null,editItemsModal:!1,RemindInvoiceModal:!1,no_items:!0,loading:!1,loading_add:!1,invoice:[],invoiceItems:[],newItem:{loading_del:!1,item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},settings:[],client_detail:[],list_vats:[],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",articles:[],categories:[],refs:[],showDropdown:!1,showDropdownRef:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isInvoiceOverdue(){const t=new Date().getTime(),e=this.invoice.due_date?new Date(this.invoice.due_date).getTime():null;return e&&e<t},defaultCurrency(){return{currency_id:this.settings.default_currency,currency_symbol:this.default_currency_symbol}},clientCurrency(){return{currency_id:this.client_detail.currency_id,currency_symbol:this.client_currency}},totalAmountWithoutDiscount(){const t=this.invoiceItems.reduce((e,s)=>{const a=s.quantity*s.unit_price;return e+a},0);return this.formatCurrency(t)},totalAmount(){const t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.invoiceItems.reduce((a,n)=>a+parseFloat(n.total_amount),0)*this.invoice.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)}},methods:{getUniqueVATRates(){const t=new Set;return this.invoiceItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.invoiceItems.forEach(s=>{if(s.vat_rate===t){const a=s.quantity*s.unit_price,n=a*s.discount/100;e+=(a-n)*t/100}}),this.formatCurrency(e)},calculateTotalAmountWithVAT(){let t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.formatCurrency(t)},fetchInvoice(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.invoice=t,this.fetchClientInfo(t.client_id)):console.error("Invoice not found")}).catch(t=>{console.error("Error fetching invoice:",t),this.loading=!1})},fetchClientInfo(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.invoiceItems=[],this.loading=!1,this.no_items=!0):(this.invoiceItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loading=!1,new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var a=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;a=s+n}else a=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(a)},calculateTotalWithVat(t,e,s,a){const n=t*e,o=n*a/100,m=n-o,h=m*s/100,f=m+h;return this.formatCurrency(f)},calculateTotal(t,e,s){const a=t*e,n=a*s/100,m=a-n;return this.formatCurrency(m)},submitItems(){this.updateTotal();const t={...this.newItem,invoice_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/invoices/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.SelectedInvoiceId=e,modal_remove.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.invoiceItems.find(a=>a.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:e})}).then(a=>a.json()).then(a=>{a.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(a.message,"alert-error"),console.error("Error removing item:",a.message),s.loading_del=!1)}).catch(a=>{this.showToast(a.message,"alert-error"),console.error("Error removing item:",a),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/invoices/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,a){const o=t*e*a/100,m=o*s/100,h=o+m;return this.formatCurrency(h)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.invoiceItems[t.oldIndex];this.invoiceItems.splice(t.oldIndex,1),this.invoiceItems.splice(t.newIndex,0,e);const s=this.invoiceItems.map(a=>a.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/invoices/update-invoice-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.articles=t}).catch(t=>console.error("Error fetching articles:",t))},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:a}=await zt();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=a,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)},sendRemind(t){this.loadingModal=!0,this.RemindInvoiceModal=!0,modal_send_remind.showModal(),this.fetchClientInfo(t),this.loadSettings()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchInvoice(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");A.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},Op={class:"pt-2 pr-4"},Vp={key:0},Rp={key:2,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Np=i("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),Bp=[Np],Fp={key:3},Wp={role:"alert",class:"alert alert-warning"},Xp=i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),Up={key:0},Qp=["data-tip"],Lp={class:"btn btn-sm btn-primary",disabled:""},zp={class:"grid grid-cols-2"},Hp={class:"md:col-span-1"},Gp=["src"],Yp={class:"md:col-span-1 text-right"},Jp={class:"text-lg font-semibold"},Kp={key:0,class:"badge badge-error text-white"},Zp={key:1,class:"badge badge-error text-white"},$p={key:2,class:"badge badge-success text-white"},e_={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},t_=i("br",null,null,-1),n_=i("br",null,null,-1),s_=i("br",null,null,-1),o_=["href"],i_=i("br",null,null,-1),a_=i("br",null,null,-1),l_=i("br",null,null,-1),r_=["href"],c_=i("br",null,null,-1),d_=["href"],u_={class:"table mt-8"},h_=i("th",null,null,-1),m_={width:"5%"},f_={width:"19%"},p_={width:"21%"},__={width:"10%",class:"text-center"},g_={width:"8%",class:"text-center"},v_={key:0,width:"5%",class:"text-center"},y_={key:1,width:"5%"},b_={width:"10%",class:"text-center"},w_={width:"10%",class:"text-right"},x_=i("th",{width:"18%",class:"text-right inv-actions"},null,-1),I_=i("td",{class:"draggable-item drag-handle px-2"},[i("i",{class:"fas fa-bars"})],-1),E_={key:0,class:"badge badge-ghost badge-xs"},C_=["innerHTML"],k_={class:"text-center"},T_={class:"text-center"},A_={key:0},S_={key:1},D_={key:0,class:"text-center"},P_={key:1},M_={key:2,class:"text-center"},j_=i("br",null,null,-1),q_={key:3,class:"text-center"},O_=i("br",null,null,-1),V_={class:"text-right"},R_={key:0},N_={key:1},B_={key:0},F_=["data-tip"],W_=["onClick"],X_=i("i",{class:"far fa-edit"},null,-1),U_=[X_],Q_=["data-tip"],L_=["onClick"],z_={key:0,class:"far fa-trash-alt"},H_={key:1,class:"loading loading-spinner loading-xs"},G_={key:0},Y_=i("td",{class:"px-2"},null,-1),J_={class:"align-top px-2"},K_={class:"flex items-center border rounded-md relative"},Z_=["placeholder"],$_={key:0,class:"autocomplete-dropdown bg-base-100"},eg=["onClick","innerHTML"],tg={class:"align-top px-2"},ng=i("option",{disabled:"",selected:""},"Type",-1),sg=["value"],og={class:"flex items-center border rounded-md relative"},ig=["placeholder"],ag={key:0,class:"autocomplete-dropdown bg-base-100"},lg=["onClick","innerHTML"],rg={class:"align-top"},cg={class:"flex items-center rounded-md"},dg=["placeholder"],ug={class:"align-top"},hg={class:"flex items-center border rounded-lg"},mg={class:"inline-flex"},fg=["placeholder"],pg={class:"align-top"},_g={class:"flex items-center border rounded-md"},gg=["placeholder"],vg={key:0,class:"align-top"},yg=["value"],bg={key:1,class:"align-top"},wg={class:"align-top"},xg={class:"flex items-center border rounded-md"},Ig=["placeholder"],Eg=i("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),Cg={key:2,class:"text-right"},kg={key:3,class:"text-right"},Tg=["data-tip"],Ag={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},Sg={key:0,class:"fa fa-plus"},Dg={key:1,class:"loading loading-spinner loading-xs"},Pg={colspan:"8",class:"text-right no-border"},Mg={class:"text-right"},jg={key:0,class:"line-through"},qg=i("td",null,null,-1),Og={colspan:"8",class:"text-right no-border"},Vg={class:"text-right"},Rg=i("td",null,null,-1),Ng={colspan:"8",class:"text-right no-border font-bold text-xl"},Bg={class:"text-right no-border font-bold text-xl"},Fg=i("td",null,null,-1),Wg={key:2},Xg={colspan:"8",class:"text-right no-border"},Ug={class:"text-right no-border"},Qg={key:3},Lg={colspan:"8",class:"text-right no-border"},zg={class:"text-right no-border font-bold text-xl"};function Hg(t,e,s,a,n,o){const m=j("InvoiceNavBar"),h=j("remove-modal"),f=j("remind-invoice-modal"),d=j("edit-item-modal"),u=j("Card");return r(),c("div",Op,[P(m,{invoiceInfo:n.invoice,currencyDefault:o.defaultCurrency,currencyClient:o.clientCurrency,emailActive:n.settings.easy_compta_email_addon_active,noItems:n.no_items},null,8,["invoiceInfo","currencyDefault","currencyClient","emailActive","noItems"]),P(h,{"show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=p=>this.removeItem(n.selectedItem,n.SelectedInvoiceId)),onCancel:e[1]||(e[1]=p=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.settings.easy_compta_email_addon_active==1?(r(),c("div",Vp,[P(f,{loading:t.loadingModal,"show-modal":n.RemindInvoiceModal,"modal-id":"modal_send_remind",client:n.client_detail,"invoice-id":n.invoice.id,subject:n.settings.remind_invoice_subject,content:n.settings.remind_invoice_content,onClose:e[2]||(e[2]=p=>n.RemindInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):_("",!0),n.toast.visible?(r(),c("div",{key:1,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),n.loading?(r(),c("div",Rp,Bp)):_("",!0),o.isInvoiceOverdue&&n.invoice.status=="unpaid"?(r(),c("div",Fp,[i("div",Wp,[Xp,i("span",null,l(o.translations.invoice_overdue),1),n.settings.easy_compta_email_addon_active==1?(r(),c("div",Up,[i("button",{onClick:e[3]||(e[3]=K(p=>o.sendRemind(n.invoice.client_id),["prevent"])),class:"btn btn-sm btn-primary"},l(o.translations.remind_invoice),1)])):(r(),c("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[i("button",Lp,l(o.translations.remind_invoice),1)],8,Qp))])])):_("",!0),P(u,{topMargin:"mt-8",id:"invoice-content"},{default:re(()=>[i("div",zp,[i("div",Hp,[i("div",null,[i("img",{src:n.settings.logo_url,style:Zn({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,Gp)])]),i("div",Yp,[i("p",Jp,l(n.invoice.invoice_number),1),i("div",null,[w(l(o.translations.created_at)+": ",1),i("strong",null,l(n.invoice.created_at),1)]),i("div",null,[w(l(o.translations.due_date)+": ",1),i("strong",null,l(n.invoice.due_date),1)]),i("div",null,[w(l(o.translations.status)+": ",1),n.invoice.status=="draft"?(r(),c("span",Kp,l(o.translations.draft),1)):_("",!0),n.invoice.status=="unpaid"?(r(),c("span",Zp,l(o.translations.unpaid),1)):_("",!0),n.invoice.status=="paid"?(r(),c("span",$p,l(o.translations.paid),1)):_("",!0)])])]),i("div",e_,[i("div",null,[i("strong",null,l(o.translations.bill_to)+":",1),i("h4",null,[i("strong",null,l(n.client_detail.company_name),1)]),i("p",null,[w(l(n.client_detail.address),1),t_,w(" "+l(n.client_detail.postal_code)+", "+l(n.client_detail.city)+" ",1),n_,w(" "+l(n.client_detail.country),1),s_,n.client_detail.phone?(r(),c("a",{key:0,href:"tel:"+n.client_detail.phone},l(n.client_detail.phone),9,o_)):_("",!0)])]),i("div",null,[i("strong",null,l(o.translations.received_from)+":",1),i("h4",null,[i("strong",null,l(n.settings.company_name),1)]),i("p",null,[w(l(n.settings.company_address),1),i_,w(" "+l(n.settings.postal_code)+", "+l(n.settings.city)+" ",1),a_,w(" "+l(n.settings.country),1),l_,n.settings.company_phone?(r(),c("a",{key:0,href:"tel:"+n.settings.company_phone},l(n.settings.company_phone),9,r_)):_("",!0),c_,n.settings.mobile_phone?(r(),c("a",{key:1,href:"tel:"+n.settings.mobile_phone},l(n.settings.mobile_phone),9,d_)):_("",!0)])])]),P(d,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[4]||(e[4]=p=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),i("form",{onSubmit:e[24]||(e[24]=K((...p)=>o.submitItems&&o.submitItems(...p),["prevent"]))},[i("table",u_,[i("thead",null,[i("tr",null,[h_,i("th",m_,l(o.translations.item_ref),1),i("th",f_,l(o.translations.item_name),1),i("th",p_,l(o.translations.description),1),i("th",__,l(o.translations.quantity),1),i("th",g_,l(o.translations.unit_price),1),n.settings.vat_active==1?(r(),c("th",v_,l(o.translations.vat),1)):(r(),c("th",y_)),i("th",b_,l(o.translations.discount),1),i("th",w_,l(o.translations.total),1),x_])]),i("tbody",null,[(r(!0),c(W,null,U(n.invoiceItems,(p,g)=>(r(),c("tr",{key:p.id||g},[I_,i("td",null,l(p.item_ref),1),i("td",null,[p.category_name?(r(),c("div",E_,l(p.category_name),1)):_("",!0),i("div",null,l(p.item_name),1)]),i("td",{innerHTML:o.nl2br(p.item_description)},null,8,C_),i("td",k_,l(p.quantity),1),i("td",T_,[w(l(p.unit_price),1),n.default_currency_symbol==n.client_currency?(r(),c("span",A_,l(n.default_currency_symbol),1)):(r(),c("span",S_,l(n.client_currency),1))]),n.settings.vat_active==1?(r(),c("td",D_,l(p.vat_rate)+"%",1)):(r(),c("td",P_)),n.settings.vat_active==1?(r(),c("td",M_,[w(l(p.discount)+"% ",1),j_,w(" "+l(o.calculateDiscountAmountWithVAT(p.quantity,p.unit_price,p.vat_rate,p.discount)),1)])):(r(),c("td",q_,[w(l(p.discount)+"% ",1),O_,w(" "+l(o.calculateDiscountAmount(p.quantity,p.unit_price,p.discount)),1)])),i("td",V_,[w(l(p.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(r(),c("span",R_,l(n.default_currency_symbol),1)):(r(),c("span",N_,l(n.client_currency),1))]),i("td",null,[n.invoice.status=="draft"?(r(),c("div",B_,[i("span",{class:"lg:tooltip","data-tip":o.translations.edit},[i("button",{onClick:K(v=>o.editItem(p.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},U_,8,W_)],8,F_),i("span",{class:"lg:tooltip","data-tip":o.translations.delete},[i("button",{onClick:K(v=>o.confirmremoveItem(p.id,n.invoice.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[p.loading_del?_("",!0):(r(),c("i",z_)),p.loading_del?(r(),c("span",H_)):_("",!0)],8,L_)],8,Q_)])):_("",!0)])]))),128)),n.invoice.status=="draft"?(r(),c("tr",G_,[Y_,i("td",J_,[i("div",K_,[B(i("input",{type:"text","onUpdate:modelValue":e[5]||(e[5]=p=>n.newItem.item_ref=p),onInput:e[6]||(e[6]=(...p)=>o.fetchRefs&&o.fetchRefs(...p)),onFocus:e[7]||(e[7]=p=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 input-xs outline-none"},null,40,Z_),[[J,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(r(),c("ul",$_,[(r(!0),c(W,null,U(n.refs,p=>(r(),c("li",{key:p.ref,onClick:g=>o.selectItem(p),class:"autocomplete-item",innerHTML:o.highlightMatch(p.ref)},null,8,eg))),128))])):_("",!0)])]),i("td",tg,[B(i("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[8]||(e[8]=p=>n.newItem.item_category=p)},[ng,(r(!0),c(W,null,U(n.categories,p=>(r(),c("option",{key:p.id,value:p.id},l(p.name),9,sg))),128))],512),[[ve,n.newItem.item_category]]),i("div",og,[B(i("input",{type:"text","onUpdate:modelValue":e[9]||(e[9]=p=>n.newItem.item_name=p),onInput:e[10]||(e[10]=(...p)=>o.fetchArticles&&o.fetchArticles(...p)),onFocus:e[11]||(e[11]=p=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,ig),[[J,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(r(),c("ul",ag,[(r(!0),c(W,null,U(n.articles,p=>(r(),c("li",{key:p.name,onClick:g=>o.selectItem(p),class:"autocomplete-item bt-primary",innerHTML:o.highlightMatch(p.name)},null,8,lg))),128))])):_("",!0)])]),i("td",rg,[i("div",cg,[B(i("textarea",{"onUpdate:modelValue":e[12]||(e[12]=p=>n.newItem.item_description=p),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[13]||(e[13]=p=>o.resize()),ref:"textarea"},null,40,dg),[[J,n.newItem.item_description]])])]),i("td",ug,[i("div",hg,[i("div",mg,[i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[14]||(e[14]=(...p)=>o.decrease&&o.decrease(...p))}," - "),B(i("input",{type:"number",min:"1","onUpdate:modelValue":e[15]||(e[15]=p=>n.newItem.quantity=p),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[16]||(e[16]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,fg),[[J,n.newItem.quantity]]),i("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[17]||(e[17]=(...p)=>o.increase&&o.increase(...p))}," + ")])])]),i("td",pg,[i("div",_g,[B(i("input",{type:"number","onUpdate:modelValue":e[18]||(e[18]=p=>n.newItem.unit_price=p),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[19]||(e[19]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,gg),[[J,n.newItem.unit_price]])])]),n.settings.vat_active==1?(r(),c("td",vg,[B(i("select",{"onUpdate:modelValue":e[20]||(e[20]=p=>n.newItem.vat_rate=p),onChange:e[21]||(e[21]=(...p)=>o.updateTotal&&o.updateTotal(...p)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(r(!0),c(W,null,U(n.list_vats,p=>(r(),c("option",{key:p,value:p.rate},l(p.rate)+"% ",9,yg))),128))],544),[[ve,n.newItem.vat_rate]])])):(r(),c("td",bg)),i("td",wg,[i("div",xg,[B(i("input",{type:"number","onUpdate:modelValue":e[22]||(e[22]=p=>n.newItem.discount=p),min:"0",max:"100",placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40",onInput:e[23]||(e[23]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,Ig),[[J,n.newItem.discount]]),Eg])]),n.settings.vat_active==1?(r(),c("td",Cg,l(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(r(),c("td",kg,l(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),i("td",null,[i("span",{class:"lg:tooltip","data-tip":o.translations.add},[i("button",Ag,[n.loading_add?_("",!0):(r(),c("i",Sg)),n.loading_add?(r(),c("span",Dg)):_("",!0)])],8,Tg)])])):_("",!0),i("tr",null,[i("td",Pg,[i("strong",null,l(o.translations.subtotal),1)]),i("td",Mg,[o.totalAmount!==o.totalAmountWithoutDiscount?(r(),c("span",jg,l(o.totalAmountWithoutDiscount),1)):_("",!0),w(" "+l(o.totalAmount),1)]),qg]),n.settings.vat_active==1?(r(!0),c(W,{key:1},U(o.getUniqueVATRates(),(p,g)=>(r(),c("tr",{key:g},[i("td",Og,[i("strong",null,l(o.translations.tax)+" ("+l(p)+"%) ",1)]),i("td",Vg,l(o.calculateVATForRate(p)),1),Rg]))),128)):_("",!0),i("tr",null,[i("td",Ng,[i("strong",null,l(o.translations.total),1)]),i("td",Bg,l(o.calculateTotalAmountWithVAT()),1),Fg]),n.client_currency!=n.default_currency_symbol?(r(),c("tr",Wg,[i("td",Xg,[i("strong",null,l(o.translations.exchange_rate),1)]),i("td",Ug,l(n.invoice.exchange_rate),1)])):_("",!0),n.client_currency!=n.default_currency_symbol?(r(),c("tr",Qg,[i("td",Lg,[i("strong",null,l(o.translations.total)+" "+l(n.default_currency_symbol),1)]),i("td",zg,l(o.totalAmountDefaultCurrency)+l(n.default_currency_symbol),1)])):_("",!0)])])],32)]),_:1})])}var Gg=oe(qp,[["render",Hg]]);const Yg={name:"InvoiceNew",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],last_invoice_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.invoice_prefix}_${String(this.settings.last_invoice_id).padStart(4,"0")}`;this.invoice.number=s}else{const e=await t.json()}}catch{this.loading=!1}},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/invoices",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting invoice:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Jg={class:"pt-2 pr-4"},Kg={class:"flex justify-between items-center mb-4"},Zg={class:"card-title"},$g=i("div",{class:"divider mt-2"},null,-1),ev={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},tv={class:"grid grid-cols-2 gap-4"},nv={class:"ecwp-group form-group mb-4"},sv={for:"invoiceNumber",class:"ecwp-label"},ov={class:"ecwp-group form-group mb-4"},iv={for:"invoiceDate",class:"ecwp-label"},av={class:"ecwp-group form-group mb-4"},lv={for:"client",class:"ecwp-label"},rv={class:"ecwp-group form-group mb-4"},cv={for:"status",class:"ecwp-label"},dv={value:"draft"},uv={key:0,class:"ecwp-group form-group mb-4"},hv={for:"exchangeRate",class:"ecwp-label"},mv={class:"flex justify-between"},fv=["disabled"],pv={key:0,class:"loading loading-spinner loading-sm"};function _v(t,e,s,a,n,o){const m=j("VueDatePicker"),h=j("model-select"),f=j("Card");return r(),c("div",Jg,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),P(f,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:re(()=>[i("div",Kg,[i("h2",Zg,l(o.translations.new_invoice),1)]),$g,n.loading?(r(),c("div",ev)):_("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...d)=>o.submitInvoice&&o.submitInvoice(...d),["prevent"]))},[i("div",tv,[i("div",nv,[i("label",sv,l(o.translations.invoice_number),1),B(i("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=d=>n.invoice.number=d),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[J,n.invoice.number]])]),i("div",ov,[i("label",iv,l(o.translations.due_date),1),P(m,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=d=>n.invoice.due_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),i("div",av,[i("label",lv,l(o.translations.company_name),1),P(h,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[2]||(e[2]=d=>n.invoice.client_id=d),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",rv,[i("label",cv,l(o.translations.status),1),B(i("select",{id:"status","onUpdate:modelValue":e[3]||(e[3]=d=>n.invoice.status=d),class:k(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[i("option",dv,l(o.translations.draft),1)],2),[[ve,n.invoice.status]])]),o.currencyMismatch?(r(),c("div",uv,[i("label",hv,l(o.translations.exchange_rate),1),B(i("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[4]||(e[4]=d=>n.invoice.exchange_rate=d),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[J,n.invoice.exchange_rate]])])):_("",!0)]),i("div",mv,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...d)=>o.cancelAction&&o.cancelAction(...d))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.submit)+" ",1),n.loadingBtn?(r(),c("span",pv)):_("",!0)],8,fv)])],32)]),_:1})])}var gv=oe(Yg,[["render",_v]]);const vv={name:"invoiceEdit",components:{Card:Ue,ModelSelect:Lt,VueDatePicker:It},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"paid",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getFullYear();return`${e}-${s}-${a}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchInvoiceDetails()},methods:{cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.invoice.client_id&&this.setClientById(this.invoice.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchInvoiceDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?this.invoice=e:(console.error("Error fetching invoice details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching invoice details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.invoice.client=this.clients.find(e=>e.id===t)||null},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting invoice:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},yv={class:"pt-2 pr-4"},bv={class:"flex justify-between items-center mb-4"},wv={class:"card-title"},xv=i("div",{class:"divider mt-2"},null,-1),Iv={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Ev={class:"grid grid-cols-2 gap-4"},Cv={class:"ecwp-group form-group mb-4"},kv={for:"invoiceNumber",class:"ecwp-label"},Tv={class:"ecwp-group form-group mb-4"},Av={for:"invoiceDate",class:"ecwp-label"},Sv={class:"ecwp-group form-group mb-4"},Dv={for:"client",class:"ecwp-label"},Pv={class:"ecwp-group form-group mb-4"},Mv={for:"status",class:"ecwp-label"},jv={value:"draft",selected:""},qv={value:"unpaid"},Ov={value:"paid"},Vv={key:0,class:"ecwp-group form-group mb-4"},Rv={for:"exchangeRate",class:"ecwp-label"},Nv={class:"flex justify-between"},Bv=["disabled"],Fv={key:0,class:"loading loading-spinner loading-sm"};function Wv(t,e,s,a,n,o){const m=j("VueDatePicker"),h=j("model-select"),f=j("Card");return r(),c("div",yv,[n.toast.visible?(r(),c("div",{key:0,class:k(["toast",n.toast.position]),style:{zIndex:9999}},[i("div",{class:k(["alert",n.toast.type,"text-white"])},[i("span",null,l(n.toast.message),1)],2)],2)):_("",!0),P(f,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:re(()=>[i("div",bv,[i("h2",wv,l(o.translations.edit_invoice),1)]),xv,n.loading?(r(),c("div",Iv)):_("",!0),i("form",{onSubmit:e[6]||(e[6]=K((...d)=>o.submitInvoice&&o.submitInvoice(...d),["prevent"]))},[i("div",Ev,[i("div",Cv,[i("label",kv,l(o.translations.invoice_number),1),B(i("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=d=>n.invoice.invoice_number=d),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[J,n.invoice.invoice_number]])]),i("div",Tv,[i("label",Av,l(o.translations.due_date),1),P(m,{class:k(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=d=>n.invoice.due_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),i("div",Sv,[i("label",Dv,l(o.translations.company_name),1),P(h,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[2]||(e[2]=d=>n.invoice.client_id=d),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:k(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),i("div",Pv,[i("label",Mv,l(o.translations.status),1),B(i("select",{id:"status","onUpdate:modelValue":e[3]||(e[3]=d=>n.invoice.status=d),class:k(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[i("option",jv,l(o.translations.draft),1),i("option",qv,l(o.translations.unpaid),1),i("option",Ov,l(o.translations.paid),1)],2),[[ve,n.invoice.status]])]),o.currencyMismatch?(r(),c("div",Vv,[i("label",Rv,l(o.translations.exchange_rate),1),B(i("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[4]||(e[4]=d=>n.invoice.exchange_rate=d),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[J,n.invoice.exchange_rate]])])):_("",!0)]),i("div",Nv,[i("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...d)=>o.cancelAction&&o.cancelAction(...d))},l(o.translations.cancel),1),i("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[w(l(o.translations.save)+" ",1),n.loadingBtn?(r(),c("span",Fv)):_("",!0)],8,Bv)])],32)]),_:1})])}var Xv=oe(vv,[["render",Wv]]);const xe=Qt;(function(t,e){const s=Qt,a=t();for(;[];)try{if(parseInt(s(353))/1+parseInt(s(336))/2*(-parseInt(s(340))/3)+parseInt(s(338))/4*(parseInt(s(342))/5)+parseInt(s(344))/6*(parseInt(s(355))/7)+parseInt(s(348))/8+parseInt(s(341))/9*(-parseInt(s(345))/10)+parseInt(s(350))/11*(-parseInt(s(352))/12)===e)break;a.push(a.shift())}catch{a.push(a.shift())}})(Ut,347969);function Ut(){const t=["441583qMNFVP","InvoiceNew","3377682uCiSVP","Quote","/invoice/detail/:id","InvoiceViewDetail","2amEBit","/quote/detail/:id","4MdSzOn","/quote/edit/:id","895119FtyMfL","162BLVpZn","2831455SaAzsC","QuoteEdit","6dpZVDv","247550HSKaXY","Invoice","QuoteViewDetail","4071216MjUAJK","/invoice/edit/:id","1705IAGfBM","/quotes","70248XdLfXe"];return Ut=function(){return t},Ut()}function Qt(t,e){const s=Ut();return Qt=function(a,n){return a=a-335,s[a]},Qt(t,e)}const Uv=[{path:xe(351),name:xe(356),component:Ma},{path:xe(337),name:xe(347),component:xu},{path:"/quote/new",name:"QuoteNew",component:Yu},{path:xe(339),name:xe(343),component:_s},{path:"/invoices",name:xe(346),component:$h},{path:xe(357),name:xe(335),component:Gg},{path:xe(349),name:"InvoiceEdit",component:Xv},{path:"/invoice/new",name:xe(354),component:gv}],Jv=Xo({history:_o(),routes:Uv});export{Jv as r}; -
my-easy-compta/trunk/includes/Modules/Invoices.php
r3144896 r3155896 752 752 'payment_date' => current_time('mysql'), 753 753 'client_id' => $invoice->client_id, 754 //'payment_method_id' => $method,755 'payment_method_id' => 1,754 'payment_method_id' => $method, 755 //'payment_method_id' => 1, 756 756 ); 757 757 -
my-easy-compta/trunk/includes/Modules/Payments.php
r3142459 r3155896 49 49 }); 50 50 51 $this->routes->add_route('/payments/methods', 'GET', $this, 'get_payment_methods', function () { 52 return current_user_can('manage_options'); 53 }); 54 51 55 $this->routes->add_route('/payments/details/(?P<id>\d+)', 'GET', $this, 'get_payment_details', function () { 52 56 return current_user_can('manage_options'); … … 59 63 return current_user_can('manage_options'); 60 64 }); 65 61 66 $this->routes->register_routes(); 62 67 } … … 214 219 } 215 220 221 public function get_payment_methods($request) { 222 223 $nonce = sanitize_text_field(wp_unslash($request->get_header('X-WP-Nonce'))); 224 if (!wp_verify_nonce($nonce, 'wp_rest')) { 225 return new WP_Error('invalid_nonce', 'Nonce verification failed.', array('status' => 403)); 226 } 227 global $wpdb; 228 $payment_methods = $wpdb->get_results($wpdb->prepare("SELECT * FROM %i", ECWP_TABLE_PAYMENTS_METHODS)); 229 230 return new WP_REST_Response($payment_methods, 200); 231 } 216 232 } -
my-easy-compta/trunk/my-easy-compta.php
r3155882 r3155896 3 3 * Plugin Name: myEasyCompta 4 4 * Description: Streamline your financial management with myEasyCompta, an all-in-one accounting plugin. Effortlessly handle quotes, invoices, expenses, and more, all within a sleek, user-friendly interface. Perfect for freelancers and small businesses looking to simplify their accounting processes. 5 * Version: 1.2. 05 * Version: 1.2.1 6 6 * Author: MELIOZ.dev 7 7 * Author URI: https://myeasycompta.com … … 22 22 * 23 23 * @package myEasyCompta 24 * @since 1.2. 024 * @since 1.2.1 25 25 */ 26 26 … … 37 37 * @var string 38 38 */ 39 public $version = '1.2. 0';39 public $version = '1.2.1'; 40 40 41 41 /** -
my-easy-compta/trunk/readme.txt
r3155882 r3155896 4 4 Tested up to: 6.6.1 5 5 Requires PHP: 8.0 6 Stable tag: 1.2. 06 Stable tag: 1.2.1 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.