function invoice_insert in Invoice 6
Same name and namespace in other branches
- 7 invoice.module \invoice_insert()
Implementation of hook_insert()
File
- ./
invoice.module, line 640 - Invoice module
Code
function invoice_insert($node) {
// Get template ID
$tid = db_result(db_query("SELECT tid FROM {invoice_templates} WHERE name='%s'", $node->template));
// Create invoice
db_query("INSERT INTO {invoice_invoices} (iid,nid,leading_zeros,prefix,description,tid,pay_limit,uid) VALUES (%d,%d,%d,'%s','%s',%d,'%s',%d)", $node->invoice_number, $node->nid, empty($node->invoice_invoice_number_zerofill) ? variable_get('invoice_invoice_number_zerofill', 0) : $node->invoice_invoice_number_zerofill, empty($node->invoice_invoice_number_prefix) ? variable_get('invoice_invoice_number_prefix', NULL) : $node->invoice_invoice_number_prefix, $node->invoice_description, $tid, $node->pay_limit, $GLOBALS['user']->uid);
// Create customer
db_query("INSERT {invoice_customers} (customer_number,company_name,firstname,lastname,street,building_number,zipcode,city,country,coc_number,vat_number,description,invoice_id)\n VALUES (%d, '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',%d)", $node->customer_number, $node->company_name, $node->firstname, $node->lastname, $node->street, $node->building_number, $node->zipcode, $node->city, $node->country, $node->coc_number, $node->vat_number, $node->customer_description, $node->invoice_number);
// Add all temporary invoice items to this invoice
db_query("UPDATE {invoice_items} SET invoice_id=%d WHERE uid=%d AND invoice_id=0", $node->invoice_number, $GLOBALS['user']->uid);
db_query("UPDATE {node} SET promote=0 WHERE type='invoice' AND nid=%d", $node->nid);
unset($_SESSION['invoice_template']);
}