1import{u as fe,r as i,ao as be,ah as Ce,a as Te,al as we,b as ke,j as e,B as u,x as v,n as a,L as Ne,S as Se,f as y,dB as Ie,z as x,h as f,dy as Pe,dz as Ve,dC as Be}from"./index-BvNIJ_c2.js";import{L as Je}from"./index-Dd_NvOz0.js";import{u as Ee,D as Fe}from"./index-B_Ogjjpj.js";import{R as Z}from"./index-Cza-r62S.js";import{u as De}from"./index-DnfnUxZA.js";import{p as j,f as g}from"./index-CW-ndsYY.js";import{S as Ae}from"./index-CGXRXm6f.js";import{a as Le}from"./featureFlags-D6rWTZOc.js";import{I as Me,V as Oe,t as _e,b as Ge}from"./formErrors-CCW91Grc.js";import{I as Re}from"./validationRules-Eb6EGYXU.js";import{P as Ue}from"./PriceSummary-CaGr8AJ5.js";import{u as $e,W as Ke}from"./WebGuide-BIxIKBbg.js";import{R as c}from"./Row-Bj__9rZq.js";import"./profile1-DX-Es6KB.js";import"./NavbarContext-C9kG8e2O.js";import"./Anchor-C0wshJja.js";import"./index-Laxbxmnr.js";import"./navigationConfig-DMPz6vwn.js";import"./NavIcon-CE0lX41N.js";import"./index-IEJD0KmR.js";import"./Image-y3xwkAif.js";import"./Tab-B5OAj-R1.js";import"./Nav-Tj50dJFm.js";import"./CardHeaderContext-CfKayEkG.js";import"./useAiChatStore-DgcBp8ir.js";import"./Card-DEsHlakG.js";const fn=()=>{const{t:s}=fe(),[k,b]=i.useState([]),{canUseFeature:N}=be(),{showSubscriptionModal:S}=Ce(),p=$e("inventoryServiceEdit"),[ee,I]=i.useState(!1),m=Te(),{id:d}=we(),[C,ne]=i.useState([]),[ze,te]=i.useState([]),[se,P]=i.useState(""),[re,V]=i.useState("price"),B=(t,l)=>{const o=j(t)||0,h=parseFloat(l)||0;return Math.round(o*(1+h/100))},J=(t,l)=>{const o=j(t)||0,h=parseFloat(l)||0;return Math.round(o/(1+h/100))},ae=t=>{const l=t.target.value;if(/^[0-9,.]*$/.test(l)){n.setFieldValue("price",l),V("price");const o=B(l,n.values.vat);n.setFieldValue("sellingPrice",o>0?g(o):"")}},oe=t=>{const l=t.target.value;if(/^[0-9,.]*$/.test(l)){n.setFieldValue("sellingPrice",l),V("sellingPrice");const o=J(l,n.values.vat);n.setFieldValue("price",o>0?g(o):"")}},le=t=>{const l=t.target.value.replace(/[^0-9.]/g,"");if(n.setFieldValue("vat",l),re==="sellingPrice"&&n.values.sellingPrice){const o=J(n.values.sellingPrice,l);n.setFieldValue("price",o>0?g(o):"")}else if(n.values.price){const o=B(n.values.price,l);n.setFieldValue("sellingPrice",o>0?g(o):"")}},n=ke({initialValues:{service:"",category:"",subcategory:"",price:"",sellingPrice:"",unit:"",vat:"25",showInJournal:!0,journalText:"",invoiceText:"",internalNotes:"",showTextInJournal:!0,showTextOnInvoice:!0,allowAutoJournal:!1},validationSchema:Ae(),onSubmit:async t=>{const l={name:t.service,typeId:t.category,subCategoryId:t.subcategory||null,pricePerUnit:j(t.price),unit:parseInt(t.unit,10),vatPercentage:parseInt(t.vat,10),showInJournal:t.showInJournal,journalText:t.journalText,invoiceText:t.invoiceText,internalNotes:t.internalNotes,showTextInJournal:t.showTextInJournal,showTextOnInvoice:t.showTextOnInvoice,allowAutoJournal:t.allowAutoJournal};try{const{data:o}=await y.put(Ie.endPoint(d),l);x.success((o==null?void 0:o.message)||"Inventory service updated successfully"),D(),O(!0),t.allowAutoJournal?m(`/inventory-management/service/${d}/template-management`):m("/inventory-management",{state:{restoreList:!0}})}catch(o){x.error(f(o))}}}),{hasDraft:E,draftAge:T,restoreDraft:F,clearDraft:D}=Ee(`service-edit-${d}`,{formValues:n.values});i.useEffect(()=>{if(E&&T<3e5){const t=F();t!=null&&t.formValues&&n.setValues(t.formValues)}},[]);const ie=Object.keys(n.touched).length>0,ce={service:s("inventory.service.serviceName")||"Servicenamn",category:s("CommonText.Category"),unit:s("CommonText.Unit"),price:s("CommonText.SellingPriceExVat"),vat:s("CommonText.VAT-normal")},ue=["service","category","unit","price","vat"],A=async()=>{const t=await n.validateForm();return Object.keys(t).length>0?(_e(n),b(Ge(t,ce,ue)),!1):(b([]),await n.submitForm(),!0)},w=async t=>{t!=null&&t.preventDefault&&t.preventDefault(),await A()},{showModal:L,confirmNavigation:de,cancelNavigation:M,setByPass:O,handleSave:me}=De({isFormDirty:ie,excludedPaths:["/login"],formikErrors:n.errors,onSave:w,onSaveAndNavigate:A}),he=async()=>{{te([]);return}};i.useEffect(()=>{he()},[se]);const ve=async()=>{try{const{data:t}=await y.get(Pe.endPoint());ne(t==null?void 0:t.result)}catch(t){x.error(f(t))}},xe=async()=>{var t,l,o,h,G,R,U,$,K,z,H,W,X,Y;try{const{data:r}=await y.get(Ve.endPoint(d)),q=((t=r==null?void 0:r.result)==null?void 0:t.pricePerUnit)||0,Q=((l=r==null?void 0:r.result)==null?void 0:l.vatPercentage)||25,ye=Math.round(q*(1+Q/100));P(((o=r==null?void 0:r.result)==null?void 0:o.typeId)||""),n.setValues({service:(h=r==null?void 0:r.result)==null?void 0:h.name,category:(G=r==null?void 0:r.result)==null?void 0:G.typeId,subcategory:((R=r==null?void 0:r.result)==null?void 0:R.subCategoryId)||"",price:g(q),sellingPrice:g(ye),unit:(U=r==null?void 0:r.result)==null?void 0:U.unit,vat:Q.toString(),showInJournal:($=r==null?void 0:r.result)==null?void 0:$.showInJournal,journalText:((K=r==null?void 0:r.result)==null?void 0:K.journalText)||"",invoiceText:((z=r==null?void 0:r.result)==null?void 0:z.invoiceText)||"",internalNotes:((H=r==null?void 0:r.result)==null?void 0:H.internalNotes)||"",showTextInJournal:((W=r==null?void 0:r.result)==null?void 0:W.showTextInJournal)!==!1,showTextOnInvoice:((X=r==null?void 0:r.result)==null?void 0:X.showTextOnInvoice)!==!1,allowAutoJournal:((Y=r==null?void 0:r.result)==null?void 0:Y.allowAutoJournal)||!1})}catch(r){x.error(f(r)),m("/inventory-management",{state:{restoreList:!0}})}};i.useEffect(()=>{ve(),xe()},[d]),i.useEffect(()=>{const t=N("service");t.allowed||S(t.errorCode,null,()=>{m("/inventory-management",{replace:!0,state:{restoreList:!0}})})},[N,S,m]);const ge=async()=>{try{const{data:t}=await y.patch(Be.endPoint(d),{status:4});x.success((t==null?void 0:t.message)||s("InventoryManagement.serviceDeleteSuccess")),O(!0),m("/inventory-management",{state:{restoreList:!0}})}catch(t){x.error(f(t))}}
1,pe=()=>{I(!0)},_=()=>{I(!1)},je=e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"secondary",onClick:()=>_(),children:s("commonButton.Close")}),e.jsx(u,{variant:"warning",type:"button",className:"text-white",onClick:()=>ge(),children:s("commonButton.Delete")})]});return e.jsxs(Je,{pageTitle:"Inventory Management",onRestartTour:p.startManually,children:[p.shouldShow&&e.jsx(Ke,{steps:p.steps,onComplete:p.complete,onSkip:p.skip}),e.jsxs("form",{onSubmit:w,children:[e.jsxs("div",{className:"from_wrap",children:[E&&T>=3e5&&e.jsx(Fe,{savedAt:Date.now()-T,onRestore:()=>{const t=F();t!=null&&t.formValues&&n.setValues(t.formValues)},onDiscard:D}),e.jsxs("div",{className:"from_des_block","data-guide":"inventory-service-edit-basics",children:[e.jsxs(c,{className:"align-items-center",children:[e.jsx(v,{children:e.jsx("h6",{className:"mb-3",children:s("inventory.service.editTitle")})}),e.jsx(v,{xs:"auto",children:e.jsx(a.Group,{controlId:"showInJournal",children:e.jsx(a.Check,{type:"checkbox",label:s("CommonText.Show-In-Journal"),name:"showInJournal",checked:n.values.showInJournal,onChange:t=>n.setFieldValue("showInJournal",t.target.checked)})})})]}),e.jsx(c,{children:e.jsxs(a.Group,{className:"mb-3 col-lg-12",children:[e.jsxs(a.Label,{children:[s("inventory.service.serviceName")||"Servicenamn"," ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsx(a.Control,{type:"text",name:"service",maxLength:Re,onChange:n.handleChange,onBlur:n.handleBlur,value:n.values.service,isInvalid:n.touched.service&&!!n.errors.service}),e.jsx(a.Control.Feedback,{type:"invalid",children:n.errors.service})]})}),e.jsxs(c,{children:[e.jsxs(a.Group,{className:"mb-3 col-lg-6",children:[e.jsxs(a.Label,{children:[s("CommonText.Category")," ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsxs(a.Control,{as:"select",name:"category",onChange:t=>{n.handleChange(t),P(t.target.value),n.setFieldValue("subcategory","")},onBlur:n.handleBlur,value:n.values.category||"",isInvalid:n.touched.category&&!!n.errors.category,children:[e.jsx("option",{value:"",children:s("CommonText.Select-Category")}),C==null?void 0:C.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),e.jsx(a.Control.Feedback,{type:"invalid",children:n.errors.category})]}),Le,e.jsxs(a.Group,{className:"mb-3 col-lg-6",children:[e.jsxs(a.Label,{children:[s("CommonText.Unit")," ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsxs(a.Select,{name:"unit",onChange:n.handleChange,onBlur:n.handleBlur,value:n.values.unit||"",isInvalid:n.touched.unit&&!!n.errors.unit,children:[e.jsx("option",{value:"",children:s("CommonText.Select-Unit")}),e.jsx("option",{value:"1",children:s("CommonText.Piece")}),e.jsx("option",{value:"2",children:s("CommonText.Pair")}),e.jsx("option",{value:"3",children:s("CommonText.Hour")})]}),e.jsx(a.Control.Feedback,{type:"invalid",children:n.errors.unit})]})]})]}),e.jsxs("div",{className:"from_des_block","data-guide":"inventory-service-edit-pricing",children:[e.jsx(c,{children:e.jsx(v,{children:e.jsxs("h6",{className:"mb-3",children:[e.jsx("i",{className:"bi bi-calculator me-2"}),s("inventory.group.pricing")]})})}),e.jsxs(c,{children:[e.jsxs(a.Group,{className:"mb-3 col-lg-4",children:[e.jsxs(a.Label,{children:[s("CommonText.SellingPriceExVat")," ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsx(a.Control,{type:"text",name:"price",onChange:ae,onBlur:n.handleBlur,value:n.values.price,isInvalid:n.touched.price&&!!n.errors.price,onKeyPress:t=>{/[0-9,.]/.test(t.key)||t.preventDefault()}}),e.jsx(a.Text,{className:"text-muted",children:s("CommonText.SellingPriceExVatHelp")}),e.jsx(a.Control.Feedback,{type:"invalid",children:n.errors.price})]}),e.jsxs(a.Group,{className:"mb-3 col-lg-4",children:[e.jsxs(a.Label,{children:[s("CommonText.VAT-normal")," ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsx(a.Control,{type:"text",name:"vat",onChange:le,onKeyDown:t=>{t.key==="Backspace"&&n.setFieldValue("vat","")},onBlur:n.handleBlur,value:n.values.vat?`${n.values.vat}%`:"",isInvalid:n.touched.vat&&!!n.errors.vat}),e.jsx(a.Control.Feedback,{type:"invalid",children:n.errors.vat})]}),e.jsxs(a.Group,{className:"mb-3 col-lg-4",children:[e.jsx(a.Label,{children:s("CommonText.SellingPrice")}),e.jsx(a.Control,{type:"text",name:"sellingPrice",onChange:oe,onBlur:n.handleBlur,value:n.values.sellingPrice,onKeyPress:t=>{/[0-9,.]/.test(t.key)||t.preventDefault()},style:{backgroundColor:"#f8f9fa"}}),e.jsx(a.Text,{className:"text-muted",children:s("CommonText.SellingPriceHelp")})]})]}),e.jsx(Ue,{priceExVat:j(n.values.price)||0,vatPercent:n.values.vat||25,purchasePrice:null,showMargin:!1})]}),e.jsxs("div",{className:"from_des_block","data-guide":"inventory-service-edit-texts",children:[e.jsx(c,{children:e.jsx(v,{children:e.jsxs("h6",{className:"mb-3",children:[e.jsx("i",{className:"bi bi-card-text me-2"}),s("inventory.service.textsTitle")]})})}),e.jsxs(c,{children:[e.jsxs(a.Group,{className:"mb-3 col-lg-6",children:[e.jsx(a.Label,{children:s("inventory.service.j
1ournalText")||"Text till journal"}),e.jsx(a.Control,{as:"textarea",rows:3,name:"journalText",onChange:n.handleChange,onBlur:n.handleBlur,value:n.values.journalText,placeholder:s("inventory.service.journalTextPlaceholder")||"Beskrivning som visas i journalen...",maxLength:1e3,disabled:!n.values.showInJournal,style:n.values.showInJournal?{}:{backgroundColor:"#e9ecef",opacity:.7}}),e.jsxs(a.Text,{className:"text-muted",children:[(n.values.journalText||"").length,"/1000 ",s("CommonText.Characters")||"tecken"]}),e.jsx(a.Check,{type:"checkbox",id:"showTextInJournal",label:s("inventory.service.showTextInJournal")||"Visa tjänsttexten i journal",checked:n.values.showTextInJournal,onChange:t=>n.setFieldValue("showTextInJournal",t.target.checked),disabled:!n.values.showInJournal,className:"mt-2",style:n.values.showInJournal?{}:{opacity:.5}})]}),e.jsxs(a.Group,{className:"mb-3 col-lg-6",children:[e.jsx(a.Label,{children:s("inventory.service.invoiceText")||"Text till faktura"}),e.jsx(a.Control,{as:"textarea",rows:3,name:"invoiceText",onChange:n.handleChange,onBlur:n.handleBlur,value:n.values.invoiceText,placeholder:s("inventory.service.invoiceTextPlaceholder")||"Beskrivning som visas på fakturan...",maxLength:500}),e.jsxs(a.Text,{className:"text-muted",children:[(n.values.invoiceText||"").length,"/500 ",s("CommonText.Characters")||"tecken"]}),e.jsx(a.Check,{type:"checkbox",id:"showTextOnInvoice",label:s("inventory.service.showTextOnInvoice")||"Visa tjänsttexten på faktura",checked:n.values.showTextOnInvoice,onChange:t=>n.setFieldValue("showTextOnInvoice",t.target.checked),className:"mt-2"})]}),e.jsxs(a.Group,{className:"mb-3 col-lg-12",children:[e.jsx(a.Label,{children:s("inventory.service.internalNotes")||"Intern notering"}),e.jsx(a.Control,{as:"textarea",rows:2,name:"internalNotes",onChange:n.handleChange,onBlur:n.handleBlur,value:n.values.internalNotes,placeholder:s("inventory.service.internalNotesPlaceholder")||"Endast synlig för dig (t.ex. instruktioner, anteckningar)"})]})]})]}),e.jsxs("div",{className:"from_des_block","data-guide":"inventory-service-edit-auto-journal",children:[e.jsx(c,{children:e.jsx(v,{children:e.jsxs("h6",{className:"mb-3",children:[e.jsx("i",{className:"bi bi-lightning-charge me-2"}),s("inventory.service.autoJournalTitle")||"Automatisk journalföring"]})})}),e.jsx(c,{children:e.jsxs(v,{xs:12,children:[e.jsx(a.Check,{type:"switch",id:"allowAutoJournal",label:e.jsxs("span",{children:[e.jsx("i",{className:"bi bi-lightning-charge me-2"}),s("inventory.service.allowAutoJournal")||"Tillåt automatisk journalföring"]}),checked:n.values.allowAutoJournal,onChange:t=>n.setFieldValue("allowAutoJournal",t.target.checked),className:"mb-2"}),e.jsx(a.Text,{className:"text-muted d-block mb-3",children:s("inventory.service.allowAutoJournalDescription")||"När aktiverad kan journaler skapas automatiskt från en mall när bokningar påbörjas."}),n.values.allowAutoJournal&&e.jsxs("div",{className:"alert alert-info d-flex align-items-center",children:[e.jsx("i",{className:"bi bi-info-circle me-2"}),e.jsxs("span",{children:[s("inventory.service.templateManagementInfo")||"Efter att du sparat kan du hantera journalmallen för denna tjänst."," ",e.jsx(Ne,{to:`/inventory-management/service/${d}/template-management`,children:s("inventory.service.goToTemplateManagement")||"Gå till mallhantering"})]})]})]})})]}),e.jsx("div",{className:"from_des_block",children:e.jsx(Me,{type:"service",name:n.values.service,price:j(n.values.price)||0,journalText:n.values.journalText,invoiceText:n.values.invoiceText})})]}),e.jsxs("div",{className:"form-action-buttons-container","data-guide":"inventory-service-edit-actions",children:[e.jsx("div",{className:"form-action-buttons-left",children:e.jsx(u,{className:"form-action-btn-cancel",onClick:()=>{window.history.back()},children:s("commonButton.Cancel")})}),e.jsxs("div",{className:"form-action-buttons-right",children:[e.jsxs(u,{className:"form-action-btn-danger",onClick:()=>pe(),children:[e.jsx("i",{className:"bi bi-trash3 me-2"}),s("commonButton.Delete")]}),e.jsx(u,{className:"form-action-btn-primary",onClick:w,disabled:n.isSubmitting,children:n.isSubmitting?e.jsxs(e.Fragment,{children:[e.jsx(Se,{animation:"border",size:"sm",className:"me-2"}),s("CommonText.Saving")||"Sparar..."]}):s("commonButton.Update")||"Uppdatera"})]})]})]}),e.jsx(Z,{id:"emailModal",title:s("DeletePopup.Delete-this-item"),isOpen:ee,onClose:_,footerButtons:je,children:e.jsx("div",{children:e.jsx("p",{children:s("CommonText.Delete-Item")})})}),L&&e.jsx(Z,{id:"navigationConfirmModal",isOpen:L,onClose:M,footerButtons:e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"warning",className:"text-white",onClick:me,children:s("commonButton.Save")}),e.jsx(u,{variant:"secondary",onClick:M,children:s("commonButton.Cancel")}),e.jsx(u,{variant:"danger",onClick:de,children:s("commonButton.Discard")})]}),children:e.jsx("p",{children:s("CommonText.leave-this-page")})}),e.jsx(Oe,{isOpen:k.length>0,onClose:()=>b([]),errors:k})]})};export{fn 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.