Пример #1
0
        private (PkudatYomanShura[] shuras, bool isBalanced) GeneratePkudatYoman(GeneralBillingSummary dbSummary, DateTime dateOfRegistration, SupplierEntity supplier = null)
        {
            string dateOfRegistrationString = dateOfRegistration.ToString("yyyyMMdd");
            string DateOfValueString        = dbSummary.DateOfValue.ToString("yyyyMMdd");

            if (dbSummary != null)
            {
                supplier = supplier == null ? new SuppliersService(context).GetSuppliersByCustomer(new CustomerEntity {
                    Id = dbSummary.CustomerId
                }).FirstOrDefault(x => x.Id == dbSummary.SupplierId && x.IsEnable):supplier;
                var budgetsContracts = new BudgetContractService(context).GetRelationshipBySupplier(supplier);
                var contracts        = new ContractsService(context).GetBySupplier(supplier).Result;
                var banks            = new BankAccountsService(context).GetBySupplier(supplier);
                switch (Convert.ToInt32(dbSummary.SupplierId))
                {
                case (int)Enums.Suppliers.Bezek:
                    return(createPkudaForBezek(dbSummary, dateOfRegistrationString, supplier, DateOfValueString, budgetsContracts, contracts, banks).Result);

                case (int)Enums.Suppliers.Electricity:
                    return(createPkudaForElectricity(dbSummary, dateOfRegistrationString, supplier, DateOfValueString, budgetsContracts, contracts, banks).Result);

                default:
                    return(createPkudaForPrivateSupplier(dbSummary, dateOfRegistrationString, supplier, DateOfValueString, budgetsContracts, contracts, banks).Result);
                }
            }
            return(null, false);
        }
        private ChartEntity[] getBudgetInfo(SupplierEntity supplier, ChartEntity[] contracts)
        {
            Dictionary <long, decimal> chartEntitiesDictionary = new Dictionary <long, decimal>();
            var     budegtsContracts = new BudgetContractService(context).GetRelationshipBySupplier(supplier);
            decimal amount           = 0;

            foreach (var contract in contracts)
            {
                var budget = budegtsContracts.FirstOrDefault(x => x.ContractId == contract.TopicId);
                if (budget != null)
                {
                    if (chartEntitiesDictionary.TryGetValue(budget.BudgetId, out amount))
                    {
                        chartEntitiesDictionary[budget.BudgetId] += amount * Convert.ToDecimal(budget.Precent) / 100;
                    }
                    else
                    {
                        chartEntitiesDictionary.Add(budget.BudgetId, contract.Amount * Convert.ToDecimal(budget.Precent) / 100);
                    }
                }
            }
            return(chartEntitiesDictionary.Select(x => new ChartEntity {
                TopicId = x.Key, Amount = x.Value
            }).ToArray());
        }
Пример #3
0
        public async Task <bool> AddRelationshipByFile(FileEntity fileEntity)
        {
            var pck = new ExcelPackage();

            pck.Load(fileEntity.File.OpenReadStream());
            try
            {
                SupplierEntity supplier = new SupplierEntity
                {
                    Id         = fileEntity.SupplierId,
                    CustomerId = fileEntity.CustomerId
                };
                var result = await Task.Run(() =>
                {
                    var excel        = pck.Workbook.Worksheets.First();
                    var budgets      = new BudgetsService(context).GetBySupplier(supplier);
                    var contracts    = new ContractsService(context).GetBySupplier(supplier).Result;
                    var relationship = new BudgetContractService(context).GetRelationshipBySupplier(supplier);
                    for (int rowNum = 2; rowNum <= excel.Dimension.End.Row; rowNum++)
                    {
                        if (!string.IsNullOrEmpty(excel.Cells[rowNum, 1].Text))
                        {
                            handleRelationShipsExcel(excel, rowNum, contracts, budgets, relationship, supplier);
                        }
                        else
                        {
                            break;
                        }
                    }
                    return(true);
                });

                pck.Dispose();
                await context.SaveChangesAsync();

                return(result);
            }
            catch (Exception e)
            {
                pck.Dispose();
                throw e;
            }
        }