2012-02-16 110 views
0

公司将在每月的第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)完成

我是否需要添加在ordersinvoice_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_productsorders表中的更改进行更改 - 是否应重新计算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'); 

随时要更新/表添加到这里的答案。

感谢

+0

现在是2012年。是否有充分的理由编写自己的会计系统而不是使用COTS或FOSS会计? – 2012-02-16 12:27:13

+0

@Catcall不知道你是什么意思......我已经开发了一个系统来让客户订购产品。在后台显示订单列表等。 – 2012-02-16 12:44:42

+0

我的意思是谷歌没有编写自己的会计系统,Facebook也没有写自己的会计系统。你为什么*写*你自己的会计系统?有时候有充分的理由重新发明轮子。会计通常不是一个好的理由。 – 2012-02-16 12:58:53

回答

0

看一看我的添加为Gemini - SimplyFi。它将允许您相应地标记您的发票,可以在生成时自动将它们发送给客户,还可以记录付款并发送未收到付款(报表)的提醒,并且具有可用于集成到系统中的完整REST API。也有可能从其特点的循环计费中受益。

如果您提到负面的发票金额,那些实际上是“信用票据”(从我的帖子了解)。一般来说,在发给客户后,您不应该自行更改发票 - 如果您需要对金额进行修改(即:添加或减少),那么您应该发行新的发票(用于增加金额) ,或者是一个信用票据,扣除金额。

另外,我建议您不要在几周内收到客户的款项,只需跟踪帐户余额,并在必要时只发出发票或信用票据。转移资金需要花钱,如果没有必要,你不需要这样做。只是我的2美分