// 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 // - a mapped primary key from your application // // For this example, we're going to refer to the items by name, so the items // must already be present in QuickBooks for this invoice to be added. // 3 items of type "Item Type 1" at $10.00 per item $InvoiceLine1 = new QuickBooks_Object_Invoice_InvoiceLine(); $InvoiceLine1->setItemName('Item Type 1'); $InvoiceLine1->setRate(10.0); $InvoiceLine1->setQuantity(3); // 5 items of type "Item Type 2", for a total amount of $225.00 ($45.00 each) $InvoiceLine2 = new QuickBooks_Object_Invoice_InvoiceLine(); $InvoiceLine2->setItemName('Item Type 2'); $InvoiceLine2->setAmount(225.0); $InvoiceLine2->setQuantity(5); // Make sure you add those invoice lines on to the invoice $Invoice->addInvoiceLine($InvoiceLine1); $Invoice->addInvoiceLine($InvoiceLine2); // Queue up the request to be sent to QuickBooks $priority_of_add_invoice_request = 10; // Make sure this is lower than the customer add it depends on if ($API->addInvoice($Invoice, '_quickbooks_ca_invoice_add_callback', $primary_key_of_invoice_in_your_application, $priority_of_add_invoice_request)) { print 'Queued up a request to add invoice #' . $primary_key_of_invoice_in_your_application . ' to QuickBooks!' . "\n"; } // Adding an estimate for a customer $primary_key_of_estimate_in_your_application = 'ABC-123'; // Adding an estimate is very similar to adding an invoice, as most of the
/** * Create a QuickBooks shipping (actually an item) object, from an array * * This method can return items of the following type: * - QuickBooks_Object_SalesReceipt_SalesReceiptLine * - QuickBooks_Object_Invoice_InvoiceLine * * @param array $arr * @return QuickBooks_Object */ protected function _shippingFromArray($arr) { if (count($arr) == 1 and strlen(current($arr)) == 0) { return null; } switch ($this->_config['push_orders_as']) { case QUICKBOOKS_OBJECT_SALESRECEIPT: $SalesReceiptLine = new QuickBooks_Object_SalesReceipt_SalesReceiptLine(); if (!empty($arr['Rate'])) { $SalesReceiptLine->setRate($arr['Rate']); $SalesReceiptLine->setQuantity(1); } else { if (!empty($arr['Amount'])) { $SalesReceiptLine->setAmount((double) $arr['Amount']); } else { $SalesReceiptLine->setAmount(0); } } $map = array('Desc' => array('setDescription', 'Desc'), 'Descrip' => array('setDescription', 'Desc'), 'Description' => array('setDescription', 'Desc'), 'UnitOfMeasure' => array('setUnitOfMeasure', 'UnitOfMeasure'), 'PriceLevelName' => array('setPriceLevelName', 'PriceLevelRef FullName'), 'PriceLevelListID' => array('setPriceLevelListID', 'PriceLevelRef ListID'), 'PriceLevelID' => array('setPriceLevelApplicationID', 'PriceLevelRef ' . QUICKBOOKS_API_APPLICATIONID, 'setPriceLevelID'), 'ClassName' => array('setClassName', 'ClassRef FullName'), 'ClassListID' => array('setClassListID', 'ClassRef ListID'), 'ClassID' => array('setClassApplicationID', 'ClassRef ' . QUICKBOOKS_API_APPLICATIONID, 'setClassListID'), 'ServiceDate' => array('setServiceDate', 'ServiceDate'), 'Other1' => array('setOther1', 'Other1'), 'Other2' => array('setOther2', 'Other2'), 'SalesTaxCodeName' => array('setSalesTaxCodeName', 'SalesTaxCodeRef FullName'), 'SalesTaxCodeListID' => array('setSalesTaxCodeListID', 'SalesTaxCodeRef ListID'), 'SalesTaxCodeID' => array('setSalesTaxCodeApplicationID', 'SalesTaxCodeRef ' . QUICKBOOKS_API_APPLICATIONID, 'setSalesTaxCodeListID')); $SalesReceiptLine = $this->_applyBaseMap($arr, $map, $SalesReceiptLine, 'SalesReceipt SalesReceiptLine'); $SalesReceiptLine->setItemApplicationID(QUICKBOOKS_INTEGRATOR_SHIPPING_ID); return $SalesReceiptLine; break; case QUICKBOOKS_OBJECT_SALESORDER: break; case QUICKBOOKS_OBJECT_INVOICE: default: $InvoiceLine = new QuickBooks_Object_Invoice_InvoiceLine(); if (!empty($arr['Rate'])) { $InvoiceLine->setRate($arr['Rate']); $InvoiceLine->setQuantity(1); } else { if (!empty($arr['Amount'])) { $InvoiceLine->setAmount((double) $arr['Amount']); } else { $InvoiceLine->setAmount(0); } } $map = array('Desc' => array('setDescription', 'Invoice InvoiceLine Desc'), 'ClassID' => array('setClassApplicationID', 'ClassRef ' . QUICKBOOKS_API_APPLICATIONID, 'setClassListID')); $InvoiceLine = $this->_applyBaseMap($arr, $map, $InvoiceLine, 'Invoice InvoiceLine'); $InvoiceLine->setItemApplicationID(QUICKBOOKS_INTEGRATOR_SHIPPING_ID); return $InvoiceLine; } }
$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()); $Vendor->setPhone('1.860.634.1602'); $Vendor->setFirstName('Test'); $Vendor->setFax('1.860.429.5183'); $API->addVendor($Vendor, '_quickbooks_vendor_add_callback', 19); // SERVICE ITEMS $ServiceItem = new QuickBooks_Object_ServiceItem();
/** * Create a QuickBooks shipping (actually an item) object, from an array * * This method can return items of the following type: * - QuickBooks_Object_ServiceItem * - QuickBooks_Object_OtherChargeItem * * @param array $arr * @return QuickBooks_Object */ protected function _shippingFromArray($arr) { switch ($this->_config['push_orders_as']) { case QUICKBOOKS_OBJECT_SALESRECEIPT: break; case QUICKBOOKS_OBJECT_SALESORDER: break; case QUICKBOOKS_OBJECT_INVOICE: default: $InvoiceLine = new QuickBooks_Object_Invoice_InvoiceLine(); if (!empty($arr['Rate'])) { $InvoiceLine->setRate($arr['Rate']); $InvoiceLine->setQuantity(1); } else { if (!empty($arr['Amount'])) { $InvoiceLine->setAmount((double) $arr['Amount']); } else { $InvoiceLine->setAmount(0); } } $map = array('Desc' => array('setDescription', 'Invoice InvoiceLine Desc'), 'ClassID' => array('setClassApplicationID', 'ClassRef ' . QUICKBOOKS_API_APPLICATIONID, 'setClassListID')); $InvoiceLine = $this->_applyBaseMap($arr, $map, $InvoiceLine, 'Invoice InvoiceLine'); $InvoiceLine->setItemApplicationID(QUICKBOOKS_INTEGRATOR_SHIPPING_ID); return $InvoiceLine; } }