1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\ORM\Query\Parameter; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* OrdersRepository |
11
|
|
|
* |
12
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
13
|
|
|
* repository methods below. |
14
|
|
|
*/ |
15
|
|
|
class OrdersRepository extends EntityRepository |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Renvoi les dernières commandes. |
19
|
|
|
* |
20
|
|
|
* @param integer $count Nombre d'élément à afficher |
21
|
|
|
* @return array Query result |
22
|
|
|
*/ |
23
|
|
|
public function getLastOrder($count) |
24
|
|
|
{ |
25
|
|
|
$query = $this->findOrders() |
26
|
|
|
->setMaxResults($count) |
27
|
|
|
->getQuery(); |
28
|
|
|
|
29
|
|
|
return $query->getResult(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Renvoi les dernières commandes. |
34
|
|
|
* |
35
|
|
|
* @param integer $count Nombre d'élément à afficher |
36
|
|
|
* @return array Query result |
37
|
|
|
*/ |
38
|
|
|
public function getLastDelivery($count) |
39
|
|
|
{ |
40
|
|
|
$query = $this->findDeliveries() |
41
|
|
|
->setMaxResults($count) |
42
|
|
|
->getQuery(); |
43
|
|
|
|
44
|
|
|
return $query->getResult(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Renvoi les dernières commandes. |
49
|
|
|
* |
50
|
|
|
* @param integer $count Nombre d'élément à afficher |
51
|
|
|
* @return array Query result |
52
|
|
|
*/ |
53
|
|
|
public function getLastInvoice($count) |
54
|
|
|
{ |
55
|
|
|
$query = $this->findInvoices() |
56
|
|
|
->setMaxResults($count) |
57
|
|
|
->andWhere('o.status = 2') |
58
|
|
|
->getQuery(); |
59
|
|
|
|
60
|
|
|
return $query->getResult(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Find Orders before delivering. |
65
|
|
|
* |
66
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public function findOrders() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$query = $this->createQueryBuilder('o') |
71
|
|
|
->orderBy('o.id', 'DESC') |
72
|
|
|
->where('o.delivdate > :date') |
73
|
|
|
->andWhere('o.status = :status') |
74
|
|
|
->setParameters(new ArrayCollection([new Parameter('date', date('Y-m-d')), new Parameter('status', 1)])); |
75
|
|
|
|
76
|
|
|
return $query; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Find Orders for delivering. |
81
|
|
|
* |
82
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
83
|
|
|
*/ |
84
|
|
View Code Duplication |
public function findDeliveries() |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$query = $this->createQueryBuilder('o') |
87
|
|
|
->orderBy('o.id', 'DESC') |
88
|
|
|
->where('o.delivdate <= :date') |
89
|
|
|
->andWhere('o.status = :status') |
90
|
|
|
->setParameters(new ArrayCollection([new Parameter('date', date('Y-m-d')), new Parameter('status', 1)])); |
91
|
|
|
|
92
|
|
|
return $query; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Find Orders for billing. |
97
|
|
|
* |
98
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
public function findInvoices() |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$query = $this->createQueryBuilder('o') |
103
|
|
|
->orderBy('o.id', 'DESC') |
104
|
|
|
->where('o.delivdate < :date') |
105
|
|
|
->andWhere('o.status > :status') |
106
|
|
|
->setParameters(new ArrayCollection([new Parameter('date', date('Y-m-d')), new Parameter('status', 1)])); |
107
|
|
|
|
108
|
|
|
return $query; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.