public function incrementIndex($node, $sub_node = NULL) { $data = array('id' => $this->NEXT($node, $sub_node)); if ($data['id'] == 1) { $data['node'] = $node; if (!is_null($sub_node) && !empty($sub_node)) { $data['sub_node'] = $sub_node; } if ($this->insert($data)) { return $data['id']; } throw new ErrorException('Unable to insert value in index table', 0, 1); } else { $auth_session = Zend_Registry::get('auth_session'); $where = array(); $where[] = $this->getAdapter()->quoteInto('domain_id = ?', $auth_session->domain_id); $where[] = $this->getAdapter()->quoteInto('node = ?', $node); if (!is_null($sub_node) && !empty($sub_node)) { $where[] = $this->getAdapter()->quoteInto('sub_node = ?', $sub_node); } if (parent::update($data, $where)) { return $data['id']; } throw new ErrorException('Unable to update index table', 0, 1); } }
/** * Update */ public function update($data, $id) { $auth_session = Zend_Registry::get('auth_session'); $where = array(); $where[] = $this->getAdapter()->quoteInto('id = ?', $id); $where[] = $this->getAdapter()->quoteInto('domain_id = ?', $auth_session->domain_id); return parent::update($data, $where); }
/** * Get the total paid amount by this customer. * Replaces: calc_customer_paid() * Enter description here ... */ public function getPaidAmount() { $tbl_prefix = SimpleInvoices_Db_Table_Abstract::getTablePrefix(); $select = new Zend_Db_Select($this->_db); $select->from($tbl_prefix . "payment", array('amount' => new Zend_Db_Expr("COALESCE(SUM(" . $tbl_prefix . "payment.ac_amount), 0)"))); $select->joinInner($tbl_prefix . "invoices", $tbl_prefix . "payment.ac_inv_id=" . $tbl_prefix . "invoices.id", NULL); $select->where($tbl_prefix . "invoices.customer_id=?", $this->_id); return $this->_db->fetchOne($select); }
/** * Initialize payment data. * replaces method getPayment($id) */ protected function _initData() { $tbl_prefix = SimpleInvoices_Db_Table_Abstract::getTablePrefix(); $select = new Zend_Db_Select($this->_db); $select->from($tbl_prefix . 'payment'); $select->joinInner($tbl_prefix . 'invoices', $tbl_prefix . "payment.ac_inv_id = " . $tbl_prefix . "invoices.id", NULL); $select->joinInner($tbl_prefix . 'customers', $tbl_prefix . "invoices.customer_id = " . $tbl_prefix . "customers.id", array('customer_id' => $tbl_prefix . "customers.id", 'customer' => $tbl_prefix . "customers.name")); $select->joinInner($tbl_prefix . 'biller', $tbl_prefix . "invoices.biller_id = " . $tbl_prefix . "biller.id", array('biller_id' => $tbl_prefix . "biller.id", 'biller' => $tbl_prefix . "biller.name")); $select->where($tbl_prefix . 'payment.id=?', $this->_id); $this->_data = $this->_db->fetchRow($select); $this->_data['date'] = siLocal::date($payment['ac_date']); }
public static function performBackup() { $adapter = SimpleInvoices_Db_Table_Abstract::getDefaultAdapter(); $table_list = $adapter->listTables(); foreach ($table_list as $table) { $adapter->query("OPTIMIZE TABLE " . $table); } // ToDo: Try with exec for faster response // If exec not working let's do it step by step $config = Zend_Registry::get('config'); $sql_backup = "--\n-- Database: `" . $config->resources->db->params->dbname . "`\n--\n-- --------------------------------------------------------\n"; foreach ($table_list as $table) { $sql_backup .= "\n--\n-- Table structure for table `" . $table . "`\n--\n\n"; $create = $adapter->query("SHOW CREATE TABLE `" . $table . "`")->fetch(); $sql_backup .= preg_replace('/^CREATE TABLE /', 'CREATE TABLE IF NOT EXISTS ', $create['Create Table']) . ";\n"; $columns = $adapter->query("SHOW COLUMNS FROM `" . $table . "`")->fetchAll(); $column_text = ""; foreach ($columns as $column) { if (!empty($column_text)) { $column_text .= ", `" . $column['Field'] . "`"; } else { $column_text .= "`" . $column['Field'] . "`"; } } $rows = $adapter->query("SELECT " . $column_text . " FROM `" . $table . "`")->fetchAll(); if (count($rows) > 0) { $sql_backup .= "\n--\n-- Dumping data for table `" . $table . "`\n--\n\n"; $sql_backup .= "INSERT INTO `" . $table . "` (" . $column_text . ") VALUES "; $isFirst = true; foreach ($rows as $row) { $tmp_query = ""; foreach ($row as $value) { if (!empty($tmp_query)) { $tmp_query .= ", '" . addslashes($value) . "'"; } else { $tmp_query .= "'" . addslashes($value) . "'"; } } if (!$isFirst) { $sql_backup .= ",\n(" . $tmp_query . ")"; } else { $sql_backup .= "\n(" . $tmp_query . ")"; $isFirst = false; } } $sql_backup .= ";\n"; } } return $sql_backup; }
/** * Get payments for this invoice. */ public function getPayments() { $tbl_prefix = SimpleInvoices_Db_Table_Abstract::getTablePrefix(); $select = new Zend_Db_Select($this->_db); $select->from($tbl_prefix . 'payment'); $select->joinInner($tbl_prefix . 'invoices', $tbl_prefix . 'payment.ac_inv_id=' . $tbl_prefix . 'invoices.id', NULL); $select->joinInner($tbl_prefix . 'customers', $tbl_prefix . 'customers.id=' . $tbl_prefix . 'invoices.customer_id', array('cname' => $tbl_prefix . 'customers.name')); $select->joinInner($tbl_prefix . 'biller', $tbl_prefix . 'biller.id=' . $tbl_prefix . 'invoices.biller_id', array('bname' => $tbl_prefix . 'biller.name')); $select->where($tbl_prefix . 'payment.ac_inv_id=?', $this->_id); $select->order($tbl_prefix . 'payment.id DESC'); return $this->_db->fetchAll($select); }
/** * Replaces updateDefault * * @param mixed $data * @param mixed $id * @return int */ public function update($name, $value, $extension_name = "core") { $auth_session = Zend_Registry::get('auth_session'); $where = array(); $where[] = $this->getAdapter()->quoteInto('name = ?', $name); $SI_EXTENSIONS = new SimpleInvoices_Db_Table_Extensions(); $extension_id = $SI_EXTENSIONS->findByName($extension_name); if ($extension_id >= 0) { $where[] = $this->getAdapter()->quoteInto('extension_id = ?', $extension_id); } else { throw new Exception("Invalid extension name: " . str_replace(array('{', '}', '+'), array('{', '}', '+'), htmlentities($extension_name, ENT_QUOTES, 'UTF-8'))); exit(1); } return parent::update(array('value' => $value), $where); }
/** * Update a customer * * @param mixed $data * @param mixed $id * @return int */ public function update(array $data, $id) { $auth_session = Zend_Registry::get('auth_session'); $where = array(); $where[] = $this->getAdapter()->quoteInto('id = ?', $id); $where[] = $this->getAdapter()->quoteInto('domain_id = ?', $auth_session->domain_id); // IF Credit Card Number is present it must be cyphered if (array_key_exists('credit_card_number', $data)) { if (!empty($data['credit_card_number'])) { $config = Zend_Registry::get('config'); $enc = new encryption(); $key = $config->encryption->default->key; $data['credit_card_number'] = $enc->encrypt($key, $data['credit_card_number']); } } return parent::update($data, $where); }
public function insert($data) { // Set the domain ID $auth_session = Zend_Registry::get('auth_session'); $data['domain_id'] = $auth_session->domain_id; return parent::insert($data); }