新增分包合同
This commit is contained in:
parent
a3212c907c
commit
7d43b5393b
@ -16,9 +16,9 @@
|
||||
namespace app\adminapi\controller\contract;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\contract\SubcontractingContractLists;
|
||||
use app\adminapi\logic\contract\SubcontractingContractLogic;
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\contract\SubcontractingContractLists;
|
||||
use app\adminapi\logic\contract\SubcontractingContractLogic;
|
||||
use app\adminapi\validate\contract\SubcontractingContractValidate;
|
||||
|
||||
|
||||
@ -75,21 +75,7 @@ class SubcontractingContractController extends BaseAdminController
|
||||
}
|
||||
return $this->fail(SubcontractingContractLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/12 17:15
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new SubcontractingContractValidate())->post()->goCheck('delete');
|
||||
SubcontractingContractLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
|
@ -43,54 +43,6 @@ class SubcontractingContractDetailController extends BaseAdminController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加分包合同-分包明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/28 22:08
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new SubcontractingContractDetailValidate())->post()->goCheck('add');
|
||||
$result = SubcontractingContractDetailLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(SubcontractingContractDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑分包合同-分包明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/28 22:08
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new SubcontractingContractDetailValidate())->post()->goCheck('edit');
|
||||
$result = SubcontractingContractDetailLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(SubcontractingContractDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除分包合同-分包明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/28 22:08
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new SubcontractingContractDetailValidate())->post()->goCheck('delete');
|
||||
SubcontractingContractDetailLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包合同-分包明细详情
|
||||
* @return \think\response\Json
|
||||
|
@ -17,9 +17,10 @@ namespace app\adminapi\lists\contract;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\contract\SubcontractingContract;
|
||||
use app\common\model\contract\ProcurementContract;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use think\facade\Db;
|
||||
use app\common\model\contract\SubcontractingContractDetail;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\supplier\Supplier;
|
||||
|
||||
|
||||
/**
|
||||
@ -40,20 +41,11 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['pc.project_id', 'pc.contract_no', 'pc.contract_name', 'pc.supplier_id', 'pc.contract_type'],
|
||||
'=' => ['supplier_id', 'project_id'],
|
||||
'%like%' => ['contract_no']
|
||||
];
|
||||
}
|
||||
|
||||
public function querySearch(): array
|
||||
{
|
||||
$queryWhere = [];
|
||||
$queryWhere['pc.contract_cate'] = 2;
|
||||
if (!empty($this->params['all'])) {
|
||||
unset($queryWhere['contract_cate']);
|
||||
}
|
||||
return $queryWhere;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
@ -65,29 +57,35 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Db::name('ProcurementContract')->alias('pc')
|
||||
->where($this->searchWhere)->where($this->querySearch())
|
||||
->whereNull('pc.delete_time')
|
||||
->leftJoin('project p','p.id = pc.project_id')
|
||||
->field('pc.*, p.name as project_name, p.project_code')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['pc.id' => 'desc'])
|
||||
->select()->each(function($item, $key){
|
||||
$item['signing_date'] = date('Y-m-d',$item['signing_date']);
|
||||
//关联数据后续添加
|
||||
$item['supplier_name'] = '供应商名称';
|
||||
$item['approve_no'] = '付款单号';
|
||||
$item['approve_step'] = '流程步骤';
|
||||
$item['approve_settle_status'] = 1;
|
||||
if (!empty($item['pay_plan'])) {
|
||||
$otherContactsArray = json_decode($item['pay_plan'], true);
|
||||
if (is_array($otherContactsArray)) {
|
||||
$item['pay_plan'] = $otherContactsArray;
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
return SubcontractingContract::where($this->searchWhere)
|
||||
->field('id,project_id,supplier_id,contract_no,contract_name,contract_type,signing_date,contract_amount')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['supplier_name'] = $supplier['supplier_name'];
|
||||
$data['supplier_code'] = $supplier['supplier_code'];
|
||||
$data['contract_type'] = $data->contract_type_text;
|
||||
//不含税金额
|
||||
$data['excluding_tax_amount'] = SubcontractingContractDetail::where('contract_id',$data['id'])->sum('amount_excluding_tax');
|
||||
//已付款金额
|
||||
$data['has_pay_amount'] = 0;
|
||||
//未付款金额
|
||||
$data['not_pay_amount'] = $data['contract_amount'] - $data['has_pay_amount'];
|
||||
//已开票金额
|
||||
$data['has_invoice_amount'] = 0;
|
||||
//未开票金额
|
||||
$data['not_invoice_amount'] = $data['contract_amount'] - $data['has_invoice_amount'];
|
||||
//退款金额
|
||||
$data['refund_amount'] = 0;
|
||||
//结算差异
|
||||
$data['settlement_difference'] = 0;
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@ -99,10 +97,7 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Db::name('ProcurementContract')->alias('pc')
|
||||
->where($this->searchWhere)->where($this->querySearch())
|
||||
->whereNull('pc.delete_time')
|
||||
->leftJoin('project p','p.id = pc.project_id')->count();
|
||||
return SubcontractingContract::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ namespace app\adminapi\lists\project;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\contract\SubcontractingContractDetail;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectSubpackageBudget;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
@ -67,7 +68,7 @@ class ProjectSubpackageBudgetDetailLists extends BaseAdminDataLists implements L
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['subpackage_budget_code'] = $subpackage_budget['subpackage_budget_code'];
|
||||
//已分包工作量
|
||||
$data['has_subcontract_num'] = 0;
|
||||
$data['has_subcontract_num'] = SubcontractingContractDetail::where('subpackage_budget_detail_id',$data['id'])->sum('num');
|
||||
//剩余工作量
|
||||
$data['residue_num'] = $data['num'] - $data['has_subcontract_num'];
|
||||
return $data;
|
||||
|
@ -16,6 +16,7 @@ namespace app\adminapi\lists\project;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\contract\SubcontractingContractDetail;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectSubpackageBudget;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
@ -69,7 +70,8 @@ class ProjectSubpackageBudgetLists extends BaseAdminDataLists implements ListsSe
|
||||
//预算总金额
|
||||
$data['total_amount'] = ProjectSubpackageBudgetDetail::where('subpackage_budget_id',$data['id'])->sum('amount');
|
||||
//已分包工作量
|
||||
$data['has_subcontract_num'] = 0;
|
||||
$project_subpackage_budget_detail_ids = ProjectSubpackageBudgetDetail::where('subpackage_budget_id',$data['id'])->column('id');
|
||||
$data['has_subcontract_num'] = SubcontractingContractDetail::where('subpackage_budget_detail_id','in',$project_subpackage_budget_detail_ids)->sum('num');
|
||||
//剩余工作量
|
||||
$data['residue_num'] = $data['total_num'] - $data['has_subcontract_num'];
|
||||
return $data;
|
||||
|
@ -145,12 +145,11 @@ class ProcurementContractLogic extends BaseLogic
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$procurementContract = ProcurementContract::where('id',$params['id'])->update([
|
||||
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']),
|
||||
|
@ -15,8 +15,13 @@
|
||||
namespace app\adminapi\logic\contract;
|
||||
|
||||
|
||||
use app\common\model\contract\ProcurementContract;
|
||||
use app\common\model\contract\SubcontractingContract;
|
||||
use app\common\model\contract\SubcontractingContractDetail;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -113,6 +118,21 @@ class SubcontractingContractDetailLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return SubcontractingContractDetail::findOrEmpty($params['id'])->toArray();
|
||||
$data = SubcontractingContractDetail::field('id,contract_id,subpackage_budget_detail_id,num,price,tax_rate,amount_excluding_tax,amount_including_tax,remark')->findOrEmpty($params['id']);
|
||||
$contract = SubcontractingContract::field('contract_no,project_id,supplier_id,contract_type')->where('id',$data['contract_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$contract['project_id'])->findOrEmpty();
|
||||
$supplier = Supplier::field('supplier_code,supplier_name')->where('id',$contract['supplier_id'])->findOrEmpty();
|
||||
$subpackage_budget_detail = ProjectSubpackageBudgetDetail::field('work_type,work_content,project_features,unit')->where('id',$data['subpackage_budget_detail_id'])->findOrEmpty();
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['supplier_code'] = $supplier['supplier_code'];
|
||||
$data['supplier_name'] = $supplier['supplier_name'];
|
||||
$data['contract_no'] = $contract['contract_no'];
|
||||
$data['contract_type'] = $contract->contract_type_text;
|
||||
$data['work_type'] = $subpackage_budget_detail['work_type'];
|
||||
$data['work_content'] = $subpackage_budget_detail['work_content'];
|
||||
$data['project_features'] = $subpackage_budget_detail['project_features'];
|
||||
$data['unit'] = $subpackage_budget_detail['unit'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -16,10 +16,15 @@ namespace app\adminapi\logic\contract;
|
||||
|
||||
|
||||
use app\common\model\contract\SubcontractingContract;
|
||||
use app\common\model\contract\ProcurementContract;
|
||||
use app\common\model\contract\SubcontractingContractDetail;
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\logic\BaseLogic;
|
||||
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\project\Project;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -41,51 +46,79 @@ class SubcontractingContractLogic extends BaseLogic
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$subcontractingContract = ProcurementContract::create([
|
||||
'org_id' => $params['org_id'] ?? 0,
|
||||
'dept_id' => $params['dept_id'] ?? 0,
|
||||
'project_id' => $params['project_id'] ?? 0,
|
||||
'approve_id' => $params['approve_id'] ?? 0,
|
||||
'contract_cate' => 2,
|
||||
'contract_no' => $params['contract_no'] ?? '',
|
||||
'contract_name' => $params['contract_name'] ?? '',
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'contract_type' => $params['contract_type'] ?? 0,
|
||||
'signing_date' => strtotime($params['signing_date']),
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'account_period' => $params['account_period'] ?? 0,
|
||||
'amount' => $params['amount'] ?? 0,
|
||||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||||
'tax_rate' => $params['tax_rate'] ?? 0,
|
||||
'amount_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||||
'retention_money_rate' => $params['retention_money_rate'] ?? '',
|
||||
'retention_money' => $params['retention_money'] ?? 0,
|
||||
'pay_plan' => empty($params['pay_plan']) ? [] : json_encode($params['pay_plan']),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
]);
|
||||
SubcontractingContractDetail::where('subcontracting_contract_id', $subcontractingContract->id)->update(['delete_time' =>time()]);
|
||||
foreach ($params['work'] ?? [] as $item)
|
||||
{
|
||||
SubcontractingContractDetail::create([
|
||||
'subcontracting_contract_id' => $subcontractingContract->id,
|
||||
'subcontracting_budget_id' => $item['subcontracting_budget_id'] ?? 0,
|
||||
'workload' => $item['workload'] ?? '',
|
||||
'unit_price_including_tax' => $item['unit_price_including_tax'] ?? 0,
|
||||
'amount_excluding_tax' => $item['amount_excluding_tax'] ?? 0,
|
||||
'amount_including_tax' => $item['amount_including_tax'] ?? 0,
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
//分包合同明细
|
||||
$subcontracting_contract_detail = json_decode($params['subcontracting_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($subcontracting_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 {
|
||||
$res = SubcontractingContract::create([
|
||||
'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('FBHT'),
|
||||
'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 ($subcontracting_contract_detail as $v)
|
||||
{
|
||||
SubcontractingContractDetail::create([
|
||||
'contract_id' => $res->id,
|
||||
'subpackage_budget_detail_id' => $v['subpackage_budget_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'],
|
||||
'remark' => $v['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
foreach ($payment_plan as $v)
|
||||
{
|
||||
FinancePaymentPlan::create([
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'contract_id' => $res->id,
|
||||
'contract_type' => 2,
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -98,66 +131,109 @@ class SubcontractingContractLogic extends BaseLogic
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProcurementContract::where('id', $params['id'])->update([
|
||||
'org_id' => $params['org_id'] ?? 0,
|
||||
'dept_id' => $params['dept_id'] ?? 0,
|
||||
'project_id' => $params['project_id'] ?? 0,
|
||||
'approve_id' => $params['approve_id'] ?? 0,
|
||||
'contract_cate' => 2,
|
||||
'contract_no' => $params['contract_no'] ?? '',
|
||||
'contract_name' => $params['contract_name'] ?? '',
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'contract_type' => $params['contract_type'] ?? 0,
|
||||
'signing_date' => strtotime($params['signing_date']),
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'account_period' => $params['account_period'] ?? 0,
|
||||
'amount' => $params['amount'] ?? 0,
|
||||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||||
'tax_rate' => $params['tax_rate'] ?? 0,
|
||||
'amount_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||||
'retention_money_rate' => $params['retention_money_rate'] ?? '',
|
||||
'retention_money' => $params['retention_money'] ?? 0,
|
||||
'pay_plan' => empty($params['pay_plan']) ? [] : json_encode($params['pay_plan']),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
]);
|
||||
SubcontractingContractDetail::where('subcontracting_contract_id', $params['id'])->update(['delete_time' =>time()]);
|
||||
foreach ($params['work'] ?? [] as $item)
|
||||
{
|
||||
SubcontractingContractDetail::create([
|
||||
'subcontracting_contract_id' => $params['id'],
|
||||
'subcontracting_budget_id' => $item['subcontracting_budget_id'] ?? 0,
|
||||
'workload' => $item['workload'] ?? '',
|
||||
'unit_price_including_tax' => $item['unit_price_including_tax'] ?? 0,
|
||||
'amount_excluding_tax' => $item['amount_excluding_tax'] ?? 0,
|
||||
'amount_including_tax' => $item['amount_including_tax'] ?? 0,
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2023/12/12 17:15
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
SubcontractingContractDetail::where('subcontracting_contract_id', $params['id'])->update(['delete_time' =>time()]);
|
||||
return ProcurementContract::destroy($params['id']);
|
||||
//分包合同明细
|
||||
$subcontracting_contract_detail = json_decode($params['subcontracting_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($subcontracting_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 {
|
||||
SubcontractingContract::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_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 ($subcontracting_contract_detail as $v)
|
||||
{
|
||||
if(isset($v['id']) && $v != ''){
|
||||
SubcontractingContractDetail::where('id',$v['id'])->update([
|
||||
'contract_id' => $params['id'],
|
||||
'subpackage_budget_detail_id' => $v['subpackage_budget_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'],
|
||||
'remark' => $v['remark'] ?? '',
|
||||
]);
|
||||
}else{
|
||||
SubcontractingContractDetail::create([
|
||||
'contract_id' => $params['id'],
|
||||
'subpackage_budget_detail_id' => $v['subpackage_budget_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'],
|
||||
'remark' => $v['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
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' => 2,
|
||||
'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' => 2,
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -169,18 +245,20 @@ class SubcontractingContractLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$subcontractingContract = ProcurementContract::findOrEmpty($params['id']);
|
||||
$subcontractingContract->supplier = null;
|
||||
$subcontractingContract->custom = null;
|
||||
if (!empty($subcontractingContract->project->custom_id)) {
|
||||
$subcontractingContract->custom = Custom::findOrEmpty($subcontractingContract->project->custom_id);
|
||||
}
|
||||
$subcontractingContract->pay_plan = json_decode($subcontractingContract->pay_plan, true);
|
||||
$subcontractingContract->project;
|
||||
$subcontractingContract->work;
|
||||
$subcontractingContract->org;
|
||||
$subcontractingContract->dept;
|
||||
$subcontractingContract->annex = json_decode($subcontractingContract->annex, true);
|
||||
return $subcontractingContract->toArray();
|
||||
$data = SubcontractingContract::findOrEmpty($params['id']);
|
||||
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
|
||||
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
|
||||
$data['org_name'] = $org['name'];
|
||||
$data['dept_name'] = $dept['name'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['supplier_name'] = $supplier['supplier_name'];
|
||||
$data['supplier_code'] = $supplier['supplier_code'];
|
||||
$data['contract_type'] = $data->contract_type_text;
|
||||
$data['pay_type'] = $data->pay_type_text;
|
||||
$data['account_period'] = $data->account_period_text;
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -14,7 +14,14 @@
|
||||
|
||||
namespace app\adminapi\validate\contract;
|
||||
|
||||
|
||||
use app\common\model\contract\SubcontractingContractDetail;
|
||||
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\project\Project;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
@ -31,23 +38,40 @@ class SubcontractingContractValidate extends BaseValidate
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'project_id' => 'require',
|
||||
'approve_id' => 'require',
|
||||
'supplier_id' => 'require',
|
||||
'contract_name' => 'require',
|
||||
'work' => 'require|array|checkWork',
|
||||
'pay_plan' => 'require|array|checkPlan',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'id' => 'require',
|
||||
'org_id' => 'require|checkOrg',
|
||||
'dept_id' => 'require|checkDept',
|
||||
'supplier_id' => 'require|checkSupplier',
|
||||
'project_id' => 'require|checkProject',
|
||||
'contract_name' => 'require',
|
||||
'contract_type' => 'require|checkContractType',
|
||||
'signing_date' => 'require|dateFormat:Y-m-d',
|
||||
'pay_type' => 'require|checkPayType',
|
||||
'account_period' => 'require|checkAccountPeriod',
|
||||
'retention_money_rate' => 'require|float|egt:0',
|
||||
'annex' => 'checkAnnex',
|
||||
'subcontracting_contract_detail' => 'require|checkSubcontractingContractDetail',
|
||||
'payment_plan' => 'require|checkPaymentPlan'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'org_id.require' => '请选择组织',
|
||||
'dept_id.require' => '请选择部门',
|
||||
'supplier_id.require' => '请选择供应商',
|
||||
'project_id.require' => '请选择项目',
|
||||
'contract_name.require' => '请填写合同名称',
|
||||
'contract_type.require' => '请选择合同类型',
|
||||
'signing_date.require' => '请选择签约日期',
|
||||
'signing_date.dateFormat' => '签约日期数据格式错误',
|
||||
'pay_type.require' => '请选择付款方式',
|
||||
'account_period.require' => '请选择账期',
|
||||
'retention_money_rate.require' => '请填写质保金比例',
|
||||
'retention_money_rate.float' => '质保金比例值必须是数字',
|
||||
'retention_money_rate.egt' => '质保金比例值必须大于等于0',
|
||||
'subcontracting_contract_detail.require' => '分包合同明细不能为空',
|
||||
'payment_plan.require' => '付款计划不能为空'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
@ -69,9 +93,7 @@ class SubcontractingContractValidate extends BaseValidate
|
||||
* @date 2023/12/12 17:15
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'project_id', 'approve_id', 'supplier_id', 'contract_name', 'work', 'pay_plan']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -96,41 +118,163 @@ class SubcontractingContractValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkWork($value, $rule, $data)
|
||||
{
|
||||
$firstData = $value[0] ?? [];
|
||||
if (empty($firstData['subcontracting_budget_id'])) {
|
||||
return '分包预算id不能为空!';
|
||||
}
|
||||
if (empty($firstData['workload'])) {
|
||||
return '工作量不能为空!';
|
||||
}
|
||||
if (empty($firstData['unit_price_including_tax'])) {
|
||||
return '含税单价不能为空!';
|
||||
}
|
||||
if (empty($firstData['amount_excluding_tax'])) {
|
||||
return '不含税金额不能为空!';
|
||||
}
|
||||
if (empty($firstData['amount_including_tax'])) {
|
||||
return '含税金额不能为空!';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkPlan($value, $rule, $data)
|
||||
{
|
||||
$firstData = $value[0] ?? [];
|
||||
if (empty($firstData['period'])) {
|
||||
return '付款期次不能为空!';
|
||||
}
|
||||
if (empty($firstData['pay_date'])) {
|
||||
return '付款日期不能为空!';
|
||||
}
|
||||
if (empty($firstData['pay_amount'])) {
|
||||
return '付款金额不能为空!';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function checkOrg($value): bool|string
|
||||
{
|
||||
$org = Orgs::where('id',$value)->findOrEmpty();
|
||||
if($org->isEmpty()){
|
||||
return '组织不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkDept($value,$rule,$data): bool|string
|
||||
{
|
||||
$dept = Dept::where('id',$value)->findOrEmpty();
|
||||
if($dept->isEmpty()){
|
||||
return '部门不存在';
|
||||
}
|
||||
if($dept['org_id'] != $data['org_id']){
|
||||
return '部门无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkSupplier($value): bool|string
|
||||
{
|
||||
$supplier = Supplier::where('id',$value)->findOrEmpty();
|
||||
if($supplier->isEmpty()){
|
||||
return '供应商信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkProject($value): bool|string
|
||||
{
|
||||
$project = Project::where('id',$value)->findOrEmpty();
|
||||
if($project->isEmpty()){
|
||||
return '项目信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkContractType($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','divide_contract_type')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '合同类型无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkPayType($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','pay_type')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '付款方式无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkAccountPeriod($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','account_period')->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 checkSubcontractingContractDetail($value): bool|string
|
||||
{
|
||||
$detail = json_decode($value,true);
|
||||
if(empty($detail) || !is_array($detail)){
|
||||
return '分包合同明细数据格式错误';
|
||||
}
|
||||
foreach($detail as $v) {
|
||||
if(isset($v['id']) && $v['id'] != ''){
|
||||
$data_detail = SubcontractingContractDetail::where('id',$v['id'])->findOrEmpty();
|
||||
if($data_detail->isEmpty()){
|
||||
return '分包合同明细信息不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['subpackage_budget_detail_id'])){
|
||||
return '请选择分包预算明细信息';
|
||||
}else{
|
||||
$subcontracting_budget_detail = ProjectSubpackageBudgetDetail::where('id',$v['subpackage_budget_detail_id'])->findOrEmpty();
|
||||
if($subcontracting_budget_detail->isEmpty()){
|
||||
return '分包预算明细信息不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['num'])){
|
||||
return '工作量不能为空';
|
||||
}else{
|
||||
if(!is_numeric($v['num']) || $v['num'] <= 0){
|
||||
return '工作量必须是大于0的数字';
|
||||
}
|
||||
}
|
||||
if(empty($v['price'])){
|
||||
return '含税单价不能为空';
|
||||
}else{
|
||||
if(!is_numeric($v['price']) || $v['price'] <= 0){
|
||||
return '含税单价必须是大于0的数字';
|
||||
}
|
||||
}
|
||||
if(empty($v['tax_rate'])){
|
||||
return '请选择税率';
|
||||
}else{
|
||||
$dict = DictData::where('type_value','tax_rate')->column('value');
|
||||
if(!in_array($v['tax_rate'],$dict)){
|
||||
return '税率无效';
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkPaymentPlan($value): bool|string
|
||||
{
|
||||
$detail = json_decode($value,true);
|
||||
if(empty($detail) || !is_array($detail)){
|
||||
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{
|
||||
$dict = DictData::where('type_value','pay_period')->column('value');
|
||||
if(!in_array($v['period'],$dict)){
|
||||
return '期次无效';
|
||||
}
|
||||
}
|
||||
if(empty($v['pay_date'])){
|
||||
return '请选择计划付款日期';
|
||||
}
|
||||
if(empty($v['amount'])){
|
||||
return '金额不能为空';
|
||||
}else{
|
||||
if(!is_numeric($v['amount']) || $v['amount'] <= 0){
|
||||
return '金额必须是大于0的数字';
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ namespace app\common\model\contract;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\dict\DictData;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
@ -29,20 +30,29 @@ class SubcontractingContract extends BaseModel
|
||||
use SoftDelete;
|
||||
protected $name = 'subcontracting_contract';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getSigningDateAttr($value)
|
||||
{
|
||||
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(\app\common\model\project\Project::class, 'project_id');
|
||||
}
|
||||
|
||||
public function work()
|
||||
{
|
||||
return $this->hasMany(\app\common\model\contract\SubcontractingContractDetail::class, 'subcontracting_contract_id', 'id');
|
||||
}
|
||||
|
||||
public function getSigningDateAttr($value): string
|
||||
{
|
||||
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value) : '';
|
||||
}
|
||||
|
||||
public function getContractTypeTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','divide_contract_type')->column('name','value');
|
||||
return $dict[$data['contract_type']];
|
||||
}
|
||||
|
||||
public function getPayTypeTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','pay_type')->column('name','value');
|
||||
return $dict[$data['pay_type']];
|
||||
}
|
||||
|
||||
public function getAccountPeriodTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','account_period')->column('name','value');
|
||||
return $dict[$data['account_period']];
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user