예제 #1
0
 public function historyList($id)
 {
     $list = array();
     $calculationList = $this->findAllCalculations($id);
     foreach ($calculationList as $calculation) {
         $items = $this->calculationItemFacade->findCalculationItems($calculation->getId());
         foreach ($items as $item) {
             array_push($list, array('date' => $calculation->getDate(), 'name' => $item->getName(), 'previous' => $item->getPrevious(), 'current' => $item->getCurrent(), 'tariff' => $item->getTariff()));
         }
     }
     return $list;
 }
예제 #2
0
 public function formCalculatorSucceeded($form)
 {
     if ($form['submit']->isSubmittedBy()) {
         $date = DateTime::createFromFormat('Y-m-d', date("Y-m-d"))->format('Y-m-d');
         $currentCalculation = $this->calculationFacade->findByDate($date, $this->addressId);
         if ($currentCalculation == NULL) {
             $this->calculationFacade->update(array('date' => $date, 'address' => $this->addressFacade->find($this->addressId)));
             $currentCalculation = $this->calculationFacade->findByDate($date, $this->addressId);
         } else {
             $items = $this->calculationItemFacade->findCalculationItems($currentCalculation->getId());
             foreach ($items as $item) {
                 $this->calculationItemFacade->delete($item->getId());
             }
         }
         foreach ($this->tariffs as $item) {
             $this->calculationItemFacade->update(array('tariff' => $item['value'], 'previous' => $form['previous_' . array_search($item, $this->tariffs)]->getValue(), 'current' => $form['current_' . array_search($item, $this->tariffs)]->getValue(), 'calculation' => $currentCalculation, 'name' => $item['name']));
         }
     } else {
         if ($form['addCategory']->isSubmittedBy()) {
             foreach ($form['addCategory']->values as $newCategory) {
                 $this->tariffFacade->update(array('address' => $this->addressFacade->find($this->addressId), 'value' => (double) str_replace(',', '.', $newCategory['tariff']), 'name' => $newCategory['category']));
             }
         } else {
             if ($form['deleteAddress']->isSubmittedBy()) {
                 $this->addressFacade->delete($this->addressId);
                 throw new InvalidArgumentException('Address with id=' . $this->addressId . ' has been deleted');
             } else {
                 foreach (array_keys($this->tariffs) as $key) {
                     if ($form['delete_' . $key]->isSubmittedBy()) {
                         $this->tariffFacade->delete($key);
                     }
                 }
             }
         }
     }
 }