2013-09-10 23:07:39 +02:00
|
|
|
<?php
|
|
|
|
require_once('data/config.php');
|
|
|
|
require_once('Storage.class.php');
|
|
|
|
|
|
|
|
class Payback extends Storage {
|
2013-09-11 00:51:45 +02:00
|
|
|
protected $id = 0, $date, $invoice_id, $amount, $from_user, $to_user;
|
2013-09-10 23:07:39 +02:00
|
|
|
protected $TABLE_NAME = "Paybacks";
|
|
|
|
protected $fields = array(
|
|
|
|
'id'=>'key',
|
|
|
|
'date'=>'date',
|
|
|
|
'invoice_id'=>'int',
|
|
|
|
'amount'=>'float',
|
|
|
|
'from_user'=>'int',
|
|
|
|
'to_user'=>'int'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getters
|
|
|
|
// =======
|
|
|
|
|
|
|
|
public function getId() {
|
|
|
|
return (int) $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDate($format = 'd-m-Y H:i') {
|
|
|
|
if(!empty($this->date))
|
|
|
|
return $this->date->format($format);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInvoice() {
|
|
|
|
return (int) $this->invoice_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAmount() {
|
|
|
|
return (float) $this->amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFrom() {
|
2013-09-11 00:51:45 +02:00
|
|
|
return (int) $this->from_user;
|
2013-09-10 23:07:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTo() {
|
2013-09-11 00:51:45 +02:00
|
|
|
return (int) $this->to_user;
|
2013-09-10 23:07:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setters
|
|
|
|
// =======
|
|
|
|
|
|
|
|
public function setId($id) {
|
|
|
|
$this->id = (int) $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDate($minute, $hour, $day, $month, $year) {
|
|
|
|
if((int) $minute < 10) $minute = '0'.$minute;
|
|
|
|
|
|
|
|
$this->date = DateTime::createFromFormat('Y-n-j G:i', $year.'-'.(int) $month.'-'.(int) $day.' '.(int) $hour.':'.$minute);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setInvoice($invoice_id) {
|
|
|
|
$this->invoice_id = (int) $invoice_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAmount($amount) {
|
|
|
|
$this->amount = (float) $amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFrom($from) {
|
2013-09-11 00:51:45 +02:00
|
|
|
$this->from_user = (int) $from;
|
2013-09-10 23:07:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setTo($to) {
|
2013-09-11 00:51:45 +02:00
|
|
|
$this->to_user = (int) $to;
|
2013-09-10 23:07:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restores object from array
|
|
|
|
// ==========================
|
|
|
|
|
|
|
|
public function sessionRestore($data, $serialized = false) {
|
|
|
|
if($serialized)
|
|
|
|
$data = unserialize($data);
|
|
|
|
|
|
|
|
$this->setId($data['id']);
|
|
|
|
$this->setInvoice($data['invoice_id']);
|
|
|
|
$this->setAmount($data['amount']);
|
2013-09-11 00:51:45 +02:00
|
|
|
$this->setFrom($data['from_user']);
|
|
|
|
$this->setTo($data['to_user']);
|
2013-09-10 23:07:39 +02:00
|
|
|
|
|
|
|
$this->date = DateTime::createFromFormat('Y-m-d H:i:s', $data['date']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maps htmlspecialchars on the class before display
|
|
|
|
// =================================================
|
|
|
|
|
|
|
|
public function secureDisplay() {
|
|
|
|
$this->id = (int) $this->id;
|
|
|
|
$this->invoice_id = (int) $this->invoice_id;
|
|
|
|
$this->amount = (float) $this->amount;
|
2013-09-11 00:51:45 +02:00
|
|
|
$this->from = (int) $this->from_user;
|
|
|
|
$this->to = (int) $this->to_user;
|
|
|
|
|
|
|
|
return $this;
|
2013-09-10 23:07:39 +02:00
|
|
|
}
|
|
|
|
}
|