Ejemplo n.º 1
0
 /**
  * Delete a currency as long as it is not in use.
  */
 public function actionDelete($id)
 {
     if (!CurrencyValue::isCurrencyInUseById(intval($id))) {
         $currency = Currency::GetById(intval($id));
         $currency->delete();
     } else {
         Yii::app()->user->setFlash('notification', Zurmo::t('ZurmoModule', 'The currency was not removed because it is in use.'));
     }
     $this->redirect(array($this->getId() . '/configurationList'));
 }
 /**
  * Render a form layout.
  * @param $form If the layout is editable, then pass a $form otherwise it can
  * be null.
  * @return A string containing the element's content.
  */
 protected function renderFormLayout(ZurmoActiveForm $form)
 {
     $content = '<table>';
     $content .= '<colgroup>';
     $content .= '<col style="width:15%" /><col style="width:15%" /><col style="width:50%" /><col style="width:20%" />';
     $content .= '</colgroup>';
     $content .= '<tbody>';
     $content .= '<tr><th>' . $this->renderActiveHeaderContent() . '</th>';
     $content .= '<th>' . Zurmo::t('ZurmoModule', 'Code') . '</th>';
     $content .= '<th>' . Zurmo::t('ZurmoModule', 'Rate to') . '&#160;' . Yii::app()->currencyHelper->getBaseCode() . ' ' . $this->renderLastUpdatedHeaderContent() . '</th>';
     $content .= '<th>' . Zurmo::t('Core', 'Remove') . '</th>';
     $content .= '</tr>';
     foreach ($this->currencies as $currency) {
         $route = $this->moduleId . '/' . $this->controllerId . '/delete/';
         $content .= '<tr>';
         $content .= '<td class="checkbox-column">' . self::renderActiveCheckBoxContent($form, $currency) . '</td>';
         $content .= '<td>' . $currency->code . '</td>';
         $content .= '<td>' . $currency->rateToBase . '</td>';
         $content .= '<td>';
         if (count($this->currencies) == 1 || CurrencyValue::isCurrencyInUseById($currency->id)) {
             $content .= Zurmo::t('ZurmoModule', 'Currency in use.');
         } else {
             $content .= ZurmoHtml::link(Zurmo::t('Core', 'Remove'), Yii::app()->createUrl($route, array('id' => $currency->id)), array('class' => 'z-link'));
         }
         $content .= '</td>';
         $content .= '</tr>';
     }
     $content .= '</tbody>';
     $content .= '</table>';
     return $content;
 }
Ejemplo n.º 3
0
 /**
  * @depends testConstructDerivedWithUserDefaultCurrency
  */
 public function testIsCurrencyInUseByIdAndChangRateIfValueChangesOrCurrencyChanges()
 {
     $currencyHelper = Yii::app()->currencyHelper;
     $euro = Currency::getByCode('EUR');
     $this->assertFalse(CurrencyValue::isCurrencyInUseById($euro->id));
     $opportunity = new Opportunity();
     $opportunity->name = 'Tyfe';
     $opportunity->stage->value = 'Starting Up';
     $opportunity->closeDate = '2008-10-05';
     $opportunity->amount->value = 456.78;
     $opportunity->amount->currency = $euro;
     $this->assertTrue($opportunity->save());
     $this->assertEquals(1.5, $opportunity->amount->rateToBase);
     $this->assertTrue(CurrencyValue::isCurrencyInUseById($euro->id));
     //change the currency rate for the euro.
     $euro->rateToBase = 3;
     $this->assertTrue($euro->save());
     //Now test saving the opportunity again but not changing the amount value. The rate should stay the same.
     $id = $opportunity->id;
     unset($opportunity);
     $opportunity = Opportunity::getById($id);
     $this->assertEquals(456.78, $opportunity->amount->value);
     $opportunity->amount->value = 456.78;
     $this->assertTrue($opportunity->save());
     $this->assertEquals(456.78, $opportunity->amount->value);
     $this->assertEquals(1.5, $opportunity->amount->rateToBase);
     //Now change amount. the exchange rate should change.
     $opportunity->amount->value = 566.0;
     $this->assertTrue($opportunity->save());
     $this->assertEquals(3, $opportunity->amount->rateToBase);
     //Now change the currency only. should change rate.
     $id = $opportunity->id;
     unset($opportunity);
     $opportunity = Opportunity::getById($id);
     $opportunity->amount->currency = Currency::getByCode('USD');
     $this->assertTrue($opportunity->save());
     $this->assertEquals(1, $opportunity->amount->rateToBase);
 }