* 02110-1301 USA. * * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley, * California 95067, USA. or at email address contact@x2engine.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * X2Engine" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by X2Engine". *****************************************************************************************/ $submitButton = isset($submitButton) ? $submitButton : true; $htmlOptions = !isset($htmlOptions) ? array() : $htmlOptions; $form = $this->beginWidget('ProductsActiveForm', array('formModel' => $model, 'htmlOptions' => $htmlOptions)); echo $form->textArea($model, 'actionDescription'); $dummyQuote = new Quote(); if (is_array($model->lineitem)) { $dummyQuote->setLineItems($model->lineitem); } Yii::app()->controller->renderPartial('application.modules.quotes.views.quotes._lineItems', array('model' => $dummyQuote, 'readOnly' => false, 'module' => Yii::app()->getModule('quotes'), 'products' => Product::activeProducts(), 'namespacePrefix' => $form->namespace, 'saveButtonId' => 'save-publisher', 'modelName' => get_class($model), 'mini' => true)); echo $form->hiddenField($model, 'associationType'); echo $form->hiddenField($model, 'associationId'); echo $form->hiddenField($model, 'assignedTo'); if ($submitButton) { echo $form->submitButton(); } $this->endWidget();
/** * Creates a new model. * * If creation is successful, the browser will be redirected to the 'view' page. * * @param bool $quick If true, this indicates the action is being requested via AJAX */ public function actionCreate($quick = false, $duplicate = false) { $model = new Quote(); if ($duplicate && !isset($_POST['Quote'])) { $copiedModel = Quote::model()->findByPk($duplicate); if (!empty($copiedModel)) { foreach ($copiedModel->attributes as $name => $value) { if ($name != 'id') { $model->{$name} = $value; } } $model->setLineItems($this->duplicateLineItems($copiedModel), false, true); } } $users = User::getNames(); if ($quick && !Yii::app()->request->isAjaxRequest) { throw new CHttpException(400); } $currency = Yii::app()->params->currency; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Quote'])) { $model->setX2Fields($_POST['Quote']); $model->currency = $currency; $model->createDate = time(); $model->lastUpdated = $model->createDate; $model->createdBy = Yii::app()->user->name; $model->updatedBy = $model->createdBy; if (empty($model->name)) { $model->name = ''; } if (isset($_POST['lineitem'])) { $model->lineItems = $_POST['lineitem']; } if (!$model->hasLineItemErrors) { if ($model->save()) { $model->createEventRecord(); $model->createActionRecord(); $model->saveLineItems(); if (!$quick) { $this->redirect(array('view', 'id' => $model->id)); } else { if (isset($_GET['recordId']) && isset($_GET['recordType'])) { $recordId = $_GET['recordId']; $recordType = $_GET['recordType']; $relatedModel = X2Model::model($_GET['recordType'])->findByPk($recordId); // tie record to quote if ($relatedModel) { $relate = new Relationships(); $relate->firstId = $model->id; $relate->firstType = "Quote"; $relate->secondId = $relatedModel->id; $relate->secondType = $recordType; $relate->save(); $model->createAssociatedAction(X2Model::getAssociationType(get_class($relatedModel)), $relatedModel->id); } } return; } } } } // get products $products = Product::activeProducts(); $viewData = array('model' => $model, 'users' => $users, 'products' => $products, 'quick' => $quick); if (!$quick) { $this->render('create', $viewData); } else { if ($model->hasErrors() || $model->hasLineItemErrors) { // Sneak into the response that validation failed via setting // the response code manually: header('HTTP/1.1 400 Validation Error'); } $this->renderPartial('create', $viewData, false, true); } }
/** * 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)); }