118 lines
4.0 KiB
JavaScript
118 lines
4.0 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|
const path = require('path');
|
|
|
|
const dbPath = path.join(__dirname, 'company_finance.db');
|
|
const db = new sqlite3.Database(dbPath);
|
|
|
|
console.log('开始添加供应商信息...');
|
|
|
|
// 供应商基本信息
|
|
const supplierInfo = {
|
|
name: '云南山茶花电线电缆有限公司',
|
|
contact: '沈志凯',
|
|
position: '销售',
|
|
phone: '18725101565',
|
|
email: '',
|
|
address: '',
|
|
supply_category: '电线电缆',
|
|
country: '中国',
|
|
remark: ''
|
|
};
|
|
|
|
// 银行信息
|
|
const bankInfo = {
|
|
bank_name: '中国建设银行股份有限公司昆明世纪城支行',
|
|
account_name: '唐圣',
|
|
account_number: '6217003850004004379',
|
|
currency: 'CNY'
|
|
};
|
|
|
|
// 插入供应商基本信息
|
|
db.run(
|
|
`INSERT INTO suppliers (name, contact, position, phone, email, address, supply_category, country, remark)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
[supplierInfo.name, supplierInfo.contact, supplierInfo.position, supplierInfo.phone,
|
|
supplierInfo.email, supplierInfo.address, supplierInfo.supply_category,
|
|
supplierInfo.country, supplierInfo.remark],
|
|
function(err) {
|
|
if (err) {
|
|
console.error('插入供应商信息失败:', err.message);
|
|
db.close();
|
|
return;
|
|
}
|
|
|
|
const supplierId = this.lastID;
|
|
console.log(`✓ 成功插入供应商信息,ID: ${supplierId}`);
|
|
|
|
// 插入联系人信息
|
|
db.run(
|
|
`INSERT INTO contacts (entity_id, entity_type, name, position, phone, is_primary, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))`,
|
|
[supplierId, 'supplier', supplierInfo.contact, supplierInfo.position, supplierInfo.phone, 1],
|
|
(err) => {
|
|
if (err) {
|
|
console.error('插入联系人信息失败:', err.message);
|
|
} else {
|
|
console.log('✓ 成功插入联系人信息');
|
|
}
|
|
|
|
// 插入银行信息
|
|
db.run(
|
|
`INSERT INTO supplier_payment_infos (supplier_id, bank_name, account_name, account_number, currency, is_default)
|
|
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
[supplierId, bankInfo.bank_name, bankInfo.account_name, bankInfo.account_number, bankInfo.currency, 1],
|
|
(err) => {
|
|
if (err) {
|
|
console.error('插入银行信息失败:', err.message);
|
|
} else {
|
|
console.log('✓ 成功插入银行信息');
|
|
}
|
|
|
|
// 验证插入结果
|
|
db.get(
|
|
`SELECT * FROM suppliers WHERE id = ?`,
|
|
[supplierId],
|
|
(err, supplier) => {
|
|
if (err) {
|
|
console.error('查询供应商信息失败:', err.message);
|
|
} else {
|
|
console.log('\n供应商信息:');
|
|
console.log(supplier);
|
|
|
|
// 查询联系人信息
|
|
db.get(
|
|
`SELECT * FROM contacts WHERE entity_id = ? AND entity_type = 'supplier'`,
|
|
[supplierId],
|
|
(err, contact) => {
|
|
if (err) {
|
|
console.error('查询联系人信息失败:', err.message);
|
|
} else {
|
|
console.log('\n联系人信息:');
|
|
console.log(contact);
|
|
}
|
|
|
|
// 查询银行信息
|
|
db.get(
|
|
`SELECT * FROM supplier_payment_infos WHERE supplier_id = ?`,
|
|
[supplierId],
|
|
(err, paymentInfo) => {
|
|
if (err) {
|
|
console.error('查询银行信息失败:', err.message);
|
|
} else {
|
|
console.log('\n银行信息:');
|
|
console.log(paymentInfo);
|
|
}
|
|
db.close();
|
|
}
|
|
);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
);
|
|
}
|
|
);
|
|
}
|
|
); |