private function saveAccountOrdertasks($ordertasks, $accountId){ if(!isset($ordertasks)) return; foreach($ordertasks as $ordertask){ $ordertaskId = (!is_null($ordertask->id))?$ordertask->id:0; if($ordertaskId === 0) continue; $dummyorderid = 1; $orderId = (!is_null($ordertask->order->id))?$ordertask->order->id:$dummyorderid; $attributes = array( "account_id" => $accountId, "order_id" => $orderId, "ordertask_id" => $ordertaskId, //"addnlinfo" => $postedData->addnlinfo ); \Accountorder::create($attributes); $tmp = \Ordertask::find($ordertaskId); if(!is_null($tmp)){ $attributes = array( "status" => Menu::sts_closed, "invstatus" => Menu::sts_invoiced ); $tmp->update_attributes($attributes); } } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model=Accountorder::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $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; }