public ActionResult Edit([Bind(Include = "id,desc,flag")] Models.Bill bill_tmp) { try { if (ModelState.IsValid) { var bill = db.Bills.Find(bill_tmp.id); bill.flag = bill_tmp.flag; bill.desc = bill_tmp.desc; db.Entry(bill).State = EntityState.Modified; db.SaveChanges(); this.success(TM.Common.Language.msgUpdateSucsess); return(RedirectToAction("Index")); } else { this.danger(TM.Common.Language.msgError); } } catch (Exception) { this.danger(TM.Common.Language.msgUpdateError); } return(RedirectToAction("Edit")); }
public IActionResult OnPostInsertBill([FromBody] Models.Bill obj) { try { obj.CompanyID = (int)_session.GetInt32("Cid"); obj.BranchID = (int)_session.GetInt32("Bid"); Random generator = new Random(); obj.SecretUnlockCode = Int32.Parse(generator.Next(0, 999999).ToString("D6")); obj.BillDelivered = false; obj.MessageSent = false; obj.BillDate = DateTime.Now; _context.Bill.Add(obj); _context.SaveChanges(); } catch (DbUpdateException) { string exce = "Update 1"; return(new JsonResult(exce)); } var DebtorGroupInfo = _context.DebtorGroup.Where(a => a.DebtorGroupID.Equals(obj.DebtorGroupID)).Select(a => a.DebtorGroupPhoneNumber).FirstOrDefault(); return(new JsonResult("Added Successfully!")); }
public IActionResult OnPostSendMessage([FromBody] Models.Bill obj) { var fyear = obj.Note; var DebtorGroupInfo = _context.DebtorGroup.Where(a => a.DebtorGroupID.Equals(obj.DebtorGroupID)).FirstOrDefault(); var format = ""; if (string.IsNullOrEmpty(obj.SeriesName)) { format = "Format2"; } else { format = "Format1"; } string companyname = _context.Company.Where(a => a.CompanyID.Equals(obj.CompanyID)).Select(ab => ab.CompanyName).FirstOrDefault().ToString(); string[] msgcnt = new string[3]; msgcnt[0] = SendSmsAsync(DebtorGroupInfo.DebtorGroupPhoneNumber.Substring(DebtorGroupInfo.DebtorGroupPhoneNumber.Length - 10), fyear, obj.BillAmount, format, Options.WhatsappAccountPassword, obj.BillNumber, obj.SecretUnlockCode, companyname, DebtorGroupInfo.DebtorOutstanding); msgcnt[1] = (DebtorGroupInfo.DebtorGroupPhoneNumber.Substring(DebtorGroupInfo.DebtorGroupPhoneNumber.Length - 10)); msgcnt[2] = DebtorGroupInfo.DebtorGroupName; return(new JsonResult(msgcnt)); }
public ActionResult Create([Bind(Include = "customer_id,total_item,total_quantity,total_price,desc,flag")] Models.Bill bill, FormCollection collection) { try { if (ModelState.IsValid) { if (bill.totalItem == 0) { this.danger("Vui lòng chọn ít nhất một sản phẩm"); return(RedirectToAction("Create")); } bill.id = Guid.NewGuid(); bill.codeKey = GetBillCode(Guid.NewGuid().ToString().Split('-')[4].ToUpper()); bill.createdBy = Common.Auth.getUser().id.ToString(); bill.createdAt = DateTime.Now; db.Bills.Add(bill); //Sub_Bill var listItem = collection["listItem[]"].Split(','); foreach (var item in listItem) { var i = item.Split('|'); var sub_bill = new Models.SubBill(); sub_bill.id = Guid.NewGuid(); sub_bill.idKey = bill.id; sub_bill.codeKey = bill.codeKey; sub_bill.itemId = Guid.Parse(i[0]); sub_bill.title = i[1]; sub_bill.quantity = Int32.Parse(i[2]); sub_bill.priceOld = decimal.Parse(i[3]); sub_bill.price = decimal.Parse(i[4]); sub_bill.totalPrice = sub_bill.quantity * sub_bill.price; sub_bill.flag = 1; //Update product quantity in store var items = db.Items.Find(sub_bill.itemId); if (items.quantity < sub_bill.quantity) { this.danger("Sản phẩm Không đủ số lượng trong kho!"); return(RedirectToAction("Create")); } items.quantity = items.quantity - sub_bill.quantity; db.Entry(items).State = EntityState.Modified; db.SubBills.Add(sub_bill); } db.SaveChanges(); this.success(TM.Common.Language.msgCreateSucsess); return(RedirectToAction("Create")); } } catch (Exception) { this.danger(TM.Common.Language.msgCreateError); } return(View(bill)); }
public void UpdateBill(string _id, float _money, DateTime _billDate, string _billDetail) { for(int x = 0; x < allBills.Count; x++) { if(allBills[x].id == _id) { selectedBill = allBills[x]; allBills[x].billDate = _billDate; allBills[x].billDetail = _billDetail; allBills[x].money = _money; } } }
public void RemoveBill(string _id) { for(int x = 0; x < allBills.Count; x++) { if(allBills[x].id == _id) { selectedBill = allBills[x]; allBills.RemoveAt(x); break; } } selectedBill = null; }
public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } Bill = await _context.Bill .Include(b => b.BillSeries) .Include(b => b.Company) .Include(b => b.DebtorGroup).FirstOrDefaultAsync(m => m.BillNumber == id); if (Bill == null) { return(NotFound()); } return(Page()); }
public IActionResult OnPost(int num, string billnum) { var rowcn = _context.Bill.Where(a => a.BillNumber == billnum && a.SecretUnlockCode == num).Select(a => a.BillNumber).FirstOrDefault(); if (string.IsNullOrEmpty(rowcn)) { return(NotFound()); } else { var billdelivered = new Models.Bill { BillNumber = billnum, BillDelivered = true }; _context.Bill.Attach(billdelivered).Property(x => x.BillDelivered).IsModified = true; _context.SaveChanges(); return(RedirectToPage("/Bill/Format1/PrintGuest", new { id = billnum, seccode = num })); } }
public IActionResult OnPutUpdateBill(int id, [FromBody] Models.Bill obj) { _context.Attach(obj).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BillExists(obj.BillNumber)) { return(new JsonResult("Update Error!")); } else { return(new JsonResult("Update Error!")); } } return(new JsonResult("Bill Information Updated!")); }
public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } Bill = await _context.Bill .Include(b => b.BillSeries) .Include(b => b.Company) .Include(b => b.DebtorGroup).FirstOrDefaultAsync(m => m.BillNumber == id); if (Bill == null) { return(NotFound()); } ViewData["SeriesName"] = new SelectList(_context.BillSeries, "SeriesName", "SeriesName"); ViewData["CompanyID"] = new SelectList(_context.Company, "CompanyID", "CompanyName"); ViewData["DebtorGroupID"] = new SelectList(_context.DebtorGroup, "DebtorGroupID", "DebtorGroupName"); return(Page()); }
public IActionResult OnGetUpdateBillAmt(string bnum, double billamt) { try { if (Double.IsNaN(billamt)) { return(NotFound()); } var billamtobj = new Models.Bill { BillNumber = bnum, BillAmount = billamt }; _context.Bill.Attach(billamtobj).Property(x => x.BillAmount).IsModified = true; _context.SaveChanges(); return(new JsonResult("Information Updated!")); } catch (Exception e) { return(NotFound()); } }
public void AddBill(string _billDetail, float _money, DateTime _billDate) { var tmp = new Models.Bill(_billDate, _billDetail, _money); allBills.Add(tmp); }
/// <summary> /// Add new Bill to Database /// </summary> /// <param name="sp"></param> public void AddBill(Repository.Repository repository, Models.Bill bill) { string queryString = "insert into Bill(saler_name, customer_id) " + "values('" + bill.salerName + "', '" + bill.customerID + ")"; repository.cmd.CommandText = queryString; try { repository.cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show( "Có lỗi xảy ra trong quá trình thêm dữ liệu, vui lòng thử lại!\nChi tiết: " + ex.StackTrace, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } queryString = "select * from Bill order by id desc limit 1"; repository.cmd.CommandText = queryString; using (DbDataReader reader = repository.cmd.ExecuteReader()) { if (!reader.HasRows) { MessageBox.Show( "Data chưa có dữ liệu", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { while (reader.Read()) { Models.Bill temp = new Models.Bill( reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2), this.listSanPham ); foreach (Models.Item sp in this.listSanPham) { string q = "insert into CT_DH_SP(bill_id, product_id, amount, is_error) " + "values('" + temp.ID + "', '" + sp.ID + "', '" + 1 + "', '" + false + ")"; repository.cmd.CommandText = q; try { repository.cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show( "Có lỗi xảy ra trong quá trình thêm dữ liệu, vui lòng thử lại!\nChi tiết: " + ex.StackTrace, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } }
public BillViewModel(Models.Bill objBill) { this.ApplyFromModel(objBill); }
public IActionResult OnPostSendMessage([FromBody] Models.Bill obj) { //var mnth = obj.InvoiceDate.Month; //var quarter = ""; //if(mnth==4 || mnth==5 || mnth==6) //{ // quarter = "1"; //} //else if(mnth == 7 || mnth == 8 || mnth == 9) //{ // quarter = "2"; //} //else if (mnth == 10 || mnth == 11 || mnth == 12) //{ // quarter = "3"; //} //else //{ // quarter = "4"; //} //if(quarter=="") //{ // return NotFound(); //} var fyear = obj.Note; //if(quarter=="4") //{ // fyear ="" +((obj.InvoiceDate.Year)-1)+"-"+(obj.InvoiceDate.Year); //} //else //{ // fyear= "" + (obj.InvoiceDate.Year) + "-" + ((obj.InvoiceDate.Year)+1); //} var DebtorGroupInfo = _context.DebtorGroup.Where(a => a.DebtorGroupID.Equals(obj.DebtorGroupID)).FirstOrDefault(); var format = ""; if (string.IsNullOrEmpty(obj.SeriesName)) { format = "Format2"; } else { format = "Format1"; } string companyname = _context.Company.Where(a => a.CompanyID.Equals(obj.CompanyID)).Select(ab => ab.CompanyName).FirstOrDefault().ToString(); string[] msgcnt = new string[3]; msgcnt[0] = SendSmsAsync(DebtorGroupInfo.DebtorGroupPhoneNumber.Substring(DebtorGroupInfo.DebtorGroupPhoneNumber.Length - 10), fyear, obj.BillAmount, format, Options.WhatsappAccountPassword, obj.BillNumber, obj.SecretUnlockCode, companyname, DebtorGroupInfo.DebtorOutstanding); msgcnt[1] = (DebtorGroupInfo.DebtorGroupPhoneNumber.Substring(DebtorGroupInfo.DebtorGroupPhoneNumber.Length - 10)); msgcnt[2] = DebtorGroupInfo.DebtorGroupName; // SendSmsAsync(DebtorGroupInfo.DebtorGroupPhoneNumber.Substring(DebtorGroupInfo.DebtorGroupPhoneNumber.Length-10), fyear, obj.BillAmount, format, Options.WhatsappAccountPassword, obj.BillNumber, obj.SecretUnlockCode,companyname, DebtorGroupInfo.DebtorOutstanding); var messagesent = new Models.Bill { BillNumber = obj.BillNumber, MessageSent = true }; _context.Bill.Attach(messagesent).Property(x => x.MessageSent).IsModified = true; _context.SaveChanges(); return(new JsonResult(msgcnt)); }