public async Task <ActionResult> SaveDetails(Models.PropertyModel data) { try { if (ModelState.IsValid) { if (data.PropertyFor == 0) { data.PropertyFor = 3; } data.CheckInTime = data.CheckInhr + ":" + data.CheckInmin + " " + data.CheckInclock; data.CheckOutTime = data.CheckOuthr + ":" + data.CheckOutmin + " " + data.CheckOutClock; //data.Description != "" && //if (data.Description.Length > 8000) data.Description = data.Description.Substring(0, 8000); CLayer.Property prprty = new CLayer.Property() { PropertyId = data.PropertyId, Title = data.Title, Description = data.Description, Location = data.Location, Status = (CLayer.ObjectStatus.StatusType)data.Status, OwnerId = BLayer.User.GetUserId(User.Identity.Name), Address = data.Address, Country = data.Country, // CountryId=data.CountryId, State = data.State, City = data.City, CityId = data.CityId, ZipCode = data.ZipCode, Email = data.Email, DistanceFromCity = data.DistanceFromCity, Phone = data.Phone, Mobile = data.Mobile, CheckInTime = data.CheckInTime, CheckOutTime = data.CheckOutTime, CheckInhr = data.CheckInhr, CheckInmin = data.CheckInmin, CheckInclock = data.CheckInclock, CheckOuthr = data.CheckOuthr, CheckOutmin = data.CheckOutmin, CheckOutClock = data.CheckOutClock, AgeLimit = data.AgeLimit, PageTitle = data.PageTitle, MetaDescription = data.MetaDescription, PropertyFor = data.PropertyFor }; string loc = ""; try { string statename = BLayer.State.Get(data.State).Name; string cityname; if (data.CityId < 1) { cityname = data.City; } else { cityname = BLayer.City.Get(data.CityId).Name; data.City = cityname; prprty.City = cityname; } string Countryname = BLayer.Country.Get(data.Country).Name; loc = cityname + "," + statename + "," + Countryname; string qAdddress = data.Title + "," + data.Address + "," + loc; Common.Utils.Location pos; pos = await Common.Utils.GetLocation(qAdddress); prprty.PositionLat = pos.Lattitude.ToString(); prprty.PositionLng = pos.Longitude.ToString(); //string apiQuery = BLayer.Settings.GetValue(CLayer.Settings.GOOGLE_API_QUERY); //apiQuery = apiQuery.Replace("[ADDR]", HttpUtility.UrlEncode(qAdddress)); //apiQuery = apiQuery.Replace("[API]", BLayer.Settings.GetValue(CLayer.Settings.GOOGLE_API_KEY)); //System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); //string result = await client.GetStringAsync(apiQuery); //System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //doc.LoadXml(result); //string status = doc.SelectSingleNode("/GeocodeResponse/status").InnerText; //if (status.ToUpper().Trim() == "OK") //{ // string lat = doc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat").InnerText; // string longitude = doc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText; // prprty.PositionLat = lat; // prprty.PositionLng = longitude; //} } catch (Exception ex) { Common.LogHandler.LogError(ex); } if (data.DistanceFromCity <= 0) { try { Common.Utils.Location pos; pos = await Common.Utils.GetLocation(loc); double lat, lng; lat = lng = 0; double.TryParse(prprty.PositionLat, out lat); double.TryParse(prprty.PositionLng, out lng); // double val = Common.Utils.GetDistance(lat,lng, (double) pos.Lattitude,(double) pos.Longitude); double val = Common.Utils.DistanceCalc(lat, lng, (double)pos.Lattitude, (double)pos.Longitude); //val = val * 1000; prprty.DistanceFromCity = (int)Math.Round(val, 1); if (prprty.DistanceFromCity > 100) { prprty.DistanceFromCity = 0; } } catch (Exception ex) { Common.LogHandler.LogError(ex); } } else { prprty.DistanceFromCity = data.DistanceFromCity; } data.PropertyId = BLayer.Property.Save(prprty); BLayer.Property.SetPosition(data.PropertyId, prprty.PositionLat, prprty.PositionLng); ViewBag.Message = "Saved property."; return(RedirectToAction("Index", new { id = data.PropertyId })); } else { ViewBag.Message = "Error. Please try again"; return(View("Index", data)); } } catch (Exception ex) { Common.LogHandler.HandleError(ex); return(Redirect("~/ErrorPage")); } }
private Models.PropertyModel GetDetails(long propertyid) { Models.PropertyModel prprty = new Models.PropertyModel(); CLayer.Property data = BLayer.Property.Get(propertyid); if (data != null) { if (data.CheckInTime == "" || data.CheckOutTime == "") { data.CheckInTime = "02:00 AM"; data.CheckOutTime = "12:00 PM"; } string a = data.CheckInTime; string[] Intime = a.Split(' '); string Inhrmin = Intime[0]; string[] Inhrmin1 = Inhrmin.Split(':'); string CheckInclock = Intime[1]; string CheckInHr = Inhrmin1[0]; string CheckInMin = Inhrmin1[1]; string b = data.CheckOutTime; string[] Outtime = b.Split(' '); string Outhrmin = Outtime[0]; string[] Outhrmin1 = Outhrmin.Split(':'); string CheckOutclock = Outtime[1]; string CheckOutHr = Outhrmin1[0]; string CheckOutMin = Outhrmin1[1]; prprty = new Models.PropertyModel() { PropertyId = data.PropertyId, Title = data.Title, Description = data.Description, Location = data.Location, Status = (int)data.Status, OwnerId = data.OwnerId, Address = data.Address, ZipCode = data.ZipCode, Landmarks = GetLandmarks(propertyid), Pictures = GetPictures(propertyid), Features = GetFeatures(propertyid), Email = data.Email, Accommodations = GetAccommodations(propertyid), DistanceFromCity = data.DistanceFromCity, Phone = data.Phone, Mobile = data.Mobile, AgeLimit = data.AgeLimit, CheckInhr = CheckInHr, CheckInmin = CheckInMin, CheckInclock = CheckInclock, CheckOuthr = CheckOutHr, CheckOutmin = CheckOutMin, CheckOutClock = CheckOutclock, PageTitle = data.PageTitle, MetaDescription = data.MetaDescription, PropertyFor = data.PropertyFor }; prprty.Country = data.Country; prprty.State = data.State; if (data.City != null && data.City != "") { prprty.City = data.City; } if (data.CityId > 0) { prprty.City = BLayer.City.Get(data.CityId).Name; } prprty.CityId = data.CityId; prprty.LoadPlaces(); } else { prprty.PropertyId = -1; } return(prprty); }
public static int SavePartialPay(CLayer.Property data) { DataLayer.Property task = new DataLayer.Property(); return(task.SavePartialPay(data)); }
public static long SaveAmadeus_Property(CLayer.Property propertydata) { DataLayer.Property property = new DataLayer.Property(); return(property.SaveAmadeus_Property(propertydata)); }
//public static void CancelAccommodation(long bookingItemId) //{ // CLayer.BookingItem detail = BLayer.BookingItem.GetDetails(bookingItemId); // List<CLayer.Transaction> refundable = BLayer.Transaction.GetAllRefundable(detail.BookingId); // double serviceCharge = 0; // BLayer.Transaction.GetTotalCancellationServiceCharge(detail.BookingId, ref refundable, detail.Amount); // decimal cancellationCharge = 0; // decimal firstDayCharge = BLayer.BookingItem.GetFirstDayCharge(bookingItemId); // CLayer.Property prp = BLayer.Property.GetCancellationCharges(BLayer.Bookings.GetPropertyId(detail.BookingId)); // if (detail.CheckIn.AddHours(-1 * (double)prp.CancellationPeriod) <= DateTime.Now) // { // cancellationCharge = BLayer.Bookings.GetTotalCancellationCharge(prp, detail.Amount, firstDayCharge, detail.CheckIn); ; // } // //found refund amount by reducing cancellation charge, service charge will be deducted once the transaction is done // decimal RefundAmount = detail.TotalAmount - cancellationCharge; // bool CanCancel = (RefundAmount > CLayer.Settings.TRANSACTION_MIN_AMOUNT); // BLayer.BookingItem.SetStatus(bookingItemId, CLayer.ObjectStatus.StatusType.Disabled); // if (CanCancel) // { // //mark as trying // double amt = 0; // decimal tryRefund = 0; // foreach (CLayer.Transaction tran in refundable) // { // //(pPaymentId VARCHAR(12),pTryAmount DECIMAL(14,2), pTryTime DATETIME,pTotalAmount DECIMAL(14,2),pStatus INT) // serviceCharge = GetServiceCharge((CLayer.ObjectStatus.PaymentMethod)tran.PaymentType); // if (serviceCharge > 0) // { // serviceCharge = Math.Round((double)RefundAmount * serviceCharge / 100 * 2); // RefundAmount = RefundAmount - (decimal)serviceCharge; // } // if (RefundAmount <= 0) break; // amt = tran.TotalAmount; // if (amt >= (double)RefundAmount) // { // amt = amt - (double)RefundAmount; // tryRefund = RefundAmount; // RefundAmount = 0; // } // else // { // RefundAmount = RefundAmount - (decimal)amt; // tryRefund = (decimal)amt; // amt = 0; // } // tran.TryAmount = tryRefund; // tran.ServiceCharge = tran.ServiceCharge + serviceCharge; // tran.TryTime = DateTime.Today; // tran.TotalAmount = amt; // tran.Status = CLayer.ObjectStatus.TransactionStatus.TryingForRefund; // BLayer.Transaction.UpdateAmountAndStatus(tran); // // if (RefundAmount <= 0) break; // } // foreach (CLayer.Transaction tran in refundable) // { // try // { // if (tran.Status != CLayer.ObjectStatus.TransactionStatus.TryingForRefund) continue; // if (SendRefund(tran)) // { // if (tran.TotalAmount > 0) // tran.Status = CLayer.ObjectStatus.TransactionStatus.PartialRefund; // else // tran.Status = CLayer.ObjectStatus.TransactionStatus.Refunded; // tran.TryAmount = 0; // BLayer.Transaction.UpdateAmountAndStatus(tran); // } // } // catch // { } // } // //BLayer.Bookings.UpdateCharges(bookingId, cancellationCharge, (decimal)totalServiceCharge); // //BLayer.Bookings.SetRefund(bookingId, totalRefund - (decimal)totalServiceCharge); // } //} public static void CancelAllTransactions(long bookingId) { CLayer.ObjectStatus.BookingStatus BStatus = BLayer.Bookings.GetStatus(bookingId); long PayOption = BLayer.Bookings.GetPaymentoption(bookingId); CLayer.Booking detail = BLayer.Bookings.GetDetails(bookingId); List <CLayer.Transaction> refundable = BLayer.Transaction.GetAllRefundable(bookingId); double serviceCharge = 0;// BLayer.Transaction.GetTotalCancellationServiceCharge(bookingId, ref refundable); decimal cancellationCharge = 0; double totalServiceCharge = 0; decimal firstDayCharge = BLayer.Bookings.GetFirstDayCharge(bookingId); CLayer.Property prp = BLayer.Property.GetCancellationCharges(BLayer.Bookings.GetPropertyId(bookingId)); int noOfDays = (detail.CheckOut - detail.CheckIn).Days; cancellationCharge = BLayer.Bookings.GetTotalCancellationCharge(prp, detail.TotalAmount, noOfDays * firstDayCharge, detail.CheckIn); if (BStatus == CLayer.ObjectStatus.BookingStatus.BookingRequest) { cancellationCharge = 0; } decimal RefundAmountFCancel = Math.Round(detail.TotalAmount - cancellationCharge); if (PayOption == (int)CLayer.ObjectStatus.PaymentOption.FullPayment) { RefundAmountFCancel = Math.Round(detail.TotalAmount - cancellationCharge); } else if (PayOption == (int)CLayer.ObjectStatus.PaymentOption.PartialPayment) { CLayer.ObjectStatus.PartialPaymentStatus PartialPayStatus = BLayer.Bookings.GetPartialPaymentStatus(bookingId); CLayer.Booking PartBookDt = BLayer.Bookings.GetPartialBookDetailsbyBookId(bookingId); if (PartialPayStatus == CLayer.ObjectStatus.PartialPaymentStatus.InitialPaymentSuccess || PartialPayStatus == CLayer.ObjectStatus.PartialPaymentStatus.SecondPaymentFailed || PartialPayStatus == CLayer.ObjectStatus.PartialPaymentStatus.Secondpaycheckout) { RefundAmountFCancel = Math.Round(PartBookDt.PaymentFirstinstallment - cancellationCharge); } else if (PartialPayStatus == CLayer.ObjectStatus.PartialPaymentStatus.SecondPaymentSuccess) { RefundAmountFCancel = Math.Round(detail.TotalAmount - cancellationCharge); } } bool CanCancel = (RefundAmountFCancel > CLayer.Settings.TRANSACTION_MIN_AMOUNT); if (BStatus == CLayer.ObjectStatus.BookingStatus.BookingRequest) { BLayer.Bookings.SetStatus((int)CLayer.ObjectStatus.BookingStatus.Decline, bookingId); } else { BLayer.Bookings.SetStatus((int)CLayer.ObjectStatus.BookingStatus.Cancelled, bookingId); } BLayer.Bookings.SetPartialPaymentStatus((int)CLayer.ObjectStatus.PartialPaymentStatus.BookingCancel, bookingId); BLayer.Bookings.SetUpdatedDate(bookingId); decimal totalRefund = RefundAmountFCancel; long Gatewaytype = BLayer.Bookings.Getgatewaytype(bookingId); if (CanCancel) { //mark as trying double amt = 0; decimal tryRefund = 0; int countlist = 0; foreach (CLayer.Transaction tran in refundable) { decimal RefundAmount = RefundAmountFCancel; if (PayOption == (int)CLayer.ObjectStatus.PaymentOption.FullPayment) { RefundAmount = RefundAmountFCancel; } else if (PayOption == (int)CLayer.ObjectStatus.PaymentOption.PartialPayment) { CLayer.Booking PartBookDt = BLayer.Bookings.GetPartialBookDetailsbyBookId(bookingId); if (countlist == 0) { RefundAmount = Math.Round(PartBookDt.PaymentFirstinstallment - cancellationCharge); } else if (countlist == 1) { RefundAmount = Math.Round(PartBookDt.PaymentSecondinstallment - cancellationCharge); } } else { RefundAmount = RefundAmountFCancel; } serviceCharge = GetServiceCharge((CLayer.ObjectStatus.PaymentMethod)tran.PaymentType); if (serviceCharge > 0) { serviceCharge = Math.Round((double)RefundAmount * serviceCharge / 100 * 2); if (BStatus == CLayer.ObjectStatus.BookingStatus.Decline) { serviceCharge = 0; } RefundAmount = RefundAmount - (decimal)serviceCharge; } if (RefundAmount <= 0) { break; } amt = tran.TotalAmount; if (Gatewaytype == (int)CLayer.ObjectStatus.Gateway.EBS) { if (amt >= (double)RefundAmount) { amt = amt - (double)RefundAmount; tryRefund = RefundAmount; RefundAmount = 0; } else { RefundAmount = RefundAmount - (decimal)amt; tryRefund = (decimal)amt; amt = 0; } } else if (Gatewaytype == (int)CLayer.ObjectStatus.Gateway.PayPal) { CLayer.Currency cur = BLayer.Currency.Get("USD"); RefundAmount = Math.Round(RefundAmount * cur.ConversionRate, 2, MidpointRounding.AwayFromZero); if (amt >= (double)RefundAmount) { amt = amt - (double)RefundAmount; tryRefund = RefundAmount; RefundAmount = 0; } else { RefundAmount = RefundAmount - (decimal)amt; tryRefund = (decimal)amt; amt = 0; } } totalServiceCharge = totalServiceCharge + serviceCharge; tran.TryAmount += tryRefund; tran.ServiceCharge = tran.ServiceCharge + serviceCharge; //tran.TryAmount = tryRefund; //tran.ServiceCharge = tran.ServiceCharge + serviceCharge; tran.TryTime = DateTime.Today; tran.TotalAmount = amt; tran.Status = CLayer.ObjectStatus.TransactionStatus.TryingForCanc; BLayer.Transaction.UpdateAmountAndStatus(tran); // if (RefundAmount <= 0) break; countlist = countlist + 1; } //set totalservice charge and cancellation charge BLayer.Bookings.UpdateCharges(bookingId, cancellationCharge, (decimal)totalServiceCharge); BLayer.Bookings.SetRefund(bookingId, totalRefund - (decimal)totalServiceCharge); //save to booking refund //BLayer.Bookings.SaveBookingRefundAmt(bookingId, totalRefund - (decimal)totalServiceCharge, (int)CLayer.ObjectStatus.BookingChangeType.Cancel); foreach (CLayer.Transaction tran in refundable) { try { //if (tran.ResponseCode != CLayer.Transaction.TRAN_SUCCESS) //{ // continue; //} if (tran.Status != CLayer.ObjectStatus.TransactionStatus.TryingForCanc) { continue; } if (Gatewaytype == (int)CLayer.ObjectStatus.Gateway.EBS) { if (SendRefund(tran)) { // if (tran.TotalAmount > 0) // tran.Status = CLayer.ObjectStatus.TransactionStatus.PartialRefund; // else tran.Status = CLayer.ObjectStatus.TransactionStatus.Refunded; tran.TryAmount = 0; BLayer.Transaction.UpdateAmountAndStatus(tran); } } else if (Gatewaytype == (int)CLayer.ObjectStatus.Gateway.PayPal) { if (SendPayPalRefund(tran)) { tran.Status = CLayer.ObjectStatus.TransactionStatus.Refunded; tran.TryAmount = 0; BLayer.Transaction.UpdateAmountAndStatus(tran); } } } catch { } } } else { //very less amount to refund which can be less than Rs.10 BLayer.Transaction.RefundAllTransactions(bookingId); } }
public static void RefundAmount(long bookingId, decimal refundAmountAfterApplyingCancCharge, decimal cancellationCharge) { decimal RefundAmount = refundAmountAfterApplyingCancCharge; CLayer.Booking detail = BLayer.Bookings.GetDetails(bookingId); List <CLayer.Transaction> refundable = BLayer.Transaction.GetAllRefundable(bookingId); double serviceCharge = 0; double totalServiceCharge = 0; CLayer.Property prp = BLayer.Property.GetCancellationCharges(BLayer.Bookings.GetPropertyId(bookingId)); //found refund amount by reducing cancellation charge, service charge will be deducted once the transaction is done bool CanCancel = (RefundAmount > CLayer.Settings.TRANSACTION_MIN_AMOUNT); decimal totalRefund = RefundAmount; if (CanCancel) { //mark as trying double amt = 0; decimal tryRefund = 0; foreach (CLayer.Transaction tran in refundable) { //(pPaymentId VARCHAR(12),pTryAmount DECIMAL(14,2), pTryTime DATETIME,pTotalAmount DECIMAL(14,2),pStatus INT) serviceCharge = GetServiceCharge((CLayer.ObjectStatus.PaymentMethod)tran.PaymentType); if (serviceCharge > 0) { serviceCharge = Math.Round((double)RefundAmount * serviceCharge / 100 * 2); RefundAmount = RefundAmount - (decimal)serviceCharge; } if (RefundAmount <= 0) { break; } amt = tran.TotalAmount; // -serviceCharge; if (amt >= (double)RefundAmount) { amt = amt - (double)RefundAmount; tryRefund = RefundAmount; RefundAmount = 0; } else { RefundAmount = RefundAmount - (decimal)amt; tryRefund = (decimal)amt; amt = 0; } totalServiceCharge = totalServiceCharge + serviceCharge; tran.TryAmount += tryRefund; tran.ServiceCharge = tran.ServiceCharge + serviceCharge; tran.TryTime = DateTime.Today; tran.TotalAmount = amt; tran.Status = CLayer.ObjectStatus.TransactionStatus.TryingForRefund; BLayer.Transaction.UpdateAmountAndStatus(tran); } foreach (CLayer.Transaction tran in refundable) { try { if (tran.Status != CLayer.ObjectStatus.TransactionStatus.TryingForRefund) { continue; } if (SendRefund(tran)) { if (tran.TotalAmount > 0) { tran.Status = CLayer.ObjectStatus.TransactionStatus.PartialRefund; } else { tran.Status = CLayer.ObjectStatus.TransactionStatus.Refunded; } tran.TryAmount = 0; BLayer.Transaction.UpdateAmountAndStatus(tran); } } catch { } } //set totalservice charge and cancellation charge BLayer.Bookings.UpdateCharges(bookingId, cancellationCharge, (decimal)totalServiceCharge); BLayer.Bookings.SetRefund(bookingId, totalRefund - (decimal)totalServiceCharge); //save to booking refund //BLayer.Bookings.SaveBookingRefundAmt(bookingId, totalRefund - (decimal)totalServiceCharge, (int)CLayer.ObjectStatus.BookingChangeType.Modify); } }