1: <?php
2:
3: namespace Igestis\Modules\Commercial;
4: 5: 6: 7: 8:
9: class AccountingController extends \IgestisController {
10:
11: 12: 13:
14: public function indexAction() {
15: $this->context->render("Commercial/pages/accountingList.twig", array(
16: 'sellingAccounts' => $this->context->entityManager->getRepository("CommercialSellingAccount")->findAll(),
17: 'purchasingAccounts' => $this->context->entityManager->getRepository("CommercialPurchasingAccount")->findAll()
18: ));
19: }
20:
21:
22: 23: 24:
25: public function purchasingAccountDelAction($Id) {
26: $CommercialPurchasingAccount = $this->context->entityManager->getRepository("CommercialPurchasingAccount")->find($Id);
27: if(!$CommercialPurchasingAccount) $this->context->throw404error();
28:
29:
30: try {
31: $this->context->entityManager->remove($CommercialPurchasingAccount);
32: $this->context->entityManager->flush();
33: } catch (\Exception $e) {
34:
35: \gestisErrors::createWizz($e);
36: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
37: }
38:
39:
40: new \wizz(_("The purchasing account has been successfully deleted"), \WIZZ::$WIZZ_SUCCESS);
41:
42:
43: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
44: }
45:
46: 47: 48:
49: public function purchasingAccountNewAction() {
50: if ($this->request->IsPost()) {
51:
52: if (!$this->request->getPost("label"))
53: $this->context->invalid_form(_("The account name is a required field"));
54:
55: if (!$this->request->getPost("accountNumber"))
56: $this->context->invalid_form(_("The account number is a required field"));
57:
58:
59: $account = new \CommercialPurchasingAccount();
60:
61:
62: $parser = new \IgestisFormParser();
63: $department = $parser->FillEntityFromForm($account, $_POST);
64:
65:
66: $this->context->entityManager->persist($department);
67: $this->context->entityManager->flush();
68:
69:
70: new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
71:
72:
73: $this->redirect(ConfigControllers::createUrl("commercial_accounting_index"));
74: }
75:
76: $this->context->render("Commercial/pages/accountingPurchasingNew.twig", array());
77: }
78:
79: 80: 81:
82: public function purchasingAccountEditAction($Id) {
83: $account = $this->context->entityManager->getRepository("CommercialPurchasingAccount")->find($Id);
84: if(!$account) $this->context->throw404error();
85:
86:
87: if ($this->request->IsPost()) {
88:
89: if (!$this->request->getPost("label")) $this->context->invalid_form(_("The account name is a required field"));
90: if (!$this->request->getPost("accountNumber")) $this->context->invalid_form(_("The account number is a required field"));
91:
92: try {
93:
94: $parser = new \IgestisFormParser();
95: $account = $parser->FillEntityFromForm($account, $_POST);
96: $this->context->entityManager->persist($account);
97: $this->context->entityManager->flush();
98: } catch (\Exception $e) {
99: \IgestisErrors::createWizz($e, \IgestisErrors::TYPE_ANY);
100: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
101: }
102:
103:
104: new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
105:
106:
107: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
108: }
109:
110:
111: $this->context->render("Commercial/pages/accountingPurchasingEdit.twig", array(
112: 'form_data' => $account
113: ));
114: }
115:
116: 117: 118:
119: public function sellingAccountDelAction($Id) {
120: $CommercialSellingAccount = $this->context->entityManager->getRepository("CommercialSellingAccount")->find($Id);
121: if(!$CommercialSellingAccount) $this->context->throw404error();
122:
123:
124: try {
125: $this->context->entityManager->remove($CommercialSellingAccount);
126: $this->context->entityManager->flush();
127: } catch (\Exception $e) {
128:
129: \gestisErrors::createWizz($e);
130: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
131: }
132:
133:
134: new \wizz(_("The selling account has been successfully deleted"), \WIZZ::$WIZZ_SUCCESS);
135:
136:
137: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
138: }
139:
140: 141: 142:
143: public function sellingAccountNewAction() {
144: if ($this->request->IsPost()) {
145:
146: if (!$this->request->getPost("label"))
147: $this->context->invalid_form(_("The account name is a required field"));
148:
149: if (!$this->request->getPost("accountNumber"))
150: $this->context->invalid_form(_("The account number is a required field"));
151:
152:
153: $account = new \CommercialSellingAccount();
154:
155:
156: $parser = new \IgestisFormParser();
157: $department = $parser->FillEntityFromForm($account, $_POST);
158:
159:
160: $this->context->entityManager->persist($department);
161: $this->context->entityManager->flush();
162:
163:
164: new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
165:
166:
167: $this->redirect(ConfigControllers::createUrl("commercial_accounting_index"));
168: }
169:
170: $this->context->render("Commercial/pages/accountingSellingNew.twig", array());
171: }
172:
173: 174: 175:
176: public function sellingAccountEditAction($Id) {
177: $account = $this->context->entityManager->getRepository("CommercialSellingAccount")->find($Id);
178: if(!$account) $this->context->throw404error();
179:
180:
181: if ($this->request->IsPost()) {
182:
183: if (!$this->request->getPost("label")) $this->context->invalid_form(_("The account name is a required field"));
184: if (!$this->request->getPost("accountNumber")) $this->context->invalid_form(_("The account number is a required field"));
185:
186: try {
187:
188: $parser = new \IgestisFormParser();
189: $account = $parser->FillEntityFromForm($account, $_POST);
190: $this->context->entityManager->persist($account);
191: $this->context->entityManager->flush();
192: } catch (\Exception $e) {
193: \IgestisErrors::createWizz($e, \IgestisErrors::TYPE_ANY);
194: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
195: }
196:
197:
198: new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
199:
200:
201: $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
202: }
203:
204:
205: $this->context->render("Commercial/pages/accountingSellingEdit.twig", array(
206: 'form_data' => $account
207: ));
208: }
209:
210: }
211: