@@ -28,7 +28,7 @@ |
||
28 | 28 | * |
29 | 29 | * @throws \Exception |
30 | 30 | */ |
31 | - public function __invoke(InvoiceDamageCommand $command){ |
|
31 | + public function __invoke(InvoiceDamageCommand $command) { |
|
32 | 32 | $damage = $this->damageRepository->getById(DamageId::create($command->getDamageId())); |
33 | 33 | $damage = $damage->invoice(); |
34 | 34 | $this->damageRepository->save($damage); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | public function __construct(\DoliDB $db, $tableName) |
24 | 24 | { |
25 | 25 | $this->db = $db; |
26 | - $this->tableName = strpos($tableName, MAIN_DB_PREFIX) === 0 ? $tableName : MAIN_DB_PREFIX.$tableName; |
|
26 | + $this->tableName = strpos($tableName, MAIN_DB_PREFIX) === 0 ? $tableName : MAIN_DB_PREFIX . $tableName; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @throws \Exception |
35 | 35 | */ |
36 | - protected function write(array $elements){ |
|
36 | + protected function write(array $elements) { |
|
37 | 37 | $columns = join(',', array_keys($elements)); |
38 | 38 | $values = join(',', array_map([$this, 'escape'], array_values($elements))); |
39 | 39 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $lasterror = $this->db->lasterror(); |
45 | 45 | dol_syslog(__METHOD__ . ' ' . $lasterror, LOG_ERR); |
46 | 46 | $this->db->rollback(); |
47 | - throw new \Exception("Repository error - ".$lasterror); |
|
47 | + throw new \Exception("Repository error - " . $lasterror); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $id = $this->db->last_insert_id($this->tableName); |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return int|string|null |
59 | 59 | */ |
60 | - private function escape($value){ |
|
61 | - if(is_null($value)){ |
|
60 | + private function escape($value) { |
|
61 | + if (is_null($value)) { |
|
62 | 62 | return null; |
63 | 63 | } |
64 | 64 | |
65 | - if(is_bool($value)){ |
|
66 | - return (int)$value; |
|
65 | + if (is_bool($value)) { |
|
66 | + return (int) $value; |
|
67 | 67 | } |
68 | 68 | |
69 | - return is_string($value) ? $this->db->escape($value) : $value ; |
|
69 | + return is_string($value) ? $this->db->escape($value) : $value; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -79,18 +79,18 @@ discard block |
||
79 | 79 | { |
80 | 80 | $sqlModifications = []; |
81 | 81 | |
82 | - foreach($elements as $field => $value){ |
|
82 | + foreach ($elements as $field => $value) { |
|
83 | 83 | $sqlModifications[] = sprintf('%s=%s', $field, $this->escape($value)); |
84 | 84 | } |
85 | 85 | |
86 | 86 | $this->db->begin(); |
87 | - $resql = $this->db->query(sprintf('UPDATE %s SET %s WHERE rowid = %s ', $this->tableName, join(',',$sqlModifications), $id)); |
|
87 | + $resql = $this->db->query(sprintf('UPDATE %s SET %s WHERE rowid = %s ', $this->tableName, join(',', $sqlModifications), $id)); |
|
88 | 88 | |
89 | 89 | if (!$resql) { |
90 | 90 | $lasterror = $this->db->lasterror(); |
91 | 91 | dol_syslog(__METHOD__ . ' ' . $lasterror, LOG_ERR); |
92 | 92 | $this->db->rollback(); |
93 | - throw new \Exception("Repository error - ".$lasterror); |
|
93 | + throw new \Exception("Repository error - " . $lasterror); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $this->db->commit(); |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array|null |
105 | 105 | */ |
106 | - protected function get($id){ |
|
107 | - $sql = sprintf('SELECT * FROM %s WHERE rowid = %s', $this->tableName, $id ); |
|
106 | + protected function get($id) { |
|
107 | + $sql = sprintf('SELECT * FROM %s WHERE rowid = %s', $this->tableName, $id); |
|
108 | 108 | |
109 | 109 | $resql = $this->db->query($sql); |
110 | 110 | if (!$resql) { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | return null; |
117 | 117 | } |
118 | 118 | |
119 | - for($i = 0; $i < $num ; $i++) { |
|
119 | + for ($i = 0; $i < $num; $i++) { |
|
120 | 120 | return $this->db->fetch_array($resql); |
121 | 121 | } |
122 | 122 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function __invoke(CreateDamageCommand $command) |
42 | 42 | { |
43 | 43 | $damage = FlightDamage::waiting(new DamageAmount($command->getAmount()), AuthorId::create($command->getAuthorId())); |
44 | - if(null !== $command->getFlightId()){ |
|
44 | + if (null !== $command->getFlightId()) { |
|
45 | 45 | $damage = FlightDamage::damage(FlightId::create($command->getFlightId()), new DamageAmount($command->getAmount()), AuthorId::create($command->getAuthorId())); |
46 | 46 | } |
47 | 47 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | private function linkSupplierInvoice($damageId, $invoiceId) |
61 | 61 | { |
62 | - if($invoiceId <= 0){ |
|
62 | + if ($invoiceId <= 0) { |
|
63 | 63 | return; |
64 | 64 | } |
65 | 65 | |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | * @param int $targetId |
81 | 81 | * @param string $targetType |
82 | 82 | */ |
83 | - private function insertLinks($damageId, $targetId, $targetType){ |
|
84 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
|
83 | + private function insertLinks($damageId, $targetId, $targetType) { |
|
84 | + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element ("; |
|
85 | 85 | $sql .= "fk_source"; |
86 | 86 | $sql .= ", sourcetype"; |
87 | 87 | $sql .= ", fk_target"; |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | $sql .= ") VALUES ("; |
90 | 90 | $sql .= $damageId; |
91 | 91 | $sql .= ", 'flightlog_damage'"; |
92 | - $sql .= ", ".$targetId; |
|
93 | - $sql .= ", '".$targetType."'"; |
|
92 | + $sql .= ", " . $targetId; |
|
93 | + $sql .= ", '" . $targetType . "'"; |
|
94 | 94 | $sql .= ")"; |
95 | 95 | |
96 | 96 | if ($this->db->query($sql)) |
@@ -14,20 +14,20 @@ |
||
14 | 14 | <td>Montant</td> |
15 | 15 | </tr> |
16 | 16 | <?php $total = 0; ?> |
17 | - <?php foreach($damages as $currentDamage):?> |
|
17 | + <?php foreach ($damages as $currentDamage):?> |
|
18 | 18 | <?php $total += $currentDamage->getAmount(); ?> |
19 | 19 | <tr> |
20 | - <td><?php echo $currentDamage->getAuthorName();?></td> |
|
21 | - <td><?php echo $currentDamage->getAmount();?>€</td> |
|
20 | + <td><?php echo $currentDamage->getAuthorName(); ?></td> |
|
21 | + <td><?php echo $currentDamage->getAmount(); ?>€</td> |
|
22 | 22 | <td> |
23 | - <?php if($currentDamage->isInvoiced()): ?> |
|
23 | + <?php if ($currentDamage->isInvoiced()): ?> |
|
24 | 24 | <i class="fas fa-check"></i> |
25 | 25 | <?php else: ?> |
26 | 26 | <i class="fas fa-times"></i> |
27 | 27 | <?php endif; ?> |
28 | 28 | </td> |
29 | 29 | <td> |
30 | - <a href="<?php print sprintf('%s/flightlog/index.php?r=get_one_damage&id=%s', DOL_URL_ROOT, $currentDamage->getId());?>"><i class="fas fa-link"></i></a> |
|
30 | + <a href="<?php print sprintf('%s/flightlog/index.php?r=get_one_damage&id=%s', DOL_URL_ROOT, $currentDamage->getId()); ?>"><i class="fas fa-link"></i></a> |
|
31 | 31 | </td> |
32 | 32 | </tr> |
33 | 33 | <?php endforeach; ?> |
@@ -53,9 +53,9 @@ |
||
53 | 53 | ?> |
54 | 54 | |
55 | 55 | <table class="border centpercent"> |
56 | - <tr><td class="fieldrequired">Auteur</td><td><?php echo $damage->getAuthorName();?></td></tr> |
|
57 | - <tr><td class="fieldrequired">Montant</td><td><?php echo $damage->getAmount();?>€</td></tr> |
|
58 | - <tr><td class="fieldrequired">Facturé</td><td><?php echo $damage->isInvoiced()? 'Oui' : 'Non';?></td></tr> |
|
56 | + <tr><td class="fieldrequired">Auteur</td><td><?php echo $damage->getAuthorName(); ?></td></tr> |
|
57 | + <tr><td class="fieldrequired">Montant</td><td><?php echo $damage->getAmount(); ?>€</td></tr> |
|
58 | + <tr><td class="fieldrequired">Facturé</td><td><?php echo $damage->isInvoiced() ? 'Oui' : 'Non'; ?></td></tr> |
|
59 | 59 | <tr> |
60 | 60 | <td class="fieldrequired">Vol</td> |
61 | 61 | <td> |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return FlightDamage |
57 | 57 | */ |
58 | - public static function load(FlightId $flightId, DamageAmount $amount, $billed, AuthorId $authorId, DamageId $id = null){ |
|
58 | + public static function load(FlightId $flightId, DamageAmount $amount, $billed, AuthorId $authorId, DamageId $id = null) { |
|
59 | 59 | return new self($amount, $billed, $authorId, $flightId, $id); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return FlightDamage |
68 | 68 | */ |
69 | - public static function damage(FlightId $flightId, DamageAmount $amount, AuthorId $authorId){ |
|
69 | + public static function damage(FlightId $flightId, DamageAmount $amount, AuthorId $authorId) { |
|
70 | 70 | return new self($amount, false, $authorId, $flightId); |
71 | 71 | } |
72 | 72 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return FlightDamage |
78 | 78 | */ |
79 | - public static function waiting(DamageAmount $amount, AuthorId $authorId){ |
|
79 | + public static function waiting(DamageAmount $amount, AuthorId $authorId) { |
|
80 | 80 | return new self($amount, false, $authorId); |
81 | 81 | } |
82 | 82 | |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | /** |
92 | 92 | * @return FlightId |
93 | 93 | */ |
94 | - public function getFlightId(){ |
|
94 | + public function getFlightId() { |
|
95 | 95 | return $this->flight; |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @return DamageAmount |
100 | 100 | */ |
101 | - public function amount(){ |
|
101 | + public function amount() { |
|
102 | 102 | return $this->amount; |
103 | 103 | } |
104 | 104 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return FlightDamage |
117 | 117 | */ |
118 | - public function invoice(){ |
|
118 | + public function invoice() { |
|
119 | 119 | return new self($this->flight, $this->amount, true, $this->author, $this->id); |
120 | 120 | } |
121 | 121 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | 'author_id' => $flightDamage->getAuthor()->getId() |
36 | 36 | ]; |
37 | 37 | |
38 | - if($flightDamage->getId()){ |
|
38 | + if ($flightDamage->getId()) { |
|
39 | 39 | $this->update($flightDamage->getId()->getId(), $fields); |
40 | 40 | return $flightDamage->getId()->getId(); |
41 | 41 | } |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @throws \Exception |
52 | 52 | */ |
53 | - public function getById(DamageId $id){ |
|
53 | + public function getById(DamageId $id) { |
|
54 | 54 | $damage = $this->get($id->getId()); |
55 | 55 | |
56 | - if(null === $damage){ |
|
56 | + if (null === $damage) { |
|
57 | 57 | throw new \Exception('Damage not found'); |
58 | 58 | } |
59 | 59 |
@@ -65,7 +65,7 @@ |
||
65 | 65 | * |
66 | 66 | * @return bool |
67 | 67 | */ |
68 | - public function match($route){ |
|
68 | + public function match($route) { |
|
69 | 69 | return $this->name === $route; |
70 | 70 | } |
71 | 71 |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * Display the form. |
21 | 21 | */ |
22 | - public function view(){ |
|
22 | + public function view() { |
|
23 | 23 | $id = $this->request->getParam('id'); |
24 | 24 | |
25 | - if($id === null){ |
|
25 | + if ($id === null) { |
|
26 | 26 | print '<p>Paramètre non fournis.</p>'; |
27 | 27 | return; |
28 | 28 | } |
29 | 29 | |
30 | 30 | $flight = new \Bbcvols($this->db); |
31 | - if($flight->fetch($id) <= 0){ |
|
31 | + if ($flight->fetch($id) <= 0) { |
|
32 | 32 | print '<p>Vol non trouvé</p>'; |
33 | 33 | return; |
34 | 34 | } |
@@ -39,24 +39,24 @@ discard block |
||
39 | 39 | $form = new DamageCreationForm('damage_creation', $this->db); |
40 | 40 | $form->bind($command); |
41 | 41 | |
42 | - if($this->request->isPost()){ |
|
42 | + if ($this->request->isPost()) { |
|
43 | 43 | $form->setData($this->request->getPostParameters()); |
44 | 44 | |
45 | - if(!$form->validate()){ |
|
45 | + if (!$form->validate()) { |
|
46 | 46 | return $this->render('flight_damage/form.php', [ |
47 | 47 | 'form' => $form, |
48 | 48 | ]); |
49 | 49 | } |
50 | 50 | |
51 | - try{ |
|
51 | + try { |
|
52 | 52 | $this->handle($form->getObject()); |
53 | - }catch(\Exception $e){ |
|
53 | + } catch (\Exception $e) { |
|
54 | 54 | print $e->getMessage(); |
55 | 55 | dol_syslog($e->getMessage(), LOG_ERR); |
56 | 56 | } |
57 | 57 | |
58 | 58 | |
59 | - return $this->redirect($_SERVER["PHP_SELF"].'?id='.$id); |
|
59 | + return $this->redirect($_SERVER["PHP_SELF"] . '?id=' . $id); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | return $this->render('flight_damage/form.php', [ |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * @return CreateDamageCommandHandler |
79 | 79 | */ |
80 | - private function getHandler(){ |
|
80 | + private function getHandler() { |
|
81 | 81 | return new CreateDamageCommandHandler($this->db, $this->getDamageRepository()); |
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @return FlightDamageRepository |
86 | 86 | */ |
87 | - private function getDamageRepository(){ |
|
87 | + private function getDamageRepository() { |
|
88 | 88 | return new FlightDamageRepository($this->db); |
89 | 89 | } |
90 | 90 |