From 5f63f4ec3f55ae0d68c2f224ec6682164c14a77f Mon Sep 17 00:00:00 2001 From: weiz Date: Fri, 12 Jan 2024 15:41:27 +0800 Subject: [PATCH] update --- .../finance/FinancePaymentPlanController.php | 6 +- .../contract/ProcurementContractLists.php | 3 +- .../contract/SubcontractingContractLists.php | 3 +- .../lists/finance/FinancePaymentPlanLists.php | 47 +++++---- .../logic/finance/FinancePaymentPlanLogic.php | 86 ++++++++++------ .../finance/FinanceReceiptRecordLogic.php | 1 + .../finance/FinancePaymentPlanValidate.php | 97 +++++++++++++++---- .../model/finance/FinancePaymentPlan.php | 28 ++++-- 8 files changed, 196 insertions(+), 75 deletions(-) diff --git a/app/adminapi/controller/finance/FinancePaymentPlanController.php b/app/adminapi/controller/finance/FinancePaymentPlanController.php index d190f88b5..dad584b0d 100644 --- a/app/adminapi/controller/finance/FinancePaymentPlanController.php +++ b/app/adminapi/controller/finance/FinancePaymentPlanController.php @@ -16,9 +16,9 @@ namespace app\adminapi\controller\finance; -use app\adminapi\controller\BaseAdminController; -use app\adminapi\lists\finance\FinancePaymentPlanLists; -use app\adminapi\logic\finance\FinancePaymentPlanLogic; +use app\adminapi\controller\BaseAdminController; +use app\adminapi\lists\finance\FinancePaymentPlanLists; +use app\adminapi\logic\finance\FinancePaymentPlanLogic; use app\adminapi\validate\finance\FinancePaymentPlanValidate; diff --git a/app/adminapi/lists/contract/ProcurementContractLists.php b/app/adminapi/lists/contract/ProcurementContractLists.php index 79f04201c..1fbf6b844 100644 --- a/app/adminapi/lists/contract/ProcurementContractLists.php +++ b/app/adminapi/lists/contract/ProcurementContractLists.php @@ -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']; //退款金额 diff --git a/app/adminapi/lists/contract/SubcontractingContractLists.php b/app/adminapi/lists/contract/SubcontractingContractLists.php index 01136fcfb..3159e559a 100644 --- a/app/adminapi/lists/contract/SubcontractingContractLists.php +++ b/app/adminapi/lists/contract/SubcontractingContractLists.php @@ -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']; //退款金额 diff --git a/app/adminapi/lists/finance/FinancePaymentPlanLists.php b/app/adminapi/lists/finance/FinancePaymentPlanLists.php index 0bd4efa41..7ad4ff173 100644 --- a/app/adminapi/lists/finance/FinancePaymentPlanLists.php +++ b/app/adminapi/lists/finance/FinancePaymentPlanLists.php @@ -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(); } } \ No newline at end of file diff --git a/app/adminapi/logic/finance/FinancePaymentPlanLogic.php b/app/adminapi/logic/finance/FinancePaymentPlanLogic.php index a59c7058e..889a858ad 100644 --- a/app/adminapi/logic/finance/FinancePaymentPlanLogic.php +++ b/app/adminapi/logic/finance/FinancePaymentPlanLogic.php @@ -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(); } } \ No newline at end of file diff --git a/app/adminapi/logic/finance/FinanceReceiptRecordLogic.php b/app/adminapi/logic/finance/FinanceReceiptRecordLogic.php index 3dfeb745e..f4c743c54 100644 --- a/app/adminapi/logic/finance/FinanceReceiptRecordLogic.php +++ b/app/adminapi/logic/finance/FinanceReceiptRecordLogic.php @@ -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']; diff --git a/app/adminapi/validate/finance/FinancePaymentPlanValidate.php b/app/adminapi/validate/finance/FinancePaymentPlanValidate.php index 6f9da2f5f..a4222e567 100644 --- a/app/adminapi/validate/finance/FinancePaymentPlanValidate.php +++ b/app/adminapi/validate/finance/FinancePaymentPlanValidate.php @@ -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; @@ -31,13 +35,15 @@ class FinancePaymentPlanValidate extends BaseValidate * @var string[] */ protected $rule = [ - 'id' => 'require', - 'supplier_id' => 'require', - 'contract_id' => 'require', - 'period' => 'require', - 'pay_date' => 'require', - 'amount' => 'require', - 'status' => 'require', + 'id' => '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', ]; @@ -46,13 +52,14 @@ class FinancePaymentPlanValidate extends BaseValidate * @var string[] */ protected $field = [ - 'id' => 'id', - 'supplier_id' => '供应商id', - 'contract_id' => '合同id', - 'period' => '期次', - 'pay_date' => '计划付款日期', - 'amount' => '金额', - 'status' => '状态', + 'id' => 'id', + 'supplier_id' => '供应商id', + 'contract_cate' => '合同类型', + 'contract_id' => '合同id', + 'period' => '期次', + 'pay_date' => '计划付款日期', + 'amount' => '金额', + 'status' => '状态', ]; @@ -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']); - } + {} /** @@ -102,5 +107,61 @@ 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; + } } \ No newline at end of file diff --git a/app/common/model/finance/FinancePaymentPlan.php b/app/common/model/finance/FinancePaymentPlan.php index 16494199b..026fe20ed 100644 --- a/app/common/model/finance/FinancePaymentPlan.php +++ b/app/common/model/finance/FinancePaymentPlan.php @@ -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; @@ -29,15 +30,30 @@ class FinancePaymentPlan extends BaseModel use SoftDelete; 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) : ''; } } \ No newline at end of file