Hi. A client is creating Journals for timesheets captured externally to Jiwa V72. Can he use the Jiwa core code call to create the Journal to do the necessary updates?
Cheers
public void InsertJournal()
{
eResult.AddLine("Insert Journal Called");
JiwaFinancials.Jiwa.JiwaApplication.Manager manager = null;
try
{
manager = new JiwaFinancials.Jiwa.JiwaApplication.Manager();
manager.Logon(reader.Server, reader.Database, JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, reader.JiwaUser, reader.JiwaPassword);
//JiwaDBWorker.CopyBasketAfterProcessing("00000005GA0000000002");
this.eResult.AddLine("JiwaWebOrderProcessor constructor called");
// JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm form = manager.FormFactory.CreateForm<JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm>();
}
catch (Exception ex)
{
if(manager == null || manager.Database == null || ! manager.Database.IsConnected)
throw ex;
}
JournalSet oJournal = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
oJournal.CreateNew();
oJournal.SetType = JournalSet.SetTypes.Pending;
HR3Record hrecord = Records[0];
var noteTypes = manager.CollectionFactory.CreateCollection<NoteTypeCollection, NoteType>();
noteTypes.NoteType = "JiwaFinancials.Jiwa.JiwaJournalSets.JournalSet";
noteTypes.Read();
var defaultNoteType = noteTypes.GetDefaultNoteType();
JiwaFinancials.Jiwa.JiwaApplication.Notes.Note note = manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Notes.Note>();
note.ItemNo = 1;
note.LastSavedDateTime = DateTime.Now;
note.LastModifiedByStaffMember = manager.EntityFactory.CreateEntity<JiwaFinancials.Jiwa.JiwaApplication.Entities.Staff.Staff>();
note.LastModifiedByStaffMember.ReadRecord(manager.Staff.RecID);
note.NoteText = "HR3:"+ hrecord.EarnHistID;
oJournal.Notes.Add(note);
oJournal.PostedDate = (DateTime)hrecord.Processed;
//oJournal.TransactionCode = "Pay";
oJournal.Description ="HR3 Run Number: " + hrecord.RunNo.ToString();
if (hrecord.Memo.Length > 50)
{
hrecord.Memo = hrecord.Memo.Substring(0, 50);
}
oJournal.Description += Environment.NewLine + hrecord.Memo;
// int i = 0;
foreach (HR3Record record in Records)
{
if (record.GLDBCode != "" && !record.ProcessedDB)
{
string strAcc = GetAccount(record.GLDBCode);
if (strAcc != "")
{
JiwaFinancials.Jiwa.JiwaJournalSets.Line line = manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaJournalSets.Line>();
line.GLAccount.ReadRecordFromAccountNo(strAcc);
line.DebitAmount = (decimal)record.Amount;
oJournal.Lines.Add(line);
}
record.ProcessedDB = true;
}
if (record.GLCRCode != "" && !record.ProcessedCR)
{
string strAcc = GetAccount(record.GLCRCode);
if (strAcc != "")
{
JiwaFinancials.Jiwa.JiwaJournalSets.Line line = manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaJournalSets.Line>();
line.GLAccount.ReadRecordFromAccountNo(strAcc);
line.CreditAmount = (decimal)record.Amount;
oJournal.Lines.Add(line);
}
record.ProcessedCR = true;
}
}
double DebitTotal = 0;
double CreditTotal = 0;
foreach (JiwaFinancials.Jiwa.JiwaJournalSets.Line item in oJournal.Lines)
{
DebitTotal += (double)item.DebitAmount;
CreditTotal += (double)item.CreditAmount;
}
if (Math.Round(DebitTotal, 2) != Math.Round(CreditTotal, 2))
{
eResult.AddLine("Insert Journal Called failed due to unbalanced debits and credits, credits total " + CreditTotal.ToString("$#,##0.00") + " and debits total " + DebitTotal.ToString("$#,##0.00"));
eResult.EResult = EmailResultValues.Failed;
eResult.AddLine(ToRecordsString());
foreach (JiwaFinancials.Jiwa.JiwaJournalSets.Line item in oJournal.Lines)
{
if (item.DebitAmount != 0)
{
eResult.AddLine("Debit " + item.GLAccount.AccountNo + " " + GetAccountName(item.GLAccount.AccountNo) + " Amount: " + item.DebitAmount.ToString("$#,##.00"));
}
if (item.CreditAmount != 0)
{
eResult.AddLine("Credit " + item.GLAccount.AccountNo + " " + GetAccountName(item.GLAccount.AccountNo) + " Amount: " + item.CreditAmount.ToString("$#,##.00"));
}
}
if (reader.SendInternalMessage)
{
SendInternalMessage(manager, GetEmailUsers().Select(user => user.UserCode).ToList(), "HR3 Journal insert failed", "Insert Journal Called failed to add journal because journal does not balance for run " + hrecord.RunNo.ToString(), oJournal);
}
return;
}
try
{
oJournal.Save();
eResult.AddLine("Insert Journal Call succeeded journal number " + oJournal.DocumentNo + " added with " + oJournal.Lines.Count.ToString() + " lines.");
if (reader.SendInternalMessage)
{
SendInternalMessage(manager, GetEmailUsers().Select(user => user.UserCode).ToList(), "Insert HR3 Journal Success", "Insert Journal number " + oJournal.DocumentNo + " added with " + oJournal.Lines.Count.ToString() + " lines.", oJournal);
}
}
catch (Exception ex)
{
eResult.AddLine("Insert Journal Called failed to add journal because " + ex.Message);
if (reader.SendInternalMessage)
{
SendInternalMessage(manager, GetEmailUsers().Select(user => user.UserCode).ToList(), "HR3 Journal insert failed", "Insert Journal Called failed to add journal because " + ex.Message, oJournal);
}
eResult.EResult = EmailResultValues.Failed;
}
}
Return to Technical and or Programming
Users browsing this forum: No registered users and 32 guests