2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{j as u,ak as B,aa as W,B as v,I as uu,b0 as eu,d as U,T as R,b as ru}from"./mui-vendor-CkIVaoQP.js";import{j as V,A as G,u as K,c as X,b as D,v as J,G as l,S as g,W as ou,L as H,h as _,aZ as nu,N as M,X as Y,O as tu,a_ as iu,C as lu,p as S}from"./index-CeyyVc1v.js";import{r as C}from"./react-vendor-CmFgShSM.js";import{a as Q,u as T}from"./redux-vendor-B7uoacJt.js";import{N as O}from"./NumberFormatCustom-DwWPj40N.js";import{C as au}from"./CustomCard-B-6dDbAN.js";import{R as su}from"./ResponsiveTable-w7hk7Uq8.js";import{d as cu}from"./Edit-CqBj1Y2L.js";import{d as Cu}from"./Tune-D4M2CAhp.js";import"./FilterAlt-scT0HEUg.js";import"./styled-components.browser.esm-gS9mh05b.js";const du=Q("PROVINCE_NEW_PRICING",async i=>{const{data:r,status:e}=await V.post("pricing/",i);return{data:r,status:e}}),hu=()=>{const[i]=C.useContext(G),r=T(),e=K({initialValues:{date:J(Date()).format("YYYY-MM-DD hh:mm:ss"),price:"",floorprice:"",ceilingprice:""},validationSchema:X({price:D().required("این فیلد اجباری است!").typeError("لطفا عدد وارد کنید!")})});return C.useEffect(()=>{e.validateForm()},[]),u.jsxs(l,{container:!0,gap:g.SMALL,direction:"column",height:"100%",justifyContent:"space-between",children:[u.jsx(l,{children:u.jsx(ou,{fullWidth:!0,label:"تاریخ",id:"date",renderInput:a=>u.jsx(B,{...a}),value:e.values.date,error:e.touched.date?!!e.errors.date:null,onChange:a=>{e.setFieldValue("date",J(a).format("YYYY-MM-DD hh:mm:ss"))},onBlur:e.handleBlur,helperText:e.touched.date&&e.errors.date?e.errors.date:null})}),u.jsx(l,{children:u.jsx(O,{allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"price",label:"قیمت هر کیلو مرغ زنده",variant:"outlined",InputLabelProps:{shrink:!0},InputProps:{endAdornment:u.jsx(W,{position:"start",children:"ریال"})},value:e.values.price,error:e.touched.price?!!e.errors.price:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.price&&e.errors.price?e.errors.price:null})}),u.jsx(l,{children:u.jsx(O,{allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"floorprice",label:"قیمت کف",variant:"outlined",InputLabelProps:{shrink:!0},InputProps:{endAdornment:u.jsx(W,{position:"start",children:"ریال"})},value:e.values.floorprice,error:e.touched.floorprice?!!e.errors.floorprice:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.floorprice&&e.errors.floorprice?e.errors.floorprice:null})}),u.jsx(l,{children:u.jsx(O,{allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"ceilingprice",label:"قیمت سقف",variant:"outlined",InputLabelProps:{shrink:!0},InputProps:{endAdornment:u.jsx(W,{position:"start",children:"ریال"})},value:e.values.ceilingprice,error:e.touched.ceilingprice?!!e.errors.ceilingprice:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.ceilingprice&&e.errors.ceilingprice?e.errors.ceilingprice:null})}),u.jsx(l,{children:u.jsx(v,{fullWidth:!0,variant:"contained",component:"label",disabled:!e.isValid,size:"large",onClick:()=>{e.values.floorprice>e.values.ceilingprice?i({vertical:"top",horizontal:"center",msg:"قیمت گذاری غیر استاندارد است!",severity:"error"}):(r(H()),r(du({date:e.values.date,live_chicken_price:e.values.price,floor_price:e.values.floorprice?e.values.floorprice:0,ceiling_price:e.values.ceilingprice?e.values.ceilingprice:0})).then(a=>{a.error?(r(_()),i({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"})):r(nu()).then(c=>{r(_()),i({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),r(M({right:!1,bottom:!1,content:null}))})}))},children:"ثبت درخواست"})})]})},$=Q("PROVINCE_PRICE_EDIT_SERVICE",async(i,{dispatch:r})=>{var e,a;try{r(H());const{data:c,status:d}=await V.put(`chicken-commission-prices/${i.id}/`,{kill_house_price:i.kill_house_price,wholesaler_price:i.wholesaler_price,retailer_price:i.retailer_price});return r(_()),{data:c,status:d}}catch(c){return r(_()),{error:((a=(e=c==null?void 0:c.response)==null?void 0:e.data)==null?void 0:a.result)||"خطایی رخ داده است"}}}),pu=({updateTable:i,item:r})=>{const[e]=C.useContext(G),a=T(),c={kill_house_price:(r==null?void 0:r.killHousePrice)||0,wholesaler_price:(r==null?void 0:r.wholesalerPrice)||0,retailer_price:(r==null?void 0:r.retailerPrice)||0},d=X().shape({kill_house_price:D().required("این فیلد الزامی است").min(0,"مقدار نمیتواند منفی باشد"),wholesaler_price:D().required("این فیلد الزامی است").min(0,"مقدار نمیتواند منفی باشد"),retailer_price:D().required("این فیلد الزامی است").min(0,"مقدار نمیتواند منفی باشد")}),t=K({initialValues:c,validationSchema:d,enableReinitialize:!0}),p=()=>{a($({id:r==null?void 0:r.id,kill_house_price:Number(t.values.kill_house_price),wholesaler_price:Number(t.values.wholesaler_price),retailer_price:Number(t.values.retailer_price)})).then(F=>{var A;(A=F.payload)!=null&&A.error?e({vertical:"top",horizontal:"center",msg:F.payload.error,severity:"error"}):(i(),e({vertical:"top",horizontal:"center",msg:"قیمتها با موفقیت ویرایش شدند",severity:"success"}),a(M({right:!1,bottom:!1,content:null})))})};return u.jsxs(l,{container:!0,direction:"column",gap:g.SMALL,sx:{p:1},children:[u.jsx(B,{label:"کارمزد کشتارگاه (ریال)",variant:"outlined",fullWidth:!0,name:"kill_house_price",value:t.values.kill_house_price,onChange:t.handleChange,onBlur:t.handleBlur,error:t.touched.kill_house_price&&!!t.errors.kill_house_price,helperText:t.touched.kill_house_price&&t.errors.kill_house_price}),u.jsx(B,{label:"کارمزد عمده فروش (ریال)",variant:"outlined",fullWidth:!0,name:"wholesaler_price",value:t.values.wholesaler_price,onChange:t.handleChange,onBlur:t.handleBlur,error:t.touched.wholesaler_price&&!!t.errors.wholesaler_price,helperText:t.touched.wholesaler_price&&t.errors.wholesaler_price}),u.jsx(B,{label:"کارمزد خرده فروش (ریال)",variant:"outlined",fullWidth:!0,name:"retailer_price",value:t.values.retailer_price,onChange:t.handleChange,onBlur:t.handleBlur,error:t.touched.retailer_price&&!!t.errors.retailer_price,helperText:t.touched.retailer_price&&t.errors.retailer_price}),u.jsx(v,{variant:"contained",color:"primary",fullWidth:!0,onClick:p,disabled:!t.isValid||!t.dirty,children:"ذخیره تغییرات"})]})},Au=({item:i,updateTable:r})=>{const e=T(),[a,c]=C.useState(null),[d]=C.useContext(G),t=s=>c(s.currentTarget),p=()=>c(null),F=!!a,A=F?"popover":void 0,E=Y(),x=()=>{if(!(i!=null&&i.date))return!1;const s=new Date,h=new Date(i.date);return h.getFullYear()===s.getFullYear()&&h.getMonth()===s.getMonth()&&h.getDate()===s.getDate()},z=()=>{if(p(),!x()){d({msg:"فقط قیمتهای مربوط به تاریخ امروز قابل ویرایش هستند.",severity:"error",vertical:"top",horizontal:"center"});return}e(M({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(pu,{item:i,isEdit:!0,updateTable:r,onSubmit:s=>{e($({id:i.id,prices:{kill_house_price:s.killHousePrice,wholesaler_price:s.wholesalerPrice,retailer_price:s.retailerPrice}})).then(h=>{h.payload.error?d({msg:h.payload.error,severity:"error",vertical:"top",horizontal:"center"}):(r(),d({msg:"قیمتها با موفقیت ویرایش شدند",severity:"success",vertical:"top",horizontal:"center"}))})}}),title:"ویرایش قیمتهای کارمزد"}))},L=s=>{e($({id:i.id,prices:{kill_house_check:!0,state:s}})).then(h=>{h.payload.error?d({msg:h.payload.error,severity:"error",vertical:"top",horizontal:"center"}):(r(),e(lu()),d({msg:"وضعیت با موفقیت به روز رسانی شد",severity:"success",vertical:"top",horizontal:"center"}))})},N=()=>E!=="KillHouse"?u.jsx(U,{title:"ویرایش قیمتها",children:u.jsx(v,{size:"small",startIcon:u.jsx(cu,{fontSize:"small"}),sx:{"&.Mui-disabled":{backgroundColor:"transparent",color:"text.disabled"}},onClick:z,children:u.jsx(R,{variant:"body2",fontWeight:600,children:"ویرایش قیمتها"})})}):u.jsx(U,{title:"تایید/رد",children:u.jsx(v,{size:"small",startIcon:u.jsx(iu,{fontSize:"small"}),onClick:()=>{p(),e(tu({title:"تایید/ رد",content:u.jsxs(l,{container:!0,spacing:2,justifyContent:"center",children:[u.jsx(l,{item:!0,xs:12,children:u.jsx(R,{variant:"body2",color:"error",children:"توجه: در صورت تایید حجم قطعه اعلام شده، حجم مورد نظر از سالن مرغدار کسر شده و با میانگین وزن کشتار مرغدار به انبار شما اضافه میگردد."})}),u.jsx(l,{item:!0,children:u.jsx(v,{color:"success",variant:"contained",onClick:()=>L("accepted"),children:"تایید"})}),u.jsx(l,{item:!0,children:u.jsx(v,{color:"error",variant:"contained",onClick:()=>L("rejected"),children:"رد"})})]})}))},sx:{"&.Mui-disabled":{backgroundColor:"transparent",color:"text.disabled"}},children:u.jsx(R,{variant:"body2",fontWeight:600,children:"تایید / رد"})})});return u.jsxs("div",{children:[u.jsx(uu,{"aria-describedby":A,color:"primary",onClick:t,disabled:!x(),children:u.jsx(Cu,{})}),u.jsx(eu,{id:A,open:F,anchorEl:a,onClose:p,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},children:u.jsx("div",{style:{padding:"10px"},children:u.jsx(l,{container:!0,direction:"column",gap:1,alignItems:"flex-start",style:{width:150},children:N()})})})]})},gu=()=>{const i=T(),[r,e]=C.useState([]),[a,c]=C.useState([]),[d,t]=C.useState(0),[p,F]=C.useState(10),[A,E]=C.useState(1),x=async o=>{try{i(H());const n=await V.get(`chicken-commission-prices/?role=${Y()}&page=${o}&page_size=${p}`);i(_()),e(n.data.results),t(n.data.count)}catch(n){console.error("Error fetching pricing data:",n),i(_())}},z=o=>{x(o),E(o)},L=o=>{F(o),E(1)},N=()=>{x(A!==0?A:1)};C.useEffect(()=>{x(1)},[i,p]),C.useEffect(()=>{const o=r==null?void 0:r.map((n,j)=>{var P,b,k,y,w,m,f,I,q,Z;return[j+1,S(n==null?void 0:n.date),((P=n==null?void 0:n.chickenAveragePrice)==null?void 0:P.toLocaleString())+" ﷼",((b=n==null?void 0:n.killHousePrice)==null?void 0:b.toLocaleString())+" ﷼",((k=n==null?void 0:n.wholesalerPrice)==null?void 0:k.toLocaleString())+" ﷼",((y=n==null?void 0:n.retailerPrice)==null?void 0:y.toLocaleString())+" ﷼",((m=(w=n==null?void 0:n.priceInfo)==null?void 0:w.killHousePrice)==null?void 0:m.toLocaleString())+" ﷼",((I=(f=n==null?void 0:n.priceInfo)==null?void 0:f.wholesalePrice)==null?void 0:I.toLocaleString())+" ﷼",((Z=(q=n==null?void 0:n.priceInfo)==null?void 0:q.retailPrice)==null?void 0:Z.toLocaleString())+" ﷼",u.jsx(Au,{updateTable:N,item:n},j)]});c(o)},[r]);const s=Y(),h=()=>{var j,P,b,k,y,w,m;if(!r||r.length===0)return null;const o=r[0],n=[{title:"قیمت مرغ زنده",value:((j=o==null?void 0:o.chickenAveragePrice)==null?void 0:j.toLocaleString())+" ریال",date:S(o==null?void 0:o.createDate)},{title:"قیمت درب کشتارگاه",value:((b=(P=o==null?void 0:o.priceInfo)==null?void 0:P.killHousePrice)==null?void 0:b.toLocaleString())+" ریال",date:S(o==null?void 0:o.createDate)},{title:"قیمت عمده فروشی",value:((y=(k=o==null?void 0:o.priceInfo)==null?void 0:k.wholesalePrice)==null?void 0:y.toLocaleString())+" ریال",date:S(o==null?void 0:o.createDate)},{title:"قیمت خرده فروشی",value:((m=(w=o==null?void 0:o.priceInfo)==null?void 0:w.retailPrice)==null?void 0:m.toLocaleString())+" ریال",date:S(o==null?void 0:o.createDate)}];return u.jsx(l,{container:!0,mt:g.SMALL,px:2,children:n.map((f,I)=>u.jsx(l,{item:!0,xs:12,sm:6,md:3,p:1,children:u.jsx(au,{title:f.title,value:`${f.value} - ${f.date}`})},I))})};return u.jsxs(u.Fragment,{children:[u.jsx(l,{container:!0,direction:"column",alignItems:"start",justifyContent:"center",gap:g.SMALL,px:2,children:(s==="ProvinceFinancial"||s==="ProvinceOperator")&&u.jsx(l,{container:!0,gap:g.MEDIUM,alignItems:"start",children:u.jsx(l,{children:u.jsx(v,{variant:"contained",onClick:()=>{i(M({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"قیمت گذاری",content:u.jsx(hu,{})}))},children:"قیمت گذاری"})})})}),h(),u.jsx(l,{container:!0,alignItems:"center",justifyContent:"space-between",gap:g.SMALL,mt:g.MEDIUM,px:2,children:u.jsx(su,{title:"قیمت مرغ",name:"بایگانی قیمتها",columns:["ردیف","تاریخ","قیمت مرغ زنده"," کارمزد کشتارگاه","کارمزد عمدهفروش","کارمزد خردهفروش","قیمت درب کشتارگاه","قیمت عمده فروش","قیمت خرده فروش","عملیات"],customWidth:"100%",data:a,page:A,perPage:p,totalRows:d,handlePageChange:z,handlePerRowsChange:L})})]})},mu=()=>u.jsx(u.Fragment,{children:u.jsx(ru,{display:"flex",justifyContent:"center",children:u.jsx(l,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:u.jsx(l,{container:!0,justifyContent:"space-between",gap:g.SMALL,mt:g.SMALL,children:u.jsx(l,{width:"100%",children:u.jsx(gu,{})})})})})});export{mu as default};
|