public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <GLBATCH>
            <JOURNAL />
            <BATCH_DATE />
            <BATCH_TITLE />
            <ENTRIES>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
            </ENTRIES>
        </GLBATCH>
    </create>
</function>";

            JournalEntryCreate record = new JournalEntryCreate("unittest");

            JournalEntryLineCreate line1 = new JournalEntryLineCreate();
            JournalEntryLineCreate line2 = new JournalEntryLineCreate();

            record.Lines.Add(line1);
            record.Lines.Add(line2);

            this.CompareXml(expected, record);
        }
        public void GetAllXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <GLBATCH>
            <JOURNAL>GJ</JOURNAL>
            <BATCH_DATE>06/30/2016</BATCH_DATE>
            <REVERSEDATE>07/01/2016</REVERSEDATE>
            <BATCH_TITLE>My desc</BATCH_TITLE>
            <HISTORY_COMMENT>comment!</HISTORY_COMMENT>
            <REFERENCENO>123</REFERENCENO>
            <BASELOCATION_NO>100</BASELOCATION_NO>
            <SUPDOCID>AT001</SUPDOCID>
            <STATE>Posted</STATE>
            <CUSTOMFIELD01>test01</CUSTOMFIELD01>
            <ENTRIES>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
            </ENTRIES>
        </GLBATCH>
    </create>
</function>";

            JournalEntryCreate record = new JournalEntryCreate("unittest")
            {
                JournalSymbol   = "GJ",
                PostingDate     = new DateTime(2016, 06, 30),
                ReverseDate     = new DateTime(2016, 07, 01),
                Description     = "My desc",
                HistoryComment  = "comment!",
                ReferenceNumber = "123",
                AttachmentsId   = "AT001",
                Action          = "Posted",
                SourceEntityId  = "100",
                CustomFields    = new Dictionary <string, dynamic>
                {
                    { "CUSTOMFIELD01", "test01" }
                },
            };

            JournalEntryLineCreate line1 = new JournalEntryLineCreate();
            JournalEntryLineCreate line2 = new JournalEntryLineCreate();

            record.Lines.Add(line1);
            record.Lines.Add(line2);

            this.CompareXml(expected, record);
        }
Пример #3
0
        //get create
        public ActionResult Create(int id)
        {
            var model =
                new JournalEntryCreate
            {
                PromptId = id
            };

            return(View(model));
        }
Пример #4
0
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <GLBATCH>
            <JOURNAL />
            <BATCH_DATE />
            <BATCH_TITLE />
            <ENTRIES>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
            </ENTRIES>
        </GLBATCH>
    </create>
</function>";

            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Encoding    = Encoding.UTF8;
            xmlSettings.Indent      = true;
            xmlSettings.IndentChars = "    ";

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            JournalEntryCreate record = new JournalEntryCreate("unittest");

            JournalEntryLineCreate line1 = new JournalEntryLineCreate();
            JournalEntryLineCreate line2 = new JournalEntryLineCreate();

            record.Lines.Add(line1);
            record.Lines.Add(line2);

            record.WriteXml(ref xml);

            xml.Flush();
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);

            Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd())
                           .WithDifferenceEvaluator(DifferenceEvaluators.Default)
                           .Build();

            Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString());
        }
Пример #5
0
        /// <summary>
        /// Sends a Journal to the Intacct GL System
        /// </summary>
        /// <param name="client"></param>
        /// <param name="Org"></param>
        /// <param name="lines"></param>
        /// <param name="PostingDate"></param>
        /// <param name="ReferenceNumber"></param>
        /// <param name="JournalSymbol"></param>
        /// <param name="Description"></param>
        /// <param name="HistoryComment"></param>
        /// <param name="AsDraft"></param>
        /// <returns></returns>
        private async Task SendJournalCmd(OnlineClient client, int Org, IEnumerable <JournalExtract> lines, DateTime PostingDate, string ReferenceNumber, string JournalSymbol, string Description, string HistoryComment, bool AsDraft)
        {
            JournalEntryCreate create = new JournalEntryCreate();

            create.JournalSymbol   = JournalSymbol;
            create.ReferenceNumber = ReferenceNumber;
            create.PostingDate     = PostingDate;
            create.Description     = Description;
            create.HistoryComment  = HistoryComment;
            if (AsDraft)
            {
                create.CustomFields.Add("STATE", "Draft");
            }
            foreach (var item in lines)
            {
                JournalEntryLineCreate line = new JournalEntryLineCreate
                {
                    GlAccountNumber   = item.AccountCode,
                    TransactionAmount = decimal.Parse(item.NomAmount.ToString("F2")),
                    Memo = String.IsNullOrWhiteSpace(item.NomTransRef) ? item.NomNarrative : item.NomNarrative + " (" + item.NomTransRef + ")"
                };
                if (!String.IsNullOrWhiteSpace(item.IntacctCustomerID))
                {
                    line.CustomerId = item.IntacctCustomerID;
                }
                if (!String.IsNullOrWhiteSpace(item.IntacctEmployeeID))
                {
                    line.EmployeeId = item.IntacctEmployeeID;
                }
                if (!String.IsNullOrWhiteSpace(item.IntacctProjectID))
                {
                    line.ProjectId = item.IntacctProjectID;
                }
                if (!String.IsNullOrWhiteSpace(item.IntacctDepartment))
                {
                    line.DepartmentId = item.IntacctDepartment;
                }
                if (!String.IsNullOrWhiteSpace(item.IntacctLocation))
                {
                    line.LocationId = item.IntacctLocation;
                }
                create.Lines.Add(line);
            }
            OnlineResponse onlineResponse = await client.Execute(create);

            foreach (var result in onlineResponse.Results)
            {
                result.EnsureStatusSuccess();
            }
        }
Пример #6
0
        public IHttpActionResult Post(JournalEntryCreate journal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateJournalService();

            if (!service.CreateJournalEntry(journal))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #7
0
        public bool CreateEntry(JournalEntryCreate model)
        {
            var entity =
                new JournalEntry()
            {
                UserId          = _userId,
                PromptId        = model.PromptId,
                Content         = model.Content,
                PhotoUrl        = model.PhotoUrl,
                PublicOrPrivate = model.PublicOrPrivate,
                Tag             = model.Tag,
                CreatedUtc      = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.JournalEntries.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Пример #8
0
        public ActionResult Create(JournalEntryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new JournalEntryServices(userId);

            if (service.CreateEntry(model))
            {
                TempData["SaveResult"] = "Your entry was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Resource could not be created.");
            return(View(model));
            //GetPrompt();
        }
Пример #9
0
        public void GetAllXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <GLBATCH>
            <JOURNAL>GJ</JOURNAL>
            <BATCH_DATE>06/30/2016</BATCH_DATE>
            <REVERSEDATE>07/01/2016</REVERSEDATE>
            <BATCH_TITLE>My desc</BATCH_TITLE>
            <HISTORY_COMMENT>comment!</HISTORY_COMMENT>
            <REFERENCENO>123</REFERENCENO>
            <BASELOCATION_NO>100</BASELOCATION_NO>
            <SUPDOCID>AT001</SUPDOCID>
            <STATE>Posted</STATE>
            <CUSTOMFIELD01>test01</CUSTOMFIELD01>
            <ENTRIES>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
                <GLENTRY>
                    <ACCOUNTNO />
                    <TR_TYPE>1</TR_TYPE>
                    <TRX_AMOUNT />
                </GLENTRY>
            </ENTRIES>
        </GLBATCH>
    </create>
</function>";

            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Encoding    = Encoding.UTF8;
            xmlSettings.Indent      = true;
            xmlSettings.IndentChars = "    ";

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            JournalEntryCreate record = new JournalEntryCreate("unittest")
            {
                JournalSymbol   = "GJ",
                PostingDate     = new DateTime(2016, 06, 30),
                ReverseDate     = new DateTime(2016, 07, 01),
                Description     = "My desc",
                HistoryComment  = "comment!",
                ReferenceNumber = "123",
                AttachmentsId   = "AT001",
                Action          = "Posted",
                SourceEntityId  = "100",
                CustomFields    = new Dictionary <string, dynamic>
                {
                    { "CUSTOMFIELD01", "test01" }
                },
            };

            JournalEntryLineCreate line1 = new JournalEntryLineCreate();
            JournalEntryLineCreate line2 = new JournalEntryLineCreate();

            record.Lines.Add(line1);
            record.Lines.Add(line2);

            record.WriteXml(ref xml);

            xml.Flush();
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);

            Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd())
                           .WithDifferenceEvaluator(DifferenceEvaluators.Default)
                           .Build();

            Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString());
        }
Пример #10
0
        public bool CreateJournalEntry(JournalEntryCreate model)
        {
            var entity =
                new JournalEntry()
            {
                UserId     = _userId,
                FoodList   = model.FoodList,
                MealList   = model.MealList,
                RecipeList = model.RecipeList,
                TimeStamp  = model.JournalDate,
            };

            double carbs    = 0;
            double protein  = 0;
            double fats     = 0;
            double calories = 0;

            if (model.FoodList != null)
            {
                foreach (int i in model.FoodList)
                {
                    using (var ctx = new ApplicationDbContext())
                    {
                        carbs    += ctx.FoodItems.Find(i).Carbs;
                        protein  += ctx.FoodItems.Find(i).Protein;
                        fats     += ctx.FoodItems.Find(i).Fat;
                        calories += ctx.FoodItems.Find(i).Calories;
                    }
                }
            }

            if (model.MealList != null)
            {
                foreach (int i in model.MealList)
                {
                    using (var ctx = new ApplicationDbContext())
                    {
                        carbs    += ctx.DailyMeals.Find(i).Carbs;
                        protein  += ctx.DailyMeals.Find(i).Protein;
                        fats     += ctx.DailyMeals.Find(i).Fat;
                        calories += ctx.DailyMeals.Find(i).Calories;
                    }
                }
            }

            if (model.RecipeList != null)
            {
                foreach (int i in model.RecipeList)
                {
                    using (var ctx = new ApplicationDbContext())
                    {
                        carbs    += ctx.Recipes.Find(i).Carbs / ctx.Recipes.Find(i).HowManyPortions;
                        protein  += ctx.Recipes.Find(i).Protein / ctx.Recipes.Find(i).HowManyPortions;
                        fats     += ctx.Recipes.Find(i).Fat / ctx.Recipes.Find(i).HowManyPortions;
                        calories += ctx.Recipes.Find(i).Calories / ctx.Recipes.Find(i).HowManyPortions;
                    }
                }
            }

            entity.Carbs    = carbs;
            entity.Proteins = protein;
            entity.Fats     = fats;
            entity.Calories = calories;

            //find Days where e.journalDate =
            using (var ctx = new ApplicationDbContext())
            {
                var dayEntity =
                    ctx
                    .Days
                    .Where(e => e.UserId.Equals(_userId))
                    .ToList()
                    .SingleOrDefault(e => e.DateOfEntry.Date == entity.TimeStamp.Date);


                //If there is no day object for the date of the journal entry, create a day and give the journal entries dayID the new DayID
                if (dayEntity == null)
                {
                    var newDayEntity =
                        new Day
                    {
                        DateOfEntry = model.JournalDate,
                        UserId      = _userId
                    };

                    //save new day
                    ctx.Days.Add(newDayEntity);
                    var didItWork = ctx.SaveChanges();

                    //add the new dayID to our journal entry and add to the database.
                    if (didItWork > 0)
                    {
                        entity.DayId = newDayEntity.DayId;

                        //add journal entry to list of journal entries in day
                        newDayEntity.JournalEntries.Add(entity);
                        ctx.JournalEntries.Add(entity);
                        return(ctx.SaveChanges() > 0);
                    }
                }

                //If the day exists, make the journal entrys dayId the existing day ID
                entity.DayId = ctx.Days.Find(dayEntity.DayId).DayId;

                //add journal entry to Day's list of journal entries
                dayEntity.JournalEntries.Add(entity);

                ctx.JournalEntries.Add(entity);
                return(ctx.SaveChanges() > 0);
            }
        }