/** * 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; }