function replaceProductAction()
 {
     $this->getDi()->authAdmin->getUser()->checkPermission('_payment', 'edit');
     $item = $this->getDi()->invoiceItemTable->load($this->_request->getInt('id'));
     $pr = $this->getDi()->productTable->load($item->item_id);
     $form = new Am_Form_Admin('replace-product-form');
     $form->setDataSources(array($this->_request));
     $form->method = 'post';
     $form->addHidden('id');
     $form->addHidden('user_id');
     $form->addStatic()->setLabel(___('Replace Product'))->setContent("#{$pr->product_id} [{$pr->title}]");
     $sel = $form->addSelect('product_id')->setLabel('To Product');
     $options = array('' => '-- ' . ___('Please select') . ' --');
     foreach ($this->getDi()->billingPlanTable->getProductPlanOptions() as $k => $v) {
         if (strpos($k, $pr->pk() . '-') !== 0) {
             $options[$k] = $v;
         }
     }
     $sel->loadOptions($options);
     $sel->addRule('required');
     $form->addSubmit('_save', array('value' => ___('Save')));
     if ($form->isSubmitted() && $form->validate()) {
         try {
             list($p, $b) = explode("-", $sel->getValue(), 2);
             $item->replaceProduct(intval($p), intval($b));
             $this->getDi()->adminLogTable->log("Inside invoice: product #{$item->item_id} replaced to product #{$p} (plan #{$b})", 'invoice', $item->invoice_id);
             return $this->ajaxResponse(array('ok' => true));
         } catch (Am_Exception $e) {
             $sel->setError($e->getMessage());
         }
     }
     echo $form->__toString();
 }