This commit is contained in:
weiz 2024-01-11 17:20:10 +08:00
parent ad6d5def3a
commit f9d16f2f2b
6 changed files with 202 additions and 103 deletions

View File

@ -16,9 +16,9 @@
namespace app\adminapi\controller\finance;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\finance\FinanceInvoiceApplyLists;
use app\adminapi\logic\finance\FinanceInvoiceApplyLogic;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\finance\FinanceInvoiceApplyLists;
use app\adminapi\logic\finance\FinanceInvoiceApplyLogic;
use app\adminapi\validate\finance\FinanceInvoiceApplyValidate;

View File

@ -74,7 +74,7 @@ class ContractLists extends BaseAdminDataLists implements ListsSearchInterface
$where[] = ['business_director','in',$business_director_ids];
}
if(isset($params['custom_id']) && $params['custom_id'] != ''){
$project_ids = Admin::where('custom_id','=',$params['custom_id'])->column('id');
$project_ids = Project::where('custom_id','=',$params['custom_id'])->column('id');
$where[] = ['project_id','in',$project_ids];
}
return Contract::where($this->searchWhere)->where($where)
@ -135,7 +135,7 @@ class ContractLists extends BaseAdminDataLists implements ListsSearchInterface
$where[] = ['business_director','in',$business_director_ids];
}
if(isset($params['custom_id']) && $params['custom_id'] != ''){
$project_ids = Admin::where('custom_id','=',$params['custom_id'])->column('id');
$project_ids = Project::where('custom_id','=',$params['custom_id'])->column('id');
$where[] = ['project_id','in',$project_ids];
}
return Contract::field('id')->where($this->searchWhere)->where($where)->count();

View File

@ -16,8 +16,13 @@ namespace app\adminapi\lists\finance;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\Contract;
use app\common\model\contract\ContractNegotiation;
use app\common\model\custom\Custom;
use app\common\model\finance\FinanceInvoiceApply;
use app\common\lists\ListsSearchInterface;
use app\common\model\finance\FinanceReturnedRecord;
use app\common\model\project\Project;
use think\facade\Db;
/**
@ -38,7 +43,7 @@ class FinanceInvoiceApplyLists extends BaseAdminDataLists implements ListsSearch
public function setSearch(): array
{
return [
'=' => ['fia.customer_id', 'fia.contract_id', 'fia.invoicing_company_name'],
'=' => ['project_id', 'contract_id'],
];
}
@ -54,22 +59,29 @@ class FinanceInvoiceApplyLists extends BaseAdminDataLists implements ListsSearch
*/
public function lists(): array
{
return Db::name('FinanceInvoiceApply')->alias('fia')
->where($this->searchWhere)
->whereNull('fia.delete_time')
->leftJoin('contract c','c.id = fia.contract_id')
->leftJoin('bid_buy_bidding_document bbbd','bbbd.id = c.buy_bidding_document_id')
->leftJoin('project p','p.id = bbbd.project_id')
->leftJoin('custom ct','ct.id = fia.customer_id')
->field('fia.*, bbbd.project_id, p.name as project_name, p.project_code, ct.name as customer_name')
$params = $this->request->get(['custom_id']);
$where = [];
if(isset($params['custom_id']) && $params['custom_id'] != ''){
$project_ids = Project::where('custom_id',$params['custom_id'])->column('id');
$where[] = ['project_id','in',$project_ids];
}
return FinanceInvoiceApply::where($this->searchWhere)->where($where)
->field('id,contract_id,project_id,invoicing_code,invoicing_date,period,tax_rate,invoice_type,invoicing_amount,tax_amount,amount_including_tax')
->limit($this->limitOffset, $this->limitLength)
->order(['fia.id' => 'desc'])
->select()->each(function($item, $key){
//关联数据后续添加
$item['approve_no'] = '付款单号';
$item['approve_step'] = '流程步骤';
$item['approve_settle_status'] = 1;
return $item;
->order(['id' => 'desc'])
->select()->each(function($data){
$project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$contract = Contract::field('contract_code,contract_name,amount')->where('id',$data['contract_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['custom_name'] = $custom['name'];
$data['contract_code'] = $contract['contract_code'];
$data['contract_name'] = $contract['contract_name'];
$data['period'] = $data->period_text;
$data['tax_rate'] = $data->tax_rate_text;
$data['invoice_type'] = $data->invoice_type_text;
return $data;
})
->toArray();
}
@ -83,13 +95,13 @@ class FinanceInvoiceApplyLists extends BaseAdminDataLists implements ListsSearch
*/
public function count(): int
{
return Db::name('FinanceInvoiceApply')->alias('fia')
->where($this->searchWhere)
->whereNull('fia.delete_time')
->leftJoin('contract c','c.id = fia.contract_id')
->leftJoin('bid_buy_bidding_document bbbd','bbbd.id = c.buy_bidding_document_id')
->leftJoin('project p','p.id = bbbd.project_id')
->leftJoin('custom ct','ct.id = fia.customer_id')->count();
$params = $this->request->get(['custom_id']);
$where = [];
if(isset($params['custom_id']) && $params['custom_id'] != ''){
$project_ids = Project::where('custom_id',$params['custom_id'])->column('id');
$where[] = ['project_id','in',$project_ids];
}
return FinanceInvoiceApply::where($this->searchWhere)->where($where)->count();
}
}

View File

@ -15,8 +15,12 @@
namespace app\adminapi\logic\finance;
use app\common\model\contract\Contract;
use app\common\model\contract\ContractNegotiation;
use app\common\model\dict\DictData;
use app\common\model\finance\FinanceInvoiceApply;
use app\common\logic\BaseLogic;
use app\common\model\finance\FinanceReturnedRecord;
use app\common\model\project\Project;
use app\common\model\custom\Custom;
use app\common\model\bid\BidBuyBiddingDocument;
@ -41,26 +45,25 @@ class FinanceInvoiceApplyLogic extends BaseLogic
*/
public static function add(array $params): bool
{
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
$tax_rate = DictData::where('type_value','tax_rate')->column('name','value');
Db::startTrans();
try {
FinanceInvoiceApply::create([
'customer_id' => $params['customer_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'approve_id' => $params['approve_id'] ?? 0,
'invoicing_date' => $params['invoicing_date'] ?? '',
'period' => $params['period'] ?? 0,
'accumulate_amount' => $params['accumulate_amount'] ?? 0,
'accumulated_payments_received' => $params['accumulated_payments_received'] ?? 0,
'tax_rate' => $params['tax_rate'] ?? 0,
'invoice_type' => $params['invoice_type'] ?? 0,
'invoicing_amount' => $params['invoicing_amount'] ?? 0,
'invoicing_amount_daxie' => $params['invoicing_amount_daxie'] ?? '',
'tax' => $params['tax'] ?? 0,
'amount_including_tax' => $params['amount_including_tax'] ?? 0,
'project_id' => $contract['project_id'],
'contract_id' => $params['contract_id'],
'invoicing_code' => data_unique_code('开票申请'),
'invoicing_date' => strtotime($params['invoicing_date']),
'period' => $params['period'],
'tax_rate' => $params['tax_rate'],
'invoice_type' => $params['invoice_type'],
'invoicing_amount' => $params['invoicing_amount'],
'tax_amount' => ($tax_rate[$params['tax_rate']] / 100) * $params['invoicing_amount'],
'amount_including_tax' => (1 - $tax_rate[$params['tax_rate']] / 100) * $params['invoicing_amount'],
'content' => $params['content'] ?? '',
'invoice_no' => $params['invoice_no'] ?? '',
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null,
'invoicing_company_name' => $params['invoicing_company_name'] ?? '',
'taxpayer_identification_number' => $params['taxpayer_identification_number'] ?? '',
'deposit_bank' => $params['deposit_bank'] ?? '',
@ -69,11 +72,10 @@ class FinanceInvoiceApplyLogic extends BaseLogic
'receiving_address' => $params['receiving_address'] ?? '',
'contacts' => $params['contacts'] ?? '',
'phone' => $params['phone'] ?? '',
'mailing_time' => $params['mailing_time'] ?? '',
'mailing_time' => !empty($params['mailing_time']) ? strtotime($params['mailing_time']) : 0,
'mailing_type' => $params['mailing_type'] ?? '',
'mailing_no' => $params['mailing_no'] ?? '',
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -93,39 +95,37 @@ class FinanceInvoiceApplyLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
$tax_rate = DictData::where('type_value','tax_rate')->column('name','value');
Db::startTrans();
try {
FinanceInvoiceApply::where('id', $params['id'])->update([
'customer_id' => $params['customer_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'approve_id' => $params['approve_id'] ?? 0,
'invoicing_date' => $params['invoicing_date'] ?? '',
'period' => $params['period'] ?? 0,
'accumulate_amount' => $params['accumulate_amount'] ?? 0,
'accumulated_payments_received' => $params['accumulated_payments_received'] ?? 0,
'tax_rate' => $params['tax_rate'] ?? 0,
'invoice_type' => $params['invoice_type'] ?? 0,
'invoicing_amount' => $params['invoicing_amount'] ?? 0,
'invoicing_amount_daxie' => $params['invoicing_amount_daxie'] ?? '',
'tax' => $params['tax'] ?? 0,
'amount_including_tax' => $params['amount_including_tax'] ?? 0,
'content' => $params['content'] ?? '',
'invoice_no' => $params['invoice_no'] ?? '',
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '',
'invoicing_company_name' => $params['invoicing_company_name'] ?? '',
'taxpayer_identification_number' => $params['taxpayer_identification_number'] ?? '',
'deposit_bank' => $params['deposit_bank'] ?? '',
'bank_accnout' => $params['bank_accnout'] ?? '',
'address_phone' => $params['address_phone'] ?? '',
'receiving_address' => $params['receiving_address'] ?? '',
'contacts' => $params['contacts'] ?? '',
'phone' => $params['phone'] ?? '',
'mailing_time' => $params['mailing_time'] ?? '',
'mailing_type' => $params['mailing_type'] ?? '',
'mailing_no' => $params['mailing_no'] ?? '',
'project_id' => $contract['project_id'],
'contract_id' => $params['contract_id'],
'invoicing_date' => strtotime($params['invoicing_date']),
'period' => $params['period'],
'tax_rate' => $params['tax_rate'],
'invoice_type' => $params['invoice_type'],
'invoicing_amount' => $params['invoicing_amount'],
'tax_amount' => ($tax_rate[$params['tax_rate']] / 100) * $params['invoicing_amount'],
'amount_including_tax' => (1 - $tax_rate[$params['tax_rate']] / 100) * $params['invoicing_amount'],
'content' => $params['content'] ?? '',
'invoice_no' => $params['invoice_no'] ?? '',
'remark' => $params['remark'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null,
'invoicing_company_name' => $params['invoicing_company_name'] ?? '',
'taxpayer_identification_number' => $params['taxpayer_identification_number'] ?? '',
'deposit_bank' => $params['deposit_bank'] ?? '',
'bank_accnout' => $params['bank_accnout'] ?? '',
'address_phone' => $params['address_phone'] ?? '',
'receiving_address' => $params['receiving_address'] ?? '',
'contacts' => $params['contacts'] ?? '',
'phone' => $params['phone'] ?? '',
'mailing_time' => !empty($params['mailing_time']) ? strtotime($params['mailing_time']) : 0,
'mailing_type' => $params['mailing_type'] ?? '',
'mailing_no' => $params['mailing_no'] ?? '',
'update_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -158,17 +158,26 @@ class FinanceInvoiceApplyLogic extends BaseLogic
*/
public static function detail($params): array
{
$financeInvoiceApply = FinanceInvoiceApply::findOrEmpty($params['id']);
$financeInvoiceApply->contract;
$financeInvoiceApply->custom;
$financeInvoiceApply->document = null;
if (!empty($financeInvoiceApply->contract->buy_bidding_document_id)) {
$financeInvoiceApply->document = BidBuyBiddingDocument::findOrEmpty($financeInvoiceApply->contract->buy_bidding_document_id);
}
if (!empty($financeInvoiceApply->document->project_id)) {
$financeInvoiceApply->project = Project::findOrEmpty($financeInvoiceApply->document->project_id);
}
$financeInvoiceApply->annex = json_decode($financeInvoiceApply->annex, true);
return $financeInvoiceApply->toArray();
$data = FinanceInvoiceApply::findOrEmpty($params['id']);
$project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$contract = Contract::field('contract_code,contract_name,amount')->where('id',$data['contract_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['custom_name'] = $custom['name'];
$data['contract_code'] = $contract['contract_code'];
$data['contract_name'] = $contract['contract_name'];
//合同洽商金额
$contract_negotiation_amount = ContractNegotiation::where('contract_id',$data['contract_id'])->sum('negotiation_amount');
//合同金额 = 合同金额 + 合同洽商金额
$data['contract_amount'] = $contract['amount'] + $contract_negotiation_amount;
//回款金额
$data['returned_amount'] = FinanceReturnedRecord::where('contract_id',$data['contract_id'])->sum('amount');
//累计开票金额
$data['total_invoicing_amount'] = FinanceInvoiceApply::where('contract_id',$data['contract_id'])->where('id','<>',$data['id'])->sum('invoicing_amount');
$data['period_text'] = $data->period_text;
$data['tax_rate_text'] = $data->tax_rate_text;
$data['invoice_type_text'] = $data->invoice_type_text;
return $data->toArray();
}
}

View File

@ -15,6 +15,8 @@
namespace app\adminapi\validate\finance;
use app\common\model\contract\Contract;
use app\common\model\dict\DictData;
use app\common\validate\BaseValidate;
@ -32,9 +34,14 @@ class FinanceInvoiceApplyValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
'customer_id' => 'require',
'contract_id' => 'require',
'approve_id' => 'require',
'contract_id' => 'require|checkContract',
'invoicing_date' => 'require|dateFormat:Y-m-d',
'invoice_no' => 'require',
'period' => 'require|checkPeriod',
'tax_rate' => 'require|checkTaxRate',
'invoice_type' => 'require|checkInvoiceType',
'invoicing_amount' => 'require|float|gt:0',
'annex' => 'checkAnnex',
];
@ -43,7 +50,14 @@ class FinanceInvoiceApplyValidate extends BaseValidate
* @var string[]
*/
protected $field = [
'id' => 'id',
'id' => 'id',
'contract_id' => '项目合同id',
'invoicing_date' => '开票日期',
'period' => '期次',
'invoice_no' => '发票编号',
'tax_rate' => '税率',
'invoice_type' => '发票类型',
'invoicing_amount' => '开票金额(含税)',
];
@ -55,7 +69,7 @@ class FinanceInvoiceApplyValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->remove('id', true);
return $this->remove('id', true)->remove('invoice_no',true);
}
@ -66,9 +80,7 @@ class FinanceInvoiceApplyValidate extends BaseValidate
* @date 2023/12/13 15:01
*/
public function sceneEdit()
{
return $this->only(['id', 'customer_id', 'contract_id', 'approve_id']);
}
{}
/**
@ -93,5 +105,52 @@ class FinanceInvoiceApplyValidate extends BaseValidate
{
return $this->only(['id']);
}
public function checkContract($value): bool|string
{
$data = Contract::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目合同不存在';
}
return true;
}
public function checkPeriod($value): bool|string
{
$dict = DictData::where('type_value','pay_period')->column('value');
if(!in_array($value,$dict)){
return '期次无效';
}
return true;
}
public function checkTaxRate($value): bool|string
{
$dict = DictData::where('type_value','tax_rate')->column('value');
if(!in_array($value,$dict)){
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 checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
$annex = json_decode($value,true);
if(empty($annex) || !is_array($annex)){
return '附件格式错误';
}
}
return true;
}
}

View File

@ -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,15 +30,33 @@ class FinanceInvoiceApply extends BaseModel
use SoftDelete;
protected $name = 'finance_invoice_apply';
protected $deleteTime = 'delete_time';
public function custom()
{
return $this->belongsTo(\app\common\model\custom\Custom::class, 'customer_id');
}
public function contract()
{
return $this->belongsTo(\app\common\model\contract\Contract::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 getPeriodTextAttr($value,$data){
$dict = DictData::where('type_value','pay_period')->column('name','value');
return $dict[$data['period']];
}
public function getTaxRateTextAttr($value,$data){
$dict = DictData::where('type_value','tax_rate')->column('name','value');
return $dict[$data['tax_rate']];
}
public function getInvoiceTypeTextAttr($value,$data){
$dict = DictData::where('type_value','invoice_type')->column('name','value');
return $dict[$data['invoice_type']];
}
public function getMailingTimeAttr($value){
return !empty($value) ? date('Y-m-d',$value) : '';
}
}