PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/mcmis/protected/controllers/PtbhadarateController.php

http://mcmis.googlecode.com/
PHP | 347 lines | 243 code | 40 blank | 64 comment | 28 complexity | c1f5c749b37af0292639428363508f36 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class PtbhadarateController extends Controller {
  3. /**
  4. * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
  5. * using two-column layout. See 'protected/views/layouts/column2.php'.
  6. */
  7. // public $layout='//layouts/column2';
  8. public $layout = '//layouts/eastsouthwest';
  9. /**
  10. * @return array action filters
  11. */
  12. public function filters() {
  13. return array(
  14. 'accessControl', // perform access control for CRUD operations
  15. );
  16. }
  17. /**
  18. * Specifies the access control rules.
  19. * This method is used by the 'accessControl' filter.
  20. * @return array access control rules
  21. */
  22. public function accessRules() {
  23. return array(
  24. array('allow', // allow all users to perform 'index' and 'view' actions
  25. 'actions' => array('index', 'view', 'jsonmessage'),
  26. 'users' => array('*'),
  27. ),
  28. array('allow', // allow authenticated user to perform 'create' and 'update' actions
  29. 'actions' => array('create', 'update', 'gridupdate', 'generate'),
  30. 'users' => array('@'),
  31. ),
  32. array('allow', // allow admin user to perform 'admin' and 'delete' actions
  33. 'actions' => array('popupview', 'admin', 'delete'),
  34. 'users' => array('admin'),
  35. ),
  36. array('deny', // deny all users
  37. 'users' => array('*'),
  38. ),
  39. );
  40. }
  41. /**
  42. * Displays a particular model.
  43. * @param integer $id the ID of the model to be displayed
  44. */
  45. public function actionView($id) {
  46. $this->render('view', array(
  47. 'model' => $this->loadModel($id),
  48. ));
  49. }
  50. /**
  51. * Creates a new model.
  52. * If creation is successful, the browser will be redirected to the 'view' page.
  53. */
  54. public function actionCreate() {
  55. $model = new Ptbhadarate;
  56. // Uncomment the following line if AJAX validation is needed
  57. $this->performAjaxValidation($model);
  58. if (isset($_POST['Ptbhadarate'])) {
  59. $model->attributes = $_POST['Ptbhadarate'];
  60. if ($model->save())
  61. $this->redirect(array('create', 'id' => $model->idptbhadarate));
  62. // $this->redirect(array('view','id'=>$model->idptbhadarate));
  63. }
  64. $this->render('create', array(
  65. 'model' => $model,
  66. ));
  67. }
  68. /**
  69. * Updates a particular model.
  70. * If update is successful, the browser will be redirected to the 'view' page.
  71. * @param integer $id the ID of the model to be updated
  72. */
  73. public function actionUpdate($id) {
  74. $model = $this->loadModel($id);
  75. // Uncomment the following line if AJAX validation is needed
  76. $this->performAjaxValidation($model);
  77. if (isset($_POST['Ptbhadarate'])) {
  78. $model->attributes = $_POST['Ptbhadarate'];
  79. if ($model->save())
  80. $this->redirect(array('admin'));
  81. // $this->redirect(array('view','id'=>$model->idptbhadarate));
  82. }
  83. $this->render('update', array(
  84. 'model' => $model,
  85. ));
  86. }
  87. /**
  88. * Deletes a particular model.
  89. * If deletion is successful, the browser will be redirected to the 'admin' page.
  90. * @param integer $id the ID of the model to be deleted
  91. */
  92. public function actionDelete($id) {
  93. if (Yii::app()->request->isPostRequest) {
  94. // we only allow deletion via POST request
  95. $this->loadModel($id)->delete();
  96. // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
  97. if (!isset($_GET['ajax']))
  98. $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
  99. }
  100. else
  101. throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
  102. }
  103. /**
  104. * Lists all models.
  105. */
  106. public function actionIndex() {
  107. $dataProvider = new CActiveDataProvider('Ptbhadarate');
  108. $this->render('index', array(
  109. 'dataProvider' => $dataProvider,
  110. ));
  111. }
  112. /**
  113. * Manages all models.
  114. */
  115. public function actionAdmin() {
  116. $model = new Ptbhadarate('search');
  117. $model->unsetAttributes(); // clear any default values
  118. if (isset($_GET['Ptbhadarate']))
  119. $model->attributes = $_GET['Ptbhadarate'];
  120. $this->render('admin', array(
  121. 'model' => $model,
  122. ));
  123. }
  124. /**
  125. * Manages popupview.
  126. */
  127. public function actionPopupview() {
  128. $model = new Ptbhadarate('search');
  129. $model->unsetAttributes(); // clear any default values
  130. if (isset($_GET['Ptbhadarate']))
  131. $model->attributes = $_GET['Ptbhadarate'];
  132. if (isset($_REQUEST['isAjaxRequest']) && $_REQUEST['isAjaxRequest'] == '1') {
  133. Yii::app()->clientscript->scriptMap['jquery.js'] = false;
  134. echo CJSON::encode(array(
  135. 'status' => 'failure',
  136. 'div' => $this->renderPartial('popupview', array('model' => $model, 'id' => $_REQUEST['id']), true, true)));
  137. exit;
  138. }
  139. $this->render('popupview', array(
  140. 'model' => $model, 'id' => ''
  141. ));
  142. }
  143. /**
  144. * Returns the data model based on the primary key given in the GET variable.
  145. * If the data model is not found, an HTTP exception will be raised.
  146. * @param integer the ID of the model to be loaded
  147. */
  148. public function loadModel($id) {
  149. $model = Ptbhadarate::model()->findByPk((int) $id);
  150. if ($model === null)
  151. throw new CHttpException(404, 'The requested page does not exist.');
  152. return $model;
  153. }
  154. /**
  155. * Performs the AJAX validation.
  156. * @param CModel the model to be validated
  157. */
  158. protected function performAjaxValidation($model) {
  159. if (isset($_POST['ajax']) && $_POST['ajax'] === 'ptbhadarate-form') {
  160. echo CActiveForm::validate($model);
  161. Yii::app()->end();
  162. }
  163. }
  164. public function actionJsonmessage() {
  165. $jsonmessage = array();
  166. $jsonmessage['status code'] = 200;
  167. $jsonmessage['message'] = ' - ';
  168. if (isset($_REQUEST['cid'])) {
  169. $model = Ptbhadarate::model()->findByPk($_REQUEST['cid']);
  170. if ($model) {
  171. $jsonmessage['message'] = $model->aresidential;
  172. }
  173. }
  174. header('Content-type: application/json');
  175. echo CJSON::encode($jsonmessage);
  176. Yii::app()->end();
  177. }
  178. public function actionGridupdate() {
  179. $ptbhadarates = array();
  180. $ptbhadarates = $_POST['Ptbhadarate'];
  181. $valid = true;
  182. $errors = array();
  183. foreach ($ptbhadarates as $key => $value) {
  184. $model = $this->loadModel($key);
  185. $model->attributes = $value;
  186. // if(!$model->validate(NULL, false)){
  187. if (!$model->save()) {
  188. $valid = false;
  189. $model_errors = $model->getErrors();
  190. foreach ($model_errors as $mekey => $mevalue) {
  191. foreach ($mevalue as $key => $value) {
  192. $errors[$model->idptbhadarate . '_' . $mekey] = $value . " (" . $model->idccward0->idcczone0->zonename . " - " . $model->idccward0->wardname . ")";
  193. }
  194. }
  195. }
  196. }
  197. $model_new = new Ptbhadarate('search');
  198. $model_new->unsetAttributes(); // clear any default values
  199. if (isset($_GET['Ptbhadarate']))
  200. $model->attributes = $_POST['Ptbhadarate'];
  201. $model_new->addErrors($errors);
  202. $this->render('admin', array(
  203. 'model' => $model_new,
  204. ));
  205. }
  206. public function actionGridupdate_original() {
  207. //update aresidential column
  208. $rates = $_REQUEST['aresidential'];
  209. foreach ($rates as $key => $value) {
  210. $sql = "Update {{ptbhadarate}} set aresidential=$value WHERE idptbhadarate=$key";
  211. $connection = Yii::app()->db;
  212. $connection->createCommand($sql)->execute();
  213. }
  214. //update acommercial column
  215. $rates = $_REQUEST['acommercial'];
  216. foreach ($rates as $key => $value) {
  217. $sql = "Update {{ptbhadarate}} set acommercial=$value WHERE idptbhadarate=$key";
  218. $connection = Yii::app()->db;
  219. $connection->createCommand($sql)->execute();
  220. }
  221. //update bresidential column
  222. $rates = $_REQUEST['bresidential'];
  223. foreach ($rates as $key => $value) {
  224. $sql = "Update {{ptbhadarate}} set bresidential=$value WHERE idptbhadarate=$key";
  225. $connection = Yii::app()->db;
  226. $connection->createCommand($sql)->execute();
  227. }
  228. //update bcommercial column
  229. $rates = $_REQUEST['bcommercial'];
  230. foreach ($rates as $key => $value) {
  231. $sql = "Update {{ptbhadarate}} set bcommercial=$value WHERE idptbhadarate=$key";
  232. $connection = Yii::app()->db;
  233. $connection->createCommand($sql)->execute();
  234. }
  235. //update cresidential column
  236. $rates = $_REQUEST['cresidential'];
  237. foreach ($rates as $key => $value) {
  238. $sql = "Update {{ptbhadarate}} set cresidential=$value WHERE idptbhadarate=$key";
  239. $connection = Yii::app()->db;
  240. $connection->createCommand($sql)->execute();
  241. }
  242. //update ccommercial column
  243. $rates = $_REQUEST['ccommercial'];
  244. foreach ($rates as $key => $value) {
  245. $sql = "Update {{ptbhadarate}} set ccommercial=$value WHERE idptbhadarate=$key";
  246. $connection = Yii::app()->db;
  247. $connection->createCommand($sql)->execute();
  248. }
  249. //update dresidential column
  250. $rates = $_REQUEST['dresidential'];
  251. foreach ($rates as $key => $value) {
  252. $sql = "Update {{ptbhadarate}} set dresidential=$value WHERE idptbhadarate=$key";
  253. $connection = Yii::app()->db;
  254. $connection->createCommand($sql)->execute();
  255. }
  256. //update dcommercial column
  257. $rates = $_REQUEST['dcommercial'];
  258. foreach ($rates as $key => $value) {
  259. $sql = "Update {{ptbhadarate}} set dcommercial=$value WHERE idptbhadarate=$key";
  260. $connection = Yii::app()->db;
  261. $connection->createCommand($sql)->execute();
  262. }
  263. $this->redirect(array('ptbhadarate/admin'));
  264. }
  265. public function actionGenerate() {
  266. if (isset(Yii::app()->session['ccfyear'])) {
  267. $idccfyear = Yii::app()->session['ccfyear']->idccfyear;
  268. $ccfyear_previous = Ccfyear::model()->findbypk((int) $idccfyear - 1);
  269. }
  270. $criteria = new CDbCriteria;
  271. $criteria->compare('idccfyear', $idccfyear, true);
  272. $ptbhadarates = Ptbhadarate::model()->findAll($criteria);
  273. if (count($ptbhadarates) == 0) {
  274. if (isset($ccfyear_previous) && $ccfyear_previous) {
  275. $criteria = new CDbCriteria;
  276. $criteria->compare('idccfyear', $ccfyear_previous->idccfyear, true);
  277. $ptbhadarates = Ptbhadarate::model()->findAll($criteria);
  278. }
  279. $ccwards = Ccward::model()->findAll();
  280. foreach ($ccwards as $ccward) {
  281. $ptbhadarate = new Ptbhadarate();
  282. $ptbhadarate->idccfyear = $idccfyear;
  283. $ptbhadarate->idccward = $ccward->idccward;
  284. if (isset($ptbhadarates) && count($ptbhadarates) > 0) {
  285. foreach ($ptbhadarates as $ptbhadaratevalue) {
  286. if ($ccward->idccward == $ptbhadaratevalue->idccward) {
  287. $ptbhadarate->aresidential = $ptbhadaratevalue->aresidential;
  288. $ptbhadarate->acommercial = $ptbhadaratevalue->acommercial;
  289. $ptbhadarate->bresidential = $ptbhadaratevalue->bresidential;
  290. $ptbhadarate->bcommercial = $ptbhadaratevalue->bcommercial;
  291. $ptbhadarate->cresidential = $ptbhadaratevalue->cresidential;
  292. $ptbhadarate->ccommercial = $ptbhadaratevalue->ccommercial;
  293. $ptbhadarate->dresidential = $ptbhadaratevalue->dresidential;
  294. $ptbhadarate->dcommercial = $ptbhadaratevalue->dcommercial;
  295. }
  296. }
  297. }
  298. echo $ptbhadarate->idccward . ' ' . $ptbhadarate->aresidential . '</br>';
  299. $ptbhadarate->save();
  300. }
  301. Yii::app()->user->setFlash('success', Yii::t('application', 'Ptbhadarate for current finanical year has been generated successfully.'));
  302. } else {
  303. Yii::app()->user->setFlash('notice', Yii::t('application', 'Ptbhadarate for current finanical year already exist.'));
  304. }
  305. $this->redirect(array('ptbhadarate/admin'));
  306. }
  307. }