【问题标题】:Generate Invoice & Tracking生成发票和跟踪
【发布时间】:2012-03-07 17:32:53
【问题描述】:

公司将在每个月的 1 日和 16 日收到发票。 (它将通过 Cron Job 每 2 周运行一次。它会扫描订单表,然后添加到“发票”表中。有替代方案吗?)

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 |
+----+------------+------------+---------------------+--------+-----------+

这就是我在发票表设计上非常纠结的地方。我不确定应该怎么做。发票将每 2 周生成一次。从结果示例中,invoice.amount 是 55.00,因为它是根据 orders.company_id = 2 表计算得出的

如果invoice.amount 是-50.00(减),则表示公司需要向我发送费用金额。

如果invoice.amount是50.00,这意味着我需要向公司发送费用。

status_id 可以是:(1)Invoice Sent, (2)Cancelled, (3)Completed

我需要在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_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');

如果您想在此处更新/添加表格以回答,请随意。

谢谢

【问题讨论】:

  • 现在是 2012 年。是否有令人信服的理由编写自己的会计系统而不是使用 COTS 或 FOSS 会计?
  • @Catcall 不确定您的意思...我已经开发了一个系统来允许客户订购产品。在后端显示订单列表等。
  • 我的意思是 Google 没有编写自己的会计系统,Facebook 也没有编写他们的自己的会计系统。为什么要编写你的自己的会计系统?有时有充分的理由重新发明轮子。会计通常不是一个好理由。
  • 那么我应该使用哪种会计系统?只要我可以集成到我的系统中?
  • @MikeSherrill'CatRecall' 我认为编写自己的代码有很多很好的理由,特别是如果它简单、具体且需要紧密集成。如果需要一周的时间来构建和几个月的时间来解决错误,那可能是合理的。依赖第三方软件总是让我害怕。恰当的例子:看看下面从 2012 年初开始接受的答案。Gemini-SimplyFi 可能是一个很好的 COTS 解决方案,但在 2015 年它已经死了。此外,使用别人的软件总是有学习成本的。我更愿意花时间构建我完全理解的东西。

标签: mysql database database-design billing invoice


【解决方案1】:

看看我的 Gemini - SimplyFi 插件。它将允许您相应地标记您的发票,可以在生成发票时自动通过电子邮件将其发送给客户,可以记录付款并针对未收到的付款(报表)发送提醒,并且具有完整的基于 REST 的 API,您可以使用它来集成到您的系统中。还可以从其功能的定期计费中受益。

在您提到负发票金额的地方,这些实际上是“信用票据”(根据我从您的帖子中了解到的)。通常,您不应在向客户开具发票后自行更改发票 - 如果您需要修改金额(即:增加或减去),那么您应该开具新发票(用于增加的金额) ,或贷方票据,用于减去金额。

另外,如果客户将在几周后收到新发票,我建议您不要将钱退回,只需跟踪他们的帐户余额,仅在必要时开具发票或贷记单。转移资金需要花钱,如果没有必要,您不需要这样做。只是我的 2 美分

【讨论】:

    猜你喜欢
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多