private string invoiceMarkRead(INVOICE[] invoiceList) { using (new OperationContextScope(eInvoiceOIBPortClient.InnerChannel)) { var markReq = new MarkInvoiceRequest(); //sistemdeki gelen efatura listesi için request parametreleri markReq.REQUEST_HEADER = RequestHeader.getRequestHeaderOib; markReq.MARK = new MarkInvoiceRequestMARK(); List <INVOICE> listInvoiceMark = new List <INVOICE>(); for (int i = 0; i < invoiceList.Length; i++) { INVOICE inv = new INVOICE(); inv.ID = invoiceList[i].ID; inv.UUID = invoiceList[i].UUID; listInvoiceMark.Add(inv); } markReq.MARK.INVOICE = listInvoiceMark.ToArray(); markReq.MARK.value = MarkInvoiceRequestMARKValue.READ; markReq.MARK.valueSpecified = true; MarkInvoiceResponse markRes = eInvoiceOIBPortClient.MarkInvoice(markReq); if (markRes.REQUEST_RETURN != null && markRes.REQUEST_RETURN.RETURN_CODE == 0)//basarılıysa { return(null); } else { return("mark ınvoice basarısız"); } } }
public ActionResult Payment(INVOICE invoice) { invoice.time = DateTime.Now; try { context.INVOICEs.Add(invoice); context.SaveChanges(); var cart = (Cart)Session["CartSession"]; foreach (var item in cart.Lines) { DETAIL_INVOICE obj = new DETAIL_INVOICE(); obj.invoiceId = invoice.id; obj.voucherId = item.Voucher.id; //obj.DonGia = item.Sanpham.GiaSP; obj.quantity = item.Quantity; context.DETAIL_INVOICE.Add(obj); context.SaveChanges(); } cart.Clear(); Session["CartSession"] = cart; } catch (Exception ex) { //ghi log return(RedirectToAction("/Loi")); } return(View("Complete")); }
public void Remove(INVOICE id) { using (var conn = new SqlConnection(connString)) { try { Message = ""; conn.Open(); SqlCommand command = new SqlCommand("DELETE Invoice WHERE id = @id", conn); command.CommandType = System.Data.CommandType.Text; if (id.id != null) { command.Parameters.AddWithValue("@id", id.id); } else { command.Parameters.AddWithValue("@id", DBNull.Value); } command.ExecuteNonQuery(); } catch (Exception ex) { Message = ex.Message; } } }
//add existed invoice public void loadExistedInvoice(String code) { if (code != null && !code.Equals("")) { updateInvoice = model.getInvoiceByCode(code, RECORD_STATUS.ACTIVE); DataTable table = model.getInvoiceItemListBy(updateInvoice.INVOICE_ID, RECORD_STATUS.ACTIVE); if (table == null) { table = new DataTable(); table = new DataTable(); var collumns = table.Columns; collumns.Add("INVOICE_ITEM_CODE"); collumns.Add("PRODUCT_NAME"); collumns.Add("SIZE"); collumns.Add("UNIT"); collumns.Add("DISCOUNT_AMOUNT"); collumns.Add("QUANTITY"); collumns.Add("UNIT_PRICE"); collumns.Add("AMOUNT"); collumns.Add("NOTE"); } else { isUpdated = true; } invoiceAddingView.showInfoComponents(updateInvoice); invoiceAddingView.showInvoiceItemGrid(table); } else { invoiceView.showMessageBox("Có lỗi xảy ra! Thử lại sau!", System.Windows.Forms.MessageBoxIcon.Error); } }
public bool addInvoice(INVOICE invoice, List <INVOICE_ITEM> itemList) { try { UShopDB.INVOICEs.InsertOnSubmit(invoice); UShopDB.SubmitChanges(); invoice.INVOICE_CODE = getCODE("INV", invoice.INVOICE_ID); if (itemList != null && itemList.Count > 0) { UShopDB.INVOICE_ITEMs.InsertAllOnSubmit(itemList); UShopDB.SubmitChanges(); double totalDiscount = 0; foreach (var item in itemList) { item.INVOICE_ITEM_CODE = getCODE("INVI", item.INVOICE_ITEM_ID); item.INVOICE_ID = invoice.INVOICE_ID; totalDiscount += (double)item.DISCOUNT; //updateProductSize((int)item.PRODUCT_ID, item.SIZE,0 -(int)item.QUANTITY); } invoice.TOTAL_SALE = totalDiscount; } UShopDB.SubmitChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public int INVOICE_Insert(INVOICE obj) { try { return(DataProvider.ExecuteNonquery(DataProvider.ConnectionString, "INVOICE_Insert", obj.ID , obj.RefNo , obj.RefDate , obj.RefType , obj.RefStatus , obj.StockID , obj.PrintCount , obj.TongTien , obj.KhachTra , obj.ConLai , obj.Active , obj.CreateBy , obj.Createdate , obj.ModifyBy , obj.ModifyDate )); } catch { //throw ex; return(-1); } }
public void createInvListWithUuid(string uuid) { INVOICE invoice = new INVOICE(); invoice.UUID = uuid; invoiceList.Add(invoice); }
private INVOICE CopyInvoice(OrderDateModel itemOrder) { INVOICE invoice = new INVOICE(); invoice.InvoiceNumber = itemOrder.InvoiceNumber; invoice.OrderID = itemOrder.OrderID; invoice.OrderNumber = itemOrder.OrderNumber; invoice.Total = Convert.ToInt32(itemOrder.TotalAmount); invoice.Status = 1; invoice.DiscountType = itemOrder.DiscountType; invoice.Discount = (itemOrder.Discount); invoice.Payment = itemOrder.Payment; invoice.Change = itemOrder.Change; invoice.CashOut = Convert.ToInt32(itemOrder.CashOut); if (itemOrder.ListInvoiceByCard.Count > 0) { invoice.InvoiceByCardID = Convert.ToInt32(CustomerInvoiceByCardID()); } else { invoice.InvoiceByCardID = 0; } invoice.CreateBy = itemOrder.CreateBy ?? 0; invoice.CreateDate = DateTime.Now; invoice.UpdateBy = itemOrder.UpdateBy ?? 0; invoice.UpdateDate = DateTime.Now; invoice.Note = itemOrder.Note ?? ""; invoice.ShiftID = itemOrder.ShiftID; return(invoice); }
public InvoiceAutoForm(Guid guidInvoice) : this() { INVOICE nVOICE = (new INVOICE_BL()).Load(guidInvoice); this.pluginBox1.SetId(nVOICE.ID_STORE); this.plInvoice.SetGuid(guidInvoice); }
public List <INVOICE> GetDataByid(int id) { List <INVOICE> items = new List <INVOICE>(); using (var conn = new SqlConnection(connString)) { Message = ""; try { conn.Open(); SqlCommand command = new SqlCommand("SELECT [id], [invoice_date], [t_o], [ship_to], [payment_type], [sales_name], [courier_name], [no_invoice] FROM Invoice WHERE no_invoice = @id", conn); command.Parameters.AddWithValue("@id", id); SqlDataReader reader = command.ExecuteReader(); INVOICE item = new INVOICE(); while (reader.Read()) { item = new INVOICE(); if (reader[0] != DBNull.Value) { item.id = Convert.ToInt32(reader[0]); } if (reader[1] != DBNull.Value) { item.invoice_date = Convert.ToDateTime(reader[1]); } if (reader[2] != DBNull.Value) { item.t_o = Convert.ToString(reader[2]); } if (reader[3] != DBNull.Value) { item.ship_to = Convert.ToString(reader[3]); } if (reader[4] != DBNull.Value) { item.payment_type = Convert.ToString(reader[4]); } if (reader[5] != DBNull.Value) { item.sales_name = Convert.ToString(reader[5]); } if (reader[6] != DBNull.Value) { item.courier_name = Convert.ToString(reader[6]); } if (reader[7] != DBNull.Value) { item.no_invoice = Convert.ToString(reader[7]); } items.Add(item); } } catch (Exception ex) { Message = ex.Message; } } return(items); }
public override global::System.Data.DataSet Clone() { INVOICE cln = ((INVOICE)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public InvoicePresenter(IInvoice model) { isUpdated = false; this.model = model; productList = new List <PRODUCT>(); proSizeList = new List <PRODUCT_SIZE>(); invoiceItemList = new List <INVOICE_ITEM>(); updateInvoice = new INVOICE(); invoiceList = new List <INVOICE>(); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { INVOICE ds = new INVOICE(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public void showInfoComponents(INVOICE invoice) { CUSTOMER temp = presenter.findCustomerBy((int)invoice.BUYER_ID); cmbAICustomer.Text = temp.CUS_CODE + "-" + temp.CUS_NAME; cmbAIPaymentMethod.Text = invoice.PAYMENT_METHOD; txteAIEmployee.Text = AccountPresenter.currentEmployee.EMP_NAME; txteAIInvoiceNo.Text = invoice.INVOICE_CODE; dpickAIDate.Value = (DateTime)(invoice.DATE != null ? invoice.DATE : DateTime.Now); txteAITotalAmount.Text = invoice.TOTAL_AMOUNT + ""; txteAITotalPayment.Text = invoice.TOTAL_PAYMENT + ""; txteAINote.Text = invoice.NOTE; txteAIVAT.Text = invoice.VAT_RATE + ""; }
public ActionResult Checkout(INVOICE invoice) { var sessionCart = (CartModel)Session[Common.CommonConstants.CART_SESSION]; var sessionUser = Session[Common.CommonConstants.USER_SESSION]; invoice.Created_Time = DateTime.Now; invoice.Status = 0; invoice.Total = sessionCart.Total * (100 - sessionCart.DiscountAmount) / 100; if (sessionCart.DiscountCode != null) { invoice.Id_Discount_Code = new DiscountCodeDAO().GetDiscountCodeByCode(sessionCart.DiscountCode).Id; } if (sessionUser != null) { var user = (USER)sessionUser; invoice.Id_User = user.Id; } if (ModelState.IsValid) { var invoiceId = new InvoiceDAO().Insert(invoice); if (invoiceId > 0) { var detailDAO = new InvoiceDetailDAO(); foreach (var item in sessionCart.ListCartItem) { var invoiceDetail = new INVOICE_DETAIL { Id_Invoice = invoiceId, Id_Product = item.Product.Id, Quantity = item.Quantity }; detailDAO.Insert(invoiceDetail); } Session[Common.CommonConstants.CART_SESSION] = null; return(Json(new { result = true })); } } return(PartialView("CheckoutForm", invoice)); }
public ActionResult UpdateInvoice(INVOICE invoice, FormCollection f) { invoice.Customer_Message = f["txtMessage"].ToString(); //If checked, f["checkStatus"] = true,false bool checkStatus = Convert.ToBoolean(f["checkStatus"].Split(',')[0]); invoice.Status = checkStatus ? 1 : 0; invoice.Payment_Method = f["selectMethod"].ToString(); INVOICE model = invoiceDAO.Update(invoice); if (model == null) { return(Json(new { result = false })); } return(Json(new { result = true, data = PartialViewToString("InvoiceDetailForm", model) })); }
/// <summary> /// islem basarılıysa status doner degılse null doner /// </summary> public GetInvoiceStatusResponseINVOICE_STATUS getInvoiceStatatus(string invoiceUuid) { INVOICE invoice = new INVOICE(); invoice.UUID = invoiceUuid; using (new OperationContextScope(eInvoiceOIBPortClient.InnerChannel)) { GetInvoiceStatusRequest req = new GetInvoiceStatusRequest() { REQUEST_HEADER = RequestHeader.getRequestHeaderOib, INVOICE = invoice, }; return(eInvoiceOIBPortClient.GetInvoiceStatus(req).INVOICE_STATUS); } }
public void createInvListWithContent(bool withZip, string xmlStr) { INVOICE invoice = new INVOICE(); base64Binary contentByte = new base64Binary(); if (withZip) //zipli gönderilmek isteniyorsa { contentByte.Value = Compress.compressFile(xmlStr); } else //zipsiz content value { contentByte.Value = Encoding.UTF8.GetBytes(xmlStr); } invoice.CONTENT = contentByte; invoiceList.Add(invoice); }
private bool plInvoice_ValidatingItem(DataRowItem item) { if (item.Id == (long)0) { return(true); } INVOICE nVOICE = (new INVOICE_BL()).Load(item.Guid); if (this.pluginBox1.RowItem.Id == (long)0) { this.pluginBox1.SetId(nVOICE.ID_STORE); return(true); } if (nVOICE.ID_STORE == this.pluginBox1.Id) { return(true); } ePlus.MetaData.Core.Logger.ShowInfo("Накладная принадлежит другому складу!"); return(false); }
public INVOICE Update(INVOICE entity) { try { var invoice = db.INVOICE.Find(entity.Id); invoice.Customer_Name = entity.Customer_Name; invoice.Customer_Phone = entity.Customer_Phone; invoice.Customer_Email = entity.Customer_Email; invoice.Customer_Address = entity.Customer_Address; invoice.Customer_Message = entity.Customer_Message; invoice.Status = entity.Status; invoice.Payment_Method = entity.Payment_Method; db.SaveChanges(); return(invoice); } catch (Exception ex) { return(null); } }
public INVOICE getInvoiceByCode(string code, RECORD_STATUS status) { INVOICE invoice = new INVOICE(); try { var queryResult = UShopDB.INVOICEs .Where (o => o.INVOICE_CODE.Equals(code) && (status != 0 ? o.RECORD_STATUS.Equals((char)status) : true) //if status = 0 -> independent record status ).SingleOrDefault(); invoice = queryResult; } catch (Exception e) { Console.WriteLine(e.Message); } return(invoice); }
public ActionResult Edit([Bind(Include = "INVOICE_ID,CUSTOMER_ID,INVOICE_DATE")] INVOICE invoice) { // проверяем правильность модели if (ModelState.IsValid) { try { var INVOICE_ID = new FbParameter("INVOICE_ID", FbDbType.Integer); var CUSTOMER_ID = new FbParameter("CUSTOMER_ID", FbDbType.Integer); var INVOICE_DATE = new FbParameter("INVOICE_DATE", FbDbType.TimeStamp); // инициализируем параметры значениями INVOICE_ID.Value = invoice.INVOICE_ID; CUSTOMER_ID.Value = invoice.CUSTOMER_ID; INVOICE_DATE.Value = invoice.INVOICE_DATE; // выполняем ХП db.Database.ExecuteSqlCommand( "EXECUTE PROCEDURE SP_EDIT_INVOICE(@INVOICE_ID, @CUSTOMER_ID, @INVOICE_DATE)", INVOICE_ID, CUSTOMER_ID, INVOICE_DATE); // возвращаем успех в формате JSON return(Json(true)); } catch (Exception ex) { // возвращаем ошибку в формате JSON return(Json(new { error = ex.Message })); } } else { string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); // возвращаем ошибку в формате JSON return(Json(new { error = messages })); } }
private void purchase_Click(object sender, EventArgs e) { DateTimePicker date = new DateTimePicker(); // DateTime date = new DateTime(); int qty; //making sure the user enters an integer if (int.TryParse(textBox.Text, out qty)) { if (qty > 0) { if (qty <= context.BOOKs.Select(b => b.Book_Qty).First()) { //check balance-if able to buy it, then change balance amount if (context.CUSTOMERs.Where(c => c.Cust_ID == CustLogin.Id) .Select(c => c.Cust_Balance).First() + (context.BOOKs.Where(b => b.Book_ID.Equals(BookId)) .Select(b => b.Book_Price).First() * qty) <= MyAccount.Credit) { //now need to subtract qty BOOK book = context.BOOKs.Single(b => b.Book_ID == BookId); book.Book_Qty -= qty; //increase the balance CUSTOMER cust = context.CUSTOMERs.Single(c => c.Cust_ID == CustLogin.Id); cust.Cust_Balance += context.BOOKs.Where(b => b.Book_ID == BookId) .Select(b => b.Book_Price).First() * qty; //insert into the invoice table INVOICE invoice = new INVOICE { Book_ID = BookId, Cust_ID = CustLogin.Id, Inv_Total = context.BOOKs.Where(b => b.Book_ID == BookId) .Select(b => b.Book_Price).First() * qty, Inv_Date = date.Value, Inv_Qty = qty }; context.INVOICEs.InsertOnSubmit(invoice); //submit ALL the changes... context.SubmitChanges(); MessageBox.Show("Item is being shipped!"); }//end if else { MessageBox.Show("You have gone over your Balance"); } }//end if else { if (context.BOOKs.Select(b => b.Book_Qty).First() == 0) { MessageBox.Show("Out of stock\nPick another book"); } else { MessageBox.Show("Not enough in stock, reenter quantity"); } } }//end if else { MessageBox.Show("Enter quantity amount"); } }//end if }
private List <INVOICE> MapINVOICE(DataTable dt) { List <INVOICE> rs = new List <INVOICE>(); for (int i = 0; i < dt.Rows.Count; i++) { INVOICE obj = new INVOICE(); if (dt.Columns.Contains("ID")) { obj.ID = long.Parse(dt.Rows[i]["ID"].ToString()); } if (dt.Columns.Contains("RefNo")) { obj.RefNo = dt.Rows[i]["RefNo"].ToString(); } if (dt.Columns.Contains("RefDate")) { obj.RefDate = DateTime.Parse(dt.Rows[i]["RefDate"].ToString()); } if (dt.Columns.Contains("RefStatus")) { obj.RefStatus = int.Parse(dt.Rows[i]["RefStatus"].ToString()); } if (dt.Columns.Contains("RefType")) { obj.RefType = int.Parse(dt.Rows[i]["RefType"].ToString()); } if (dt.Columns.Contains("StockID")) { obj.StockID = dt.Rows[i]["StockID"].ToString(); } if (dt.Columns.Contains("PrintCount")) { obj.PrintCount = int.Parse(dt.Rows[i]["PrintCount"].ToString()); } if (dt.Columns.Contains("TongTien")) { obj.TongTien = double.Parse(dt.Rows[i]["TongTien"].ToString()); } if (dt.Columns.Contains("KhachTra")) { obj.KhachTra = double.Parse(dt.Rows[i]["KhachTra"].ToString()); } if (dt.Columns.Contains("ConLai")) { obj.ConLai = double.Parse(dt.Rows[i]["ConLai"].ToString()); } if (dt.Columns.Contains("Active")) { obj.Active = bool.Parse(dt.Rows[i]["Active"].ToString()); } if (dt.Columns.Contains("CreateBy")) { obj.CreateBy = dt.Rows[i]["CreateBy"].ToString(); } if (dt.Columns.Contains("Createdate")) { obj.Createdate = DateTime.Parse(dt.Rows[i]["Createdate"].ToString()); } if (dt.Columns.Contains("ModifyBy")) { obj.ModifyBy = dt.Rows[i]["ModifyBy"].ToString(); } if (dt.Columns.Contains("ModifyDate")) { obj.ModifyDate = DateTime.Parse(dt.Rows[i]["ModifyDate"].ToString()); } rs.Add(obj); } return(rs); }
public void Delete(INVOICE invoice) { INVOICERepository rep = new INVOICERepository(connectionString); rep.Remove(invoice); }
public bool updateInvoice(INVOICE updated, List <INVOICE_ITEM> itemList) { int queryid = updated.INVOICE_ID; if (queryid > 0) { try { var invoice = UShopDB.INVOICEs.Where(o => o.INVOICE_ID == queryid).SingleOrDefault(); //invoice.INVOICE_CODE = updated.INVOICE_CODE; invoice.BUYER_ID = updated.BUYER_ID; invoice.DATE = updated.DATE; invoice.NOTE = updated.NOTE; invoice.PAYMENT_METHOD = updated.PAYMENT_METHOD; invoice.TOTAL_AMOUNT = updated.TOTAL_AMOUNT; invoice.TOTAL_PAYMENT = updated.TOTAL_PAYMENT; invoice.VAT_AMOUNT = updated.VAT_AMOUNT; invoice.VAT_RATE = updated.VAT_RATE; invoice.SELLER_ID = updated.SELLER_ID; UShopDB.SubmitChanges(); invoice.INVOICE_CODE = getCODE("INV", invoice.INVOICE_ID); UShopDB.SubmitChanges(); if (itemList != null && itemList.Count > 0) { double totalDiscount = 0; //double totalAmount = 0; //double totalPayment = 0; List <INVOICE_ITEM> invoiceItemList = UShopDB.INVOICE_ITEMs.Where(o => o.INVOICE_ID == queryid).DefaultIfEmpty().ToList(); if (invoiceItemList != null && invoiceItemList.Count > 0) { foreach (var item in invoiceItemList) { //tra lai so luong cho product size //updateProductSize((int)item.PRODUCT_ID, item.SIZE,(int)item.QUANTITY - 0); // xoa di item nay UShopDB.INVOICE_ITEMs.DeleteOnSubmit(item); ////update invoice item data //bool isExisted = false; //foreach (var updateItem in itemList) //{ // if (item.INVOICE_ITEM_ID == updateItem.INVOICE_ITEM_ID) // { // isExisted = true; // item.NOTE = updateItem.NOTE; // item.PRICE = updateItem.PRICE; // item.RECORD_STATUS = updateItem.RECORD_STATUS; // if( !item.SIZE.Equals(updateItem.SIZE) // || !item.PRODUCT_ID.Equals(updateItem.PRODUCT_ID) // || !item.QUANTITY.Equals(updateItem.QUANTITY)) // { // //UPDATE product size // updateProductSize((int)updateItem.PRODUCT_ID, updateItem.SIZE, (int)( item.QUANTITY - updateItem.QUANTITY )); // } // item.SIZE = updateItem.SIZE; // item.PRODUCT_ID = updateItem.PRODUCT_ID; // item.QUANTITY = updateItem.QUANTITY; // UShopDB.SubmitChanges(); // break; // } //} //UShopDB.INVOICE_ITEMs.DeleteOnSubmit(item); } UShopDB.SubmitChanges(); } //add lai UShopDB.INVOICE_ITEMs.InsertAllOnSubmit(itemList); UShopDB.SubmitChanges(); foreach (var update in itemList) { totalDiscount += (double)update.DISCOUNT; // totalAmount += (double)update.AMOUNT; update.INVOICE_ITEM_CODE = getCODE("INVI", update.INVOICE_ITEM_ID); update.INVOICE_ID = invoice.INVOICE_ID; //tru lai trong bang product size //updateProductSize((int)update.PRODUCT_ID, update.SIZE, (int)(0 - update.QUANTITY)); } UShopDB.SubmitChanges(); invoice.TOTAL_SALE = totalDiscount; } UShopDB.SubmitChanges(); return(true); } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } } return(false); }
public void Update(INVOICE invoice) { using (var conn = new SqlConnection(connString)) { try { Message = ""; conn.Open(); SqlCommand command = new SqlCommand("UPDATE Invoice SET invoice_date = @invoice_date, t_o = @t_o, ship_to = @ship_to, payment_type = @payment_type, sales_name = @sales_name, courier_name = @courier_name, no_invoice = @no_invoice WHERE id = @id", conn); command.CommandType = System.Data.CommandType.Text; if (invoice.id != null) { command.Parameters.AddWithValue("@id", invoice.id); } else { command.Parameters.AddWithValue("@id", DBNull.Value); } if (invoice.invoice_date != null) { command.Parameters.AddWithValue("@invoice_date", invoice.invoice_date); } else { command.Parameters.AddWithValue("@invoice_date", DBNull.Value); } if (invoice.t_o != null) { command.Parameters.AddWithValue("@t_o", invoice.t_o); } else { command.Parameters.AddWithValue("@t_o", DBNull.Value); } if (invoice.ship_to != null) { command.Parameters.AddWithValue("@ship_to", invoice.ship_to); } else { command.Parameters.AddWithValue("@ship_to", DBNull.Value); } if (invoice.payment_type != null) { command.Parameters.AddWithValue("@payment_type", invoice.payment_type); } else { command.Parameters.AddWithValue("@payment_type", DBNull.Value); } if (invoice.sales_name != null) { command.Parameters.AddWithValue("@sales_name", invoice.sales_name); } else { command.Parameters.AddWithValue("@sales_name", DBNull.Value); } if (invoice.courier_name != null) { command.Parameters.AddWithValue("@courier_name", invoice.courier_name); } else { command.Parameters.AddWithValue("@courier_name", DBNull.Value); } if (invoice.no_invoice != null) { command.Parameters.AddWithValue("@no_invoice", invoice.no_invoice); } else { command.Parameters.AddWithValue("@no_invoice", DBNull.Value); } command.ExecuteNonQuery(); } catch (Exception ex) { Message = ex.Message; } } }
public void Add(INVOICE invoice) { using (var conn = new SqlConnection(connString)) { try { Message = ""; conn.Open(); SqlCommand command = new SqlCommand("INSERT INTO Invoice ( [invoice_date], [t_o], [ship_to], [payment_type], [sales_name], [courier_name], [no_invoice]) VALUES(@invoice_date, @t_o, @ship_to, @payment_type, @sales_name, @courier_name, @no_invoice)", conn); command.CommandType = System.Data.CommandType.Text; //if (invoice.id != null) { command.Parameters.AddWithValue("@id", invoice.id); } else { command.Parameters.AddWithValue("@id", DBNull.Value); } if (invoice.invoice_date != null) { command.Parameters.AddWithValue("@invoice_date", invoice.invoice_date); } else { command.Parameters.AddWithValue("@invoice_date", DBNull.Value); } if (invoice.t_o != null) { command.Parameters.AddWithValue("@t_o", invoice.t_o); } else { command.Parameters.AddWithValue("@t_o", DBNull.Value); } if (invoice.ship_to != null) { command.Parameters.AddWithValue("@ship_to", invoice.ship_to); } else { command.Parameters.AddWithValue("@ship_to", DBNull.Value); } if (invoice.payment_type != null) { command.Parameters.AddWithValue("@payment_type", invoice.payment_type); } else { command.Parameters.AddWithValue("@payment_type", DBNull.Value); } if (invoice.sales_name != null) { command.Parameters.AddWithValue("@sales_name", invoice.sales_name); } else { command.Parameters.AddWithValue("@sales_name", DBNull.Value); } if (invoice.courier_name != null) { command.Parameters.AddWithValue("@courier_name", invoice.courier_name); } else { command.Parameters.AddWithValue("@courier_name", DBNull.Value); } if (invoice.no_invoice != null) { command.Parameters.AddWithValue("@no_invoice", invoice.no_invoice); } else { command.Parameters.AddWithValue("@no_invoice", DBNull.Value); } command.ExecuteNonQuery(); } catch (Exception ex) { Message = ex.Message; } } }
public void insertInvoice(string cusCode, string paymentMethod, string vAT, string note, DateTime date, string totalPayment, string totalAmount) { String error = Resources.MB_FAILURE; try { int cusId = 0; if (!checkValidCusCode(cusCode)) { error += ": Không tìm thấy khách hàng này trong CSDL."; throw new Exception(); } else if (!checkValidVAT(vAT)) { error += ": VAT không thể chứa kí tự đặc biệt, chữ và luôn >=0."; throw new Exception(); } else if (!checkValidDate(date)) { error += ": Ngày lập phiếu không thể lớn hơn ngày hiện tại."; throw new Exception(); } else if (!checkValidTotalPayment(totalPayment)) { error += ": tổng trả không thể chứa kí tự đặc biệt, chữ và luôn >=0."; throw new Exception(); } else if (!checkValidTotalAmount(totalAmount)) { error += ": tổng tiền không thể chứa kí tự đặc biệt, chữ và luôn >=0."; throw new Exception(); } cusId = findCustomerBy(cusCode).CUS_ID; INVOICE invoice = new INVOICE(); invoice.SELLER_ID = AccountPresenter.currentEmployee.EMP_ID; invoice.BUYER_ID = cusId; invoice.PAYMENT_METHOD = paymentMethod; invoice.DATE = date; invoice.NOTE = note; invoice.TOTAL_AMOUNT = Convert.ToDouble(totalAmount); invoice.TOTAL_PAYMENT = Convert.ToDouble(totalPayment); invoice.TOTAL_SALE = 0; invoice.VAT_AMOUNT = 0; invoice.VAT_RATE = Convert.ToDouble(vAT); invoice.RECORD_STATUS = ((char)RECORD_STATUS.ACTIVE) + ""; //put into invoiceItemList DataTable table = InvoiceAddingView.getInvoiceItemDataTable(); invoiceItemList.Clear(); for (int i = 0; i < table.Rows.Count; i++) { var currRow = table.Rows[i]; String proCodeName = currRow["PRODUCT_NAME"] + ""; String proCode = proCodeName.Split(new char[] { '-' })[0]; INVOICE_ITEM item = new INVOICE_ITEM(); item.PRICE = Convert.ToSingle(currRow["UNIT_PRICE"]); item.QUANTITY = Convert.ToInt16(currRow["QUANTITY"]); item.SIZE = currRow["SIZE"] + ""; item.DISCOUNT = Convert.ToSingle(currRow["DISCOUNT_AMOUNT"]); item.AMOUNT = Convert.ToDouble(currRow["AMOUNT"]); item.RECORD_STATUS = ((char)RECORD_STATUS.ACTIVE) + ""; item.PRODUCT_ID = findProductBy(proCode).PRODUCT_ID; invoiceItemList.Add(item); } //update or insert if (!isUpdated) { if (model.addInvoice(invoice, invoiceItemList)) { invoice = new INVOICE(); invoiceItemList.Clear(); invoiceAddingView.showMessageBox(Resources.MB_SUCCESS, System.Windows.Forms.MessageBoxIcon.Information); invoiceAddingView.resetAll(); } else { invoiceAddingView.showMessageBox(Resources.MB_FAILURE, System.Windows.Forms.MessageBoxIcon.Information); } } else { updateInvoice.BUYER_ID = invoice.BUYER_ID; updateInvoice.DATE = invoice.DATE; updateInvoice.NOTE = invoice.NOTE; updateInvoice.PAYMENT_METHOD = invoice.PAYMENT_METHOD; updateInvoice.SELLER_ID = invoice.SELLER_ID; updateInvoice.TOTAL_AMOUNT = invoice.TOTAL_AMOUNT; updateInvoice.TOTAL_PAYMENT = invoice.TOTAL_PAYMENT; updateInvoice.TOTAL_SALE = invoice.TOTAL_SALE; updateInvoice.VAT_AMOUNT = invoice.VAT_AMOUNT; updateInvoice.VAT_RATE = invoice.VAT_RATE; updateInvoice.RECORD_STATUS = invoice.RECORD_STATUS; if (model.updateInvoice(updateInvoice, invoiceItemList)) { invoice = new INVOICE(); invoiceItemList.Clear(); invoiceAddingView.showMessageBox(Resources.MB_SUCCESS, System.Windows.Forms.MessageBoxIcon.Information); invoiceAddingView.resetAll(); } else { invoiceAddingView.showMessageBox(Resources.MB_FAILURE, System.Windows.Forms.MessageBoxIcon.Information); } } }catch (Exception e) { Console.WriteLine(e.Message); invoiceAddingView.showMessageBox(error, System.Windows.Forms.MessageBoxIcon.Error); } }
public int InsertInvoice(OrderDateModel Order) { int result = 0; int InvoiceID; INVOICE invoice = new INVOICE(); List <INVOICE_DETAIL> invoiceDEtail = new List <INVOICE_DETAIL>(); List <INVOICE_DETAIL_MODIFIRE> invoiceDetailModifier = new List <INVOICE_DETAIL_MODIFIRE>(); List <PAYMENT_INVOICE_HISTORY> PaymentHistory = new List <PAYMENT_INVOICE_HISTORY>(); List <INVOICE_BY_CARD> InvoiceByCard = new List <INVOICE_BY_CARD>(); ACC_PAYMENT Acc = new ACC_PAYMENT(); using (var trans = _context.Database.BeginTransaction()) { _context.Database.ExecuteSqlCommand("update ORDER_DATE set Status=1 where OrderID='" + Order.OrderID + "'"); invoice = CopyInvoice(Order); _context.Entry(invoice).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); InvoiceID = invoice.InvoiceID; string InvNum = InvoiceID + "" + DateTime.Now.Date.Year + "" + DateTime.Now.Date.Month + "" + DateTime.Now.Date.Day; _context.Database.ExecuteSqlCommand("update invoice set InvoiceNumber='" + InvNum + "'where InvoiceID='" + InvoiceID + "'"); //Update balance for customer _context.Database.ExecuteSqlCommand("update client set balance=balance+'" + -Convert.ToInt32(Order.Payment) + "' where ClientID='" + Order.CusItem.ClientID + "'"); Acc = CopyAcc(Order); Acc.InvoiceID = InvoiceID; Acc.InvoiceNumber = Convert.ToInt32(InvNum); //_context.Entry(Acc).State = System.Data.Entity.EntityState.Added; string sql = "insert into acc_payment(CusNo,SubTotal,InvoiceID,InvoiceNumber,Cash,Card,IsCredit,IsDebit,CreateDate,CreateBy,UpdateDate,UpdateBy)values(" + "'" + Order.CusItem.ClientID + "','" + Convert.ToInt32(Order.Payment) + "','" + InvoiceID + "','" + Convert.ToInt32(InvNum) + "',0,0,1,0,'" + DateTime.Now + "','" + Order.ShiftID + "','" + DateTime.Now + "','" + Order.ShiftID + "')"; _context.Database.ExecuteSqlCommand("insert into acc_payment(CusNo,SubTotal,InvoiceID,InvoiceNumber,Cash,Card,IsCredit,IsDebit,CreateDate,CreateBy,UpdateDate,UpdateBy)values(" + "'" + Order.CusItem.ClientID + "','" + Convert.ToInt32(Order.Payment) + "','" + InvoiceID + "','" + Convert.ToInt32(InvNum) + "',0,0,1,0,'" + DateTime.Now + "','" + Order.ShiftID + "','" + DateTime.Now + "','" + Order.ShiftID + "')"); // invoiceDEtail = CopyInvoicedetail(Order); foreach (INVOICE_DETAIL item in invoiceDEtail) { item.InvoiceID = InvoiceID; item.InvoiceNumber = Convert.ToInt32(InvNum); _context.Entry(item).State = System.Data.Entity.EntityState.Added; } invoiceDetailModifier = CopyInvoiceMidifire(Order); foreach (INVOICE_DETAIL_MODIFIRE item in invoiceDetailModifier) { item.InvoiceID = InvoiceID; item.InvoiceNumber = Convert.ToInt32(InvNum); _context.Entry(item).State = System.Data.Entity.EntityState.Added; } PaymentHistory = CopyListPayment(Order); foreach (PAYMENT_INVOICE_HISTORY item in PaymentHistory) { item.InvoiceID = InvoiceID; item.InvoiceNumber = Convert.ToInt32(InvNum); _context.Entry(item).State = System.Data.Entity.EntityState.Added; } InvoiceByCard = CopyInvoiceByCard(Order); foreach (INVOICE_BY_CARD item in InvoiceByCard) { item.InvoiceID = InvoiceID; _context.Entry(item).State = System.Data.Entity.EntityState.Added; } _context.SaveChanges(); trans.Commit(); result = 1; } return(result); }