/**
  *
  * @param sfWebRequest $request
  * @param ImputationAccountTransactionForm $form
  */
 private function processAccountTransactionForm(sfWebRequest $request, ImputationAccountTransactionForm $form)
 {
     $parameters = $request->getParameter($form->getName());
     if ($parameters['imputation']['account_id'] == 0) {
         $parameters['imputation']['account_id'] = null;
         $this->error_account = true;
     }
     if ($parameters['quantity'] != '') {
         $parameters['sum'] = -$parameters['quantity'];
         $parameters['imputation']['total'] = 0;
         $parameters['imputation']['method_of_payment_id'] = ImputationDefaultValues::getFreeMethodId();
         unset($parameters['unitary_price']);
         unset($parameters['quantity']);
         $this->error_account = false;
     }
     $form->bind($parameters);
     if ($form->isValid()) {
         $transaction = $form->save();
         $account = Doctrine::getTable('Account')->find($parameters['imputation']['account_id']);
         $account->setValue($account->getValue() + $parameters['sum']);
         $account->save();
         if ($parameters['imputation']['method_of_payment_id'] == ImputationDefaultValues::getAccountMethodId()) {
             //If the method of payment is 'account':
             //Find the target account (the account used to pay):
             $target_account = Doctrine::getTable('Account')->find($parameters['account_to_pay_id']);
             $parameters_to_pay = $parameters;
             $parameters_to_pay['sum'] = $parameters['imputation']['total'];
             $parameters_to_pay['imputation']['total'] = $parameters_to_pay['sum'];
             $parameters_to_pay['imputation']['account_id'] = $parameters['account_to_pay_id'];
             $parameters_to_pay['imputation']['unity_id'] = $target_account->getAct()->getUnityId();
             //print_r($parameters_to_pay);exit(-1);
             //Duplicate the form:
             $transaction = new ImputationAccountTransaction();
             $transaction->getImputation()->setUserId($parameters['imputation']['user_id']);
             $form_to_pay = new ImputationAccountTransactionForm($transaction, array('culture' => ParametersConfiguration::getDefault('default_language')));
             //Bind it with the duplicate parameters:
             $form_to_pay->bind($parameters_to_pay);
             if ($form_to_pay->isValid()) {
                 //If the form is valid, change the target account value:
                 $target_account->setValue($target_account->getValue() - $parameters_to_pay['sum']);
                 $target_account->save();
                 //Eventually if the form is valid, save the duplicated form:
                 $form_to_pay->save();
                 $this->error_account = false;
             }
         } else {
             $this->error_account = true;
         }
         $this->redirect('use/index');
     }
 }