protected void btnSave_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; int agentID = 0; string username = Request.Cookies["userLoginSystem"].Value; if (!string.IsNullOrEmpty(username)) { var a = AccountController.GetByUsername(username); if (a != null) { // Change user string RefundNote = ""; if (username != hdfUsernameCurrent.Value) { RefundNote = "Được tạo giúp bởi " + username; username = hdfUsernameCurrent.Value; } agentID = Convert.ToInt32(a.AgentID); string CustomerPhone = txtPhone.Text; string CustomerName = txtFullname.Text; string Nick = txtNick.Text.Trim(); string CustomerAddress = txtAddress.Text.Trim(); string Zalo = txtZalo.Text.Trim(); string Facebook = txtFacebook.Text.Trim(); if (!string.IsNullOrEmpty(CustomerPhone)) { var checkCustomer = CustomerController.GetByPhone(CustomerPhone); if (checkCustomer != null) { int custID = checkCustomer.ID; string kq = CustomerController.Update(custID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2); double totalPrice = Convert.ToDouble(hdfTotalPrice.Value); double totalQuantity = Convert.ToDouble(hdfTotalQuantity.Value); double totalRefund = Convert.ToDouble(hdfTotalRefund.Value); var agent = AgentController.GetByID(agentID); string agentName = String.Empty; if (agent != null) { agentName = agent.AgentName; } //insert ddlstatus, refundnote int status = ddlRefundStatus.SelectedValue.ToInt(); RefundNote += ". " + txtRefundsNote.Text; int rID = RefundGoodController.Insert( new tbl_RefundGoods() { AgentID = agentID, TotalPrice = totalPrice.ToString(), Status = status, CustomerID = custID, TotalQuantity = totalQuantity, TotalRefundFee = totalRefund.ToString(), CreatedDate = currentDate, CreatedBy = username, CustomerName = checkCustomer.CustomerName, CustomerPhone = checkCustomer.CustomerPhone, AgentName = agentName, RefundNote = RefundNote }); if (rID > 0) { RefundGoodModel refundModel = JsonConvert.DeserializeObject <RefundGoodModel>(hdfListProduct.Value); int t = 0; int time = 0; foreach (RefundDetailModel item in refundModel.RefundDetails) { t++; time += 20; int rdID = RefundGoodDetailController.Insert( new tbl_RefundGoodsDetails() { RefundGoodsID = rID, AgentID = agentID, OrderID = 0, ProductName = item.ProductTitle, CustomerID = custID, SKU = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU, Quantity = item.QuantityRefund, QuantityMax = item.QuantityRefund, PriceNotFeeRefund = (item.QuantityRefund * item.ReducedPrice).ToString(), ProductType = item.ProductStyle, IsCount = true, RefundType = item.ChangeType, RefundFeePerProduct = item.ChangeType == 2 ? item.FeeRefund.ToString() : "0", TotalRefundFee = item.ChangeType == 2 ? (item.FeeRefund * item.QuantityRefund).ToString() : "0", GiavonPerProduct = item.Price.ToString(), DiscountPricePerProduct = (item.Price - item.ReducedPrice).ToString(), SoldPricePerProduct = item.ReducedPrice.ToString(), TotalPriceRow = item.TotalFeeRefund.ToString(), CreatedDate = currentDate.AddMilliseconds(time), CreatedBy = username }); if (rdID > 0) { if (item.ChangeType < 3) { int typeRe = 0; string note = ""; if (item.ChangeType == 1) { note = "Đổi size đơn " + rdID; typeRe = 8; } else if (item.ChangeType == 2) { note = "Đổi sản phẩm khác đơn " + rdID; typeRe = 9; } if (item.ChangeType == 1 || item.ChangeType == 2) { StockManagerController.Insert( new tbl_StockManager { AgentID = agentID, ProductID = item.ProductStyle == 1 ? item.ProductID : 0, ProductVariableID = item.ProductVariableID, Quantity = item.QuantityRefund, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = 0, Status = typeRe, SKU = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU, CreatedDate = currentDate.AddMilliseconds(time), CreatedBy = username, MoveProID = 0, ParentID = item.ProductID, }); } } } PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ")", Page); } } } } } } }
protected void btnSave_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; int AgentID = 0; string username = Request.Cookies["usernameLoginSystem"].Value; if (!string.IsNullOrEmpty(username)) { var a = AccountController.GetByUsername(username); if (a != null) { AgentID = Convert.ToInt32(a.AgentID); string phone = hdfPhone.Value; if (!string.IsNullOrEmpty(phone)) { var cust = CustomerController.GetByPhone(phone); if (cust != null) { #region Tạo đơn hàng đổi tra int custID = cust.ID; string totalprice = hdfTotalPrice.Value; string totalquantity = hdfTotalQuantity.Value; string totalrefund = hdfTotalRefund.Value; var agent = AgentController.GetByID(AgentID); string agentName = ""; if (agent != null) { agentName = agent.AgentName; } //insert ddlstatus, refundnote int status = ddlRefundStatus.SelectedValue.ToInt(); string RefundsNote = txtRefundsNote.Text; int rID = RefundGoodController.Insert(AgentID, totalprice, status, custID, Convert.ToInt32(totalquantity), totalrefund, agentName, cust.CustomerName, cust.CustomerPhone, currentDate, username, RefundsNote); #endregion if (rID > 0) { string listString = hdfListProduct.Value; string[] items = listString.Split('|'); if (items.Length - 1 > 0) { for (int i = 0; i < items.Length - 1; i++) { #region Tạo chi tiết đơn hàng đổi tra string[] element = items[i].Split(';'); var sku = element[0]; var orderID = element[1].ToInt(0); var orderDetailID = element[2]; var ProductName = element[3]; var GiavonPerProduct = Convert.ToDouble(element[5]); var SoldPricePerProduct = Convert.ToDouble(element[6]); var DiscountPricePerProduct = Convert.ToDouble(element[7]); var quantity = Convert.ToDouble(element[10]); var quantityMax = Convert.ToDouble(element[8]); var ProductType = element[4].ToInt(1); var RefundType = element[9].ToInt(1); var RefundFeePerProduct = Convert.ToDouble(element[11]); var TotalPriceRow = element[12]; var PriceNotFeeRefund = SoldPricePerProduct * quantity; var rdTotalRefundFee = RefundFeePerProduct * quantity; int rdID = RefundGoodDetailController.Insert(rID, AgentID, orderID, ProductName, custID, sku, quantity, quantityMax, PriceNotFeeRefund.ToString(), ProductType, true, RefundType, RefundFeePerProduct.ToString(), rdTotalRefundFee.ToString(), GiavonPerProduct.ToString(), DiscountPricePerProduct.ToString(), SoldPricePerProduct.ToString(), TotalPriceRow, currentDate, username); #endregion #region Cập nhật stock if (rdID > 0) { if (RefundType < 3) { int typeRe = 0; string note = ""; if (RefundType == 1) { note = "Đổi size"; typeRe = 8; } else if (RefundType == 2) { note = "Đổi sản phẩm"; typeRe = 9; } if (ProductType == 1) { var product = ProductController.GetBySKU(sku); if (product != null) { int productID = product.ID; string ProductImageOrigin = ""; var ProductImage = ProductImageController.GetFirstByProductID(product.ID); if (ProductImage != null) { ProductImageOrigin = ProductImage.ProductImage; } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = productID, ProductVariableID = 0, Quantity = quantity, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = orderID, Status = typeRe, SKU = sku, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = productID, }); } } else { string ProductVariableName = ""; string ProductVariableValue = ""; string ProductVariable = ""; int parentID = 0; string parentSKU = ""; string ProductImageOrigin = ""; int ID = 0; var productvariable = ProductVariableController.GetBySKU(sku); if (productvariable != null) { ID = productvariable.ID; ProductImageOrigin = productvariable.Image; parentSKU = productvariable.ParentSKU; var variables = ProductVariableValueController.GetByProductVariableID(productvariable.ID); if (variables.Count > 0) { foreach (var v in variables) { ProductVariable += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|"; ProductVariableName += v.VariableName + "|"; ProductVariableValue += v.VariableValue + "|"; } } } if (!string.IsNullOrEmpty(parentSKU)) { var product = ProductController.GetBySKU(parentSKU); if (product != null) { parentID = product.ID; } } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = 0, ProductVariableID = ID, Quantity = quantity, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = orderID, Status = typeRe, SKU = sku, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID, }); } } } #endregion } RefundGoodController.updateQuantityCOGS(rID); PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ")", Page); } } } } } } }
protected void btnSave_Click(object sender, EventArgs e) { // Làm lại đơn hàng đổi trả if (!String.IsNullOrEmpty(hdRefundGoodsID.Value)) { RefundGoodDetailController.DeleteByRefundGoodsID(hdRefundGoodsID.Value.ToInt()); RefundGoodController.DeleteByID(hdRefundGoodsID.Value.ToInt()); OrderController.DeleteOrderRefund(hdRefundGoodsID.Value.ToInt()); } DateTime currentDate = DateTime.Now; int agentID = 0; string username = Request.Cookies["usernameLoginSystem"].Value; if (!string.IsNullOrEmpty(username)) { var a = AccountController.GetByUsername(username); if (a != null) { #region Lấy thông tin tao đơn đổi tra // Change user string UserHelp = ""; string redirectToUsername = ""; if (username != hdfUsernameCurrent.Value) { UserHelp = username; username = hdfUsernameCurrent.Value; redirectToUsername = hdfUsernameCurrent.Value; } agentID = Convert.ToInt32(a.AgentID); string CustomerPhone = txtPhone.Text; string CustomerName = txtFullname.Text; string Nick = txtNick.Text.Trim(); string CustomerAddress = txtAddress.Text.Trim(); string Zalo = ""; string Facebook = txtFacebook.Text.Trim(); string RefundNote = txtRefundsNote.Text; int ProvinceID = hdfProvinceID.Value.ToInt(0); int DistrictID = hdfDistrictID.Value.ToInt(0); int WardID = hdfWardID.Value.ToInt(0); #endregion if (!string.IsNullOrEmpty(CustomerPhone)) { var checkCustomer = CustomerController.GetByPhone(CustomerPhone); if (checkCustomer != null) { #region Cập nhật thông tin khách hàng int custID = checkCustomer.ID; string kq = CustomerController.Update(custID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", checkCustomer.CustomerLevelID.Value, checkCustomer.Status.Value, checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, Nick, checkCustomer.Avatar, checkCustomer.ShippingType.Value, checkCustomer.PaymentType.Value, checkCustomer.TransportCompanyID.Value, checkCustomer.TransportCompanySubID.Value, checkCustomer.CustomerPhone2, ProvinceID, DistrictID, WardID); #endregion #region Tạo đơn hàng đổi trả double totalPrice = Convert.ToDouble(hdfTotalPrice.Value); double totalRefund = Convert.ToDouble(hdfTotalRefund.Value); int OrderSaleID = hdfOrderSaleID.Value.ToInt(0); var agent = AgentController.GetByID(agentID); string agentName = String.Empty; if (agent != null) { agentName = agent.AgentName; } //insert ddlstatus, refundnote int status = ddlRefundStatus.SelectedValue.ToInt(); if (OrderSaleID != 0) { status = 2; } int rID = RefundGoodController.Insert( new tbl_RefundGoods() { AgentID = agentID, TotalPrice = totalPrice.ToString(), Status = status, CustomerID = custID, TotalRefundFee = totalRefund.ToString(), CreatedDate = currentDate, CreatedBy = username, CustomerName = checkCustomer.CustomerName, CustomerPhone = checkCustomer.CustomerPhone, AgentName = agentName, RefundNote = RefundNote, OrderSaleID = OrderSaleID, UserHelp = UserHelp }); #endregion if (rID > 0) { #region Cập nhật đơn đổi hàng vào order if (OrderSaleID != 0) { OrderController.UpdateRefund(OrderSaleID, rID, username); } #endregion #region Thực hiện tạo chi tiết đơn đổi hàng RefundGoodModel refundModel = JsonConvert.DeserializeObject <RefundGoodModel>(hdfListProduct.Value); var refundDetails = new List <tbl_RefundGoodsDetails>(); var stocks = new List <tbl_StockManager>(); int t = 0; int time = 0; foreach (RefundDetailModel item in refundModel.RefundDetails) { #region Tạo từng dòng chi tiết đổi hàng t++; time += 20; refundDetails.Add(new tbl_RefundGoodsDetails() { RefundGoodsID = rID, AgentID = agentID, OrderID = 0, ProductName = item.ProductTitle, CustomerID = custID, SKU = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU, Quantity = item.QuantityRefund, QuantityMax = item.QuantityRefund, PriceNotFeeRefund = (item.QuantityRefund * item.ReducedPrice).ToString(), ProductType = item.ProductStyle, IsCount = true, RefundType = item.ChangeType, RefundFeePerProduct = item.ChangeType == 2 ? item.FeeRefund.ToString() : "0", TotalRefundFee = item.ChangeType == 2 ? (item.FeeRefund * item.QuantityRefund).ToString() : "0", GiavonPerProduct = item.Price.ToString(), DiscountPricePerProduct = (item.Price - item.ReducedPrice).ToString(), SoldPricePerProduct = item.ReducedPrice.ToString(), TotalPriceRow = item.TotalFeeRefund.ToString(), CreatedDate = currentDate.AddMilliseconds(time), CreatedBy = username }); #endregion #region Cập nhật thông tin đổi hàng vào Stock if (item.ChangeType < 3) { int typeRe = 0; string note = ""; if (item.ChangeType == 1) { note = "Đổi size đơn " + rID; typeRe = 8; } else if (item.ChangeType == 2) { note = "Đổi sản phẩm khác đơn " + rID; typeRe = 9; } if (item.ChangeType == 1 || item.ChangeType == 2) { stocks.Add(new tbl_StockManager() { AgentID = agentID, ProductID = item.ProductStyle == 1 ? item.ProductID : 0, ProductVariableID = item.ProductVariableID, Quantity = item.QuantityRefund, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = 0, Status = typeRe, SKU = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU, CreatedDate = currentDate.AddMilliseconds(time), CreatedBy = username, MoveProID = 0, ParentID = item.ProductID, }); } } #endregion } refundDetails = RefundGoodDetailController.Insert(refundDetails); RefundGoodController.updateQuantityCOGS(rID); StockManagerController.Insert(stocks); #endregion PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ",'" + redirectToUsername + "')", Page); } } } } } }