Search code examples
javascriptquickbooksquickbooks-online

How to set invoice date in quickbooks invoice?


I am using quickbooks and I want to set the invoice date to what ever I want. I am using this code.

If I set it to TxnDate field it throws me error. So how can I set the invStartDate?

const createInvoiceObj = {
    DocNumber: docNumber,
    Line: [
      {
        Id: "1",
        LineNum: 1,
        Description: `The description`,
        Amount: 1232,
        DetailType: "SalesItemLineDetail",
        SalesItemLineDetail: {
          ItemRef: {
            value: "19",
            name: "Service"
          },
          UnitPrice: 1232,
          Qty: "1"
        }
      }
    ],
    CustomerRef: {
      value: "1"
    },
    CustomerMemo: {
      value: "Thank you for your business and have a great day!"
    },
    TotalAmt: totalAmount,
    TxnDate: moment(order.createdAt).format("YYYY-MM-DD")  // TxnDate: '2020-05-22'
  };

enter image description here

Error I am getting when using TxnDate

{
  "Fault": {
    "Error": [
      {
        "Message": "Transaction date is prior to start date for inventory item",
        "Detail": "Transactions with inventory (QOH) products cant be dated earlier than the Inventory Start Date for the product",
        "code": "6270",
        "element": ""
      }
    ],
    "type": "ValidationFault"
  },
  "time": "2020-05-27T05:26:58.217-07:00"
}

Solution

  • The correct field to set the date of the invoice is TxnDate.

    Example:

    {
      "Invoice": {
        "TxnDate": "2014-09-19", 
    ...
    

    This is documented well here:

    If you get this error message:

    "Error": [
          {
            "Message": "Transaction date is prior to start date for inventory item",
            "Detail": "Transactions with inventory (QOH) products cant be dated earlier than the Inventory Start Date for the product",
            "code": "6270",
            "element": ""
          }
        ],
    

    It means you're sending a date that makes no sense. In a real-world scenario, what you're trying to do is this:

    You have 0 widgets in inventory 
    You try to sell 5 items (you can't, you have zero items in inventory)
    You start carrying and stocking widgets in inventory 
    

    The invoice date needs to be after the date you created/started carrying the item/product.

    Change the date of the invoice so that the invoice is dated after you stated carrying the item/product.