PageSourceSearch

https://stone-profit-flow.base44.app/assets/DigitalChangeOrders-XQc4vsZh.js

js stone-profit-flow.base44.app collected 2026-10-03 03:10:26 UTC 11,054 bytes, 1 lines download raw bytes

1import{a as x,u as K,d as D,e as S,j as e}from"./vendor-query-B-_nDQQY.js";import{F as O,B as r,C as c,d,n as _,D as N,a as Q,c as $,e as B,r as R,I as j,t as k,b as m}from"./index-D8ww6b7J.js";import{T as C}from"./textarea-Bhj0eADY.js";import{D as q,a as T,b as F,c as P}from"./dialog-BQWtAG_x.js";import{b as H}from"./index-BgPuGWoM.js";import{P as J}from"./PageHeader-DOQecRZi.js";import{P as W}from"./plus-MQo5wr8n.js";import{C as y}from"./circle-check-big-4Ew-rpqG.js";import{C as z}from"./circle-x-CIIBFH3_.js";import{f as L}from"./format-C2V2JF1Z.js";import"./vendor-three-1K-S22da.js";import"./vendor-charts-i-522T5A.js";import"./vendor-react-BUIlT3ms.js";import"./vendor-pdf-Bwkk3Ew0.js";import"./vendor-radix-X0WMATEu.js";import"./constants-yGZMfuMC.js";function me(){var w;const[i,v]=x.useState(null),[I,p]=x.useState(!1),[M,u]=x.useState(!1),[a,n]=x.useState({job_id:"",customer_name:"",customer_email:"",change_description:"",change_type:"material",original_specification:"",new_specification:"",price_adjustment:0,timeline_impact_days:0,notes:""}),h=x.useRef(null),f=K(),{data:l=[]}=D({queryKey:["change-orders"],queryFn:()=>m.entities.ChangeOrder.list("-request_date",100)}),{data:b=[]}=D({queryKey:["jobs"],queryFn:()=>m.entities.Job.list()}),A=S({mutationFn:async s=>{const t=await m.entities.Job.get(s.job_id);return await m.entities.ChangeOrder.create({...s,change_order_number:`CO-${Date.now()}`,job_label:t.customer_name,request_date:new Date().toISOString(),status:"pending_approval"})},onSuccess:()=>{f.invalidateQueries({queryKey:["change-orders"]}),k.success("Change order created"),p(!1),n({job_id:"",customer_name:"",customer_email:"",change_description:"",change_type:"material",original_specification:"",new_specification:"",price_adjustment:0,timeline_impact_days:0,notes:""})}});S({mutationFn:({id:s,status:t})=>m.entities.ChangeOrder.update(s,{status:t}),onSuccess:()=>{f.invalidateQueries({queryKey:["change-orders"]}),k.success("Status updated")}});const E=()=>{if(h.current){const s=h.current.getTrimmedCanvas().toDataURL("image/png");i&&(m.entities.ChangeOrder.update(i.id,{customer_signature:s,signature_date:new Date().toISOString(),status:"approved"}),f.invalidateQueries({queryKey:["change-orders"]}),u(!1),v(null))}},o={total:l.length,pending:l.filter(s=>s.status==="pending_approval").length,approved:l.filter(s=>s.status==="approved").length,declined:l.filter(s=>s.status==="declined").length,total_value:l.filter(s=>s.status==="approved").reduce((s,t)=>s+(t.price_adjustment||0),0)};return e.jsxs("div",{className:"p-4 sm:p-6 space-y-6",children:[e.jsx(J,{icon:O,title:"Digital Change Orders",subtitle:"Create, approve, and track change orders with e-signatures",children:e.jsxs(r,{onClick:()=>p(!0),children:[e.jsx(W,{className:"w-4 h-4 mr-2"}),"Create Change Order"]})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-5",children:[e.jsx(c,{children:e.jsx(d,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total"}),e.jsx("p",{className:"text-2xl font-bold",children:o.total})]})]})})}),e.jsx(c,{children:e.jsx(d,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"w-5 h-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pending"}),e.jsx("p",{className:"text-2xl font-bold",children:o.pending})]})]})})}),e.jsx(c,{children:e.jsx(d,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{className:"w-5 h-5 text-green-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Approved"}),e.jsx("p",{className:"text-2xl font-bold",children:o.approved})]})]})})}),e.jsx(c,{children:e.jsx(d,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{className:"w-5 h-5 text-red-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Declined"}),e.jsx("p",{className:"text-2xl font-bold",children:o.declined})]})]})})}),e.jsx(c,{children:e.jsx(d,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Value"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",o.total_value.toFixed(2)]})]})]})})})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:l.map(s=>{var t;return e.jsxs(c,{className:"cursor-pointer hover:bg-accent/50",onClick:()=>v(s),children:[e.jsx(Q,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx($,{className:"text-lg",children:s.change_order_number}),e.jsx(B,{variant:s.status==="approved"?"default":s.status==="declined"?"destructive":s.status==="pending_approval"?"secondary":"outline",children:s.status.replace("_"," ")})]})}),e.jsxs(d,{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:s.customer_name}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:s.change_description}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(R,{className:"w-4 h-4"}),e.jsx("span",{children:L(new Date(s.request_date),"MMM d, yyyy")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(N,{className:"w-4 h-4"}),e.jsxs("span",{className:s.price_adjustment>0?"text-green-600":"text-red-600",children:[s.price_adjustment>0?"+":"","$",(t=s.price_adjustment)==null?void 0:t.toFixed(2)]})]}),s.timeline_impact_days&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(_,{className:"w-4 h-4"}),e.jsxs("span",{children:[s.timeline_impact_days>0?"+":"",s.timeline_impact_days," days"]})]}),s.status==="pending_approval"&&e.jsxs(r,{size:"sm",className:"w-full mt-2",onClick:g=>{g.stopPropagation(),v(s),u(!0)},children:[e.jsx(y,{className:"w-4 h-4 mr-2"}),"Sign to Approve"]})]})]},s.id)})}),e.jsx(q,{open:I,onOpenChange:p,children:e.jsxs(T,{className:"max-w-2xl",children:[e.jsx(F,{children:e.jsx(P,{children:"Create Change Order"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Select Job"}),e.jsxs("select",{className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:a.job_id,onChange:s=>{const t=b.find(g=>g.id===s.target.value);n({...a,job_id:s.target.value,customer_name:(t==null?void 0:t.customer_name)||"",customer_email:(t==null?void 0:t.customer_email)||""})},children:[e.jsx("option",{value:"",children:"Select a job"}),b.filter(s=>!["completed","cancelled"].includes(s.status)).map(s=>e.jsxs("option",{value:s.id,children:[s.customer_name," - ",s.job_address]},s.id))]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Customer Name"}),e.jsx(j,{value:a.customer_name,onChange:s=>n({...a,customer_name:s.target.value})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Customer Email"}),e.jsx(j,{type:"email",value:a.customer_email,onChange:s=>n({...a,customer_email:s.target.value})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Change Type"}),e.jsxs("select",{className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:a.change_type,onCh
1ange:s=>n({...a,change_type:s.target.value}),children:[e.jsx("option",{value:"material",children:"Material"}),e.jsx("option",{value:"design",children:"Design"}),e.jsx("option",{value:"dimensions",children:"Dimensions"}),e.jsx("option",{value:"edge_profile",children:"Edge Profile"}),e.jsx("option",{value:"cutouts",children:"Cutouts"}),e.jsx("option",{value:"timeline",children:"Timeline"}),e.jsx("option",{value:"other",children:"Other"})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Change Description"}),e.jsx(C,{placeholder:"Describe the requested change...",value:a.change_description,onChange:s=>n({...a,change_description:s.target.value})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Original Specification"}),e.jsx(C,{placeholder:"What was originally specified...",value:a.original_specification,onChange:s=>n({...a,original_specification:s.target.value})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"New Specification"}),e.jsx(C,{placeholder:"What customer now wants...",value:a.new_specification,onChange:s=>n({...a,new_specification:s.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Price Adjustment ($)"}),e.jsx(j,{type:"number",value:a.price_adjustment,onChange:s=>n({...a,price_adjustment:parseFloat(s.target.value)||0})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Timeline Impact (Days)"}),e.jsx(j,{type:"number",value:a.timeline_impact_days,onChange:s=>n({...a,timeline_impact_days:parseInt(s.target.value)||0})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(r,{variant:"outline",onClick:()=>p(!1),children:"Cancel"}),e.jsx(r,{onClick:()=>A.mutate(a),disabled:!a.job_id||!a.customer_name,children:"Create Change Order"})]})]})]})}),e.jsx(q,{open:M,onOpenChange:u,children:e.jsxs(T,{children:[e.jsx(F,{children:e.jsx(P,{children:"Sign to Approve Change Order"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:i==null?void 0:i.customer_name}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:i==null?void 0:i.change_description}),e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(N,{className:"w-4 h-4"}),"$",(w=i==null?void 0:i.price_adjustment)==null?void 0:w.toFixed(2)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(_,{className:"w-4 h-4"}),(i==null?void 0:i.timeline_impact_days)||0," days"]})]})]}),e.jsx("div",{className:"border rounded-lg",children:e.jsx(H.SignatureCanvas,{ref:h,canvasProps:{width:400,height:200,className:"signature-canvas w-full"}})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(r,{variant:"outline",onClick:()=>{var s;return(s=h.current)==null?void 0:s.clear()},children:"Clear"}),e.jsx(r,{variant:"outline",onClick:()=>u(!1),children:"Cancel"}),e.jsxs(r,{onClick:E,children:[e.jsx(y,{className:"w-4 h-4 mr-2"}),"Approve"]})]})]})]})})]})}export{me 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.