public long Insert(InvoiceModel model) { TblInvoice obj = _mapper.Map <InvoiceModel, TblInvoice>(model); obj.Day = model.InvoiceDate.Day; obj.Month = model.InvoiceDate.Month; obj.Year = model.InvoiceDate.Year; obj.InvoiceNo = ""; obj.SequenceNo = 0; obj.TotalAmount = CustomRepository.GetTotalAmountForInvoice(model.checkedDispatchId).TotalAmount; decimal SgstAmount = Math.Round(obj.TotalAmount * (model.Sgst ?? 0) / 100, 2); decimal IgstAmount = Math.Round(obj.TotalAmount * (model.Igst ?? 0) / 100, 2); decimal CgstAmount = Math.Round(obj.TotalAmount * (model.Cgst ?? 0) / 100, 2); obj.TaxAmount = SgstAmount + IgstAmount + CgstAmount; obj.TotalAmountWithTax = obj.TotalAmount + obj.TaxAmount; obj.AmountInWords = CurrencyHelper.changeCurrencyToWords(obj.TotalAmountWithTax); List <long> dispatchIdList = model.checkedDispatchId.Split(',').Select(long.Parse).ToList(); foreach (long dispatchId in dispatchIdList) { obj.TblInvoiceDetail.Add(new TblInvoiceDetail { DispatchId = dispatchId }); } _repository.Insert(obj); return(obj.InvoiceId); }
public ActionResult Detail(int?id, string msg, AlertMsgType?msgType) { TblInvoice ob = uow.Modules.Invoice.Get(id ?? 0); ob.SaleOrder = uow.Modules.SaleOrder.Get(ob.SaleOrderId); return(ViewDetail(ob, msg, msgType)); }
private ActionResult ViewDetail(TblInvoice ob, string msg, AlertMsgType?msgType) { try { if (ob == null) { throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง"); } if (!string.IsNullOrWhiteSpace(msg)) { WidgetAlertModel alert = new WidgetAlertModel() { Message = msg }; if (msgType.HasValue) { alert.Type = msgType.Value; } ViewBag.Alert = alert; } List <TblSaleOrder> saleOrderList = uow.Modules.SaleOrder.GetListForInvoiceByCondition("", "", "2"); List <TblSaleOrder> saleOrderList2 = new List <TblSaleOrder>(); decimal remain = 0; decimal total = 0; foreach (TblSaleOrder so in saleOrderList) { remain = uow.Modules.Invoice.GetRemain(so.SaleOrderId); total = so.SubTotalNet.HasValue ? so.SubTotalNet.Value : 0; if (total - remain > 0) { saleOrderList2.Add(so); } } AccountPermission permission = new AccountPermission(); permission = GetPermissionSale(CurrentUser.AccountId, ob.CreatedBy.HasValue?ob.CreatedBy.Value:0); ViewData["optSaleOrder"] = uow.Modules.SaleOrder.Gets(); //ViewData["optSaleOrder"] = saleOrderList2; ViewData["optQuotation"] = uow.Modules.Quotation.Gets(); ViewData["optPayment"] = uow.Modules.PaymentCondition.Gets(); ViewData["optRemain"] = uow.Modules.Invoice.GetRemain(ob.SaleOrderId); ViewData["optInvoiceRemain"] = uow.Modules.Invoice.GetRemain(ob.SaleOrderId, ob.InvoiceTerm); ViewData["optPermission"] = permission; ViewData["optHistoryAmt"] = uow.Modules.Invoice.GetHistoryInvoiceAmount(ob.SaleOrderId); return(View(ob)); } catch (Exception ex) { return(RedirectToAction("Index", MVCController, new { area = MVCArea, msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
public async Task <IActionResult> PutTblInvoice(long id, TblInvoice tblInvoice) { if (id != tblInvoice.Id) { return(BadRequest()); } _context.Entry(tblInvoice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblInvoiceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult SetDetail() { int sid = Request.Form["selSaleOrder"].ParseInt(); if (sid > -1) { int id = Request.Form["InvoiceId"].ParseInt(); TblInvoice ob = uow.Modules.Invoice.Get(id); if (ob.InvoiceId <= 0) { ob.InvoiceNo = genInvoiceId("DEK"); ob.CreatedBy = CurrentUID; ob.UpdatedBy = CurrentUID; ob.CreatedDate = CurrentDate; ob.UpdateDate = CurrentDate; ob.InvoiceDate = CurrentDate; } else { ob.UpdatedBy = CurrentUID; ob.UpdateDate = CurrentDate; } try { ob.SaleOrderId = sid; ob.StatusId = Request.Form["StatusId"].ParseInt(); ob.InvoiceTerm = Request.Form["InvoiceTerm"].ParseInt(); ob.InvoiceRemark = Request.Form["InvoiceRemark"]; ob.InvoiceAmount = 0; if (Request.Form["InvoiceAmount"] != "") { ob.InvoiceAmount = decimal.Parse(Request.Form["InvoiceAmount"].ToString()); } uow.Modules.Invoice.Set(ob); uow.SaveChanges(); return(RedirectToAction("Detail", MVCController, new { id = ob.InvoiceId, msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { string msg = ex.GetMessage(true); return(ViewDetail(ob, msg, AlertMsgType.Danger)); } } else { return(RedirectToAction("Index", MVCController, new { msg = "กรุณาเลือก เลขที่ใบเสนอราคา/ใบสั่งงาน", msgType = AlertMsgType.Danger })); } }
private int createInvoice() { int id = -1; TblInvoice invoice = new TblInvoice(); invoice.dateInvoice = DateTime.Now.Date; invoice.userEmail = Session["user"].ToString(); this.entities.TblInvoice.Add(invoice); this.entities.SaveChanges(); id = this.entities.TblInvoice.OrderByDescending(i => i.idInvoice).First().idInvoice; return(id); }
//[Authorized] public ActionResult Delete() { try { int id = Request.Form["InvoiceId"].ParseInt(); TblInvoice ob = uow.Modules.Invoice.Get(id); if (ob == null) { return(RedirectToAction("Index", MVCController, new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning })); } uow.Modules.Invoice.Delete(ob); uow.SaveChanges(); return(RedirectToAction("Index", MVCController, new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { return(RedirectToAction("Index", MVCController, new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
private ActionResult ViewDetail(TblInvoice ob, string msg, AlertMsgType?msgType) { try { if (ob == null) { throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง"); } if (!string.IsNullOrWhiteSpace(msg)) { WidgetAlertModel alert = new WidgetAlertModel() { Message = msg }; if (msgType.HasValue) { alert.Type = msgType.Value; } ViewBag.Alert = alert; } ViewData["optSaleOrder"] = uow.Modules.SaleOrder.Gets() .Where(so => so.StatusId == 1) .ToList(); ViewData["optQuotation"] = uow.Modules.Quotation.Gets() .Where(q => q.StatusId == 3) .ToList(); ViewData["optPayment"] = uow.Modules.PaymentCondition.Gets(); return(View(ob)); } catch (Exception ex) { return(RedirectToAction("Index", MVCController, new { area = MVCArea, msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
public long Update(InvoiceModel model) { TblInvoice obj = _mapper.Map <InvoiceModel, TblInvoice>(model); obj.TotalAmount = CustomRepository.GetTotalAmountForInvoice(model.checkedDispatchId).TotalAmount; decimal SgstAmount = Math.Round(obj.TotalAmount * (model.Sgst ?? 0) / 100, 2); decimal IgstAmount = Math.Round(obj.TotalAmount * (model.Igst ?? 0) / 100, 2); decimal CgstAmount = Math.Round(obj.TotalAmount * (model.Cgst ?? 0) / 100, 2); obj.TaxAmount = SgstAmount + IgstAmount + CgstAmount; obj.TotalAmountWithTax = obj.TotalAmount + obj.TaxAmount; obj.AmountInWords = CurrencyHelper.changeCurrencyToWords(obj.TotalAmountWithTax); List <TblInvoiceDetail> invoiceDetailModel = _repositoryDetail.GetAll().Where(m => m.InvoiceId == obj.InvoiceId).ToList(); List <long> originalDispatchId = invoiceDetailModel.Select(m => m.DispatchId).ToList(); List <long> currentDispatchId = model.checkedDispatchId.Split(',').Select(long.Parse).ToList(); List <long> deleteDispatchId = originalDispatchId.Except(currentDispatchId).ToList(); List <long> insertDispatchId = currentDispatchId.Except(originalDispatchId).ToList(); foreach (long deleteId in deleteDispatchId) { TblInvoiceDetail objModel = invoiceDetailModel.FirstOrDefault(m => m.DispatchId == deleteId); if (objModel != null) { _repositoryDetail.Delete(objModel.InvoiceDetailId); } } foreach (long insertingId in insertDispatchId) { TblInvoiceDetail objInsertModel = new TblInvoiceDetail { InvoiceId = obj.InvoiceId, DispatchId = insertingId }; _repositoryDetail.Insert(objInsertModel); } _repository.Update(obj); return(obj.InvoiceId); }
public InvoiceModel GetById(long id) { TblInvoice obj = _repository.GetById(id); return(obj == null ? new InvoiceModel() : Map(obj)); }
private InvoiceModel Map(TblInvoice unit) { return(_mapper.Map <InvoiceModel>(unit)); }
public ActionResult SetDetail() { int sid = Request.Form["SaleOrderId"].ParseInt(); if (sid > -1) { int id = Request.Form["InvoiceId"].ParseInt(); TblInvoice ob = uow.Modules.Invoice.Get(id); if (Request.Form["SaleOrderId"] != "") { ob.SaleOrderId = int.Parse(Request.Form["SaleOrderId"].ToString()); } ob.SaleOrder = uow.Modules.SaleOrder.Get(ob.SaleOrderId); decimal remain = 0; decimal SumInvoiceAmt = 0; if (ob.InvoiceId <= 0) { ob.InvoiceNo = genInvoiceId("DEK"); ob.CreatedBy = CurrentUID; ob.UpdatedBy = CurrentUID; ob.CreatedDate = CurrentDate; ob.UpdatedDate = CurrentDate; ob.InvoiceDate = CurrentDate; ob.ConditionId = ob.SaleOrder.ConditionId; ob.InvoiceTerm = uow.Modules.Invoice.CountTerm(ob.SaleOrderId) + 1; //ob.DueDate = CurrentDate.AddMonths(1); SumInvoiceAmt = uow.Modules.Invoice.GetRemain(ob.SaleOrderId); remain = (ob.SaleOrder.SummaryNet.HasValue ? ob.SaleOrder.SummaryNet.Value : 0) - SumInvoiceAmt; switch (ob.SaleOrder.ConditionId) { case 1: //จ่าย 100% หลังติดตั้งงาน case 2: //มัดจำ 100 % ก่อนติดตั้งงาน if (ob.SaleOrder.SummaryNet >= remain) { ob.InvoiceAmount = remain; } else { ob.InvoiceAmount = ob.SaleOrder.SummaryNet; } break; case 3: ob.InvoiceAmount = ob.SaleOrder.SummaryNet / 2; //2 งวด 50 / 50 if (ob.SaleOrder.SummaryNet / 2 >= remain) { ob.InvoiceAmount = remain; } else { ob.InvoiceAmount = ob.SaleOrder.SummaryNet / 2; } break; case 4: //3 งวด case 5: ob.InvoiceAmount = 0; //4 งวด break; default: ob.InvoiceAmount = 0; break; } } else { ob.UpdatedBy = CurrentUID; ob.UpdatedDate = CurrentDate; ob.ConditionId = Request.Form["ConditionId"].ParseInt(); ob.InvoiceAmount = 0; if (Request.Form["InvoiceAmount"] != "") { ob.InvoiceAmount = decimal.Parse(Request.Form["InvoiceAmount"].ToString()); } ob.InvoiceTerm = Request.Form["InvoiceTerm"].ParseInt(); SumInvoiceAmt = uow.Modules.Invoice.GetRemain(ob.SaleOrderId, ob.InvoiceTerm); decimal amt = ob.InvoiceAmount.HasValue ? ob.InvoiceAmount.Value : decimal.Zero; remain = (ob.SaleOrder.SummaryNet.HasValue ? ob.SaleOrder.SummaryNet.Value : 0) - SumInvoiceAmt; if (amt - remain > 0) { return(ViewDetail(ob, "ยอดเรียกเก็บต้อง น้อยกว่าหรือเท่ากับ ยอดที่ยังไม่ได้เรียกเก็บ", AlertMsgType.Danger)); } } try { ob.SaleOrderId = sid; ob.StatusId = Request.Form["StatusId"].ParseInt(); ob.InvoiceRemark = Request.Form["InvoiceRemark"]; //string hddIsDeposit = Request.Form["hddIsDeposit"].ToString(); //ob.IsDeposit = hddIsDeposit == ""? 0:int.Parse(Request.Form["hddIsDeposit"]); //decimal reamin = Request.Form["remain"].ToString().ParseDecimal(); //if (ob.StatusId > 1) //{ // if (ob.InvoiceAmount <= 0) // { // return ViewDetail(ob, "กรุณาระบุยอดที่ต้องการเรียกเก็บ", AlertMsgType.Danger); // } //} //if (ob.InvoiceId > 0) //{ // if (ob.InvoiceAmount > reamin) // { // return ViewDetail(ob, "ยอดเรียกเก็บต้อง น้อยกว่าหรือเท่ากับ ยอดที่ยังไม่ได้เรียกเก็บ", AlertMsgType.Danger); // } //} bool result = false; if (ob.InvoiceId <= 0) { result = uow.Modules.Invoice.Add(ob); int ins = uow.Modules.Invoice.GetInsertId(ob.InvoiceNo); return(RedirectToAction("Detail", MVCController, new { id = ins, msg = "สร้างหมายเลขใบแจ้งหนี้เรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } else { AccountPermission permission = new AccountPermission(); permission = GetPermissionSale(CurrentUser.AccountId, ob.CreatedBy.HasValue ? ob.CreatedBy.Value : 0); if (permission.IsEdit) { uow.Modules.Invoice.Set(ob); uow.SaveChanges(); } else { return(RedirectToAction("Index", MVCController, new { msg = "ไม่มีสิทธิ์แก้ไขงาน", msgType = AlertMsgType.Danger })); } } return(RedirectToAction("Detail", MVCController, new { id = ob.InvoiceId, msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { string msg = ex.GetMessage(true); return(ViewDetail(ob, msg, AlertMsgType.Danger)); } } else { return(RedirectToAction("Index", MVCController, new { msg = "กรุณาเลือก เลขที่ใบเสนอราคา/ใบสั่งงาน", msgType = AlertMsgType.Danger })); } }
public async Task <ApiResponse> AddSale(TblInvoice tblInvoice) { // //[NotMapped] Sample Code // public object InstallmentDetail { get; set; } // // //[NotMapped] //public string PaymentMode { get; set; } // //List<Testcalss> res = tblInvoice.InstallmentDetail as List<Testcalss>; List <TblInstallment> installmentDetail = JsonConvert.DeserializeObject <List <TblInstallment> >(tblInvoice.InstallmentDetail.ToString()); try { for (int i = 0; i < installmentDetail.Count; i++) { TblInvoice objInvoice = new TblInvoice(); objInvoice.UserId = tblInvoice.UserId; objInvoice.CurrencyId = tblInvoice.CurrencyId; objInvoice.CountryId = tblInvoice.CountryId; objInvoice.CustomerId = tblInvoice.CustomerId; objInvoice.Comment = tblInvoice.Comment; objInvoice.PaymentMode = installmentDetail[i].PaymentMode; objInvoice.StockNumber = installmentDetail[i].StockNumber; objInvoice.SalePrice = Convert.ToDecimal(installmentDetail[i].SalePrice); objInvoice.SaleDate = DateTime.Now; if (installmentDetail[i].PaymentMode == "CASH") { objInvoice.PaymentStatus = "Paid"; } else { objInvoice.PaymentStatus = "INSTALLMENT"; } objInvoice.PaidAmount = Convert.ToDecimal(installmentDetail[i].SalePrice); objInvoice.BalanceAmount = 0; objInvoice.Status = "Sale"; long lastInvoiceid = 0; try { // _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[tbl_Invoice] ON"); _context.TblInvoice.Add(objInvoice); await _context.SaveChangesAsync(); lastInvoiceid = objInvoice.Id; var currentmonthShort = DateTime.Now.ToString("MMM-dd"); var invoiceNumber = "INV-" + currentmonthShort + "-" + String.Format("{0:D4}", lastInvoiceid); objInvoice.InvoiceNumber = invoiceNumber; _context.Entry(objInvoice).Property(x => x.InvoiceNumber).IsModified = true; await _context.SaveChangesAsync(); //tblInvoice.Id=0; // _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[tbl_Invoice] OFF"); if (installmentDetail[i].PaymentMode == "INSTALLMENT") { TblInstallment objInstallment = new TblInstallment(); objInstallment.InvoiceNumber = lastInvoiceid.ToString(); objInstallment.StockNumber = installmentDetail[i].StockNumber; objInstallment.CustomerId = tblInvoice.CustomerId; objInstallment.SalemanId = tblInvoice.UserId; objInstallment.SalePrice = installmentDetail[i].SalePrice; objInstallment.DownPayment = installmentDetail[i].DownPayment; objInstallment.TimeDurationYears = installmentDetail[i].TimeDurationYears; objInstallment.TotalInstallment = installmentDetail[i].TotalInstallment; objInstallment.TaxPer = installmentDetail[i].TaxPer; objInstallment.TaxAmount = installmentDetail[i].TaxAmount; objInstallment.FinalAmount = installmentDetail[i].FinalAmount; objInstallment.InstallAmount = installmentDetail[i].InstallAmount; objInstallment.Installmentmode = installmentDetail[i].Installmentmode; objInstallment.Day = installmentDetail[i].Day; objInstallment.CreatedDate = DateTime.Now; _context.TblInstallment.Add(objInstallment); await _context.SaveChangesAsync(); var Currentyear = DateTime.Now.Year; var currentmonth = DateTime.Now.Month; var currday = DateTime.Now.Day; DateTime installmentDate = new DateTime(); for (int j = 0; j < installmentDetail[i].TotalInstallment; j++) { TblInstallmentDetail objinstallmentDetail = new TblInstallmentDetail(); decimal TaxAmount = 0; decimal pendingPayment = Convert.ToDecimal(installmentDetail[i].SalePrice - installmentDetail[i].DownPayment); int timeperiod = Convert.ToInt32(installmentDetail[i].TimeDurationYears); switch (installmentDetail[i].Installmentmode) { case "YEAR": Currentyear++; installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day)); // TimeSpan aMonth = new System.TimeSpan(365, 0, 0, 0); //installmentDate.Add(aMonth); TaxAmount = Convert.ToDecimal((pendingPayment / timeperiod) * Convert.ToDecimal(installmentDetail[i].TaxPer) / 100); break; case "HALFYEAR": currentmonth = currentmonth + 6; if (currentmonth > 12) { Currentyear++; var addcurrentmonth = currentmonth % 12; installmentDate = new DateTime(Currentyear, addcurrentmonth, Convert.ToInt32(installmentDetail[i].Day)); } else { installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day)); } // TimeSpan aMonthHalf = new System.TimeSpan(180, 0, 0, 0); //installmentDate.Add(aMonthHalf); TaxAmount = Convert.ToDecimal((pendingPayment / (timeperiod * 2)) * Convert.ToDecimal(installmentDetail[i].TaxPer) / 100); break; case "MONTHLY": currentmonth++; if (currentmonth > 12) { currentmonth = currentmonth % 12; Currentyear++; installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day)); } else { installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day)); } //TimeSpan aMonthM = new System.TimeSpan(30, 0, 0, 0); //installmentDate.Add(aMonthM); TaxAmount = Convert.ToDecimal((pendingPayment / (timeperiod * 12)) * Convert.ToDecimal(installmentDetail[i].TaxPer) / 100); break; } objinstallmentDetail.InstallmentDate = installmentDate; objinstallmentDetail.InstallmentId = objInstallment.Id; objinstallmentDetail.DueDate = installmentDate.AddDays(15); objinstallmentDetail.PaymentStatus = "PENDING"; objinstallmentDetail.TaxPer = installmentDetail[i].TaxPer; objinstallmentDetail.TaxAmount = TaxAmount; objinstallmentDetail.FinalAmount = installmentDetail[i].InstallAmount; objinstallmentDetail.PaidAmount = 0; objinstallmentDetail.CreatedDate = DateTime.Now; _context.TblInstallmentDetail.Add(objinstallmentDetail); await _context.SaveChangesAsync(); } } //tblInvoice.Id = 0; } catch (DbUpdateConcurrencyException ex) { var ApiResponseCatch = await response.ApiResult("FAILED", ex, "Error "); return(ApiResponseCatch); } } var ApiResponse = await response.ApiResult("OK", "Data Save Installment", "Success "); return(ApiResponse); } catch (DbUpdateConcurrencyException ex) { var ApiResponseCatch = await response.ApiResult("FAILED", ex, "Error "); return(ApiResponseCatch); } // return CreatedAtAction("GetTblInvoice", new { id = tblInvoice.Id }, tblInvoice); }