Beispiel #1
0
        private void CreateJournalTransaction(BankExpenditureNoteModel model, IdentityService identityService)
        {
            var items = new List <JournalTransactionItem>();

            foreach (var detail in model.Details)
            {
                var sumDataByUnit = detail.Items.GroupBy(g => g.UnitCode).Select(s => new
                {
                    s.First().UnitCode,
                    Total = s.Sum(sm => sm.Price)
                });

                foreach (var datum in sumDataByUnit)
                {
                    var item = new JournalTransactionItem()
                    {
                        COA = new COA()
                        {
                            Code = COAGenerator.GetDebtCOA(model.SupplierImport, detail.DivisionName, datum.UnitCode)
                        },
                        Debit = datum.Total
                    };

                    items.Add(item);
                }
            }

            items = items.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            {
                COA   = s.First().COA,
                Debit = s.Sum(sm => sm.Debit)
            }).ToList();

            var bankJournalItem = new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = model.BankAccountCOA
                },
                Credit = items.Sum(s => s.Debit)
            };

            items.Add(bankJournalItem);

            var modelToPost = new JournalTransaction()
            {
                Date        = DateTimeOffset.Now,
                Description = "Bukti Pengeluaran Bank",
                ReferenceNo = model.DocumentNo,
                Items       = items
            };

            string journalTransactionUri = "journal-transactions";
            //var httpClient = new HttpClientService(identityService);
            var httpClient = (IHttpClientService)serviceProvider.GetService(typeof(IHttpClientService));
            var response   = httpClient.PostAsync($"{APIEndpoint.Finance}{journalTransactionUri}", new StringContent(JsonConvert.SerializeObject(modelToPost).ToString(), Encoding.UTF8, General.JsonMediaType)).Result;

            response.EnsureSuccessStatusCode();
        }
Beispiel #2
0
        private async Task CreateJournalTransaction(BankExpenditureNoteModel model, IdentityService identityService)
        {
            //var unitPaymentOrderIds = model.Details.Select(detail => detail.UnitPaymentOrderId).ToList();
            //var unitPaymentOrders = dbContext.UnitPaymentOrders.Where(unitPaymentOrder => unitPaymentOrderIds.Contains(unitPaymentOrder.Id)).ToList();
            var items = new List <JournalTransactionItem>();

            foreach (var detail in model.Details)
            {
                //var unitPaymentOrder = unitPaymentOrders.FirstOrDefault(entity => entity.Id == detail.UnitPaymentOrderId);
                var sumDataByUnit = detail.Items.GroupBy(g => g.UnitCode).Select(s => new
                {
                    UnitCode = s.Key,
                    Total    = s.Sum(sm => sm.Price)
                });



                foreach (var datum in sumDataByUnit)
                {
                    var item = new JournalTransactionItem()
                    {
                        COA = new COA()
                        {
                            Code = COAGenerator.GetDebtCOA(model.SupplierImport, detail.DivisionName, datum.UnitCode)
                        },
                        Debit  = Convert.ToDecimal(datum.Total),
                        Remark = detail.UnitPaymentOrderNo + " / " + detail.InvoiceNo
                    };

                    var vatCOA = "";
                    if (detail.Vat > 0)
                    {
                        if (model.SupplierImport)
                        {
                            vatCOA = "1510.00." + COAGenerator.GetDivisionAndUnitCOACode(detail.DivisionName, datum.UnitCode);
                        }
                        else
                        {
                            vatCOA = "1509.00." + COAGenerator.GetDivisionAndUnitCOACode(detail.DivisionName, datum.UnitCode);
                        }
                    }

                    if (string.IsNullOrWhiteSpace(vatCOA))
                    {
                        var vatItem = new JournalTransactionItem()
                        {
                            COA = new COA()
                            {
                                Code = vatCOA
                            },
                            Debit = Convert.ToDecimal(datum.Total * 0.1)
                        };

                        items.Add(vatItem);
                    }

                    items.Add(item);
                }
            }

            //items = items.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            //{
            //    COA = s.First().COA,
            //    Debit = s.Sum(sm => Math.Round(sm.Debit.GetValueOrDefault(), 4))
            //}).ToList();

            var bankJournalItem = new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = model.BankAccountCOA
                },
                Credit = items.Sum(s => Math.Round(s.Debit.GetValueOrDefault(), 4))
            };

            items.Add(bankJournalItem);

            var modelToPost = new JournalTransaction()
            {
                Date        = DateTimeOffset.Now,
                Description = "Bukti Pengeluaran Bank",
                ReferenceNo = model.DocumentNo,
                Items       = items
            };

            string journalTransactionUri = "journal-transactions";
            //var httpClient = new HttpClientService(identityService);
            var httpClient = (IHttpClientService)serviceProvider.GetService(typeof(IHttpClientService));
            var response   = await httpClient.PostAsync($"{APIEndpoint.Finance}{journalTransactionUri}", new StringContent(JsonConvert.SerializeObject(modelToPost).ToString(), Encoding.UTF8, General.JsonMediaType));

            response.EnsureSuccessStatusCode();
        }
Beispiel #3
0
        public void Should_Success_Get_COA_SpinningMS()
        {
            var result = COAGenerator.GetDebtCOA(false, "SPINNING", "S4");

            Assert.NotNull(result);
        }
Beispiel #4
0
        public void Should_Success_Get_COA_SpinningOther()
        {
            var result = COAGenerator.GetDebtCOA(true, "SPINNING", "other");

            Assert.NotNull(result);
        }
        public async Task CreateJournalTransactionUnitReceiptNote(UnitReceiptNote model)

        {
            var items = new List <JournalTransactionItem>();

            var purchasingItems    = new List <JournalTransactionItem>();
            var stockItems         = new List <JournalTransactionItem>();
            var debtItems          = new List <JournalTransactionItem>();
            var incomeTaxPaidItems = new List <JournalTransactionItem>();
            var incomeTaxItems     = new List <JournalTransactionItem>();
            var productListRemark  = new List <string>();

            foreach (var item in model.Items)
            {
                var purchaseRequest = dbContext.PurchaseRequests.FirstOrDefault(f => f.Id.Equals(item.PRId));
                var poExternalItem  = dbContext.ExternalPurchaseOrderItems.FirstOrDefault(f => f.PRId.Equals(item.PRId));
                var poExternal      = dbContext.ExternalPurchaseOrders.FirstOrDefault(f => f.Id.Equals(poExternalItem.EPOId));

                var purchasingCOACode = "";
                var stockCOACode      = "";
                var debtCOACode       = "";
                var incomeTaxCOACode  = "";
                if (purchaseRequest != null)
                {
                    purchasingCOACode = COAGenerator.GetPurchasingCOA(purchaseRequest.DivisionName, purchaseRequest.UnitCode, purchaseRequest.CategoryCode);
                    stockCOACode      = COAGenerator.GetStockCOA(purchaseRequest.DivisionName, purchaseRequest.UnitCode, purchaseRequest.CategoryCode);
                    debtCOACode       = COAGenerator.GetDebtCOA(model.SupplierIsImport, purchaseRequest.DivisionName, purchaseRequest.UnitCode);
                    if (poExternal.UseIncomeTax && double.TryParse(poExternal.IncomeTaxRate, out double test) && double.Parse(poExternal.IncomeTaxRate) > 0)
                    {
                        incomeTaxCOACode = COAGenerator.GetIncomeTaxCOA(poExternal.IncomeTaxName, purchaseRequest.DivisionName, purchaseRequest.UnitCode);
                    }
                }

                var journalPurchasingItem = new JournalTransactionItem()
                {
                    COA = new COA()
                    {
                        Code = purchasingCOACode
                    },
                    Debit = item.PricePerDealUnit * item.ReceiptQuantity,
                };
                purchasingItems.Add(journalPurchasingItem);

                var journalStockItem = new JournalTransactionItem()
                {
                    COA = new COA()
                    {
                        Code = stockCOACode
                    },
                    Debit = item.PricePerDealUnit * item.ReceiptQuantity,
                };
                stockItems.Add(journalStockItem);

                var journalDebtItem = new JournalTransactionItem()
                {
                    COA = new COA()
                    {
                        Code = debtCOACode
                    },
                    Credit = item.PricePerDealUnit * item.ReceiptQuantity
                };
                debtItems.Add(journalDebtItem);

                if (poExternal.UseIncomeTax && double.Parse(poExternal.IncomeTaxRate) > 0)
                {
                    var pphItem = new JournalTransactionItem()
                    {
                        COA = new COA()
                        {
                            Code = incomeTaxCOACode
                        },
                        Credit = item.PricePerDealUnit * item.ReceiptQuantity * double.Parse(poExternal.IncomeTaxRate) / 100
                    };
                    incomeTaxItems.Add(pphItem);

                    var incomeTaxPaid = new JournalTransactionItem()
                    {
                        COA = new COA()
                        {
                            Code = debtCOACode
                        },
                        Debit = item.PricePerDealUnit * item.ReceiptQuantity * double.Parse(poExternal.IncomeTaxRate) / 100
                    };
                    incomeTaxPaidItems.Add(incomeTaxPaid);
                }


                productListRemark.Add($"- {item.ProductName}");
            }

            purchasingItems = purchasingItems.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = s.First().COA.Code
                },
                Debit  = s.Sum(sum => sum.Debit),
                Remark = string.Join("\n", productListRemark)
            }).ToList();
            items.AddRange(purchasingItems);

            debtItems = debtItems.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = s.First().COA.Code
                },
                Credit = s.Sum(sum => sum.Credit)
            }).ToList();
            items.AddRange(debtItems);

            incomeTaxPaidItems = incomeTaxPaidItems.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = s.First().COA.Code
                },
                Debit = s.Sum(sum => sum.Debit)
            }).ToList();
            if (incomeTaxPaidItems.Count > 0)
            {
                items.AddRange(incomeTaxPaidItems);
            }

            incomeTaxItems = incomeTaxItems.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = s.First().COA.Code
                },
                Credit = s.Sum(sum => sum.Credit)
            }).ToList();
            if (incomeTaxItems.Count > 0)
            {
                items.AddRange(incomeTaxItems);
            }

            stockItems = stockItems.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = s.First().COA.Code
                },
                Debit  = s.Sum(sum => sum.Debit),
                Remark = string.Join("\n", productListRemark)
            }).ToList();
            items.AddRange(stockItems);

            var purchasingCreditItems = purchasingItems.GroupBy(g => g.COA.Code).Select(s => new JournalTransactionItem()
            {
                COA = new COA()
                {
                    Code = s.First().COA.Code
                },
                Credit = s.Sum(sum => sum.Debit)
            }).ToList();

            items.AddRange(purchasingCreditItems);

            var modelToPost = new JournalTransaction()
            {
                Date        = DateTimeOffset.Now,
                Description = "Bon Terima Unit",
                ReferenceNo = model.URNNo,
                Items       = items
            };

            string journalTransactionUri = "journal-transactions";
            var    httpClient            = (IHttpClientService)serviceProvider.GetService(typeof(IHttpClientService));

            var response = await httpClient.PostAsync($"{APIEndpoint.Finance}{journalTransactionUri}", new StringContent(JsonConvert.SerializeObject(modelToPost).ToString(), Encoding.UTF8, General.JsonMediaType));

            response.EnsureSuccessStatusCode();
        }