1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7365],{4236:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>L});var o=r(37876),l=r(14232),a=r(46520),n=r(87263),i=r(27481),s=r(94515),d=r(12809),c=r(11054),u=r(61428),x=r(65965),m=r(451),h=r(78423),f=r(84676),p=r(9858),b=r(33840),g=r(1413),j=r(52460),A=r(52039),v=r(19280),C=r(9729),_=r(25767),k=r(22528),y=r(94559),S=r(66680),M=r(84949),w=r(70825),z=r(75978),B=r(17346),N=r(68493),T=r(43215);let F=[function(){let e=new Date;return{label:"Current Month",dateFrom:(0,z.A)(e),dateTo:e}}(),function(){let e=new Date,t=(0,B.A)(e,1);return{label:"Previous Month",dateFrom:(0,z.A)(t),dateTo:(0,N.A)(t)}}(),function(){let e=new Date;return{label:"Current Year",dateFrom:(0,T.A)(e),dateTo:e}}(),{label:"Custom",dateFrom:null,dateTo:null}],W={"Current Month":"M\xeas atual","Previous Month":"M\xeas anterior","Current Year":"Ano atual",Custom:"Personalizado"};function L(){let{currentCompany:e}=(0,S.A)(),[t,r]=(0,l.useState)(F[0]),[j,A]=(0,l.useState)(F[0].label),[z,B]=(0,l.useState)(null),[N,T]=(0,l.useState)(null),[L,R]=(0,l.useState)(!1),[H,E]=(0,l.useState)(!1),[G,q]=(0,l.useState)(null),[O,Y]=(0,l.useState)([]),[V,U]=(0,l.useState)(null),[X,$]=(0,l.useState)("desc"),J=()=>{if(!(null==e?void 0:e.marketplaces)||0===e.marketplaces.length)return null;let t=e.marketplaces.find(e=>1===e.marketplace_id);return(null==t?void 0:t.marketplace_user_id)||null},[K,Q]=(0,l.useState)(null);async function Z(e,t){E(!0),Q(null);let r=J();if(!r){q(null),Y([]),Q("Esta empresa n\xe3o possui o Mercado Livre configurado. Configure o marketplace nas configura\xe7\xf5es da empresa para visualizar os dados."),E(!1);return}try{var o;console.log("\uD83D\uDD0D Buscando dados BI Mercado Livre:",{dateFrom:P(e),dateTo:P(t),user_id:r});let[l,a]=await Promise.all([y.A.get("/api/meli/orders/totals",{params:{dateFrom:P(e),dateTo:P(t),user_id:r}}),y.A.get("/api/meli/analytics/brand-summary",{params:{dateFrom:P(e),dateTo:P(t),user_id:r}})]);console.log("â
Dados recebidos:",{totals:l.data,brandsCount:(null==(o=a.data)?void 0:o.length)||0}),q(l.data),Y(a.data||[])}catch(e){console.error("â Erro ao buscar dados:",e),Q("Error fetching data. "+(e.message||"")),q(null),Y([])}finally{E(!1)}}function ee(e){V===e?$("desc"===X?"asc":"desc"):(U(e),$("desc"))}(0,l.useEffect)(()=>{let e,r;if("Custom"===j){if(e=z,r=N,!e||!r)return}else e=t.dateFrom,r=t.dateTo;Z(e,r)},[t,j,z,N]);let et="Custom"===j?z:t.dateFrom,er="Custom"===j?N:t.dateTo;return J()?(0,o.jsxs)(a.A,{sx:{p:3,width:"100%"},children:[(0,o.jsx)(w.zY,{title:"BI \xb7 Mercado Livre",subtitle:"Vendas e resultado por marca"}),(0,o.jsxs)(n.A,{direction:{xs:"column",md:"row"},spacing:1.5,alignItems:{md:"center"},sx:{mb:3,flexWrap:"wrap"},useFlexGap:!0,children:[F.map(e=>{let t=j===e.label;return(0,o.jsx)(i.A,{variant:t?"contained":"outlined",onClick:()=>{r(e),A(e.label),"Custom"===e.label?(B(null),T(null),R(!0)):R(!1)},sx:{textTransform:"none",borderRadius:"8px",fontWeight:600,fontSize:13,boxShadow:"none",...t?{}:{borderColor:w.lm.fieldBorder,color:w.lm.muted}},children:W[e.label]||e.label},e.label)}),(0,o.jsxs)(v.$,{dateAdapter:_.h,children:[(0,o.jsx)(C.l,{label:"De",value:"Custom"===j?z:et,onChange:e=>"Custom"===j?void B(e):null,renderInput:e=>(0,o.jsx)(s.A,{...e,size:"small",sx:{width:150,...w.W_}}),disabled:"Custom"!==j}),(0,o.jsx)(C.l,{label:"At\xe9",value:"Custom"===j?N:er,onChange:e=>"Custom"===j?void(T(e),z&&e&&(r({label:"Custom",dateFrom:z,dateTo:e}),A("Custom"),R(!1))):null,renderInput:e=>(0,o.jsx)(s.A,{...e,size:"small",sx:{width:150,...w.W_}}),disabled:"Custom"!==j,minDate:z||void 0})]})]}),(0,o.jsxs)(d.A,{container:!0,spacing:2,sx:{mb:4},children:[(0,o.jsx)(d.A,{size:{xs:12,sm:6,md:2},children:(0,o.jsx)(D,{label:"Vendas totais",value:null==G?void 0:G.totalAmount})}),(0,o.jsx)(d.A,{size:{xs:12,sm:6,md:2},children:(0,o.jsx)(D,{label:"Pedidos",value:null==G?void 0:G.totalOrders,decimal:!1})}),(0,o.jsx)(d.A,{size:{xs:12,sm:6,md:2},children:(0,o.jsx)(D,{label:"Custo total",value:null==G?void 0:G.totalCost})}),(0,o.jsx)(d.A,{size:{xs:12,sm:6,md:2},children:(0,o.jsx)(D,{label:"Frete",value:null==G?void 0:G.totalShipping})}),(0,o.jsx)(d.A,{size:{xs:12,sm:6,md:2},children:(0,o.jsx)(D,{label:"Tarifa Marketplace",value:null==G?void 0:G.totalMarketplaceFee})}),(0,o.jsx)(d.A,{size:{xs:12,sm:6,md:2},children:(0,o.jsx)(D,{label:"Lucro l\xedquido",value:null==G?void 0:G.grossProfit,accent:"#2e7d32"})})]}),(0,o.jsxs)(c.A,{sx:{...w.Cy,overflow:"hidden"},children:[(0,o.jsx)(a.A,{sx:{px:2,py:1.5,borderBottom:"1px solid ".concat(w.lm.headBorder)},children:(0,o.jsx)(u.A,{sx:{fontSize:13,fontWeight:600,color:w.lm.text},children:"Resultado por marca"})}),(0,o.jsx)(a.A,{sx:{overflow:"auto",maxHeight:700,...w.e8},children:H?(0,o.jsx)(a.A,{sx:{p:6,textAlign:"center"},children:(0,o.jsx)(x.A,{size:36})}):K?(0,o.jsx)(a.A,{sx:{p:4,color:"error.main",textAlign:"center"},children:(0,o.jsx)(u.A,{variant:"subtitle1",children:K})}):0===O.length?(0,o.jsx)(a.A,{sx:{p:4,textAlign:"center"},children:(0,o.jsx)(u.A,{variant:"subtitle1",children:"No sales found for this period."})}):(0,o.jsxs)(m.A,{stickyHeader:!0,children:[(0,o.jsx)(h.A,{children:(0,o.jsxs)(f.A,{children:[(0,o.jsx)(p.A,{children:"#"}),(0,o.jsx)(p.A,{children:"Marca"}),(0,o.jsx)(p.A,{align:"right",sx:{cursor:"pointer",userSelect:"none"},onClick:()=>ee("stock_balance"),children:(0,o.jsx)(b.A,{active:"stock_balance"===V,direction:"stock_balance"===V?X:"desc",children:"Saldo estoque"})}),(0,o.jsx)(p.A,{align:"right",children:"Un. vendidas"}),(0,o.jsx)(p.A,{align:"right",sx:{cursor:"pointer",userSelect:"none"},onClick:()=>ee("total_sales"),children:(0,o.jsx)(b.A,{active:"total_sales"===V,direction:"total_sales"===V?X:"desc",children:"Vendas totais"})}),(0,o.jsx)(p.A,{align:"right",children:"Custo"}),(0,o.jsx)(p.A,{align:"right",children:"Frete"}),(0,o.jsx)(p.A,{align:"right",children:"Tarifa ML"}),(0,o.jsx)(p.A,{align:"right",children:"Lucro l\xedquido"}),(0,o.jsx)(p.A,{align:"right",sx:{cursor:"pointer",userSelect:"none"},onClick:()=>ee("margin"),children:(0,o.jsx)(b.A,{active:"margin"===V,direction:"margin"===V?X:"desc",children:"Margem (%)"})})]})}),(0,o.jsx)(g.A,{children:(!V?O:[...O].sort((e,t)=>
1{let r,o;switch(V){case"stock_balance":r=Number(e.stock_balance||0),o=Number(t.stock_balance||0);break;case"margin":let l=Number(e.net_profit||0),a=Number(e.total_sales||0),n=Number(t.net_profit||0),i=Number(t.total_sales||0);r=a>0?l/a*100:0,o=i>0?n/i*100:0;break;case"total_sales":r=Number(e.total_sales||0),o=Number(t.total_sales||0);break;default:return 0}return"desc"===X?o-r:r-o})).map((e,t)=>{var r;let l=0>Number(e.net_profit||0)?"#d32f2f":"#2e7d32";return(0,o.jsxs)(f.A,{sx:{bgcolor:0===t?"#fffbeb":"inherit"},children:[(0,o.jsx)(p.A,{sx:{color:w.lm.faint},children:t+1}),(0,o.jsx)(p.A,{sx:{fontWeight:600,color:w.lm.textStrong},children:(r=e.brand)?r.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" "):""}),(0,o.jsx)(p.A,{align:"right",children:I(e.stock_balance||0)}),(0,o.jsx)(p.A,{align:"right",children:e.items_sold}),(0,o.jsx)(p.A,{align:"right",children:I(e.total_sales)}),(0,o.jsx)(p.A,{align:"right",sx:{color:w.lm.muted},children:I(e.total_cost)}),(0,o.jsx)(p.A,{align:"right",sx:{color:w.lm.muted},children:I(e.total_shipping_fee)}),(0,o.jsx)(p.A,{align:"right",sx:{color:w.lm.muted},children:I(e.total_marketplace_fee)}),(0,o.jsx)(p.A,{align:"right",sx:{color:l,fontWeight:600},children:I(e.net_profit)}),(0,o.jsx)(p.A,{align:"right",sx:{color:l,fontWeight:600},children:function(e,t){let r=Number(e||0),o=Number(t||0);return!o||isNaN(o)||isNaN(r)?"-":"".concat((r/o*100).toFixed(2),"%")}(e.net_profit,e.total_sales)})]},e.brand||t)})})]})})]})]}):(0,o.jsx)(k.A,{requiredPermission:"meli.bi.view",children:(0,o.jsx)(M.A,{marketplaceName:"Mercado Livre",companyName:(null==e?void 0:e.corporate_name)||(null==e?void 0:e.company_name)})})}function D(e){let{label:t,value:r,decimal:l=!0,accent:a}=e,n=!1===l?null!=r?r:0:I(r);return(0,o.jsx)(j.A,{sx:{...w.Cy,minHeight:84,display:"flex",flexDirection:"column",justifyContent:"center"},children:(0,o.jsxs)(A.A,{sx:{p:2,"&:last-child":{pb:2}},children:[(0,o.jsx)(u.A,{sx:{fontSize:11,fontWeight:500,color:w.lm.muted},children:t}),(0,o.jsx)(u.A,{sx:{fontWeight:700,fontSize:18,color:a||w.lm.ink,mt:.5},children:n})]})})}function I(e){return null==e||isNaN(e)?"R$\xa00.00":Number(e).toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}function P(e){return e?"string"==typeof e?e.slice(0,10):e.toISOString().slice(0,10):""}L.getLayout=e=>(0,o.jsx)(k.A,{requiredPermission:"meli.bi.view",children:e})},17510:(e,t,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/meli/bi",function(){return r(4236)}])},70825:(e,t,r)=>{"use strict";r.d(t,{Cy:()=>s,WL:()=>c,W_:()=>d,e8:()=>u,hj:()=>h,lm:()=>n,qs:()=>m,zY:()=>i});var o=r(37876);r(14232);var l=r(46520),a=r(61428);let n={pageBg:"#f4f6fb",cardBorder:"#e7e9f0",fieldFill:"#f8fafc",fieldBorder:"#e2e8f0",headFill:"#f8fafc",headBorder:"#eef2f7",rowBorder:"#f1f5f9",primary:"#1976d2",primaryDark:"#1565c0",ink:"#0f172a",text:"#334155",textStrong:"#1e293b",muted:"#64748b",faint:"#94a3b8",outline:"#cbd5e1"};function i(e){let{title:t,subtitle:r,right:i,sx:s}=e;return(0,o.jsxs)(l.A,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,mb:2,flexWrap:"wrap",...s},children:[(0,o.jsxs)(l.A,{children:[(0,o.jsx)(a.A,{variant:"h4",component:"h1",sx:{fontWeight:700,letterSpacing:"-0.02em",color:n.ink,fontSize:{xs:"1.4rem",sm:"1.65rem"},lineHeight:1.15},children:t}),r&&(0,o.jsx)(a.A,{variant:"body2",sx:{color:"text.secondary",mt:.25},children:r})]}),i]})}let s={bgcolor:"#fff",border:"1px solid ".concat(n.cardBorder),borderRadius:"12px",boxShadow:"none"},d={"& .MuiOutlinedInput-root":{borderRadius:"8px",bgcolor:n.fieldFill,fontSize:13,"& fieldset":{borderColor:n.fieldBorder},"&:hover fieldset":{borderColor:n.outline}},"& .MuiInputLabel-root":{fontSize:13,color:n.muted}},c={border:"none","& .MuiDataGrid-columnHeaders":{backgroundColor:"".concat(n.headFill," !important"),borderBottom:"1px solid ".concat(n.headBorder)},"& .MuiDataGrid-columnHeader":{backgroundColor:"".concat(n.headFill," !important")},"& .MuiDataGrid-columnHeaderTitle":{fontWeight:600,fontSize:11,color:n.muted},"& .MuiDataGrid-columnSeparator":{display:"none !important"},"& .MuiDataGrid-cell":{borderBottom:"1px solid ".concat(n.rowBorder),fontSize:12,color:n.text},"& .MuiDataGrid-footerContainer":{borderTop:"1px solid ".concat(n.rowBorder),backgroundColor:n.headFill}},u={"& .MuiTableCell-head":{backgroundColor:n.headFill,color:n.muted,fontWeight:600,fontSize:11,borderBottom:"1px solid ".concat(n.headBorder),py:1},"& .MuiTableCell-stickyHeader":{backgroundColor:"".concat(n.headFill," !important")},"& .MuiTableCell-body":{fontSize:12,color:n.text,borderBottom:"1px solid ".concat(n.rowBorder)},"& .MuiTableSortLabel-root, & .MuiTableSortLabel-root:hover, & .MuiTableSortLabel-root.Mui-active":{color:"".concat(n.muted," !important")},"& .MuiTableSortLabel-icon":{color:"".concat(n.muted," !important")}},x={green:["#e8f5e9","#2e7d32"],orange:["#fff3e0","#ef6c00"],red:["#feebee","#d32f2f"],blue:["#e3f2fd","#1565c0"],amber:["#fff8e1","#b45309"],neutral:["#eef2f7","#546e7a"]};function m(e){let{label:t,tone:r="neutral",width:a}=e,[n,i]=x[r]||x.neutral;
1return(0,o.jsx)(l.A,{component:"span",sx:{display:"inline-flex",alignItems:"center",justifyContent:a?"flex-start":"center",bgcolor:n,color:i,fontSize:10,fontWeight:500,px:1,py:"2px",borderRadius:"999px",lineHeight:1.4,width:a||"auto",whiteSpace:"nowrap"},children:t})}let h={"& .MuiToggleButton-root":{textTransform:"none",fontSize:12,fontWeight:500,color:n.muted,border:"1px solid ".concat(n.fieldBorder),borderRadius:"7px !important",px:1.5,py:.5,mr:.75,"&.Mui-selected":{bgcolor:n.primary,color:"#fff","&:hover":{bgcolor:n.primaryDark}}}}},84949:(e,t,r)=>{"use strict";r.d(t,{A:()=>x});var o=r(37876);r(14232);var l=r(46520),a=r(11054),n=r(61428),i=r(31331),s=r(27481),d=r(95268),c=r(93943),u=r(89099);function x(e){let{marketplaceName:t="Mercado Livre",companyName:r,showButton:x=!0}=e,m=(0,u.useRouter)();return(0,o.jsx)(l.A,{sx:{p:3,display:"flex",justifyContent:"center",alignItems:"center",minHeight:"60vh"},children:(0,o.jsxs)(a.A,{sx:{p:4,maxWidth:600,textAlign:"center",borderRadius:2},children:[(0,o.jsx)(d.A,{sx:{fontSize:64,color:"text.secondary",mb:2}}),(0,o.jsx)(n.A,{variant:"h5",gutterBottom:!0,fontWeight:"bold",children:"Marketplace N\xe3o Configurado"}),(0,o.jsxs)(n.A,{variant:"body1",color:"text.secondary",paragraph:!0,children:["A empresa ",(0,o.jsx)("strong",{children:r})," n\xe3o possui o ",(0,o.jsx)("strong",{children:t})," configurado."]}),(0,o.jsx)(i.A,{severity:"info",sx:{mb:3,textAlign:"left"},children:(0,o.jsxs)(n.A,{variant:"body2",children:[(0,o.jsx)("strong",{children:"Para visualizar os dados:"}),(0,o.jsx)("br",{}),"1. Acesse as configura\xe7\xf5es da empresa",(0,o.jsx)("br",{}),"2. Configure as credenciais do ",t,(0,o.jsx)("br",{}),"3. Ative o marketplace para esta empresa"]})}),x&&(0,o.jsx)(s.A,{variant:"contained",startIcon:(0,o.jsx)(c.A,{}),onClick:()=>{m.push("/settings/companies")},size:"large",children:"Configurar Marketplace"}),(0,o.jsx)(n.A,{variant:"caption",display:"block",sx:{mt:2,color:"text.secondary"},children:"Cada empresa pode ter marketplaces espec\xedficos configurados independentemente."})]})})}}},e=>{var t=t=>e(e.s=t);e.O(0,[7661,7715,5242,5776,4515,3207,2809,2053,6320,2906,9729,6343,5767,6465,2528,636,6593,8792],()=>t(17510)),_N_E=e.O()}]);
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.