Files
Rasadyar_FrontEnd/build/assets/SlaughterInventoryPage-C_Mhkpg6.js
2026-01-19 15:55:00 +03:30

2 lines
92 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{j as u,T as V,ag as $u,ah as Yu,ai as gu,aj as Su,ak as z,B as J,d as Du,I as wu,aX as u6,av as S6,aw as b6,ax as Vu,b0 as E6,b2 as e6,b3 as Iu,al as Hu,c9 as V6,an as H6,ao as Gu,b4 as Ku,ap as Qu,aq as Zu,b as Fu,aJ as U6,b1 as G6,aa as K6,am as Q6}from"./mui-vendor-CkIVaoQP.js";import{L as su,j as tu,h as ru,A as vu,u as Uu,c as Ru,b as ku,G as l,S as Q,C as c6,fH as _u,O as Wu,v as G,X as eu,p as ju,W as iu,N as du,fl as D6,jv as Z6,cq as qu,M as hu,fF as Xu,e8 as J6,dn as w6,dp as _6,fT as Ou,fI as X6,jw as m6,jx as u0,_ as L6,dh as T6,j9 as Ju,ju as e0,jy as i6,jz as a0,jA as d6,jB as t0,jC as C6,bT as h6,jD as g6,jE as p6,jt as r0,jF as n0}from"./index-Vwb3Bce5.js";import{B as Eu}from"./BackButton-CX1bfrW9.js";import{r,f as s0}from"./react-vendor-CmFgShSM.js";import{a as a6,d as l0,S as o0}from"./SlaughterSellCarcass-aTlo1rLy.js";import{a as Nu,u as lu,f as Mu}from"./redux-vendor-B7uoacJt.js";import{R as cu}from"./ResponsiveTable-DugzNG82.js";import{p as c0}from"./province-policy-drop-limit-qzpRWpbK.js";import{d as i0}from"./Settings-CQYLXtys.js";import{R as Lu,a as k6}from"./index.esm-Bu7XMDZU.js";import{a as $6,b as d0,s as C0,c as I6,d as h0,v as g0,S as p0}from"./SlaughterFreeBuyBars-CmFNn9_4.js";import{S as R6}from"./ShowImage-DVQI0Zh5.js";import{d as x0}from"./ToggleOffOutlined-6-7EFsBZ.js";import{d as A0}from"./ToggleOn-DkUpTkpl.js";import{d as f0}from"./SystemUpdateAlt-DElmCVQA.js";import{C as W6}from"./ChechClearanceCode-DDXdFQyx.js";import{d as N6}from"./Tune-DzkdDfJZ.js";import{d as B6}from"./Search-CLlOaERQ.js";import{s as y0,a as F0,g as j0,b as v0,c as S0,S as b0,d as E0,e as D0,f as w0,h as _0,i as P6}from"./StewardSegmentOperation-BAUI5RnA.js";import{s as L0,a as T0}from"./slaughter-get-provinces-CcGCtzRc.js";import{L as O6}from"./LabelField-BQFRAtg7.js";import{d as Y6}from"./Edit-CwJaslma.js";import{s as x6}from"./slaughter-sell-carcass-out-province-DlzZ5JKk.js";import{N as mu}from"./NumberFormatCustom-DwWPj40N.js";import{M as k0,S as $0}from"./SlaughterAllocateToGuild-D4Rv4RKa.js";import{s as M6,g as I0,a as R0}from"./steward-get-dashboard-service-Cwt20o7g.js";import{d as z6}from"./Delete-DHYHiC8G.js";import{d as W0}from"./Send-DPLmC2fd.js";import{d as A6}from"./Info-CJG2wnhf.js";import{I as N0,f as B0}from"./toBase64-DB8tmZmy.js";import{d as P0}from"./Add-C-nZhvlM.js";import{d as O0}from"./CheckCircle-eA7tEzBu.js";import{a as Y0}from"./province-policy-upload-image-Bz2ni3_d.js";import{d as M0}from"./Visibility-Dotz22eQ.js";import{a as z0}from"./SlaughterManageInventoryAllocationOperations-CAkldXdj.js";import{N as Bu}from"./NavLink-D2GD_ItM.js";import{L as Pu}from"./LinkItem-Cp7DiDkz.js";import"./guild-allocated-stock-operation-BZvss5_H.js";import"./getProvinceName-BujSmyBy.js";import"./slaughter-get-guilds-for-allocate-Xqnmd7KJ.js";import"./Sms-DJEGTBb8.js";import"./getAllocationType-76F45b0K.js";import"./FilterAlt-CTDmPS36.js";import"./styled-components.browser.esm-gS9mh05b.js";import"./iconBase-BEJYyZsk.js";import"./CarPelak-3Cy5Nurk.js";import"./EditOutlined-TxNFG3HQ.js";import"./DeleteOutlineOutlined-BatOxAQI.js";import"./Download-guGqWZIG.js";import"./Close-8pFLGZ5w.js";import"./Pageview-DD_sus_t.js";import"./AddCircleOutline-BMHZv8K-.js";import"./PublishedWithChanges-BErs-ATv.js";import"./CheckCircleOutline-DkCEhVRL.js";const q0=Nu("SLAUGHTER_SUBMIT_REAL_INVENTORY",async(e,{dispatch:n})=>{n(su());try{const{data:a,status:E}=await tu.put("ware-house-accept-kill-house-request/0/",e);return n(ru()),{data:a,status:E}}catch(a){return n(ru()),{error:a.response.data.result}}}),V0=({item:e,updateTable:n})=>{var F,I,c;const[a,E]=r.useState("weight"),[h,f]=r.useState("0"),[x,D]=r.useState({min:0,max:100}),d=b=>{E(b.target.value)},[j,v]=r.useState(e!=null&&e.killer?"killer":"self"),Y=b=>{v(b.target.value)},[k]=r.useContext(vu),T=lu();r.useEffect(()=>{T(c0()).then(b=>{var p;(p=b.payload)!=null&&p.data&&D({min:parseFloat(b.payload.data.killHouseLimitPercentDown),max:parseFloat(b.payload.data.killHouseLimitPercentUp)})})},[]);const y=Uu({initialValues:{realNumber:e!=null&&e.acceptedRealQuantity?e==null?void 0:e.acceptedRealQuantity:"",realWeight:e!=null&&e.wareHouseAcceptedRealWeight?e==null?void 0:e.wareHouseAcceptedRealWeight:0},validationSchema:Ru({realNumber:ku().typeError("لطفا فیلد را به درستی وارد کنید.!").required("این فیلد اجباری است!").min(0,"مقدار نمی‌تواند منفی باشد"),realWeight:ku().typeError("لطفا فیلد را به درستی وارد کنید.!").required("این فیلد اجباری است!").min(0,"مقدار نمی‌تواند منفی باشد")})}),w=Uu({initialValues:{lossWeight:""},validationSchema:Ru({lossWeight:ku().typeError("لطفا فیلد را به درستی وارد کنید.!").required("این فیلد اجباری است!").min(x.min,`درصد افت باید بین ${x.min} تا ${x.max} درصد باشد!`).max(x.max,`درصد افت باید بین ${x.min} تا ${x.max} درصد باشد!`)})});r.useEffect(()=>{if(a==="weight")if(e!=null&&e.acceptedRealWeight&&y.values.realWeight){const p=(e.acceptedRealWeight-y.values.realWeight)/e.acceptedRealWeight*100;f(p.toFixed(2))}else f(0);else if(e!=null&&e.acceptedRealWeight&&w.values.lossWeight){const b=e.acceptedRealWeight/100*w.values.lossWeight;f((e.acceptedRealWeight-b).toFixed(2))}else f(0)},[y.values.realWeight,w.values.lossWeight,a,e]);const B=()=>a==="weight"?h>=x.min&&h<=x.max:w.isValid,M=()=>a==="weight"?y.isValid&&B():w.isValid,L=()=>{if(!M())return;const b=a==="weight"?{input_type:"input_weight",ware_house_accepted_real_quantity:parseInt(y.values.realNumber),ware_house_accepted_real_weight:parseInt(y.values.realWeight),kill_house_request_key:e==null?void 0:e.key,loss_percent:parseFloat(h)}:{input_type:"loss_weight",loss_percent:parseInt(w.values.lossWeight),kill_house_request_key:e==null?void 0:e.key};T(q0({...b,...e!=null&&e.killer?{input_warehouse:j}:{}})).then(p=>{p.payload.error?k({vertical:"top",horizontal:"center",msg:p.payload.error,severity:"error"}):(T(c6()),n(),T(_u()),g())})},g=()=>{T(Wu({title:"عملیات با موفقیت انجام شد",content:u.jsx(u.Fragment,{children:u.jsxs(l,{container:!0,gap:Q.SMALL,justifyContent:"center",children:[u.jsx(V,{variant:"body2",color:"secondary",children:"جهت ویرایش میتوانید حداکثر تا پایان امروز یا قبل از اولین تخصیص اقدام کنید."}),u.jsx(J,{variant:"outlined",onClick:()=>{T(c6())},children:"متوجه شدم"})]})})}))};return u.jsx(u.Fragment,{children:u.jsxs(l,{xs:12,container:!0,spacing:Q.SMALL,alignItems:"center",justifyContent:"center",children:[u.jsxs(l,{container:!0,xs:12,gap:Q.TINY,children:[u.jsxs(l,{container:!0,xs:12,gap:Q.SMALL,justifyContent:"center",children:[(e==null?void 0:e.killer)&&u.jsxs(V,{color:"primary",variant:"body2",children:["کشتارکن: ",(F=e==null?void 0:e.killer)==null?void 0:F.name]}),u.jsxs(V,{color:"primary",variant:"body2",children:["کد بار: ",e.barCode]}),u.jsxs(V,{color:"primary",variant:"body2",children:["حجم بار: ",(I=e==null?void 0:e.acceptedRealQuantity)==null?void 0:I.toLocaleString()]}),u.jsxs(V,{color:"primary",variant:"body2",children:["وزن بار: ",(c=e==null?void 0:e.acceptedRealWeight)==null?void 0:c.toLocaleString()]})]}),u.jsx($u,{children:u.jsxs(Yu,{"aria-labelledby":"demo-radio-buttons-group-label",defaultValue:"بر اساس وزن ورودی",name:"radio-buttons-group",value:a,onChange:d,row:!0,children:[u.jsx(gu,{value:"weight",control:u.jsx(Su,{}),label:"بر اساس وزن ورودی"}),u.jsx(gu,{value:"loss",control:u.jsx(Su,{}),label:"بر اساس درصد افت"})]})}),a==="weight"?u.jsxs(u.Fragment,{children:[u.jsx(z,{fullWidth:!0,id:"realWeight",size:"small",label:"وزن لاشه",variant:"outlined",value:y.values.realWeight,error:y.touched.realWeight?!!y.errors.realWeight:null,onChange:y.handleChange,onBlur:y.handleBlur,helperText:y.touched.realWeight&&y.errors.realWeight?y.errors.realWeight:null}),u.jsx(z,{fullWidth:!0,id:"realNumber",size:"small",label:"حجم لاشه",variant:"outlined",value:y.values.realNumber,error:y.touched.realNumber?!!y.errors.realNumber:null,onChange:y.handleChange,onBlur:y.handleBlur,helperText:y.touched.realNumber&&y.errors.realNumber?y.errors.realNumber:null})]}):u.jsx(z,{fullWidth:!0,id:"lossWeight",size:"small",label:"درصد افت",variant:"outlined",value:w.values.lossWeight,error:w.touched.lossWeight?!!w.errors.lossWeight:null,onChange:w.handleChange,onBlur:w.handleBlur,helperText:w.touched.lossWeight&&w.errors.lossWeight?w.errors.lossWeight:null})]}),(e==null?void 0:e.killer)&&u.jsx(l,{mt:2,xs:12,container:!0,justifyContent:"start",p:1,sx:{borderStyle:"solid",borderWidth:"1px",borderColor:"red",borderRadius:"15px"},children:u.jsx($u,{children:u.jsxs(Yu,{"aria-labelledby":"demo-radio-buttons-group-label",defaultValue:j,name:"radio-buttons-group",value:j,onChange:Y,row:!0,children:[u.jsx(gu,{value:"self",control:u.jsx(Su,{color:"error"}),label:"ورود به انبار کشتارگاه"}),u.jsx(gu,{value:"killer",control:u.jsx(Su,{color:"error"}),label:"ورود به انبار کشتارکن"})]})})}),u.jsxs(l,{container:!0,xs:12,gap:4,alignItems:"center",mt:2,justifyContent:"space-between",children:[u.jsx(l,{children:a==="weight"?u.jsxs(l,{container:!0,gap:2,alignItems:"center",children:[u.jsxs(V,{variant:"body1",color:"primary",children:["افت: ",h>0?h:0,"%"]}),!B()&&u.jsxs(V,{variant:"body2",color:"error",children:["درصد افت باید بین ",x.min," تا ",x.max," درصد باشد!"]})]}):u.jsxs(V,{variant:"body1",color:"primary",children:["وزن: ",h]})}),u.jsx(l,{children:u.jsx(J,{disabled:!M(),size:"small",variant:"outlined",onClick:L,children:"ثبت"})})]})]})})},f6=({type:e})=>{const[n,a]=r.useState(G(new Date).format("YYYY-MM-DD")),[E,h]=r.useState(G(new Date).format("YYYY-MM-DD")),f=lu(),x=P=>{B(P.target.value)},[D,d]=r.useState(e==="entered"),[j,v]=r.useState([]),[Y,k]=r.useState(0),[T,y]=r.useState(10),[w,B]=r.useState(""),[M,L]=r.useState(1),[g,F]=r.useState([]),[I,c]=r.useState("all"),b=r.useCallback(async P=>{f(su());const o=await tu.get(`bars_for_kill_house/?search=filter&value=${w}&role=${eu()}${D?`&date1=${n}&date2=${E}`:""}&page=${P}&page_size=${T}&type=${e}&quota=${I}`);f(ru()),v(o.data.results),k(o.data.count)},[w,D,n,E,T,e,I,f,v,k]),p=P=>{b(P),L(P)},t=P=>{y(P),L(1)},q=()=>{b(M!==0?M:1)};r.useEffect(()=>{const P=j==null?void 0:j.map((o,_)=>{var s,i,Z,A,$,H,au,K,X,m,ou,uu,S,C,N,U,O,R,Cu,pu,xu,Au,fu,yu,nu,bu,Tu,zu,t6,r6,n6,s6,l6,o6;return[M===1?_+1:_+T*(M-1)+1,o==null?void 0:o.barCode,ju((s=o==null?void 0:o.poultryRequest)==null?void 0:s.date),`${(i=o==null?void 0:o.poultryRequest)==null?void 0:i.poultryName} (${(Z=o==null?void 0:o.poultryRequest)==null?void 0:Z.poultryMobile}) - ${(A=o==null?void 0:o.poultryRequest)==null?void 0:A.poultryUserName}`,($=o==null?void 0:o.poultryRequest)==null?void 0:$.poultryCity,`${(H=o==null?void 0:o.killhouseUser)!=null&&H.killer?"کشتارکن":"کشتارگاه"} ${(au=o==null?void 0:o.killhouseUser)==null?void 0:au.name} (${(m=(X=(K=o==null?void 0:o.killhouseUser)==null?void 0:K.killHouseOperator)==null?void 0:X.user)==null?void 0:m.mobile})`,(ou=o==null?void 0:o.poultryRequest)==null?void 0:ou.poultryReqOrderCode,o!=null&&o.freezing?"انجماد":o!=null&&o.export?"صادرات":"عادی",o!=null&&o.killer?`${(uu=o==null?void 0:o.killer)==null?void 0:uu.name} (${(N=(C=(S=o==null?void 0:o.killer)==null?void 0:S.killHouseOperator)==null?void 0:C.user)==null?void 0:N.mobile})`:"-",(U=o==null?void 0:o.poultryRequest)!=null&&U.freeSaleInProvince?"آزاد":"دولتی",(O=o==null?void 0:o.poultryRequest)==null?void 0:O.chickenBreed,`${(Cu=(R=o==null?void 0:o.addCar)==null?void 0:R.driver)==null?void 0:Cu.driverName}/${(xu=(pu=o==null?void 0:o.addCar)==null?void 0:pu.driver)==null?void 0:xu.typeCar}`,(fu=(Au=o==null?void 0:o.addCar)==null?void 0:Au.driver)!=null&&fu.healthCode?(nu=(yu=o==null?void 0:o.addCar)==null?void 0:yu.driver)==null?void 0:nu.healthCode:"-",o!=null&&o.clearanceCode?o==null?void 0:o.clearanceCode:"-",(bu=o==null?void 0:o.acceptedRealQuantity)==null?void 0:bu.toLocaleString(),(Tu=o==null?void 0:o.acceptedRealWeight)==null?void 0:Tu.toLocaleString(),(zu=o==null?void 0:o.weightInfo)==null?void 0:zu.state,o==null?void 0:o.wareHouseAcceptedRealQuantity.toLocaleString(),o==null?void 0:o.wareHouseAcceptedRealWeight.toLocaleString(),(t6=o==null?void 0:o.weightInfo)!=null&&t6.weightLoss?((n6=(r6=o==null?void 0:o.weightInfo)==null?void 0:r6.weightLoss)==null?void 0:n6.toFixed(2))+"%":"0%",(s6=o==null?void 0:o.weightInfo)!=null&&s6.inputLoss?((o6=(l6=o==null?void 0:o.weightInfo)==null?void 0:l6.inputLoss)==null?void 0:o6.toFixed(2))+"%":"0%",o!=null&&o.dateOfWareHouse?ju(o==null?void 0:o.dateOfWareHouse):"-",u.jsx(Du,{title:"ورود بار به انبار",children:u.jsx(wu,{size:"small",color:"primary",onClick:()=>{f(Wu({title:"ثبت موجودی واقعی",content:u.jsx(V0,{updateTable:q,item:o})}))},children:u.jsx(i0,{fontSize:"small"})})},_)]});F(P)},[j]),r.useEffect(()=>{b(1)},[b]);const W=async P=>{P.preventDefault(),f(su());try{const o=await tu.get(`bars_for_kill_house/?role=${eu()}&search=filter&value=${w}${D?`&date1=${n}&date2=${E}`:""}&page=1&page_size=${T}&type=${e}&quota=${I}`);v(o.data.results),k(o.data.count),f(ru())}catch(o){console.error("Error fetching data:",o)}};return u.jsxs(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(l,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:[u.jsxs(l,{container:!0,style:{borderStyle:"solid",borderWidth:"1px",padding:"10px",borderRadius:"15px",borderColor:"gray",justifyContent:"left"},children:[e==="notentered"&&u.jsx(l,{children:u.jsx(gu,{control:u.jsx(u6,{checked:D,onChange:()=>d(!D),color:"primary"})})}),u.jsx(l,{children:u.jsx(iu,{disabled:!D,label:"از تاریخ",id:"date",renderInput:P=>u.jsx(z,{size:"small",style:{width:"160px"},...P}),value:n,onChange:P=>{a(G(P).format("YYYY-MM-DD"))}})}),u.jsx(l,{children:u.jsx(iu,{disabled:!D,label:"تا تاریخ",id:"date",renderInput:P=>u.jsx(z,{size:"small",style:{width:"160px"},...P}),value:E,onChange:P=>{h(G(P).format("YYYY-MM-DD"))}})})]}),u.jsx(l,{children:u.jsxs($u,{size:"small",style:{minWidth:150},children:[u.jsx(S6,{children:"نوع فروش"}),u.jsxs(b6,{value:I,onChange:P=>c(P.target.value),label:"نوع فروش",children:[u.jsx(Vu,{value:"all",children:"همه"}),u.jsx(Vu,{value:"governmental",children:"دولتی"}),u.jsx(Vu,{value:"free",children:"آزاد"})]})]})}),u.jsx(l,{children:u.jsxs("form",{onSubmit:W,children:[u.jsx(z,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:x}),u.jsx(J,{type:"submit",onClick:W,endIcon:u.jsx(Lu,{}),children:"جستجو"})]})})]}),u.jsx(cu,{data:g,columns:["ردیف","کدبار","تاریخ کشتار","مرغدار","شهر مرغدار","خریدار","کدسفارش","کشتار","کشتارکن","فروش","نژاد","راننده/نوع خودرو","کدبهداشتی حمل و نقل","کدرهگیری سامانه قرنطینه","حجم بار (قطعه)","وزن بار (کیلوگرم)","وضعیت","حجم لاشه","وزن لاشه","درصد افت در لحظه","درصد افت ورود به انبار","تاریخ ورود به انبار","عملیات"],handlePageChange:p,totalRows:Y,page:M,perPage:T,handlePerRowsChange:t,title:e==="entered"?"وارد شده به انبار (کشتار داخل استان)":"در انتظار ورود به انبار (کشتار داخل استان)"})]})},H0=({item:e,updateTable:n,barState:a,type:E})=>{const h=lu(),[f,x]=r.useState(null),D=T=>{x(T.currentTarget)},d=()=>{x(null)},j=!!f,v=j?"popover":void 0,Y=()=>E==="carcass"||(e==null?void 0:e.buyType)!=="live"?!0:!a&&!e.weightOfCarcasses,k=(e==null?void 0:e.registerType)==="automatic"?!1:e.weightOfCarcasses&&!a&&(e==null?void 0:e.buyType)==="live";return u.jsxs("div",{children:[u.jsx(wu,{disabled:k,"aria-describedby":v,variant:"contained",color:"primary",onClick:D,children:u.jsx(N6,{})}),u.jsx(E6,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:v,open:j,anchorEl:f,onClose:d,children:u.jsx("div",{style:{padding:"20px"},children:u.jsxs(l,{container:!0,direction:"column",children:[a==="entered"&&(e==null?void 0:e.registerType)==="automatic"&&u.jsx(J,{onClick:()=>{d(),h(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ویرایش بار آزاد",content:u.jsx($6,{item:e,updateTable:n})}))},children:"ویرایش"}),(a==="entered"?(e==null?void 0:e.registerType)!=="automatic":!0)&&u.jsx(J,{onClick:()=>{d(),h(Wu({title:"ثبت اطلاعات لاشه ورودی به انبار",content:u.jsx(d0,{item:e,updateTable:n,IsEdit:a==="entered"})}))},children:a==="entered"?"ویرایش":"ورود به انبار"}),Y()&&(e==null?void 0:e.registerType)!=="automatic"&&u.jsx(J,{color:"error",onClick:()=>{d(),h(C0(e.key)).then(()=>{n(),h(_u())})},children:"حذف"})]})})})]})},y6=({title:e,barState:n,fetchDashboardData:a,withDate:E,selectedDate1:h,selectedDate2:f,searchValue:x})=>{const D=lu(),[d]=r.useContext(vu);r.useEffect(()=>{D(D6())},[]);const[j,v]=r.useState([]),[Y,k]=r.useState(0),[T,y]=r.useState(10),[w,B]=r.useState(1),[M,L]=r.useState([]),g=async p=>{let t;D(su());try{t=await tu.get(`kill_house_free_bar/?type=live&role=${eu()}&page=${p}&page_size=${T}&bar_state=${n}&date_type=input${E?`&date1=${h}&date2=${f}`:""}${x?`&search=filter&value=${x}`:""}`),v(t.data.results),k(t.data.count)}catch(q){console.error("Error fetching data:",q)}finally{D(ru())}},F=p=>{g(p),B(p)},I=p=>{y(p),B(1)},c=()=>{g(w!==0?w:1),a()};r.useEffect(()=>{g(1)},[T,E,h,f,x]),r.useEffect(()=>{const p=j==null?void 0:j.map((t,q)=>{var W,P,o,_,s,i,Z,A;return[w===1?q+1:q+T*(w-1)+1,(t==null?void 0:t.barCode)||"-",(t==null?void 0:t.registerType)==="automatic"?"سیستمی":"دستی",ju(t.createDate),`${(W=t==null?void 0:t.killHouse)==null?void 0:W.name} (${(_=(o=(P=t==null?void 0:t.killHouse)==null?void 0:P.killHouseOperator)==null?void 0:o.user)==null?void 0:_.mobile})`,t!=null&&t.exclusiveKiller?`${(s=t==null?void 0:t.exclusiveKiller)==null?void 0:s.name} (${(A=(Z=(i=t==null?void 0:t.exclusiveKiller)==null?void 0:i.killHouseOperator)==null?void 0:Z.user)==null?void 0:A.mobile})`:"-",t.buyType==="live"?"مرغ زنده":"لاشه",t.poultryName,`${t.province}/${t.city}`,u.jsx(W6,{clearanceCode:t.barClearanceCode},q),t.quantity.toLocaleString(),t.liveWeight.toLocaleString(),ju(t.date),t.numberOfCarcasses.toLocaleString(),t.weightOfCarcasses.toLocaleString(),t!=null&&t.weightLoss?(t==null?void 0:t.weightLoss)+"%":"-",u.jsx(R6,{src:t.barImage},q),u.jsx(u.Fragment,{children:eu()==="KillHouse"?u.jsx(H0,{item:t,inventoryKey:t==null?void 0:t.key,updateTable:c,barState:n},t.key):u.jsx(J,{variant:"outlined",disabled:(t==null?void 0:t.killHouseVetState)!=="pending",size:"small",onClick:()=>{D(Wu({title:"تایید / رد",content:u.jsx(I6,{item:t,updateTable:c})}))},children:"تایید / رد"})})]});L(p)},[j,w,T]);const b=Mu(p=>p.userSlice.userProfile.key);return u.jsx(l,{container:!0,justifyContent:"flex-end",mt:2,mb:2,children:u.jsx(l,{container:!0,mt:Q.MEDIUM,alignItems:"end",gap:2,justifyContent:"flex-end",children:u.jsx(cu,{operation:u.jsx(l,{children:u.jsx(Du,{title:"خروجی اکسل",placement:"top",children:u.jsx(wu,{color:"primary",onClick:()=>{d({vertical:"top",horizontal:"center",msg:"فایل اکسل در حال دانلود می باشد، این علمیات ممکن است زمان بر باشد لطفا صبر کنید.",severity:"success"});const p=`${tu.defaults.baseURL}kill_house_free_bar_excel/?role=${eu()}&key=${b}&type=live&bar_state=${n}${E?`&date1=${h}&date2=${f}`:""}`;window.location.href=p},children:u.jsx(f0,{})})})}),data:M,columns:["ردیف","کد بار","نوع بار","تاریخ خرید","خریدار","کشتارکن","محصول","فروشنده","استان/شهر","کدقرنطینه","حجم زنده","وزن زنده (کیلوگرم)","تاریخ ورود به انبار","حجم لاشه","وزن لاشه (کیلوگرم)","درصد افت","بارنامه","عملیات"],handlePageChange:F,totalRows:Y,page:w,perPage:T,handlePerRowsChange:I,title:e})})})},U0=()=>{var A,$,H,au,K,X,m,ou,uu,S,C,N,U;const e=lu(),[n,a]=r.useState(0),E=(O,R)=>{a(R)},[,,h,f,x,D]=r.useContext(vu);r.useEffect(()=>{const O=G(new Date).format("YYYY-MM-DD");f(O),D(O)},[]);const d=O=>{B(O.target.value)};r.useEffect(()=>{e(D6())},[]);const[j,v]=r.useState([]),[Y,k]=r.useState(0),[T,y]=r.useState(10),[w,B]=r.useState(""),[M,L]=r.useState(1),[g,F]=r.useState([]),[I,c]=r.useState(!1),[b,p]=r.useState(""),t=async O=>{let R;e(su()),R=await tu.get(`kill_house_free_bar/?type=${n===0?"live":"carcass"}&dashboard=true&search=filter&value=${b}&role=${eu()}${I?`&date1=${h}&date2=${x}`:""}&page=${O}&page_size=${T}&date_type=input`),e(ru()),v(R.data.results),k(R.data.count)},q=O=>{t(O),L(O)},W=O=>{y(O),L(1)},P=()=>{t(M!==0?M:1),o()},o=()=>{e(g0({search:"filter",role:eu(),value:b,type:n===0?"live":"carcass",...I&&{date1:h,date2:x}})).then(O=>{Z(O.payload.data)})};r.useEffect(()=>{t(M!==0?M:1),o()},[I,h,x,T,n,b]),r.useEffect(()=>{const O=j==null?void 0:j.map((R,Cu)=>{var pu,xu,Au,fu,yu,nu,bu,Tu;return[M===1?Cu+1:Cu+T*(M-1)+1,(R==null?void 0:R.barCode)||"-",ju(R.createDate),`${(pu=R==null?void 0:R.killHouse)==null?void 0:pu.name} (${(fu=(Au=(xu=R==null?void 0:R.killHouse)==null?void 0:xu.killHouseOperator)==null?void 0:Au.user)==null?void 0:fu.mobile})`,R!=null&&R.exclusiveKiller?`${(yu=R==null?void 0:R.exclusiveKiller)==null?void 0:yu.name} (${(Tu=(bu=(nu=R==null?void 0:R.exclusiveKiller)==null?void 0:nu.killHouseOperator)==null?void 0:bu.user)==null?void 0:Tu.mobile})`:"-",R.buyType==="live"?"مرغ زنده":"لاشه",R.poultryName,`${R.province}/${R.city}`,R.barClearanceCode,R.numberOfCarcasses.toLocaleString(),R.weightOfCarcasses.toLocaleString(),u.jsx(R6,{src:R.barImage},Cu),u.jsx(u.Fragment,{children:eu()==="KillHouse"?u.jsx(h0,{item:R,inventoryKey:R==null?void 0:R.key,updateTable:P,type:"carcass"},R.key):u.jsx(J,{variant:"outlined",disabled:(R==null?void 0:R.killHouseVetState)!=="pending",size:"small",onClick:()=>{e(Wu({title:"تایید / رد",content:u.jsx(I6,{item:R,updateTable:P})}))},children:"تایید / رد"})})]});F(O)},[j]);const _=async O=>{O.preventDefault(),p(w)},s=Mu(O=>O.userSlice.userProfile.key),[i,Z]=r.useState([]);return u.jsxs(l,{container:!0,direction:"column",flexWrap:"nowrap",children:[u.jsx(l,{container:!0,justifyContent:"center",alignItems:"center",children:u.jsxs(e6,{scrollButtons:"auto",variant:"scrollable",allowScrollButtonsMobile:!0,value:n,onChange:E,children:[u.jsx(Iu,{label:"زنده"}),u.jsx(Iu,{label:"لاشه"})]})}),n===0&&u.jsx(l,{mt:2,container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:u.jsxs(l,{container:!0,gap:1,style:{borderStyle:"solid",borderWidth:"1px",padding:"5px",borderRadius:"15px",borderColor:"gray",justifyContent:"left"},alignItems:"center",children:[u.jsx(u6,{icon:u.jsx(x0,{}),checkedIcon:u.jsx(A0,{}),checked:I,onChange:()=>{c(!I),t(1)},color:"primary",size:"large"}),u.jsx(l,{children:u.jsx(iu,{disabled:!I,label:"از تاریخ",id:"date",renderInput:O=>u.jsx(z,{size:"small",style:{width:"160px"},...O}),value:h,onChange:O=>{f(G(O).format("YYYY-MM-DD"))}})}),u.jsx(l,{children:u.jsx(iu,{disabled:!I,label:"تا تاریخ",id:"date",renderInput:O=>u.jsx(z,{size:"small",style:{width:"160px"},...O}),value:x,onChange:O=>{D(G(O).format("YYYY-MM-DD"))}})}),u.jsx(l,{children:u.jsxs("form",{onSubmit:_,children:[u.jsx(z,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},value:w,onChange:d}),u.jsx(J,{type:"submit",onClick:_,endIcon:u.jsx(Lu,{}),children:"جستجو"})]})})]})}),u.jsxs(l,{container:!0,mt:Q.MEDIUM,alignItems:"center",justifyContent:"center",gap:2,children:[u.jsx(l,{container:!0,alignItems:"center",gap:Q.SMALL,justifyContent:"start",xs:12,children:u.jsx(J,{variant:"contained",onClick:()=>{e(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ثبت اطلاعات خرید",content:u.jsx($6,{inventoryKey:"slaughterGetInventoryStockData?.key",selectedDate:h,updateTable:P})}))},children:"ثبت اطلاعات خرید"})}),u.jsx(l,{container:!0,mb:4,isDashboard:!0,children:n===0?u.jsx(cu,{noPagination:!0,columns:["تعداد کل بارهای زنده","حجم کل بارهای زنده","وزن کل بارهای زنده","تعداد کل بارها وارد شده به انبار","حجم کل بارهای زنده وارد شده به انبار","وزن کل بارهای زنده وارد شده به انبار","وزن لاشه بارهای وارد شده به انبار","تعداد کل بارها وارد نشده به انبار","حجم کل بارهای زنده وارد نشده به انبار","وزن کل بارهای زنده وارد نشده به انبار"],data:[[(A=i==null?void 0:i.totalBars)==null?void 0:A.toLocaleString(),($=i==null?void 0:i.totalBarsQuantity)==null?void 0:$.toLocaleString(),(H=i==null?void 0:i.totalBarsLiveWeight)==null?void 0:H.toLocaleString(),(au=i==null?void 0:i.enteredTotalBars)==null?void 0:au.toLocaleString(),(K=i==null?void 0:i.enteredTotalBarsQuantity)==null?void 0:K.toLocaleString(),(X=i==null?void 0:i.enteredTotalBarsLiveWeight)==null?void 0:X.toLocaleString(),(m=i==null?void 0:i.enteredTotalBarsWeightOfCarcasses)==null?void 0:m.toLocaleString(),(ou=i==null?void 0:i.notEnteredTotalBars)==null?void 0:ou.toLocaleString(),(uu=i==null?void 0:i.notEnteredTotalBarsQuantity)==null?void 0:uu.toLocaleString(),(S=i==null?void 0:i.notEnteredTotalBarsLiveWeight)==null?void 0:S.toLocaleString()]],customColors:[{name:"وزن لاشه بارهای وارد شده به انبار",color:"green"}],title:"خلاصه اطلاعات"}):u.jsx(cu,{noPagination:!0,isDashboard:!0,columns:["تعداد کل بارها","حجم لاشه","وزن لاشه"],data:[[(C=i==null?void 0:i.totalBars)==null?void 0:C.toLocaleString(),(N=i==null?void 0:i.totalBarsNumberOfCarcasses)==null?void 0:N.toLocaleString(),(U=i==null?void 0:i.totalBarsWeightOfCarcasses)==null?void 0:U.toLocaleString()]],title:"خلاصه اطلاعات"})}),n===0?u.jsxs(u.Fragment,{children:[u.jsx(y6,{title:"بار زنده در انتظار ورود به انبار (خارج استان)",barState:"notentered",fetchDashboardData:o,searchValue:b,withDate:I,selectedDate1:h,selectedDate2:x}),u.jsx(y6,{title:"بار زنده وارد شده به انبار (خارج استان)",barState:"entered",fetchDashboardData:o,searchValue:b,withDate:I,selectedDate1:h,selectedDate2:x})]}):u.jsxs(u.Fragment,{children:[u.jsx("form",{onSubmit:_,children:u.jsxs(l,{container:!0,alignItems:"center",gap:Q.SMALL,children:[u.jsx(z,{size:"small",autoComplete:"off",label:"جستجو",variant:"outlined",style:{width:250},value:w,onChange:d}),u.jsx(J,{type:"submit",onClick:_,endIcon:u.jsx(Lu,{}),children:"جستجو"}),u.jsx(l,{children:u.jsx(iu,{label:"از تاریخ",id:"date",renderInput:O=>u.jsx(z,{style:{width:"160px"},...O}),value:h,onChange:O=>{f(G(O).format("YYYY-MM-DD"))},disabled:!I})}),u.jsx(l,{children:u.jsx(iu,{label:"تا تاریخ",id:"date",renderInput:O=>u.jsx(z,{style:{width:"160px"},...O}),value:x,onChange:O=>{D(G(O).format("YYYY-MM-DD"))},disabled:!I})}),u.jsx(Du,{title:"خروجی اکسل",children:u.jsx(J,{color:"success",onClick:()=>{const O=`${tu.defaults.baseURL}kill_house_free_bar_excel/?role=${eu()}&key=${s}${I?`&date1=${h}&date2=${x}`:""}&type=${n===0?"live":"carcass"}&search=filter&value=${b}&date_type=input`;window.location.href=O},children:u.jsx(k6,{size:32})})})]})}),u.jsx(cu,{data:g,columns:["ردیف","کد بار","تاریخ خرید","خریدار","کشتارکن","محصول","فروشنده","استان/شهر","کدقرنطینه","حجم لاشه","وزن لاشه (کیلوگرم)","بارنامه","عملیات"],handlePageChange:q,totalRows:Y,page:M,perPage:T,handlePerRowsChange:W,title:"بار لاشه خرید خارج استان"})]})]})]})},G0=()=>{var x,D,d,j,v,Y,k,T,y,w;const[e,n]=r.useState("0"),[a,E]=r.useState([]),h=(B,M)=>{n(M)},f=lu();return r.useEffect(()=>{f(Z6()).then(B=>{E(B.payload.data)})},[f]),u.jsxs(l,{container:!0,xs:12,justifyContent:"end",alignItems:"center",children:[u.jsx(l,{container:!0,width:"100%",isDashboard:!0,children:u.jsx(a6,{})}),u.jsx(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",mt:2,children:u.jsxs(e6,{value:e,onChange:h,textColor:"secondary",indicatorColor:"secondary","aria-label":"secondary tabs example",children:[u.jsx(Iu,{value:"0",label:"بارهای داخل استان"}),u.jsx(Iu,{value:"1",label:"خریدهای خارج استان"})]})}),e==="0"&&u.jsx(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",children:u.jsxs(l,{container:!0,justifyContent:"start",alignItems:"center",xs:12,children:[u.jsx(cu,{title:"اطلاعات کلی بارها",noPagination:!0,data:[[(x=a==null?void 0:a.totalBars)==null?void 0:x.toLocaleString(),(D=a==null?void 0:a.totalBarsQuantity)==null?void 0:D.toLocaleString(),(d=a==null?void 0:a.totalBarsWeight)==null?void 0:d.toLocaleString(),(j=a==null?void 0:a.totalEnteredBars)==null?void 0:j.toLocaleString(),(v=a==null?void 0:a.totalEnteredBarsWeight)==null?void 0:v.toLocaleString(),(Y=a==null?void 0:a.totalEnteredBarsCarcasses)==null?void 0:Y.toLocaleString(),(k=a==null?void 0:a.totalEnteredBarsCarcassesWeight)==null?void 0:k.toLocaleString(),(T=a==null?void 0:a.totalNotEnteredBars)==null?void 0:T.toLocaleString(),(y=a==null?void 0:a.totalNotEnteredBarsQuantity)==null?void 0:y.toLocaleString(),(w=a==null?void 0:a.totalNotEnteredKillHouseRequestsWeight)==null?void 0:w.toLocaleString()]],columns:["تعداد کل بارها","حجم کل بارها (قطعه)","وزن کل بارها (کیلوگرم)","تعداد کل بارهای وارد شده","وزن کل بارهای وارد شده","حجم کل لاشه وارد شده (قطعه)","وزن کل لاشه وارد شده (کیلوگرم)","تعداد کل بارهای وارد نشده","حجم کل بار وارد نشده (قطعه)","وزن کل بار وارد نشده (کیلوگرم)"],allColors:{color:"#f3bda3",text:"#332a3d"}}),u.jsx(l,{container:!0,mt:Q.MEDIUM,mb:Q.MEDIUM,children:u.jsx(f6,{type:"notentered"})}),u.jsx(l,{container:!0,mt:Q.MEDIUM,mb:Q.MEDIUM,children:u.jsx(f6,{type:"entered"})})]})}),e==="1"&&u.jsx(l,{container:!0,mt:Q.MEDIUM,mb:Q.MEDIUM,children:u.jsx(U0,{})})]})},K0=()=>u.jsx(l,{container:!0,alignItems:"center",justifyContent:"center",direction:"column",xs:12,children:u.jsx(G0,{})}),F6=Nu("PROVINCE_GET_NATIONAL_DOCUMENTS_SERVICE",async(e,{dispatch:n})=>{var a,E,h;n(su());try{const{data:f,status:x}=await tu.get(`https://pay.rasadyar.com/national-documents?info=${e.info}&type=${e.type}`,{timeout:3e4});return n(ru()),{data:f,status:x}}catch(f){if(n(ru()),f.code==="ECONNABORTED"||f.message.includes("timeout"))return qu("زمان درخواست به پایان رسید. لطفا دوباره تلاش کنید.","error"),{error:"زمان درخواست به پایان رسید. لطفا دوباره تلاش کنید."};if(((a=f.response)==null?void 0:a.status)===500)return qu("خطای سرور رخ داده است. لطفا بعدا تلاش کنید.","error"),{error:"خطای سرور رخ داده است. لطفا بعدا تلاش کنید."};if(!f.response)return qu("خطا در برقراری ارتباط با سرور. لطفا اتصال اینترنت خود را بررسی کنید.","error"),{error:"خطا در برقراری ارتباط با سرور. لطفا اتصال اینترنت خود را بررسی کنید."};const x=((h=(E=f.response)==null?void 0:E.data)==null?void 0:h.result)||"خطا در دریافت اطلاعات";return qu(x,"error"),{error:x}}}),Q0=(e,n)=>{if(!e||typeof e!="string"||!n||n.length===0)return"";const a=e.replace(/\u200c/g," ").replace(/\s+/g," ").trim(),h=a.split(/\s+/).slice(0,2).join(" "),f=n.find(x=>{const D=x.name||"";return D.includes(h)||h.includes(D)||a.includes(D)});return f?f.name:""},j6=({updateTable:e,isEdit:n,data:a,defaultPersonType:E,defaultNationalCode:h})=>{const[f]=r.useContext(vu),[x,D]=r.useState(null),[d,j]=r.useState(!1),[v,Y]=r.useState(!1),[k,T]=r.useState({}),y=lu(),[w,B]=r.useState([]),[M,L]=r.useState([]),g=Uu({initialValues:{mobile:"",firstName:"",lastName:"",unitName:"",province:"",city:"",nationalId:""},validationSchema:Ru({mobile:hu().required("این فیلد اجباری است!").min(11,"شماره موبایل باید 11 رقم باشد").max(11,"شماره موبایل باید 11 رقم باشد").matches(/^09\d{9}$/,"شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),firstName:hu().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),lastName:hu().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),unitName:hu().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),province:hu().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),city:hu().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),nationalId:hu().required("این فیلد اجباری است!").matches(/^\d{10,11}$/,"شناسه باید 10 یا 11 رقم و فقط عدد باشد")}),validateOnMount:!0}),F=Uu({initialValues:{personType:E||"real",nationalCode:h||""},validationSchema:Ru({personType:hu().oneOf(["real","legal"]).required(),nationalCode:hu().required("این فیلد اجباری است!").when("personType",{is:"real",then:c=>c.length(10,"کد ملی باید 10 رقم باشد").matches(/^\d{10}$/,"کد ملی باید فقط شامل اعداد باشد"),otherwise:c=>c.length(11,"شناسه ملی حقوقی باید 11 رقم باشد").matches(/^\d{11}$/,"شناسه ملی حقوقی باید فقط شامل اعداد باشد")})}),validateOnMount:!0});r.useEffect(()=>{g.validateForm()},[]),r.useEffect(()=>{n&&(a!=null&&a.buyer)&&(a.buyer.isRealPerson===!1&&F.setFieldValue("personType","legal",!1),a.buyer.nationalCode||a.buyer.parentLegalPersonNationalCode&&F.setFieldValue("nationalCode",a.buyer.parentLegalPersonNationalCode,!1))},[n,a]),r.useEffect(()=>{if(x){g.setValues({mobile:x.mobile||"",firstName:x.firstName||"",lastName:x.lastName||"",unitName:x.unitName||"",province:x.province||"",city:x.city||"",nationalId:x.nationalId||""});const b=["nationalId","mobile","firstName","lastName","unitName","city"].reduce((p,t)=>{const q=x[t];return p[t]=!!(q&&q!==""),p},{});b.province=!1,T(b),setTimeout(()=>{g.validateForm()},1)}},[x]),r.useEffect(()=>{n&&(g.setValues({mobile:a.mobile||"",firstName:a.firstName||"",lastName:a.lastName||"",unitName:a.unitName||"",province:a.province||"",city:a.city||"",nationalId:a.national_id||a.nationalId||""}),T({}),setTimeout(()=>{g.validateForm()},1))},[n]),r.useEffect(()=>{y(L0()).then(c=>{B(c.payload.data)})},[]),r.useEffect(()=>{g.values.province&&L([],y(T0(g.values.province)).then(c=>{L(c.payload.data)}))},[g.values.province]);const I=async()=>{var q,W,P,o,_,s,i,Z,A,$;if(!F.isValid||v)return;const c=F.values.nationalCode,b=F.values.personType;Y(!0),j(!1),D(null),T({});let p=null,t=null;try{if(b==="legal"){const m=`https://pay.rasadyar.com/national-documents?info=${encodeURIComponent(c)}&type=unit`,uu=await(await fetch(m)).json();if(uu!=null&&uu.status&&(uu!=null&&uu.data)){const S=uu.data,C=Q0(S.address||"",w),N={mobile:"",firstName:S.name||"",lastName:S.name||"",unitName:S.name||"",province:S.state||C||"",city:"",nationalId:S.nationalCode||c};D(N),F.setFieldValue("nationalCode",N.nationalId||c),f({vertical:"top",horizontal:"center",msg:"اطلاعات حقوقی با موفقیت دریافت شد.",severity:"success"})}else j(!0),g.setFieldValue("nationalId",c),T({}),f({vertical:"top",horizontal:"center",msg:"اطلاعات حقوقی برای این شناسه یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",severity:"warning"});return}const H=await y(F6({info:c,type:"person"}));(q=H.payload)!=null&&q.error?f({vertical:"top",horizontal:"center",msg:H.payload.error,severity:"error"}):(P=(W=H.payload)==null?void 0:W.data)!=null&&P.status&&((_=(o=H.payload)==null?void 0:o.data)!=null&&_.data)?p=H.payload.data.data:f({vertical:"top",horizontal:"center",msg:"اطلاعات فردی یافت نشد.",severity:"warning"});const au=await y(F6({info:c,type:"guild"}));if((s=au.payload)!=null&&s.error)f({vertical:"top",horizontal:"center",msg:au.payload.error,severity:"error"});else if((Z=(i=au.payload)==null?void 0:i.data)!=null&&Z.status&&(($=(A=au.payload)==null?void 0:A.data)!=null&&$.data)){const m=au.payload.data.data,ou=Array.isArray(m)?m:[m];if(ou.length>0){const uu=ou.findIndex(S=>S.licenseStatus==="فعال/صادر شده");t=ou[uu!==-1?uu:0]}else f({vertical:"top",horizontal:"center",msg:"اطلاعات صنفی برای این کد ملی یافت نشد.",severity:"warning"})}else f({vertical:"top",horizontal:"center",msg:"اطلاعات صنفی برای این کد ملی یافت نشد.",severity:"warning"});if(!p&&!t){j(!0),g.setFieldValue("nationalId",c),T({}),f({vertical:"top",horizontal:"center",msg:"اطلاعاتی برای این کد ملی یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",severity:"warning"});return}const K=(t==null?void 0:t.layerTwo)||{},X={mobile:K.mobilenumber||(p==null?void 0:p.mobile)||K.phonenumber||"",firstName:(p==null?void 0:p.firstName)||"",lastName:(p==null?void 0:p.lastName)||"",unitName:(t==null?void 0:t.title)||K.corporationName||K.unionName||"",province:(t==null?void 0:t.state)||"",city:(t==null?void 0:t.city)||"",nationalId:(p==null?void 0:p.nationalId)||K.nationalcode||(t==null?void 0:t.nationalId)||c};D(X),F.setFieldValue("nationalCode",X.nationalId||c),f({vertical:"top",horizontal:"center",msg:"اطلاعات با موفقیت دریافت شد.",severity:"success"})}finally{Y(!1)}};return u.jsxs(l,{container:!0,justifyContent:"space-between",alignItems:"center",xs:12,direction:"column",gap:2,children:[u.jsxs(l,{container:!0,xs:12,children:[u.jsx(O6,{label:"نوع شخص",children:u.jsxs(Yu,{row:!0,name:"personType",value:F.values.personType,onChange:c=>{const b=c.target.value;F.setFieldValue("personType",b),D(null),j(!1),T({}),g.resetForm({values:{mobile:"",firstName:"",lastName:"",unitName:"",province:"",city:"",nationalId:""}})},children:[u.jsx(gu,{value:"real",control:u.jsx(Su,{}),label:"حقیقی"}),u.jsx(gu,{value:"legal",control:u.jsx(Su,{}),label:"حقوقی"})]})}),u.jsxs(V,{mt:2,children:["استعلام ",F.values.personType==="legal"?"شناسه ملی حقوقی":"کد ملی"]}),u.jsxs(l,{mt:Q.SMALL,display:"flex",width:1,children:[u.jsx(z,{fullWidth:!0,id:"nationalCode",name:"nationalCode",label:F.values.personType==="legal"?"شناسه ملی حقوقی":"کد ملی",variant:"outlined",value:F.values.nationalCode,error:!!(F.touched.nationalCode&&F.errors.nationalCode),onChange:F.handleChange,onBlur:F.handleBlur,helperText:F.touched.nationalCode&&F.errors.nationalCode,inputProps:{maxLength:F.values.personType==="legal"?11:10}}),u.jsx(wu,{disabled:!F.isValid||v,"aria-label":"search",color:"primary",onClick:I,children:u.jsx(B6,{})})]})]}),x||d||n?u.jsxs(l,{container:!0,justifyContent:"space-between",alignItems:"start",xs:12,direction:"column",gap:2,children:[u.jsx(z,{fullWidth:!0,id:"nationalId",name:"nationalId",label:F.values.personType==="legal"?"شناسه ملی حقوقی":"کد ملی",disabled:!0,variant:"outlined",value:F.values.personType==="legal"?F.values.nationalCode:g.values.nationalId,onChange:g.handleChange,onBlur:g.handleBlur,helperText:g.touched.nationalId&&g.errors.nationalId,InputProps:{readOnly:!!k.nationalId}}),u.jsx(z,{fullWidth:!0,id:"mobile",label:"شماره موبایل",variant:"outlined",value:g.values.mobile,onChange:g.handleChange,onBlur:g.handleBlur,error:!!g.errors.mobile,helperText:g.errors.mobile}),u.jsx(z,{fullWidth:!0,id:"firstName",label:"نام",variant:"outlined",value:g.values.firstName,onChange:g.handleChange,onBlur:g.handleBlur,helperText:g.touched.firstName&&g.errors.firstName,disabled:!!k.firstName,InputProps:{readOnly:!!k.firstName},error:!!g.errors.firstName}),u.jsx(z,{fullWidth:!0,id:"lastName",label:"نام خانوادگی",variant:"outlined",value:g.values.lastName,onChange:g.handleChange,onBlur:g.handleBlur,helperText:g.touched.lastName&&g.errors.lastName,disabled:!!k.lastName,InputProps:{readOnly:!!k.lastName},error:!!g.errors.lastName}),u.jsx(z,{fullWidth:!0,id:"unitName",label:"نام واحد",variant:"outlined",value:g.values.unitName,onChange:g.handleChange,onBlur:g.handleBlur,helperText:g.touched.unitName&&g.errors.unitName,disabled:!!k.unitName,InputProps:{readOnly:!!k.unitName},error:!!g.errors.unitName}),u.jsx(Hu,{style:{width:"100%"},disablePortal:!0,id:"province",options:w?w.map(c=>({id:c.name,label:c.name})):[],disabled:!!k.province,isOptionEqualToValue:(c,b)=>c.id===b.id,onChange:(c,b)=>{g.setFieldValue("province",b?b.id:""),g.setFieldValue("city","")},value:g.values.province?{id:g.values.province,label:g.values.province}:null,renderInput:c=>u.jsx(z,{...c,label:"استان را انتخاب کنید"})}),!d&&u.jsxs(V,{variant:"caption",color:"error",children:["استان: ",g.values.province]}),u.jsx(Hu,{minWidth:210,style:{width:"100%"},disabled:!g.values.province||!!k.city,disablePortal:!0,id:"city",options:M?M.map(c=>({id:c.name,label:c.name})):[],isOptionEqualToValue:(c,b)=>c.id===b.id,onChange:(c,b)=>{g.setFieldValue("city",b?b.id:"")},value:g.values.city?{id:g.values.city,label:g.values.city}:null,renderInput:c=>u.jsx(z,{...c,label:"شهر را انتخاب کنید"})}),!d&&u.jsxs(V,{variant:"caption",color:"error",children:["شهر: ",g.values.city]})]}):u.jsx(V,{variant:"body2",color:"text.secondary",children:"برای نمایش فرم، ابتدا استعلام کد ملی را انجام دهید."}),(x||d||n)&&u.jsx(l,{container:!0,xs:12,children:u.jsx(J,{fullWidth:!0,variant:"contained",disabled:!g.isValid,onClick:()=>{n?y(y0({buyer_key:a==null?void 0:a.key,mobile:g.values.mobile,first_name:g.values.firstName,last_name:g.values.lastName,unit_name:g.values.unitName,city:g.values.city,province:g.values.province,national_id:g.values.nationalId})).then(c=>{e(),c.payload.error?f({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(y(du({right:!1,bottom:!1,content:null})),f({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}):y(F0({mobile:g.values.mobile,first_name:g.values.firstName,last_name:g.values.lastName,unit_name:g.values.unitName,city:g.values.city,province:g.values.province,national_id:F.values.personType==="legal"?null:g.values.nationalId,...F.values.personType==="legal"&&{isRealPerson:!1,info_value:F.values.nationalCode}})).then(c=>{e(),c.payload.error?f({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(y(du({right:!1,bottom:!1,content:null})),f({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:n?"ویرایش":"ثبت"})})]})},Z0=()=>{const e=I=>{j(I.target.value)},n=lu(),[a,E]=r.useState([]),[h,f]=r.useState(0),[x,D]=r.useState(10),[d,j]=r.useState(""),[v,Y]=r.useState(1),[k,T]=r.useState([]),[y,w]=r.useState("real"),B=async I=>{n(su());const c=await tu.get(`out-province-carcasses-buyer/?search=filter&value=${d}&role=${eu()}&page=${I}&page_size=${x}&state=buyer-list&type=${y}`);n(ru()),E(c.data.results),f(c.data.count)},M=I=>{B(I),Y(I)},L=I=>{D(I),Y(1)},g=()=>{B(v!==0?v:1)};r.useEffect(()=>{const I=a==null?void 0:a.map((c,b)=>{var W,P,o,_,s,i,Z,A,$,H,au,K,X;const p=[v===1?b+1:b+x*(v-1)+1],t=`${c==null?void 0:c.fullname} (${c==null?void 0:c.mobile})`,q=u.jsx(wu,{color:"primary",onClick:()=>{var m,ou;n(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(j6,{updateTable:g,isEdit:!0,data:c,defaultPersonType:(m=c==null?void 0:c.buyer)!=null&&m.parentLegalPersonNationalCode?"legal":"real",defaultNationalCode:(ou=c==null?void 0:c.buyer)==null?void 0:ou.nationalCode}),title:"ویرایش خریدار"}))},children:u.jsx(Y6,{})},b);return y==="real"?[...p,t,c==null?void 0:c.unitName,c==null?void 0:c.province,c==null?void 0:c.city,(P=(W=c==null?void 0:c.requestsInfo)==null?void 0:W.numberOfRequests)==null?void 0:P.toLocaleString(),(_=(o=c==null?void 0:c.requestsInfo)==null?void 0:o.totalQuantity)==null?void 0:_.toLocaleString(),(i=(s=c==null?void 0:c.requestsInfo)==null?void 0:s.totalWeight)==null?void 0:i.toLocaleString(),q]:[...p,c==null?void 0:c.unitName,(Z=c==null?void 0:c.buyer)==null?void 0:Z.parentLegalPersonNationalCode,c==null?void 0:c.province,c==null?void 0:c.city,($=(A=c==null?void 0:c.requestsInfo)==null?void 0:A.numberOfRequests)==null?void 0:$.toLocaleString(),(au=(H=c==null?void 0:c.requestsInfo)==null?void 0:H.totalQuantity)==null?void 0:au.toLocaleString(),(X=(K=c==null?void 0:c.requestsInfo)==null?void 0:K.totalWeight)==null?void 0:X.toLocaleString(),q]});T(I)},[a,y,v,x,n]),r.useEffect(()=>{B(1)},[n,x,y]);const F=async I=>{I.preventDefault(),n(su());try{const c=await tu.get(`out-province-carcasses-buyer/?role=${eu()}&search=filter&value=${d}&page=1&page_size=${x}&state=buyer-list&type=${y}`);E(c.data.results),f(c.data.count),n(ru())}catch(c){console.error("Error fetching data:",c)}};return u.jsxs(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsx(l,{container:!0,justifyContent:"center",alignItems:"center",gap:2,xs:12,children:u.jsx($u,{children:u.jsxs(Yu,{style:{display:"flex",justifyContent:"center"},row:!0,"aria-labelledby":"person-type-radio-group",name:"personType",value:y,onChange:I=>{const c=I.target.value;w(c),Y(1)},children:[u.jsx(gu,{value:"real",control:u.jsx(Su,{}),label:"حقیقی"}),u.jsx(gu,{value:"legal",control:u.jsx(Su,{}),label:"حقوقی"})]})})}),u.jsxs(l,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:[u.jsx(J,{variant:"contained",onClick:()=>{n(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(j6,{updateTable:g}),title:"افزودن خریدار"}))},children:"افزودن خریدار"}),u.jsx(l,{children:u.jsxs("form",{onSubmit:F,children:[u.jsx(z,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:e}),u.jsx(J,{type:"submit",onClick:F,endIcon:u.jsx(Lu,{}),children:"جستجو"})]})})]}),u.jsx(cu,{data:k,columns:y==="real"?["ردیف","مشخصات خریدار","نام واحد","استان","شهر","تعداد درخواست ها","حجم تقریبی (قطعه)","وزن (کیلوگرم)","ویرایش"]:["ردیف","نام واحد","شناسه حقوقی","استان","شهر","تعداد درخواست ها","حجم تقریبی (قطعه)","وزن (کیلوگرم)","ویرایش"],handlePageChange:M,totalRows:h,page:v,perPage:x,handlePerRowsChange:L,title:"خریداران لاشه خارج استان"})]})},J0=Nu("SLAUGHTER_GET_BUYERS_CARCASS",async(e,{dispatch:n})=>{n(su());const{data:a,status:E}=await tu.get("out-province-carcasses-buyer/",{params:{role:eu()}});return n(ru()),{data:a,status:E}}),X0=Nu("SLAUGHTER_SUBMIT_CARCASS_OUT_PROVINCE_SELL",async(e,{dispatch:n})=>{try{const{data:a,status:E}=await tu.post("kill_house_free_sale_bar/",e);return n(su()),{data:a,status:E}}catch(a){return n(ru()),{error:a.response.data.result}}}),m0=(e,n)=>Ru({weight_of_carcasses:ku().required("وزن لاشه‌ها الزامی است").integer("عدد باید صحیح باشد!").positive("وزن باید عددی مثبت باشد").test("max-production-date-amount",`وزن نمی‌تواند بیشتر از موجودی تاریخ تولید (${(e==null?void 0:e.toLocaleString())||0} کیلوگرم) باشد!`,function(a){return!e||e===null?!0:a<=e}),clearance_code:hu().required("کد قرنطینه الزامی است").matches(/^(?=.*[A-Z])(?=.*\d)[A-Z0-9]+$/,"کد قرنطینه باید ترکیبی از حروف بزرگ انگلیسی و عدد باشد"),date:X6().required("تاریخ الزامی است").test("date-not-before-production","تاریخ نمی‌تواند قبل از تاریخ تولید باشد",function(a){return!n||!a?!0:G(a).isSameOrAfter(G(n),"day")})}),q6=({updateTable:e,fetchItems:n,isInventory:a})=>{const[E,h]=r.useState([]),[f,x]=r.useState(null),[D]=r.useState("free"),[d,j]=r.useState("governmental"),v=lu(),[Y]=r.useContext(vu),[k,T]=r.useState(null),[y,w]=r.useState({}),[B,M]=r.useState(null),[L,g]=r.useState(null),[F,I]=r.useState({governmental:[],free:[]}),c=r.useRef(null);r.useEffect(()=>{v(J0()).then(A=>{h(A.payload.data)})},[v]);const[b,p]=r.useState([]),[t,q]=r.useState(null);r.useEffect(()=>{v(Xu()).then(A=>{p(A.payload.data)})},[]);const W=A=>{const $=A.target.value;if(j($),$==="governmental"&&c.current){const H=G(new Date).format("YYYY-MM-DD");c.current.setFieldValue("date",H),i(H),Z(H)}},P=A=>{if(A&&A.formattedDate){T(A.formattedDate);const $=y[A.formattedDate];$&&$.originalDay&&M($.originalDay),$&&$.value1!==void 0?g($.value1):g(null)}},o=r.useCallback(A=>{if(!Array.isArray(A))return{};const $={};return A.forEach(H=>{if(H.day&&H.amount!==void 0){const K=new J6(new Date(H.day)).format("YYYY/MM/DD");$[K]={value1:H.amount,originalDay:H.day,active:H.active===!0}}}),$},[]),_=r.useCallback(A=>{const $=o(A);w($)},[o]),[s,i]=r.useState(G(new Date).format("YYYY-MM-DD")),Z=r.useCallback(async(A=s)=>{try{const $=await tu.get("/kill-house-remain-weight/",{params:{date:A}});if($.data){I({governmental:$.data.governmental||[],free:$.data.free||[]});const H=d==="governmental"?$.data.governmental:$.data.free;_(H)}}catch($){console.error("Error fetching calendar data:",$)}},[d,_,s]);return r.useEffect(()=>{Z(s)},[Z,s]),r.useEffect(()=>{if(d==="governmental"&&c.current){const A=G(new Date).format("YYYY-MM-DD");c.current.setFieldValue("date",A),i(A),Z(A)}},[d,Z]),r.useEffect(()=>{if(F.governmental.length>0||F.free.length>0){const A=d==="governmental"?F.governmental:F.free;_(A),T(null),M(null),g(null)}},[d,F,_]),u.jsx(l,{container:!0,gap:Q.SMALL,direction:"column",display:"flex",children:u.jsxs(l,{container:!0,gap:Q.SMALL,direction:"column",children:[u.jsx(l,{minWidth:210,children:u.jsx(Hu,{disablePortal:!0,id:"combo-box-demo",getOptionDisabled:A=>A.disabled,options:E?E.map(A=>({id:A==null?void 0:A.key,label:`${A==null?void 0:A.fullname} (${A.mobile}) / استان ${A.province} / شهر ${A.city}`,item:A})):[],onChange:(A,$)=>{x($==null?void 0:$.id)},renderInput:A=>u.jsx(z,{...A,label:"انتخاب خریدار"})})}),f&&u.jsxs(u.Fragment,{children:[u.jsx(l,{xs:12,container:!0,children:u.jsx(Hu,{fullWidth:!0,disablePortal:!0,id:"hatching",options:b?b.map(A=>({data:A,label:`${A.name}`})):[],onChange:(A,$)=>{q($.data)},renderInput:A=>u.jsx(z,{fullWidth:!0,...A,label:"انتخاب محصول"})})}),u.jsx(w6,{innerRef:c,initialValues:{weight_of_carcasses:"",clearance_code:"",date:G(new Date).format("YYYY-MM-DD")},validationSchema:m0(L,B),onSubmit:A=>{v(X0({buyer_key:f,number_of_carcasses:Math.round((A==null?void 0:A.weight_of_carcasses)/(t==null?void 0:t.weightAverage))||0,weight_of_carcasses:parseInt(A.weight_of_carcasses),date:A.date,clearance_code:A.clearance_code,product_key:t==null?void 0:t.key,sale_type:D,quota:d,production_date:B,distribution_type:"web"})).then($=>{$.payload.error?Y({vertical:"top",horizontal:"center",msg:$.payload.error,severity:"error"}):(a?n():e(),v(_u()),v(du({right:!1,bottom:!1,content:null})),Y({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:({values:A,errors:$,touched:H,setFieldValue:au})=>u.jsx(_6,{children:u.jsxs(l,{container:!0,gap:Q.SMALL,direction:"column",children:[u.jsx(l,{item:!0,children:u.jsx(z,{disabled:!0,label:"حجم تقریبی",value:Math.round((A==null?void 0:A.weight_of_carcasses)/(t==null?void 0:t.weightAverage))||0,InputProps:{readOnly:!0}})}),u.jsx(O6,{label:"نوع انبار",children:u.jsx($u,{fullWidth:!0,children:u.jsxs(Yu,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:d,onChange:W,sx:{justifyContent:"space-between"},children:[u.jsx(gu,{value:"governmental",control:u.jsx(Su,{}),label:"دولتی"}),u.jsx(gu,{value:"free",control:u.jsx(Su,{}),label:"آزاد"})]})})}),u.jsx(l,{children:u.jsx(iu,{label:"تاریخ",disabled:d==="governmental",value:G(A.date),onChange:K=>{const X=G(K).format("YYYY-MM-DD");au("date",X),i(X),Z(X)},renderInput:K=>u.jsx(z,{...K,fullWidth:!0,size:"small",error:H.date&&!!$.date,helperText:H.date&&$.date})})}),u.jsx(l,{item:!0,children:u.jsx(Ou,{name:"clearance_code",as:z,label:"کد قرنطینه",fullWidth:!0,onChange:K=>au("clearance_code",K.target.value.toUpperCase()),error:H.clearance_code&&!!$.clearance_code,helperText:H.clearance_code&&$.clearance_code})}),u.jsxs(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:Q.TINY,sx:{width:"100%"},direction:"column",children:[u.jsx(k0,{onDateSelect:P,dayData:y,selectedDate:k,maxGregorianDate:A.date,label:`تاریخ تولید گوشت ${L!==null?`(موجودی: ${L==null?void 0:L.toLocaleString()} کیلوگرم)`:""}`}),B&&A.date&&G(B).isAfter(G(A.date),"day")&&u.jsx(V,{sx:{color:"#d32f2f",fontSize:"0.75rem",marginTop:"4px",marginRight:"14px",textAlign:"right"},children:"تاریخ تولید نمی‌تواند بعد از تاریخ انتخابی باشد"})]}),u.jsx(l,{item:!0,children:u.jsx(Ou,{name:"weight_of_carcasses",children:({field:K,form:X,meta:m})=>u.jsx(mu,{allowLeadingZeros:!0,thousandSeparator:",",decimalScale:0,allowNegative:!1,fullWidth:!0,id:"weight_of_carcasses",label:"وزن لاشه‌ها",variant:"outlined",value:K.value,error:m.touched&&!!m.error||L&&K.value>L,onChange:ou=>{const uu=ou.target.value;if(uu===""||uu===null||uu===void 0){X.setFieldValue("weight_of_carcasses","");return}const S=Math.floor(Number(uu));S>0?X.setFieldValue("weight_of_carcasses",S):S===0&&X.setFieldValue("weight_of_carcasses","")},onBlur:K.onBlur,helperText:L&&K.value>L?`وزن نمی‌تواند بیشتر از موجودی تاریخ تولید (${L==null?void 0:L.toLocaleString()} کیلوگرم) باشد!`:m.touched&&m.error})})}),u.jsxs(l,{container:!0,spacing:Q.SMALL,children:[u.jsx(l,{xs:6,children:u.jsx(J,{fullWidth:!0,type:"submit",variant:"contained",disabled:!t||!B||L&&A.weight_of_carcasses>L||B&&A.date&&G(A.date).isBefore(G(B),"day"),children:"ثبت"})}),u.jsx(l,{xs:6,children:u.jsx(J,{fullWidth:!0,variant:"outlined",color:"primary",onClick:()=>{v(du({right:!1,bottom:!1,content:null}))},children:"انصراف"})})]})]})})})]})]})})},ue=({item:e,fetchApiData:n})=>{const a=lu(),[E]=r.useContext(vu),[h,f]=r.useState((e==null?void 0:e.loggedRegistrationCode)||""),x=()=>{var D,d;a(M6({key:e==null?void 0:e.key,register_code:parseInt(h),role:eu(),date:e==null?void 0:e.date,buyer_name:e==null?void 0:e.buyerName,buyer_mobile:e==null?void 0:e.buyerMobile,province:e==null?void 0:e.province,city:e==null?void 0:e.city,clearance_code:e==null?void 0:e.clearanceCode,number_of_carcasses:e==null?void 0:e.numberOfCarcasses,quarantine_weight_of_carcasses:e==null?void 0:e.quarantineWeightOfCarcasses,weight_of_carcasses:e==null?void 0:e.weightOfCarcasses,quota:e==null?void 0:e.quota,sale_type:e==null?void 0:e.saleType,...((D=e==null?void 0:e.buyer)==null?void 0:D.key)&&{buyer_key:(d=e==null?void 0:e.buyer)==null?void 0:d.key}})).then(j=>{j.payload.error?E({vertical:"top",horizontal:"center",msg:j.payload.error,severity:"error"}):(E({vertical:"top",horizontal:"center",msg:"کد احراز با موفقیت ثبت شد.",severity:"success"}),n())})};return u.jsxs(l,{container:!0,direction:"row",alignItems:"center",justifyContent:"flex-start",gap:1,sx:{position:"relative"},children:[u.jsx(z,{value:h,size:"small",onChange:D=>f(D.target.value),style:{minWidth:"150px"},disabled:e==null?void 0:e.loggedRegistrationCode,placeholder:"کد احراز",inputProps:{inputMode:"numeric",pattern:"[0-9]*"},type:"number"}),!(e!=null&&e.loggedRegistrationCode)&&h&&u.jsx(J,{size:"small",variant:"contained",color:"primary",onClick:x,sx:{position:"absolute",right:"0",minWidth:"40px",width:"40px",height:"38px"},children:u.jsx(V6,{})})]})},ee=Nu("SLAUGHTER_DELETE_OUT_OF_PROVINCE_SELL",async(e,{dispatch:n})=>{n(su());try{const{data:a,status:E}=await tu.delete(`kill_house_free_sale_bar/0/?key=${e}`);return n(ru()),{data:a,status:E}}catch(a){return n(ru()),{error:a}}}),ae=Ru().shape({quarantineCode:hu().required("کد قرنطینه الزامی است"),carcassCount:ku().required("حجم لاشه الزامی است"),carcassWeight:ku().required("وزن لاشه الزامی است"),date:hu().required("تاریخ الزامی است")}),te=({fetchItems:e,isEdit:n,item:a,selectedDate:E,stewardKey:h})=>{const f=lu(),[x]=r.useContext(vu),D={quarantineCode:(a==null?void 0:a.clearanceCode)||"",carcassCount:(a==null?void 0:a.numberOfCarcasses)||"",carcassWeight:(a==null?void 0:a.weightOfCarcasses)||"",date:(a==null?void 0:a.date)||G().format("YYYY-MM-DD HH:mm:ss")};return u.jsx(l,{children:u.jsx(w6,{initialValues:D,validationSchema:ae,onSubmit:d=>{const j={...d,date:d.date,number_of_carcasses:d.carcassCount,weight_of_carcasses:d.carcassWeight};d.quarantineCode!==(a==null?void 0:a.quarantineCode)&&(j.quarantineCode=d.quarantineCode);const v=h?n?I0({key:a==null?void 0:a.key,...j}):j0({steward_key:h,...j}):n?M6({key:a==null?void 0:a.key,driver_mobile:d.driverPhone,...j}):v0({driver_mobile:d.driverPhone,...j});f(v).then(Y=>{Y.payload.error?x({vertical:"top",horizontal:"center",msg:Y.payload.error,severity:"error"}):(h?f(m6({date:d.date})):e(),h&&f(u0({date:d.date,steward_key:h})),f(_u()),f(du({right:!1,bottom:!1,content:null})),x({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:({errors:d,touched:j,setFieldValue:v,values:Y})=>u.jsx(_6,{children:u.jsxs(l,{container:!0,spacing:1,justifyContent:"center",alignItems:"center",children:[u.jsx(l,{item:!0,xs:12,children:u.jsx(Ou,{as:z,name:"quarantineCode",label:"کد قرنطینه",fullWidth:!0,error:j.quarantineCode&&!!d.quarantineCode,helperText:j.quarantineCode&&d.quarantineCode})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(Ou,{as:z,name:"carcassCount",label:"حجم لاشه",type:"number",fullWidth:!0,error:j.carcassCount&&!!d.carcassCount,helperText:j.carcassCount&&d.carcassCount})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(iu,{label:"تاریخ",value:G(Y.date),onChange:k=>{const T=G(k).format("YYYY-MM-DD HH:mm:ss");v("date",T)},renderInput:k=>u.jsx(z,{...k,fullWidth:!0,error:j.date&&!!d.date,helperText:j.date&&d.date})})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(Ou,{as:z,name:"carcassWeight",label:"وزن لاشه",type:"number",fullWidth:!0,error:j.carcassWeight&&!!d.carcassWeight,helperText:j.carcassWeight&&d.carcassWeight})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(J,{variant:"contained",fullWidth:!0,type:"submit",children:n?"ویرایش":"ثبت"})})]})})})})},re=Nu("SLAUGHTER_RESEND_OUT_PROVINCE_REGISTRATION_CODE",async(e,{dispatch:n})=>{var a,E;n(su());try{const{data:h,status:f}=await tu.post("send_again_sms_kill_house_free_sale_bar/",e);return n(ru()),{data:h,status:f}}catch(h){return n(ru()),{error:((E=(a=h.response)==null?void 0:a.data)==null?void 0:E.result)||"خطا در ارسال مجدد کد"}}}),ne=({item:e,updateTable:n,fetchApiData:a,page:E})=>{const h=lu(),[f]=r.useContext(vu),[x,D]=r.useState(null),d=w=>{D(w.currentTarget)},j=()=>{D(null)},v=()=>{j(),h(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ویرایش فروش خارج از استان",content:u.jsx(te,{fetchItems:n,isEdit:!0,item:e})}))},Y=()=>{j(),h(ee(e==null?void 0:e.key)).then(w=>{w.payload.error?f({vertical:"top",horizontal:"center",msg:w.payload.data.result,severity:"error"}):(n(),h(_u()),f({vertical:"top",horizontal:"center",msg:w.payload.data.result,severity:"success"}))})},k=()=>{j(),h(re({key:e==null?void 0:e.key})).then(w=>{w.payload.error?f({vertical:"top",horizontal:"center",msg:w.payload.error,severity:"error"}):(f({vertical:"top",horizontal:"center",msg:"کد با موفقیت ارسال شد.",severity:"success"}),a(E))})},T=!!x,y=T?"popover":void 0;return u.jsxs("div",{children:[u.jsx(wu,{"aria-describedby":y,variant:"contained",color:"primary",onClick:d,children:u.jsx(N6,{})}),u.jsx(E6,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:y,open:T,anchorEl:x,onClose:j,children:u.jsxs(H6,{sx:{py:1,minWidth:130},children:[u.jsx(Du,{title:"ویرایش",placement:"left-start",children:u.jsx(Gu,{disablePadding:!0,children:u.jsxs(Ku,{onClick:v,children:[u.jsx(Qu,{sx:{minWidth:36},children:u.jsx(Y6,{color:"primary"})}),u.jsx(Zu,{primary:u.jsx(V,{variant:"body2",color:"primary",children:"ویرایش"})})]})})}),u.jsx(Du,{title:"حذف",placement:"left-start",children:u.jsx(Gu,{disablePadding:!0,children:u.jsxs(Ku,{onClick:Y,children:[u.jsx(Qu,{sx:{minWidth:36},children:u.jsx(z6,{color:"error"})}),u.jsx(Zu,{primary:u.jsx(V,{variant:"body2",color:"error",children:"حذف"})})]})})}),(e==null?void 0:e.systemRegistrationCode)&&(e==null?void 0:e.registrationCode)&&!(e!=null&&e.loggedRegistrationCode)&&u.jsx(Du,{title:"ارسال مجدد کد",placement:"left-start",children:u.jsx(Gu,{disablePadding:!0,children:u.jsxs(Ku,{onClick:k,children:[u.jsx(Qu,{sx:{minWidth:36},children:u.jsx(W0,{color:"success"})}),u.jsx(Zu,{primary:u.jsx(V,{variant:"body2",color:"success",children:"ارسال مجدد کد"})})]})})})]})})]})},se=()=>{var q,W,P,o;const[,,e,n,a,E]=r.useContext(vu),h=lu();r.useEffect(()=>{const _=G(new Date).format("YYYY-MM-DD");n(_),E(_)},[]);const f=_=>{T(_.target.value)},[x,D]=r.useState([]),[d,j]=r.useState(0),[v,Y]=r.useState(10),[k,T]=r.useState(""),[y,w]=r.useState(1),[B,M]=r.useState([]),L=async _=>{h(su());const s=await tu.get(`kill_house_free_sale_bar/?search=filter&value=${k}&role=${eu()}&date1=${e}&date2=${a}&page=${_}&page_size=${v}&type=dashboard`);h(ru()),D(s.data.results),j(s.data.count)},g=_=>{L(_),w(_)},F=Mu(_=>_.userSlice.userProfile.key),I=_=>{Y(_),w(1)},c=()=>{L(y!==0?y:1)};r.useEffect(()=>{const _=x==null?void 0:x.map((s,i)=>{var Z,A,$;return[y===1?i+1:i+v*(y-1)+1,s!=null&&s.date?L6(s==null?void 0:s.date):"-",s!=null&&s.productionDate?ju(s==null?void 0:s.productionDate):"-",((s==null?void 0:s.distributionType)==="web"?"سایت":(s==null?void 0:s.distributionType)==="app"?"موبایل":(s==null?void 0:s.distributionType)==="pos"?"پوز":s==null?void 0:s.distributionType)||"-",`${s==null?void 0:s.buyerName} (${s==null?void 0:s.buyerMobile})`,s!=null&&s.buyer?`${(Z=s==null?void 0:s.buyer)==null?void 0:Z.unitName}`:`${s==null?void 0:s.buyerName}`,s==null?void 0:s.province,s==null?void 0:s.city,(s==null?void 0:s.clearanceCode)&&u.jsx(W6,{clearanceCode:s==null?void 0:s.clearanceCode}),(A=s==null?void 0:s.quarantineWeightOfCarcasses)==null?void 0:A.toLocaleString(),($=s==null?void 0:s.weightOfCarcasses)==null?void 0:$.toLocaleString(),(s==null?void 0:s.quota)==="governmental"?"دولتی":(s==null?void 0:s.quota)==="free"?"آزاد":"-",(s==null?void 0:s.saleType)==="governmental"?"دولتی":(s==null?void 0:s.saleType)==="free"?"آزاد":"-",s!=null&&s.systemRegistrationCode?s!=null&&s.loggedRegistrationCode?"تایید شده":s!=null&&s.registrationCode?u.jsx(ue,{item:s,fetchApiData:()=>L(y)},i):"-":"-",u.jsx(ne,{item:s,updateTable:c,fetchApiData:L,page:y},i)]});M(_)},[x,y]),r.useEffect(()=>{L(1)},[h,e,a,v]);const b=async _=>{_.preventDefault(),h(su());try{const s=await tu.get(`kill_house_free_sale_bar/?role=${eu()}&search=filter&value=${k}&date1=${e}&date2=${a}&page=1&page_size=${v}&type=dashboard`);D(s.data.results),j(s.data.count),h(ru())}catch(s){console.error("Error fetching data:",s)}h(x6({selectedDate1:e,selectedDate2:a})).then(s=>{t(s.payload.data)})},[p,t]=r.useState([]);return r.useEffect(()=>{h(x6({selectedDate1:e,selectedDate2:a})).then(_=>{t(_.payload.data)})},[e,a]),u.jsxs(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(l,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,mt:2,children:[u.jsx(l,{children:u.jsx(iu,{label:"از تاریخ",id:"date",renderInput:_=>u.jsx(z,{style:{width:"160px"},..._,size:"small"}),value:e,onChange:_=>{n(G(_).format("YYYY-MM-DD"))}})}),u.jsx(l,{children:u.jsx(iu,{label:"تا تاریخ",id:"date",renderInput:_=>u.jsx(z,{style:{width:"160px"},..._,size:"small"}),value:a,onChange:_=>{E(G(_).format("YYYY-MM-DD"))}})}),u.jsx(l,{children:u.jsxs("form",{onSubmit:b,children:[u.jsx(z,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:f}),u.jsx(J,{type:"submit",onClick:b,endIcon:u.jsx(Lu,{}),children:"جستجو"})]})}),u.jsx(Du,{title:"خروجی اکسل",children:u.jsx("a",{href:`${tu.defaults.baseURL}kill_house_free_sale_bar_information_for_excel_excel/?key=${F}&role=${eu()}&date1=${e}&date2=${a}`,rel:"noreferrer",children:u.jsx(J,{color:"success",children:u.jsx(k6,{size:32})})})})]}),u.jsx(l,{container:!0,xs:12,mt:2,mb:4,isDashboard:!0,children:u.jsx(cu,{noPagination:!0,isDashboard:!0,columns:["تعداد فروش","خریدار","حجم لاشه ها (تقریبی)","وزن کل لاشه ها"],data:[[(q=p==null?void 0:p.numberOfAllocations)==null?void 0:q.toLocaleString(),(W=p==null?void 0:p.numberOfBuyers)==null?void 0:W.toLocaleString(),(P=p==null?void 0:p.totalNumberOfAllocationCarcasses)==null?void 0:P.toLocaleString(),(o=p==null?void 0:p.totalWeightOfAllocationCarcasses)==null?void 0:o.toLocaleString()]],title:"خلاصه اطلاعات"})}),u.jsx(l,{container:!0,xs:12,children:u.jsx(J,{variant:"contained",onClick:()=>{h(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,size:{xs:"100%",sm:"350px"},content:u.jsx(q6,{updateTable:c}),title:"ثبت اطلاعات فروش"}))},children:"ثبت اطلاعات فروش"})}),u.jsx(cu,{data:B,columns:["ردیف","تاریخ","تاریخ تولید گوشت","ثبت شده","مشخصات خریدار","نام واحد","استان","شهر","کد قرنطینه","وزن استعلامی","وزن لاشه","سهمیه","نوع فروش","کد احراز","عملیات"],handlePageChange:g,totalRows:d,page:y,perPage:v,handlePerRowsChange:I,title:"فروش لاشه به خارج استان"})]})},le=()=>{const e=lu(),[n,a]=r.useState(0),E=(f,x)=>{a(x)},h=()=>{e(_u()),e(T6())};return r.useEffect(()=>{h()},[e]),u.jsxs(l,{container:!0,direction:"column",alignItems:"center",justifyContent:"space-between",gap:Q.SMALL,mt:Q.MEDIUM,width:"100%",children:[u.jsx(l,{container:!0,width:"100%",isDashboard:!0,children:u.jsx(a6,{})}),u.jsxs(l,{container:!0,direction:"column",alignItems:"center",justifyContent:"space-between",gap:Q.SMALL,mb:Q.SMALL,width:"100%",children:[u.jsx(Fu,{sx:{borderBottom:1,borderColor:"divider"},children:u.jsxs(e6,{className:"insidetabs",size:"small",value:n,onChange:E,"aria-label":"basic tabs example",children:[u.jsx(Iu,{label:"فروش"}),u.jsx(Iu,{label:"خریداران"})]})}),n===0&&u.jsx(se,{fetchData:h}),n===1&&u.jsx(Z0,{})]})]})},oe=()=>{var K,X,m,ou,uu;const[e,n]=r.useState(),[a,E]=r.useState(),[h,f]=r.useState([]),[x,D]=r.useState(!1),[d,j]=r.useState([]),[v,Y]=r.useState([]),[k,T]=r.useState([]),[y,w]=r.useState(""),[B,M]=r.useState([]),[L,g]=r.useState([]),[F,I]=r.useState({killHouseAllocation:!0}),[c]=r.useContext(vu),b=r.useRef([]),p=r.useRef([]),t=r.useRef([]),q=lu(),[W,P]=r.useState({active:!1,killHousePrice:0,stewardPrice:0,guildPrice:0}),o=()=>{const S=eu();return S==="KillHouse"?W.killHousePrice:S==="Steward"?W.stewardPrice:S==="Guilds"?W.guildPrice:0};r.useEffect(()=>{b.current=b.current.slice(0,(v==null?void 0:v.length)||0),p.current=p.current.slice(0,(v==null?void 0:v.length)||0),t.current=t.current.slice(0,(v==null?void 0:v.length)||0)},[v]),r.useEffect(()=>{if(y){const S=k.filter(C=>C.some(N=>String(N).toLowerCase().includes(y.toLowerCase())));M(S)}else M(k)},[y,k]);const _=(S,C,N)=>{if(S.key==="Enter"){if(S.preventDefault(),N==="price"){const U=[...h];U[C]=Number(S.target.value.replace(/,/g,"")),f(U),p.current[C]&&p.current[C].focus()}else if(N==="weight"){const U=[...d];U[C]=Number(S.target.value.replace(/,/g,"")),j(U),F!=null&&F.killHouseAllocation||L[C]?t.current[C]&&t.current[C].focus():s(C)}}},s=S=>{var C,N;if(W!=null&&W.active){let U=S+1;for(;U<v.length;){if(p.current[U]){p.current[U].focus();break}U++}U>=v.length&&p.current[0]&&((C=p.current[0])==null||C.focus())}else{let U=S+1;for(;U<v.length;){if(b.current[U]){b.current[U].focus();break}U++}U>=v.length&&b.current[0]&&((N=b.current[0])==null||N.focus())}},i=()=>{q(Y0()).then(S=>{var C;(C=S.payload)!=null&&C.data&&I(S.payload.data)})},Z=async()=>{q(E0({role:eu()})).then(S=>{P(S.payload.data)})},A=async()=>{q(su());try{const S=await tu.get(`commonly-used/?search=filter&value=&role=${eu()}&page=1&page_size=10000`);D(!0),Y(S.data.results||[])}catch(S){console.error(S)}finally{q(ru())}},$=(S,C)=>{var U;const N=[...L];N[C]=S[0]?{...S[0],base64:B0((U=S[0])==null?void 0:U.data_url)}:null,g(N),(F!=null&&F.killHouseAllocation&&S[0]||!(F!=null&&F.killHouseAllocation))&&s(C)};r.useEffect(()=>{const S=v==null?void 0:v.map((C,N)=>{var O,R,Cu,pu,xu,Au,fu,yu;const U=parseInt(W!=null&&W.active?o():h[N])*parseInt(d[N]);return[N+1,(O=C==null?void 0:C.guild)!=null&&O.steward?"مباشر":"صنف",`${(R=C==null?void 0:C.guild)==null?void 0:R.guildsName}/${(pu=(Cu=C==null?void 0:C.guild)==null?void 0:Cu.user)==null?void 0:pu.fullname}/${(Au=(xu=C==null?void 0:C.guild)==null?void 0:xu.user)==null?void 0:Au.city}/${(yu=(fu=C==null?void 0:C.guild)==null?void 0:fu.user)==null?void 0:yu.mobile}`,C!=null&&C.exclusive?"اختصاصی":"آزاد",u.jsx(mu,{allowLeadingZeros:!0,thousandSeparator:",",size:"small",label:"قیمت",disabled:W==null?void 0:W.active,value:W!=null&&W.active?o():h[N]||"",onKeyDown:nu=>_(nu,N,"price"),inputRef:nu=>b.current[N]=nu,variant:"outlined",style:{width:100}},`price-${N}`),u.jsx(mu,{allowLeadingZeros:!0,thousandSeparator:",",size:"small",label:"وزن",value:d[N]||"",onKeyDown:nu=>{_(nu,N,"weight")},inputRef:nu=>p.current[N]=nu,variant:"outlined",style:{width:100}},`weight-${N}`),isNaN(U)?"وارد نشده! ":(U==null?void 0:U.toLocaleString())+" ریال",u.jsxs("div",{style:{width:150},children:[u.jsx(N0,{onChange:nu=>$(nu,N),images:L[N]?[L[N]]:[],maxNumber:1,title:"بارگزاری سند",required:F==null?void 0:F.killHouseAllocation,inputRef:nu=>t.current[N]=nu}),(F==null?void 0:F.killHouseAllocation)&&!L[N]&&u.jsx(V,{variant:"caption",color:"error",children:"تصویر الزامی است"})]},N),u.jsx(wu,{color:"error",children:u.jsx(z6,{onClick:()=>H(C.key)})},N)]});T(S),M(S)},[v,h,d,W,L,F]),r.useEffect(()=>{A(),Z(),i(),q(Xu()).then(S=>{E(S.payload.data)})},[]),r.useEffect(()=>{const S=a==null?void 0:a.map(C=>{var N;return[C==null?void 0:C.name,(N=C==null?void 0:C.totalRemainWeight)==null?void 0:N.toLocaleString()]});n(S)},[a]);const H=S=>{q(S0(S)).then(C=>{C.payload.error?c({vertical:"top",horizontal:"center",msg:C.payload.error,severity:"error"}):(c({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),A())})},au=()=>{const S=v==null?void 0:v.map((C,N)=>{var Cu,pu,xu,Au,fu,yu,nu,bu;const U=W!=null&&W.active?o():h[N],O=d[N];if(!U||!O||F!=null&&F.killHouseAllocation&&!L[N])return null;let R={seller_type:"KillHouse",buyer_type:(Cu=C==null?void 0:C.guild)!=null&&Cu.steward?"Steward":"Guild",guild_key:(pu=C==null?void 0:C.guild)!=null&&pu.steward?null:(xu=C==null?void 0:C.guild)==null?void 0:xu.key,steward_key:(Au=C==null?void 0:C.guild)!=null&&Au.steward?(fu=C==null?void 0:C.guild)==null?void 0:fu.key:null,product_key:(yu=a[0])==null?void 0:yu.key,type:"manual",allocation_type:(nu=C==null?void 0:C.guild)!=null&&nu.steward?"killhouse_steward":"killhouse_guild",number_of_carcasses:0,weight_of_carcasses:O,sell_type:"free",amount:U,total_amount:U*O,approved_price_status:W==null?void 0:W.active,date:G(new Date).format("YYYY-MM-DD")};return L[N]&&(R.image=(bu=L[N])==null?void 0:bu.base64),Object.fromEntries(Object.entries(R).filter(([Tu,zu])=>zu!==null))}).filter(Boolean);if(S.length===0){c({vertical:"top",horizontal:"center",msg:"لطفا حداقل یک رکورد معتبر با عکس وارد کنید",severity:"error"});return}q(D0(S)).then(C=>{C.payload.error?c({vertical:"top",horizontal:"center",msg:C.payload.error,severity:"error"}):(c({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),f([]),j([]),g([]),A(),Z(),i(),q(Xu()).then(N=>{E(N.payload.data)}))})};return u.jsxs(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",children:[u.jsx(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",children:u.jsx(cu,{noPagination:!0,title:"موجودی انبار",columns:["محصول","مانده انبار (کیلوگرم)"],data:e,customColors:[{name:"محصول",color:"red"}]})}),u.jsxs(l,{xs:12,container:!0,spacing:2,mt:2,alignItems:"center",justifyContent:"space-between",children:[u.jsx(l,{item:!0,xs:12,md:"auto",children:u.jsx(J,{variant:"contained",startIcon:u.jsx(P0,{}),sx:{borderRadius:3,px:3},onClick:()=>{q(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(b0,{updateTable:A}),title:"افزودن"}))},children:"افزودن مباشر/صنف"})}),u.jsx(l,{item:!0,xs:12,md:!0,children:u.jsx(U6,{variant:"outlined",sx:{borderRadius:3,boxShadow:1},children:u.jsx(G6,{children:u.jsxs(l,{container:!0,spacing:2,alignItems:"center",justifyContent:"space-between",children:[u.jsxs(l,{item:!0,children:[u.jsx(V,{variant:"subtitle2",children:"مجموع وزن وارد شده"}),u.jsx(V,{variant:"body1",color:"text.secondary",children:d!=null&&d.length?d.reduce((S,C)=>S+C,0).toLocaleString():"۰"})]}),u.jsxs(l,{item:!0,children:[u.jsx(V,{variant:"subtitle2",children:"وزن باقیمانده"}),u.jsx(V,{variant:"body1",color:d!=null&&d.length&&a&&(d==null?void 0:d.reduce((S,C)=>S+C,0))>((K=a[0])==null?void 0:K.totalRemainWeight)?"error":"text.secondary",children:((X=a==null?void 0:a[0])==null?void 0:X.totalRemainWeight)!==void 0?d!=null&&d.length?(((m=a[0])==null?void 0:m.totalRemainWeight)-d.reduce((S,C)=>S+C,0)).toLocaleString():(ou=a[0])==null?void 0:ou.totalRemainWeight.toLocaleString():"۰"})]}),u.jsx(l,{item:!0,children:u.jsx(J,{variant:"contained",color:"success",startIcon:u.jsx(O0,{}),sx:{borderRadius:3,px:3},onClick:au,disabled:d.length?d.reduce((S,C)=>S+C,0)>((uu=a[0])==null?void 0:uu.totalRemainWeight)||(F==null?void 0:F.killHouseAllocation)&&v.some((S,C)=>h[C]&&d[C]&&(!L[C]||!L[C].base64)):!0,children:"ثبت"})})]})})})})]}),u.jsxs(l,{container:!0,xs:12,mt:2,gap:1,sx:{userSelect:"none"},children:[u.jsx(A6,{color:"error"}),u.jsx(V,{variant:"body1",color:"error",children:"پس از وارد کردن هر مقدار، کلید Enter را فشار دهید!"})]}),u.jsxs(l,{container:!0,xs:12,mt:2,gap:1,sx:{userSelect:"none"},children:[u.jsx(A6,{color:"primary"}),u.jsx(V,{variant:"body1",color:"primary",children:"صرفا تخصیصاتی که هر دو مقدار قیمت و وزن آنها را وارد کنید ثبت خواهند شد."})]}),u.jsx(l,{container:!0,xs:12,mt:2,children:u.jsx(z,{fullWidth:!0,variant:"outlined",placeholder:"جستجو...",value:y,onChange:S=>w(S.target.value),InputProps:{startAdornment:u.jsx(K6,{position:"start",children:u.jsx(B6,{})})},sx:{mb:2}})}),B!=null&&B.length?u.jsx(l,{container:!0,xs:12,gap:1,mt:2,mb:2,children:B==null?void 0:B.map((S,C)=>u.jsxs(l,{container:!0,xs:12,sx:{p:2,pl:5,borderRadius:2,backgroundColor:C%2===0?"#fef6f0":"#ffffff",boxShadow:"0 2px 6px rgba(0,0,0,0.05)",position:"relative",flexDirection:"row",gap:2,alignItems:"center"},children:[u.jsx(Fu,{sx:{position:"absolute",top:12,left:12,backgroundColor:"#fb8c00",width:28,height:28,borderRadius:"50%",color:"#fff",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"0.8rem",fontWeight:700,boxShadow:"0 1px 4px rgba(0,0,0,0.2)"},children:S[0]}),u.jsxs(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:[u.jsx(V,{variant:"caption",color:"text.secondary",sx:{minWidth:64},children:"ماهیت:"}),u.jsx(V,{variant:"body2",fontSize:"0.8rem",children:S[1]})]}),u.jsxs(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:[u.jsx(V,{variant:"caption",color:"text.secondary",sx:{minWidth:64},children:"خریدار:"}),u.jsx(V,{variant:"body2",fontSize:"0.8rem",children:S[2]})]}),u.jsxs(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:[u.jsx(V,{variant:"caption",color:"text.secondary",sx:{minWidth:64},children:"نوع فروش:"}),u.jsx(V,{variant:"body2",fontSize:"0.8rem",children:S[3]})]}),u.jsxs(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:[u.jsx(V,{variant:"caption",color:"text.secondary",children:"قیمت هرکیلو:"}),u.jsx(V,{variant:"body2",fontSize:"0.8rem",children:S[4]})]}),u.jsxs(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:[u.jsx(V,{variant:"caption",color:"text.secondary",children:"وزن لاشه:"}),u.jsx(V,{variant:"body2",fontSize:"0.8rem",children:S[5]})]}),u.jsxs(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:[u.jsx(V,{variant:"caption",color:"text.secondary",sx:{minWidth:64},children:"قیمت کل:"}),u.jsx(V,{variant:"body2",fontSize:"0.8rem",children:S[6]})]}),u.jsx(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:S[7]}),u.jsx(l,{item:!0,sx:{display:"flex",alignItems:"center",gap:.5},children:S[8]}),u.jsx(l,{item:!0,children:!(W!=null&&W.active)&&(!h[C]||!d[C])&&(h[C]||d[C])&&u.jsx(V,{variant:"caption",color:"error",children:"لطفا همه موارد را وارد کنید و کلید Enter را بزنید"})})]},C))}):u.jsx(V,{mt:4,children:x?"موردی یافت نشد!":y?"نتیجه‌ای یافت نشد":"در حال بارگزاری..."})]})},ce=()=>{var P,o,_;const[e,n]=r.useState([]),[a,E]=r.useState([]),[h,f]=r.useState([]),[x,D]=r.useState(0),[d,j]=r.useState(10),[v,Y]=r.useState(""),[k,T]=r.useState(1),[y,w]=r.useState([]),[,,B,M,L,g]=r.useContext(vu),F=lu(),I=()=>{F(R0({value:v,date1:B,date2:L,role:eu()})).then(s=>{w(s.payload.data)})};r.useEffect(()=>{const s=G(new Date).format("YYYY-MM-DD");M(s),g(s)},[]);const c=async s=>{F(su());const i=await tu.get(`app-segmentation/?search=filter&value=${v}&date1=${B}&date2=${L}&page=${s}&page_size=${d}&role=${eu()}`);I(),F(ru()),n(i.data.results),D(i.data.count)},b=s=>{c(s),T(s)},p=()=>{c(k)},t=s=>{j(s),T(1)},q=s=>{Y(s.target.value)};r.useEffect(()=>{c(1),F(w0()).then(s=>{E(s.payload.data)})},[]),r.useEffect(()=>{const s=e==null?void 0:e.map((i,Z)=>{var A,$,H,au,K,X,m;return[k===1?Z+1:Z+d*(k-1)+1,i!=null&&i.productionDate?L6(i==null?void 0:i.productionDate):"-",(i==null?void 0:i.distributionType)==="web"?"سایت":(i==null?void 0:i.distributionType)==="app"?"موبایل":(i==null?void 0:i.distributionType)==="pos"?"پوز":(i==null?void 0:i.distributionType)||"-",`${(A=i==null?void 0:i.buyer)==null?void 0:A.fullname}(${($=i==null?void 0:i.buyer)==null?void 0:$.mobile})`,i!=null&&i.toGuild?`به قطعه بند - ${(au=(H=i==null?void 0:i.toGuild)==null?void 0:H.user)==null?void 0:au.fullname}(${(X=(K=i==null?void 0:i.toGuild)==null?void 0:K.user)==null?void 0:X.mobile})`:"قطعه بندی توسط کشتارگاه",i!=null&&i.date?ju(i==null?void 0:i.date):"-",i==null?void 0:i.weight,(i==null?void 0:i.quota)==="governmental"?"دولتی":(i==null?void 0:i.quota)==="free"?"آزاد":"-",(i==null?void 0:i.saleType)==="governmental"?"دولتی":(i==null?void 0:i.saleType)==="free"?"آزاد":"-",u.jsx(_0,{item:i,productKey:(m=a==null?void 0:a[0])==null?void 0:m.key,updateTable:p},Z)]});f(s)},[e]),r.useEffect(()=>{c(1)},[B,L,d]);const W=async s=>{s.preventDefault(),F(su());try{const i=await tu.get(`app-segmentation/?search=filter&value=${v}&date1=${B}&date2=${L}&page=${k}&role=${eu()}`);n(i.data.results),D(i.data.count),I(),F(ru())}catch(i){console.error("Error fetching data:",i)}};return u.jsx(l,{container:!0,direction:"column",flexWrap:"nowrap",children:u.jsxs(l,{xs:12,container:!0,alignItems:"center",gap:Q.SMALL,justifyContent:"flex-start",children:[u.jsx(l,{container:!0,mb:4,isDashboard:!0,children:u.jsx(cu,{noPagination:!0,isDashboard:!0,columns:["وزن کل (کیلوگرم)","وزن قطعه بندی","وزن تخصیصی به قطعه بندها"],data:[[((P=y==null?void 0:y.totalWeight)==null?void 0:P.toLocaleString())||"0",((o=y==null?void 0:y.totalSelfWeight)==null?void 0:o.toLocaleString())||"0",((_=y==null?void 0:y.totalOtherWeight)==null?void 0:_.toLocaleString())||"0"]],title:"خلاصه اطلاعات"})}),u.jsx("form",{children:u.jsxs(l,{container:!0,alignItems:"center",gap:Q.SMALL,children:[u.jsx(J,{variant:"contained",onClick:()=>{var s;F(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ثبت قطعه بندی",size:{xs:"100%",sm:"380px"},content:u.jsx(P6,{updateTable:p,productKey:(s=a==null?void 0:a[0])==null?void 0:s.key})}))},children:"ثبت قطعه بندی"}),u.jsx(z,{size:"small",autoComplete:"off",label:"جستجو",variant:"outlined",style:{width:250},onChange:q}),u.jsx(J,{type:"submit",onClick:W,endIcon:u.jsx(Lu,{}),children:"جستجو"}),u.jsx(l,{children:u.jsx(iu,{label:"از تاریخ",id:"date",renderInput:s=>u.jsx(z,{style:{width:"160px"},...s}),value:B,onChange:s=>M(G(s).format("YYYY-MM-DD"))})}),u.jsx(l,{children:u.jsx(iu,{label:"تا تاریخ",id:"date",renderInput:s=>u.jsx(z,{style:{width:"160px"},...s}),value:L,onChange:s=>g(G(s).format("YYYY-MM-DD"))})})]})}),u.jsx(cu,{data:h,columns:["ردیف","تاریخ تولید گوشت","ثبت شده","کشتارگاه","تخصیص","تاریخ ","وزن (کیلوگرم)","سهمیه","نوع فروش","عملیات"],handlePageChange:b,totalRows:x,page:k,perPage:d,handlePerRowsChange:t,title:"قطعه بندی"})]})})},ie=()=>{const[e,n]=r.useState(G(new Date).format("YYYY-MM-DD")),[a,E]=r.useState(G(new Date).format("YYYY-MM-DD")),h=lu(),f=p=>{w(p.target.value)},[x,D]=r.useState(!0),[d,j]=r.useState([]),[v,Y]=r.useState(0),[k,T]=r.useState(10),[y,w]=r.useState(""),[B,M]=r.useState(1),[L,g]=r.useState([]),F=r.useCallback(async p=>{let t;h(su()),t=await tu.get(`orders_for_kill_house/?search=filter&value=${y}&role=${eu()}${x?`&date1=${e}&date2=${a}`:""}&page=${p}&page_size=${k}`),h(ru()),j(t.data.results),Y(t.data.count)},[y,x,e,a,k,h]),I=p=>{F(p),M(p)},c=p=>{T(p),M(1)};r.useEffect(()=>{const p=d==null?void 0:d.map((t,q)=>{var W,P;return[B===1?q+1:q+k*(B-1)+1,t==null?void 0:t.orderCode,ju(t==null?void 0:t.date),t==null?void 0:t.customerName,t==null?void 0:t.customerMobile,t==null?void 0:t.customerCity,t==null?void 0:t.productType,(W=t==null?void 0:t.quantity)==null?void 0:W.toLocaleString(),(P=t==null?void 0:t.weight)==null?void 0:P.toLocaleString(),t==null?void 0:t.status,t!=null&&t.deliveryDate?ju(t==null?void 0:t.deliveryDate):"-",u.jsx(Du,{title:"مشاهده جزئیات",children:u.jsx(wu,{size:"small",color:"primary",onClick:()=>{var o,_;h(Wu({title:"جزئیات سفارش",content:u.jsxs(l,{container:!0,gap:2,children:[u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"کد سفارش:"})," ",t==null?void 0:t.orderCode]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"مشتری:"})," ",t==null?void 0:t.customerName]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"تلفن:"})," ",t==null?void 0:t.customerMobile]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"شهر:"})," ",t==null?void 0:t.customerCity]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"نوع محصول:"})," ",t==null?void 0:t.productType]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"حجم:"})," ",(o=t==null?void 0:t.quantity)==null?void 0:o.toLocaleString()," ","قطعه"]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"وزن:"})," ",(_=t==null?void 0:t.weight)==null?void 0:_.toLocaleString()," ","کیلوگرم"]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"وضعیت:"})," ",t==null?void 0:t.status]}),u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"تاریخ ثبت:"})," ",ju(t==null?void 0:t.date)]}),(t==null?void 0:t.deliveryDate)&&u.jsxs(l,{xs:12,children:[u.jsx("strong",{children:"تاریخ تحویل:"})," ",ju(t==null?void 0:t.deliveryDate)]})]})}))},children:u.jsx(M0,{fontSize:"small"})})},q)]});g(p)},[d]),r.useEffect(()=>{F(1)},[F]);const b=async p=>{p.preventDefault(),h(su());try{const t=await tu.get(`orders_for_kill_house/?role=${eu()}&search=filter&value=${y}${x?`&date1=${e}&date2=${a}`:""}&page=1&page_size=${k}`);j(t.data.results),Y(t.data.count),h(ru())}catch(t){console.error("Error fetching data:",t)}};return u.jsxs(l,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(l,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:[u.jsxs(l,{container:!0,style:{borderStyle:"solid",borderWidth:"1px",padding:"10px",borderRadius:"15px",borderColor:"gray",justifyContent:"left"},children:[u.jsx(l,{children:u.jsx(gu,{control:u.jsx(u6,{checked:x,onChange:()=>D(!x),color:"primary"})})}),u.jsx(l,{children:u.jsx(iu,{disabled:!x,label:"از تاریخ",id:"date",renderInput:p=>u.jsx(z,{size:"small",style:{width:"160px"},...p}),value:e,onChange:p=>{n(G(p).format("YYYY-MM-DD"))}})}),u.jsx(l,{children:u.jsx(iu,{disabled:!x,label:"تا تاریخ",id:"date",renderInput:p=>u.jsx(z,{size:"small",style:{width:"160px"},...p}),value:a,onChange:p=>{E(G(p).format("YYYY-MM-DD"))}})})]}),u.jsx(l,{children:u.jsxs("form",{onSubmit:b,children:[u.jsx(z,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:f}),u.jsx(J,{type:"submit",onClick:b,endIcon:u.jsx(Lu,{}),children:"جستجو"})]})})]}),u.jsx(cu,{data:L,columns:["ردیف","کد سفارش","تاریخ ثبت","نام مشتری","شماره تماس","شهر","نوع محصول","حجم (قطعه)","وزن (کیلوگرم)","وضعیت","تاریخ تحویل","عملیات"],handlePageChange:I,totalRows:v,page:B,perPage:k,handlePerRowsChange:c,title:"سفارشات کشتارگاه"})]})},v6=[{value:"inProvinceSale",label:"توزیع/ فروش درون استان",description:"ثبت توزیع و فروش لاشه داخل استان"},{value:"coldStorage",label:"انتقال به سردخانه",description:"ثبت انتقال لاشه به سردخانه"},{value:"outProvinceSale",label:"فروش خارج استان",description:"ثبت فروش لاشه به خارج از استان"},{value:"segmentation",label:"قطعه بندی",description:"ثبت قطعه بندی لاشه"}],de=({updateTable:e,priceInfo:n,slaughterProducts:a,fetchApiData:E})=>{const[h,f]=r.useState(""),x=j=>{f(j.target.value)},D=()=>{var v,Y;const j={updateTable:e,priceInfo:n,remainWeight:(v=a==null?void 0:a[0])==null?void 0:v.totalRemainWeight,fetchApiData:E};switch(h){case"inProvinceSale":return u.jsx($0,{...j,sellerType:"KillHouse",sellType:"exclusive",killHouseAllocation:!0});case"coldStorage":return u.jsx(z0,{...j,sellerType:"KillHouse",sellType:"free",killHouseAllocation:!1});case"outProvinceSale":return u.jsx(q6,{updateTable:e});case"segmentation":return u.jsx(P6,{updateTable:e,productKey:(Y=a==null?void 0:a[0])==null?void 0:Y.key});default:return null}},d=v6.find(j=>j.value===h);return u.jsxs(l,{container:!0,direction:"column",gap:Q.MEDIUM,width:"100%",children:[u.jsxs($u,{fullWidth:!0,children:[u.jsx(S6,{id:"operation-select-label",children:"انتخاب عملیات"}),u.jsx(b6,{labelId:"operation-select-label",id:"operation-select",value:h,label:"انتخاب عملیات",onChange:x,children:v6.map(j=>u.jsx(Vu,{value:j.value,children:j.label},j.value))})]}),d&&u.jsxs(u.Fragment,{children:[u.jsx(Q6,{}),u.jsxs(l,{container:!0,direction:"column",gap:Q.TINY,children:[u.jsx(V,{variant:"h6",color:"primary",children:d.label}),u.jsx(V,{variant:"body2",color:"textSecondary",children:d.description})]})]}),u.jsx(Fu,{sx:{width:"100%"},children:D()})]})},Ce=({priceInfo:e})=>{var f,x,D,d,j,v,Y,k,T,y,w,B,M,L,g,F;const{distributionInfo:n,slaughterProducts:a}=Mu(I=>I.slaughterSlice),E=lu(),h=()=>{E(_u())};return u.jsxs(l,{container:!0,width:"100%",gap:Q.SMALL,mb:2,children:[u.jsx(J,{disabled:!a,variant:"contained",color:"primary",size:"large",onClick:()=>{E(du({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ثبت عملیات",size:window.innerWidth<=600?"auto":450,content:u.jsx(de,{updateTable:h,priceInfo:e,slaughterProducts:a})}))},children:"ثبت عملیات"}),u.jsx(a6,{}),u.jsx(cu,{title:"اطلاعات پخش",noPagination:!0,isDashboard:!0,data:[[(f=n==null?void 0:n.totalGovernmentalInputWeight)==null?void 0:f.toLocaleString(),(x=n==null?void 0:n.totalFreeInputWeight)==null?void 0:x.toLocaleString(),(D=n==null?void 0:n.totalGovernmentalOutputWeight)==null?void 0:D.toLocaleString(),(d=n==null?void 0:n.totalFreeOutputWeight)==null?void 0:d.toLocaleString(),(j=n==null?void 0:n.totalKillHouseAllocationsWeight)==null?void 0:j.toLocaleString(),(v=n==null?void 0:n.totalKillHouseFreeSale_barCarcassesWeight)==null?void 0:v.toLocaleString(),(Y=n==null?void 0:n.segmentationsWeight)==null?void 0:Y.toLocaleString(),(k=n==null?void 0:n.coldHouseAllocationsWeight)==null?void 0:k.toLocaleString(),(T=n==null?void 0:n.totalGovernmentalRemainWeight)==null?void 0:T.toLocaleString(),(y=n==null?void 0:n.totalFreeRemainWeight)==null?void 0:y.toLocaleString()]],columns:["وزن دولتی (کیلوگرم)","وزن آزاد (کیلوگرم)","فروش دولتی (کیلوگرم)","فروش آزاد (کیلوگرم)","فروش و توزیع داخل استان (کیلوگرم)","فروش و توزیع خارج استان (کیلوگرم)","وزن قطعه بندی (کیلوگرم)","وزن انجماد (کیلوگرم)","مانده دولتی (کیلوگرم)"," مانده آزاد (کیلوگرم)"]}),u.jsx(cu,{title:"تعهدات",noPagination:!0,isDashboard:!0,data:[[(w=n==null?void 0:n.totalCommitmentSellingInProvinceGovernmentalWeight)==null?void 0:w.toLocaleString(),(B=n==null?void 0:n.totalSellingInProvinceGovernmentalWeight)==null?void 0:B.toLocaleString(),(M=n==null?void 0:n.totalCommitmentSellingInProvinceGovernmentalRemainWeight)==null?void 0:M.toLocaleString(),(L=n==null?void 0:n.totalCommitmentSellingInProvinceFreeWeight)==null?void 0:L.toLocaleString(),(g=n==null?void 0:n.totalSellingInProvinceFreeWeight)==null?void 0:g.toLocaleString(),(F=n==null?void 0:n.totalCommitmentSellingInProvinceFreeRemainWeight)==null?void 0:F.toLocaleString()]],columns:["تعهد دولتی توزیع داخل استان","توزیع دولتی داخل استان","باقیمانده تعهد دولتی توزیع داخل استان","تعهد آزاد توزیع داخل استان","توزیع آزاد داخل استان","باقیمانده تعهد آزاد توزیع داخل استان"],allColors:{color:"green",text:"#332a3d"}})]})},ha=()=>{const{pathname:e}=s0(),n=lu(),{distributionInfo:a,priceInfo:E}=Mu(h=>h.slaughterSlice);return r.useEffect(()=>{e===Ju&&(n(_u()),n(T6()))},[e]),u.jsxs(u.Fragment,{children:[u.jsx(Fu,{display:"flex",justifyContent:"center",children:e===Ju&&u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(Ce,{priceInfo:E})]})}),(e===Ju||e===e0)&&u.jsxs(l,{container:!0,gap:Q.SMALL,p:Q.SMALL,justifyContent:"center",mt:Q.MEDIUM,xs:12,alignItems:"center",width:"900px",mx:"auto",children:[u.jsx(Bu,{to:i6,children:u.jsx(Pu,{icon:u.jsx(a0,{sx:{fontSize:30,color:"#244CCC"}}),title:"ورود به انبار"})}),u.jsx(Bu,{to:d6,children:u.jsx(Pu,{icon:u.jsx(t0,{sx:{fontSize:30,color:"#244CCC"}}),title:"فروش داخل استان"})}),u.jsx(Bu,{to:C6,children:u.jsx(Pu,{icon:u.jsx(h6,{sx:{fontSize:30,color:"#244CCC"}}),title:"فروش به خارج استان"})}),u.jsx(Bu,{to:g6,children:u.jsx(Pu,{icon:u.jsx(h6,{sx:{fontSize:30,color:"#244CCC"}}),title:"خرید خارج از استان"})}),u.jsx(Bu,{to:p6,children:u.jsx(Pu,{icon:u.jsx(l0,{sx:{fontSize:30,color:"#244CCC"}}),title:"قطعه بندی"})})]}),e.includes(i6)&&u.jsx(Fu,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(K0,{})]})}),e.includes(C6)&&u.jsx(Fu,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(le,{})]})}),e.includes(r0)&&u.jsx(Fu,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(oe,{})]})}),e.includes(d6)&&u.jsx(Fu,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(o0,{distributionInfo:a})]})}),e.includes(p6)&&u.jsx(Fu,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(ce,{})]})}),e.includes(n0)&&u.jsx(Fu,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(ie,{})]})}),e.includes(g6)&&u.jsx(Fu,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[u.jsx(Eu,{}),u.jsx(p0,{})]})})]})};export{ha as default};