Esempio n. 1
0
    public async Task <ExpenseModel> GetExpense(int id)
    {
        ExpenseModel      model  = new ExpenseModel();
        List <PayerModel> payers = new List <PayerModel>();
        var expense         = context.Expenses.ToList().FirstOrDefault(x => x.ExpenseId == id);
        var expenseinfolist = context.Expensesinfo.ToList().Where(x => x.ExpenseId == id);
        var sharelist       = context.Shareinfo.ToList().Where(x => x.ExpenseId == id);

        foreach (var item in expenseinfolist)
        {
            PayerModel payerModel = new PayerModel();
            var        user       = await UserManager.FindByIdAsync(item.UserId);

            payerModel.Payer  = user;
            payerModel.Amount = item.PaidAmouunt;
            payers.Add(payerModel);
        }


        foreach (var item in sharelist)
        {
            var user = await UserManager.FindByIdAsync(item.UserId);

            item.User = user;
        }

        model.Shares  = sharelist.ToList();
        model.Expense = expense;
        model.Payers  = payers;


        return(model);
    }
 /// <summary>
 /// 檢查「繳款人編號」長度
 /// </summary>
 /// <param name="payer"></param>
 private static void CheckPayerNoLen(SysMessageLog message, PayerModel payer)
 {
     if (payer.PayerNo.Length != payer.BizCustomer.PayerNoLen)
     {
         message.AddCustErrorMessage(MessageCode.Code1005, ResxManage.GetDescription <PayerModel>(p => p.PayerNo), payer.BizCustomer.PayerNoLen);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 檢查繳款人是否為約定扣款帳號
 /// </summary>
 /// <param name="message"></param>
 /// <param name="payer"></param>
 private static void CheckPayerType(SysMessageLog message, PayerModel payer)
 {
     if (payer.PayerType != PayerType.Account)
     {
         message.AddCustErrorMessage(MessageCode.Code1017, payer.PayerName, ResxManage.GetDescription(PayerType.Account));
     }
 }
 public static Payer FromModel(this PayerModel model)
 {
     return(new Payer
     {
         Amount = model.Amount,
         ParticipantId = model.ParticipantId
     });
 }
Esempio n. 5
0
        public ActionResult Save(PayerModel payer)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false));
            }

            payerManager.Save(new Payer {
                PayerId = payer.PayerId, Name = payer.Name, Logo = payer.Logo
            });

            return(Json(true));
        }
Esempio n. 6
0
        public ActionResult Edit(PayerModel payer, string payerId)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false));
            }

            var existingPayer = payerManager.Get(payerId);

            {
                existingPayer.Name    = payer.Name;
                existingPayer.Logo    = payer.Logo;
                existingPayer.PayerId = payer.PayerId;
            }

            payerManager.Update(existingPayer);

            return(Json(true));
        }
Esempio n. 7
0
    async Task <UserModel> IAccount.GetUserinfo(string id)
    {
        List <PayerModel> OF        = new List <PayerModel>();
        List <PayerModel> OT        = new List <PayerModel>();
        UserModel         userModel = new UserModel();

        userModel.User = await userManager.FindByIdAsync(id);

        userModel.Expenses     = expenserepo.GetUserExpense(id);
        userModel.Groups       = grouprepo.GetUserGroups(id).ToList();
        userModel.Activities   = activityrepo.GetUserActivities(id).ToList();
        userModel.Transactions = await transactionrepo.GetUsertransactionsAsync(id);


        var settelements = context.Settelements.ToList().Where(x => (x.BorrowerId == id || x.LenterId == id) && x.SettelementAmount > 0);

        var OWESTO = (from item in settelements
                      where item.BorrowerId == id
                      group item by item.LenterId into Owesto
                      orderby Owesto.Key
                      select new {
            name = Owesto.Key,
            amount = Owesto.Sum(x => x.SettelementAmount)
        }).ToList();

        var OWESFROM = (from item in settelements
                        where item.LenterId == id
                        group item by item.BorrowerId into Owesfrom
                        orderby Owesfrom.Key
                        select new {
            name = Owesfrom.Key,
            amount = Owesfrom.Sum(x => x.SettelementAmount)
        }).ToList();



        foreach (var item in OWESTO.ToList())
        {
            var user = await userManager.FindByIdAsync(item.name);

            PayerModel pmm = new PayerModel()
            {
                Amount  = 0,
                Payer   = user,
                PayerId = user.Id
            };
            foreach (var subitem in OWESFROM.ToList())
            {
                if (item.name == subitem.name)
                {
                    var result = item.amount - subitem.amount;
                    if (result > 0)
                    {
                        pmm.Amount = result;
                        OT.Add(pmm);
                        OWESTO.Remove(item);
                        OWESFROM.Remove(subitem);
                    }
                    else if (result < 0)
                    {
                        pmm.Amount = result * -1;
                        OF.Add(pmm);
                        OWESTO.Remove(item);
                        OWESFROM.Remove(subitem);
                    }
                    else if (result == 0)
                    {
                        OWESTO.Remove(item);
                        OWESFROM.Remove(subitem);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }

        if (OWESTO.Count == 0)
        {
            foreach (var item in OWESFROM.ToList())
            {
                var user = await userManager.FindByIdAsync(item.name);

                PayerModel pm = new PayerModel()
                {
                    Amount  = item.amount,
                    Payer   = user,
                    PayerId = user.Id,
                };

                OF.Add(pm);
            }
        }
        if (OWESFROM.Count == 0)
        {
            foreach (var item in OWESTO.ToList())
            {
                var user = await userManager.FindByIdAsync(item.name);

                PayerModel pm = new PayerModel()
                {
                    Amount  = item.amount,
                    Payer   = user,
                    PayerId = user.Id,
                };

                OT.Add(pm);
            }
        }

        if (OWESFROM.ToList().Count() > 0)
        {
            foreach (var item in OWESTO)
            {
                var user = await userManager.FindByIdAsync(item.name);

                PayerModel pmm = new PayerModel()
                {
                    Amount  = item.amount,
                    Payer   = user,
                    PayerId = user.Id
                };

                OT.Add(pmm);
            }
        }

        if (OWESTO.ToList().Count() > 0)
        {
            foreach (var item in OWESFROM)
            {
                var user = await userManager.FindByIdAsync(item.name);

                PayerModel pmm = new PayerModel()
                {
                    Amount  = item.amount,
                    Payer   = user,
                    PayerId = user.Id
                };

                OF.Add(pmm);
            }
        }



        userModel.Owesfrom = OF.ToList();
        userModel.Owsto    = OT.ToList();
        return(userModel);
    }
        public async Task <InvoiceModel> CreateAsync(string email, DateTime due_date, Item[] items, string return_url,
                                                     string expired_url, string notification_url, int tax_cents = 0, int discount_cents = 0, string customer_id = null, bool ignore_due_email = false,
                                                     string subscription_id = null, int?credits = null, Logs logs = null, List <CustomVariables> custom_variables = null, PayerModel payer = null, bool early_payment_discount = false, List <EarlyPaymentDiscounts> early_payment_discounts = null)
        {
            var invoice = new
            {
                email                   = email,
                due_date                = due_date.ToString("dd/MM/yyyy"),
                items                   = items,
                return_url              = return_url,
                expired_url             = expired_url,
                tax_cents               = tax_cents,
                discount_cents          = discount_cents,
                customer_id             = customer_id,
                ignore_due_email        = ignore_due_email,
                subscription_id         = subscription_id,
                credits                 = credits,
                logs                    = logs,
                custom_variables        = custom_variables,
                notification_url        = notification_url,
                early_payment_discount  = early_payment_discount,
                early_payment_discounts = early_payment_discounts,
                payer                   = payer
            };
            var retorno = await PostAsync <InvoiceModel>(invoice).ConfigureAwait(false);

            return(retorno);
        }
        public InvoiceModel Create(string email, DateTime due_date, Item[] items, string return_url = "",
                                   string expired_url     = "", string notification_url = "", int tax_cents = 0, int discount_cents                    = 0, string customer_id  = "", bool ignore_due_email = false,
                                   string subscription_id = "", int credits             = 0, Logs logs = null, List <CustomVariables> custom_variables = null, PayerModel payer = null, bool early_payment_discount = false, List <EarlyPaymentDiscounts> early_payment_discounts = null)
        {
            var retorno = CreateAsync(email, due_date, items, return_url, expired_url, notification_url, tax_cents,
                                      discount_cents, customer_id, ignore_due_email, subscription_id, credits, logs,
                                      custom_variables, payer, early_payment_discount, early_payment_discounts).Result;

            return(retorno);
        }
Esempio n. 10
0
 /// <summary>
 /// 檢查繳款人編號是否重複
 /// </summary>
 /// <param name="dataAccess"></param>
 /// <param name="payer"></param>
 /// <returns></returns>
 private static void CheckPayerNoExist(SysMessageLog message, ApplicationDbContext dataAccess, PayerModel payer)
 {
     if (dataAccess.Set <PayerModel>().Any(p =>
                                           !p.InternalId.Equals(payer.InternalId) &&
                                           p.CustomerCode.Equals(payer.CustomerCode) &&
                                           p.PayerNo.Equals(payer.PayerNo) &&
                                           (p.FormStatus == FormStatus.Saved) || p.FormStatus == FormStatus.Approved))
     {
         message.AddCustErrorMessage(MessageCode.Code1008, ResxManage.GetDescription <PayerModel>(p => p.PayerNo), payer.PayerNo);
     }
 }
Esempio n. 11
0
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            var addressHelper = new AddressHelper(_addressAttributeParser, _workContext);

            var invoiceDate = DateTime.Now.AddDays(3);

            string urlRedirect = string.Empty;

            // Act
            using (var apiInvoice = new Invoice())
            {
                string number     = string.Empty;
                string complement = string.Empty;
                string cnpjcpf    = string.Empty;

                addressHelper.GetCustomNumberAndComplement(postProcessPaymentRequest.Order.BillingAddress.CustomAttributes,
                                                           out number, out complement, out cnpjcpf);

                InvoiceModel invoice;

                var customVariables = new List <CustomVariables>
                {
                    new CustomVariables {
                        name  = IuguHelper.CODIGO_PEDIDO,
                        value = postProcessPaymentRequest.Order.Id.ToString()
                    }
                };

                var addressModel = new AddressModel()
                {
                    ZipCode  = postProcessPaymentRequest.Order.BillingAddress.ZipPostalCode,
                    District = postProcessPaymentRequest.Order.BillingAddress.Address2,
                    State    = postProcessPaymentRequest.Order.BillingAddress.StateProvince.Name,
                    Street   = postProcessPaymentRequest.Order.BillingAddress.Address1,
                    Number   = number,
                    City     = postProcessPaymentRequest.Order.BillingAddress.City,
                    Country  = postProcessPaymentRequest.Order.BillingAddress.Country.Name
                };

                var invoiceItems = new Item[postProcessPaymentRequest.Order.OrderItems.Count + 1];
                int i            = 0;
                var cartItems    = postProcessPaymentRequest.Order.OrderItems;
                foreach (var item in cartItems)
                {
                    var productID = string.IsNullOrWhiteSpace(item.Product.Sku)
                        ? item.Product.Id.ToString()
                        : item.Product.Sku;

                    var productName = ProductHelper.GetProcuctName(item);

                    productName = ProductHelper.AddItemDescrition(productName, item);

                    invoiceItems[i] = new Item()
                    {
                        description = productName,
                        price_cents = ObterPrecoCentavos(decimal.Round(item.UnitPriceInclTax, 2)),
                        quantity    = item.Quantity
                    };
                    i++;
                }

                invoiceItems[i] = new Item()
                {
                    description = postProcessPaymentRequest.Order.ShippingMethod,
                    price_cents = ObterPrecoCentavos(decimal.Round(postProcessPaymentRequest.Order.OrderShippingInclTax, 2)),
                    quantity    = 1
                };


                string email = !string.IsNullOrWhiteSpace(postProcessPaymentRequest.Order.Customer.Email)?
                               postProcessPaymentRequest.Order.Customer.Email:
                               postProcessPaymentRequest.Order.BillingAddress.Email;
                string name  = AddressHelper.GetFullName(postProcessPaymentRequest.Order.BillingAddress);
                string phone = AddressHelper.FormatarCelular(postProcessPaymentRequest.Order.BillingAddress.PhoneNumber);

                string phoneNumber     = AddressHelper.ObterNumeroTelefone(phone);
                string phonePrefix     = AddressHelper.ObterAreaTelefone(postProcessPaymentRequest.Order.BillingAddress.PhoneNumber);
                string urlRetorno      = _storeContext.CurrentStore.Url + "checkout/completed/" + postProcessPaymentRequest.Order.Id.ToString();
                string urlNotification = _storeContext.CurrentStore.Url + "Plugins/PaymentIugu/PaymentReturn";

                int descontoCentavos = 0;

                //Desconto aplicado na ordem subtotal
                if (postProcessPaymentRequest.Order.OrderSubTotalDiscountExclTax > 0)
                {
                    var discount = postProcessPaymentRequest.Order.OrderSubTotalDiscountExclTax;
                    discount          = Math.Round(discount, 2);
                    descontoCentavos += ObterPrecoCentavos(decimal.Round(discount, 2));
                }

                //desconto fixo, dado por cupom, os descontos podem ser cumulativos
                if (postProcessPaymentRequest.Order.OrderDiscount > 0)
                {
                    var discount = postProcessPaymentRequest.Order.OrderDiscount;
                    discount          = Math.Round(discount, 2);
                    descontoCentavos += ObterPrecoCentavos(decimal.Round(discount, 2));
                }


                var payer = new PayerModel()
                {
                    CpfOrCnpj   = cnpjcpf,
                    Address     = addressModel,
                    Email       = email,
                    Name        = name,
                    Phone       = phone,
                    PhonePrefix = phonePrefix
                };

                var invoiceRequest = new InvoiceRequestMessage(email, invoiceDate, invoiceItems)
                {
                    Payer           = payer,
                    ReturnUrl       = urlRetorno,
                    NotificationUrl = urlNotification,
                    DiscountCents   = descontoCentavos,
                    CustomVariables = customVariables.ToArray()
                };

                invoice = apiInvoice.CreateAsync(invoiceRequest, _iuguPaymentSettings.CustomApiToken).ConfigureAwait(false).GetAwaiter().GetResult();

                urlRedirect = invoice.secure_url;
            };


            _orderNoteService.AddOrderNote("Fatura IUGU Bradesco gerada.", true, postProcessPaymentRequest.Order);

            System.Web.HttpContext.Current.Response.Redirect(urlRedirect);
        }
Esempio n. 12
0
 public PayerViewModel(PayerModel payer)
 {
     this.Id   = payer.Id;
     this.Name = payer.Name;
     this.Logo = payer.Logo;
 }