Merge pull request 'update' (#161) from zhangwei into dev
Reviewed-on: #161
This commit is contained in:
commit
8a54d6b581
@ -16,9 +16,9 @@
|
||||
namespace app\adminapi\controller\finance;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\finance\FinanceReceiptRecordLists;
|
||||
use app\adminapi\logic\finance\FinanceReceiptRecordLogic;
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\finance\FinanceReceiptRecordLists;
|
||||
use app\adminapi\logic\finance\FinanceReceiptRecordLogic;
|
||||
use app\adminapi\validate\finance\FinanceReceiptRecordValidate;
|
||||
|
||||
|
||||
|
@ -16,8 +16,12 @@ namespace app\adminapi\lists\finance;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\contract\ProcurementContract;
|
||||
use app\common\model\contract\SubcontractingContract;
|
||||
use app\common\model\finance\FinanceReceiptRecord;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -39,7 +43,8 @@ class FinanceReceiptRecordLists extends BaseAdminDataLists implements ListsSearc
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['frr.supplier_id', 'frr.contract_id', 'frr.commitor', 'frr.invoice_type', 'frr.invoice_no'],
|
||||
'=' => ['supplier_id', 'project_id', 'contract_id', 'contract_type', 'invoice_type'],
|
||||
'%like%' => ['commitor','invoice_no'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -55,19 +60,27 @@ class FinanceReceiptRecordLists extends BaseAdminDataLists implements ListsSearc
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Db::name('FinanceReceiptRecord')->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 FinanceReceiptRecord::where($this->searchWhere)
|
||||
->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')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['frr.id' => 'desc'])
|
||||
->select()->each(function($item, $key){
|
||||
//关联数据后续添加
|
||||
$item['supplier_name'] = '供应商名称';
|
||||
$item['contract_type'] = '1';
|
||||
return $item;
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$data['invoice_type_text'] = $data->invoice_type_text;
|
||||
$data['invoice_tax_rate_text'] = $data->invoice_tax_rate_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();
|
||||
}
|
||||
|
@ -15,9 +15,13 @@
|
||||
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;
|
||||
|
||||
|
||||
@ -39,25 +43,34 @@ class FinanceReceiptRecordLogic 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;
|
||||
}
|
||||
$tax_rate = DictData::where('type_value','tax_rate')->column('name','value');
|
||||
Db::startTrans();
|
||||
try {
|
||||
FinanceReceiptRecord::create([
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'contract_id' => $params['contract_id'] ?? 0,
|
||||
'invoicing_date' => $params['invoicing_date'] ?? '',
|
||||
'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'] ?? 0,
|
||||
'invoice_type' => $params['invoice_type'],
|
||||
'invoice_no' => $params['invoice_no'] ?? '',
|
||||
'invoice_amount' => $params['invoice_amount'] ?? 0,
|
||||
'invoice_amount_daxie' => $params['invoice_amount_daxie'] ?? '',
|
||||
'invoice_tax_rate' => $params['invoice_tax_rate'] ?? 0,
|
||||
'tax' => $params['tax'] ?? 0,
|
||||
'amount_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||||
'receipt_date' => $params['receipt_date'] ?? '',
|
||||
'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'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -77,25 +90,34 @@ class FinanceReceiptRecordLogic 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;
|
||||
}
|
||||
$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'] ?? 0,
|
||||
'contract_id' => $params['contract_id'] ?? 0,
|
||||
'invoicing_date' => $params['invoicing_date'] ?? '',
|
||||
'commitor' => $params['commitor'] ?? '',
|
||||
'invoice_type' => $params['invoice_type'] ?? 0,
|
||||
'invoice_no' => $params['invoice_no'] ?? '',
|
||||
'invoice_amount' => $params['invoice_amount'] ?? 0,
|
||||
'invoice_amount_daxie' => $params['invoice_amount_daxie'] ?? '',
|
||||
'invoice_tax_rate' => $params['invoice_tax_rate'] ?? 0,
|
||||
'tax' => $params['tax'] ?? 0,
|
||||
'amount_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||||
'receipt_date' => $params['receipt_date'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'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' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -128,13 +150,23 @@ class FinanceReceiptRecordLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$financeReceiptRecord = FinanceReceiptRecord::findOrEmpty($params['id']);
|
||||
$financeReceiptRecord->contract;
|
||||
$financeReceiptRecord->project = null;
|
||||
if (!empty($financeReceiptRecord->contract->project_id)) {
|
||||
$financeReceiptRecord->project = Project::findOrEmpty($financeReceiptRecord->contract->project_id);
|
||||
}
|
||||
$financeReceiptRecord->annex = json_decode($financeReceiptRecord->annex, true);
|
||||
return $financeReceiptRecord->toArray();
|
||||
$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;
|
||||
$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();
|
||||
}
|
||||
}
|
@ -14,7 +14,10 @@
|
||||
|
||||
namespace app\adminapi\validate\finance;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@ -32,8 +35,15 @@ class FinanceReceiptRecordValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'supplier_id' => 'require',
|
||||
'contract_id' => 'require',
|
||||
'supplier_id' => 'require|checkSupplier',
|
||||
'contract_cate' => 'require|in:1,2',
|
||||
'contract_id' => 'require|checkContract',
|
||||
'invoicing_date' => 'require|dateFormat:Y-m-d',
|
||||
'invoice_type' => 'require|checkInvoiceType',
|
||||
'invoice_amount' => 'require|float|gt:0',
|
||||
'invoice_tax_rate' => 'require|checkInvoiceTaxRate',
|
||||
'receipt_date' => 'require|dateFormat:Y-m-d',
|
||||
'annex' => 'checkAnnex',
|
||||
];
|
||||
|
||||
|
||||
@ -43,6 +53,14 @@ class FinanceReceiptRecordValidate extends BaseValidate
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'supplier_id' => '供应商id',
|
||||
'contract_cate' => '合同类型',
|
||||
'contract_id' => '合同id',
|
||||
'invoicing_date' => '开票日期',
|
||||
'invoice_type' => '发票类型',
|
||||
'invoice_amount' => '发票金额',
|
||||
'invoice_tax_rate' => '发票税率',
|
||||
'receipt_date' => '收票日期',
|
||||
];
|
||||
|
||||
|
||||
@ -65,9 +83,7 @@ class FinanceReceiptRecordValidate extends BaseValidate
|
||||
* @date 2023/12/15 10:20
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'supplier_id', 'contract_id']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -92,5 +108,61 @@ class FinanceReceiptRecordValidate 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 checkInvoiceType($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','invoice_type')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '发票类型无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkInvoiceTaxRate($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','tax_rate')->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;
|
||||
}
|
||||
|
||||
}
|
@ -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,34 @@ class FinanceReceiptRecord extends BaseModel
|
||||
use SoftDelete;
|
||||
protected $name = 'finance_receipt_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 getInvoicingDateAttr($value): string
|
||||
{
|
||||
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||
}
|
||||
|
||||
public function getReceiptDateAttr($value): string
|
||||
{
|
||||
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||
}
|
||||
|
||||
public function getInvoiceTypeTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','invoice_type')->column('name','value');
|
||||
return $dict[$data['invoice_type']];
|
||||
}
|
||||
|
||||
public function getInvoiceTaxRateTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','tax_rate')->column('name','value');
|
||||
return $dict[$data['invoice_tax_rate']];
|
||||
}
|
||||
|
||||
public function getContractTypeTextAttr($value,$data): string
|
||||
{
|
||||
$type = [1=>'采购合同',2=>'分包合同'];
|
||||
return $type[$data['contract_type']];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user