Merge pull request 'update' (#165) from zhangwei into dev

Reviewed-on: #165
This commit is contained in:
weiz 2024-01-13 14:55:38 +08:00
commit e9acba9b76
7 changed files with 200 additions and 84 deletions

View File

@ -16,9 +16,9 @@
namespace app\adminapi\controller\finance;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\finance\FinanceRefundRecordLists;
use app\adminapi\logic\finance\FinanceRefundRecordLogic;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\finance\FinanceRefundRecordLists;
use app\adminapi\logic\finance\FinanceRefundRecordLogic;
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\lists\ListsSearchInterface;
use app\common\model\contract\ProcurementContractDetail;
use app\common\model\finance\FinancePaymentApply;
use app\common\model\finance\FinanceReceiptRecord;
use app\common\model\finance\FinanceRefundRecord;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
use think\facade\Db;
@ -71,7 +73,7 @@ class ProcurementContractLists extends BaseAdminDataLists implements ListsSearch
$data['supplier_code'] = $supplier['supplier_code'];
$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'];
//已开票金额
@ -79,7 +81,7 @@ class ProcurementContractLists extends BaseAdminDataLists implements ListsSearch
//未开票金额
$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');
//已入库数量

View File

@ -20,7 +20,9 @@ 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\FinancePaymentApply;
use app\common\model\finance\FinanceReceiptRecord;
use app\common\model\finance\FinanceRefundRecord;
use app\common\model\project\Project;
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['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'];
//已开票金额
@ -86,7 +88,7 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
//未开票金额
$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;
return $data;

View File

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

View File

@ -15,9 +15,13 @@
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\project\Project;
use app\common\logic\BaseLogic;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
use think\facade\Db;
@ -39,23 +43,29 @@ class FinanceRefundRecordLogic 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 {
FinanceRefundRecord::create([
'supplier_id' => $params['supplier_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'refund_amount' => $params['refund_amount'] ?? 0,
'refund_amount_daxie' => $params['refund_amount_daxie'] ?? '',
'refund_date' => $params['refund_date'] ?? '',
'refund_type' => $params['refund_type'] ?? 0,
'supplier_id' => $params['supplier_id'],
'project_id' => $contract['project_id'],
'contract_type' => $params['contract_cate'],
'contract_id' => $params['contract_id'],
'refund_amount' => $params['refund_amount'],
'refund_date' => strtotime($params['refund_date']),
'refund_type' => $params['refund_type'],
'reason' => $params['reason'] ?? '',
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '',
'bank_account_id' => $params['bank_account_id'] ?? 0,
'is_calculate_interest' => $params['is_calculate_interest'] ?? 0,
'interest_calculation_start_date' => $params['interest_calculation_start_date'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null,
'bank_account_id' => $params['bank_account_id'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -75,23 +85,30 @@ class FinanceRefundRecordLogic 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 {
FinanceRefundRecord::where('id', $params['id'])->update([
'supplier_id' => $params['supplier_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'refund_amount' => $params['refund_amount'] ?? 0,
'refund_amount_daxie' => $params['refund_amount_daxie'] ?? '',
'refund_date' => $params['refund_date'] ?? '',
'refund_type' => $params['refund_type'] ?? 0,
'reason' => $params['reason'] ?? '',
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '',
'bank_account_id' => $params['bank_account_id'] ?? 0,
'is_calculate_interest' => $params['is_calculate_interest'] ?? 0,
'interest_calculation_start_date' => $params['interest_calculation_start_date'] ?? '',
'supplier_id' => $params['supplier_id'],
'project_id' => $contract['project_id'],
'contract_type' => $params['contract_cate'],
'contract_id' => $params['contract_id'],
'refund_amount' => $params['refund_amount'],
'refund_date' => strtotime($params['refund_date']),
'refund_type' => $params['refund_type'],
'reason' => $params['reason'] ?? '',
'remark' => $params['remark'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null,
'bank_account_id' => $params['bank_account_id'],
'update_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -124,15 +141,24 @@ class FinanceRefundRecordLogic extends BaseLogic
*/
public static function detail($params): array
{
$financeRefundRecord = FinanceRefundRecord::findOrEmpty($params['id']);
$financeRefundRecord->contract;
$financeRefundRecord->supplier = null;
$financeRefundRecord->project = null;
if (!empty($financeRefundRecord->contract->project_id)) {
$financeRefundRecord->project = $financeRefundRecord->contract->project;
unset($financeRefundRecord->contract->project);
}
$financeRefundRecord->annex = json_decode($financeRefundRecord->annex, true);
return $financeRefundRecord->toArray();
$data = FinanceRefundRecord::field('id,supplier_id,project_id,contract_type,contract_id,refund_amount,refund_date,refund_type,reason,remark,annex,bank_account_id')
->findOrEmpty($params['id']);
$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();
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['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;
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;
@ -31,13 +36,15 @@ class FinanceRefundRecordValidate extends BaseValidate
* @var string[]
*/
protected $rule = [
'id' => 'require',
'supplier_id' => 'require',
'contract_id' => 'require',
'refund_amount' => 'require',
'refund_date' => 'require',
'refund_type' => 'require',
'bank_account_id' => 'require',
'id' => 'require',
'supplier_id' => 'require|checkSupplier',
'contract_cate' => 'require|in:1,2',
'contract_id' => 'require|checkContract',
'refund_amount' => 'require|float|gt:0',
'refund_date' => 'require|dateFormat:Y-m-d',
'refund_type' => 'require|checkRefundType',
'annex' => 'checkAnnex',
'bank_account_id' => 'require|checkBankAccount',
];
@ -46,13 +53,14 @@ class FinanceRefundRecordValidate extends BaseValidate
* @var string[]
*/
protected $field = [
'id' => 'id',
'supplier_id' => '供应商id',
'contract_id' => '合同id',
'refund_amount' => '退款金额',
'refund_date' => '退款日期',
'refund_type' => '退款方式',
'bank_account_id' => '收款账户id',
'id' => 'id',
'supplier_id' => '供应商id',
'contract_cate' => '合同类型',
'contract_id' => '合同id',
'refund_amount' => '退款金额',
'refund_date' => '退款日期',
'refund_type' => '退款方式',
'bank_account_id' => '收款账户id',
];
@ -64,7 +72,7 @@ class FinanceRefundRecordValidate extends BaseValidate
*/
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
*/
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']);
}
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\dict\DictData;
use think\model\concern\SoftDelete;
@ -29,9 +30,24 @@ class FinanceRefundRecord extends BaseModel
use SoftDelete;
protected $name = 'finance_refund_record';
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 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']];
}
}