This commit is contained in:
weiz 2024-01-10 14:33:44 +08:00
parent e70b862de0
commit 555a1166dd
3 changed files with 141 additions and 0 deletions

View File

@ -58,6 +58,22 @@ class ProcurementContractController extends BaseAdminController
}
return $this->fail(ProcurementContractLogic::getError());
}
/**
* @notes 编辑采购合同
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/02 17:19
*/
public function edit()
{
$params = (new ProcurementContractValidate())->post()->goCheck('edit');
$result = ProcurementContractLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProcurementContractLogic::getError());
}
/**
* @notes 获取采购合同详情

View File

@ -120,6 +120,117 @@ class ProcurementContractLogic extends BaseLogic
}
}
/**
* @notes 编辑采购合同
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/02 17:19
*/
public static function edit(array $params): bool
{
//采购合同明细
$procurement_contract_detail = json_decode($params['procurement_contract_detail'],true);
//付款计划
$payment_plan = json_decode($params['payment_plan'],true);
//税率字典值
$tax_rate_dict = DictData::where('type_value','tax_rate')->column('name','value');
//合同金额\不含税金额
$contract_amount = 0;
$amount_excluding_tax = 0;
foreach($procurement_contract_detail as $v){
$contract_amount += $v['price']*$v['num'];
$amount_excluding_tax += $v['num'] * $v['price'] * (1- $tax_rate_dict[$v['tax_rate']] / 100);
}
Db::startTrans();
try {
$procurementContract = ProcurementContract::where('id',$params['id'])->update([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'supplier_id' => $params['supplier_id'],
'project_id' => $params['project_id'],
'contract_no' => data_unique_code('CGHT'),
'contract_name' => $params['contract_name'],
'contract_type' => $params['contract_type'],
'signing_date' => strtotime($params['signing_date']),
'pay_type' => $params['pay_type'],
'account_period' => $params['account_period'],
//合同金额
'contract_amount' => $contract_amount,
//不含税金额
'amount_excluding_tax' => $amount_excluding_tax,
//质保金
'retention_money' => $contract_amount * ($params['retention_money_rate'] / 100),
//质保金比例
'retention_money_rate' => $params['retention_money_rate'],
'remark' => $params['remark'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null
]);
foreach ($procurement_contract_detail as $v)
{
if(isset($v['id']) && $v != ''){
ProcurementContractDetail::where('id',$v['id'])->update([
'contract_id' => $params['id'],
'material_purchase_request_detail_id' => $v['material_purchase_request_detail_id'],
'num' => $v['num'],
'price' => $v['price'],
'tax_rate' => $v['tax_rate'],
//不含税金额
'amount_excluding_tax' => $v['num'] * $v['price'] * (1- $tax_rate_dict[$v['tax_rate']] / 100),
//含税金额
'amount_including_tax' => $v['num'] * $v['price'],
]);
}else{
ProcurementContractDetail::create([
'contract_id' => $params['id'],
'material_purchase_request_detail_id' => $v['material_purchase_request_detail_id'],
'num' => $v['num'],
'price' => $v['price'],
'tax_rate' => $v['tax_rate'],
//不含税金额
'amount_excluding_tax' => $v['num'] * $v['price'] * (1- $tax_rate_dict[$v['tax_rate']] / 100),
//含税金额
'amount_including_tax' => $v['num'] * $v['price'],
]);
}
}
foreach ($payment_plan as $v)
{
if(isset($v['id']) && $v != ''){
FinancePaymentPlan::where('id',$v['id'])->update([
'supplier_id' => $params['supplier_id'],
'project_id' => $params['project_id'],
'contract_id' => $params['id'],
'contract_type' => 1,
'period' => $v['period'],
'pay_date' => strtotime($v['pay_date']),
'amount' => $v['amount'],
'status' => 1,
'remark' => $v['remark'] ?? '',
]);
}else{
FinancePaymentPlan::create([
'supplier_id' => $params['supplier_id'],
'project_id' => $params['project_id'],
'contract_id' => $params['id'],
'contract_type' => 1,
'period' => $v['period'],
'pay_date' => strtotime($v['pay_date']),
'amount' => $v['amount'],
'status' => 1,
'remark' => $v['remark'] ?? '',
]);
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 获取采购合同详情

View File

@ -15,9 +15,11 @@
namespace app\adminapi\validate\contract;
use app\common\model\contract\ProcurementContractDetail;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\dict\DictData;
use app\common\model\finance\FinancePaymentPlan;
use app\common\model\material\MaterialPurchaseRequestDetail;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
@ -207,6 +209,12 @@ class ProcurementContractValidate extends BaseValidate
return '采购合同明细数据格式错误';
}
foreach($detail as $v) {
if(isset($v['id']) && $v['id'] != ''){
$data_detail = ProcurementContractDetail::where('id',$v['id'])->findOrEmpty();
if($data_detail->isEmpty()){
return '采购合同明细信息不存在';
}
}
if(empty($v['material_purchase_request_detail_id'])){
return '请选择采购申请明细信息';
}else{
@ -248,6 +256,12 @@ class ProcurementContractValidate extends BaseValidate
return '付款计划据格式错误';
}
foreach($detail as $v) {
if(isset($v['id']) && $v['id'] != ''){
$data_detail = FinancePaymentPlan::where('id',$v['id'])->findOrEmpty();
if($data_detail->isEmpty()){
return '付款计划信息不存在';
}
}
if(empty($v['period'])){
return '请选择期次';
}else{