This commit is contained in:
weiz 2024-01-13 14:55:02 +08:00
parent d77f54e2d8
commit 1c0ccbdf48
7 changed files with 200 additions and 84 deletions

View File

@ -16,9 +16,9 @@
namespace app\adminapi\controller\finance; namespace app\adminapi\controller\finance;
use app\adminapi\controller\BaseAdminController; use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\finance\FinanceRefundRecordLists; use app\adminapi\lists\finance\FinanceRefundRecordLists;
use app\adminapi\logic\finance\FinanceRefundRecordLogic; use app\adminapi\logic\finance\FinanceRefundRecordLogic;
use app\adminapi\validate\finance\FinanceRefundRecordValidate; use app\adminapi\validate\finance\FinanceRefundRecordValidate;

View File

@ -19,7 +19,9 @@ use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\ProcurementContract; use app\common\model\contract\ProcurementContract;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\contract\ProcurementContractDetail; use app\common\model\contract\ProcurementContractDetail;
use app\common\model\finance\FinancePaymentApply;
use app\common\model\finance\FinanceReceiptRecord; use app\common\model\finance\FinanceReceiptRecord;
use app\common\model\finance\FinanceRefundRecord;
use app\common\model\project\Project; use app\common\model\project\Project;
use app\common\model\supplier\Supplier; use app\common\model\supplier\Supplier;
use think\facade\Db; use think\facade\Db;
@ -71,7 +73,7 @@ class ProcurementContractLists extends BaseAdminDataLists implements ListsSearch
$data['supplier_code'] = $supplier['supplier_code']; $data['supplier_code'] = $supplier['supplier_code'];
$data['contract_type'] = $data->contract_type_text; $data['contract_type'] = $data->contract_type_text;
//已付款金额 //已付款金额
$data['has_pay_amount'] = 0; $data['has_pay_amount'] = FinancePaymentApply::where('contract_id',$data['id'])->where('contract_type',1)->sum('amount');
//未付款金额 //未付款金额
$data['not_pay_amount'] = $data['contract_amount'] - $data['has_pay_amount']; $data['not_pay_amount'] = $data['contract_amount'] - $data['has_pay_amount'];
//已开票金额 //已开票金额
@ -79,7 +81,7 @@ class ProcurementContractLists extends BaseAdminDataLists implements ListsSearch
//未开票金额 //未开票金额
$data['not_invoice_amount'] = $data['contract_amount'] - $data['has_invoice_amount']; $data['not_invoice_amount'] = $data['contract_amount'] - $data['has_invoice_amount'];
//退款金额 //退款金额
$data['refund_amount'] = 0; $data['refund_amount'] = FinanceRefundRecord::where('contract_id',$data['id'])->where('contract_type',1)->sum('refund_amount');
//数量 //数量
$data['num'] = ProcurementContractDetail::where('contract_id',$data['id'])->sum('num'); $data['num'] = ProcurementContractDetail::where('contract_id',$data['id'])->sum('num');
//已入库数量 //已入库数量

View File

@ -20,7 +20,9 @@ use app\common\model\contract\SubcontractingContract;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\contract\SubcontractingContractDetail; use app\common\model\contract\SubcontractingContractDetail;
use app\common\model\contract\SubcontractingContractNegotiation; use app\common\model\contract\SubcontractingContractNegotiation;
use app\common\model\finance\FinancePaymentApply;
use app\common\model\finance\FinanceReceiptRecord; use app\common\model\finance\FinanceReceiptRecord;
use app\common\model\finance\FinanceRefundRecord;
use app\common\model\project\Project; use app\common\model\project\Project;
use app\common\model\supplier\Supplier; use app\common\model\supplier\Supplier;
@ -78,7 +80,7 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
//不含税金额 //不含税金额
$data['excluding_tax_amount'] = SubcontractingContractDetail::where('contract_id',$data['id'])->sum('amount_excluding_tax'); $data['excluding_tax_amount'] = SubcontractingContractDetail::where('contract_id',$data['id'])->sum('amount_excluding_tax');
//已付款金额 //已付款金额
$data['has_pay_amount'] = 0; $data['has_pay_amount'] = FinancePaymentApply::where('contract_id',$data['id'])->where('contract_type',2)->sum('amount');;
//未付款金额 //未付款金额
$data['not_pay_amount'] = $data['contract_amount'] - $data['has_pay_amount']; $data['not_pay_amount'] = $data['contract_amount'] - $data['has_pay_amount'];
//已开票金额 //已开票金额
@ -86,7 +88,7 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
//未开票金额 //未开票金额
$data['not_invoice_amount'] = $data['contract_amount'] - $data['has_invoice_amount']; $data['not_invoice_amount'] = $data['contract_amount'] - $data['has_invoice_amount'];
//退款金额 //退款金额
$data['refund_amount'] = 0; $data['refund_amount'] = FinanceRefundRecord::where('contract_id',$data['id'])->where('contract_type',2)->sum('refund_amount');;
//结算差异 //结算差异
$data['settlement_difference'] = 0; $data['settlement_difference'] = 0;
return $data; return $data;

View File

@ -16,8 +16,13 @@ namespace app\adminapi\lists\finance;
use app\adminapi\lists\BaseAdminDataLists; use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\bank\BankAccount;
use app\common\model\contract\ProcurementContract;
use app\common\model\contract\SubcontractingContract;
use app\common\model\finance\FinanceRefundRecord; use app\common\model\finance\FinanceRefundRecord;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
use think\facade\Db; use think\facade\Db;
/** /**
@ -38,7 +43,7 @@ class FinanceRefundRecordLists extends BaseAdminDataLists implements ListsSearch
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['frr.supplier_id', 'frr.contract_id', 'frr.refund_type'], '=' => ['supplier_id', 'project_id', 'contract_type', 'contract_id', 'refund_type'],
]; ];
} }
@ -54,20 +59,27 @@ class FinanceRefundRecordLists extends BaseAdminDataLists implements ListsSearch
*/ */
public function lists(): array public function lists(): array
{ {
return Db::name('FinanceRefundRecord')->alias('frr') return FinanceRefundRecord::where($this->searchWhere)
->where($this->searchWhere) ->field('id,supplier_id,project_id,contract_type,contract_id,refund_amount,refund_date,refund_type,reason,remark')
->whereNull('frr.delete_time')
->leftJoin('procurement_contract pc','pc.id = frr.contract_id')
->leftJoin('project p','p.id = pc.project_id')
->field('frr.*, p.id as project_id, p.name as project_name, p.project_code, pc.contract_no')
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['frr.id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function($item, $key){ ->select()->each(function($data){
//关联数据后续添加 $supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
$item['supplier_name'] = '供应商名称'; $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$item['supplier_code'] = '供应编号'; if($data['contract_type'] == 1){
$item['contract_type'] = '1'; $contract = ProcurementContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
return $item; }else{
$contract = SubcontractingContract::field('contract_no,contract_name')->where('id',$data['contract_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'];
$data['contract_no'] = $contract['contract_no'];
$data['contract_name'] = $contract['contract_name'];
$data['contract_type_text'] = $data->contract_type_text;
$data['refund_type_text'] = $data->refund_type_text;
return $data;
}) })
->toArray(); ->toArray();
} }
@ -81,11 +93,7 @@ class FinanceRefundRecordLists extends BaseAdminDataLists implements ListsSearch
*/ */
public function count(): int public function count(): int
{ {
return Db::name('FinanceRefundRecord')->alias('frr') return FinanceRefundRecord::where($this->searchWhere)->count();
->where($this->searchWhere)
->whereNull('frr.delete_time')
->leftJoin('procurement_contract pc','pc.id = frr.contract_id')
->leftJoin('project p','p.id = pc.project_id')->count();
} }
} }

View File

@ -15,9 +15,13 @@
namespace app\adminapi\logic\finance; namespace app\adminapi\logic\finance;
use app\common\model\bank\BankAccount;
use app\common\model\contract\ProcurementContract;
use app\common\model\contract\SubcontractingContract;
use app\common\model\finance\FinanceRefundRecord; use app\common\model\finance\FinanceRefundRecord;
use app\common\model\project\Project;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
use think\facade\Db; use think\facade\Db;
@ -39,23 +43,29 @@ class FinanceRefundRecordLogic extends BaseLogic
*/ */
public static function add(array $params): bool 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(); Db::startTrans();
try { try {
FinanceRefundRecord::create([ FinanceRefundRecord::create([
'supplier_id' => $params['supplier_id'] ?? 0, 'supplier_id' => $params['supplier_id'],
'contract_id' => $params['contract_id'] ?? 0, 'project_id' => $contract['project_id'],
'refund_amount' => $params['refund_amount'] ?? 0, 'contract_type' => $params['contract_cate'],
'refund_amount_daxie' => $params['refund_amount_daxie'] ?? '', 'contract_id' => $params['contract_id'],
'refund_date' => $params['refund_date'] ?? '', 'refund_amount' => $params['refund_amount'],
'refund_type' => $params['refund_type'] ?? 0, 'refund_date' => strtotime($params['refund_date']),
'refund_type' => $params['refund_type'],
'reason' => $params['reason'] ?? '', 'reason' => $params['reason'] ?? '',
'remark' => $params['remark'] ?? '', 'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '', 'annex' => !empty($params['annex']) ? $params['annex'] : null,
'bank_account_id' => $params['bank_account_id'] ?? 0, 'bank_account_id' => $params['bank_account_id'],
'is_calculate_interest' => $params['is_calculate_interest'] ?? 0,
'interest_calculation_start_date' => $params['interest_calculation_start_date'] ?? '',
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -75,23 +85,30 @@ class FinanceRefundRecordLogic extends BaseLogic
*/ */
public static function edit(array $params): bool 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(); Db::startTrans();
try { try {
FinanceRefundRecord::where('id', $params['id'])->update([ FinanceRefundRecord::where('id', $params['id'])->update([
'supplier_id' => $params['supplier_id'] ?? 0, 'supplier_id' => $params['supplier_id'],
'contract_id' => $params['contract_id'] ?? 0, 'project_id' => $contract['project_id'],
'refund_amount' => $params['refund_amount'] ?? 0, 'contract_type' => $params['contract_cate'],
'refund_amount_daxie' => $params['refund_amount_daxie'] ?? '', 'contract_id' => $params['contract_id'],
'refund_date' => $params['refund_date'] ?? '', 'refund_amount' => $params['refund_amount'],
'refund_type' => $params['refund_type'] ?? 0, 'refund_date' => strtotime($params['refund_date']),
'reason' => $params['reason'] ?? '', 'refund_type' => $params['refund_type'],
'remark' => $params['remark'] ?? '', 'reason' => $params['reason'] ?? '',
'annex' => $params['annex'] ?? '', 'remark' => $params['remark'] ?? '',
'bank_account_id' => $params['bank_account_id'] ?? 0, 'annex' => !empty($params['annex']) ? $params['annex'] : null,
'is_calculate_interest' => $params['is_calculate_interest'] ?? 0, 'bank_account_id' => $params['bank_account_id'],
'interest_calculation_start_date' => $params['interest_calculation_start_date'] ?? '', 'update_time' => time(),
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -124,15 +141,24 @@ class FinanceRefundRecordLogic extends BaseLogic
*/ */
public static function detail($params): array public static function detail($params): array
{ {
$financeRefundRecord = FinanceRefundRecord::findOrEmpty($params['id']); $data = FinanceRefundRecord::field('id,supplier_id,project_id,contract_type,contract_id,refund_amount,refund_date,refund_type,reason,remark,annex,bank_account_id')
$financeRefundRecord->contract; ->findOrEmpty($params['id']);
$financeRefundRecord->supplier = null; $supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
$financeRefundRecord->project = null; $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
if (!empty($financeRefundRecord->contract->project_id)) { if($data['contract_type'] == 1){
$financeRefundRecord->project = $financeRefundRecord->contract->project; $contract = ProcurementContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
unset($financeRefundRecord->contract->project); }else{
} $contract = SubcontractingContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
$financeRefundRecord->annex = json_decode($financeRefundRecord->annex, true); }
return $financeRefundRecord->toArray(); $data['supplier_name'] = $supplier['supplier_name'];
$data['supplier_code'] = $supplier['supplier_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['contract_no'] = $contract['contract_no'];
$data['contract_name'] = $contract['contract_name'];
$data['contract_type_text'] = $data->contract_type_text;
$data['refund_type_text'] = $data->refund_type_text;
$data['bank_account_info'] = BankAccount::field('account_sn,deposit_bank,account_name,account')->where('id',$data['bank_account_id'])->findOrEmpty();
return $data->toArray();
} }
} }

View File

@ -15,6 +15,11 @@
namespace app\adminapi\validate\finance; namespace app\adminapi\validate\finance;
use app\common\model\bank\BankAccount;
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; use app\common\validate\BaseValidate;
@ -31,13 +36,15 @@ class FinanceRefundRecordValidate extends BaseValidate
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
'supplier_id' => 'require', 'supplier_id' => 'require|checkSupplier',
'contract_id' => 'require', 'contract_cate' => 'require|in:1,2',
'refund_amount' => 'require', 'contract_id' => 'require|checkContract',
'refund_date' => 'require', 'refund_amount' => 'require|float|gt:0',
'refund_type' => 'require', 'refund_date' => 'require|dateFormat:Y-m-d',
'bank_account_id' => 'require', 'refund_type' => 'require|checkRefundType',
'annex' => 'checkAnnex',
'bank_account_id' => 'require|checkBankAccount',
]; ];
@ -46,13 +53,14 @@ class FinanceRefundRecordValidate extends BaseValidate
* @var string[] * @var string[]
*/ */
protected $field = [ protected $field = [
'id' => 'id', 'id' => 'id',
'supplier_id' => '供应商id', 'supplier_id' => '供应商id',
'contract_id' => '合同id', 'contract_cate' => '合同类型',
'refund_amount' => '退款金额', 'contract_id' => '合同id',
'refund_date' => '退款日期', 'refund_amount' => '退款金额',
'refund_type' => '退款方式', 'refund_date' => '退款日期',
'bank_account_id' => '收款账户id', 'refund_type' => '退款方式',
'bank_account_id' => '收款账户id',
]; ];
@ -64,7 +72,7 @@ class FinanceRefundRecordValidate extends BaseValidate
*/ */
public function sceneAdd() public function sceneAdd()
{ {
return $this->only(['supplier_id','contract_id','refund_amount','refund_date','refund_type','bank_account_id']); return $this->remove('id',true);
} }
@ -75,9 +83,7 @@ class FinanceRefundRecordValidate extends BaseValidate
* @date 2023/12/15 14:41 * @date 2023/12/15 14:41
*/ */
public function sceneEdit() public function sceneEdit()
{ {}
return $this->only(['id','supplier_id','contract_id','refund_amount','refund_date','refund_type','bank_account_id']);
}
/** /**
@ -102,5 +108,61 @@ class FinanceRefundRecordValidate extends BaseValidate
{ {
return $this->only(['id']); 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 checkRefundType($value): bool|string
{
$dict = DictData::where('type_value','refund_type')->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;
}
public function checkBankAccount($value): bool|string
{
$bank = BankAccount::where('id',$value)->findOrEmpty();
if($bank->isEmpty()){
return '付款银行账户信息不存在';
}
return true;
}
} }

View File

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