公司将在每月的第1和第16天收到发票。 (它将每隔两周通过Cron Job运行,它通过订单表扫描,然后添加到'invoice'表中。是否有其他选择?)生成发票和跟踪
orders
表中有客户订单列表,它也表示它属于的公司(orders.company_id
)
invoice
表中计算的订单总成本从orders
表中计算。
我想弄清楚如何设计合理的发票跟踪。有时公司会送我的费用或有时我给他们的费用(invoice.amount
)
我需要用下面的跟踪发票:
- 的时候,公司已经给我发量
- 我什么时候发送量到公司
- 多少量已经从公司
- 多少量我才发送到公司 收到
- 我收到全款(如果没有,我需要做什么对DB更新?)
- 发票状态(发票已发送,已取消,收到的金额,发送量)
这里是数据库设计我已经想出了:
公司表
mysql> select * from company;
+----+-----------+
| id | name |
+----+-----------+
| 1 | Company A |
| 2 | Company B |
+----+-----------+
客户可以从我的网站选择一个公司。
订单表
mysql> select * from orders;
+----+---------+------------+------------+---------------------+-----------+
| id | user_id | company_id | total_cost | order_date | status_id |
+----+---------+------------+------------+---------------------+-----------+
| 1 | 5 | 2 | 25.00 | 2012-02-03 23:30:24 | 1 |
| 2 | 7 | 2 | 30.00 | 2012-02-13 18:06:12 | 1 |
+----+---------+------------+------------+---------------------+-----------+
两个客户订购的产品B公司(orders.company_id = 2
)。我知道订单字段不够,只是简化了你。
orders_products表什么的客户订购产品
mysql> select * from orders_products;
+----+----------+------------+--------------+-------+
| id | order_id | product_id | product_name | cost |
+----+----------+------------+--------------+-------+
| 1 | 1 | 34 | Chair | 10.00 |
| 2 | 1 | 25 | TV | 10.00 |
| 3 | 1 | 27 | Desk | 2.50 |
| 4 | 1 | 36 | Laptop | 2.50 |
| 5 | 2 | 75 | PHP Book | 25.00 |
| 6 | 2 | 74 | MySQL Book | 5.00 |
+----+----------+------------+--------------+-------+
名单。
发票表
mysql> select * from invoice;
+----+------------+------------+---------------------+--------+-----------+
| id | company_id | invoice_no | invoice_date | amount | status_id |
+----+------------+------------+---------------------+--------+-----------+
| 7 | 2 | 123 | 2012-02-16 23:59:59 | 55.00 | 1 |
+----+------------+------------+---------------------+--------+-----------+
这是我很卡在发票表的设计。我不知道该怎么做。发票将每两周生成一次。从结果示例invoice.amount
是55.00,因为它是从orders.company_id = 2
计算的表
如果invoice.amount
是-50.00(减),则表示公司需要向我发送费用金额。
如果invoice.amount
是50.00,这意味着我需要向公司发送费用。
的STATUS_ID可能是:(1)发送发票;(2)取消,(3)完成
我是否需要添加在orders
表invoice_id
场?行已插入“发票”表中时更新orders.invoice_id
字段。
invoice_payment表
mysql> select * from invoice_payment;
+----+------------+-----------------+-------------+---------------------+---------------------+
| id | invoice_id | amount_received | amount_sent | date_received | date_sent |
+----+------------+-----------------+-------------+---------------------+---------------------+
| 1 | 1 | 0.00 | 55.00 | 0000-00-00 00:00:00 | 2012-02-18 22:20:53 |
+----+------------+-----------------+-------------+---------------------+---------------------+
这是我可以跟踪和更新事务..付款将通过BACS进行。
这是很好的表设计或我需要改进什么?我应该添加哪些字段和表格?
如果已经生成发票,稍后我需要对orders_products
或orders
表中的更改进行更改 - 是否应重新计算invoice.amount
字段? (我将使用PHP/MySQL)。
SQL转储:
CREATE TABLE IF NOT EXISTS `company` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `company` (`id`, `name`) VALUES
(1, 'Company A'),
(2, 'Company B');
CREATE TABLE IF NOT EXISTS `invoice` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) NOT NULL,
`invoice_no` int(11) NOT NULL,
`invoice_date` datetime NOT NULL,
`amount` decimal(6,2) NOT NULL,
`status_id` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
INSERT INTO `invoice` (`id`, `company_id`, `invoice_no`, `invoice_date`, `amount`, `status_id`) VALUES
(7, 2, 123, '2012-02-16 23:59:59', '55.00', 1);
CREATE TABLE IF NOT EXISTS `invoice_payment` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`invoice_id` int(11) NOT NULL,
`amount_received` decimal(6,2) NOT NULL,
`amount_sent` decimal(6,2) NOT NULL,
`date_received` datetime NOT NULL,
`date_sent` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
INSERT INTO `invoice_payment` (`id`, `invoice_id`, `amount_received`, `amount_sent`, `date_received`, `date_sent`) VALUES
(1, 1, '0.00', '55.00', '0000-00-00 00:00:00', '2012-02-18 22:20:53');
CREATE TABLE IF NOT EXISTS `orders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`company_id` int(11) NOT NULL,
`total_cost` decimal(6,2) NOT NULL,
`order_date` datetime NOT NULL,
`status_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `orders` (`id`, `user_id`, `company_id`, `total_cost`, `order_date`, `status_id`) VALUES
(1, 5, 2, '25.00', '2012-02-03 23:30:24', 1),
(2, 7, 2, '30.00', '2012-02-13 18:06:12', 1);
CREATE TABLE IF NOT EXISTS `orders_products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`product_name` varchar(100) NOT NULL,
`cost` decimal(6,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
INSERT INTO `orders_products` (`id`, `order_id`, `product_id`, `product_name`, `cost`) VALUES
(1, 1, 34, 'Chair', '10.00'),
(2, 1, 25, 'TV', '10.00'),
(3, 1, 27, 'Desk', '2.50'),
(4, 1, 36, 'Laptop', '2.50'),
(5, 2, 75, 'PHP Book', '25.00'),
(6, 2, 74, 'MySQL Book', '5.00');
随时要更新/表添加到这里的答案。
感谢
现在是2012年。是否有充分的理由编写自己的会计系统而不是使用COTS或FOSS会计? – 2012-02-16 12:27:13
@Catcall不知道你是什么意思......我已经开发了一个系统来让客户订购产品。在后台显示订单列表等。 – 2012-02-16 12:44:42
我的意思是谷歌没有编写自己的会计系统,Facebook也没有写自己的会计系统。你为什么*写*你自己的会计系统?有时候有充分的理由重新发明轮子。会计通常不是一个好的理由。 – 2012-02-16 12:58:53