quoteCalculator.service("dataService",function(uiService,ajaxService,restructureService,childTableService,instantiateService,apiService){this.initiateScopeDataStructureFunctions=function($scope,$compile){$scope.RefreshApiQuoteData=function(){ajaxService.getRequest("optimised/quote/data/"+$scope.ApiQuote.id+"/"+$scope.userType,{},function(response){$scope.IndexChoices(response),$scope.$digest()})},$scope.SelectionChangedWithAjaxHandle=function(event,option,fieldName,sendFieldName){$scope.HandleSpecialCases(fieldName,option),$scope.ChangeParentValue(event,option,fieldName),"5-Print Size"==fieldName&&48!=option.ChoiceValueId&&($scope.ClearCustomPrintSize(option.ChoiceValueId),$scope.customSizeError="");var postData,event="Input changed by "+$scope.userType+" user.",oldValue=$scope.IndexedChoiceData[fieldName].selected?$scope.IndexedChoiceData[fieldName].selected.ChoiceValueId:0;-1==oldValue&&(oldValue=0),postData=sendFieldName?{quoteId:$scope.ApiQuote.id,field:sendFieldName,quoteFieldName:sendFieldName,oldValue:oldValue,newValue:option.ChoiceValueId,note:event}:{quoteId:$scope.ApiQuote.id,field:sendFieldName,quoteFieldName:fieldName,oldValue:oldValue,newValue:option.ChoiceValueId,note:event},$scope.IndexedChoiceData[fieldName].selected=option,$scope.IndexedChoiceData[fieldName].displayed=option,postData.oldValue!==postData.newValue?"5-Print Size"==fieldName&&48!=option.ChoiceValueId||apiService.QuoteTableUpdate(postData).then(function(){"8-Binding"==postData.fieldName&&$scope.RefreshInterface(8,$scope.ApiQuote.id)}):"8-Binding"==fieldName&&$scope.RefreshInterface(8,$scope.ApiQuote.id),"5-Print Size"==fieldName&&$scope.sizeChanged(),"7-Material"==fieldName&&$scope.materialChanged()},$scope.HandleSpecialCases=function(fieldName,option){"22-Print Colour Front"==fieldName&&$scope.printColourChanged(option.ChoiceValueId,fieldName),"22-Print Colour Back"==fieldName&&$scope.printColourChanged(option.ChoiceValueId,fieldName)},$scope.RefreshInterface=function(interfaceId,quoteId){-1<[46].indexOf(interfaceId)||ajaxService.getRequest("quote/data/"+quoteId+"/interface/"+interfaceId,{interface:interfaceId},function(response,httpCode,optionalData){restructureService.parseQuoteDataArray(response,$scope),$scope.setChangedTabs($scope),$scope.handleBindingUpdate(response,interfaceId),$scope.$digest()})},$scope.handleBindingUpdate=function(response,interfaceId){if(8==interfaceId){let removeBinding=!0;response.forEach(function(row){"FinishingOptionId"==row.boundFieldName&&(removeBinding=!1)}),removeBinding&&delete $scope.IndexedChoiceData["8-Binding - Wiro Colour Option"]}},$scope.ChangeParentValue=function(event,option,fieldName){"7-Material"==fieldName&&($scope.IndexedChoiceData["7-Material Type"].displayed=$scope.IndexedChoiceData["7-Material Type"].selected)},$scope.DemoSelectionChanged=function(event,option,fieldName){$scope.IndexedChoiceData[fieldName].selected=option,$scope.IndexedChoiceData[fieldName].displayed=option},$scope.materialTypeChanged=function(option){if($scope.IndexedChoiceData["7-Material Type"].selected=option,$scope.IndexedChoiceData["7-Material Type"].displayed=option,$scope.IndexedChoiceData["7-Material Type"]&&$scope.IndexedChoiceData["7-Material Type"].selected&&$scope.IndexedChoiceData["7-Material Type"].selected.ChoiceValueString){let initialMaterialCategoryId=null;try{initialMaterialCategoryId=parseInt($scope.IndexedChoiceData["7-Material Type"].selected.ChoiceFurtherInformation)}catch(e){}var options=$scope.IndexedChoiceData["7-Material"].filter(function(f){return f.ChoiceParentId==option.ChoiceValueId});$scope.selectMatchingMaterialWeight(options,initialMaterialCategoryId,option.ChoiceValueId),$scope.validateDieCutting()}},$scope.SelectionChangedHandle=function(event,option,fieldName,indexName){"PrintSizeGroupId"==fieldName&&($scope.CustomSizeValues.width="",$scope.CustomSizeValues.height="");var childFieldName=$scope.LookupChildFieldName(fieldName),fieldName=($scope.IndexedChoiceData[indexName].selected=option,$scope.IndexedChoiceData[indexName].displayed=option,"choice/"+$scope.ApiQuote.id+"/"+option.ChoiceValueId+"/"+childFieldName);optionalData={url:fieldName,productId:productId,quoteId:$scope.ApiQuote.id,userType:$scope.userType,fieldName:childFieldName},ajaxService.getRequest(fieldName,optionalData,function(response,httpCode,optionalData){if(console.log(response),"ProductStyleId"==optionalData.fieldName){for(var i=0;i<response.length;i++)response[i].previewImageFile||(response[i].previewImageFile=response[i].choiceImageFile.replaceAll(" ","%20"));$scope.ProductStyles=restructureService.standardiseCapitalisation(response)}else if("ProductStyleShapeId"==optionalData.fieldName){for(var selected=$scope.IndexedChoiceData["81-Product Shapes"].selected,displayed=$scope.IndexedChoiceData["81-Product Shapes"].displayed,i=0;i<response.length;i++)response[i].previewImageFile||(response[i].previewImageFile=response[i].choiceImageFile.replaceAll(" ","%20"));response=restructureService.standardiseCapitalisation(response),$scope.IndexedChoiceData["81-Product Shapes"]=response,$scope.IndexedChoiceData["81-Product Shapes"].selected=selected,$scope.IndexedChoiceData["81-Product Shapes"].displayed=displayed}else if("ReadymadeArtworkId"==optionalData.fieldName){for(i=0;i<response.length;i++)response[i].previewImageFile||(response[i].previewImageFile=response[i].choiceImageFile.replaceAll(" ","%20"));$scope.IndexedChoiceData["70-Readymade Artwork"]=response}else if("HardwareId"==optionalData.fieldName){for(selected=$scope.IndexedChoiceData["4-Hardware"].selected,displayed=$scope.IndexedChoiceData["4-Hardware"].displayed,i=0;i<response.length;i++)response[i].ChoiceDisplayName=response[i].choiceDisplayName,response[i].ChoiceDeliveryDaysAdjustment=response[i].choiceDeliveryDaysAdjustment,response[i].ChoicePriceAdjustmentNet=response[i].choicePriceAdjustmentNet,response[i].ChoiceValueId=response[i].choiceValueId;1==($scope.IndexedChoiceData["4-Hardware"]=response).length?($scope.IndexedChoiceData["4-Hardware"].selected=response[0],$scope.IndexedChoiceData["4-Hardware"].displayed=response[0],$scope.SendQuoteUpdate($scope.ApiQuote.id,"HardwareId",0,response[0].ChoiceValueId,"Hardware category with only one option selected")):($scope.IndexedChoiceData["4-Hardware"].selected=selected,$scope.IndexedChoiceData["4-Hardware"].displayed=new ChoiceObject($scope.ApiQuote.id,-1,"Select an option"))}else{var childIndexName=$scope.LookupChildIndexName(optionalData.fieldName),selected=$scope.IndexedChoiceData[childIndexName].selected;$scope.IndexedChoiceData[childIndexName]=[];for(i=0;i<response.length;i++)response[i].ChoiceDisplayName=response[i].choiceDisplayName,response[i].ChoiceDeliveryDaysAdjustment=response[i].choiceDeliveryDaysAdjustment,response[i].ChoicePriceAdjustmentNet=response[i].choicePriceAdjustmentNet,response[i].ChoiceValueId=response[i].choiceValueId,response[i].choiceDescription&&(response[i].ChoiceDescription=response[i].choiceDescription),$scope.IndexedChoiceData[childIndexName].push(response[i]);$scope.IndexedChoiceData[childIndexName].selected=selected;for(var parentCategoryContainsSelected=!1,i=0;i<response.length;i++)try{response[i].ChoiceValueId==$scope.IndexedChoiceData[childIndexName].selected.ChoiceValueId&&(parentCategoryContainsSelected=!0)}catch(e){}1<$scope.IndexedChoiceData[childIndexName].length?$scope.IndexedChoiceData[childIndexName].displayed=parentCategoryContainsSelected?selected:{ChoiceDisplayName:"Select an option"}:0<response.length?($scope.IndexedChoiceData[childIndexName].displayed=response[0],$scope.IndexedChoiceData[childIndexName].selected=response[0],$scope.SelectionChangedWithAjaxHandle({},$scope.IndexedChoiceData[childIndexName].displayed,childIndexName,childFieldName)):console.error("Empty response sent from choice API")}$scope.$digest()})},$scope.boardMaterialCategories=[1,2],$scope.selectMatchingMaterialWeight=function(options,initialMaterialCategoryId,materialTypeId){var currentWeight=$scope.getCurrentMaterialWeight(),currentThickness=$scope.getCurrentMaterialThickness(),materialCategoryId=$scope.getMaterialCategoryId();let currentBoard=!1,initialBoard=(-1<$scope.boardMaterialCategories.indexOf(materialCategoryId)&&(currentBoard=!0),!1);if(-1<$scope.boardMaterialCategories.indexOf(initialMaterialCategoryId)&&(initialBoard=!0),currentBoard&&initialBoard){let smallestDistanceFromThickness=null,smallestDistanceIndex=null;for(let i=0;i<options.length;i++){var thickness=$scope.getMaterialThickness(options[i]),thickness=Math.abs(currentThickness-thickness);(null==smallestDistanceFromThickness||smallestDistanceFromThickness>thickness)&&(smallestDistanceIndex=i,smallestDistanceFromThickness=thickness)}0!==smallestDistanceFromThickness&&$scope.warnAboutMaterialWeightChange(),$scope.setMaterialOptionBySmallestDistanceIndex(options,smallestDistanceIndex,materialTypeId)}else if(currentBoard||initialBoard)$scope.warnAboutMaterialWeightChange(),$scope.setMaterialOptionBySmallestDistanceIndex(options,0,materialTypeId);else{let smallestDistanceFromWeight=null,smallestDistanceIndex=null;for(let i=0;i<options.length;i++){var weight=$scope.getMaterialWeight(options[i]),weight=Math.abs(currentWeight-weight);(null==smallestDistanceFromWeight||smallestDistanceFromWeight>weight)&&(smallestDistanceIndex=i,smallestDistanceFromWeight=weight)}0!==smallestDistanceFromWeight&&$scope.warnAboutMaterialWeightChange(),$scope.setMaterialOptionBySmallestDistanceIndex(options,smallestDistanceIndex,materialTypeId)}},$scope.setMaterialOptionBySmallestDistanceIndex=function(options,smallestDistanceIndex,materialTypeId){if(options[smallestDistanceIndex]){$scope.IndexedChoiceData["7-Material"].selected=new ChoiceObject($scope.ApiQuote.id,options[smallestDistanceIndex].ChoiceValueId,options[smallestDistanceIndex].ChoiceDisplayName),$scope.IndexedChoiceData["7-Material"].selected.ChoiceFurtherInformation=options[smallestDistanceIndex].ChoiceFurtherInformation,$scope.IndexedChoiceData["7-Material"].selected.choiceFurtherInformation=options[smallestDistanceIndex].choiceFurtherInformation,$scope.IndexedChoiceData["7-Material"].selected.ChoiceDescription=options[smallestDistanceIndex].choiceDescription,$scope.IndexedChoiceData["7-Material"].selected.Note=options[smallestDistanceIndex].Note,$scope.IndexedChoiceData["7-Material"].displayed=new ChoiceObject($scope.ApiQuote.id,options[smallestDistanceIndex].ChoiceValueId,options[smallestDistanceIndex].ChoiceDisplayName),$scope.IndexedChoiceData["7-Material"].displayed.ChoiceFurtherInformation=options[smallestDistanceIndex].ChoiceFurtherInformation,$scope.IndexedChoiceData["7-Material"].displayed.choiceFurtherInformation=options[smallestDistanceIndex].choiceFurtherInformation,$scope.IndexedChoiceData["7-Material"].displayed.ChoiceDescription=options[smallestDistanceIndex].choiceDescription;let selectedMaterialId=options[smallestDistanceIndex].ChoiceValueId,relevantMaps=(options[smallestDistanceIndex].choiceValueId&&(selectedMaterialId=options[smallestDistanceIndex].choiceValueId),$scope.IndexedChoiceData["7-Material Option maps"].filter(function(f){return f.MaterialId==selectedMaterialId}).sort(function(a,b){return a.DisplayOrder>b.DisplayOrder?1:a.DisplayOrder<b.DisplayOrder?-1:0})),choices=[],materialOptions=$scope.IndexedChoiceData["7-Material Option"];relevantMaps.forEach(function(map){var o=materialOptions.find(function(f){return f.ChoiceValueId==map.MaterialOptionId});o&&choices.push(o)}),choices.length?(options[smallestDistanceIndex].choiceValueId?$scope.SendBulkQuoteUpdate($scope.ApiQuote.id,[{field:"MaterialId",oldValue:null,newValue:options[smallestDistanceIndex].choiceValueId},{field:"MaterialOptionId",oldValue:null,newValue:choices[0].ChoiceValueId},{field:"MaterialTypeId",oldValue:null,newValue:materialTypeId}]):$scope.SendBulkQuoteUpdate($scope.ApiQuote.id,[{field:"MaterialId",oldValue:null,newValue:options[smallestDistanceIndex].ChoiceValueId},{field:"MaterialOptionId",oldValue:null,newValue:choices[0].ChoiceValueId},{field:"MaterialTypeId",oldValue:null,newValue:materialTypeId}]),$scope.IndexedChoiceData["7-Material Option"].selected=choices[0],$scope.IndexedChoiceData["7-Material Option"].displayed=choices[0]):options[smallestDistanceIndex].choiceValueId?$scope.SendBulkQuoteUpdate($scope.ApiQuote.id,[{field:"MaterialId",oldValue:null,newValue:options[smallestDistanceIndex].choiceValueId},{field:"MaterialTypeId",oldValue:null,newValue:materialTypeId}]):$scope.SendBulkQuoteUpdate($scope.ApiQuote.id,[{field:"MaterialId",oldValue:null,newValue:options[smallestDistanceIndex].ChoiceValueId},{field:"MaterialTypeId",oldValue:null,newValue:materialTypeId}]),$scope.$$phase||$scope.$digest()}},$scope.getMaterialCategoryId=function(){return parseInt($scope.IndexedChoiceData["7-Material Type"].selected.ChoiceFurtherInformation)},$scope.getCurrentMaterialWeight=function(){try{var currentWeight=JSON.parse($scope.IndexedChoiceData["7-Material"].selected.ChoiceFurtherInformation).weight;return parseInt(currentWeight)}catch(e){let currentWeight=JSON.parse($scope.IndexedChoiceData["7-Material"].selected.choiceFurtherInformation).weight;return parseInt(currentWeight)}},$scope.getCurrentMaterialThickness=function(){try{var currentWeight=JSON.parse($scope.IndexedChoiceData["7-Material"].selected.ChoiceFurtherInformation).thickness;return parseInt(currentWeight)}catch(e){let currentWeight=JSON.parse($scope.IndexedChoiceData["7-Material"].selected.choiceFurtherInformation).thickness;return parseInt(currentWeight)}},$scope.getMaterialThickness=function(option){try{var currentWeight=JSON.parse(option.ChoiceFurtherInformation).thickness;return parseInt(currentWeight)}catch(e){let currentWeight=JSON.parse(option.choiceFurtherInformation).thickness;return parseInt(currentWeight)}},$scope.getMaterialWeight=function(option){option.ChoiceFurtherInformation||(option.ChoiceFurtherInformation=option.choiceFurtherInformation);try{var currentWeight=JSON.parse(option.ChoiceFurtherInformation).weight;return parseInt(currentWeight)}catch(e){try{let currentWeight=JSON.parse(option.choiceFurtherInformation).weight;return parseInt(currentWeight)}catch(e){return 100}}},$scope.StyleParentChangedHandle=function(event,option,fieldName){option="quote/data/styles/productStyleType/"+option.ChoiceValueId;optionalData={},ajaxService.getRequest(option,optionalData,function(response,httpCode,optionalData){})},$scope.weightWarning=!1,$scope.weightWarningTimeoutHandle=null,$scope.warnAboutMaterialWeightChange=function(){$scope.weightWarning=!0,$scope.weightWarningTimeoutHandle=setTimeout($scope.endWarningAboutWeightchange,5e3)},$scope.endWarningAboutWeightchange=function(){$scope.weightWarning=!1,$scope.$digest()},$scope.ArtworkChangedHandle=function(event,option,fieldName){console.log("THIS FUNCTION IS TO DO"),console.log("event"),console.log(event),console.log("option"),console.log(option),console.log("fieldName"),console.log(fieldName)},$scope.LookupChildIndexName=function(fieldName){return"ProductStyleId"==fieldName?"14-Product Styles":"PrintSizeId"==fieldName?"5-Print Size":"MaterialId"==fieldName?"7-Material":"ReadymadeArtworkId"==fieldName?"70-Readymade Artwork":"ProductStyleShapeId"==fieldName?"81-Product Shapes":void 0},$scope.LookupChildFieldName=function(fieldName){return"ProductStyleTypeId"==fieldName?"ProductStyleId":"PrintSizeGroupId"==fieldName?"PrintSizeId":"MaterialTypeId"==fieldName?"MaterialId":"ReadymadeArtworkTypeId"==fieldName?"ReadymadeArtworkId":"HardwareTypeId"==fieldName?"HardwareId":"ProductStyleShapeId"==fieldName?"ProductStyleShapeId":void console.error("Unrecognised field name: "+fieldName)},$scope.setVersions=function(response){var newRow;0==response.length?(newRow=new QuoteDataVersions($scope.ApiQuote.id,1,"Version 1",parseInt($scope.IndexedChoiceData["3-Quantity"].valueDisplay)),$scope.Quantity=[newRow]):($scope.Quantity=[],Array.isArray(response)&&response.forEach(function(row){$scope.Quantity.push(row)}))},$scope.setEnvelope=function(envelopes){0<envelopes.length?$scope.envelope=envelopes[0]:$scope.envelope=!1},$scope.setFittings=function(fittings){fittings&&(0<fittings.length?$scope.fittings=fittings:$scope.fittings=!1,$scope.parseFittings(fittings))},$scope.setLabels=function(labels){($scope.labels=labels).length&&($scope.label=labels[0])},$scope.setFolder=function(folders){folders.length&&console.error("Folded instantiation not yet implemented")},$scope.setFiles=function(data){$scope.FileTable=data},$scope.setNotes=function(notes){$scope.quoteDataNotes=notes},$scope.setFinishingMaps=function(maps){$scope.finishingMaps=maps},$scope.setFoldingValidationRules=function(validationRules){$scope.foldValidationRules=validationRules},$scope.setQuoteCovers=function(covers,allPantones,coverPantones){covers&&($scope.covers=covers,$scope.covers.length&&($scope.cover=$scope.covers[0]),$scope.initialiseCoverMaterial(),coverPantones&&($scope.coverPantoneColours=coverPantones),$scope.pantoneLookup=allPantones)},$scope.setProductionOptionConditions=function(conditions){$scope.productionOptionConditions=conditions},$scope.setCoverFinishingMaps=function(json){json.length?$scope.productTypeCoverFinishingMaps=json:$scope.productTypeCoverFinishingMaps=[{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:1,finishingTypeDisplayName:"Lamination",showAdvanced:!1,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:7,finishingTypeDisplayName:"Spot UV",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:17,finishingTypeDisplayName:"Embossing",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:37,finishingTypeDisplayName:"Debossing",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:3,finishingTypeDisplayName:"Foiling",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:23,finishingTypeDisplayName:"Perforation",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:53,finishingTypeDisplayName:"Scoring",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:59,finishingTypeDisplayName:"Cover fold out",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1},{id:0,productTypeId:0,productTypeDisplayName:"",finishingTypeId:13,finishingTypeDisplayName:"Die cut",showAdvanced:!0,initiallySelected:!1,defaultFinishingOptionId:null,defaultQuantity:null,defaultValue:null,forceOn:!1}]},$scope.isInterfaceDisplayed=function(interfaceId){return!!$scope.IndexedSpecificationInterfaces&&(!!$scope.IndexedSpecificationInterfaces[interfaceId]&&$scope.IndexedSpecificationInterfaces[interfaceId].displayed)},$scope.tempBoxFlatAreaObject=null,$scope.tempBoxFlatAreaUnits="mm",$scope.boxFlatAreaError="",$scope.getTempBoxFlatAreaobject=function(){return $scope.tempBoxFlatAreaObject||($scope.ApiQuote?($scope.tempBoxFlatAreaObject=Object.assign({},$scope.ApiQuote),$scope.tempBoxFlatAreaObject):{})},$scope.quoteDataSigns=[],$scope.signsLoaded=!1,$scope.initialiseSigns=function(){$scope.refreshSigns().then(()=>{$scope.updateSigns()})},$scope.updateSigns=function(){clearTimeout($scope.signUpdateTimeoutHandle);var signs=$scope.quoteDataSigns.filter(f=>f.signId==$scope.getSelectedSignId());$scope.validateSignData(signs),ajaxService.postRequest(signs,"quote/data/signs/update/"+$scope.ApiQuote.id,{},function(response){$scope.updateLocalPrices(response),$scope.updateTotalPriceWithSigns(),$scope.digest()})},$scope.refreshSigns=function(){return new Promise((res,rej)=>{$scope.ApiQuote.signId&&ajaxService.getRequest("quote/data/signs/"+$scope.ApiQuote.id,{},function(response){$scope.validateSignData(response),$scope.quoteDataSigns=response,$scope.signsLoaded=!0,$scope.$$phase||$scope.$digest(),res()})})},$scope.validateSignData=function(signdata){let signProductTypes=[];signdata.forEach(sign=>{-1==signProductTypes.indexOf(sign.signProductTypeId)&&signProductTypes.push(sign.signProductTypeId)}),signProductTypes.forEach(signProductType=>{$scope.validateSignDataForProductTypeId(signdata.filter(f=>f.signProductTypeId==signProductType))})},$scope.validateSignDataForProductTypeId=function(signdata){let usedIndexes=[],signsToRenumber=[];signdata.forEach(data=>{-1!=usedIndexes.indexOf(data.signProductQuoteNumber)?signsToRenumber.push(data):usedIndexes.push(data.signProductQuoteNumber)}),signsToRenumber.forEach(sign=>{for(let i=0;i<signdata.length;i++)signdata.find(f=>f.signProductQuoteNumber==i)||(sign.signProductQuoteNumber=i)})},$scope.getAlternativeSignsData=function(){return $scope.ApiQuoteData.filter(f=>"96-SignLayouts"==f.indexName)},$scope.getSelectedSignId=function(){return $scope.ApiQuoteData.find(f=>"96-SignSelection"==f.indexName).valueId},$scope.getSafetySignImageFullUrl=function(imageName){return"https://api.printprice.co.uk/images/safetysigns/signimages/medium/"+imageName},$scope.selectSign=function(sign){$scope.ApiQuoteData.find(f=>"96-SignSelection"==f.indexName).valueId=sign.id,"undefined"!=typeof localProductId&&(localProductId=sign.id+1e4),setTimeout($scope.updateSigns,300)},$scope.getSelectedSignDataObject=function(){let selectedSignId=$scope.ApiQuoteData.find(f=>"96-SignSelection"==f.indexName).valueId;return $scope.ApiQuoteData.find(f=>"96-SignLayouts"==f.indexName&&f.sign.id==selectedSignId)},$scope.getSelectedSign=function(){return $scope.getSelectedSignDataObject().sign},$scope.getSignOptions=function(){return $scope.getSelectedSignDataObject().signs},$scope.generateSignInformation=function(){var sign=$scope.getSelectedSign();let info={};return info.title=sign.name,info.signContent=sign.textContent,100<info.signContent.length&&(info.signContent=info.signContent.substring(0,98)+"..."),info.orientation=1==sign.orientationId?"Portrait":2==sign.orientationId?"Landscape":3==sign.orientationId?"Square":"Shape",info},$scope.countAvailableProductsForSelectedSign=function(){return $scope.getSelectedSignDataObject().signs.length.toString()},$scope.getSignName=function(sign){return sign.displayName.replace("Signs - ","")},$scope.getSignProductImageSrc=function(sign){return"https://api.printprice.co.uk/images/"+sign.imageFile},$scope.getQuoteDataSign=function(signProduct,index){let sign=$scope.getSelectedSign();var search=$scope.quoteDataSigns.filter(f=>f.signId==sign.id&&f.signProductTypeId==signProduct.id&&f.signProductQuoteNumber==index);return search.length?search[0]:null},$scope.getQuotesForSignProduct=function(signProduct){let sign=$scope.getSelectedSign();return $scope.quoteDataSigns.filter(f=>f.signId==sign.id&&f.signProductTypeId==signProduct.id)},$scope.addNewSignData=function(sign,signProduct,index){let newSignData=new QuoteDataSign;newSignData.signId=sign.id,newSignData.signProductTypeId=signProduct.id,newSignData.signProductQuoteNumber=index,newSignData.quoteId=$scope.ApiQuote.id,newSignData.quantity=1;sign=$scope.getSignMaterialOptions(signProduct),index=$scope.getSignSizeOptions(signProduct);return sign.length&&(newSignData.materialId=sign[0].id),index.length&&(newSignData.sizeId=index[0].id),$scope.quoteDataSigns.push(newSignData),newSignData},$scope.getSelectedSize=function(sign,index){index=$scope.getQuoteDataSign(sign,index);if(!index)return null;let sizeId=index.sizeId;return sign.sizes.find(f=>f.id==sizeId)},$scope.getSelectedMaterial=function(sign,index){index=$scope.getQuoteDataSign(sign,index);if(!index)return null;let materialId=index.materialId;return sign.materials.find(f=>f.id==materialId)},$scope.getSelectedSizeName=function(sign,index){sign=$scope.getSelectedSize(sign,index);return sign?sign.displayName:"Custom size"},$scope.getSelectedMaterialName=function(sign,index){sign=$scope.getSelectedMaterial(sign,index);return sign?sign.displayName:"Please select..."},$scope.getSignSizeOptions=function(sign){var custom=sign.allowCustomPrintSize;return!sign.sizesWithCustom&&custom&&(sign.sizesWithCustom=[],sign.sizes.forEach(size=>sign.sizesWithCustom.push(size))),custom?sign.sizesWithCustom:sign.sizes},$scope.getCustomSizeOptionForSign=function(){let size={displayName:"Custom size",printSizeName:"Custom size",published:!0,id:null};return size},$scope.getSignMaterialOptions=function(sign){return sign.materials},$scope.isSignSizeSelected=function(sign,size,index){if(0<index)return!1;sign=$scope.getSelectedSize(sign,index);return!!sign&&sign.id==size.id},$scope.isSignMaterialSelected=function(sign,material,index){if(0<index)return!1;sign=$scope.getSelectedMaterial(sign,index);return!!sign&&sign.id==material.id},$scope.selectSignSize=function(sign,index,size){let qdSign=$scope.getQuoteDataSign(sign,index);qdSign.sizeId=size.id,size.displayName,qdSign.customSize=!1,$scope.updateSigns()},$scope.selectSignMaterial=function(sign,index,material){let qdSign=$scope.getQuoteDataSign(sign,index);qdSign.materialId=material.id,$scope.updateSigns()},$scope.updateLocalPrices=function(signResponse){let signs=signResponse.filter(f=>f.signId==$scope.getSelectedSignId());signs.forEach(sign=>{let localSign=$scope.quoteDataSigns.find(f=>f.signId==sign.signId&&f.signProductTypeId==sign.signProductTypeId&&f.signProductQuoteNumber==sign.signProductQuoteNumber);localSign.unitPrice=sign.unitPrice,localSign.totalPrice=sign.totalPrice}),$scope.digest()},$scope.updateTotalPriceWithSigns=function(){let totalPrice=0,signs=$scope.quoteDataSigns.filter(f=>f.signId==$scope.getSelectedSignId());signs.forEach(sign=>{totalPrice+=sign.totalPrice}),$scope.IndexedChoiceData["57-Price Information"].specificationData.PriceNetTotal=totalPrice,$scope.IndexedChoiceData["57-Price Information"].specificationData.PriceGrossTotal=1.2*totalPrice},$scope.signUpdateTimeoutHandle=null,$scope.queueSignUpdate=function(){clearTimeout($scope.signUpdateTimeoutHandle),$scope.signUpdateTimeoutHandle=setTimeout($scope.updateSigns,800)},$scope.changeSignQuantity=function(raiseValue,sign,signIndex){let qdSign=$scope.getQuoteDataSign(sign,signIndex);raiseValue?qdSign.quantity++:qdSign.quantity--,$scope.signQuantityChanged(sign,signIndex)},$scope.signQuantityChanged=function(sign,signIndex){let qdSign=$scope.getQuoteDataSign(sign,signIndex);signIndex=qdSign.quantity,sign=sign.maximumQuantity;signIndex<1&&(qdSign.quantity=1),sign<signIndex&&(qdSign.quantity=sign),$scope.queueSignUpdate()},$scope.addAnotherSignQuoteRow=function(signProduct){var sign=$scope.getSelectedSign(),currentIndex=$scope.getMaxSignIndex(sign,signProduct);$scope.addNewSignData(sign,signProduct,currentIndex+1),$scope.updateSigns()},$scope.queryAddAnotherSign=function(sign){return 0<$scope.getQuotesForSignProduct(sign).length},$scope.getMaxSignIndex=function(sign,signProduct){let qdSigns=$scope.quoteDataSigns.filter(f=>f.signProductTypeId==signProduct.id&&f.signId==sign.id),maxIndex=-1;return qdSigns.forEach(qdSign=>{qdSign.signProductQuoteNumber>maxIndex&&(maxIndex=qdSign.signProductQuoteNumber)}),maxIndex},$scope.removeSignRow=function(sign,signIndex){var qdSign=$scope.getQuoteDataSign(sign,signIndex);for(let i=0;i<$scope.quoteDataSigns.length;i++)$scope.quoteDataSigns[i]==qdSign&&($scope.quoteDataSigns.splice(i,1),i--);$scope.refreshSignIndexes(),$scope.updateSigns()},$scope.refreshSignIndexes=function(){let signIds=[],arr=$scope.quoteDataSigns;arr.forEach(s=>{signIds.includes(s.signId)||signIds.push(s.signId)}),signIds.forEach(signId=>{$scope.refreshSignIndexesForSignId(signId)})},$scope.refreshSignIndexesForSignId=function(signId){let productTypeIds=[],arr=$scope.quoteDataSigns.filter(f=>f.signId==signId);arr.forEach(p=>{productTypeIds.includes(p.signProductTypeId)||productTypeIds.push(p.signProductTypeId)}),productTypeIds.forEach(productTypeId=>{$scope.refreshSignIndexesForSignIdAndProductTypeId(signId,productTypeId)})},$scope.refreshSignIndexesForSignIdAndProductTypeId=function(signId,productTypeId){let indexes=[],arr=$scope.quoteDataSigns.filter(f=>f.signId==signId&&f.signProductTypeId==productTypeId);arr.forEach(p=>{indexes.includes(p.signProductQuoteNumber)||indexes.push(p.signProductQuoteNumber)}),indexes.sort();for(let i=0;i<indexes.length;i++){let currentIndex=indexes[i];arr.forEach(item=>{item.signProductQuoteNumber==currentIndex&&(item.signProductQuoteNumber=i)})}},$scope.signsShowMore=!1,$scope.displaySignProductQuery=function(index){return index<4||!!$scope.signsShowMore},$scope.toggleSignShowMore=function(){$scope.signsShowMore=!$scope.signsShowMore,$scope.queueSignUpdate()},$scope.signCustomSizeChanged=function(sign){$scope.queueSignUpdate()},$scope.selectSignCustomSizeUnit=function(sign,signIndex,unit){$scope.getQuoteDataSign(sign,signIndex).customSizeUnit=unit,$scope.updateSigns()},$scope.allCustomSignSizeUnits=["mm","cm","in","ft","m"],$scope.getPriceOfSign=function(sign,signIndex){sign=$scope.getQuoteDataSign(sign,signIndex);return sign&&sign.unitPrice?$scope.FormatPrice(sign.unitPrice)+" each":"..."},$scope.digest=function(){$scope.$$phase||$scope.$digest()},$scope.showSignHeadersQuery=function(index){return 0==index||$scope.getWindowWidth()<1121},$scope.getWindowWidth=function(){return Math.max(document.body.scrollWidth,document.documentElement.scrollWidth,document.body.offsetWidth,document.documentElement.offsetWidth,document.documentElement.clientWidth)},$scope.getWindowHeight=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.documentElement.clientHeight)},$scope.checkSafetySignSectionShows=function(sign,section){switch(section){case"size":return!0!==sign.signWithoutSizeChoices;case"material":return!0!==sign.signWithoutMaterialChoices}return!0},$scope.checkForHideTurnaroundOptions=function(){return!$scope.product||!$scope.product.hideTurnaroundOptions}},this.createErrorHandlers=function($scope){$scope.Errors={},$scope.Errors.QuantityInputs=[],$scope.Errors.NewVersionQuantityInput=[],$scope.Errors.pagesCount=new ErrorClass,$scope.Errors.finishingPerforationId=new ErrorClass,$scope.Errors.finishingScoringId=new ErrorClass,$scope.Errors.NumberOfBindingStitches=new ErrorClass,$scope.Errors.PerfCount=new ErrorClass,$scope.Errors.HandFinishingRate=new ErrorClass,$scope.Errors.leafCountId=new ErrorClass,$scope.Errors.zFoldColumnCountId=new ErrorClass,$scope.Errors.zFoldRowCountId=new ErrorClass,$scope.Errors.BannerEyeletsCount=new ErrorClass,$scope.Errors.scoreCount=new ErrorClass,$scope.apiError=function(){ajaxService.apiErrorFunction()}}});