Esempio n. 1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                RefundGoodDetailController.DeleteByRefundGoodsID(_refundGood.RefundGoodsID);
                RefundGoodController.DeleteByID(_refundGood.RefundGoodsID);
                int OrderSaleID = OrderController.DeleteOrderRefund(_refundGood.RefundGoodsID);
                if (OrderSaleID > 0)
                {
                    _refundGood.OrderSaleID = OrderSaleID;
                }

                foreach (var product in _refundGood.RefundDetails)
                {
                    if (!string.IsNullOrEmpty(product.ChildSKU))
                    {
                        var    ProductVariable = ProductVariableValueController.GetByProductVariableSKU(product.ChildSKU);
                        string VariableValue   = "";
                        if (ProductVariable.Count > 0)
                        {
                            foreach (var v in ProductVariable)
                            {
                                VariableValue += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|";
                            }
                        }
                        product.VariableValue = VariableValue;
                    }

                    if (product.ChangeType != 3) // Change product error
                    {
                        StockManagerController.Insert(new tbl_StockManager()
                        {
                            AgentID           = 1,
                            ProductID         = product.ProductStyle == 1 ? product.ProductID : 0,
                            ProductVariableID = product.ProductVariableID,
                            Quantity          = product.QuantityRefund,
                            QuantityCurrent   = 0,
                            Type        = 1,
                            NoteID      = "Xuất kho do làm lại đơn hàng đổi trả",
                            OrderID     = product.OrderID,
                            Status      = 11,
                            SKU         = product.ProductStyle == 1 ? product.ParentSKU : product.ChildSKU,
                            CreatedDate = DateTime.Now,
                            CreatedBy   = _refundGood.CreateBy,
                            MoveProID   = 0,
                            ParentID    = product.ProductID,
                        });
                    }
                }

                HttpContext.Current.Items.Add("xem-don-hang-doi-tra", JsonConvert.SerializeObject(_refundGood));
                Server.Transfer("tao-don-hang-doi-tra.aspx");
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void printItemList(ref int ID, ref double TotalQuantity, ref double TotalOrder, ref string Print)
        {
            var orderdetails = RefundGoodDetailController.GetByRefundGoodsID(ID);

            if (orderdetails.Count > 0)
            {
                foreach (var item in orderdetails)
                {
                    TotalQuantity += Convert.ToDouble(item.Quantity);

                    int    ProductType = Convert.ToInt32(item.ProductType);
                    double ItemPrice   = Convert.ToDouble(item.SoldPricePerProduct);
                    string SKU         = item.SKU;
                    string ProductName = "";
                    int    SubTotal    = (Convert.ToInt32(ItemPrice) - Convert.ToInt32(item.RefundFeePerProduct)) * Convert.ToInt32(item.Quantity);

                    Print += "<tr>";
                    if (ProductType == 1)
                    {
                        var product = ProductController.GetBySKU(SKU);
                        if (product != null)
                        {
                            ProductName = product.ProductTitle;
                            Print      += "<td colspan='4'><strong>" + SKU + "</strong> - " + PJUtils.Truncate(ProductName, 27) + "</td>";
                        }
                    }
                    else
                    {
                        var productvariable = ProductVariableController.GetBySKU(SKU);
                        if (productvariable != null)
                        {
                            var parent_product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                            if (parent_product != null)
                            {
                                ProductName = parent_product.ProductTitle;
                            }
                            Print += "<td colspan='4'><strong>" + SKU + "</strong> - " + PJUtils.Truncate(ProductName, 27) + "</td>";
                        }
                    }
                    Print += "</tr>";
                    Print += "<tr>";
                    Print += "<td>" + item.Quantity + "</td>";
                    Print += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>";
                    Print += "<td>" + string.Format("{0:N0}", Convert.ToDouble(item.RefundFeePerProduct)) + "</td>";
                    Print += "<td>" + string.Format("{0:N0}", SubTotal) + "</td>";
                    Print += "</tr>";

                    TotalOrder += SubTotal;
                }
            }
        }
Esempio n. 3
0
        public void LoadData()
        {
            string username = Request.Cookies["userLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID = Convert.ToInt32(acc.AgentID);
                int ID      = Request.QueryString["id"].ToInt(0);
                if (ID > 0)
                {
                    ViewState["ID"] = ID;
                    var r = RefundGoodController.GetByIDAndAgentID(ID, AgentID);
                    if (r == null)
                    {
                        PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy đơn hàng " + ID, "e", true, "/danh-sach-don-tra-hang", Page);
                    }
                    else
                    {
                        if (acc.RoleID != 0)
                        {
                            if (r.CreatedBy != acc.Username)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này không phải của bạn", "e", true, "/danh-sach-don-tra-hang", Page);
                            }
                        }
                        ltrOrderID.Text     = ID.ToString();
                        ltrCreateBy.Text    = r.CreatedBy;
                        ltrCreateDate.Text  = r.CreatedDate.ToString();
                        ltrOrderStatus.Text = PJUtils.RefundStatus(Convert.ToInt32(r.Status));
                        if (r.OrderSaleID > 0)
                        {
                            ltrOrderSaleID.Text = "<td><a class=\"customer-name-link\" target=\"_blank\" title=\"Bấm vào xem đơn hàng trừ tiền\" href=\"/thong-tin-don-hang?id=" + r.OrderSaleID + "\">" + r.OrderSaleID + " (Xem đơn)</a>";
                        }
                        else
                        {
                            ltrOrderSaleID.Text = "";
                        }
                        ltrOrderQuantity.Text   = r.TotalQuantity.ToString();
                        ltrOrderTotalPrice.Text = string.Format("{0:N0}", (Convert.ToDouble(r.TotalPrice)));
                        ltrTotalRefundFee.Text  = string.Format("{0:N0}", (Convert.ToDouble(r.TotalRefundFee)));
                        ltrRefundNote.Text      = r.RefundNote;

                        ltrInfo.Text += "<div class=\"row\">";
                        ltrInfo.Text += "<div class=\"col-md-6\">";
                        ltrInfo.Text += "<div class=\"form-group\">";
                        ltrInfo.Text += "<label>Họ tên</label>";
                        ltrInfo.Text += "<span class=\"form-control input-disabled\">" + r.CustomerName + "</span>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "<div class=\"col-md-6\">";
                        ltrInfo.Text += "<div class=\"form-group\">";
                        ltrInfo.Text += "<label>Điện thoại</label>";
                        ltrInfo.Text += "<span class=\"form-control input-disabled\">" + r.CustomerPhone + "</span>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "</div>";

                        var cus = CustomerController.GetByID(r.CustomerID.Value);
                        if (cus != null)
                        {
                            ltrInfo.Text += "<div class=\"row\">";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Nick đặt hàng</label>";
                            ltrInfo.Text += "<span class=\"form-control input-disabled\">" + cus.Nick + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Địa chỉ</label>";
                            ltrInfo.Text += "<span class=\"form-control input-disabled\">" + cus.CustomerAddress + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";

                            ltrInfo.Text += "<div class=\"row\">";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Zalo</label>";
                            ltrInfo.Text += "<span class=\"form-control input-disabled\">" + cus.Zalo + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Facebook</label>";
                            ltrInfo.Text += "<span class=\"form-control input-disabled\">" + cus.Facebook + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "<div class=\"row\">";
                            ltrInfo.Text += "    <div class=\"col-md-12 view-detail\">";
                            ltrInfo.Text += "    	<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"viewCustomerDetail('"+ cus.ID + "')\"><i class=\"fa fa-address-card-o\" aria-hidden=\"true\"></i> Xem chi tiết</a>";
                            ltrInfo.Text += "    </div>";
                            ltrInfo.Text += "</div>";
                        }

                        ltrTotal.Text    = string.Format("{0:N0}", Convert.ToDouble(r.TotalPrice));
                        ltrQuantity.Text = string.Format("{0:N0}", Convert.ToDouble(r.TotalQuantity));
                        ltrRefund.Text   = string.Format("{0:N0}", Convert.ToDouble(r.TotalRefundFee));

                        // get info tranfor page tao-don-hang-doi-tra.aspx
                        _refundGood.RefundGoodsID    = ID;
                        _refundGood.CustomerName     = r.CustomerName;
                        _refundGood.CustomerPhone    = r.CustomerPhone;
                        _refundGood.CustomerNick     = cus != null? cus.Nick : String.Empty;
                        _refundGood.CustomerAddress  = cus != null ? cus.CustomerAddress : String.Empty;
                        _refundGood.CustomerZalo     = cus != null ? cus.Zalo : String.Empty;
                        _refundGood.CustomerFacebook = cus != null ? cus.Facebook : String.Empty;
                        _refundGood.RefundDetails    = RefundGoodDetailController.GetInfoShowRefundDetail(ID);
                        _refundGood.TotalPrice       = Convert.ToDouble(r.TotalPrice);
                        _refundGood.TotalQuantity    = Convert.ToDouble(r.TotalQuantity);
                        _refundGood.TotalFreeRefund  = Convert.ToDouble(r.TotalRefundFee);
                        _refundGood.Status           = r.Status.Value;
                        _refundGood.Note             = txtRefundsNote.Text;
                        _refundGood.CreateBy         = r.CreatedBy;

                        var rds = RefundGoodDetailController.GetByRefundGoodsID(ID);

                        var product = _refundGood.RefundDetails
                                      .Join(
                            rds,
                            p1 => new {
                            RefundGoodsID  = p1.RefundGoodsID,
                            RefundDetailID = p1.RefundDetailID
                        },
                            p2 => new {
                            RefundGoodsID  = p2.RefundGoodsID.Value,
                            RefundDetailID = p2.ID
                        },
                            (p1, p2) => new { p1, p2 })
                                      .Select(x => new {
                            SKU                     = x.p2.SKU,
                            OrderID                 = x.p2.OrderID,
                            ProductName             = x.p2.ProductName,
                            ProductType             = x.p2.ProductType,
                            GiavonPerProduct        = x.p2.GiavonPerProduct,
                            SoldPricePerProduct     = x.p2.SoldPricePerProduct,
                            DiscountPricePerProduct = x.p2.DiscountPricePerProduct,
                            Quantity                = x.p2.Quantity,
                            QuantityMax             = x.p2.QuantityMax,
                            RefundType              = x.p2.RefundType,
                            RefundFeePerProduct     = x.p2.RefundFeePerProduct,
                            TotalPriceRow           = x.p2.TotalPriceRow,
                            ProductImage            = x.p1.ProductImage
                        })
                                      .ToList();

                        if (product.Count > 0)
                        {
                            string html = "";
                            int    t    = 0;
                            foreach (var item in product)
                            {
                                var    variables = ProductVariableValueController.GetByProductVariableSKU(item.SKU);
                                string variable  = "";
                                if (variables.Count > 0)
                                {
                                    variable += "<br><br>";
                                    foreach (var v in variables)
                                    {
                                        variable += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "<br>";
                                    }
                                }
                                t++;
                                html += "<tr ondblclick=\"clickrow($(this))\" class=\"product-result\" data-sku=\"" + item.SKU + "\" data-orderID=\"" + item.OrderID
                                        + "\" data-ProductName=\"" + item.ProductName
                                        + "\" data-ProductType=\"" + item.ProductType + "\" data-Giagoc=\"" + item.GiavonPerProduct
                                        + "\" data-Giadaban=\"" + item.SoldPricePerProduct
                                        + "\" data-TienGiam=\"" + item.DiscountPricePerProduct
                                        + "\" data-Soluongtoida=\"" + item.QuantityMax + "\" data-RefundFee=\"" + item.RefundFeePerProduct + "\"  >";
                                html += "   <td>" + t + "</td>";
                                html += "   <td><img src='" + item.ProductImage + "'></td>";
                                html += "   <td>" + item.ProductName + variable + "</td>";
                                html += "   <td>" + item.SKU + "</td>";
                                html += "   <td class=\"giagoc\" data-giagoc=\"" + item.GiavonPerProduct + "\">" + string.Format("{0:N0}", Convert.ToDouble(item.GiavonPerProduct)) + "</td>";
                                html += "   <td class=\"giadaban\" data-giadaban=\"" + item.SoldPricePerProduct + "\"><strong>" + string.Format("{0:N0}", Convert.ToDouble(item.SoldPricePerProduct)) + "</strong><br>(CK: " + string.Format("{0:N0}", Convert.ToDouble(item.DiscountPricePerProduct)) + ")</td>";
                                html += "   <td class=\"slcandoi\">" + item.Quantity + "</td>";
                                html += "   <td>";
                                int    refundType     = Convert.ToInt32(item.RefundType);
                                string refuntTypeName = "";
                                if (item.RefundType == 1)
                                {
                                    refuntTypeName = "Đổi size";
                                }
                                else if (item.RefundType == 2)
                                {
                                    refuntTypeName = "Đổi sản phẩm khác";
                                }
                                else
                                {
                                    refuntTypeName = "Đổi hàng lỗi";
                                }
                                html += refuntTypeName;
                                html += "    </td>";
                                html += "   <td class=\"phidoihang\">" + string.Format("{0:N0}", Convert.ToDouble(item.RefundFeePerProduct)) + "</td>";
                                html += "   <td class=\"thanhtien\">" + string.Format("{0:N0}", Convert.ToDouble(item.TotalPriceRow)) + "</td>";
                                html += "</tr>";
                            }

                            ddlRefundStatus.SelectedValue = r.Status.ToString();
                            txtRefundsNote.Text           = r.RefundNote;
                            ltrList.Text = html;
                        }
                        ltrPrint.Text  = "<a href=\"/print-invoice-return?id=" + ID + "\" target=\"_blank\" class=\"btn primary-btn fw-btn not-fullwidth\"><i class=\"fa fa-print\" aria-hidden=\"true\"></i> In hóa đơn</a>";
                        ltrPrint.Text += "<a href=\"/print-return-order-image?id=" + ID + "\" target=\"_blank\" class=\"btn primary-btn fw-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-picture-o\" aria-hidden=\"true\"></i> Lấy ảnh đơn hàng</a>";
                    }
                }
            }
        }
Esempio n. 4
0
        public static string checkphone(string phonefullname)
        {
            RefundCust rf       = new RefundCust();
            int        AgentID  = 0;
            string     username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;

            if (!string.IsNullOrEmpty(username))
            {
                var a = AccountController.GetByUsername(username);
                if (a != null)
                {
                    AgentID = Convert.ToInt32(a.AgentID);
                }
            }
            var customer = CustomerController.GetByPhone(phonefullname);

            if (customer != null)
            {
                rf.CustName    = customer.CustomerName;
                rf.CustPhone   = customer.CustomerPhone;
                rf.CustZalo    = customer.Zalo;
                rf.CustFB      = customer.Facebook;
                rf.CustAddress = customer.CustomerAddress;


                int    custID    = customer.ID;
                double FeeRefund = 0;
                double NumOfDateToChangeProduct = 0;
                double NumOfProductCanChange    = 0;
                var    config = ConfigController.GetByTop1();
                if (config != null)
                {
                    FeeRefund = Convert.ToDouble(config.FeeChangeProduct);
                    NumOfDateToChangeProduct = Convert.ToDouble(config.NumOfDateToChangeProduct);
                    NumOfProductCanChange    = Convert.ToDouble(config.NumOfProductCanChange);
                }
                var d = DiscountCustomerController.getbyCustID(custID);
                if (d.Count > 0)
                {
                    FeeRefund = d[0].FeeRefund;
                    NumOfDateToChangeProduct = d[0].NumOfDateToChangeProduct;
                    NumOfProductCanChange    = d[0].NumOfProductCanChange;
                }

                DateTime toDate   = DateTime.Now.Date;
                var      fromDate = toDate.AddDays(-NumOfDateToChangeProduct);

                double totalProductRefund = 0;
                var    refundList         = RefundGoodController.GetByAgentIDCustomerIDFromDateToDate(AgentID, custID, fromDate, toDate.AddDays(1));
                if (refundList.Count > 0)
                {
                    foreach (var item in refundList)
                    {
                        var rfD = RefundGoodDetailController.GetByRefundGoodsID(item.ID);
                        if (rfD.Count > 0)
                        {
                            foreach (var fd in rfD)
                            {
                                totalProductRefund += Convert.ToDouble(fd.Quantity);
                            }
                        }
                    }
                }
                double leftCanchange = NumOfProductCanChange - totalProductRefund;
                if (leftCanchange > 0)
                {
                    rf.CustleftCanchange = leftCanchange.ToString();

                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return(serializer.Serialize(rf));
                }
                else
                {
                    rf.CustleftCanchange = "full";
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return(serializer.Serialize(rf));
                }
            }
            else
            {
                rf.CustleftCanchange = "nocustomer";
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return(serializer.Serialize(rf));
            }
        }
Esempio n. 5
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

            if (ID > 0)
            {
                var order = RefundGoodController.GetByID(ID);

                if (order != null)
                {
                    string error = "";
                    string Print = "";

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;

                    var orderdetails   = RefundGoodDetailController.GetByRefundGoodsID(ID);
                    var numberOfOrders = RefundGoodController.GetByCustomerID(Convert.ToInt32(order.CustomerID));

                    if (orderdetails.Count > 0)
                    {
                        printItemList(ref ID, ref TotalQuantity, ref TotalOrder, ref Print);

                        string productPrint = "";
                        string shtml        = "";

                        productPrint += "<div class='body'>";
                        productPrint += "<div class='table-1'>";
                        productPrint += "<h1>ĐƠN ĐỔI HÀNG #" + order.ID + "</h1>";

                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class='col-left' />";
                        productPrint += "<col class='col-right' />";
                        productPrint += "</colgroup>";
                        productPrint += "<tbody>";
                        productPrint += "<tr>";
                        productPrint += "<td>Khách hàng</td>";
                        productPrint += "<td>" + order.CustomerName + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Điện thoại</td>";
                        productPrint += "<td>" + order.CustomerPhone + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Ngày tạo</td>";
                        string date = string.Format("{0:dd/MM/yyyy HH:mm}", order.CreatedDate);
                        productPrint += "<td>" + date + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Nhân viên</td>";
                        productPrint += "<td>" + order.CreatedBy + "</td>";
                        productPrint += "</tr>";

                        productPrint += "<tr>";
                        productPrint += "<td>Trạng thái</td>";
                        if (order.Status == 1)
                        {
                            productPrint += "<td>Chưa trừ tiền</td>";
                        }
                        else
                        {
                            productPrint += "<td>Đã trừ tiền</td>";
                        }
                        productPrint += "</tr>";

                        if (!string.IsNullOrEmpty(order.RefundNote))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Ghi chú</td>";
                            productPrint += "<td>" + order.RefundNote + "</td>";
                            productPrint += "</tr>";
                        }

                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";

                        productPrint += "<div class='table-2 print-invoice-return'>";
                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class='soluong' />";
                        productPrint += "<col class='gia' />";
                        productPrint += "<col class='gia' />";
                        productPrint += "<col class='tong' />";
                        productPrint += "</colgroup>";
                        productPrint += "<thead>";
                        productPrint += "<th>SL</th>";
                        productPrint += "<th>Giá</th>";
                        productPrint += "<th>Phí</th>";
                        productPrint += "<th>Tổng</th>";
                        productPrint += "</thead>";
                        productPrint += "<tbody>";
                        productPrint += Print;
                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";
                        productPrint += "<div class='table-3'>";
                        productPrint += "<table>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan='2'>Số lượng</td>";
                        productPrint += "<td>" + TotalQuantity + "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                        productPrint += "</tr>";

                        if (TotalOrder != Convert.ToDouble(order.TotalPrice))
                        {
                            error += "Đơn hàng tính sai tổng tiền";
                        }

                        productPrint += "<tr>";
                        productPrint += "<td colspan='2'>Phí đổi hàng</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.TotalRefundFee)) + "&nbsp;</td>";
                        productPrint += "</tr>";

                        productPrint += "<tr>";
                        productPrint += "<td class='strong' colspan='2'>TỔNG TIỀN (đã trừ phí)</td>";
                        productPrint += "<td class='strong'>" + string.Format("{0:N0}", TotalOrder) + "&nbsp;</td>";
                        productPrint += "</tr>";

                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";
                        productPrint += "</div>";

                        shtml += "<div class='hoadon'>";
                        shtml += "<div class='all'>";

                        shtml += productPrint;

                        if (numberOfOrders.Count < 4)
                        {
                            shtml += "<div class='footer'>";
                            shtml += "<p>Quý khách lưu ý:</p>";
                            shtml += "<p>- Miễn phí đổi hàng lỗi hoặc đổi size/màu cùng mẫu.</p>";
                            shtml += "<p>- Tính phí đổi hàng tồn hoặc đổi sang mẫu khác.</p>";
                            shtml += "<p>- ANN chỉ hoàn lại tiền mặt khi tổng tiền dưới 50.000.</p>";
                            shtml += "<p>- Đơn trên 50.000 được trừ vào đơn mua hàng kế tiếp.</p>";
                            shtml += "<p>- Giá trên này là giá bán ra đã trừ chiết khấu nếu có.</p>";
                            shtml += "</div>";
                        }

                        shtml += "</div>";
                        shtml += "</div>";

                        if (error != "")
                        {
                            ltrPrintInvoice.Text = "Xảy ra lỗi: " + error;
                            ltrPrintEnable.Text  = "";
                        }
                        else
                        {
                            ltrPrintInvoice.Text = shtml;
                            ltrPrintEnable.Text  = "<div class='print-enable true'></div>";
                        }
                    }
                }
                else
                {
                    ltrPrintInvoice.Text = "Không tìm thấy đơn hàng " + ID;
                }
            }
            else
            {
                ltrPrintInvoice.Text = "Xảy ra lỗi!!!";
            }
        }
Esempio n. 7
0
        public void LoadData()
        {
            string fromdate = "";
            string todate   = "";

            if (Request.QueryString["fromdate"] != null)
            {
                fromdate = Request.QueryString["fromdate"];
            }
            if (Request.QueryString["todate"] != null)
            {
                todate = Request.QueryString["todate"];
            }
            DateTime now   = DateTime.Now;
            var      start = new DateTime(now.Year, now.Month, 1, 0, 0, 0);

            if (!string.IsNullOrEmpty(fromdate))
            {
                rFromDate.SelectedDate = Convert.ToDateTime(fromdate);
            }
            else
            {
                fromdate = start.ToString();
            }
            if (!string.IsNullOrEmpty(todate))
            {
                rToDate.SelectedDate = Convert.ToDateTime(todate);
            }

            var refund = RefundGoodController.TotalRefund(fromdate, todate);

            if (refund != null)
            {
                int total = 0;
                int kt    = 0;
                int ct    = 0;
                foreach (var item in refund)
                {
                    var refundg = RefundGoodDetailController.GetByRefundGoodsID(item.ID);
                    if (refundg != null)
                    {
                        foreach (var temp in refundg)
                        {
                            total += Convert.ToInt32(temp.Quantity);
                            if (temp.RefundType == 2)
                            {
                                ct += Convert.ToInt32(temp.Quantity);
                            }
                            else
                            {
                                kt += Convert.ToInt32(temp.Quantity);
                            }
                        }
                    }
                }
                ltrList.Text += "<tr>";
                ltrList.Text += "<td style=\"text-align:center;\">" + total + "</td>";
                ltrList.Text += "<td>" + ct + "</td>";
                ltrList.Text += "<td>" + kt + "</td>";


                ltrList.Text += "</tr>";
            }
        }
Esempio n. 8
0
        public static string getOrder(int ID)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string username = HttpContext.Current.Request.Cookies["userLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID = Convert.ToInt32(acc.AgentID);
                var agent   = AgentController.GetByID(AgentID);
                if (agent != null)
                {
                }
                //List<GetOutOrder> go = new List<GetOutOrder>();
                GetOutRefundOrder getOrder = new GetOutRefundOrder();
                var refund = RefundGoodController.GetByID(ID);
                if (refund != null)
                {
                    var refunddetail = RefundGoodDetailController.GetByRefundGoodsID(refund.ID);
                    if (refunddetail != null)
                    {
                        //table 1
                        getOrder.ID            = refund.ID;
                        getOrder.CustomerName  = refund.CustomerName;
                        getOrder.CustomerPhone = refund.CustomerPhone;
                        if (refund.Status == 1)
                        {
                            getOrder.Status = "Chưa trừ tiền";
                        }
                        if (refund.Status == 2)
                        {
                            getOrder.Status = "Đã trừ tiền";
                        }
                        getOrder.CreatedBy  = refund.CreatedBy;
                        getOrder.CreateDate = string.Format("{0:dd/MM/yyyy}", refund.CreatedDate);


                        getOrder.ListAgent += agent.AgentAddress + "|";
                        getOrder.ListAgent += agent.AgentPhone;


                        for (int j = 0; j < refunddetail.Count(); j++)
                        {
                            getOrder.ListProduct += refunddetail[j].SKU + ";" + refunddetail[j].ProductName + ";";
                            var    productvalue = ProductVariableValueController.GetByProductVariableSKU(refunddetail[j].SKU);
                            string value        = "";
                            if (productvalue != null)
                            {
                                foreach (var item in productvalue)
                                {
                                    value += item.VariableName + ":" + item.VariableValue + "|";
                                }
                            }
                            getOrder.ListProduct += value + ";" + refunddetail[j].Quantity + ";" + refunddetail[j].SoldPricePerProduct + ";" + refunddetail[j].RefundFeePerProduct + ";" + refunddetail[j].TotalPriceRow + "*";
                        }

                        getOrder.TotalQuantity    = Convert.ToInt32(refund.TotalQuantity);
                        getOrder.TotalPrice       = Convert.ToInt32(refund.TotalPrice);
                        getOrder.TotalRefundPrice = Convert.ToInt32(refund.TotalRefundFee);
                    }
                }

                return(serializer.Serialize(getOrder));
            }
            return(serializer.Serialize(null));
        }
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

            if (ID > 0)
            {
                var order = RefundGoodController.GetByID(ID);

                if (order != null)
                {
                    string error = "";
                    string Print = "";

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;
                    double TotalFee      = 0;
                    var    orderdetails  = RefundGoodDetailController.GetByRefundGoodsID(ID);

                    if (orderdetails.Count > 0)
                    {
                        printItemList(ref ID, ref TotalQuantity, ref TotalOrder, ref Print, ref TotalFee);

                        string productPrint = "";
                        string shtml        = "";

                        productPrint += "<div class=\"body\">";
                        productPrint += "<div class=\"table-1\">";
                        productPrint += "<h1>ĐƠN HÀNG ĐỔI TRẢ #" + order.ID + "</h1>";
                        productPrint += "<div class=\"note\">";
                        productPrint += "<p>- Miễn phí đổi size hoặc đổi hàng lỗi (cùng mẫu và cùng màu như lúc đầu).</p>";
                        productPrint += "<p>- Tính phí 15.000đ/cái nếu đổi sang sản phẩm khác bất kỳ.</p>";
                        productPrint += "<p>- Giá đã bán nếu nhỏ hơn giá niêm yết là do lúc bán ra có trừ chiết khấu.</p>";
                        productPrint += "<p>- Chúng tôi chỉ đổi hàng mà không hoàn tiền đơn hàng trả.</p>";
                        productPrint += "<p>- Đơn hàng đổi trả sẽ được trừ tiền vào đơn hàng mua sau đó.</p>";
                        productPrint += "<p>- Lưu ý hình ảnh sản phẩm trên đơn hàng có thể hiển thị không đúng.</p>";
                        productPrint += "<p>- Nếu có sai sót, quý khách có thể gọi điện thoại để thông báo cho nhân viên.</p>";
                        productPrint += "</div>";
                        productPrint += "<table>";
                        productPrint += "<colgroup >";
                        productPrint += "<col class=\"col-left\"/>";
                        productPrint += "<col class=\"col-right\"/>";
                        productPrint += "</colgroup>";
                        productPrint += "<tbody>";
                        productPrint += "<tr>";
                        productPrint += "<td>Khách hàng</td>";
                        productPrint += "<td class=\"customer-name\">" + order.CustomerName + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Điện thoại</td>";
                        productPrint += "<td>" + order.CustomerPhone + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Ngày tạo</td>";
                        string date = string.Format("{0:dd/MM/yyyy HH:mm}", order.CreatedDate);
                        productPrint += "<td>" + date + "</td>";
                        productPrint += "</tr>";


                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Nhân viên</td>";
                        productPrint += "<td>" + order.CreatedBy + "</td>";
                        productPrint += "</tr>";

                        if (!string.IsNullOrEmpty(order.RefundNote))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Ghi chú</td>";
                            productPrint += "<td>" + order.RefundNote + "</td>";
                            productPrint += "</tr>";
                        }

                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";
                        productPrint += "<div class=\"table-2\">";
                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class=\"order-item\" />";
                        productPrint += "<col class=\"image\" />";
                        productPrint += "<col class=\"name\" />";
                        productPrint += "<col class=\"quantity\" />";
                        productPrint += "<col class=\"price\" />";
                        productPrint += "<col class=\"sold-price\" />";
                        productPrint += "<col class=\"fee\" />";
                        productPrint += "<col class=\"subtotal\"/>";
                        productPrint += "</colgroup>";
                        productPrint += "<thead>";
                        productPrint += "<th>#</th>";
                        productPrint += "<th>Hình ảnh</th>";
                        productPrint += "<th>Sản phẩm</th>";
                        productPrint += "<th>SL</th>";
                        productPrint += "<th>Giá niêm yết</th>";
                        productPrint += "<th>Giá đã bán</th>";
                        productPrint += "<th>Phí đổi hàng</th>";
                        productPrint += "<th>Tổng</th>";
                        productPrint += "</thead>";
                        productPrint += "<tbody>";
                        productPrint += Print;
                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"7\" class=\"align-right\">Số lượng</td>";
                        productPrint += "<td>" + TotalQuantity + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"7\" class=\"align-right\">Thành tiền</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<td colspan=\"7\" class=\"align-right\">Phí đổi hàng</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", TotalFee) + "</td>";
                        productPrint += "</tr>";

                        double TotalPrice = TotalOrder;

                        if (TotalPrice != Convert.ToDouble(order.TotalPrice))
                        {
                            error += "Đơn hàng tính sai tổng tiền";
                        }

                        productPrint += "<tr>";
                        productPrint += "<td class=\"strong align-right\" colspan=\"7\">TỔNG CỘNG (Đã trừ phí đổi hàng)</td>";
                        productPrint += "<td class=\"strong\">" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";


                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";
                        productPrint += "</div>";

                        string dateOrder = string.Format("{0:dd/MM/yyyy HH:mm}", order.CreatedDate);

                        shtml += "<div class=\"print-order-image\">";
                        shtml += "<div class=\"all print print-0\">";



                        shtml += "<div class=\"head\">";
                        string address = "";
                        string phone   = "";
                        var    agent   = AgentController.GetByID(Convert.ToInt32(order.AgentID));
                        if (agent != null)
                        {
                            address = agent.AgentAddress;
                            phone   = agent.AgentPhone;
                        }
                        shtml += "<div class=\"logo\"><img src=\"App_Themes/Ann/image/logo.png\" /></div>";
                        shtml += "<div class=\"info\">";

                        shtml += "<div class=\"ct\">";
                        shtml += "<div class=\"ct-title\"></div>";
                        shtml += "<div class=\"ct-detail\"> " + address + "</div>";
                        shtml += "</div>";

                        shtml += "<div class=\"ct\">";
                        shtml += "<div class=\"ct-title\"> </div>";
                        shtml += "<div class=\"ct-detail\"> " + phone + "</div>";
                        shtml += "</div>";

                        shtml += "</div>";
                        shtml += "</div>";



                        shtml += productPrint;

                        shtml += "</div>";
                        shtml += "</div>";

                        if (error != "")
                        {
                            ltrPrintInvoice.Text = "Xảy ra lỗi: " + error;
                        }
                        else
                        {
                            ltrPrintInvoice.Text = shtml;
                        }
                    }
                }
                else
                {
                    ltrPrintInvoice.Text = "Không tìm thấy đơn hàng " + ID;
                }
            }
            else
            {
                ltrPrintInvoice.Text = "Xảy ra lỗi!!!";
            }
        }
        public void printItemList(ref int ID, ref double TotalQuantity, ref double TotalOrder, ref string Print, ref double TotalFee)
        {
            var orderdetails = RefundGoodDetailController.GetByRefundGoodsID(ID);

            if (orderdetails.Count > 0)
            {
                int t     = 0;
                int print = 1;
                foreach (var item in orderdetails)
                {
                    TotalQuantity += Convert.ToDouble(item.Quantity);

                    int    ProductType  = Convert.ToInt32(item.ProductType);
                    double ItemPrice    = Convert.ToDouble(item.GiavonPerProduct);
                    double SoldPrice    = Convert.ToDouble(item.SoldPricePerProduct);
                    double RefundFee    = Convert.ToDouble(item.RefundFeePerProduct);
                    string SKU          = item.SKU;
                    string ProductName  = "";
                    string ProductImage = "/App_Themes/Ann/image/placeholder.png";
                    int    SubTotal     = (Convert.ToInt32(SoldPrice) - Convert.ToInt32(item.RefundFeePerProduct)) * Convert.ToInt32(item.Quantity);

                    t++;
                    Print += "<tr>";
                    Print += "<td>" + t + "</td>";

                    if (ProductType == 1)
                    {
                        var product = ProductController.GetBySKU(SKU);
                        if (product != null)
                        {
                            ProductName = product.ProductTitle;
                            if (!string.IsNullOrEmpty(product.ProductImage))
                            {
                                ProductImage = product.ProductImage;
                            }
                            Print += "<td><image src=\"" + ProductImage + "\" /></td> ";
                            Print += "<td><strong>" + SKU + "</strong> - " + ProductName + "</td> ";
                        }
                    }
                    else
                    {
                        var productvariable = ProductVariableController.GetBySKU(SKU);
                        if (productvariable != null)
                        {
                            var parent_product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                            if (parent_product != null)
                            {
                                ProductName = parent_product.ProductTitle;

                                if (string.IsNullOrEmpty(productvariable.Image))
                                {
                                    ProductImage = parent_product.ProductImage;
                                }
                                else
                                {
                                    ProductImage = productvariable.Image;
                                }
                            }

                            Print += "<td><image src=\"" + ProductImage + "\" /></td>";
                            Print += "<td><p><strong>" + SKU + "</strong> - " + ProductName + "</p></td> ";
                        }
                    }

                    Print      += "<td>" + item.Quantity + "</td>";
                    Print      += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>";
                    Print      += "<td>" + string.Format("{0:N0}", SoldPrice) + "</td>";
                    Print      += "<td>" + string.Format("{0:N0}", RefundFee) + "</td>";
                    Print      += "<td>" + string.Format("{0:N0}", SubTotal) + "</td>";
                    Print      += "</tr>";
                    TotalFee   += Convert.ToInt32(item.RefundFeePerProduct) * Convert.ToInt32(item.Quantity);
                    TotalOrder += SubTotal;

                    if (t % 10 == 0)
                    {
                        if (t == print * 10)
                        {
                            continue;
                        }
                        Print += "</tbody>";
                        Print += "</table>";
                        Print += "</div>";
                        Print += "</div>";
                        Print += "</div>";
                        Print += "</div>";

                        Print += "<div class=\"print-order-image\">";
                        Print += "<div class=\"all print print-" + print + "\">";
                        Print += "<div class=\"body\">";
                        Print += "<div class=\"table-2\">";
                        Print += "<table>";
                        Print += "<colgroup>";
                        Print += "<col class=\"order-item\" />";
                        Print += "<col class=\"image\" />";
                        Print += "<col class=\"name\" />";
                        Print += "<col class=\"quantity\" />";
                        Print += "<col class=\"price\" />";
                        Print += "<col class=\"sold-price\" />";
                        Print += "<col class=\"fee\" />";
                        Print += "<col class=\"subtotal\"/>";
                        Print += "</colgroup>";
                        Print += "<thead>";
                        Print += "<th>#</th>";
                        Print += "<th>Hình ảnh</th>";
                        Print += "<th>Sản phẩm</th>";
                        Print += "<th>SL</th>";
                        Print += "<th>Giá niêm yết</th>";
                        Print += "<th>Giá đã bán</th>";
                        Print += "<th>Phí đổi hàng</th>";
                        Print += "<th>Tổng</th>";
                        Print += "</thead>";
                        Print += "<tbody>";
                        print++;
                    }
                }
            }
        }
Esempio n. 11
0
        public void LoadData()
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID = Convert.ToInt32(acc.AgentID);
                int ID      = Request.QueryString["id"].ToInt(0);
                if (ID > 0)
                {
                    ViewState["ID"] = ID;
                    var r = RefundGoodController.GetByIDAndAgentID(ID, AgentID);
                    if (r != null)
                    {
                        ltrOrderID.Text         = ID.ToString();
                        ltrCreateBy.Text        = r.CreatedBy;
                        ltrCreateDate.Text      = r.CreatedDate.ToString();
                        ltrOrderStatus.Text     = PJUtils.RefundStatus(Convert.ToInt32(r.Status));
                        ltrOrderQuantity.Text   = r.TotalQuantity.ToString();
                        ltrOrderTotalPrice.Text = string.Format("{0:N0}", (Convert.ToDouble(r.TotalPrice)));
                        ltrTotalRefundFee.Text  = r.TotalRefundFee;

                        ltrInfo.Text += "<div class=\"row\">";
                        ltrInfo.Text += "<div class=\"col-md-6\">";
                        ltrInfo.Text += "<div class=\"form-group\">";
                        ltrInfo.Text += "<label>Họ tên</label>";
                        ltrInfo.Text += "<span class=\"form-control\">" + r.CustomerName + "</span>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "<div class=\"col-md-6\">";
                        ltrInfo.Text += "<div class=\"form-group\">";
                        ltrInfo.Text += "<label>Điện thoại</label>";
                        ltrInfo.Text += "<span class=\"form-control\">" + r.CustomerPhone + "</span>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "</div>";
                        ltrInfo.Text += "</div>";

                        var cus = CustomerController.GetByID(r.CustomerID.Value);
                        if (cus != null)
                        {
                            ltrInfo.Text += "<div class=\"row\">";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Nick đặt hàng</label>";
                            ltrInfo.Text += "<span class=\"form-control\">" + cus.Nick + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Địa chỉ</label>";
                            ltrInfo.Text += "<span class=\"form-control\">" + cus.CustomerAddress + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";

                            ltrInfo.Text += "<div class=\"row\">";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Zalo</label>";
                            ltrInfo.Text += "<span class=\"form-control\">" + cus.Zalo + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "<div class=\"col-md-6\">";
                            ltrInfo.Text += "<div class=\"form-group\">";
                            ltrInfo.Text += "<label>Facebook</label>";
                            ltrInfo.Text += "<span class=\"form-control\">" + cus.Facebook + "</span>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "</div>";
                            ltrInfo.Text += "<div class=\"row\">";
                            ltrInfo.Text += "    <div class=\"col-md-12 view-detail\">";
                            ltrInfo.Text += "    	<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"viewCustomerDetail('"+ cus.ID + "')\"><i class=\"fa fa-address-card-o\" aria-hidden=\"true\"></i> Xem chi tiết</a>";
                            ltrInfo.Text += "    </div>";
                            ltrInfo.Text += "</div>";
                        }


                        ltrTotal.Text    = string.Format("{0:N0}", Convert.ToDouble(r.TotalPrice));
                        ltrQuantity.Text = string.Format("{0:N0}", Convert.ToDouble(r.TotalQuantity));
                        ltrRefund.Text   = string.Format("{0:N0}", Convert.ToDouble(r.TotalRefundFee));
                        var rds = RefundGoodDetailController.GetByRefundGoodsID(ID);
                        if (rds.Count > 0)
                        {
                            string html = "";
                            foreach (var item in rds)
                            {
                                html += "<tr class=\"product-result\" data-sku=\"" + item.SKU + "\" data-orderID=\"" + item.OrderID
                                        + "\" data-ProductName=\"" + item.ProductName
                                        + "\" data-ProductType=\"" + item.ProductType + "\" data-Giagoc=\"" + item.GiavonPerProduct
                                        + "\" data-Giadaban=\"" + item.SoldPricePerProduct
                                        + "\" data-TienGiam=\"" + item.DiscountPricePerProduct
                                        + "\" data-Soluongtoida=\"" + item.QuantityMax + "\" data-RefundFee=\"" + item.RefundFeePerProduct + "\"  >";
                                html += "   <td>" + item.OrderID + "</td>";
                                html += "   <td>" + item.ProductName + "</td>";
                                html += "   <td>" + item.SKU + "</td>";
                                html += "   <td class=\"giagoc\" data-giagoc=\"" + item.GiavonPerProduct + "\">" + string.Format("{0:N0}", Convert.ToDouble(item.GiavonPerProduct)) + "</td>";
                                html += "   <td class=\"giadaban\" data-giadaban=\"" + item.SoldPricePerProduct + "\">" + item.SoldPricePerProduct + " ( CK: " + string.Format("{0:N0}", Convert.ToDouble(item.DiscountPricePerProduct)) + ")</td>";
                                html += "   <td class=\"sltoida\" data-soluongtoida=\"" + item.QuantityMax + "\">" + item.QuantityMax + "</td>";
                                html += "   <td class=\"slcandoi\">" + item.Quantity + "</td>";
                                html += "   <td>";
                                int    refundType     = Convert.ToInt32(item.RefundType);
                                string refuntTypeName = "";
                                if (item.RefundType == 1)
                                {
                                    refuntTypeName = "Đổi size";
                                }
                                else if (item.RefundType == 2)
                                {
                                    refuntTypeName = "Đổi sản phẩm khác";
                                }
                                else
                                {
                                    refuntTypeName = "Đổi hàng lỗi";
                                }
                                html += refuntTypeName;
                                html += "    </td>";
                                html += "   <td class=\"phidoihang\">" + string.Format("{0:N0}", Convert.ToDouble(item.RefundFeePerProduct)) + "</td>";
                                html += "   <td class=\"thanhtien\">" + string.Format("{0:N0}", Convert.ToDouble(item.TotalPriceRow)) + "</td>";
                                html += "</tr>";
                            }
                            ddlRefundStatus.SelectedValue = r.Status.ToString();
                            txtRefundsNote.Text           = r.RefundNote;
                            ltrList.Text = html;
                        }
                    }
                }
            }
        }
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        public void LoadData()
        {
            int n;

            if (String.IsNullOrEmpty(Request.QueryString["id"]) || !int.TryParse(Request.QueryString["id"], out n))
            {
                PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy đơn hàng", "e", true, "/danh-sach-don-tra-hang", Page);
            }

            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID = Convert.ToInt32(acc.AgentID);
                int ID      = Request.QueryString["id"].ToInt(0);
                if (ID > 0)
                {
                    ViewState["ID"] = ID;
                    var r = RefundGoodController.GetByIDAndAgentID(ID, AgentID);
                    if (r == null)
                    {
                        PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy đơn hàng " + ID, "e", true, "/danh-sach-don-tra-hang", Page);
                    }
                    else
                    {
                        if (acc.RoleID != 0)
                        {
                            // Kiểm tra nếu đơn hàng này không "chính chủ"
                            if (r.CreatedBy != acc.Username)
                            {
                                // Kiểm tra đơn hàng này có đang được tạo giúp bởi nhân viên khác không?
                                var usernameRequest = HttpContext.Current.Request["username"];
                                if (!String.IsNullOrEmpty(usernameRequest))
                                {
                                    var userRequest = AccountController.GetByUsername(usernameRequest);
                                    if (userRequest == null)
                                    {
                                        PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy nhân viên " + usernameRequest, "e", true, "/danh-sach-don-tra-hang", Page);
                                    }
                                    else
                                    {
                                        if (usernameRequest != r.CreatedBy)
                                        {
                                            PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này không phải của " + usernameRequest, "e", true, "/danh-sach-don-tra-hang", Page);
                                        }
                                        else
                                        {
                                            if (r.UserHelp != acc.Username)
                                            {
                                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này không phải do bạn tạo giúp", "e", true, "/danh-sach-don-tra-hang", Page);
                                            }
                                            else
                                            {
                                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này do bạn tạo giúp. Nhấn OK để tiếp tục xử lý!", "i", false, "", Page);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này không phải của bạn", "e", true, "/danh-sach-don-tra-hang", Page);
                                }
                            }
                        }

                        ltrCreateBy.Text    = r.CreatedBy;
                        ltrCreateDate.Text  = r.CreatedDate.ToString();
                        ltrOrderStatus.Text = PJUtils.RefundStatus(Convert.ToInt32(r.Status));
                        if (r.OrderSaleID > 0)
                        {
                            ltrOrderSaleID.Text = "<td><a class='customer-name-link' target='_blank' title='Bấm vào xem đơn hàng trừ tiền' href='/thong-tin-don-hang?id=" + r.OrderSaleID + "'>" + r.OrderSaleID + " (Xem đơn)</a>";
                        }
                        else
                        {
                            ltrOrderSaleID.Text = "";
                        }
                        ltrOrderQuantity.Text   = r.TotalQuantity.ToString();
                        ltrOrderTotalPrice.Text = string.Format("{0:N0}", (Convert.ToDouble(r.TotalPrice)));
                        ltrTotalRefundFee.Text  = string.Format("{0:N0}", (Convert.ToDouble(r.TotalRefundFee)));
                        ltrRefundNote.Text      = r.RefundNote;

                        int    cusID    = 0;
                        string zalo     = "";
                        string nick     = "";
                        string address  = "";
                        string facebook = "";
                        var    cus      = CustomerController.GetByID(r.CustomerID.Value);
                        if (cus != null)
                        {
                            cusID    = cus.ID;
                            zalo     = cus.Zalo;
                            nick     = cus.Nick;
                            address  = cus.CustomerAddress;
                            facebook = cus.Facebook;
                            hdfCustomerPhone.Value = cus.CustomerPhone;
                        }

                        // Title
                        this.Title      = String.Format("{0} - Đổi trả", string.IsNullOrEmpty(nick) ? nick.ToTitleCase() : r.CustomerName.ToTitleCase());
                        ltrHeading.Text = "Đơn đổi trả " + ID.ToString() + " - " + (string.IsNullOrEmpty(nick) ? nick.ToTitleCase() : r.CustomerName.ToTitleCase()) + (!string.IsNullOrEmpty(r.UserHelp) ? " (được tạo giúp bởi " + r.UserHelp + ")" : "");

                        ltrInfo.Text += "<div class='row'>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Họ tên</label>";
                        ltrInfo.Text += "            <span class='form-control input-disabled'>" + r.CustomerName + "</span>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Điện thoại</label>";
                        ltrInfo.Text += "            <span class='form-control input-disabled'>" + r.CustomerPhone + "</span>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Nick đặt hàng</label>";
                        ltrInfo.Text += "            <span class='form-control input-disabled'>" + nick + "</span>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Facebook</label>";
                        ltrInfo.Text += "            <span class='form-control input-disabled'>" + facebook + "</span>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "</div> ";
                        ltrInfo.Text += "<div class='row'>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Tỉnh thành</label>";
                        ltrInfo.Text += "            <select id='_ddlProvince' class='form-control' disable='true' readonly='readonly'></select>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Quận huyện</label>";
                        ltrInfo.Text += "            <select id='_ddlDistrict' class='form-control' disable='true' readonly='readonly'></select>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Phường xã</label>";
                        ltrInfo.Text += "            <select id='_ddlWard' class='form-control' disable='true' readonly='readonly'></select>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "    <div class='col-md-3'>";
                        ltrInfo.Text += "        <div class='form-group'>";
                        ltrInfo.Text += "            <label>Địa chỉ</label>";
                        ltrInfo.Text += "            <span class='form-control input-disabled'>" + address + "</span>";
                        ltrInfo.Text += "        </div>";
                        ltrInfo.Text += "    </div>";
                        ltrInfo.Text += "</div>";

                        ltrInfo.Text += "<div class='form-row view-detail'>";
                        ltrInfo.Text += "    <a href='javascript:;' class='btn primary-btn fw-btn not-fullwidth' onclick='viewCustomerDetail(`" + cusID + "`)'><i class='fa fa-address-card-o' aria-hidden='true'></i> Xem</a>";
                        ltrInfo.Text += "</div>";

                        #region Thông tin phí đổi tra
                        double feeRefundDefault = 0;

                        var discount = DiscountCustomerController.getbyCustID(cusID).FirstOrDefault();
                        if (discount != null)
                        {
                            feeRefundDefault = discount.FeeRefund;

                            ltrInfo.Text += "<div class='form-row discount-info'>";
                            ltrInfo.Text += String.Format("    <strong>* Chiết khấu của khách: {0:0,0}/cái. (đơn từ {1:N0} cái)</strong>", discount.DiscountAmount, discount.QuantityProduct);
                            ltrInfo.Text += "</div>";
                        }
                        else
                        {
                            var config = ConfigController.GetByTop1();
                            feeRefundDefault = config.FeeChangeProduct.Value;
                        }

                        var refundPromotion = RefundGoodController.getPromotion(cusID);
                        if (refundPromotion.IsPromotion)
                        {
                            feeRefundDefault = (feeRefundDefault - refundPromotion.DecreasePrice) < 0 ? 0 : feeRefundDefault - refundPromotion.DecreasePrice;
                        }

                        ltrInfo.Text += "<div class='form-row refund-info'>";
                        if (feeRefundDefault == 0)
                        {
                            ltrInfo.Text += "    <strong>* Miễn phí đổi hàng</strong>";
                        }
                        else
                        {
                            ltrInfo.Text += String.Format("    <strong>* Phí đổi trả hàng: {0:0,0}/cái.</strong>", feeRefundDefault);
                        }
                        ltrInfo.Text += "</div>";

                        if (UserController.checkExists(cusID))
                        {
                            ltrInfo.Text += "<div class='form-row refund-info'>";
                            ltrInfo.Text += "    <strong class='font-green'>Đã đăng ký App</strong>";
                            ltrInfo.Text += "</div>";
                        }
                        else
                        {
                            ltrInfo.Text += "<div class='form-row refund-info'>";
                            ltrInfo.Text += "    <strong class='font-red'>Chưa đăng ký App</strong>";
                            ltrInfo.Text += "</div>";
                        }
                        #endregion


                        ltrTotal.Text    = string.Format("{0:N0}", Convert.ToDouble(r.TotalPrice));
                        ltrQuantity.Text = string.Format("{0:N0}", Convert.ToDouble(r.TotalQuantity));
                        ltrRefund.Text   = string.Format("{0:N0}", Convert.ToDouble(r.TotalRefundFee));

                        // get info tranfor page tao-don-hang-doi-tra.aspx
                        _refundGood.RefundGoodsID    = ID;
                        _refundGood.CustomerID       = r.CustomerID.Value;
                        _refundGood.CustomerName     = r.CustomerName;
                        _refundGood.CustomerPhone    = r.CustomerPhone;
                        _refundGood.CustomerNick     = cus != null ? cus.Nick : String.Empty;
                        _refundGood.CustomerAddress  = cus != null ? cus.CustomerAddress : String.Empty;
                        _refundGood.CustomerZalo     = cus != null ? cus.Zalo : String.Empty;
                        _refundGood.CustomerFacebook = cus != null ? cus.Facebook : String.Empty;
                        _refundGood.RefundDetails    = RefundGoodDetailController.GetInfoShowRefundDetail(ID, feeRefundDefault);
                        _refundGood.TotalPrice       = Convert.ToDouble(r.TotalPrice);
                        _refundGood.TotalQuantity    = Convert.ToDouble(r.TotalQuantity);
                        _refundGood.TotalFreeRefund  = Convert.ToDouble(r.TotalRefundFee);
                        _refundGood.Status           = r.Status.Value;
                        _refundGood.Note             = txtRefundsNote.Text;
                        _refundGood.CreateBy         = r.CreatedBy;

                        var rds = RefundGoodDetailController.GetByRefundGoodsID(ID);

                        var product = _refundGood.RefundDetails
                                      .Join(
                            rds,
                            p1 => new {
                            RefundGoodsID  = p1.RefundGoodsID,
                            RefundDetailID = p1.RefundDetailID
                        },
                            p2 => new {
                            RefundGoodsID  = p2.RefundGoodsID.Value,
                            RefundDetailID = p2.ID
                        },
                            (p1, p2) => new { p1, p2 })
                                      .Select(x => new {
                            SKU                     = x.p2.SKU,
                            OrderID                 = x.p2.OrderID,
                            ProductName             = x.p2.ProductName,
                            ProductType             = x.p2.ProductType,
                            GiavonPerProduct        = x.p2.GiavonPerProduct,
                            SoldPricePerProduct     = x.p2.SoldPricePerProduct,
                            DiscountPricePerProduct = x.p2.DiscountPricePerProduct,
                            Quantity                = x.p2.Quantity,
                            QuantityMax             = x.p2.QuantityMax,
                            RefundType              = x.p2.RefundType,
                            RefundFeePerProduct     = x.p2.RefundFeePerProduct,
                            TotalPriceRow           = x.p2.TotalPriceRow,
                            ProductImage            = x.p1.ProductImage
                        })
                                      .ToList();

                        if (product.Count > 0)
                        {
                            string html = "";
                            int    t    = 0;
                            foreach (var item in product)
                            {
                                var    variables = ProductVariableValueController.GetByProductVariableSKU(item.SKU);
                                string variable  = "";
                                if (variables.Count > 0)
                                {
                                    variable += "<br><br>";
                                    foreach (var v in variables)
                                    {
                                        variable += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "<br>";
                                    }
                                }
                                t++;
                                html += "<tr ondblclick='clickrow($(this))' class='product-result' data-sku='" + item.SKU
                                        + "' data-orderID='" + item.OrderID
                                        + "' data-ProductName='" + item.ProductName
                                        + "' data-ProductType='" + item.ProductType
                                        + "' data-Giagoc='" + item.GiavonPerProduct
                                        + "' data-Giadaban='" + item.SoldPricePerProduct
                                        + "' data-TienGiam='" + item.DiscountPricePerProduct
                                        + "' data-Soluongtoida='" + item.QuantityMax
                                        + "' data-RefundFee='" + item.RefundFeePerProduct
                                        + "'>";
                                html += "   <td>" + t + "</td>";
                                html += "   <td class='image-item'><img src='" + Thumbnail.getURL(item.ProductImage, Thumbnail.Size.Small) + "'></td>";
                                html += "   <td class='name-item'><a href='/xem-san-pham?sku=" + item.SKU + "' target='_blank'>" + item.ProductName + "</a>" + variable + "</td>";
                                html += "   <td class='sku-item'>" + item.SKU + "</td>";
                                html += "   <td class='price-item giagoc' data-giagoc='" + item.GiavonPerProduct + "'>" + string.Format("{0:N0}", Convert.ToDouble(item.GiavonPerProduct)) + "</td>";
                                html += "   <td class='giadaban' data-giadaban='" + item.SoldPricePerProduct + "'><strong>" + string.Format("{0:N0}", Convert.ToDouble(item.SoldPricePerProduct)) + "</strong><br>(CK: " + string.Format("{0:N0}", Convert.ToDouble(item.DiscountPricePerProduct)) + ")</td>";
                                html += "   <td class='slcandoi'>" + item.Quantity + "</td>";
                                html += "   <td>";
                                int    refundType     = Convert.ToInt32(item.RefundType);
                                string refuntTypeName = "";
                                if (item.RefundType == 1)
                                {
                                    refuntTypeName = "Đổi size";
                                }
                                else if (item.RefundType == 2)
                                {
                                    refuntTypeName = "Đổi sản phẩm khác";
                                }
                                else if (item.RefundType == 4)
                                {
                                    refuntTypeName = "Đổi sản phẩm khác (miễn phí)";
                                }
                                else
                                {
                                    refuntTypeName = "Đổi hàng lỗi";
                                }
                                html += refuntTypeName;
                                html += "    </td>";
                                html += "   <td class='phidoihang'>" + string.Format("{0:N0}", Convert.ToDouble(item.RefundFeePerProduct)) + "</td>";
                                html += "   <td class='thanhtien'>" + string.Format("{0:N0}", Convert.ToDouble(item.TotalPriceRow)) + "</td>";
                                html += "</tr>";
                            }

                            ddlRefundStatus.SelectedValue = r.Status.ToString();
                            txtRefundsNote.Text           = r.RefundNote;
                            ltrList.Text = html;
                        }

                        ltrPrint.Text  = "<a href='/print-invoice-return?id=" + ID + "' target='_blank' class='btn primary-btn fw-btn not-fullwidth'><i class='fa fa-print' aria-hidden='true'></i> In hóa đơn</a>";
                        ltrPrint.Text += "<a href='/print-return-order-image?id=" + ID + "' target='_blank' class='btn primary-btn btn-blue fw-btn not-fullwidth print-invoice-merged'><i class='fa fa-picture-o' aria-hidden='true'></i> Lấy ảnh đơn hàng</a>";
                    }
                }
            }
        }
Esempio n. 14
0
        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);
                            }
                        }
                    }
                }
            }
        }
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

            if (ID > 0)
            {
                var order = RefundGoodController.GetByID(ID);

                if (order != null)
                {
                    string error = "";
                    string Print = "";

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;

                    var orderdetails = RefundGoodDetailController.GetByRefundGoodsID(ID);

                    if (orderdetails.Count > 0)
                    {
                        printItemList(ref ID, ref TotalQuantity, ref TotalOrder, ref Print);

                        string productPrint = "";
                        string shtml        = "";

                        productPrint += "<div class=\"body\">";
                        productPrint += "<div class=\"table-1\">";
                        productPrint += "<h1 class=\"invoice-return\">HÓA ĐƠN ĐỔI TRẢ HÀNG #" + order.ID + "</h1>";

                        productPrint += "<table>";
                        productPrint += "<colgroup >";
                        productPrint += "<col class=\"col-left\"/>";
                        productPrint += "<col class=\"col-right\"/>";
                        productPrint += "</colgroup>";
                        productPrint += "<tbody>";
                        productPrint += "<tr>";
                        productPrint += "<td>Khách hàng</td>";
                        productPrint += "<td>" + order.CustomerName + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Điện thoại</td>";
                        productPrint += "<td>" + order.CustomerPhone + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Ngày tạo</td>";
                        string date = string.Format("{0:dd/MM/yyyy HH:mm}", order.CreatedDate);
                        productPrint += "<td>" + date + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Nhân viên</td>";
                        productPrint += "<td>" + order.CreatedBy + "</td>";
                        productPrint += "</tr>";

                        productPrint += "<tr>";
                        productPrint += "<td>Trạng thái</td>";
                        if (order.Status == 0)
                        {
                            productPrint += "<td>Chưa trừ tiền</td>";
                        }
                        else
                        {
                            productPrint += "<td>Đã trừ tiền</td>";
                        }
                        productPrint += "</tr>";

                        if (!string.IsNullOrEmpty(order.RefundNote))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Ghi chú</td>";
                            productPrint += "<td>" + order.RefundNote + "</td>";
                            productPrint += "</tr>";
                        }

                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";

                        productPrint += "<div class=\"table-2 print-invoice-return\">";
                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class=\"sanpham\" />";
                        productPrint += "<col class=\"soluong\" />";
                        productPrint += "<col class=\"gia\" />";
                        productPrint += "<col class=\"gia\" />";
                        productPrint += "<col class=\"tong\"/>";
                        productPrint += "</colgroup>";
                        productPrint += "<thead>";
                        productPrint += "<th>Sản phẩm</th>";
                        productPrint += "<th>SL</th>";
                        productPrint += "<th>Giá</th>";
                        productPrint += "<th>Phí</th>";
                        productPrint += "<th>Tổng</th>";
                        productPrint += "</thead>";
                        productPrint += "<tbody>";
                        productPrint += Print;
                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"4\">Số lượng</td>";
                        productPrint += "<td>" + TotalQuantity + "</td>";
                        productPrint += "</tr>";

                        if (TotalOrder != Convert.ToDouble(order.TotalPrice))
                        {
                            error += "Đơn hàng tính sai tổng tiền";
                        }

                        productPrint += "<tr>";
                        productPrint += "<td class=\"strong\" colspan=\"4\">Tổng tiền</td>";
                        productPrint += "<td class=\"strong\">" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";

                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"4\">Phí đổi hàng</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.TotalRefundFee)) + "</td>";
                        productPrint += "</tr>";

                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";
                        productPrint += "</div>";

                        shtml += "<div class=\"hoadon\">";
                        shtml += "<div class=\"all\">";

                        shtml += productPrint;

                        shtml += "<div class=\"footer\"><h3>CẢM ƠN QUÝ KHÁCH !!!</h3>";
                        shtml += "<p>Lưu ý:</p>";
                        shtml += "<p>- Chúng tôi chỉ trả lại tiền mặt khi tổng tiền dưới 50.000đ.</p>";
                        shtml += "<p>- Đơn hàng đổi trả trên 50.000đ dùng để trừ tiền khi mua sản phẩm khác.</p>";
                        shtml += "<p>- Giá trên hóa đơn là giá bán ra đã trừ chiết khấu (nếu có).</p>";
                        shtml += "<p>- Phí đổi hàng áp dụng khi đổi hàng tồn hoặc đổi sang màu/mẫu khác.</p>";
                        shtml += "<p>- Miễn phí đổi size hoặc hàng lỗi cùng màu/mẫu như lúc đầu.</p>";
                        shtml += "</div>";
                        shtml += "</div>";
                        shtml += "</div>";


                        if (error != "")
                        {
                            ltrPrintInvoice.Text = "Xảy ra lỗi: " + error;
                            ltrPrintEnable.Text  = "";
                        }
                        else
                        {
                            ltrPrintInvoice.Text = shtml;
                            ltrPrintEnable.Text  = "<div class=\"print-enable true\"></div>";
                        }
                    }
                }
                else
                {
                    ltrPrintInvoice.Text = "Không tìm thấy đơn hàng " + ID;
                }
            }
            else
            {
                ltrPrintInvoice.Text = "Xảy ra lỗi!!!";
            }
        }