公司将在每月1日和16日收到发票。(它将通过Cron作业每两周运行一次。它扫描订单表,然后添加到“发票”表中。还有其他选择吗?)
在orders表中有客户订单列表,它还表明它属于哪个公司(orders.company_id)
invoice表计算来自orders表的订单的总成本。
我试图找出如何设计合理的发票跟踪。有时公司会给我费用,有时我会寄给他们费用(invoice.amount)
--我需要用以下内容跟踪发票:
下面是我想出的数据库设计:
公司表
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)完成
我需要在invoice_id表中添加orders字段吗?当行插入“发票”表时更新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-02-16 16:22:37
看看我对双子座 - SimplyFi的附加内容。它将允许您相应地为您的发票贴上品牌,生成时可以自动发送电子邮件给客户,还可以记录付款和发送未收到付款的提示(语句),并且有一个基于REST的完整API,您可以使用它来集成到系统中。此外,也可以受益于它的反复计费功能。
如果您提到发票金额为负数,则实际上是“信用备注”(据我从您的帖子中了解到的)。通常,在向客户发出发票后,您不应该自己更改发票--如果您需要修改金额(即:添加或减去),那么您应该签发一张新发票(用于添加金额)或信用卡,用于减去金额。
另外,如果客户几周后要收到一张新发票,我建议你不要把钱寄回来,只需跟踪他们的帐户余额,并且只在必要时开发票或信用卡。把钱搬来搬去是要花钱的,如果没有必要的话,你也不需要这样做。只是我的两分钱
https://stackoverflow.com/questions/9309248
复制相似问题