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

费用报销脚本

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