0

Create Sales Receipt

by
Published Mar 6, 2024

Creates a sales receipt. [See the documentation](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/salesreceipt#create-a-salesreceipt)

Script quickbooks Verified

The script

Submitted by hugo697 Bun
Verified 323 days ago
1
import QuickBooks from "node-quickbooks";
2

3
type Quickbooks = {
4
  realmId: string;
5
  token: string;
6
  isSandBox: boolean;
7
};
8

9
export async function main(
10
  resource: Quickbooks,
11
  salesReceipt: {
12
    Line: (
13
      | {
14
          Id: string;
15
          DetailType: "SalesItemLineDetail";
16
          SalesItemLineDetail: {
17
            TaxInclusiveAmt?: number;
18
            DiscountAmt?: number;
19
            ItemRef?: {
20
              value: string;
21
              name?: string;
22
            };
23
            ClassRef?: {
24
              value: string;
25
              name?: string;
26
            };
27
            TaxCodeRef?: {
28
              value: string;
29
              name?: string;
30
            };
31
            MarkupInfo?: {
32
              PriceLevelRef?: {
33
                value: string;
34
                name?: string;
35
              };
36
              Percent?: number;
37
              MarkUpIncomeAccountRef?: {
38
                value: string;
39
                name?: string;
40
              };
41
            };
42
            ItemAccountRef?: {
43
              value: string;
44
              name?: string;
45
            };
46
            ServiceDate?: string;
47
            DiscountRate?: number;
48
            Qty?: number;
49
            UnitPrice?: number;
50
            TaxClassificationRef?: {
51
              value: string;
52
              name?: string;
53
            };
54
          };
55
          Amount: number;
56
          Description?: string;
57
          LineNum?: number;
58
        }
59
      | {
60
          Id: string;
61
          GroupLineDetail: {
62
            Quantity?: number;
63
            Line?: {
64
              Id: string;
65
              DetailType: "SalesItemLineDetail";
66
              SalesItemLineDetail: {
67
                TaxInclusiveAmt?: number;
68
                DiscountAmt?: number;
69
                ItemRef?: {
70
                  value: string;
71
                  name?: string;
72
                };
73
                ClassRef?: {
74
                  value: string;
75
                  name?: string;
76
                };
77
                TaxCodeRef?: {
78
                  value: string;
79
                  name?: string;
80
                };
81
                MarkupInfo?: {
82
                  PriceLevelRef?: {
83
                    value: string;
84
                    name?: string;
85
                  };
86
                  Percent?: number;
87
                  MarkUpIncomeAccountRef?: {
88
                    value: string;
89
                    name?: string;
90
                  };
91
                };
92
                ItemAccountRef?: {
93
                  value: string;
94
                  name?: string;
95
                };
96
                ServiceDate?: string;
97
                DiscountRate?: number;
98
                Qty?: number;
99
                UnitPrice?: number;
100
                TaxClassificationRef?: {
101
                  value: string;
102
                  name?: string;
103
                };
104
              };
105
              Amount: number;
106
              Description?: string;
107
              LineNum?: number;
108
            }[];
109
            GroupItemRef?: {
110
              value: string;
111
              name?: string;
112
            };
113
          };
114
          DetailType: "GroupLineDetail";
115
          LineNum?: number;
116
          Description?: string;
117
        }
118
    )[];
119
    CurrencyRef?: {
120
      value: string;
121
      name?: string;
122
    };
123
    ProjectRef?: {
124
      value: string;
125
      name?: string;
126
    };
127
  }
128
) {
129
  const qbo = new QuickBooks("", "", resource.token, false, resource.realmId, resource.isSandBox, true, null, "2.0");
130

131
  return new Promise((resolve, reject) => {
132
    qbo.createSalesReceipt(salesReceipt, function (err: any, result: any) {
133
      if (err) {
134
        reject(err);
135
      } else {
136
        resolve(result);
137
      }
138
    });
139
  });
140
}
141