rangka / quickbooks

PHP Library for connecting to QuickBooks.
MIT License
8 stars 11 forks source link

create Bill #12

Closed code2prog closed 7 years ago

code2prog commented 7 years ago

How to create new Bill with multiple line items? Thanks for answer.

khairulashraff commented 7 years ago

According to the docs, Line is an array. So I would assume you just add more elements to that array. https://developer.intuit.com/docs/api/accounting/bill

Sorry I can't test it out. Having weird issue with my local server.

code2prog commented 7 years ago

but Line should be set as $builder->setLine([ [ //line 1], [ //line 2 ] ]);

?

khairulashraff commented 7 years ago

Yes that is what I meant. Is there a problem with that?

code2prog commented 7 years ago

i get error like this: {"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Unrecognized field \"Vendor\" (class com.intuit.schema.finance.v3.Bill), not marked as ignorable (37 known properties: \"DocNumber\", \"ExchangeR specified is unsupported or invalid","code":"2010"}],"type":"ValidationFault"},"time":"2017-04-26T02:44:30.912-07:00"}

this is my code: `function createBill( $vendor_id, $positions = [] ) { try { $bill = new Bill(); $builder = $bill->getBuilder(); $builder->setLine( [ [ "Amount" => 3.00, "Description" => "Test 1" ], [ "Amount" => 8.00, "Description" => "Test 2" ] ] ); $builder->setVendor( $vendor_id );

return $builder->create(); } catch ( ClientException $e ) { return (string) $e->getResponse()->getBody(); } }`

khairulashraff commented 7 years ago

The error as given by Quickbooks is on the Vendor property, not Line.

I have not added any shorthand methods to Bill, so you have to use the full name and structure of each property.

In the case of vendor, try

$builder->setVendorRef(["value" => $vendor_id]);
code2prog commented 7 years ago

Now works :) Thanks for your help.