Files
crater/public/build/assets/ItemModal.de9c843c.js
2021-12-07 17:28:49 +05:30

2 lines
33 KiB
JavaScript

var we=Object.defineProperty,Be=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var ie=Object.getOwnPropertySymbols;var Pe=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var ce=(e,o,t)=>o in e?we(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,N=(e,o)=>{for(var t in o||(o={}))Pe.call(o,t)&&ce(e,t,o[t]);if(ie)for(var t of ie(o))Se.call(o,t)&&ce(e,t,o[t]);return e},W=(e,o)=>Be(e,Ie(o));import{q as oe,g as Z,d as de,c as Q,p as ue,e as me,T as pe,j as ke,u as Te}from"./main.e180e539.js";import{D as Ce,d as Me}from"./DragIcon.b917feab.js";import{i as G,j as De,am as ne,g as J,k as $,D as ye,r as m,o as r,c as p,t as n,x as f,b as s,a5 as je,y as a,w as i,v as V,s as C,A as E,u as Ve,l as xe,m as U,n as ee,b4 as fe,a4 as te,aZ as qe,q as he,a0 as X,F as H,H as K,G as ge,ac as Le,a6 as Ee,z as Y,T as Oe,a7 as Ne,a8 as Ue,p as Fe,M as Ae,B as ze}from"./vendor.e9042f2c.js";import{_ as We}from"./SelectNotePopup.60a0bf04.js";const Ye={class:"flex items-center justify-between mb-3"},Re={class:"flex items-center text-base",style:{flex:"4"}},Ge={class:"pr-2 mb-0",align:"right"},Xe={class:"absolute left-3.5"},He={class:"ml-2 text-sm leading-none text-primary-400 cursor-pointer"},Ze=n("br",null,null,-1),Je={class:"text-sm text-right",style:{flex:"3"}},Ke={class:"flex items-center justify-center w-6 h-10 mx-2 cursor-pointer"},Qe={props:{ability:{type:String,default:""},store:{type:Object,default:null},storeProp:{type:String,default:""},itemIndex:{type:Number,required:!0},index:{type:Number,required:!0},taxData:{type:Object,required:!0},taxes:{type:Array,default:[]},total:{type:Number,default:0},totalTax:{type:Number,default:0},currency:{type:[Object,String],required:!0},updateItems:{type:Function,default:()=>{}}},emits:["remove","update"],setup(e,{emit:o}){const t=e,y=oe(),_=Z(),v=de(),w=G(null),d=De(N({},t.taxData));ne("utils");const{t:P}=J(),S=$(()=>y.taxTypes.map(g=>N({},g)).map(g=>(t.taxes.find(x=>x.tax_type_id===g.id)?g.disabled=!0:g.disabled=!1,g))),M=$(()=>d.compound_tax&&t.total?(t.total+t.totalTax)*d.percent/100:t.total&&d.percent?t.total*d.percent/100:0);ye(()=>t.total,()=>{k()}),ye(()=>t.totalTax,()=>{k()}),t.taxData.tax_type_id>0&&(w.value=y.taxTypes.find(c=>c.id===t.taxData.tax_type_id)),k();function q(c){d.percent=c.percent,d.tax_type_id=c.id,d.compound_tax=c.compound_tax,d.name=c.name,k()}function k(){d.tax_type_id!==0&&o("update",{index:t.index,item:W(N({},d),{amount:M.value})})}function l(){let c={itemIndex:t.itemIndex,taxIndex:t.index};_.openModal({title:P("settings.tax_types.add_tax"),componentName:"TaxTypeModal",data:c,size:"sm"})}function h(c){t.store.$patch(g=>{g[t.storeProp].items[t.itemIndex].taxes.splice(c,1)})}return(c,g)=>{const T=m("BaseIcon"),x=m("BaseMultiselect"),I=m("BaseFormatMoney");return r(),p("div",Ye,[n("div",Re,[n("label",Ge,f(c.$t("invoices.item.tax")),1),s(x,{modelValue:w.value,"onUpdate:modelValue":[g[0]||(g[0]=B=>w.value=B),g[1]||(g[1]=B=>q(B))],"value-prop":"id",options:a(S),placeholder:c.$t("general.select_a_tax"),"open-direction":"top","track-by":"name",searchable:"",object:"",label:"name"},je({singlelabel:i(({value:B})=>[n("div",Xe,f(B.name)+" - "+f(B.percent)+" % ",1)]),option:i(({option:B})=>[V(f(B.name)+" - "+f(B.percent)+" % ",1)]),_:2},[a(v).hasAbilities(e.ability)?{name:"action",fn:i(()=>[n("button",{type:"button",class:"flex items-center justify-center w-full px-2 cursor-pointer py-2 bg-gray-200 border-none outline-none",onClick:l},[s(T,{name:"CheckCircleIcon",class:"h-5 text-primary-400"}),n("label",He,f(c.$t("invoices.add_new_tax")),1)])])}:void 0]),1032,["modelValue","options","placeholder"]),Ze]),n("div",Je,[s(I,{amount:a(M),currency:e.currency},null,8,["amount","currency"])]),n("div",Ke,[e.taxes.length&&e.index!==e.taxes.length-1?(r(),C(T,{key:0,name:"TrashIcon",class:"h-5 text-gray-700 cursor-pointer",onClick:g[2]||(g[2]=B=>h(e.index))})):E("",!0)])])}}},et={class:"box-border bg-white border border-gray-200 border-solid rounded-b"},tt={colspan:"5",class:"p-0 text-left align-top"},ot={class:"w-full"},nt=n("col",{style:{width:"40%","min-width":"280px"}},null,-1),st=n("col",{style:{width:"10%","min-width":"120px"}},null,-1),at=n("col",{style:{width:"15%","min-width":"120px"}},null,-1),rt={key:0,style:{width:"15%","min-width":"160px"}},lt=n("col",{style:{width:"15%","min-width":"120px"}},null,-1),it={class:"px-5 py-4 text-left align-top"},ct={class:"flex justify-start"},dt={class:"flex items-center justify-center w-5 h-5 mt-2 text-gray-300 cursor-move handle mr-2"},ut={class:"px-5 py-4 text-right align-top"},mt={class:"px-5 py-4 text-left align-top"},pt={class:"flex flex-col"},yt={class:"flex-auto flex-fill bd-highlight"},xt={class:"relative w-full"},ft={key:0,class:"px-5 py-4 text-left align-top"},ht={class:"flex flex-col"},gt={class:"flex",style:{width:"120px"},role:"group"},bt={class:"flex items-center"},_t={class:"px-5 py-4 text-right align-top"},vt={class:"flex items-center justify-end text-sm"},$t={class:"flex items-center justify-center w-6 h-10 mx-2"},wt={key:0},Bt=n("td",{class:"px-5 py-4 text-left align-top"},null,-1),It={colspan:"4",class:"px-5 py-4 text-left align-top"},Pt={props:{store:{type:Object,default:null},storeProp:{type:String,default:""},itemData:{type:Object,default:null},index:{type:Number,default:null},type:{type:String,default:""},loading:{type:Boolean,default:!1},currency:{type:[Object,String],required:!0},invoiceItems:{type:Array,required:!0},itemValidationScope:{type:String,default:""}},emits:["update","remove","itemValidate"],setup(e,{emit:o}){const t=e,y=Q(),_=ue();Ve();const{t:v}=J(),w=$({get:()=>t.itemData.quantity,set:u=>{j("quantity",parseFloat(u))}}),d=$({get:()=>{const u=t.itemData.price;return parseFloat(u)>0?u/100:u},set:u=>{if(parseFloat(u)>0){let b=Math.round(u*100);j("price",b)}else j("price",u)}}),P=$(()=>t.itemData.price*t.itemData.quantity),S=$({get:()=>t.itemData.discount,set:u=>{t.itemData.discount_type==="percentage"?j("discount_val",P.value*u/100):j("discount_val",Math.round(u*100)),j("discount",u)}}),M=$(()=>P.value-t.itemData.discount_val),q=$(()=>t.currency?t.currency:y.selectedCompanyCurrency),k=$(()=>t.store[t.storeProp].items.length!=1),l=$(()=>Math.round(xe.exports.sumBy(t.itemData.taxes,function(u){return u.compound_tax?0:u.amount}))),h=$(()=>Math.round(xe.exports.sumBy(t.itemData.taxes,function(u){return u.compound_tax?u.amount:0}))),c=$(()=>l.value+h.value),g={name:{required:U.withMessage(v("validation.required"),ee)},quantity:{required:U.withMessage(v("validation.required"),ee),minValue:U.withMessage(v("validation.qty_must_greater_than_zero"),fe(1)),maxLength:U.withMessage(v("validation.amount_maxlength"),te(20))},price:{required:U.withMessage(v("validation.required"),ee),minValue:U.withMessage(v("validation.number_length_minvalue"),fe(1)),maxLength:U.withMessage(v("validation.price_maxlength"),te(20))},discount_val:{between:U.withMessage(v("validation.discount_maxlength"),qe(0,$(()=>P.value)))},description:{maxLength:U.withMessage(v("validation.notes_maxlength"),te(65e3))}},T=he(g,$(()=>t.store[t.storeProp].items[t.index]),{$scope:t.itemValidationScope});function x(u){t.store.$patch(L=>{L[t.storeProp].items[t.index].taxes[u.index]=u.item});let b=t.itemData.taxes[t.itemData.taxes.length-1];(b==null?void 0:b.tax_type_id)!==0&&t.store.$patch(L=>{L[t.storeProp].items[t.index].taxes.push(W(N({},pe),{id:ge.raw()}))}),D()}function I(u){j("name",u)}function B(u){t.store.$patch(b=>{if(b[t.storeProp].items[t.index].name=u.name,b[t.storeProp].items[t.index].price=u.price,b[t.storeProp].items[t.index].item_id=u.id,b[t.storeProp].items[t.index].description=u.description,u.unit&&(b[t.storeProp].items[t.index].unit_name=u.unit.name),t.store[t.storeProp].tax_per_item==="YES"&&u.taxes){let L=0;u.taxes.forEach(z=>{x({index:L,item:N({},z)}),L++})}b[t.storeProp].exchange_rate&&(b[t.storeProp].items[t.index].price/=b[t.storeProp].exchange_rate)}),_.fetchItems(),D()}function R(){t.itemData.discount_type!=="fixed"&&(j("discount_val",Math.round(t.itemData.discount*100)),j("discount_type","fixed"))}function A(){t.itemData.discount_type!=="percentage"&&(j("discount_val",P.value*t.itemData.discount/100),j("discount_type","percentage"))}function D(){var L,z;let u=(z=(L=t.store[t.storeProp])==null?void 0:L.items[t.index])==null?void 0:z.taxes;u||(u=[]);let b=W(N({},t.store[t.storeProp].items[t.index]),{index:t.index,total:M.value,sub_total:P.value,totalSimpleTax:l.value,totalCompoundTax:h.value,totalTax:c.value,tax:c.value,taxes:[...u]});t.store.updateItem(b)}function j(u,b){t.store.$patch(L=>{L[t.storeProp].items[t.index][u]=b}),D()}return(u,b)=>{const L=m("BaseItemSelect"),z=m("BaseInput"),O=m("BaseMoney"),se=m("BaseIcon"),be=m("BaseButton"),ae=m("BaseDropdownItem"),_e=m("BaseDropdown"),re=m("BaseContentPlaceholdersText"),le=m("BaseContentPlaceholders"),ve=m("BaseFormatMoney");return r(),p("tr",et,[n("td",tt,[n("table",ot,[n("colgroup",null,[nt,st,at,e.store[e.storeProp].discount_per_item==="YES"?(r(),p("col",rt)):E("",!0),lt]),n("tbody",null,[n("tr",null,[n("td",it,[n("div",ct,[n("div",dt,[s(Ce)]),s(L,{type:"Invoice",item:e.itemData,invalid:a(T).name.$error,"invalid-description":a(T).description.$error,taxes:e.itemData.taxes,index:e.index,"store-prop":e.storeProp,store:e.store,onSearch:I,onSelect:B},null,8,["item","invalid","invalid-description","taxes","index","store-prop","store"])])]),n("td",ut,[s(z,{modelValue:a(w),"onUpdate:modelValue":b[0]||(b[0]=F=>X(w)?w.value=F:null),invalid:a(T).quantity.$error,"content-loading":e.loading,type:"number",small:"",min:"1",step:"any",onChange:b[1]||(b[1]=F=>D()),onInput:b[2]||(b[2]=F=>a(T).quantity.$touch())},null,8,["modelValue","invalid","content-loading"])]),n("td",mt,[n("div",pt,[n("div",yt,[n("div",xt,[s(O,{key:a(q),modelValue:a(d),"onUpdate:modelValue":b[3]||(b[3]=F=>X(d)?d.value=F:null),invalid:a(T).price.$error,"content-loading":e.loading,currency:a(q)},null,8,["modelValue","invalid","content-loading","currency"])])])])]),e.store[e.storeProp].discount_per_item==="YES"?(r(),p("td",ft,[n("div",ht,[n("div",gt,[s(z,{modelValue:a(S),"onUpdate:modelValue":b[4]||(b[4]=F=>X(S)?S.value=F:null),invalid:a(T).discount_val.$error,"content-loading":e.loading,class:"border-r-0 focus:border-r-2 rounded-tr-sm rounded-br-sm h-[38px]"},null,8,["modelValue","invalid","content-loading"]),s(_e,{position:"bottom-end"},{activator:i(()=>[s(be,{"content-loading":e.loading,class:"rounded-tr-md rounded-br-md !p-2 rounded-none",type:"button",variant:"white"},{default:i(()=>[n("span",bt,[V(f(e.itemData.discount_type=="fixed"?e.currency.symbol:"%")+" ",1),s(se,{name:"ChevronDownIcon",class:"w-4 h-4 text-gray-500 ml-1"})])]),_:1},8,["content-loading"])]),default:i(()=>[s(ae,{onClick:R},{default:i(()=>[V(f(u.$t("general.fixed")),1)]),_:1}),s(ae,{onClick:A},{default:i(()=>[V(f(u.$t("general.percentage")),1)]),_:1})]),_:1})])])])):E("",!0),n("td",_t,[n("div",vt,[n("span",null,[e.loading?(r(),C(le,{key:0},{default:i(()=>[s(re,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),C(ve,{key:1,amount:a(M),currency:a(q)},null,8,["amount","currency"]))]),n("div",$t,[a(k)?(r(),C(se,{key:0,class:"h-5 text-gray-700 cursor-pointer",name:"TrashIcon",onClick:b[5]||(b[5]=F=>e.store.removeItem(e.index))})):E("",!0)])])])]),e.store[e.storeProp].tax_per_item==="YES"?(r(),p("tr",wt,[Bt,n("td",It,[e.loading?(r(),C(le,{key:0},{default:i(()=>[s(re,{lines:1,class:"w-24 h-8 rounded-md border"})]),_:1})):(r(!0),p(H,{key:1},K(e.itemData.taxes,(F,$e)=>(r(),C(Qe,{key:F.id,index:$e,"item-index":e.index,"tax-data":F,taxes:e.itemData.taxes,"discounted-total":a(M),"total-tax":a(l),total:a(P),currency:e.currency,"update-items":D,ability:a(me).CREATE_INVOICE,store:e.store,"store-prop":e.storeProp,onUpdate:x},null,8,["index","item-index","tax-data","taxes","discounted-total","total-tax","total","currency","ability","store","store-prop"]))),128))])])):E("",!0)])])])])}}},St={class:"text-center item-table min-w-full"},kt=n("col",{style:{width:"40%","min-width":"280px"}},null,-1),Tt=n("col",{style:{width:"10%","min-width":"120px"}},null,-1),Ct=n("col",{style:{width:"15%","min-width":"120px"}},null,-1),Mt={key:0,style:{width:"15%","min-width":"160px"}},Dt=n("col",{style:{width:"15%","min-width":"120px"}},null,-1),jt={class:"bg-white border border-gray-200 border-solid"},Vt={class:"px-5 py-3 text-sm not-italic font-medium leading-5 text-left text-gray-700 border-t border-b border-gray-200 border-solid"},qt={key:1,class:"pl-7"},Lt={class:"px-5 py-3 text-sm not-italic font-medium leading-5 text-right text-gray-700 border-t border-b border-gray-200 border-solid"},Et={key:1},Ot={class:"px-5 py-3 text-sm not-italic font-medium leading-5 text-left text-gray-700 border-t border-b border-gray-200 border-solid"},Nt={key:1},Ut={key:0,class:"px-5 py-3 text-sm not-italic font-medium leading-5 text-left text-gray-700 border-t border-b border-gray-200 border-solid"},Ft={key:1},At={class:"px-5 py-3 text-sm not-italic font-medium leading-5 text-right text-gray-700 border-t border-b border-gray-200 border-solid"},zt={key:1,class:"pr-10 column-heading"},Yo={props:{store:{type:Object,default:null},storeProp:{type:String,default:""},currency:{type:[Object,String,null],required:!0},isLoading:{type:Boolean,default:!1},itemValidationScope:{type:String,default:""}},setup(e){const o=e,t=Q(),y=$(()=>o.currency?o.currency:t.selectedCompanyCurrency);return(_,v)=>{const w=m("BaseContentPlaceholdersText"),d=m("BaseContentPlaceholders"),P=m("BaseIcon");return r(),p(H,null,[n("table",St,[n("colgroup",null,[kt,Tt,Ct,e.store[e.storeProp].discount_per_item==="YES"?(r(),p("col",Mt)):E("",!0),Dt]),n("thead",jt,[n("tr",null,[n("th",Vt,[e.isLoading?(r(),C(d,{key:0},{default:i(()=>[s(w,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("span",qt,f(_.$tc("items.item",2)),1))]),n("th",Lt,[e.isLoading?(r(),C(d,{key:0},{default:i(()=>[s(w,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("span",Et,f(_.$t("invoices.item.quantity")),1))]),n("th",Ot,[e.isLoading?(r(),C(d,{key:0},{default:i(()=>[s(w,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("span",Nt,f(_.$t("invoices.item.price")),1))]),e.store[e.storeProp].discount_per_item==="YES"?(r(),p("th",Ut,[e.isLoading?(r(),C(d,{key:0},{default:i(()=>[s(w,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("span",Ft,f(_.$t("invoices.item.discount")),1))])):E("",!0),n("th",At,[e.isLoading?(r(),C(d,{key:0},{default:i(()=>[s(w,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("span",zt,f(_.$t("invoices.item.amount")),1))])])]),s(a(Me),{modelValue:e.store[e.storeProp].items,"onUpdate:modelValue":v[0]||(v[0]=S=>e.store[e.storeProp].items=S),"item-key":"id",tag:"tbody",handle:".handle"},{item:i(({element:S,index:M})=>[s(Pt,{key:S.id,index:M,"item-data":S,loading:e.isLoading,currency:a(y),"item-validation-scope":e.itemValidationScope,"invoice-items":e.store[e.storeProp].items,store:e.store,"store-prop":e.storeProp},null,8,["index","item-data","loading","currency","item-validation-scope","invoice-items","store","store-prop"])]),_:1},8,["modelValue"])]),n("div",{class:"flex items-center justify-center w-full px-6 py-3 text-base border border-t-0 border-gray-200 border-solid cursor-pointer text-primary-400 hover:bg-primary-100",onClick:v[1]||(v[1]=(...S)=>e.store.addItem&&e.store.addItem(...S))},[s(P,{name:"PlusCircleIcon",class:"mr-2"}),V(" "+f(_.$t("general.add_new_item")),1)])],64)}}},Wt={class:"flex items-center justify-between w-full mt-2 text-sm"},Yt={class:"font-semibold leading-5 text-gray-500 uppercase"},Rt={class:"flex items-center justify-center text-lg text-black"},Gt={props:{index:{type:Number,required:!0},tax:{type:Object,required:!0},taxes:{type:Array,required:!0},currency:{type:[Object,String],required:!0},store:{type:Object,default:null},data:{type:String,default:""}},emits:["update","remove"],setup(e,{emit:o}){const t=e;ne("$utils");const y=$(()=>t.tax.compound_tax&&t.store.getSubtotalWithDiscount?Math.round((t.store.getSubtotalWithDiscount+t.store.getTotalSimpleTax)*t.tax.percent/100):t.store.getSubtotalWithDiscount&&t.tax.percent?Math.round(t.store.getSubtotalWithDiscount*t.tax.percent/100):0);Le(()=>{t.store.getSubtotalWithDiscount&&_(),t.store.getTotalSimpleTax&&_()});function _(){o("update",W(N({},t.tax),{amount:y.value}))}return(v,w)=>{const d=m("BaseFormatMoney"),P=m("BaseIcon");return r(),p("div",Wt,[n("label",Yt,f(e.tax.name)+" ("+f(e.tax.percent)+" %) ",1),n("label",Rt,[s(d,{amount:e.tax.amount,currency:e.currency},null,8,["amount","currency"]),s(P,{name:"TrashIcon",class:"h-5 ml-2 cursor-pointer",onClick:w[0]||(w[0]=S=>v.$emit("remove",e.tax.id))})])])}}},Xt={class:"w-full mt-4 tax-select"},Ht={class:"relative w-full max-w-md px-4"},Zt={class:"overflow-hidden rounded-md shadow-lg ring-1 ring-black ring-opacity-5"},Jt={class:"relative bg-white"},Kt={class:"relative p-4"},Qt={key:0,class:"relative flex flex-col overflow-auto list max-h-36 border-t border-gray-200"},eo=["onClick"],to={class:"flex justify-between px-2"},oo={class:"m-0 text-base font-semibold leading-tight text-gray-700 cursor-pointer"},no={class:"m-0 text-base font-semibold text-gray-700 cursor-pointer"},so={key:1,class:"flex justify-center p-5 text-gray-400"},ao={class:"text-base text-gray-500 cursor-pointer"},ro={class:"m-0 ml-3 text-sm leading-none cursor-pointer font-base text-primary-400"},lo={props:{type:{type:String,default:null},store:{type:Object,default:null},storeProp:{type:String,default:""}},emits:["select:taxType"],setup(e,{emit:o}){const t=e,y=Z(),_=oe(),v=de(),{t:w}=J(),d=G(null),P=$(()=>d.value?_.taxTypes.filter(function(k){return k.name.toLowerCase().indexOf(d.value.toLowerCase())!==-1}):_.taxTypes),S=$(()=>t.store[t.storeProp].taxes);function M(k,l){o("select:taxType",N({},k)),l()}function q(){y.openModal({title:w("settings.tax_types.add_tax"),componentName:"TaxTypeModal",size:"sm",refreshData:k=>o("select:taxType",k)})}return(k,l)=>{const h=m("BaseIcon"),c=m("BaseInput");return r(),p("div",Xt,[s(a(Ue),{class:"relative"},{default:i(({isOpen:g})=>[s(a(Ee),{class:Y([g?"":"text-opacity-90","flex items-center text-sm font-medium text-primary-400 focus:outline-none focus:border-none"])},{default:i(()=>[s(h,{name:"PlusIcon",class:"w-4 h-4 font-medium text-primary-400"}),V(" "+f(k.$t("settings.tax_types.add_tax")),1)]),_:2},1032,["class"]),n("div",Ht,[s(Oe,{"enter-active-class":"transition duration-200 ease-out","enter-from-class":"translate-y-1 opacity-0","enter-to-class":"translate-y-0 opacity-100","leave-active-class":"transition duration-150 ease-in","leave-from-class":"translate-y-0 opacity-100","leave-to-class":"translate-y-1 opacity-0"},{default:i(()=>[s(a(Ne),{style:{"min-width":"350px","margin-left":"62px",top:"-28px"},class:"absolute z-10 px-4 py-2 transform -translate-x-full sm:px-0"},{default:i(({close:T})=>[n("div",Zt,[n("div",Jt,[n("div",Kt,[s(c,{modelValue:d.value,"onUpdate:modelValue":l[0]||(l[0]=x=>d.value=x),placeholder:k.$t("general.search"),type:"text",class:"text-black"},null,8,["modelValue","placeholder"])]),a(P).length>0?(r(),p("div",Qt,[(r(!0),p(H,null,K(a(P),(x,I)=>(r(),p("div",{key:I,class:Y([{"bg-gray-100 cursor-not-allowed opacity-50 pointer-events-none":a(S).find(B=>B.tax_type_id===x.id)},"px-6 py-4 border-b border-gray-200 border-solid cursor-pointer hover:bg-gray-100 hover:cursor-pointer last:border-b-0"]),tabindex:"2",onClick:B=>M(x,T)},[n("div",to,[n("label",oo,f(x.name),1),n("label",no,f(x.percent)+" % ",1)])],10,eo))),128))])):(r(),p("div",so,[n("label",ao,f(k.$t("general.no_tax_found")),1)]))]),a(v).hasAbilities(a(me).CREATE_TAX_TYPE)?(r(),p("button",{key:0,type:"button",class:"flex items-center justify-center w-full h-10 px-2 py-3 bg-gray-200 border-none outline-none",onClick:q},[s(h,{name:"CheckCircleIcon",class:"text-primary-400"}),n("label",ro,f(k.$t("estimates.add_new_tax")),1)])):E("",!0)])]),_:1})]),_:1})])]),_:1})])}}},io={class:"px-5 py-4 mt-6 bg-white border border-gray-200 border-solid rounded md:min-w-[390px] min-w-[300px] lg:mt-7"},co={class:"flex items-center justify-between w-full"},uo={key:1,class:"text-sm font-semibold leading-5 text-gray-400 uppercase"},mo={key:3,class:"flex items-center justify-center m-0 text-lg text-black uppercase"},po={key:1,class:"m-0 text-sm font-semibold leading-5 text-gray-500 uppercase"},yo={key:3,class:"flex items-center justify-center m-0 text-lg text-black uppercase"},xo={key:0,class:"flex items-center justify-between w-full mt-2"},fo={key:1,class:"text-sm font-semibold leading-5 text-gray-400 uppercase"},ho={key:3,class:"flex",style:{width:"140px"},role:"group"},go={class:"flex items-center"},bo={key:1},_o={class:"flex items-center justify-between w-full pt-2 mt-5 border-t border-gray-200 border-solid"},vo={key:1,class:"m-0 text-sm font-semibold leading-5 text-gray-400 uppercase"},$o={key:3,class:"flex items-center justify-center text-lg uppercase text-primary-400"},Ro={props:{store:{type:Object,default:null},storeProp:{type:String,default:""},taxPopupType:{type:String,default:""},currency:{type:[Object,String],default:""},isLoading:{type:Boolean,default:!1}},setup(e){const o=e,t=G(null);ne("$utils");const y=Q(),_=$({get:()=>o.store[o.storeProp].discount,set:l=>{o.store[o.storeProp].discount_type==="percentage"?o.store[o.storeProp].discount_val=Math.round(o.store.getSubTotal*l/100):o.store[o.storeProp].discount_val=Math.round(l*100),o.store[o.storeProp].discount=l}}),v=$({get:()=>o.store[o.storeProp].taxes,set:l=>{o.store.$patch(h=>{h[o.storeProp].taxes=l})}}),w=$(()=>{let l=[];return o.store[o.storeProp].items.forEach(h=>{h.taxes&&h.taxes.forEach(c=>{let g=l.find(T=>T.tax_type_id===c.tax_type_id);g?g.amount+=c.amount:c.tax_type_id&&l.push({tax_type_id:c.tax_type_id,amount:c.amount,percent:c.percent,name:c.name})})}),l}),d=$(()=>o.currency?o.currency:y.selectedCompanyCurrency);function P(){o.store[o.storeProp].discount_type!=="fixed"&&(o.store[o.storeProp].discount_val=Math.round(o.store[o.storeProp].discount*100),o.store[o.storeProp].discount_type="fixed")}function S(){o.store[o.storeProp].discount_type!=="percentage"&&(o.store[o.storeProp].discount_val=o.store.getSubTotal*o.store[o.storeProp].discount/100,o.store[o.storeProp].discount_type="percentage")}function M(l){let h=0;l.compound_tax&&o.store.getSubtotalWithDiscount?h=Math.round((o.store.getSubtotalWithDiscount+o.store.getTotalSimpleTax)*l.percent/100):o.store.getSubtotalWithDiscount&&l.percent&&(h=Math.round(o.store.getSubtotalWithDiscount*l.percent/100));let c=W(N({},pe),{id:ge.raw(),name:l.name,percent:l.percent,compound_tax:l.compound_tax,tax_type_id:l.id,amount:h});o.store.$patch(g=>{g[o.storeProp].taxes.push(N({},c))})}function q(l){const h=o.store[o.storeProp].taxes.find(c=>c.id===l.id);h&&Object.assign(h,N({},l))}function k(l){const h=o.store[o.storeProp].taxes.findIndex(c=>c.id===l);o.store.$patch(c=>{c[o.storeProp].taxes.splice(h,1)})}return(l,h)=>{const c=m("BaseContentPlaceholdersText"),g=m("BaseContentPlaceholders"),T=m("BaseFormatMoney"),x=m("BaseInput"),I=m("BaseIcon"),B=m("BaseButton"),R=m("BaseDropdownItem"),A=m("BaseDropdown");return r(),p("div",io,[n("div",co,[e.isLoading?(r(),C(g,{key:0},{default:i(()=>[s(c,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("label",uo,f(l.$t("estimates.sub_total")),1)),e.isLoading?(r(),C(g,{key:2},{default:i(()=>[s(c,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("label",mo,[s(T,{amount:e.store.getSubTotal,currency:a(d)},null,8,["amount","currency"])]))]),(r(!0),p(H,null,K(a(w),D=>(r(),p("div",{key:D.tax_type_id,class:"flex items-center justify-between w-full"},[e.isLoading?(r(),C(g,{key:0},{default:i(()=>[s(c,{lines:1,class:"w-16 h-5"})]),_:1})):e.store[e.storeProp].tax_per_item==="YES"?(r(),p("label",po,f(D.name)+" - "+f(D.percent)+"% ",1)):E("",!0),e.isLoading?(r(),C(g,{key:2},{default:i(()=>[s(c,{lines:1,class:"w-16 h-5"})]),_:1})):e.store[e.storeProp].tax_per_item==="YES"?(r(),p("label",yo,[s(T,{amount:D.amount,currency:a(d)},null,8,["amount","currency"])])):E("",!0)]))),128)),e.store[e.storeProp].discount_per_item==="NO"||e.store[e.storeProp].discount_per_item===null?(r(),p("div",xo,[e.isLoading?(r(),C(g,{key:0},{default:i(()=>[s(c,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("label",fo,f(l.$t("estimates.discount")),1)),e.isLoading?(r(),C(g,{key:2},{default:i(()=>[s(c,{lines:1,class:"w-24 h-8 rounded-md border"})]),_:1})):(r(),p("div",ho,[s(x,{modelValue:a(_),"onUpdate:modelValue":h[0]||(h[0]=D=>X(_)?_.value=D:null),class:"border-r-0 focus:border-r-2 rounded-tr-sm rounded-br-sm h-[38px]"},null,8,["modelValue"]),s(A,{position:"bottom-end"},{activator:i(()=>[s(B,{class:"rounded-tr-md rounded-br-md p-2 rounded-none",type:"button",variant:"white"},{default:i(()=>[n("span",go,[V(f(e.store[e.storeProp].discount_type=="fixed"?a(d).symbol:"%")+" ",1),s(I,{name:"ChevronDownIcon",class:"w-4 h-4 text-gray-500 ml-1"})])]),_:1})]),default:i(()=>[s(R,{onClick:P},{default:i(()=>[V(f(l.$t("general.fixed")),1)]),_:1}),s(R,{onClick:S},{default:i(()=>[V(f(l.$t("general.percentage")),1)]),_:1})]),_:1})]))])):E("",!0),e.store[e.storeProp].tax_per_item==="NO"||e.store[e.storeProp].tax_per_item===null?(r(),p("div",bo,[(r(!0),p(H,null,K(a(v),(D,j)=>(r(),C(Gt,{key:D.id,index:j,tax:D,taxes:a(v),currency:e.currency,store:e.store,onRemove:k,onUpdate:q},null,8,["index","tax","taxes","currency","store"]))),128))])):E("",!0),e.store[e.storeProp].tax_per_item==="NO"||e.store[e.storeProp].tax_per_item===null?(r(),p("div",{key:2,ref:(D,j)=>{j.taxModal=D,t.value=D},class:"float-right pt-2 pb-4"},[s(lo,{"store-prop":e.storeProp,store:e.store,type:e.taxPopupType,"onSelect:taxType":M},null,8,["store-prop","store","type"])],512)):E("",!0),n("div",_o,[e.isLoading?(r(),C(g,{key:0},{default:i(()=>[s(c,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("label",vo,f(l.$t("estimates.total"))+" "+f(l.$t("estimates.amount"))+":",1)),e.isLoading?(r(),C(g,{key:2},{default:i(()=>[s(c,{lines:1,class:"w-16 h-5"})]),_:1})):(r(),p("label",$o,[s(T,{amount:e.store.getTotal,currency:a(d)},null,8,["amount","currency"])]))])])}}},wo={class:"flex text-primary-800 font-medium text-sm mb-2"},Bo=n("span",{class:"text-sm text-red-500"}," *",-1),Go={props:{store:{type:Object,default:null},storeProp:{type:String,default:""}},setup(e){const o=e,t=Z(),{t:y}=J();function _(){t.openModal({title:y("general.choose_template"),componentName:"SelectTemplate",data:{templates:o.store.templates,store:o.store,storeProp:o.storeProp}})}return(v,w)=>{const d=m("BaseIcon"),P=m("BaseButton");return r(),p("div",null,[n("label",wo,[V(f(v.$t("general.select_template"))+" ",1),Bo]),s(P,{type:"button",class:"flex justify-center w-full text-sm lg:w-auto hover:bg-gray-200",variant:"gray",onClick:_},{right:i(S=>[s(d,{name:"PencilIcon",class:Y(S.class)},null,8,["class"])]),default:i(()=>[V(" "+f(e.store[e.storeProp].template_name),1)]),_:1})])}}},Io={class:"mb-6"},Po={class:"z-20 text-sm font-semibold leading-5 text-primary-400 float-right"},So={class:"text-primary-800 font-medium mb-4 text-sm"},Xo={props:{store:{type:Object,default:null},storeProp:{type:String,default:""},fields:{type:Object,default:null},type:{type:String,default:null}},setup(e){const o=e;function t(y){o.store[o.storeProp].notes=""+y.notes}return(y,_)=>{const v=m("BaseCustomInput");return r(),p("div",Io,[n("div",Po,[s(We,{type:e.type,onSelect:t},null,8,["type"])]),n("label",So,f(y.$t("invoices.notes")),1),s(v,{modelValue:e.store[e.storeProp].notes,"onUpdate:modelValue":_[0]||(_[0]=w=>e.store[e.storeProp].notes=w),"content-loading":e.store.isFetchingInitialSettings,fields:e.fields,class:"mt-1"},null,8,["modelValue","content-loading","fields"])])}}};var ko="/build/img/tick.png";const To={class:"flex justify-between w-full"},Co={class:"px-8 py-8 sm:p-6"},Mo={key:0,class:"grid grid-cols-3 gap-2 p-1 overflow-x-auto"},Do=["src","alt","onClick"],jo=["alt"],Vo={class:"z-0 flex justify-end p-4 border-t border-gray-200 border-solid"},Ho={setup(e){const o=Z(),t=G(""),y=$(()=>o.active&&o.componentName==="SelectTemplate"),_=$(()=>o.title);function v(){o.data.store[o.data.storeProp].template_name?t.value=o.data.store[o.data.storeProp].template_name:t.value=o.data.templates[0]}async function w(){await o.data.store.setTemplate(t.value),d()}function d(){o.closeModal(),setTimeout(()=>{o.$reset()},300)}return(P,S)=>{const M=m("BaseIcon"),q=m("BaseButton"),k=m("BaseModal");return r(),C(k,{show:a(y),onClose:d,onOpen:v},{header:i(()=>[n("div",To,[V(f(a(_))+" ",1),s(M,{name:"XIcon",class:"h-6 w-6 text-gray-500 cursor-pointer",onClick:d})])]),default:i(()=>[n("div",Co,[a(o).data?(r(),p("div",Mo,[(r(!0),p(H,null,K(a(o).data.templates,(l,h)=>(r(),p("div",{key:h,class:Y([{"border border-solid border-primary-500":t.value===l.name},"relative flex flex-col m-2 border border-gray-200 border-solid cursor-pointer hover:border-primary-300"])},[n("img",{src:l.path,alt:l.name,class:"w-full",onClick:c=>t.value=l.name},null,8,Do),t.value===l.name?(r(),p("img",{key:0,alt:l.name,class:"absolute z-10 w-5 h-5 text-primary-500",style:{top:"-6px",right:"-5px"},src:ko},null,8,jo)):E("",!0),n("span",{class:Y(["w-full p-1 bg-gray-200 text-sm text-center absolute bottom-0 left-0",{"text-primary-500 bg-primary-100":t.value===l.name,"text-gray-600":t.value!=l.name}])},f(l.name),3)],2))),128))])):E("",!0)]),n("div",Vo,[s(q,{class:"mr-3",variant:"primary-outline",onClick:d},{default:i(()=>[V(f(P.$t("general.cancel")),1)]),_:1}),s(q,{variant:"primary",onClick:S[0]||(S[0]=l=>w())},{left:i(l=>[s(M,{name:"SaveIcon",class:Y(l.class)},null,8,["class"])]),default:i(()=>[V(" "+f(P.$t("general.choose")),1)]),_:1})])]),_:1},8,["show"])}}},qo={class:"flex justify-between w-full"},Lo={class:"item-modal"},Eo=["onSubmit"],Oo={class:"px-8 py-8 sm:p-6"},No={class:"z-0 flex justify-end p-4 border-t border-gray-200 border-solid"},Zo={emits:["newItem"],setup(e,{emit:o}){const t=Z(),y=ue(),_=Q(),v=oe();ke(),Te();const{t:w}=J(),d=G(!1),P=G(_.selectedCompanySettings.tax_per_item),S=$(()=>t.active&&t.componentName==="ItemModal"),M=$({get:()=>y.currentItem.price/100,set:x=>{y.currentItem.price=Math.round(x*100)}}),q=$({get:()=>y.currentItem.taxes.map(x=>{if(x)return W(N({},x),{tax_type_id:x.id,tax_name:x.name+" ("+x.percent+"%)"})}),set:x=>{y.$patch(I=>{I.currentItem.taxes=x})}}),k=$(()=>P.value==="YES"),l={name:{required:U.withMessage(w("validation.required"),ee),minLength:U.withMessage(w("validation.name_min_length",{count:3}),Fe(3))},description:{maxLength:U.withMessage(w("validation.description_maxlength",{count:255}),te(255))}},h=he(l,$(()=>y.currentItem)),c=$(()=>v.taxTypes.map(x=>W(N({},x),{tax_name:x.name+" ("+x.percent+"%)"})));Ae(()=>{h.value.$reset(),y.fetchItemUnits({limit:"all"})});async function g(){if(h.value.$touch(),h.value.$invalid)return!0;let x=W(N({},y.currentItem),{taxes:y.currentItem.taxes.map(B=>({tax_type_id:B.id,amount:M.value*B.percent/100,percent:B.percent,name:B.name,collective_tax:0}))});d.value=!0,await(y.isEdit?y.updateItem:y.addItem)(x).then(B=>{d.value=!1,B.data.data&&t.data&&t.refreshData(B.data.data),T()})}function T(){t.closeModal(),setTimeout(()=>{y.resetCurrentItem(),t.$reset(),h.value.$reset()},300)}return(x,I)=>{const B=m("BaseIcon"),R=m("BaseInput"),A=m("BaseInputGroup"),D=m("BaseMoney"),j=m("BaseMultiselect"),u=m("BaseTextarea"),b=m("BaseInputGrid"),L=m("BaseButton"),z=m("BaseModal");return r(),C(z,{show:a(S),onClose:T},{header:i(()=>[n("div",qo,[V(f(a(t).title)+" ",1),s(B,{name:"XIcon",class:"h-6 w-6 text-gray-500 cursor-pointer",onClick:T})])]),default:i(()=>[n("div",Lo,[n("form",{action:"",onSubmit:ze(g,["prevent"])},[n("div",Oo,[s(b,{layout:"one-column"},{default:i(()=>[s(A,{label:x.$t("items.name"),required:"",error:a(h).name.$error&&a(h).name.$errors[0].$message},{default:i(()=>[s(R,{modelValue:a(y).currentItem.name,"onUpdate:modelValue":I[0]||(I[0]=O=>a(y).currentItem.name=O),type:"text",invalid:a(h).name.$error,onInput:I[1]||(I[1]=O=>a(h).name.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"]),s(A,{label:x.$t("items.price")},{default:i(()=>[s(D,{key:a(_).selectedCompanyCurrency,modelValue:a(M),"onUpdate:modelValue":I[2]||(I[2]=O=>X(M)?M.value=O:null),currency:a(_).selectedCompanyCurrency,class:"relative w-full focus:border focus:border-solid focus:border-primary"},null,8,["modelValue","currency"])]),_:1},8,["label"]),s(A,{label:x.$t("items.unit")},{default:i(()=>[s(j,{modelValue:a(y).currentItem.unit_id,"onUpdate:modelValue":I[3]||(I[3]=O=>a(y).currentItem.unit_id=O),label:"name",options:a(y).itemUnits,"value-prop":"id","can-deselect":!1,"can-clear":!1,placeholder:x.$t("items.select_a_unit"),searchable:"","track-by":"id"},null,8,["modelValue","options","placeholder"])]),_:1},8,["label"]),a(k)?(r(),C(A,{key:0,label:x.$t("items.taxes")},{default:i(()=>[s(j,{modelValue:a(q),"onUpdate:modelValue":I[4]||(I[4]=O=>X(q)?q.value=O:null),options:a(c),label:"name","value-prop":"id",class:"w-full","can-deselect":!1,"can-clear":!1,searchable:"","track-by":"id",object:""},null,8,["modelValue","options"])]),_:1},8,["label"])):E("",!0),s(A,{label:x.$t("items.description"),error:a(h).description.$error&&a(h).description.$errors[0].$message},{default:i(()=>[s(u,{modelValue:a(y).currentItem.description,"onUpdate:modelValue":I[5]||(I[5]=O=>a(y).currentItem.description=O),rows:"4",cols:"50",invalid:a(h).description.$error,onInput:I[6]||(I[6]=O=>a(h).description.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"])]),_:1})]),n("div",No,[s(L,{class:"mr-3",variant:"primary-outline",type:"button",onClick:T},{default:i(()=>[V(f(x.$t("general.cancel")),1)]),_:1}),s(L,{loading:d.value,disabled:d.value,variant:"primary",type:"submit"},{left:i(O=>[s(B,{name:"SaveIcon",class:Y(O.class)},null,8,["class"])]),default:i(()=>[V(" "+f(a(y).isEdit?x.$t("general.update"):x.$t("general.save")),1)]),_:1},8,["loading","disabled"])])],40,Eo)])]),_:1},8,["show"])}}};export{Ho as _,Zo as a,Yo as b,Xo as c,Go as d,Ro as e};