Daniel Camargo 94c28adddf implement additional payment math in Settlement.php #2250
- added option to include refunded orders at the payment
- added pay type filter
2014-06-13 14:54:49 -03:00

44 lines
1.4 KiB
PHP

<?php
class Cockpit_Restaurant extends Crunchbutton_Restaurant {
public function __construct($id = null) {
$this->_changeSetName = 'Crunchbutton_Restaurant';
parent::__construct($id);
}
// Settlement stuff
// get the last payment
public function getLastPayment(){
if (!isset($this->_lastPayment)) {
$this->_lastPayment = Payment::q('select * from payment where id_restaurant="'.$this->id_restaurant.'" order by date desc limit 1')->get(0);
}
return $this->_lastPayment;
}
// get the last sent payment
public function sendPayment($filters = []) {
if (!isset($this->_lastPayment)) {
$this->_lastPayment = Payment::q('select * from payment where id_restaurant="'.$this->id_restaurant.'" order by date desc limit 1')->get(0);
}
return $this->_lastPayment;
}
// get orders that are payable; not test, within our date range, it just return the order, the calc are made at settlement class
public function payableOrders($filters = []) {
if (!isset($this->_payableOrders)) {
$q = 'SELECT * FROM `order`
WHERE id_restaurant="'.$this->id_restaurant.'"
AND DATE(`date`) >= "' . (new DateTime($filters['start']))->format('Y-m-d') . '"
AND DATE(`date`) <= "' . (new DateTime($filters['end']))->format('Y-m-d') . '"
AND NAME NOT LIKE "%test%"
ORDER BY `pay_type` ASC, `date` ASC ';
$orders = Order::q($q);
$this->_payableOrders = $orders;
}
return $this->_payableOrders;
}
}