133 lines
4.8 KiB
PHP
133 lines
4.8 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\project;
|
||
|
||
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\project\ProjectTravelReimbursement;
|
||
use app\common\model\project\ProjectTravelReimbursementInvoiceDetail;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 发票明细逻辑
|
||
* Class ProjectTravelReimbursementInvoiceDetailLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectTravelReimbursementInvoiceDetailLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加发票明细
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/18 13:57
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
//获取税率
|
||
$tax_rate = DictData::where('type_value','tax_rate')->column('name','value');
|
||
Db::startTrans();
|
||
try {
|
||
ProjectTravelReimbursementInvoiceDetail::create([
|
||
'travel_reimbursement_id' => $params['travel_reimbursement_id'],
|
||
'invoice_type' => $params['invoice_type'],
|
||
'invoice_sn' => $params['invoice_sn'],
|
||
'tax_rate' => $params['tax_rate'],
|
||
'invoice_form' => $params['invoice_form'],
|
||
'invoice_amount' => $params['invoice_amount'],
|
||
'tax_amount' => $tax_rate[$params['tax_rate']] / 100 * $params['invoice_amount'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'remark' => $params['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 2024/01/18 13:57
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
//获取税率
|
||
$tax_rate = DictData::where('type_value','tax_rate')->column('name','value');
|
||
Db::startTrans();
|
||
try {
|
||
ProjectTravelReimbursementInvoiceDetail::where('id', $params['id'])->update([
|
||
'travel_reimbursement_id' => $params['travel_reimbursement_id'],
|
||
'invoice_type' => $params['invoice_type'],
|
||
'invoice_sn' => $params['invoice_sn'],
|
||
'tax_rate' => $params['tax_rate'],
|
||
'invoice_form' => $params['invoice_form'],
|
||
'invoice_amount' => $params['invoice_amount'],
|
||
'tax_amount' => $tax_rate[$params['tax_rate']] / 100 * $params['invoice_amount'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'remark' => $params['remark'] ?? '',
|
||
'update_time' => time(),
|
||
]);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除发票明细
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/18 13:57
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectTravelReimbursementInvoiceDetail::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取发票明细详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/18 13:57
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectTravelReimbursementInvoiceDetail::field('id,travel_reimbursement_id,invoice_type,invoice_sn,tax_rate,invoice_form,invoice_amount,tax_amount,annex,remark')->findOrEmpty($params['id']);
|
||
$travel_reimbursement = ProjectTravelReimbursement::field('trip_reimbursement_code')->where('id',$data['travel_reimbursement_id'])->findOrEmpty();
|
||
$data['trip_reimbursement_code'] = $travel_reimbursement['trip_reimbursement_code'];
|
||
$data['invoice_type_text'] = $data->invoice_type_text;
|
||
$data['tax_rate_text'] = $data->tax_rate_text;
|
||
$data['invoice_form_text'] = $data->invoice_form_text;
|
||
return $data->toArray();
|
||
}
|
||
} |