{"version":3,"sources":["Areas/ProductConfiguration/Scripts/ConfigurationV2/OfferModelV2.js"],"names":["OfferModelV2","requestHandle","that","this","AddressModal","ko","observable","Offers","observableArray","SelectedMailHeadType","Working","UserHasMailHead","Amount","extend","rateLimit","timeout","method","ShowPrice","GrossPrice","IsAdvantageousAmountAvailable","NextTopAmount","UserReferenceText","ArticleReference","SelectedOrderOptions","SelectedAdditionalWorkIds","SelectedDeliveryCountryId","IsLoading","OfferId","Email","Company","LastName","Reference","ObjectId","Revenue","RevenueOperator","CurrencyId","OnlyOffersWithoutOrder","IsAmountSetProgrammatically","subscribe","abort","console","info","$","ajax","url","ajaxUrls","offer","GetGrossPriceForArticleWithAmount","type","data","JSON","stringify","articleReference","amount","selectedOrderOptions","selectedAdditionalWorkIds","countryId","dataType","contentType","done","Success","IsIndividualAmount","offerModel","circulation","price","Circulation","Price","Clear","removeAll","AddOffer","push","AddToOffer","validAmount","each","index","item","offerId","alerts","error","fail","warning","constants","DoubleOfferAmountError","RemoveOffer","RemoveAmount","toJSON","always","remove","UpdateData","selectedDeliveryCountryId","grossPrice","parseInt","PrintOffer","input","event","target","getAttribute","link","ShowOffer","window","open","ListOffersPartial","listOffersPartialUrl","val","params","email","company","lastname","reference","objectId","revenue","revenueOperator","currencyId","onlyOffersWithoutOrder","result","html","xhr"],"mappings":"AAAA,IAAIA,aAAe,WACf,IACIC,cADAC,KAAOC,KAGXD,KAAKE,aAAeC,GAAGC,WAAW,MAClCJ,KAAKK,OAASF,GAAGG,gBAAgB,IACjCN,KAAKO,qBAAuBJ,GAAGC,WAAW,GAC1CJ,KAAKQ,QAAUL,GAAGC,YAAW,GAC7BJ,KAAKS,gBAAkBN,GAAGC,YAAW,GACrCJ,KAAKU,OAASP,GAAGC,WAAW,GAAGO,OAAO,CAAEC,UAAW,CAAEC,QAAS,IAAKC,OAAQ,2BAC3Ed,KAAKe,UAAYZ,GAAGC,YAAW,GAC/BJ,KAAKgB,WAAab,GAAGC,aACrBJ,KAAKiB,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,KAAKkC,0BAGjCM,EAAEC,KAAK,CACHC,IAAK0D,qBACLtD,KAAM,MACNC,KAAMuD,SACP7C,MAAK,SAAUuD,QACdxE,EAAE,gBAAgByE,KAAKD,OAC3B,IAAGnC,MAAK,SAAUqC,KACdvC,OAAOC,OACX,IAAGQ,QAAO,WACNpF,KAAKwB,WAAU,EACnB,GACJ,CACJ","file":"offer.min.js","sourcesContent":["var OfferModelV2 = function () {\r\n var that = this;\r\n var requestHandle;\r\n\r\n that.AddressModal = ko.observable(null);\r\n that.Offers = ko.observableArray([]);\r\n that.SelectedMailHeadType = ko.observable(0);\r\n that.Working = ko.observable(false);\r\n that.UserHasMailHead = ko.observable(false);\r\n that.Amount = ko.observable(0).extend({ rateLimit: { timeout: 400, method: \"notifyWhenChangesStop\" } });\r\n that.ShowPrice = ko.observable(false);\r\n that.GrossPrice = ko.observable();\r\n that.IsAdvantageousAmountAvailable = ko.observable(false);\r\n that.NextTopAmount = ko.observable(0);\r\n that.UserReferenceText = ko.observable(\"\");\r\n\r\n that.ArticleReference = \"\";\r\n that.SelectedOrderOptions = [];\r\n that.SelectedAdditionalWorkIds = [];\r\n that.SelectedDeliveryCountryId = 0;\r\n that.IsLoading = ko.observable(false);\r\n\r\n //search offer parameter\r\n that.OfferId = ko.observable(null);\r\n that.Email = ko.observable(\"\");\r\n that.Company = ko.observable(\"\");\r\n that.LastName = ko.observable(\"\");\r\n that.Reference = ko.observable(\"\");\r\n that.ObjectId = ko.observable(0);\r\n that.Revenue = ko.observable(\"\");\r\n that.RevenueOperator = ko.observable(\"\");\r\n that.CurrencyId = ko.observable(null);\r\n that.OnlyOffersWithoutOrder = ko.observable(false);\r\n\r\n that.IsAmountSetProgrammatically = false;\r\n\r\n that.Amount.subscribe(function () {\r\n that.IsAdvantageousAmountAvailable(false);\r\n });\r\n\r\n var abortPendingRequest = function () {\r\n if (!that.ShowPrice()) {\r\n requestHandle.abort();\r\n console.info(\"aborted call to GetGrossPriceForArticleWithAmount\");\r\n }\r\n };\r\n\r\n that.Amount.subscribe(function () {\r\n if (that.IsAmountSetProgrammatically || that.Amount() === 0) {\r\n that.IsAmountSetProgrammatically = false;\r\n return;\r\n }\r\n abortPendingRequest();\r\n that.ShowPrice(false);\r\n that.IsAdvantageousAmountAvailable(false);\r\n requestHandle = $.ajax({\r\n url: ajaxUrls.offer.GetGrossPriceForArticleWithAmount,\r\n type: \"POST\",\r\n data: JSON.stringify({\r\n articleReference: that.ArticleReference,\r\n amount: that.Amount(),\r\n selectedOrderOptions: that.SelectedOrderOptions,\r\n selectedAdditionalWorkIds: that.SelectedAdditionalWorkIds,\r\n countryId: that.SelectedDeliveryCountryId\r\n }),\r\n dataType: \"json\",\r\n contentType: \"application/json; charset=utf-8\"\r\n }).done(function (data) {\r\n if (data.Success) {\r\n that.ShowPrice(true);\r\n if (data.data.IsIndividualAmount === true && data.data.NextTopAmount > 0) {\r\n that.IsAdvantageousAmountAvailable(true);\r\n } else {\r\n that.IsAdvantageousAmountAvailable(false);\r\n }\r\n that.GrossPrice(data.data.GrossPrice);\r\n that.NextTopAmount(data.data.NextTopAmount);\r\n }\r\n });\r\n });\r\n\r\n var offerModel = function (circulation, price) {\r\n this.Circulation = ko.observable(circulation);\r\n this.Price = ko.observable(price);\r\n };\r\n\r\n that.Clear = function () {\r\n that.Offers.removeAll();\r\n that.IsAdvantageousAmountAvailable(false);\r\n that.ShowPrice(false);\r\n };\r\n\r\n that.AddOffer = function (circulation, price) {\r\n that.Offers.push(new offerModel(circulation, price));\r\n };\r\n\r\n that.AddToOffer = function () {\r\n var validAmount = true;\r\n $.each(that.Offers(),\r\n function (index, offer) {\r\n if (offer.Circulation() === that.Amount()) {\r\n //amount already added\r\n validAmount = false;\r\n }\r\n });\r\n if (!validAmount) {\r\n alerts.warning(constants.offer.DoubleOfferAmountError);\r\n return;\r\n }\r\n that.Working(true);\r\n $.ajax({\r\n url: ajaxUrls.offer.AddToOffer,\r\n type: \"POST\",\r\n data: JSON.stringify({\r\n item: {\r\n articleReference: that.ArticleReference,\r\n amount: that.Amount(),\r\n selectedOrderOptions: that.SelectedOrderOptions,\r\n selectedAdditionalWorkIds: that.SelectedAdditionalWorkIds,\r\n countryId: that.SelectedDeliveryCountryId\r\n },\r\n offerId: that.OfferId\r\n }),\r\n dataType: \"json\",\r\n contentType: \"application/json; charset=utf-8\",\r\n }).done(function (data) {\r\n if (data.Success) {\r\n that.Offers.push(new offerModel(that.Amount(), that.GrossPrice()));\r\n that.Working(false);\r\n } else {\r\n alerts.error();\r\n }\r\n }).fail(function () {\r\n alerts.error();\r\n });\r\n };\r\n\r\n that.RemoveOffer = function (offer) {\r\n that.Working(true);\r\n\r\n var data = {\r\n Amount: offer.Circulation(),\r\n OfferId: that.OfferId\r\n };\r\n\r\n $.ajax({\r\n url: ajaxUrls.offer.RemoveAmount,\r\n type: \"POST\",\r\n data: ko.toJSON(data),\r\n dataType: \"json\",\r\n contentType: \"application/json; charset=utf-8\",\r\n }).fail(function () {\r\n alerts.error();\r\n }).always(function () {\r\n that.Working(false);\r\n });\r\n\r\n that.Offers.remove(offer);\r\n };\r\n\r\n that.UpdateData = function (articleReference, amount, selectedOrderOptions, selectedAdditionalWorkIds, selectedDeliveryCountryId, grossPrice) {\r\n that.Amount(0);\r\n that.ArticleReference = articleReference;\r\n that.SelectedOrderOptions = selectedOrderOptions;\r\n that.SelectedAdditionalWorkIds = selectedAdditionalWorkIds;\r\n that.IsAmountSetProgrammatically = true;\r\n that.Amount(parseInt(amount));\r\n that.SelectedDeliveryCountryId = selectedDeliveryCountryId;\r\n that.GrossPrice(grossPrice);\r\n that.ShowPrice(true);\r\n };\r\n\r\n that.PrintOffer = function (input, event) {\r\n that.Working(true);\r\n var target = event.target;\r\n var isExtended = target.getAttribute(\"data-extendedprint\");\r\n that.Working(false);\r\n var link = ajaxUrls.offer.ShowOffer + \"/\" + that.OfferId;\r\n window.open(link, \"_blank\");\r\n };\r\n\r\n that.ListOffersPartial = function () {\r\n that.IsLoading(true);\r\n var listOffersPartialUrl = $(\"#listOffersPartialUrl\").val();\r\n var params = {\r\n offerId: that.OfferId(),\r\n email: that.Email(),\r\n company: that.Company(),\r\n lastname: that.LastName(),\r\n reference: that.Reference(),\r\n objectId: that.ObjectId(),\r\n revenue: that.Revenue(),\r\n revenueOperator: that.RevenueOperator(),\r\n currencyId: that.CurrencyId(),\r\n onlyOffersWithoutOrder: that.OnlyOffersWithoutOrder()\r\n };\r\n\r\n $.ajax({\r\n url: listOffersPartialUrl,\r\n type: \"GET\",\r\n data: params\r\n }).done(function (result) {\r\n $(\"#OfferResult\").html(result);\r\n }).fail(function (xhr) {\r\n alerts.error();\r\n }).always(function () {\r\n that.IsLoading(false);\r\n });\r\n };\r\n};\r\n"]}