Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • Quote
  • QuoteProduct
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Model class for line items and adjustments in a quote.
  5:  *
  6:  * @property bool $isTotalAdjustment Tells whether the adjustment type
  7:  * designates it as an adjustment to the subtotal
  8:  * @property bool $isPercentAdjustment Tells whether the adjustment units is
  9:  * a percentage
 10:  * @package application.modules.quotes.models
 11:  * @author David Visbal, Demitri Morgan <demitri@x2engine.com>
 12:  */
 13: class QuoteProduct extends CActiveRecord {
 14: 
 15:     private $_isPercentAdjustment;
 16:     private $_isTotalAdjustment;
 17: 
 18:     public function resolveAdjustmentType() {
 19:         if(empty($this->adjustmentType))
 20:             $this->adjustmentType = 'linear';
 21:         return $this->adjustmentType;
 22:     }
 23: 
 24:     public function getIsPercentAdjustment() {
 25:         if (!isset($this->_isPercentAdjustment)) {
 26:             $adjType = $this->resolveAdjustmentType();
 27:             $this->_isPercentAdjustment = $adjType == 'percent' || $adjType == 'totalPercent';
 28:         }
 29:         return $this->_isPercentAdjustment;
 30:     }
 31: 
 32: 
 33:     /**
 34:      * Magic getter for {@link isTotalAdjustment}
 35:      * @return bool
 36:      */
 37:     public function getIsTotalAdjustment() {
 38:         if(!isset($this->_isTotalAdjustment)) {
 39:             $adjType = $this->resolveAdjustmentType();
 40:             $this->_isTotalAdjustment = strpos($adjType,'total') === 0;
 41:         }
 42:         return $this->_isTotalAdjustment;
 43:     }
 44: 
 45: 
 46:     public static function model($className = __CLASS__) {
 47:         return parent::model($className);
 48:     }
 49: 
 50: // return: database table name
 51:     public function tableName() {
 52:         return 'x2_quotes_products';
 53:     }
 54: 
 55: 
 56: // return: array validation rules for model attributes.
 57:     public function rules() {
 58: // NOTE: you should only define rules for those attributes that
 59: // will receive user inputs.
 60:         return array(
 61:             array('lineNumber,productId', 'numerical', 'integerOnly' => true),
 62:             array('quantity','numerical'),
 63:             array('price,adjustment,total','numerical','allowEmpty'=>true),
 64:             array('name','required'),
 65:             array('name,type,currency', 'length', 'max' => 100),
 66:             array('description', 'safe', 'safe' => true),
 67:             array('adjustmentType', 'in', 'range' => array('percent', 'linear', 'totalPercent', 'totalLinear')),
 68:         );
 69:     }
 70: 
 71:     public function relations() {
 72:         return array(
 73:             'product' => array(self::BELONGS_TO, 'Product', 'productId'),
 74:             'quote' => array(self::BELONGS_TO, 'Quote', 'quoteId'),
 75:         );
 76:     }
 77: 
 78:     /**
 79:      * Formats an attribute that's a numeric value so that it reflects its type,
 80:      * i.e. currency or percentage.
 81:      */
 82:     public function formatAttribute($attr,$value=null) {
 83:         $percentage =  $this->isPercentAdjustment;
 84:         if(empty($this->currency) && !empty($this->quoteId))
 85:             $this->currency = $this->quote->currency;
 86:         if($value===null)
 87:             $value = $this->$attr;
 88:         if($attr == 'adjustment' && $percentage) {
 89:             return $value.'%';
 90:         } else if($attr == 'price' || $attr == 'adjustment' || $attr == 'total') {
 91:             return $this->formatCurrency ($value);
 92:         } else {
 93:             return $value;
 94:         }
 95:     }
 96: 
 97:     /**
 98:      * Wrapper for {@link formatAttribute()} used in direct markup output
 99:      * @param string $attr
100:      * @param mixed $value
101:      * @return type
102:      */
103:     public function renderAttribute($attr,$value=null) {
104:         return CHtml::encode($this->formatAttribute($attr,$value));
105:     }
106: 
107:     /**
108:      * Wrapper around formatCurrency which forces use of '-' negative prefix
109:      */
110:     private function formatCurrency ($value) {
111:         return Yii::app ()->locale->numberFormatter->formatCurrency (
112:             $value, $this->currency, '-ยค');
113: 
114:     }
115: 
116: }
117: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0