public function actionDeleteAll($id) { $arrIdNew = explode(",", $id); for ($i = 0; $i < count($arrIdNew); $i++) { $model = $this->loadModel($arrIdNew[$i]); // Xóa chi tiết đơn hàng $billDetail = new BillDetail(); $criteria = new CDBCriteria(); $criteria->addCondition("bill_id = " . $arrIdNew[$i]); $billDetail->deleteAll($criteria); // Xóa đơn hàng $model->delete(); } Yii::app()->user->setFlash('success', translate('Xóa thành công.')); $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); }
public function actionIndex($id = null) { $model = new BillDetail('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['BillDetail'])) { $model->attributes = $_GET['BillDetail']; } $result = null; if ($id != null) { $criteria = new CDBCriteria(); $criteria->select = 'number, price'; $criteria->addCondition("bill_id = " . $id); $data = BillDetail::model()->findAll($criteria); $result = 0; foreach ($data as $dt) { $result += $dt->number * $dt->price; } } $this->render('index', array('model' => $model, 'id' => $id, 'total' => $result)); }
public function details() { return $this->hasMany(BillDetail::getClass()); }