public void Should_Success_Get_COA_TaxNotExist() { var result = COAGenerator.GetIncomeTaxCOA("BELUMADA", "FINISHING&PRINTING", "F1"); Assert.NotNull(result); }
public void Should_Success_Get_COA_IncomeTaxGarmentC1A() { var result = COAGenerator.GetIncomeTaxCOA("Final", "GARMENT", "C1A"); Assert.NotNull(result); }
public void Should_Success_Get_COA_IncomeTaxGarmentOther() { var result = COAGenerator.GetIncomeTaxCOA("PASAL26", "GARMENT", "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(); }