protected virtual IEnumerable history() { this.History.Cache.Clear(); ARStatementHistoryParameters header = Filter.Current; if (header == null) { yield break; } int? prevCustomerID = null; string prevCuryID = null; HistoryResult prevRec = null; PXResultset <ARStatement> res; List <object> stored = new List <object>(); PXSelectBase <ARStatement> select = new PXSelectJoin <ARStatement, LeftJoin <ARStatementCycle, On <ARStatementCycle.statementCycleId, Equal <ARStatement.statementCycleId> >, LeftJoin <Customer, On <Customer.bAccountID, Equal <ARStatement.statementCustomerID> > > >, Where <ARStatement.statementCustomerID, Equal <ARStatement.customerID>, And <ARStatement.statementDate, GreaterEqual <Required <ARStatement.statementDate> >, And <ARStatement.statementDate, LessEqual <Required <ARStatement.statementDate> >, And <Where <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> >, Or <Required <ARStatement.statementCycleId>, IsNull> > > > > >, OrderBy <Asc <ARStatement.statementCycleId, Asc <ARStatement.statementDate, Asc <ARStatement.customerID, Asc <ARStatement.curyID> > > > > >(this); using (new PXFieldScope(select.View, typeof(ARStatement.branchID), typeof(ARStatement.statementCycleId), typeof(ARStatement.statementDate), typeof(ARStatement.customerID), typeof(ARStatement.statementCustomerID), typeof(ARStatement.curyID), typeof(ARStatement.dontPrint), typeof(ARStatement.dontEmail), typeof(ARStatement.printed), typeof(ARStatement.emailed), typeof(ARStatementCycle.descr), typeof(Customer.printCuryStatements))) { res = select.Select(header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId); } foreach (PXResult <ARStatement, ARStatementCycle, Customer> item in res) { stored.Add(item); ARStatement st = item; ARStatementCycle cycle = item; Customer cust = item; HistoryResult rec = new HistoryResult { StatementCycleId = st.StatementCycleId, StatementDate = st.StatementDate, Descr = cycle.Descr, DontPrintCount = 0, DontEmailCount = 0, PrintedCount = 0, EmailedCount = 0, NoActionCount = 0 }; rec = (HistoryResult)this.History.Cache.Locate(rec) ?? this.History.Insert(rec); if (rec != null) { if (prevRec != rec) { prevCustomerID = null; prevCuryID = null; } if (prevCustomerID != st.CustomerID || (cust.PrintCuryStatements == true && prevCuryID != st.CuryID)) { rec.NumberOfDocuments += 1; rec.DontPrintCount += st.DontPrint == true ? 1 : 0; rec.DontEmailCount += st.DontEmail == true ? 1 : 0; rec.NoActionCount += st.DontEmail == true && st.DontPrint == true ? 1 : 0; rec.PrintedCount += st.Printed == true ? 1 : 0; rec.EmailedCount += st.Emailed == true ? 1 : 0; } prevRec = rec; prevCustomerID = st.CustomerID; prevCuryID = st.CuryID; } } select.StoreCached(new PXCommandKey(new object[] { header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId }), stored); this.History.Cache.IsDirty = false; foreach (HistoryResult ret in this.History.Cache.Inserted) { yield return(ret); } }
protected virtual IEnumerable history() { this.History.Cache.Clear(); ARStatementHistoryParameters header = Filter.Current; if (header == null) { yield break; } Dictionary <string, Dictionary <DateTime, int> > result = new Dictionary <string, Dictionary <DateTime, int> >(); Dictionary <string, string> dictARStatementCycle = new Dictionary <string, string>(); int? prevCustomerID = null; string prevCuryID = null; HistoryResult prevRec = null; foreach (PXResult <ARStatement, ARStatementCycle, Customer> item in PXSelectJoin <ARStatement, LeftJoin <ARStatementCycle, On <ARStatementCycle.statementCycleId, Equal <ARStatement.statementCycleId> >, LeftJoin <Customer, On <Customer.bAccountID, Equal <ARStatement.customerID> > > >, Where <ARStatement.statementDate, GreaterEqual <Required <ARStatement.statementDate> >, And <ARStatement.statementDate, LessEqual <Required <ARStatement.statementDate> >, And <Where <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> >, Or <Required <ARStatement.statementCycleId>, IsNull> > > > >, OrderBy <Asc <ARStatement.statementCycleId, Asc <ARStatement.statementDate, Asc <ARStatement.customerID, Asc <ARStatement.curyID> > > > > > .Select(this, header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId)) { ARStatement st = item; Customer cust = item; HistoryResult rec = new HistoryResult(); rec.StatementCycleId = st.StatementCycleId; rec.StatementDate = st.StatementDate; rec.Descr = ((ARStatementCycle)item).Descr; rec.DontPrintCount = 0; rec.DontEmailCount = 0; rec.PrintedCount = 0; rec.EmailedCount = 0; rec.NoActionCount = 0; rec = (HistoryResult)this.History.Cache.Locate(rec) ?? this.History.Insert(rec); if (rec != null) { if (prevRec != rec) { prevCustomerID = null; prevCuryID = null; } if (prevCustomerID != st.CustomerID || (cust.PrintCuryStatements == true && prevCuryID != st.CuryID)) { rec.NumberOfDocuments += 1; rec.DontPrintCount += ((st.DontPrint ?? false) == true) ? 1 : 0; rec.DontEmailCount += ((st.DontEmail ?? false) == true) ? 1 : 0; rec.NoActionCount += ((st.DontEmail ?? false) == true && (st.DontPrint ?? false) == true) ? 1 : 0; rec.PrintedCount += ((st.Printed ?? false) == true) ? 1 : 0; rec.EmailedCount += ((st.Emailed ?? false) == true) ? 1 : 0; } prevRec = rec; prevCustomerID = st.CustomerID; prevCuryID = st.CuryID; } /* * if (result.ContainsKey(((ARStatement)st).StatementCycleId)) * { * if (result[((ARStatement)st).StatementCycleId].ContainsKey(((ARStatement)st).StatementDate ?? DateTime.MinValue)) * { * result[((ARStatement)st).StatementCycleId][((ARStatement)st).StatementDate ?? DateTime.MinValue] = result[((ARStatement)st).StatementCycleId][((ARStatement)st).StatementDate ?? DateTime.MinValue] + 1; * } * else * { * result[((ARStatement)st).StatementCycleId].Add(((ARStatement)st).StatementDate ?? DateTime.MinValue, 1); * } * } * else * { * Dictionary<DateTime, int> dictValue = new Dictionary<DateTime, int>(); * dictValue.Add(((ARStatement)st).StatementDate ?? DateTime.MinValue, 1); * result.Add(((ARStatement)st).StatementCycleId, dictValue); * } * if(dictARStatementCycle.ContainsKey (((ARStatement)st).StatementCycleId) == false) * dictARStatementCycle.Add(((ARStatement)st).StatementCycleId, ((ARStatementCycle)st).Descr); */ } this.History.Cache.IsDirty = false; foreach (HistoryResult ret in this.History.Cache.Inserted) { yield return(ret); } /* * foreach (string statementCycleId in result.Keys) * { * foreach (DateTime statementDate in result[statementCycleId].Keys) * { * HistoryResult res = new HistoryResult(); * res.StatementCycleId = statementCycleId; * res.StatementDate = statementDate; * res.NumberOfDocuments = result[statementCycleId][statementDate]; * res.Descr = dictARStatementCycle[statementCycleId]; * yield return res; * } * } */ }