/// <summary> /// 取得所有開立訂單與阿票號碼 /// </summary> /// <param name="filterID">[31=>B2B],[32=>B2C]</param> /// <returns></returns> private List <ContactModel> GetAllERPEinvoiceDataB2B(DateTime startDate, DateTime endDate, FilterInvoiceType filterType) { string type = filterType.GetDescription(); List <ContactModel> phoneOrderNumbers = new List <ContactModel>(); try { phoneOrderNumbers = this.DB.Rinnai_GUI_Transaction_Header .Where(o => o.GUI_Transaction_Type == "SAL" && (SqlFunctions.Replicate("0", 5 - o.Period_Of_Declaration.Length) + o.Period_Of_Declaration).CompareTo("10611") > 0 && o.Order_Date > new DateTime(2011, 01, 01) && o.GUI_Foramt_Code == "31" && o.VAT_Tax_Type == type && o.Return_Seq__No_ == 0 && o.Create_Date >= startDate && o.Create_Date <= endDate) .Select(s => new ContactModel() { InvoiceNumber = s.VAT_Transaction_Number, StartDate = s.Order_Date, OrderNumber = s.Order_No_ } ) .ToList(); #region 無發票直接回傳 if (phoneOrderNumbers.Count == 0) { return(phoneOrderNumbers); } #endregion 無發票直接回傳 } catch (Exception ex) { throw ex; } return(phoneOrderNumbers); }
/// <summary> /// 取得所有開立訂單與阿票號碼 /// </summary> /// <param name="filterID">[31=>B2B],[32=>B2C]</param> /// <returns></returns> private List <ContactModel> GetAllERPEinvoiceDataB2C(DateTime startDate, DateTime endDate, FilterInvoiceType filterType) { string type = filterType.GetDescription(); List <ContactModel> phoneOrderNumbers = new List <ContactModel>(); try { List <string> invoiceNumbers = this.DB.Rinnai_GUI_Transaction_Header .Where(o => o.GUI_Transaction_Type == "SAL" && (SqlFunctions.Replicate("0", 5 - o.Period_Of_Declaration.Length) + o.Period_Of_Declaration).CompareTo("10611") > 0 && o.Order_Date > new DateTime(2011, 01, 01) && o.GUI_Foramt_Code == "32" && o.VAT_Tax_Type == type && o.Return_Seq__No_ == 0 && o.Create_Date >= startDate && o.Create_Date <= endDate) .Select(s => s.Invoice_No_) .ToList(); #region 無發票直接回傳 if (invoiceNumbers.Count == 0) { return(phoneOrderNumbers); } #endregion 無發票直接回傳 List <string> serviceOrderNumbers = this.DB.Rinnai_Service_Ledger_Entry .Where(o => invoiceNumbers.Contains(o.Document_No_) && o.Document_Type == 2) .Select(s => s.Service_Order_No_) .Distinct() .ToList(); phoneOrderNumbers = this.DB.Rinnai_Posted_Service_Header .Where(o => serviceOrderNumbers.Contains(o.No_)) .Select(s => new ContactModel() { OrderNumber = s.No_, StartDate = s.Starting_Date }) .ToList(); //取發票號碼 foreach (var obj in phoneOrderNumbers) { var inv = this.DB.Rinnai_Sales_Invoice_Line.Where(o => o.Shipment_No_ == obj.OrderNumber).FirstOrDefault(); if (inv != null) { obj.InvoiceNumber = inv.VAT_Transaction_Number; } } } catch (Exception ex) { throw ex; } return(phoneOrderNumbers); }