Skip to content

Commit

Permalink
maintenance record
Browse files Browse the repository at this point in the history
maintenance record
  • Loading branch information
hivoid committed Sep 7, 2013
1 parent e5d38cf commit 68cf3ea
Show file tree
Hide file tree
Showing 29 changed files with 925 additions and 34 deletions.
12 changes: 7 additions & 5 deletions property.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

CREATE DATABASE `property_management` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `property_management`;

CREATE TABLE IF NOT EXISTS `basic_info` (
`id` int(10) unsigned NOT NULL DEFAULT '10000' COMMENT 'ID',
Expand Down Expand Up @@ -714,3 +711,8 @@ CHANGE `resident_count` `resident_count` INT( 10 ) NOT NULL DEFAULT '0' COMME
ALTER TABLE `building` CHANGE `household_count` `household_count` INT( 10 ) NOT NULL DEFAULT '0' COMMENT '住户数量';
ALTER TABLE `resident` CHANGE `phone` `phone` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '联系电话';
ALTER TABLE `household` CHANGE `up_ty` `up_by` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新人';
ALTER TABLE `household` ADD `carport_count` TINYINT NOT NULL DEFAULT '0' COMMENT '车位数量' AFTER `size`;
ALTER TABLE `payment_record` CHANGE `waste_collection` `waste_collection` FLOAT( 9, 2 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '垃圾清理',
CHANGE `other` `other` FLOAT( 9, 2 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '其它费用';
ALTER TABLE `payment_record` ADD `up_by` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新人' AFTER `crt_by` ,
ADD `up_time` BIGINT NOT NULL DEFAULT '0' COMMENT '更新时间' AFTER `up_by`
133 changes: 133 additions & 0 deletions protected/controllers/CarportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

class CarportController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column1';

/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate($hid)
{
$hm = Household::model()->findByPk($hid);
if(empty($hm))
{
Yii::app()->user->setMessage('您尝试在一个不存在的住户下添加车位!','info');
$this->redirect(array('//resident/index'));
}
$model=new Carport;
$model->household_id = $hm->id;
if(isset($_POST['Carport']))
{
$model->attributes=$_POST['Carport'];
if($model->save())
{
BasicInfo::model()->updateCounters(array('carport_count'=>1), 'id='.Yii::app()->params['infoId']);
Household::model()->updateCounters(array('carport_count'=>1), 'id='.$hm->id);
$this->redirect(array('view','id'=>$model->id));
}
}

$this->render('create',array(
'model'=>$model,
));
}

/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Carport']))
{
$model->attributes=$_POST['Carport'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('update',array(
'model'=>$model,
));
}

/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$model = $this->loadModel($id);
if($model->delete())
{
BasicInfo::model()->updateCounters(array('carport_count'=>-1), 'id='.Yii::app()->params['infoId']);
Household::model()->updateCounters(array('carport_count'=>-1), 'id='.$model->household_id);
}
if(!isset($_GET['ajax']))
$this->redirect(isset($_GET['returnUrl']) ? $_GET['returnUrl'] : array('index'));
}

public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Carport');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}

public function loadModel($id)
{
$model=Carport::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'车位不存在.');
return $model;
}

/**
* Performs the AJAX validation.
* @param Carport $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='carport-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}

public function actionFastview()
{
if (isset($_POST['carport-id']) && !empty($_POST['carport-id']))
{
$cpid = intval($_POST['carport-id']);
if(Carport::model()->exists('id='.$cpid))
$this->redirect(array('view', 'id'=>$cpid));
}
Yii::app()->user->setMessage('编号为 ['.$_POST['carport-id'].'] 的车位不存在.');
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
}
}
148 changes: 148 additions & 0 deletions protected/controllers/MaintenanceController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

class MaintenanceController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';

/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new MaintenanceRecord;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['MaintenanceRecord']))
{
$model->attributes=$_POST['MaintenanceRecord'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('create',array(
'model'=>$model,
));
}

/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['MaintenanceRecord']))
{
$model->attributes=$_POST['MaintenanceRecord'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('update',array(
'model'=>$model,
));
}

/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}

/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('MaintenanceRecord');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}

/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new MaintenanceRecord('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['MaintenanceRecord']))
$model->attributes=$_GET['MaintenanceRecord'];

$this->render('admin',array(
'model'=>$model,
));
}

/**
* 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 $id the ID of the model to be loaded
* @return MaintenanceRecord the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=MaintenanceRecord::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

/**
* Performs the AJAX validation.
* @param MaintenanceRecord $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='maintenance-record-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}

public function beforeAction($action)
{
if(parent::beforeAction($action))
{
$this->menu=array(
array('label'=>'所有记录', 'url'=>array('index'), 'active'=>$action->id == 'index'),
array('label'=>'添加新记录', 'url'=>array('create'), 'active'=>$action->id == 'create'),
);
return true;
}
}
}
Loading

0 comments on commit 68cf3ea

Please sign in to comment.