public IActionResult DetalhesProposta(string id, string version = "")
        {
            UserAccessesViewModel UPerm = DBUserAccesses.GetByUserAreaFunctionality(User.Identity.Name, Enumerations.Features.Propostas);

            if (UPerm != null && UPerm.Read.Value)
            {
                Contratos cContract = null;
                if (version != "")
                {
                    cContract = DBContracts.GetByIdAndVersion(id, int.Parse(version));
                }
                else
                {
                    cContract = DBContracts.GetByIdLastVersion(id);
                }

                if (cContract != null && cContract.Arquivado == true)
                {
                    UPerm.Update = false;
                }

                ViewBag.ContractNo   = id ?? "";
                ViewBag.VersionNo    = version ?? "";
                ViewBag.UPermissions = UPerm;
                return(View());
            }
            else
            {
                return(RedirectToAction("AccessDenied", "Error"));
            }
        }
示例#2
0
        public ProjectBillingAuthorization(string projectNo, string userName, string navDatabaseName, string navCompanyName)
        {
            this.navCompanyName  = navCompanyName;
            this.navDatabaseName = navDatabaseName;
            this.userName        = userName;

            this.project = DBProjects.GetById(projectNo).ParseToViewModel();
            if (project != null)
            {
                this.contract = DBContracts.ParseToViewModel(DBContracts.GetByIdLastVersion(project.ProjectNo), navDatabaseName, navCompanyName);
            }

            if (project != null)
            {
                this.Movements = GetProjectMovements(null);
            }
            LoadBillingResume();
        }
示例#3
0
        public static async Task <WSCreatePreInvoice.Create_Result> CreateContractInvoice(AutorizarFaturaçãoContratos CreateInvoice, NAVWSConfigurations WSConfigurations, string ContractInvoicePeriod, string InvoiceBorrowed, string CodTermosPagamento, bool PricesIncludingVAT, string Ship_to_Code)
        {
            DateTime           now             = DateTime.Now;
            string             PostingNoSeries = "";
            string             Observacoes     = "";
            string             Mes             = InvoiceBorrowed.Substring(0, InvoiceBorrowed.IndexOf("/"));
            string             Ano             = InvoiceBorrowed.Substring(InvoiceBorrowed.IndexOf("/") + 1, 4);
            ConfigUtilizadores CUsers          = DBUserConfigurations.GetById(CreateInvoice.UtilizadorCriação);
            Contratos          Contrato        = DBContracts.GetByIdLastVersion(CreateInvoice.NºContrato);

            WSCreatePreInvoice.Create_Result result = new WSCreatePreInvoice.Create_Result();


            if (Contrato != null && Contrato.TipoContrato == 3 && Contrato.Tipo == 3) //Contrato Quotas
            {
                ConfiguracaoParametros Parametro = DBConfiguracaoParametros.GetByParametro("QuotasNoSeries");

                if (Parametro != null && !string.IsNullOrEmpty(Parametro.Valor))
                {
                    PostingNoSeries = Parametro.Valor;
                }

                if (Contrato != null && !string.IsNullOrEmpty(Contrato.TextoFatura))
                {
                    Observacoes = Contrato.TextoFatura;
                    Observacoes = Observacoes.Replace("<MES>", Mes);
                    Observacoes = Observacoes.Replace("<ANO>", Ano);
                }
            }
            else
            {
                PostingNoSeries = !string.IsNullOrEmpty(CUsers.NumSerieFaturas) ? CUsers.NumSerieFaturas : "";
                Observacoes     = !string.IsNullOrEmpty(CreateInvoice.Descrição) ? CreateInvoice.Descrição : "";
            }

            WSCreatePreInvoice.Create NAVCreate = new WSCreatePreInvoice.Create()
            {
                WSPreInvoice = new WSCreatePreInvoice.WSPreInvoice()
                {
                    Sell_to_Customer_No          = !string.IsNullOrEmpty(CreateInvoice.NºCliente) ? CreateInvoice.NºCliente : "",
                    Document_Date                = DateTime.Today,
                    Document_DateSpecified       = true,
                    Shipment_Date                = now,
                    Shipment_DateSpecified       = true,
                    Shipment_Start_Time          = now.AddHours(1),
                    Shipment_Start_TimeSpecified = true,
                    Document_Type                = WSCreatePreInvoice.Document_Type.Invoice,
                    Document_TypeSpecified       = true,
                    Posting_Date             = CreateInvoice.DataDeRegisto ?? DateTime.Now,
                    Posting_DateSpecified    = true,
                    Periodo_de_Fact_Contrato = !string.IsNullOrEmpty(ContractInvoicePeriod) ? ContractInvoicePeriod : "",
                    Data_Serv_Prestado       = !string.IsNullOrEmpty(InvoiceBorrowed) ? InvoiceBorrowed : "",
                    Responsibility_Center    = !string.IsNullOrEmpty(CUsers.CentroDeResponsabilidade) ? CUsers.CentroDeResponsabilidade : "",

                    Posting_No_Series  = PostingNoSeries,
                    Due_Date           = (DateTime)CreateInvoice.DataDeExpiração,
                    Due_DateSpecified  = true,
                    Payment_Terms_Code = CodTermosPagamento,

                    //Amaro
                    Observacoes             = Observacoes,
                    Contract_No             = !string.IsNullOrEmpty(CreateInvoice.NºContrato) ? CreateInvoice.NºContrato : "",
                    Factura_CAF             = true,
                    Factura_CAFSpecified    = true,
                    Codigo_Pedido           = !string.IsNullOrEmpty(CreateInvoice.NoRequisicaoDoCliente) ? CreateInvoice.NoRequisicaoDoCliente : "",
                    No_Compromisso          = !string.IsNullOrEmpty(CreateInvoice.NoCompromisso) ? CreateInvoice.NoCompromisso : "",
                    Data_Encomenda          = CreateInvoice.DataRececaoRequisicao ?? DateTime.MinValue,
                    Data_EncomendaSpecified = true,

                    RegionCode20               = !string.IsNullOrEmpty(CreateInvoice.CódigoRegião) ? CreateInvoice.CódigoRegião : "",
                    FunctionAreaCode20         = !string.IsNullOrEmpty(CreateInvoice.CódigoÁreaFuncional) ? CreateInvoice.CódigoÁreaFuncional : "",
                    ResponsabilityCenterCode20 = !string.IsNullOrEmpty(CreateInvoice.CódigoCentroResponsabilidade) ? CreateInvoice.CódigoCentroResponsabilidade : "",

                    Prices_Including_VAT          = PricesIncludingVAT,
                    Prices_Including_VATSpecified = true,

                    Ship_to_Code = !string.IsNullOrEmpty(Ship_to_Code) ? Ship_to_Code : "",
                }
            };

            // Configure NAV Client
            EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_PreInvoice_URL.Replace("Company", WSConfigurations.WS_User_Company));

            WSCreatePreInvoice.WSPreInvoice_PortClient WS_Client = new WSCreatePreInvoice.WSPreInvoice_PortClient(navWSBinding, WS_URL);
            WS_Client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
            WS_Client.ClientCredentials.Windows.ClientCredential          = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain);

            try
            {
                result = await WS_Client.CreateAsync(NAVCreate);

                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public static async Task <WSCreatePreInvoiceLine.CreateMultiple_Result> CreatePreInvoiceLineList(List <LinhasFaturaçãoContrato> LinesList, String HeaderNo, string InvoiceBorrowed, NAVWSConfigurations WSConfigurations)
        {
            int       counter       = 0;
            string    TextoFatura   = "";
            string    Mes           = InvoiceBorrowed.Substring(0, InvoiceBorrowed.IndexOf("/"));
            string    Ano           = InvoiceBorrowed.Substring(InvoiceBorrowed.IndexOf("/") + 1, 4);
            bool      ContratoQuota = false;
            Contratos Contrato      = DBContracts.GetByIdLastVersion(LinesList.FirstOrDefault().NºContrato);

            if (Contrato != null && Contrato.TipoContrato == 3 && Contrato.Tipo == 3) //Contrato Quotas
            {
                ContratoQuota = true;

                if (Contrato != null && !string.IsNullOrEmpty(Contrato.TextoFatura))
                {
                    TextoFatura = Contrato.TextoFatura;
                    TextoFatura = TextoFatura.Replace("<MES>", Mes);
                    TextoFatura = TextoFatura.Replace("<ANO>", Ano);
                }
            }

            WSCreatePreInvoiceLine.WsPreInvoiceLine[] parsedList = LinesList.Select(
                x => new WSCreatePreInvoiceLine.WsPreInvoiceLine
            {
                Document_No            = HeaderNo,
                Line_No                = counter += 10000,
                Line_NoSpecified       = true,
                Document_Type          = WSCreatePreInvoiceLine.Document_Type.Invoice,
                Document_TypeSpecified = true,
                No                         = x.Código,
                TypeSpecified              = true,
                Type                       = ConvertToSaleslineType(x.Tipo.Replace(" ", String.Empty)),
                Description                = ContratoQuota == false ? x.Descrição != null && x.Descrição.Length > 50 ? x.Descrição.Substring(0, 50) : !string.IsNullOrEmpty(x.Descrição) ? x.Descrição : "" : !string.IsNullOrEmpty(TextoFatura) ? TextoFatura : "",
                Description_2              = ContratoQuota == false ? x.Descricao2 != null && x.Descricao2.Length > 50 ? x.Descricao2.Substring(0, 50) : !string.IsNullOrEmpty(x.Descricao2) ? x.Descricao2 : "" : "",
                Quantity                   = x.Quantidade.HasValue ? x.Quantidade.Value : 0,
                QuantitySpecified          = true,
                Unit_of_Measure            = x.CódUnidadeMedida,
                Unit_Price                 = x.PreçoUnitário.HasValue ? x.PreçoUnitário.Value : 0,
                Unit_PriceSpecified        = true,
                Service_Contract_No        = x.NºContrato,
                Contract_No                = x.NºContrato,
                gJobDimension              = x.NºContrato,
                RegionCode20               = x.CódigoRegião,
                FunctionAreaCode20         = x.CódigoÁreaFuncional,
                ResponsabilityCenterCode20 = x.CódigoCentroResponsabilidade,
            }).ToArray();

            WSCreatePreInvoiceLine.CreateMultiple NAVCreate = new WSCreatePreInvoiceLine.CreateMultiple(parsedList);

            //Configure NAV Client
            EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_PreInvoiceLine_URL.Replace("Company", WSConfigurations.WS_User_Company));

            WSCreatePreInvoiceLine.WsPreInvoiceLine_PortClient WS_Client = new WSCreatePreInvoiceLine.WsPreInvoiceLine_PortClient(navWSBinding, WS_URL);
            WS_Client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
            WS_Client.ClientCredentials.Windows.ClientCredential          = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain);

            try
            {
                WSCreatePreInvoiceLine.CreateMultiple_Result result = await WS_Client.CreateMultipleAsync(NAVCreate);

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ContractViewModel ArchiveContract(ContractViewModel contractToArchive)
        {
            if (contractToArchive != null)
            {
                Contratos cContract           = DBContracts.GetByIdAndVersion(contractToArchive.ContractNo, contractToArchive.VersionNo);
                var       lastVersionContract = DBContracts.GetByIdLastVersion(contractToArchive.ContractNo);
                int       lastVersionNumber   = 0;

                if (lastVersionContract != null)
                {
                    lastVersionNumber = lastVersionContract.NºVersão + 1;
                }
                else
                {
                    lastVersionNumber = contractToArchive.VersionNo + 1;
                }

                if (cContract != null)
                {
                    try
                    {
                        //Create new contract and update old
                        cContract.Notas                 = cContract.Notas;
                        cContract.RazãoArquivo          = contractToArchive.ArchiveReason;
                        cContract.UtilizadorModificação = changedByUserName;
                        cContract.Arquivado             = true;
                        DBContracts.Update(cContract);

                        //NR20181116 - Só faz se não for Oportunidade
                        if (cContract.TipoContrato == (int)ContractType.Oportunity)
                        {
                            contractToArchive.eReasonCode = 1;
                            contractToArchive.eMessage    = "Arquivado com sucesso.";
                            return(contractToArchive);
                        }

                        cContract.NºVersão              = lastVersionNumber;// cContract.NºVersão + 1;
                        cContract.UtilizadorCriação     = changedByUserName;
                        cContract.UtilizadorModificação = "";
                        if (cContract.TipoContrato == (int)ContractType.Oportunity)
                        {
                            cContract.NºProposta = "";
                        }
                        else if (cContract.TipoContrato == (int)ContractType.Proposal)
                        {
                            cContract.NºContrato = "";
                        }

                        cContract.DataHoraModificação = null;
                        cContract.Arquivado           = false;

                        if (contractToArchive.ActionCode.HasValue && contractToArchive.ActionCode.Value == 2)
                        {
                            cContract.Estado = 1;
                            cContract.DataHoraModificação   = DateTime.Now;
                            cContract.UtilizadorModificação = changedByUserName;
                        }

                        DBContracts.Create(cContract);

                        //Duplicate Contract Lines
                        List <LinhasContratos> ContractLines = DBContractLines.GetAllByActiveContract(contractToArchive.ContractNo, contractToArchive.VersionNo);

                        ContractLines.ForEach(x =>
                        {
                            x.NºVersão = lastVersionNumber;// cContract.NºVersão;
                            DBContractLines.Create(x);
                        });

                        contractToArchive.VersionNo   = lastVersionNumber;// cContract.NºVersão;
                        contractToArchive.eReasonCode = 1;
                        contractToArchive.eMessage    = "Arquivado com sucesso.";
                        return(contractToArchive);
                    }
                    catch (Exception)
                    {
                        contractToArchive.eReasonCode = 2;
                        contractToArchive.eMessage    = "Ocorreu um erro ao arquivar.";
                    }
                }
            }
            else
            {
                contractToArchive.eReasonCode = 2;
                contractToArchive.eMessage    = "Ocorreu um erro ao arquivar.";
            }
            return(contractToArchive);
        }