public function editAction($id)
 {
     $payment = Paymentplan::findFirst(array("conditions" => "idPaymentplan = ?1", "bind" => array(1 => $id)));
     if (!$payment) {
         $this->flashSession->warning('El plan de pago que desea editar no existe, por favor valide la informaciĆ³n');
         return $this->response->redirect('Paymentplan');
     }
     $form = new PaymentplanForm($payment);
     $pxr = Pxr::findByIdPaymentplan($payment->idPaymentplan);
     if ($this->request->isPost()) {
         $form->bind($this->request->getPost(), $payment);
         $reports = $form->getValue('reports');
         if ($this->validateReports($reports)) {
             $status = $form->getValue('status');
             $status = trim($status);
             try {
                 $this->db->begin();
                 $payment->status = empty($status) || !$status ? 0 : 1;
                 $payment->updated = time();
                 if ($form->isValid() && $payment->save()) {
                     if ($this->deletePxr($pxr)) {
                         if ($this->savePxr($payment)) {
                             $this->db->commit();
                             $this->flashSession->success('Se ha editado el plan de pago exitosamente');
                             return $this->response->redirect("Paymentplan");
                         }
                     }
                 }
                 foreach ($payment->getMessages() as $msg) {
                     $this->flashSession->error($msg)->getMessage();
                 }
             } catch (Exception $ex) {
                 $this->db->rollback();
                 $this->logger->log("Exception while creatin payment plan... {$ex}");
                 $this->flashSession->error("Ha ocurrido un error, por favor contacte al administrador");
             }
         }
     }
     $reports = Report::find();
     $this->view->PaymentplanForm = $form;
     $this->view->setVar("payment", $payment);
     $this->view->setVar("reports", $reports);
     $this->view->setVar("pxr", $pxr);
 }