/** VOID INVOICE
  */
 function voidInvoice($VAR)
 {
     # Update the invoice approval status:
     $db =& DB();
     $q = "UPDATE " . AGILE_DB_PREFIX . "invoice SET\n\t        \t\tdate_last \t\t= " . $db->qstr(time()) . ",\n\t        \t\tprocess_status \t= " . $db->qstr('0') . " WHERE\n\t        \t\tid\t\t \t\t= " . $db->qstr($VAR['id']) . " AND\n\t        \t\tsite_id \t\t= " . $db->qstr(DEFAULT_SITE);
     $update = $db->Execute($q);
     if ($update === false) {
         global $C_debug;
         $C_debug->error('invoice.inc.php', 'voidInvoice', $db->ErrorMsg());
         return false;
     }
     # Determine if services have already been created for this invoice and deactivate:
     $q = "SELECT id FROM " . AGILE_DB_PREFIX . "service WHERE\n\t        \t\tinvoice_id = " . $db->qstr($VAR['id']) . " AND\n\t        \t\tsite_id = " . $db->qstr(DEFAULT_SITE);
     $service = $db->Execute($q);
     if ($service === false) {
         global $C_debug;
         $C_debug->error('invoice.inc.php', 'voidInvoice', $db->ErrorMsg());
         return false;
     }
     if ($service->RecordCount() > 0) {
         # Include the service class
         include_once PATH_MODULES . 'service/service.inc.php';
         $srvc = new service();
         # Update services to inactive status:
         while (!$service->EOF) {
             $srvc->voidService($service->fields['id']);
             $service->MoveNext();
         }
     }
     # Loop through invoice items & delete assoc services
     $q = "SELECT service_id FROM " . AGILE_DB_PREFIX . "invoice_item WHERE\n                    invoice_id = " . $db->qstr($VAR['id']) . " AND\n                    site_id = " . $db->qstr(DEFAULT_SITE);
     $service = $db->Execute($q);
     if ($service === false) {
         global $C_debug;
         $C_debug->error('invoice.inc.php', 'voidInvoice', $db->ErrorMsg());
         return false;
     }
     if ($service->RecordCount() > 0) {
         # Include the service class
         include_once PATH_MODULES . 'service/service.inc.php';
         $srvc = new service();
         # Update services to inactive status:
         while (!$service->EOF) {
             $srvc->voidService($service->fields['service_id']);
             $service->MoveNext();
         }
     }
     # if voided, create a memo
     $id = $db->GenID(AGILE_DB_PREFIX . 'invoice_memo_id');
     $q = "INSERT INTO " . AGILE_DB_PREFIX . "invoice_memo\n\t\t    \t\tSET\n\t\t    \t\tid \t\t\t= " . $db->qstr($id) . ",\n\t\t    \t\tsite_id \t= " . $db->qstr(DEFAULT_SITE) . ",\n\t\t    \t\tdate_orig \t= " . $db->qstr(time()) . ",\n\t\t    \t\tinvoice_id\t= " . $db->qstr($VAR['id']) . ",\n\t\t    \t\taccount_id\t= " . $db->qstr(SESS_ACCOUNT) . ",\n\t\t    \t\ttype\t\t= " . $db->qstr('void') . ",\n\t\t    \t\tmemo\t\t= " . $db->qstr('NA');
     $insert = $db->Execute($q);
     if ($insert === false) {
         global $C_debug;
         $C_debug->error('invoice.inc.php', 'voidInvoice', $db->ErrorMsg());
         return false;
     }
     return true;
 }