engineering/app/adminapi/lists/project/ProjectSubcontractSettlementLists.php
2024-01-30 17:34:03 +08:00

130 lines
4.7 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\auth\Admin;
use app\common\model\contract\ContractNegotiation;
use app\common\model\contract\SubcontractingContract;
use app\common\model\contract\SubcontractingContractDetail;
use app\common\model\project\Project;
use app\common\model\project\ProjectSubcontractSettlement;
use app\common\lists\ListsSearchInterface;
use app\common\model\supplier\Supplier;
/**
* 分包结算列表
* Class ProjectSubcontractSettlementLists
* @package app\adminapi\listsproject
*/
class ProjectSubcontractSettlementLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/29 13:59
*/
public function setSearch(): array
{
return [
'=' => ['project_id'],
'%like%' => ['settlement_code'],
];
}
/**
* @notes 获取分包结算列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/29 13:59
*/
public function lists(): array
{
return ProjectSubcontractSettlement::where($this->searchWhere)
->field(['id', 'settlement_code', 'project_id', 'contract_id', 'settlement_amount', 'settlement_date', 'remark', 'add_user'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$project = Project::field('name')->where('id',$item['project_id'])->findOrEmpty();
$contract = SubcontractingContract::field('supplier_id,contract_no')->where('id',$item['contract_id'])->findOrEmpty();
$supplier = Supplier::field('supplier_code,supplier_name')->where('id',$contract['supplier_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['add_user'])->findOrEmpty();
$item['supplier_name'] = $supplier['supplier_name'];
$item['project_name'] = $project['name'];
$item['contract_code'] = $contract['contract_no'];
//合同金额
$item['contract_amount'] = SubcontractingContractDetail::where('contract_id',$item['contract_id'])->sum('amount_including_tax');
//洽商金额
$item['negotiation_amount'] = ContractNegotiation::where('contract_id',$item['contract_id'])->sum('negotiation_amount');
//结算差异
$item['settlement_difference'] = bcsub(($item['contract_amount']+$item['negotiation_amount']),$item['settlement_amount']);
$item['add_user_name'] = $admin['name'];
unset($item['project_id'],$item['contract_id'],$item['add_user']);
return $item;
})
->toArray();
}
/**
* @notes 获取分包结算数量
* @return int
* @author likeadmin
* @date 2023/12/29 13:59
*/
public function count(): int
{
return ProjectSubcontractSettlement::where($this->searchWhere)->count();
}
public function setFileName(): string
{
return '分包结算列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 段誉
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
return [
"id" => "id",
"settlement_code" => "结算单号",
"supplier_name" => "供应商名称",
"project_name" => "项目名称",
"contract_code" => "合同编号",
"settlement_date" => "结算日期",
"contract_amount" => "合同金额",
"negotiation_amount" => "洽商金额",
"settlement_amount" => "结算金额",
"settlement_difference" => "结算差异",
"add_user_name" => "添加人",
];
}
}