$primary_key_of_invoice_in_your_application = 125;
// Create the new invoice object
$Invoice = new QuickBooks_Object_Invoice();
// We're going to assign this invoice to the customer we created above, #20,
//	"Shannon Daniels". There are a few ways you can refer to that customer. You
//	can refer to them by their Name/FullName attribute ("Shannon's Company" in
//	the example shown above), by their ListID (a primary key within QuickBooks)
//	or, if you've created a mapping between the customer's primary key within
//	your application and the customer in QuickBooks, you can refer to them by
//	the primary key within your application, and the framework will map this
//	value to a ListID for you.
//
// 	For this example, we're going to refer to them by their mapped primar key,
//	because the callback function "_quickbooks_ca_customer_add_callback" that
//	we used above when adding Shannon creates this mapping for us.
$Invoice->setCustomerApplicationID($primary_key_of_customer_in_your_application);
// $Invoice->setCustomerName('The Company Name Here');
// $Invoice->setCustomerListID($ListID_from_QuickBooks);
// Invoice #125
$Invoice->setRefNumber($primary_key_of_invoice_in_your_application);
// Set some other fields...
$Invoice->setMemo('This invoice was created using the QuickBooks PHP API!');
// Now, we need to build each invoice line for the invoice. Each invoice line
//	will contain at least a reference to an item, and probably a quantity or
//	the item ordered, and either a total amount or a rate (price per item).
//
// As with customers above, the items need to be present in QuickBooks before
//	we can add an invoice that depends on them. You can again refer to the item
//	in three different ways:
//	- Name/FullName
//	- ListID
// CUSTOMERS
$fname = 'Shannon ' . mt_rand();
$lname = 'Daniels';
$Customer = new QuickBooks_Object_Customer();
$Customer->setFirstName($fname);
$Customer->setLastName($lname);
$Customer->setShipAddress('56 Cowles Road', '', '', '', '', 'Willington', 'CT');
$Customer->setMiddleName('R');
$Customer->setSalutation('Mr.');
$Customer->setPhone('1.860.634.1602');
$API->addCustomer($Customer, '_quickbooks_customer_add_callback', 15);
// INVOICES
$Invoice = new QuickBooks_Object_Invoice();
//$Invoice->setOther('test of other');		// for some reason this field doesn't work...
$Invoice->setMemo('test of a memo');
$Invoice->setCustomerApplicationID(15);
$Invoice->setRefNumber(125);
$InvoiceLine1 = new QuickBooks_Object_Invoice_InvoiceLine();
$InvoiceLine1->setItemApplicationID(12);
$InvoiceLine1->setAmount(300.0);
$InvoiceLine1->setQuantity(3);
$InvoiceLine2 = new QuickBooks_Object_Invoice_InvoiceLine();
$InvoiceLine2->setItemApplicationID(11);
$InvoiceLine2->setAmount(225.0);
$InvoiceLine2->setQuantity(5);
$Invoice->addInvoiceLine($InvoiceLine1);
$Invoice->addInvoiceLine($InvoiceLine2);
$API->addInvoice($Invoice, '_quickbooks_invoice_add_callback', 20);
// VENDORS
$Vendor = new QuickBooks_Object_Vendor();
$Vendor->setName('Test Vendor ' . mt_rand());