first commit

This commit is contained in:
2026-07-23 09:40:36 +08:00
commit 090abf48fa
989 changed files with 145728 additions and 0 deletions
+350
View File
@@ -0,0 +1,350 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\api\BaseController;
use app\finance\model\Loan;
use app\finance\model\Expense;
use app\finance\model\Invoice;
use app\finance\model\InvoiceIncome;
use app\finance\model\Ticket;
use app\finance\model\TicketPayment;
use think\facade\Db;
use think\facade\View;
class Api extends BaseController
{
//获取获取借支
public function get_loan()
{
$param = get_params();
$where = array();
$where[] = ['delete_time', '=', 0];
$where[] = ['admin_id', '=', $this->uid];
$where[] = ['balance_status', '<', 2];
$where[] = ['pay_status', '=', 1];
$where[] = ['check_status', '=', 2];
$where[] = ['back_status', '=', 0];
/*
if(!empty($param['project_id'])){
$where[] = ['project_id', '=', $param['project_id']];
}
else{
$where[] = ['project_id', '=', 0];
}
*/
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = Db::name('Loan')->where($where)
->paginate(['list_rows'=> $rows])
->each(function ($item, $key) {
$item['create_time'] = to_date($item['create_time'],'Y-m-d');
$item['pay_time'] = to_date($item['pay_time'],'Y-m-d');
$item['un_balance_cost'] = ($item['cost']*100 - $item['balance_cost']*100)/100;
if($item['balance_status']==0){
$item['balance_name']='待冲抵';
}
if($item['balance_status']==1){
$item['balance_name']='部分冲抵';
}
return $item;
});
return table_assign(0, '', $list);
}
//删除报销项
public function del_expense_interfix()
{
$id = get_params("id");
$admin_id = Db::name('ExpenseInterfix')->where('id', $id)->value('admin_id');
if ($admin_id == $this->uid) {
if (Db::name('ExpenseInterfix')->where('id', $id)->delete() !== false) {
return to_assign(0, "删除成功");
} else {
return to_assign(1, "删除失败");
}
} else {
return to_assign(1, "您不是申请人,没权限删除该报销数据");
}
}
//报销设置为已打款
public function topay()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthExpense($this->uid);
if($auth == 0){
return to_assign(1, "你没有打款权限,请联系管理员或者HR");
}
//打款,数据操作
$param['pay_status'] = 1;
$param['pay_admin_id'] = $this->uid;
$param['pay_time'] = time();
$res = Expense::where('id', $param['id'])->strict(false)->field(true)->update($param);
if ($res !== false) {
add_log('topay', $param['id'],$param,'报销');
//发送消息通知
$detail = Expense::where(['id' => $param['id']])->find();
$msg=[
'from_uid'=>$this->uid,//发送人
'to_uids'=>$detail['admin_id'],//接收人
'template_id'=>'expense_pay',//消息模板标识
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s'),
'action_id'=>$detail['id'],
'title' => '报销'
]
];
event('SendMessage',$msg);
return to_assign();
} else {
return to_assign(1, "操作失败");
}
}
}
//借支设置为已打款
public function topay2()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthExpense($this->uid);
if($auth == 0){
return to_assign(1, "你没有打款权限,请联系管理员或者HR");
}
//打款,数据操作
$param['pay_status'] = 1;
$param['pay_admin_id'] = $this->uid;
$param['pay_time'] = time();
$res = Loan::where('id', $param['id'])->strict(false)->field(true)->update($param);
if ($res !== false) {
add_log('topay', $param['id'],$param,'借支');
//发送消息通知
$detail = Loan::where(['id' => $param['id']])->find();
$msg=[
'from_uid'=>$this->uid,//发送人
'to_uids'=>$detail['admin_id'],//接收人
'template_id'=>'loan_pay',//消息模板标识
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s'),
'action_id'=>$detail['id'],
'title' => '借支'
]
];
event('SendMessage',$msg);
return to_assign();
} else {
return to_assign(1, "操作失败");
}
}
}
//借支设置为已归还
public function topay3()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthExpense($this->uid);
if($auth == 0){
return to_assign(1, "你没有操作权限,请联系管理员或者HR");
}
//打款,数据操作
$param['back_status'] = 1;
$param['back_admin_id'] = $this->uid;
$param['back_time'] = time();
$res = Loan::where('id', $param['id'])->strict(false)->field(true)->update($param);
if ($res !== false) {
add_log('toback', $param['id'],$param,'借支');
//发送消息通知
$detail = Loan::where(['id' => $param['id']])->find();
$msg=[
'from_uid'=>$this->uid,//发送人
'to_uids'=>$detail['admin_id'],//接收人
'template_id'=>'loan_back',//消息模板标识
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s'),
'action_id'=>$detail['id'],
'title' => '借支'
]
];
event('SendMessage',$msg);
return to_assign();
} else {
return to_assign(1, "操作失败");
}
}
}
//开具发票
public function open()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthInvoice($this->uid);
if($auth == 0){
return to_assign(1, "你没有开票权限,请联系管理员或者HR");
}
$status = Invoice::where(['id' => $param['id']])->value('check_status');
if ($status == 2) {
$param['open_status'] = 1;
$param['open_admin_id'] = $this->uid;
}
if(isset($param['open_time'])){
$param['open_time'] = strtotime(urldecode($param['open_time']));
}
$res = Invoice::where('id', $param['id'])->strict(false)->field('code,open_status,open_time,open_admin_id,delivery')->update($param);
if ($res !== false) {
add_log('open', $param['id'],$param,'发票');
return to_assign();
} else {
return to_assign(1, "操作失败");
}
}
}
//作废发票
public function tovoid()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthInvoice($this->uid);
if($auth == 0){
return to_assign(1, "你没有作废发票权限,请联系管理员或者HR");
}
$count = InvoiceIncome::where(['invoice_id'=>$param['id'],'status'=>1])->count();
if($count>0){
return to_assign(1, "发票已经新增有回款记录,请先反回款后再作废发票");
}
else{
$param['update_time'] = time();
$param['open_status'] = 2;
}
$res = Invoice::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
if ($res !== false) {
return to_assign();
add_log('tovoid', $param['id'],$param,'发票');
} else {
return to_assign(1, "操作失败");
}
}
}
//反作废发票
public function novoid()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthInvoice($this->uid);
if($auth == 0){
return to_assign(1, "你没有反作废发票权限,请联系管理员或者HR");
}
$param['open_status'] = 1;
$param['update_time'] = time();
$res = Invoice::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
if ($res !== false) {
return to_assign();
add_log('novoid', $param['id'],$param,'发票');
} else {
return to_assign(1, "操作失败");
}
}
}
//上传电子发票
public function upload_invoice()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthInvoice($this->uid);
if($auth == 0){
return to_assign(1, "你没有开票权限,请联系管理员或者HR");
}
$param['update_time'] = time();
$res = Invoice::where('id', $param['id'])->strict(false)->field('update_time,other_file_ids')->update($param);
if ($res !== false) {
return to_assign();
} else {
return to_assign(1, "操作失败");
}
}
}
//作废收票
public function tovoid_ticket()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthInvoice($this->uid);
if($auth == 0){
return to_assign(1, "你没有作废发票权限,请联系管理员或者HR");
}
$count = TicketPayment::where(['ticket_id'=>$param['id'],'status'=>1])->count();
if($count>0){
return to_assign(1, "发票已经新增有付款记录,请先反付款后再作废发票");
}
else{
$param['update_time'] = time();
$param['open_status'] = 2;
}
$res = Ticket::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
if ($res !== false) {
return to_assign();
add_log('tovoid', $param['id'],$param,'发票');
} else {
return to_assign(1, "操作失败");
}
}
}
//反作废收票
public function novoid_ticket()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthInvoice($this->uid);
if($auth == 0){
return to_assign(1, "你没有反作废发票权限,请联系管理员或者HR");
}
$param['open_status'] = 1;
$param['update_time'] = time();
$res = Ticket::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
if ($res !== false) {
return to_assign();
add_log('novoid', $param['id'],$param,'发票');
} else {
return to_assign(1, "操作失败");
}
}
}
//上传
public function upload_ticket()
{
$param = get_params();
if (request()->isAjax()) {
$auth = isAuthInvoice($this->uid);
if($auth == 0){
return to_assign(1, "你没有发票权限,请联系管理员或者HR");
}
$param['update_time'] = time();
$res = Ticket::where('id', $param['id'])->strict(false)->field('update_time,other_file_ids')->update($param);
if ($res !== false) {
return to_assign();
} else {
return to_assign(1, "操作失败");
}
}
}
}
+141
View File
@@ -0,0 +1,141 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\CostCate as CostCateModel;
use app\finance\validate\CostcateValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Costcate extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CostCateModel();
}
/**
* 数据列表
*/
public function datalist()
{
if (request()->isAjax()) {
$list = $this->model->where('delete_time',0)->select();
return to_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(CostcateValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(CostcateValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getCateById($id);
View::assign('detail', $detail);
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
if (request()->isDelete()) {
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$type = isset($param['type']) ? $param['type'] : 0;
$this->model->delById($id,$type);
} else {
return to_assign(1, "错误的请求");
}
}
/**
* 设置
*/
public function set()
{
if (request()->isAjax()) {
$param = get_params();
$res = $this->model->strict(false)->field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+284
View File
@@ -0,0 +1,284 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\Expense as ExpenseModel;
use app\finance\validate\ExpenseValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Expense extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new ExpenseModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$tab = isset($param['tab']) ? $param['tab'] : 0;
$uid = $this->uid;
$where = array();
$whereOr = array();
$where[]=['delete_time','=',0];
if($tab == 0){
//全部
$auth = isAuthExpense($uid);
if($auth == 0){
$whereOr[] = ['admin_id', '=', $this->uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
}
if($tab == 1){
//我创建的
$where[] = ['admin_id', '=', $this->uid];
}
if($tab == 2){
//待我审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
}
if($tab == 3){
//我已审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
}
if($tab == 4){
//抄送给我的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
}
if($tab == 5){
//已打款的
$where[] = ['pay_status', '=', 1];
$auth = isAuthExpense($uid);
if($auth == 0){
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
$whereOr[] = ['admin_id', '=', $this->uid];
}
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['income_month', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['pay_status']) && $param['pay_status'] != "") {
$where[] = ['pay_status', '=', $param['pay_status']];
}
if (isset($param['check_status']) && $param['check_status'] != "") {
$where[] = ['check_status', '=', $param['check_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
$param['income_month'] = isset($param['income_month']) ? strtotime(urldecode($param['income_month'])) : 0;
$param['expense_time'] = isset($param['expense_time']) ? strtotime(urldecode($param['expense_time'])) : 0;
$amountData = isset($param['amount']) ? $param['amount'] : '0';
$cost = 0;
if ($amountData == 0) {
return to_assign(1,'报销金额不完善');
}
else{
foreach ($amountData as $key => $value) {
if ($value == 0) {
return to_assign(1,'第' . ($key + 1) . '条报销选项的金额不能为零');
}
else{
$cost+=$value;
}
}
}
if($cost==0){
return to_assign(1,'报销金额不能为零');
}
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
$param['cost'] = $cost;
$param['pay_amount'] = $cost;
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(ExpenseValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
if(!empty($param['loan_id'])){
$loan = Db::name('Loan')->where('id',$param['loan_id'])->find();
$balance_cost = Db::name('Expense')->where([['delete_time','=',0],['loan_id','=',$param['loan_id']],['id','<>',$param['id']]])->sum('balance_cost');
$un_balance_cost = ($loan['cost']*100 - $balance_cost*100)/100;
if($un_balance_cost<0){
return to_assign(1,'所选借支已经冲抵完毕,不支持冲抵');
}
$balance_cost = $un_balance_cost*100 - $cost*100;
if($balance_cost>=0){
$param['balance_cost'] = $cost;
$param['pay_amount'] = 0;
}
else{
$param['balance_cost'] = $un_balance_cost;
$param['pay_amount'] = ($cost *100 - $un_balance_cost*100)/100;
}
}
$this->model->edit($param);
} else {
try {
validate(ExpenseValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
if(!empty($param['loan_id'])){
$loan = Db::name('Loan')->where('id',$param['loan_id'])->find();
$un_balance_cost = ($loan['cost']*100 - $loan['balance_cost']*100)/100;
if($un_balance_cost<0){
return to_assign(1,'所选借支已经冲抵完毕,不支持冲抵');
}
$balance_cost = $un_balance_cost*100 - $cost*100;
if($balance_cost>=0){
$param['balance_cost'] = $cost;
$param['pay_amount'] = 0;
}
else{
$param['balance_cost'] = $un_balance_cost;
$param['pay_amount'] = ($cost *100 - $un_balance_cost*100)/100;
}
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
$is_codeno = Db::name('DataAuth')->where('name','finance_admin')->value('conf_10');
View::assign('is_codeno', $is_codeno);
View::assign('expense_cate', Db::name('ExpenseCate')->where(['status' => 1])->select()->toArray());
View::assign('user', get_admin($this->uid));
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/add_expense');
}
return view('edit');
}
$codeno='';
if($is_codeno==1){
$codeno = get_codeno(3);
}
View::assign('codeno', $codeno);
if(is_mobile()){
return view('qiye@/finance/add_expense');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
View::assign('create_user', get_admin($detail['admin_id']));
if(is_mobile()){
return view('qiye@/finance/view_expense');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
//报销记录
public function record()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
$where[]=['delete_time','=',0];
$where[]=['check_status','=',2];
if(isAuthExpense($this->uid)==0){
$where[] = ['admin_id', '=', $this->uid];
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['expense_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['pay_status']) && $param['pay_status'] != "") {
$where[] = ['pay_status', '=', $param['pay_status']];
}
$list = $this->model->datalist($param,$where);
$cost = $this->model::where($where)->sum('cost');
$totalRow['cost'] = sprintf("%.2f",$cost);
return table_assign(0, '', $list);
} else {
View::assign('authExpense',isAuthExpense($this->uid));
return view();
}
}
}
+141
View File
@@ -0,0 +1,141 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\ExpenseCate as ExpenseCateModel;
use app\finance\validate\ExpensecateValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Expensecate extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new ExpenseCateModel();
}
/**
* 数据列表
*/
public function datalist()
{
if (request()->isAjax()) {
$list = $this->model->where('delete_time',0)->select();
return to_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(ExpensecateValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(ExpensecateValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getCateById($id);
View::assign('detail', $detail);
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
if (request()->isDelete()) {
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$type = isset($param['type']) ? $param['type'] : 0;
$this->model->delById($id,$type);
} else {
return to_assign(1, "错误的请求");
}
}
/**
* 设置
*/
public function set()
{
if (request()->isAjax()) {
$param = get_params();
$res = $this->model->strict(false)->field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+288
View File
@@ -0,0 +1,288 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\Invoice as InvoiceModel;
use app\finance\model\InvoiceIncome;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Income extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new InvoiceModel();
}
public function datalist()
{
$uid = $this->uid;
$auth = isAuthIncome($uid);
if (request()->isAjax()) {
$param = get_params();
$where = array();
$whereOr = array();
$where[] = ['delete_time', '=', 0];
$where[] = ['check_status', '=', 2];
$where[] = ['open_status', '=', 1];
$where[] = ['invoice_type','>',0];
if($auth == 0){
$whereOr[] = ['admin_id','=',$this->uid];
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['enter_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['enter_status']) && $param['enter_status']!='') {
$where[] = ['enter_status', '=', $param['enter_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
} else {
View::assign('auth', $auth);
return view();
}
}
//查看
public function add()
{
$param = get_params();
$auth = isAuthIncome($this->uid);
if (request()->isAjax()) {
if($auth == 0){
return to_assign(1, "你没有到账管理权限,请联系管理员或者HR");
}
$invoice_id = $param['invoice_id'];
$admin_id = $this->uid;
//计算已到账的金额
$hasIncome = InvoiceIncome::where(['invoice_id'=>$invoice_id,'status'=>1])->sum('amount');
//查询发票金额
$invoiceAmount = $this->model->where(['id'=>$invoice_id])->value('amount');
if($param['enter_type']==1){ //单个到账记录
//相关内容多个数组
$enterPriceData=isset($param['amount'])? $param['amount'] : '';
$enterTimeData=isset($param['enter_time'])? $param['enter_time'] : '';
$remarksData=isset($param['remarks'])? $param['remarks'] : '';
//把合同协议关联的单个内容的发票入账明细重新添加
if($enterPriceData){
$enter_price = 0;
$insert = [];
$time = time();
foreach ($enterPriceData as $key => $value) {
if (!$value ) continue;
$insert[] = [
'invoice_id' => $invoice_id,
'amount' => $value,
'enter_time' => $enterTimeData[$key]? strtotime($enterTimeData[$key]) : 0,
'remarks' => $remarksData[$key],
'admin_id' => $admin_id,
'create_time' => $time
];
$enter_price += $value*100;
}
if(($enter_price + $hasIncome*100)> $invoiceAmount*100){
return to_assign(1,'到账金额大于发票金额,不允许保存');
}
else{
$res = InvoiceIncome::strict(false)->field(true)->insertAll($insert);
if($res!==false){
if(($enter_price + $hasIncome*100) == $invoiceAmount*100){
//发票全部到账
$this->model->where(['id'=>$invoice_id])->update(['enter_status'=>2,'enter_amount'=>$invoiceAmount,'enter_time'=>time()]);
}
else if(($enter_price + $hasIncome*100) < $invoiceAmount*100){
$incomeTotal=($enter_price + $hasIncome*100)/100;
//发票部分到账
$this->model->where(['id'=>$invoice_id])->update(['enter_status'=>1,'enter_amount'=>$incomeTotal,'enter_time'=>time()]);
}
add_log('add',$invoice_id,$param);
return to_assign();
}
else{
return to_assign(1,'保存失败');
}
}
}
else{
return to_assign(1,'提交的到账数据异常,请核对再提交');
}
}
else if($param['enter_type']==2){ //全部到账记录
$enter_price = ($invoiceAmount*100-$hasIncome*100)/100;
$data = [
'invoice_id' => $invoice_id,
'amount' => $enter_price,
'enter_time' => isset($param['enter_time'])? strtotime($param['enter_time']) : 0,
'remarks' => '一次性全部到账',
'admin_id' => $admin_id,
'create_time' => time()
];
$res = InvoiceIncome::strict(false)->field(true)->insertGetId($data);
if($res!==false){
//设置发票全部到账
$this->model->where(['id'=>$invoice_id])->update(['enter_status'=>2,'enter_amount'=>$invoiceAmount,'enter_time'=>time()]);
add_log('add',$invoice_id,$param);
return to_assign();
}
}
else if ($param['enter_type']==3) {//全部反账记录
//作废初始化发票到账数据
$res = InvoiceIncome::where(['invoice_id'=>$invoice_id])->update(['status'=>'6','update_time'=>time()]);
if($res!==false){
//设置发票全部没到账
$this->model->where(['id'=>$invoice_id])->update(['enter_status'=>0,'enter_amount'=>0,'enter_time'=>0]);
add_log('tovoid',$invoice_id,$param);
return to_assign();
}
}
}
else{
if($auth == 0){
return view(EEEOR_REPORTING,['code'=>405,'warning'=>'无权限访问']);
}
$id = isset($param['id']) ? $param['id']: 0 ;
$detail = $this->model->getById($id);
if(empty($detail)){
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到记录']);
}
$detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
$file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
$detail['file_array'] = $file_array;
$other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
$detail['other_file_array'] = $other_file_array;
if($detail['open_status']>0){
$detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
}
$not_income = ($detail['amount']*100 - $detail['enter_amount']*100)/100;
$detail['not_income'] = sprintf("%.2f",$not_income);
//已到账的记录
$detail['income'] = InvoiceIncome::field('i.*,a.name as admin')
->alias('i')
->join('Admin a', 'a.id = i.admin_id', 'LEFT')
->where(['i.invoice_id'=>$id,'i.status'=>1])
->order('i.enter_time desc')
->select();
View::assign('uid', $this->uid);
View::assign('id', $id);
View::assign('detail', $detail);
if($detail['invoice_type'] == 0){
return view('add_a');
}
return view();
}
}
//查看
public function view()
{
$id = empty(get_params('id')) ? 0 : get_params('id');
$detail = $this->model->getById($id);
if(empty($detail)){
throw new \think\exception\HttpException(406, '找不到记录');
}
$detail['not_income'] = ($detail['amount']*100 - $detail['enter_amount']*100)/100;
//已到账的记录
$detail['income'] = InvoiceIncome::field('i.*,a.name as admin')
->alias('i')
->join('Admin a', 'a.id = i.admin_id', 'LEFT')
->where(['i.invoice_id'=>$id,'i.status'=>1])
->order('i.enter_time desc')
->select();
$detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
$file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
$detail['file_array'] = $file_array;
$other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
$detail['other_file_array'] = $other_file_array;
if($detail['open_status']>0){
$detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
}
View::assign('uid', $this->uid);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/view_income');
}
return view();
}
//删除到账记录
public function del()
{
$param = get_params();
if (request()->isAjax()) {
$income =InvoiceIncome::where(['id'=>$param['id']])->find();
$invoice = $this->model->where(['id'=>$income['invoice_id']])->find();
if($income){
$res = InvoiceIncome::where(['id'=>$param['id']])->update(['status'=>'6','update_time'=>time()]);
if($res!==false){
if($income['amount']*100 == $invoice['amount']*100){
//发票全部反到账
$this->model->where(['id'=>$income['invoice_id']])->update(['enter_status'=>0,'enter_amount'=>0,'enter_time'=>0]);
}
else if($income['amount']*100 < $invoice['amount']*100){
$incomeTotal=InvoiceIncome::where(['invoice_id'=>$income['invoice_id'],'status'=>1])->sum('amount');
//发票部分到账
$this->model->where(['id'=>$income['invoice_id']])->update(['enter_status'=>1,'enter_amount'=>$incomeTotal,'enter_time'=>time()]);
}
add_log('enter',$income['invoice_id'],$invoice);
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
}
}
//回款记录
public function record()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
$where[]=['status','=',1];
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['enter_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
$model = new InvoiceIncome();
$list = $model->datalist($param,$where);
$amount = $model::where($where)->sum('amount');
$totalRow['amount'] = sprintf("%.2f",$amount);
return table_assign(0, '', $list);
} else {
return view();
}
}
}
+380
View File
@@ -0,0 +1,380 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\Invoice as InvoiceModel;
use app\finance\validate\InvoiceValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Invoice extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new InvoiceModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$tab = isset($param['tab']) ? $param['tab'] : 0;
$uid=$this->uid;
$where = array();
$whereOr = array();
$where[]=['delete_time','=',0];
$where[]=['invoice_type','>',0];
if($tab == 0){
$auth = isAuthInvoice($uid);
if($auth == 0){
$whereOr[] = ['admin_id', '=', $this->uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
}
if($tab == 1){
//我创建的
$where[] = ['admin_id', '=', $this->uid];
}
if($tab == 2){
//待我审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
}
if($tab == 3){
//我已审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
}
if($tab == 4){
//抄送给我的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
}
if($tab == 5){
//已开具的
$where[] = ['open_status', '=', 1];
}
if($tab == 6){
//已作废的
$where[] = ['open_status', '=', 2];
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['open_status']) && $param['open_status'] != "") {
$where[] = ['open_status', '=', $param['open_status']];
}
if (isset($param['enter_status']) && $param['enter_status'] != "") {
$where[] = ['enter_status', '=', $param['enter_status']];
}
if (isset($param['check_status']) && $param['check_status'] != "") {
$where[] = ['check_status', '=', $param['check_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if ($param['types'] == 1) {
if (!$param['invoice_bank']) {
return to_assign(1, '开户银行不能为空');
}
if (!$param['invoice_account']) {
return to_assign(1, '银行账号不能为空');
}
}
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(InvoiceValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(InvoiceValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/add_invoice');
}
return view('edit');
}
if(is_mobile()){
return view('qiye@/finance/add_invoice');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
$other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
$detail['other_file_array'] = $other_file_array;
if($detail['open_status']>0){
$detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
}
View::assign('detail', $detail);
View::assign('create_user', get_admin($detail['admin_id']));
if(is_mobile()){
return view('qiye@/finance/view_invoice');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
//开票记录
public function record()
{
$uid = $this->uid;
$auth = isAuthInvoice($uid);
if (request()->isAjax()) {
$param = get_params();
$tab = isset($param['tab']) ? $param['tab'] : 0;
$where = [];
$whereOr = [];
$where[]=['delete_time','=',0];
$where[]=['check_status','=',2];
$where[]=['invoice_type','>',0];
if($auth == 0){
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
if($tab == 0){
//正常的
$where[] = ['open_status', '<', 2];
}
if($tab == 1){
//已作废的
$where[] = ['open_status', '=', 2];
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['open_status']) && $param['open_status'] != "") {
$where[] = ['open_status', '=', $param['open_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
$amount = $this->model::where($where)->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})->sum('amount');
$totalRow['amount'] = sprintf("%.2f",$amount);
return table_assign(0, '', $list);
} else {
View::assign('authInvoice', $auth);
return view();
}
}
/**
* 无发票回款列表
*/
public function datalist_a()
{
$param = get_params();
if (request()->isAjax()) {
$uid=$this->uid;
$where = array();
$whereOr = array();
$where[]=['delete_time','=',0];
$where[]=['invoice_type','=',0];
$whereOr[] = ['admin_id', '=', $this->uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
$auth = isAuthInvoice($uid);
if($auth == 0){
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['enter_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['enter_status']) && $param['enter_status'] != "") {
$where[] = ['enter_status', '=', $param['enter_status']];
}
if (isset($param['check_status']) && $param['check_status'] != "") {
$where[] = ['check_status', '=', $param['check_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
View::assign('auth', isAuthIncome($this->uid));
return view();
}
}
/**
* 无发票添加/编辑
*/
public function add_a()
{
$param = get_params();
if (request()->isAjax()) {
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(InvoiceValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(InvoiceValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/add_invoice_a');
}
return view('edit_a');
}
if(is_mobile()){
return view('qiye@/finance/add_invoice_a');
}
return view();
}
}
/**
* 无发票查看
*/
public function view_a($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
$detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
$other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
$detail['other_file_array'] = $other_file_array;
if($detail['open_status']>0){
$detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
}
View::assign('detail', $detail);
View::assign('create_user', get_admin($detail['admin_id']));
if(is_mobile()){
return view('qiye@/finance/view_invoice_a');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del_a($id)
{
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}
+231
View File
@@ -0,0 +1,231 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\Loan as LoanModel;
use app\finance\validate\LoanValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Loan extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new LoanModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$tab = isset($param['tab']) ? $param['tab'] : 0;
$uid = $this->uid;
$where = array();
$whereOr = array();
$where[]=['delete_time','=',0];
if($tab == 0){
//全部
$auth = isAuthLoan($uid);
if($auth == 0){
$whereOr[] = ['admin_id', '=', $this->uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
}
if($tab == 1){
//我创建的
$where[] = ['admin_id', '=', $this->uid];
}
if($tab == 2){
//待我审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
}
if($tab == 3){
//我已审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
}
if($tab == 4){
//抄送给我的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
}
if($tab == 5){
//已打款的
$where[] = ['pay_status', '=', 1];
$auth = isAuthLoan($uid);
if($auth == 0){
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
$whereOr[] = ['admin_id', '=', $this->uid];
}
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['create_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['pay_status']) && $param['pay_status'] != "") {
$where[] = ['pay_status', '=', $param['pay_status']];
}
if (isset($param['check_status']) && $param['check_status'] != "") {
$where[] = ['check_status', '=', $param['check_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
$param['loan_time'] = isset($param['loan_time']) ? strtotime(urldecode($param['loan_time'])) : 0;
$param['plan_time'] = isset($param['plan_time']) ? strtotime(urldecode($param['plan_time'])) : 0;
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(LoanValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(LoanValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
$is_codeno = Db::name('DataAuth')->where('name','finance_admin')->value('conf_9');
View::assign('is_codeno', $is_codeno);
View::assign('user', get_admin($this->uid));
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/add_loan');
}
return view('edit');
}
$codeno='';
if($is_codeno==1){
$codeno = get_codeno(4);
}
View::assign('codeno', $codeno);
if(is_mobile()){
return view('qiye@/finance/add_loan');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
$detail['expense'] = Db::name('Expense')->where(['delete_time'=>0,'loan_id'=>$id])->select()->toArray();
View::assign('detail', $detail);
View::assign('create_user', get_admin($detail['admin_id']));
if(is_mobile()){
return view('qiye@/finance/view_loan');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
//借支记录
public function record()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
$where[]=['delete_time','=',0];
$where[]=['check_status','=',2];
if(isAuthLoan($this->uid)==0){
$where[] = ['admin_id', '=', $this->uid];
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['loan_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['pay_status']) && $param['pay_status'] != "") {
$where[] = ['pay_status', '=', $param['pay_status']];
}
$list = $this->model->datalist($param,$where);
$cost = $this->model::where($where)->sum('cost');
$totalRow['cost'] = sprintf("%.2f",$cost);
return table_assign(0, '', $list);
} else {
View::assign('isAuthLoan',isAuthLoan($this->uid));
return view();
}
}
}
+281
View File
@@ -0,0 +1,281 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\Ticket as TicketModel;
use app\finance\model\TicketPayment;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Payment extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new TicketModel();
}
public function datalist()
{
$auth = isAuthPayment($this->uid);
if (request()->isAjax()) {
$param = get_params();
$where = array();
$whereOr = array();
$where[] = ['delete_time', '=', 0];
$where[] = ['check_status', '=', 2];
$where[] = ['open_status', '=', 1];
$where[] = ['invoice_type','>',0];
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['pay_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['pay_status']) && $param['pay_status']!='') {
$where[] = ['pay_status', '=', $param['pay_status']];
}
if($auth == 0){
$where[] = ['admin_id','=',$this->uid];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
} else {
View::assign('auth', $auth);
return view();
}
}
//查看
public function add()
{
$param = get_params();
$auth = isAuthPayment($this->uid);
if (request()->isAjax()) {
if($auth == 0){
return to_assign(1, "你没有付款管理权限,请联系管理员或者HR");
}
$ticket_id = $param['ticket_id'];
$admin_id = $this->uid;
//计算已付款的金额
$hasPay = TicketPayment::where(['ticket_id'=>$ticket_id,'status'=>1])->sum('amount');
//查询发票金额
$ticketAmount = $this->model->where(['id'=>$ticket_id])->value('amount');
if($param['pay_type']==1){ //单个付款记录
//相关内容多个数组
$payPriceData=isset($param['amount'])? $param['amount'] : '';
$payTimeData=isset($param['pay_time'])? $param['pay_time'] : '';
$remarksData=isset($param['remarks'])? $param['remarks'] : '';
//把合同协议关联的单个内容的发票入账明细重新添加
if($payPriceData){
$pay_price = 0;
$insert = [];
$time = time();
foreach ($payPriceData as $key => $value) {
if (!$value ) continue;
$insert[] = [
'ticket_id' => $ticket_id,
'amount' => $value,
'pay_time' => $payTimeData[$key]? strtotime($payTimeData[$key]) : 0,
'remarks' => $remarksData[$key],
'admin_id' => $admin_id,
'create_time' => $time
];
$pay_price += $value*100;
}
if(($pay_price + $hasPay*100)> $ticketAmount*100){
return to_assign(1,'付款金额大于发票金额,不允许保存');
}
else{
$res = TicketPayment::strict(false)->field(true)->insertAll($insert);
if($res!==false){
if(($pay_price + $hasPay*100) == $ticketAmount*100){
//发票全部付款
$this->model->where(['id'=>$ticket_id])->update(['pay_status'=>2,'pay_amount'=>$ticketAmount,'pay_time'=>time()]);
}
else if(($pay_price + $hasPay*100) < $ticketAmount*100){
$payTotal=($pay_price + $hasPay*100)/100;
//发票部分付款
$this->model->where(['id'=>$ticket_id])->update(['pay_status'=>1,'pay_amount'=>$payTotal,'pay_time'=>time()]);
}
add_log('add',$ticket_id,$param);
return to_assign();
}
else{
return to_assign(1,'保存失败');
}
}
}
else{
return to_assign(1,'提交的付款数据异常,请核对再提交');
}
}
else if($param['pay_type']==2){ //全部付款记录
$pay_price = ($ticketAmount*100-$hasPay*100)/100;
$data = [
'ticket_id' => $ticket_id,
'amount' => $pay_price,
'pay_time' => isset($param['pay_time'])? strtotime($param['pay_time']) : 0,
'remarks' => '一次性全部付款',
'admin_id' => $admin_id,
'create_time' => time()
];
$res = TicketPayment::strict(false)->field(true)->insertGetId($data);
if($res!==false){
//设置发票全部付款
$this->model->where(['id'=>$ticket_id])->update(['pay_status'=>2,'pay_amount'=>$ticketAmount,'pay_time'=>time()]);
add_log('add',$ticket_id,$param);
return to_assign();
}
}
else if ($param['pay_type']==3) {//全部反账记录
//作废初始化发票付款数据
$res = TicketPayment::where(['ticket_id'=>$ticket_id])->update(['status'=>'6','update_time'=>time()]);
if($res!==false){
//设置发票全部没付款
$this->model->where(['id'=>$ticket_id])->update(['pay_status'=>0,'pay_amount'=>0,'pay_time'=>0]);
add_log('tovoid',$ticket_id,$param);
return to_assign();
}
}
}
else{
if($auth == 0){
return view(EEEOR_REPORTING,['code'=>405,'warning'=>'无权限访问']);
}
$id = isset($param['id']) ? $param['id']: 0 ;
$detail = $this->model->getById($id);
if(empty($detail)){
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到记录']);
}
$detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
$file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
$detail['file_array'] = $file_array;
$other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
$detail['other_file_array'] = $other_file_array;
if($detail['open_status']>0){
$detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
}
$not_pay = ($detail['amount']*100 - $detail['pay_amount']*100)/100;
$detail['not_pay'] = sprintf("%.2f",$not_pay);
//已付款的记录
$detail['payment'] = TicketPayment::field('i.*,a.name as admin')
->alias('i')
->join('Admin a', 'a.id = i.admin_id', 'LEFT')
->where(['i.ticket_id'=>$id,'i.status'=>1])
->order('i.pay_time desc')
->select();
View::assign('uid', $this->uid);
View::assign('id', $id);
View::assign('detail', $detail);
if($detail['invoice_type'] == 0){
return view('add_a');
}
return view();
}
}
//查看
public function view()
{
$id = empty(get_params('id')) ? 0 : get_params('id');
$detail = $this->model->getById($id);
if(empty($detail)){
throw new \think\exception\HttpException(406, '找不到记录');
}
$detail['not_pay'] = ($detail['amount']*100 - $detail['pay_amount']*100)/100;
//已付款的记录
$detail['payment'] = TicketPayment::field('i.*,a.name as admin')
->alias('i')
->join('Admin a', 'a.id = i.admin_id', 'LEFT')
->where(['i.ticket_id'=>$id,'i.status'=>1])
->order('i.pay_time desc')
->select();
$detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
$file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
$detail['file_array'] = $file_array;
$other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
$detail['other_file_array'] = $other_file_array;
if($detail['open_status']>0){
$detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
}
View::assign('uid', $this->uid);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/view_payment');
}
return view();
}
//删除付款记录
public function del()
{
$param = get_params();
if (request()->isAjax()) {
$payment =TicketPayment::where(['id'=>$param['id']])->find();
$ticket = $this->model->where(['id'=>$payment['ticket_id']])->find();
if($payment){
$res = TicketPayment::where(['id'=>$param['id']])->update(['status'=>'6','update_time'=>time()]);
if($res!==false){
if($payment['amount']*100 == $ticket['amount']*100){
//发票全部反付款
$this->model->where(['id'=>$payment['ticket_id']])->update(['pay_status'=>0,'pay_amount'=>0,'pay_time'=>0]);
}
else if($payment['amount']*100 < $ticket['amount']*100){
$payTotal=TicketPayment::where(['ticket_id'=>$payment['ticket_id'],'status'=>1])->sum('amount');
//发票部分付款
$this->model->where(['id'=>$payment['ticket_id']])->update(['pay_status'=>1,'pay_amount'=>$payTotal,'pay_time'=>time()]);
}
add_log('pay',$payment['ticket_id'],$ticket);
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
}
}
//回款记录
public function record()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
$where[]=['status','=',1];
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['pay_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
$model = new TicketPayment();
$list = $model->datalist($param,$where);
$amount = $model::where($where)->sum('amount');
$totalRow['amount'] = sprintf("%.2f",$amount);
return table_assign(0, '', $list);
} else {
return view();
}
}
}
+346
View File
@@ -0,0 +1,346 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\finance\controller;
use app\base\BaseController;
use app\finance\model\Ticket as TicketModel;
use app\finance\validate\TicketValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Ticket extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new TicketModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$tab = isset($param['tab']) ? $param['tab'] : 0;
$uid=$this->uid;
$where = array();
$whereOr = array();
$where[]=['delete_time','=',0];
$where[]=['invoice_type','>',0];
if($tab == 0){
$auth = isAuthInvoice($uid);
if($auth == 0){
$whereOr[] = ['admin_id', '=', $this->uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
}
if($tab == 1){
//我创建的
$where[] = ['admin_id', '=', $this->uid];
}
if($tab == 2){
//待我审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
}
if($tab == 3){
//我已审核的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
}
if($tab == 4){
//抄送给我的
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['open_status']) && $param['open_status'] != "") {
$where[] = ['open_status', '=', $param['open_status']];
}
if (isset($param['pay_status']) && $param['pay_status'] != "") {
$where[] = ['pay_status', '=', $param['pay_status']];
}
if (isset($param['check_status']) && $param['check_status'] != "") {
$where[] = ['check_status', '=', $param['check_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
if (!empty($param['open_time'])) {
$param['open_time'] = strtotime(urldecode($param['open_time']));
}
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(TicketValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(TicketValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/add_ticket');
}
return view('edit');
}
if(is_mobile()){
return view('qiye@/finance/add_ticket');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
View::assign('create_user', get_admin($detail['admin_id']));
if(is_mobile()){
return view('qiye@/finance/view_ticket');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
//收票记录
public function record()
{
$uid = $this->uid;
$auth = isAuthInvoice($uid);
if (request()->isAjax()) {
$param = get_params();
$tab = isset($param['tab']) ? $param['tab'] : 0;
$where = [];
$where[]=['delete_time','=',0];
$where[]=['check_status','=',2];
$where[]=['invoice_type','>',0];
if($auth == 0){
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['did','in',$dids];
}
}
if($tab == 0){
//正常的
$where[] = ['open_status', '<', 2];
}
if($tab == 1){
//已作废的
$where[] = ['open_status', '=', 2];
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['open_status']) && $param['open_status'] != "") {
$where[] = ['open_status', '=', $param['open_status']];
}
$list = $this->model->datalist($param,$where);
$amount = $this->model::where($where)->sum('amount');
$totalRow['amount'] = sprintf("%.2f",$amount);
return table_assign(0, '', $list);
} else {
View::assign('authInvoice',$auth);
return view();
}
}
/**
* 无发票付款列表
*/
public function datalist_a()
{
$param = get_params();
if (request()->isAjax()) {
$uid=$this->uid;
$where = array();
$whereOr = array();
$where[]=['delete_time','=',0];
$where[]=['invoice_type','=',0];
$whereOr[] = ['admin_id', '=', $this->uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['pay_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
}
if (isset($param['pay_status']) && $param['pay_status'] != "") {
$where[] = ['pay_status', '=', $param['pay_status']];
}
if (isset($param['check_status']) && $param['check_status'] != "") {
$where[] = ['check_status', '=', $param['check_status']];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
View::assign('auth', isAuthPayment($this->uid));
return view();
}
}
/**
* 无发票付款添加/编辑
*/
public function add_a()
{
$param = get_params();
if (request()->isAjax()) {
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
if (!empty($param['open_time'])) {
$param['open_time'] = strtotime(urldecode($param['open_time']));
}
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(TicketValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(TicketValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/finance/add_ticket_a');
}
return view('edit_a');
}
if(is_mobile()){
return view('qiye@/finance/add_ticket_a');
}
return view();
}
}
/**
* 无发票付款查看
*/
public function view_a($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
$detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
$other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
$detail['other_file_array'] = $other_file_array;
View::assign('detail', $detail);
View::assign('create_user', get_admin($detail['admin_id']));
if(is_mobile()){
return view('qiye@/finance/view_ticket_a');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 无发票付款删除
*/
public function del_a()
{
$param = get_params();
if (request()->isDelete()) {
$this->model->delById($param['id']);
} else {
return to_assign(1, "错误的请求");
}
}
}