Ejemplo 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)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Add([Bind("BankTransId,AccountBankId,Description,CreateDate,DueDate,MidleDesc,ExpenseTransId,RevenueTransId,Total,Signal,BusinessEntityId,ChartAccountId")] BankTrans bankTrans, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _bankTransServices.AddAsync(bankTrans);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            LoadDataView();
            return(View(bankTrans));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Add([Bind("InvoiceId,TaxOperationId,RevisionNumber,InvoiceDate,InvoiceCode,DueDate,ShipDate,Status,OnlineInvoiceFlag,InvoiceNumber,PurchaseOrderNumber,AccountNumber,CustomerId,SalesPersonId,CarrierId,WarehouseId,BillToAddressId,ShipToAddressId,CarrierTrackingNumber,FreightType,Volumes,Package,CarrierTruckId,Weight,TotalWeight,SubTotal,TaxAmt,Freight,TotalDue,Comment,ModifiedDate,BusinessEntityId,OrderQty,ProductId,Finality,InvoiceTp,Number,Sequence,ProductId,Name,Qty,UnitPrice,TaxProduction,TaxSales,CodOper,Discount,Total,CustomerName")] Invoice invoice, List <InvoiceProductModel> product, bool continueAdd)
        {
            if (invoice.Number == 0)
            {
                invoice.Number = (_invoiceServices.Query(a => a.Sequence == invoice.Sequence).Max(p => (int?)p.Number) ?? 0) + 1;
            }


            product.RemoveAll(e => e.ProductId == 0);

            ModelState.Clear();
            var validInvoice = TryValidateModel(invoice);
            var validProduct = TryValidateModel(product);

            if (validInvoice)
            {
                if (product.Any())
                {
                    invoice.BusinessEntityId = _BusinessId;
                    List <InvoiceDetail> invoiceDetailList = _invoiceExtension.CreateInvoiceDetail(product, invoice).ToList();
                    invoice.SubTotal = invoiceDetailList.Sum(a => a.LineTotal);
                    invoiceDetailList.ForEach(a => _invoinceDetailsServices.AddAsync(a, false));
                    ViewData["products"] = invoiceDetailList;
                }
                else
                {
                    await _invoiceServices.AddAsync(invoice, false);
                }


                try
                {
                    await _context.SaveChangesAsync();

                    ErrorMessage = $"Nota incluída com sucesso { invoice.Number}";
                    return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
                }
                catch (System.Exception e)
                {
                    ErrorMessage = $"Erro na inclusão da Nota: { e }";
                    return(View(invoice));
                }
            }
            string messages = string.Join("; ", ModelState.Values
                                          .SelectMany(x => x.Errors)
                                          .Select(x => x.ErrorMessage));

            ErrorMessage = $"Erro, Nota inválida par alnaçamento: { messages }";

            LoadViewData();
            return(View(invoice));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Add([Bind("TaxOperationId,Name,TaxFunction,TaxWay,DefaultCode,StockTrigger,CostTrigger,BusinessEntityId")] TaxOperation taxOperation, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _taxOperationServices.AddAsync(taxOperation);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(taxOperation));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Add([Bind("ClassId,Name,BusinessEntityId")] ClassProduct classProduct, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _classProductServices.AddAsync(classProduct);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(classProduct));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Add([Bind("AccountBankId,Name,Active,BusinessEntityId,Code,Agency,DigitAgency,Account,DigitAccount")] AccountBank bank, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _bankServices.AddAsync(bank);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(bank));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Add([Bind("TaxGroupId,Name,BusinessEntityId")] TaxGroup taxGroup, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _taxGroupServices.AddAsync(taxGroup);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(taxGroup));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Add([Bind("WarehouseId,Name,BusinessEntityId,DefaultLocation")] Location warehouse, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _warehouseServices.AddAsync(warehouse);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(warehouse));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Add([Bind("CountryId,Name,MiddleName,CountryRegionCode,SpecialCodeRegion")] Country country, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _countryServices.AddAsync(country);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(country));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Add([Bind("ChartAccountId,Name,Type,CreateDate,ModifiedDate,Active,BusinessEntityId")] CategoryFinancial categoryFinancial, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _categoryFinancialServices.AddAsync(categoryFinancial);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(categoryFinancial));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Add([Bind("CategoryId,Name,CreateDate,ModifiedDate,BusinessEntityId")] CategoryPerson CategoryPerson, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _categoryPersonServices.AddAsync(CategoryPerson);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(CategoryPerson));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Add([Bind("CostCenterId,Name,Active,BusinessEntityId")] CostCenter costCenter, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _costCenterServices.AddAsync(costCenter);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(costCenter));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Add([Bind("ConditionId,Name,PaymentQty,PaymentDays,Tax,PaymentUse,Active,Deleted,BusinessEntityId")] Condition condition, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _conditionServices.AddAsync(condition);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            return(View(condition));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Add([Bind("StateProvinceId,StateProvinceCode,IsOnlyStateProvinceFlag,Name,CountryID")] StateProvince stateProvince, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _stateProvinceServices.AddAsync(stateProvince);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            ViewData["CountryID"] = new SelectList(_countryServices.GetAll(), "CountryId", "Name");
            return(View(stateProvince));
        }
Ejemplo n.º 15
0
        private BusinessEntity IncludeBusinessEntity(string name, string email, string externalcode)
        {
            var obj = new BusinessEntity(
                new SingleName(name),
                new EmailAddress(email),
                externalcode);

            var x = _businessEntityServices.AddAsync(obj);

            return(x.Result);
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Add([Bind("CityId,Name,MiddleName,SpecialCodeRegion,StateProvinceId")] City city, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                await _cityServices.AddAsync(city);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            ViewData["StateProvinceId"] = new SelectList(_stateProvinceServices.GetAll(), "StateProvinceId", "Name");
            return(View(city));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Inventory([Bind("Id,BusinessEntityID,LocationId,ProductId,VarId,Shelf,Bin,CreateDate,Description,NumberDoc,Quantity,Signal")] ProductInventory data)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _productInventoryServices.AddAsync(data);

                    ErrorMessage = $"Movimentação efetuada com sucesso";
                }
                catch (System.Exception e)
                {
                    ErrorMessage = $"Erro na Movimentação {(string.IsNullOrEmpty(e.Message) ? "" : e.Message)}";
                }
            }
            else
            {
                ErrorMessage = $"Erro na movimentação";
            }

            return(RedirectToAction(nameof(List)));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Add([Bind("PersonId,PersonCode,FirstName,LastName,RegistrationCode," +
                                                    "RegistrationState,Type,PersonType,CategoryId,Email,Image,Comments,CreateDate,ModifiedDate,Active,Deleted,BusinessEntityId,avatarImage," +
                                                    "PostalCode,StreetAddress,Number,StreetAddressLine2,StreetAddressLine3,District,CityId,StateProvinceId,SpatialLocation," +
                                                    "CityName", "StateProvinceName", "CityCode", "AddressId", "Phone")] PersonModel data, bool continueAdd, IFormFile files)
        {
            var address = Mapper.Map <PersonModel, Address>(data);
            var person  = Mapper.Map <PersonModel, Person>(data);

            if (!string.IsNullOrEmpty(person.RegistrationCode))
            {
                person.RegistrationCode = Regex.Match(person.RegistrationCode, @"\d+").Value;
            }
            var addressperson = new PersonAddress()
            {
                Address = address, Person = person
            };

            if (ModelState.IsValid)
            {
                person.PersonCode        = (_personServices.Query().Max(p => (int?)p.PersonCode) ?? 0) + 1;
                person.BusinessEntityId  = _BusinessId;
                address.BusinessEntityId = _BusinessId;
                try
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        person.avatarImage.CopyTo(memoryStream);
                        person.Image = memoryStream.ToArray();
                    }
                }
                catch {; }
                //await _personServices.AddAsync(person);
                await _personAddressServices.AddAsync(addressperson);

                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            LoadViewData();
            return(View(person));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Add([Bind("ProductId,Name,ProductNumber,Manufacturer,Ean,HsCode,HsCodeTax,Location,MakeFlag,VariableFlag,FinishedGoodsFlag,SafetyStockLevel,MaximumStocklevel,ReorderPoint,StandardCost,ListPrice,SizeUnitMeasureCode,Weight,WeightTotal,Height,Width,Length,DaysToManufacture,ProductAttribute,ProductSourceId,ClassId,CategoryId,TaxGroupId,TaxIva,TaxImport,TaxProduction,TaxSale,SellStartDate,SellEndDate,ModifiedDate,CreateDate,Active,BusinessEntityId,Deleted,Image,Product,InitialStock")] Product product, List <IFormFile> Image, decimal?InitialStock, bool continueAdd)
        {
            if (ModelState.IsValid)
            {
                if (Image.Any())
                {
                    foreach (var image in Image)
                    {
                        if (image.Length > 0)
                        {
                            using (var memoryStream = new MemoryStream())
                            {
                                image.CopyTo(memoryStream);
                                var newimage = new Image()
                                {
                                    BusinessEntityId   = _BusinessId,
                                    Active             = true,
                                    Comments           = "",
                                    CreateDate         = System.DateTime.Now.Date,
                                    Deleted            = false,
                                    LargeImage         = memoryStream.ToArray(),
                                    LargeImageFileName = image.FileName,
                                    ModifiedDate       = System.DateTime.Now.Date
                                };
                                product.BusinessEntityId = _BusinessId;
                                var productimage = new ProductImage()
                                {
                                    BusinessEntityId = _BusinessId,
                                    CreateDate       = System.DateTime.Now.Date,
                                    Image            = newimage,
                                    IsPrimary        = true,
                                    Product          = product
                                };

                                await _productImageServices.AddAsync(productimage, false);
                            }
                        }
                    }
                    await _context.SaveChangesAsync();
                }
                else
                {
                    await _productServices.AddAsync(product);
                }

                if (InitialStock.HasValue && InitialStock.Value > 0)
                {
                    var location = _locationServices.SingleOrDefaultAsync(a => a.DefaultLocation == true).Result;
                    if (location != null)
                    {
                        var stockInicial = new ProductInventory()
                        {
                            Bin = 0,
                            BusinessEntityId = _BusinessId,
                            Description      = "Inicial",
                            LocationId       = location.WarehouseId,
                            ProductId        = product.ProductId,
                            NumberDoc        = product.ProductId.ToString(),
                            Quantity         = InitialStock.Value,
                            Signal           = 1
                        };
                        await _productInventoryServices.AddAsync(stockInicial);
                    }
                }
                ErrorMessage = $"Cadastro efetuado com sucesso";
                return(continueAdd ? RedirectToAction(nameof(Add)) : RedirectToAction(nameof(List)));
            }
            LoadViewData();
            return(View(product));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Edit(int id, [Bind("BankTransId,AccountBankId,Description,CreateDate,DueDate,MidleDesc,ExpenseTransId,RevenueTransId,Total,Signal,BusinessEntityId,ChartAccountId")] BankTrans bankTrans, bool continueAdd, bool addTrash)
        {
            if (id != bankTrans.BankTransId)
            {
                return(NotFound());
            }
            typeof(BankTrans).GetProperty("Deleted").SetValue(bankTrans, addTrash);
            BankTrans originalValue = await _bankTransServices.SingleOrDefaultAsync(a => a.BankTransId == id);

            LoadDataView();


            if (ModelState.IsValid)
            {
                bankTrans.Total = originalValue.Total;
                await _bankTransServices.UpdateAsync(bankTrans, false);

                if (addTrash)
                {
                    BankTrans reversal = new BankTrans()
                    {
                        AccountBankId    = bankTrans.AccountBankId,
                        BusinessEntityId = bankTrans.BusinessEntityId,
                        ChartAccountId   = bankTrans.ChartAccountId,
                        CreateDate       = bankTrans.CreateDate,
                        Deleted          = false,
                        Description      = bankTrans.Description,
                        DueDate          = bankTrans.DueDate,
                        ExcludeId        = id,
                        Total            = bankTrans.Total,
                        MidleDesc        = "EST:" + bankTrans.BankTransId.ToString(),
                        Signal           = bankTrans.Signal == 1 ? 2 : 1
                    };


                    if (bankTrans.RevenueTransId.HasValue)
                    {
                        var revenueTransLanc = await _revenueTransServices.SingleOrDefaultAsync(a => a.RevenueTransId == bankTrans.RevenueTransId);

                        var revenue = await _revenueServices.SingleOrDefaultAsync(a => a.RevenueId == revenueTransLanc.RevenueId);

                        reversal.MidleDesc = "EST:" + revenue.RevenueNumber + "/" + revenue.RevenueSeq.ToString();
                        RevenueTrans reversalrevenueTrans = new RevenueTrans()
                        {
                            AccountBankId    = revenueTransLanc.AccountBankId,
                            BusinessEntityId = revenueTransLanc.BusinessEntityId,
                            CreateDate       = revenueTransLanc.CreateDate,
                            Description      = revenueTransLanc.Description,
                            Midledesc        = "EST:" + revenue.RevenueNumber + "/" + revenue.RevenueSeq.ToString(),
                            ConditionId      = revenueTransLanc.ConditionId,
                            RevenueId        = revenueTransLanc.RevenueId,
                            Signal           = revenueTransLanc.Signal == 3 ? 3 : revenueTransLanc.Signal == 1 ? 2 : 1,
                            Total            = revenueTransLanc.Total
                        };
                        await _revenueTransServices.AddAsync(reversalrevenueTrans, false);

                        if (revenue.DuePayment.HasValue)
                        {
                            revenue.DuePayment = null;
                            await _revenueServices.UpdateAsync(revenue, false);
                        }
                    }

                    if (bankTrans.ExpenseTransId.HasValue)
                    {
                        var expenseTransLanc = await _expenseTransServices.SingleOrDefaultAsync(a => a.ExpenseTransId == bankTrans.ExpenseTransId);

                        var expense = await _expenseServices.SingleOrDefaultAsync(a => a.ExpenseId == expenseTransLanc.ExpenseId);

                        reversal.MidleDesc = "EST:" + expense.ExpenseNumber + "/" + expense.ExpenseSeq.ToString();
                        ExpenseTrans reversalexpenseTransLanc = new ExpenseTrans()
                        {
                            AccountBankId    = expenseTransLanc.AccountBankId,
                            BusinessEntityId = expenseTransLanc.BusinessEntityId,
                            CreateDate       = expenseTransLanc.CreateDate,
                            Description      = expenseTransLanc.Description,
                            Midledesc        = "EST:" + expense.ExpenseNumber + "/" + expense.ExpenseSeq.ToString(),
                            ConditionId      = expenseTransLanc.ConditionId,
                            ExpenseId        = expenseTransLanc.ExpenseId,
                            Signal           = expenseTransLanc.Signal == 3 ? 3 : expenseTransLanc.Signal == 1 ? 2 : 1,
                            Total            = expenseTransLanc.Total
                        };
                        await _expenseTransServices.AddAsync(reversalexpenseTransLanc, false);

                        if (expense.DuePayment.HasValue)
                        {
                            expense.DuePayment = null;
                            await _expenseServices.UpdateAsync(expense, false);
                        }
                    }

                    await _bankTransServices.AddAsync(reversal, false);
                }

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(continueAdd ? RedirectToAction(nameof(Edit), new { id = bankTrans.BankTransId }) : RedirectToAction(nameof(List)));
            }
            return(View(bankTrans));
        }