2014-03-31 30 views
0

从微软Dynamics GP的2013通过下面的代码创建销售发票Web服务:动态GP:读销售发票的行项目

private void CreateInvoice() 
    { 
     CompanyKey companyKey; 
     Context context; 
     SalesInvoice salesInvoice; 
     SalesDocumentTypeKey salesInvoiceType; 
     CustomerKey customerKey; 
     BatchKey batchKey; 
     SalesInvoiceLine salesInvoiceLine; 
     ItemKey invoiceItem; 
     Quantity invoiceCount; 
     Policy salesInvoiceCreatePolicy; 
     MoneyAmount unitPrice; 

     DynamicsGPClient wsDynamicsGP = new DynamicsGPClient(); 
     context = new Context(); 
     companyKey = new CompanyKey(); 
     companyKey.Id = (-1); 
     context.OrganizationKey = (OrganizationKey)companyKey; 
     salesInvoice = new SalesInvoice(); 
     salesInvoice.Key = new SalesDocumentKey(); 
     salesInvoice.Key.Id = "XX555"; 
     salesInvoiceType = new SalesDocumentTypeKey(); 
     salesInvoiceType.Type = SalesDocumentType.Invoice; 
     salesInvoice.DocumentTypeKey = salesInvoiceType; 
     customerKey = new CustomerKey(); 
     customerKey.Id = "ADAMPARK0001";// "AARONFIT0001"; 
     salesInvoice.CustomerKey = customerKey; 
     batchKey = new BatchKey(); 
     batchKey.Id = "SALES INVOICES"; 
     salesInvoice.BatchKey = batchKey; 

     IList<SalesInvoiceLine> salesInvoiceLines = new List<SalesInvoiceLine>(); 
     string[] itemId = { "ACCS-HDS-1EAR", "32X IDE" }; //"ACCS-RST-DXBK";// "512 SDRAM";//    
     for (int i = 0; i < itemId.Count(); i++) 
     { 
      salesInvoiceLine = new SalesInvoiceLine(); 
      invoiceItem = new ItemKey(); 
      invoiceItem.Id = itemId[i]; 
      salesInvoiceLine.ItemKey = invoiceItem; 
      unitPrice = new MoneyAmount(); 
      unitPrice.Currency = "USD"; 
      unitPrice.DecimalDigits = 2; 
      unitPrice.Value = 1.00M; 
      salesInvoiceLine.UnitPrice = unitPrice; 
      invoiceCount = new Quantity(); 
      invoiceCount.Value = 1 + i; 
      salesInvoiceLine.Quantity = invoiceCount; 
      salesInvoiceLines.Add(salesInvoiceLine); 
     }    
     SalesInvoiceLine[] invoiceLines = salesInvoiceLines.ToArray(); 
     salesInvoice.Lines = invoiceLines; 
     salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context); 
     wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy); 
     if (wsDynamicsGP.State != CommunicationState.Faulted) 
     { 
      wsDynamicsGP.Close();    
     } 
    } 

Creating Sales Invoice Example is here

阅读销售发票由下面的代码:

private void ShowInvoice() 
    { 

     CompanyKey companyKey; 
     Context context; 
     LikeRestrictionOfstring salespersonIdRestriction; 
     ListRestrictionOfNullableOfSalesTransactionState transactionStateRestriction; 
     SalesInvoiceCriteria salesInvoiceCriteria; 
     SalesInvoiceSummary[] salesInvoiceSummary; 
     BetweenRestrictionOfNullableOfdateTime restriction; 

     DynamicsGPClient wsDynamicsGP = new DynamicsGPClient(); 
     context = new Context(); 
     companyKey = new CompanyKey(); 
     companyKey.Id = (-1); 
     context.OrganizationKey = (OrganizationKey)companyKey; 
     salespersonIdRestriction = new LikeRestrictionOfstring(); 
     transactionStateRestriction = new ListRestrictionOfNullableOfSalesTransactionState(); 
     transactionStateRestriction.EqualValue = SalesTransactionState.Work; 
     salesInvoiceCriteria = new SalesInvoiceCriteria(); 
     salesInvoiceCriteria.TransactionState = transactionStateRestriction; 
     salesInvoiceCriteria.SalespersonId = salespersonIdRestriction; 
     salesInvoiceSummary = wsDynamicsGP.GetSalesInvoiceList(salesInvoiceCriteria, context); 

     StringBuilder summaryList = new StringBuilder();   
     foreach (SalesInvoiceSummary a in salesInvoiceSummary) 
     { 
      summaryList.AppendLine("<b>Invoice number:</b> " + a.Key.Id + " <b>Invoice amount:</b> " + a.TotalAmount.Value.ToString("C")); 
     } 
     if (wsDynamicsGP.State != CommunicationState.Faulted) 
     { 
      wsDynamicsGP.Close(); 
     } 
    } 

Reading Sales Invoice Example is here

问题是:如何获取特定发票的行项目?

回答

1

您需要获取包含关联订单项的实际SalesInvoice对象。您可以使用GetSalesInvoiceByKey()传递发票的订单号(SOPNUMBE)来完成此操作。

扩展你的第二个例子:

foreach (SalesInvoiceSummary a in salesInvoiceSummary) 
{ 
    summaryList.AppendLine("<b>Invoice number:</b> " + a.Key.Id + " <b>Invoice amount:</b> " + a.TotalAmount.Value.ToString("C")); 

    SalesInvoice invoice = wsDynamicsGP.GetSalesInvoiceByKey(a.Key.Id, context); 
    SalesInvoiceLine[] lineItems = invoice.Lines; 
} 

然而,有没有要求调用GetSalesInvoiceList()第一 - 你可以直接打电话GetSalesInvoiceByKey()如果知道订单编号。