/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Accountorder; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Accountorder'])) { $model->attributes=$_POST['Accountorder']; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('create',array( 'model'=>$model, )); }
private function saveOrUpdateAccountOrdertasks($account) { $condition = 'account_id=' . $account->id; $condition .= ' AND ordertask_id>0'; $criteria = new CDbCriteria; $criteria->condition = $condition; $result = Accountorder::model()->findAll($criteria); $foundOrdertasks = array(); foreach($result as $record) { $found = null; foreach($account->ordertasks as $ordertask) { if($record->ordertask_id === $ordertask->id) { $found = $ordertask; break; } } if(empty($found)) { $prvordertaskid = $record->ordertask_id; $rtn = $record->delete(); if(!$rtn) return $rtn; $prvordertask = Ordertask::model()->findByPk($prvordertaskid); if(!empty($prvordertask)) { $prvordertask->invstatus = Helper::CONST_INVSTS_UNINVOICED; $rtn = $prvordertask->save(false); if(!$rtn) return $rtn; } } else { $foundOrdertasks[$found->id] = $found; } } foreach($account->ordertasks as $ordertask) { if( !in_array($ordertask->id, array_keys($foundOrdertasks)) ) { $accountorder = new Accountorder; $accountorder->account_id = $account->id; $accountorder->order_id = $ordertask->order->id; $accountorder->ordertask_id = $ordertask->id; $rtn = $accountorder->save(); if(!$rtn) return $rtn; $ordertask->invstatus = Helper::CONST_INVSTS_INVOICED; $rtn = $ordertask->save(false); if(!$rtn) return $rtn; } } return true; }