使用web服务创建netsuite发票

本文关键字:netsuite 发票 创建 服务 web 使用 | 更新日期: 2023-09-27 18:13:41

我正在尝试使用Web服务c#创建Netsuite发票:

Invoice nsInvoice = new Invoice();
        //trainid
        nsInvoice.tranId = invoice.Code;
        //createdDate
        nsInvoice.tranDate = invoice.Date;
        nsInvoice.tranDateSpecified = true;
        //createdFrom
        //nsVendorBill.entity = NSPurchaseOrder.getRef(nsPurchaseOrder.internalId);
        nsInvoice.entity = NSVendor.getRef(nsSaleOrder2.entity.internalId);

从销售订单中复制所有行:

var invoiceItems = new List<InvoiceItem>();
            //copy from purchase order
            foreach (SalesOrderItem poitem in nsSaleOrder.itemList.item)
            {
                var invoiceItem = new InvoiceItem();
                invoiceItem.item = poitem.item;
                invoiceItem.orderLine = poitem.line;
                invoiceItem.orderLineSpecified = true;
                invoiceItem.isTaxable = false;
                invoiceItem.isTaxableSpecified = true;
                invoiceItem.quantity = 0;
                invoiceItem.quantitySpecified = true;
                invoiceItem.tax1Amt = 0;
                invoiceItem.tax1AmtSpecified = true;
                invoiceItems.Add(invoiceItem);
            }

和检查哪一行添加到发票(数量>0):

//update quantity
                foreach (var invoiceItem in invoiceItems)
                {
                    if (invoiceItem.item.internalId == itemID)
                    {
                        invoiceItem.isTaxable = true;
                        invoiceItem.quantity = line.Quantity;
                        invoiceItem.tax1Amt = line.Tax;
                        //custom pricelevel
                        RecordRef plRef = new RecordRef();
                        plRef.type = RecordType.priceLevel;
                        plRef.typeSpecified = true;
                        plRef.internalId = "-1";
                        invoiceItem.price = plRef;
                        invoiceItem.rate = "" + line.UnitPrice;
                    }
                }

然而,所有的行,即使是零数量,都列在发票上。

请问是否可以取消数量为零的行?

使用web服务创建netsuite发票

已解析。不需要从销售订单中复制所有的行。只需在发票上加上数量>0的行即可。

//itemlist
        {
            var invoiceItems = new List<InvoiceItem>();
            //override
            foreach (var line in invoice.SaleInvoiceLines)
            {
                //soline
                var soitem = (from t in nsSaleOrder.itemList.item
                              where t.item.internalId == line.PurchaseOrderLine.ProductSupplier.Product.NSInternalID
                              && t.poVendor.internalId == line.PurchaseOrderLine.ProductSupplier.Supplier.NSInternalID
                              select t).FirstOrDefault();
                if (soitem != null)
                {
                    //invoice item
                    var invoiceItem = new InvoiceItem();
                    invoiceItem.item = soitem.item;
                    invoiceItem.orderLine = soitem.line;
                    invoiceItem.orderLineSpecified = true;
                    invoiceItem.isTaxable = true;
                    invoiceItem.isTaxableSpecified = true;
                    invoiceItem.quantity = line.Quantity;
                    invoiceItem.quantitySpecified = true;
                    invoiceItem.tax1Amt = line.Tax;
                    invoiceItem.tax1AmtSpecified = true;
                    //price
                    RecordRef plRef = new RecordRef();
                    plRef.type = RecordType.priceLevel;
                    plRef.typeSpecified = true;
                    plRef.internalId = "-1";
                    invoiceItem.price = plRef;
                    invoiceItem.rate = "" + line.UnitPrice;
                    invoiceItems.Add(invoiceItem);
                }
                else
                {
                    throw new Exception(string.Format("Product [{0}] from Supplier [{1}] is missing",
                        line.PurchaseOrderLine.ProductSupplier.Product.Code,
                        line.PurchaseOrderLine.ProductSupplier.Supplier.Code));
                }
            }
            var itemReceiptItemList = new InvoiceItemList();
            itemReceiptItemList.item = invoiceItems.Where(t=>t.quantity>0).ToArray();
            itemReceiptItemList.replaceAll = true;
            nsInvoice.itemList = itemReceiptItemList;
        }