Exemplo n.º 1
0
        public async Task <IActionResult> PayAccount([Bind("RevenueId,DueDate,AccountBankId,ConditionId,Payment,Tax,Discont,Comment,Active,Image,Id")] PayAccount data, bool Active, List <IFormFile> Image)
        {
            Revenue revenue = await _revenueServices.SingleOrDefaultAsync(a => a.RevenueId == data.RevenueId);

            if (data.Payment.HasValue)
            {
                RevenueTrans revenueTrans = _financialExtension.GetRevenueTrans(data, _BusinessId, "PAG", revenue.DueDate.HasValue ? 2 : 3);
                BankTrans    bankTrans    = _financialExtension.GetBankTrans(data, revenueTrans, _BusinessId, revenue.ChartAccountId);
                //await _revenueTransServices.AddAsyncNoSave(revenue);
                await _bankTransServices.AddAsync(bankTrans, false);
            }
            if (data.Tax.HasValue)
            {
                RevenueTrans revenueTrans = _financialExtension.GetRevenueTrans(data, _BusinessId, "JUR", 1);
                await _revenueTransServices.AddAsync(revenueTrans, false);
            }
            if (data.Discont.HasValue)
            {
                RevenueTrans revenueTrans = _financialExtension.GetRevenueTrans(data, _BusinessId, "DIS", 2);
                await _revenueTransServices.AddAsync(revenueTrans, false);
            }
            if (data.Active)
            {
                revenue.DuePayment = data.DueDate;
                await _revenueServices.UpdateAsync(revenue, false);
            }
            var insert = await _revenueTransServices.SaveAsync();

            return(RedirectToAction(nameof(List)));
        }