public IActionResult Edit(int id, Transaction request) { var transaction = transactionDac.Get(id); transaction.IssueDate = request.IssueDate; transaction.DuplicatePaymentType = request.DuplicatePaymentType; transaction.DuplicatePaymentNumber = request.DuplicatePaymentNumber; transaction.DuplicatePaymentYear = request.DuplicatePaymentYear; transaction.Title = request.Title; transaction.Remark = request.Remark; transaction.ProductType = request.ProductType; if (transaction.Amount < 0) { if (request.PartnerId.HasValue) { var partner = partnerDac.Get(request.PartnerId.Value); transaction.VatInclude = partner.PartnerType switch { PartnerType.Shop => VatHelper.GetShopVatFromFullAmount(request.Amount), PartnerType.Person => VatHelper.GetPersonVatFromFullAmount(request.Amount), _ => 0, }; } transaction.Amount = -Math.Abs(request.Amount); if (request.BudgetId == 0) { request.DuplicatePaymentType = null; request.DuplicatePaymentNumber = null; request.DuplicatePaymentYear = null; request.PaymentType = null; request.PartnerId = null; } } transactionDac.Update(transaction); CalculateBringForword(request.IssueDate, request.BudgetId); CalculateBringForword(request.IssueDate, 0); return(RedirectToAction(nameof(Index))); }
public IActionResult CreatePayment(Transaction request, string trackVat, int DPYCount) { if (request.PartnerId.HasValue) { var partner = partnerDac.Get(request.PartnerId.Value); request.VatInclude = partner.PartnerType switch { PartnerType.Shop => VatHelper.GetShopVatFromFullAmount(request.Amount), PartnerType.Person => VatHelper.GetPersonVatFromFullAmount(request.Amount), _ => 0, }; var lastDuplicatePaymentNumber = transactionDac.GetLastDuplicatePaymentNumber(CurrentSchoolConfig.SchoolYear); var nextNumber = int.Parse(lastDuplicatePaymentNumber?.DuplicatePaymentNumber ?? "1") + (lastDuplicatePaymentNumber?.DuplicatePaymentCount ?? 0); request.DuplicatePaymentType = partner.IsInternal ? "บค." : "บจ."; request.DuplicatePaymentNumber = nextNumber.ToString(); request.DuplicatePaymentCount = DPYCount < 1 ? 1 : DPYCount; request.DuplicatePaymentYear = CurrentSchoolConfig.SchoolYear; } request.Amount = -Math.Abs(request.Amount); request.SchoolId = CurrentSchoolData.sc_id; if (request.BudgetId == 0) { request.DuplicatePaymentType = null; request.DuplicatePaymentNumber = null; request.DuplicatePaymentCount = null; request.DuplicatePaymentYear = null; request.PaymentType = null; request.PartnerId = null; } transactionDac.InsertPayment(request); CalculateBringForword(request.IssueDate, request.BudgetId); CalculateBringForword(request.IssueDate, 0); return(RedirectToAction(nameof(Index))); }