/// <summary> /// Method to get payout vendor /// </summary> /// <param name="error">Error</param> /// <returns>Vendor payout</returns> public VendorPayout GetPayoutVendor(out ErrorMessage error) { error = new ErrorMessage(); var offSet = _policyManager.LoadStoreInfo().OffSet; if (!_policyManager.DO_PAYOUTS) { MessageType temp_VbStyle8 = (int)MessageType.Exclamation + MessageType.OkOnly; error.MessageStyle = _resourceManager.CreateMessage(offSet, 38, 54, null, temp_VbStyle8); return(null); } var vendorPayout = new VendorPayout(); var po = new Payout(); var taxes = po.Payout_Taxes; _taxManager.Load_Taxes(ref taxes); int totals = 0; foreach (Payout_Tax tax in taxes) { if (totals >= 4) { MessageType temp_VbStyle = (int)MessageType.Information + MessageType.OkOnly; vendorPayout.Message = _resourceManager.CreateMessage(offSet, 23, 90, null, temp_VbStyle); break; } if (tax.Tax_Active) { vendorPayout.Taxes.Add(new Tax { Description = _resourceManager.GetResString(offSet, 194) + tax.Tax_Name, Code = tax.Tax_Name, Amount = 0 }); totals++; } } var vendors = _stockService.GetAllVendors(); foreach (var vendor in vendors) { vendorPayout.Vendors.Add(new PayoutVendor { Code = vendor.Code, Name = vendor.Name }); } var reasons = _reasonService.GetReasons((char)ReasonType.Payouts); foreach (Return_Reason reason in reasons) { vendorPayout.Reasons.Add(new VendorReason { Code = reason.Reason, Description = reason.Description }); } return(vendorPayout); }
public void HandleEvent(OrderPaidEvent eventMessage) { var order = eventMessage.Order; var vendorIds = order.OrderItems.Select(m => m.Product.VendorId).Distinct(); //to store the vendor based order items var vendorItems = new Dictionary <int, IList <OrderItem> >(); //to store the vendors in a dictionary because there may be more than one vendors in one order var vendorsExtended = new Dictionary <int, Domain.ExtendedVendor>(); foreach (var vid in vendorIds) { vendorItems.Add(vid, order.OrderItems.Where(m => m.Product.VendorId == vid).ToList()); var ex = _extendedVendorService.GetExtendedVendor(vid); vendorsExtended.Add(vid, ex); } foreach (var vi in vendorItems) { var vendorId = vi.Key; var orderItems = vi.Value; var orderItemTotal = decimal.Zero; var discountTotal = decimal.Zero; if (_taxSettings.PricesIncludeTax) { orderItemTotal = orderItems.Sum(m => m.PriceInclTax); discountTotal = orderItems.Sum(m => m.DiscountAmountInclTax); } else { orderItemTotal = orderItems.Sum(m => m.PriceExclTax); discountTotal = orderItems.Sum(m => m.DiscountAmountExclTax); } orderItemTotal = orderItemTotal - discountTotal; //create a new payout for each vendor var vendorPayout = new VendorPayout { VendorId = vendorId, CommissionPercentage = vendorsExtended[vendorId] == null ? _extendedVendorSettings.DefaultCommissionPercentage : vendorsExtended[vendorId].CommissionPercentage, OrderId = order.Id, PayoutDate = null, Remarks = "", VendorOrderTotal = orderItemTotal, PayoutStatus = PayoutStatus.Pending, ShippingCharge = (vendorsExtended[vendorId] == null ? _extendedVendorSettings.DefaultShippingCharge : vendorsExtended[vendorId].ShippingCharge) * orderItems.Count }; _extendedVendorService.SaveVendorPayout(vendorPayout); } }
public void SaveVendorPayout(VendorPayout VendorPayout) { if (VendorPayout.Id == 0) { _vendorPayoutRepository.Insert(VendorPayout); } else { _vendorPayoutRepository.Update(VendorPayout); } }
public static VendorPayoutModel ToModel(this VendorPayout Payout, IOrderService _orderService) { var model = new VendorPayoutModel() { CommissionPercentage = Payout.CommissionPercentage, Id = Payout.Id, OrderId = Payout.OrderId, PayoutDate = Payout.PayoutDate, PayoutStatus = Payout.PayoutStatus, Remarks = Payout.Remarks, VendorId = Payout.VendorId, VendorOrderTotal = Payout.VendorOrderTotal, ShippingCharge = Payout.ShippingCharge, PayoutStatusName = Payout.PayoutStatus.ToString(), }; if (Payout.PayoutStatus == PayoutStatus.Cancelled) { model.CommissionAmount = 0; model.PayoutAmount = 0; model.VendorOrderTotal = 0; } else if (_orderService != null) { var order = _orderService.GetOrderById(Payout.OrderId); model.OrderDate = order.CreatedOnUtc; /* * var vendorItemTotalExShipping = Payout.VendorOrderTotal - model.ShippingCharge; * var vendorItemTotalOriginal = (vendorItemTotalExShipping * 100) / (100 + Payout.CommissionPercentage); * decimal commission = vendorItemTotalExShipping - vendorItemTotalOriginal; * model.CommissionAmount = commission; * model.PayoutAmount = vendorItemTotalOriginal;*/ model.PayoutAmount = GetPayoutAmount(Payout.VendorOrderTotal, Payout.CommissionPercentage); model.CommissionAmount = model.VendorOrderTotal - model.PayoutAmount; } return(model); }
public static VendorPayoutListModel ToListModel(this VendorPayout Payout, IOrderService _orderService) { var model = new VendorPayoutListModel() { CommissionPercentage = Payout.CommissionPercentage, Id = Payout.Id, OrderId = Payout.OrderId, PayoutDate = Payout.PayoutDate, PayoutStatus = Payout.PayoutStatus, Remarks = Payout.Remarks, VendorId = Payout.VendorId, VendorOrderTotal = Payout.VendorOrderTotal, PayoutStatusName = Payout.PayoutStatus.ToString() }; if (_orderService != null) { var order = _orderService.GetOrderById(Payout.OrderId); model.OrderId = order.Id; } return(model); }
public void DeleteVendorPayout(VendorPayout VendorPayout) { _vendorPayoutRepository.Delete(VendorPayout); }