public function actionDrawcashSetup() { $this->checkLogin(); if (!empty($_POST)) { if (!empty($_POST['draw_price'])) { $drawCash = new DrawCash(); $drawCash->draw_price = Util::input($_POST['draw_price']); $drawCash->draw_date = new CDbExpression("NOW()"); if ($drawCash->save()) { $this->redirect(array("DrawcashSetup")); } } } $drawCashs = new CActiveDataProvider('DrawCash', array('criteria' => array("order" => "id DESC", "limit" => 30))); $this->render("//Config/Drawcash", array('drawCashs' => $drawCashs)); }
function actionSalePerDay() { $params = array(); // checked $checked_cash = 'checked="checked"'; $checked_credit = 'checked="checked"'; $checked_bonus_no = 'checked="checked"'; $checked_bonus_yes = 'checked="checked"'; // default date $date_end = date("d/m/Y"); $branch_id = null; if (!empty($_POST)) { // data $sale_condition_cash = Util::input($_POST['sale_condition_cash']); $sale_condition_credit = Util::input($_POST['sale_condition_credit']); $has_bonus_yes = ""; if (!empty($_POST['has_bonus_yes'])) { $has_bonus_yes = Util::input($_POST['has_bonus_yes']); } $has_bonus_no = ""; if (!empty($_POST['has_bonus_no'])) { $has_bonus_no = Util::input($_POST['has_bonus_no']); } $branch_id = Util::input($_POST['branch_id']); // checked if (!empty($sale_condition_cash)) { $checked_cash = 'checked="checked"'; } else { $checked_cash = ''; } if (!empty($sale_condition_credit)) { $checked_credit = 'checked="checked"'; } else { $checked_credit = ''; } if (!empty($has_bonus_yes)) { $checked_bonus_yes = 'checked="checked"'; } else { $checked_bonus_yes = ''; } if (!empty($has_bonus_no)) { $checked_bonus_no = 'checked="checked"'; } else { $checked_bonus_no = ''; } // SQL Condition if (!empty($sale_condition_cash)) { $condition_sale = "AND bill_sale_status = 'pay'"; } if (!empty($sale_condition_credit)) { $condition_sale = "AND bill_sale_status = 'credit'"; } if (!empty($sale_condition_cash) && !empty($sale_condition_credit)) { $condition_sale = "AND bill_sale_status IN('credit', 'pay')"; } if (!empty($has_bonus_no)) { $condition_has_bonus = "AND bill_sale_detail_has_bonus = 'no'"; } if (!empty($has_bonus_yes)) { $condition_has_bonus = "AND bill_sale_detail_has_bonus = 'yes'"; } if (!empty($has_bonus_no) && !empty($has_bonus_yes)) { $condition_has_bonus = "AND bill_sale_detail_has_bonus IS NOT NULL"; } // Date $date_find = $_POST['date_find']; $date_end_sql = $_POST['date_end']; $date_end = $_POST['date_end']; $date = explode('/', $date_find); $y = (int) $date[2]; $m = (int) $date[1]; $d = (int) $date[0]; $date_end_arr = explode("/", $date_end_sql); $y_end = (int) $date_end_arr[2]; $m_end = (int) $date_end_arr[1]; $d_end = (int) $date_end_arr[0]; // SQL Command $sql = "\n SELECT * FROM tb_bill_sale_detail\n LEFT JOIN tb_bill_sale ON tb_bill_sale.bill_sale_id = tb_bill_sale_detail.bill_id\n LEFT JOIN tb_product ON tb_product.product_code = tb_bill_sale_detail.bill_sale_detail_barcode\n WHERE\n bill_sale_detail_barcode != ''\n AND\n (\n YEAR(tb_bill_sale.bill_sale_created_date) >= {$y}\n AND MONTH(bill_sale_created_date) >= {$m}\n AND DAY(bill_sale_created_date) >= {$d}\n )\n AND \n (\n YEAR(bill_sale_created_date) <= {$y_end}\n AND MONTH(bill_sale_created_date) <= {$m_end}\n AND DAY(bill_sale_created_date) <= {$d_end}\n )\n {$condition_sale}\n {$condition_has_bonus}\n AND tb_bill_sale.branch_id = {$branch_id}\n ORDER BY tb_bill_sale_detail.bill_id ASC\n "; // query all $result = Yii::app()->db->createCommand($sql)->queryAll(); $params['date'] = $date_find; $params['result'] = $result; // save result to session $session = new CHttpSession(); $session->open(); $session['result'] = $result; $session['date_find'] = $date_find; $session['sale_condition_cash'] = $sale_condition_cash; $session['sale_condition_credit'] = $sale_condition_credit; $session['has_bonus_no'] = $has_bonus_no; $session['has_bonus_yes'] = $has_bonus_yes; $session['branch_id'] = $branch_id; } $params['checked_cash'] = $checked_cash; $params['checked_credit'] = $checked_credit; $params['checked_bonus_yes'] = $checked_bonus_yes; $params['checked_bonus_no'] = $checked_bonus_no; $params['branch_id'] = $branch_id; $params['date_end'] = $date_end; $drawcash = DrawCash::model()->find(array('condition' => ' YEAR(draw_date) = YEAR(NOW()) AND MONTH(draw_date) = MONTH(NOW()) AND DAY(draw_date) = DAY(NOW()) ')); $params['drawcash'] = $drawcash; $this->render('//Report/ReportSalePerDay', $params); }