This commit is contained in:
weiz 2024-01-12 15:41:27 +08:00
parent 785da1961d
commit 5f63f4ec3f
8 changed files with 196 additions and 75 deletions

View File

@ -19,6 +19,7 @@ use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\ProcurementContract;
use app\common\lists\ListsSearchInterface;
use app\common\model\contract\ProcurementContractDetail;
use app\common\model\finance\FinanceReceiptRecord;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
use think\facade\Db;
@ -74,7 +75,7 @@ class ProcurementContractLists extends BaseAdminDataLists implements ListsSearch
//未付款金额
$data['not_pay_amount'] = $data['contract_amount'] - $data['has_pay_amount'];
//已开票金额
$data['has_invoice_amount'] = 0;
$data['has_invoice_amount'] = FinanceReceiptRecord::where('contract_id',$data['id'])->where('contract_type',1)->sum('invoice_amount');
//未开票金额
$data['not_invoice_amount'] = $data['contract_amount'] - $data['has_invoice_amount'];
//退款金额

View File

@ -20,6 +20,7 @@ use app\common\model\contract\SubcontractingContract;
use app\common\lists\ListsSearchInterface;
use app\common\model\contract\SubcontractingContractDetail;
use app\common\model\contract\SubcontractingContractNegotiation;
use app\common\model\finance\FinanceReceiptRecord;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
@ -81,7 +82,7 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
//未付款金额
$data['not_pay_amount'] = $data['contract_amount'] - $data['has_pay_amount'];
//已开票金额
$data['has_invoice_amount'] = 0;
$data['has_invoice_amount'] = FinanceReceiptRecord::where('contract_id',$data['id'])->where('contract_type',2)->sum('invoice_amount');
//未开票金额
$data['not_invoice_amount'] = $data['contract_amount'] - $data['has_invoice_amount'];
//退款金额

View File

@ -16,8 +16,12 @@ namespace app\adminapi\lists\finance;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\ProcurementContract;
use app\common\model\contract\SubcontractingContract;
use app\common\model\finance\FinancePaymentPlan;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
use think\facade\Db;
/**
@ -38,7 +42,7 @@ class FinancePaymentPlanLists extends BaseAdminDataLists implements ListsSearchI
public function setSearch(): array
{
return [
'=' => ['fpp.supplier_id', 'fpp.contract_id', 'fpp.status'],
'=' => ['supplier_id', 'project_id', 'contract_id', 'contract_type', 'period', 'status'],
];
}
@ -54,19 +58,30 @@ class FinancePaymentPlanLists extends BaseAdminDataLists implements ListsSearchI
*/
public function lists(): array
{
return Db::name('FinancePaymentPlan')->alias('fpp')
->where($this->searchWhere)
->whereNull('fpp.delete_time')
->leftJoin('procurement_contract pc','pc.id = fpp.contract_id')
->leftJoin('project p','p.id = pc.project_id')
->field('fpp.*, p.id as project_id, p.name as project_name, p.project_code, pc.contract_no')
return FinancePaymentPlan::where($this->searchWhere)
->field('id,supplier_id,project_id,contract_id,contract_type,period,pay_date,amount,foreign_currency_remark,status,remark')
->limit($this->limitOffset, $this->limitLength)
->order(['fpp.id' => 'desc'])
->select()->each(function($item, $key){
//关联数据后续添加
$item['supplier_name'] = '供应商名称';
$item['contract_type'] = '1';
return $item;
->order(['id' => 'desc'])
->select()->each(function($data){
$data['period_text'] = $data->period_text;
$data['status_text'] = $data->status_text;
$data['contract_type_text'] = $data->contract_type_text;
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['supplier_name'] = $supplier['supplier_name'];
$data['supplier_code'] = $supplier['supplier_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
if($data['contract_type'] == 1){
$contract = ProcurementContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
}else{
$contract = SubcontractingContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
}
$data['contract_no'] = $contract['contract_no'];
$data['contract_name'] = $contract['contract_name'];
$data['has_payment_amount'] = 0;
$data['not_payment_amount'] = $data['amount'] - $data['has_payment_amount'];
return $data;
})
->toArray();
}
@ -80,11 +95,7 @@ class FinancePaymentPlanLists extends BaseAdminDataLists implements ListsSearchI
*/
public function count(): int
{
return Db::name('FinancePaymentPlan')->alias('fpp')
->where($this->searchWhere)
->whereNull('fpp.delete_time')
->leftJoin('procurement_contract pc','pc.id = fpp.contract_id')
->leftJoin('project p','p.id = pc.project_id')->count();
return FinancePaymentPlan::where($this->searchWhere)->count();
}
}

View File

@ -15,9 +15,12 @@
namespace app\adminapi\logic\finance;
use app\common\model\contract\ProcurementContract;
use app\common\model\contract\SubcontractingContract;
use app\common\model\finance\FinancePaymentPlan;
use app\common\model\project\Project;
use app\common\logic\BaseLogic;
use app\common\model\supplier\Supplier;
use think\facade\Db;
@ -39,20 +42,29 @@ class FinancePaymentPlanLogic extends BaseLogic
*/
public static function add(array $params): bool
{
if($params['contract_cate'] == 1){
$contract = ProcurementContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
}elseif($params['contract_cate'] == 2){
$contract = SubcontractingContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
}else{
self::setError('合同信息不存在');
return false;
}
Db::startTrans();
try {
FinancePaymentPlan::create([
'supplier_id' => $params['supplier_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'period' => $params['period'] ?? 0,
'pay_date' => $params['pay_date'] ?? '',
'amount' => $params['amount'] ?? 0,
'supplier_id' => $params['supplier_id'],
'project_id' => $contract['project_id'],
'contract_id' => $params['contract_id'],
'contract_type' => $params['contract_cate'],
'period' => $params['period'],
'pay_date' => strtotime($params['pay_date']),
'amount' => $params['amount'],
'foreign_currency_remark' => $params['foreign_currency_remark'] ?? '',
'status' => $params['status'] ?? 0,
'status' => $params['status'],
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '',
'annex' => !empty( $params['annex']) ? $params['annex'] : null,
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -72,20 +84,29 @@ class FinancePaymentPlanLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
if($params['contract_cate'] == 1){
$contract = ProcurementContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
}elseif($params['contract_cate'] == 2){
$contract = SubcontractingContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
}else{
self::setError('合同信息不存在');
return false;
}
Db::startTrans();
try {
FinancePaymentPlan::where('id', $params['id'])->update([
'supplier_id' => $params['supplier_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'period' => $params['period'] ?? 0,
'pay_date' => $params['pay_date'] ?? '',
'amount' => $params['amount'] ?? 0,
'foreign_currency_remark' => $params['foreign_currency_remark'] ?? '',
'status' => $params['status'] ?? 0,
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '',
'supplier_id' => $params['supplier_id'],
'project_id' => $contract['project_id'],
'contract_id' => $params['contract_id'],
'contract_type' => $params['contract_cate'],
'period' => $params['period'],
'pay_date' => strtotime($params['pay_date']),
'amount' => $params['amount'],
'foreign_currency_remark' => $params['foreign_currency_remark'] ?? '',
'status' => $params['status'],
'remark' => $params['remark'] ?? '',
'annex' => !empty( $params['annex']) ? $params['annex'] : null,
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -118,15 +139,24 @@ class FinancePaymentPlanLogic extends BaseLogic
*/
public static function detail($params): array
{
$financePaymentPlan = FinancePaymentPlan::findOrEmpty($params['id']);
$financePaymentPlan->contract;
// 供应商关联数据后续添加
$financePaymentPlan->supplier = null;
$financePaymentPlan->project = null;
if (!empty($financePaymentPlan->contract->project_id)) {
$financePaymentPlan->project = Project::findOrEmpty($financePaymentPlan->contract->project_id);
}
$financePaymentPlan->annex = json_decode($financePaymentPlan->annex, true);
return $financePaymentPlan->toArray();
$data = FinancePaymentPlan::field('id,supplier_id,project_id,contract_id,contract_type,period,pay_date,amount,foreign_currency_remark,status,remark,annex')
->findOrEmpty($params['id']);
$data['period_text'] = $data->period_text;
$data['status_text'] = $data->status_text;
$data['contract_type_text'] = $data->contract_type_text;
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['supplier_name'] = $supplier['supplier_name'];
$data['supplier_code'] = $supplier['supplier_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
if($data['contract_type'] == 1){
$contract = ProcurementContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
}else{
$contract = SubcontractingContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
}
$data['contract_no'] = $contract['contract_no'];
$data['contract_name'] = $contract['contract_name'];
return $data->toArray();
}
}

View File

@ -154,6 +154,7 @@ class FinanceReceiptRecordLogic extends BaseLogic
->findOrEmpty($params['id']);
$data['invoice_type_text'] = $data->invoice_type_text;
$data['invoice_tax_rate_text'] = $data->invoice_tax_rate_text;
$data['contract_type_text'] = $data->contract_type_text;
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['supplier_name'] = $supplier['supplier_name'];

View File

@ -15,6 +15,10 @@
namespace app\adminapi\validate\finance;
use app\common\model\contract\ProcurementContract;
use app\common\model\contract\SubcontractingContract;
use app\common\model\dict\DictData;
use app\common\model\supplier\Supplier;
use app\common\validate\BaseValidate;
@ -32,12 +36,14 @@ class FinancePaymentPlanValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
'supplier_id' => 'require',
'contract_id' => 'require',
'period' => 'require',
'pay_date' => 'require',
'amount' => 'require',
'status' => 'require',
'supplier_id' => 'require|checkSupplier',
'contract_cate' => 'require|in:1,2',
'contract_id' => 'require|checkContract',
'period' => 'require|checkPeriod',
'pay_date' => 'require|dateFormat:Y-m-d',
'amount' => 'require|float|gt:0',
'status' => 'require|checkStatus',
'annex' => 'checkAnnex',
];
@ -48,6 +54,7 @@ class FinancePaymentPlanValidate extends BaseValidate
protected $field = [
'id' => 'id',
'supplier_id' => '供应商id',
'contract_cate' => '合同类型',
'contract_id' => '合同id',
'period' => '期次',
'pay_date' => '计划付款日期',
@ -64,7 +71,7 @@ class FinancePaymentPlanValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->only(['supplier_id','contract_id','period','pay_date','amount','status']);
return $this->remove('id', true);
}
@ -75,9 +82,7 @@ class FinancePaymentPlanValidate extends BaseValidate
* @date 2023/12/15 11:14
*/
public function sceneEdit()
{
return $this->only(['id','supplier_id','contract_id','period','pay_date','amount','status']);
}
{}
/**
@ -103,4 +108,60 @@ class FinancePaymentPlanValidate extends BaseValidate
return $this->only(['id']);
}
public function checkSupplier($value): bool|string
{
$supplier = Supplier::where('id',$value)->findOrEmpty();
if($supplier->isEmpty()){
return '供应商信息不存在';
}
return true;
}
public function checkContract($value,$rule,$data): bool|string
{
if($data['contract_cate'] == 1){
$contract = ProcurementContract::where('id',$value)->findOrEmpty()->toArray();
}elseif($data['contract_cate'] == 2){
$contract = SubcontractingContract::where('id',$value)->findOrEmpty()->toArray();
}else{
$contract = [];
}
if(empty($contract)){
return '合同信息不存在';
}
if($contract['supplier_id'] != $data['supplier_id']){
return '合同信息无效';
}
return true;
}
public function checkPeriod($value): bool|string
{
$dict = DictData::where('type_value','pay_period')->column('value');
if(!in_array($value,$dict)){
return '期次无效';
}
return true;
}
public function checkStatus($value): bool|string
{
$dict = DictData::where('type_value','pay_status')->column('value');
if(!in_array($value,$dict)){
return '状态无效';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
$annex = json_decode($value,true);
if(empty($annex) || !is_array($annex)){
return '附件格式错误';
}
}
return true;
}
}

View File

@ -16,6 +16,7 @@ namespace app\common\model\finance;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
@ -30,14 +31,29 @@ class FinancePaymentPlan extends BaseModel
protected $name = 'finance_payment_plan';
protected $deleteTime = 'delete_time';
public function contract()
{
return $this->belongsTo(\app\common\model\contract\ProcurementContract::class, 'contract_id');
}
public function getAnnexAttr($value){
return !empty($value) ? json_decode($value,true) : '';
}
public function getContractTypeTextAttr($value,$data): string
{
$type = [1=>'采购合同',2=>'分包合同'];
return $type[$data['contract_type']];
}
public function getPeriodTextAttr($value,$data){
$dict = DictData::where('type_value','pay_period')->column('name','value');
return $dict[$data['period']];
}
public function getStatusTextAttr($value,$data){
$dict = DictData::where('type_value','pay_status')->column('name','value');
return $dict[$data['status']];
}
public function getPayDateAttr($value): string
{
return !empty($value) ? date('Y-m-d') : '';
return !empty($value) ? date('Y-m-d',$value) : '';
}
}