PageSourceSearch

https://xynergy.ai/_next/static/chunks/9494.e4178eeb65f758ee.js

js xynergy.ai collected 2026-10-05 16:02:48 UTC 8,674 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9494],{25450:(e,t,a)=>{a.d(t,{A:()=>r});let r=(0,a(46775).A)("square-pen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]])},79494:(e,t,a)=>{a.r(t),a.d(t,{default:()=>C});var r=a(85047),n=a(31615),i=a(82520),s=a(21410),c=a(3208),d=a(866),l=a(96968),o=a(21582),u=a(18534),h=a(41178),x=a(54306),m=a(73521),y=a(24571),p=a(76458),j=a(15418),f=a(96774);let g=j.Ik({userId:j.Yj().min(1,"userId 不能為空"),accountId:j.Yj().min(1,"accountId 不能為空"),type:f.Z,amount:j.ai().positive("金額必須大於 0"),frequency:j.k5(["daily","weekly","monthly"]),startDate:j.Yj().regex(/^\d{4}-\d{2}-\d{2}$/,"日期格式必須為 YYYY-MM-DD"),endDate:j.Yj().regex(/^\d{4}-\d{2}-\d{2}$/,"日期格式必須為 YYYY-MM-DD").optional(),lastExecuted:j.Yj().regex(/^\d{4}-\d{2}$/,"月份格式必須為 YYYY-MM").optional(),nextExecution:j.Yj().regex(/^\d{4}-\d{2}$/,"月份格式必須為 YYYY-MM"),autoCreate:j.zM().default(!1),enabled:j.zM().default(!0),createdAt:j.bz(),updatedAt:j.bz().optional()}),v="recurring_transactions",w={async getRecurringTransactions(e){if(!p.db)throw Error("Firestore 尚未初始化");if(!e)throw Error("用戶 ID 未提供");let t=(0,y.P)((0,y.rJ)(p.db,v),(0,y._M)("userId","==",e));return(await (0,y.GG)(t)).docs.map(e=>({id:e.id,...e.data()}))},async addRecurringTransaction(e,t){if(!p.db)throw Error("Firestore 尚未初始化");if(!e)throw Error("用戶 ID 未提供");let a=y.Timestamp.now(),r={userId:e,...t,createdAt:a,updatedAt:a},n=g.parse(r),i=(0,y.doc)((0,y.rJ)(p.db,v));return await (0,y.setDoc)(i,n),i.id},async updateRecurringTransaction(e,t,a){if(!p.db)throw Error("Firestore 尚未初始化");if(!e)throw Error("用戶 ID 未提供");let r=(0,y.doc)(p.db,v,t),n=await (0,y.getDoc)(r);if(!n.exists())throw Error("定期交易不存在");if(n.data().userId!==e)throw Error("無權限修改此定期交易");let i=Object.prototype.hasOwnProperty.call(a,"endDate")&&void 0===a.endDate,{endDate:s,...c}=a,d={...c,...void 0!==s?{endDate:s}:{},updatedAt:y.Timestamp.now()},l={...g.partial().parse(d)};i&&(l.endDate=(0,y.CL)()),await (0,y.setDoc)(r,l,{merge:!0})},async deleteRecurringTransaction(e,t){if(!p.db)throw Error("Firestore 尚未初始化");if(!e)throw Error("用戶 ID 未提供");let a=(0,y.doc)(p.db,v,t),r=await (0,y.getDoc)(a);if(!r.exists())throw Error("定期交易不存在");if(r.data().userId!==e)throw Error("無權限刪除此定期交易");await (0,y.kd)(a)}};var b=a(12217),D=a(2687),I=a(18654),Y=a(42119),N=a(25450),E=a(54296);function C({type:e,requestOpenCreate:t}){let{toast:a}=(0,h.dj)(),{user:y,viewingUserId:p}=(0,m.A)(),j=p||y?.uid,[f,g]=(0,n.useState)([]),[v,k]=(0,n.useState)(!1),[q,M]=(0,n.useState)(null),[$,T]=(0,n.useState)([]),[A,S]=(0,n.useState)(!0),[R,J]=(0,n.use
1State)({accountId:"",type:"income",amount:"",frequency:"monthly",startDate:""});(0,n.useEffect)(()=>{j?(async()=>{try{let[t,a]=await Promise.all([w.getRecurringTransactions(j),b.W.getAllAccounts(j)]),r=e?t.filter(t=>t.type===e):t;g(r),T(a)}catch(e){(0,I.vV)("載入定期交易失敗:",e)}finally{S(!1)}})():S(!1)},[j,e]),(0,n.useEffect)(()=>{null==t||t<1||(J({accountId:"",type:e??"income",amount:"",frequency:"monthly",startDate:""}),M(null),k(!0))},[t,e]);let z=$.filter(e=>"income"===R.type?(0,D.Xd)(e.category):(0,D.I2)(e.category)),F=async()=>{if(!R.accountId||!R.amount||!R.startDate)return void a({title:"請填寫必填欄位",variant:"destructive"});if(j)try{let t=new Date,r=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}`,n={accountId:R.accountId,type:R.type,amount:Number(R.amount),frequency:R.frequency,startDate:R.startDate,nextExecution:r,endDate:void 0,autoCreate:!1,enabled:!0};q?(await w.updateRecurringTransaction(j,q,n),a({title:"已更新定期交易"})):(await w.addRecurringTransaction(j,n),a({title:"已建立定期交易"}));let i=await w.getRecurringTransactions(j),s=e?i.filter(t=>t.type===e):i;g(s),k(!1),M(null),J({accountId:"",type:e??"income",amount:"",frequency:"monthly",startDate:""})}catch(e){(0,I.vV)("儲存定期交易失敗:",e),a({title:"操作失敗",variant:"destructive"})}},_=async t=>{if(j&&confirm("確定要刪除此定期交易嗎?"))try{await w.deleteRecurringTransaction(j,t),a({title:"已刪除定期交易"});let r=await w.getRecurringTransactions(j),n=e?r.filter(t=>t.type===e):r;g(n)}catch(e){(0,I.vV)("刪除定期交易失敗:",e),a({title:"刪除失敗",variant:"destructive"})}},V=e=>{let t=(0,D.F$)(e.category);return`${e.name}(${t})`};return A?(0,r.jsx)(x.default,{size:64}):(0,r.jsxs)(i.Zp,{children:[(0,r.jsx)(i.aR,{children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(i.ZB,{children:"定期自動記帳"}),(0,r.jsx)(i.BT,{children:e?`設定定期${"income"===e?"收入":"支出"}規則,系統將建立待確認項目`:"設定定期交易規則,系統將建立待確認項目"})]}),(0,r.jsxs)(s.$,{onClick:()=>{J({accountId:"",type:e??"income",amount:"",frequency:"monthly",startDate:""}),M(null),k(!0)},children:[(0,r.jsx)(Y.A,{className:"h-4 w-4 mr-2"}),"新增規則"]})]})}),(0,r.jsx)(i.Wu,{children:0===f.length?(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:"尚未設定任何定期交易規則"}):(0,r.jsx)("div",{className:"space-y-2",children:f.map(e=>{let t=$.find(t=>t.id===e.accountId);return(0,r.jsxs)("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"font-medium",children:[t?V(t):"未知帳戶"," - ",e.amount.toLocaleString()," 元"]}),(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:["monthly"===e.frequency?"每月":"weekly"===e.frequency?"每週":"每日"," ","| 下次執行: ",e.nextExecution]})]}),(0,r.jsx)(c.j,{ariaLabel:"定期交易規則操作",items:[{id:"edit",label:"編輯",icon:N.A,onSelect:()=>{M(e.id),J({accountId:e.accountId,type:e.type,amount:e.amount.toString(),frequency:e.frequency,startDate:e.startDate}),k(!0)}},{id:"delete",label:"刪除",icon:E.A,destructive:!0,onSelect:()=>_(e.id)}]})]},e.id)})})}),(0,r.jsx)(u.lG,{open:v,onOpenChange:k,children:(0,r.jsxs)(u.Cf,{className:"sm:max-w-[500px]",children:[(0,r.jsxs)(u.c7,{children:[(0,r.jsx)(u.L3,{children:q?"編輯定期交易":"新增定期交易"}),(0,r.jsx)(u.rr,{children:"儲存後將依頻率與排程產生待確認記錄;確認後才會寫入流水帳。"})]}),(0,r.jsxs)("div",{className:"space-y-4",children:[!e&&(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(l.J,{children:"類型"}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(s.$,{type:"button",variant:"income"===R.type?"default":"outline",className:"flex-1",onClick:()=>J({...R,type:"income",accountId:""}),children:"收入"}),(0,r.jsx)(s.$,{type:"button",variant:"expense"===R.type?"default":"outline",className:"flex-1",onClick:()=>J({...R,type:"expense",accountId:""}),children:"支出"})]})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(l.J,{children:"帳戶"}),(0,r.jsxs)(o.l6,{value:R.accountId,onValueChange:e=>J({...R,accountId:e}),children:[(0,r.jsx)(o.bq,{children:(0,r.jsx)(o.yv,{placeholder:"請選擇帳戶"})}),(0,r.jsx)(o.gC,{children:z.map(e=>(0,r.jsx)(o.eb,{value:e.id,children:V(e)},e.id))})]})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(l.J,{children:"金額"}),(0,r.jsx)(d.p,{type:"number",min:0,value:R.amount,onChange:e=>J({...R,amount:e.target.value}),placeholder:"NT$"})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(l.J,{children:"頻率"}),(0,r.jsxs)(o.l6,{value:R.frequency,onValueChange:e=>J({...R,frequency:e}),children:[(0,r.jsx)(o.bq,{children:(0,r.jsx)(o.yv,{})}),(0,r.jsxs)(o.gC,{children:[(0,r.jsx)(o.eb,{value:"daily",children:"每日"}),(0,r.jsx)(o.eb,{value:"weekly",children:"每週"}),(0,r.jsx)(o.eb,{value:"monthly",children:"每月"})]})]})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(l.J,{children:"新增日/生效日"}),(0,r.jsx)(d.p,{type:"date",value:R.startDate,onChange:e=>J({...R,startDate:e.target.value})}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"用於規則生效與排程計算之基準日(YYYY-
1MM-DD)。"})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,r.jsx)(s.$,{variant:"outline",onClick:()=>k(!1),children:"取消"}),(0,r.jsx)(s.$,{onClick:F,children:q?"更新":"建立"})]})]})]})})]})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.