Example #1
0
 public function init()
 {
     if (isset($_POST)) {
         $startHidden = false;
     }
     if ($this->startHidden) {
         // register css
         Yii::app()->clientScript->registerCssFile(Yii::app()->theme->getBaseUrl() . '/css/inlinequotes.css');
         // register (lots of) javascript
         Yii::app()->clientScript->registerScript('toggleQuotes', ($this->startHidden ? "\$(document).ready(function() { \$('#quotes-form').hide();\n\t\t\t });\n" : '') . "function toggleQuotes() {\n\t\t\t\t\n\t\t\t\tif(\$('#quotes-form').is(':hidden')) {\n\t\t\t\t\t\$('.focus-mini-module').removeClass('focus-mini-module');\n\t\t\t\t\t\$('#quotes-form').find('.wide.form').addClass('focus-mini-module');\n\t\t\t\t\t\$('html,body').animate({\n\t\t\t\t\t\tscrollTop: (\$('#action-form').offset().top - 200)\n\t\t\t\t\t}, 300);\n\t\t\t\t}\n\t\t\t\t\$('#quotes-form').toggle('blind',300,function() {\n\t\t\t\t\t\$('#quotes-form').focus();\n\t\t\t\t});\n\t\t\t}\n\t\t\t\n\t\t\t\$(function() {\n\t\t\t\t\$('#quotes-form').click(function() {\n\t\t\t\t\tif(sendingQuote) {\n\t\t\t\t\t\tsendingQuote = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif(!\$('#quotes-form').find('.wide.form').hasClass('focus-mini-module')) {\n\t\t\t\t\t\t\t\$('.focus-mini-module').removeClass('focus-mini-module');\n\t\t\t\t\t\t\t\$('#quotes-form').find('.wide.form').addClass('focus-mini-module');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t});\n\t\t\t});\n\t\t\t", CClientScript::POS_HEAD);
         Yii::app()->clientScript->registerScript('emailQuote', "\n\t\tfunction appendEmail(line) {\n\t\t\tvar email = \$('#email-message');\n\t\t\temail.val(email.val() + line + " . '""' . ");\n\t\t}\n\t\t\n\t\tvar sendingQuote = false;\n\t\tfunction sendQuoteEmail(quote) {\n\t\t\tvar notes = " . '"\\n"' . " + quote['notes']['label'] + " . '"\\n"' . " + quote['notes']['notes'] + " . '"\\n"' . ";\n\t\t\ttoggleEmailForm();\n\t\t\tteditor.e.body.innerHTML = '' + quote['name'] + quote['products'] + notes;\n\t\t\tvar value = \$('#email-template option:contains(\"Quote\")').val();\n\t\t\t\$('#email-template').val(value);\n\t\t\t\$('#InlineEmail_subject').val('Quote');\n\t\t\t\$('#email-template').change();\n\t\t    sendingQuote = true; // stop quote mini-module from stealing focus away from email\n\t\t}\n\t\t", CClientScript::POS_HEAD);
         $products = Product::model()->findAll(array('select' => 'id, name, price'));
         $jsProductList = "\$(productList).append(\$('<option>', {value: 0}).append(''));\n";
         $jsProductPrices = "var prices = [];\n";
         $jsProductPrices .= "prices[0] = 0;\n";
         foreach ($products as $product) {
             $jsProductList .= "\$(productList).append(\$('<option>', {value: {$product->id}}).append('{$product->name}'));\n";
             $jsProductPrices .= "prices[{$product->id}] = {$product->price};\n";
         }
         $productNames = Product::productNames();
         $jsonProductList = json_encode($productNames);
         $region = Yii::app()->getLocale()->getId();
         Yii::app()->clientScript->registerScript('productTable', "\n\n// translate ISO 4217 currency into i18n\nvar currencyTable = {\n\t'USD': 'en-US',\n\t'EUR': 'hsb-DE',\n\t'GBP': 'en-GB',\n\t'CAD': 'en-CA',\n\t'JPY': 'ja-JP',\n\t'CNY': 'zh-CN',\n\t'CHF': 'de-CH',\n\t'INR': 'hi-IN',\n\t'BRL': 'pt-BR',\n};\n\nfunction removeProduct(object) {\n\t\$(object).closest('tr').remove();\n\tupdateProductTotal();\n}\n\nfunction updateProduct(id, price, quantity, adjustments, label, currency) {\n\tprice = parseFloat(price);\n\tquantity = parseFloat(quantity);\n\tvar total = price * quantity;\n\tvar index = adjustments.indexOf('%');\n\tif(index == -1) { // adjustment\n\t    total += parseFloat(adjustments);\n\t} else { // percent adjustment\n\t    adjustments = adjustments.substring(0, index);\n\t    adjustments = parseFloat(adjustments) / 100;\n\t    total += total * adjustments;\n\t}\n\t\$(label).html('' + total);\n\t\$(label).formatCurrency({'region': currencyTable[currency]});\n\tupdateProductTotal(id, currency);\n}\n\nfunction updateProductTotal(id, currency) {\n\tvar total = 0;\n\t\$('#product-table-' + id + ' .product-list-price').each(function () {\n\t\t\$(this).toNumber({'region': currencyTable[currency]});\n\t    total += parseFloat(\$(this).html());\n\t    \$(this).formatCurrency({'region': currencyTable[currency]});\n\t});\n\t\$('#product-list-total-' + id).html('' + total);\n\t\$('#product-list-total-' + id).formatCurrency({'region': currencyTable[currency]});\n}\n\n\n\nfunction addProduct(id, currency, productNames, prices) {\n\tvar row = \$('<tr></tr>');\n\t\$('#product-table-' + id + ' tbody').append(row);\n\n\tvar td = \$('<td></td>');\n\tvar tdRemove = \$('<td></td>', {\n\t\t'style': 'padding: 0;'\n\t});\n\t\n\tvar remove = \$('<a>', {\n\t\thref: 'javascript:void(0)',\n\t\t'onClick': 'removeProduct(this);'\n\t});\n\tvar removeImage = \$('<img>', {\n\t\tsrc: '" . Yii::app()->request->baseUrl . '/themes/x2engine/css/gridview/delete.png' . "',\n\t\talt: '[" . Yii::t('quotes', 'Delete Quote') . "]'\n\t});\n\t\$(row).append(tdRemove.clone().append(remove));\n\t\$(remove).append(removeImage);\n\t\n\tvar productList = \$('<select>', {\n\t\tname: 'ExistingProducts[id][]'\n\t});\n\t\$(row).append(td.clone().append(productList));\n\tfor(var i in productNames) {\n\t\t\$(productList).append(\$('<option>', {value: i}).append(productNames[i]));\n\t}\n\t\n\tvar price = \$('<input>', {\n\t\ttype: 'text',\n\t\tsize: 10,\n\t\t'onFocus': 'toggleText(this);',\n\t\t'onBlur': 'toggleText(this);',\n\t\t'style': 'color:#aaa;',\n\t\tname: 'ExistingProducts[price][]',\n\t\tvalue: 0\n\t});\n\t\$(row).append(td.clone().append(price));\n\t\n\tvar quantity = \$('<input>', {\n\t\ttype: 'text',\n\t\tsize: 10,\n\t\t'onFocus': 'toggleText(this);',\n\t\t'onBlur': 'toggleText(this);',\n\t\t'style': 'color:#aaa;',\n\t\tname: 'ExistingProducts[quantity][]',\n\t\tvalue: 0\n\t});\n\t\$(row).append(td.clone().append(quantity));\n\t\n\tvar adjustments = \$('<input>', {\n\t\ttype: 'text',\n\t\tsize: 10,\n\t\t'onFocus': 'toggleText(this);',\n\t\t'onBlur': 'toggleText(this);',\n\t\t'style': 'color:#aaa;',\n\t\tname: 'ExistingProducts[adjustment][]',\n\t\tvalue: 0\n\t});\n\t\$(row).append(td.clone().append(adjustments));\n\t\n\tvar label = \$('<label>', {\n\t\t'class': 'product-list-price',\n\t\t'style': 'width: auto;',\n\t});\n\t\$(row).append(td.clone().append(label));\n\t\$(label).append('0');\n\t\n\t\$(productList).change(function() {\n\t\t\$(price).val('' + prices[\$(this).attr('value')]);\n\t\t\$(price).css('color', 'black');\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n\t\n\t\$('#update-quote-button-' + id).css('background', 'yellow');\n\t\n\t\$(price).change(function() {\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n\t\n\t\$(quantity).change(function() {\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n\t\n\t\$(adjustments).change(function() {\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n} \n\n\nfunction addFilledProduct(id, fillId, fillPrice, fillQuantity, fillAdjustment, currency, productNames, prices) {\n\tvar row = \$('<tr></tr>');\n\t\$('#product-table-' + id + ' tbody').append(row);\n\n\tvar td = \$('<td></td>');\n\tvar tdRemove = \$('<td></td>', {\n\t\t'style': 'padding: 0;'\n\t});\n\t\n\tvar remove = \$('<a>', {\n\t\thref: 'javascript:void(0)',\n\t\t'onClick': 'removeProduct(this);'\n\t});\n\tvar removeImage = \$('<img>', {\n\t\tsrc: '" . Yii::app()->request->baseUrl . '/themes/x2engine/css/gridview/delete.png' . "',\n\t\talt: '[" . Yii::t('quotes', 'Delete Quote') . "]'\n\t});\n\t\$(row).append(tdRemove.clone().append(remove));\n\t\$(remove).append(removeImage);\n\t\n\tvar productList = \$('<select>', {\n\t\tname: 'ExistingProducts[id][]',\n\t});\n\t\$(row).append(td.clone().append(productList));\n\tfor(var i in productNames) {\n\t\t\$(productList).append(\$('<option>', {value: i}).append(productNames[i]));\n\t}\n\t\$(productList).val(fillId);\n\t\n\tvar price = \$('<input>', {\n\t\ttype: 'text',\n\t\tsize: 10,\n\t\t'onFocus': 'toggleText(this);',\n\t\t'onBlur': 'toggleText(this);',\n\t\tname: 'ExistingProducts[price][]',\n\t\tvalue: 0,\n\t\tdefaultValue: 0,\n\t});\n\t\$(row).append(td.clone().append(price));\n\t\$(price).val(fillPrice);\n\t\n\tvar quantity = \$('<input>', {\n\t\ttype: 'text',\n\t\tsize: 10,\n\t\t'onFocus': 'toggleText(this);',\n\t\t'onBlur': 'toggleText(this);',\n\t\tname: 'ExistingProducts[quantity][]',\n\t\tvalue: 0,\n\t\tdefaultValue: 0,\n\t});\n\t\$(row).append(td.clone().append(quantity));\n\t\$(quantity).val(fillQuantity);\n\t\n\tvar adjustments = \$('<input>', {\n\t\ttype: 'text',\n\t\tsize: 10,\n\t\t'onFocus': 'toggleText(this);',\n\t\t'onBlur': 'toggleText(this);',\n\t\tname: 'ExistingProducts[adjustment][]',\n\t\tvalue: 0,\n\t\tdefaultValue: 0,\n\t});\n\t\$(row).append(td.clone().append(adjustments));\n\t\$(adjustments).val(fillAdjustment);\n\t\n\tvar label = \$('<label>', {\n\t\t'class': 'product-list-price',\n\t\t'style': 'width: auto;',\n\t});\n\t\$(row).append(td.clone().append(label));\n\t\$(label).append('0');\n\t\n\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\n\t\$(productList).change(function() {\n\t\t\$(price).val('' + prices[\$(this).attr('value')]);\n\t\t\$(price).css('color', 'black');\n\t\t\$('#update-quote-button-' + id).css('background', 'yellow');\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n\t\n\t\$(price).change(function() {\n\t\t\$('#update-quote-button-' + id).css('background', 'yellow');\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n\t\n\t\$(quantity).change(function() {\n\t\t\$('#update-quote-button-' + id).css('background', 'yellow');\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n\t\n\t\$(adjustments).change(function() {\n\t\t\$('#update-quote-button-' + id).css('background', 'yellow');\n\t\tupdateProduct(id, \$(price).val(), \$(quantity).val(), \$(adjustments).val(), label, currency);\n\t});\n}\n\nfunction toggleUpdateQuote(id, locked, strict) {\n\tvar confirmBox = \$('<div></div>')\n\t\t.html('This quote is locked. Are you sure you want to update this quote?')\n\t\t.dialog({\n\t\t\ttitle: 'Locked', \n\t\t\tautoOpen: false,\n\t\t\tresizable: false,\n\t\t\tbuttons: {\n\t\t\t\t'Yes': function() {\n\t\t\t\t\t\$('#quote-detail-' + id).hide('blind', 'slow');\n\t\t\t\t\t\$('#quote-update-' + id).show('slow');\n\t\t\t\t\t\$(this).dialog('close');\n\t\t\t\t},\n\t\t\t\t'No': function() {\n\t\t\t\t\t\$(this).dialog('close');\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\n\tvar denyBox = \$('<div></div>')\n\t\t.html('This quote is locked.')\n\t\t.dialog({\n\t\t\ttitle: 'Locked', \n\t\t\tautoOpen: false,\n\t\t\tresizable: false,\n\t\t\tbuttons: {\n\t\t\t\t'OK': function() {\n\t\t\t\t\t\$(this).dialog('close');\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\t\n\tif(locked)\n\t\tif(strict)\n\t\t\tdenyBox.dialog('open');\n\t\telse\n\t\t\tconfirmBox.dialog('open');\n\telse {\n\t\t\$('#quote-detail-' + id).hide('blind', 'slow');\n\t\t\$('#quote-update-' + id).show('slow');\n\t}\n}\n\nfunction toggleNewQuote() {\n\t\$('#show-new-quote-button').hide('blind', 'slow');\n\t\$('#new-quote').show('slow');\n}\n\nfunction duplicateQuote(quote) {\n\t\$('#new-quote [name=\"Quote[status]\"]').val(quote['status']);\n\t\$('#new-quote [name=\"Quote[expirationDate]\"]').val(quote['expirationDate']);\n\t\n\t\$('#product-table-create tbody tr').remove();\n\tfor(var i in quote['products']) {\n\t\taddFilledProduct('create', quote['products'][i]['id'], quote['products'][i]['price'], quote['products'][i]['quantity'], '' + quote['products'][i]['adjustment'], quote['currency'], quote['productNames'], quote['prices']);\n\t}\n\t\n\t\$('#new-quote').show('slow');\n}\n\n", CClientScript::POS_HEAD);
     }
     parent::init();
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Quote();
     $users = User::getNames();
     $currency = Yii::app()->params->currency;
     $productNames = Product::productNames();
     $productCurrency = Product::productCurrency();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Quote'])) {
         /*
                             foreach($_POST as $key=>$arr){
                                     $pieces=explode("_",$key);
                                     if(isset($pieces[0]) && $pieces[0]=='autoselect'){
                                         $newKey=$pieces[1];
                                         if(isset($_POST[$newKey."_id"]) && $_POST[$newKey."_id"]!=""){
                                             $val=$_POST[$newKey."_id"];
                                         }else{
                                             $field=Fields::model()->findByAttributes(array('fieldName'=>$newKey));
                                             if(isset($field)){
                                                 $type=ucfirst($field->linkType);
                                                 if($type!="Contacts"){
                                                     eval("\$lookupModel=$type::model()->findByAttributes(array('name'=>'$arr'));");
                                                 }else{
                                                     $names=explode(" ",$arr);
                                                     $lookupModel=Contacts::model()->findByAttributes(array('firstName'=>$names[0],'lastName'=>$names[1]));
                                                 }
                                                 if(isset($lookupModel))
                                                     $val=$lookupModel->id;
                                                 else
                                                     $val=$arr;
                                             }
                                         }
                                         $model->$newKey=$val;
                                     }
                                 }
         //			$this->render('test', array('model'=>$_POST));
                     $temp=$model->attributes;
         foreach(array_keys($model->attributes) as $field){
                                     if(isset($_POST['Quote'][$field])){
                                         $model->$field=$_POST['Quote'][$field];
                                         $fieldData=Fields::model()->findByAttributes(array('modelName'=>'Quotes','fieldName'=>$field));
                                         if($fieldData->type=='assignment' && $fieldData->linkType=='multiple'){
                                             $model->$field=Accounts::parseUsers($model->$field);
                                         }elseif($fieldData->type=='date'){
                                             $model->$field=strtotime($model->$field);
                                         }
                                         
                                     }
                                 }
                 	
         			$model->expirationDate = $this->parseDate($model->expirationDate);
         */
         /*
         if(isset($model->associatedContacts)) {
         	$contacts = $model->associatedContacts;
         	$model->associatedContacts = Quote::parseContacts($model->associatedContacts);
         } else {
         	$contacts = array();
         }
         */
         $temp = $model->attributes;
         $model->setX2Fields($_POST['Quote']);
         // get products
         $products = array();
         if (isset($_POST['ExistingProducts'])) {
             $ids = $_POST['ExistingProducts']['id'];
             $prices = $_POST['ExistingProducts']['price'];
             $quantities = $_POST['ExistingProducts']['quantity'];
             $adjustments = $_POST['ExistingProducts']['adjustment'];
             foreach ($ids as $key => $id) {
                 if ($id != 0) {
                     // remove blanks
                     $products[$key]['id'] = $id;
                     $products[$key]['name'] = $productNames[$id];
                     $products[$key]['price'] = $prices[$key];
                     $products[$key]['quantity'] = $quantities[$key];
                     if (strchr($adjustments[$key], '%')) {
                         // percent adjustment
                         $products[$key]['adjustment'] = intval(str_replace("%", "", $adjustments[$key]));
                         $products[$key]['adjustmentType'] = 'percent';
                     } else {
                         $products[$key]['adjustment'] = $adjustments[$key];
                         $products[$key]['adjustmentType'] = 'linear';
                     }
                 }
             }
             if (!empty($products)) {
                 $currency = $productCurrency[$products[0]['id']];
             }
         }
         $model->currency = $currency;
         $this->createQuote($model, $temp, $products);
     }
     $products = Product::activeProducts();
     $this->render('create', array('model' => $model, 'users' => $users, 'products' => $products, 'productNames' => $productNames));
 }
Example #3
0
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 ********************************************************************************/
?>

<?php 
$productNames = json_encode((object) Product::productNames());
$prices = json_encode((object) Product::productPrices());
$defaultCurrency = Yii::app()->params['currency'];
Yii::app()->clientScript->registerScript("productTableQuoteCreate", "\n\$(function() {\n\taddProduct('create', '{$defaultCurrency}', {$productNames}, {$prices});\n\t\$('#new-quote').hide();\n   \t/*\n\t\$('#create-quote-button').click(function() {\n\t\t" . CHtml::ajax(array('update' => '#history-list-wrapper', 'url' => Yii::app()->createUrl('contacts/quickUpdateHistory', array('id' => $contactId)))) . "\n\t}); */\n});\n", CClientScript::POS_END);
$form = $this->beginWidget('CActiveForm', array('id' => 'quote-form-inside', 'enableAjaxValidation' => false));
// Get Quotes field 'name'
$nameField = Fields::model()->findByAttributes(array('modelName' => 'Quotes', 'fieldName' => 'name'));
$expirationField = Fields::model()->findByAttributes(array('modelName' => 'Quotes', 'fieldName' => 'expirationDate'));
$existingProductsField = Fields::model()->findByAttributes(array('modelName' => 'Quotes', 'fieldName' => 'existingProducts'));
?>

<?php 
echo CHtml::button(Yii::t('quotess', 'New Quote'), array('id' => 'show-new-quote-button', 'onclick' => 'toggleNewQuote();', 'class' => 'x2-button'));
?>

<div id="new-quote">