Exemplo n.º 1
0
        public static ActivityInfo Insert(string sessionId, Activity jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var activityInfo    = new CrmBEActividade();
            var activityId      = PrimaveraEngine.generateGUID();
            var activitiesTable = PrimaveraEngine.Engine.CRM.Actividades;

            if (activitiesTable.Existe(activityId))
            {
                throw new EntityExistsException("actividade", true);
            }

            activityInfo.set_ID(activityId);
            activityInfo.set_Estado("0");
            activityInfo.set_CriadoPor(sessionId);
            activityInfo.set_DataCriacao(DateTime.Now);
            activityInfo.set_DataUltAct(DateTime.Now);
            SetFields(activityInfo, jsonObject);
            activityInfo = activitiesTable.PreencheDadosRelacionados(activityInfo);
            activitiesTable.Actualiza(activityInfo);

            return(GenerateActivity(activityInfo));
        }
Exemplo n.º 2
0
        public static ActivityInfo Delete(string sessionId, string activityId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var activitiesTable = PrimaveraEngine.Engine.CRM.Actividades;

            if (activitiesTable.Existe(activityId) == false)
            {
                throw new NotFoundException("actividade", true);
            }

            var activityInfo = activitiesTable.Edita(activityId);

            /*if (CheckPermissions(activityInfo, sessionId) == false)
             * {
             *  return null;
             * }*/

            activityInfo.set_EmModoEdicao(true);
            activityInfo.set_Estado("1");
            activityInfo.set_DataUltAct(DateTime.Now);
            activitiesTable.Actualiza(activityInfo);

            return(GenerateActivity(activityInfo));
        }
        public static List <ProductListing> List()
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var productList = new List <ProductListing>();
            var productInfo = PrimaveraEngine.Consulta(new SqlBuilder().FromTable("ARTIGO").Columns(sqlColumnsListing));

            if (productInfo == null || productInfo.Vazia())
            {
                return(productList);
            }

            while (!productInfo.NoFim())
            {
                productList.Add(GenerateListing(productInfo));
                productInfo.Seguinte();
            }

            productList.Sort(delegate(ProductListing lhs, ProductListing rhs)
            {
                if (lhs.Identificador == null || rhs.Identificador == null)
                {
                    return(-1);
                }

                return(lhs.Identificador.CompareTo(rhs.Identificador));
            });

            return(productList);
        }
        public static ProposalsLine Insert(string sessionId, ProposalsLine jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var proposalLineInfo   = new CrmBELinhaPropostaOPV();
            var opportunitiesTable = PrimaveraEngine.Engine.CRM.PropostasOPV;
            var proposalInfo       = opportunitiesTable.Edita(jsonObject.idOportunidade, jsonObject.ProposalNumber);
            var proposalLines      = proposalInfo.get_Linhas();

            /*if (opportunitiesTable.Existe(opportunityId))
             * {
             *  throw new EntityExistsException("oportunidade", true);
             * }*/

            proposalInfo.set_EmModoEdicao(true);
            SetFields(proposalLineInfo, jsonObject);
            proposalLines.Insere(proposalLineInfo);
            proposalInfo.set_Linhas(proposalLines);
            opportunitiesTable.Actualiza(proposalInfo);

            return(GenerateProposal(proposalLineInfo));
        }
        public static List <Reference> ListTypes(DefinitionType definitionType)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            if (definitionColumns.ContainsKey(definitionType) == false)
            {
                throw new NotFoundException("tipo", false);
            }

            var typeList = new List <Reference>();
            var typeInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                    .FromTable(getTable(definitionType))
                                                    .Columns(definitionColumns[definitionType]));

            if (typeInfo == null || typeInfo.Vazia())
            {
                return(typeList);
            }

            while (!typeInfo.NoFim())
            {
                typeList.Add(GenerateType(typeInfo, definitionType));
                typeInfo.Seguinte();
            }

            return(typeList);
        }
        public static List <Reference> View(string paramId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var concelhoList = new List <Reference>();
            var concelhoInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                        .FromTable("CONCELHOS")
                                                        .Columns(sqlConcelho)
                                                        .Where(fieldDistrito, Comparison.Equals, paramId)
                                                        .Where(fieldConcelho, Comparison.GreaterThan, 0));

            if (concelhoInfo == null || concelhoInfo.Vazia())
            {
                return(concelhoList);
            }

            while (!concelhoInfo.NoFim())
            {
                concelhoList.Add(new Reference()
                {
                    Descricao     = TypeParser.String(concelhoInfo.Valor(fieldDescricao)),
                    Identificador = TypeParser.String(concelhoInfo.Valor(fieldConcelho))
                });

                concelhoInfo.Seguinte();
            }

            return(concelhoList);
        }
        public static List <Opportunity> List(string sessionId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var opportunityList = new List <Opportunity>();
            var opportunityInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                           .FromTable("CABECOPORTUNIDADESVENDA")
                                                           .Columns(sqlColumnsListing)
                                                           .Where("Descricao", Comparison.NotEquals, "DELETED"));

            if (opportunityInfo == null || opportunityInfo.Vazia())
            {
                return(opportunityList);
            }

            while (!opportunityInfo.NoFim())
            {
                opportunityList.Add(GenerateListing(opportunityInfo));
                opportunityInfo.Seguinte();
            }

            return(opportunityList);
        }
        public static List <ActivityType> ListActivityTypes()
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var typeList = new List <ActivityType>();
            var typeInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                    .FromTable(getTable(DefinitionType.ActivityType))
                                                    .Columns(getColumns(DefinitionType.ActivityType)));

            if (typeInfo == null || typeInfo.Vazia())
            {
                return(typeList);
            }

            while (!typeInfo.NoFim())
            {
                typeList.Add(GenerateActivity(typeInfo));
                typeInfo.Seguinte();
            }

            return(typeList);
        }
Exemplo n.º 9
0
        public static LeadInfo Delete(string sessionId, string leadId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var leadsTable = PrimaveraEngine.Engine.CRM.EntidadesExternas;

            if (leadsTable.Existe(leadId) == false)
            {
                throw new NotFoundException("lead", true);
            }

            var leadInfo = leadsTable.Edita(leadId);

            if (CheckPermissions(leadInfo, sessionId) == false)
            {
                return(null);
            }

            leadInfo.set_EmModoEdicao(true);
            leadInfo.set_Activo(false);
            leadInfo.set_TipoEntidade("004");
            leadInfo.set_DataUltAct(DateTime.Now);
            leadsTable.Actualiza(leadInfo);

            return(GenerateInfo(leadInfo));
        }
        public static List <ProposalsLine> List(string id, short proposalNumber)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var formattedId = id.Replace("%7B", "{").Replace("%7D", "}");
            var lineInfo    = PrimaveraEngine.Consulta(new SqlBuilder()
                                                       .FromTable("LINHASPROPOSTASOPV")
                                                       .Columns(sqlColumnsListing)
                                                       .Where("IdOportunidade", Comparison.Equals, formattedId)
                                                       .Where("NumProposta", Comparison.Equals, proposalNumber));

            /*if (lineInfo == null || lineInfo.Vazia())
             * {
             *  throw new NotFoundException("proposta", true);
             * }*/

            var lineList = new List <ProposalsLine>();

            while (!lineInfo.NoFim())
            {
                lineList.Add(GenerateListing(lineInfo));
                lineInfo.Seguinte();
            }

            return(lineList);
        }
Exemplo n.º 11
0
        public static bool Delete(string sessionId, string quoteId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var quotesTable = PrimaveraEngine.Engine.Comercial.Vendas;

            if (quotesTable.ExisteID(quoteId) == false)
            {
                return false;
            }

            var quoteInfo = quotesTable.EditaID(quoteId);

            if (CheckPermissions(quoteInfo, sessionId) == false)
            {
                return false;
            }

            quoteInfo.set_EmModoEdicao(true);
            quoteInfo.set_Anulado(true);
            quotesTable.Actualiza(quoteInfo);

            return true;
        }
        public static Proposals Insert(string sessionId, Proposals jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var proposalInfo   = new CrmBEPropostaOPV();
            var proposalsTable = PrimaveraEngine.Engine.CRM.PropostasOPV;

            /*if (opportunitiesTable.Existe(opportunityId))
             * {
             *  throw new EntityExistsException("oportunidade", true);
             * }*/

            SetFields(proposalInfo, jsonObject);
            proposalsTable.Actualiza(proposalInfo);

            /* for (int i = 0; i < jsonObject.ProposalsLines.Count; i++)
             * {
             *   ProposalLinesIntegration.Insert(jsonObject.ProposalsLines[i]);
             * }*/

            return(GenerateProposal(proposalInfo, jsonObject.ProposalsLines));
        }
        public static List <Proposals> List(string sessionId, string opportunityId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var proposalInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                        .FromTable("PROPOSTASOPV")
                                                        .Columns(sqlColumnsListing)
                                                        .Where("IdOportunidade", Comparison.Equals, opportunityId));

            /*if (proposalInfo == null || proposalInfo.Vazia())
             * {
             *  throw new NotFoundException("oportunidade", true);
             * }*/

            var queryResult = new List <Proposals>();

            while (!proposalInfo.NoFim())
            {
                queryResult.Add(GenerateListing(proposalInfo, opportunityId));
                proposalInfo.Seguinte();
            }

            return(queryResult);
        }
Exemplo n.º 14
0
        public static List <RepresentativeListing> List()
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var representativeList = new List <RepresentativeListing>();
            var representativeInfo = PrimaveraEngine.Consulta(new SqlBuilder().Columns(sqlVendedor).FromTable("VENDEDORES"));

            if (representativeInfo == null || representativeInfo.Vazia())
            {
                return(representativeList);
            }

            while (!representativeInfo.NoFim())
            {
                representativeList.Add(new RepresentativeListing
                {
                    Identificador = TypeParser.String(representativeInfo.Valor(fieldVendedor)),
                    Nome          = TypeParser.String(representativeInfo.Valor(fieldNome)),
                    Comissao      = TypeParser.Double(representativeInfo.Valor(fieldComissao))
                });

                representativeInfo.Seguinte();
            }

            return(representativeList);
        }
Exemplo n.º 15
0
        public static Representative View(string representativeId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var representativesTable = PrimaveraEngine.Engine.Comercial.Vendedores;

            if (representativesTable.Existe(representativeId) == false)
            {
                throw new NotFoundException("vendedor", false);
            }

            var representativeInfo = representativesTable.Edita(representativeId);

            return(new Representative
            {
                Nome = representativeInfo.get_Nome(),
                Email = representativeInfo.get_Email(),
                Morada = representativeInfo.get_Morada(),
                Comissao = representativeInfo.get_Comissao(),
                Telefone = representativeInfo.get_Telefone(),
                Telemovel = representativeInfo.get_Telemovel(),
                Identificador = representativeInfo.get_Vendedor(),
                Empresa = PrimaveraEngine.Engine.Licenca.get_Nome(),
                CodigoPostal = representativeInfo.get_CodigoPostal(),
                Fotografia = representativeInfo.get_LocalizacaoFoto(),
                Localidade = representativeInfo.get_LocalidadeCodigoPostal(),
            });
        }
Exemplo n.º 16
0
        public static Warehouse Get(string warehouseId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var warehouseInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                         .FromTable("ARMAZENS")
                                                         .Columns(sqlColumnsFull)
                                                         .Where("Armazem", Comparison.Equals, warehouseId));

            if (warehouseInfo == null || warehouseInfo.Vazia())
            {
                throw new NotFoundException("armazém", false);
            }

            return(new Warehouse
            {
                Localizacao = GetAddress(warehouseInfo),
                Descricao = TypeParser.String(warehouseInfo.Valor("Descricao")),
                Telefone = TypeParser.String(warehouseInfo.Valor("Telefone")),
                Identificador = TypeParser.String(warehouseInfo.Valor("Armazem")),
                DataModificacao = TypeParser.Date(warehouseInfo.Valor("DataUltimaActualizacao"))
            });
        }
Exemplo n.º 17
0
        public static List <WarehouseListing> List()
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var warehouseList = new List <WarehouseListing>();
            var warehouseInfo = PrimaveraEngine.Consulta(new SqlBuilder().FromTable("ARMAZENS").Columns(sqlColumnsListing));

            if (warehouseInfo == null || warehouseInfo.Vazia())
            {
                return(warehouseList);
            }
            ;

            while (!warehouseInfo.NoFim())
            {
                warehouseList.Add(new WarehouseListing
                {
                    Localizacao   = GetAddress(warehouseInfo),
                    Descricao     = TypeParser.String(warehouseInfo.Valor("Descricao")),
                    Identificador = TypeParser.String(warehouseInfo.Valor("Armazem")),
                });

                warehouseInfo.Seguinte();
            }

            return(warehouseList);
        }
Exemplo n.º 18
0
        public static List <WarehouseProduct> GetWarehouses(string productId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var warehouseList = new List <WarehouseProduct>();
            var warehouseInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                         .FromTable("ARTIGOARMAZEM")
                                                         .Columns(sqlColumnsAggregate)
                                                         .Where("ARTIGOARMAZEM.Artigo", Comparison.Equals, productId)
                                                         .LeftJoin("ARMAZENS", "Armazem", Comparison.Equals, "ARTIGOARMAZEM", "Armazem")
                                                         .GroupBy(new string[] { "ARTIGOARMAZEM.Artigo", "ARMAZENS.Armazem" }));

            if (warehouseInfo == null || warehouseInfo.Vazia())
            {
                return(warehouseList);
            }

            while (!warehouseInfo.NoFim())
            {
                warehouseList.Add(new WarehouseProduct
                {
                    Localizacao   = GetAddress(warehouseInfo),
                    Stock         = TypeParser.Double(warehouseInfo.Valor("Stock")),
                    Descricao     = TypeParser.String(warehouseInfo.Valor("Descricao")),
                    Identificador = TypeParser.String(warehouseInfo.Valor("Armazem"))
                });

                warehouseInfo.Seguinte();
            }

            return(warehouseList);
        }
        public static bool Delete(string sessionId, string opportunityId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var opportunitiesTable = PrimaveraEngine.Engine.CRM.OportunidadesVenda;

            if (opportunitiesTable.Existe(opportunityId) == false)
            {
                throw new NotFoundException("oportunidade", true);
            }

            var opportunityInfo = opportunitiesTable.Edita(opportunityId);

            /*if (CheckPermissions(opportunityInfo, sessionId) == false)
             * {
             *  return false;
             * }*/

            opportunityInfo.set_EmModoEdicao(true);
            opportunityInfo.set_Descricao("DELETED");
            opportunitiesTable.Actualiza(opportunityInfo);

            return(true);
        }
        public static bool Delete(string sessionId, string proposalsId, ProposalsLine jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            /*if (opportunitiesTable.Existe(opportunityId) == false)
             * {
             *  throw new NotFoundException("oportunidade", true);
             * }*/

            var proposalsTableAux = PrimaveraEngine.Engine.CRM.PropostasOPV;
            var proposalsTable    = PrimaveraEngine.Engine.CRM.PropostasOPV.Edita(jsonObject.idOportunidade, jsonObject.ProposalNumber);
            var proposalLines     = proposalsTable.get_Linhas();

            proposalsTable.set_EmModoEdicao(true);
            proposalLines.Remove(jsonObject.Line);
            proposalsTableAux.Actualiza(proposalsTable);

            /*if (CheckPermissions(opportunityInfo, sessionId) == false)
             * {
             *  return false;
             * }*/

            return(true);
        }
        public static List <Reference> ListCampaigns()
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var campaignList = new List <Reference>();
            var campaignInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                        .FromTable(definitionTables[DefinitionType.Campaign])
                                                        .Columns(definitionColumns[DefinitionType.Campaign])
                                                        .Where("Activa", Comparison.Equals, 1));

            if (campaignInfo == null || campaignInfo.Vazia())
            {
                return(campaignList);
            }

            while (!campaignInfo.NoFim())
            {
                campaignList.Add(GenerateType(campaignInfo, DefinitionType.Campaign));
                campaignInfo.Seguinte();
            }

            return(campaignList);
        }
        public static List <Reference> ListThirdPartyTypes()
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var typeList = new List <Reference>();
            var typeInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                    .FromTable("TipoTerceiros")
                                                    .Columns(definitionColumns[DefinitionType.ThirdParty])
                                                    .Where("EntidadesExternas", Comparison.Equals, 1));

            if (typeInfo == null || typeInfo.Vazia())
            {
                return(typeList);
            }

            while (!typeInfo.NoFim())
            {
                typeList.Add(GenerateType(typeInfo, DefinitionType.ThirdParty));
                typeInfo.Seguinte();
            }

            return(typeList);
        }
        public static List <Reference> List()
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var distritoList = new List <Reference>();
            var distritoInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                        .FromTable("DISTRITOS")
                                                        .Columns(sqlDistrito)
                                                        .Where(fieldDistrito, Comparison.GreaterThan, 0));

            if (distritoInfo == null || distritoInfo.Vazia())
            {
                return(distritoList);
            }

            while (!distritoInfo.NoFim())
            {
                distritoList.Add(new Reference()
                {
                    Descricao     = TypeParser.String(distritoInfo.Valor(fieldDescricao)),
                    Identificador = TypeParser.String(distritoInfo.Valor(fieldDistrito))
                });

                distritoInfo.Seguinte();
            }

            return(distritoList);
        }
        public static ContactInfo Insert(string sessionId, Contact jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var contactInfo   = new CrmBEContacto();
            var contactId     = PrimaveraEngine.GenerateName(jsonObject.Nome);
            var contactsTable = PrimaveraEngine.Engine.CRM.Contactos;

            if (contactsTable.Existe(contactId))
            {
                throw new EntityExistsException("contacto", false);
            }

            contactInfo.set_Contacto(contactId);
            contactInfo.set_CriadoPor(sessionId);
            contactInfo.set_DataUltContacto(DateTime.Now);
            contactInfo.set_ID(PrimaveraEngine.generateGUID());
            SetFields(contactInfo, jsonObject);
            contactsTable.Actualiza(contactInfo);

            return(GenerateContact(contactInfo));
        }
        public static ContactInfo Update(string sessionId, string contactId, Contact jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var contactsTable = PrimaveraEngine.Engine.CRM.Contactos;

            if (contactsTable.Existe(contactId) == false)
            {
                throw new NotFoundException("contacto", false);
            }

            var contactInfo = contactsTable.Edita(contactId);

            /*if (CheckPermissions(contactInfo, sessionId) == false)
             * {
             *  return null;
             * }*/

            contactInfo.set_EmModoEdicao(true);
            contactInfo.set_DataUltContacto(DateTime.Now);
            SetFields(contactInfo, jsonObject);
            contactsTable.Actualiza(contactInfo);

            return(GenerateContact(contactInfo));
        }
        public static CustomerInfo Delete(string sessionId, string customerId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var customerQuery = PrimaveraEngine.Consulta(new SqlBuilder()
                                                         .Column("Cliente")
                                                         .FromTable("CLIENTES")
                                                         .Where("Cliente", Comparison.Equals, customerId));

            if (customerQuery == null || customerQuery.Vazia())
            {
                throw new NotFoundException("cliente", false);
            }

            var customersTable = PrimaveraEngine.Engine.Comercial.Clientes;
            var customerInfo   = customersTable.Edita(customerId);

            /*if (CheckPermissions(customerInfo, sessionId) == false)
             * {
             *  return null;
             * }*/

            customerInfo.set_EmModoEdicao(true);
            customerInfo.set_Situacao("INACTIVO");
            customerInfo.set_DataUltimaActualizacao(DateTime.Now);
            customersTable.Actualiza(customerInfo);

            return(generateCustomer(customerInfo));
        }
        public static CustomerInfo Insert(string sessionId, Customer jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var customerInfo   = new GcpBECliente();
            var customerId     = PrimaveraEngine.GenerateName(jsonObject.Nome);
            var customersTable = PrimaveraEngine.Engine.Comercial.Clientes;

            if (customersTable.Existe(customerId))
            {
                throw new EntityExistsException("cliente", false);
            }

            customerInfo.set_Cliente(customerId);
            SetFields(customerInfo, jsonObject);
            customerInfo.set_Moeda("EUR");
            customerInfo.set_Situacao("ACTIVO");
            customerInfo.set_Inactivo(false);
            customerInfo.set_Vendedor(sessionId);
            customerInfo.set_DataCriacao(DateTime.Now);
            customerInfo.set_DataUltimaActualizacao(DateTime.Now);
            customersTable.Actualiza(customerInfo);

            return(generateCustomer(customerInfo));
        }
        public static CustomerInfo View(string sessionId, string customerId)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var customerInfo = PrimaveraEngine.Consulta(new SqlBuilder()
                                                        .FromTable("CLIENTES")
                                                        .Columns(sqlColumnsFull)
                                                        .Where("Cliente", Comparison.Equals, customerId));

            if (customerInfo == null || customerInfo.Vazia())
            {
                throw new NotFoundException("cliente", false);
            }

            var responsavelId = TypeParser.String(customerInfo.Valor("Vendedor"));
            var distritoId    = TypeParser.String(customerInfo.Valor("Distrito"));

            /*if (responsavelId.Equals(sessionId) == false)
             * {
             *  return null;
             * }*/

            return(new CustomerInfo()
            {
                Identificador = TypeParser.String(customerInfo.Valor("Cliente")),
                Nome = TypeParser.String(customerInfo.Valor("Nome")),
                Estado = TypeParser.String(customerInfo.Valor("Situacao")),
                Debito = TypeParser.Double(customerInfo.Valor("TotalDeb")),
                NumContribuinte = TypeParser.String(customerInfo.Valor("NumContrib")),
                Pendentes = TypeParser.Double(customerInfo.Valor("EncomendasPendentes")),
                DataCriacao = TypeParser.Date(customerInfo.Valor("DataCriacao")),
                DataModificacao = TypeParser.Date(customerInfo.Valor("DataUltimaActualizacao")),
                EnderecoWeb = TypeParser.String(customerInfo.Valor("EnderecoWeb")),
                Particular = TypeParser.Boolean(customerInfo.Valor("PessoaSingular")),
                Telefone = TypeParser.String(customerInfo.Valor("Fac_Tel")),
                Telefone2 = TypeParser.String(customerInfo.Valor("Fac_Fax")),
                Telemovel = TypeParser.String(customerInfo.Valor("Telefone2")),
                Responsavel = UserIntegration.Reference(responsavelId),
                Localizacao = new Address
                {
                    Pais = TypeParser.String(customerInfo.Valor("Pais")),
                    Morada = TypeParser.String(customerInfo.Valor("Fac_Mor")),
                    Distrito = LocationIntegration.DistritoReference(distritoId),
                    CodigoPostal = TypeParser.String(customerInfo.Valor("Fac_Cp")),
                    Localidade = TypeParser.String(customerInfo.Valor("Fac_Local"))
                }
            });
        }
Exemplo n.º 29
0
        public static QuoteInfo Insert(string sessionId, QuoteInfo jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var quoteInfo = new GcpBEDocumentoVenda();

            try
            {
                SetDefaultQuotesInfo(sessionId, quoteInfo);
                SetOptionalFields(quoteInfo, jsonObject);

                if (jsonObject.Produtos != null)
                {
                    foreach (var produto in jsonObject.Produtos)
                    {
                        PrimaveraEngine.Engine.Comercial.Vendas.AdicionaLinha(quoteInfo, produto.Produto.Identificador, produto.Quantidade, "", "", produto.Preco, produto.Desconto);
                    }
                }

                PrimaveraEngine.Engine.IniciaTransaccao();
                PrimaveraEngine.Engine.Comercial.Vendas.Actualiza(quoteInfo);
                PrimaveraEngine.Engine.TerminaTransaccao();
            }
            catch (Exception ex)
            {
                PrimaveraEngine.Engine.DesfazTransaccao();
                throw ex;
            }

            return new QuoteInfo
            {
                NumEncomenda = quoteInfo.get_NumDoc(),
                Cliente = quoteInfo.get_Entidade(),
                NomeCliente = quoteInfo.get_Nome(),
                EnderecoEntrega = new Address
                {
                    Morada = quoteInfo.get_Morada(),
                    CodigoPostal = quoteInfo.get_CodigoPostal(),
                    Localidade = quoteInfo.get_Localidade(),
                    Distrito = LocationIntegration.DistritoReference(quoteInfo.get_Distrito()),
                    Pais = quoteInfo.get_Pais()
                },
                Data = quoteInfo.get_DataDoc(),
                IdOportunidade = quoteInfo.get_IdOportunidade(),
                TotalMerc = quoteInfo.get_TotalMerc(),
                Produtos = null
            };
        }
Exemplo n.º 30
0
        public static bool Update(string sessionId, string leadId, Lead jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var leadsTable = PrimaveraEngine.Engine.CRM.EntidadesExternas;

            if (leadsTable.Existe(leadId) == false)
            {
                throw new NotFoundException("lead", true);
            }

            var leadInfo = leadsTable.Edita(leadId);

            if (CheckPermissions(leadInfo, sessionId) == false)
            {
                return(false);
            }

            string clientId       = null;
            bool   convert2client = jsonObject.TipoTerceiro != null && jsonObject.TipoTerceiro.Equals(LeadInfo.CONVERT_TO_CLIENT_ID);

            if (convert2client)
            {
                //tem que ser feito nesta ordem para evitar alterar estado sem criar cliente
                var clientsTable = PrimaveraEngine.Engine.Comercial.Clientes;
                clientId = leadId;
                if (clientsTable.Existe(clientId))
                {
                    //clientId = PrimaveraEngine.GenerateHash();
                    if (clientsTable.Existe(clientId))
                    {
                        return(false);
                    }
                }
            }

            leadInfo.set_EmModoEdicao(true);
            leadInfo.set_DataUltAct(DateTime.Now);
            SetFields(leadInfo, jsonObject);
            leadsTable.Actualiza(leadInfo);

            if (convert2client)
            {
                PrimaveraEngine.Engine.CRM.EntidadesExternas.TransformarNoutraEntidade(leadId, clientId, "C", null, null, null);
            }

            return(true);
        }