Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region FinalizeBookRequests
- public override string FinalizeBookRequests(Citybreak.Confirmation.OrganizationConfirmation rv,
- Citybreak.Booking.Data.BookingDefinition bvr,
- Defcon.Product.ProductFactory inProdFac, bool preliminaryReservation)
- {
- if (preliminaryReservation)
- {
- // TODO Validate availability in preliminary step (if possible)
- return "<OK>";
- }
- if (bvr != null && bvr.BookingCode != null)
- LogUtil.Log("LPG Bookrequest " + bvr.BookingCode);
- try
- {
- using (var LPGClient = GetLPGClient())
- using (var db = new PersistanceAdapter())
- {
- var deliveryMethods = LPGClient.ListDeliveryMethods();
- int deliveryId = deliveryMethods.deliveryList[0].deliveryCode;
- string deliveryDescription = deliveryMethods.deliveryList[0].deliveryName;
- decimal totalDeliveryCost = 0m;
- decimal totalAmount = 0m;
- decimal totalVatAmount = 0m;
- string orderCurrencyCode = "";
- string orderVerificationCode = "";
- CustomerInfo customer = null;
- DateTime firstUsageDate = bvr.BookingDate;
- var actionsToBook = new List<LPGBookingAction>();
- foreach (LPGBookingAction action in mActiveActions)
- {
- if (action.pr.Status == Defcon.Booking.Common.BookingItemStatus.Removed
- || action.pr.Status == Defcon.Booking.Common.BookingItemStatus.RemovedForEndCustomer)
- {
- continue;
- }
- if (action.StartDate < new DateTime(2010, 1, 10))
- continue;
- Defcon.Product.Entity.Producttype prod = new Defcon.Product.Entity.Producttype();
- prod.Id = action.pr.ProducttypeId;
- prod = inProdFac.GetProducttype(prod);
- action.pr.RemoteCode = prod.RemoteId;
- orderCurrencyCode = action.pr.Currency;
- #region Calc total price and delivery methods
- decimal productPriceInclTax = 0;
- decimal productPriceExclTax = 0;
- decimal productTax = 0;
- int productTaxCode = 0;
- if (IsPrepaid(rv))
- {
- GetProductPrice(action.bpr, ref productPriceInclTax, ref productPriceExclTax, ref productTax, ref productTaxCode);
- totalAmount += productPriceExclTax;
- totalVatAmount += productTax;
- foreach (Citybreak.Booking.Data.SubProduct s in action.bpr.SubProducts)
- {
- decimal sbPriceInclTax = 0;
- decimal sbPriceExclTax = 0;
- decimal sbTax = 0;
- int sbTaxCode = 0;
- GetSubProductPrice(s, action.bpr, ref sbPriceInclTax, ref sbPriceExclTax, ref sbTax, ref sbTaxCode);
- totalDeliveryCost += sbPriceInclTax;
- totalAmount += sbPriceExclTax;
- totalVatAmount += sbTax;
- Defcon.Product.Entity.Producttype prd = new Defcon.Product.Entity.Producttype();
- prd.Id = s.ProducttypeId;
- prd = inProdFac.GetProducttype(prd);
- foreach (var d in deliveryMethods.deliveryList)
- {
- if (prd.RemoteId == d.deliveryName)
- {
- deliveryId = d.deliveryCode;
- deliveryDescription = d.deliveryName;
- }
- }
- }
- }
- else
- {
- totalAmount += (decimal) action.bpr.Price;
- totalVatAmount += (decimal) action.bpr.VatOutTax;
- foreach (Citybreak.Confirmation.SubProduct s in action.bpr.SubProducts)
- {
- if (!s.Included)
- totalDeliveryCost += (decimal)s.Price;
- }
- }
- #endregion
- firstUsageDate = action.pr.DateStart;
- customer = action.Customer;
- if (!string.IsNullOrEmpty(action.pr.RemoteCode))
- {
- actionsToBook.Add(action);
- }
- }
- string newBookingNumber = null;
- if (actionsToBook.Count > 0)
- {
- //weborder, redemptionsale, agentsale
- string orderType = "weborder";
- string vendorId = "";
- if (customer.Surname != null && customer.Surname.Length > 40)
- customer.Surname = customer.Surname.Substring(0, 40);
- if (customer.GivenName != null && customer.GivenName.Length > 40)
- customer.GivenName = customer.GivenName.Substring(0, 40);
- if (rv.Salespoint.Name.Contains("Accueil"))
- orderType = "tourist";
- else if (rv.Salespoint.Name.Contains("Call Center Produits"))
- orderType = "callcenter";
- LogUtil.Log("LPG booking " + bvr.BookingCode + " OrderStart()");
- OrderStartResponse orderResponse;
- if (this.mPmsSystem.Client == "AarhusLPG")
- {
- orderResponse = LPGClient.OrderStart(bvr.BookingCode,
- bvr.BookingDate,
- firstUsageDate,
- "",
- customer.GivenName,
- customer.Surname,
- customer.DayPhone,
- customer.Email ?? "",
- new lpgAddressStruct()
- {
- addressCountry = customer.CountryCode,
- addressCompanyName = customer.CompanyName ?? "",
- addressCustomerName = customer.GivenName + " " + customer.Surname,
- addressLine1 = customer.AddressLine1 ?? "",
- addressLine2 = customer.AddressLine2 ?? "",
- addressLine3 = customer.City ?? "",
- addressLine4 = "",
- addressPostcode = customer.ZipCode ?? "",
- },
- new lpgAddressStruct()
- {
- addressCountry = customer.CountryCode,
- addressCompanyName = customer.CompanyName ?? "",
- addressCustomerName = customer.GivenName + " " + customer.Surname,
- addressLine1 = customer.AddressLine1 ?? "",
- addressLine2 = customer.AddressLine2 ?? "",
- addressLine3 = customer.City ?? "",
- addressLine4 = "",
- addressPostcode = customer.ZipCode ?? "",
- });
- }
- else
- {
- orderResponse = LPGClient.OrderStart(bvr.BookingCode,
- bvr.BookingDate,
- firstUsageDate,
- "",
- customer.GivenName,
- customer.Surname,
- customer.DayPhone,
- customer.Email ?? "",
- new lpgAddressStruct()
- {
- addressCountry = customer.CountryCode,
- addressCompanyName = customer.CompanyName ?? "",
- addressCustomerName = customer.GivenName + " " + customer.Surname,
- addressLine1 = customer.AddressLine1 ?? "",
- addressLine2 = customer.AddressLine2 ?? "",
- addressLine3 = customer.City ?? "",
- addressLine4 = "",
- addressPostcode = customer.ZipCode ?? "",
- },
- new lpgAddressStruct()
- {
- addressCountry = customer.CountryCode,
- addressCompanyName = customer.CompanyName ?? "",
- addressCustomerName = customer.GivenName + " " + customer.Surname,
- addressLine1 = customer.AddressLine1 ?? "",
- addressLine2 = customer.AddressLine2 ?? "",
- addressLine3 = customer.City ?? "",
- addressLine4 = "",
- addressPostcode = customer.ZipCode ?? "",
- },
- orderType,
- vendorId);
- }
- LogUtil.Log("LPG booking " + bvr.BookingCode + " OrderStart response: " + PmsSharedClassesAndUtilities.PmsSharedUtil.Serialize2String(orderResponse));
- newBookingNumber = orderResponse.orderIdentifier;
- if (newBookingNumber == "ERROR")
- throw new Exception(orderResponse.errorDescription);
- string civicNumber = customer.CivicRegistrationNumber;
- if (string.IsNullOrEmpty(civicNumber))
- civicNumber = "0000" + rv.BookingCode;
- else
- civicNumber = civicNumber.Replace("-", "");
- foreach (LPGBookingAction action in actionsToBook)
- {
- decimal productPriceInclTax = 0;
- decimal productPriceExclTax = 0;
- decimal productTax = 0;
- int productTaxCode = 0;
- if (IsPrepaid(rv))
- {
- GetProductPrice(action.bpr, ref productPriceInclTax, ref productPriceExclTax, ref productTax, ref productTaxCode);
- foreach (Citybreak.Booking.Data.SubProduct s in action.bpr.SubProducts)
- {
- decimal sbPriceInclTax = 0;
- decimal sbPriceExclTax = 0;
- decimal sbTax = 0;
- int sbTaxCode = 0;
- GetSubProductPrice(s, action.bpr, ref sbPriceInclTax, ref sbPriceExclTax, ref sbTax, ref sbTaxCode);
- productPriceExclTax += sbPriceExclTax;
- productTax += sbTax;
- }
- }
- else
- {
- productPriceInclTax = (decimal)action.bpr.Price;
- productTax = (decimal)action.bpr.VatOutTax;
- productPriceExclTax = productPriceInclTax - productTax;
- }
- string lpgProduct = action.pr.RemoteCode;
- string lgpPriceGroupName = "Adult";
- string cbPriceGroupName = "";
- if (action.bpr.GuestLinks == null || action.bpr.GuestLinks.Count >= 0)
- cbPriceGroupName = "Adult";
- else
- cbPriceGroupName = action.bpr.GuestLinks[0].PricegroupName ?? action.bpr.GuestLinks[0].PPricegroupName;
- if (cbPriceGroupName.Contains("Child") || cbPriceGroupName.Contains("Lapsi"))
- lgpPriceGroupName = "Child";
- else if (cbPriceGroupName.Contains("Student"))
- lgpPriceGroupName = "Student";
- else if (cbPriceGroupName.Contains("Etudiant"))
- lgpPriceGroupName = "Student";
- else if (cbPriceGroupName.Contains("Junior"))
- lgpPriceGroupName = "Junior";
- lpgProduct = lpgProduct.Replace("Adult", lgpPriceGroupName);
- LogUtil.Log(string.Format("LPG booking {0} call to OrderAddLine(orderId, prodId, quant, price, product) [{1}, {2}, {3}, {4}, {5}]",
- bvr.BookingCode, orderResponse.orderIdentifier, action.bpr.ProducttypeId, 1, productPriceInclTax, lpgProduct));
- var addOrderLineResponse = LPGClient.OrderAddLine(orderResponse.orderIdentifier, action.bpr.ProducttypeId.ToString(), 1, (double)productPriceInclTax, lpgProduct);
- if (addOrderLineResponse.errorCode > 0)
- {
- throw new Exception(string.Format("LPG booking {0} product code {1} got error code in OrderAddLine: {2}, error: {3}", bvr.BookingCode, lpgProduct, addOrderLineResponse.errorCode, addOrderLineResponse.errorDescription));
- }
- if (this.mPmsSystem.Client == "LYONLPG")
- {
- // rv.BookingUser.
- if (rv.CustomerInformation.Culture.Contains("fr"))
- LPGClient.OrderAddLine(orderResponse.orderIdentifier, action.bpr.ProducttypeId.ToString(), 1, 0, "Guidebook - French");
- else
- LPGClient.OrderAddLine(orderResponse.orderIdentifier, action.bpr.ProducttypeId.ToString(), 1, 0, "Guidebook - English");
- }
- }
- if (totalDeliveryCost > 0)
- {
- LogUtil.Log(string.Format("LPG booking {0} SetOrderDelivery() deliveryId: {1}, descr: {2}, totalDeliveryCost: {3}",
- bvr.BookingCode, deliveryId, deliveryDescription, totalDeliveryCost));
- LPGClient.SetOrderDelivery(orderResponse.orderIdentifier, deliveryId, deliveryDescription, (double)totalDeliveryCost);
- }
- LogUtil.Log("LPG booking " + bvr.BookingCode + " call to OrderComplete() orderId: " + orderResponse.orderIdentifier + " total: " + (totalAmount + totalVatAmount));
- OrderCompleteResponse orderCompleteResponse;
- if (this.mPmsSystem.Client == "AarhusLPG")
- {
- orderCompleteResponse = LPGClient.OrderComplete(orderResponse.orderIdentifier, (double)(totalAmount + totalVatAmount), orderCurrencyCode, orderVerificationCode);
- }
- else
- {
- orderCompleteResponse = LPGClient.OrderComplete(orderResponse.orderIdentifier, (double)(totalAmount + totalVatAmount));
- }
- if(orderCompleteResponse.errorCode > 0)
- {
- throw new Exception("OrderComplete() got errorCode: " + orderCompleteResponse.errorCode + ", error: " + orderCompleteResponse.errorDescription);
- }
- }
- else
- {
- LogUtil.Log("LPG booking " + bvr.BookingCode + " call to OrderCancel()");
- var cancelResponse = LPGClient.OrderCancel(bvr.BookingCode);
- if (cancelResponse.errorCode > 0)
- {
- throw new Exception("OrderCancel() got errorCode: " + cancelResponse.errorCode + ", error: " + cancelResponse.errorDescription);
- }
- }
- try
- {
- foreach (LPGBookingAction action in mActiveActions)
- {
- action.BookingItem.BookingNumber = newBookingNumber;
- // if (setBookingReadyResponse != null)
- // action.BookingItem.SystemBookingNumber = setBookingReadyResponse.FriendlyMessage;
- if (actionsToBook.Count == 0)
- action.logItem.Status = 4;
- else if (actionsToBook.Count > 0)
- action.logItem.Status = 2;
- action.logItem.ResponseRecieved = DateTime.Now;
- XmlSerializer serializer = new XmlSerializer(typeof(Citybreak.PMSConnect.Legacy.ConnectorModules.LPG.LPGItem));
- System.IO.StringWriter stringWriter = new System.IO.StringWriter();
- serializer.Serialize(stringWriter, action.BookingItem);
- action.logItem.XmlAnswer = stringWriter.ToString();
- db.UpdateEntity(action.logItem);
- }
- }
- catch (Exception)
- {
- }
- }
- }
- catch (Exception ex)
- {
- try
- {
- LogUtil.MailException(mPmsSystem.ConnectorConfiguration.warningEmail, "LPG Booking Failed " + rv.BookingCode, rv.BookingCode, ex, ex.Message);
- }
- catch (Exception e)
- {
- LogUtil.LogException("Unable to mail exception for failed booking " + rv.BookingCode, e);
- }
- LogUtil.LogException("LPG FinalizeBookRequests Failed " + this.mPmsSystem.Client + " " + rv.BookingCode, ex);
- }
- return "<OK>";
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement