Beispiel #1
0
 /**
 	Contact Model delete()
 
 	Removes this Contact and All Addresses, Channels, Work Orders and Invoices!
 	@todo Should block if the Contact has a WorkOrder or Invoice
 */
 function delete()
 {
     $id = intval($this->id);
     // Check Workorder
     $res = SQL::fetch_one('SELECT count(id) FROM workorder WHERE contact_id = ?', array($id));
     if ($res > 0) {
         throw new Exception("Cannot delete Contact who owns Work Orders");
     }
     // Check Invoice
     $res = SQL::fetch_one('SELECT count(id) FROM invoice WHERE contact_id = ?', array($id));
     if ($res > 0) {
         throw new Exception("Cannot delete Contact who owns Invoices");
     }
     SQL::query('DELETE FROM contact_address WHERE contact_id = ?', array($id));
     SQL::query('DELETE FROM contact_channel WHERE contact_id = ?', array($id));
     //$db->query("delete from workorder where contact_id = $id");
     //$this->WorkOrder->deleteAll("WorkOrder.contact_id=$id",false,false);
     //$db->query("delete from invoice where contact_id = $id");
     //$this->Invoice->deleteAll("Invoice.contact_id=$id",false,false);
     $x = parent::delete($id, true);
     return $x;
 }