public void testCashFlowItemsPenjualanLain()
 {
     PeriodeId periodid = _periodeId;
     _cashFlow = new CashFlow("ABC", periodid, 1000000.0);
     _cashFlow.AddPenjualanLain(new DateTime(2015, 10, 1), 1500000.0);
     var cashFlowSnapshot = _cashFlow.Snap();
     var expected = new CashFlowDto()
     {
         TenantId = "ABC",
         PeriodId = _periode.Snap(),
         SaldoAwal = 1000000.0,
         SaldoAkhir = 2500000.0,
         TotalPenjualan = 0.0,
         TotalPenjualanLain = 1500000.0,
         TotalPengeluaran = 0.0
     };
     Assert.AreEqual(expected, cashFlowSnapshot);
     Assert.AreEqual(1, cashFlowSnapshot.ItemsPenjualanLain.Count);
     var itemPenjualanLainDto = cashFlowSnapshot.ItemsPenjualanLain[0];
     Assert.AreEqual(new DateTime(2015, 10, 1), itemPenjualanLainDto.DateTimeLain);
     Assert.AreEqual(1500000.0, itemPenjualanLainDto.NominalLain);
 }
        public void testMenginstanceDariSnapshot()
        {
            PeriodeId periodid = _periodeId;
            _cashFlow = new CashFlow("ABC", periodid, 1000000.0);
            _cashFlow.AddPenjualan(new DateTime(2015, 10, 1), 1500000.0);
            _cashFlow.AddPenjualan(new DateTime(2015, 10, 2), 2000000.0);
            _cashFlow.AddPenjualanLain(new DateTime(2015, 10, 1), 1500000.0);
            _cashFlow.AddPenjualanLain(new DateTime(2015, 10, 2), 2000000.0);
            _cashFlow.ChangePengeluaran("Ayam", 1400000.0,7);
            _cashFlow.ChangePengeluaran("Ayam", 2400000.0,14);

            var cashFlowSnapshot = _cashFlow.Snap();
            var cashflow = new CashFlow(cashFlowSnapshot);
            var loadedSanpshot = cashflow.Snap();

            Assert.AreEqual(cashFlowSnapshot, loadedSanpshot);

            Assert.AreEqual(2, loadedSanpshot.ItemsPenjualan.Count);
            var in1ItemPenjualanDto = loadedSanpshot.ItemsPenjualan[0];
            var in2ItemPenjualanDto = loadedSanpshot.ItemsPenjualan[1];
            Assert.AreEqual(new DateTime(2015, 10, 1), in1ItemPenjualanDto.DateTime);
            Assert.AreEqual(1500000.0, in1ItemPenjualanDto.Nominal);
            Assert.AreEqual(new DateTime(2015, 10, 2), in2ItemPenjualanDto.DateTime);
            Assert.AreEqual(2000000.0, in2ItemPenjualanDto.Nominal);

            Assert.AreEqual(2, loadedSanpshot.ItemsPenjualanLain.Count);
            var in1ItemPenjualanLainDto = loadedSanpshot.ItemsPenjualanLain[0];
            var in2ItemPenjualanLainDto = loadedSanpshot.ItemsPenjualanLain[1];
            Assert.AreEqual(new DateTime(2015, 10, 1), in1ItemPenjualanLainDto.DateTimeLain);
            Assert.AreEqual(1500000.0, in1ItemPenjualanLainDto.NominalLain);
            Assert.AreEqual(new DateTime(2015, 10, 2), in2ItemPenjualanLainDto.DateTimeLain);
            Assert.AreEqual(2000000.0, in2ItemPenjualanLainDto.NominalLain);

            Assert.AreEqual(1, loadedSanpshot.ItemsPengeluaran.Count);
            var in1ItemPengeluaranDto = loadedSanpshot.ItemsPengeluaran[0];
            Assert.AreEqual("Ayam", in1ItemPengeluaranDto.Akun);
            Assert.AreEqual(2400000.0, in1ItemPengeluaranDto.Nominal);
            Assert.AreEqual(14, in1ItemPengeluaranDto.Jumlah);
        }
 public void testSecenario()
 {
     PeriodeId periodid = _periodeId;
     _cashFlow = new CashFlow("ABC", periodid, 1000000.0);
     _cashFlow.AddPenjualan(new DateTime(2015, 10, 1), 1500000.0);
     _cashFlow.AddPenjualan(new DateTime(2015, 10, 2), 2000000.0);
     _cashFlow.AddPenjualanLain(new DateTime(2015, 10, 1), 1500000.0);
     _cashFlow.AddPenjualanLain(new DateTime(2015, 10, 2), 2000000.0);
     _cashFlow.ChangePengeluaran("Ayam", 1400000.0,7);
     _cashFlow.ChangePengeluaran("Ayam", 2400000.0,12);
     var snapPengeluaran = _cashFlow.Snap();
     var expectedPengeluaran = new CashFlowDto()
     {
         TenantId = "ABC",
         PeriodId = _periode.Snap(),
         SaldoAwal = 1000000.0,
         SaldoAkhir = 5600000.0,
         TotalPenjualan = 3500000.0,
         TotalPenjualanLain = 3500000.0,
         TotalPengeluaran = 2400000.0
     };
     Assert.AreEqual(expectedPengeluaran, snapPengeluaran);
 }
        public void TestCashflowSucessCase()
        {
            var repo = new InMemoryRepository();
            var periodeId1 = new PeriodeId(new DateTime(2015, 11, 1), new DateTime(2015, 11, 6));
            var periode = new Periode(periodeId1, StatusPeriode.Mingguan);
            repo.SavePeriod(periode);
            var periodeSnapShot = new PeriodeDto()
            {
                StartPeriode = new DateTime(2015, 11, 1),
                EndPeriode = new DateTime(2015, 11, 6),
                IsPeriode = StatusPeriode.Bebas
            };

            var periodeSave = repo.FindPeriodForDate(new DateTime(2015, 11, 3));

            Assert.AreEqual(periodeSnapShot, periodeSave.Snap());

            //cashflow
            var cashFlow = new CashFlow("ABC", periodeId1, 500000.0);
            repo.Save(cashFlow);

            var cashflowSnapshotDto = new CashFlowDto()
            {
                TenantId = "ABC",
                PeriodId = periode.Snap(),
                SaldoAwal = 500000.0,
                SaldoAkhir = 500000.0,
                TotalPenjualan = 0.0,
                TotalPenjualanLain = 0.0,
                TotalPengeluaran = 0.0,
            };

            var findCashFlow = repo.FindCashFlowByPeriod(periodeId1);
            Assert.AreEqual(cashflowSnapshotDto, findCashFlow.Snap());

            //Penjualan
            cashFlow.AddPenjualan(new DateTime(2015, 11, 1), 200000.0);
            repo.Save(cashFlow);
            var repoFind = repo.FindPeriodForDate(new DateTime(2015, 11, 3));
            var cashFlowSnapshot = cashFlow.Snap();
            var cashflowPenjualanSnapshot = new CashFlowDto()
            {
                TenantId = "ABC",
                PeriodId = periode.Snap(),
                SaldoAwal = 500000.0,
                SaldoAkhir = 700000.0,
                TotalPenjualan = 200000.0,
                TotalPenjualanLain = 0.0,
                TotalPengeluaran = 0.0,
            };

            Assert.AreEqual(cashflowPenjualanSnapshot, cashFlowSnapshot);
            Assert.AreEqual(1, cashFlowSnapshot.ItemsPenjualan.Count);
            var itemPenjualan = cashFlowSnapshot.ItemsPenjualan[0];
            Assert.AreEqual(new DateTime(2015, 11, 1), itemPenjualan.DateTime);
            Assert.AreEqual(200000.0, itemPenjualan.Nominal);

            //PenjualanLain
            cashFlow.AddPenjualanLain(new DateTime(2015, 11, 1), 200000.0);
            repo.Save(cashFlow);
            var repoFindLain = repo.FindPeriodForDate(new DateTime(2015, 11, 3));
            var cashFlowSnapshotLain = cashFlow.Snap();
            var cashflowPenjualanLainSnapshot = new CashFlowDto()
            {
                TenantId = "ABC",
                PeriodId = periode.Snap(),
                SaldoAwal = 500000.0,
                SaldoAkhir = 900000.0,
                TotalPenjualan = 200000.0,
                TotalPenjualanLain = 200000.0,
                TotalPengeluaran = 0.0,
            };

            Assert.AreEqual(cashflowPenjualanLainSnapshot, cashFlowSnapshotLain);
            Assert.AreEqual(1, cashFlowSnapshotLain.ItemsPenjualanLain.Count);
            var itemPenjualanLain = cashFlowSnapshotLain.ItemsPenjualanLain[0];
            Assert.AreEqual(new DateTime(2015, 11, 1), itemPenjualanLain.DateTimeLain);
            Assert.AreEqual(200000.0, itemPenjualanLain.NominalLain);

            //Pengeluaran
            cashFlow.ChangePengeluaran("Ayam",200000,5);
            repo.Save(cashFlow);
            var repoFindPengeluaran = repo.FindPeriodForDate(new DateTime(2015, 11, 3));
            var cashFlowSnapshotPengeluaran = cashFlow.Snap();
            var cashflowPengeluaranSnapshot = new CashFlowDto()
            {
                TenantId = "ABC",
                PeriodId = periode.Snap(),
                SaldoAwal = 500000.0,
                SaldoAkhir = 700000.0,
                TotalPenjualan = 200000.0,
                TotalPenjualanLain = 200000.0,
                TotalPengeluaran = 200000.0,
            };

            Assert.AreEqual(cashflowPengeluaranSnapshot, cashFlowSnapshotPengeluaran);
            Assert.AreEqual(1, cashFlowSnapshotPengeluaran.ItemsPengeluaran.Count);
            var itemPengeluaran = cashFlowSnapshotPengeluaran.ItemsPengeluaran[0];
            Assert.AreEqual("Ayam", itemPengeluaran.Akun);
            Assert.AreEqual(200000.0, itemPengeluaran.Nominal);
            Assert.AreEqual(5, itemPengeluaran.Jumlah);

            //NotaPengeluaran

            //var noNota = new NotaPengeluaranId("123");
            //var notaPengeluaran = new NotaPengeluaran(new DateTime(2015, 11, 1), noNota);
            //repo.SaveNota(notaPengeluaran);
            //var foundNota = repo.FindNotaPengeluaranByID("123");
            ////var notaSnapshot = notaPengeluaran.Snap();
            //var notaSnap = new NotaPengeluaranDto()
            //{
            //    Tanggal = new DateTime(2015, 11, 1),
            //    NoNota = noNota,
            //    TotalNota = 0.0
            //};
            //Assert.AreEqual(notaSnap, foundNota.Snap());

            ////AddAkunNota
            //notaPengeluaran.AddAkun("Ayam", 200000, 5);
            //repo.SaveNota(notaPengeluaran);
            //var repoFindNotaAkun = repo.FindPeriodForDate(new DateTime(2015, 11, 3));
            //var notaAkunSnapshot = notaPengeluaran.Snap();
            //var notaAkunSnap = new NotaPengeluaranDto()
            //{
            //    Tanggal = new DateTime(2015, 10, 26),
            //    NoNota = "123",
            //    TotalNota = 0.0
            //};
            //Assert.AreEqual(notaAkunSnap, notaAkunSnapshot);
        }