Files
docker-invoiceninja/docker/app/public/bundle.b5328565.js
2024-10-19 18:17:42 +00:00

2 lines
2.3 KiB
JavaScript

import{O as N,u as D,a6 as E,x as I,bI as k,_ as B,p as r,f3 as j,c as a,ac as A,aJ as O,b9 as P,i as Y,T as $,j as b,f4 as w,ba as _,r as F,e as M,bb as q,h as H,dg as J}from"./bundle.3e24044b.js";import{D as Q,N as z,A as G,T as K}from"./bundle.0068fcec.js";import"./bundle.70f44589.js";import"./bundle.b543ffc0.js";import"./bundle.f10c961a.js";import"./bundle.61eb3282.js";function Z(){const{documentTitle:g}=N("new_expense"),[c]=D(),y=E(),e=I(),[n]=k(),T=[{name:c("expenses"),href:"/expenses"},{name:c("new_expense"),href:"/expenses/create"}],[t,d]=B(J),[p,u]=r.useState(),[x,S]=r.useState(e!=null&&e.calculate_expense_tax_by_amount?"by_amount":"by_rate"),[m,v]=r.useState(!1),{data:o}=j({enabled:typeof t>"u"}),l=w({setExpense:d,setErrors:u}),h=f=>{m||(_.processing(),u(void 0),v(!0),F("POST",M("/api/v1/expenses"),t).then(s=>{_.success("created_expense"),q(["expenses"]),f==="save"?y(H("/expenses/:id/edit",{id:s.data.data.id})):o&&d(o)}).catch(s=>{var i;((i=s.response)==null?void 0:i.status)===422&&(u(s.response.data),_.dismiss())}).finally(()=>v(!1)))},C=[{onClick:()=>h("create"),label:`${c("save")} / ${c("create")}`,icon:a(A,{element:O})}];return r.useEffect(()=>{d(f=>{let s=f;if(n.get("action")!=="clone"&&(s=void 0),typeof o<"u"&&typeof s>"u"&&n.get("action")!=="clone"){const i=P.cloneDeep(o);n.has("vendor")&&(i.vendor_id=n.get("vendor")),n.has("client")&&(i.client_id=n.get("client")),s={...i,payment_date:e!=null&&e.mark_expenses_paid?Y().format("YYYY-MM-DD"):"",should_be_invoiced:e==null?void 0:e.mark_expenses_invoiceable,invoice_documents:e==null?void 0:e.invoice_expense_documents,calculate_tax_by_amount:x==="by_amount",uses_inclusive_taxes:e.expense_inclusive_taxes}}return s})},[o]),a($,{title:g,breadcrumbs:T,onSaveClick:()=>t&&h("save"),additionalSaveOptions:C,disableSaveButton:m,children:b("div",{className:"grid grid-cols-12 gap-4",children:[a("div",{className:"col-span-12 xl:col-span-4",children:a(Q,{expense:t,handleChange:l,taxInputType:x,pageType:"create",errors:p})}),a("div",{className:"col-span-12 xl:col-span-4",children:a(z,{expense:t,handleChange:l,errors:p})}),b("div",{className:"col-span-12 xl:col-span-4 space-y-4",children:[a(G,{expense:t,handleChange:l,errors:p}),a(K,{expense:t,handleChange:l,taxInputType:x,setTaxInputType:S})]})]})})}export{Z as default};