1import{a6 as G,aG as L,i as E,aH as j,a7 as N,a8 as h,a9 as _,bk as B,aI as U,aJ as H,aq as P,e as R,K as W,g as K,Q as s,S as d,x as C,U as o,W as b,X as c,k as v,Z as p,$ as X,a0 as z,aM as J,aN as Y,a1 as Z,ba as ee,aX as te,a2 as ie,a3 as re,a4 as ne,a5 as se,bl as oe,bm as de,at as le,au as ae,ac as u,aa as O,ad as w,am as S,ae as T,ab as D,an as f,ao as g,j as F,Y as x,aV as ce,aW as ue,h as I,aw as q,aP as V}from"./index-BGzvIKro.js";import{I as me}from"./item.store-C4KQbsBp.js";import{S as _e}from"./school.store-BkyTa5pb.js";import{U as he}from"./user.store-C0-klb0z.js";import{O as pe}from"./order.store-D4SeBP45.js";var k;const M=(r,t)=>t.id,y=(r,t)=>({"is-invalid":r,"is-valid":t});function fe(r,t){if(r&1&&(s(0,"option",14),d(1),o()),r&2){const e=u().$implicit;v("value",e.id),c(),T(e.name)}}function ge(r,t){if(r&1&&b(0,fe,2,2,"option",14),r&2){const e=t.$implicit;p(e.role!=="admin"?0:-1)}}function Ce(r,t){r&1&&(s(0,"p"),d(1,"Caithfear cliant a rognú."),o())}function be(r,t){if(r&1){const e=S();s(0,"div",4)(1,"label",9),d(2,"Client"),o(),s(3,"span",10),d(4,"*"),o(),s(5,"select",11),C("change",function(n){f(e);const a=u(2);return g(a.selectClient(n))}),s(6,"option",12),d(7,"Roghnaigh cliant"),o(),O(8,ge,1,1,null,null,M),o(),s(10,"div",13),b(11,Ce,2,0,"p"),o()()}if(r&2){let e;const i=u(2);c(5),F(x(3,y,(i.clientId==null?null:i.clientId.invalid)&&((i.clientId==null?null:i.clientId.dirty)||(i.clientId==null?null:i.clientId.touched)),(i.clientId==null?null:i.clientId.valid)&&((i.clientId==null?null:i.clientId.dirty)||(i.clientId==null?null:i.clientId.touched)))),c(3),w(i.userStore.items()),c(3),p(!((e=i.editForm.get("clientId"))==null||e.errors==null)&&e.errors.required?11:-1)}}function ve(r,t){r&1&&d(0," Tá ÃirChód ag teastáil. ")}function Ie(r,t){if(r&1&&d(0),r&2){let e;const i=u().$implicit;q(" Eircode must be atleast ",(e=i.get("eirCode"))==null||e.errors==null||e.errors.minlength==null?null:e.errors.minlength.requiredLength," characters long. ")}}function Fe(r,t){if(r&1&&d(0),r&2){let e;const i=u().$implicit;q(" Eircode cannot be more than ",(e=i.get("eirCode"))==null||e.errors==null||e.errors.maxlength==null?null:e.errors.maxlength.requiredLength," characters long. ")}}function xe(r,t){if(r&1&&(s(0,"div",32),I(1,"input",33),s(2,"label",34),d(3," Are you want to add this address in school? "),o()()),r&2){const e=u().$index;c(),V("id",e),c(),V("for",e)}}function ye(r,t){if(r&1){const e=S();s(0,"div",16)(1,"div",17)(2,"div",18)(3,"div",19)(4,"input",20),C("change",function(n){const a=f(e).$implicit,m=u(3);return g(m.checked(n,a))}),o()(),s(5,"div",21)(6,"div",22),I(7,"input",23),s(8,"div",13),d(9,"Tá seoladh riachtanach."),o()(),s(10,"div",22),I(11,"input",24),s(12,"div",13),d(13,"Tá seoladh riachtanach."),o()(),s(14,"div",22),I(15,"input",25),s(16,"div",13),d(17,"Tá seoladh riachtanach."),o()(),s(18,"div",18)(19,"div",26)(20,"span",27),I(21,"input",28),s(22,"div",13),b(23,ve,1,0)(24,Ie,1,1)(25,Fe,1,1),o()(),s(26,"div",29),I(27,"input",30),s(28,"label",31),d(29," Seoladh baile "),o()()()(),b(30,xe,4,2,"div",32),o()()()()}if(r&2){let e,i,n,a,m;const l=t.$implicit,$=t.$index,Q=u(3);v("formGroupName",$),c(4),v("checked",Q.isAddressSelected(l.value.index)),c(3),F(x(12,y,((e=l.get("firstAddress"))==null?null:e.invalid)&&(((e=l.get("firstAddress"))==null?null:e.dirty)||((e=l.get("firstAddress"))==null?null:e.touched)),((e=l.get("firstAddress"))==null?null:e.valid)&&(((e=l.get("firstAddress"))==null?null:e.dirty)||((e=l.get("firstAddress"))==null?null:e.touched)))),c(4),F(x(15,y,((i=l.get("secondAddress"))==null?null:i.invalid)&&(((i=l.get("secondAddress"))==null?null:i.dirty)||((i=l.get("secondAddress"))==null?null:i.touched)),((i=l.get("secondAddress"))==null?null:i.valid)&&(((i=l.get("secondAddress"))==null?null:i.dirty)||((i=l.get("secondAddress"))==null?null:i.touched)))),c(4),F(x(18,y,((n=l.get("thirdAddress"))==null?null:n.invalid)&&(((n=l.get("thirdAddress"))==null?null:n.dirty)||((n=l.get("thirdAddress"))==null?null:n.touched)),((n=l.get("thirdAddress"))==null?null:n.valid)&&(((n=l.get("thirdAddress"))==null?null:n.dirty)||((n=l.get("thirdAddress"))==null?null:n.touched))
1)),c(6),F(x(21,y,((a=l.get("eirCode"))==null?null:a.invalid)&&(((a=l.get("eirCode"))==null?null:a.dirty)||((a=l.get("eirCode"))==null?null:a.touched)),((a=l.get("eirCode"))==null?null:a.valid)&&(((a=l.get("eirCode"))==null?null:a.dirty)||((a=l.get("eirCode"))==null?null:a.touched)))),c(2),p(!((m=l.get("eirCode"))==null||m.errors==null)&&m.errors.required?23:!((m=l.get("eirCode"))==null||m.errors==null)&&m.errors.minlength?24:!((m=l.get("eirCode"))==null||m.errors==null)&&m.errors.maxlength?25:-1),c(7),p(l.get("isChecked")?30:-1)}}function Ae(r,t){if(r&1&&(ce(0,8),s(1,"label",15),d(2," Seoladh "),o(),s(3,"span",10),d(4,"*"),o(),O(5,ye,31,24,"div",16,D),ue()),r&2){const e=u(2);c(5),w(e.addresses.controls)}}function Se(r,t){if(r&1&&b(0,be,12,6,"div",4)(1,Ae,7,0,"ng-container",8),r&2){let e;const i=u();p(((e=i.authStore.currentUser())==null?null:e.role)===i.constantVariables.fixedRoles[0].userType?0:-1),c(),p(i.addresses.length?1:-1)}}function Ee(r,t){if(r&1){const e=S();s(0,"tr")(1,"td")(2,"input",38),C("change",function(n){const a=f(e).$implicit,m=u(3);return g(m.selectItem(n,a))}),o()(),s(3,"td"),d(4),o(),s(5,"td"),d(6),o(),s(7,"td")(8,"input",39,0),C("keydown",function(n){f(e);const a=u(3);return g(a.restrictInputToNumeric(n))})("input",function(n){const a=f(e).$implicit,m=u(3);return g(m.enterQty(n,a.id))}),o()()()}if(r&2){const e=t.$implicit,i=u(3);c(2),v("checked",i.isItemSelected(e.id)),c(2),T(e.itemName),c(2),T(e.itemQuantity),c(2),F(x(7,y,i.touchedInputs[e.id]&&!i.inputValues[e.id],i.touchedInputs[e.id]&&i.inputValues[e.id])),v("disabled",!i.touchedInputs[e.id]&&!i.inputValues[e.id])("value",i.inputValues[e.id]||"")}}function ke(r,t){if(r&1&&(s(0,"label",35),d(1," MÃreanna "),o(),s(2,"span",10),d(3,"*"),o(),s(4,"table",36)(5,"thead")(6,"tr")(7,"th",37),d(8,"#"),o(),s(9,"th",37),d(10," Ainm na mÃre "),o(),s(11,"th",37),d(12," Stoc "),o(),s(13,"th",37),d(14," Luach "),o()()(),s(15,"tbody"),O(16,Ee,10,10,"tr",null,M),o()()),r&2){const e=u(2);c(16),w(e.filterItems)}}function Te(r,t){r&1&&(s(0,"div")(1,"p",40),d(2," No item found "),o()())}function Oe(r,t){if(r&1&&b(0,ke,18,0)(1,Te,3,0,"div"),r&2){const e=u();p(e.filterItems&&e.filterItems.length?0:1)}}function we(r,t){if(r&1&&(s(0,"li"),d(1),o()),r&2){const e=t.$implicit;c(),T(e)}}function Ne(r,t){if(r&1&&(s(0,"div",6),O(1,we,2,1,"li",null,D),o()),r&2){const e=u();c(),w(e.errorMessages)}}function Ve(r,t){if(r&1){const e=S();s(0,"button",41),C("click",function(){f(e);const n=u();return g(n.closeEdit())}),s(1,"label"),d(2,"Dún"),o()(),s(3,"button",42),C("click",function(){f(e);const n=u();return g(n.next())}),d(4,"Ar lean"),o()}if(r&2){let e;const i=u();c(3),v("disabled",((e=i.editForm.get("clientId"))==null?null:e.invalid)||((e=i.editForm.get("schoolName"))==null?null:e.invalid)||i.checkValiditiy())}}function De(r,t){if(r&1){const e=S();s(0,"button",41),C("click",function(){f(e);const n=u();return g(n.back())}),d(1,"Previous"),o(),s(2,"button",43),C("click",function(){f(e);const n=u();return g(n.onSubmit())}),d(3," Update Order "),o()}if(r&2){const e=u();c(2),v("disabled",e.isSubmitBtnDisable())}}const Le={title:"Edit",canActivate:[()=>!0],providers:[]};class A extends G{constructor(){super(...arguments),this.close=new L,this.orderStore=E(pe),this.userStore=E(he),this.schoolStore=E(_e),this.itemStore=E(me),this.action=j("action"),this.errorMessages=[],this.step=1,this.enterValue=1,this.filterItems=[],this.selectedItems=[],this.inputValues={},this.currentData={},this.selectedAddress=[],this.touchedInputs={},k.set(this,""),this.editForm=new N({clientId:new h("",[_.required,_.minLength(1)]),schoolName:new h("",[_.required,_.minLength(1)]),addresses:new B([]),items:new h([],[_.required]),orderNumber:new h([],[_.required])})}updateFormdata(t){this.editForm.patchValue({clientId:t.clientId||"",orderNumber:t.orderNumber||null,items:t.items||[],deliverAddress:this.currentData.deliverAddress}),this.selectedAddress=this.currentData.addresses,this.selectedItems=this.currentData.items,this.patchFormArray(this.addresses,t.addresses||[]),this.getFilterItem(t.clientId),this.selectedItems&&this.selectedItems.length&&this.selectedItems.map(e=>{this.inputValues[e.id]=e.requestQuantity}),console.log("this.currentData",this.currentData)}get id(){return U(this,k,"f")}set id(t){H(this,k,t,"f"),this.id&&(this.currentData=this.orderStore.get(this.id
1),this.currentData&&this.updateFormdata(this.currentData))}get clientId(){return this.editForm.get("clientId")}get schoolName(){return this.editForm.get("schoolName")}get orderNumber(){return this.editForm.get("orderNumber")}get addresses(){return this.editForm.get("addresses")}ngOnInit(){this.editForm.valueChanges.subscribe(()=>{this.clearErrorMessages(this.editForm),this.errorMessages=[]}),this.itemStore.items().length||this.subscribeToData(this.itemStore),this.userStore.items().length||this.subscribeToData(this.userStore),this.schoolStore.items().length||this.subscribeToData(this.schoolStore)}selectClient(t){t&&t.target.value&&this.getFilterItem(t.target.value)}getFilterItem(t){this.itemStore.items().length&&(this.filterItems=this.itemStore.items().filter(e=>e.createdBy===t),console.log(this.filterItems))}selectSchool(t){this.addresses.clear();const e=this.schoolStore.get(t.target.value);this.patchFormArray(this.addresses,e?.addresses||[])}patchFormArray(t,e=[]){t.clear(),e.forEach(i=>{const n=this.createFormGroup(i);t.push(n)})}createFormGroup(t){const e={},i=["firstAddress","secondAddress","thirdAddress","eirCode"];return i.forEach(n=>{n==="eirCode"?e[n]=new h({value:t[n]||"",disabled:!0},[_.required,_.minLength(7),_.maxLength(7)]):e[n]=new h({value:t[n]||"",disabled:!0},[_.required])}),Object.keys(t).forEach(n=>{i.includes(n)||(e[n]=new h({value:t[n]||"",disabled:!0}))}),new N(e)}closeEdit(){this.editForm.reset(),this.close.emit()}onSubmit(){if(this.editForm.invalid){this.focusFirstInvalidField(this.editForm),this.errorMessages=this.getFormErrors(this.editForm);return}const t={...this.editForm.value,clientId:this.editForm.value.clientId?`parent::/Clients/${this.editForm.value.clientId}`:"",schoolName:this.editForm.value.schoolName?`parent::/Schools/${this.editForm.value.schoolName}`:"",addresses:this.selectedAddress,modifiedBy:this.authStore.currentUser()?.id,deliverAddress:this.currentData.deliverAddress};console.log("*******order form",t),this.orderStore.update(this.id,t).subscribe(()=>{this.orderStore.isSuccess()?(this.toastService.showToastMsg("D'éirigh le hordú a nuashonrú.","","success"),this.editForm.reset(),this.close.emit()):this.orderStore.error()&&this.toastService.showToastMsg(this.orderStore.error(),"","danger")})}addAddress(){const t=new N({firstAddress:new h("",[_.required]),secondAddress:new h("",[_.required]),thirdAddress:new h("",[_.required]),eirCode:new h("",[_.required,_.minLength(7),_.maxLength(7)]),isHomeAddress:new h(!1,[_.required]),isChecked:new h(!1)});this.addresses.push(t)}checkValiditiy(){return this.editForm.get("addresses").invalid}removeAddress(t){this.addresses.removeAt(t)}
1next(){this.step=2}back(){this.step=1,this.editForm.get("items")?.patchValue([]),this.touchedInputs={}}enterQty(t,e){const i=t.target,n=Number(i.value);this.inputValues[e]=i.value,this.touchedInputs[e]=!0,this.enterValue=n,this.errorMessages=[];const a=this.selectedItems.find(m=>m.id===e);a?a.requestQuantity=n:console.log(`Item with id ${e} not found in selectedItems.`),console.log("this.selectedItems",this.selectedItems),this.editForm.get("items")?.setValue(this.selectedItems)}selectItem(t,e){const i=t.target.checked,n=e.id;this.touchedInputs[e.id]=i;const a={id:e.id,itemName:e.itemName,avlQuantity:e.itemQuantity,requestQuantity:this.getValidQuantity(this.enterValue)};this.updateInputValues(n,a.requestQuantity),this.updateSelectedItems(a,i),this.updateFormValue(),this.editForm.get("items")?.setValue(this.selectedItems),console.log("this.selectedItems ",this.selectedItems)}getValidQuantity(t){return t===0?1:t}updateInputValues(t,e){this.inputValues[t]=e}updateFormValue(){console.log("this.selectedItems",this.selectedItems),this.editForm.get("items")?.setValue(this.selectedItems)}updateSelectedItems(t,e){const i=this.selectedItems.findIndex(n=>n.id===t.id);e&&i===-1?this.selectedItems.push(t):!e&&i!==-1&&(this.selectedItems.splice(i,1),this.inputValues[t.id]="",this.enterValue=1)}isItemSelected(t){return this.selectedItems.find(e=>e.id===t)}resetInputValue(t){this.inputValues[t]=""}checked(t,e){t.target.checked&&(e.value.isSelected=!0,this.selectedAddress.push(e.value)),console.log("selectedAddress",this.selectedAddress)}isAddressSelected(t){const e=t||0;return this.currentData.deliverAddress.index===e}isSubmitBtnDisable(){return!!this.selectedItems.find(e=>!e.requestQuantity)}}k=new WeakMap;A.ɵfac=(()=>{let r;return function(e){return(r||(r=P(A)))(e||A)}})();A.ɵcmp=R({type:A,selectors:[["arc-edit-order"]],inputs:{action:[1,"action"],id:"id"},outputs:{close:"close"},standalone:!0,features:[W,K],decls:14,vars:4,consts:[["quantvalue",""],[1,"arc_order_edit"],[1,"container"],[1,"centered-form","rounded",3,"formGroup"],[1,"mb-4"],[1,"cursor","text-primary","float-end",3,"click"],[1,"alert","alert-danger","mt-2"],[1,"mb-4","d-grid","gap-2","d-md-flex","justify-content-between"],["formArrayName","addresses"],["for","clientId",1,"form-label","fw-bold"],[1,"mandatory"],["formControlName","clientId","id","clientId",1,"form-select",3,"change"],["value","","disabled","","selected",""],[1,"invalid-feedback"],[3,"value"],["for","firstAddress",1,"form-label","fw-bold"],[1,"card","mb-4",3,"formGroupName"],[1,"card-body"],[1,"row"],[1,"col-1","m-0","pe-0","d-flex","justify-content-center","align-items-center"],["type","checkbox","disabled","","name","address",1,"form-check-input","border","border-primary",3,"change","checked"],[1,"col-11","m-0"],[1,"mb-1"],["type","text","placeholder","ScrÃobh Seoladh 1","formControlName","firstAddress","id","firstAddress",1,"form-control"],["type","text","placeholder","ScrÃobh Seoladh 2","formControlName","secondAddress","id","secondAddress",1,"form-control"],["type","text","placeholder","ScrÃobh Seoladh 3","formControlName","thirdAddress","id","thirdAddress",1,"form-control"],[1,"col-8","mb-0","d-flex","align-items-start","justify-content-between"],[2,"width","50%"],["type","text","placeholder","Ãirchód","formControlName","eirCode","id","eirCode",1,"form-control"],[1,"form-check","d-flex","align-items-start",2,"margin-top","7px"],["type","checkbox","id","isHomeAddress","formControlName","isHomeAddress",1,"form-check-input","me-2"],["for","isHomeAddress",1,"form-check-label"],[1,"form-check","form-check-inline","mt-3"],["type","checkbox","formControlName","isChecked",1,"form-check-input","me-2",3,"value","id"],[1,"form-check-label",3,"for"],[1,"fw-bold","form-label"],[1,"table","table-striped","table-borderless","align-middle","mt-3"],["scope","col",1,"text-secondary","text-nowrap"],["type","checkbox",1,"form-check-input","border","border-primary","mt-2",3,"change","checked"],["type","number","placeholder","Stoc",1,"form-control",3,"keydown","input","disabled","value"],[1,"mt-4","mb-4","d-flex","justify-content-center"],["type","button",1,"btn","btn-light","btn-sm",3,"click"],["type","button",1,"btn","btn-primary","btn-sm",3,"click","disabled"],["type","submit",1,"btn","btn-primary","btn-sm","ms-2",3,"click","disabled"]],template:function(t,e){t&1&&(s(0,"div",1)(1,"div",2)(2,"form",3)(3,"div",4)(4,"h5"),d(5," Update orders "),s(6,"mat-icon",5),C("click",function(){return e.closeEdit()}),d(7,"close"),o()()(),b(8,Se,2,2)(9,Oe,2,1)(10,Ne,3,0,"div",6),s(11,"div",7),b(12,Ve,5,1)(13,De,4,1),o()()()()),t&2&&(c(2),v("formGroup",e.editForm),c(6),p(e.step===1?8:9),c(2),p(e.errorMessages&&e.errorMessages.length?10:-1),c(2),p(e.step===1?12:13))},dependencies:[X,z,J,Y,Z,ee,te,ie,re,ne,se,oe,de,le,ae],changeDetection:0});export{A as default,Le as routeMeta};
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.