109 lines
5.5 KiB
PHP
109 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\controller\finance;
|
|
|
|
use app\adminapi\controller\BaseAdminController;
|
|
use app\common\model\contract\ProcurementContract;
|
|
use app\common\model\contract\ProcurementContractDetail;
|
|
use app\common\model\contract\SubcontractingContract;
|
|
use app\common\model\contract\SubcontractingContractDetail;
|
|
use app\common\model\contract\SubcontractingContractNegotiation;
|
|
use app\common\model\finance\FinancePaymentPlan;
|
|
use app\common\model\finance\FinanceReceiptRecord;
|
|
use app\common\model\project\Project;
|
|
use app\common\model\supplier\Supplier;
|
|
|
|
class FinancePaymentReceiptDifferenceController extends BaseAdminController
|
|
{
|
|
//采购付款与收票差异
|
|
public function procure(): \think\response\Json
|
|
{
|
|
$params = $this->request->get(['page_no','page_size','contract_no','project_id']);
|
|
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
|
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
|
$where = [];
|
|
if(isset($params['project_id']) && $params['project_id']){
|
|
$where[] = ['project_id','=',$params['project_id']];
|
|
}
|
|
if(isset($params['contract_no']) && $params['contract_no']){
|
|
$where[] = ['contract_no','like','%'.$params['contract_no'].'%'];
|
|
}
|
|
$data = ProcurementContract::field('id,supplier_id,project_id,contract_no,signing_date')->where($where)->page($pageNo,$pageSize)
|
|
->order(['id' => 'desc'])
|
|
->select()->each(function($item){
|
|
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
|
|
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$item['supplier_id'])->findOrEmpty();
|
|
$item['project_name'] = $project['name'];
|
|
$item['project_code'] = $project['project_code'];
|
|
$item['supplier_name'] = $supplier['supplier_name'];
|
|
$item['supplier_code'] = $supplier['supplier_code'];
|
|
//合同金额
|
|
$item['contract_amount'] = ProcurementContractDetail::where('contract_id',$item['id'])->sum('amount_including_tax');
|
|
//已付款金额
|
|
$item['has_payment_amount'] = FinancePaymentPlan::where('contract_id',$item['id'])->where('contract_type',1)->sum('amount');
|
|
//已收票金额
|
|
$item['has_receipt_amount'] = FinanceReceiptRecord::where('contract_id',$item['id'])->where('contract_type',1)->sum('invoice_amount');
|
|
//收票未付款
|
|
$item['has_receipt_not_payment_amount'] = ($item['has_receipt_amount'] - $item['has_payment_amount']) <= 0 ? 0 : $item['has_receipt_amount'] - $item['has_payment_amount'];
|
|
//付款未收票
|
|
$item['has_payment_not_receipt_amount'] = ($item['has_payment_amount'] - $item['has_receipt_amount']) <= 0 ? 0 : $item['has_payment_amount'] - $item['has_receipt_amount'];
|
|
return $item;
|
|
})->toArray();
|
|
$count = ProcurementContract::field('id')->where($where)->count();
|
|
$result = [
|
|
'count' => $count,
|
|
'page_no' => $pageNo,
|
|
'page_size' => $pageSize,
|
|
'lists' => $data
|
|
];
|
|
return $this->success('请求成功',$result);
|
|
}
|
|
|
|
//分包付款与收票差异
|
|
public function subcontract(): \think\response\Json
|
|
{
|
|
$params = $this->request->get(['page_no','page_size','contract_no','project_id']);
|
|
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
|
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
|
$where = [];
|
|
if(isset($params['project_id']) && $params['project_id']){
|
|
$where[] = ['project_id','=',$params['project_id']];
|
|
}
|
|
if(isset($params['contract_no']) && $params['contract_no']){
|
|
$where[] = ['contract_no','like','%'.$params['contract_no'].'%'];
|
|
}
|
|
$data = SubcontractingContract::field('id,supplier_id,project_id,contract_no,signing_date')->where($where)->page($pageNo,$pageSize)
|
|
->order(['id' => 'desc'])
|
|
->select()->each(function($item){
|
|
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
|
|
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$item['supplier_id'])->findOrEmpty();
|
|
$item['project_name'] = $project['name'];
|
|
$item['project_code'] = $project['project_code'];
|
|
$item['supplier_name'] = $supplier['supplier_name'];
|
|
$item['supplier_code'] = $supplier['supplier_code'];
|
|
//合同金额
|
|
$item['contract_amount'] = SubcontractingContractDetail::where('contract_id',$item['id'])->sum('amount_including_tax');
|
|
//洽商金额
|
|
$negotiate_amount = SubcontractingContractNegotiation::where('subcontracting_contract_id',$item['id'])->sum('negotiation_amount');
|
|
//实际合同金额
|
|
$item['contract_amount'] = $item['contract_amount'] + $negotiate_amount;
|
|
//已付款金额
|
|
$item['has_payment_amount'] = FinancePaymentPlan::where('contract_id',$item['id'])->where('contract_type',2)->sum('amount');
|
|
//已收票金额
|
|
$item['has_receipt_amount'] = FinanceReceiptRecord::where('contract_id',$item['id'])->where('contract_type',2)->sum('invoice_amount');
|
|
//收票未付款
|
|
$item['has_receipt_not_payment_amount'] = ($item['has_receipt_amount'] - $item['has_payment_amount']) <= 0 ? 0 : $item['has_receipt_amount'] - $item['has_payment_amount'];
|
|
//付款未收票
|
|
$item['has_payment_not_receipt_amount'] = ($item['has_payment_amount'] - $item['has_receipt_amount']) <= 0 ? 0 : $item['has_payment_amount'] - $item['has_receipt_amount'];
|
|
return $item;
|
|
})->toArray();
|
|
$count = SubcontractingContract::field('id')->where($where)->count();
|
|
$result = [
|
|
'count' => $count,
|
|
'page_no' => $pageNo,
|
|
'page_size' => $pageSize,
|
|
'lists' => $data
|
|
];
|
|
return $this->success('请求成功',$result);
|
|
}
|
|
} |