← Back
Editing: reports-balance-actions.js
"use strict";(globalThis.webpackChunkwoocommerce_payments=globalThis.webpackChunkwoocommerce_payments||[]).push([[1505],{2354(e,t,a){a.d(t,{BalanceActions:()=>b});var n=a(1609),o=a(6427),r=a(7143),s=a(1554),c=a(7723),l=a(8227),i=a(4137),u=a(4904),p=a(1983),d=a(4022),m=a(7840),y=a(790);const _=(e,t,a)=>({currency:t,visible_row_count:a,range_days:(0,m.PM)(e.start,e.end)}),w=e=>e instanceof Error?e.message.slice(0,200):"unknown",b=()=>{const{period:e,hasDateFilterValue:t}=(0,p.yR)(),{createNotice:a}=(0,r.useDispatch)("core/notices"),{summary:b,error:g={},isLoading:h}=(0,i.Np)(t?e:void 0,wcpaySettings.accountDefaultCurrency||""),v=(0,m.xV)(g),f=(0,u.k3)(b),k=(0,m.aO)(f,b),C=(0,m.yF)({summary:b,hasDateFilterValue:t,isLoading:h,hasStoreError:v}),D={start:b.period?.start??e.start,end:b.period?.end??e.end},S=b.currency??"",x=!t||h||v||C||!k,A=(0,n.useId)(),E=t?h?(0,c.__)("Print and Export are available once the Balance report finishes loading.","woocommerce-payments"):v||C?(0,c.__)("Print and Export are unavailable while the Balance report is unavailable.","woocommerce-payments"):k?"":(0,c.__)("Print and Export are unavailable when the selected range has no Balance activity.","woocommerce-payments"):(0,c.__)("Select a date range to enable Print and Export.","woocommerce-payments");return(0,y.jsxs)("div",{className:"wcpay-reports-balance-actions",children:[x&&(0,y.jsx)("span",{id:A,className:"screen-reader-text",children:E}),(0,y.jsx)(o.Button,{variant:"secondary",disabled:x,accessibleWhenDisabled:!0,onClick:()=>{x||((0,l.yM)("wcpay_reports_balance_print_click",_(D,S,f.length)),window.print())},"aria-describedby":x?A:void 0,__next40pxDefaultSize:!0,children:(0,c.__)("Print","woocommerce-payments")}),(0,y.jsx)(o.Button,{variant:"primary",disabled:x,accessibleWhenDisabled:!0,onClick:()=>{if(x)return;const e=_(D,S,f.length);(0,l.yM)("wcpay_reports_balance_export_click",e);try{(0,s.downloadCSVFile)((0,d.Sn)(D),(0,d.hz)({visibleRows:f,summary:b,displayPeriod:D,currency:S})),(0,l.yM)("wcpay_reports_balance_export_success",e)}catch(t){(0,l.yM)("wcpay_reports_balance_export_error",{...e,error_message:w(t)}),console.error("Balance CSV export failed:",t),a("error",(0,c.__)("There was a problem generating your export.","woocommerce-payments"))}},"aria-describedby":x?A:void 0,__next40pxDefaultSize:!0,children:(0,c.__)("Export","woocommerce-payments")})]})}},4022(e,t,a){a.d(t,{Sn:()=>l,WT:()=>u,hz:()=>i});var n=a(1554),o=a(5395),r=a(4904),s=a(7840);const c=e=>e.slice(0,10),l=e=>`wcpay-balance-${c(e.start)}_${c(e.end)}.csv`,i=({visibleRows:e,summary:t,displayPeriod:a,currency:l})=>{const i=c(a.start),u=c(a.end),p=(0,s.h8)();return(0,n.generateCSVDataFromTable)([{key:"business_name",label:"business_name"},{key:"woopayments_account_id",label:"woopayments_account_id"},{key:"row_key",label:"row_key"},{key:"label",label:"label"},{key:"amount",label:"amount"},{key:"count",label:"count"},{key:"currency",label:"currency"},{key:"period_start",label:"period_start"},{key:"period_end",label:"period_end"}],e.map(e=>{const n=e.getCount?.(t),c=(0,s.Fe)(e,a);return[{value:p.businessName,display:p.businessName},{value:p.accountId,display:p.accountId},{value:e.key,display:e.key},{value:c,display:c},{value:(0,o.o5)((0,r.wG)(e,e.getAmount(t)),l),display:""},{value:n??"",display:""},{value:l,display:l},{value:i,display:i},{value:u,display:u}]}))},u=(e,t)=>{const a=(0,o.$9)(e,t);return e>0?`+${a}`:a}},4904(e,t,a){a.d(t,{Qg:()=>o,k3:()=>u,wG:()=>r});var n=a(7723);const o=e=>e.depth??0,r=(e,t)=>e.displayNegative&&0!==t?-Math.abs(t):t,s=(e,t)=>e[t],c=e=>t=>s(t,e)?.amount??0,l=e=>t=>s(t,e)?.count,i=[{key:"starting_balance",label:(0,n.__)("Starting balance","woocommerce-payments"),alwaysVisible:!0,getAmount:c("starting_balance")},{key:"total_charges_captured",label:(0,n.__)("Total charges captured","woocommerce-payments"),alwaysVisible:!0,getAmount:c("total_charges_captured"),getCount:l("total_charges_captured")},{key:"fees",label:(0,n.__)("Fees","woocommerce-payments"),alwaysVisible:!0,depth:1,getAmount:c("fees")},{key:"charge_fees",label:(0,n.__)("Charge fees","woocommerce-payments"),depth:2,getAmount:c("charge_fees")},{key:"dispute_fees",label:(0,n.__)("Dispute fees","woocommerce-payments"),depth:2,getAmount:c("dispute_fees")},{key:"fee_refunds",label:(0,n.__)("Fee refunds","woocommerce-payments"),depth:2,getAmount:c("fee_refunds")},{key:"refunds",label:(0,n.__)("Refunds","woocommerce-payments"),depth:1,getAmount:c("refunds"),getCount:l("refunds")},{key:"refund_failure",label:(0,n.__)("Refund failures","woocommerce-payments"),depth:1,getAmount:c("refund_failure"),getCount:l("refund_failure")},{key:"disputes",label:(0,n.__)("Disputes","woocommerce-payments"),depth:1,getAmount:c("disputes"),getCount:l("disputes")},{key:"financing_payout",label:(0,n.__)("Financing payout","woocommerce-payments"),depth:1,getAmount:c("financing_payout"),getCount:l("financing_payout")},{key:"financing_paydown",label:(0,n.__)("Financing paydown","woocommerce-payments"),depth:1,getAmount:c("financing_paydown"),getCount:l("financing_paydown")},{key:"payout_fees",label:(0,n.__)("Payout fees","woocommerce-payments"),depth:1,getAmount:c("payout_fees")},{key:"reader_fees",label:(0,n.__)("Reader costs","woocommerce-payments"),depth:1,getAmount:c("reader_fees")},{key:"network_costs",label:(0,n.__)("Network costs","woocommerce-payments"),depth:1,getAmount:c("network_costs"),getCount:l("network_costs")},{key:"other_adjustments",label:(0,n.__)("Other adjustments","woocommerce-payments"),depth:1,getAmount:c("other_adjustments"),getCount:l("other_adjustments")},{key:"net_balance_change_in_the_period",label:(0,n.__)("Net balance change in the period","woocommerce-payments"),alwaysVisible:!0,getAmount:c("net_balance_change_in_the_period")},{key:"payouts",label:(0,n.__)("Payouts","woocommerce-payments"),alwaysVisible:!0,depth:1,displayNegative:!0,getAmount:c("payouts"),getCount:l("payouts")},{key:"ending_balance",label:(0,n.__)("Ending balance","woocommerce-payments"),alwaysVisible:!0,getAmount:c("ending_balance")}],u=e=>i.filter(t=>t.alwaysVisible||0!==t.getAmount(e)||0!==(t.getCount?.(e)??0))},1983(e,t,a){a.d(t,{tb:()=>g,yR:()=>h});var n=a(1609),o=a(6476),r=a(4965),s=a(6401),c=a(2310);const l="wcpay-balance-date-filter-change",i=e=>{const[t,a,n]=e.split("-").map(Number);return[t,a,n]},u=e=>{const[t,a,n]=i(e);return new Date(Date.UTC(t,a-1,n,0,0,0,0)).toISOString()},p=e=>{const[t,a,n]=i(e);return new Date(Date.UTC(t,a-1,n,23,59,59,999)).toISOString()},d=e=>[e.getUTCFullYear(),String(e.getUTCMonth()+1).padStart(2,"0"),String(e.getUTCDate()).padStart(2,"0")].join("-"),m=e=>{const[t,a]=i(e);return d(new Date(Date.UTC(t,a-1,1)))},y=e=>d(new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()-1))),_=(e,t)=>e<=t?e:t,w=(e,t)=>_(e,y(t)),b=(e,t)=>{if(e){if("between"===e.operator){const[a,n]=((e,t)=>e<=t?[e,t]:[t,e])(w(e.value[0],t),w(e.value[1],t));return{operator:"between",value:[a,n]}}return"on"===e.operator?{operator:"on",value:w(e.value,t)}:"before"===e.operator?{operator:"before",value:w(e.value,t)}:{operator:"after",value:w(e.value,t)}}},g=(e,t=new Date)=>{const a=b(e,t);if(!a)return(0,s.A)(t);if("on"===a.operator)return{start:u(a.value),end:p(a.value)};if("between"===a.operator)return{start:u(a.value[0]),end:p(a.value[1])};if("before"===a.operator)return{start:u(m(a.value)),end:p(a.value)};const n=_((e=>{const[t,a]=i(e);return d(new Date(Date.UTC(t,a,0)))})(a.value),y(t));return{start:u(a.value),end:p(n)}},h=e=>{const t=(0,n.useContext)(c.W),a=(0,n.useRef)(e??t??new Date).current,i=(0,n.useRef)(!1),[u,p]=(0,n.useState)(0),[d,m]=(0,n.useState)(),y=(0,n.useCallback)(()=>p(e=>e+1),[]),_=(0,n.useCallback)(()=>b((0,r.e)((0,o.getQuery)()),a),[a]),w=(0,n.useCallback)(e=>{m(e.detail),y()},[y]),h=(0,n.useCallback)(()=>{i.current||m(void 0),y()},[y]);(0,n.useEffect)(()=>(window.addEventListener(l,w),window.addEventListener("popstate",h),window.addEventListener("pushstate",h),window.addEventListener("replacestate",h),()=>{window.removeEventListener(l,w),window.removeEventListener("popstate",h),window.removeEventListener("pushstate",h),window.removeEventListener("replacestate",h)}),[h,w]);const v=d?d.value:_()??(e=>{const t=(0,s.A)(e);return{operator:"between",value:[t.start.slice(0,10),t.end.slice(0,10)]}})(a);return{value:v,period:g(v,a),hasDateFilterValue:void 0!==v,setValue:(0,n.useCallback)(e=>{const t=b(e,a);i.current=!0;try{(0,o.updateQueryString)((0,r.K)(t),"/payments/reports")}finally{i.current=!1}window.dispatchEvent(new CustomEvent(l,{detail:{value:t}})),p(e=>e+1)},[a])}}},7840(e,t,a){a.d(t,{Fe:()=>d,PM:()=>c,aO:()=>u,h8:()=>s,xV:()=>l,xi:()=>r,yF:()=>i});var n=a(7723),o=a(9310);const r="wcpay-reports-balance-print-context",s=()=>({businessName:(wcpaySettings.accountStatus?.businessName||wcpaySettings.storeName||"").trim(),accountId:(wcpaySettings.accountStatus?.accountId||"").trim()}),c=(e,t)=>e&&t?Math.round((new Date(t).getTime()-new Date(e).getTime())/864e5):null,l=e=>Object.keys(e??{}).length>0,i=({summary:e,hasDateFilterValue:t,isLoading:a,hasStoreError:n})=>t&&!a&&!n&&!(e=>Boolean(e.currency&&e.period?.start&&e.period?.end))(e),u=(e,t)=>e.some(e=>0!==e.getAmount(t)||0!==(e.getCount?.(t)??0)),p=e=>(0,n.sprintf)((0,n.__)("%s UTC","woocommerce-payments"),(0,o._)(e,{timezone:"UTC"})),d=(e,t)=>"starting_balance"===e.key?(0,n.sprintf)((0,n.__)("Starting balance - %s","woocommerce-payments"),p(t.start)):"ending_balance"===e.key?(0,n.sprintf)((0,n.__)("Ending balance - %s","woocommerce-payments"),p(t.end)):e.label}}]);
Save File
Cancel