|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Doctrine Gateway to DebtorDoctrine |
|
4
|
|
|
* |
|
5
|
|
|
* Bruges til at holde styr p� debtor. |
|
6
|
|
|
* |
|
7
|
|
|
* @package Intraface_Debtor |
|
8
|
|
|
* @author Sune Jensen |
|
9
|
|
|
* @see DebtorDoctrine |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
class Intraface_modules_debtor_DebtorDoctrineGateway |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var object |
|
17
|
|
|
*/ |
|
18
|
|
|
private $user; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
* @var object doctrine record table |
|
23
|
|
|
*/ |
|
24
|
|
|
private $table; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var integer type |
|
28
|
|
|
*/ |
|
29
|
|
|
private $type_key; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor |
|
33
|
|
|
* |
|
34
|
|
|
* @param object $user Userobject |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
function __construct($doctrine, $user) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->user = $user; |
|
41
|
|
|
$this->table = $doctrine->getTable('Intraface_modules_debtor_DebtorDoctrine'); |
|
42
|
|
|
$this->type_key = 3; // invoice |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Finds a product with an id |
|
47
|
|
|
* |
|
48
|
|
|
* @param integer $id product id |
|
49
|
|
|
* @return object |
|
50
|
|
|
*/ |
|
51
|
|
|
/* |
|
|
|
|
|
|
52
|
|
|
function findById($id) |
|
53
|
|
|
{ |
|
54
|
|
|
|
|
55
|
|
|
die('Not created'); |
|
56
|
|
|
$collection = $this->table |
|
57
|
|
|
->createQuery() |
|
58
|
|
|
->select('*, details.*') |
|
59
|
|
|
->innerJoin('Intraface_modules_product_ProductDoctrine.details AS details') |
|
60
|
|
|
->addWhere('active = 1') |
|
61
|
|
|
->addWhere('id = ?', $id) |
|
62
|
|
|
->addOrderBy('details.id') |
|
63
|
|
|
->execute(); |
|
64
|
|
|
|
|
65
|
|
|
if ($collection == NULL || $collection->count() != 1) { |
|
66
|
|
|
throw new Intraface_Gateway_Exception('Error finding product from id '.$id); |
|
67
|
|
|
} else { |
|
68
|
|
|
return $collection->getLast(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
}*/ |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Finds all products |
|
75
|
|
|
* |
|
76
|
|
|
* Hvis den er fra webshop b�r den faktisk opsamle oplysninger om s�gningen |
|
77
|
|
|
* s� man kan se, hvad folk er interesseret i. |
|
78
|
|
|
* S�gemaskinen skal v�re tolerant for stavefejl |
|
79
|
|
|
* |
|
80
|
|
|
* @param object $search |
|
|
|
|
|
|
81
|
|
|
* |
|
82
|
|
|
* @return object collection containing products |
|
83
|
|
|
*/ |
|
84
|
|
|
public function findByDbQuerySearch($dbquery = null) |
|
85
|
|
|
{ |
|
86
|
|
|
$query = $this->table |
|
87
|
|
|
->createQuery() |
|
88
|
|
|
->select('due_date, status, number, description, this_date, date_sent, contact_id |
|
89
|
|
|
item.id, item.product_detail_id, item.product_variation_id, item.product_variation_detail_id, item.quantity, |
|
90
|
|
|
item_product.id, item_product.has_variation, |
|
91
|
|
|
item_product_details.id, item_product_details.number, item_product_details_translation.name, item_product_details_translation.description, item_product_details.price, item_product_details.vat, |
|
92
|
|
|
item_product_variation.id, item_product_variation.number, |
|
93
|
|
|
item_product_variation_detail.id, item_product_variation_detail.price_difference, item_product_variation_detail.weight_difference') |
|
94
|
|
|
->leftJoin('Intraface_modules_debtor_DebtorDoctrine.item item') |
|
95
|
|
|
->innerJoin('item.product item_product') |
|
96
|
|
|
->innerJoin('item_product.details item_product_details WITH item.product_detail_id = item_product_details.id') |
|
97
|
|
|
->innerJoin('item_product_details.Translation item_product_details_translation WITH item_product_details.id = item_product_details_translation.id') |
|
98
|
|
|
->leftJoin('item_product.variation item_product_variation WITH item.product_variation_id = item_product_variation.id AND (item_product_variation.deleted_at IS NULL OR item_product_variation.deleted_at IS NOT NULL)') // also deleted variations is used |
|
99
|
|
|
->leftJoin('item_product_variation.detail item_product_variation_detail') |
|
100
|
|
|
->addWhere('active = 1') |
|
101
|
|
|
->addWhere('item.active = 1') |
|
102
|
|
|
->addWhere('type = ?', $this->type_key) |
|
103
|
|
|
->addWhere('intranet_id = ?', $this->user->getActiveIntranetId()); |
|
104
|
|
|
|
|
105
|
|
|
if ($dbquery->checkFilter("contact_id")) { |
|
106
|
|
|
$query = $query->addWhere("contact_id = ?", intval($dbquery->getFilter("contact_id"))); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if ($dbquery->checkFilter("text")) { |
|
110
|
|
|
$query = $query->addWhere('description LIKE ? OR girocode = ? OR number = ?', array('%'.$dbquery->getFilter("text").'%', $dbquery->getFilter("text"), $dbquery->getFilter("text"))); |
|
111
|
|
|
// OR contact_address.name LIKE \"%".$dbquery->getFilter("text")."%\") |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/* To be implemented |
|
|
|
|
|
|
115
|
|
|
if ($dbquery->checkFilter("product_id")) { |
|
116
|
|
|
$dbquery->setCondition("debtor_item.product_id = ".$dbquery->getFilter('product_id')); |
|
117
|
|
|
if ($dbquery->checkFilter("product_variation_id")) { |
|
118
|
|
|
$dbquery->setCondition("debtor_item.product_variation_id = ".$dbquery->getFilter('product_variation_id')); |
|
119
|
|
|
} else { |
|
120
|
|
|
$dbquery->setCondition("debtor_item.product_variation_id = 0"); |
|
121
|
|
|
} |
|
122
|
|
|
} */ |
|
123
|
|
|
|
|
124
|
|
|
if ($dbquery->checkFilter("date_field")) { |
|
125
|
|
|
if (in_array($dbquery->getFilter("date_field"), array('this_date', 'date_created', 'date_sent', 'date_executed', 'data_cancelled'))) { |
|
126
|
|
|
$date_field = $dbquery->getFilter("date_field"); |
|
127
|
|
|
} else { |
|
128
|
|
|
$this->error->set("Ugyldigt datointerval felt"); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
} else { |
|
131
|
|
|
$date_field = 'this_date'; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
View Code Duplication |
if ($dbquery->checkFilter("from_date")) { |
|
135
|
|
|
$date = new Intraface_Date($dbquery->getFilter("from_date")); |
|
136
|
|
|
if ($date->convert2db()) { |
|
137
|
|
|
$query = $query->addWhere($date_field." >= ?", $date->get()); |
|
|
|
|
|
|
138
|
|
|
} else { |
|
139
|
|
|
$this->error->set("Fra dato er ikke gyldig"); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
// Poster med fakturadato f�r slutdato. |
|
144
|
|
View Code Duplication |
if ($dbquery->checkFilter("to_date")) { |
|
145
|
|
|
$date = new Intraface_Date($dbquery->getFilter("to_date")); |
|
146
|
|
|
if ($date->convert2db()) { |
|
147
|
|
|
$query = $query->addWhere($date_field." <= ? ", $date->get()); |
|
148
|
|
|
} else { |
|
149
|
|
|
$this->error->set("Til dato er ikke gyldig"); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
// alle ikke bogf�rte skal findes |
|
153
|
|
|
if ($dbquery->checkFilter("not_stated")) { |
|
154
|
|
|
$query = $query->addWhere("voucher_id = 0"); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
if ($dbquery->checkFilter("status")) { |
|
158
|
|
|
if ($dbquery->getFilter("status") == "-1") { |
|
|
|
|
|
|
159
|
|
|
// Beh�ves ikke, den tager alle. |
|
160
|
|
|
// $query = $query->addWhere("status >= 0"); |
|
|
|
|
|
|
161
|
|
View Code Duplication |
} elseif ($dbquery->getFilter("status") == "-2") { |
|
162
|
|
|
// Not executed = �bne |
|
163
|
|
|
if ($dbquery->checkFilter("to_date")) { |
|
164
|
|
|
$date = new Intraface_Date($dbquery->getFilter("to_date")); |
|
165
|
|
|
if ($date->convert2db()) { |
|
166
|
|
|
// Poster der er executed eller cancelled efter dato, og sikring at executed stadig er det, da faktura kan s�ttes tilbage. |
|
167
|
|
|
$query = $query->addWhere("(date_executed >= \"".$date->get()."\" AND status = 2) OR (date_cancelled >= \"".$date->get()."\") OR status < 2"); |
|
168
|
|
|
} |
|
169
|
|
|
} else { |
|
170
|
|
|
// Hvis der ikke er nogen dato s� tager vi alle dem som p� nuv�rende tidspunkt har status under |
|
171
|
|
|
$query = $query->addWhere("status < 2"); |
|
172
|
|
|
} |
|
173
|
|
|
} elseif ($dbquery->getFilter("status") == "-3") { |
|
174
|
|
|
// Afskrevne. Vi tager f�rst alle sendte og executed. |
|
175
|
|
|
|
|
176
|
|
|
if ($this->get("type") != "invoice") { |
|
|
|
|
|
|
177
|
|
|
throw new Exception("Afskrevne kan kun benyttes ved faktura"); |
|
178
|
|
|
} |
|
179
|
|
|
die('functionality not implemented yet! contact Intraface'); |
|
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
$dbquery->setJoin("INNER", "invoice_payment", "invoice_payment.payment_for_id = debtor.id", "invoice_payment.intranet_id = ".$this->kernel->intranet->get("id")." AND invoice_payment.payment_for = 1"); |
|
|
|
|
|
|
182
|
|
|
$query = $query->addWhere("invoice_payment.type = -1"); |
|
183
|
|
|
|
|
184
|
|
View Code Duplication |
if ($dbquery->checkFilter("to_date")) { |
|
185
|
|
|
$date = new Intraface_Date($dbquery->getFilter("to_date")); |
|
186
|
|
|
if ($date->convert2db()) { |
|
187
|
|
|
// alle som er sendte p� datoen og som ikke er cancelled |
|
188
|
|
|
$query = $query->addWhere("debtor.date_sent <= '".$date->get()."' AND debtor.status != 3"); |
|
189
|
|
|
$query = $query->addWhere("invoice_payment.payment_date <= '".$date->get()."'"); |
|
190
|
|
|
} |
|
191
|
|
|
} else { |
|
192
|
|
|
// Hvis der ikke er nogen dato s� tager vi alle dem som p� nuv�rende tidspunkt har status under |
|
193
|
|
|
$query = $query->addWhere("status = 1 OR status = 2"); |
|
194
|
|
|
} |
|
195
|
|
|
} else { |
|
196
|
|
|
$query = $query->addWhere("status = ?", intval($dbquery->getFilter("status"))); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
switch ($dbquery->getFilter("sorting")) { |
|
201
|
|
|
case 1: |
|
202
|
|
|
$query = $query->addOrderBy('number ASC, item.position'); |
|
203
|
|
|
break; |
|
204
|
|
|
case 2: |
|
205
|
|
|
$query = $query->addOrderBy('contact.number ASC, item.position'); |
|
206
|
|
|
break; |
|
207
|
|
|
case 3: |
|
208
|
|
|
$query = $query->addOrderBy('contact_address.name ASC, item.position'); |
|
209
|
|
|
break; |
|
210
|
|
|
default: |
|
211
|
|
|
$query = $query->addOrderBy('number DESC, item.position'); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
// $query = $query->getSql(); die($query); |
|
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
$collection = $query->execute(); |
|
218
|
|
|
|
|
219
|
|
|
return $collection; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
|
|
223
|
|
|
/* |
|
|
|
|
|
|
224
|
|
|
public function getMaxNumber() |
|
225
|
|
|
{ |
|
226
|
|
|
$collection = $this->table |
|
227
|
|
|
->createQuery() |
|
228
|
|
|
->select('id, details.number') |
|
229
|
|
|
->innerJoin('Intraface_modules_product_ProductDoctrine.details AS details') |
|
230
|
|
|
->addWhere('Intraface_modules_product_ProductDoctrine.active = 0 OR Intraface_modules_product_ProductDoctrine.active = 1') |
|
231
|
|
|
->orderBy('details.number') |
|
232
|
|
|
->execute(); |
|
233
|
|
|
|
|
234
|
|
|
if ($collection == NULL || $collection->count() == 0) { |
|
235
|
|
|
return 0; |
|
236
|
|
|
} else { |
|
237
|
|
|
return $collection->getLast()->getDetails()->getNumber(); |
|
238
|
|
|
} |
|
239
|
|
|
}*/ |
|
240
|
|
|
} |
|
241
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.