// Created QuoteAdt Record which lists changes we made
//
// 12/13/2016 HK: Initial Epicor 10 Conversion
// 12/26/2016 HK: Final Conversion Tasks - Ready for E10
//
const string bpmName = "Quote.Update.PRE.CreateAuditRecord";
Ice.Diagnostics.Log.WriteEntry(String.Format("[ {0} ] START", bpmName));
// Initialize Vars
string changeList = string.Empty;
bool hasChanges = false;
// Main Query
// Get Quotes however only when the ChangeDescription is specified
var quotes =
from tqh in ttQuoteHed
join qh in Db.QuoteHed.With(LockHint.NoLock) on tqh.QuoteNum equals qh.QuoteNum
where tqh.Updated() && tqh.ChangeDescription != ""
select new { tqh, qh };
foreach (var quoteRow in quotes)
{
// Clear out The Vars if we have multiple
changeList = string.Empty;
hasChanges = false;
/* Confidence Pct */
if (quoteRow.qh.ConfidencePct != quoteRow.tqh.ConfidencePct)
{
hasChanges = true;
changeList += "[QuoteHed.ConfidencePct] " + "Old: " + Convert.ToString(quoteRow.qh.ConfidencePct) + " - New: " + Convert.ToString(quoteRow.tqh.ConfidencePct) + Environment.NewLine;
}
/* Date Quoted */
if (quoteRow.qh.DateQuoted != quoteRow.tqh.DateQuoted && quoteRow.qh.DateQuoted.HasValue && quoteRow.tqh.DateQuoted.HasValue)
{
hasChanges = true;
changeList += "[QuoteHed.DateQuoted] " + "Old: " + Convert.ToString(quoteRow.qh.DateQuoted) + " - New: " + Convert.ToString(quoteRow.tqh.DateQuoted) + Environment.NewLine;
}
if (hasChanges == true)
{
using (var txScope = IceDataContext.CreateDefaultTransactionScope())
{
Ice.Diagnostics.Log.WriteEntry(String.Format("[ {0} ] Starting Transaction...", bpmName));
// Create New
Erp.Tables.QuoteAdt QuoteAdt = new Erp.Tables.QuoteAdt();
Db.QuoteAdt.Insert(QuoteAdt);
QuoteAdt.Company = Session.CompanyID;
QuoteAdt.QuoteNum = quoteRow.tqh.QuoteNum;
QuoteAdt.ChangeDate = quoteRow.tqh.ChangeDate;
QuoteAdt.ChangeTime = System.Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds);
QuoteAdt.ChangedBy = Session.UserID;
QuoteAdt.ChangeDescription = "[CHANGES] \n \n" + changeList;
// Do I have to call ?
//Db.QuoteAdt.Update(QuoteAdt)
// Commit to Database
Db.Validate(QuoteAdt);
// Complete Transaction
txScope.Complete();
Ice.Diagnostics.Log.WriteEntry(String.Format("[ {0} ] Ending Transaction...", bpmName));
}
}
}
Ice.Diagnostics.Log.WriteEntry(String.Format("[ {0} ] END", bpmName));
// EPICOR 9
def var changeList as character init "".
def var hasChanges as logical init false.
for each ttQuoteHed where ttQuoteHed.RowMod = "U" and ttQuoteHed.ChangeDescription eq "", first QuoteHed where QuoteHed.QuoteNum = ttQuoteHed.QuoteNum.
// If we have multiple
assign changeList = "".
assign hasChanges = false.
// Confidence Pct
IF (QuoteHed.ConfidencePct ne ttQuoteHed.ConfidencePct) THEN DO:
assign hasChanges = true.
assign changeList = changeList + "[QuoteHed.ConfidencePct] " + "Old: " + string(QuoteHed.ConfidencePct) + " - New: " + string(ttQuoteHed.ConfidencePct) + "~n".
END.
// DateQuoted
IF (QuoteHed.DateQuoted ne ttQuoteHed.DateQuoted and QuoteHed.DateQuoted ne ? and ttQuoteHed.DateQuoted ne ?) THEN DO:
assign hasChanges = true.
assign changeList = changeList + "[QuoteHed.DateQuoted] " + "Old: " + string(QuoteHed.DateQuoted) + " - New: " + string(ttQuoteHed.DateQuoted) + "~n".
END.
// If we have changes
IF (hasChanges eq true) THEN DO:
CREATE QuoteAdt.
ASSIGN
QuoteAdt.Company = CUR-COMP
QuoteAdt.QuoteNum = ttQuoteHed.QuoteNum
QuoteAdt.ChangeDate = ttQuoteHed.ChangeDate
QuoteAdt.ChangeTime = TIME - 35
QuoteAdt.ChangedBy = DCD-USERID
QuoteAdt.ChangeDescription = "[CHANGES] ~n ~n" + changeList.
END.
end.