提交 3f0662d8 authored 作者: fengzy's avatar fengzy

费用报销脚本

上级 328d7562
......@@ -285,8 +285,8 @@ class flow_finfybxClassModel extends flowModel
$ret[$v['cbxmid']]['money'] += $v['money'];
}
}
foreach ($data as $key => $vo) {
$ret = array_values($ret);
foreach ($ret as $key => $vo) {
$cbzx_code=$vo['cbxmid'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,type,name,freeze_amount,account_balance');//查询账户表成本中心
......@@ -421,7 +421,6 @@ class flow_finfybxClassModel extends flowModel
$post_content = self::create_postdata($data);
$result = self::invoke_login($cloudUrl,$post_content,$cookie_jar);
header("Content-type: text/html; charset=utf8");
$starttime = microtime(true);
$applicant=$this->rs['applicant'];//申请人
$applicationdpt=$this->rs['applicationdpt'];//申请部门
$applydt=$this->rs['applydt'];//申请日期
......@@ -515,11 +514,8 @@ class flow_finfybxClassModel extends flowModel
);
$post_content = self::create_postdata($data);
var_dump($post_content);
$result = self::invoke_add($cloudUrl,$post_content,$cookie_jar);
var_dump($result);
$array = json_decode($result,true);
var_dump($array);
$num=$array['Result']['Number'];
if($array['Result']['ResponseStatus']['IsSuccess']){
......
......@@ -9,6 +9,7 @@ class flow_oafkClassModel extends flowModel
return $rs;
}
protected function flowcheckafter($zt, $sm){
$flowid=$this->getflow();
......@@ -23,11 +24,12 @@ protected function flowcheckafter($zt, $sm){
foreach ($details_fk as $k=> $value) {
foreach ($value as $key => $val) {
switch ($key) {
// case 'charge_type':
// $arr['FPAYBILLENTRY'][$k]['FCOSTID']['FNUMBER']=self::getbxlx($val);
case 'charge_type':
// break;
$arr['FPAYBILLENTRY'][$k]['F_KXType']['FNUMBER']=self::getkxlx($val);
break;
case 'cbzx_code':
......@@ -60,7 +62,7 @@ protected function flowcheckafter($zt, $sm){
}
$cloudUrl = "http://36.110.39.211/k3cloud/";
$cloudUrl = "http://36.110.39.211/k3cloud/";
//登陆参数
$data = array(
'5e64f6ff0bd47f',//帐套Id
......@@ -80,63 +82,63 @@ protected function flowcheckafter($zt, $sm){
$data_model ='{
"Creator": "",
"NeedUpDateFields": [],
"NeedReturnFields": [],
"IsDeleteEntry": "true",
"SubSystemId": "",
"IsVerifyBaseDataField": "false",
"IsEntryBatchFill": "true",
"ValidateFlag": "true",
"NumberSearch": "true",
"InterationFlags": "",
"IsAutoSubmitAndAudit": "false",
"Model": {
"FID": 0,
"FBillTypeID": {
"FNUMBER": "FKDLX10_SYS"
},
"FDATE": "2020-08-02 00:00:00",
"FCONTACTUNITTYPE": "BD_Supplier",
"FCONTACTUNIT": {
"FNumber": "GDGYS-0002"
},
"FRECTUNITTYPE": "BD_Supplier",
"FRECTUNIT": {
"FNumber": "GDGYS-0002"
},
"FDepartment": {
"FNumber": ""
},
"FISINIT": false,
"FCURRENCYID": {
"FNumber": "PRE001"
},
"FEXCHANGERATE": 1.0,
"FSETTLERATE": 1.0,
"FSETTLEORGID": {
"FNumber": "1000"
},
"FDOCUMENTSTATUS": "Z",
"FCancelStatus": "A",
"FPAYORGID": {
"FNumber": "1000"
},
"FISSAMEORG": true,
"FIsCredit": false,
"FSETTLECUR": {
"FNUMBER": "PRE001"
},
"FIsWriteOff": false,
"FREALPAY": false,
"FISCARRYRATE": false,
"FSETTLEMAINBOOKID": {
"FNUMBER": "PRE001"
},
"F_PAEZ_OADJBH": "123213"
}
}';
"Creator": "",
"NeedUpDateFields": [],
"NeedReturnFields": [],
"IsDeleteEntry": "true",
"SubSystemId": "",
"IsVerifyBaseDataField": "false",
"IsEntryBatchFill": "true",
"ValidateFlag": "true",
"NumberSearch": "true",
"InterationFlags": "",
"IsAutoSubmitAndAudit": "false",
"Model": {
"FID": 0,
"FBillTypeID": {
"FNUMBER": "FKDLX10_SYS"
},
"FDATE": "2020-08-02 00:00:00",
"FCONTACTUNITTYPE": "BD_Supplier",
"FCONTACTUNIT": {
"FNumber": "GDGYS-0002"
},
"FRECTUNITTYPE": "BD_Supplier",
"FRECTUNIT": {
"FNumber": "GDGYS-0002"
},
"FDepartment": {
"FNumber": ""
},
"FISINIT": false,
"FCURRENCYID": {
"FNumber": "PRE001"
},
"FEXCHANGERATE": 1.0,
"FSETTLERATE": 1.0,
"FSETTLEORGID": {
"FNumber": "1000"
},
"FDOCUMENTSTATUS": "Z",
"FCancelStatus": "A",
"FPAYORGID": {
"FNumber": "1000"
},
"FISSAMEORG": true,
"FIsCredit": false,
"FSETTLECUR": {
"FNUMBER": "PRE001"
},
"FIsWriteOff": false,
"FREALPAY": false,
"FISCARRYRATE": false,
"FSETTLEMAINBOOKID": {
"FNUMBER": "PRE001"
},
"F_PAEZ_OADJBH": "123213"
}
}';
$model=json_decode($data_model,true);
......@@ -145,9 +147,10 @@ protected function flowcheckafter($zt, $sm){
$model['Model']['FCONTACTUNIT']['FNumber']=$supplier['number'];
$model['Model']['FRECTUNIT']['FNumber']=$supplier['number'];
$model['Model']['FDepartment']['FNumber']=self::dept($this->rs['applicationdpt']);
$model['Model']['FSETTLEORGID']['FNumber']=self::getorg($this->rs['fkorg']);
$model['Model']['FPAYORGID']['FNumber']=self::getorg($this->rs['fkorg']);
$model['Model']['FPAYBILLENTRY']=$arr['FPAYBILLENTRY'];
$data_model=json_encode($model);
$data = array(
'AP_PAYBILL',//业务对象标识FormId
......@@ -157,25 +160,14 @@ protected function flowcheckafter($zt, $sm){
$post_content = self::create_postdata($data);
$result = self::invoke_add($cloudUrl,$post_content,$cookie_jar);
$array = json_decode($result,true);
$num=$array['Result']['Number'];
if($array['Result']['ResponseStatus']['IsSuccess']){
$num=$array['Result']['Number'];
$this->update("`fbillno`='$num'", $this->rs['id']);
$this->erplog($this->rs['docnum'],'c_fininfom_oafk','保存成功',json_encode($array),date("Y-m-d H:i:s"),2,$num,$array['Result']['Id'],1);
if($this->oafk_submit($cloudUrl,$cookie_jar,$array['Result']['Id'],$array['Result']['Number'])){
$this->erplog($this->rs['docnum'],'c_fininfom_oafk','提交成功',json_encode($array),date("Y-m-d H:i:s"),2,$num,$array['Result']['Id'],2);
}else{
$this->erplog($this->rs['docnum'],'c_fininfom_oafk','提交失败',json_encode($array),date("Y-m-d H:i:s"),1,$num,$array['Result']['Id'],2);
}
}else{
$this->erplog($this->rs['docnum'],'c_fininfom_oafk','保存失败',json_encode($array),date("Y-m-d H:i:s"),1,$num,$array['Result']['Id'],1);
......@@ -188,7 +180,20 @@ protected function flowcheckafter($zt, $sm){
}
static function getkxlx($name)
{
$data = m('option')->getone("num='kxtype'", 'id,name');
$kxlxlist = m('option')->getone("pid='".$data['id']."' and name='".$name."'", 'name,num');
return $kxlxlist['num'];
}
static function getorg($name)
{
$data = m('option')->getone("num='organization'", 'id,name');
$orglist = m('option')->getone("pid='".$data['id']."' and name='".$name."'", 'name,num');
return $orglist['num'];
}
public static function dept($data)
{
$sql=" name= '$data'";
......@@ -215,133 +220,162 @@ protected function flowcheckafter($zt, $sm){
}
//二级 或一级审批同意之后进行预扣款
protected function flowcheckbefore($zt, $sm){
$id=$this->rs['id'];
//二级 或一级审批同意之后进行预扣款
protected function flowcheckbefore($zt, $sm){
$id=$this->rs['id'];
$sql = " mid ='$id' and `table`='c_fininfom_oafk' ";
$flow_bill = m('flow_bill')->getone($sql,'allcheckid');
$allcheckid=explode(',',$flow_bill['allcheckid']);
$optionid = m('option')->getone("num = 'oafk_manager' ",'id');
$flow_bill = m('flow_bill')->getone($sql,'allcheckid');
$allcheckid=explode(',',$flow_bill['allcheckid']);
$optionid = m('option')->getone("num = 'oafk_manager' ",'id');
$optionid=$optionid['id'];
$option = m('option')->getall("pid = '$optionid' and num =1 order by sort desc",'num,name,value,sort');
foreach ($option as $key => $value) {
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
break;
}
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
break;
}
}
if(empty($checkid)){
if(empty($checkid)){
$option = m('option')->getall("pid = '$optionid' and num =2 order by sort desc",'num,name,value,sort,`explain`');
foreach ($option as $key => $value) {
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
$explain= $value['explain'];
break;
}
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
$explain= $value['explain'];
break;
}
}
}
}
//zt 1代表同意
//zt 1代表同意
if($zt==1){
$flowid=$this->getflow();
$flowid=$this->getflow();
if($explain){
if($flowid['nowcheckid']==$checkid && $flowid['nowcourseid']==$explain){
$data = m('c_fund_details_fk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach ($data as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,type,name,freeze_amount,account_balance');//查询账户表成本中心
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $vo['cbzx_code'],
'amount' => $vo['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $vo['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
$data = m('c_fund_details_fk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach($data as $v){
if(!isset($ret[$v['cbzx_code']])){
$ret[$v['cbzx_code']] = $v;
}else{
$ret[$v['cbzx_code']]['charge_amount'] += $v['charge_amount'];
}
}
$ret = array_values($ret);
foreach ($ret as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,type,name,freeze_amount,account_balance');//查询账户表成本中心
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
}
foreach ($data as $ke => $ve) {
$cbzx_code=$ve['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,type,name,freeze_amount,account_balance');//查询账户表成本中心
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $ve['cbzx_code'],
'amount' => $ve['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $ve['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
}else{
if($flowid['nowcheckid']==$checkid){
$data = m('c_fund_details_fk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach ($data as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心id
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $vo['cbzx_code'],
'amount' => $vo['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $vo['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
if($flowid['nowcheckid']==$checkid){
$data = m('c_fund_details_fk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach($data as $v){
if(!isset($ret[$v['cbzx_code']])){
$ret[$v['cbzx_code']] = $v;
}else{
$ret[$v['cbzx_code']]['charge_amount'] += $v['charge_amount'];
}
}
$ret = array_values($ret);
foreach ($ret as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心id
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
}
foreach ($data as $ke => $ve) {
$cbzx_code=$ve['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心id
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $ve['cbzx_code'],
'amount' => $ve['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $ve['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
}
}else{
$docnum=$this->rs['docnum'];
//将单据状态作废余额
$withhold_cost = m('c_withhold')->getall("docnum='$docnum' and status =1", 'id,cost_id,amount');
$withhold_cost = m('c_withhold')->getall("docnum='$docnum' and status =1", 'id,cost_id,amount');
foreach ($withhold_cost as $key => $vo) {
foreach ($withhold_cost as $key => $vo) {
//减去冻结金额
$cost_id=$vo['cost_id'];
$sql = " cost_id='$cost_id' and status = 1 and is_default=1";
$fund_account_cost = m('c_fund_account')->getone($sql, 'id,freeze_amount');
$sql = " cost_id='$cost_id' and status = 1 and is_default=1";
$fund_account_cost = m('c_fund_account')->getone($sql, 'id,freeze_amount');
$id=$fund_account_cost['id'];
$freeze = array(
'freeze_amount' => $fund_account_cost['freeze_amount'] - $vo['amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
$freeze = array(
'freeze_amount' => $fund_account_cost['freeze_amount'] - $vo['amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
$status = array(
'status' => 0,
);
m('c_withhold')->update($status, "docnum='$docnum'");
$status = array(
'status' => 0,
);
m('c_withhold')->update($status, "docnum='$docnum'");
}
}
......
......@@ -8,6 +8,7 @@ class flow_oayfkClassModel extends flowModel
if($rs['contractNumber']) $rs['contractNumber'] = $this->getContractByTag($rs['contractNumber']);
return $rs;
}
protected function flowcheckafter($zt, $sm){
$flowid=$this->getflow();
......@@ -21,12 +22,16 @@ protected function flowcheckafter($zt, $sm){
foreach ($details_yfk as $k=> $value) {
foreach ($value as $key => $val) {
switch ($key) {
case 'charge_type':
$arr['FPAYBILLENTRY'][$k]['F_KXType']['FNUMBER']=self::getkxlx($val);
break;
case 'cbzx_code':
$arr['FPAYBILLENTRY'][$k]['F_PAEZ_Cbzx']['FNUMBER']=substr($val,0,strpos($val, "("));;
break;
case 'charge_amount':
......@@ -52,7 +57,7 @@ protected function flowcheckafter($zt, $sm){
}
$cloudUrl = "http://36.110.39.211/k3cloud/";
$cloudUrl = "http://36.110.39.211/k3cloud/";
//登陆参数
$data = array(
'5e64f6ff0bd47f',//帐套Id
......@@ -71,75 +76,76 @@ protected function flowcheckafter($zt, $sm){
$applydt=$this->rs['applydt'];//申请日期
$data_model ='{
"Creator": "",
"NeedUpDateFields": [],
"NeedReturnFields": [],
"IsDeleteEntry": "true",
"SubSystemId": "",
"IsVerifyBaseDataField": "false",
"IsEntryBatchFill": "true",
"ValidateFlag": "true",
"NumberSearch": "true",
"InterationFlags": "",
"IsAutoSubmitAndAudit": "false",
"Model": {
"FID": 0,
"FBillTypeID": {
"FNUMBER": "FKDLX11_SYS"
},
"FDATE": "2020-08-03 00:00:00",
"FCONTACTUNITTYPE": "BD_Supplier",
"FCONTACTUNIT": {
"FNumber": "GDGYS-0003"
},
"FRECTUNITTYPE": "BD_Supplier",
"FRECTUNIT": {
"FNumber": "GDGYS-0003"
},
"FISINIT": false,
"FCURRENCYID": {
"FNumber": "PRE001"
},
"Creator": "",
"NeedUpDateFields": [],
"NeedReturnFields": [],
"IsDeleteEntry": "true",
"SubSystemId": "",
"IsVerifyBaseDataField": "false",
"IsEntryBatchFill": "true",
"ValidateFlag": "true",
"NumberSearch": "true",
"InterationFlags": "",
"IsAutoSubmitAndAudit": "false",
"Model": {
"FID": 0,
"FBillTypeID": {
"FNUMBER": "FKDLX11_SYS"
},
"FDATE": "2020-08-03 00:00:00",
"FCONTACTUNITTYPE": "BD_Supplier",
"FCONTACTUNIT": {
"FNumber": "GDGYS-0003"
},
"FRECTUNITTYPE": "BD_Supplier",
"FRECTUNIT": {
"FNumber": "GDGYS-0003"
},
"FISINIT": false,
"FCURRENCYID": {
"FNumber": "PRE001"
},
"FDepartment": {
"FNumber": ""
},
"FEXCHANGERATE": 1.0,
"FSETTLERATE": 1.0,
"FSETTLEORGID": {
"FNumber": "1000"
},
"FPURCHASEORGID": {
"FNumber": "1000"
},
"FPURCHASEDEPTID": {
"FNumber": "GS.BM.08"
},
"FDOCUMENTSTATUS": "Z",
"FCancelStatus": "A",
"FPAYORGID": {
"FNumber": "1000"
},
"FISSAMEORG": true,
"FIsCredit": false,
"FSETTLECUR": {
"FNUMBER": "PRE001"
},
"FIsWriteOff": false,
"FREALPAY": false,
"FISCARRYRATE": false,
"FSETTLEMAINBOOKID": {
"FNUMBER": "PRE001"
},
"F_PAEZ_OADJBH": "213123213"
}
}';
"FEXCHANGERATE": 1.0,
"FSETTLERATE": 1.0,
"FSETTLEORGID": {
"FNumber": "1000"
},
"FPURCHASEORGID": {
"FNumber": "1000"
},
"FPURCHASEDEPTID": {
"FNumber": "GS.BM.08"
},
"FDOCUMENTSTATUS": "Z",
"FCancelStatus": "A",
"FPAYORGID": {
"FNumber": "1000"
},
"FISSAMEORG": true,
"FIsCredit": false,
"FSETTLECUR": {
"FNUMBER": "PRE001"
},
"FIsWriteOff": false,
"FREALPAY": false,
"FISCARRYRATE": false,
"FSETTLEMAINBOOKID": {
"FNUMBER": "PRE001"
},
"F_PAEZ_OADJBH": "213123213"
}
}';
$model=json_decode($data_model,true);
$model['Model']['FDATE']=$applydt;
$model['Model']['F_PAEZ_OADJBH']=$this->rs['docnum'];
$model['Model']['FCONTACTUNIT']['FNumber']=$supplier['number'];
$model['Model']['FRECTUNIT']['FNumber']=$supplier['number'];
$model['Model']['FDepartment']['FNumber']=self::dept($this->rs['application']);
$model['Model']['FSETTLEORGID']['FNumber']=self::getorg($this->rs['fkorg']);
$model['Model']['FPAYORGID']['FNumber']=self::getorg($this->rs['fkorg']);
$model['Model']['FPAYBILLENTRY']=$arr['FPAYBILLENTRY'];
$data_model=json_encode($model);
......@@ -152,24 +158,13 @@ protected function flowcheckafter($zt, $sm){
$result = self::invoke_add($cloudUrl,$post_content,$cookie_jar);
$array = json_decode($result,true);
$num=$array['Result']['Number'];
if($array['Result']['ResponseStatus']['IsSuccess']){
$num=$array['Result']['Number'];
$this->update("`fbillno`='$num'", $this->rs['id']);
$this->erplog($this->rs['docnum'],'c_fininfom_oayfk','保存成功',json_encode($array),date("Y-m-d H:i:s"),2,$num,$array['Result']['Id'],1);
if($this->oayfk_submit($cloudUrl,$cookie_jar,$array['Result']['Id'],$array['Result']['Number'])){
$this->erplog($this->rs['docnum'],'c_fininfom_oayfk','提交成功',json_encode($array),date("Y-m-d H:i:s"),2,$num,$array['Result']['Id'],2);
}else{
$this->erplog($this->rs['docnum'],'c_fininfom_oayfk','提交失败',json_encode($array),date("Y-m-d H:i:s"),1,$num,$array['Result']['Id'],2);
}
}else{
$this->erplog($this->rs['docnum'],'c_fininfom_oayfk','保存失败',json_encode($array),date("Y-m-d H:i:s"),1,$num,$array['Result']['Id'],1);
......@@ -184,6 +179,20 @@ protected function flowcheckafter($zt, $sm){
}
static function getkxlx($name)
{
$data = m('option')->getone("num='kxtype'", 'id,name');
$kxlxlist = m('option')->getone("pid='".$data['id']."' and name='".$name."'", 'name,num');
return $kxlxlist['num'];
}
static function getorg($name)
{
$data = m('option')->getone("num='organization'", 'id,name');
$orglist = m('option')->getone("pid='".$data['id']."' and name='".$name."'", 'name,num');
return $orglist['num'];
}
public static function dept($data)
{
$sql=" name= '$data'";
......@@ -209,130 +218,161 @@ protected function flowcheckafter($zt, $sm){
}
//二级 或一级审批同意之后进行预扣款
protected function flowcheckbefore($zt, $sm){
$id=$this->rs['id'];
//二级 或一级审批同意之后进行预扣款
protected function flowcheckbefore($zt, $sm){
$id=$this->rs['id'];
$sql = " mid ='$id' and `table`='c_fininfom_oayfk' ";
$flow_bill = m('flow_bill')->getone($sql,'allcheckid');
$flow_bill = m('flow_bill')->getone($sql,'allcheckid');
$allcheckid=explode(',',$flow_bill['allcheckid']);
$optionid = m('option')->getone("num = 'oayfk_manager' ",'id');
$allcheckid=explode(',',$flow_bill['allcheckid']);
$optionid = m('option')->getone("num = 'oayfk_manager' ",'id');
$optionid=$optionid['id'];
$option = m('option')->getall("pid = '$optionid' and num =1 order by sort desc",'num,name,value,sort');
foreach ($option as $key => $value) {
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
break;
}
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
break;
}
}
if(empty($checkid)){
if(empty($checkid)){
$option = m('option')->getall("pid = '$optionid' and num =2 order by sort desc",'num,name,value,sort,`explain`');
foreach ($option as $key => $value) {
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
$explain= $value['explain'];
break;
}
if(in_array($value['value'], $allcheckid)){
$checkid= $value['value'];
$explain= $value['explain'];
break;
}
}
}
}
//zt 1代表同意
//zt 1代表同意
if($zt==1){
$flowid=$this->getflow();
$flowid=$this->getflow();
if($explain){
if($flowid['nowcheckid']==$checkid && $flowid['nowcourseid']==$explain){
$data = m('c_fund_details_yfk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach ($data as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $vo['cbzx_code'],
'amount' => $vo['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold_yfk')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $vo['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
$data = m('c_fund_details_yfk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach($data as $v){
if(!isset($ret[$v['cbzx_code']])){
$ret[$v['cbzx_code']] = $v;
}else{
$ret[$v['cbzx_code']]['charge_amount'] += $v['charge_amount'];
}
}
$ret = array_values($ret);
foreach ($ret as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
}
foreach ($data as $ke => $ve) {
$cbzx_code=$ve['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $ve['cbzx_code'],
'amount' => $ve['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold_yfk')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $ve['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
}else{
if($flowid['nowcheckid']==$checkid){
$data = m('c_fund_details_yfk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach ($data as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $vo['cbzx_code'],
'amount' => $vo['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold_yfk')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $vo['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
if($flowid['nowcheckid']==$checkid){
$data = m('c_fund_details_yfk')->getall('mid='.$this->rs['id'], 'id,cbzx_code,charge_amount');
foreach($data as $v){
if(!isset($ret[$v['cbzx_code']])){
$ret[$v['cbzx_code']] = $v;
}else{
$ret[$v['cbzx_code']]['charge_amount'] += $v['charge_amount'];
}
}
$ret = array_values($ret);
foreach ($ret as $key => $vo) {
$cbzx_code=$vo['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心
if(($cost['account_balance']-$cost['freeze_amount'])<$vo['charge_amount']){
return $cost['name']."余额不足";die;
}
}
foreach ($data as $ke => $ve) {
$cbzx_code=$ve['cbzx_code'];
$sql = " cost_id='$cbzx_code' and status = 1 and is_default=1";
$cost = m('c_fund_account')->getone($sql, 'id,name,type,freeze_amount,account_balance');//查询账户表成本中心
$id=$cost['id'];
$c_withhold = array(
'fund_account_id' => $id,
'docnum' => $this->rs['docnum'],
'cost_id' => $ve['cbzx_code'],
'amount' => $ve['charge_amount'],
'status' => 1,
'create_time' => date("Y-m-d H:i:s"),
'uid' => $this->rs['uid'],
);
m('c_withhold_yfk')->insert($c_withhold);
//修改冻结余额
$freeze = array(
'freeze_amount' => $cost['freeze_amount'] + $ve['charge_amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
}
}else{
$docnum=$this->rs['docnum'];
//将单据状态作废余额
$withhold_cost = m('c_withhold_yfk')->getall("docnum='$docnum' and status =1", 'id,cost_id,amount');
$withhold_cost = m('c_withhold_yfk')->getall("docnum='$docnum' and status =1", 'id,cost_id,amount');
foreach ($withhold_cost as $key => $vo) {
foreach ($withhold_cost as $key => $vo) {
//减去冻结金额
$cost_id=$vo['cost_id'];
$sql = " cost_id='$cost_id' and status = 1 and is_default=1";
$fund_account_cost = m('c_fund_account')->getone($sql, 'id,freeze_amount');
$sql = " cost_id='$cost_id' and status = 1 and is_default=1";
$fund_account_cost = m('c_fund_account')->getone($sql, 'id,freeze_amount');
$id=$fund_account_cost['id'];
$freeze = array(
'freeze_amount' => $fund_account_cost['freeze_amount'] - $vo['amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
$freeze = array(
'freeze_amount' => $fund_account_cost['freeze_amount'] - $vo['amount'],
);
m('c_fund_account')->update($freeze, "`id`='$id'");
}
}
$status = array(
'status' => 0,
);
m('c_withhold_yfk')->update($status, "docnum='$docnum'");
$status = array(
'status' => 0,
);
m('c_withhold_yfk')->update($status, "docnum='$docnum'");
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论