SQL Server:根据起始日期和终止日期以及缴费方式计算每月的缴费记录

本文介绍了一个SQL过程,用于根据合同的起租日期、终止日期及缴费方式计算租金。该过程首先验证输入的有效性,然后根据不同的缴费周期计算每月的租金,并将结果存入数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

做项目时经常碰到的业务:根据合同指定的起租日期和终止日期以及缴费方式,计算出两个日期之间的缴费记录,以便提醒缴费。

 

说明:

1、例子中的两个日期、缴费方式从合同中获取。

2、缴费方式主要有:月份、季付、半年付、年付,且以汉字的形式保存在数据库。

 

思路:根据终止日期和起租日期,计算出两个日期之间相差多少个月份,再根据缴费方式进行月份叠加,即

月付*1,季付*3,半年付*6,年付*12,如此计算出每个月缴费的日期以及下个月缴费的日期,再计算这两个日期之间的天数,最后乘以每天的房租费用,就可以得到每个月应该缴纳的总房租。

SQL如下:

CREATE PROCEDURE [dbo].[calcuteContractPay] 
	@id int --合同序号
AS
BEGIN
	
	SET NOCOUNT ON;

	--1、校验合同序号是否存在
	if @id is null
	begin
		raiserror('必须告知合同序号',16,1);
		return ;
	end   

	--2、获取缴费方式
	declare @field12 varchar(20);--缴费方式
	declare @field39 datetime;--起租日期
	declare @field40 datetime;--截止日期
	declare @field66 numeric(18,2);--每天总租金
	select @field12 = field12,@field39=field39,@field40=field40,@field66=isnull(field66,0) from table3 where field1=@id;
	if @field12 is null or len(@field12)<=0
	begin
		raiserror('必须告知缴费方式',16,1);
		return ;
	end
	
	
	--3、校验日期是否合法
	declare @day int;--两者之间的天数
	set @day = datediff(day,@field39,@field40);
	if(@day<=0)
	begin
		raiserror('终止日期必须大于起租日期',16,1);
		return ;
	end	
	
	--4、根据缴费方式判断总共要输入多少条缴费记录
	set @field12 = rtrim(ltrim(@field12));--去除空格
	declare @monthes int;
	declare @totalRent numeric(18,2);--总租金
	declare @type int;--缴费类型
	if(@field12='月付') set @type=1;
	else if(@field12='季付') set @type=2;
	else if(@field12='半年付') set @type=3;
	else if(@field12='年付') set @type=4;
	
	--4、1 计算开始日期与终止之间有多少个月份		
	set @monthes = datediff(month,@field39,@field40);--月份
	
	if @monthes=0 --说明是在当月/当季/半年之内/当年起租、终止,那么只需要直接计算两者之间的天数
	begin
		set @totalRent = @day*@field66;--天数*每天的总价
		begin
			--添加缴费记录
			insert into table6  
			select field1,field2,field4,field5,field12,field39,@totalRent,field42,field64,field11,0,NULL,0,@totalRent,@totalRent,0,							field13,@day,field40 
			from table3 where field1=@id;
		end
	end
	else --说明至少有一个月
	begin
		declare @startTime datetime;--开始日期
		declare @endTime datetime;--结束日期
		declare @num int;
		set @num=0;
		while(@num<=@monthes)	
		begin
			--print @num;
			set @startTime = dateadd(month,@num,@field39);--计算每个月应缴费日期
			if(@type=1) set @num=@num+1;--月付
			else if(@type=2) set @num=@num+3;--季付
			else if(@type=3) set @num=@num+6;--半年付
			else if(@type=4) set @num=@num+12;--年付

			set @endTime = dateadd(month,@num,@field39);--下个月的缴费日期
			--终止日期减去下一个月的日期,如果终止日期比下一个月的日期大,说明还需要再缴一个月,那么使用下一个月的日期,否则使用终止日期
			set @day = datediff(day,@endTime,@field40);
			if(@day<0) set @endTime=@field40;
			--计算开始日期和结束日期之间的天数
			set @day = datediff(day,@startTime,@endTime);
			set @totalRent = @day*@field66;--天数*每天的总价
			if(@totalRent>0)
			begin
				insert into table6  
				select field1,field2,field4,field5,field12,@startTime,@totalRent,field42,field64,field11,0,NULL,0,@totalRent,@totalRent,0,							field13,@day,@endTime 
				from table3 where field1=@id;
			end
		end		
	end

END
GO

 

 

#include "financialwidget.h" #include "ui_financialwidget.h" #include <QVBoxLayout> #include <QHBoxLayout> #include <QChart> #include <QChartView> #include <QLabel> #include <QComboBox> #include <QDate> #include <QDateEdit> #include <QPushButton> #include <QStringList> #include <QTableWidget> #include <QSqlQuery> #include <QHeaderView> #include <QDialog> #include <QFormLayout> #include <QLineEdit> #include <QDialogButtonBox> #include <QSqlError> #include <QPieSeries> #include <QPieSlice> #include <QLineSeries> #include <QDateTimeAxis> #include <QValueAxis> #include <QMessageBox> FinancialWidget::FinancialWidget(QWidget *parent) : QWidget(parent) , ui(new Ui::FinancialWidget) { ui->setupUi(this); setupUI(); populateStudentComboBox(); } FinancialWidget::~FinancialWidget() { delete ui; } void FinancialWidget::setupUI() { QVBoxLayout* mainLayout = new QVBoxLayout(this); QHBoxLayout* topLayout = new QHBoxLayout(); QHBoxLayout* middleLayout = new QHBoxLayout(); chartView = new QChartView(); mainLayout->addLayout(topLayout); mainLayout->addLayout(middleLayout, 60); // 占60%高度 mainLayout->addWidget(chartView, 40); // 占40%高度 // =============== 顶部筛选条件与按钮布局 =============== topLayout->addWidget(new QLabel("学生姓名:", this)); studentComboBox = new QComboBox(this); topLayout->addWidget(studentComboBox); topLayout->addWidget(new QLabel("起始日期:", this)); startDateEdit = new QDateEdit(QDate::currentDate().addMonths(-1)); startDateEdit->setCalendarPopup(true); topLayout->addWidget(startDateEdit); topLayout->addWidget(new QLabel("结束日期:", this)); endDateEdit = new QDateEdit(QDate::currentDate()); endDateEdit->setCalendarPopup(true); topLayout->addWidget(endDateEdit); addButton = new QPushButton("添加"); deleteButton = new QPushButton("删除"); editButton = new QPushButton("修改"); topLayout->addWidget(addButton); topLayout->addWidget(deleteButton); topLayout->addWidget(editButton); topLayout->addStretch(); // =============== 主内容布局 =============== tableWidget = new QTableWidget(); tableWidget->setFixedWidth(550); tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); tableWidget->setAlternatingRowColors(true); QStringList header = QStringList() << "ID" << "学生名字" << "缴费日期" << "金额" << "支付类型" << "备注"; tableWidget->setColumnCount(header.count()); tableWidget->setHorizontalHeaderLabels(header); tableWidget->setColumnHidden(0, true); middleLayout->addWidget(tableWidget); //饼状图 pieChartView = new QChartView(); middleLayout->addWidget(pieChartView); chartView->setRenderHint(QPainter::Antialiasing); chartView->setMinimumHeight(200); // 最小高度保障 // 连接 // 打印所有控件地址,检查是否为 nullptr qDebug() << "addButton:" << addButton; qDebug() << "deleteButton:" << deleteButton; qDebug() << "editButton:" << editButton; qDebug() << "studentComboBox:" << studentComboBox; qDebug() << "startDateEdit:" << startDateEdit; qDebug() << "endDateEdit:" << endDateEdit; connect(addButton, &QPushButton::clicked, this, &FinancialWidget::addRecord); connect(deleteButton, &QPushButton::clicked, this, &FinancialWidget::deleteRecord); connect(editButton, &QPushButton::clicked, this, &FinancialWidget::editRecord); connect(studentComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FinancialWidget::loadFinancialRecords); connect(startDateEdit, &QDateEdit::dateChanged, this, &FinancialWidget::loadFinancialRecords); connect(endDateEdit, &QDateEdit::dateChanged, this, &FinancialWidget::loadFinancialRecords); } void FinancialWidget::loadFinancialRecords() { tableWidget->setRowCount(0); QString studentId = studentComboBox->currentData().toString(); QDate startDate = startDateEdit->date(); QDate endDate = endDateEdit->date(); QString queryStr = QString( "SELECT fr.id, s.name, fr.payment_date, fr.amount, fr.payment_type, fr.notes " "FROM financialRecords fr " "JOIN studentInfo s ON fr.student_id = s.id " "WHERE fr.payment_date BETWEEN '%1' AND '%2' %3" ).arg(startDate.toString("yyyy-MM-dd"), endDate.toString("yyyy-MM-dd"), (studentId != "-1") ? QString("AND fr.student_id = '%1'").arg(studentId) : ""); QSqlQuery query(queryStr); while (query.next()) { int row = tableWidget->rowCount(); tableWidget->insertRow(row); for (int col = 0; col < 6; ++col) { QTableWidgetItem* item = new QTableWidgetItem(query.value(col).toString()); item->setTextAlignment(Qt::AlignCenter); tableWidget->setItem(row, col, item); } } tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); updateChart(); // 更新下方折线图 updatePieChart(); // 更新右侧饼图 } void FinancialWidget::populateStudentComboBox() { studentComboBox->clear(); studentComboBox->addItem("所有学生", QVariant("-1")); // "-1" 表示所有学生 QSqlQuery query("SELECT id, name FROM studentInfo"); while (query.next()) { QString id = query.value(0).toString(); // id 是字符串类型 QString name = query.value(1).toString(); studentComboBox->addItem(name, QVariant(id)); } } void FinancialWidget::addRecord() { QDialog dialog(this); dialog.setWindowTitle("添加缴费记录"); QFormLayout form(&dialog); // 学生名称下拉菜单 QComboBox* studentNameComboBox = new QComboBox(&dialog); QSqlQuery query("SELECT id, name FROM studentInfo"); while (query.next()) { QString id = query.value(0).toString(); QString name = query.value(1).toString(); studentNameComboBox->addItem(name, QVariant(id)); // 将学生ID与名称关联 } QDateEdit* paymentDateEdit = new QDateEdit(&dialog); paymentDateEdit->setDate(QDate::currentDate()); // 设置默认值为当前日期 paymentDateEdit->setCalendarPopup(true); // 允许弹出日历选择器 QLineEdit* amountEdit = new QLineEdit(&dialog); QLineEdit* feeTypeEdit = new QLineEdit(&dialog); QLineEdit* remarkEdit = new QLineEdit(&dialog); form.addRow("学生名称:", studentNameComboBox); form.addRow("缴费日期:", paymentDateEdit); // 修改为 QDateEdit form.addRow("金额:", amountEdit); form.addRow("支付类型:", feeTypeEdit); form.addRow("备注:", remarkEdit); QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); buttonBox.button(QDialogButtonBox::Ok)->setText("确定"); buttonBox.button(QDialogButtonBox::Cancel)->setText("取消"); form.addRow(&buttonBox); QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); QObject::connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); if (dialog.exec() == QDialog::Accepted) { QString studentId = studentNameComboBox->currentData().toString(); QString paymentDate = paymentDateEdit->date().toString("yyyy-MM-dd"); double amount = amountEdit->text().toDouble(); QString feeType = feeTypeEdit->text(); QString remark = remarkEdit->text(); // 准备SQL查询 QSqlQuery query; query.prepare("INSERT INTO financialRecords (student_id, payment_date, amount, payment_type, notes) " "VALUES (:student_id, :payment_date, :amount, :payment_type, :notes)"); query.bindValue(":student_id", studentId); // 绑定学生ID query.bindValue(":payment_date", paymentDate); query.bindValue(":amount", amount); query.bindValue(":payment_type", feeType); query.bindValue(":notes", remark); // 执行SQL查询 if (query.exec()) { qDebug() << "记录添加成功!"; loadFinancialRecords(); // 刷新表格 } else qDebug() << "添加记录失败:" << query.lastError().text(); } } void FinancialWidget::updatePieChart() { // 确保视图有效 if (!pieChartView) return; // 获取筛选条件 QString studentId = studentComboBox->currentData().toString(); QDate startDate = startDateEdit->date(); QDate endDate = endDateEdit->date(); // 安全查询 QString baseQuery = QString( "SELECT payment_type, SUM(amount) " "FROM financialRecords " "WHERE payment_date BETWEEN :startDate AND :endDate %1 " "GROUP BY payment_type") .arg(studentId != "-1" ? "AND student_id = :studentId" : ""); QSqlQuery query; query.prepare(baseQuery); query.bindValue(":startDate", startDate.toString("yyyy-MM-dd")); query.bindValue(":endDate", endDate.toString("yyyy-MM-dd")); if (studentId != "-1") query.bindValue(":studentId", studentId); if (!query.exec()) { qWarning() << "Financial chart query error:" << query.lastError(); return; } // 创建新图表对象 QChart* newChart = new QChart(); newChart->setTitle("支付类型分布"); // 创建饼图系列 QPieSeries* series = new QPieSeries(); series->setPieSize(0.75); bool hasData = false; double totalAmount = 0.0; // 处理查询结果 while (query.next()) { QString type = query.value(0).toString(); qreal value = query.value(1).toDouble(); if (value > 0) { hasData = true; totalAmount += value; // 创建带金额显示的扇区 QPieSlice* slice = series->append( QString("%1\n%2元").arg(type).arg(value), // 显示支付类型金额 value ); // 配置扇区标签 slice->setLabelVisible(true); slice->setLabelPosition(QPieSlice::LabelInsideTangential); slice->setLabelFont(QFont("Arial", 8, QFont::Bold)); slice->setLabelColor(Qt::white); slice->setLabel(QString("%1\n%2元\n%3%") .arg(type) .arg(value) .arg(QString::number(value/totalAmount*100, 'f', 1))); } } // 添加总金额标题 if (hasData) { newChart->setTitle(QString("支付类型分布 (总金额: %1元)").arg(totalAmount)); newChart->addSeries(series); } else { // 无数据时显示占位信息 newChart->setTitle("支付类型分布 (无数据)"); QPieSeries* emptySeries = new QPieSeries(); QPieSlice* slice = emptySeries->append("无数据", 1); slice->setLabelVisible(true); slice->setLabel("暂无支付记录"); newChart->addSeries(emptySeries); } // 配置图例 newChart->legend()->setVisible(true); newChart->legend()->setAlignment(Qt::AlignBottom); newChart->legend()->setBackgroundVisible(true); newChart->legend()->setBrush(QBrush(Qt::white)); newChart->legend()->setLabelColor(Qt::black); newChart->legend()->setContentsMargins(10, 10, 10, 10); // 配置动画效果 newChart->setAnimationOptions(QChart::AllAnimations); // 安全替换图表 QChart* oldChart = pieChartView->chart(); pieChartView->setChart(newChart); // 延迟删除旧图表 if (oldChart) oldChart->deleteLater(); } void FinancialWidget::updateChart() { // ================== 1. 获取并验证日期范围 ================== QDate startDate = startDateEdit->date(); QDate endDate = endDateEdit->date(); if (startDate > endDate) { std::swap(startDate, endDate); startDateEdit->setDate(startDate); endDateEdit->setDate(endDate); } // ================== 2. 构建安全SQL查询 ================== QString studentId = studentComboBox->currentData().toString(); // 如果 studentId 为 "-1"(不筛选特定学生),直接返回 /*if (studentId == "-1") { qDebug() << "未选择特定学生,跳过饼图更新"; return; }*/ QString queryStr = QString("SELECT DATE(payment_date) AS day, SUM(amount) AS total " "FROM financialRecords " "WHERE payment_date BETWEEN :startDate AND :endDate " "%1 GROUP BY day ORDER BY day" ).arg(studentId != "-1" ? "AND student_id = :studentId" : ""); QSqlQuery query; query.prepare(queryStr); query.bindValue(":startDate", startDate.toString("yyyy-MM-dd")); query.bindValue(":endDate", endDate.toString("yyyy-MM-dd")); if (studentId != "-1") query.bindValue(":studentId", studentId); if (!query.exec()) qCritical() << "[SQL错误]" << query.lastError().text(); // ================== 3. 处理查询数据 ================== QMap<QDate, qreal> dayData; qreal maxAmount = 0; while (query.next()) { QDate day = QDate::fromString(query.value(0).toString(), "yyyy-MM-dd"); if (!day.isValid()) continue; qreal amount = query.value(1).toDouble(); dayData[day] = amount; if (amount > maxAmount) maxAmount = amount; } // ================== 4. 创建图表系列 ================== QLineSeries* series = new QLineSeries(); series->setName("销售额"); QPen pen(Qt::blue); series->setPen(pen); QDate currentDate = startDate; while (currentDate <= endDate) { qreal value = dayData.value(currentDate, 0.0); series->append(currentDate.startOfDay().toMSecsSinceEpoch(), value); currentDate = currentDate.addDays(1); } // ================== 5. 配置坐标轴 ================== QChart* chart = new QChart(); chart->addSeries(series); QDateTimeAxis* axisX = new QDateTimeAxis(); axisX->setFormat("yyyy-MM-dd"); axisX->setTitleText("日期"); axisX->setRange(startDate.startOfDay(),endDate.startOfDay()); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); QValueAxis* axisY = new QValueAxis(); axisY->setTitleText("金额 (元)"); axisY->setLabelFormat("%.0f"); chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY); // ================== 6. 应用图表 ================== if (chartView->chart()) delete chartView->chart(); chartView->setChart(chart); chartView->setRenderHint(QPainter::Antialiasing); chart->legend()->setVisible(false); } void FinancialWidget::editRecord() { int currentRow = tableWidget->currentRow(); if (currentRow < 0) { QMessageBox::warning(this, "警告", "请选择要修改的记录!"); return; } // 获取当前行的数据 QString id = tableWidget->item(currentRow, 0)->text(); // ID 是字符串类型 QString studentName = tableWidget->item(currentRow, 1)->text(); // 学生名称 QString paymentDate = tableWidget->item(currentRow, 2)->text(); QString amount = tableWidget->item(currentRow, 3)->text(); QString feeType = tableWidget->item(currentRow, 4)->text(); QString remark = tableWidget->item(currentRow, 5)->text(); QDialog dialog(this); dialog.setWindowTitle("修改缴费记录"); QFormLayout form(&dialog); // 学生名称下拉菜单 QComboBox* studentNameComboBox = new QComboBox(&dialog); QSqlQuery query("SELECT id, name FROM studentInfo"); while (query.next()) { QString id = query.value(0).toString(); // id 是字符串类型 QString name = query.value(1).toString(); studentNameComboBox->addItem(name, QVariant(id)); } studentNameComboBox->setCurrentText(studentName); // 设置当前学生名称 QLineEdit* paymentDateEdit = new QLineEdit(paymentDate, &dialog); QLineEdit* amountEdit = new QLineEdit(amount, &dialog); QLineEdit* feeTypeEdit = new QLineEdit(feeType, &dialog); QLineEdit* remarkEdit = new QLineEdit(remark, &dialog); form.addRow("学生名称:", studentNameComboBox); form.addRow("缴费日期:", paymentDateEdit); form.addRow("金额:", amountEdit); form.addRow("支付类型:", feeTypeEdit); form.addRow("备注:", remarkEdit); QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); buttonBox.button(QDialogButtonBox::Ok)->setText("确定"); buttonBox.button(QDialogButtonBox::Cancel)->setText("取消"); form.addRow(&buttonBox); QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); QObject::connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); if (dialog.exec() == QDialog::Accepted) { QString studentId = studentNameComboBox->currentData().toString(); // studentId 是字符串类型 QString paymentDate = paymentDateEdit->text(); double amount = amountEdit->text().toDouble(); QString feeType = feeTypeEdit->text(); QString remark = remarkEdit->text(); // 准备 SQL 查询 QSqlQuery query; query.prepare("UPDATE financialRecords SET student_id = :student_id, payment_date = :payment_date, " "amount = :amount, payment_type = :payment_type, notes = :notes WHERE id = :id"); query.bindValue(":student_id", studentId); // studentId 是字符串类型 query.bindValue(":payment_date", paymentDate); query.bindValue(":amount", amount); query.bindValue(":payment_type", feeType); query.bindValue(":notes", remark); query.bindValue(":id", id); // 执行 SQL 查询 if (query.exec()) { qDebug() << "记录修改成功!"; loadFinancialRecords(); // 刷新表格 } else qDebug() << "修改记录失败:" << query.lastError().text(); } } void FinancialWidget::deleteRecord() { int currentRow = tableWidget->currentRow(); if (currentRow < 0) { QMessageBox::warning(this, "警告", "请选择要删除的记录!"); return; } // 获取 ID 列的值 int id = tableWidget->item(currentRow, 0)->text().toInt(); // ID 列是第一列 // 确认删除操作 QMessageBox confirmBox(this); confirmBox.setWindowTitle("确认删除"); confirmBox.setText("确定要删除该记录吗?"); // 设置按钮为中文 QPushButton* yesButton = confirmBox.addButton("确定", QMessageBox::YesRole); QPushButton* noButton = confirmBox.addButton("取消", QMessageBox::NoRole); // 设置默认按钮 confirmBox.setDefaultButton(noButton); // 显示对话框并等待用户选择 confirmBox.exec(); if (confirmBox.clickedButton() == yesButton) { // 用户点击了“确定” QSqlQuery query; query.prepare("DELETE FROM financialRecords WHERE id = :id"); query.bindValue(":id", id); if (query.exec()) { qDebug() << "记录删除成功!"; loadFinancialRecords(); // 刷新表格 } else { QMessageBox::warning(this, "错误", "删除记录失败!"); } } } 这是修改后的financialwidget.cpp代码其中函数void FinancialWidget::updatePieChart()已经能够正常使用不用修改,可void FinancialWidget::updateChart()函数会导致进程崩溃请分析原因并修改
最新发布
06-26
1.项目表 (projects) 字段名 数据类型 描述 project_id INT AUTO_INCREMENT 项目主键,自增 unit_name VARCHAR(255) 编制单位 project_name VARCHAR(255) 项目名称 house_asset VARCHAR(255) 房屋资产 land_asset VARCHAR(255) 土地资产 franchise_asset VARCHAR(255) 特许经营资产 house_book_area DECIMAL(10, 2) 房屋资产账面面积(单位:平方米) house_rent_area DECIMAL(10, 2) 房屋资产出租面积(单位:平方米) house_idle_area DECIMAL(10, 2) 房屋资产闲置面积(单位:平方米) region VARCHAR(255) 所属区域 asset_location VARCHAR(255) 资产定位 remarks TEXT 备注 current_status VARCHAR(255) 使用现状 special_conditions TEXT 其他特殊情况 createtime DATETIME 创建时间,默认当前时间 updatetime DATETIME 更新时间,默认当前时间,更新时自动修改 2.房屋资产表 (house_assets) 字段名称 数据类型 备注 house_asset_id INT AUTO_INCREMENT 房屋资产主键ID project_id INT 项目ID unit_name VARCHAR(255) NOT NULL 编制单位 asset_name VARCHAR(255) NOT NULL 资产名称 has_certificate BOOLEAN 是否有证书 rights_holder VARCHAR(255) 权利人 certificate_date DATE 发证日期 certificate_number VARCHAR(255) 证书号码 is_off_books BOOLEAN 是否账外资产 asset_type VARCHAR(255) 资产类型 asset_source VARCHAR(255) 资产来源 current_status VARCHAR(255) 使用现状 has_income BOOLEAN 是否产生收益 rental_guideline DECIMAL(10, 2) 租赁指导价 asset_value DECIMAL(15, 2) 资产价值 certificate_area DECIMAL(10, 2) 产证面积 book_area DECIMAL(10, 2) 账面面积 rent_area DECIMAL(10, 2) 出租面积 lend_area DECIMAL(10, 2) 出借面积 self_use_area DECIMAL(10, 2) 自用面积 other_area DECIMAL(10, 2) 其他面积 idle_area DECIMAL(10, 2) 闲置面积 remarks TEXT 备注 check_area DECIMAL(10, 2) 清查面积 check_date DATE 清查日期 change_reason TEXT 变动原因 community VARCHAR(255) 社区 createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) other_id INT 对方ID FOREIGN KEY 外键约束,关联projects表的project_id 3.土地资产表 (land_assets) 字段名称 数据类型 备注 land_asset_id INT AUTO_INCREMENT 土地资产主键ID project_id INT (外键,关联项目表) unit_name VARCHAR(255) 编制单位 asset_name VARCHAR(255) NOT NULL 资产名称 has_certificate BOOLEAN 是否有证书 certificate_holder VARCHAR(255) 持证人 certificate_date DATE 发证日期 certificate_number VARCHAR(255) 证书号码 marked_area DECIMAL(10, 2) 载明面积 land_nature VARCHAR(255) 土地性质 land_source VARCHAR(255) 土地来源 acquisition_date DATE 取得时间 location VARCHAR(255) 坐落位置 is_off_books BOOLEAN 是否账外资产 has_income BOOLEAN 是否产生收益 usage_status VARCHAR(255) 使用情况 asset_value DECIMAL(15, 2) 资产价值 book_area DECIMAL(10, 2) 账面面积 rent_area DECIMAL(10, 2) 出租面积 lend_area DECIMAL(10, 2) 出借面积 self_use_area DECIMAL(10, 2) 自用面积 other_area DECIMAL(10, 2) 其他面积 idle_area DECIMAL(10, 2) 闲置面积 existing_issues TEXT 存在问题 rectification_status TEXT 整改情况 remarks TEXT 备注信息 check_area DECIMAL(10, 2) 清查面积 check_date DATE 清查时间 change_reason TEXT 变动原因 createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 4.特许经营资产表 (franchise_assets) 字段名称 数据类型 备注 franchise_asset_id INT AUTO_INCREMENT 特许经营资产主键ID,唯一标识每条记录 project_id INT 关联项目表的项目ID(外键,关联项目表) contract_id INT 合同表主键(关联合同表) franchise_name VARCHAR(255) 特许经营项目名称 franchise_category VARCHAR(255) 特许经营类别 franchise_scope VARCHAR(255) 特许经营规模及范围 governing_department VARCHAR(255) 主管部门 is_transferred BOOLEAN 是否已出让(值为TRUE表示已出让,FALSE表示未出让) transferable_services TEXT 可出让特许经营服务项目(具体说明可转让的服务项目) is_transferable BOOLEAN 是否具备出让条件(值为TRUE表示具备出让条件,FALSE表示不具备) reasons_for_non_transferable TEXT 不具备出让条件的原因(描述具体原因) estimated_annual_revenue_1 DECIMAL(15, 2) 出让预计年收益项目1(具体描述) estimated_annual_revenue_2 DECIMAL(15, 2) 出让预计年收益项目2 estimated_annual_revenue_3 DECIMAL(15, 2) 出让预计年收益项目3 estimated_annual_revenue_4 DECIMAL(15, 2) 出让预计年收益项目4 estimated_annual_revenue_total DECIMAL(15, 2) 出让预计年收益合计(四个项目的合计) operating_entity VARCHAR(255) 经营主体 entity_type VARCHAR(255) 经营主体性质(描述经营主体是企业、个体等类型) license_period INT 特许经营期许可协议年限(特许经营许可的有效年限) transfer_method VARCHAR(255) 特许经营出让方式(例如:拍卖、协议转让等) authorization_unit VARCHAR(255) 授权单位(特许经营授权的单位名称) start_date DATE 起始日期(特许经营开始日期) end_date DATE 到期时间(特许经营结束日期) pricing_basis VARCHAR(255) 定价依据(例如:市场价、政府规定价格等) fee_standard DECIMAL(10, 2) 特许经营权使用费金额标准(按金额计费的标准) fee_frequency VARCHAR(255) 特许经营权使用费频次(例如:每年、每月等) outstanding_fees DECIMAL(15, 2) 应收未收使用费金额(尚未支付的费用金额) government_subsidy DECIMAL(15, 2) 政府补贴金额每年(每年获得的政府补贴金额) issues TEXT 存在问题(描述当前在执行过程中遇到的问题) rectification_status TEXT 整改情况(描述是否需要整改以及整改的进展) remarks_time TIMESTAMP 备注时间(记录备注的时间) current_status VARCHAR(255) 使用现状(描述特许经营当前的使用状态) createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 5.承租方表 (lessees) 字段名称 数据类型 备注 lessee_id INT AUTO_INCREMENT 承租方主键ID unit_name VARCHAR(255) 编制单位 lessee_name VARCHAR(255) 名称 lessee_type VARCHAR(255) 类型 contact_person VARCHAR(255) 企业联系人 contact_phone VARCHAR(255) 联系人手机号 tax_number VARCHAR(255) 税号 electricity_usage DECIMAL(10, 2) 用电量,租户的电力消耗(单位:kWh) water_usage DECIMAL(10, 2) 用水量,租户的水消耗(单位:立方米) photovoltaic_usage DECIMAL(10, 2) 光伏供电量,租户使用的光伏电力(单位:kWh) storage_usage DECIMAL(10, 2) 储能供电量,租户使用的储能电力(单位:kWh) payment_details TEXT 缴费详情 energy_efficiency DECIMAL(10, 2) 节能效率 createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 6.合同表contracts 字段名称 数据类型 备注 contract_id INT AUTO_INCREMENT 合同主键ID,唯一标识每条合同记录 unit_name VARCHAR(255) 编制单位 asset_type VARCHAR(255) 资产类型 lease_info TEXT 租赁信息 lease_area DECIMAL(10, 2) 租赁面积 lessee_name VARCHAR(255) 承租方 deposit DECIMAL(10, 2) 押金 first_rent DECIMAL(10, 2) 首期租金 total_rent DECIMAL(10, 2) 租金总额 lease_start_date DATE 租赁起始时间 lease_end_date DATE 租赁结束时间 rent_payment_cycle VARCHAR(255) 租金支付周期 rent_free_months INT 免租月数 status VARCHAR(255) 状态 contract_type VARCHAR(255) 合同类型(表示房屋合同、土地合同或特许经营合同) termination_date DATE 退租日期 remarks TEXT 备注信息,关于合同的其他补充说明或备注 other_id INT 对方ID advance_payment_days INT 约定提前支付天数 createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 7.附件表 attachments 字段名称 数据类型 备注 attachment_id INT AUTO_INCREMENT 文件ID,唯一标识每个附件记录 project_id INT 关联项目表的项目ID(外键,关联项目表) contract_id INT 关联合同表的主键ID(外键,关联合同表) unit_name VARCHAR(255) 编制单位,指提供或管理附件的单位名称 file_type VARCHAR(255) 类型(合同、图纸、照片等) file_name VARCHAR(255) 文件名,表示附件文件的名称 file_size DECIMAL(15, 2) 文件大小,表示附件文件的大小,单位为字节(可以有小数) file_extension VARCHAR(50) 文件类型,表示附件文件的扩展名(如 .pdf, .jpg) last_modified_date DATETIME 文件最近修改日期记录附件文件的最后修改时间 remarks TEXT 备注信息,记录附件文件的补充说明或附加信息 data_type VARCHAR(255) 对应数据类型,表示附件所关联的数据类型(如合同、报告等) data_content TEXT 对应数据 (内容) regedit_path VARCHAR(255) 跳转路径 other_id INT 对方ID,表示与该附件相关的另一方(如合同的对方、提供文件的单位等)的唯一标识 createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 8使用情况表asset_usage 字段名称 数据类型 备注 usage_id INT AUTO_INCREMENT 主键ID house_asset_id INT 房屋资产主键id (关联房屋资产表) contract_id INT 合同主键id(关联合同表) asset_type VARCHAR(50) 资产类型,区分房屋土地(如 'house', 'land') name VARCHAR(255) 名称,资产使用情况的名称 land_asset_id INT 土地资产主键id(关联土地资产表) area DECIMAL(10, 2) 面积,资产使用面积,单位为平方米 remarks TEXT 备注信息,记录资产使用情况的补充说明 other_id INT 对方ID,表示与该资产相关的另一方(如租客等) usage_status VARCHAR(100) 使用现状,描述资产当前的使用状态(如已租、空置等) createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 9 清查情况表 asset_inventory 字段名称 数据类型 备注 Inventory_id INT AUTO_INCREMENT 主键ID asset_type VARCHAR(50) 资产类型,区分房屋资产土地资产(如 'house', 'land') house_asset_id INT 房屋资产主键id (关联房屋资产表) land_asset_id INT 土地资产主键id(关联土地资产表) check_area DECIMAL(10, 2) 清查面积,单位为平方米 check_date DATE 清查时间 change_reason TEXT 变动原因,描述清查中发现的资产变动原因 createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 10.账单表 bill 字段名称 数据类型 备注 bill_id INT AUTO_INCREMENT 账单主键id contract_id INT 关联租约, 合同主键ID(关联合同表)展示合同表lease_info(租赁信息) bill_type VARCHAR(100) 账单类型(如租金、物业费等) amount_due DECIMAL(10, 2) 应付金额 due_date DATE 应付时间,账单到期日期 status ENUM('未支付', '已支付', '部分支付') 状态,描述账单的支付情况 amount_paid DECIMAL(10, 2) 已付金额,实际已支付的金额 discount_amount DECIMAL(10, 2) 减免金额,账单中减免的金额 remaining_amount DECIMAL(10, 2) 剩余未付金额,剩余需要支付的金额 lease_id INT 承租方, 承租方主键id(关联承租方表) 展示承租方表的 lessee_name(名称) remarks TEXT 备注信息,记录账单的其他补充说明 11流水表 payments 字段名称 数据类型 备注 payment_id INT 主键id bill_id INT 账单主键id(关联账单表) payment_amount DECIMAL(15, 2) 支付金额,最多 15 位数字,保留 2 位小数。 payment_date DATE 支付日期记录支付发生的日期。 payment_type VARCHAR(255) 支付方式,描述支付类型(如信用卡、现金、银行转账等),最大长度为 255 字符。 createdtime DATETIME 创建时间(默认当前时间) updatedtime DATETIME 更新时间(默认当前时间,更新时自动更改) 12 日志表logs 字段名称 数据类型 备注 log_id INT AUTO_INCREMENT 主键,日志记录的唯一标识,自动递增。 operator VARCHAR(255) 操作人,记录执行操作的人员。 data_type VARCHAR(100) 数据类型(例如:账单、用户等)。 data_id INT 数据ID,记录被操作的数据的唯一标识。 operation_type VARCHAR(50) 操作类型(如:新增、删除、修改、查看等)。 changes TEXT 修改内容, 描述具体的操作内容或更改的详细信息。 remarks TEXT 备注, 记录补充信息或额外说明。 operation_time DATETIME 时间, 记录操作发生的时间。 ip_address VARCHAR(45) IP地址, 记录执行操作时的IP地址。 根据上述表描述,创建表mysql语句,并备注每个字段的注释
05-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值