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

  • AccountsGridViewProfileWidget
  • ActionMenu
  • ActionsGridViewProfileWidget
  • ActionsQuickCreateRelationshipBehavior
  • ActiveDateRangeInput
  • ApplicationConfigBehavior
  • Attachments
  • ChatBox
  • CommonControllerBehavior
  • ContactMapInlineTags
  • ContactsGridViewProfileWidget
  • CronForm
  • CSaveRelationsBehavior
  • DateRangeInputsWidget
  • DocsGridViewProfileWidget
  • DocViewer
  • DocViewerProfileWidget
  • EButtonColumnWithClearFilters
  • EmailDeliveryBehavior
  • EmailProgressControl
  • EncryptedFieldsBehavior
  • EventsChartProfileWidget
  • FileUploader
  • FontPickerInput
  • Formatter
  • FormView
  • GridViewWidget
  • History
  • IframeWidget
  • ImportExportBehavior
  • InlineActionForm
  • InlineEmailAction
  • InlineEmailForm
  • InlineEmailModelBehavior
  • InlineQuotes
  • JSONEmbeddedModelFieldsBehavior
  • JSONFieldsDefaultValuesBehavior
  • LeadRoutingBehavior
  • LeftWidget
  • LoginThemeHelper
  • LoginThemeHelperBase
  • MarketingGridViewProfileWidget
  • MediaBox
  • MessageBox
  • MobileFormatter
  • MobileFormLayoutRenderer
  • MobileLayoutRenderer
  • MobileLoginThemeHelper
  • MobileViewLayoutRenderer
  • ModelFileUploader
  • NewWebLeadsGridViewProfileWidget
  • NormalizedJSONFieldsBehavior
  • NoteBox
  • OnlineUsers
  • OpportunitiesGridViewProfileWidget
  • Panel
  • ProfileDashboardManager
  • ProfileGridViewWidget
  • ProfileLayoutEditor
  • ProfilesGridViewProfileWidget
  • Publisher
  • PublisherActionTab
  • PublisherCalendarEventTab
  • PublisherCallTab
  • PublisherCommentTab
  • PublisherEventTab
  • PublisherSmallCalendarEventTab
  • PublisherTab
  • PublisherTimeTab
  • QuickContact
  • QuickCreateRelationshipBehavior
  • QuotesGridViewProfileWidget
  • RecordAliasesWidget
  • RecordViewLayoutManager
  • RecordViewWidgetManager
  • RememberPagination
  • Reminders
  • ResponseBehavior
  • ResponsiveHtml
  • SearchIndexBehavior
  • ServicesGridViewProfileWidget
  • SmallCalendar
  • SmartActiveDataProvider
  • SmartDataProviderBehavior
  • SmartSort
  • SocialForm
  • SortableWidgetManager
  • SortableWidgets
  • TagBehavior
  • TagCloud
  • TemplatesGridViewProfileWidget
  • TimeZone
  • TopContacts
  • TopSites
  • TransformedFieldStorageBehavior
  • TranslationLogger
  • TwitterFeed
  • TwoColumnSortableWidgetManager
  • UpdaterBehavior
  • UpdatesForm
  • UserIdentity
  • UsersChartProfileWidget
  • WorkflowBehavior
  • X2ActiveGridView
  • X2ActiveGridViewForSortableWidgets
  • X2AssetManager
  • X2AuthManager
  • X2ChangeLogBehavior
  • X2ClientScript
  • X2Color
  • X2DateUtil
  • X2FixtureManager
  • X2FlowFormatter
  • X2GridView
  • X2GridViewBase
  • X2GridViewForSortableWidgets
  • X2GridViewSortableWidgetsBehavior
  • X2LeadsGridViewProfileWidget
  • X2LinkableBehavior
  • X2ListView
  • X2PillBox
  • X2ProgressBar
  • X2SmartSearchModelBehavior
  • X2TimestampBehavior
  • X2TranslationBehavior
  • X2UrlRule
  • X2WebModule
  • X2Widget
  • X2WidgetList
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /*****************************************************************************************
  3:  * X2Engine Open Source Edition is a customer relationship management program developed by
  4:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  5:  * 
  6:  * This program is free software; you can redistribute it and/or modify it under
  7:  * the terms of the GNU Affero General Public License version 3 as published by the
  8:  * Free Software Foundation with the addition of the following permission added
  9:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 10:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 11:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 12:  * 
 13:  * This program is distributed in the hope that it will be useful, but WITHOUT
 14:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 15:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 16:  * details.
 17:  * 
 18:  * You should have received a copy of the GNU Affero General Public License along with
 19:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 20:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 21:  * 02110-1301 USA.
 22:  * 
 23:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 24:  * California 95067, USA. or at email address contact@x2engine.com.
 25:  * 
 26:  * The interactive user interfaces in modified source and object code versions
 27:  * of this program must display Appropriate Legal Notices, as required under
 28:  * Section 5 of the GNU Affero General Public License version 3.
 29:  * 
 30:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 31:  * these Appropriate Legal Notices must retain the display of the "Powered by
 32:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 33:  * technical reasons, the Appropriate Legal Notices must display the words
 34:  * "Powered by X2Engine".
 35:  *****************************************************************************************/
 36: 
 37: /**
 38:  *  Class for creating quotes from a contact view.
 39:  *  
 40:  *  This is used for creating, updating, deleting, duplicating
 41:  *  a quote or invoice from the contact view page. It makes heavy use of
 42:  *  javascript and ajax calls to the QuotesController.
 43:  * 
 44:  * @package application.components 
 45:  */
 46: class InlineQuotes extends X2Widget {
 47: 
 48:     public $recordId; // quotes displayed here are related to this record
 49:     private $_contactId; // id of associated contact (optional)
 50:     public $contact;
 51:     public $account = null; // name of associated account (optional)
 52:     public $modelName;
 53: 
 54:     public $errors = array();
 55:     public $startHidden = false;
 56: 
 57:     public function init() {
 58:         $quotesAssetsUrl = $this->module->assetsUrl;
 59:     
 60:         if(isset($_POST))
 61:             $startHidden = false;
 62: 
 63:         if($this->startHidden) {
 64:             if($this->startHidden)
 65:                 Yii::app()->clientScript->registerScript(
 66:                     'startQuotesHidden',"$('#quotes-form').hide();" ,CClientScript::POS_READY);
 67:             
 68:             // Set up the new create form:
 69:             Yii::app()->clientScript->registerScriptFile(
 70:                 $quotesAssetsUrl.'/js/inlineQuotes.js', CClientScript::POS_HEAD);
 71:             Yii::app()->clientScript->registerScriptFile(
 72:                 $quotesAssetsUrl.'/js/LineItems.js', CClientScript::POS_HEAD);
 73: 
 74:             Yii::app()->clientScript->registerCssFiles('InlineQuotesCss', array (
 75:                 $quotesAssetsUrl.'/css/inlineQuotes.css',
 76:                 $quotesAssetsUrl.'/css/lineItemsMain.css',
 77:                 $quotesAssetsUrl.'/css/lineItemsWrite.css',
 78:             ), false);
 79:             Yii::app()->clientScript->registerCoreScript('jquery.ui');
 80: 
 81:             $this->contact = X2Model::model ('Contacts')->findByPk ($this->contactId);
 82: 
 83:             //$this->contact = Contacts::model()->findByPk($this->contactId);
 84:             $iqConfig = array(
 85:                 'contact' => ($this->contact instanceof Contacts) ? 
 86:                     CHtml::encode($this->contact->name) : '',
 87:                 'account' => $this->account,
 88:                 'sendingQuote' => false,
 89:                 'lockedMessage' => Yii::t(
 90:                     'quotes','This quote is locked. Are you sure you want to update this quote?'),
 91:                 'deniedMessage' => Yii::t('quotes','This quote is locked.'),
 92:                 'lockedDialogTitle' => Yii::t('quotes','Locked'),
 93:                 'failMessage' => Yii::t('quotes', 'Could not save quote.'),
 94:                 'reloadAction' => CHtml::normalizeUrl(
 95:                     array(
 96:                         '/quotes/quotes/viewInline',
 97:                         'recordId' => $this->recordId,
 98:                         'recordType' => CHtml::encode($this->modelName),
 99:                     )
100:                 ),
101:                 'createAction' => CHtml::normalizeUrl(
102:                     array(
103:                         '/quotes/quotes/create',
104:                         'quick' => 1,
105:                         'recordId' => $this->recordId,
106:                         'recordType' => $this->modelName,
107:                     )
108:                 ),
109:                 'updateAction' => CHtml::normalizeUrl(
110:                     array(
111:                         '/quotes/quotes/update', 
112:                         'quick' => 1,
113:                     )
114:                 ),
115:             );
116:             Yii::app()->clientScript->registerScript('quickquote-vars', '
117:             ;(function () {
118:                 if(typeof x2 == "undefined"){
119:                     x2 = {};
120:                 }
121:                 var iqConfig = '.CJSON::encode($iqConfig).';
122:                 if(typeof x2.inlineQuotes=="undefined") {
123:                     x2.inlineQuotes = iqConfig;
124:                 } else {
125:                     $.extend(x2.inlineQuotes,iqConfig);
126:                 }
127:             }) ();', CClientScript::POS_HEAD);
128:         }
129:         parent::init();
130:     }
131: 
132:     /**
133:      * Getter and setter for contactId will also update recordId
134:      * in order to remain backwards compatible.
135:      */
136:     public function getContactId() {
137:       return $this->_contactId;  
138:     }
139: 
140:     public function setContactId($value) {
141:         $this->_contactId = $value;
142:         $this->recordId = $value;
143:     }
144: 
145:     /**
146:      * Returns all related invoices or quotes 
147:      * @param bool $invoices
148:      * @return array array of related quotes models
149:      */
150:     public function getRelatedQuotes ($invoices=false) {
151: 
152:         if ($invoices) {
153:             $invoiceCondition = "type='invoice'";
154:         } else {
155:             $invoiceCondition = "type IS NULL OR type!='invoice'";
156:         }
157: 
158:         /*
159:         Select all quotes which have a related record with the current record's id
160:         */
161:         $quotes = Yii::app()->db->createCommand ()
162:             ->select ('quotes.id')
163:             ->from ('x2_quotes as quotes, x2_relationships as relationships')
164:             ->where ("(".$invoiceCondition.") AND ".
165:                 "((relationships.firstType='Quote' AND ".
166:                   "relationships.secondType=:recordType AND relationships.secondId=:recordId) OR ".
167:                 "(relationships.secondType='Quote' AND ".
168:                   "relationships.firstType=:recordType AND relationships.firstId=:recordId)) AND ".
169:                 '((quotes.id=relationships.firstId AND relationships.firstType="Quote") OR '.
170:                  '(quotes.id=relationships.secondId AND relationships.secondType="Quote"))',
171:                  array (
172:                     ':recordId' => $this->recordId,
173:                     ':recordType' => $this->modelName
174:                 ))
175:             ->queryAll ();
176: 
177:         // get models from ids
178:         $getId = function ($a) { return $a['id']; };
179:         $quotes = X2Model::model('Quote')->findAllByPk (array_map ($getId, $quotes));
180: 
181:         return $quotes;
182:     }
183: 
184:     public function run() {
185:         // Permissions that affect the behavior of the widget:
186:         $canDo = array();
187:         foreach(array('QuickDelete','QuickUpdate','QuickCreate') as $subAction) {
188:             $canDo[$subAction] = Yii::app()->user->checkAccess('Quotes'.$subAction);
189:         }
190: 
191:         /*$relationships = Relationships::model()->findAllByAttributes(array(
192:             'firstType'=>'quotes', 
193:             'secondType'=>'contacts', 
194:             'secondId'=>$this->contactId,
195:         ));*/
196:         
197:         echo 
198:             '<div id="quotes-form" style="display: none;">
199:                 <div id="wide-quote-form" class="wide x2-layout-island" 
200:                  style="overflow: visible;">
201:                 <a class="widget-close-button x2-icon-button" href="#">
202:                     <span class="fa fa-times fa-lg" 
203:                      title="'.CHtml::encode (Yii::t('app', 'Close Widget')).'">
204:                     </span>
205:                 </a>
206:                 <div id="quote-create-form-wrapper" style="display:none"></div>
207:                 <span class="quotes-section-title" 
208:                  style="font-weight:bold; font-size: 1.5em;">'. 
209:                     CHtml::encode (Yii::t('quotes','Quotes')) .
210:                 '</span>
211:             <br /><br />';
212: 
213:         // Mini Create Quote Form
214:         $model = new Quote;
215: 
216:         if($canDo['QuickCreate']){
217:             $this->render('createQuote');
218:             echo '<br /><hr />';
219:         }
220: 
221:         $quotes = $this->getRelatedQuotes ();
222:         
223:         foreach($quotes as $quote) {
224:             $this->render('viewQuotes', array(
225:                 'quote'=>$quote,
226:                 'recordId'=>$this->recordId,
227:                 'modelName'=>$this->modelName,
228:                 'canDo' => $canDo
229:             ));
230:         }
231:         
232:         
233:         echo '<br /><br />
234:             <span class="quotes-section-title" 
235:              style="font-weight:bold; font-size: 1.5em;">'. 
236:                 Yii::t('quotes','Invoices').'</span>
237:             <br /><br />';
238:         
239:         $quotes = $this->getRelatedQuotes (true);
240:         
241:         foreach($quotes as $quote) {
242:             $this->render('viewQuotes', array(
243:                 'quote'=>$quote,
244:                 'recordId'=>$this->recordId,
245:                 'modelName'=>$this->modelName,
246:                 'canDo' => $canDo,
247:             ));
248:         }
249: 
250:         
251:         echo "</div>";      
252:         echo "</div>";
253:     }
254: }
255: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0