根据用户日期生成+分组新发票行

时间:2018-12-04 18:40:59

标签: c# .net sql-server list

我的情况如下:

用户被分配到一个或多个发票项目组(详细信息:用户名)。

一个项目组(= InvoiceLine)具有:

  • ID
  • 名称
  • 数量
  • 费用
  • 设置费用

itemgroupDetail(= InvoiceLineDetail)具有:

  • ID
  • ItemgroupID
  • 用户名

我的数量基于用户数量。

示例:

用户A(于2018年11月加入)在“ Group G1”列表中。

用户A(于2018年11月加入)在“ Group G2”列表中。

用户B(于2018年11月加入)在“ Group G3”列表中。

用户B(已于2018年3月加入)在列表“ G1组”中。

用户C(于2018年3月加入)在“ Group G3”列表中

需要开具什么发票? 所有项目组。但是,如果在开票的月份加入了用户,则该组本身也需要是单独的发票行(因为需要向新用户开一次发票,并且要为其所属的组开具费用)。

我的发票行(结果)必须看起来像

Quantity    Itemgroup   
    2       G1
    1       G2
    2       G3
    1       G1 NEW
    1       G2 NEW
    1       G3 NEW

我的问题是我不知道该如何应对动态需要创建新发票行(带有新详细信息)的事实。

这是我知道的代码:

我首先创建发票行(但我没有设置数量“ YET”):

 public List<Company_Recurring_Invoice_Line> getInvoiceLines(int invoiceID)
        {
            List<Company_Recurring_Invoice_Line> lines = new List<Company_Recurring_Invoice_Line>();
            SqlCommand command = new SqlCommand(@"SELECT * FROM ITEMGROUPS", conn);
            command.Parameters.Add("@invoiceID", SqlDbType.Int).Value = invoiceID;
            conn.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                Company_Recurring_Invoice_Line line = new Company_Recurring_Invoice_Line();
                line.invoiceID = invoiceID;
                line.itemgroupID = int.Parse(reader["id"].ToString());
                line.unitPrice = decimal.Parse(reader["price"].ToString());
                line.description = reader["name"].ToString();
                lines.Add(line);
            }
            conn.Close();
            return lines;
        }

此后,对于每个发票行,我都要翻阅用户+设置发票行的数量并将详细信息存储到发票行:

public Company_Invoice getInvoiceLineDetails(Company_Recurring_Invoice invoice)
        {
            Company_Recurring_Invoice i = invoice;

            foreach (Company_Recurring_Invoice_Line line in i.InvoiceLines)
            {
                getInvoiceLineDetails(line);
            }
            return i;
        }

public Company_Recurring_Invoice_Line getInvoiceLineLineDetails(Company_Recurring_Invoice_Line _line)
        {
            Company_Recurring_Invoice_Line Line = _line;
            Line.InvoiceLineDetails = new List<Company_Recurring_Invoice_Line_Detail>();
            SqlCommand command = new SqlCommand(@"SELECT * FROM PERSON WHERE ITEMGROUPID = @ITEMGROUP", conn);
            command.Parameters.Add("@ITEMGROUP", SqlDbType.Int).Value = Line.itemgroupID;
            conn.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
// We create a new detail line (with the name of the user + check it's date) 
//THIS IS WHERE I NEED TO CHECK IF THE MONTH OF THE USER = MONTH OF INVOICING AND ADD IT TO AN EXISTING OR NEW INVOICE LINE TOO 
            DateTime Date = DateTime.Parse(reader["joindate"].ToString());

                    Line.quantity++;
                    Company_Recurring_Invoice_Line_Detail detail = new Company_Recurring_Invoice_Line_Detail();
                detail.Value = reader["name"].ToString();
                detail.Company_Recurring_Invoice_Line = Line.InvoiceLineID;
                Line.InvoiceLineDetails.Add(detail);
            }
            conn.Close();
            return Line;
        }

我的代码非常适合新用户(我的行+详细信息生成完美),但我挠头想弄清楚如何实现它还需要创建单独的发票行IF的事实例如,用户的日期为11。请记住,新发票行也需要由多个用户填写。

实现此目标的最佳方法是什么?由于优化在这里并不是很重要,因此我一直在考虑只为此类或新类创建单独的方法(首先生成旧方法,然后创建新方法),但是我可以不这样做吗?

0 个答案:

没有答案