forked from quaderno/quaderno-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquaderno_document.php
executable file
·78 lines (67 loc) · 2.09 KB
/
quaderno_document.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Quaderno Document
*
* @package Quaderno PHP
* @author Quaderno <[email protected]>
* @copyright Copyright (c) 2015, Quaderno
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
/* Interface that implements every document: invoices, expenses, credits and estimates */
abstract class QuadernoDocument extends QuadernoModel
{
protected $payments_array = array();
public function __construct($newdata)
{
parent::__construct($newdata);
if (isset($this->data['payments']))
{
foreach ($this->data['payments'] as $p)
array_push($this->payments_array, new QuadernoPayment($p));
}
}
public function addContact($contact)
{
$this->data['contact_id'] = $contact->id;
$this->data['contact_name'] = $contact->full_name;
return isset($this->data['contact_id']) && isset($this->data['contact_name']);
}
public function addItem($item)
{
$length = isset($this->data['items_attributes']) ? count($this->data['items_attributes']) : 0;
$this->data['items_attributes'][$length] = $item->getArray();
return count($this->data['items_attributes']) == $length + 1;
}
/* Interface - only subclasses which implement original ones (i.e. without exec-) can call these methods */
protected function execAddPayment($payment)
{
$length = count($this->payments_array);
return array_push($this->payments_array, $payment) == $length + 1;
}
protected function execGetPayments()
{
return $this->payments_array;
}
protected function execRemovePayment($payment)
{
$i = array_search($payment, $this->payments_array, true);
if ($i >= 0) $this->payments_array[$i]->markToDelete = true;
return ($i >= 0);
}
/**
* Deliver call for QuadernoDocument objects
* Deliver object to the contact email
* Returns true or false whether the request is accepted or not
*/
protected function execDeliver()
{
$return = false;
$response = QuadernoBase::deliver(static::$model, $this->id);
if (QuadernoBase::responseIsValid($response))
$return = true;
elseif (isset($response['data']['errors']))
$this->errors = $response['data']['errors'];
return $return;
}
}
?>