Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 19.38 KB | None | 0 0
  1.    #region FinalizeBookRequests
  2.         public override string FinalizeBookRequests(Citybreak.Confirmation.OrganizationConfirmation rv,
  3.             Citybreak.Booking.Data.BookingDefinition bvr,
  4.             Defcon.Product.ProductFactory inProdFac, bool preliminaryReservation)
  5.         {
  6.             if (preliminaryReservation)
  7.             {
  8.                 // TODO Validate availability in preliminary step (if possible)
  9.                 return "<OK>";
  10.             }
  11.  
  12.             if (bvr != null && bvr.BookingCode != null)
  13.                 LogUtil.Log("LPG Bookrequest " + bvr.BookingCode);
  14.  
  15.             try
  16.             {
  17.                 using (var LPGClient = GetLPGClient())
  18.                 using (var db = new PersistanceAdapter())
  19.                 {
  20.                     var deliveryMethods = LPGClient.ListDeliveryMethods();
  21.  
  22.                     int deliveryId = deliveryMethods.deliveryList[0].deliveryCode;
  23.                     string deliveryDescription = deliveryMethods.deliveryList[0].deliveryName;
  24.  
  25.                     decimal totalDeliveryCost = 0m;
  26.                     decimal totalAmount = 0m;
  27.                     decimal totalVatAmount = 0m;
  28.                     string orderCurrencyCode = "";
  29.                     string orderVerificationCode = "";
  30.  
  31.                     CustomerInfo customer = null;
  32.                     DateTime firstUsageDate = bvr.BookingDate;
  33.                     var actionsToBook = new List<LPGBookingAction>();
  34.  
  35.                     foreach (LPGBookingAction action in mActiveActions)
  36.                     {
  37.                         if (action.pr.Status == Defcon.Booking.Common.BookingItemStatus.Removed
  38.                             || action.pr.Status == Defcon.Booking.Common.BookingItemStatus.RemovedForEndCustomer)
  39.                         {
  40.                             continue;
  41.                         }
  42.  
  43.                         if (action.StartDate < new DateTime(2010, 1, 10))
  44.                             continue;
  45.  
  46.                         Defcon.Product.Entity.Producttype prod = new Defcon.Product.Entity.Producttype();
  47.                         prod.Id = action.pr.ProducttypeId;
  48.                         prod = inProdFac.GetProducttype(prod);
  49.                         action.pr.RemoteCode = prod.RemoteId;
  50.                         orderCurrencyCode = action.pr.Currency;
  51.  
  52.                         #region Calc total price and delivery methods
  53.                         decimal productPriceInclTax = 0;
  54.                         decimal productPriceExclTax = 0;
  55.                         decimal productTax = 0;
  56.                         int productTaxCode = 0;
  57.  
  58.                         if (IsPrepaid(rv))
  59.                         {
  60.                             GetProductPrice(action.bpr, ref productPriceInclTax, ref productPriceExclTax, ref productTax, ref productTaxCode);
  61.                             totalAmount += productPriceExclTax;
  62.                             totalVatAmount += productTax;
  63.  
  64.                             foreach (Citybreak.Booking.Data.SubProduct s in action.bpr.SubProducts)
  65.                             {
  66.                                 decimal sbPriceInclTax = 0;
  67.                                 decimal sbPriceExclTax = 0;
  68.                                 decimal sbTax = 0;
  69.                                 int sbTaxCode = 0;
  70.  
  71.                                 GetSubProductPrice(s, action.bpr, ref sbPriceInclTax, ref sbPriceExclTax, ref sbTax, ref sbTaxCode);
  72.                                 totalDeliveryCost += sbPriceInclTax;
  73.                                 totalAmount += sbPriceExclTax;
  74.                                 totalVatAmount += sbTax;
  75.  
  76.                                 Defcon.Product.Entity.Producttype prd = new Defcon.Product.Entity.Producttype();
  77.                                 prd.Id = s.ProducttypeId;
  78.                                 prd = inProdFac.GetProducttype(prd);
  79.  
  80.                                 foreach (var d in deliveryMethods.deliveryList)
  81.                                 {
  82.                                     if (prd.RemoteId == d.deliveryName)
  83.                                     {
  84.                                         deliveryId = d.deliveryCode;
  85.                                         deliveryDescription = d.deliveryName;
  86.                                     }
  87.                                 }
  88.                             }
  89.                         }
  90.                         else
  91.                         {
  92.                             totalAmount += (decimal) action.bpr.Price;
  93.                             totalVatAmount += (decimal) action.bpr.VatOutTax;
  94.  
  95.                             foreach (Citybreak.Confirmation.SubProduct s in action.bpr.SubProducts)
  96.                             {
  97.                                 if (!s.Included)
  98.                                     totalDeliveryCost += (decimal)s.Price;
  99.                             }
  100.                         }
  101.                         #endregion
  102.  
  103.                         firstUsageDate = action.pr.DateStart;
  104.                         customer = action.Customer;
  105.  
  106.                         if (!string.IsNullOrEmpty(action.pr.RemoteCode))
  107.                         {
  108.                             actionsToBook.Add(action);
  109.                         }
  110.                     }
  111.  
  112.  
  113.                     string newBookingNumber = null;
  114.                     if (actionsToBook.Count > 0)
  115.                     {
  116.                         //weborder, redemptionsale, agentsale
  117.                         string orderType = "weborder";
  118.                         string vendorId = "";
  119.  
  120.                         if (customer.Surname != null && customer.Surname.Length > 40)
  121.                             customer.Surname = customer.Surname.Substring(0, 40);
  122.                         if (customer.GivenName != null && customer.GivenName.Length > 40)
  123.                             customer.GivenName = customer.GivenName.Substring(0, 40);
  124.  
  125.                         if (rv.Salespoint.Name.Contains("Accueil"))
  126.                             orderType = "tourist";
  127.                         else if (rv.Salespoint.Name.Contains("Call Center Produits"))
  128.                             orderType = "callcenter";
  129.  
  130.                         LogUtil.Log("LPG booking " + bvr.BookingCode + " OrderStart()");
  131.  
  132.                         OrderStartResponse orderResponse;
  133.  
  134.                         if (this.mPmsSystem.Client == "AarhusLPG")
  135.                         {
  136.                             orderResponse = LPGClient.OrderStart(bvr.BookingCode,
  137.                                 bvr.BookingDate,
  138.                                 firstUsageDate,
  139.                                 "",
  140.                                 customer.GivenName,
  141.                                 customer.Surname,
  142.                                 customer.DayPhone,
  143.                                 customer.Email ?? "",
  144.  
  145.                                 new lpgAddressStruct()
  146.                                 {
  147.                                     addressCountry = customer.CountryCode,
  148.                                     addressCompanyName = customer.CompanyName ?? "",
  149.                                     addressCustomerName = customer.GivenName + " " + customer.Surname,
  150.                                     addressLine1 = customer.AddressLine1 ?? "",
  151.                                     addressLine2 = customer.AddressLine2 ?? "",
  152.                                     addressLine3 = customer.City ?? "",
  153.                                     addressLine4 = "",
  154.                                     addressPostcode = customer.ZipCode ?? "",
  155.                                 },
  156.  
  157.                                 new lpgAddressStruct()
  158.                                 {
  159.                                     addressCountry = customer.CountryCode,
  160.                                     addressCompanyName = customer.CompanyName ?? "",
  161.                                     addressCustomerName = customer.GivenName + " " + customer.Surname,
  162.                                     addressLine1 = customer.AddressLine1 ?? "",
  163.                                     addressLine2 = customer.AddressLine2 ?? "",
  164.                                     addressLine3 = customer.City ?? "",
  165.                                     addressLine4 = "",
  166.                                     addressPostcode = customer.ZipCode ?? "",
  167.                                 });
  168.                         }
  169.                         else
  170.                         {
  171.                             orderResponse = LPGClient.OrderStart(bvr.BookingCode,
  172.                             bvr.BookingDate,
  173.                             firstUsageDate,
  174.                             "",
  175.                             customer.GivenName,
  176.                             customer.Surname,
  177.                             customer.DayPhone,
  178.                             customer.Email ?? "",
  179.  
  180.                             new lpgAddressStruct()
  181.                             {
  182.                                 addressCountry = customer.CountryCode,
  183.                                 addressCompanyName = customer.CompanyName ?? "",
  184.                                 addressCustomerName = customer.GivenName + " " + customer.Surname,
  185.                                 addressLine1 = customer.AddressLine1 ?? "",
  186.                                 addressLine2 = customer.AddressLine2 ?? "",
  187.                                 addressLine3 = customer.City ?? "",
  188.                                 addressLine4 = "",
  189.                                 addressPostcode = customer.ZipCode ?? "",
  190.                             },
  191.  
  192.                             new lpgAddressStruct()
  193.                             {
  194.                                 addressCountry = customer.CountryCode,
  195.                                 addressCompanyName = customer.CompanyName ?? "",
  196.                                 addressCustomerName = customer.GivenName + " " + customer.Surname,
  197.                                 addressLine1 = customer.AddressLine1 ?? "",
  198.                                 addressLine2 = customer.AddressLine2 ?? "",
  199.                                 addressLine3 = customer.City ?? "",
  200.                                 addressLine4 = "",
  201.                                 addressPostcode = customer.ZipCode ?? "",
  202.                             },
  203.  
  204.                             orderType,
  205.                             vendorId);
  206.                         }
  207.  
  208.                         LogUtil.Log("LPG booking " + bvr.BookingCode + " OrderStart response: " + PmsSharedClassesAndUtilities.PmsSharedUtil.Serialize2String(orderResponse));
  209.  
  210.                         newBookingNumber = orderResponse.orderIdentifier;
  211.                         if (newBookingNumber == "ERROR")
  212.                             throw new Exception(orderResponse.errorDescription);
  213.  
  214.                         string civicNumber = customer.CivicRegistrationNumber;
  215.                         if (string.IsNullOrEmpty(civicNumber))
  216.                             civicNumber = "0000" + rv.BookingCode;
  217.                         else
  218.                             civicNumber = civicNumber.Replace("-", "");
  219.  
  220.  
  221.                         foreach (LPGBookingAction action in actionsToBook)
  222.                         {
  223.                             decimal productPriceInclTax = 0;
  224.                             decimal productPriceExclTax = 0;
  225.                             decimal productTax = 0;
  226.                             int productTaxCode = 0;
  227.  
  228.                             if (IsPrepaid(rv))
  229.                             {
  230.                                 GetProductPrice(action.bpr, ref productPriceInclTax, ref productPriceExclTax, ref productTax, ref productTaxCode);
  231.                                
  232.                                 foreach (Citybreak.Booking.Data.SubProduct s in action.bpr.SubProducts)
  233.                                 {
  234.                                     decimal sbPriceInclTax = 0;
  235.                                     decimal sbPriceExclTax = 0;
  236.                                     decimal sbTax = 0;
  237.                                     int sbTaxCode = 0;
  238.  
  239.                                     GetSubProductPrice(s, action.bpr, ref sbPriceInclTax, ref sbPriceExclTax, ref sbTax, ref sbTaxCode);
  240.                                     productPriceExclTax += sbPriceExclTax;
  241.                                     productTax += sbTax;
  242.                                 }
  243.                             }
  244.                             else
  245.                             {
  246.                                 productPriceInclTax = (decimal)action.bpr.Price;
  247.                                 productTax = (decimal)action.bpr.VatOutTax;
  248.                                 productPriceExclTax = productPriceInclTax - productTax;
  249.                             }
  250.  
  251.                             string lpgProduct = action.pr.RemoteCode;
  252.                             string lgpPriceGroupName = "Adult";
  253.                             string cbPriceGroupName = "";
  254.                             if (action.bpr.GuestLinks == null || action.bpr.GuestLinks.Count >= 0)
  255.                                 cbPriceGroupName = "Adult";
  256.                             else
  257.                                 cbPriceGroupName = action.bpr.GuestLinks[0].PricegroupName ?? action.bpr.GuestLinks[0].PPricegroupName;
  258.  
  259.                             if (cbPriceGroupName.Contains("Child") || cbPriceGroupName.Contains("Lapsi"))
  260.                                 lgpPriceGroupName = "Child";
  261.                             else if (cbPriceGroupName.Contains("Student"))
  262.                                 lgpPriceGroupName = "Student";
  263.                             else if (cbPriceGroupName.Contains("Etudiant"))
  264.                                 lgpPriceGroupName = "Student";
  265.                             else if (cbPriceGroupName.Contains("Junior"))
  266.                                 lgpPriceGroupName = "Junior";
  267.  
  268.                             lpgProduct = lpgProduct.Replace("Adult", lgpPriceGroupName);
  269.  
  270.                             LogUtil.Log(string.Format("LPG booking {0} call to OrderAddLine(orderId, prodId, quant, price, product) [{1}, {2}, {3}, {4}, {5}]",
  271.                                 bvr.BookingCode, orderResponse.orderIdentifier, action.bpr.ProducttypeId, 1, productPriceInclTax, lpgProduct));
  272.  
  273.                             var addOrderLineResponse = LPGClient.OrderAddLine(orderResponse.orderIdentifier, action.bpr.ProducttypeId.ToString(), 1, (double)productPriceInclTax, lpgProduct);
  274.  
  275.                             if (addOrderLineResponse.errorCode > 0)
  276.                             {
  277.                                 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));
  278.                             }
  279.  
  280.                             if (this.mPmsSystem.Client == "LYONLPG")
  281.                             {
  282.                                // rv.BookingUser.
  283.                                 if (rv.CustomerInformation.Culture.Contains("fr"))
  284.                                     LPGClient.OrderAddLine(orderResponse.orderIdentifier, action.bpr.ProducttypeId.ToString(), 1, 0, "Guidebook - French");
  285.                                 else
  286.                                     LPGClient.OrderAddLine(orderResponse.orderIdentifier, action.bpr.ProducttypeId.ToString(), 1, 0, "Guidebook - English");
  287.                             }
  288.  
  289.                          }
  290.  
  291.                         if (totalDeliveryCost > 0)
  292.                         {
  293.                             LogUtil.Log(string.Format("LPG booking {0} SetOrderDelivery() deliveryId: {1}, descr: {2}, totalDeliveryCost: {3}",
  294.                                 bvr.BookingCode, deliveryId, deliveryDescription, totalDeliveryCost));
  295.  
  296.                             LPGClient.SetOrderDelivery(orderResponse.orderIdentifier, deliveryId, deliveryDescription, (double)totalDeliveryCost);
  297.                         }
  298.  
  299.                         LogUtil.Log("LPG booking " + bvr.BookingCode + " call to OrderComplete() orderId: " + orderResponse.orderIdentifier + " total: " + (totalAmount + totalVatAmount));
  300.  
  301.                         OrderCompleteResponse orderCompleteResponse;
  302.  
  303.                         if (this.mPmsSystem.Client == "AarhusLPG")
  304.                         {
  305.                             orderCompleteResponse = LPGClient.OrderComplete(orderResponse.orderIdentifier, (double)(totalAmount + totalVatAmount), orderCurrencyCode, orderVerificationCode);
  306.                         }
  307.                         else
  308.                         {
  309.                             orderCompleteResponse = LPGClient.OrderComplete(orderResponse.orderIdentifier, (double)(totalAmount + totalVatAmount));
  310.                         }
  311.  
  312.                         if(orderCompleteResponse.errorCode > 0)
  313.                         {
  314.                             throw new Exception("OrderComplete() got errorCode: " + orderCompleteResponse.errorCode + ", error: " + orderCompleteResponse.errorDescription);
  315.                         }
  316.                     }
  317.                     else
  318.                     {
  319.                         LogUtil.Log("LPG booking " + bvr.BookingCode + " call to OrderCancel()");
  320.  
  321.                         var cancelResponse = LPGClient.OrderCancel(bvr.BookingCode);
  322.  
  323.                         if (cancelResponse.errorCode > 0)
  324.                         {
  325.                             throw new Exception("OrderCancel() got errorCode: " + cancelResponse.errorCode + ", error: " + cancelResponse.errorDescription);
  326.                         }
  327.                     }
  328.                  
  329.                     try
  330.                     {
  331.                  
  332.                        foreach (LPGBookingAction action in mActiveActions)
  333.                         {
  334.                             action.BookingItem.BookingNumber = newBookingNumber;
  335.                            // if (setBookingReadyResponse != null)
  336.                            //     action.BookingItem.SystemBookingNumber = setBookingReadyResponse.FriendlyMessage;
  337.                             if (actionsToBook.Count == 0)
  338.                                 action.logItem.Status = 4;
  339.                             else if (actionsToBook.Count > 0)
  340.                                 action.logItem.Status = 2;
  341.  
  342.                             action.logItem.ResponseRecieved = DateTime.Now;
  343.  
  344.                             XmlSerializer serializer = new XmlSerializer(typeof(Citybreak.PMSConnect.Legacy.ConnectorModules.LPG.LPGItem));
  345.                             System.IO.StringWriter stringWriter = new System.IO.StringWriter();
  346.                             serializer.Serialize(stringWriter, action.BookingItem);
  347.                             action.logItem.XmlAnswer = stringWriter.ToString();
  348.                             db.UpdateEntity(action.logItem);
  349.                         }
  350.                     }
  351.                     catch (Exception)
  352.                     {
  353.                     }
  354.                 }
  355.             }
  356.             catch (Exception ex)
  357.             {
  358.                 try
  359.                 {
  360.                     LogUtil.MailException(mPmsSystem.ConnectorConfiguration.warningEmail, "LPG Booking Failed " + rv.BookingCode, rv.BookingCode, ex, ex.Message);
  361.                 }
  362.                 catch (Exception e)
  363.                 {
  364.                     LogUtil.LogException("Unable to mail exception for failed booking " + rv.BookingCode, e);
  365.                 }
  366.  
  367.                 LogUtil.LogException("LPG FinalizeBookRequests Failed " + this.mPmsSystem.Client + " " + rv.BookingCode, ex);
  368.             }
  369.  
  370.             return "<OK>";
  371.         }
  372.         #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement