|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AbstractInventoryController Méthodes communes InventoryController. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Quétier Laurent <[email protected]> |
|
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
10
|
|
|
* |
|
11
|
|
|
* @version since 1.0.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace AppBundle\Controller; |
|
16
|
|
|
|
|
17
|
|
|
use AppBundle\Controller\AbstractController; |
|
18
|
|
|
use AppBundle\Entity\Inventory; |
|
19
|
|
|
use AppBundle\Form\Type\InventoryType; |
|
20
|
|
|
use AppBundle\Form\Type\InventoryEditType; |
|
21
|
|
|
use AppBundle\Form\Type\InventoryEditZonesType; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Abstract controller. |
|
25
|
|
|
* |
|
26
|
|
|
* @category Controller |
|
27
|
|
|
*/ |
|
28
|
|
|
class AbstractInventoryController extends AbstractController |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Get the Inventory edit type |
|
32
|
|
|
* |
|
33
|
|
|
* @param \AppBundle\Controller\Inventory $inventory Inventaire à éditer |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function getInvetoryEditType(Inventory $inventory) |
|
37
|
|
|
{ |
|
38
|
|
|
$etm = $this->getDoctrine()->getManager(); |
|
39
|
|
|
$zoneStorages = null; |
|
40
|
|
|
$settings = $etm->getRepository('AppBundle:Settings')->find(1); |
|
41
|
|
|
if ($settings->getInventoryStyle() == 'zonestorage') { |
|
42
|
|
|
$zoneStorages = $etm->getRepository('AppBundle:ZoneStorage')->findAll(); |
|
43
|
|
|
$typeClass = InventoryEditZonesType::class; |
|
44
|
|
|
} else { |
|
45
|
|
|
$typeClass = InventoryEditType::class; |
|
46
|
|
|
} |
|
47
|
|
|
$editForm = $this->createForm( |
|
48
|
|
|
$typeClass, |
|
49
|
|
|
$inventory, |
|
50
|
|
|
['action' => $this->generateUrl('inventory_update', ['id' => $inventory->getId()]), |
|
51
|
|
|
'method' => 'PUT',] |
|
52
|
|
|
); |
|
53
|
|
|
$deleteForm = $this->createDeleteForm($inventory->getId(), 'inventory_delete'); |
|
54
|
|
|
|
|
55
|
|
|
$return = ['editForm' => $editForm, |
|
56
|
|
|
'inventory' => $inventory, |
|
57
|
|
|
'zoneStorages' => $zoneStorages, |
|
58
|
|
|
'edit_form' => $editForm->createView(), |
|
59
|
|
|
'delete_form' => $deleteForm->createView(),]; |
|
60
|
|
|
return $return; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Create Create form. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $route Route of action form |
|
67
|
|
|
* @return \Symfony\Component\Form\Form |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function createCreateForm($route) |
|
70
|
|
|
{ |
|
71
|
|
|
$inventory = new Inventory(); |
|
72
|
|
|
return $this->createForm( |
|
73
|
|
|
InventoryType::class, |
|
74
|
|
|
$inventory, |
|
75
|
|
|
['attr' => ['id' => 'create'], 'action' => $this->generateUrl($route), 'method' => 'PUT',] |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get Line Articles |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $articleLine |
|
83
|
|
|
* @param Inventory $inventory |
|
84
|
|
|
* @return array $articleLine |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function getLineArticles(array $articleLine, Inventory $inventory) |
|
87
|
|
|
{ |
|
88
|
|
|
$inventoryArticles = array(); |
|
89
|
|
|
$lineOk = 0; |
|
90
|
|
|
foreach ($inventory->getArticles() as $line) { |
|
91
|
|
|
foreach ($articleLine as $key => $art) { |
|
92
|
|
|
if (!empty($articleLine) && $line->getArticle()->getName() === $art['article']) { |
|
93
|
|
|
$art['realstock'] = $art['realstock'] + $line->getRealstock(); |
|
94
|
|
|
$articleLine[$key]['realstock'] = strval(number_format($art['realstock'], 3)); |
|
95
|
|
|
$lineOk = 1; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
if ($lineOk === 0) { |
|
99
|
|
|
$inventoryArticles['article'] = $line->getArticle()->getName(); |
|
100
|
|
|
$inventoryArticles['realstock'] = $line->getRealstock(); |
|
101
|
|
|
array_push($articleLine, $inventoryArticles); |
|
102
|
|
|
} |
|
103
|
|
|
$lineOk = 0; |
|
104
|
|
|
} |
|
105
|
|
|
return $articleLine; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|