Bonjour,

Alors voilà j'ai cette erreur:

Undefined method 'createQueryBuider'. The method name must start with either findBy or findOneBy!
Evidemment j'ai essayé de renommer en mettant findBy au début de ma méthode, mais j'ai le même problème et j'ai bien @ORM\Entity(repositoryClass="GestionBundle\Repository\InterventionRepository") dans mon entité Intervention. Si quelqu'un a une idée.

Je fais une requête pour faire le calcul du coût total.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
 
namespace GestionBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToOne;
use GestionBundle\Entity\KindWork;
use GestionBundle\Entity\Place;
use GestionBundle\Entity\TypeIntervention;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\DateTime;
 
/**
 * Intervention
 *
 * @ORM\Table(name="intervention")
 * @ORM\Entity(repositoryClass="GestionBundle\Repository\InterventionRepository")
 */
class Intervention {
 
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var DateTime
     *
     * @ORM\Column(name="intervention_date", type="date")
     * 
     */
    private $interventionDate;
 
    /**
     * @var int
     *
     * @ORM\Column(name="week_number", type="smallint")
     * @Assert\NotBlank()
     */
    private $weekNumber;
 
    /**
     * @var float
     *
     * @ORM\Column(name="number_hours", type="float")
     */
    private $numberHours;
 
    /**
     * @var string
     *
     * @ORM\Column(name="comments", type="text", nullable=true)
     */
    private $comments;
 
    /**
     * @ORM\ManyToOne(targetEntity="KindWork", inversedBy="intervention")
     */
    private $kindWork;
 
    /**
     *
     * @ORM\ManyToOne(targetEntity="TypeIntervention", inversedBy="intervention")
     * 
     */
    private $typeIntervention;
 
    /**
     *
     * @ORM\ManyToOne(targetEntity="Place", inversedBy="intervention")
     * 
     */
    private $places;
 
    /**
     *
     * @ManyToOne(targetEntity="Technician", inversedBy="interventions")
     * @ORM\JoinColumn(nullable=false)
     * @Assert\NotBlank()
     */
    private $technician;
 
    /**
     * One Intervention has One materialCost.
     * @OneToOne(targetEntity="MaterialCost", inversedBy="intervention", cascade={"persist"})
     * 
     * 
     */
    private $materialCost;
 
    /**
     * Constructor/Constructeur
     */
    public function __construct() {
        $this->id;
    }
 
    /**
     * Getters and Setters
     */
 
    /**
     * Get id
     *
     * @return int
     */
    public function getId() {
        return $this->id;
    }
 
    /**
     * Set interventionDate
     *
     * @param DateTime $interventionDate
     *
     * @return Intervention
     */
    public function setInterventionDate($interventionDate) {
        $this->interventionDate = $interventionDate;
 
        return $this;
    }
 
    /**
     * Get interventionDate
     *
     * @return DateTime
     */
    public function getInterventionDate() {
        return $this->interventionDate;
    }
 
    /**
     * Set weekNumber
     *
     * @param integer $weekNumber
     *
     * @return Intervention
     */
    public function setWeekNumber($weekNumber) {
        $this->weekNumber = $weekNumber;
 
        return $this;
    }
 
    /**
     * Get weekNumber
     *
     * @return int
     */
    public function getWeekNumber() {
        return $this->weekNumber;
    }
 
    /**
     * Set numberHours
     *
     * @param float $numberHours
     *
     * @return Intervention
     */
    public function setNumberHours($numberHours) {
        $this->numberHours = $numberHours;
 
        return $this;
    }
 
    /**
     * Get numberHours
     *
     * @return float
     */
    public function getNumberHours() {
        return $this->numberHours;
    }
 
    /**
     * Set comments
     *
     * @param string $comments
     *
     * @return Intervention
     */
    public function setComments($comments) {
        $this->comments = $comments;
 
        return $this;
    }
 
    /**
     * Get comments
     *
     * @return string
     */
    public function getComments() {
        return $this->comments;
    }
 
    public function setKindWork($kindWork) {
        $this->kindWork = $kindWork;
    }
 
    public function setTypeIntervention($typeIntervention) {
        $this->typeIntervention = $typeIntervention;
    }
 
    public function getKindWork() {
        return $this->kindWork;
    }
 
    public function getTypeIntervention() {
        return $this->typeIntervention;
    }
 
    public function getPlaces() {
        return $this->places;
    }
 
    public function setPlaces($places) {
        $this->places = $places;
    }
 
    public function getTechnician() {
        return $this->technician;
    }
 
    public function setTechnician($technician) {
        $this->technician = $technician;
    }
 
    public function getMaterialCost() {
        return $this->materialCost;
    }
 
    public function setMaterialCost($materialCost) {
        $this->materialCost = $materialCost;
    }
 
    /**
     * Add kindWork
     *
     * @param KindWork $kindWork
     *
     * @return Intervention
     */
    public function addKindWork(KindWork $kindWork) {
        $this->kindWork[] = $kindWork;
        $kindWork->setIntervention($this);
 
        return $this;
    }
 
    /**
     * Remove kindWork
     *
     * @param KindWork $kindWork
     */
    public function removeKindWork(KindWork $kindWork) {
        $this->kindWork->removeElement($kindWork);
    }
 
    /**
     * toString method/Méthode toString
     */
    public function __toString() {
        if (is_null($this->comments)) {
            return '';
        }
        return $this->comments;
    }
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php
 
namespace GestionBundle\Repository;
 
use GestionBundle\Entity\Intervention;
 
/**
 * InterventionRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class InterventionRepository extends \Doctrine\ORM\EntityRepository {
 
    public function findAll() {
        $qb = $this
                ->createQueryBuilder('intervention')
        ;
 
        return $qb->getQuery()->execute();
    }
 
    public function findByIdTotalCostLabor() {
        $qb = $this->createQueryBuider('i')
                ->select (i.id, (('SUM(laborCost.laborCost*intervention.numberHours) AS totalLaborCost')))
                ->from(Intervention::class, 'i')
                ->innerJoin('i.kindWork', 'k')
                ->innerJoin('k.laborCost', 'l')
                ->groupBy('i.id');
        return $qb->getQuery()->getArrayResult();
    }}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
 
namespace GestionBundle\Controller;
 
use GestionBundle\Entity\Intervention;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
 
/**
 * Intervention controller.
 *
 */
class InterventionController extends Controller {
 
    /**
     * Lists all intervention entities.
     *
     */
    public function indexAction() {
        $em = $this->getDoctrine()->getManager();
 
        $interventions = $em->getRepository('GestionBundle:Intervention')->findAll();
 
        return $this->render('intervention/index.html.twig', array(
                    'interventions' => $interventions,
        ));
    }
 
    /**
     * Creates a new intervention entity.
     *
     */
    public function newAction(Request $request) {
        $intervention = new Intervention();
        $form = $this->createForm('GestionBundle\Form\InterventionType', $intervention);
        $form->handleRequest($request);
 
        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($intervention);
            $em->flush();
 
            return $this->redirectToRoute('intervention_show', array('id' => $intervention->getId()));
        }
 
        return $this->render('intervention/new.html.twig', array(
                    'intervention' => $intervention,
                    'form' => $form->createView(),
        ));
    }
 
    /**
     * Finds and displays a intervention entity.
     *
     */
    public function showAction(Intervention $intervention) {
        $deleteForm = $this->createDeleteForm($intervention);
 
        return $this->render('intervention/show.html.twig', array(
                    'intervention' => $intervention,
                    'delete_form' => $deleteForm->createView(),
        ));
    }
 
    /**
     * Displays a form to edit an existing intervention entity.
     *
     */
    public function editAction(Request $request, Intervention $intervention) {
        $deleteForm = $this->createDeleteForm($intervention);
        $editForm = $this->createForm('GestionBundle\Form\InterventionType', $intervention);
        $editForm->handleRequest($request);
 
        if ($editForm->isSubmitted() && $editForm->isValid()) {
            $this->getDoctrine()->getManager()->flush();
 
            return $this->redirectToRoute('intervention_show', array('id' => $intervention->getId()));
        }
 
        return $this->render('intervention/edit.html.twig', array(
                    'intervention' => $intervention,
                    'edit_form' => $editForm->createView(),
                    'delete_form' => $deleteForm->createView(),
        ));
    }
 
    /**
     * Deletes a intervention entity.
     *
     */
    public function deleteAction(Request $request, Intervention $intervention) {
        $form = $this->createDeleteForm($intervention);
        $form->handleRequest($request);
 
        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->remove($intervention);
            $em->flush();
        }
 
        return $this->redirectToRoute('intervention_index');
    }
 
    /**
     * Creates a form to delete a intervention entity.
     *
     * @param Intervention $intervention The intervention entity
     *
     * @return Form The form
     */
    private function createDeleteForm(Intervention $intervention) {
        return $this->createFormBuilder()
                        ->setAction($this->generateUrl('intervention_delete', array('id' => $intervention->getId())))
                        ->setMethod('DELETE')
                        ->getForm()
        ;
    }
 
 
    public function summaryAction() {
        $em = $this->getDoctrine()->getManager();
 
//        $interventions = $em->getRepository('GestionBundle:Intervention')->findAll();
//
//        return $this->render('stat/summary.html.twig', ['controller_name' => 'InterventionController',
//                    'interventions' => $interventions, 'totalCostLabor' => '2']);
 
        $interventions = $em->getRepository('GestionBundle:Intervention')->findAll();
        $totalLaborCost = $em->getRepository('GestionBundle:Intervention')->findByIdTotalCostLabor();
        return $this->render('stat/summary.html.twig', ['controller_name' => 'InterventionController',
                    'interventions' => $interventions, 'totalCostLabor' => $totalLaborCost]);
    }
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
{% extends 'base.html.twig' %}
 
{% block body %}
 
    <div class="container">  
 
        <h2>{{'Summary table'|trans}}</h2>
        </br>
        {% for intervention in interventions %}
        <select class=form-control>
 <option value=annee>{% if intervention.interventionDate %}{{ intervention.interventionDate|date('Y') }}{% endif %}</option>
 </select>
 {% endfor %}
        </br>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>{{'Intervention date'|trans}}</th>
                    <th>{{'Week number'|trans}}</th>
                    <th>{{'Technician'|trans}}</th>
                    <th>{{'Trades'|trans}}</th>
                    <th>{{'Type of Intervention'|trans}}</th>
                    <th>{{'Kind Work'|trans}}</th>
                    <th>{{'Group Place'|trans}}</th>
                    <th>{{'Place'|trans}}</th>
                    <th>{{'Number hours'|trans}}</th>
                    <th>{{'Kind labor cost'|trans}}</th>
                    <th>{{'Labor Cost'|trans}}</th> 
                    <th>{{'Material Cost'|trans}}</th>
                    <th>{{'Total cost'|trans}}</th>
                    <th>{{'Total labor cost'|trans}}</th>
                    <th>{{'Comments'|trans}}</th>
                </tr>
            </thead>
            <tbody>
                {% for intervention in interventions %}
                    <tr>
                        <td>{% if intervention.interventionDate %}{{ intervention.interventionDate|date('d-m-Y') }}{% endif %}</td>
                        <td>{{ intervention.weekNumber }}</td>
                        <td>{{ intervention.technician }}</td>
                        <td>{{ intervention.technician.trades }}</td>
                        <td>{{ intervention.typeIntervention }}</td>
                        <td>{{ intervention.kindWork }}</td>
                        <td>{{ intervention.places.groupsPlaces }}</td>
                        <td>{{ intervention.places }}</td>
                        <td>{{ intervention.numberHours }}</td>
                        <td>{{ intervention.kindWork.laborCost.kindLaborCost }}</td>
                        <td>{{ intervention.kindWork.laborCost.laborCost }}</td>
                        <td>{{ intervention.materialCost }}</td>
                        <td>{{totalCostLabor}}</td>
                        {# Il aurait été préférable de faire une fonction dans le repertory et via le controller mais pas réussi#}
                        {#<td>{{ intervention.kindWork.laborCost.laborCost * intervention.numberHours}}</td>#}
 
                        <td>{{ intervention.comments }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
 
    </div>
{% endblock %}