Exemplo n.º 1
0
        /// <summary>
        /// Method to update visit group and create a new client visit for fund
        /// </summary>
        /// <param name="dbfFilePath">DBF file that contains information to update</param>
        /// <returns>Result of updating</returns>
        public List <ClientVisit.UpdateResultData> ClientVisit_UpdateFundDbf(User user, string dbfFilePath)
        {
            BSOBusinessLogic bsoBusinessLogic = new BSOBusinessLogic();
            List <ClientVisit.UpdateData>       dataToUpdate = ClientVisitReportDao.Instance.GetUpdateDataFromDbf(dbfFilePath);
            List <ClientVisit.UpdateResultData> results      = new List <ClientVisit.UpdateResultData>();

            foreach (var updateClientVisitItem in dataToUpdate)
            {
                var clientVisits = FindClientVisitsToUpdate(updateClientVisitItem);

                ClientVisitInfo lastClientVisitInfo = clientVisits.OrderBy(v => v.Id).LastOrDefault();

                if (lastClientVisitInfo != null && (lastClientVisitInfo.Status.Id == ClientVisitStatuses.AnswerPending.Id ||
                                                    lastClientVisitInfo.Status.Id == ClientVisitStatuses.AnswerPending.Id ||
                                                    lastClientVisitInfo.Status.Id == ClientVisitStatuses.SubmitPending.Id ||
                                                    lastClientVisitInfo.Status.Id == ClientVisitStatuses.SentToGoznak.Id ||
                                                    lastClientVisitInfo.Status.Id == ClientVisitStatuses.Processed.Id ||
                                                    lastClientVisitInfo.Status.Id == ClientVisitStatuses.Comment.Id))
                {
                    ClientVisit visit = ClientVisit_Get(lastClientVisitInfo.Id);

                    // create new clientVisit to update policy information in the fund
                    if (visit.Status.Id != ClientVisitStatuses.PolicyReadyForClient.Id)
                    {
                        ClientVisit.SaveData  data           = BuildUpdatedClientVisitSaveData(updateClientVisitItem, visit);
                        ClientVisitSaveResult updatingResult = ClientVisit_Save(user, data);

                        //если bso будет найден - ему меняем статус на "Выдан клиенту"
                        BSO bso = new BSO();
                        bso = bsoBusinessLogic.BSO_GetByNumber(updateClientVisitItem.TemporaryPolicyNumber);
                        if (bso != null)
                        {
                            if (bso.Status.Id == (long)ListBSOStatusID.OnDelivery || bso.Status.Id == (long)ListBSOStatusID.OnStorage)
                            {
                                bso.Status.Id       = (long)ListBSOStatusID.OnClient;
                                bso.UserId          = user.Id;
                                bso.DeliveryPointId = data.DeliveryPointId == null ? bso.DeliveryPointId : data.DeliveryPointId; //Если точка пустая - оставляем Точку, кот. была в БСО
                                bso.StatusDate      = data.TemporaryPolicyDate == null ? data.StatusDate : data.TemporaryPolicyDate;
                                bso.Comment         = string.Format("Изменение статуса при загрузке DBF (Загрузить DBF из фонда)");
                                bso.VisitGroupId    = updatingResult.VisitGroupId;
                            }
                            else
                            {
                                //если bso уже выдан клиенту - то дальнейшие действия с БСО не имеют значения
                                bso = null;
                            }
                        }

                        // set status for created client visit
                        ClientVisit_SetStatus(user, updatingResult.ClientVisitID, ClientVisitStatuses.PolicyReadyForClient.Id, true);
                        if (bso != null)
                        {
                            bsoBusinessLogic.BSO_Save(new BSO.SaveData(bso));
                        }
                        results.Add(new ClientVisit.UpdateResultData(updateClientVisitItem, true, "Успешно", visit)
                        {
                            Status = ClientVisitStatuses.PolicyReadyForClient
                        });
                    }
                    else
                    {
                        results.Add(new ClientVisit.UpdateResultData(updateClientVisitItem, true, "Заявка на выдачу была создана ранее", visit));
                    }
                }
                else
                {
                    results.Add(new ClientVisit.UpdateResultData(updateClientVisitItem, true, "Заявка в подходящем статусе не найдена"));
                }
            }
            return(results);
        }