173 lines
7.0 KiB
PHP
173 lines
7.0 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\logic\finance;
|
||
|
||
|
||
use app\common\model\contract\ProcurementContract;
|
||
use app\common\model\contract\SubcontractingContract;
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\finance\FinanceReceiptRecord;
|
||
use app\common\model\project\Project;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\supplier\Supplier;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* FinanceReceiptRecord逻辑
|
||
* Class FinanceReceiptRecordLogic
|
||
* @package app\adminapi\logic\finance
|
||
*/
|
||
class FinanceReceiptRecordLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/15 10:20
|
||
*/
|
||
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;
|
||
}
|
||
$tax_rate = DictData::where('type_value','tax_rate')->column('name','value');
|
||
Db::startTrans();
|
||
try {
|
||
FinanceReceiptRecord::create([
|
||
'supplier_id' => $params['supplier_id'],
|
||
'project_id' => $contract['project_id'],
|
||
'contract_id' => $params['contract_id'],
|
||
'contract_type' => $params['contract_cate'],
|
||
'invoicing_date' => strtotime($params['invoicing_date']),
|
||
'commitor' => $params['commitor'] ?? '',
|
||
'invoice_type' => $params['invoice_type'],
|
||
'invoice_no' => $params['invoice_no'] ?? '',
|
||
'invoice_amount' => $params['invoice_amount'],
|
||
'invoice_tax_rate' => $params['invoice_tax_rate'],
|
||
'tax_amount' => $params['invoice_amount'] * ($tax_rate[$params['invoice_tax_rate']] / 100),
|
||
'amount_excluding_tax' => $params['invoice_amount'] * (1 - $tax_rate[$params['invoice_tax_rate']] / 100),
|
||
'receipt_date' => strtotime($params['receipt_date']),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
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/15 10:20
|
||
*/
|
||
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;
|
||
}
|
||
$tax_rate = DictData::where('type_value','tax_rate')->column('name','value');
|
||
Db::startTrans();
|
||
try {
|
||
FinanceReceiptRecord::where('id', $params['id'])->update([
|
||
'supplier_id' => $params['supplier_id'],
|
||
'project_id' => $contract['project_id'],
|
||
'contract_id' => $params['contract_id'],
|
||
'contract_type' => $params['contract_cate'],
|
||
'invoicing_date' => strtotime($params['invoicing_date']),
|
||
'commitor' => $params['commitor'] ?? '',
|
||
'invoice_type' => $params['invoice_type'],
|
||
'invoice_no' => $params['invoice_no'] ?? '',
|
||
'invoice_amount' => $params['invoice_amount'],
|
||
'invoice_tax_rate' => $params['invoice_tax_rate'],
|
||
'tax_amount' => $params['invoice_amount'] * ($tax_rate[$params['invoice_tax_rate']] / 100),
|
||
'amount_excluding_tax' => $params['invoice_amount'] * (1 - $tax_rate[$params['invoice_tax_rate']] / 100),
|
||
'receipt_date' => strtotime($params['receipt_date']),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
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/15 10:20
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return FinanceReceiptRecord::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/15 10:20
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = FinanceReceiptRecord::field('id,supplier_id,project_id,contract_id,contract_type,invoicing_date,commitor,invoice_type,invoice_no,invoice_amount,invoice_tax_rate,tax_amount,amount_excluding_tax,receipt_date,remark,annex')
|
||
->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'];
|
||
$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();
|
||
}
|
||
} |