Example #1
0
 private void CheckOnInputUpkzControllerSighting(BillDemand billDemand)
 {
     if (!SecurityEntityService.CheckThatSomebodyHasRole(BudgetRole.Controller))
     {
         EmailService.SendEmail("BD_NOT_FOUND_UPKZ_CONTROLLER", GetDefaultParameters(billDemand));
     }
 }
Example #2
0
 private void CheckOnInputUpkzHeadSighting(BillDemand billDemand)
 {
     if (!SecurityEntityService.CheckThatSomebodyHasRole(BudgetRole.UPKZHead))
     {
         EmailService.SendEmail("BD_NOT_FOUND_UPKZ_HEAD", GetDefaultParameters(billDemand));
     }
 }
Example #3
0
        private void SendEmailToEmployee(BillDemand bd, Employee employee, WorkflowState state)
        {
            var parameters = GetDefaultParameters(bd);

            parameters.Add("$BILLDEMANDLINK$", string.Format("{0}/BillDemand/?tid={1}", PublicPagesUrl, WorkflowTicketService.CreateTicket(employee.IdentityId, bd.Id, state.WorkflowStateName)));
            EmailService.SendEmail("BILL_DEMAND_NOTIFICATION", parameters, employee.Email);
        }
Example #4
0
 private BudgetDocumentKind GetDocumentKind(BillDemand billDemand)
 {
     if (!billDemand.DocKindId.HasValue)
     {
         return(BudgetDocumentKind.InBudget);
     }
     return(BudgetDocumentKind.All.First(p => p.Id == billDemand.DocKindId));
 }
Example #5
0
        private void SendOnInputLimitExecutorSighting(BillDemand billDemand)
        {
            var limits      = GetLimits(billDemand, false);
            var executorIds = new List <Guid>();

            limits.Where(lim => lim.ExecutorId.HasValue).ForEach(lim => executorIds.Add(lim.ExecutorId.Value));
            var employees = EmployeeService.GetEmployeesBySecurityTrusteeIdsForNotification(executorIds, billDemand.BudgetId, true);

            SendMailsToEmployee(employees, billDemand, WorkflowState.BillDemandLimitExecutorSighting);
        }
Example #6
0
        private void SendOnInputLimitManagerSighting(BillDemand billDemand)
        {
            var limits        = GetLimits(billDemand, false);
            var managerIds    = new List <Guid>();
            var sightedLimits = SightedByManagerLimitIds(billDemand);

            limits.Where(lim => lim.ManagerId.HasValue && !sightedLimits.Contains(lim.Id)).ForEach(lim => managerIds.Add(lim.ExecutorId.Value));
            var employees = EmployeeService.GetEmployeesBySecurityTrusteeIdsForNotification(managerIds, billDemand.BudgetId, true);

            SendMailsToEmployee(employees, billDemand, WorkflowState.BillLimitManagerSighting);
        }
Example #7
0
 public void SetTransferDate(Guid billDemandUid)
 {
     using (var scope = ReadCommittedSupressedScope)
     {
         using (var context = this.CreateContext())
         {
             BillDemand billDemand = GetBillDemand(context, billDemandUid);
             billDemand.TransferDate = DateTime.Now;
             context.SubmitChanges();
         }
         scope.Complete();
     }
 }
Example #8
0
        private void CheckOnInputLimitExecutorSighting(BillDemand billDemand)
        {
            List <Limit> limits = GetLimits(billDemand);

            foreach (var limit in limits)
            {
                if (!limit.ExecutorId.HasValue || !limit.Executor.Enabled || limit.Executor.Employees.Count(p => !p.IsDeleted && p.BudgetId == billDemand.BudgetId) <= 0)
                {
                    var parameters = GetDefaultParameters(billDemand);
                    parameters = AddLimitParameters(parameters, limit);
                    EmailService.SendEmail("BD_NOT_FOUND_LIMIT_EXECUTOR", parameters);
                }
            }
        }
Example #9
0
        private void SendOnInputHeadInitiatorSighting(BillDemand billDemand)
        {
            if (!billDemand.AuthorId.HasValue)
            {
                throw new InvalidOperationException("billDemand.AuthorId is null");
            }

            var trusteeIds = SecurityEntityService.GetHeadIds(billDemand.AuthorId.Value, billDemand.BudgetId);

            var employees = EmployeeService.GetEmployeesBySecurityTrusteeIdsForNotification(trusteeIds,
                                                                                            billDemand.BudgetId, true);

            SendMailsToEmployee(employees, billDemand, WorkflowState.BillDemandHeadInitiatorSighting);
        }
Example #10
0
 private IEnumerable <Guid> SightedByManagerLimitIds(BillDemand billDemand)
 {
     using (var scope = ReadUncommittedSupressedScope)
     {
         using (var context = this.CreateContext())
         {
             return
                 (context.WorkflowSightings.Where(
                      p =>
                      p.EntityId == billDemand.Id &&
                      p.SightingType == SightingType.BillDemandLimitManagerSighting.Id).Select(p => p.ItemId).
                  ToList());
         }
     }
 }
Example #11
0
 public void SetExternalParameters(Guid billDemandUid, BillDemandExternalState externalState)
 {
     using (var scope = ReadCommittedSupressedScope)
     {
         using (var context = this.CreateContext())
         {
             BillDemand billDemand = GetBillDemand(context, billDemandUid);
             billDemand.DateOfPerformance = externalState.PaymentDate;
             billDemand.AccountNumber     = externalState.DocumentNumber;
             context.SubmitChanges();
             context.spRecalcBillDemandCurrencySum(billDemandUid);
         }
         scope.Complete();
     }
 }
Example #12
0
 private Dictionary <string, string> GetDefaultParameters(BillDemand billDemand)
 {
     return(new Dictionary <string, string>()
     {
         {
             "$BILLDEMANDNUMBER$",
             billDemand.IdNumber.ToString(CultureInfo.CurrentCulture)
         },
         {
             "$BILLDEMANDDATE$",
             billDemand.AllocationDate.HasValue
                            ? billDemand.AllocationDate.Value.ToString(CultureInfo.CurrentCulture)
                            : "-"
         }
     });
 }
Example #13
0
        private void CheckOnInputHeadInitiatorSighting(BillDemand billDemand)
        {
            if (!billDemand.AuthorId.HasValue)
            {
                throw new InvalidOperationException("billDemand.AuthorId is null");
            }

            var trusteeIds = SecurityEntityService.GetHeadIds(billDemand.AuthorId.Value, billDemand.BudgetId);

            if (trusteeIds.Count() < 1)
            {
                var parameters = GetDefaultParameters(billDemand);
                parameters.Add("$INITIATOR$", billDemand.Author.Name);
                EmailService.SendEmail("BD_NOT_FOUND_INITIATOR_HEAD", parameters);
            }
        }
Example #14
0
        private void CheckOnInputInAccountingWithExport(BillDemand billDemand)
        {
            if (BillDemandBuinessService.IsBillDemandSkipInAccountingState(billDemand.Id))
            {
                return;
            }
            if (!billDemand.FilialId.HasValue || !SecurityEntityService.CheckThatSomebodyHasRoleInFilial(BudgetRole.Accountant, billDemand.FilialId.Value, billDemand.BudgetId))
            {
                var parameters = GetDefaultParameters(billDemand);
                if (billDemand.FilialId.HasValue && billDemand.Filial != null)
                {
                    parameters.Add("$FILIALNAME$", billDemand.Filial.Name);
                }
                else
                {
                    parameters.Add("$FILIALNAME$", "Не определено");
                }

                EmailService.SendEmail("BD_NOT_FOUND_ACCOUNTANT", parameters);
            }
        }
Example #15
0
 private List <Limit> GetLimits(BillDemand billDemand, bool loademployees = true)
 {
     using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
     {
         using (var context = this.CreateContext())
         {
             var dlo = new DataLoadOptions();
             dlo.LoadWith <BillDemandDistribution>(p => p.Demand);
             dlo.LoadWith <Demand>(p => p.Limit);
             if (loademployees)
             {
                 dlo.LoadWith <Limit>(p => p.Manager);
                 dlo.LoadWith <Limit>(p => p.Executor);
                 dlo.LoadWith <SecurityTrustee>(p => p.Employees);
             }
             context.LoadOptions            = dlo;
             context.DeferredLoadingEnabled = false;
             return(context.BillDemandDistributions.Where(p => p.BillDemandId == billDemand.Id).Select(
                        p => p.Demand.Limit).ToList());
         }
     }
 }
Example #16
0
        private void SendMailsToEmployee(IEnumerable <Employee> employees, BillDemand billDemand, WorkflowState state)
        {
            bool hasErrors         = false;
            var  errors            = new StringBuilder();
            var  distinctemployees = employees;//.Distinct();

            foreach (var employee in distinctemployees)
            {
                try
                {
                    SendEmailToEmployee(billDemand, employee, state);
                }
                catch (Exception ex)
                {
                    errors.AppendLine(ex.Message);
                    hasErrors = true;
                }
            }

            if (hasErrors)
            {
                throw new InvalidOperationException(errors.ToString());
            }
        }
Example #17
0
 private List <LimitSighter> GetLimitManagerSightersOperative(Budget2DataContext context, BillDemand billDemand)
 {
     return(billDemand.BillDemandDistributions.Where(
                p =>
                p.DemandId.HasValue && p.Demand.ExecutorStructId.HasValue).Select(
                p =>
                new LimitSighter {
         LimitId = p.Demand.ExecutorStructId.Value, SighterId = null
     }).
            Distinct().ToList());
 }
Example #18
0
 private bool IsBillDemandSkipInAccountingState(BillDemand billDemand)
 {
     return(billDemand.Filial != null && billDemand.Filial.IsSkipInAccountingState);
 }
Example #19
0
        public BillDemandForExport GetBillDemandForExport(Guid billDemandUid)
        {
            using (var scope = ReadCommittedSupressedScope)
            {
                using (var context = this.CreateContext())
                {
                    var dlo = new DataLoadOptions();
                    dlo.LoadWith <BillDemand>(p => p.Contract);
                    dlo.LoadWith <BillDemand>(p => p.Currency);
                    dlo.LoadWith <BillDemand>(p => p.Currency1);
                    dlo.LoadWith <BillDemand>(p => p.Filial);
                    dlo.LoadWith <BillDemand>(p => p.Counteragent);
                    dlo.LoadWith <BillDemand>(p => p.BillDemandContractMoneys);
                    dlo.LoadWith <Currency>(p => p.CurrencyRateActual);
                    dlo.LoadWith <Contract>(p => p.ContractMoneys);
                    dlo.LoadWith <Contract>(p => p.CustomerCounteragent);
                    //context.DeferredLoadingEnabled = false;
                    context.LoadOptions = dlo;

                    BillDemand billDemand = GetBillDemand(context, billDemandUid);

                    if (billDemand.ContractId == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ не привязанный к контракту BillDemandId = {0}",
                                      billDemand.Id));
                    }
                    if (billDemand.CurrencyId == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ для котрого не задана валюта BillDemandId = {0}",
                                      billDemand.Id));
                    }
                    if (billDemand.PaymentCurrencyId == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ для котрого не задана платежная валюта BillDemandId = {0}",
                                      billDemand.Id));
                    }

                    if (billDemand.CounteragentId == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ для котрого не задан Контрагент BillDemandId = {0}",
                                      billDemand.Id));
                    }

                    if (!billDemand.Currency.IsBase && billDemand.Currency.CurrencyRateActual == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ не найден актуальный курс BillDemandId = {0}",
                                      billDemand.Id));
                    }
                    if (billDemand.AllocationDate == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ для котрого не задана дата отправки на маршрут BillDemandId = {0}",
                                      billDemand.Id));
                    }

                    if (billDemand.FilialId == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ для котрого не задан Плательщик BillDemandId = {0}",
                                      billDemand.Id));
                    }

                    if (billDemand.Contract.CustomerCounteragent == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить расходный документ для конракта которого не задан контрагент заказчик BillDemandId = {0}",
                                      billDemand.Id));
                    }

                    if (billDemand.Contract.ExternalId == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Невозможно выгрузить контракт не загруженный из БОСС  BillDemandId = {0} (ExternalId = {1}) ",
                                      billDemand.Id, billDemand.Contract.ExternalId));
                    }

                    var billDemandForExport = new BillDemandForExport()
                    {
                        Id                   = billDemand.Id,
                        ContractId           = billDemand.Contract.ExternalId,
                        CurrencyCode         = billDemand.Currency1.IsBase ? billDemand.Currency.Code : billDemand.Currency1.Code,
                        CurrencyRevisionDate =
                            ((billDemand.CurrencyRateTypeId.HasValue &&
                              billDemand.CurrencyRateTypeId >= 2) || billDemand.Currency.IsBase)
                                                              ? billDemand.AllocationDate.Value
                                                              : billDemand.Currency.CurrencyRateActual.ReevaluationDate,
                        CustomerCounteragentId = billDemand.Contract.CustomerCounteragent.Number,
                        CounteragentId         = billDemand.Counteragent.Number,
                        Number       = billDemand.Number,
                        IdNumber     = billDemand.IdNumber,
                        SumWIthNDS   = billDemand.Sum,
                        NDSTaxValue  = billDemand.Currency1.IsBase ? (billDemand.NDSValue.HasValue ? billDemand.NDSValue.Value : (billDemand.Sum - (billDemand.SumWithoutNDS.HasValue ? billDemand.SumWithoutNDS.Value : 0))) : (billDemand.CurrencySum.HasValue ? billDemand.CurrencySum.Value : 0),
                        DocumentDate = billDemand.AllocationDate.Value,
                        AccountDate  = billDemand.AccountDate,
                        FirmCode     = billDemand.Filial.Code,
                        BudgetPartId = billDemand.BudgetPartId
                    };

                    billDemandForExport.PaymentPlanItemIds =
                        billDemand.Contract.ContractMoneys.Where(p => p.ExternalId.HasValue && billDemand.BillDemandContractMoneys.Count(bdcm => bdcm.ContractMoneyId == p.Id && bdcm.ToPayment) > 0).Select(
                            p => p.ExternalId.Value).Distinct().ToList();


                    var firstDistribution = billDemand.BillDemandDistributions.FirstOrDefault();
                    if (firstDistribution != null && firstDistribution.Demand != null)
                    {
                        if (firstDistribution.Demand.Project != null)
                        {
                            billDemandForExport.ProjectCode = firstDistribution.Demand.Project.Code;
                        }
                        if (firstDistribution.Demand.ExecutorStructDivision != null)
                        {
                            billDemandForExport.OPCode = firstDistribution.Demand.ExecutorStructDivision.Code;
                        }
                    }

                    var firstAllocation = billDemand.BillDemandAllocations.FirstOrDefault();
                    if (firstAllocation != null)
                    {
                        if (firstAllocation.CostArticle != null)
                        {
                            billDemandForExport.SmetaCode = firstAllocation.CostArticle.Code;
                        }
                        if (firstAllocation.CFO != null)
                        {
                            billDemandForExport.PPCode = firstAllocation.CFO.Code;
                        }
                    }


                    return(billDemandForExport);
                }
            }
        }
Example #20
0
        private void SendOnInputUpkzCuratorSighting(BillDemand billDemand)
        {
            var employees = SecurityEntityService.GetAllEmployeesInRole(BudgetRole.Curator, billDemand.BudgetId, true);

            SendMailsToEmployee(employees, billDemand, WorkflowState.BillDemandUPKZCuratorSighting);
        }
Example #21
0
 private bool IsBillDemandSupportExport(BillDemand billDemand)
 {
     return(billDemand.Filial.IsBillDemandExportable && billDemand.Contract != null && billDemand.Contract.CustomerCounteragent != null &&
            billDemand.Contract.CustomerCounteragent.Number.ToString(CultureInfo.InvariantCulture) == BossAvailiableExecutorCode);
 }
Example #22
0
 private bool CheckUPKZHeadMustSight(BillDemand billDemand)
 {
     return(billDemand.Sum >= Common.Settings.Instance.BillDemandWfLimitSum);
 }