/**
  * 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);
 }
Example #2
0
 /**
  * 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']);
 }
Example #3
0
 /**
  * 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);
 }