diff --git a/ui/dist/spa/js/app.f764c69c.js b/ui/dist/spa/js/app.f764c69c.js new file mode 100644 index 0000000..3d39630 --- /dev/null +++ b/ui/dist/spa/js/app.f764c69c.js @@ -0,0 +1 @@ +(()=>{var e={824:(e,t,r)=>{"use strict";r(939),r(6461),r(7049);var o=r(8633),n=r(7486),s=r(4187),a=r(1347);const i={__name:"App",setup(e){return(e,t)=>{const r=(0,a.g2)("router-view");return(0,a.uX)(),(0,a.Wv)(r)}}},l=i,c=l;var d=r(180),m=r(705);const u=(0,d.nY)(()=>{const e=(0,m.Ey)();return e});var p=r(6470),h=r(455);const f=[{path:"/",redirect:"/login"},{path:"/login",component:()=>Promise.all([r.e(121),r.e(913)]).then(r.bind(r,4913)),meta:{public:!0},children:[{path:"",name:"login",component:()=>Promise.all([r.e(121),r.e(713)]).then(r.bind(r,713))}]},{path:"/first-password-change",component:()=>Promise.all([r.e(121),r.e(913)]).then(r.bind(r,4913)),meta:{public:!0},children:[{path:"",name:"first-password-change",component:()=>Promise.all([r.e(121),r.e(330)]).then(r.bind(r,8330))}]},{path:"/password-reset/:token",component:()=>Promise.all([r.e(121),r.e(913)]).then(r.bind(r,4913)),meta:{public:!0},children:[{path:"",name:"password-reset",component:()=>Promise.all([r.e(121),r.e(238)]).then(r.bind(r,2238))}]},{path:"/app",component:()=>Promise.all([r.e(121),r.e(618)]).then(r.bind(r,5618)),children:[{path:"",name:"dashboard",component:()=>Promise.all([r.e(121),r.e(996),r.e(621)]).then(r.bind(r,2621)),meta:{permission:"system:read"}},{path:"permissions",name:"permissions",component:()=>Promise.all([r.e(121),r.e(996),r.e(548)]).then(r.bind(r,4548)),meta:{permission:"system:read"}},{path:"role-dept-permissions",name:"role-dept-permissions",component:()=>Promise.all([r.e(121),r.e(996),r.e(607)]).then(r.bind(r,5607)),meta:{permission:"user:update"}},{path:"role-dept-permissions/list",name:"role-dept-permissions-list",component:()=>Promise.all([r.e(121),r.e(996),r.e(54)]).then(r.bind(r,54)),meta:{permission:"user:update"}},{path:"role-dept-permissions/editor",name:"role-dept-permissions-editor",component:()=>Promise.all([r.e(121),r.e(996),r.e(673)]).then(r.bind(r,7673)),meta:{permission:"user:update"}},{path:"user-permissions",name:"user-permissions",component:()=>Promise.all([r.e(121),r.e(996),r.e(465)]).then(r.bind(r,4465)),meta:{permission:"user:update"}},{path:"statementofaccount",name:"statementofaccount",component:()=>Promise.all([r.e(121),r.e(996),r.e(493)]).then(r.bind(r,8493)),meta:{permission:"finance:view"}},{path:"statementreport",name:"statementreport",component:()=>Promise.all([r.e(121),r.e(996),r.e(891)]).then(r.bind(r,1272)),meta:{permission:"finance:view"}},{path:"statementheaderreport",name:"statementheaderreport",component:()=>Promise.all([r.e(121),r.e(996),r.e(770)]).then(r.bind(r,2770)),meta:{permission:"finance:view"}},{path:"users",name:"user-gateway",component:()=>Promise.all([r.e(121),r.e(996),r.e(784)]).then(r.bind(r,1784)),meta:{permission:"user:view"}},{path:"users/list",name:"user-list",component:()=>Promise.all([r.e(121),r.e(996),r.e(432)]).then(r.bind(r,8432)),meta:{permission:"user:view"}},{path:"users/new",name:"user-new",component:()=>Promise.all([r.e(121),r.e(996),r.e(806)]).then(r.bind(r,2806)),meta:{mode:"new",permission:"user:insert"}},{path:"users/edit/:id",name:"user-edit",component:()=>Promise.all([r.e(121),r.e(996),r.e(806)]).then(r.bind(r,2806)),props:!0,meta:{mode:"edit",permission:"user:update"}},{path:"users/view/:id",name:"user-view",component:()=>Promise.all([r.e(121),r.e(996),r.e(806)]).then(r.bind(r,2806)),props:!0,meta:{mode:"view",permission:"user:view"}},{path:"activity-logs",name:"activity-logs",component:()=>Promise.all([r.e(121),r.e(996),r.e(251)]).then(r.bind(r,5251)),meta:{permission:"user:view"}},{path:"test-mail",name:"test-mail",component:()=>Promise.all([r.e(121),r.e(996),r.e(629)]).then(r.bind(r,629)),meta:{permission:"user:insert"}},{path:"order-gateway",name:"order-gateway",component:()=>Promise.all([r.e(121),r.e(996),r.e(755)]).then(r.bind(r,2755)),meta:{permission:"order:view"}},{path:"order-entry/:orderHeaderID",name:"order-entry",component:()=>Promise.all([r.e(121),r.e(996),r.e(981)]).then(r.bind(r,6981)),props:!0,meta:{mode:"new",permission:"order:insert"}},{path:"order-edit/:orderHeaderID",name:"order-edit",component:()=>Promise.all([r.e(121),r.e(996),r.e(981)]).then(r.bind(r,6981)),props:!0,meta:{mode:"edit",permission:"order:update"}},{path:"order-list",name:"order-list",component:()=>Promise.all([r.e(121),r.e(996),r.e(358)]).then(r.bind(r,2358)),meta:{permission:"order:view"}},{path:"order-bulk-close",name:"order-bulk-close",component:()=>Promise.all([r.e(121),r.e(996),r.e(398)]).then(r.bind(r,5398)),meta:{permission:"order:update"}},{path:"order-pdf/:id",name:"order-pdf",component:()=>Promise.all([r.e(121),r.e(996),r.e(950)]).then(r.bind(r,5950)),props:!0,meta:{permission:"order:export"}},{path:"change-password",name:"change-password",component:()=>Promise.all([r.e(121),r.e(996),r.e(486)]).then(r.bind(r,1486))}]},{path:"/:catchAll(.*)*",component:()=>Promise.all([r.e(121),r.e(28)]).then(r.bind(r,28))}],g=f;var b=r(5767),w=r(2584);const v=(0,p.wE)(function(){const e=(0,h.aE)({history:(0,h.Bt)(),routes:g});return e.beforeEach(async(e,t,r)=>{const o=(0,b.n)(),n=(0,w.o)();if(!0===e.meta?.public)return r();if(!o.isAuthenticated)return r("/login");if(o.mustChangePassword&&"/first-password-change"!==e.path)return r("/first-password-change");if(o.isAdmin)return r();if(!n.loaded)try{await n.fetchPermissions()}catch(e){console.error("Permission load failed",e)}const s=e.meta?.permission;if(!s)return r();const a=n.hasApiPermission(s);if(!a)return console.warn("⛔ ACCESS DENIED:",{path:e.fullPath,permission:s}),r("/unauthorized");r()}),e});async function y(e,t){const r=e(c);r.use(n.A,t);const o="function"===typeof u?await u({}):u;r.use(o);const a=(0,s.IG)("function"===typeof v?await v({store:o}):v);return o.use(({store:e})=>{e.router=a}),{app:r,store:o,router:a}}var P=r(4222),S=r(8564),A=r(9765),k=r(144);const E={config:{notify:{position:"top",timeout:2500}},lang:P.A,plugins:{Loading:S.A,Dialog:A.A,Notify:k.A}},C="/";async function x({app:e,router:t,store:r},o){let n=!1;const s=e=>{try{return t.resolve(e).href}catch(e){}return Object(e)===e?null:e},a=e=>{if(n=!0,"string"===typeof e&&/^https?:\/\//.test(e))return void(window.location.href=e);const t=s(e);null!==t&&(window.location.href=t,window.location.reload())},i=window.location.href.replace(window.location.origin,"");for(let s=0;!1===n&&s{const[t,o]=void 0!==Promise.allSettled?["allSettled",e=>e.map(e=>{if("rejected"!==e.status)return e.value.default;console.error("[Quasar] boot error:",e.reason)})]:["all",e=>e.map(e=>e.default)];return Promise[t]([Promise.resolve().then(r.bind(r,6795))]).then(t=>{const r=o(t).filter(e=>"function"===typeof e);x(e,r)})})},2584:(e,t,r)=>{"use strict";r.d(t,{o:()=>c});r(939),r(4151);var o=r(705),n=r(2986),s=r(5767);const a={read:["read","view"],view:["read","view"],write:["write","insert"],insert:["write","insert"],update:["update"],delete:["delete"],export:["export"]};function i(e){return String(e||"").trim().toLowerCase()}function l(e){const t=i(e);return a[t]||[t]}const c=(0,o.nY)("permission",{state:()=>({routes:[],matrix:[],loaded:!1}),getters:{isAdmin(){const e=(0,s.n)();return!0===e.isAdmin},hasApiPermission:e=>t=>{const r=(0,s.n)();if(r.isAdmin)return!0;if(!e.loaded)return!1;if(!t)return!0;if(t.includes(":")){const[r,o]=t.split(":"),n=i(r),s=l(o);return e.matrix.some(e=>i(e.module)===n&&s.includes(i(e.action))&&!0===e.allowed)}const o=t;if(e.routes.some(e=>e.route===o&&e.can_access))return!0;const n=o.replace(/\/\d+/g,"/{id}");return!!e.routes.some(e=>e.route===n&&e.can_access)||e.routes.some(e=>e.can_access&&o.startsWith(e.route))},hasModule:e=>t=>{const r=(0,s.n)(),o=i(t);return!!r.isAdmin||!!e.loaded&&e.matrix.some(e=>i(e.module)===o&&!0===e.allowed)},hasPermission:e=>(t,r)=>{const o=(0,s.n)(),n=i(t),a=l(r);return!!o.isAdmin||!!e.loaded&&e.matrix.some(e=>i(e.module)===n&&a.includes(i(e.action))&&!0===e.allowed)}},actions:{async fetchPermissions(){const e=(0,s.n)();if(e.isAdmin)return this.routes=[],this.matrix=[],void(this.loaded=!0);try{const e=await n.Ay.get("/permissions/routes");this.routes=e.data||[];const t=await n.Ay.get("/permissions/effective");this.matrix=t.data||[],console.group("🔐 PERMISSION DEBUG"),console.log("API ROUTES:",this.routes),console.log("EFFECTIVE MATRIX:",this.matrix),console.groupEnd()}catch(e){console.error("❌ Permission load failed",e),this.routes=[],this.matrix=[]}finally{this.loaded=!0}},clear(){this.routes=[],this.matrix=[],this.loaded=!1}}})},2634:()=>{},2986:(e,t,r)=>{"use strict";r.d(t,{Ay:()=>f,Jt:()=>c,RG:()=>h,bE:()=>d,hi:()=>p,yJ:()=>m});var o=r(9100),n=r(367),s=r(5767);const a="/api",i=o.A.create({baseURL:a,timeout:18e4,paramsSerializer:e=>n.stringify(e,{arrayFormat:"repeat"}),withCredentials:!0});i.interceptors.request.use(e=>{const t=(0,s.n)(),r=e.url||"",o=r.startsWith("/auth/login")||r.startsWith("/auth/refresh")||r.startsWith("/password/forgot")||r.startsWith("/password/reset");return!o&&t?.token&&(e.headers||={},e.headers.Authorization=`Bearer ${t.token}`),e});let l=!1;i.interceptors.response.use(e=>e,async e=>{const t=e?.response?.status,r="undefined"!==typeof Blob&&e?.response?.data instanceof Blob;if((t>=500||r)&&e){const r=String(e?.config?.method||"GET").toUpperCase(),o=e?.config?.url||"",n=await p(e);e.parsedMessage=n,console.error(`❌ API ${t||"-"} ${r} ${o}: ${n}`)}if(401===e?.response?.status&&!l){l=!0;try{(0,s.n)().clearSession()}finally{l=!1}}return Promise.reject(e)});const c=(e,t={},r={})=>i.get(e,{params:t,...r}).then(e=>e.data),d=(e,t={},r={})=>i.post(e,t,r).then(e=>e.data),m=(e,t={},r={})=>i.put(e,t,r).then(e=>e.data);async function u(e){if(!e)return"";if("undefined"!==typeof Blob&&e instanceof Blob)try{const t=(await e.text())?.trim();if(!t)return"";try{const e=JSON.parse(t);return e?.detail||e?.message||e?.error||t}catch{return t}}catch{return""}return"string"===typeof e?e.trim():"object"===typeof e&&(e?.detail||e?.message||e?.error)||""}async function p(e){let t=e?.parsedMessage||e?.response?.data?.detail||e?.response?.data?.message||e?.response?.data?.error||"";return t||(t=await u(e?.response?.data)),t||(t=e?.message||"Request failed"),t}const h=async(e,t={},r={})=>{try{const o=await i.get(e,{params:t,responseType:"blob",...r});return o.data}catch(e){const t=await p(e),r=new Error(t);throw r.status=e?.response?.status,r.original=e,r}},f=i},5767:(e,t,r)=>{"use strict";r.d(t,{n:()=>c});r(295);var o=r(705),n=r(2986),s=r(2584);function a(e){return String(e||"").trim().toLowerCase()}function i(e){return e&&"object"===typeof e?a(e.role_code??e.roleCode??e.RoleCode):""}function l(e){const t=String(e||"").trim();if(!t)return null;const r=t.split(".");if(3!==r.length)return null;try{const e=r[1].replace(/-/g,"+").replace(/_/g,"/").padEnd(4*Math.ceil(r[1].length/4),"="),t=atob(e);return JSON.parse(t)}catch{return null}}const c=(0,o.nY)("auth",{state:()=>{let e=null;try{const t=localStorage.getItem("user");t&&"undefined"!==t&&"null"!==t&&(e=JSON.parse(t))}catch{console.warn("⚠️ Invalid user in localStorage, cleared"),localStorage.removeItem("user")}return{token:localStorage.getItem("token"),user:e,forcePasswordChange:"1"===localStorage.getItem("forcePasswordChange")}},getters:{isAuthenticated:e=>!!e.token,mustChangePassword:e=>!!e.forcePasswordChange,isAdmin:e=>{const t=i(e.user);if(t)return"admin"===t;const r=l(e.token);return"admin"===a(r?.role_code)}},actions:{setSession({token:e,user:t}){this.token=e,this.user=t?{...this.user||{},...t}:null,this.forcePasswordChange=!!t?.force_password_change,localStorage.setItem("token",e),t?localStorage.setItem("user",JSON.stringify(t)):localStorage.removeItem("user"),localStorage.setItem("forcePasswordChange",this.forcePasswordChange?"1":"0")},clearSession(){this.token=null,this.user=null,this.forcePasswordChange=!1,localStorage.removeItem("token"),localStorage.removeItem("user"),localStorage.removeItem("forcePasswordChange"),(0,s.o)().clear()},async login(e,t){const r=await n.Ay.post("/auth/login",{username:e,password:t}),o=r?.token||r?.data?.token||r?.access_token||r?.data?.access_token,a=r?.user||r?.data?.user,i="string"===typeof o?o.trim():"",l=3===i.split(".").length;if(!i||!l)throw console.error("❌ LOGIN RESPONSE (unexpected):",r),new Error("Invalid login token");this.setSession({token:i,user:a});const c=(0,s.o)();return await c.fetchPermissions(),console.log("🔐 AUTH DEBUG",{isAdmin:this.isAdmin,users:c.hasPermission("/api/users/list"),orders:c.hasPermission("/api/orders/list"),logs:c.hasPermission("/api/activity-logs"),permissions:c.hasPermission("/api/permissions/matrix")}),!0}}})},6795:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>i});var o=r(991),n=r(5115),s=r(5337),a=r(5188);r(8909);o.extend(n),o.extend(s),o.extend(a),o.locale("tr");const i=o}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,r),s.exports}r.m=e,(()=>{var e=[];r.O=(t,o,n,s)=>{if(!o){var a=1/0;for(d=0;d=s)&&Object.keys(r.O).every(e=>r.O[e](o[l]))?o.splice(l--,1):(i=!1,s0&&e[d-1][2]>s;d--)e[d]=e[d-1];e[d]=[o,n,s]}})(),(()=>{r.n=e=>{var t=e&&e.__esModule?()=>e["default"]:()=>e;return r.d(t,{a:t}),t}})(),(()=>{r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})}})(),(()=>{r.f={},r.e=e=>Promise.all(Object.keys(r.f).reduce((t,o)=>(r.f[o](e,t),t),[]))})(),(()=>{r.u=e=>"js/"+(996===e?"chunk-common":e)+"."+{28:"1861262a",54:"92abb86e",238:"471bb852",251:"ec73d906",330:"aa2a2894",358:"629c6b73",398:"9152643f",432:"939f1ebd",465:"9a2899f5",486:"a263e6f6",493:"e8a952e1",548:"61f02757",607:"70ac7b00",618:"f36e56f9",621:"2108b55f",629:"2c27a0a3",673:"8f68da58",713:"5838996c",755:"7f443827",770:"4db9e143",784:"f73528a6",806:"754fb646",891:"181bb68a",913:"c0c6a5a1",950:"6078f4a8",981:"0247bab0",996:"ed7a624a"}[e]+".js"})(),(()=>{r.miniCssF=e=>"css/"+e+"."+{54:"b237f020",358:"36bfde07",398:"961173a2",607:"8d5cccce",713:"e99910ab",784:"5916f342"}[e]+".css"})(),(()=>{r.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}()})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{var e={},t="baggisowtfaresystem:";r.l=(o,n,s,a)=>{if(e[o])e[o].push(n);else{var i,l;if(void 0!==s)for(var c=document.getElementsByTagName("script"),d=0;d{i.onerror=i.onload=null,clearTimeout(p);var n=e[o];if(delete e[o],i.parentNode&&i.parentNode.removeChild(i),n&&n.forEach(e=>e(r)),t)return t(r)},p=setTimeout(u.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=u.bind(null,i.onerror),i.onload=u.bind(null,i.onload),l&&document.head.appendChild(i)}}})(),(()=>{r.r=e=>{"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})(),(()=>{r.p="/"})(),(()=>{if("undefined"!==typeof document){var e=(e,t,o,n,s)=>{var a=document.createElement("link");a.rel="stylesheet",a.type="text/css",r.nc&&(a.nonce=r.nc);var i=r=>{if(a.onerror=a.onload=null,"load"===r.type)n();else{var o=r&&r.type,i=r&&r.target&&r.target.href||t,l=new Error("Loading CSS chunk "+e+" failed.\n("+o+": "+i+")");l.name="ChunkLoadError",l.code="CSS_CHUNK_LOAD_FAILED",l.type=o,l.request=i,a.parentNode&&a.parentNode.removeChild(a),s(l)}};return a.onerror=a.onload=i,a.href=t,o?o.parentNode.insertBefore(a,o.nextSibling):document.head.appendChild(a),a},t=(e,t)=>{for(var r=document.getElementsByTagName("link"),o=0;onew Promise((n,s)=>{var a=r.miniCssF(o),i=r.p+a;if(t(a,i))return n();e(o,i,null,n,s)}),n={524:0};r.f.miniCss=(e,t)=>{var r={54:1,358:1,398:1,607:1,713:1,784:1};n[e]?t.push(n[e]):0!==n[e]&&r[e]&&t.push(n[e]=o(e).then(()=>{n[e]=0},t=>{throw delete n[e],t}))}}})(),(()=>{var e={524:0};r.f.j=(t,o)=>{var n=r.o(e,t)?e[t]:void 0;if(0!==n)if(n)o.push(n[2]);else{var s=new Promise((r,o)=>n=e[t]=[r,o]);o.push(n[2]=s);var a=r.p+r.u(t),i=new Error,l=o=>{if(r.o(e,t)&&(n=e[t],0!==n&&(e[t]=void 0),n)){var s=o&&("load"===o.type?"missing":o.type),a=o&&o.target&&o.target.src;i.message="Loading chunk "+t+" failed.\n("+s+": "+a+")",i.name="ChunkLoadError",i.type=s,i.request=a,n[1](i)}};r.l(a,l,"chunk-"+t,t)}},r.O.j=t=>0===e[t];var t=(t,o)=>{var n,s,[a,i,l]=o,c=0;if(a.some(t=>0!==e[t])){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(l)var d=l(r)}for(t&&t(o);cr(824));o=r.O(o)})(); \ No newline at end of file diff --git a/ui/dist/spa/js/app.f764c69c.js.gz b/ui/dist/spa/js/app.f764c69c.js.gz new file mode 100644 index 0000000..2fb3059 Binary files /dev/null and b/ui/dist/spa/js/app.f764c69c.js.gz differ diff --git a/ui/dist/spa/js/chunk-common.ed7a624a.js b/ui/dist/spa/js/chunk-common.ed7a624a.js new file mode 100644 index 0000000..cb7bf67 --- /dev/null +++ b/ui/dist/spa/js/chunk-common.ed7a624a.js @@ -0,0 +1 @@ +"use strict";(globalThis["webpackChunkbaggisowtfaresystem"]=globalThis["webpackChunkbaggisowtfaresystem"]||[]).push([[996],{588:(e,r,t)=>{t.d(r,{J:()=>s});var a=t(1347),o=t(2584);function s(){const e=(0,o.o)();return{canRead:r=>(0,a.EW)(()=>e.hasPermission(r,"read")),canWrite:r=>(0,a.EW)(()=>e.hasPermission(r,"write")),canUpdate:r=>(0,a.EW)(()=>e.hasPermission(r,"update")),canDelete:r=>(0,a.EW)(()=>e.hasPermission(r,"delete")),canExport:r=>(0,a.EW)(()=>e.hasPermission(r,"export")),canApi:r=>(0,a.EW)(()=>e.hasApiPermission(r)),hasModule:r=>(0,a.EW)(()=>e.hasModule(r))}}},742:(e,r,t)=>{t.d(r,{E:()=>s});t(939),t(7049);var a=t(705),o=t(2986);const s=(0,a.nY)("account",{state:()=>({accountOptions:[],loading:!1,error:null}),actions:{async fetchAccounts(){this.loading=!0,this.error=null;try{const{data:e}=await o.Ay.get("/accounts");this.accountOptions=(Array.isArray(e)?e:[]).map(e=>({label:`${e.display_code||""} ${e.account_name||""}`.trim(),value:e.account_code}))}catch(e){console.error("❌ Error fetching accounts:",e),this.error=401===e?.response?.status?"Cari hesapları görüntüleme yetkiniz yok.":e?.response?.data?.message||e?.message||"Cari hesaplar yüklenemedi"}finally{this.loading=!1}}}})},4887:(e,r,t)=>{t.d(r,{x:()=>i});t(939),t(4520),t(3142),t(8832),t(8825),t(2528),t(4207),t(9188),t(1118);var a=t(705),o=t(2986),s=t(367);t(6795);const i=(0,a.nY)("statementheader",{state:()=>({headers:[],details:{},loading:!1,groupOpen:{}}),getters:{currencies(e){const r=new Set;for(const t of e.headers)r.add(t.para_birimi||"—");return Array.from(r).sort()},totalsByCurrency(e){const r={};for(const t of e.headers){const e=t.para_birimi||"—";r[e]||(r[e]={borc:0,alacak:0,bakiye:0,count:0}),r[e].borc+=Number(t.borc)||0,r[e].alacak+=Number(t.alacak)||0,r[e].bakiye+=Number(t.bakiye)||0,r[e].count+=1}return r},groupedRows:e=>{const r={};for(const t of e.headers){const e=t.para_birimi||"—";r[e]||(r[e]=[]),r[e].push(t)}const t=[];for(const[a,o]of Object.entries(r)){if(!o.length)continue;const r=[...o].sort((e,r)=>new Date(e.belge_tarihi)-new Date(r.belge_tarihi)),s=r.at(-1),i=s&&null!=s.bakiye?Number(s.bakiye):0;t.push({_type:"group",para_birimi:a,sonBakiye:i}),!1!==e.groupOpen[a]&&r.forEach(e=>{t.push({...e,_type:"data"})})}return t}},actions:{async loadStatements(e={}){this.loading=!0;try{const{data:r}=await o.Ay.get("/statements",{params:e,paramsSerializer:e=>s.stringify(e,{arrayFormat:"repeat"})});this.headers=Array.isArray(r)?r:[];for(const e of this.currencies)e in this.groupOpen||(this.groupOpen[e]=!0)}catch(e){console.error("❌ Statements yüklenemedi:",e),this.headers=[]}finally{this.loading=!1}},async loadDetails(e){if(e&&!this.details[e])try{const{data:r}=await o.Ay.get(`/statements/${e}/details`);this.details[e]=Array.isArray(r)?r:[]}catch(r){console.error("❌ Details yüklenemedi:",r),this.details[e]=[]}},toggleGroup(e){const r=e||"—";this.groupOpen[r]=!this.groupOpen[r]},openAllGroups(){for(const e of this.currencies)this.groupOpen[e]=!0},closeAllGroups(){for(const e of this.currencies)this.groupOpen[e]=!1}}})},5390:(e,r,t)=>{t.d(r,{w:()=>s});t(939),t(6461);var a=t(705),o=t(2986);const s=(0,a.nY)("downloadstpdf",{actions:{async downloadPDF(e,r,t,a=[]){try{const s={accountcode:e,startdate:r,enddate:t};Array.isArray(a)&&a.length>0&&(s.parislemler=a.filter(e=>void 0!==e&&null!==e&&""!==e));const i=await(0,o.RG)("/export-pdf",s),n=window.URL.createObjectURL(new Blob([i],{type:"application/pdf"}));return window.open(n,"_blank"),console.log("✅ PDF yeni sekmede açıldı"),{ok:!0,message:"📄 PDF hazırlandı"}}catch(e){const r=await(0,o.hi)(e),t=e?.status||e?.response?.status||"-";return console.error(`? PDF a�ma hatas� [${t}] /export-pdf: ${r}`),{ok:!1,message:r||"PDF al�namad�"}}}}})},5599:(e,r,t)=>{t.d(r,{l:()=>s});t(939),t(6461);var a=t(705),o=t(2986);const s=(0,a.nY)("statementdetail",{state:()=>({details:[],loading:!1,error:null}),actions:{async loadDetails({accountCode:e,startDate:r,endDate:t,parislemler:a}){if(e){this.loading=!0,this.error=null;try{const s={startdate:r,enddate:t};Array.isArray(a)&&a.length>0&&(s.parislemler=a.filter(e=>void 0!==e&&null!==e&&""!==e));const i=await o.Ay.get(`/statements/${e}/details`,{params:s});this.details=i.data||[]}catch(e){console.error("❌ Details yüklenemedi:",e),this.error=e?.data?.message||e?.message||"Detaylar yüklenemedi"}finally{this.loading=!1}}else this.error="Geçerli bir cari kod seçilmedi."},getDetailsByBelge(e){return this.details.filter(r=>r.belge_ref_numarasi===e)},reset(){this.details=[],this.loading=!1,this.error=null}}})},8338:(e,r,t)=>{t.d(r,{i:()=>s});t(939),t(6461);var a=t(705),o=t(2986);const s=(0,a.nY)("downloadstHead",{actions:{async handlestHeadDownload(e,r,t,a){try{const s={accountcode:e,startdate:r,enddate:t};Array.isArray(a)&&a.length>0&&(s.parislemler=a.filter(e=>void 0!==e&&null!==e&&""!==e));const i=await(0,o.RG)("/exportstamentheaderreport-pdf",s),n=window.URL.createObjectURL(i);return window.open(n,"_blank"),{ok:!0,message:"📄 PDF hazırlandı"}}catch(e){const r=await(0,o.hi)(e),t=e?.status||e?.response?.status||"-";return console.error(`? PDF a�ma hatas� [${t}] /exportstamentheaderreport-pdf: ${r}`),{ok:!1,message:r||"PDF a�ma hatas�"}}}}})},8557:(e,r,t)=>{t.d(r,{Bm:()=>D,Cz:()=>h,Tf:()=>w});t(939),t(6461),t(7008),t(4520),t(7049),t(6593),t(4151);var a=t(705),o=t(2986),s=t(6795),i=t(4187),n=t(5767);const d="_",l=e=>(null==e?"":String(e)).trim(),c=e=>l(e).toUpperCase();function u(e,r){const t=c(e?.model||e?.ItemCode),a=c(e?.renk||e?.ColorCode),o=c(e?.renk2||e?.ItemDim2Code),s=c(r),i=""===s?d:s;return`${t}||${a}||${o}||${i}`}const m=[{key:"ayk",title:"AYAKKABI",values:["39","40","41","42","43","44","45"]},{key:"yas",title:"YAS",values:["2","4","6","8","10","12","14"]},{key:"pan",title:"PANTOLON",values:["38","40","42","44","46","48","50","52","54","56","58","60","62","64","66","68"]},{key:"gom",title:"GOMLEK",values:["XS","S","M","L","XL","2XL","3XL","4XL","5XL","6XL","7XL"]},{key:"tak",title:"TAKIM ELBISE",values:["44","46","48","50","52","54","56","58","60","62","64","66","68","70","72","74"]},{key:"aksbir",title:"AKSESUAR",values:[" ","44","STD","110","115","120","125","130","135"]}],h=m.reduce((e,r)=>(e[r.key]=r,e),{}),y=(0,i.KR)({}),p=(0,i.KR)([]),g=(0,i.KR)({});function b(){return crypto.randomUUID()}function f(e,r,t){const a=e.clientRowKey||e.clientKey||e.id||e._id||e.tmpId||`${e.model||""}|${e.renk||""}|${e.renk2||""}`;return`${a}::${r}::${t}`}const D=(0,a.nY)("orderentry",{state:()=>({isControlledSubmit:!1,allowRouteLeaveOnce:!1,schemaMap:{},productCache:{},_lastSavedFingerprint:null,activeNewHeaderId:localStorage.getItem("bss_active_new_header")||null,loading:!1,selected:null,error:null,customers:[],selectedCustomer:null,products:[],colors:[],secondColors:[],inventory:[],selectedProduct:null,selectedColor:null,selectedColor2:null,OrderHeaderID:null,persistKey:"bss_orderentry_data",lastSnapshotKey:"bss_orderentry_snapshot",editingKey:null,currentOrderId:null,mode:"new",orders:[],header:{},summaryRows:[],lastSavedAt:null,preventPersist:!1,_uiBusy:!1,_unsavedChanges:!1}),getters:{getDraftKey(){return"bss_orderentry_new_draft"},getEditKey(){const e=this.header?.OrderHeaderID;return e?`bss_orderentry_edit:${e}`:null},hasUnsavedChanges(e){try{return e._lastSavedFingerprint!==e._persistFingerprint?.()}catch{return!1}},getPersistKey:e=>e.header?.OrderHeaderID?`${e.persistKey}:${e.header.OrderHeaderID}`:e.persistKey,getSnapshotKey:e=>e.header?.OrderHeaderID?`${e.lastSnapshotKey}:${e.header.OrderHeaderID}`:e.lastSnapshotKey,totalQty:e=>(e.orders||[]).reduce((e,r)=>e+(Number(r?.adet)||0),0),hasAnyClosedLine(e){return Array.isArray(e.summaryRows)&&e.summaryRows.some(e=>!0===e?.isClosed)},totalAmount(e){return Array.isArray(e.summaryRows)?e.summaryRows.reduce((e,r)=>e+Number(r?.tutar||0),0):0}},actions:{normalizeComboUI(e){return u(e,d)},initSchemaMap(){if(this.schemaMap&&Object.keys(this.schemaMap).length>0)return;const e={};for(const r of m)e[r.key]={key:r.key,title:r.title,values:[...r.values]};this.schemaMap=e,console.log("🧩 schemaMap INIT edildi:",Object.keys(this.schemaMap))},getRowKey(e){return e&&(e.OrderLineID||e.id)||null},updateHeaderTotals(){try{if(!Array.isArray(this.summaryRows))return 0;const e=this.summaryRows.reduce((e,r)=>e+Number(r?.tutar||0),0);return this.header&&(this.header.TotalAmount=Number(e.toFixed(2))),e}catch(e){return console.error("❌ updateHeaderTotals hata:",e),0}},async showInvalidVariantDialog(e,r=[]){if(Array.isArray(r)&&0!==r.length)return new Promise(t=>{const a=e.dialog({title:"🚨 Tanımsız Ürün Kombinasyonları",message:`\n
\n ${r.map((e,r)=>`\n \n
\n #${r+1} | Item: ${e.itemCode}\n
\n
\n Beden: ${e.dim1||"(boş)"} |\n Renk: ${e.colorCode||"-"} |\n Qty: ${e.qty1}\n
\n
\n Sebep: ${e.reason||"Tanımsız ürün kombinasyonu"}\n
\n
\n `).join("")}\n \n `,html:!0,ok:{label:"Düzelt",color:"negative"},cancel:!1,persistent:!0}).onOk(()=>t()).onDismiss(()=>t());setTimeout(()=>{if(!a)return;const e=document.querySelectorAll(".invalid-row");e.forEach(e=>{e.addEventListener("click",()=>{const r=e.getAttribute("data-clientkey");this.scrollToInvalidRow?.(r)})})},0)})},scrollToInvalidRow(e){if(!e)return;const r=this.summaryRows?.findIndex(r=>r.clientKey===e);if(-1===r)return void console.warn("❌ Satır bulunamadı:",e);const t=document.querySelector(`[data-clientkey="${e}"]`);t?(t.scrollIntoView({behavior:"smooth",block:"center"}),t.classList.add("invalid-highlight"),setTimeout(()=>{t.classList.remove("invalid-highlight")},2500)):console.warn("❌ DOM satırı bulunamadı:",e)},async checkHeaderExists(e){try{if(!e)return!1;const r=await o.Ay.get(`/orders/check/${e}`);return!0===r?.data?.exists}catch(e){return console.warn("⚠ checkHeaderExists hata:",e),!1}},async fetchOrderPdf(e){try{const r=await o.Ay.get(`/order/pdf/${e}`,{responseType:"blob"});return r.data}catch(r){const t=await(0,o.hi)(r),a=r?.status||r?.response?.status||"-";throw console.error(`? fetchOrderPdf hata [${a}] order=${e}: ${t}`),new Error(t)}},async downloadOrderPdf(e=null){try{const r=e||this.header?.OrderHeaderID;if(!r)return void console.error("❌ PDF ID bulunamadı");const t=await o.Ay.get(`/order/pdf/${r}`,{responseType:"blob"}),a=new Blob([t.data],{type:"application/pdf"}),s=URL.createObjectURL(a);window.open(s,"_blank"),setTimeout(()=>URL.revokeObjectURL(s),6e4)}catch(r){const t=await(0,o.hi)(r),a=e||this.header?.OrderHeaderID||"-",s=r?.status||r?.response?.status||"-";throw console.error(`? PDF a�ma hatas� [${s}] order=${a}: ${t}`),new Error(t)}},setActiveNewHeader(e){this.activeNewHeaderId=e||null,e?localStorage.setItem("bss_active_new_header",e):localStorage.removeItem("bss_active_new_header")},getActiveNewHeaderId(){return this.activeNewHeaderId||localStorage.getItem("bss_active_new_header")},async initFromRoute(e,r=null){if("new"===this.mode){const e=localStorage.getItem(this.getDraftKey);if(e)try{const r=JSON.parse(e);return this.header=r.header||{},this.orders=r.orders||[],this.summaryRows=r.summaryRows||this.orders,void console.log("♻️ NEW draft restore edildi (global)")}catch{}return void console.log("⚪ NEW draft yok, boş başlatılıyor")}this.schemaMap&&Object.keys(this.schemaMap).length||this.initSchemaMap();try{console.log("🧩 [initFromRoute] orderId:",e);const t=localStorage.getItem("bss_last_txn")||null,a=e=>{if(!e)return null;const r=localStorage.getItem(`bss_orderentry_data:${e}`);if(!r)return null;try{return JSON.parse(r)}catch{return null}},o=a(e),s=a(t),i=e=>!!e&&(Array.isArray(e.orders)&&e.orders.length>0||Array.isArray(e.summaryRows)&&e.summaryRows.length>0);let n=null,d=null;if(i(o)?(n=e,d=o,console.log("✅ [initFromRoute] Route ID snapshot seçildi:",n)):i(s)&&(n=t,d=s,console.log("✅ [initFromRoute] lastTxn snapshot seçildi:",n)),!n||!d)return console.log("⚪ [initFromRoute] Snapshot yok, boş başlatılıyor"),this.header={...this.header||{},OrderHeaderID:e||t||crypto.randomUUID()},this.orders=[],void(this.summaryRows=[]);this.header={...d.header||{},OrderHeaderID:n};const l=Array.isArray(d.orders)?[...d.orders]:[],c=Array.isArray(d.summaryRows)?[...d.summaryRows]:l;this.orders=l,this.summaryRows=c;try{localStorage.setItem("bss_last_txn",n)}catch(e){console.warn("⚠️ bss_last_txn yazılamadı:",e)}r&&e&&e!==n&&(console.log("🔁 [initFromRoute] Route ID düzeltiliyor →",n),await r.replace({name:"order-entry",params:{orderHeaderID:n}})),console.log("✅ [initFromRoute] Restore tamam. Satır sayısı:",this.summaryRows.length)}catch(e){console.error("❌ [initFromRoute] hata:",e)}},async startNewOrder({$q:e}){this.schemaMap&&Object.keys(this.schemaMap).length||this.initSchemaMap();const r=crypto.randomUUID();let t=`LOCAL-${(0,s["default"])().format("YYMMDD-HHmmss")}`;try{const e=await o.Ay.get("/order/new-number");e?.data?.OrderNumber&&(t=e.data.OrderNumber)}catch{console.info("ℹ️ Backend order number yok, LOCAL kullanıldı")}return this.mode="new",this.isControlledSubmit=!1,this.allowRouteLeaveOnce=!1,this.header={OrderHeaderID:r,OrderNumber:t,OrderDate:(new Date).toISOString().slice(0,10),CurrAccCode:null,DocCurrencyCode:"USD",PriceCurrencyCode:"USD",PriceExchangeRate:1},this.orders=[],this.summaryRows=[],this._lastSavedFingerprint=null,this.persistLocalStorage?.(),this.header},dedupeActiveLinesByCombo(e){const r=new Map;for(const t of e){const e=u({model:t.ItemCode,renk:t.ColorCode,renk2:t.ItemDim2Code},t.ItemDim1Code);if(!r.has(e)){t.ComboKey=e,r.set(e,t);continue}const a=r.get(e);a.Qty1=(Number(a.Qty1)||0)+(Number(t.Qty1)||0),!a.OrderLineID&&t.OrderLineID&&(a.OrderLineID=t.OrderLineID)}return Array.from(r.values())},resetCoreState(){this.orders=[],this.summaryRows=[],this.groupedRows=[],this.header={},this.editingKey=null,this.currentOrderId=null},resetForNewOrder(){this.header={OrderHeaderID:this.header?.OrderHeaderID||null,OrderDate:(new Date).toISOString().slice(0,10),CurrAccCode:null,DocCurrencyCode:"TRY",PriceCurrencyCode:"TRY"},this.orders=[],this.summaryRows=[],this.productCache={},this.stockMap={},this.setMode("new")},resetForEdit(){this.editingKey=null,this.groupedRows=[],this.mode="edit"},markAsSaved(){try{this._lastSavedFingerprint=this._persistFingerprint(),console.log("✅ markAsSaved → fingerprint senkron")}catch(e){console.warn("⚠️ markAsSaved hata:",e)}},clearLocalSnapshot(){try{const e=this.header?.OrderHeaderID;if(!e)return;localStorage.removeItem(`bss_orderentry_data:${e}`),console.log("🧹 Local snapshot temizlendi:",e)}catch(e){console.warn("⚠️ clearLocalSnapshot hata:",e)}},clearAllOrderSnapshots(){Object.keys(localStorage).filter(e=>e.startsWith("bss_orderentry_data:")||e.startsWith("bss_orderentry_edit:")).forEach(e=>{console.log("🧹 snapshot silindi:",e),localStorage.removeItem(e)}),localStorage.removeItem("bss_last_txn")},hardResetAfterSubmit(){try{const e=this.header?.OrderHeaderID||null;this.orders=[],this.summaryRows=[],this.groupedRows=[],this.header={},this.mode="new",this.editingKey=null,this.currentOrderId=null,this.activeTransactionId=null,this.submitted=!1,this._lastSavedFingerprint=null,this._lastPersistFingerprint=null,this._persistTimeout&&(clearTimeout(this._persistTimeout),this._persistTimeout=null);try{e&&(localStorage.removeItem(`bss_orderentry_data:${e}`),localStorage.removeItem(`bss_orderentry_snapshot:${e}`)),localStorage.removeItem("bss_last_txn"),localStorage.removeItem("bss_active_new_header")}catch(e){console.warn("⚠️ hardResetAfterSubmit localStorage temizliği hata:",e)}console.log("🧹 Store resetlendi (submit sonrası).")}catch(e){console.error("❌ hardResetAfterSubmit hata:",e)}},async openExistingForEdit(e,{$q:r=null,form:t=null,productCache:a=null}={}){if(this.schemaMap&&Object.keys(this.schemaMap).length||this.initSchemaMap?.(),!e)return!1;if("new"===this.mode)return console.log("⚪ openExistingForEdit skip (mode=new)"),!1;const s=a?.value?a.value:a&&"object"===typeof a?a:{};try{this.setMode?.("edit");const r=await o.Ay.get(`/order/get/${e}`),a=r?.data;if(!a?.header)throw new Error("Backend header yok");this.header={...a.header,OrderHeaderID:a.header.OrderHeaderID||e};const i=this.normalizeOrderLines(a.lines||[],this.header.DocCurrencyCode||"USD",s);this.orders=Array.isArray(i)?i:[],this.summaryRows=[...this.orders];const n=(this.summaryRows||[]).some(e=>!0===e?.isClosed);this.setMode?.(n?"view":"edit"),t&&Object.assign(t,this.header),this.persistLocalStorage?.();try{localStorage.setItem("bss_last_txn",String(e))}catch{}return console.log("✅ openExistingForEdit OK:",{id:e,rows:this.summaryRows.length,mode:this.mode,hasClosedLine:n}),!0}catch(e){return console.error("❌ openExistingForEdit hata:",e),"new"!==this.mode&&r?.notify?.({type:"negative",message:"Sipariş yüklenemedi"}),!1}},async hydrateFromLocalStorage(e,r=!1){if("new"===this.mode)return this.hydrateFromLocalStorageIfExists();try{const t=`bss_orderentry_data:${e}`,a=JSON.parse(localStorage.getItem(t)||"null");if(!a)return r&&console.log("ℹ️ hydrate → snapshot yok:",e),null;this.source=a.source||"local";const o=e=>{if(!e)return null;const r=(0,s["default"])(e);return r.isValid()?r.format("YYYY-MM-DD HH:mm:ss"):null},i=e=>{if(!e)return null;const r=(0,s["default"])(e);return r.isValid()?r.format("YYYY-MM-DD"):null},n=e=>{if(!e)return null;const r=(0,s["default"])(e);return r.isValid()?r.format("HH:mm:ss"):null};this.header={...a.header||{},OrderHeaderID:a.header?.OrderHeaderID??e,OrderNumber:a.header?.OrderNumber??null};const d=this.header;d.CreatedDate=o(d.CreatedDate),d.LastUpdatedDate=o(d.LastUpdatedDate),d.CreditableConfirmedDate=o(d.CreditableConfirmedDate),d.OrderDate=i(d.OrderDate),d.OrderTime=n(d.OrderTime),this.header=d;const l=Array.isArray(a.orders)?a.orders:[];this.orders=l,this.summaryRows=Array.isArray(a.summaryRows)?a.summaryRows:l,this.groupedRows=[];const c={type:!0===a.submitted?"submitted":"draft",source:this.source,headerId:e,orderNumber:this.header?.OrderNumber??null,rows:this.summaryRows.length,submitted:!0===a.submitted||!0===a.header?.IsSubmitted};return r&&console.log("♻️ hydrate sonuc (FIXED):",c),c}catch(e){return console.warn("⚠️ hydrateFromLocalStorage hata:",e),null}},hydrateFromLocalStorageIfExists(){try{let e=null;if("new"===this.mode&&(e=localStorage.getItem(this.getDraftKey)),"edit"===this.mode){const r=this.getEditKey;r&&(e=localStorage.getItem(r))}if(!e)return!1;const r=JSON.parse(e);return this.header=r.header||{},this.orders=r.orders||[],this.summaryRows=r.summaryRows||this.orders,console.log("♻️ hydrate OK:",this.mode),!0}catch(e){return console.warn("hydrateFromLocalStorageIfExists hata:",e),!1}},mergeOrders(e,r,t=!0){if(!r&&!e)return{header:{},orders:[]};const a=(e={},r={})=>{const t={...e};for(const[e,a]of Object.entries(r||{}))void 0!==a&&null!==a&&("string"===typeof a&&""===a.trim()||(t[e]=a));return t},o=a(r?.header||{},e?.header||{});o.OrderHeaderID=r?.header?.OrderHeaderID||e?.header?.OrderHeaderID||o.OrderHeaderID||null;const i=e=>(e.OrderLineID||`${e.model||e.ItemCode}_${e.renk||e.ColorCode}_${e.renk2||e.ColorCode2}`).toString().toUpperCase(),n=new Map;for(const e of r?.lines||r?.orders||[])n.set(i(e),{...e,_src:"backend"});for(const r of e?.orders||[]){const e=i(r);if(n.has(e)){const o=a(n.get(e),r);o._src=t?"local":"backend",n.set(e,o)}else n.set(e,{...r,_src:"local-only"})}const d=Array.from(n.values());console.log(`🧩 mergeOrders → ${d.length} satır birleşti (ID:${o.OrderHeaderID})`);const l=e=>{if(!e)return null;const r=(0,s["default"])(e);return r.isValid()?r.format("YYYY-MM-DD HH:mm:ss"):null},c=e=>{if(!e)return null;const r=(0,s["default"])(e);return r.isValid()?r.format("YYYY-MM-DD"):null},u=e=>{if(!e)return null;const r=(0,s["default"])(e);return r.isValid()?r.format("HH:mm:ss"):null};return o.CreatedDate=l(o.CreatedDate),o.LastUpdatedDate=l(o.LastUpdatedDate),o.CreditableConfirmedDate=l(o.CreditableConfirmedDate),o.OrderDate=c(o.OrderDate),o.OrderTime=u(o.OrderTime),{header:o,orders:d}},markRowSource(e){return"local-only"===e._src?"🟠 Offline":"local"===e._src?"🔵 Local":"⚪ Backend"},mergeAndPersistBackendOrder(e,r){const t=`bss_orderentry_data:${e}`,a=JSON.parse(localStorage.getItem(t)||"null"),o=this.mergeOrders(a,r,!0);localStorage.setItem(t,JSON.stringify({...o,source:"db",mode:"edit",updatedAt:(new Date).toISOString()})),console.log(`💾 mergeAndPersistBackendOrder → ${e} localStorage’a yazıldı`)},persistLocalStorage(){try{if(this.preventPersist||this._uiBusy)return;const e={mode:this.mode,header:(0,i.ux)(this.header||{}),orders:(0,i.ux)(this.orders||[]),summaryRows:(0,i.ux)(this.summaryRows||[]),updatedAt:(new Date).toISOString()};if("new"===this.mode)return localStorage.setItem(this.getDraftKey,JSON.stringify(e)),void this.setActiveNewHeader?.(this.header?.OrderHeaderID);if("edit"===this.mode){const r=this.getEditKey;if(!r)return;localStorage.setItem(r,JSON.stringify(e))}}catch(e){console.warn("persistLocalStorage error:",e)}},clearEditSnapshotIfExists(){if("edit"!==this.mode)return;const e=this.getEditKey;e&&(localStorage.removeItem(e),console.log("🧹 EDIT snapshot silindi:",e))},_persistFingerprint(){const e=JSON.stringify(this.orders||[]),r=this.header||{},t=JSON.stringify({OrderHeaderID:r.OrderHeaderID||"",OrderNumber:r.OrderNumber||"",CurrAccCode:r.CurrAccCode||"",DocCurrencyCode:r.DocCurrencyCode||"",ExchangeRate:r.ExchangeRate??null}),a=Array.isArray(this.summaryRows)?this.summaryRows:[],o=JSON.stringify({len:a.length,keys:a.map(e=>this.getRowKey?.(e)||e?.key||e?.id||"").filter(Boolean)}),s=JSON.stringify({lineIdMap:this.lineIdMap||null,comboLineIds:this.comboLineIds||null,comboLineIdMap:this.comboLineIdMap||null,comboLineIdSet:this.comboLineIdSet?Array.from(this.comboLineIdSet):null}),i=String(this.mode||"new");return`${i}|${t}|${o}|${s}|${e}`},_safePersistDebounced(e=1200){clearTimeout(this._persistTimeout),this._persistTimeout=setTimeout(()=>{try{if(this.preventPersist)return;if(this._uiBusy)return;const e=this._persistFingerprint();if(e===this._lastPersistFingerprint)return;this._lastPersistFingerprint=e,this.persistLocalStorage(),console.log(`🕒 Otomatik LocalStorage senkron (${this.orders?.length||0} satır).`)}catch(e){console.warn("⚠️ Debounce persist hata:",e)}},e)},async fetchMinPrice(e,r,t){try{const t=await o.Ay.get("/min-price",{params:{model:e,currency:r}}),a=t?.data||{};return console.log("💰 [store.fetchMinPrice] yanıt:",a),{price:Number(a.price||0),rateToTRY:Number(a.rateToTRY||1),priceTRY:Number(a.priceTRY||0)}}catch(e){return console.error("❌ [store.fetchMinPrice] Min fiyat alınamadı:",e),t?.notify?.({type:"warning",message:"Min. fiyat bilgisi alınamadı, kontrol atlandı ⚠️",position:"top-right"}),{price:0,rateToTRY:1,priceTRY:0}}},applyCurrencyToLines(e){e&&(this.header&&(this.header.DocCurrencyCode=e,this.header.PriceCurrencyCode=e),Array.isArray(this.orders)&&(this.orders=this.orders.map(r=>({...r,pb:e,DocCurrencyCode:e,PriceCurrencyCode:e}))),Array.isArray(this.summaryRows)&&(this.summaryRows=this.summaryRows.map(r=>({...r,pb:e,DocCurrencyCode:e,PriceCurrencyCode:e}))),this.updateHeaderTotals?.())},setHeaderFields(e,r={}){const{applyCurrencyToLines:t=!1,immediatePersist:a=!1}=r;this.header={...this.header||{},...e},t&&Array.isArray(this.summaryRows)&&(this.summaryRows=this.summaryRows.map(r=>({...r,pb:e.DocCurrencyCode??r.pb,DocCurrencyCode:e.DocCurrencyCode??r.DocCurrencyCode,PriceCurrencyCode:e.PriceCurrencyCode??e.DocCurrencyCode??r.PriceCurrencyCode}))),this.orders=[...this.summaryRows],a&&this.persistLocalStorage("header-change")},applyHeaderCurrencyToOrders(){if(!Array.isArray(this.orders))return;const e=this.header?.DocCurrencyCode??null,r=this.header?.PriceCurrencyCode??null,t=this.header?.PriceExchangeRate??null;let a=0;for(const o of this.orders)e&&(o.DocCurrencyCode=e),r&&(o.PriceCurrencyCode=r),null!=t&&(o.PriceExchangeRate=t),a++;console.log(`💱 ${a} satırda PB güncellendi → Doc:${e} Price:${r} Rate:${t}`)},saveSnapshot(e="snapshot"){try{const r=this.header?.OrderHeaderID;if(!r)return;const t=`bss_orderentry_snapshot:${r}`,a={tag:e,mode:this.mode,orders:(0,i.ux)(this.orders||[]),header:(0,i.ux)(this.header||{}),savedAt:(0,s["default"])().toISOString()};localStorage.setItem(t,JSON.stringify(a)),console.log(`📸 Snapshot kaydedildi [${t}]`)}catch(e){console.warn("⚠️ saveSnapshot hata:",e)}},loadFromStorage(e=!1){try{const r=localStorage.getItem(this.getPersistKey);if(!r)return console.info("ℹ️ LocalStorage boş, grid başlatılmadı."),!1;if(!e&&"edit"===this.mode)return console.info("⚠️ Edit modda local restore atlandı (force=false)."),!1;const t=JSON.parse(r);return this.orders=Array.isArray(t.orders)?t.orders:[],this.header=t.header||{},this.currentOrderId=t.currentOrderId||null,this.selectedCustomer=t.selectedCustomer||null,this.header.OrderHeaderID=t.header?.OrderHeaderID||null,this.mode=t.mode||"new",this.lastSavedAt=t.savedAt||null,console.log(`♻️ Storage yüklendi • txn:${this.header.OrderHeaderID} (${this.orders.length} satır)`),this.applyHeaderCurrencyToOrders(),this._safePersistDebounced(200),t}catch(e){return console.warn("⚠️ localStorage okuma hatası:",e),!1}},clearStorage(){try{localStorage.removeItem(this.getPersistKey),console.log(`🗑️ LocalStorage temizlendi [${this.getPersistKey}]`)}catch(e){console.warn("⚠️ clearStorage hatası:",e)}},clearNewDraft(){localStorage.removeItem(this.getDraftKey),localStorage.removeItem("bss_last_txn"),console.log("🧹 NEW taslak temizlendi")},isSameCombo(e,r){if(!e||!r)return!1;const t=e=>null==e?"":String(e).trim().toUpperCase(),a={model:t(e.model),renk:t(e.renk),renk2:t(e.renk2)},o={model:t(r.model),renk:t(r.renk),renk2:t(r.renk2)};if(!a.model||!o.model)return!1;const s=a.renk===o.renk||!a.renk||!o.renk,i=a.renk2===o.renk2||!a.renk2||!o.renk2;return a.model===o.model&&s&&i},async saveOrUpdateRowUnified({form:e,recalcVat:r=null,resetEditor:t=null,stockMap:a=null,loadProductSizes:o=null,$q:i=null}){try{console.log("🔥 saveOrUpdateRowUnified v6.6",{model:e?.model,mode:this.mode,editingKey:this.editingKey});const n="function"===typeof this.getRowKey?this.getRowKey:e=>e?.clientKey||e?.id||e?.OrderLineID,d=Array.isArray(this.summaryRows)?[...this.summaryRows]:[];if(!e?.model)return i?.notify?.({type:"warning",message:"Model seçiniz"}),!1;e.pb||(e.pb=this.header?.DocCurrencyCode||"USD");try{"function"===typeof this.loadProductSizes&&await this.loadProductSizes(e,!0,i)}catch(e){console.warn("⚠ this.loadProductSizes hata:",e)}try{"function"===typeof o&&await o(!0)}catch(e){console.warn("⚠ loadProductSizes hata:",e)}const l=a?.value||a||{},c=e.bedenLabels||[],u=e.bedenler||[],m=[];for(let e=0;e0&&a>t&&m.push({beden:r,stok:t,girilen:a})}if(m.length&&i){const e=m.map(e=>`• ${e.beden}: ${e.girilen} (Stok: ${e.stok})`).join("
"),r=await new Promise(r=>{i.dialog({title:"Stok Uyarısı",message:`Bazı bedenlerde stoktan fazla giriş yaptınız:

${e}`,html:!0,ok:{label:"Devam",color:"primary"},cancel:{label:"İptal",color:"negative"}}).onOk(()=>r(!0)).onCancel(()=>r(!1)).onDismiss(()=>r(!1))});if(!r)return!1}let h=!0;try{let r=0;if("function"===typeof this.fetchMinPrice){const t=await this.fetchMinPrice(e.model,e.pb,i);r=Number(t?.price||0)}else Number(e.minFiyat||0)>0&&(r=Number(e.minFiyat));const t=Number(e.fiyat||0);r>0&&t>0&&t{i.dialog({title:"Fiyat Uyarısı",message:`Min. Fiyat: ${r} ${e.pb}
Girdiğiniz: ${t} ${e.pb}`,html:!0,ok:{label:"Devam",color:"primary"},cancel:{label:"İptal",color:"negative"}}).onOk(()=>a(!0)).onCancel(()=>a(!1)).onDismiss(()=>a(!1))}))}catch(e){console.warn("⚠ Min fiyat hata:",e)}if(!h)return!1;const y=(e.bedenler||[]).reduce((e,r)=>e+Number(r||0),0);e.adet=y,e.tutar=Number((y*Number(e.fiyat||0)).toFixed(2));const p=k(e);if(this.editingKey){const e=d.findIndex(e=>n(e)===this.editingKey);if(-1===e)return this.editingKey=null,t?.(!0),!1;const a=d[e];if(this.isRowLocked?.(a))return i?.notify?.({type:"warning",message:"Satır kapalı"}),this.editingKey=null,t?.(!0),!1;const o=this.isSameCombo(a,p),s=a?.lineIdMap&&"object"===typeof a.lineIdMap?{...a.lineIdMap}:p?.lineIdMap&&"object"===typeof p.lineIdMap?{...p.lineIdMap}:{};if(o)return d[e]={...a,...p,id:a.id,OrderLineID:a.OrderLineID||null,lineIdMap:s},this.summaryRows=d,this.orders=d,this.updateHeaderTotals?.(),this.persistLocalStorage?.(),this.editingKey=null,t?.(!0),r?.(),i?.notify?.({type:"positive",message:"Satır güncellendi"}),!0;const l=a?.grpKey||Object.keys(a?.bedenMap||{})[0]||"tak",c={},u=a?.bedenMap?.[l]&&"object"===typeof a.bedenMap[l]?a.bedenMap[l]:s&&"object"===typeof s?s:null;if(u)for(const e of Object.keys(u))c[e]=0;else c["STD"]=0;const m={...a,id:`DEL::${a.id||a.OrderLineID||crypto.randomUUID()}`,_deleteSignal:!0,adet:0,Qty1:0,tutar:0,ComboKey:"",OrderLineID:a.OrderLineID||null,grpKey:l,bedenMap:{[l]:c},lineIdMap:s,comboLineIds:{...a.comboLineIds||{}}},h={...p,id:crypto.randomUUID(),OrderLineID:null,lineIdMap:{}};return d.splice(e,1,h),this.summaryRows=d,this.orders=[...d,m],this.updateHeaderTotals?.(),this.persistLocalStorage?.(),this.editingKey=null,t?.(!0),r?.(),i?.notify?.({type:"positive",message:"Kombinasyon değişti"}),!0}const g=d.findIndex(e=>!e?._deleteSignal&&this.isSameCombo(e,p)),b=e=>{const r=e?.grpKey||Object.keys(e?.bedenMap||{})[0]||"GENEL",t=e?.bedenMap?.[r],a=e?.bedenMap&&"object"===typeof e.bedenMap&&!t?e.bedenMap:null;return{grpKey:r,map:t||a||{}}};if(-1!==g){const e=d[g];if(!0!==e?._deleteSignal){const{grpKey:a,map:o}=b(e),{grpKey:n,map:l}=b(p),c=p?.grpKey||a||n||"GENEL",u={...o||{}};for(const[e,r]of Object.entries(l||{})){const t=null==e||""===String(e).trim()?" ":O(String(e));u[t]=Number(u[t]||0)+Number(r||0)}const m=Object.values(u).reduce((e,r)=>e+Number(r||0),0),h=Number(p?.fiyat??e?.fiyat??0),y=Number((m*h).toFixed(2));return d[g]={...e,...p,id:e.id,OrderLineID:e.OrderLineID||null,lineIdMap:{...e.lineIdMap||{}},grpKey:c,bedenMap:{[c]:u},adet:m,tutar:y,updatedAt:(0,s["default"])().toISOString()},this.summaryRows=d,this.orders=d,this.updateHeaderTotals?.(),this.persistLocalStorage?.(),t?.(!0),r?.(),i?.notify?.({type:"positive",message:"Aynı kombinasyon bulundu, bedenler birleştirildi"}),!0}}return d.push({...p,id:p.id||crypto.randomUUID(),OrderLineID:null,lineIdMap:{...p.lineIdMap||{}}}),this.summaryRows=d,this.orders=d,this.updateHeaderTotals?.(),this.persistLocalStorage?.(),t?.(!0),r?.(),i?.notify?.({type:"positive",message:"Yeni satır eklendi"}),!0}catch(e){return console.error("❌ saveOrUpdateRowUnified:",e),i?.notify?.({type:"negative",message:"Satır kaydı başarısız"}),!1}},setTransaction(e,r=!0){if(e&&(this.header.OrderHeaderID=e,localStorage.setItem("bss_last_txn",e),console.log("🔄 Transaction değiştirildi:",e),r)){const r=Array.isArray(this.orders)&&this.orders.length>0;if(r)console.log("🚫 Grid dolu, auto-resume atlandı (mevcut satırlar korundu).");else{const r=this.hydrateFromLocalStorage(e,!0);r&&console.info("📦 Local kayıt geri yüklendi (boş grid için).")}}},clearTransaction(){try{const e=this.header?.OrderHeaderID;e&&localStorage.removeItem(`bss_orderentry_data:${e}`),this.orders=[],this.summaryRows=[],this.groupedRows=[],this.header={},this.mode="new",localStorage.removeItem("bss_last_txn"),console.log("🧹 Transaction temizlendi")}catch(e){console.warn("⚠️ clearTransaction hata:",e)}},isRowLocked(e){return!!e&&("edit"===this.mode&&!!e.OrderLineID&&!0===e.isClosed)},findExistingIndexByForm(e){return this.orders.findIndex(r=>this.isSameCombo(r,e))},addRow(e){if(!e)return;const r=this.orders.findIndex(r=>{const t=r.id&&e.id&&r.id===e.id,a=this.isSameCombo(r,e);return t||a});if(-1!==r){const t=this.orders[r];this.orders[r]={...t,adet:Number(e.adet??t.adet??0),fiyat:Number(e.fiyat??t.fiyat??0),tutar:Number(e.fiyat??t.fiyat??0)*Number(e.adet??t.adet??0),ItemDim1Code:e.ItemDim1Code||t.ItemDim1Code,aciklama:e.aciklama||t.aciklama,updatedAt:(0,s["default"])().toISOString()},console.log(`⚠️ Aynı kombinasyon bulundu, satır güncellendi: ${e.model} ${e.renk||""} ${e.renk2||""}`)}else this.orders.push((0,i.ux)(e)),console.log(`➕ Yeni kombinasyon eklendi: ${e.model} ${e.renk||""} ${e.renk2||""}`);this.persistLocalStorage(),this.saveSnapshot("after-add")},updateRow(e,r){e<0||e>=this.orders.length||(this.orders[e]={...this.orders[e],...(0,i.ux)(r),updatedAt:(0,s["default"])().toISOString()},this.persistLocalStorage(),this.saveSnapshot("after-update"),console.log(`✏️ Satır güncellendi (store): #${e}`))},removeRow(e){if(e<0||e>=this.orders.length)return;const r=this.orders.splice(e,1);Array.isArray(this.summaryRows)&&this.summaryRows.splice(e,1),this.persistLocalStorage(),this.saveSnapshot("after-remove"),console.log(`🗑️ Satır silindi: ${r[0]?.model||"(model yok)"}`)},removeSelectedRow(e,r=null){if(e)return this.isRowLocked(e)?(r?.notify?.({type:"warning",message:"🔒 Bu satır (IsClosed=1) kapatılmış. Silinemez."}),!1):new Promise(t=>{r?.dialog({title:"Satır Sil",message:`${e.model} / ${e.renk} / ${e.renk2} kombinasyonu silinsin mi?`,ok:{label:"Evet",color:"negative"},cancel:{label:"Vazgeç"}}).onOk(()=>{this.removeRowInternal(e),t(!0)}).onCancel(()=>t(!1))})},removeRowInternal(e){if(!e)return!1;if(this.isRowLocked(e))return console.warn("🔒 Kilitli satır silinemez."),!1;const r="function"===typeof this.getRowKey?this.getRowKey:e=>e?.clientKey||e?.id||e?.OrderLineID,t=r(e);if(!t)return!1;const a=this.summaryRows.findIndex(e=>r(e)===t);if(-1===a)return!1;console.log("🗑️ X2 removeRowInternal →",e),this._uiBusy=!0,this.preventPersist=!0;try{if(this.summaryRows.splice(a,1),this.orders=[...this.summaryRows],"edit"===this.mode){const r=e.grpKey||Object.keys(e.bedenMap||{})[0]||"tak",t=e.lineIdMap&&"object"===typeof e.lineIdMap?{...e.lineIdMap}:{},a={};if(e.bedenMap&&e.bedenMap[r])for(const t of Object.keys(e.bedenMap[r]||{}))a[t]=0;else if(Object.keys(t).length)for(const e of Object.keys(t))a[e]=0;else a["STD"]=0;const o={...e,id:`DEL::${e.id||e.OrderLineID||crypto.randomUUID()}`,adet:0,Qty1:0,tutar:0,ComboKey:"",OrderLineID:e.OrderLineID||null,grpKey:r,bedenMap:{[r]:a},lineIdMap:t,comboLineIds:{...e.comboLineIds||{}},_deleteSignal:!0};console.log("📡 DELETE sinyali üretildi:",o),this.orders.push(o)}this.updateHeaderTotals?.()}finally{this.preventPersist=!1,this._uiBusy=!1}return this.persistLocalStorage(),!0},normalizeOrderLines(e,r="USD"){if(!Array.isArray(e))return[];const t=Object.create(null);for(const a of e){if(!a)continue;const e=!0===a.IsClosed||!0===a.isClosed||!0===a.IsClosed?.Bool;if(a.bedenMap&&Object.keys(a.bedenMap).length){const o=(a.model||a.ItemCode||"").trim(),s=(a.renk||a.ColorCode||"").trim(),i=(a.renk2||a.ItemDim2Code||"").trim(),n=`${o}||${s}||${i}`,d=a.grpKey||"tak",l=a.bedenMap[d]||{},c=Object.values(l).reduce((e,r)=>e+(Number(r)||0),0),u=Number(a.fiyat||0),m=a.pb||a.DocCurrencyCode||r,h=Number(a.tutar??c*u);t[n]??=[],t[n].push({...a,grpKey:d,bedenMap:{[d]:{...l}},adet:c,fiyat:u,pb:m,tutar:h,isClosed:e});continue}const o=(a.Model||a.ItemCode||"").trim(),s=(a.ColorCode||"").trim(),i=(a.ItemDim2Code||"").trim(),n=`${o}||${s}||${i}`;t[n]??=[];const d=null==a.ItemDim1Code?"":String(a.ItemDim1Code).trim(),l=""===d?" ":O(d),c=Number(a.Qty1||a.Qty||0);let u=t[n][0];u||(u={id:a.OrderLineID||crypto.randomUUID(),model:o,renk:s,renk2:i,urunAnaGrubu:a.UrunAnaGrubu||"GENEL",urunAltGrubu:a.UrunAltGrubu||"",kategori:a.Kategori||"",aciklama:a.LineDescription||"",fiyat:Number(a.Price||0),pb:a.DocCurrencyCode||r,__tmpMap:{},lineIdMap:{},adet:0,tutar:0,terminTarihi:a.DeliveryDate||null,isClosed:e},t[n].push(u));const m=a.OrderLineID||a.OrderLineId||a.orderLineID||null;m&&(u.lineIdMap[l]=String(m)),c>0&&(u.__tmpMap[l]=(u.__tmpMap[l]||0)+c,u.adet+=c,u.tutar+=c*u.fiyat)}const a=[];for(const e of Object.values(t))for(const r of e){if(!r.__tmpMap){a.push(r);continue}const e=Object.keys(r.__tmpMap),t=w(e,r.urunAnaGrubu,r.kategori),o={...r.__tmpMap},s=Object.keys(o).some(e=>""!==String(e).trim());"aksbir"!==t&&s&&(delete o[" "],delete o[""],r.lineIdMap&&"object"===typeof r.lineIdMap&&(delete r.lineIdMap[" "],delete r.lineIdMap[""])),r.grpKey=t,r.bedenMap={[t]:{...o}},r.adet=Object.values(o).reduce((e,r)=>e+(Number(r)||0),0),r.tutar=Number((r.adet*Number(r.fiyat||0)).toFixed(2)),"aksbir"===t&&(r.bedenMap[t]??={},r.bedenMap[t][" "]=Number(r.adet||0)),delete r.__tmpMap,a.push(r)}return console.log(`📦 normalizeOrderLines (v9 + lineIdMap) → ${a.length} satır`),a},async loadProductSizes(e,r=!1,t=null){if(!e?.model)return;const a=this,s=!!a._uiBusy,i=!!a.preventPersist;a._uiBusy=!0,a.preventPersist=!0;try{const t=e.grpKey;if(!t)return void console.warn("⛔ loadProductSizes iptal → grpKey yok");const a=e.renk||"nocolor",s=e.renk2||"no2color",i=`${e.model}_${a}_${s}_${t}`;if(!r&&g.value?.[i]){const e=g.value[i];return p.value=[...e.stockArray],y.value={...e.stockMap},void console.log(`♻️ loadProductSizes CACHE → ${t}`)}const n={code:e.model};e.renk&&(n.color=e.renk),e.renk2&&(n.color2=e.renk2);const d=await o.Ay.get("/product-colorsize",{params:n}),l=Array.isArray(d?.data)?d.data:[];if(!l.length)return p.value=[],void(y.value={});const c={};for(const e of l){const r=null===e.item_dim1_code||""===e.item_dim1_code?" ":String(e.item_dim1_code);c[r]=Number(e.kullanilabilir_envanter??0)}const u={};for(const r of e.bedenLabels)u[r]=c[r]??0;y.value={...u},p.value=Object.entries(y.value).map(([e,r])=>({beden:e,stok:r})),g.value[i]={labels:[...e.bedenLabels],stockArray:[...p.value],stockMap:{...y.value}},console.log(`✅ loadProductSizes FINAL v4.2 → ${t}`)}catch(e){console.error("❌ loadProductSizes hata:",e),t?.notify?.({type:"negative",message:"Beden / stok alınamadı"})}finally{a._uiBusy=s,a.preventPersist=i,console.log("🧩 Editor beden hydrate",{grpKey:e.grpKey,labels:e.bedenLabels,values:e.bedenler})}},updateTotals(e){e.adet=(e.bedenler||[]).reduce((e,r)=>e+Number(r||0),0);const r=Number(e.fiyat)||0;if(e.tutar=Number((e.adet*r).toFixed(2)),this.header){const e=(this.summaryRows||[]).reduce((e,r)=>e+Number(r?.tutar||0),0);this.header.TotalAmount=Number(e.toFixed(2))}return e},activeGroupKeyForRow(e){const r=(e?.urunAnaGrubu||"").toUpperCase();return r.includes("TAKIM")?"tak":r.includes("PANTOLON")?"pan":r.includes("GOMLEK")?"gom":r.includes("AYAKKABI")?"ayk":r.includes("YAS")?"yas":"tak"},setMode(e){["new","edit","view"].includes(e)?(this.mode=e,console.log(`🧭 Order mode set edildi → ${e}`)):console.warn("⚠️ Geçersiz mode:",e)},async submitAllReal(e,r,t,a,s){let i=null,n=null;try{this.loading=!0,this.isControlledSubmit=!0;const d="new"===this.mode,{header:l,lines:c}=this.buildFinalOrderJson();console.groupCollapsed(`%c📤 ORDER PAYLOAD (${this.mode})`,"color:#c9a873;font-weight:bold"),console.log("HEADER:",JSON.parse(JSON.stringify(l))),c.forEach((e,r)=>{console.log(`LINE[${r}]`,{OrderLineID:e.OrderLineID,ClientKey:e.ClientKey,ItemCode:e.ItemCode,ColorCode:e.ColorCode,ItemDim1Code:e.ItemDim1Code,ItemDim2Code:e.ItemDim2Code,ItemDim3Code:e.ItemDim3Code,Qty1:e.Qty1,ComboKey:e.ComboKey})}),console.groupEnd(),this.debugOrderPayload?.(l,c,"PRE-VALIDATE");const u=e=>Number((Number(e)||0).toFixed(2)),m=e=>Number((Number(e)||0).toFixed(4));for(const e of c){const r=Number(e?.Qty1||0),t=Number(e?.Price||0),a=Number(e?.VatRate||0),o=Number(e?.PriceExchangeRate||l?.ExchangeRate||1)||1,s=u(t*r),i=u(s*a/100),n=u(s+i),d=m(r>0?n/r:t*(1+a/100)),c=String(e?.DocCurrencyCode||l?.DocCurrencyCode||"TRY").trim()||"TRY";e.RelationCurrencyCode=c,e.DocPrice=d,e.DocAmount=n,e.LocalPrice=t,e.LocalAmount=s,e.LineDiscount=Number(e?.LineDiscount||0),e.TotalDiscount=Number(e?.TotalDiscount||0),e.TaxBase=s,e.Pct=Number(e?.Pct||0),e.VatAmount=i,e.VatDeducation=0,e.NetAmount=n,e.CurrencyCode=c,e.ExchangeRate=o,e.PriceVI=d,e.AmountVI=n,e.Amount=s,e.LDiscount1=Number(e?.LDiscount1||0),e.TDiscount1=Number(e?.TDiscount1||0),e.Vat=i}const h=await o.Ay.post("/order/validate",{header:l,lines:c}),y=h?.data?.invalid||[];if(y.length>0)return void await(this.showInvalidVariantDialog?.(e,y));console.log("📤 submitAllReal payload",{mode:this.mode,lines:c.length,deletes:c.filter(e=>e._deleteSignal).length});const p=await o.Ay.post(d?"/order/create":"/order/update",{header:l,lines:c}),g=p?.data||{};if(i=g.orderID||g.orderHeaderID||g.id||l?.OrderHeaderID,n=g.orderNumber||g.orderNo||l?.OrderNumber,!i)throw new Error("OrderHeaderID backend’den dönmedi");this.setMode("edit"),this.header={...this.header,OrderHeaderID:i,OrderNumber:n},this.updateHeaderTotals?.(),this.markAsSaved?.(),this.clearAllOrderSnapshots(),e.notify({type:"positive",message:`Sipariş kaydedildi: ${n||""}`.trim()}),this.allowRouteLeaveOnce=!0,await r.replace({name:"order-entry",params:{orderHeaderID:i},query:{mode:"edit",source:"backend"}}),await this.openExistingForEdit(i,{$q:e,form:t,summaryRowsRef:a,productCache:s});const b=await new Promise(r=>{e.dialog({title:"Sipariş Kaydedildi",options:{type:"radio",model:"continue",items:[{label:"✏️ Düzenlemeye Devam",value:"continue"},{label:"🖨 Yazdır",value:"print"},{label:"📋 Listeye Dön",value:"list"}]},ok:{label:"Seç"},cancel:{label:"Kapat"}}).onOk(e=>r(e)).onCancel(()=>r("continue"))});if("print"===b){const r=this.header?.OrderHeaderID||i;if(r)try{await this.downloadOrderPdf(r)}catch(r){console.error("⚠️ PDF açılamadı, kayıt başarılı:",r),e.notify({type:"warning",message:r?.message||"Sipariş kaydedildi fakat PDF açılamadı."})}return}if("list"===b)return this.allowRouteLeaveOnce=!0,void await r.push({name:"order-list"})}catch(r){console.error("❌ submitAllReal:",r),e.notify({type:"negative",message:r?.response?.data?.detail||r?.response?.data?.message||r?.message||"Kayıt sırasında hata"})}finally{this.isControlledSubmit=!1,this.loading=!1}},async submitAllTest(e=null){try{const{header:r,lines:t}=this.buildFinalOrderJson();console.log("🧾 TEST HEADER",Object.keys(r).length,"alan"),console.log(JSON.stringify(r,null,2)),console.log("🧾 TEST LINES",t.length,"satır"),console.log(JSON.stringify(t,null,2)),e?.notify?.({type:"info",message:`Header (${Object.keys(r).length}) + Lines (${t.length}) gösterildi`,position:"top"})}catch(r){console.error("❌ submitAllTest hata:",r),e?.notify?.({type:"negative",message:"Gösterimde hata oluştu ❌",position:"top"})}},afterSubmit(e={keepLocalStorage:!0,backendPayload:null,resetMode:!0}){try{console.log("🧹 afterSubmit başlatıldı",e),e?.backendPayload?.header?.OrderHeaderID&&this.mergeAndPersistBackendOrder(e.backendPayload.header.OrderHeaderID,e.backendPayload),e?.keepLocalStorage?this.saveSnapshot():(this.clearStorage(),this.clearTransaction()),this.orders=[],this.header={},this.editingKey=null,this.currentOrderId=null,!0===e.resetMode&&(this.mode="new"),console.log("✅ afterSubmit tamamlandı.")}catch(e){console.error("❌ afterSubmit hata:",e)}},buildFinalOrderJson(){const e=(0,n.n)(),r=e?.user||{},t=(0,s["default"])(),a=e=>Number(e)||0,o=e=>null==e?"":String(e).trim(),i=e=>e?(0,s["default"])(e).format("YYYY-MM-DD"):null,d=e=>(0,s["default"])(e).format("HH:mm:ss"),l=e=>e?(0,s["default"])(e).format("YYYY-MM-DD HH:mm:ss"):null,c=e=>{const r=o(e);return""===r||"_"===r||"-"===r?"":r},m=o(r?.v3usergroup),h=o(r?.v3_username),y=m&&h?`${m} ${h}`:h||"BSS",p="%0",g="%0",b=this.header?.OrderHeaderID||crypto.randomUUID(),D=o(this.header?.DocCurrencyCode)||"TRY",I=a(this.header?.ExchangeRate)||1,C=this.header?.AverageDueDate||(0,s["default"])(this.header?.OrderDate||t).add(14,"day"),S={...this.header,OrderHeaderID:b,OrderDate:i(this.header?.OrderDate||t),OrderTime:d(t),AverageDueDate:i(C),DocCurrencyCode:D,LocalCurrencyCode:o(this.header?.LocalCurrencyCode)||"TRY",ExchangeRate:I,CreatedUserName:"edit"===this.mode&&this.header?.CreatedUserName||y,CreatedDate:"edit"===this.mode?l(this.header?.CreatedDate||t):l(t),LastUpdatedUserName:y,LastUpdatedDate:l(t)},O=[],w=new Map,k=(e,r)=>{const{grpKey:s,bedenKey:n,bedenPayload:d,qty:c,orderLineId:m,isDeleteSignal:h}=r;if(c<=0&&!h)return;const D=u(e,n),I=()=>({OrderLineID:m||"",ClientKey:f(e,s,n),ComboKey:D,SortOrder:0,ItemTypeCode:1,ItemCode:o(e.model),ColorCode:o(e.renk),ItemDim1Code:d,ItemDim2Code:o(e.renk2),ItemDim3Code:"",Qty1:h?0:c,Qty2:0,CancelQty1:0,CancelQty2:0,DeliveryDate:e.terminTarihi?l(e.terminTarihi):null,PlannedDateOfLading:e.terminTarihi?i(e.terminTarihi):null,LineDescription:o(e.aciklama),UsedBarcode:"",CostCenterCode:"",VatCode:g,VatRate:a(e.vatRate??e.VatRate??0),PCTCode:p,PCTRate:0,LDisRate1:0,LDisRate2:0,LDisRate3:0,LDisRate4:0,LDisRate5:0,DocCurrencyCode:S.DocCurrencyCode,PriceCurrencyCode:S.DocCurrencyCode,PriceExchangeRate:a(S.ExchangeRate),Price:a(e.fiyat),BaseProcessCode:"WS",BaseOrderNumber:S.OrderNumber,BaseCustomerTypeCode:0,BaseCustomerCode:S.CurrAccCode,BaseSubCurrAccID:null,BaseStoreCode:"",OrderHeaderID:b,CreatedUserName:y,CreatedDate:l(e.CreatedDate||t),LastUpdatedUserName:y,LastUpdatedDate:l(t),SurplusOrderQtyToleranceRate:0,WithHoldingTaxTypeCode:"",DOVCode:""}),C=w.get(D);if(!C){const e=I();return w.set(D,e),void O.push(e)}if(h)return m&&!C.OrderLineID&&(C.OrderLineID=m),void(C.Qty1=0);C.Qty1+=c,"edit"===this.mode&&m&&!C.OrderLineID&&(C.OrderLineID=m),C.Price=a(e.fiyat)};for(const e of this.orders||[]){if(!0===e?.isClosed)continue;const r=e.grpKey||Object.keys(e.bedenMap||{})[0]||"GENEL",t=e.lineIdMap||{},s=e.bedenMap?.[r],i=e.bedenMap&&"object"===typeof e.bedenMap&&!s?e.bedenMap:null,n=s||i,d=n&&"object"===typeof n&&Object.keys(n).length>0;if(!d){const s="aksbir"===r||!0===e._deleteSignal;if(!s)continue;const i=a(e.qty??e.Qty1??e.miktar??0),n="_",d="";let l="";"edit"===this.mode&&(l=o(t?.[n])||o(t?.[d])||o(t?.[" "])||o(e.OrderLineID)),k(e,{grpKey:r,bedenKey:n,bedenPayload:d,qty:i,orderLineId:l,isDeleteSignal:!0===e._deleteSignal&&!!l});continue}for(const[s,i]of Object.entries(n)){const d=""===o(s);if(d&&"aksbir"!==r&&!0!==e._deleteSignal)continue;const l=a(i),u=c(s),m=u||"_";let h="";"edit"===this.mode&&(h=o(t?.[m])||o(t?.[u])||o(t?.[" "])||(1===Object.keys(n).length?o(e.OrderLineID):"")),k(e,{grpKey:r,bedenKey:m,bedenPayload:u,qty:l,orderLineId:h,isDeleteSignal:!0===e._deleteSignal&&!!h})}}if(O.forEach((e,r)=>{e.SortOrder=r+1}),O.some(e=>"_"===(e.ItemDim1Code||"")))throw console.error('❌ Payload’da "_" yakalandı',O.filter(e=>"_"===e.ItemDim1Code)),new Error('Payload ItemDim1Code "_" olamaz');return console.groupCollapsed("%c📦 BUILD FINAL ORDER JSON","color:#c9a873;font-weight:bold"),console.log("🧾 HEADER:",S),console.table(O.map((e,r)=>({i:r+1,OrderLineID:e.OrderLineID,ClientKey:e.ClientKey,ComboKey:e.ComboKey,ItemCode:e.ItemCode,ColorCode:e.ColorCode,ItemDim1Code:JSON.stringify(e.ItemDim1Code),ItemDim2Code:e.ItemDim2Code,Qty1:e.Qty1,Price:e.Price}))),console.groupEnd(),{header:S,lines:O}},setRowErrorByClientKey(e,r){if(!e)return;if(!Array.isArray(this.summaryRows))return;const t=this.summaryRows.find(r=>r?.clientKey===e);t&&(t._error={code:r?.code,message:r?.message})},clearRowErrorByClientKey(e){if(!e)return;if(!Array.isArray(this.summaryRows))return;const r=this.summaryRows.find(r=>r?.clientKey===e);r&&r._error&&delete r._error},applyTerminToRowsIfEmpty(e){if(e&&Array.isArray(this.summaryRows)){for(const r of this.summaryRows)r?.terminTarihi&&""!==r.terminTarihi||(r.terminTarihi=e);this.persistLocalStorage?.()}}}});function I(e){return(null==e?"":String(e)).trim().toUpperCase()}function C(e){return I(e).normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function S(e){const r=I(e);if(""===r||!/^\d+$/.test(r))return null;const t=Number.parseInt(r,10);return Number.isNaN(t)?null:t}function O(e){let r=(null==e?"":String(e)).trim();if(""===r)return" ";switch(r=r.toUpperCase(),r){case"STD":case"STANDART":case"STANDARD":case"ONE SIZE":case"ONESIZE":return"STD"}if(r.endsWith("CM")){const e=r.slice(0,-2).trim();if(""!==e)return e}switch(r){case"XS":case"S":case"M":case"L":case"XL":case"2XL":case"3XL":case"4XL":case"5XL":case"6XL":case"7XL":return r}return r}function w(e,r="",t=""){const a=Array.isArray(e)?e:[],o=C(r),s=C(t),i=["AKSESUAR","KRAVAT","PAPYON","KEMER","CORAP","FULAR","MENDIL","KASKOL","ASKI","YAKA","KOL DUGMESI"],n=["GOMLEK","CEKET","PANTOLON","MONT","YELEK","TAKIM","TSHIRT"];if(i.some(e=>o.includes(e)||s.includes(e))&&!n.some(e=>o.includes(e)))return"aksbir";if(o.includes("AYAKKABI")||s.includes("AYAKKABI"))return"ayk";let d=!1,l=!1,c=!1;for(const e of a){const r=I(e);switch(r){case"XS":case"S":case"M":case"L":case"XL":case"2XL":case"3XL":case"4XL":case"5XL":case"6XL":case"7XL":return"gom"}const t=S(r);null!=t&&(t>=2&&t<=14&&(d=!0),t>=39&&t<=45&&(l=!0),t>=38&&t<=68&&(c=!0))}return l?"ayk":o.includes("PANTOLON")||c?"pan":s.includes("COCUK")||s.includes("GARSON")||d?"yas":"tak"}function k(e){if(!e)return null;const r=e.grpKey||"tak",t={},a=Array.isArray(e.bedenLabels)?e.bedenLabels:[],o=Array.isArray(e.bedenler)?e.bedenler:[];for(let e=0;e0&&(t[s]=i)}return{id:e.id||b(),OrderLineID:e.OrderLineID||null,model:e.model||"",renk:e.renk||"",renk2:e.renk2||"",urunAnaGrubu:e.urunAnaGrubu||"",urunAltGrubu:e.urunAltGrubu||"",aciklama:e.aciklama||"",fiyat:Number(e.fiyat||0),pb:e.pb||"USD",adet:Number(e.adet||0),tutar:Number(e.tutar||0),grpKey:r,bedenMap:{[r]:{...t}},terminTarihi:(e.terminTarihi||"").substring(0,10)}}}}]); \ No newline at end of file diff --git a/ui/dist/spa/js/chunk-common.ed7a624a.js.gz b/ui/dist/spa/js/chunk-common.ed7a624a.js.gz new file mode 100644 index 0000000..ab41d95 Binary files /dev/null and b/ui/dist/spa/js/chunk-common.ed7a624a.js.gz differ