public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

            if (ID > 0)
            {
                var order = OrderController.GetByID(ID);
                if (order == null)
                {
                    PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy đơn hàng " + ID, "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                }
                else
                {
                    hdfOrderID.Value = order.ID.ToString();
                    string username = HttpContext.Current.Request.Cookies["userLoginSystem"].Value;
                    var    acc      = AccountController.GetByUsername(username);

                    // check order condition
                    if (acc.RoleID != 0)
                    {
                        if (order.ExcuteStatus == 4)
                        {
                            PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã chuyển hoàn", "w", false, "", Page);
                        }
                        else
                        {
                            if (order.CreatedBy != acc.Username)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này không phải của bạn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ExcuteStatus == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này chưa hoàn tất nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ExcuteStatus == 3)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã hủy nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ShippingType == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này lấy trực tiếp nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }
                        }
                    }
                    else
                    {
                        if (order.ExcuteStatus == 4)
                        {
                            PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã chuyển hoàn", "w", false, "", Page);
                        }
                        else
                        {
                            if (order.ExcuteStatus == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này chưa hoàn tất nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ExcuteStatus == 3)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã hủy nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ShippingType == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này lấy trực tiếp nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }
                        }
                    }

                    ViewState["ID"] = ID;

                    Response.Cookies["odid"].Value = ID.ToString();

                    int AgentID = Convert.ToInt32(order.AgentID);
                    txtPhone.Text    = order.CustomerPhone;
                    txtFullname.Text = order.CustomerName;
                    txtAddress.Text  = order.CustomerAddress;
                    var cus = CustomerController.GetByID(order.CustomerID.Value);
                    if (cus != null)
                    {
                        txtNick.Text = cus.Nick;

                        txtZalo.Text = cus.Zalo;

                        txtFacebook.Text = cus.Facebook;
                        if (!string.IsNullOrEmpty(cus.Facebook))
                        {
                            ltrFb.Text += "<a href =\"" + cus.Facebook + "\" class=\"btn primary-btn fw-btn not-fullwidth\" target=\"_blank\">Xem</a>";
                        }
                    }
                    int customerID = Convert.ToInt32(order.CustomerID);
                    ltrViewDetail.Text  = "<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"viewCustomerDetail('" + customerID + "')\"><i class=\"fa fa-address-card-o\" aria-hidden=\"true\"></i> Xem chi tiết</a>";
                    ltrViewDetail.Text += "<a href=\"chi-tiet-khach-hang?id=" + customerID + "\" class=\"btn primary-btn fw-btn not-fullwidth edit-customer-btn\" target=\"_blank\"><i class=\"fa fa-pencil-square-o\" aria-hidden=\"true\"></i> Chỉnh sửa</a>";

                    var d = DiscountCustomerController.getbyCustID(customerID);
                    if (d.Count > 0)
                    {
                        var da = d[0].DiscountAmount;
                        hdfIsDiscount.Value     = "1";
                        hdfDiscountAmount.Value = da.ToString();
                        ltrDiscountInfo.Text    = "<strong>Khách hàng được chiết khấu: " + string.Format("{0:N0}", Convert.ToDouble(da)) + " vnđ/sản phẩm.</strong>";
                    }
                    else
                    {
                        hdfIsDiscount.Value     = "0";
                        hdfDiscountAmount.Value = "0";
                    }

                    int customerType = Convert.ToInt32(order.OrderType);
                    ltrCustomerType.Text  = "";
                    ltrCustomerType.Text += "<select disabled class=\"form-control customer-type\" onchange=\"getProductPrice($(this))\">";
                    if (customerType == 1)
                    {
                        ltrCustomerType.Text += "<option value=\"2\">Khách mua sỉ</option>";
                        ltrCustomerType.Text += "<option value=\"1\" selected>Khách mua lẻ</option>";
                    }
                    else
                    {
                        ltrCustomerType.Text += "<option value=\"2\" selected>Khách mua sỉ</option>";
                        ltrCustomerType.Text += "<option value=\"1\">Khách mua lẻ</option>";
                    }
                    ltrCustomerType.Text += "</select>";


                    double ProductQuantity       = 0;
                    double totalPrice            = Convert.ToDouble(order.TotalPrice);
                    double totalPriceNotDiscount = Convert.ToDouble(order.TotalPriceNotDiscount);

                    hdfcheckR.Value = "";

                    int totalrefund = 0;
                    if (order.RefundsGoodsID > 0)
                    {
                        var re = RefundGoodController.GetByID(order.RefundsGoodsID.Value);
                        if (re != null)
                        {
                            totalrefund     = Convert.ToInt32(re.TotalPrice);
                            hdfcheckR.Value = order.RefundsGoodsID.ToString() + "," + re.TotalPrice;
                        }

                        ltrtotalpricedetail.Text = string.Format("{0:N0}", totalPrice - totalrefund);

                        ltrTotalPriceRefund.Text = string.Format("{0:N0}", totalrefund);
                    }

                    hdfDiscountInOrder.Value = "";

                    if (order.DiscountPerProduct > 0)
                    {
                        hdfDiscountInOrder.Value = order.DiscountPerProduct.ToString();
                    }

                    int paymentStatus         = Convert.ToInt32(order.PaymentStatus);
                    int excuteStatus          = Convert.ToInt32(order.ExcuteStatus);
                    int shipping              = Convert.ToInt32(order.ShippingType);
                    int TransportCompanyID    = Convert.ToInt32(order.TransportCompanyID);
                    int TransportCompanySubID = Convert.ToInt32(order.TransportCompanySubID);
                    int PostalDeliveryType    = Convert.ToInt32(order.PostalDeliveryType);
                    int paymenttype           = Convert.ToInt32(order.PaymentType);
                    #region Lấy danh sách sản phẩm
                    var    orderdetails = OrderDetailController.GetByOrderID(ID);
                    string html         = "";
                    string Print        = "";
                    if (orderdetails.Count > 0)
                    {
                        int t         = 0;
                        int orderitem = 0;
                        foreach (var item in orderdetails)
                        {
                            ProductQuantity += Convert.ToDouble(item.Quantity);

                            int    ProductType       = Convert.ToInt32(item.ProductType);
                            int    ProductID         = Convert.ToInt32(item.ProductID);
                            int    ProductVariableID = Convert.ToInt32(item.ProductVariableID);
                            double ItemPrice         = Convert.ToDouble(item.Price);
                            string SKU                        = item.SKU;
                            double Giabansi                   = 0;
                            double Giabanle                   = 0;
                            string stringGiabansi             = "";
                            string stringGiabanle             = "";
                            double QuantityInstock            = 0;
                            string ProductImageOrigin         = "";
                            string ProductVariable            = "";
                            string ProductName                = "";
                            int    PID                        = 0;
                            string ProductVariableName        = "";
                            string ProductVariableValue       = "";
                            string ProductVariableSave        = "";
                            double QuantityMainInstock        = 0;
                            string ProductImage               = "";
                            string QuantityMainInstockString  = "";
                            string QuantityInstockString      = "";
                            string productVariableDescription = item.ProductVariableDescrition;

                            if (ProductType == 1)
                            {
                                PID = ProductID;
                                var product = ProductController.GetBySKU(SKU);
                                if (product != null)
                                {
                                    double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                    if (customerType == 1)
                                    {
                                        Giabansi = Convert.ToDouble(product.Regular_Price);
                                        Giabanle = ItemPrice;
                                    }
                                    else
                                    {
                                        Giabansi = ItemPrice;
                                        Giabanle = Convert.ToDouble(product.Retail_Price);
                                    }
                                    stringGiabansi = string.Format("{0:N0}", Giabansi);
                                    stringGiabanle = string.Format("{0:N0}", Giabanle);
                                    string variablename  = "";
                                    string variablevalue = "";
                                    string variable      = "";



                                    QuantityInstock       = mainstock;
                                    QuantityInstockString = string.Format("{0:N0}", mainstock);

                                    var img = ProductImageController.GetFirstByProductID(product.ID);
                                    if (!string.IsNullOrEmpty(product.ProductImage))
                                    {
                                        ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                                        ProductImageOrigin = product.ProductImage;
                                    }
                                    else if (img != null)
                                    {
                                        ProductImage       = "<img src=\"" + img.ProductImage + "\" />";
                                        ProductImageOrigin = img.ProductImage;
                                    }
                                    else
                                    {
                                        ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                        ProductImageOrigin = "";
                                    }
                                    ProductVariable = variable;
                                    ProductName     = product.ProductTitle;

                                    QuantityMainInstock       = mainstock;
                                    QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                    ProductVariableSave       = item.ProductVariableDescrition;

                                    ProductVariableName  = variablename;
                                    ProductVariableValue = variablevalue;
                                }
                            }
                            else
                            {
                                PID = ProductVariableID;
                                var productvariable = ProductVariableController.GetBySKU(SKU);
                                if (productvariable != null)
                                {
                                    SKU = productvariable.SKU.Trim().ToUpper();

                                    double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                    if (customerType == 1)
                                    {
                                        Giabansi = Convert.ToDouble(productvariable.Regular_Price);
                                        Giabanle = ItemPrice;
                                    }
                                    else
                                    {
                                        Giabansi = ItemPrice;
                                        Giabanle = Convert.ToDouble(productvariable.RetailPrice);
                                    }
                                    stringGiabansi = string.Format("{0:N0}", Giabansi);
                                    stringGiabanle = string.Format("{0:N0}", Giabanle);


                                    string variablename  = "";
                                    string variablevalue = "";
                                    string variable      = "";

                                    string[] vs = productVariableDescription.Split('|');
                                    if (vs.Length - 1 > 0)
                                    {
                                        for (int i = 0; i < vs.Length - 1; i++)
                                        {
                                            string[] items = vs[i].Split(':');
                                            variable      += items[0] + ":" + items[1] + "<br/>";
                                            variablename  += items[0] + "|";
                                            variablevalue += items[1] + "|";
                                        }
                                    }

                                    QuantityInstock       = mainstock;
                                    QuantityInstockString = string.Format("{0:N0}", mainstock);

                                    var _product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));

                                    if (!string.IsNullOrEmpty(productvariable.Image))
                                    {
                                        ProductImage       = "<img src=\"" + productvariable.Image + "\" />";
                                        ProductImageOrigin = productvariable.Image;
                                    }
                                    else if (_product != null && !string.IsNullOrEmpty(_product.ProductImage))
                                    {
                                        ProductImage       = "<img src=\"" + _product.ProductImage + "\" />";
                                        ProductImageOrigin = _product.ProductImage;
                                    }
                                    else
                                    {
                                        ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                        ProductImageOrigin = "";
                                    }

                                    ProductVariable = variable;

                                    if (_product != null)
                                    {
                                        ProductName = _product.ProductTitle;
                                    }

                                    QuantityMainInstock       = mainstock;
                                    QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                    ProductVariableSave       = item.ProductVariableDescrition;

                                    ProductVariableName  = variablename;
                                    ProductVariableValue = variablevalue;
                                }
                            }
                            orderitem++;
                            html += "<tr class=\"product-result\" data-orderdetailid=\"" + item.ID + "\" data-giabansi=\"" + Giabansi + "\" data-giabanle=\"" + Giabanle + "\" " +
                                    "data-quantityinstock=\"" + QuantityInstock + "\" data-productimageorigin=\"" + ProductImageOrigin + "\" " +
                                    "data-productvariable=\"" + ProductVariable + "\" data-productname=\"" + ProductName + "\" " +
                                    "data-sku=\"" + SKU + "\" data-producttype=\"" + ProductType + "\" data-id=\"" + PID + "\" " +
                                    "data-productnariablename=\"" + ProductVariableName + "\" " +
                                    "data-productvariablevalue =\"" + ProductVariableValue + "\" " +
                                    "data-productvariablesave =\"" + ProductVariableSave + "\" " +
                                    "data-quantitymaininstock=\"" + QuantityMainInstock + "\">";
                            html += "   <td class=\"order-item\">" + orderitem + "";
                            html += "   <td class=\"image-item\">" + ProductImage + "";
                            html += "   <td class=\"name-item\">" + ProductName + "</td>";
                            html += "   <td class=\"sku-item\">" + SKU + "</td>";
                            html += "   <td class=\"variable-item\">" + ProductVariable + "</td>";
                            html += "   <td class=\"price-item gia-san-pham\" data-price=\"" + ItemPrice + "\">" + string.Format("{0:N0}", ItemPrice) + "</td>";
                            html += "   <td class=\"quantity-item soluong\">" + QuantityInstockString + "</td>";
                            html += "   <td class=\"quantity-item\"><input disabled data-quantity=\"" + item.Quantity + "\" value=\"" + item.Quantity + "\" type=\"text\" class=\"form-control in-quanlity\" value=\"1\" onblur=\"checkQuantiy($(this))\" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>";
                            int k = Convert.ToInt32(ItemPrice) * Convert.ToInt32(item.Quantity);
                            html += "<td class=\"total-item totalprice-view\">" + string.Format("{0:N0}", k) + "</td>";
                            html += "   <td class=\"trash-item\"><a href=\"javascript:;\" class=\"link-btn\"><i class=\"fa fa-trash\"></i></a>    </td>";

                            html += "</tr>";


                            Print += " <tr>";
                            t++;
                            Print += "<td>" + t + "</td>";
                            Print += "<td>" + SKU + " - " + ProductName + " - " + ProductVariableSave.Replace("|", ", ") + "</td> ";
                            Print += "<td>" + item.Quantity + "</td>";
                            Print += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>";

                            Print += "<td> " + string.Format("{0:N0}", k) + "</td>";

                            Print += "</tr>";
                        }
                        ltrProducts.Text = html;
                    }
                    #endregion
                    ddlPaymentStatus.SelectedValue      = paymentStatus.ToString();
                    ddlExcuteStatus.SelectedValue       = excuteStatus.ToString();
                    ddlPaymentType.SelectedValue        = paymenttype.ToString();
                    ddlShippingType.SelectedValue       = shipping.ToString();
                    ddlPostalDeliveryType.SelectedValue = PostalDeliveryType.ToString();

                    LoadTransportCompanySubID(TransportCompanyID);
                    ddlTransportCompanyID.SelectedValue    = TransportCompanyID.ToString();
                    ddlTransportCompanySubID.SelectedValue = TransportCompanySubID.ToString();

                    txtShippingCode.Text = order.ShippingCode;
                    txtOrderNote.Text    = order.OrderNote;

                    ltrProductQuantity.Text  = string.Format("{0:N0}", ProductQuantity) + " sản phẩm";
                    ltrTotalNotDiscount.Text = string.Format("{0:N0}", Convert.ToDouble(order.TotalPriceNotDiscount));
                    ltrTotalprice.Text       = string.Format("{0:N0}", Convert.ToDouble(order.TotalPrice));
                    pDiscount.Value          = order.DiscountPerProduct;
                    pFeeShip.Value           = Convert.ToDouble(order.FeeShipping);

                    ltrOtherFeeName.Text = order.OtherFeeName;
                    txtOtherFeeName.Text = order.OtherFeeName;
                    pOtherFee.Value      = Convert.ToDouble(order.OtherFeeValue);

                    ltrTotalAfterCK.Text = string.Format("{0:N0}", (Convert.ToDouble(order.TotalPriceNotDiscount) - Convert.ToDouble(order.TotalDiscount)));
                    ltrOrderID.Text      = ID.ToString();
                    ltrCreateBy.Text     = order.CreatedBy;
                    ltrCreateDate.Text   = order.CreatedDate.ToString();
                    ltrDateDone.Text     = "Chưa hoàn tất";
                    if (order.DateDone != null)
                    {
                        ltrDateDone.Text = order.DateDone.ToString();
                    }
                    ltrOrderNote.Text       = order.OrderNote;
                    ltrOrderQuantity.Text   = ProductQuantity.ToString();
                    ltrOrderTotalPrice.Text = string.Format("{0:N0}", Convert.ToDouble(order.TotalPrice));
                    ltrOrderStatus.Text     = PJUtils.OrderExcuteStatus(Convert.ToInt32(order.ExcuteStatus));

                    ltrOrderType.Text = PJUtils.OrderType(Convert.ToInt32(order.OrderType));
                }
            }
        }
        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!!!";
            }
        }
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

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

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

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;

                    var orderdetails = OrderDetailController.GetByIDSortBySKU(ID);

                    var numberOfOrders = OrderController.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>XÁC NHẬN ĐƠN HÀNG #" + order.ID + "</h1>";
                        productPrint += "<div class=\"note\">";
                        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>- Quý khách vui lòng kiểm tra thuộc tính sản phẩm (Mã, Màu, Mẫu, Size).</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>";

                        if (!string.IsNullOrEmpty(order.DateDone.ToString()))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Hoàn tất</td>";
                            string datedone = string.Format("{0:dd/MM/yyyy HH:mm}", order.DateDone);
                            productPrint += "<td>" + datedone + "</td>";
                        }

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

                        if (!string.IsNullOrEmpty(order.OrderNote))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Ghi chú</td>";
                            productPrint += "<td>" + order.OrderNote + "</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=\"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á</th>";
                        productPrint += "<th>Tổng</th>";
                        productPrint += "</thead>";
                        productPrint += "<tbody>";
                        productPrint += Print;
                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"5\" class=\"align-right\">Số lượng</td>";
                        productPrint += "<td>" + TotalQuantity + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"5\" class=\"align-right\">Thành tiền</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";

                        double TotalPrice = TotalOrder;

                        if (order.DiscountPerProduct > 0)
                        {
                            var TotalDiscount = Convert.ToDouble(order.DiscountPerProduct) * Convert.ToDouble(TotalQuantity);
                            TotalOrder    = TotalOrder - TotalDiscount;
                            TotalPrice    = TotalPrice - TotalDiscount;
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"5\" class=\"align-right\">Chiết khấu mỗi cái </td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.DiscountPerProduct)) + "</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"5\" class=\"align-right\">Trừ chiết khấu</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", TotalDiscount) + "</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"5\" class=\"align-right\">Sau chiết khấu</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                            productPrint += "</tr>";
                        }

                        if (order.RefundsGoodsID != null)
                        {
                            var refund = RefundGoodController.GetByID(Convert.ToInt32(order.RefundsGoodsID));
                            if (refund != null)
                            {
                                TotalOrder = TotalOrder - Convert.ToDouble(refund.TotalPrice);

                                productPrint += "<tr>";
                                productPrint += "<td colspan=\"5\" class=\"align-right\">Trừ tiền hàng trả (đơn " + order.RefundsGoodsID + ")</td>";
                                productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(refund.TotalPrice)) + "</td>";
                                productPrint += "</tr>";

                                productPrint += "<tr>";
                                productPrint += "<td colspan=\"5\" class=\"align-right\">Tổng tiền còn lại</td>";
                                productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                                productPrint += "</tr>";
                            }
                            else
                            {
                                error += "Không tìm thấy đơn hàng đổi trả " + order.RefundsGoodsID.ToString();
                            }
                        }

                        if (Convert.ToDouble(order.FeeShipping) > 0)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(order.FeeShipping);
                            TotalPrice    = TotalPrice + Convert.ToDouble(order.FeeShipping);
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"5\" class=\"align-right\">Phí vận chuyển</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.FeeShipping)) + "</td>";
                            productPrint += "</tr>";
                        }

                        if (Convert.ToDouble(order.OtherFeeValue) != 0)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(order.OtherFeeValue);
                            TotalPrice    = TotalPrice + Convert.ToDouble(order.OtherFeeValue);
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"5\" class=\"align-right\">" + order.OtherFeeName + "</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.OtherFeeValue)) + "</td>";
                            productPrint += "</tr>";
                        }

                        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=\"5\">TỔNG CỘ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.DateDone);

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


                        if (numberOfOrders.Count < 4)
                        {
                            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 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!!!";
            }
        }
Example #5
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));
        }
Example #6
0
        public void LoadData()
        {
            int ID         = Request.QueryString["id"].ToInt(0);
            int mergeprint = 0;

            if (Request.QueryString["merge"] != null)
            {
                mergeprint = Request.QueryString["merge"].ToInt(0);
            }

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

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

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;


                    var orderdetails = OrderDetailController.GetByIDSortBySKU(ID);

                    var numberOfOrders = OrderController.GetByCustomerID(Convert.ToInt32(order.CustomerID));
                    var customer       = CustomerController.GetByID(Convert.ToInt32(order.CustomerID));

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

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

                        productPrint += "<div class=\"body\">";
                        productPrint += "<div class=\"table-1\">";
                        string mergeAlert = "";
                        if (mergeprint == 1)
                        {
                            mergeAlert += "<p class=\"merge-alert\">(Đã gộp sản phẩm)<p>";
                        }
                        productPrint += "<h1>HÓA ĐƠN #" + order.ID + mergeAlert + "</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 class=\"capitalize\">" + order.CustomerName + "</td>";
                        productPrint += "</tr>";

                        if (!string.IsNullOrEmpty(customer.Nick))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Nick đặt hàng</td>";
                            productPrint += "<td class=\"capitalize\">" + customer.Nick + "</td>";
                            productPrint += "</tr>";
                        }

                        productPrint += "<tr>";
                        productPrint += "<td>Điện thoại</td>";
                        productPrint += "<td>" + order.CustomerPhone + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";

                        if (numberOfOrders.Count < 3)
                        {
                            productPrint += "<td>Loại đơn</td>";
                            if (order.OrderType == 1)
                            {
                                productPrint += "<td>Mua lẻ</td>";
                            }
                            if (order.OrderType == 2)
                            {
                                productPrint += "<td>Mua sỉ</td>";
                            }
                            productPrint += "</tr>";
                        }
                        if (!string.IsNullOrEmpty(order.DateDone.ToString()))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Hoàn tất</td>";
                            string datedone = string.Format("{0:dd/MM/yyyy HH:mm}", order.DateDone);
                            productPrint += "<td>" + datedone + "</td>";
                            productPrint += "</tr>";
                        }
                        else
                        {
                            error += "Đơn hàng chưa hoàn tất";
                        }

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

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

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

                        productPrint += "<div class=\"table-2\">";
                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class=\"stt\" />";
                        productPrint += "<col class=\"sanpham\" />";
                        productPrint += "<col class=\"soluong\" />";
                        productPrint += "<col class=\"gia\" />";
                        productPrint += "<col class=\"tong\"/>";
                        productPrint += "</colgroup>";
                        productPrint += "<thead>";
                        productPrint += "<th>#</th>";
                        productPrint += "<th>Sản phẩm</th>";
                        productPrint += "<th>SL</th>";
                        productPrint += "<th>Giá</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>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"4\">Thành tiền</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";

                        double TotalPrice = TotalOrder;

                        if (order.DiscountPerProduct > 0)
                        {
                            var TotalDiscount = Convert.ToDouble(order.DiscountPerProduct) * Convert.ToDouble(TotalQuantity);
                            TotalOrder    = TotalOrder - TotalDiscount;
                            TotalPrice    = TotalPrice - TotalDiscount;
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"4\">Chiết khấu mỗi cái </td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.DiscountPerProduct)) + "</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"4\">Trừ chiết khấu</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", TotalDiscount) + "</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"4\">Sau chiết khấu</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                            productPrint += "</tr>";
                        }

                        if (order.RefundsGoodsID != null)
                        {
                            var refund = RefundGoodController.GetByID(Convert.ToInt32(order.RefundsGoodsID));
                            if (refund != null)
                            {
                                TotalOrder = TotalOrder - Convert.ToDouble(refund.TotalPrice);

                                productPrint += "<tr>";
                                productPrint += "<td colspan=\"4\">Trừ tiền hàng trả (đơn " + order.RefundsGoodsID + ")</td>";
                                productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(refund.TotalPrice)) + "</td>";
                                productPrint += "</tr>";

                                productPrint += "<tr>";
                                productPrint += "<td colspan=\"4\">Tổng tiền còn lại</td>";
                                productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                                productPrint += "</tr>";
                            }
                            else
                            {
                                error += "Không tìm thấy đơn hàng đổi trả " + order.RefundsGoodsID.ToString();
                            }
                        }


                        if (Convert.ToDouble(order.FeeShipping) > 0)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(order.FeeShipping);
                            TotalPrice    = TotalPrice + Convert.ToDouble(order.FeeShipping);
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"4\">Phí vận chuyển</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.FeeShipping)) + "</td>";
                            productPrint += "</tr>";
                        }

                        if (Convert.ToDouble(order.OtherFeeValue) != 0)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(order.OtherFeeValue);
                            TotalPrice    = TotalPrice + Convert.ToDouble(order.OtherFeeValue);
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"4\">" + order.OtherFeeName + "</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.OtherFeeValue)) + "</td>";
                            productPrint += "</tr>";
                        }

                        if (TotalPrice != 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 CỘNG</td>";
                        productPrint += "<td class=\"strong\">" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";


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


                        string address  = "";
                        string phone    = "";
                        string facebook = "";
                        var    agent    = AgentController.GetByID(Convert.ToInt32(order.AgentID));
                        if (agent != null)
                        {
                            address  = agent.AgentAddress;
                            phone    = agent.AgentPhone;
                            facebook = agent.AgentFacebook;
                        }

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

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

                        shtml += "<div class=\"logo\"><div class=\"img\"><img src=\"App_Themes/Ann/image/logo.png\" /></div></div>";

                        if (numberOfOrders.Count < 3)
                        {
                            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 class=\"ct\">";
                            shtml += "<div class=\"ct-title\"></div>";
                            shtml += "<div class=\"ct-detail\">https://ann.com.vn</div>";
                            shtml += "</div>";

                            shtml += "</div>";
                        }

                        shtml += "</div>";

                        shtml += productPrint;

                        shtml += "<div class=\"footer\"><h3>CẢM ƠN QUÝ KHÁCH !!!</h3></div> ";

                        var    config = ConfigController.GetByTop1();
                        string rule   = "";
                        if (order.OrderType == 2)
                        {
                            rule = config.ChangeGoodsRule;
                        }
                        else
                        {
                            rule = config.RetailReturnRule;
                        }

                        if (numberOfOrders.Count < 3)
                        {
                            shtml += "<div class=\"footer\">" + rule + "</div> ";
                        }
                        else
                        {
                            shtml += "<div class=\"footer\">";
                            shtml += "<p>ANN rất vui khi quý khách đã mua được " + numberOfOrders.Count + " đơn hàng!</p>";
                            shtml += "<p>Vui lòng xem nội quy đổi trả hàng trên ANN.COM.VN</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!!!";
            }
        }
Example #7
0
        public void LoadData()
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            string error = "";

            String rowHtml = String.Empty;

            string PrintButton = "";

            int ID    = Request.QueryString["id"].ToInt(0);
            var order = OrderController.GetByID(ID);

            if (order == null)
            {
                error += "Không tìm thấy đơn hàng!";
            }
            else
            {
                if (order.PaymentStatus == 1)
                {
                    error += "<p>- Đơn hàng này <strong>Chưa thanh toán</strong>!</p>";
                }

                if (order.ExcuteStatus != 2)
                {
                    error += "<p>- Đơn hàng này <strong>Chưa hoàn tất</strong>!</p>";
                }

                if (order.ShippingType == 1 && acc.RoleID != 0)
                {
                    error += "<p>- Đơn hàng này <strong>Lấy trực tiếp</strong>. Hãy chuyển sang phương thức khác hoặc nhờ chị Ngọc in phiếu!</p>";
                }

                if (order.PaymentType == 1 && acc.RoleID != 0)
                {
                    error += "<p>- Đơn hàng này <strong>Thanh toán tiền mặt</strong>. Hãy chuyển sang phương thức khác hoặc nhờ chị Ngọc in phiếu!</p>";
                }

                string address = "";
                string phone   = "";
                string leader  = "";
                var    agent   = AgentController.GetByID(Convert.ToInt32(order.AgentID));

                if (agent != null)
                {
                    address = agent.AgentAddress;
                    leader  = agent.AgentLeader;
                    phone   = agent.AgentPhone;
                }

                double TotalOrder = Convert.ToDouble(order.TotalPrice);

                if (order.RefundsGoodsID != null)
                {
                    var refund = RefundGoodController.GetByID(Convert.ToInt32(order.RefundsGoodsID));
                    if (refund != null)
                    {
                        TotalOrder = TotalOrder - Convert.ToDouble(refund.TotalPrice);
                    }
                    else
                    {
                        error += "<p>Không tìm thấy đơn hàng đổi trả " + order.RefundsGoodsID.ToString() + " (có thể đã bị xóa khi làm lại đơn đổi trả). Thêm lại đơn hàng đổi trả nhé!</p>";
                    }
                }
                var customer = CustomerController.GetByID(order.CustomerID.Value);

                string addressDetail = "";
                string ProvinceName  = "";
                if (customer.ProvinceID.HasValue)
                {
                    var Province = ProvinceController.GetByID(customer.ProvinceID.Value);
                    addressDetail = ", " + Province.Name;
                    ProvinceName  = Province.Name;
                }
                if (customer.DistrictId.HasValue)
                {
                    var District = ProvinceController.GetByID(customer.DistrictId.Value);
                    addressDetail = ", " + District.Name + addressDetail;
                }
                if (customer.WardId.HasValue && customer.WardId.Value > 0)
                {
                    var Ward = ProvinceController.GetByID(customer.WardId.Value);
                    addressDetail = ", " + Ward.Name + addressDetail;
                }

                string CustomerAddress = order.CustomerAddress.ToTitleCase() + addressDetail;
                string DeliveryInfo    = "";
                string ShippingFeeInfo = "";
                string ShipperFeeInfo  = "";

                // BƯU ĐIỆN
                if (order.ShippingType == 2)
                {
                    if (!string.IsNullOrEmpty(order.ShippingCode))
                    {
                        string PostalDeliveryType = "Thường";
                        if (order.PostalDeliveryType == 2)
                        {
                            PostalDeliveryType = "Nhanh";
                        }
                        DeliveryInfo = String.Format("<p class='delivery'><strong>Bưu điện - {0}:</strong> {1}</p><p><img src='{2}'></p>", PostalDeliveryType, order.ShippingCode, createBarcode(order.ShippingCode));
                    }
                    else
                    {
                        error += "<p>- Đơn hàng này <strong>gửi Bưu điện</strong> nhưng <strong>chưa nhập</strong> MÃ VẬN ĐƠN!</p>";
                    }

                    if (order.PaymentType != 3 && acc.RoleID != 0)
                    {
                        PrintButton = "<a class='btn btn-black' href='javascript:;' onclick='printError(`Bưu điện`)'>Không in được</a>";
                    }
                }
                // PROSHIP
                else if (order.ShippingType == 3)
                {
                    if (!string.IsNullOrEmpty(order.ShippingCode))
                    {
                        DeliveryInfo = String.Format("<p class='delivery'><strong>Proship:</strong> {0}</p><p><img src='{1}'></p>", order.ShippingCode, createBarcode(order.ShippingCode));
                    }
                    else
                    {
                        error += "<p>- Đơn hàng này <strong>gửi Proship</strong> nhưng <strong>chưa nhập</strong> MÃ VẬN ĐƠN!</p>";
                    }

                    if (order.PaymentType != 3 && acc.RoleID != 0)
                    {
                        PrintButton = "<a class='btn btn-black' href='javascript:;' onclick='printError(`Proship`)'>Không in được</a>";
                    }
                }
                // GỬI XE
                else if (order.ShippingType == 4)
                {
                    var company = TransportCompanyController.GetTransportCompanyForOrderList(Convert.ToInt32(order.TransportCompanyID));
                    if (company != null)
                    {
                        string transportCompany        = "";
                        string transportCompanyPhone   = "";
                        string transportCompanyAddress = "";
                        string transportCompanyNote    = "";

                        transportCompany = "<strong>" + company.CompanyName.ToTitleCase() + "</strong>";
                        if (company.CompanyPhone != "")
                        {
                            transportCompanyPhone = "<span class='transport-info'>(" + company.CompanyPhone + ")</span>";
                        }
                        transportCompanyAddress = "<span class='transport-info'>" + company.CompanyAddress.ToTitleCase() + "</span>";
                        if (company.Note != "")
                        {
                            transportCompanyNote = "<span class='transport-info capitalize'> - " + company.Note.ToTitleCase() + "</span>";
                        }

                        var subID  = Convert.ToInt32(order.TransportCompanySubID);
                        var shipto = TransportCompanyController.GetReceivePlaceForOrderList(company.ID, subID);
                        if (shipto != null && subID > 0)
                        {
                            if (!String.IsNullOrEmpty(ProvinceName))
                            {
                                CustomerAddress = "<span class='phone'>" + shipto.ShipTo.ToTitleCase() + " (" + ProvinceName + ")</span>";
                            }
                            else
                            {
                                CustomerAddress = "<span class='phone'>" + shipto.ShipTo.ToTitleCase() + "</span>";
                            }
                        }
                        else
                        {
                            error += "<p>- Đơn hàng này gửi xe " + transportCompany + " nhưng <strong>chưa chọn Nơi nhận</strong>!</p>";
                        }

                        DeliveryInfo = String.Format("<p class='delivery'>Xe: {0} {1} {2}</p><p>{3}</p>", transportCompany, transportCompanyPhone, transportCompanyNote, transportCompanyAddress);
                    }
                    else
                    {
                        error += "<p>- Đơn hàng này <strong>gửi xe</strong> nhưng <strong>chưa chọn Chành xe</strong> nào!</p>";
                    }
                }
                // NHÂN VIÊN GIAO
                else if (order.ShippingType == 5)
                {
                    DeliveryInfo = String.Format("<p class='delivery'>Nhân viên giao</p>");
                }
                // GHTK
                else if (order.ShippingType == 6)
                {
                    if (!string.IsNullOrEmpty(order.ShippingCode))
                    {
                        string[] barcode = order.ShippingCode.Split('.');
                        string   newCode = barcode[barcode.Length - 1];
                        if (newCode.Length < 9)
                        {
                            error += "<p>- MÃ VẬN ĐƠN của GHTK phải có ít nhất 9 số ở cuối!</p>";
                        }
                        DeliveryInfo  = String.Format("<p class='delivery'><strong>GHTK:</strong> {0}</p>", order.ShippingCode);
                        DeliveryInfo += String.Format("<p><img src='{0}'></p>", createBarcode(newCode));
                    }
                    else
                    {
                        error += "<p>- Đơn hàng này <strong>gửi GHTK</strong> nhưng <strong>chưa nhập</strong> MÃ VẬN ĐƠN!</p>";
                    }

                    if (order.PaymentType != 3 && acc.RoleID != 0)
                    {
                        PrintButton = "<a class='btn btn-black' href='javascript:;' onclick='printError(`GHTK`)'>Không in được</a>";
                    }
                }
                // VIETTEL
                else if (order.ShippingType == 7)
                {
                    DeliveryInfo = String.Format("<p class='delivery'><strong>Viettel</strong></p>");
                }

                // Lấy tiền THU HỘ
                if (order.PaymentType == 3)
                {
                    ShippingFeeInfo = String.Format("<p class='cod'>Thu hộ: {0}</p>", string.Format("{0:N0}", TotalOrder));
                }
                else
                {
                    ShippingFeeInfo = String.Format("<p class='cod'>Thu hộ: KHÔNG</p>");
                }

                // Lấy phí nhân viên giao
                if (order.ShippingType == 5)
                {
                    if (Convert.ToDouble(order.FeeShipping) > 0)
                    {
                        ShipperFeeInfo = String.Format("<p class='shipping-fee'>Phí ship (đã cộng vào thu hộ): {0}</p>", string.Format("{0:N0}", Convert.ToDouble(order.FeeShipping)));
                    }
                    else
                    {
                        ShipperFeeInfo = String.Format("<p class='shipping-fee'>Phí ship: không</p>");
                    }
                }

                // Lấy số điện thoại 2 nếu có
                string CustomerPhone = order.CustomerPhone;

                if (!string.IsNullOrEmpty(customer.CustomerPhone2))
                {
                    CustomerPhone += " - " + customer.CustomerPhone2;
                }

                // Lấy logo ANN
                string LogoANN = "";
                if (order.ShippingType != 2 && order.ShippingType != 3 && order.ShippingType != 6)
                {
                    LogoANN = String.Format("<img class='img' src='https://ann.com.vn/wp-content/uploads/ANN-logo-3.png'>");
                }

                // Xử lý phiếu GHTK
                string cssClass    = "";
                string bodyClass   = "";
                string destination = "";
                if (order.ShippingType == 6 && !string.IsNullOrEmpty(order.ShippingCode))
                {
                    string[] barcode = order.ShippingCode.Split('.');
                    if (barcode.Length < 6 && barcode.Length > 3)
                    {
                        destination = String.Format("<p>{0}.{1}</p>", barcode[barcode.Length - 3], barcode[barcode.Length - 2]);
                    }
                    else if (barcode.Length >= 6)
                    {
                        destination = String.Format("<p>{0}.{1}.{2}</p>", barcode[barcode.Length - 4], barcode[barcode.Length - 3], barcode[barcode.Length - 2]);
                    }
                }
                if (destination != "")
                {
                    bodyClass = "table-ghtk";
                }

                // HTML in phiếu gửi hàng
                rowHtml += Environment.NewLine + String.Format("<div class='table {0}'>", bodyClass);
                rowHtml += Environment.NewLine + String.Format("    <div class='top-left'>");
                rowHtml += Environment.NewLine + String.Format("        <p>Người gửi: <span class='name'>{0}</span></p>", leader);
                rowHtml += Environment.NewLine + String.Format("        <p>{0}</p>", phone);
                rowHtml += Environment.NewLine + String.Format("        <p class='agent-address'>{0}</p>", address);
                rowHtml += Environment.NewLine + String.Format("        <p class='web'>ANN.COM.VN</p>");
                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("    <div class='bottom-left'>");
                rowHtml += Environment.NewLine + String.Format("    {0}", ShippingFeeInfo);
                rowHtml += Environment.NewLine + String.Format("        <p>Nhân viên: {0}</p>", order.CreatedBy);
                rowHtml += Environment.NewLine + String.Format("        <p><img src='{0}'></p>", createBarcode(order.ID.ToString()));
                rowHtml += Environment.NewLine + String.Format("        <p>Mã đơn hàng: {0}</p>", order.ID);
                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("    <div class='top-right'>");
                rowHtml += Environment.NewLine + String.Format("        {0}", LogoANN);
                rowHtml += Environment.NewLine + String.Format("        {0}", DeliveryInfo);
                rowHtml += Environment.NewLine + String.Format("        {0}", ShippingFeeInfo);
                rowHtml += Environment.NewLine + String.Format("        {0}", ShipperFeeInfo);
                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("    <div class='bottom-right'>");
                rowHtml += Environment.NewLine + String.Format("        <p>Người nhận: <span class='name'>{0}</span></p>", order.CustomerName.ToTitleCase());
                rowHtml += Environment.NewLine + String.Format("        <p>Điện thoại: <span class='phone'>{0}</span></p>", CustomerPhone);
                rowHtml += Environment.NewLine + String.Format("        <p>Địa chỉ: <span class='address'>{0}</span></p>", CustomerAddress);
                rowHtml += Environment.NewLine + String.Format("    </div>");
                if (destination != "")
                {
                    rowHtml += Environment.NewLine + String.Format("    <div class='rotated ghtk'>");
                    rowHtml += Environment.NewLine + String.Format("        {0}", destination);
                    rowHtml += Environment.NewLine + String.Format("    </div>");
                    cssClass = "margin-left-ghtk";
                }
                rowHtml += Environment.NewLine + String.Format("    <div class='rotated {0}'>", cssClass);
                rowHtml += Environment.NewLine + String.Format("        KHO HÀNG SỈ ANN");
                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("</div>");
                // Kết thúc HTML in phiếu gửi hàng
            }

            /// Hiển thị lỗi nếu có
            if (error != "")
            {
                ltrShippingNote.Text = "<h1>Lỗi:</h1>" + error;
            }
            else
            {
                ltrShippingNote.Text = rowHtml;
                ltrPrintButton.Text  = "<div class='print-it'>";
                if (!string.IsNullOrEmpty(PrintButton))
                {
                    ltrPrintButton.Text  += PrintButton;
                    ltrDisablePrint.Text  = "<style type='text/css' media='print'>* { display: none; }</style>";
                    ltrDisablePrint.Text += "<script type='text/javascript'>jQuery(document).bind('keyup keydown', function(e){ if (e.ctrlKey && e.keyCode == 80){ return false;}});</script>";
                }
                else
                {
                    ltrPrintButton.Text += "<a class='btn' href='javascript:;' onclick='printIt()'>In phiếu gửi hàng</a>";
                }
                if (order.ShippingType == 4)
                {
                    ltrPrintButton.Text += "<a class='btn show-transport-info' href='javascript:;' onclick='showTransportInfo()'>Hiện thông tin nhà xe</a>";
                }
                if (order.ShippingType == 3 && order.PaymentType == 3)
                {
                    ltrPrintButton.Text += "<a class='btn show-transport-info' href='https://proship.vn/quan-ly-van-don/?isInvoiceFilter=1&generalInfo=" + order.ShippingCode + "' target='_blank'>Kiểm tra thu hộ trên Proship</a>";
                }
                ltrPrintButton.Text += "</div>";
            }
        }
Example #8
0
        public void LoadData()
        {
            int ID         = Request.QueryString["id"].ToInt(0);
            int mergeprint = 0;

            if (Request.QueryString["merge"] != null)
            {
                mergeprint = Request.QueryString["merge"].ToInt(0);
            }

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

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

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;


                    var orderdetails = OrderDetailController.GetByIDSortBySKU(ID);

                    var numberOfOrders = OrderController.GetByCustomerID(Convert.ToInt32(order.CustomerID));
                    var customer       = CustomerController.GetByID(Convert.ToInt32(order.CustomerID));

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

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

                        productPrint += "<div class='body'>";
                        productPrint += "<div class='table-1'>";
                        string mergeAlert = "";
                        if (mergeprint == 1)
                        {
                            mergeAlert += "<p class='merge-alert'>(Đã gộp sản phẩm)<p>";
                        }
                        productPrint += "<h1>HÓA ĐƠN #" + order.ID + mergeAlert + "</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.ToTitleCase() + "</td>";
                        productPrint += "</tr>";

                        if (!string.IsNullOrEmpty(customer.Nick))
                        {
                            if (order.ShippingType != 1)
                            {
                                productPrint += "<tr>";
                                productPrint += "<td>Nick</td>";
                                productPrint += "<td>" + customer.Nick.ToTitleCase() + "</td>";
                                productPrint += "</tr>";
                            }
                        }

                        productPrint += "<tr>";
                        productPrint += "<td>Điện thoại</td>";
                        productPrint += "<td>" + order.CustomerPhone + "</td>";
                        productPrint += "</tr>";

                        if (order.ExcuteStatus == 2 && !string.IsNullOrEmpty(order.DateDone.ToString()))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Ngày hoàn tất</td>";
                            string datedone = string.Format("{0:dd/MM/yyyy HH:mm}", order.DateDone);
                            productPrint += "<td>" + datedone + "</td>";
                            productPrint += "</tr>";
                        }
                        else
                        {
                            error += "Đơn hàng chưa hoàn tất";
                        }

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

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

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

                        productPrint += "<div class='table-2'>";
                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class='soluong' />";
                        productPrint += "<col class='gia' />";
                        productPrint += "<col class='tong' />";
                        productPrint += "</colgroup>";
                        productPrint += "<thead>";
                        productPrint += "<th>Số lượng</th>";
                        productPrint += "<th>Giá</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>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan='2'>Thành tiền</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "&nbsp;</td>";
                        productPrint += "</tr>";

                        double TotalPrice = TotalOrder;

                        if (order.DiscountPerProduct > 0)
                        {
                            var TotalDiscount = Convert.ToDouble(order.DiscountPerProduct) * Convert.ToDouble(TotalQuantity);
                            TotalOrder    = TotalOrder - TotalDiscount;
                            TotalPrice    = TotalPrice - TotalDiscount;
                            productPrint += "<tr>";
                            productPrint += "<td colspan='2'>Chiết khấu mỗi cái </td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.DiscountPerProduct)) + "&nbsp;</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan='2'>Trừ tổng chiết khấu</td>";
                            productPrint += "<td>-" + string.Format("{0:N0}", TotalDiscount) + "&nbsp;</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan='2'>Sau chiết khấu</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "&nbsp;</td>";
                            productPrint += "</tr>";
                        }

                        if (order.RefundsGoodsID != null)
                        {
                            var refund = RefundGoodController.GetByID(Convert.ToInt32(order.RefundsGoodsID));
                            if (refund != null)
                            {
                                TotalOrder = TotalOrder - Convert.ToDouble(refund.TotalPrice);

                                productPrint += "<tr>";
                                productPrint += "<td colspan='2'>Trừ hàng trả (đơn " + order.RefundsGoodsID + ")</td>";
                                productPrint += "<td>-" + string.Format("{0:N0}", Convert.ToDouble(refund.TotalPrice)) + "&nbsp;</td>";
                                productPrint += "</tr>";

                                productPrint += "<tr>";
                                productPrint += "<td colspan='2'>Tổng tiền còn lại</td>";
                                productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "&nbsp;</td>";
                                productPrint += "</tr>";
                            }
                            else
                            {
                                error += "Không tìm thấy đơn hàng đổi trả " + order.RefundsGoodsID.ToString();
                            }
                        }


                        if (Convert.ToDouble(order.FeeShipping) > 0)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(order.FeeShipping);
                            TotalPrice    = TotalPrice + Convert.ToDouble(order.FeeShipping);
                            productPrint += "<tr>";
                            productPrint += "<td colspan='2'>Phí vận chuyển</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.FeeShipping)) + "&nbsp;</td>";
                            productPrint += "</tr>";
                        }

                        // Check fee
                        var fees = FeeController.getFeeInfo(ID);
                        foreach (var fee in fees)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(fee.Price);
                            TotalPrice    = TotalPrice + Convert.ToDouble(fee.Price);
                            productPrint += "<tr>";
                            productPrint += "<td colspan='2'>" + fee.Name + "</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(fee.Price)) + "&nbsp;</td>";
                            productPrint += "</tr>";
                        }

                        // Giảm giá
                        if (order.CouponID.HasValue && order.CouponID.Value > 0)
                        {
                            var coupon = CouponController.getCoupon(order.CouponID.Value);

                            TotalOrder    = TotalOrder - Convert.ToDouble(coupon.Value);
                            TotalPrice    = TotalPrice - Convert.ToDouble(coupon.Value);
                            productPrint += "<tr>";
                            productPrint += String.Format("<td colspan='2'>Mã giảm giá: {0}</td>", coupon.Code);
                            productPrint += String.Format("<td>-{0:N0}&nbsp;</td>", Convert.ToDouble(coupon.Value));
                            productPrint += "</tr>";
                        }


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

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


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


                        string address  = "";
                        string phone    = "";
                        string facebook = "";
                        var    agent    = AgentController.GetByID(Convert.ToInt32(order.AgentID));
                        if (agent != null)
                        {
                            address  = agent.AgentAddress;
                            phone    = agent.AgentPhone;
                            facebook = agent.AgentFacebook;
                        }

                        var acc = AccountController.GetByUsername(order.CreatedBy);
                        if (acc != null)
                        {
                            var accountInfo = AccountInfoController.GetByUserID(acc.ID);
                            if (accountInfo != null)
                            {
                                if (!string.IsNullOrEmpty(accountInfo.Phone))
                                {
                                    phone = accountInfo.Phone;
                                }
                            }
                        }

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

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

                        if (numberOfOrders.Count < 4)
                        {
                            shtml += "<div class='head'>";
                            shtml += "<div class='logo'><div class='img'><img src='App_Themes/Ann/image/logo.png' /></div></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 class='ct'>";
                            shtml += "<div class='ct-title'></div>";
                            shtml += "<div class='ct-detail'>http://ann.com.vn</div>";
                            shtml += "</div>";

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

                        shtml += productPrint;

                        if (numberOfOrders.Count < 4)
                        {
                            var    config = ConfigController.GetByTop1();
                            string rule   = "";
                            if (order.OrderType == 2)
                            {
                                rule = config.ChangeGoodsRule;
                            }
                            else
                            {
                                rule = config.RetailReturnRule;
                            }

                            shtml += "<div class='footer'><h3>CẢM ƠN QUÝ KHÁCH! HẸN GẶP LẠI !</h3></div> ";
                            shtml += "<div class='footer'>" + rule + "</div> ";
                        }
                        else
                        {
                            shtml += "<div class='footer'>";
                            shtml += "<p>ANN rất vui khi quý khách đã mua " + numberOfOrders.Count + " đơn hàng!</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!!!";
            }
        }
Example #9
0
        public void LoadData()
        {
            int ID         = Request.QueryString["id"].ToInt(0);
            int mergeprint = 0;

            if (Request.QueryString["merge"] != null)
            {
                mergeprint = Request.QueryString["merge"].ToInt(0);
            }

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

                if (order != null)
                {
                    #region Lấy ghi chú đơn hàng cũ

                    var oldOrders = OrderController.GetAllNoteByCustomerID(Convert.ToInt32(order.CustomerID), ID);
                    if (oldOrders.Count() > 1)
                    {
                        StringBuilder notestring = new StringBuilder();
                        foreach (var item in oldOrders)
                        {
                            notestring.AppendLine(String.Format("<li>Đơn <strong><a href='/thong-tin-don-hang?id={0}' target='_blank'>{0}</a></strong> (<em>{1}<em>): {2}</li>", item.ID, item.DateDone, item.OrderNote));
                        }

                        StringBuilder notehtml = new StringBuilder();
                        notehtml.AppendLine("<div id='old-order-note'>");
                        notehtml.AppendLine("   <h2>" + oldOrders.Count() + " đơn hàng cũ gần nhất có ghi chú:</h2>");
                        notehtml.AppendLine("   <ul>");
                        notehtml.AppendLine(String.Format("{0}", notestring));
                        notehtml.AppendLine("   </ul>");
                        notehtml.AppendLine("</div>");

                        ltrOldOrderNote.Text = notehtml.ToString();
                    }

                    #endregion

                    ltrCopyInvoiceURL.Text = "<a href='javascript:;' onclick='copyInvoiceURL(" + order.ID + ", " + order.CustomerID + ")' title='Copy link hóa đơn' class='btn btn-violet h45-btn'>Copy link hóa đơn</a>";

                    string error = "";
                    string Print = "";

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;

                    var orderdetails = OrderDetailController.GetByIDSortBySKU(ID);

                    var numberOfOrders = OrderController.GetByCustomerID(Convert.ToInt32(order.CustomerID));

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

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

                        productPrint += "<div class=\"body\">";
                        productPrint += "<div class=\"table-1\">";
                        productPrint += "<h1>XÁC NHẬN ĐƠN HÀNG #" + order.ID + "</h1>";
                        productPrint += "<div class=\"note\">";
                        productPrint += "<p>- Lưu ý, hình ảnh sản phẩm có thể hiển thị không đúng màu.</p>";
                        productPrint += "<p>- Quý khách vui lòng kiểm tra thuộc tính sản phẩm (Màu, Size).</p>";
                        productPrint += "<p>- Nếu có sai sót, quý khách vui lòng 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>";

                        if (!string.IsNullOrEmpty(order.DateDone.ToString()))
                        {
                            productPrint += "<tr>";
                            productPrint += "<td>Hoàn tất</td>";
                            string datedone = string.Format("{0:dd/MM/yyyy HH:mm}", order.DateDone);
                            productPrint += "<td>" + datedone + "</td>";
                        }

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

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

                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";
                        productPrint += "<div class=\"table-2\">";
                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class=\"order-item\" />";

                        if (mergeprint == 0)
                        {
                            productPrint += "<col class=\"image\" />";
                        }

                        productPrint += "<col class=\"name\" />";
                        productPrint += "<col class=\"quantity\" />";
                        productPrint += "<col class=\"price\" />";
                        productPrint += "<col class=\"subtotal\"/>";
                        productPrint += "</colgroup>";
                        productPrint += "<thead>";
                        productPrint += "<th>#</th>";

                        if (mergeprint == 0)
                        {
                            productPrint += "<th>Hình ảnh</th>";
                        }

                        productPrint += "<th>Sản phẩm</th>";
                        productPrint += "<th>SL</th>";
                        productPrint += "<th>Giá</th>";
                        productPrint += "<th>Tổng</th>";
                        productPrint += "</thead>";
                        productPrint += "<tbody>";
                        productPrint += Print;
                        productPrint += "<tr>";

                        string colspan = "5";
                        if (mergeprint == 1)
                        {
                            colspan = "4";
                        }

                        productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Số lượng</td>";
                        productPrint += "<td>" + TotalQuantity + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Thành tiền</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";

                        double TotalPrice = TotalOrder;

                        if (order.DiscountPerProduct > 0)
                        {
                            var TotalDiscount = Convert.ToDouble(order.DiscountPerProduct) * Convert.ToDouble(TotalQuantity);
                            TotalOrder    = TotalOrder - TotalDiscount;
                            TotalPrice    = TotalPrice - TotalDiscount;
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Chiết khấu mỗi cái </td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.DiscountPerProduct)) + "</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Trừ tổng chiết khấu</td>";
                            productPrint += "<td>-" + string.Format("{0:N0}", TotalDiscount) + "</td>";
                            productPrint += "</tr>";
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Sau chiết khấu</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                            productPrint += "</tr>";
                        }

                        if (order.RefundsGoodsID != null && order.RefundsGoodsID != 0)
                        {
                            var refund = RefundGoodController.GetByID(Convert.ToInt32(order.RefundsGoodsID));
                            if (refund != null)
                            {
                                TotalOrder = TotalOrder - Convert.ToDouble(refund.TotalPrice);

                                productPrint += "<tr>";
                                productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Trừ hàng trả (đơn " + order.RefundsGoodsID + ")</td>";
                                productPrint += "<td>-" + string.Format("{0:N0}", Convert.ToDouble(refund.TotalPrice)) + "</td>";
                                productPrint += "</tr>";

                                productPrint += "<tr>";
                                productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Tổng tiền còn lại</td>";
                                productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "</td>";
                                productPrint += "</tr>";
                            }
                            else
                            {
                                error += "Không tìm thấy đơn hàng đổi trả " + order.RefundsGoodsID.ToString();
                            }
                        }

                        if (Convert.ToDouble(order.FeeShipping) > 0)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(order.FeeShipping);
                            TotalPrice    = TotalPrice + Convert.ToDouble(order.FeeShipping);
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">Phí vận chuyển</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(order.FeeShipping)) + "</td>";
                            productPrint += "</tr>";
                        }

                        // Check fee
                        var fees = FeeController.getFeeInfo(ID);
                        foreach (var fee in fees)
                        {
                            TotalOrder    = TotalOrder + Convert.ToDouble(fee.Price);
                            TotalPrice    = TotalPrice + Convert.ToDouble(fee.Price);
                            productPrint += "<tr>";
                            productPrint += "<td colspan=\"" + colspan + "\" class=\"align-right\">" + fee.Name + "</td>";
                            productPrint += "<td>" + string.Format("{0:N0}", Convert.ToDouble(fee.Price)) + "</td>";
                            productPrint += "</tr>";
                        }

                        // Giảm giá
                        if (order.CouponID.HasValue && order.CouponID.Value > 0)
                        {
                            var coupon = CouponController.getCoupon(order.CouponID.Value);

                            TotalOrder    = TotalOrder - Convert.ToDouble(coupon.Value);
                            TotalPrice    = TotalPrice - Convert.ToDouble(coupon.Value);
                            productPrint += "<tr>";
                            productPrint += String.Format("<td colspan='{0}' class='align-right'>Mã giảm giá: {1}</td>", colspan, coupon.Code);
                            productPrint += String.Format("<td>-{0:N0}</td>", Convert.ToDouble(coupon.Value));
                            productPrint += "</tr>";
                        }

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

                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"" + colspan + "\" class=\"strong align-right\">TỔNG CỘ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.DateDone);

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


                        if (numberOfOrders.Count < 4)
                        {
                            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;
                            }

                            var acc = AccountController.GetByUsername(order.CreatedBy);
                            if (acc != null)
                            {
                                var accountInfo = AccountInfoController.GetByUserID(acc.ID);
                                if (accountInfo != null)
                                {
                                    if (!string.IsNullOrEmpty(accountInfo.Phone))
                                    {
                                        phone = accountInfo.Phone;
                                    }
                                }
                            }

                            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 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!!!";
            }
        }
Example #11
0
        public void LoadData()
        {
            string username = Request.Cookies["userLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            string error = "";

            int ID = Request.QueryString["id"].ToInt(0);

            String rowHtml = String.Empty;

            var order = OrderController.GetByID(ID);

            if (order != null)
            {
                if (order.PaymentStatus == 1)
                {
                    error += "<p>- Đơn hàng này <strong>chưa thanh toán</strong>!</p>";
                }

                if (order.ExcuteStatus != 2)
                {
                    error += "<p>- Đơn hàng này <strong>chưa hoàn tất</strong>!</p>";
                }

                if (order.ShippingType == 1)
                {
                    error += "<p>- Đơn hàng này đang có phương thức giao hàng: <strong>Lấy trực tiếp</strong>. Hãy chuyển sang phương thức khác!</p>";
                }

                string address = "";
                string phone   = "0914615408 - 0918567409";
                string leader  = "";
                var    agent   = AgentController.GetByID(Convert.ToInt32(order.AgentID));

                if (agent != null)
                {
                    address = agent.AgentAddress;
                    leader  = agent.AgentLeader;
                }

                double TotalOrder = Convert.ToDouble(order.TotalPrice);

                if (order.RefundsGoodsID != null)
                {
                    var refund = RefundGoodController.GetByID(Convert.ToInt32(order.RefundsGoodsID));
                    if (refund != null)
                    {
                        TotalOrder = TotalOrder - Convert.ToDouble(refund.TotalPrice);
                    }
                    else
                    {
                        error += "<p>Không tìm thấy đơn hàng đổi trả " + order.RefundsGoodsID.ToString() + " (có thể đã bị xóa khi làm lại đơn đổi trả). Thêm lại đơn hàng đổi trả nhé!</p>";
                    }
                }

                rowHtml += Environment.NewLine + String.Format("<div class=\"table\">");
                rowHtml += Environment.NewLine + String.Format("    <div class=\"top-left\">");
                rowHtml += Environment.NewLine + String.Format("        <p><span>Người gửi: <span class=\"name\">{0}</span></span></p>", leader);
                rowHtml += Environment.NewLine + String.Format("        <p><span>{0}</span></p>", phone);
                rowHtml += Environment.NewLine + String.Format("        <p><span>{0}</span></p>", address);
                rowHtml += Environment.NewLine + String.Format("        <p><span class=\"web\">ANN.COM.VN</span></p>");
                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("    <div class=\"bottom-left\">");
                if (order.PaymentType == 3)
                {
                    rowHtml += Environment.NewLine + String.Format("        <p><span class=\"cod\">Thu hộ: {0}</span></p>", string.Format("{0:N0}", TotalOrder));
                }
                else
                {
                    rowHtml += Environment.NewLine + String.Format("        <p><span class=\"cod\">Thu hộ: KHÔNG</span></p>");
                }

                rowHtml += Environment.NewLine + String.Format("        <p><span>Mã đơn hàng: {0}</span></p>", order.ID);
                rowHtml += Environment.NewLine + String.Format("        <p><span>Nhân viên: {0}</span></p>", order.CreatedBy);

                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("    <div class=\"top-right\">");
                rowHtml += Environment.NewLine + String.Format("        <img class=\"img\" src=\"https://ann.com.vn/wp-content/uploads/ANN-logo-3.png\">");

                var    company                 = TransportCompanyController.GetTransportCompanyByID(Convert.ToInt32(order.TransportCompanyID));
                string transportCompany        = "";
                string transportCompanyPhone   = "";
                string transportCompanyAddress = "";
                string transportCompanyNote    = "";

                string CustomerAddress = order.CustomerAddress;

                if (company != null)
                {
                    transportCompany = "<strong>" + company.CompanyName + "</strong>";
                    if (company.CompanyPhone != "")
                    {
                        transportCompanyPhone = "<span class=\"transport-info\">(" + company.CompanyPhone + ")</span>";
                    }

                    transportCompanyAddress = "<p class=\"transport-info capitalize\">" + company.CompanyAddress + "</p>";

                    if (company.Note != "")
                    {
                        transportCompanyNote = "<span class=\"transport-info capitalize\"> - " + company.Note + "</span>";
                    }

                    var subID  = Convert.ToInt32(order.TransportCompanySubID);
                    var shipto = TransportCompanyController.GetReceivePlaceByID(company.ID, subID);
                    if (shipto != null && subID > 0)
                    {
                        CustomerAddress = "<span class=\"phone\">" + shipto.ShipTo + "</span>";
                    }
                    else
                    {
                        error += "<p>- Đơn hàng này gửi chành xe " + transportCompany + " nhưng <strong>chưa chọn Nơi nhận</strong>!</p>";
                    }
                }

                if (order.ShippingType == 2)
                {
                    string PostalDeliveryType = "Thường";
                    if (order.PostalDeliveryType == 2)
                    {
                        PostalDeliveryType = "Nhanh";
                    }

                    if (!string.IsNullOrEmpty(order.ShippingCode))
                    {
                        rowHtml += Environment.NewLine + String.Format("        <p class=\"delivery\"><span><strong>Gửi Bưu điện - {0}:</strong> {1}</span></p>", PostalDeliveryType, order.ShippingCode);
                    }
                    else
                    {
                        error += "<p>- Đơn hàng này <strong>gửi Bưu điện</strong> nhưng <strong>chưa nhập</strong> MÃ VẬN ĐƠN!</p>";
                    }

                    if (order.PaymentType != 3 && acc.RoleID != 0)
                    {
                        error += "<p>- Đơn hàng này <strong>gửi Bưu điện</strong> nhưng <strong>Không gửi thu hộ</strong>. Nếu có lý do thì báo chị Ngọc xử lý nhé!</p>";
                    }
                }
                else if (order.ShippingType == 3)
                {
                    rowHtml += Environment.NewLine + String.Format("        <p class=\"delivery\"><span>Dịch vụ ship</span></p>");
                    if (!string.IsNullOrEmpty(order.ShippingCode))
                    {
                        rowHtml += Environment.NewLine + String.Format("        <p class=\"delivery\"><span>{0}</span></p>", order.ShippingCode);
                    }
                    else
                    {
                        error += "<p>- Đơn hàng này <strong>gửi Dịch vụ ship</strong> nhưng <strong>chưa nhập</strong> MÃ VẬN ĐƠN!</p>";
                    }
                }
                else if (order.ShippingType == 4)
                {
                    if (transportCompany == "")
                    {
                        error += "<p>- Đơn hàng này <strong>gửi xe</strong> nhưng <strong>chưa chọn Chành xe</strong> nào!</p>";
                    }
                    else
                    {
                        rowHtml += Environment.NewLine + String.Format("        <p class=\"delivery\"><span>Gửi xe: {0} {1} {2}</p>", transportCompany, transportCompanyPhone, transportCompanyNote);

                        // Lấy thông tin xe ra gửi
                        rowHtml += Environment.NewLine + String.Format("        {0}", transportCompanyAddress);
                    }
                }
                else if (order.ShippingType == 5)
                {
                    rowHtml += Environment.NewLine + String.Format("        <p class=\"delivery\"><span>Nhân viên giao hàng</span></p>");
                }

                if (order.PaymentType == 3)
                {
                    rowHtml += Environment.NewLine + String.Format("        <p><span class=\"cod\">Thu hộ: {0}</span></p>", string.Format("{0:N0}", TotalOrder));
                }
                else
                {
                    rowHtml += Environment.NewLine + String.Format("        <p><span class=\"cod\">Thu hộ: KHÔNG</span></p>");
                }
                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("    <div class=\"bottom-right\">");
                rowHtml += Environment.NewLine + String.Format("        <p><span>Người nhận: <span class=\"name\">{0}</span></span></p>", order.CustomerName);

                string CustomerPhone2 = "";

                var customer = CustomerController.GetByID(Convert.ToInt32(order.CustomerID));
                if (!string.IsNullOrEmpty(customer.CustomerPhone2))
                {
                    CustomerPhone2 = " - " + customer.CustomerPhone2;
                }

                rowHtml += Environment.NewLine + String.Format("        <p><span>Điện thoại: <span class=\"phone\">{0}{1}</span></span></p>", order.CustomerPhone, CustomerPhone2);
                rowHtml += Environment.NewLine + String.Format("        <p><span>Địa chỉ: <span class=\"address\">{0}</span></span></p>", CustomerAddress);
                rowHtml += Environment.NewLine + String.Format("    </div>");
                rowHtml += Environment.NewLine + String.Format("</div>");
            }
            else
            {
                error += "Không tìm thấy đơn hàng!";
            }

            if (error != "")
            {
                ltrShippingNote.Text = "<h1>Lỗi:</h1>" + error;
            }
            else
            {
                ltrShippingNote.Text = rowHtml;
                ltrPrintButton.Text  = "<div class=\"print-it\">";
                ltrPrintButton.Text += "<a class=\"btn\" href=\"javascript:;\" onclick=\"printIt()\">In phiếu gửi hàng</a>";
                if (order.ShippingType == 4)
                {
                    ltrPrintButton.Text += "<a class=\"btn show-transport-info\" href=\"javascript:;\" onclick=\"showTransportInfo()\">Hiện thông tin nhà xe</a>";
                }
                ltrPrintButton.Text += "</div>";
            }
        }
Example #12
0
        public void pagingall(List <OrderList> acs)
        {
            string username = Request.Cookies["userLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            int PageSize = 30;

            StringBuilder html = new StringBuilder();

            html.Append("<tr>");
            html.Append("    <th>Mã</th>");
            html.Append("    <th>Loại</th>");
            html.Append("    <th class='col-customer'>Khách hàng</th>");
            html.Append("    <th>Mua</th>");
            html.Append("    <th>Xử lý</th>");
            html.Append("    <th>Thanh toán</th>");
            html.Append("    <th>Thanh toán</th>");
            html.Append("    <th>Giao hàng</th>");
            html.Append("    <th>Tổng tiền</th>");
            if (acc.RoleID == 0)
            {
                html.Append("    <th>Nhân viên</th>");
            }
            html.Append("    <th>Ngày tạo</th>");
            html.Append("    <th>Hoàn tất</th>");
            html.Append("    <th></th>");
            html.Append("</tr>");

            if (acs.Count > 0)
            {
                int TotalItems = acs.Count;
                if (TotalItems % PageSize == 0)
                {
                    PageCount = TotalItems / PageSize;
                }
                else
                {
                    PageCount = TotalItems / PageSize + 1;
                }

                Int32 Page = GetIntFromQueryString("Page");

                if (Page == -1)
                {
                    Page = 1;
                }
                int FromRow = (Page - 1) * PageSize;
                int ToRow   = Page * PageSize - 1;
                if (ToRow >= TotalItems)
                {
                    ToRow = TotalItems - 1;
                }


                for (int i = FromRow; i < ToRow + 1; i++)
                {
                    var item = acs[i];
                    html.Append("<tr>");
                    html.Append("   <td><a href=\"/thong-tin-don-hang?id=" + item.ID + "\">" + item.ID + "</a></td>");
                    html.Append("   <td>" + PJUtils.OrderTypeStatus(Convert.ToInt32(item.OrderType)) + "</td>");

                    if (!string.IsNullOrEmpty(item.Nick))
                    {
                        html.Append("   <td><a class=\"col-customer-name-link capitalize\" href=\"/thong-tin-don-hang?id=" + item.ID + "\">" + item.Nick + "</a><br><span class=\"name-bottom-nick\">(" + item.CustomerName + ")</span></td>");
                    }
                    else
                    {
                        html.Append("   <td><a class=\"col-customer-name-link capitalize\" href=\"/thong-tin-don-hang?id=" + item.ID + "\">" + item.CustomerName + "</a></td>");
                    }

                    html.Append("   <td>" + item.Quantity + "</td>");
                    html.Append("   <td>" + PJUtils.OrderExcuteStatus(Convert.ToInt32(item.ExcuteStatus)) + "</td>");
                    html.Append("   <td>" + PJUtils.OrderPaymentStatus(Convert.ToInt32(item.PaymentStatus)) + "</td>");
                    html.Append("   <td>" + PJUtils.PaymentType(Convert.ToInt32(item.PaymentType)) + "</td>");
                    html.Append("   <td>" + PJUtils.ShippingType(Convert.ToInt32(item.ShippingType)) + "</td>");
                    html.Append("   <td><strong>" + string.Format("{0:N0}", Convert.ToDouble(item.TotalPrice)) + "</strong></td>");

                    if (acc.RoleID == 0)
                    {
                        html.Append("   <td>" + item.CreatedBy + "</td>");
                    }

                    string date = string.Format("{0:dd/MM}", item.CreatedDate);
                    html.Append("   <td>" + date + "</td>");

                    string datedone = "";
                    if (item.ExcuteStatus == 2)
                    {
                        datedone = string.Format("{0:dd/MM}", item.DateDone);
                    }
                    html.Append("   <td>" + datedone + "</td>");

                    html.Append("   <td>");
                    html.Append("       <a href=\"/print-invoice?id=" + item.ID + "\" title=\"In hóa đơn\" target=\"_blank\" class=\"btn primary-btn h45-btn\"><i class=\"fa fa-print\" aria-hidden=\"true\"></i></a>");
                    html.Append("       <a href=\"/print-shipping-note?id=" + item.ID + "\" title=\"In phiếu gửi hàng\" target=\"_blank\" class=\"btn primary-btn btn-red h45-btn\"><i class=\"fa fa-file-text-o\" aria-hidden=\"true\"></i></a>");
                    html.Append("       <a href=\"/chi-tiet-khach-hang?id=" + item.CustomerID + "\" title=\"Thông tin khách hàng " + item.CustomerName + "\" target=\"_blank\" class=\"btn primary-btn btn-black h45-btn\"><i class=\"fa fa-user-circle\" aria-hidden=\"true\"></i></a>");
                    html.Append("   </td>");
                    html.Append("</tr>");

                    // thông tin thêm

                    html.Append("<tr class='tr-more-info'>");
                    html.Append("   <td colspan='2'>");
                    html.Append("   </td>");
                    html.Append("   <td colspan='11'>");

                    if (item.RefundsGoodsID != null)
                    {
                        var refund = RefundGoodController.GetByID(Convert.ToInt32(item.RefundsGoodsID));
                        if (refund != null)
                        {
                            html.Append("<span class='order-info'><strong>Trừ hàng trả:</strong> " + string.Format("{0:N0}", Convert.ToDouble(refund.TotalPrice)) + " (<a href='xem-don-hang-doi-tra?id=" + item.RefundsGoodsID + "' target='_blank'>Xem đơn " + item.RefundsGoodsID + "</a>)</span>");
                        }
                    }
                    if (item.TotalDiscount > 0)
                    {
                        html.Append("<span class='order-info'><strong>Chiết khấu:</strong> " + string.Format("{0:N0}", Convert.ToDouble(item.TotalDiscount)) + "</span>");
                    }
                    if (item.OtherFeeValue != 0)
                    {
                        html.Append("<span class='order-info'><strong>Phí khác:</strong> " + string.Format("{0:N0}", Convert.ToDouble(item.OtherFeeValue)) + " (" + item.OtherFeeName.Trim() + ")</span>");
                    }
                    if (item.FeeShipping > 0)
                    {
                        html.Append("<span class='order-info'><strong>Phí vận chuyển:</strong> " + string.Format("{0:N0}", Convert.ToDouble(item.FeeShipping)) + "</span>");
                    }
                    if (!string.IsNullOrEmpty(item.ShippingCode))
                    {
                        string moreInfo = "";
                        if (item.ShippingType == 3)
                        {
                            moreInfo = " (<a href='https://proship.vn/quan-ly-van-don/?isInvoiceFilter=1&amp;generalInfo=" + item.ShippingCode + "' target='_blank'>Xem</a>)";
                        }
                        if (item.ShippingType == 2)
                        {
                            moreInfo = " (Chuyển " + ((item.PostalDeliveryType == 1) ? "thường" : "nhanh") + ")";
                        }
                        html.Append("<span class='order-info'><strong>Mã vận đơn:</strong> " + item.ShippingCode + moreInfo + "</span>");
                    }
                    if (item.ShippingType == 4)
                    {
                        if (item.TransportCompanyID != 0)
                        {
                            var transport    = TransportCompanyController.GetTransportCompanyByID(Convert.ToInt32(item.TransportCompanyID));
                            var transportsub = TransportCompanyController.GetReceivePlaceByID(Convert.ToInt32(item.TransportCompanyID), Convert.ToInt32(item.TransportCompanySubID));
                            html.Append("<span class='order-info'><strong>Gửi xe: </strong> " + transport.CompanyName + " (" + transportsub.ShipTo + ")</span>");
                        }
                    }
                    if (!string.IsNullOrEmpty(item.OrderNote))
                    {
                        html.Append("<span class='order-info'><strong>Ghi chú:</strong> " + item.OrderNote + "</span>");
                    }
                    html.Append("   </td>");
                    html.Append("</tr>");
                }
            }
            else
            {
                if (acc.RoleID == 0)
                {
                    html.Append("<tr><td colspan=\"13\">Không tìm thấy đơn hàng...</td></tr>");
                }
                else
                {
                    html.Append("<tr><td colspan=\"12\">Không tìm thấy đơn hàng...</td></tr>");
                }
            }

            ltrList.Text = html.ToString();
        }