public async Task <IActionResult> Create([Bind("Id,Code,Description")] ItemType itemType) { if (ModelState.IsValid) { _context.Add(itemType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(itemType)); }
public async Task <IActionResult> Create([Bind("Id,Code,Bar_Code,Name,Parent_Code,Type,Unit,Rate,Is_Vatable,Remarks")] Item item) { if (ModelState.IsValid) { _context.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(item)); }
public async Task <IActionResult> Create([Bind("Id,Initial,Name,Is_Active,Remarks,Cash_Drop_Limit")] Terminal terminal) { if (ModelState.IsValid) { _context.Add(terminal); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(terminal)); }
public async Task <IActionResult> Create([Bind("Id,Code,Parent_Code,Description,Indentation,Order,Has_Child,Modified_Date")] ItemCategory itemCategory) { if (ModelState.IsValid) { itemCategory.Id = Guid.NewGuid().ToString(); itemCategory.ModifiedDate = DateTime.Now; _context.Add(itemCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(itemCategory)); }
public async Task <IActionResult> Create(Denomination denomination) { if (ModelState.IsValid) { if (denomination.Date.ToShortDateString() != System.DateTime.Now.ToShortDateString()) { return(StatusCode(400, "Date not Up-to-Date !!")); } //check if Session present denomination.User_Id = User.Identity.Name; IList <Settlement> settlementData = _context.Settlement.Where(x => x.UserId == denomination.User_Id).ToList(); if (settlementData == null || settlementData.Count == 0) { ModelState.AddModelError(string.Empty, "Sorry, No Transaction Found In Your Name !!"); } else if (!settlementData.Any(x => x.Status == "Open")) { if (settlementData.Any(x => x.Status == "Closed")) { ModelState.AddModelError(string.Empty, "Already Saved, Cannot Save Twice !!"); } else { ModelState.AddModelError(string.Empty, "Sorry, No Transaction Found In Your Name !!"); } } else { denomination.TotalCash = denomination.Total;//CalcTotalCash(denomination); _context.Add(denomination); await _context.SaveChangesAsync(); var newSettlementData = settlementData.Where(x => x.Status == "Open"); foreach (var item in newSettlementData) { item.Status = "Closed"; item.DenominationId = denomination.Id; _context.Entry(item).State = EntityState.Modified; } await _context.SaveChangesAsync(); TempData["StatusMessage"] = "Saved Successfully"; return(RedirectToAction(nameof(Edit), new { id = denomination.Id })); } } ViewData["Terminal_Id"] = new SelectList(_context.Terminal, "Id", "Name", denomination.Terminal_Id); return(View(denomination)); }
public async Task <IActionResult> Edit(string id, [Bind("ID,INITIAL,NAME,COMPANY_NAME,ADDRESS,PHONE,PHONE_ALT,FAX,VAT,EMAIL,WEBSITE,FISCAL_YEAR")] Store store) { if (id != store.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(store); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StoreExists(store.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(store)); }
public async Task <IActionResult> Index([FromBody] CreditNote creditNote) { if (ModelState.IsValid) { try { Store store = JsonConvert.DeserializeObject <Store>(HttpContext.Session.GetString("Store"));; creditNote.Id = Guid.NewGuid(); creditNote.Credit_Note_Id = _context.CreditNote.Select(x => x.Credit_Note_Id).DefaultIfEmpty(0).Max() + 1; creditNote.Credit_Note_Number = "CN-" + creditNote.Credit_Note_Id.ToString("0000") + "-" + store.INITIAL + '-' + store.FISCAL_YEAR; creditNote.Trans_Time = DateTime.Now.TimeOfDay; creditNote.Division = "Divisioin"; creditNote.Terminal = HttpContext.Session.GetString("Terminal"); creditNote.Created_Date = DateTime.Now; creditNote.Created_By = User.Identity.Name; creditNote.isRedeem = creditNote.isRedeem; if (creditNote.isRedeem == true) { creditNote.Remarks = "Claimed"; } _context.Add(creditNote); foreach (var item in creditNote.CreditNoteItems) { item.Credit_Note_Id = creditNote.Id; item.Credit_Note_Number = creditNote.Credit_Note_Number; _context.CreditNoteItem.Add(item); } //save to print table InvoicePrint print = new InvoicePrint() { InvoiceNumber = creditNote.Credit_Note_Number, Type = "CreditNote", FirstPrintedDate = DateTime.Now, FirstPrintedBy = User.Identity.Name, PrintCount = 1 }; _context.InvoicePrint.Add(print); await _context.SaveChangesAsync(); //now update invoice remarks also SalesInvoice invoice = _context.SalesInvoice.FirstOrDefault(x => x.Invoice_Number == creditNote.Reference_Number.Trim()); invoice.Remarks = "Return"; _context.Entry(invoice).State = EntityState.Modified; InvoiceMaterializedView invoiceMaterializedViewOld = _context.InvoiceMaterializedView.FirstOrDefault(x => x.BillNo == creditNote.Reference_Number.Trim()); invoiceMaterializedViewOld.IsBillActive = false; _context.Entry(invoiceMaterializedViewOld).State = EntityState.Modified; InvoiceMaterializedView view = new InvoiceMaterializedView() { BillNo = creditNote.Credit_Note_Number, DocumentType = "Credit Memo", FiscalYear = store.FISCAL_YEAR, LocationCode = store.INITIAL, BillDate = creditNote.Trans_Date_Ad.Value, PostingTime = creditNote.Trans_Time.Value, CustomerCode = creditNote.Customer_Id, CustomerName = creditNote.Customer_Name, Vatno = creditNote.Customer_Vat, Amount = creditNote.Total_Gross_Amount.Value, Discount = creditNote.Total_Discount.Value, TaxableAmount = creditNote.TaxableAmount, NonTaxableAmount = creditNote.NonTaxableAmount, TaxAmount = creditNote.Total_Vat == null ? 0 : creditNote.Total_Vat.Value, TotalAmount = creditNote.Total_Net_Amount.Value, IsBillActive = true, IsBillPrinted = false, PrintedTime = DateTime.Now, PrintedBy = "", EnteredBy = creditNote.Created_By, SyncStatus = "Not Started", SyncedDate = DateTime.Now, SyncedTime = DateTime.Now.TimeOfDay, SyncWithIrd = false, IsRealTime = false }; InvoiceMaterializedView invoiceMaterializedView = _context.InvoiceMaterializedView.FirstOrDefault(x => x.BillNo == creditNote.Reference_Number.Trim()); invoiceMaterializedView.IsBillActive = false; _context.Entry(invoiceMaterializedView).State = EntityState.Modified; NavCreditMemo navCreditMemo = new NavCreditMemo() { id = creditNote.Id.ToString(), number = creditNote.Credit_Note_Number, postingno = creditNote.Credit_Note_Number, creditMemoDate = creditNote.Trans_Date_Ad.Value.ToString("yyyy-MM-dd"), customerNumber = creditNote.MemberId, customerName = creditNote.Customer_Name, vatregistrationnumber = creditNote.Customer_Vat, locationcode = store.INITIAL, accountabilitycenter = store.INITIAL, assigneduserid = creditNote.Created_By, externalDocumentNumber = creditNote.Reference_Number, amountrounded = creditNote.IsRoundup, returnremarks = creditNote.Credit_Note }; _context.InvoiceMaterializedView.Add(view); _context.SaveChanges(); //post to ird //background task BackgroundJob.Enqueue(() => SendDataToIRD(creditNote, store)); //Send data to NAV Config config = ConfigJSON.Read(); if (!config.StopCreditNotePosting) { NavPostData navPostData = new NavPostData(_context, _mapper); BackgroundJob.Enqueue(() => navPostData.PostCreditNote(navCreditMemo)); } //for api return TempData["StatusMessage"] = "Credit Note Added Successfully"; return(Ok(new { redirectUrl = "/CreditNote", Message = "Credit Note Added Successfully", InvoiceData = creditNote, StoreData = store })); } catch (Exception ex) { if (ex.Message.Contains("UniqueCreditNoteNumber") || ex.InnerException.Message.Contains("UniqueCreditNoteNumber")) { return(await Index(creditNote)); } } } return(View(creditNote)); }
public async Task <IActionResult> Index([FromBody] SalesInvoiceAndCustomerViewModel model) { SalesInvoiceTmp salesInvoiceTmp = model.SalesInvoice; Customer customer = model.Customer; if (ModelState.IsValid) { if (model.SalesInvoice.Trans_Date_Ad.Value.ToShortDateString() != DateTime.Now.ToShortDateString()) { return(StatusCode(400, "Date is not Up-to-Date !!")); } try { //if that salesinvoice already exist, than track first SalesInvoiceTmp oldData = new SalesInvoiceTmp(); bool isExistOldSalesInvoice = false; if (salesInvoiceTmp.Id != null) { oldData = await _context.SalesInvoiceTmp.FirstOrDefaultAsync(x => x.Id == salesInvoiceTmp.Id); if (oldData != null) { isExistOldSalesInvoice = true; } } //add membership if (!string.IsNullOrEmpty(customer.Name) && !string.IsNullOrEmpty(customer.Mobile1) && customer.Is_Member == true) { Customer member = AddCustomer(customer); //_context.SaveChanges(); salesInvoiceTmp.Customer_Id = member.Code; salesInvoiceTmp.MemberId = member.Membership_Number; } //now processed to new save invoice salesInvoiceTmp.Id = Guid.NewGuid(); salesInvoiceTmp.Trans_Time = DateTime.Now.TimeOfDay; salesInvoiceTmp.Division = "Divisioin"; salesInvoiceTmp.Terminal = HttpContext.Session.GetString("Terminal"); salesInvoiceTmp.Created_Date = DateTime.Now; salesInvoiceTmp.Created_By = User.Identity.Name; _context.Add(salesInvoiceTmp); foreach (var item in salesInvoiceTmp.SalesInvoiceItems) { item.Invoice_Id = salesInvoiceTmp.Id; item.Invoice_Number = salesInvoiceTmp.Invoice_Number; _context.SalesInvoiceItemsTmp.Add(item); } await _context.SaveChangesAsync(); //if everything goes right then delete old sales invoice in background if (isExistOldSalesInvoice) { _context.SalesInvoiceTmp.Remove(oldData); _context.SaveChanges(); } //for serverside return //if (salesInvoiceTmp.Trans_Type == "Hold") // return RedirectToAction("Index"); //else // return RedirectToAction("Billing", new { id = salesInvoiceTmp.Id }); //for api return if (salesInvoiceTmp.Trans_Type == "Save") { return(Ok(new { redirectUrl = "" })); } if (salesInvoiceTmp.Trans_Type == "Hold" || salesInvoiceTmp.Trans_Type == "Save") { return(Ok(new { redirectUrl = "/SalesInvoice/Landing" })); } else if (salesInvoiceTmp.Trans_Type == "Tax") { return(Ok(new { RedirectUrl = "/SalesInvoice/Billing/" + salesInvoiceTmp.Id + "?M=" + salesInvoiceTmp.MemberId + "&Mode=tax" })); } else { return(Ok(new { RedirectUrl = "/SalesInvoice/Billing/" + salesInvoiceTmp.Id + "?M=" + salesInvoiceTmp.MemberId })); } } catch (Exception ex) { return(StatusCode(500, ex.InnerException)); } } return(View(salesInvoiceTmp)); }