Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QBO/.NET SDK [Quickbooks Online] - How to remove empty invoice line item?

I have a new issue with quickbooks invoice. Upon creation of an invoice I get all items I added plus one extra line item in my invoice.

How do I filter, remove, prevent this line from appearing?

Here is what I have tried.

//Find Item
var itemQueryService = new QueryService<Item>(qboContextoAuth);
Item item = itemQueryService.ExecuteIdsQuery("Select * From Item StartPosition 1 MaxResults 1").FirstOrDefault();

int idx = 0;

var lines = new List<Line>();

foreach (var orderItem in orderItems)
{

    //Line
    Line invoiceLine = new Line();

    //Line Description
    invoiceLine.Description = itemRepository.Get(i => i.ItemID == orderItem.ItemID).First().FullDescription;

    //Line Amount
    invoiceLine.Amount = orderItem.Price * orderItem.Quantity;

    invoiceLine.AmountSpecified = true;

    //Line Detail Type
    invoiceLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail;

    invoiceLine.DetailTypeSpecified = true;

    //Line Sales Item Line Detail
    SalesItemLineDetail lineSalesItemLineDetail = new SalesItemLineDetail();


    //Line Sales Item Line Detail - ItemRef
    lineSalesItemLineDetail.ItemRef = new ReferenceType()
    {
        name = itemRepository.Get(i => i.ItemID == orderItem.ItemID).First().FullDescription,
                    Value = item.Id
               };

        //Line Sales Item Line Detail - UnitPrice
        lineSalesItemLineDetail.AnyIntuitObject = orderItem.Price; //33m;
        lineSalesItemLineDetail.ItemElementName = ItemChoiceType.UnitPrice;

        //Line Sales Item Line Detail - Qty
        lineSalesItemLineDetail.Qty = orderItem.Quantity; //10;
        lineSalesItemLineDetail.QtySpecified = true;

        //Line Sales Item Line Detail - TaxCodeRef
        //For US companies, this can be 'TAX' or 'NON

        /* lineSalesItemLineDetail.TaxCodeRef = new ReferenceType()
         {
             Value = "TAX"
         };*/

        //Line Sales Item Line Detail - ServiceDate 
        lineSalesItemLineDetail.ServiceDate = DateTime.Now.Date;
        lineSalesItemLineDetail.ServiceDateSpecified = true;

        //Assign Sales Item Line Detail to Line Item
        invoiceLine.AnyIntuitObject = lineSalesItemLineDetail;

        //Assign Line Item to Invoice
        //invoice.Line = new Line[] { invoiceLine };
        lines.Add(invoiceLine);

        //TxnTaxDetail
        /*TxnTaxDetail txnTaxDetail = new TxnTaxDetail();
        txnTaxDetail.TxnTaxCodeRef = new ReferenceType()
        {
            name = stateTaxCode.Name,
            Value = stateTaxCode.Id
        };
        Line taxLine = new Line();
        taxLine.DetailType = LineDetailTypeEnum.TaxLineDetail;
        TaxLineDetail taxLineDetail = new TaxLineDetail();

        //Assigning the fist Tax Rate in this Tax Code
        taxLineDetail.TaxRateRef = stateTaxCode.SalesTaxRateList.TaxRateDetail[0].TaxRateRef;
        taxLine.AnyIntuitObject = taxLineDetail;
        txnTaxDetail.TaxLine = new Line[] { taxLine };
        invoice.TxnTaxDetail = txnTaxDetail;
        */

        idx++;
    }

Removal Code

Item item2 = itemQueryService.ExecuteIdsQuery("Select * From Item StartPosition 2 MaxResults 1").FirstOrDefault();

//Line Sales Item Line Detail - ItemRef
SalesItemLineDetail lineDetail = new SalesItemLineDetail();
Line removeLine = new Line();

lineDetail.ItemRef = new ReferenceType()
{
    Value = item2.Id
};
removeLine.AnyIntuitObject = lineDetail;

lines.RemoveAt(1);

Related question:

Quickbooks Online Accounting - How to add multiple line items in an invoice?

like image 886
Vahe J Avatar asked Jul 31 '17 17:07

Vahe J


People also ask

How do I delete an item in QuickBooks online?

Go to Inventory, then select Products. Double-click the product you want to delete. Select Delete Product. Select Yes, Delete Product.

What is the difference between voiding and deleting an invoice in QuickBooks?

When you void a transaction in QuickBooks, you still have a record of the transaction, but it won't affect your account balances or reports. When you delete a transaction in QuickBooks, the transaction is completely erased from your books, and it won't appear on any reports or in any accounts.


1 Answers

Check that extra line item's Detail Type, It must be SubTotalLineDetail. It's SubTotal of all line items. Then you can skip it on it's enum type.

like image 125
user6395764 Avatar answered Oct 06 '22 00:10

user6395764