var H=Object.defineProperty,J=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var a=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var A=(t,e,o)=>e in t?H(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,K=(t,e)=>{for(var o in e||(e={}))B.call(e,o)&&A(t,o,e[o]);if(a)for(var o of a(e))M.call(e,o)&&A(t,o,e[o]);return t},U=(t,e)=>J(t,P(e));var j=(t,e)=>{var o={};for(var n in t)B.call(t,n)&&e.indexOf(n)<0&&(o[n]=t[n]);if(t!=null&&a)for(var n of a(t))e.indexOf(n)<0&&M.call(t,n)&&(o[n]=t[n]);return o};var d=(t,e,o)=>new Promise((n,c)=>{var f=i=>{try{r(o.next(i))}catch(u){c(u)}},s=i=>{try{r(o.throw(i))}catch(u){c(u)}},r=i=>i.done?n(i.value):Promise.resolve(i.value).then(f,s);r((o=o.apply(t,e)).next())});import{cb as Q,bf as l}from"./bootstrap-Bqxdt4iG.js";const F="*, inventoryDetail:inventoryDetailId(inventory:inventoryId(tdSku, originalSku, name, customerId, customer:customerId(companyName)), location:locationId(code)), packingOrder:packingOrderId(code, type, customerId, customer:customerId(companyName))";function G(t){var f,s,r,i,u,y,k,I,g,_,v,S,w,h,O,q,m,N,T,C,E,b,D,L,x,z;const c=t,{inventoryDetail:e,packingOrder:o}=c,n=j(c,["inventoryDetail","packingOrder"]);return U(K({},n),{inventoryTdSku:(r=(s=(f=e==null?void 0:e.inventory)==null?void 0:f.tdSku)!=null?s:n.inventoryTdSku)!=null?r:"",inventoryOriginalSku:(y=(u=(i=e==null?void 0:e.inventory)==null?void 0:i.originalSku)!=null?u:n.inventoryOriginalSku)!=null?y:"",inventoryName:(g=(I=(k=e==null?void 0:e.inventory)==null?void 0:k.name)!=null?I:n.inventoryName)!=null?g:"",locationCode:(S=(v=(_=e==null?void 0:e.location)==null?void 0:_.code)!=null?v:n.locationCode)!=null?S:"",packingOrderCode:(h=(w=o==null?void 0:o.code)!=null?w:n.packingOrderCode)!=null?h:null,packingOrderType:(q=(O=o==null?void 0:o.type)!=null?O:n.packingOrderType)!=null?q:null,customerId:(C=(T=(N=(m=e==null?void 0:e.inventory)==null?void 0:m.customerId)!=null?N:o==null?void 0:o.customerId)!=null?T:n.customerId)!=null?C:"",customerName:(z=(x=(L=(b=(E=e==null?void 0:e.inventory)==null?void 0:E.customer)==null?void 0:b.companyName)!=null?L:(D=o==null?void 0:o.customer)==null?void 0:D.companyName)!=null?x:n.customerName)!=null?z:""})}const W=Q("stock-out-details",{state:()=>({version:0}),getters:{isMockMode:()=>!1},actions:{getList(t){return d(this,null,function*(){var y,k;let e=l.from("stock_out_details").select(F,{count:"exact"});e=e.eq("isDelete",!1),t!=null&&t.stockOutId&&(e=e.eq("stockOutId",t.stockOutId)),t!=null&&t.packingOrderId&&(e=e.eq("packingOrderId",t.packingOrderId)),t!=null&&t.inventoryDetailId&&(e=e.eq("inventoryDetailId",t.inventoryDetailId)),e=t!=null&&t.sortBy?e.order(t.sortBy,{ascending:t.sortOrder!=="desc"}):e.order("createdAt",{ascending:!1});const o=(y=t==null?void 0:t.page)!=null?y:1,n=(k=t==null?void 0:t.pageSize)!=null?k:10,c=(o-1)*n,f=c+n-1;e=e.range(c,f);const{data:s,error:r,count:i}=yield e;if(r)throw r;return{items:(s!=null?s:[]).map(I=>G(I)),total:i!=null?i:0,page:o,pageSize:n}})},getDetail(t){return d(this,null,function*(){const{data:e,error:o}=yield l.from("stock_out_details").select(F).eq("id",t).eq("isDelete",!1).single();if(o)throw o;return e?G(e):null})},create(t){return d(this,null,function*(){const{data:e,error:o}=yield l.from("stock_out_details").insert(t).select().single();if(o||!e)throw o!=null?o:new Error("Create failed");return this.version++,e})},update(t,e){return d(this,null,function*(){const{data:o,error:n}=yield l.from("stock_out_details").update(e).eq("id",t).select().single();if(n)throw n;return this.version++,o})},remove(t){return d(this,null,function*(){const{error:e}=yield l.from("stock_out_details").update({isDelete:!0}).eq("id",t);if(e)throw e;return this.version++,!0})},restore(t){return d(this,null,function*(){const{error:e}=yield l.from("stock_out_details").update({isDelete:!1}).eq("id",t);if(e)throw e;return this.version++,!0})},hardDelete(t){return d(this,null,function*(){const{error:e}=yield l.from("stock_out_details").delete().eq("id",t);if(e)throw e;return this.version++,!0})},invalidate(){this.version++}}});export{W as u};
