public static async Task <WSRegistaGuia_Result> RegisterAsync(string noGuia, NAVWSConfigurations WSConfigurations) { WSRegistaGuia noGuiaRegistar = new WSRegistaGuia() { noGuiaTransporte = noGuia }; EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.Ws_SuchNav2017_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSNAV2017_PortClient ws_Client = new WSNAV2017_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 { WSRegistaGuia_Result result = await ws_Client.WSRegistaGuiaAsync(noGuia); return(result); } catch (Exception ex) { return(null); } }
public static void DeleteNavDiaryLines(Guid TransactID, NAVWSConfigurations WSConfigurations) { //Configure NAV Client EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_JobJournalLine_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSCreateProjectDiaryLine.WSJobJournalLine_PortClient WS_Client = new WSCreateProjectDiaryLine.WSJobJournalLine_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); var filter = new WSCreateProjectDiaryLine.WSJobJournalLine_Filter { Field = WSCreateProjectDiaryLine.WSJobJournalLine_Fields.Portal_Transaction_No, Criteria = TransactID.ToString() }; var filterArray = new WSCreateProjectDiaryLine.WSJobJournalLine_Filter[] { filter }; var result = WS_Client.ReadMultipleAsync(filterArray, null, 2000); if (result != null && result.Result != null) { foreach (var line in result.Result.ReadMultiple_Result1) { WS_Client.DeleteAsync(line.Key); } } }
public static async Task <WSGenericCodeUnit.FxGetURLOrderRequisition_Result> GetOrderRequisition(string HeaderNo, NAVWSConfigurations WSConfigurations) { //Configure NAV Client EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_Generic_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSGenericCodeUnit.WsGeneric_PortClient WS_Client = new WSGenericCodeUnit.WsGeneric_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 { WSGenericCodeUnit.FxGetURLOrderRequisition_Result result = await WS_Client.FxGetURLOrderRequisitionAsync(HeaderNo); return(result); } catch (Exception ex) { return(null); } }
public static async Task <WSCreatePreInvoice.CreateMultiple_Result> CreateMultipleContractInvoice(List <AutorizarFaturaçãoContratos> CreateList, NAVWSConfigurations WSConfigurations) { WSCreatePreInvoice.WSPreInvoice[] parsedList = CreateList.Select( x => new WSCreatePreInvoice.WSPreInvoice { Sell_to_Customer_No = x.NºCliente, Document_Date = x.DataDeRegisto.Value, Due_Date = x.DataDeExpiração.Value }).ToArray(); WSCreatePreInvoice.CreateMultiple NAVCreate = new WSCreatePreInvoice.CreateMultiple(parsedList); // 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 { WSCreatePreInvoice.CreateMultiple_Result result = await WS_Client.CreateMultipleAsync(NAVCreate); return(result); } catch (Exception ex) { return(null); } }
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 <WSCreatePreInvoice.Create_Result> CreatePreInvoice(AuthorizedCustomerBillingHeader billingHeader, NAVWSConfigurations WSConfigurations, string dataFormulario, string projeto, SPInvoiceListViewModel Ship) { SPInvoiceListViewModel invoiceHeader = new SPInvoiceListViewModel(); invoiceHeader.InvoiceToClientNo = billingHeader.InvoiceToClientNo; invoiceHeader.Date = billingHeader.Date; invoiceHeader.DataPedido = billingHeader.DataPedido; invoiceHeader.CommitmentNumber = billingHeader.CommitmentNumber; invoiceHeader.ClientRequest = billingHeader.ClientRequest; invoiceHeader.ClientVATReg = billingHeader.ClientVATReg; invoiceHeader.ContractNo = billingHeader.ContractNo; invoiceHeader.Currency = billingHeader.Currency; invoiceHeader.ServiceDate = billingHeader.ServiceDate; invoiceHeader.UpdateDate = billingHeader.UpdateDate; invoiceHeader.RegionCode = billingHeader.RegionCode; invoiceHeader.FunctionalAreaCode = billingHeader.FunctionalAreaCode; invoiceHeader.ResponsabilityCenterCode = billingHeader.ResponsabilityCenterCode; invoiceHeader.LocationCode = billingHeader.LocationCode; invoiceHeader.Comments = billingHeader.Comments; invoiceHeader.CodTermosPagamento = billingHeader.CodTermosPagamento; invoiceHeader.CodMetodoPagamento = billingHeader.CodMetodoPagamento; invoiceHeader.CreateUser = billingHeader.CreateUser; invoiceHeader.Posting_Date = Convert.ToDateTime(dataFormulario); invoiceHeader.ProjectNo = projeto; invoiceHeader.MovementType = billingHeader.MovementType; invoiceHeader.Ship_to_Code = Ship.Ship_to_Code; //invoiceHeader.Ship_to_Address = Ship.Ship_to_Address; //invoiceHeader.Ship_to_Address_2 = Ship.Ship_to_Address_2; //invoiceHeader.Ship_to_City = Ship.Ship_to_City; //invoiceHeader.Ship_to_Contact = Ship.Ship_to_Contact; //invoiceHeader.Ship_to_Country_Region_Code = Ship.Ship_to_Country_Region_Code; //invoiceHeader.Ship_to_County = Ship.Ship_to_County; //invoiceHeader.Ship_to_Name = Ship.Ship_to_Name; //invoiceHeader.Ship_to_Name_2 = Ship.Ship_to_Name_2; //invoiceHeader.Ship_to_Post_Code = Ship.Ship_to_Post_Code; invoiceHeader.FaturaPrecosIvaIncluido = billingHeader.FaturaPrecosIvaIncluido.HasValue ? (bool)billingHeader.FaturaPrecosIvaIncluido : false; return(await CreatePreInvoice(invoiceHeader, WSConfigurations)); }
public static async Task <WSVendorNAV.Create_Result> CreateAsync(FornecedorDetailsViewModel vendor, NAVWSConfigurations WSConfigurations) { if (vendor == null) { throw new ArgumentNullException("vendor"); } WSVendorNAV.Create navCreate = new WSVendorNAV.Create() { WSVendor = MapVendorModelToVendorNAV(vendor) }; navCreate.WSVendor.No = null; //Configure NAV Vendor EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_Vendor_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSVendorNAV.WSVendor_PortClient ws_Vendor = new WSVendorNAV.WSVendor_PortClient(navWSBinding, ws_URL); ws_Vendor.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; ws_Vendor.ClientCredentials.Windows.ClientCredential = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain); try { navCreate.WSVendor.Utilizador_Alteracao_eSUCH = vendor.Utilizador_Alteracao_eSUCH; navCreate.WSVendor.BlockedSpecified = true; navCreate.WSVendor.Bloqueado_Falta_PagamentoSpecified = true; navCreate.WSVendor.Bloqueado_UrgenteSpecified = true; navCreate.WSVendor.CertificaçãoSpecified = true; navCreate.WSVendor.ClassificaçãoSpecified = true; navCreate.WSVendor.CriticidadeSpecified = true; navCreate.WSVendor.Interface_ComprasSpecified = true; navCreate.WSVendor.PontuaçãoSpecified = true; navCreate.WSVendor.PreferencialSpecified = true; WSVendorNAV.Create_Result result = await ws_Vendor.CreateAsync(navCreate); return(result); } catch (Exception ex) { throw; } }
public static async Task <FornecedorDetailsViewModel> GetByNoAsync(string VendorNo, NAVWSConfigurations WSConfigurations) { if (VendorNo == null) { throw new ArgumentNullException("VendorNo"); } //Configure NAV Vendor EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_Vendor_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSVendorNAV.WSVendor_PortClient WS_Vendor = new WSVendorNAV.WSVendor_PortClient(navWSBinding, WS_URL); WS_Vendor.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; WS_Vendor.ClientCredentials.Windows.ClientCredential = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain); try { WSVendorNAV.Read_Result result = await WS_Vendor.ReadAsync(VendorNo); var WSVendor = result.WSVendor; var vendor = MapVendorNAVToVendorModel(WSVendor); return(vendor); } catch (Exception ex) { throw; } }
public static async Task <WSCustomerNAV.Update_Result> UpdateAsync(ClientDetailsViewModel client, NAVWSConfigurations WSConfigurations) { if (client == null) { throw new ArgumentNullException("client"); } client.Cliente_Interno = false; WSCustomerNAV.Update navUpdate = new WSCustomerNAV.Update() { WSCustomer = MapCustomerModelToCustomerNAV(client) }; //Configure NAV Client EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_Customer_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSCustomerNAV.WSCustomer_PortClient ws_Client = new WSCustomerNAV.WSCustomer_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); WSCustomerNAV.Read_Result resultRead = await ws_Client.ReadAsync(navUpdate.WSCustomer.No); navUpdate.WSCustomer.Key = resultRead.WSCustomer.Key; try { navUpdate.WSCustomer.Utilizador_Alteracao_eSUCH = client.Utilizador_Alteracao_eSUCH; navUpdate.WSCustomer.Abrigo_Lei_CompromissoSpecified = true; navUpdate.WSCustomer.BlockedSpecified = true; navUpdate.WSCustomer.Cliente_AssociadoSpecified = true; navUpdate.WSCustomer.Cliente_InternoSpecified = true; navUpdate.WSCustomer.Cliente_NacionalSpecified = true; navUpdate.WSCustomer.Data_Cliente_PaiSpecified = true; navUpdate.WSCustomer.Natureza_ClienteSpecified = true; navUpdate.WSCustomer.Regiao_ClienteSpecified = true; navUpdate.WSCustomer.Taxa_AprovisionamentoSpecified = true; navUpdate.WSCustomer.Tipo_ClienteSpecified = true; WSCustomerNAV.Update_Result result = await ws_Client.UpdateAsync(navUpdate); return(result); } catch (Exception ex) { throw; } }
public static async Task <WSShipToAddressNAV.Create_Result> CreateAsync(ShipToAddressViewModel shipToAddress, NAVWSConfigurations WSConfigurations) { if (shipToAddress == null) { throw new ArgumentNullException("shipToAddress"); } WSShipToAddressNAV.Create navCreate = new WSShipToAddressNAV.Create() { WSShipToAddress = MapShipToAddressNAV(shipToAddress) }; //Configure NAV Client EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_ShipToAddress_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSShipToAddressNAV.WSShipToAddress_PortClient WS_ShipToAddress = new WSShipToAddressNAV.WSShipToAddress_PortClient(navWSBinding, ws_URL); WS_ShipToAddress.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; WS_ShipToAddress.ClientCredentials.Windows.ClientCredential = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain); try { navCreate.WSShipToAddress.Utilizador_Alteracao_eSUCH = shipToAddress.Utilizador_Alteracao_eSUCH; WSShipToAddressNAV.Create_Result result = await WS_ShipToAddress.CreateAsync(navCreate); return(result); } catch (Exception ex) { throw; } }
public static async Task <List <ShipToAddressViewModel> > GetByNoAsync(string CustomerNo, NAVWSConfigurations WSConfigurations) { if (CustomerNo == null) { throw new ArgumentNullException("CustomerNo"); } //Configure NAV Client EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_ShipToAddress_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSShipToAddressNAV.WSShipToAddress_PortClient WS_ShipToAddress = new WSShipToAddressNAV.WSShipToAddress_PortClient(navWSBinding, WS_URL); WS_ShipToAddress.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; WS_ShipToAddress.ClientCredentials.Windows.ClientCredential = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain); var filter = new WSShipToAddressNAV.WSShipToAddress_Filter { Field = WSShipToAddressNAV.WSShipToAddress_Fields.Customer_No, Criteria = CustomerNo }; var filterArray = new WSShipToAddressNAV.WSShipToAddress_Filter[] { filter }; try { WSShipToAddressNAV.ReadMultiple_Result result = await WS_ShipToAddress.ReadMultipleAsync(filterArray, null, 0); //WS_ShipToAddress.ReadAsync(CustomerNo); //return result.ReadMultiple_Result1; List <ShipToAddressViewModel> retval = new List <ShipToAddressViewModel>(); foreach (var r in result.ReadMultiple_Result1) { var item = MapShipToAddressViewModel(r); item.Selected = false; retval.Add(item); } return(retval); //return WSCustomer; } catch (Exception ex) { throw; } }
public static async Task <WSCreateNAVProject.Update_Result> UpdateNavProject(string Key, ProjectDetailsViewModel ProjectToUpdate, NAVWSConfigurations WSConfigurations) { WSCreateNAVProject.Update NAVUpdate = new WSCreateNAVProject.Update() { WSJob = new WSCreateNAVProject.WSJob() { Key = Key, No = ProjectToUpdate.ProjectNo, Description100 = ProjectToUpdate.Description, Bill_to_Customer_No = ProjectToUpdate.ClientNo, Estado_eSUCH = (Estado_eSUCH)((int)ProjectToUpdate.Status), Estado_eSUCHSpecified = true, RegionCode20 = ProjectToUpdate.RegionCode, FunctionAreaCode20 = ProjectToUpdate.FunctionalAreaCode, ResponsabilityCenterCode20 = ProjectToUpdate.ResponsabilityCenterCode, Job_Posting_Group = "" //Project_Manager = ProjectToUpdate.ProjectLeader, //Person_Responsible = ProjectToUpdate.ProjectResponsible } }; //Configure NAV Client EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_Job_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSCreateNAVProject.WSJob_PortClient WS_Client = new WSCreateNAVProject.WSJob_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 { WSCreateNAVProject.Update_Result result = await WS_Client.UpdateAsync(NAVUpdate); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static async Task <WSCreateNAVProject.Read_Result> GetNavProject(string ProjectNo, NAVWSConfigurations WSConfigurations) { //Configure NAV Client EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_Job_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSCreateNAVProject.WSJob_PortClient WS_Client = new WSCreateNAVProject.WSJob_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 { WSCreateNAVProject.Read_Result result = await WS_Client.ReadAsync(ProjectNo); return(result); } catch (Exception ex) { throw; } }
public static async Task <WSPurchaseInvHeader.Create_Result> CreateAsync(PurchOrderDTO purchFromSupplier, NAVWSConfigurations WSConfigurations) { if (purchFromSupplier == null) { throw new ArgumentNullException("purchFromSupplier"); } int localMarketRegion; if (int.TryParse(purchFromSupplier.LocalMarketRegion, out localMarketRegion)) { localMarketRegion--; } WSPurchaseInvHeader.Create navCreate = new WSPurchaseInvHeader.Create() { WSPurchInvHeaderInterm = new WSPurchaseInvHeader.WSPurchInvHeaderInterm() { Buy_from_Vendor_No = purchFromSupplier.SupplierId, Pay_to_Vendor_No = purchFromSupplier.SupplierId, LocationCode = purchFromSupplier.LocationCode, RegionCode20 = purchFromSupplier.RegionCode, FunctionAreaCode20 = purchFromSupplier.FunctionalAreaCode, ResponsabilityCenterCode20 = purchFromSupplier.CenterResponsibilityCode, //Your_Reference = purchFromSupplier //Observacoes = purchFromSupplier; //Purchaser_Code = purchFromSupplier; //N_Consulta = purchFromSupplier; //Expected_Receipt_Date = purchFromSupplier; //Expected_Receipt_DateSpecified = true; //Responsibility_Center = purchFromSupplier; //V_Prop_Num = purchFromSupplier; //Ship_to_Name = purchFromSupplier; //Ship_to_Name_2 = purchFromSupplier; //Ship_to_Address = purchFromSupplier; //Ship_to_Address_2 = purchFromSupplier; //Ship_to_City = purchFromSupplier; //Ship_to_Contact = purchFromSupplier; //Ship_to_Post_Code = purchFromSupplier; //Ship_to_County = purchFromSupplier; //Ship_to_Country_Region_Code = purchFromSupplier; Requisition_No = purchFromSupplier.RequisitionId, //Payment_Terms_Code = purchFromSupplier; Mercado_Local_Regiao = (WSPurchaseInvHeader.Mercado_Local_Regiao)localMarketRegion, Mercado_Local_RegiaoSpecified = true, //Motivo_Anulacao_Encomenda = purchFromSupplier, //Motivo_Anulacao_EncomendaSpecified = true; //Encomenda_Origem_NAV17 = purchFromSupplier, //Utilizador_Criacao = purchFromSupplier, Prices_Including_VAT = purchFromSupplier.PricesIncludingVAT.HasValue ? purchFromSupplier.PricesIncludingVAT.Value : false, Prices_Including_VATSpecified = purchFromSupplier.PricesIncludingVAT.HasValue, Down_Payment = purchFromSupplier.InAdvance.HasValue ? purchFromSupplier.InAdvance.Value : false, Down_PaymentSpecified = purchFromSupplier.InAdvance.HasValue, Vendor_Mail = purchFromSupplier.Vendor_Mail, N_Consulta = purchFromSupplier.NAVPrePurchOrderId, Purchaser_Code = purchFromSupplier.Purchaser_Code } }; //Configure NAV Client EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_PurchaseInvIntermHeader_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSPurchaseInvHeader.WSPurchInvHeaderInterm_PortClient ws_Client = new WSPurchaseInvHeader.WSPurchInvHeaderInterm_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 //{ return(await ws_Client.CreateAsync(navCreate)); //} //catch (Exception ex) //{ // throw; //} }
public static async Task <WSGenericCodeUnit.FxCabimento_Result> CreatePurchaseOrder(String prePurchHeaderNo, NAVWSConfigurations WSConfigurations) { //Configure NAV Client EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_Generic_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSGenericCodeUnit.WsGeneric_PortClient ws_Client = new WSGenericCodeUnit.WsGeneric_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 //{ return(await ws_Client.FxCabimentoAsync(prePurchHeaderNo)); //} //catch (Exception ex) //{ // return null; //} }
public static async Task <WsPrePurchaseDocs.Create_Result> CreateAsync(BillingReceptionModel purchDoc, string prePurchInvoiceNoSerie, NAVWSConfigurations WSConfigurations) { if (purchDoc == null) { throw new ArgumentNullException("purchDoc"); } WsPrePurchaseDocs.WSPrePurchaseDocs itemToCreate = new WsPrePurchaseDocs.WSPrePurchaseDocs(); itemToCreate.Document_Type = (WsPrePurchaseDocs.Document_Type)purchDoc.TipoDocumento; itemToCreate.Document_TypeSpecified = true; itemToCreate.RegionCode20 = purchDoc.CodRegiao; itemToCreate.FunctionAreaCode20 = purchDoc.CodAreaFuncional; itemToCreate.ResponsabilityCenterCode20 = purchDoc.CodCentroResponsabilidade; itemToCreate.Buy_from_Vendor_No = purchDoc.CodFornecedor; itemToCreate.Rececao_Faturacao = purchDoc.Id; itemToCreate.No_Series = string.Empty; itemToCreate.Posting_No_Series = prePurchInvoiceNoSerie; if (purchDoc.Valor.HasValue) { itemToCreate.Valor_Factura = purchDoc.Valor.Value; itemToCreate.Valor_FacturaSpecified = true; } if (purchDoc.TipoDocumento == Enumerations.BillingDocumentTypes.Fatura) { itemToCreate.Vendor_Invoice_No = purchDoc.NumDocFornecedor; } else { itemToCreate.Vendor_Cr_Memo_No = purchDoc.NumDocFornecedor; } WsPrePurchaseDocs.Create navCreate = new WsPrePurchaseDocs.Create(itemToCreate); //Configure NAV Client EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_PurchaseHeaderDocs_URL.Replace("Company", WSConfigurations.WS_User_Company)); WsPrePurchaseDocs.WSPrePurchaseDocs_PortClient ws_Client = new WsPrePurchaseDocs.WSPrePurchaseDocs_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 //{ return(await ws_Client.CreateAsync(navCreate)); //} //catch (Exception ex) //{ // throw; //} }
public static async Task <WSVendorNAV.Delete_Result> DeleteAsync(string VendorNo, NAVWSConfigurations WSConfigurations) { if (VendorNo == null) { throw new ArgumentNullException("VendorNo"); } //Configure NAV Vendor EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_Vendor_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSVendorNAV.WSVendor_PortClient ws_Vendor = new WSVendorNAV.WSVendor_PortClient(navWSBinding, ws_URL); ws_Vendor.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; ws_Vendor.ClientCredentials.Windows.ClientCredential = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain); try { WSVendorNAV.Read_Result resultRead = await ws_Vendor.ReadAsync(VendorNo); WSVendorNAV.Delete_Result result = await ws_Vendor.DeleteAsync(resultRead.WSVendor.Key); return(result); } catch (Exception ex) { throw; } }
public static async Task <WSCustomerNAV.Create_Result> CreateAsync(ClientDetailsViewModel client, NAVWSConfigurations WSConfigurations) { if (client == null) { throw new ArgumentNullException("client"); } client.Cliente_Interno = false; WSCustomerNAV.Create navCreate = new WSCustomerNAV.Create() { WSCustomer = MapCustomerModelToCustomerNAV(client) }; navCreate.WSCustomer.No = null; //Configure NAV Client EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_Customer_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSCustomerNAV.WSCustomer_PortClient ws_Client = new WSCustomerNAV.WSCustomer_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 { /*var lastClientResult = await ws_Client.ReadMultipleAsync(null, null, -1); * * string lastClientNo = null, newClientNo = "1"; //default client No * if (lastClientResult != null) * lastClientNo = lastClientResult.ReadMultiple_Result1[0].No; * * if (lastClientNo != null) * { * var digits = from c in lastClientNo * where Char.IsDigit(c) * select c; * * var alphas = from c in lastClientNo * where !Char.IsDigit(c) * select c; * * if (alphas.Count() > 0) * newClientNo = String.Join("", alphas); * * if (digits.Count() > 0) * { * var newNum = int.Parse(String.Join("", digits)) + 1; * newClientNo += newNum.ToString(); * } * * } * * navCreate.WSCustomer.No = newClientNo;*/ navCreate.WSCustomer.Utilizador_Alteracao_eSUCH = client.Utilizador_Alteracao_eSUCH; navCreate.WSCustomer.Abrigo_Lei_CompromissoSpecified = true; navCreate.WSCustomer.BlockedSpecified = true; navCreate.WSCustomer.Cliente_AssociadoSpecified = true; navCreate.WSCustomer.Cliente_InternoSpecified = true; navCreate.WSCustomer.Cliente_NacionalSpecified = true; navCreate.WSCustomer.Data_Cliente_PaiSpecified = true; navCreate.WSCustomer.Natureza_ClienteSpecified = true; navCreate.WSCustomer.Regiao_ClienteSpecified = true; navCreate.WSCustomer.Taxa_AprovisionamentoSpecified = true; navCreate.WSCustomer.Tipo_ClienteSpecified = true; WSCustomerNAV.Create_Result result = await ws_Client.CreateAsync(navCreate); return(result); } catch (Exception ex) { throw; } }
public static async Task <WSVendorNAV.ReadMultiple_Result> GetAllAsync(int size, NAVWSConfigurations WSConfigurations) { //Configure NAV Vendor EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_Vendor_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSVendorNAV.WSVendor_PortClient WS_Vendor = new WSVendorNAV.WSVendor_PortClient(navWSBinding, WS_URL); WS_Vendor.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; WS_Vendor.ClientCredentials.Windows.ClientCredential = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain); var filter = new WSVendorNAV.WSVendor_Filter { Field = WSVendorNAV.WSVendor_Fields.No, Criteria = "200*" }; var filterArray = new WSVendorNAV.WSVendor_Filter[] { filter }; try { WSVendorNAV.ReadMultiple_Result result = await WS_Vendor.ReadMultipleAsync(filterArray, null, size); return(result); } catch (Exception ex) { throw; } }
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 static async Task <WSNovaGuiaTransporte_Result> CreateAsync(string userId, NAVWSConfigurations WSConfigurations) { if (userId == null || userId == "") { return(null); } WSNovaGuiaTransporte novaGuia = new WSNovaGuiaTransporte() { idUtilizador = userId }; EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.Ws_SuchNav2017_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSNAV2017_PortClient ws_Client = new WSNAV2017_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 { WSNovaGuiaTransporte_Result result = await ws_Client.WSNovaGuiaTransporteAsync(userId); return(result); } catch (Exception) { return(null); } }
public static async Task <WSCreatePreInvoiceLine.CreateMultiple_Result> CreatePreInvoiceLineList(List <LinhasFaturaçãoContrato> LinesList, String HeaderNo, NAVWSConfigurations WSConfigurations) { int counter = 0; 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 = x.Descrição != null && x.Descrição.Length > 50 ? x.Descrição.Substring(0, 50) : !string.IsNullOrEmpty(x.Descrição) ? x.Descrição : "", Description_2 = 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 static async Task <WSCreatePreInvoice.Create_Result> CreatePreInvoice(AuthorizedCustomerBillingHeader billingHeader, NAVWSConfigurations WSConfigurations) { SPInvoiceListViewModel invoiceHeader = new SPInvoiceListViewModel(); invoiceHeader.InvoiceToClientNo = billingHeader.InvoiceToClientNo; invoiceHeader.Date = billingHeader.Date; invoiceHeader.CommitmentNumber = billingHeader.CommitmentNumber; invoiceHeader.ClientRequest = billingHeader.ClientRequest; invoiceHeader.ClientVATReg = billingHeader.ClientVATReg; invoiceHeader.ContractNo = billingHeader.ContractNo; invoiceHeader.Currency = billingHeader.Currency; invoiceHeader.ServiceDate = billingHeader.ServiceDate; invoiceHeader.UpdateDate = billingHeader.UpdateDate; invoiceHeader.RegionCode = billingHeader.RegionCode; invoiceHeader.FunctionalAreaCode = billingHeader.FunctionalAreaCode; invoiceHeader.ResponsabilityCenterCode = billingHeader.ResponsabilityCenterCode; invoiceHeader.LocationCode = billingHeader.LocationCode; invoiceHeader.Comments = billingHeader.Comments; invoiceHeader.CodTermosPagamento = billingHeader.CodTermosPagamento; invoiceHeader.CodMetodoPagamento = billingHeader.CodMetodoPagamento; invoiceHeader.CreateUser = billingHeader.CreateUser; invoiceHeader.FaturaPrecosIvaIncluido = billingHeader.FaturaPrecosIvaIncluido.HasValue ? (bool)billingHeader.FaturaPrecosIvaIncluido : false; return(await CreatePreInvoice(invoiceHeader, WSConfigurations)); }
public static async Task <WSCreatePreInvoiceLine.CreateMultiple_Result> CreatePreInvoiceLineListProject(List <SPInvoiceListViewModel> LinesList, String HeaderNo, string OptionInvoice, NAVWSConfigurations WSConfigurations) { int counter = 0; int array = 0; WSCreatePreInvoiceLine.WsPreInvoiceLine[] parsedList = new WSCreatePreInvoiceLine.WsPreInvoiceLine[LinesList.Count]; foreach (var x in LinesList) { TiposRefeição refeicao = DBMealTypes.GetById(x.MealType ?? 0); WSCreatePreInvoiceLine.WsPreInvoiceLine line = new WSCreatePreInvoiceLine.WsPreInvoiceLine(); line.Document_Type = OptionInvoice.Replace(" ", String.Empty) == "4" ? WSCreatePreInvoiceLine.Document_Type.Credit_Memo : WSCreatePreInvoiceLine.Document_Type.Invoice; line.Document_TypeSpecified = true; line.Document_No = HeaderNo; line.Type = ConvertInvoiceLineType(x.Type.ToString()); line.No = x.Code; line.Description100 = x.Description; line.QuantitySpecified = true; line.Quantity = x.Quantity.HasValue ? x.Quantity.Value : 0; line.TypeSpecified = true; line.Unit_of_Measure = x.MeasurementUnitCode; //line.Unit_of_Measure_Code = x.MeasurementUnitCode; line.Location_Code = x.LocationCode; line.Unit_Price = x.UnitPrice.HasValue ? x.UnitPrice.Value : 0; line.Unit_PriceSpecified = true; line.Unit_Cost_LCY = x.UnitCost.HasValue ? x.UnitCost.Value : 0; line.Unit_Cost_LCYSpecified = true; line.Line_No = counter += 10000; line.Line_NoSpecified = true; line.Job_No = x.ProjectNo; line.gJobDimension = x.ProjectDimension; line.Service_Contract_No = x.ContractNo; line.Contract_No_Portal = x.ContractNo; line.Contract_No = x.ContractNo; line.Tipo_Refeicao = x.MealType.HasValue ? x.MealType.Value.ToString() : string.Empty;// (refeicao!=null) ? refeicao.Código.ToString() : ""; line.Gen_Prod_Posting_Group = (refeicao != null) ? refeicao.GrupoContabProduto : x.ProjectContabGroup; line.Cod_Serv_Cliente = x.ServiceClientCode; line.Consumption_Date = !string.IsNullOrEmpty(x.ConsumptionDate) ? DateTime.Parse(x.ConsumptionDate) : DateTime.MinValue; line.Consumption_DateSpecified = !string.IsNullOrEmpty(x.ConsumptionDate); line.Grupo_Serviço = !string.IsNullOrEmpty(x.ServiceGroupCode) ? x.ServiceGroupCode : ""; line.Service_Group_Description = !string.IsNullOrEmpty(x.ServiceGroupCode) && DBServices.GetById(x.ServiceGroupCode) != null?DBServices.GetById(x.ServiceGroupCode).Descrição : ""; line.Nº_Guia_Externa = x.ExternalGuideNo; line.Nº_Guia_Resíduos_GAR = x.WasteGuideNo_GAR; line.RegionCode20 = x.RegionCode; line.FunctionAreaCode20 = x.FunctionalAreaCode; line.ResponsabilityCenterCode20 = x.ResponsabilityCenterCode; line.Des_Serv_Cliente = !string.IsNullOrEmpty(x.ServiceClientCode) ? DBServices.GetById(x.ServiceClientCode) != null?DBServices.GetById(x.ServiceClientCode).Descrição : "" : ""; line.Data_Registo_Diario = !string.IsNullOrEmpty(x.ConsumptionDate) ? DateTime.Parse(x.ConsumptionDate) : DateTime.MinValue; line.Data_Registo_DiarioSpecified = !string.IsNullOrEmpty(x.ConsumptionDate); if (x.ResourceType.HasValue) { line.Tipo_Recurso = (WSCreatePreInvoiceLine.Tipo_Recurso)x.ResourceType.Value; line.Tipo_RecursoSpecified = true; } parsedList[array] = line; array++; //Job_Journal_Line_No_Portal = x.LineNo, //Job_Journal_Line_No_PortalSpecified = true, } ; 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 //{ return(await WS_Client.CreateMultipleAsync(NAVCreate)); //} //catch (Exception ex) //{ // return null; //} }
public static async Task <WSCreatePreInvoice.Create_Result> CreatePreInvoiceHeader(NAVSalesHeaderViewModel PreInvoiceToCreate, NAVWSConfigurations WSConfigurations) { WSCreatePreInvoice.Create NAVCreate = new WSCreatePreInvoice.Create() { WSPreInvoice = new WSCreatePreInvoice.WSPreInvoice() { Sell_to_Customer_No = PreInvoiceToCreate.Sell_toCustomerNo, Document_Date = PreInvoiceToCreate.DocumentDate, Shipment_Date = PreInvoiceToCreate.ShipmentDate, Periodo_de_Fact_Contrato = PreInvoiceToCreate.PeriododeFact_Contrato, Valor_Contrato = PreInvoiceToCreate.ValorContrato, Ship_to_Code = PreInvoiceToCreate.Ship_toCode, //Ship_to_Address = PreInvoiceToCreate.Ship_toAddress.Length >= 50 ? PreInvoiceToCreate.Ship_toAddress.Substring(0, 49) : PreInvoiceToCreate.Ship_toAddress, //Ship_to_Address_2 = PreInvoiceToCreate.Ship_toAddress2, //Ship_to_City = PreInvoiceToCreate.Ship_toCity, //Ship_to_Contact = PreInvoiceToCreate.Ship_toContact, //Ship_to_Country_Region_Code = PreInvoiceToCreate.Ship_toCountryRegionCode, //Ship_to_County = PreInvoiceToCreate.Ship_toCounty, //Ship_to_Name = PreInvoiceToCreate.Ship_toName, //Ship_to_Name_2 = PreInvoiceToCreate.Ship_toName2, //Ship_to_Post_Code = PreInvoiceToCreate.Ship_toPostCode, Currency_Code = PreInvoiceToCreate.CurrencyCode, Due_Date = PreInvoiceToCreate.DueDate, Payment_Terms_Code = PreInvoiceToCreate.PaymentTermsCode, Payment_Method_Code = PreInvoiceToCreate.PaymentMethodCode, Responsibility_Center = PreInvoiceToCreate.ResponsibilityCenter, Posting_No_Series = PreInvoiceToCreate.PostingNoSeries, No_Compromisso = PreInvoiceToCreate.No_Compromisso, Codigo_Pedido = PreInvoiceToCreate.CodigoPedido, Data_Encomenda = PreInvoiceToCreate.DataEncomenda, Data_Serv_Prestado = PreInvoiceToCreate.DataServ_Prestado, Observacoes = PreInvoiceToCreate.Observacoes, Contract_No = PreInvoiceToCreate.ContractNo, Document_Type = WSCreatePreInvoice.Document_Type.Invoice, Factura_CAF = PreInvoiceToCreate.FacturaCAF, User_pre_registo_2009 = PreInvoiceToCreate.Userpreregisto2009, Posting_Date = PreInvoiceToCreate.PostingDate, Document_TypeSpecified = true, Posting_DateSpecified = true, Shipment_DateSpecified = true, Shipment_Start_TimeSpecified = true, ReportID_OriginalSpecified = true, Valor_ContratoSpecified = true, Document_DateSpecified = true, Factura_CAFSpecified = true, Due_DateSpecified = true, Order_DateSpecified = true, Data_EncomendaSpecified = true, CommentSpecified = true, Debit_MemoSpecified = true, //Dimensions ResponsabilityCenterCode20 = PreInvoiceToCreate.ResponsabilityCenterCode20, FunctionAreaCode20 = PreInvoiceToCreate.FunctionAreaCode20, RegionCode20 = PreInvoiceToCreate.RegionCode20, Prices_Including_VAT = PreInvoiceToCreate.PricesIncludingVAT == 1 ? true : false, Prices_Including_VATSpecified = true } }; //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 { WSCreatePreInvoice.Create_Result result = await WS_Client.CreateAsync(NAVCreate); return(result); } catch (Exception ex) { return(null); } }
public static async Task <WSCreatePreInvoiceLine.Create_Result> CreatePreInvoiceLine(ProjectDiaryViewModel PreInvoiceLineToCreate, NAVWSConfigurations WSConfigurations, string PKey) { //Mapping Object WSCreatePreInvoiceLine.Type TypeValue; switch (PreInvoiceLineToCreate.Type) { case 1: TypeValue = WSCreatePreInvoiceLine.Type.Resource; break; case 2: TypeValue = WSCreatePreInvoiceLine.Type.Item; break; case 3: TypeValue = WSCreatePreInvoiceLine.Type.G_L_Account; break; case 4: TypeValue = WSCreatePreInvoiceLine.Type.Fixed_Asset; break; case 5: TypeValue = WSCreatePreInvoiceLine.Type.Charge_Item; break; default: TypeValue = WSCreatePreInvoiceLine.Type._blank_; break; } WSCreatePreInvoiceLine.Create NAVCreate = new WSCreatePreInvoiceLine.Create() { WsPreInvoiceLine = new WSCreatePreInvoiceLine.WsPreInvoiceLine() { Unit_PriceSpecified = true, Unit_Cost_LCYSpecified = true, Document_Type = WSCreatePreInvoiceLine.Document_Type.Invoice, Document_TypeSpecified = true, Document_No = PKey, Type = TypeValue, No = PreInvoiceLineToCreate.Code, Description100 = PreInvoiceLineToCreate.Description, QuantitySpecified = true, Quantity = (int)PreInvoiceLineToCreate.Quantity, TypeSpecified = true, Unit_of_Measure = PreInvoiceLineToCreate.MeasurementUnitCode, Location_Code = PreInvoiceLineToCreate.LocationCode, Unit_Price = (decimal)PreInvoiceLineToCreate.UnitPrice, Unit_Cost_LCY = (decimal)PreInvoiceLineToCreate.UnitCost, Job_Journal_Line_No_Portal = PreInvoiceLineToCreate.LineNo, Job_Journal_Line_No_PortalSpecified = true, } }; //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.Create_Result result = await WS_Client.CreateAsync(NAVCreate); return(result); } catch (Exception ex) { throw; } }
public static async Task <WSCreatePreInvoice.Create_Result> CreatePreInvoice(SPInvoiceListViewModel preInvoiceToCreate, NAVWSConfigurations WSConfigurations) { WSCreatePreInvoice.Document_Type tipo; bool notaDebito = false; string PostingNoSeries = ""; ConfigUtilizadores CUsers = DBUserConfigurations.GetById(preInvoiceToCreate.CreateUser); if (preInvoiceToCreate.MovementType == 2)//Nota de débito { tipo = WSCreatePreInvoice.Document_Type.Invoice; notaDebito = true; PostingNoSeries = CUsers.NumSerieNotasDebito; } else if (preInvoiceToCreate.MovementType == 4)//Nota de crédito { tipo = WSCreatePreInvoice.Document_Type.Credit_Memo; notaDebito = false; PostingNoSeries = CUsers.NumSerieNotasCredito; } else// Fatura { tipo = WSCreatePreInvoice.Document_Type.Invoice; notaDebito = false; PostingNoSeries = CUsers.NumSerieFaturas; } WSCreatePreInvoice.Create NAVCreate = new WSCreatePreInvoice.Create() { WSPreInvoice = new WSCreatePreInvoice.WSPreInvoice() { Document_Type = tipo, Document_TypeSpecified = true, Sell_to_Customer_No = preInvoiceToCreate.InvoiceToClientNo, VAT_Registration_No = preInvoiceToCreate.ClientVATReg, Contract_No = preInvoiceToCreate.ContractNo, Debit_Memo = notaDebito, Debit_MemoSpecified = true, Posting_No_Series = PostingNoSeries, Codigo_Pedido = preInvoiceToCreate.ClientRequest, Currency_Code = preInvoiceToCreate.Currency, Data_Serv_Prestado = preInvoiceToCreate.ServiceDate, Data_Encomenda = !string.IsNullOrEmpty(preInvoiceToCreate.DataPedido) ? DateTime.Parse(preInvoiceToCreate.DataPedido) : DateTime.MinValue, Data_EncomendaSpecified = !string.IsNullOrEmpty(preInvoiceToCreate.DataPedido), //Document_Date = preInvoiceToCreate.dat //Due_Date //Document_Date //External_Document_No RegionCode20 = preInvoiceToCreate.RegionCode, FunctionAreaCode20 = preInvoiceToCreate.FunctionalAreaCode, ResponsabilityCenterCode20 = preInvoiceToCreate.ResponsabilityCenterCode, Location_Code = preInvoiceToCreate.LocationCode, No_Compromisso = preInvoiceToCreate.CommitmentNumber, Observacoes = preInvoiceToCreate.Comments, Responsibility_Center = CUsers.CentroDeResponsabilidade, //Order_Date Payment_Method_Code = preInvoiceToCreate.CodMetodoPagamento, Payment_Terms_Code = preInvoiceToCreate.CodTermosPagamento, //Posting_Date Posting_Date = !string.IsNullOrEmpty(preInvoiceToCreate.Posting_Date.ToString()) ? DateTime.Parse(preInvoiceToCreate.Posting_Date.ToString()) : DateTime.MinValue, Posting_DateSpecified = !string.IsNullOrEmpty(preInvoiceToCreate.Posting_Date.ToString()), Document_Date = !string.IsNullOrEmpty(preInvoiceToCreate.Posting_Date.ToString()) ? DateTime.Parse(preInvoiceToCreate.Posting_Date.ToString()) : DateTime.MinValue, Document_DateSpecified = !string.IsNullOrEmpty(preInvoiceToCreate.Posting_Date.ToString()), External_Document_No = preInvoiceToCreate.ProjectNo, Ship_to_Address = preInvoiceToCreate.Ship_to_Address, Ship_to_Address_2 = preInvoiceToCreate.Ship_to_Address_2, Ship_to_City = preInvoiceToCreate.Ship_to_City, Ship_to_Code = preInvoiceToCreate.Ship_to_Code, Ship_to_Contact = preInvoiceToCreate.Ship_to_Contact, Ship_to_Country_Region_Code = preInvoiceToCreate.Ship_to_Country_Region_Code, Ship_to_County = preInvoiceToCreate.Ship_to_County, Ship_to_Name = preInvoiceToCreate.Ship_to_Name, Ship_to_Name_2 = preInvoiceToCreate.Ship_to_Name_2, Ship_to_Post_Code = preInvoiceToCreate.Ship_to_Post_Code, Prices_Including_VAT = preInvoiceToCreate.FaturaPrecosIvaIncluido.HasValue ? (bool)preInvoiceToCreate.FaturaPrecosIvaIncluido : false, Prices_Including_VATSpecified = true } }; //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); return(await WS_Client.CreateAsync(NAVCreate)); }
public static async Task <WSTransferShipmentHeader.Create_Result> CreateHeaderAsync(TransferShipment transferShipment, NAVWSConfigurations WSConfigurations) { if (transferShipment == null) { throw new ArgumentNullException("transferShipment"); } WSTransferShipmentHeader.Create navCreate = new WSTransferShipmentHeader.Create() { WSShipmentDocHeader = new WSTransferShipmentHeader.WSShipmentDocHeader() { Nº_Projecto = transferShipment.ProjectNo, FunctionAreaCode20 = transferShipment.FunctionalAreaNo, RegionCode20 = transferShipment.RegionNo, ResponsabilityCenterCode20 = transferShipment.ResponsibilityCenterNo, Nº_Requisição = transferShipment.RequisitionNo, Observações = transferShipment.Comments, Cod_Postal_Descarga = "4700-301", Post_Code = "4700-301", Local_Descarga1 = "Local_Descarga1", Morada_Cliente = "Morada_Cliente", Data_Descarga = DateTime.Now, Data_DescargaSpecified = true } }; //Configure NAV Client EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_TransferShipmentHeader_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSTransferShipmentHeader.WSShipmentDocHeader_PortClient ws_Client = new WSTransferShipmentHeader.WSShipmentDocHeader_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 //{ return(await ws_Client.CreateAsync(navCreate)); //} //catch (Exception ex) //{ // throw; //} }
public static async Task <WSCreatePreInvoice.Delete_Result> DeletePreInvoiceLineList(String HeaderNo, NAVWSConfigurations WSConfigurations) { //Configure NAV Client EndpointAddress WS_URL = new EndpointAddress(WSConfigurations.WS_PreInvoiceLine_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 { WSCreatePreInvoice.Delete_Result result = await WS_Client.DeleteAsync(HeaderNo); return(result); } catch (Exception ex) { return(null); } }
public static async Task <WSTransferShipmentLine.CreateMultiple_Result> CreateLinesAsync(TransferShipment transferShipment, NAVWSConfigurations WSConfigurations) { if (transferShipment == null) { throw new ArgumentNullException("transferShipment"); } int counter = 0; WSTransferShipmentLine.CreateMultiple navCreate = new WSTransferShipmentLine.CreateMultiple(); navCreate.WSShipmentDocLine_List = transferShipment.Lines.Select(line => new WSTransferShipmentLine.WSShipmentDocLine() { Nº_Linha = (counter += 10000), Nº_LinhaSpecified = true, Tipo = WSTransferShipmentLine.Tipo.Produto, TipoSpecified = true, No_projecto = transferShipment.ProjectNo, No = line.ProductNo, Descricao = line.ProductDescription, Nº_Documento = transferShipment.TransferShipmentNo, Quantidade = line.Quantity.HasValue ? line.Quantity.Value : 0, QuantidadeSpecified = true, Unit_Cost = line.UnitCost.HasValue ? line.UnitCost.Value : 0, Unit_CostSpecified = true, }) .ToArray(); //Configure NAV Client EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_TransferShipmentLine_URL.Replace("Company", WSConfigurations.WS_User_Company)); WSTransferShipmentLine.WSShipmentDocLine_PortClient ws_Client = new WSTransferShipmentLine.WSShipmentDocLine_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 //{ return(await ws_Client.CreateMultipleAsync(navCreate)); //} //catch (Exception ex) //{ // throw; //} }