array('far_key'=>'id'), 'invoice'=>array('through'=>'payment_item'), ); protected $_belongs_to = array( 'account'=>array(), 'checkout'=>array('foreign_key'=>'checkout_plugin_id'), ); protected $_sorting = array( 'date_payment'=>'DESC' ); protected $_display_filters = array( 'date_payment'=>array( array('Config::date',array(':value')), ), 'total_amt'=>array( array('Currency::display',array(':value')), ), ); /** * Find all items that are exportable. * * @param int $start List payments that were modified this many days ago */ public function export($start) { return ORM::factory('payment') ->where('date_payment','>=',time()-$start*86400) ->find_all(); } /** * Calculate the remaining balance available for this payment */ public function balance($format=FALSE) { $t = 0; foreach ($this->payment_item->find_all() as $pio) $t += $pio->alloc_amt; return $format ? Currency::display($this->total_amt-$t) : $this->total_amt-$t; } /** * Return a list of invoices that this payment is applied to */ public function invoices() { $invoices = array(); foreach ($this->payment_item->find_all() as $pio) array_push($invoices,$pio->invoice); return $invoices; } public function invoicelist() { return join(',',$this->invoices()); } }