提交 0591d1b2 authored 作者: chengye's avatar chengye 提交者: wangkr

完成抄表的驳回,修改操作

上级 d4369841
......@@ -119,11 +119,35 @@ class Useage extends Base
return $this->fetch('default');
}
public function update(){
$useage_id = Request::param('useage_id');
$uModel = (new \app\em\model\Useage())->with('photo')->get(['useage_id'=>$useage_id]);
$em = (new \app\em\model\Em)->getEmUseageInfoById($uModel->em_id,false);
//基站信息
$station_info = Station::getBaseInfoById($em->station_id);
$this->assign('station',$station_info);
//当前用户
$user = Session::get('user');
$this->assign('uid',$user['user_id']);
//员工列表
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin'],'','useage'));
$this->assign('em',$em);
$step = 1000000;
$uModel->repo_numb = ((int)($uModel->current_sum_numb * $step) - (int)($uModel->last_sum_numb * $step)) / $step;
$this->assign('useage',$uModel);
return $this->fetch('update');
}
//保存抄表单
public function store($useage_id = ''){
public function store(){
//获取表单数据
$data = Request::post();
$useage_id = isset($data['useage_id']) ? $data['useage_id'] : '';
$action = '新增';
//数据验证
$validate = new UseageGeneralInfoValidate();
......@@ -149,6 +173,7 @@ class Useage extends Base
$this->checkEnd($useage_id);
$action = '修改';
$uModel = (new \app\em\model\Useage())->get(['useage_id' => $useage_id]);
$uModel->status = 1;
}
//更新
$uModel->staff_id = $data['staff_id'];
......@@ -162,13 +187,14 @@ class Useage extends Base
if(empty($useage_id)){
$udModel = new UseageDetail(); //抄表详情模型
$udModel->type = $data['type'] == 1 ? 5 : 6;
$uModel->current_numb = $data['current_numb'];
$uModel->last_numb = $data['last_numb'];
$udModel->useage_id = $uModel->useage_id;
$udModel->type = $data['pricing_type'] == 1 ? 5 : 6;
$udModel->current_numb = $uModel->current_sum_numb;
$udModel->last_numb = $uModel->last_sum_numb;
} else {
$udModel = (new UseageDetail())->get(['useage_id' => $useage_id]);; //抄表详情模型
$udModel = (new UseageDetail())->get(['useage_id' => $useage_id]); //抄表详情模型
}
$udModel->current_numb = $data['current_numb'];
$udModel->current_numb = $uModel->current_sum_numb;
$udModel->price = $uModel->price;
$udModel->save();
......@@ -188,6 +214,8 @@ class Useage extends Base
$checkType = Request::param('checkType');
$this->verify($useage_id,$checkType); //1是通过 2是驳回
if($checkType == 2) {
$res = $this->checkEnd($useage_id);
if($res !== true) return $res;
$useage->status = 3; //3代表被驳回
$useage->save();
return json(['status'=>1,'message'=>'单据已经驳回']);
......@@ -249,15 +277,20 @@ class Useage extends Base
public function del(){
$useage_id = Request::param('uid');
$this->checkEnd($useage_id);
$res = $this->checkEnd($useage_id);
if($res !== true) return $res;
$useage = (new \app\em\model\Useage())->get(['useage_id'=>$useage_id]);
$useage_details = (new UseageDetail())->select(['useage_id'=>$useage_id]);
Db::startTrans();
try{
$useage->delete();
$useage_details->delete();
if(!empty($useage_details)){
foreach ($useage_details as $u){
$u->delete();
}
}
Db::commit();
return json(['status'=>1,'message'=>"删除单据成功"]);
} catch (\Exception $e) {
......@@ -278,15 +311,16 @@ class Useage extends Base
public function checkEnd($useage_id){
$uModel = (new \app\em\model\Useage())->get(['useage_id'=>$useage_id]);
if(!$uModel) return json(['status'=>0,'message'=>"不存在的抄表单号,请联系管理员"]);
if($uModel->status == 2) return json(['status'=>0,'message'=>"已审核过的单据无法编辑,请联系管理员"]);
if($uModel->status == 2) return json(['status'=>0,'message'=>"已审核过的单据无法操作,请联系管理员"]);
//找出电表最后一条数据
$lastModel = (new \app\em\model\Useage())->where('em_id','=',$uModel->em_id)
->order('id desc')->find();
if($lastModel->status == 2) return json(['status'=>0,'message'=>"单号不是最新的抄表记录且最新的抄表记录已经审核无法修改,请联系管理员"]);
if($lastModel->status == 2) return json(['status'=>0,'message'=>"单号不是最新的抄表记录且最新的抄表记录已经审核无法操作,请联系管理员"]);
if($uModel->id != $lastModel->id){
return json(['status'=>0,'message'=>"抄表单号不是最新的抄表记录,无法修改,请联系管理员"]);
return json(['status'=>0,'message'=>"抄表单号不是最新的抄表记录无法操作,请联系管理员"]);
}
return true;
}
......
......@@ -53,8 +53,13 @@ class Useage extends Base
foreach ($data as $k => $v){
$data[$k]['repo_numb'] = round(round($v['current_sum_numb'] - $v['last_sum_numb'],2)*$v['rate'],2);
if($v['status'] == 3){
$info = (new EmCheckBill())->field('info')->get(['mode_id'=>$v['useage_id']]);
$data[$k]['info'] = $info['info'];
}
}
return $data;
return $data;
}
public function getCopyListCount($map){
$data = self::alias('ue')
......
......@@ -30,7 +30,7 @@ class UseageGeneralInfoValidate extends Validate
];
protected $scene = [
's1' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id',
's1' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id,price',
's2' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id,price',
];
......
......@@ -205,7 +205,7 @@
</div>
{if $detail == false}
<div class="layui-form-item layui-col-md-offset4">
<a href="/em" class="layui-btn">
<a href="/useage/" class="layui-btn">
返回
</a>
<button class="layui-btn" lay-filter="save" lay-submit="">
......
......@@ -217,13 +217,6 @@
{block name="js"}
<script>
//限制输入长度
function sliceDom(dom,len){
if(dom.value.length>len)
return dom.value = dom.value.slice(0,len)
}
//初始化Layui控件
layui.use(['form', 'layer', 'laydate', 'upload'],
function () {
......@@ -251,11 +244,11 @@
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 2000},function(){
layer.msg(data.message,{icon: 6,time: 3000},function(){
window.location.href='/useage';
})
} else {
layer.msg(data.message || data.msg,{icon: 5,time: 1000 })
layer.msg(data.message || data.msg,{icon: 5,time: 3000 })
window.location.href='/useage';
}
}
......@@ -272,7 +265,7 @@
layer.open({
type: 1,
title:'填写驳回理由',
content: '<div class="layui-form-item><div class="layui-input-block" style="padding:15px;"><textarea placeholder="驳回理由" class="layui-textarea" id="refuseInfo" name="refuseInfo"></textarea></div>',
content: '<div class="layui-form-item"><div style="padding:15px;"><textarea placeholder="驳回理由" class="layui-textarea" id="refuseInfo" name="refuseInfo"></textarea></div>',
btn:"提交",
yes: function(){
$data.field.checkType = 2;
......@@ -284,12 +277,11 @@
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 2000},function(){
layer.msg(data.message,{icon: 6,time: 4000},function(){
window.location.href='/useage';
})
} else {
layer.msg(data.message || data.msg,{icon: 5,time: 1000 })
window.location.href='/useage';
layer.msg(data.message || data.msg,{icon: 5,time: 5000 })
}
}
});
......
......@@ -95,18 +95,19 @@
{{# if(d.status == 2){ }}
<span class="layui-bg-blue">已审核</span>
{{# } }}
{{# if(d.status == 3) { }}
<span class="layui-bg-orange" title="{{ d.info.info }}">被驳回</span>
{{# if(d.status == 3){ }}
<span class="layui-bg-orange" title="{{ d.info }}">被驳回</span>
{{# } }}
{{# if(d.status < 2) { }}
<span class="layui-bg-green" title="{{ d.info.info }}">未审核</span>
{{# if(d.status < 2){ }}
<span class="layui-bg-green">未审核</span>
{{# } }}
</script>
{if $admin == true}
<script type="text/html" id="barDemo">
{{# if(d.status == 1 || d.status == 3){ }}
<a title="删除" class="layui-btn layui-btn-sm layui-bg-green" lay-event="update">编辑</a>
<a title="编辑" class="layui-btn layui-btn-sm layui-bg-green" href="/useage_update/{{d.useage_id}}">编辑</a>
<a title="删除" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
{{# } }}
</script>
......@@ -138,13 +139,13 @@
dataType: "json",
success: function (data) {
if(data.status == 1){
layer.msg(data.message,{icon: 6,time: 2000},function(){
layer.msg(data.message,{icon: 6,time: 4000},function(){
obj.del();
layer.close(index);
location.reload()
})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
layer.msg(data.message,{icon: 5,time: 5000 })
}
}
});
......
{extend name="public:base" /}
{block name="body"}
<div class="layui-row">
<div class="layui-col-md12">
<div class="layui-card">
<form class="layui-form">
<div class="layui-form-box">
<div class="layui-form-head">
<div class="layui-form-item">
<label class="layui-form-label">
基本信息
</label>
</div>
</div>
<div class="layui-form-body">
<div class="layui-row">
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
基站编号
</label>
<div class="layui-input-inline">
<input type="text" name="station_sp_code" autocomplete="off"
class="layui-input" value="{$station.station_sp_code|default=''}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
基站名称
</label>
<div class="layui-input-inline">
<input type="text" name="station_name" autocomplete="off" class="layui-input" value="{$station.station_name|default=''}"
disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
电表类型
</label>
<div class="layui-input-inline">
<input type="text" name="project_number" autocomplete="off"
class="layui-input" value="{$em.type.name|default=''}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
电表编号
</label>
<div class="layui-input-inline">
<input type="text" name="project_number" autocomplete="off"
class="layui-input" value="{$em.em_numb|default=''}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
倍率
</label>
<div class="layui-input-inline">
<input type="text" id="rate" name="rate" autocomplete="off"
class="layui-input" value="{$em.rate}" disabled="disabled">
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<form class="layui-form">
<input type="hidden" name="em_id" value="{$em.id}">
<input type="hidden" name="charge_type" value="{$em.rule.charge_type}">
<input type="hidden" name="pricing_type" value="{$em.rule.pricing_type}">
<input type="hidden" name="useage_id" value="{$useage.useage_id|default=''}">
<div class="layui-form-box">
<div class="layui-form-head">
<div class="layui-form-item">
<label class="layui-form-label">
抄表信息
</label>
</div>
</div>
<div class="layui-form-body">
<div class="layui-row">
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
上次抄表日期
</label>
<div class="layui-input-inline">
<input type="text" id="last_date" name="last_date"
autocomplete="off" class="layui-input" value="{$useage.last_date}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
本次抄表日期
</label>
<div class="layui-input-inline">
<input type="text" id="current_date" name="current_date"
autocomplete="off" class="layui-input" value="{$useage.current_date}" {if $useage.status neq 3} disabled="disabled" {/if} >
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
<span class="x-red">*</span>上期度数
</label>
<div class="layui-input-inline">
<input type="text" id="last_numb" name="last_numb"
autocomplete="off" class="layui-input" disabled="disabled" value="{$useage.last_sum_numb}" >
</div>
<div class="layui-form-mid layui-word-aux">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
<span class="x-red">*</span>本期度数
</label>
<div class="layui-input-inline">
<input type="text" id="current_numb" name="current_numb"
autocomplete="off" class="layui-input" value="{$useage.current_sum_numb}" {if $useage.status neq 3} disabled="disabled" {/if} >
</div>
<div class="layui-form-mid layui-word-aux">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
用电量
</label>
<div class="layui-input-inline">
<input type="text" id="repo_numb" name="repo_numb" autocomplete="off" class="layui-input" value="{$useage.repo_numb}" disabled="disabled">
</div>
<div class="layui-form-mid layui-word-aux">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
单价
</label>
<div class="layui-input-inline">
<input type="text" id="price" name="price" autocomplete="off" class="layui-input" {if $useage.status neq 3} disabled="disabled" {/if} value="{$useage.price}">
</div>
<div class="layui-form-mid layui-word-aux">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
<span class="x-red">*</span>抄表员
</label>
<div class="layui-input-inline">
<select name="staff_id" {if $useage.status neq 3} disabled="disabled" {/if}>
{foreach $staffs as $u}
<option value="{$u['id']}" {if $u['id'] == $uid} selected {/if}>{$u['name']}</option>
{/foreach}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
<span class="x-red">*</span>抄表凭证
</label>
<div class="layui-input-inline">
<button type="button" class="layui-btn" id="up_photo" {if $useage.status==2} disabled="disabled" {/if}>
<i class="layui-icon"></i>上传
</button>
<input type="hidden" name="photo_id" value="{$useage.photo_id}">
<a href="{$useage.photo.src}" target="_blank" class="layui-btn {if empty($useage.photo_id)} layui-hide {/if}">
<i class="layui-icon">&#xe64a;</i>预览
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item layui-col-md-offset4">
<a href="/useage" class="layui-btn">
返回
</a>
<button class="layui-btn" lay-filter="save" lay-submit="">
保存
</button>
</div>
</form>
</div>
</div>
</div>
{/block}
{block name="js"}
<script>
//初始化Layui控件
layui.use(['form', 'layer', 'laydate', 'upload'],
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
upload = layui.upload;
//消息提示
function layMsg(msg,type=6,time=1000){
layer.msg(msg,{
icon: type,
time: time,
});
}
laydate.render({
elem:'#current_date',
trigger:'click',
})
//保存抄表单,并且返回列表
form.on('submit(save)',
function (data) {
$.ajax({
url: '/useage_add',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 4000},function(){
window.location.href='/useage';
})
} else {
layer.msg(data.message,{icon: 5,time: 5000 })
}
}
});
return false;
});
//上传电表照片
var upPhoto = upload.render({
elem: '#up_photo' ,
url: '/upFile',
field: 'up_file',
accept: 'file',
size:10240,
done: function (res) {
if(res.status == 1){
layMsg(res.message)
//将电表照片的ID填写
var $photoId = $("input[name='photo_id']")
$photoId.val(res.data.id)
var $a = $photoId.next('a');
$a.removeClass('layui-hide')
$a.attr('href',res.data.src);
}
else {
layMsg(res.message,5)
return;
}
}
});
$('#current_numb').change(function(){
var $level = 100000;
var $rate = $('#rate').val();
var $baseNum = $level*$rate;
var $rNum = $(this).val()*$baseNum - $('#last_numb').val()*$baseNum;
if($rNum < 0){
layMsg('本次抄表必须大于上次抄表读数',5);
$('#current_numb').focus();
} else{
$('#repo_numb').val( $rNum/$level )
}
})
});
</script>
{/block}
\ No newline at end of file
......@@ -147,7 +147,7 @@ Route::get('useage/:useage_id','em/useage/detail');
Route::get('useage_add/:id','em/useage/create');
Route::post('useage_add','em/useage/store');
Route::post('useage_del','em/useage/del');
Route::post('useage_update','em/useage/update');
Route::get('useage_update/:useage_id','em/useage/update');
Route::post('upFile','em/UploadFile/upFile');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论