如何使用QuickBooks Online Java SDK创建发票实体

时间:2014-04-30 13:45:20

标签: java quickbooks intuit-partner-platform quickbooks-online intuit

我指的是SDK的v3(2.2.1)版本。我试图找出创建发票需要做的事情。我的问题不是任何错误或连接问题,只是文档看起来很差而且没有例子。所以我拥有的是:

BatchOperation batch= new BatchOperation();
Invoice invoice = new Invoice();
invoice.set...
...
batch.addEntity(invoice, OperationEnum.CREATE, "bID");

问题在于,我只是不明白Invoice实体的许多 setter方法如何与一般发票相对应,例如ID,客户身份等。

如果有人这样做过,你能不能给我一个例子,说明我可能想要用于通用发票的那些种子。我的主要问题是JavaDoc中所有Invoice setter(和getter)的解释如下:

setAllowIPNPayment(Boolean value) 
       Sets the value of the allowIPNPayment property.

......他们都是这样的,例如Sets the value of the [X] property

1 个答案:

答案 0 :(得分:1)

PFB一个样本有效载荷。

请求

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Invoice xmlns="http://schema.intuit.com/finance/v3">
        <Line>
            <Amount>15</Amount>
            <DetailType>SalesItemLineDetail</DetailType>
            <SalesItemLineDetail>
                <ItemRef name="Hours">2</ItemRef>
            </SalesItemLineDetail>
        </Line>
        <CustomerRef name="Hours">2</CustomerRef>
    </Invoice>

<强>响应

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-04-30T07:35:49.705-07:00">
    <Invoice domain="QBO" sparse="false">
        <Id>16</Id>
        <SyncToken>0</SyncToken>
        <MetaData>
            <CreateTime>2014-04-30T07:35:49-07:00</CreateTime>
            <LastUpdatedTime>2014-04-30T07:35:49-07:00</LastUpdatedTime>
        </MetaData>
        <DocNumber>1003</DocNumber>
        <TxnDate>2014-04-30</TxnDate>
        <CurrencyRef name="Australian Dollar">AUD</CurrencyRef>
        <Line>
            <Id>1</Id>
            <LineNum>1</LineNum>
            <Amount>15.00</Amount>
            <DetailType>SalesItemLineDetail</DetailType>
            <SalesItemLineDetail>
                <ItemRef name="Hours">2</ItemRef>
            </SalesItemLineDetail>
        </Line>
        <Line>
            <Amount>15.00</Amount>
            <DetailType>SubTotalLineDetail</DetailType>
            <SubTotalLineDetail/>
        </Line>
        <CustomerRef name="abc">2</CustomerRef>
        <DueDate>2014-05-30</DueDate>
        <GlobalTaxCalculation>NotApplicable</GlobalTaxCalculation>
        <TotalAmt>15.00</TotalAmt>
        <PrintStatus>NeedToPrint</PrintStatus>
        <EmailStatus>NotSet</EmailStatus>
        <Balance>15.00</Balance>
        <Deposit>0</Deposit>
        <AllowIPNPayment>false</AllowIPNPayment>
        <AllowOnlinePayment>false</AllowOnlinePayment>
        <AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
        <AllowOnlineACHPayment>false</AllowOnlineACHPayment>
    </Invoice>
</IntuitResponse>

您可以使用java sdk使用上述setter。它将创建一个有效的发票。 请使用有效引用对象的ID(项目和客户)

文档参考 - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice

<强>更新

void createInvoice() {
    try {

        Invoice invoice = new Invoice();
        ReferenceType customerReferenceType = new ReferenceType();
        customerReferenceType.setName("abc");
        customerReferenceType.setValue("2");
        invoice.setCustomerRef(customerReferenceType);
        Line line = new Line();
        line.setAmount(new BigDecimal(15));
        line.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL);

        SalesItemLineDetail salesItemLineDetail = new SalesItemLineDetail();
        ReferenceType referenceType = customerReferenceType;
        referenceType.setName("Hours");
        referenceType.setValue("2");
        salesItemLineDetail.setItemRef(referenceType);
        line.setSalesItemLineDetail(salesItemLineDetail);

        List linesList = new ArrayList<Line>();
        linesList.add(line);
        invoice.setLine(linesList);

        this.service.add(invoice);
    } catch (FMSException e) {
        e.printStackTrace();
    } 

由于