관리-도구
편집 파일: analytics-report-coupons.js
(window.__wcAdmin_webpackJsonp=window.__wcAdmin_webpackJsonp||[]).push([[15],{748:function(e,t,r){"use strict";r.r(t),r.d(t,"default",(function(){return V}));var n=r(5),a=r.n(n),o=r(17),c=r.n(o),i=r(15),u=r.n(i),s=r(18),l=r.n(s),m=r(19),d=r.n(m),p=r(9),f=r.n(p),y=r(0),b=r(1),g=r.n(b),v=r(3),h=r(789),O=r(11),_=r.n(O),j=r(2),w=r(77),R=r(32),C=r(298),D=r(36),q=r(40),k=r(771),E=r(762);function P(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=f()(e);if(t){var a=f()(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return d()(this,r)}}var S=function(e){l()(r,e);var t=P(r);function r(){var e;return c()(this,r),(e=t.call(this)).getHeadersContent=e.getHeadersContent.bind(_()(e)),e.getRowsContent=e.getRowsContent.bind(_()(e)),e.getSummary=e.getSummary.bind(_()(e)),e}return u()(r,[{key:"getHeadersContent",value:function(){return[{label:Object(v.__)("Coupon Code",'kkart'),key:"code",required:!0,isLeftAligned:!0,isSortable:!0},{label:Object(v.__)("Orders",'kkart'),key:"orders_count",required:!0,defaultSort:!0,isSortable:!0,isNumeric:!0},{label:Object(v.__)("Amount Discounted",'kkart'),key:"amount",isSortable:!0,isNumeric:!0},{label:Object(v.__)("Created",'kkart'),key:"created"},{label:Object(v.__)("Expires",'kkart'),key:"expires"},{label:Object(v.__)("Type",'kkart'),key:"type"}]}},{key:"getRowsContent",value:function(e){var t=this,r=this.props.query,n=Object(R.getPersistedQuery)(r),a=Object(D.g)("dateFormat",q.defaultTableDateFormat),o=this.context,c=o.formatAmount,i=o.formatDecimal,u=o.getCurrencyConfig;return Object(j.map)(e,(function(e){var r=e.amount,o=e.coupon_id,s=e.orders_count,l=e.extended_info||{},m=l.code,d=l.date_created,p=l.date_expires,f=l.discount_type,b=o>0?Object(R.getNewPath)(n,"/analytics/coupons",{filter:"single_coupon",coupons:o}):null,g=null===b?m:Object(y.createElement)(w.Link,{href:b,type:"kkart-admin"},m),h=o>0?Object(R.getNewPath)(n,"/analytics/orders",{filter:"advanced",coupon_includes:o}):null;return[{display:g,value:m},{display:null===h?s:Object(y.createElement)(w.Link,{href:h,type:"kkart-admin"},Object(C.formatValue)(u(),"number",s)),value:s},{display:c(r),value:i(r)},{display:d?Object(y.createElement)(w.Date,{date:d,visibleFormat:a}):Object(v.__)("N/A",'kkart'),value:d},{display:p?Object(y.createElement)(w.Date,{date:p,visibleFormat:a}):Object(v.__)("N/A",'kkart'),value:p},{display:t.getCouponType(f),value:f}]}))}},{key:"getSummary",value:function(e){var t=e.coupons_count,r=void 0===t?0:t,n=e.orders_count,a=void 0===n?0:n,o=e.amount,c=void 0===o?0:o,i=this.context,u=i.formatAmount,s=(0,i.getCurrencyConfig)();return[{label:Object(v._n)("coupon","coupons",r,'kkart'),value:Object(C.formatValue)(s,"number",r)},{label:Object(v._n)("order","orders",a,'kkart'),value:Object(C.formatValue)(s,"number",a)},{label:Object(v.__)("amount discounted",'kkart'),value:u(c)}]}},{key:"getCouponType",value:function(e){return{percent:Object(v.__)("Percentage",'kkart'),fixed_cart:Object(v.__)("Fixed cart",'kkart'),fixed_product:Object(v.__)("Fixed product",'kkart')}[e]||Object(v.__)("N/A",'kkart')}},{key:"render",value:function(){var e=this.props,t=e.advancedFilters,r=e.filters,n=e.isRequesting,a=e.query;return Object(y.createElement)(k.a,{compareBy:"coupons",endpoint:"coupons",getHeadersContent:this.getHeadersContent,getRowsContent:this.getRowsContent,getSummary:this.getSummary,summaryFields:["coupons_count","orders_count","amount"],isRequesting:n,itemIdField:"coupon_id",query:a,searchBy:"coupons",tableQuery:{orderby:a.orderby||"orders_count",order:a.order||"desc",extended_info:!0},title:Object(v.__)("Coupons",'kkart'),columnPrefsKey:"coupons_report_columns",filters:r,advancedFilters:t})}}]),r}(y.Component);S.contextType=E.a;var F=S,T=r(768),A=r(766),x=r(769),N=r(770);function L(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function M(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=f()(e);if(t){var a=f()(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return d()(this,r)}}var V=function(e){l()(r,e);var t=M(r);function r(){return c()(this,r),t.apply(this,arguments)}return u()(r,[{key:"getChartMeta",value:function(){var e=this.props.query,t="compare-coupons"===e.filter&&e.coupons&&e.coupons.split(",").length>1?"item-comparison":"time-comparison";return{itemsLabel:Object(v.__)("%d coupons",'kkart'),mode:t}}},{key:"render",value:function(){var e=this.props,t=e.isRequesting,r=e.query,n=e.path,o=this.getChartMeta(),c=o.mode,i=o.itemsLabel,u=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?L(Object(r),!0).forEach((function(t){a()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):L(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},r);return"item-comparison"===c&&(u.segmentby="coupon"),Object(y.createElement)(y.Fragment,null,Object(y.createElement)(N.a,{query:r,path:n,filters:h.c,advancedFilters:h.a,report:"coupons"}),Object(y.createElement)(x.a,{charts:h.b,endpoint:"coupons",isRequesting:t,query:u,selectedChart:Object(T.a)(r.chart,h.b),filters:h.c,advancedFilters:h.a}),Object(y.createElement)(A.a,{charts:h.b,filters:h.c,advancedFilters:h.a,mode:c,endpoint:"coupons",path:n,query:u,isRequesting:t,itemsLabel:i,selectedChart:Object(T.a)(r.chart,h.b)}),Object(y.createElement)(F,{isRequesting:t,query:r,filters:h.c,advancedFilters:h.a}))}}]),r}(y.Component);V.propTypes={query:g.a.object.isRequired}},764:function(e,t,r){"use strict";r.d(t,"e",(function(){return m})),r.d(t,"a",(function(){return d})),r.d(t,"b",(function(){return p})),r.d(t,"c",(function(){return f})),r.d(t,"d",(function(){return y})),r.d(t,"f",(function(){return b})),r.d(t,"h",(function(){return g})),r.d(t,"g",(function(){return v}));var n=r(37),a=r(43),o=r.n(a),c=r(2),i=r(32),u=r(35),s=r(36),l=r(765);function m(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c.identity;return function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",a=arguments.length>1?arguments[1]:void 0,c="function"==typeof e?e(a):e,u=Object(i.getIdsFromQuery)(r);if(u.length<1)return Promise.resolve([]);var s={include:u.join(","),per_page:u.length};return o()({path:Object(n.addQueryArgs)(c,s)}).then((function(e){return e.map(t)}))}}var d=m(u.NAMESPACE+"/products/categories",(function(e){return{key:e.id,label:e.name}})),p=m(u.NAMESPACE+"/coupons",(function(e){return{key:e.id,label:e.code}})),f=m(u.NAMESPACE+"/customers",(function(e){return{key:e.id,label:e.name}})),y=m(u.NAMESPACE+"/products",(function(e){return{key:e.id,label:e.name}})),b=m(u.NAMESPACE+"/taxes",(function(e){return{key:e.id,label:Object(l.a)(e)}}));function g(e){var t=e.attributes,r=e.name,n=Object(s.g)("variationTitleAttributesSeparator"," - ");if(r.indexOf(n)>-1)return r;var a=t.map((function(e){return e.option})).join(", ");return a?r+n+a:r}var v=m((function(e){var t=e.products;return t?u.NAMESPACE+"/products/".concat(t,"/variations"):u.NAMESPACE+"/variations"}),(function(e){return{key:e.id,label:g(e)}}))},765:function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r(3);function a(e){return[e.country,e.state,e.name||Object(n.__)("TAX",'kkart'),e.priority].map((function(e){return e.toString().toUpperCase().trim()})).filter(Boolean).join("-")}},766:function(e,t,r){"use strict";var n=r(5),a=r.n(n),o=r(17),c=r.n(o),i=r(15),u=r.n(i),s=r(18),l=r.n(s),m=r(19),d=r.n(m),p=r(9),f=r.n(p),y=r(0),b=r(3),g=r(277),v=r(154),h=r(20),O=r(2),_=r(1),j=r.n(_),w=r(77),R=r(35),C=r(40),D=r(762),q=r(763),k=r(32);function E(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function P(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?E(Object(r),!0).forEach((function(t){a()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):E(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function S(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=f()(e);if(t){var a=f()(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return d()(this,r)}}var F=function(e){l()(r,e);var t=S(r);function r(){return c()(this,r),t.apply(this,arguments)}return u()(r,[{key:"shouldComponentUpdate",value:function(e){return e.isRequesting!==this.props.isRequesting||e.primaryData.isRequesting!==this.props.primaryData.isRequesting||e.secondaryData.isRequesting!==this.props.secondaryData.isRequesting||!Object(O.isEqual)(e.query,this.props.query)}},{key:"getItemChartData",value:function(){var e=this.props,t=e.primaryData,r=e.selectedChart;return t.data.intervals.map((function(e){var t={};return e.subtotals.segments.forEach((function(e){if(e.segment_label){var n=t[e.segment_label]?e.segment_label+" (#"+e.segment_id+")":e.segment_label;t[e.segment_id]={label:n,value:e.subtotals[r.key]||0}}})),P({date:Object(v.a)("Y-m-d\\TH:i:s",e.date_start)},t)}))}},{key:"getTimeChartData",value:function(){var e=this.props,t=e.query,r=e.primaryData,n=e.secondaryData,a=e.selectedChart,o=e.defaultDateRange,c=Object(C.getIntervalForQuery)(t),i=Object(C.getCurrentDates)(t,o),u=i.primary,s=i.secondary;return r.data.intervals.map((function(e,r){var o=Object(C.getPreviousDate)(e.date_start,u.after,s.after,t.compare,c),i=n.data.intervals[r];return{date:Object(v.a)("Y-m-d\\TH:i:s",e.date_start),primary:{label:"".concat(u.label," (").concat(u.range,")"),labelDate:e.date_start,value:e.subtotals[a.key]||0},secondary:{label:"".concat(s.label," (").concat(s.range,")"),labelDate:o.format("YYYY-MM-DD HH:mm:ss"),value:i&&i.subtotals[a.key]||0}}}))}},{key:"getTimeChartTotals",value:function(){var e=this.props,t=e.primaryData,r=e.secondaryData,n=e.selectedChart;return{primary:Object(O.get)(t,["data","totals",n.key],null),secondary:Object(O.get)(r,["data","totals",n.key],null)}}},{key:"renderChart",value:function(e,t,r,n){var a=this.props,o=a.emptySearchResults,c=a.filterParam,i=a.interactiveLegend,u=a.itemsLabel,s=a.legendPosition,l=a.path,m=a.query,d=a.selectedChart,p=a.showHeaderControls,f=a.primaryData,g=Object(C.getIntervalForQuery)(m),v=Object(C.getAllowedIntervalsForQuery)(m),h=Object(C.getDateFormatsForInterval)(g,f.data.intervals.length),O=o?Object(b.__)("No data for the current search",'kkart'):Object(b.__)("No data for the selected date range",'kkart'),_=this.context,j=_.formatAmount,D=_.getCurrencyConfig;return Object(y.createElement)(w.Chart,{allowedIntervals:v,data:r,dateParser:"%Y-%m-%dT%H:%M:%S",emptyMessage:O,filterParam:c,interactiveLegend:i,interval:g,isRequesting:t,itemsLabel:u,legendPosition:s,legendTotals:n,mode:e,path:l,query:m,screenReaderFormat:h.screenReaderFormat,showHeaderControls:p,title:d.label,tooltipLabelFormat:h.tooltipLabelFormat,tooltipTitle:"time-comparison"===e&&d.label||null,tooltipValueFormat:Object(R.getTooltipValueFormat)(d.type,j),chartType:Object(C.getChartTypeForQuery)(m),valueType:d.type,xFormat:h.xFormat,x2Format:h.x2Format,currency:D()})}},{key:"renderItemComparison",value:function(){var e=this.props,t=e.isRequesting,r=e.primaryData;if(r.isError)return Object(y.createElement)(q.a,{isError:!0});var n=t||r.isRequesting,a=this.getItemChartData();return this.renderChart("item-comparison",n,a)}},{key:"renderTimeComparison",value:function(){var e=this.props,t=e.isRequesting,r=e.primaryData,n=e.secondaryData;if(!r||r.isError||n.isError)return Object(y.createElement)(q.a,{isError:!0});var a=t||r.isRequesting||n.isRequesting,o=this.getTimeChartData(),c=this.getTimeChartTotals();return this.renderChart("time-comparison",a,o,c)}},{key:"render",value:function(){return"item-comparison"===this.props.mode?this.renderItemComparison():this.renderTimeComparison()}}]),r}(y.Component);F.contextType=D.a,F.propTypes={filters:j.a.array,isRequesting:j.a.bool,itemsLabel:j.a.string,limitProperties:j.a.array,mode:j.a.string,path:j.a.string.isRequired,primaryData:j.a.object,query:j.a.object.isRequired,secondaryData:j.a.object,selectedChart:j.a.shape({key:j.a.string.isRequired,label:j.a.string.isRequired,order:j.a.oneOf(["asc","desc"]),orderby:j.a.string,type:j.a.oneOf(["average","number","currency"]).isRequired}).isRequired},F.defaultProps={isRequesting:!1,primaryData:{data:{intervals:[]},isError:!1,isRequesting:!1},secondaryData:{data:{intervals:[]},isError:!1,isRequesting:!1}};t.a=Object(g.a)(Object(h.withSelect)((function(e,t){var r=t.charts,n=t.endpoint,a=t.filters,o=t.isRequesting,c=t.limitProperties,i=t.query,u=t.advancedFilters,s=c||[n],l=function e(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t||0===t.length)return null;var a=t.slice(0),o=a.pop();if(o.showFilters(r,n)){var c=Object(k.flattenFilters)(o.filters),i=r[o.param]||o.defaultValue||"all";return Object(O.find)(c,{value:i})}return e(a,r,n)}(a,i),m=Object(O.get)(l,["settings","param"]),d=t.mode||function(e,t){if(e&&t){var r=Object(O.get)(e,["settings","param"]);if(!r||Object.keys(t).includes(r))return Object(O.get)(e,["chartMode"])}return null}(l,i)||"time-comparison",p=e(R.SETTINGS_STORE_NAME).getSetting("kkart_admin","wcAdminSettings").kkart_default_date_range,f={mode:d,filterParam:m,defaultDateRange:p};if(o)return f;var y=s.some((function(e){return i[e]&&i[e].length}));if(i.search&&!y)return P(P({},f),{},{emptySearchResults:!0});var b=r&&r.map((function(e){return e.key})),g=Object(R.getReportChartData)({endpoint:n,dataType:"primary",query:i,select:e,limitBy:s,filters:a,advancedFilters:u,defaultDateRange:p,fields:b});if("item-comparison"===d)return P(P({},f),{},{primaryData:g});var v=Object(R.getReportChartData)({endpoint:n,dataType:"secondary",query:i,select:e,limitBy:s,filters:a,advancedFilters:u,defaultDateRange:p,fields:b});return P(P({},f),{},{primaryData:g,secondaryData:v})})))(F)},768:function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r(2);function a(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=Object(n.find)(t,{key:e});return r||t[0]}},769:function(e,t,r){"use strict";var n=r(17),a=r.n(n),o=r(15),c=r.n(o),i=r(18),u=r.n(i),s=r(19),l=r.n(s),m=r(9),d=r.n(m),p=r(0),f=r(3),y=r(277),b=r(20),g=r(1),v=r.n(g),h=r(32),O=r(77),_=r(298),j=r(35),w=r(40),R=r(64),C=r(763),D=r(762);function q(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=d()(e);if(t){var a=d()(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return l()(this,r)}}var k=function(e){u()(r,e);var t=q(r);function r(){return a()(this,r),t.apply(this,arguments)}return c()(r,[{key:"formatVal",value:function(e,t){var r=this.context,n=r.formatAmount,a=r.getCurrencyConfig;return"currency"===t?n(e):Object(_.formatValue)(a(),t,e)}},{key:"getValues",value:function(e,t){var r=this.props,n=r.emptySearchResults,a=r.summaryData.totals,o=a.primary?a.primary[e]:0,c=a.secondary?a.secondary[e]:0,i=n?0:o,u=n?0:c;return{delta:Object(_.calculateDelta)(i,u),prevValue:this.formatVal(u,t),value:this.formatVal(i,t)}}},{key:"render",value:function(){var e=this,t=this.props,r=t.charts,n=t.query,a=t.selectedChart,o=t.summaryData,c=t.endpoint,i=t.report,u=t.defaultDateRange,s=o.isError,l=o.isRequesting;if(s)return Object(p.createElement)(C.a,{isError:!0});if(l)return Object(p.createElement)(O.SummaryListPlaceholder,{numberOfItems:r.length});var m=Object(w.getDateParamsFromQuery)(n,u).compare;return Object(p.createElement)(O.SummaryList,null,(function(t){var n=t.onToggle;return r.map((function(t){var r=t.key,o=t.order,u=t.orderby,s=t.label,l=t.type,d={chart:r};u&&(d.orderby=u),o&&(d.order=o);var y=Object(h.getNewPath)(d),b=a.key===r,g=e.getValues(r,l),v=g.delta,_=g.prevValue,j=g.value;return Object(p.createElement)(O.SummaryNumber,{key:r,delta:v,href:y,label:s,prevLabel:"previous_period"===m?Object(f.__)("Previous Period:",'kkart'):Object(f.__)("Previous Year:",'kkart'),prevValue:_,selected:b,value:j,onLinkClickCallback:function(){n&&n(),Object(R.recordEvent)("analytics_chart_tab_click",{report:i||c,key:r})}})}))}))}}]),r}(p.Component);k.propTypes={charts:v.a.array.isRequired,endpoint:v.a.string.isRequired,limitProperties:v.a.array,query:v.a.object.isRequired,selectedChart:v.a.shape({key:v.a.string.isRequired,label:v.a.string.isRequired,order:v.a.oneOf(["asc","desc"]),orderby:v.a.string,type:v.a.oneOf(["average","number","currency"]).isRequired}).isRequired,summaryData:v.a.object,report:v.a.string},k.defaultProps={summaryData:{totals:{primary:{},secondary:{}},isError:!1}},k.contextType=D.a,t.a=Object(y.a)(Object(b.withSelect)((function(e,t){var r=t.charts,n=t.endpoint,a=t.limitProperties,o=t.query,c=t.filters,i=t.advancedFilters,u=a||[n],s=u.some((function(e){return o[e]&&o[e].length}));if(o.search&&!s)return{emptySearchResults:!0};var l=r&&r.map((function(e){return e.key})),m=e(j.SETTINGS_STORE_NAME).getSetting("kkart_admin","wcAdminSettings").kkart_default_date_range;return{summaryData:Object(j.getSummaryNumbers)({endpoint:n,query:o,select:e,limitBy:u,filters:c,advancedFilters:i,defaultDateRange:m,fields:l}),defaultDateRange:m}})))(k)},789:function(e,t,r){"use strict";r.d(t,"b",(function(){return c})),r.d(t,"c",(function(){return i})),r.d(t,"a",(function(){return u}));var n=r(3),a=r(55),o=r(764),c=Object(a.applyFilters)("kkart_admin_coupons_report_charts",[{key:"orders_count",label:Object(n.__)("Discounted Orders",'kkart'),order:"desc",orderby:"orders_count",type:"number"},{key:"amount",label:Object(n.__)("Amount",'kkart'),order:"desc",orderby:"amount",type:"currency"}]),i=Object(a.applyFilters)("kkart_admin_coupons_report_filters",[{label:Object(n.__)("Show",'kkart'),staticParams:["chartType","paged","per_page"],param:"filter",showFilters:function(){return!0},filters:[{label:Object(n.__)("All Coupons",'kkart'),value:"all"},{label:Object(n.__)("Single Coupon",'kkart'),value:"select_coupon",chartMode:"item-comparison",subFilters:[{component:"Search",value:"single_coupon",chartMode:"item-comparison",path:["select_coupon"],settings:{type:"coupons",param:"coupons",getLabels:o.b,labels:{placeholder:Object(n.__)("Type to search for a coupon",'kkart'),button:Object(n.__)("Single Coupon",'kkart')}}}]},{label:Object(n.__)("Comparison",'kkart'),value:"compare-coupons",settings:{type:"coupons",param:"coupons",getLabels:o.b,labels:{title:Object(n.__)("Compare Coupon Codes",'kkart'),update:Object(n.__)("Compare",'kkart'),helpText:Object(n.__)("Check at least two coupon codes below to compare",'kkart')}}}]}]),u=Object(a.applyFilters)("kkart_admin_coupon_report_advanced_filters",{})}}]);