public function process($data) { $db = Zend_Registry::get('db'); $receivableMapper = new C3op_Projects_ReceivableMapper($db); if ($this->isValid($data) !== true) { throw new C3op_Form_ReceivableEditException('Invalid data!'); } else { $id = $data['id']; $receivable = $receivableMapper->findById($id); $receivable->SetTitle($data['title']); $receivable->SetProject($data['project']); $receivable->SetPredictedDate($this->prepareDateValueToSet($data['predictedDate'], new C3op_Util_ValidDate(), new C3op_Util_DateConverter())); $receivable->SetPredictedValue($data['predictedValue']); $receivable->SetRealDate($this->prepareDateValueToSet($data['realDate'], new C3op_Util_ValidDate(), new C3op_Util_DateConverter())); $receivable->SetRealValue($data['realValue']); $receivableMapper->update($receivable); } }
public function receivablesAction() { $receivableMapper = new C3op_Projects_ReceivableMapper($this->db); $id = $this->checkIdFromGet(); $thisProject = $this->projectMapper->findById($id); $receivablesIdList = $this->projectMapper->getAllReceivables($thisProject); $receivablesList = array(); reset($receivablesList); $receivablesTotalValue = 0; $receivablesCounter = 0; foreach ($receivablesIdList as $receivableId) { $thisReceivable = $receivableMapper->findById($receivableId); $receivablesCounter++; if ($thisReceivable->GetTitle()) { $title = $thisReceivable->GetTitle(); } else { $title = "(#{$receivablesCounter})"; } $validator = new C3op_Util_ValidDate(); if ($validator->isValid($thisReceivable->GetPredictedDate())) { $predictedDate = C3op_Util_DateDisplay::FormatDateToShow($thisReceivable->GetPredictedDate()); } else { $predictedDate = "(data desconhecida)"; } if ($thisReceivable->GetPredictedValue() > 0) { $receivablesTotalValue += $thisReceivable->GetPredictedValue(); $predictedValue = C3op_Util_CurrencyDisplay::FormatCurrency($thisReceivable->GetPredictedValue()); } else { $predictedValue = ""; } $productsIdList = $receivableMapper->getAllProducts($thisReceivable); $productsList = array(); foreach ($productsIdList as $productId) { $actionMapper = new C3op_Projects_ActionMapper($this->db); $thisAction = $actionMapper->findById($productId); $actionTitle = sprintf("<a href=/projects/action/detail/?id=%d>%s</a>", $productId, $thisAction->GetTitle()); $productsList[$productId] = array('title' => $actionTitle, 'linkDetail' => '/projects/action/detail/?id=' . $productId); } $receivablesList[$receivableId] = array('title' => $title, 'productsList' => $productsList, 'predictedDate' => $predictedDate, 'predictedValue' => $predictedValue, 'editLink' => '/projects/receivable/edit/?id=' . $receivableId); } if ($receivablesTotalValue == $thisProject->GetValue()) { $projectValue = C3op_Util_CurrencyDisplay::FormatCurrency($receivablesTotalValue) . " (OK)"; } else { $projectValue = "Valor do Projeto: " . C3op_Util_CurrencyDisplay::FormatCurrency($thisProject->GetValue()); $projectValue .= " Total dos recebimentos:" . C3op_Util_CurrencyDisplay::FormatCurrency($receivablesTotalValue) . " (?)"; } $projectInfo = array('title' => $thisProject->GetTitle(), 'linkDetail' => '/projects/project/detail/?id=' . $id, 'projectValue' => $projectValue, 'editLink' => '/projects/project/edit/?id=' . $id, 'receivablesList' => $receivablesList); $this->view->projectInfo = $projectInfo; }