Page 1 of 1

GL Journal Post

PostPosted: Tue Jul 26, 2022 1:14 pm
by 2can2
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

Re: GL Journal Post

PostPosted: Tue Jul 26, 2022 3:02 pm
by Scott.Pearce
Absolutely.

I know we have a plugin that adds a button to the journal set form that when clicked allows a journal to be created from a chosen CSV file.

Or perhaps the external application could call into our code and create the journal directly.

What exactly did you have in mind?

Re: GL Journal Post

PostPosted: Tue Jul 26, 2022 8:20 pm
by SBarnes
I've written a windows service that inserted a journal from a wages package called HR3 below is the code that inserts a pending journal with a note on it to be used as a reference to what has been imported given Jiwa doesn't allow custom fields on Journals, it may point you in the right direction


Code: Select all
 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;
            }

           


        }


Re: GL Journal Post

PostPosted: Thu Aug 11, 2022 10:37 am
by 2can2
Hi,
Thank you both for the replies.
Scott could you attach the plugin you mentioned I am sure the client could mod this or get a good idea of what he needs to do.
Cheers

Re: GL Journal Post

PostPosted: Thu Aug 11, 2022 10:42 am
by Scott.Pearce
Enjoy:

Plugin Journal Set CSV Import.xml
(42.52 KiB) Downloaded 747 times

Re: GL Journal Post  Topic is solved

PostPosted: Thu Aug 11, 2022 10:52 am
by 2can2
Hi Scott,
I have just found the plugin attached to another query. Thanks.