예제 #1
0
        public static WFExchangeData PostModirDakhiliAction(ActionMethodParams actionMethodParams)
        {
            try
            {
                int contractId = actionMethodParams.InitialExchangeData[WfConstants.RelatedRecordIdKey].ConvertTo <int>();

                WFExchangeData ex = (WFExchangeData)actionMethodParams.WorkflowInstanceState.ExchangeData;

                ContractRule contractRule = new ContractRule(UnitOfWork);
                DomainClasses.Contract.Contract contract = contractRule.Find(contractId);



                if (contract == null)
                {
                    throw new OMFValidationException($" قرارداد با شناسه ثبت شده یافت نشد. شناسه: {contractId}");
                }


                if (actionMethodParams.ContinueInfo.ActionId == (int)WorkFlowActionType.TabdelPishghrardadBeGharardad)
                {
                    using (var uow = new UnitOfWork())
                    {
                        contract.Status       = Status.ConfirmationPreContract;
                        contract.ContractType = ContractType.RentTo;

                        // var contract_Sazes = uow.Repository<Contract_Saze>().Queryable().Where(x => x.ContractID == contract.ID).ToList();

                        foreach (var contract_Saze in contract.Contract_Sazes ?? new List <Contract_Saze>())
                        {
                            contract_Saze.Status      = Status.ConfirmationPreContract;
                            contract_Saze.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                        }

                        uow.Repository <DomainClasses.Contract.Contract>().Update(contract);


                        uow.SaveChanges();
                    }


                    InvoiceRule invoiceRule = new InvoiceRule(UnitOfWork);
                    var         invoice     = invoiceRule.ConvertContractToInvoice(contract.ID, NoeFactor.RentTo);

                    var document = invoiceRule.RegisterDocument(invoice, invoice.OrganId);

                    DocumentRule documentRule = new DocumentRule();
                    documentRule.Insert(document, invoice.OrganId);
                    documentRule.SaveChanges();
                }
                return(ex);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #2
0
        public static WFExchangeData PostModirAction(ActionMethodParams actionMethodParams)
        {
            try
            {
                int invoiceId = actionMethodParams.InitialExchangeData[WfConstants.RelatedRecordIdKey].ConvertTo <int>();

                WFExchangeData ex = (WFExchangeData)actionMethodParams.WorkflowInstanceState.ExchangeData;

                InvoiceRule invoiceRule = new InvoiceRule(UnitOfWork);
                Invoice     invoice     = invoiceRule.Find(invoiceId);

                if (invoice == null)
                {
                    throw new OMFValidationException($"فاکتوری با شناسه ثبت شده یافت نشد. شناسه: {invoiceId}");
                }

                if (actionMethodParams.ContinueInfo.ActionId == (int)WorkFlowActionType.TaeedVaKhateme)
                {
                    var document = invoiceRule.RegisterDocument(invoice, invoice.OrganId);

                    DocumentRule documentRule = new DocumentRule();
                    documentRule.Insert(document, invoice.OrganId);
                    documentRule.SaveChanges();

                    invoice.Status = NoeInsertFactor.WaitingToReceive;
                    invoiceRule.Update(invoice);

                    invoiceRule.SaveChanges();
                }
                return(ex);
            }
            catch (Exception ex1)
            {
                throw;
            }
        }
예제 #3
0
        public async Task <List <string> > SaveContract(ContractVM contractVM)
        {
            try
            {
                var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId);

                FinanYearRule finanYearRule = new FinanYearRule();
                var           finanYears    = await finanYearRule.GetAllByOrganIdAsync(organId);

                var finanYear = finanYears.Where(x => x.Closed == false && x.OrganId == organId);

                contractVM.Contract_Sazes = contractVM.Contract_Sazes.Where(x => x.Saze != null).ToList();

                foreach (var contract_Saze in contractVM.Contract_Sazes)
                {
                    if (contract_Saze.Saze != null)
                    {
                        contract_Saze.SazeId = contract_Saze.Saze.ID;
                    }

                    if (contract_Saze.NoeEjare != null)
                    {
                        contract_Saze.NoeEjareId = contract_Saze.NoeEjare.ID;
                    }

                    if (contract_Saze.DisplayTarikhShorou != null)
                    {
                        contract_Saze.TarikhShorou = PersianDateUtils.ToDateTime(contract_Saze.DisplayTarikhShorou);



                        if (contract_Saze.NoeEjareId == 1)
                        {
                            contract_Saze.TarikhPayan = contract_Saze.TarikhShorou.AddDays((double)contract_Saze.Quantity);
                        }
                        else if (contract_Saze.NoeEjareId == 2)
                        {
                            PersianCalendar pc = new PersianCalendar();
                            contract_Saze.TarikhPayan        = pc.AddMonths(contract_Saze.TarikhShorou, (int)contract_Saze.Quantity);
                            contract_Saze.DisplayTarikhPayan = PersianDateUtils.ToPersianDate(contract_Saze.TarikhPayan);
                        }
                    }
                }

                if (contractVM.Contact != null)
                {
                    contractVM.ContactId = contractVM.Contact.ID;
                }

                DomainClasses.Contract.Contract contract = new DomainClasses.Contract.Contract();
                Mapper.Map(contractVM, contract);
                contract.OrganId  = organId;
                contract.DateTime = PersianDateUtils.ToDateTime(contract.DisplayDate);


                ContractValidate validator = new ContractValidate();
                FluentValidation.Results.ValidationResult results = validator.Validate(contract);

                List <string> failurs = new List <string>();;

                if (!results.IsValid)
                {
                    foreach (var error in results.Errors)
                    {
                        failurs.Add(error.ErrorMessage);
                    }
                    return(failurs);
                }

                //  contract = savePaymentForContract(contract, contractVM);
                if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                    contractVM.ContractType == ContractType.RentFrom)
                {
                    contract.Status = Status.ConfirmationContract;
                }
                else if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                         contractVM.ContractType == ContractType.PreContract)
                {
                    contract.Status = Status.ConfirmationPreContract;

                    contract.ContractType = ContractType.RentTo;

                    // contract.Contract_Sazes = uow.Repository<Contract_Saze>().Queryable().Where(x => x.ContractID == contract.ID).ToList();

                    foreach (var contract_Saze in contract.Contract_Sazes ?? new List <Contract_Saze>())
                    {
                        contract_Saze.Status = Status.ConfirmationPreContract;
                        //contract_Saze.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                    }
                }
                else if (contractVM.ContractType == ContractType.PreContract && contractVM.Status == Status.SendPreContract)
                {
                    //nothing
                }
                else
                {
                    contract.Status = Status.Temporary;
                }

                if (contract.ID > 0)
                {
                    foreach (var contractSaze in contract.Contract_Sazes)
                    {
                        contractSaze.TarikhShorou = PersianDateUtils.ToDateTime(contractSaze.DisplayTarikhShorou);
                        contractSaze.ContractID   = contract.ID;

                        if (contractSaze.ID > 0)
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                        }

                        else
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Added;
                        }


                        foreach (var contarct_Saze_Bazareab in contractSaze.Contarct_Saze_Bazareabs)
                        {
                            contractSaze.HasBazareab = true;
                            if (contarct_Saze_Bazareab.ID > 0)
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Modified;
                            }
                            else
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Tarah in contractSaze.Contract_Saze_Tarahs)
                        {
                            contractSaze.HasTarah = true;

                            if (contract_Saze_Tarah.ID > 0)
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Chapkhane in contractSaze.Contract_Saze_Chapkhanes)
                        {
                            contractSaze.HasChap = true;

                            if (contract_Saze_Chapkhane.ID > 0)
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Nasab in contractSaze.Contract_Saze_Nasabs)
                        {
                            contractSaze.HasNasab = true;
                            if (contract_Saze_Nasab.ID > 0)
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Added;
                            }
                        }
                    }


                    foreach (var contract_PayRecevie in contract.Contract_PayRecevies)
                    {
                        if (contract_PayRecevie.ID > 0)
                        {
                            contract_PayRecevie.ContractId  = contract.ID;
                            contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                        }

                        else
                        {
                            contract_PayRecevie.ContractId = contract.ID;
                            contract_PayRecevie.IsReceive  = true;
                            contract_PayRecevie.OrganId    = organId;
                            contract_PayRecevie.Status     = Status.Temporary;
                            contract_PayRecevie.Type       = PayRecevieType.Sir;
                            contract_PayRecevie.Date       = DateTime.Now;

                            contract_PayRecevie.ContactId   = contract.ID;
                            contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Added;
                        }


                        foreach (var contract_DetailPayRecevie in contract_PayRecevie.Contract_DetailPayRecevies)
                        {
                            if (contract_DetailPayRecevie.ID > 0)
                            {
                                contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                contract_DetailPayRecevie.ObjectState           = ObjectState.Modified;
                            }
                            else
                            {
                                contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                contract_DetailPayRecevie.ObjectState           = ObjectState.Added;
                            }
                        }
                    }
                    contract.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                }

                else
                {
                    foreach (var contractSaze in contract.Contract_Sazes)
                    {
                        contractSaze.ContractID   = contract.ID;
                        contractSaze.TarikhShorou = PersianDateUtils.ToDateTime(contractSaze.DisplayTarikhShorou);

                        if (contractSaze.ID > 0)
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                        }

                        else
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Added;
                        }


                        foreach (var contarct_Saze_Bazareab in contractSaze.Contarct_Saze_Bazareabs)
                        {
                            contractSaze.HasBazareab = true;

                            if (contarct_Saze_Bazareab.NoeMozdBazryab == NoeMozd.Month)
                            {
                                contarct_Saze_Bazareab.Hazine = 0;
                            }

                            if (contarct_Saze_Bazareab.ID > 0)
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Modified;
                            }
                            else
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Tarah in contractSaze.Contract_Saze_Tarahs)
                        {
                            contractSaze.HasTarah = true;

                            if (contract_Saze_Tarah.NoeMozdTarah == NoeMozd.Month)
                            {
                                contract_Saze_Tarah.Hazine = 0;
                            }

                            if (contract_Saze_Tarah.ID > 0)
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Chapkhane in contractSaze.Contract_Saze_Chapkhanes)
                        {
                            contractSaze.HasChap = true;



                            if (contract_Saze_Chapkhane.ID > 0)
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Nasab in contractSaze.Contract_Saze_Nasabs)
                        {
                            contractSaze.HasNasab = true;

                            if (contract_Saze_Nasab.NoeMozdNasab == NoeMozd.Month)
                            {
                                contract_Saze_Nasab.Hazine = 0;
                            }

                            if (contract_Saze_Nasab.ID > 0)
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Added;
                            }
                        }
                    }

                    if (contract.Contract_PayRecevies != null && contract.Contract_PayRecevies.Count() > 0 &&
                        contract.Contract_PayRecevies[0].Contract_DetailPayRecevies != null && contract.Contract_PayRecevies[0].Contract_DetailPayRecevies.Count() > 0)
                    {
                        foreach (var contract_PayRecevie in contract.Contract_PayRecevies)
                        {
                            contract_PayRecevie.ContractId = contract.ID;
                            contract_PayRecevie.Date       = DateTime.Now;
                            contract_PayRecevie.IsReceive  = true;


                            if (contract_PayRecevie.ID > 0)
                            {
                                contract_PayRecevie.ContractId  = contract.ID;
                                contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                            }

                            else
                            {
                                contract_PayRecevie.ContractId  = contract.ID;
                                contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Added;
                            }


                            foreach (var contract_DetailPayRecevie in contract_PayRecevie.Contract_DetailPayRecevies)
                            {
                                if (contract_DetailPayRecevie.ID > 0)
                                {
                                    contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                    contract_DetailPayRecevie.ObjectState           = ObjectState.Modified;
                                }
                                else
                                {
                                    contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                    contract_DetailPayRecevie.ObjectState           = ObjectState.Added;
                                }
                            }
                        }
                    }
                    else
                    {
                        contract.Contract_PayRecevies = null;
                    }
                    contract.ObjectState = OMF.Common.Enums.ObjectState.Added;
                }


                this.UnitOfWork.RepositoryAsync <DomainClasses.Contract.Contract>().InsertOrUpdateGraph(contract);



                //  ContactRule contactRule = new ContactRule();
                //   await contactRule.UpdateContact(invoice.InvoiceType, invoice.ContactId);



                await this.UnitOfWork.SaveChangesAsync();

                if (contractVM.ID <= 0)
                {
                    if ((SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                         contractVM.ContractType == ContractType.PreContract) || (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                                                                                  contractVM.Status == Status.ConfirmationContract))
                    {
                        InvoiceRule invoiceRule = new InvoiceRule();
                        var         invoice     = invoiceRule.ConvertContractToInvoice(contract.ID, NoeFactor.RentTo);

                        var document = invoiceRule.RegisterDocument(invoice, invoice.OrganId);

                        DocumentRule documentRule = new DocumentRule();
                        await documentRule.InsertAsync(document, invoice.OrganId);

                        await documentRule.SaveChangesAsync();

                        invoice.DocumentID = document.ID;
                        invoiceRule.Update(invoice);
                        await invoiceRule.SaveChangesAsync();
                    }
                    else if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                             contractVM.ContractType == ContractType.RentTo)
                    {
                        InvoiceRule invoiceRule = new InvoiceRule();
                        invoiceRule.ConvertContractToInvoice(contract.ID, NoeFactor.RentFrom);
                    }
                }



                return(failurs);
            }
            catch (Exception ex)
            {
                var p = ex;
                throw;
            }
        }