@ -8,6 +8,7 @@ namespace Admin\Controller;
class AggregateFinanceStatementController extends ThinkController
{
public $verify_status = [
"-4"=>"汇总审批拒绝",
"-3"=>"撤销汇总",
"-1"=>"审批拒绝",
"0"=>"未申请开票",
@ -17,6 +18,7 @@ class AggregateFinanceStatementController extends ThinkController
"4"=>"已上传凭证",
"5"=>"已到账",
"6"=>"已汇总",
"7"=>"汇总审批同意",
];
public $admininfo;
public $OpAuthList=[];
@ -110,8 +112,12 @@ class AggregateFinanceStatementController extends ThinkController
$data[$key]['withdraw_type_1'] = ($value['withdraw_type'] == 1 ? "月结" :"周结");
$data[$key]['withdraw_type_2'] = ($value['withdraw_type'] == 2 ? "补点" :"正常结算");
$data[$key]['detail'] = json_decode($value['detail'],true);
$data[$key]['oplist'] = $this->OpAuth($value);
}
// dump($data);die();
$count = M("aggregate_statement","tab_")->field("count(id) count,SUM(ratio_money) ratio_money")->where($map)->find();
$map['withdraw_type'] = ["NEQ",2];
$pay_money_count = M("aggregate_statement","tab_")->field("SUM(pay_money) pay_money")->where($map)->find()['pay_money'];
@ -146,7 +152,26 @@ class AggregateFinanceStatementController extends ThinkController
}
$info = M("aggregate_statement","tab_")->field("statement_info,pay_money,ratio_money,channel_id")->where("id={$id}")->find();
$company_info = M("company_relation","tab_")->field("first_company_id,second_company_id,first_company_type")->where("first_company_id={$info['channel_id']} or second_company_id={$info['channel_id']}")->find();
$company_info = M("company_relation","tab_")->field("first_company_id,second_company_id,first_company_type,collection")->where("first_company_id={$info['channel_id']} or second_company_id={$info['channel_id']}")->find();
if($company_info['first_company_type'] == 3) {
$first_partner_type = 1;
} else {
$first_partner_type = 0;
}
$this->setAggregateDetail(2,1,'申请开票',$id);
if ($company_info['collection'] == 1) {
$pay_company_id = 0;
} else if ($company_info['collection'] == 2) {
$pay_company_id = 1;
}
// dump($pay_company_id);die();
$this->assign("pay_company_id",$pay_company_id);
$this->assign('first_partner_type',$first_partner_type);
$this->assign('first_channel_id',$company_info['first_company_id']);
$this->assign('second_company_id',$company_info['second_company_id']);
$statement_info = json_decode($info['statement_info'],true);
$this->assign('company_info',$company_info);
@ -192,7 +217,7 @@ class AggregateFinanceStatementController extends ThinkController
public function getCompanyList()
{
$id = $_REQUEST['id'];
$cpCompany = M("aggregate_statement","tab_")->field("id,second_party_info")->where("id={$id}")->find();
$cpCompany = M("aggregate_statement","tab_")->field("channel_id id,second_party_info")->where("id={$id}")->find();
$data = array();
$data['ptCompany']= M("CompanyInfo","tab_")->field('id,partner')->select();
@ -209,9 +234,10 @@ class AggregateFinanceStatementController extends ThinkController
if($company_type == 'pt'){
$info = M("CompanyInfo","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where("id = '{$CompanyId}'")->find();
}else{
$cpCompany = M("aggregate_statement","tab_")->field("id,second_party_info")->where("id={$CompanyId}")->find();
$cpCompany = M("aggregate_statement","tab_")->field("channel_id id,second_party_info,channel_id ")->where("channel_ id={$CompanyId}")->find();
$info = json_decode($cpCompany['second_party_info'],true);
$relation = M("company_relation","tab_")->where("first_company_id={$cpCompany['channel_id']} or second_company_id = {$cpCompany['channel_id']}")->find();
// $info['link_man'] = $info['connection_person'];
// $info['link_phone'] = $info['phone'];
// $info['address'] = $info['send_address'];
@ -221,8 +247,19 @@ class AggregateFinanceStatementController extends ThinkController
// $info['bank_account'] = $info['bank_card'];
// $info['company_tax_no'] = $info['tax_identification_number'];
}
$info['invoice_item'] = "信息技术服务费";
$info['invoice_type'] = "增值税专用发票";
if ($relation['invoice_type'] == 1) {
$info['invoice_type'] = "专票";
} else if($relation['invoice_type'] == 2) {
$info['invoice_type'] = "普票";
}
if($relation['invoice_content']) {
$info['invoice_item'] = $relation['invoice_content'];
}
if(empty($info)){
$this->ajaxReturn(array("error"=>"no find","code"=>2000));
}else{
@ -431,8 +468,10 @@ class AggregateFinanceStatementController extends ThinkController
"info"=>"审批拒绝成功"
));
}
//已开票
public function Invoiced(){
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$savedata = ["verify_status"=>3,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
@ -440,6 +479,7 @@ class AggregateFinanceStatementController extends ThinkController
$ids = explode(",",$ids);
foreach($ids as $k=>$v){
$this->setAggregateDetail(2,1,'已开票',$v);
$this->doAddOperationLog($v,"已开票");
}
@ -457,9 +497,10 @@ class AggregateFinanceStatementController extends ThinkController
$ids = explode(",",$ids);
foreach($ids as $k=>$v){
$this->setAggregateDetail(3,1,'已到账',$v);
$this->doAddOperationLog($id,"已到账");
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"已到账成功"
@ -471,13 +512,16 @@ class AggregateFinanceStatementController extends ThinkController
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = explode(",",$_REQUEST['ids']);
foreach ($ids as $k => $v) {
$res = A("AggregateFinanceSet")->updateAggregateFinanceData($v);
if(!$res){
$this->ajaxReturn(array(
'status' => 0,
"info"=>"重算结算金额失败"
));
}else{
M("aggregate_statement","tab_")->where(['id'=>$v])->save(['detail'=>'']);
$this->doAddOperationLog($v,"重算结算金额");
}
}
@ -491,7 +535,7 @@ class AggregateFinanceStatementController extends ThinkController
public function cancelVerify(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$savedata = ["verify_status"=>1 ,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
$savedata = ["verify_status"=>0 ,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
M("aggregate_statement","tab_")->where("id ='{$id}'")->save($savedata);
$this->doAddOperationLog($id,"撤销审核");
$this->ajaxReturn(array(
@ -504,13 +548,14 @@ class AggregateFinanceStatementController extends ThinkController
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$data = M("aggregate_statement","tab_")->where("id = '{$id}'")->find();
$savedata = ["verify_status"=>0 ,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
$savedata = ["verify_status"=>7 ,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
$first_party_info = json_decode($data['first_party_info'], 1);
if($first_party_info['partner'] == $data['channel_name']){
$savedata['second_party_info'] = $data['first_party_info'];
$savedata['first_party_info'] = $data['second_party_info'];
$savedata['pay_type'] =0;
}
$this->setAggregateDetail(2,0,'撤销申请',$id);
M("aggregate_statement","tab_")->where("id ='{$id}'")->save($savedata);
$this->doAddOperationLog($id,"撤销申请");
$this->ajaxReturn(array(
@ -758,6 +803,9 @@ class AggregateFinanceStatementController extends ThinkController
//操作对应菜单
$optist = [];
switch ($info['verify_status']) {
case '-4':
$optist = ["viewStatement"];
break;
case '-3':
$optist = ["viewStatement","editStatement","addRemark","viewRemark","editRemark"];
break;
@ -765,7 +813,7 @@ class AggregateFinanceStatementController extends ThinkController
$optist = ["viewStatement","cancelVerify","addRemark","viewRemark","editRemark"];
break;
case '0':
$optist = ["viewStatement","createStatement" ];
$optist = ["viewStatement"];
break;
case '1':
$optist = ["viewStatement","editStatement","cancelApply"];
@ -785,6 +833,9 @@ class AggregateFinanceStatementController extends ThinkController
case "6":
$optist = ["viewStatement","addRemark","viewRemark","editRemark"];
break;
case "7":
$optist = ["viewStatement","createStatement"];
break;
default:
break;
}
@ -836,6 +887,7 @@ class AggregateFinanceStatementController extends ThinkController
}
}
}
return $resarr;
}
//操作日志
@ -906,6 +958,7 @@ class AggregateFinanceStatementController extends ThinkController
$Pool = M("aggregate_statement_pool","tab_");
$Statemen = M("aggregate_statement","tab_");
foreach ($datas as $k => $v) {
if(count($v['company_list']) < = 0){continue;}
$v['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3);
//保存公司信息
@ -913,7 +966,10 @@ class AggregateFinanceStatementController extends ThinkController
foreach ($company_list as $ke => $va) {
$this->addStatementInfo($va,$k,$v);
}
$get_statement_ids = $v['statement_ids'];
foreach ($get_statement_ids as $key => $value) {
$this->setAggregateDetail(0,1,'已汇总',$value);
}
if(empty($v['create_lack_ids']) & & empty($v['del_lack_ids']) & & empty($v['info_ids'])){ continue;}
$v['statement_ids'] = implode(",",$v['statement_ids']);
@ -935,9 +991,14 @@ class AggregateFinanceStatementController extends ThinkController
$v["withdraw_type"] = 0;
}
$pool_id = $Pool->add($v);
if($pool_id == false){
$this->ajaxReturn(array('status' => 0,"info"=>"汇总失败"));
}
if(!empty($info)){
$save["pool_id"]=$pool_id;
M("aggregate_statement_info","tab_")->where("id in ({$info})")->save($save);
@ -1144,5 +1205,30 @@ class AggregateFinanceStatementController extends ThinkController
M("aggregate_statement","tab_")->save($v);
}
}
//type 0 汇总 1 审批 2 开票 3 到账
public function setAggregateDetail($type=0, $status = 1,$detail_info = "",$id = 0) {
$data = M("aggregate_statement","tab_")->where(['id'=>$id])->find();
$detail['detail'] = json_decode($data['detail'],true);
$adminInfo = $_SESSION['onethink_admin']['user_auth'];
if ($type == 0) {
$detail['detail']['pool'] = $detail_info."({$adminInfo["username"]})".date("Y-m-d H:i:s");
$detail['detail']['pool_status'] = $status;
} else if($type == 1) {
$detail['detail']['apply'] = $detail_info."({$adminInfo["username"]})".date("Y-m-d H:i:s");
$detail['detail']['apply_status'] = $status;
} else if($type == 2) {
$detail['detail']['invoiced'] = $detail_info."({$adminInfo["username"]})".date("Y-m-d H:i:s");
$detail['detail']['invoiced_status'] = $status;
} else if($type == 3) {
$detail['detail']['received'] = $detail_info."({$adminInfo["username"]})".date("Y-m-d H:i:s");
$detail['detail']['received_status'] = $status;
}
M("aggregate_statement","tab_")->where(['id'=>$id])->save(['detail'=>json_encode($detail['detail'])]);
}
}