Overview

Namespaces

  • Igestis
    • Modules
      • Commercial
  • None

Classes

  • AccountingController
  • ConfigControllers
  • ConfigHookListener
  • ConfigInitModule
  • ConfigModuleVars
  • indexController
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  1: <?php
  2: 
  3: namespace Igestis\Modules\Commercial;
  4: /**
  5:  * Accounting management
  6:  *
  7:  * @author Gilles Hemmerlé
  8:  */
  9: class AccountingController extends \IgestisController {
 10: 
 11:     /**
 12:      * Show the list of accountings
 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:      * Delete the purchasing account
 24:      */
 25:     public function purchasingAccountDelAction($Id) {
 26:         $CommercialPurchasingAccount = $this->context->entityManager->getRepository("CommercialPurchasingAccount")->find($Id);
 27:         if(!$CommercialPurchasingAccount) $this->context->throw404error();
 28:         
 29:         // Delete the purchasing account from the database
 30:         try {
 31:             $this->context->entityManager->remove($CommercialPurchasingAccount);
 32:             $this->context->entityManager->flush();
 33:         } catch (\Exception $e) {
 34:             // Show wizz to alert user that the purchasing account deletion has not realy been deleted
 35:             \gestisErrors::createWizz($e);
 36:             $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
 37:         }
 38: 
 39:         // Show wizz to confirm the update
 40:         new \wizz(_("The purchasing account has been successfully deleted"), \WIZZ::$WIZZ_SUCCESS);
 41: 
 42:         // Redirect to the list
 43:         $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
 44:     }
 45: 
 46:     /**
 47:      * Add a purchasing account
 48:      */
 49:     public function purchasingAccountNewAction() {
 50:         if ($this->request->IsPost()) {
 51:             // Check the form validity
 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:             // Get the original department
 59:             $account = new \CommercialPurchasingAccount();
 60: 
 61:             // Set the new datas to the department
 62:             $parser = new \IgestisFormParser();
 63:             $department = $parser->FillEntityFromForm($account, $_POST);
 64: 
 65:             // Save the department into the $account
 66:             $this->context->entityManager->persist($department);
 67:             $this->context->entityManager->flush();
 68: 
 69:             // Show wizz to confirm the department update
 70:             new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
 71: 
 72:             // Redirect to the department list
 73:             $this->redirect(ConfigControllers::createUrl("commercial_accounting_index"));
 74:         }
 75: 
 76:         $this->context->render("Commercial/pages/accountingPurchasingNew.twig", array());
 77:     }
 78:     
 79:     /**
 80:      * Get a form to edit or validate it if the form is received
 81:      */
 82:     public function purchasingAccountEditAction($Id) {
 83:         $account = $this->context->entityManager->getRepository("CommercialPurchasingAccount")->find($Id);
 84:         if(!$account) $this->context->throw404error();
 85:         
 86:         // If the form has been received, manage the form...
 87:         if ($this->request->IsPost()) {
 88:             // Check the form validity
 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:                 // Set the new datas to the department
 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:             // Show wizz to confirm the department update
104:             new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
105: 
106:             // Redirect to the department list
107:             $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
108:         }
109: 
110:         // If no form received, show the form
111:         $this->context->render("Commercial/pages/accountingPurchasingEdit.twig", array(
112:             'form_data' => $account
113:         ));
114:     }
115:     
116:     /****************************************************************************************************************************************
117:      * Delete the selling account
118:      */
119:     public function sellingAccountDelAction($Id) {
120:         $CommercialSellingAccount = $this->context->entityManager->getRepository("CommercialSellingAccount")->find($Id);
121:         if(!$CommercialSellingAccount) $this->context->throw404error();
122:         
123:         // Delete the selling account from the database
124:         try {
125:             $this->context->entityManager->remove($CommercialSellingAccount);
126:             $this->context->entityManager->flush();
127:         } catch (\Exception $e) {
128:             // Show wizz to alert user that the selling account deletion has not realy been deleted
129:             \gestisErrors::createWizz($e);
130:             $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
131:         }
132: 
133:         // Show wizz to confirm the update
134:         new \wizz(_("The selling account has been successfully deleted"), \WIZZ::$WIZZ_SUCCESS);
135: 
136:         // Redirect to the list
137:         $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
138:     }
139: 
140:     /**
141:      * Add a selling account
142:      */
143:     public function sellingAccountNewAction() {
144:         if ($this->request->IsPost()) {
145:             // Check the form validity
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:             // Get the original department
153:             $account = new \CommercialSellingAccount();
154: 
155:             // Set the new datas to the department
156:             $parser = new \IgestisFormParser();
157:             $department = $parser->FillEntityFromForm($account, $_POST);
158: 
159:             // Save the department into the $account
160:             $this->context->entityManager->persist($department);
161:             $this->context->entityManager->flush();
162: 
163:             // Show wizz to confirm the department update
164:             new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
165: 
166:             // Redirect to the department list
167:             $this->redirect(ConfigControllers::createUrl("commercial_accounting_index"));
168:         }
169: 
170:         $this->context->render("Commercial/pages/accountingSellingNew.twig", array());
171:     }
172:     
173:     /**
174:      * Get a form to edit or validate it if the form is received
175:      */
176:     public function sellingAccountEditAction($Id) {
177:         $account = $this->context->entityManager->getRepository("CommercialSellingAccount")->find($Id);
178:         if(!$account) $this->context->throw404error();
179:         
180:         // If the form has been received, manage the form...
181:         if ($this->request->IsPost()) {
182:             // Check the form validity
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:                 // Set the new datas to the department
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:             // Show wizz to confirm the department update
198:             new \wizz(_("The account data has been successfully saved"), \WIZZ::$WIZZ_SUCCESS);
199: 
200:             // Redirect to the department list
201:             $this->redirect(\ConfigControllers::createUrl("commercial_accounting_index"));
202:         }
203: 
204:         // If no form received, show the form
205:         $this->context->render("Commercial/pages/accountingSellingEdit.twig", array(
206:             'form_data' => $account
207:         ));
208:     }
209: 
210: }
211: 
igestis-iprojectis-v2 API documentation generated by ApiGen 2.8.0