engineering/app/adminapi/lists/project/ProjectExpenseReimbursementInvoiceDetailLists.php
2024-01-30 18:01:46 +08:00

146 lines
6.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsExcelInterface;
use app\common\model\project\Project;
use app\common\model\project\ProjectExpenseReimbursement;
use app\common\model\project\ProjectExpenseReimbursementInvoiceDetail;
use app\common\lists\ListsSearchInterface;
use think\helper\Str;
/**
* 发票明细列表
* Class ProjectExpenseReimbursementInvoiceDetailLists
* @package app\adminapi\listsproject
*/
class ProjectExpenseReimbursementInvoiceDetailLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/19 13:44
*/
public function setSearch(): array
{
return [
'=' => ['expense_reimbursement_id', 'invoice_type', 'invoice_form'],
'%like%' => ['invoice_sn'],
];
}
/**
* @notes 获取发票明细列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/19 13:44
*/
public function lists(): array
{
$params = $this->request->get(['expense_reimbursement_code','project_code']);
$where = [];
if(isset($params['expense_reimbursement_code']) && $params['expense_reimbursement_code']){
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('expense_reimbursement_code','like','%'.$params['expense_reimbursement_code'].'%')->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
if(isset($params['project_code']) && $params['project_code']){
$project_ids = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id');
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('project_id','in',$project_ids)->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
return ProjectExpenseReimbursementInvoiceDetail::where($this->searchWhere)->where($where)
->field(['id', 'expense_reimbursement_id', 'invoice_type', 'invoice_sn', 'tax_rate', 'invoice_form', 'invoice_amount', 'tax_amount', 'remark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$expense_reimbursement = ProjectExpenseReimbursement::field('expense_reimbursement_code,project_id,apply_user,apply_date')->where('id',$data['expense_reimbursement_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$expense_reimbursement['project_id'])->findOrEmpty();
$data['expense_reimbursement_code'] = $expense_reimbursement['expense_reimbursement_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['apply_user'] = $expense_reimbursement['apply_user'];
$data['apply_date'] = $expense_reimbursement['apply_date'];
$data['invoice_type_text'] = $data->invoice_type_text;
$data['tax_rate_text'] = $data->tax_rate_text;
$data['invoice_form_text'] = $data->invoice_form_text;
$data['invoice_type'] = (string)$data['invoice_type'];
$data['tax_rate'] = (string)$data['tax_rate'];
$data['invoice_form'] = (string)$data['invoice_form'];
return $data;
})
->toArray();
}
/**
* @notes 获取发票明细数量
* @return int
* @author likeadmin
* @date 2024/01/19 13:44
*/
public function count(): int
{
$params = $this->request->get(['expense_reimbursement_code','project_code']);
$where = [];
if(isset($params['expense_reimbursement_code']) && $params['expense_reimbursement_code']){
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('expense_reimbursement_code','like','%'.$params['expense_reimbursement_code'].'%')->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
if(isset($params['project_code']) && $params['project_code']){
$project_ids = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id');
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('project_id','in',$project_ids)->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
return ProjectExpenseReimbursementInvoiceDetail::where($this->searchWhere)->where($where)->count();
}
public function setFileName(): string
{
return '费用报销发票明细列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 段誉
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
return [
"id" => "id",
"project_name" => "项目名称",
"expense_reimbursement_code" => "费用报销单号",
"invoice_form_text" => "发票类型",
"invoice_sn" => "发票号",
"tax_rate_text" => "发票税率(%)",
"invoice_type_text" => "发票形式",
"invoice_amount" => "发票金额",
"tax_amount" => "发票税额",
"remark" => "发票备注",
];
}
}