PageSourceSearch

https://company-e82bc.web.app/assets/ScheduledContainerForm-C4FMY66C.js

js company-e82bc.web.app collected 2026-10-03 12:21:24 UTC 8,172 bytes, 1 lines download raw bytes

1import{r as s,ad as u}from"./vendor-B2mwFaEh.js";import{F as X,z as fe,m as Y,x as he,r as be,C as Ne}from"./firebase-BEuJf_if.js";import{P as ye,S as ge,a as we,b as Ce}from"./SupplierSearch-DRt_dsRW.js";import{P as Se}from"./ProductSalesHistoryModal-BqDqfN8F.js";import{a4 as Re,X as je,aC as ke}from"./icons-od6ehn-l.js";import"./excel-libs-DENYFglI.js";import"./index-3ztlLpng.js";import"./pdf-libs-Pu_J_WX0.js";import"./lotExpiryPolicy-BFoFfUpN.js";import"./postgrestIn-CzsSh00X.js";const K=()=>{const i=new Date(Date.now()+324e5);return`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`},Oe=({slipToEdit:r,onClose:i,db:N,companyId:y,products:R,inventory:V,warehouses:x,customers:g,purchases:Z,salesData:U,quotes:E,T:o,formatCurrency:w,logSystemAction:m,currentUser:C,userName:P})=>{const[p,$]=s.useState(K()),[j,Q]=s.useState(""),[S,_]=s.useState(null),[k,O]=s.useState(x?.[0]?.id||""),[F,z]=s.useState("掛売り"),[H,W]=s.useState(""),[f,h]=s.useState([]),[I,v]=s.useState({productCode:"",unitQty:"",qty:"",unitCost:"",totalAmount:0,taxRate:.1}),J=s.useMemo(()=>r?.writerName?r.writerName:C?.displayName||P||C?.email||"Unknown",[r,C,P]);s.useEffect(()=>{if(r){$(r.expectedDate||K()),Q(r.supplierId||"");const e=g.find(a=>a.id===r.supplierId);e&&_(e),O(r.warehouseId||x?.[0]?.id||""),z(r.slipType||"掛売り");const t=r.remarks?.replace("[예약사입] ","")||"";W(t);const n=(r.items||[]).map(a=>({...a,taxRate:a.taxRate?Number(a.taxRate):.1}));h(n)}},[r,g,x]);const T=s.useRef(null),ee=s.useRef(null),te=s.useRef(null),ae=s.useRef(null),se=s.useRef(null),ne={inputRef:T,dateRef:ee,slipTypeRef:te,warehouseRef:ae,remarksRef:se},[D,L]=s.useState({isOpen:!1,product:null}),re=s.useCallback(e=>{if(!e)return;const t=R.find(n=>n.code===e);t&&L({isOpen:!0,product:t})},[R]),{subTotal:B,tax8:q,tax10:A,finalTotal:G}=s.useMemo(()=>{let e=0,t=0;f.forEach(c=>{const d=Number(c.totalAmount)||0,b=Number(c.taxRate)||.1;Math.abs(b-.08)<.001?e+=d:t+=d});const n=Math.round(e*.08),a=Math.round(t*.1),l=e+t;return{subTotal:l,tax8:n,tax10:a,finalTotal:l+n+a}},[f]),M=s.useCallback(e=>e?o(e.name_kr||e.name,e.name_jp||e.name)||e.name:"",[o]),oe=s.useCallback((e,t,n)=>{h(a=>{const l=[...a],c={...l[e],[t]:n};if(t==="qty"||t==="unitQty"||t==="unitCost"){const d=Number(c.unitQty??c.qty??0),b=Number(c.unitCost??0);c.totalAmount=Math.round(d*b)}return l[e]=c,l})},[]),le=s.useCallback((e,t)=>{t&&h(n=>{const a=[...n],l=Number(t.unitCost||t.movingAverageCost||t.price||0),c=Number(a[e].unitQty??a[e].qty??1),d=t.tax_rate??t.taxRate??.1,b=Number(d)===8||Number(d)===.08?.08:.1;return a[e]={...a[e],productCode:t.code||t.id,unitCost:l,totalAmount:Math.round(c*l),taxRate:b},a})},[]),ue=s.useCallback((e,t)=>{v(n=>{const a={...n,[e]:t};
1if(e==="qty"||e==="unitQty"||e==="unitCost"){const l=Number(a.unitQty??a.qty??0),c=Number(a.unitCost??0);a.totalAmount=Math.round(l*c)}return a})},[]),ce=s.useCallback(e=>{e&&v(t=>{const n=Number(e.unitCost||e.movingAverageCost||e.price||0),a=Number(t.unitQty??t.qty??1),l=e.tax_rate??e.taxRate??.1,c=Number(l)===8||Number(l)===.08?.08:.1;return{...t,productCode:e.code||e.id,unitCost:n,unitQty:a,qty:a,totalAmount:Math.round(a*n),taxRate:c}})},[]),ie=s.useCallback(e=>{const t=e&&e.productCode?e:I;!t||!t.productCode||(h(n=>[...n,t]),v({productCode:"",unitQty:"",qty:"",unitCost:"",totalAmount:0,taxRate:.1}))},[I]),de=s.useCallback(e=>{h(t=>t.filter((n,a)=>a!==e))},[]),me=async()=>{if(!p||!j&&!S?.id||f.length===0){alert(o("필수 정보(입고예정일, 거래처, 상품)를 모두 입력해주세요.","必須情報をすべて入力してください。"));return}try{const e=j||S?.id,t=g.find(a=>a.id===e)||S,n={expectedDate:p,status:"PENDING",supplierId:e,supplierName:t?.name||"",supplier:t?.name_kr||t?.name||"",supplierJp:t?.name_jp||"",warehouseId:k,slipType:F,remarks:`[예약사입] ${H}`,items:f.map(a=>{const l=Number(a.unitQty??a.qty??0);return{productCode:a.productCode,qty:l,unitQty:l,unitCost:Number(a.unitCost),totalAmount:Number(a.totalAmount),taxRate:Number(a.taxRate)||.1}}),subTotal:Number(B),tax8:Number(q),tax10:Number(A),taxTotal:Number(q+A),finalTotal:Number(G),updatedAt:X()};r?.id?(await fe(Y(N,`companies/${y}/scheduled_purchases`,r.id),n),m&&m("UPDATE",`예약 사입 수정: ${t?.name} (${p})`),alert(o("예약 내용이 수정되었습니다.","予約内容が修正されました。"))):(n.createdAt=X(),n.createdBy=C?.uid||"system",n.writerName=J,await he(be(N,`companies/${y}/scheduled_purchases`),n),m&&m("CREATE",`예약 사입 생성: ${t?.name} (${p})`),alert(o("성공적으로 예약되었습니다.","予約が完了しました。"))),i()}catch(e){console.error("Save error:",e),alert("저장 중 오류가 발생했습니다.")}},pe=async()=>{if(r?.id&&window.confirm(o("이 예약을 취소(삭제)하시겠습니까?","この予約をキャンセル(削除)しますか?")))try{await Ne(Y(N,`companies/${y}/scheduled_purchases`,r.id)),m&&m("DELETE",`예약 사입 취소: ${r.supplierName} (${r.expectedDate})`),alert(o("예약이 취소되었습니다.","予約がキャンセルされました。")),i()}catch(e){console.error("Delete error:",e),alert("삭제 중 오류가 발생했습니다.")}},xe=[{key:"F2",label:r?o("예약 수정 (F2)","予約修正 (F2)"):o("예약 저장 (F2)","予約保存 (F2)"),handler:me,color:"bg-indigo-600 hover:bg-indigo-700",primary:!0},...r?[{key:"Delete",label:o("예약 취소","予約キャンセル"),handler:pe,color:"bg-red-500 hover:bg-red-600"}]:[],{key:"Escape",label:o("닫기 (Esc)","閉じる (Esc)"),handler:i,color:"bg-gray-500 hover:bg-gray-600"}];return u.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:u.jsxs("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",children:[u.jsxs("div",{className:"flex justify-between items-center p-4 border-b bg-indigo-50 rounded-t-lg flex-none",children:[u.jsxs("h2",{className:"text-lg font-bold text-indigo-800 flex items-center gap-2",children:[u.jsx(Re,{size:20}),r?o("컨테이너 입고 / 예약 수정","コンテナ入荷 / 予約修正"):o("컨테이너 입고 / 예약 사입 등록","コンテナ入荷 / 予約仕入登録")]}),u.jsx("button",{onClick:i,className:"text-gray-500 hover:text-red-500 transition-colors",children:u.jsx(je,{size:24})})]}),u.jsxs("div",{className:"bg-indigo-100 p-3 text-sm text-indigo-800 flex items-start gap-2 border-b border-indigo-200 flex-none",children:[u.jsx(ke,{size:18,className:"mt-0.5 flex-shrink-0"}),u.jsxs("p",{children:[o("이곳에 입력한 내용은 ","ここに入力した内容は "),u.jsx("strong",{className:"text-red-600 underline decoration-red-400 decoration-2 underline-offset-2",children:p}),o(" 자정(00:00)에 자동으로 재고가 증가하고 시스템 원가(unitCost)가 갱신됩니다."," の深夜に自動的に在庫が増加し、システム原価(unitCost)が更新されます。")]})]}),u.jsx(ye,{supplierId:j,setSupplierId:Q,selectedSupplier:S,setSelectedSupplier:_,purchaseDate:p,setPurchaseDate:$,slipType:F,setSlipType:z,warehouseId:k,setWarehouseId:O,warehouses:x,customers:g,remarks:
1H,setRemarks:W,SupplierSearchComponent:ge,refs:ne,writerName:J,T:o,getName:M,formatCurrency:w,slipTypeOptions:[{value:"掛売り",label:o("0. 외상","0. 掛買い")},{value:"現金",label:o("1. 현금","1. 現金")}]}),u.jsx("div",{className:"flex-grow p-2 overflow-hidden flex flex-col bg-gray-100",children:u.jsx(we,{items:f,products:R,inventory:V,selectedWarehouseId:k,warehouses:x,newItem:I,onNewItemChange:ue,onNewProductSelect:ce,onAddNewItem:ie,handleItemChange:oe,handleProductSelect:le,handleRemoveItem:de,onShowHistory:re,T:o,getName:M,formatCurrency:w,setLastFocused:()=>{}})}),u.jsx("div",{className:"flex-none bg-white",children:u.jsx(Ce,{subTotal:B,tax8:q,tax10:A,finalTotal:G,formatCurrency:w,T:o,actions:xe})}),D.isOpen&&u.jsx(Se,{isOpen:D.isOpen,onClose:()=>L({isOpen:!1,product:null}),product:D.product,allSales:U,allQuotes:E,allPurchases:Z,customer:null,db:N,companyId:y,T:o,getName:M,formatCurrency:w})]})})};export{Oe 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.