1import{r as u,j as e,a as V,d as y,Y as K}from"./app-GeuYNidI.js";import{d as J}from"./download-DigR6lTq.js";import{h as v,_ as r,r as j,c as Q,a as N,b as X,B as Z,L as ee,d as te}from"./index-BKZvW2E0.js";import{F as ae,a as se}from"./index-C3GXdEto.js";import{A as oe}from"./AlertInfo-Bp2nTjlh.js";import{F as k,S as re,A as le}from"./SearchButton-DmJfY5_Z.js";import{T as a,B as Y,E as ne,P as de}from"./PdfIcon-C-FzrWpD.js";import{P as ie}from"./index-BS5Y-d5R.js";import{u as ce,h as R}from"./httpService-DyEjt2DT.js";import{A as pe}from"./AuthenticatedLayout-DUnuCfre.js";import"./CheckCircleIcon-GGnMvzC1.js";import"./Navbar-CpyAM3Us.js";import"./transition-K1BrbCiB.js";const F="text-brand-019 font-semibold underline hover:!text-brand-020 px-2 py-1 rounded transition-colors duration-150",$=({data:n})=>{const l=u.useMemo(()=>{const o=n.reduce((i,p)=>i+(p.bins_total||0),0),x=n.reduce((i,p)=>i+(p.pounds_total||0),0);return{bins:o,pounds:v(x)}},[n]);return e.jsx(a.Wrapper,{className:"border border-brand-021 rounded-[20px]",children:e.jsx("div",{className:"md:max-h-[700px] md:overflow-y-auto rounded-[20px]",children:e.jsxs(a,{children:[e.jsx(a.Head,{className:"!bg-brand-021 sticky top-0 z-10",children:e.jsxs(a.Row,{children:[e.jsx(a.Cell,{as:"th",className:"px-4 py-3 text-left text-sm font-semibold !text-brand-018",children:"Pool ID"}),e.jsx(a.Cell,{as:"th",className:"px-4 py-3 text-left text-sm font-semibold !text-brand-018",children:"Pool Dates"}),e.jsx(a.Cell,{as:"th",className:"px-4 py-3 text-left text-sm font-semibold !text-brand-018",children:"Receipt Numbers"}),e.jsx(a.Cell,{as:"th",className:"px-4 py-3 text-left text-sm font-semibold !text-brand-018",children:"ACH/Check Date"}),e.jsx(a.Cell,{as:"th",className:"px-4 py-3 text-left text-sm font-semibold !text-brand-018",children:"Total Bins"}),e.jsx(a.Cell,{as:"th",className:"px-4 py-3 text-left text-sm font-semibold !text-brand-018",children:"Total Pounds"})]})}),e.jsxs(a.Body,{className:"bg-brand-022",children:[n.map((o,x)=>e.jsxs(a.Row,{children:[e.jsx(a.Cell,{as:"td",children:o.pool_target==="_self"?e.jsx(V,{className:F,href:o.pool_url,children:o.pool_uid}):e.jsx("a",{className:F,href:o.pool_url,rel:"noopener noreferrer",target:"_blank",children:o.pool_uid})}),e.jsx(a.Cell,{as:"td",children:o.pool_dates}),e.jsx("td",{className:"px-2 text-gray-900 text-sm text-left first:pl-4 last:pr-4 py-2 max-w-[200px] break-words",children:o.receipt_numbers}),e.jsx(a.Cell,{as:"td",children:o.check_date}),e.jsx(a.Cell,{as:"td",children:o.bins_total_formatted}),e.jsx(a.Cell,{as:"td",children:o.pounds_total_formatted})]},x)),e.jsxs(a.Row,{className:"bg-gray-50 sticky bottom-0 z-10",children:[e.jsx(a.Cell,{children:"GRAND TOTAL"}),e.jsx(a.Cell,{}),e.jsx(a.Cell,{}),e.jsx(a.Cell,{}),e.jsx(a.Cell,{children:l.bins}),e.jsx(a.Cell,{children:l.pounds})]})]})]})})})};$.propTypes={data:ie.array.isRequired};const ue=y(),me={block:"*",grower:"",year:String(ue.year())},xe=Q({block:N().required("Block is required."),grower:N().required("Grower is required."),year:N().required("Year is required.")});function he(n,l){const o={label:"All Blocks",value:"*"};if(!n)return[o];const x=r.get(l,[n],[]);if(!x.length)return[o];const i=r.chain(x).map(p=>({label:`${p.name} (${p.variety_name})`,value:p.id})).orderBy(["label"],["asc"]).value();return i.unshift(o),i}function be(){const n=new Date().getFullYear();return Array.from(Array(3).keys()).map(l=>({label:String(n-l),value:String(n-l)}))}function Se({auth:n,growers:l,sessionOverrides:o,sessionRows:x,sessionValues:i}){const p=ce(),[C,D]=u.useState(!1),[w,B]=u.useState(!1),[P,M]=u.useState(o),[h,O]=u.useState(x),[S,q]=u.useState(i),E=u.useMemo(()=>r.chain(l).keyBy(t=>t.uid).mapValues("blocks").value(),[l]),_=u.useMemo(()=>r.chain(h).groupBy("pool_uid").map(t=>{const c=[],s=r.chain(t).filter(m=>m.type==="product").groupBy("receipt_uid").map((m,z)=>(c.push(z),m)).flatten().first().value();if(!s)return null;const f=t.filter(m=>m.type==="product"),d=f.some(m=>m.hasOwnProperty("receipt_uid"))?"receipt_uid":"block_uid",g=r.chain(f).groupBy(d).map(m=>
1r.get(m,"[0].bin_count",0)).sum().value(),T=r.sumBy(f,"weight"),b={bins_total:g,bins_total_formatted:g.toLocaleString(),check_date:y(s.check_signed_at).format("M/D/YYYY"),grower_uid:s.grower_uid,pool_dates:`${y(s.pool_started_at).format("M/D/YYYY")} - ${y(s.pool_ended_at).format("M/D/YYYY")}`,pool_target:"_self",pool_uid:s.pool_uid,pool_url:j("statements.report",{grower:s.grower_uid,pool:s.pool_uid}),pounds_total:T,pounds_total_formatted:v(T),receipt_numbers:c.sort().join(", ")};return P.includes(b.pool_uid)&&(b.override=!0,b.pool_target="_blank",b.pool_url=j("statements.override",{grower:b.grower_uid,pool:b.pool_uid})),b}).filter(t=>!!t).orderBy(["pool_uid"],["desc"]).value(),[P,h]),I=u.useMemo(()=>r.chain(l).map(t=>({label:`${t.name} (${t.uid})`,value:t.uid})).orderBy(["label"],["asc"]).value(),[l]),L=u.useMemo(()=>{const t=r.cloneDeep(me),c=r.chain(l).map(s=>({label:`${s.name} (${s.uid})`,value:s.uid})).orderBy(["label"],["asc"]).map(s=>s.value).head().value();return c&&(t.grower=c),r.isPlainObject(i)&&r.assign(t,i),t},[l,i]),W=()=>{D(!0);const t=_.map(d=>({"Pool ID":d.pool_uid,"Pool Dates":d.pool_dates,"Receipt Numbers":d.receipt_numbers,"ACH/Check Date":d.check_date,"Total Bins":d.bins_total,"Total Pounds":v(d.pounds_total)})),c=_.reduce((d,g)=>d+(g.bins_total||0),0),s=_.reduce((d,g)=>d+(g.pounds_total||0),0);t.push({"Pool ID":"GRAND TOTAL","Pool Dates":"","Receipt Numbers":"","ACH/Check Date":"","Total Bins":c,"Total Pounds":v(s)});const f=X(`pool-statements-${S.grower}`),A=Z(f)(t);ee(f)(A),D(!1)},G=()=>{B(!0),R.postDownload(j("statements.search.download"),S).then(t=>{J(t.data,te(t),t.data.type)}).catch(p).finally(()=>{B(!1)})},H=t=>c=>{t.setFieldValue("block","*")},U=(t,{setSubmitting:c})=>{c(!0),R.post(j("statements.search"),t).then(s=>s.data).then(s=>{M(s.overrides),O(s.rows),q(t)}).catch(p).finally(()=>{c(!1)})};return e.jsxs(pe,{auth:n,title:"Pool Statements",children:[e.jsx(K,{title:"Pool Statements"}),e.jsx("div",{className:"pb-12 md-py-12",children:e.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:"grid grid-cols-3 gap-4 lg:gap-8",children:[e.jsx("div",{className:"col-span-3 lg:col-span-1 print:hidden",children:e.jsx("div",{className:"bg-brand-021 rounded-[31px] p-4 md:p-6 lg:p-8",children:e.jsx(ae,{initialValues:L,validationSchema:xe,onSubmit:U,children:t=>e.jsx(se,{className:"block space-y-4 space-y-4 text-[20px] text-brand-018 !border-none font-regular",autoComplete:"off",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(k,{label:"Grower",name:"grower",options:I,onChange:H(t)}),e.jsx(k,{label:"Block",name:"block",options:he(t.values.grower,E)}),e.jsx(k,{label:"Year",name:"year",options:be()}),e.jsx(re,{submitting:t.isSubmitting,onClick:()=>{t.submitForm()},className:"inline-flex items-center gap-2 py-[12px] px-[42px] bg-brand-019 text-brand-018 hover:text-brand-018 active:bg-brand-020 rounded-full hover:bg-brand-017 border border-brand-018 font-serif !w-auto"})]})})})})}),e.jsxs("div",{className:"col-span-3 lg:col-span-2",children:[h===null&&e.jsx(oe,{children:e.jsx("p",{children:"Enter search criteria to view pool statements."})}),r.isArray(h)&&h.length<1&&e.jsx(le,{children:e.jsx("p",{children:"No pool statements found for that search criteria."})}),r.isArray(h)&&h.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx($,{data:_}),e.jsxs("div",{className:"gap-4 grid grid-cols-1 md:grid-cols-2",children:[e.jsxs(Y,{className:"inline-flex items-center gap-2 py-[8px] px-[42px] bg-brand-021 text-brand-018 hover:text-brand-018 rounded-full hover:bg-brand-017 border-brand-018 font-serif",disabled:C,onClick:W,children:[e.jsx(ne,{className:"block h-4 w-auto"}),e.jsx("span",{children:C?"Downloading...":"Download Data"})]}),e.jsxs(Y,{className:"inline-flex items-center gap-2 py-[8px] px-[42px] bg-brand-021 text-brand-018 hover:text-brand-018 rounded-full hover:bg-brand-017 border-brand-018 font-serif",disabled:w,onClick:G,children:[e.jsx(de,{className:"block h-4 w-auto"}),e.jsx("span",{children:w?"Downloading...":"Download PDF"})]})]})]})]})]})})})]})}export{Se as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.