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

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

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

                HttpContext.Current.Items.Add("xem-don-hang-doi-tra", JsonConvert.SerializeObject(_refundGood));
                Server.Transfer("tao-don-hang-doi-tra.aspx");
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public void LoadData()
        {
            DateTime fromdate = DateTime.Today;
            DateTime todate   = fromdate.AddDays(1).AddMinutes(-1);

            if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
            {
                fromdate = Convert.ToDateTime(Request.QueryString["fromdate"]);
            }

            if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
            {
                todate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
            }

            rFromDate.SelectedDate = fromdate;
            rToDate.SelectedDate   = todate;

            int day = Convert.ToInt32((todate - fromdate).TotalDays);

            int TotalSales = 0;
            var order      = OrderDetailController.Report(fromdate.ToString(), todate.ToString());

            if (order != null)
            {
                foreach (var item in order)
                {
                    TotalSales += Convert.ToInt32(item.Quantity);
                }
            }

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

            if (refund.Count() > 0)
            {
                foreach (var vl in refund)
                {
                    TotalRefund += Convert.ToInt32(vl.TotalQuantity);
                }
            }

            ltrTotalRemain.Text        = (TotalSales - TotalRefund).ToString() + " cái";
            ltrAverageTotalRemain.Text = ((TotalSales - TotalRefund) / day).ToString() + " cái / ngày";
            ltrTotalSales.Text         = TotalSales.ToString() + " cái";
            ltrAverageTotalSales.Text  = (TotalSales / day).ToString() + " cái / ngày";
            ltrTotalRefund.Text        = TotalRefund.ToString() + " cái";
            ltrAverageTotalRefund.Text = (TotalRefund / day).ToString() + " cái / ngày";
        }
Beispiel #3
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            string username = Request.Cookies["userLoginSystem"].Value;
            var    a        = AccountController.GetByUsername(username);

            if (a != null)
            {
                var re = RefundGoodController.updatestatus((ViewState["ID"].ToString()).ToInt(), Convert.ToInt32(ddlRefundStatus.SelectedValue), DateTime.Now, a.Username, txtRefundsNote.Text);
                if (re != null)
                {
                    PJUtils.ShowMessageBoxSwAlert("Cập nhật đơn hàng đổi trả thành công", "s", true, Page);
                }
                else
                {
                    PJUtils.ShowMessageBoxSwAlert("Thất bại", "e", false, Page);
                }
            }
        }
Beispiel #4
0
        public static string checkOrderOld(int customerID, int status = 1)
        {
            var customer    = CustomerController.GetByID(customerID);
            var order       = OrderController.GetByCustomerID(customerID, status);
            int orderReturn = RefundGoodController.GetByCustomerID(customerID, status);
            var serializer  = new JavaScriptSerializer();

            if (customer != null)
            {
                return(serializer.Serialize(new
                {
                    phone = customer.CustomerPhone,
                    numberOrder = order.Count,
                    numberOrderReturn = orderReturn
                }));
            }
            else
            {
                return("null");
            }
        }
Beispiel #5
0
        public static string getReturnOrder(string order, string remove)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            if (remove.ToInt() == 0)
            {
                var or = RefundGoodController.GetOrderByID(order.ToInt());
                if (or != null)
                {
                    HttpContext.Current.Response.Cookies["refund"].Value = or.ID + "|" + or.TotalPrice;
                    return(serializer.Serialize(or));
                }
                else
                {
                    return(serializer.Serialize(null));
                }
            }
            else
            {
                HttpContext.Current.Response.Cookies["refund"].Value = "1";
                return(serializer.Serialize(null));
            }
        }
        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;

                    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!!!";
            }
        }
Beispiel #8
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 2)
                {
                    int    AgentID     = Convert.ToInt32(acc.AgentID);
                    int    OrderType   = hdfOrderType.Value.ToInt();
                    string AdditionFee = "0";
                    string DisCount    = "0";
                    int    CustomerID  = 0;

                    string CustomerPhone   = txtPhone.Text.Trim().Replace(" ", "");
                    string CustomerName    = txtFullname.Text.Trim();
                    string Nick            = txtNick.Text.Trim();
                    string CustomerAddress = txtAddress.Text.Trim();
                    string Zalo            = txtZalo.Text.Trim();
                    string Facebook        = txtFacebook.Text.Trim();
                    int    PaymentStatus   = hdfPaymentStatus.Value.ToInt(1);
                    int    ExcuteStatus    = hdfExcuteStatus.Value.ToInt(1);
                    int    PaymentType     = hdfPaymentType.Value.ToInt(1);
                    int    ShippingType    = hdfShippingType.Value.ToInt(1);

                    var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                    if (checkCustomer != null)
                    {
                        CustomerID = checkCustomer.ID;
                        string kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2);
                    }
                    else
                    {
                        string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, "", 0, 0, currentDate, username, false, Zalo, Facebook, "", "", Nick, "", ShippingType, PaymentType);
                        if (kq.ToInt(0) > 0)
                        {
                            CustomerID = kq.ToInt();
                        }
                    }

                    var Customer = CustomerController.GetByID(CustomerID);

                    int TransportCompanyID    = 0;
                    int TransportCompanySubID = 0;
                    if (Customer.ShippingType == ShippingType)
                    {
                        TransportCompanyID    = Convert.ToInt32(Customer.TransportCompanyID);
                        TransportCompanySubID = Convert.ToInt32(Customer.TransportCompanySubID);
                    }

                    string totalPrice            = hdfTotalPrice.Value.ToString();
                    string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value;


                    double DiscountPerProduct = Convert.ToDouble(pDiscount.Value);

                    double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value);
                    string FeeShipping   = pFeeShip.Value.ToString();

                    string OtherFeeName  = txtOtherFeeName.Text;
                    double OtherFeeValue = Convert.ToDouble(pOtherFee.Value);

                    bool IsHidden = false;
                    int  WayIn    = 1;

                    string datedone = "";

                    if (ExcuteStatus == 2)
                    {
                        datedone = DateTime.Now.ToString();
                    }

                    var ret = OrderController.Insert(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress,
                                                     "", totalPrice, totalPriceNotDiscount, PaymentStatus, ExcuteStatus, IsHidden, WayIn, currentDate, username, Convert.ToDouble(pDiscount.Value),
                                                     TotalDiscount, FeeShipping, PaymentType, ShippingType, datedone, 0, 0, TransportCompanyID, TransportCompanySubID, OtherFeeName, OtherFeeValue, 1);

                    int OrderID = ret.ID;

                    double totalQuantity = 0;
                    if (OrderID > 0)
                    {
                        string   list  = hdfListProduct.Value;
                        string[] items = list.Split(';');
                        if (items.Length - 1 > 0)
                        {
                            for (int i = 0; i < items.Length - 1; i++)
                            {
                                var      item      = items[i];
                                string[] itemValue = item.Split(',');

                                int    ProductID         = itemValue[0].ToInt();
                                int    ProductVariableID = itemValue[11].ToInt();
                                string SKU         = itemValue[1].ToString();
                                int    ProductType = itemValue[2].ToInt();

                                // Tìm parentID
                                int parentID = ProductID;
                                var variable = ProductVariableController.GetByID(ProductVariableID);
                                if (variable != null)
                                {
                                    parentID = Convert.ToInt32(variable.ProductID);
                                }

                                string ProductVariableName  = itemValue[3];
                                string ProductVariableValue = itemValue[4];
                                double Quantity             = Convert.ToDouble(itemValue[5]);
                                string ProductName          = itemValue[6];
                                string ProductImageOrigin   = itemValue[7];
                                string ProductVariable      = itemValue[8];
                                double Price = Convert.ToDouble(itemValue[9]);
                                string ProductVariableSave = itemValue[10];

                                OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity, Price, 1, 0,
                                                             ProductType, currentDate, username, true);

                                StockManagerController.Insert(
                                    new tbl_StockManager
                                {
                                    AgentID           = AgentID,
                                    ProductID         = ProductID,
                                    ProductVariableID = ProductVariableID,
                                    Quantity          = Quantity,
                                    QuantityCurrent   = 0,
                                    Type        = 2,
                                    NoteID      = "Xuất kho khi tạo đơn",
                                    OrderID     = OrderID,
                                    Status      = 3,
                                    SKU         = SKU,
                                    CreatedDate = currentDate,
                                    CreatedBy   = username,
                                    MoveProID   = 0,
                                    ParentID    = parentID,
                                });
                                totalQuantity += Quantity;
                            }
                        }

                        string refund = Request.Cookies["refundt"].Value;
                        if (refund != "1")
                        {
                            string[] RefundID = refund.Split('|');
                            var      update   = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID);
                            var      updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username);
                        }

                        Response.Cookies["refundt"].Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(Response.Cookies["refundt"]);

                        PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng thành công", "s", true, "redirectTo(" + OrderID + ")", Page);
                    }
                }
            }
        }
Beispiel #9
0
        public static string getCustomerDiscount(int ID)
        {
            var now      = DateTime.Now;
            var discount = DiscountCustomerController.getbyCustID(ID).FirstOrDefault();
            var config   = ConfigController.GetByTop1();
            // Khởi tao object json
            bool isDiscount;
            var  isUserApp = UserController.checkExists(userID: ID);
            var  ci        = new CustomerGroup();
            var  promotion = RefundGoodController.getPromotion(customerID: ID);


            if (discount != null)
            {
                // Phí đổi trả
                var feeRefund = discount.FeeRefund;
                // Tính số lượng hàng trã có phí
                var refundQuantityFee = Convert.ToInt32(discount.NumOfProductCanChange - discount.RefundQuantityNoFee);
                // Tính số lượng hàng đổi trả trong 30 ngày
                var fromDate       = now.AddDays(-discount.NumOfDateToChangeProduct).Date;
                var toDate         = now.Date;
                var customer       = CustomerController.getRefundQuantity(ID, fromDate, toDate).FirstOrDefault();
                var quantityNoFree = discount.RefundQuantityNoFee - (customer != null ? Convert.ToInt32(customer.refundNoFeeQuantity) : 0);
                var quantityFree   = refundQuantityFee - (customer != null ? Convert.ToInt32(customer.refundFeeQuantity) : 0);

                isDiscount     = discount.DiscountAmount > 0;
                quantityNoFree = quantityNoFree > 0 ? quantityNoFree : 0;
                quantityFree   = quantityFree > 0 ? quantityFree : 0;

                if (promotion.IsPromotion)
                {
                    isDiscount = true;
                    feeRefund  = feeRefund - promotion.DecreasePrice;

                    if (feeRefund <= 0)
                    {
                        feeRefund      = 0;
                        quantityNoFree = quantityFree + quantityNoFree;
                        quantityFree   = 0;
                    }
                }

                ci.IsDiscount          = isDiscount;
                ci.Discount            = discount.DiscountAmount.ToString();
                ci.QuantityProduct     = discount.QuantityProduct;
                ci.FeeRefund           = feeRefund.ToString();
                ci.DaysExchange        = Convert.ToInt32(discount.NumOfDateToChangeProduct);
                ci.RefundQuantityNoFee = quantityNoFree;
                ci.RefundQuantityFee   = quantityFree;
                ci.IsUserApp           = isUserApp;

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return(serializer.Serialize(ci));
            }
            else if (config != null)
            {
                // Phí đổi trả
                var feeRefund = config.FeeChangeProduct;
                // Tính số lượng hàng trã có phí
                var refundQuantityFee = config.NumOfProductCanChange.HasValue ? Convert.ToInt32(config.NumOfProductCanChange.Value) : 0;
                // Tính số lượng hàng đổi trả trong 30 ngày
                var days         = config.NumOfDateToChangeProduct.HasValue ? config.NumOfDateToChangeProduct.Value : 0;
                var fromDate     = now.AddDays(-days).Date;
                var toDate       = now.Date;
                var customer     = CustomerController.getRefundQuantity(ID, fromDate, toDate).FirstOrDefault();
                var quantityFree = refundQuantityFee - (customer != null ? Convert.ToInt32(customer.refundNoFeeQuantity) : 0) - (customer != null ? Convert.ToInt32(customer.refundFeeQuantity) : 0);

                isDiscount = config.FeeDiscountPerProduct > 0;

                if (promotion.IsPromotion)
                {
                    isDiscount = true;
                    feeRefund  = (feeRefund - promotion.DecreasePrice) < 0 ? 0 : feeRefund - promotion.DecreasePrice;
                }

                ci.IsDiscount          = isDiscount;
                ci.Discount            = config.FeeDiscountPerProduct.ToString();
                ci.QuantityProduct     = 0;
                ci.FeeRefund           = feeRefund.ToString();
                ci.DaysExchange        = Convert.ToInt32(config.NumOfDateToChangeProduct);
                ci.RefundQuantityNoFee = 0;
                ci.RefundQuantityFee   = quantityFree > 0 ? quantityFree : 0;
                ci.IsUserApp           = isUserApp;

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return(serializer.Serialize(ci));
            }
            else
            {
                return("null");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            int      agentID     = 0;
            string   username    = Request.Cookies["userLoginSystem"].Value;

            if (!string.IsNullOrEmpty(username))
            {
                var a = AccountController.GetByUsername(username);

                if (a != null)
                {
                    // Change user
                    string RefundNote = "";
                    if (username != hdfUsernameCurrent.Value)
                    {
                        RefundNote = "Được tạo giúp bởi " + username;
                        username   = hdfUsernameCurrent.Value;
                    }

                    agentID = Convert.ToInt32(a.AgentID);

                    string CustomerPhone   = txtPhone.Text;
                    string CustomerName    = txtFullname.Text;
                    string Nick            = txtNick.Text.Trim();
                    string CustomerAddress = txtAddress.Text.Trim();
                    string Zalo            = txtZalo.Text.Trim();
                    string Facebook        = txtFacebook.Text.Trim();

                    if (!string.IsNullOrEmpty(CustomerPhone))
                    {
                        var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                        if (checkCustomer != null)
                        {
                            int custID = checkCustomer.ID;

                            string kq = CustomerController.Update(custID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2);

                            double totalPrice    = Convert.ToDouble(hdfTotalPrice.Value);
                            double totalQuantity = Convert.ToDouble(hdfTotalQuantity.Value);
                            double totalRefund   = Convert.ToDouble(hdfTotalRefund.Value);
                            var    agent         = AgentController.GetByID(agentID);
                            string agentName     = String.Empty;

                            if (agent != null)
                            {
                                agentName = agent.AgentName;
                            }

                            //insert ddlstatus, refundnote
                            int status = ddlRefundStatus.SelectedValue.ToInt();
                            RefundNote += ". " + txtRefundsNote.Text;
                            int rID = RefundGoodController.Insert(
                                new tbl_RefundGoods()
                            {
                                AgentID        = agentID,
                                TotalPrice     = totalPrice.ToString(),
                                Status         = status,
                                CustomerID     = custID,
                                TotalQuantity  = totalQuantity,
                                TotalRefundFee = totalRefund.ToString(),
                                CreatedDate    = currentDate,
                                CreatedBy      = username,
                                CustomerName   = checkCustomer.CustomerName,
                                CustomerPhone  = checkCustomer.CustomerPhone,
                                AgentName      = agentName,
                                RefundNote     = RefundNote
                            });

                            if (rID > 0)
                            {
                                RefundGoodModel refundModel = JsonConvert.DeserializeObject <RefundGoodModel>(hdfListProduct.Value);

                                int t    = 0;
                                int time = 0;
                                foreach (RefundDetailModel item in refundModel.RefundDetails)
                                {
                                    t++;
                                    time += 20;
                                    int rdID = RefundGoodDetailController.Insert(
                                        new tbl_RefundGoodsDetails()
                                    {
                                        RefundGoodsID           = rID,
                                        AgentID                 = agentID,
                                        OrderID                 = 0,
                                        ProductName             = item.ProductTitle,
                                        CustomerID              = custID,
                                        SKU                     = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU,
                                        Quantity                = item.QuantityRefund,
                                        QuantityMax             = item.QuantityRefund,
                                        PriceNotFeeRefund       = (item.QuantityRefund * item.ReducedPrice).ToString(),
                                        ProductType             = item.ProductStyle,
                                        IsCount                 = true,
                                        RefundType              = item.ChangeType,
                                        RefundFeePerProduct     = item.ChangeType == 2 ? item.FeeRefund.ToString() : "0",
                                        TotalRefundFee          = item.ChangeType == 2 ? (item.FeeRefund * item.QuantityRefund).ToString() : "0",
                                        GiavonPerProduct        = item.Price.ToString(),
                                        DiscountPricePerProduct = (item.Price - item.ReducedPrice).ToString(),
                                        SoldPricePerProduct     = item.ReducedPrice.ToString(),
                                        TotalPriceRow           = item.TotalFeeRefund.ToString(),
                                        CreatedDate             = currentDate.AddMilliseconds(time),
                                        CreatedBy               = username
                                    });

                                    if (rdID > 0)
                                    {
                                        if (item.ChangeType < 3)
                                        {
                                            int    typeRe = 0;
                                            string note   = "";

                                            if (item.ChangeType == 1)
                                            {
                                                note   = "Đổi size đơn " + rdID;
                                                typeRe = 8;
                                            }
                                            else if (item.ChangeType == 2)
                                            {
                                                note   = "Đổi sản phẩm khác đơn " + rdID;
                                                typeRe = 9;
                                            }

                                            if (item.ChangeType == 1 || item.ChangeType == 2)
                                            {
                                                StockManagerController.Insert(
                                                    new tbl_StockManager
                                                {
                                                    AgentID           = agentID,
                                                    ProductID         = item.ProductStyle == 1 ? item.ProductID : 0,
                                                    ProductVariableID = item.ProductVariableID,
                                                    Quantity          = item.QuantityRefund,
                                                    QuantityCurrent   = 0,
                                                    Type        = 1,
                                                    NoteID      = note,
                                                    OrderID     = 0,
                                                    Status      = typeRe,
                                                    SKU         = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU,
                                                    CreatedDate = currentDate.AddMilliseconds(time),
                                                    CreatedBy   = username,
                                                    MoveProID   = 0,
                                                    ParentID    = item.ProductID,
                                                });
                                            }
                                        }
                                    }
                                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ")", Page);
                                }
                            }
                        }
                    }
                }
            }
        }
        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));
                }
            }
        }
Beispiel #12
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>";
            }
        }
        public void LoadData()
        {
            string   SKU        = String.Empty;
            int      CategoryID = 0;
            DateTime fromdate   = DateTime.Today;
            DateTime todate     = fromdate.AddDays(1).AddMinutes(-1);

            string CreatedBy           = "";
            int    totalRemainQuantity = 0;
            int    totalSoldQuantity   = 0;
            int    totalRefundQuantity = 0;
            double totalCost           = 0;
            double totalProfit         = 0;
            double totalRefundProfit   = 0;
            double totalRevenue        = 0;

            int day = 0;

            if (!String.IsNullOrEmpty(Request.QueryString["SKU"]))
            {
                SKU = Request.QueryString["SKU"];

                var product = ProductController.GetBySKU(SKU);
                if (product != null)
                {
                    fromdate = Convert.ToDateTime(product.CreatedDate);
                }
            }

            if (!String.IsNullOrEmpty(Request.QueryString["categoryid"]))
            {
                CategoryID = Request.QueryString["categoryid"].ToInt(0);
            }

            if (!String.IsNullOrEmpty(Request.QueryString["createdby"]))
            {
                CreatedBy = Request.QueryString["createdby"];
            }

            if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
            {
                fromdate = Convert.ToDateTime(Request.QueryString["fromdate"]);
            }

            if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
            {
                todate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
            }

            txtTextSearch.Text         = SKU;
            ddlCategory.SelectedValue  = CategoryID.ToString();
            ddlCreatedBy.SelectedValue = CreatedBy;
            rFromDate.SelectedDate     = fromdate;
            rToDate.SelectedDate       = todate;
            day = Convert.ToInt32((todate - fromdate).TotalDays);

            if (day <= 0)
            {
                day = 1;
            }

            this.ltrTotalRemain.Text       = String.Empty;
            this.ltrTotalRemainPerDay.Text = String.Empty;
            this.ltrTotalSold.Text         = String.Empty;
            this.ltrTotalRefund.Text       = String.Empty;
            this.ltrTotalProfit.Text       = String.Empty;
            this.ltrTotalRevenue.Text      = String.Empty;
            this.ltrTotalStock.Text        = String.Empty;
            this.ltrTotalStockValue.Text   = String.Empty;

            var productReport = OrderController.getProductReport(SKU, CategoryID, CreatedBy, fromdate, todate);

            totalSoldQuantity = productReport.Sum(x => x.totalSold);
            totalRevenue      = productReport.Sum(x => x.totalRevenue);
            totalCost         = productReport.Sum(x => x.totalCost);
            totalProfit       = totalRevenue - totalCost;

            var productRefundReport = RefundGoodController.getRefundProductReport(SKU, CategoryID, CreatedBy, fromdate, todate);

            totalRefundQuantity = productRefundReport.Sum(x => x.totalRefund);
            double totalRefundRevenue = productRefundReport.Sum(x => x.totalRevenue);
            double totalRefundCost    = productRefundReport.Sum(x => x.totalCost);
            double totalRefundFee     = productRefundReport.Sum(x => x.totalRefundFee);

            totalRefundProfit = totalRefundRevenue - totalRefundCost;

            totalRemainQuantity = totalSoldQuantity - totalRefundQuantity;

            var productStockReport = ProductController.getProductStockReport(SKU, CategoryID);

            totalProfit = totalProfit - totalRefundProfit + totalRefundFee;

            ltrTotalSold.Text         = totalSoldQuantity.ToString();
            ltrTotalRefund.Text       = totalRefundQuantity.ToString();
            ltrTotalRemain.Text       = totalRemainQuantity.ToString();
            ltrTotalRemainPerDay.Text = (totalRemainQuantity / day).ToString() + " cái/ngày";
            ltrTotalRevenue.Text      = string.Format("{0:N0}", totalRevenue);
            ltrTotalProfit.Text       = string.Format("{0:N0}", totalProfit);
            ltrAverageProfit.Text     = string.Format("{0:N0}", totalProfit / day).ToString();
            ltrTotalStock.Text        = productStockReport.totalStock.ToString() + " cái";
            ltrTotalStockValue.Text   = string.Format("{0:N0}", productStockReport.totalStockValue);

            if (day > 1)
            {
                string chartLabelDays           = "";
                string chartTotalRemainQuantity = "";

                List <string> dataDays = new List <string>();
                List <string> dataTotalRemainQuantity = new List <string>();

                while (fromdate < todate)
                {
                    // Ngày biểu đồ
                    dataDays.Add(String.Format("'{0:d/M}'", fromdate));

                    // Biểu đồ sản lượng
                    int TotalSoldQuantity   = productReport.Where(x => x.reportDate.Date == fromdate).Sum(x => x.totalSold);
                    int TotalRefundQuantity = productRefundReport.Where(x => x.reportDate == fromdate).Sum(x => x.totalRefund);
                    dataTotalRemainQuantity.Add((TotalSoldQuantity - TotalRefundQuantity).ToString());

                    // Thêm 1 ngày chạy vòng lặp
                    fromdate = fromdate.AddDays(1);
                }

                chartLabelDays           = String.Join(", ", dataDays);
                chartTotalRemainQuantity = String.Join(", ", dataTotalRemainQuantity);

                StringBuilder html = new StringBuilder();
                html.Append("<script>");
                html.Append("var lineChartData = {");
                html.Append("	labels: ["+ chartLabelDays + "],");
                html.Append("	datasets: [{");
                html.Append("		label: 'Sản lượng',");
                html.Append("		borderColor: 'rgb(255, 99, 132)',");
                html.Append("		backgroundColor: 'rgb(255, 99, 132)',");
                html.Append("		fill: false,");
                html.Append("		data: ["+ chartTotalRemainQuantity + "],");
                html.Append("		yAxisID: 'y-axis-1',");
                html.Append("	}]");
                html.Append("};");
                html.Append("</script>");

                ltrChartData.Text = html.ToString();
            }
        }
Beispiel #14
0
        public void LoadData()
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

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

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

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

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


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

            if (acc != null)
            {
                string   user       = acc.Username;
                string   SKU        = String.Empty;
                int      CategoryID = 0;
                DateTime fromdate   = DateTime.Today;
                DateTime todate     = fromdate.AddDays(1).AddMinutes(-1);

                if (!String.IsNullOrEmpty(Request.QueryString["SKU"]))
                {
                    SKU = Request.QueryString["SKU"];

                    var product = ProductController.GetBySKU(SKU);
                    if (product != null)
                    {
                        fromdate = Convert.ToDateTime(product.CreatedDate);
                    }
                }

                if (!String.IsNullOrEmpty(Request.QueryString["categoryid"]))
                {
                    CategoryID = Request.QueryString["categoryid"].ToInt(0);
                }

                if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
                {
                    fromdate = Convert.ToDateTime(Request.QueryString["fromdate"]);
                }

                if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
                {
                    todate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
                }

                txtTextSearch.Text        = SKU;
                ddlCategory.SelectedValue = CategoryID.ToString();
                rFromDate.SelectedDate    = fromdate;
                rToDate.SelectedDate      = todate;

                // Tính theo thời gian đã chọn
                var uReport   = OrderController.getReport(SKU, CategoryID, user, fromdate, todate);
                var sysReport = OrderController.getReport(SKU, CategoryID, "", fromdate, todate);

                // Tính tháng trước
                DateTime fromdateLastMonth = fromdate.FirstDayOfMonth().AddMonths(-1);
                DateTime todateLastMonth   = fromdateLastMonth.LastDayOfMonth().AddDays(1).AddMinutes(-1);
                var      uReportLastMonth  = OrderController.getReport(SKU, CategoryID, user, fromdateLastMonth, todateLastMonth);

                int totalDays = Convert.ToInt32((todate - fromdate).TotalDays);

                string compareTotalRemainQuantity   = "";
                string compareTotalSoldQuantity     = "";
                string compareTotalSaleOrder        = "";
                string compareNewCustomer           = "";
                string compareTotalRefundQuantity   = "";
                string compareAverageRemainQuantity = "";

                if (totalDays > 1)
                {
                    // So sánh tổng số lượng còn lại với tháng trước
                    int diffTotalRemainQuantity    = uReport.totalRemainQuantity - uReportLastMonth.totalRemainQuantity;
                    int percentTotalRemainQuantity = uReport.totalRemainQuantity * 100 / uReportLastMonth.totalRemainQuantity - 100;
                    if (diffTotalRemainQuantity > 0)
                    {
                        compareTotalRemainQuantity += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalRemainQuantity + " (+" + percentTotalRemainQuantity + "%)</span>";
                    }
                    else
                    {
                        compareTotalRemainQuantity += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalRemainQuantity + " (" + percentTotalRemainQuantity + "%)</span>";
                    }

                    // So sánh tổng số lượng bán ra với tháng trước
                    int diffTotalSoldQuantity    = uReport.totalSoldQuantity - uReportLastMonth.totalSoldQuantity;
                    int percentTotalSoldQuantity = uReport.totalSoldQuantity * 100 / uReportLastMonth.totalSoldQuantity - 100;
                    if (diffTotalSoldQuantity > 0)
                    {
                        compareTotalSoldQuantity += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalSoldQuantity + " (+" + percentTotalSoldQuantity + "%)</span>";
                    }
                    else
                    {
                        compareTotalSoldQuantity += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalSoldQuantity + " (" + percentTotalSoldQuantity + "%)</span>";
                    }

                    // So sánh tổng số đơn với tháng trước
                    int diffTotalSaleOrder    = uReport.totalSaleOrder - uReportLastMonth.totalSaleOrder;
                    int percentTotalSaleOrder = uReport.totalSaleOrder * 100 / uReportLastMonth.totalSaleOrder - 100;
                    if (diffTotalSaleOrder > 0)
                    {
                        compareTotalSaleOrder += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalSaleOrder + " (+" + percentTotalSaleOrder + "%)</span>";
                    }
                    else
                    {
                        compareTotalSaleOrder += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalSaleOrder + " (" + percentTotalSaleOrder + "%)</span>";
                    }

                    // So sánh số lượng hàng trả với tháng trước
                    int diffTotalRefundQuantity = uReport.totalRefundQuantity - uReportLastMonth.totalRefundQuantity;
                    if (diffTotalRefundQuantity > 0)
                    {
                        compareTotalRefundQuantity += "<span class='font-red' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffTotalRefundQuantity + "</span>";
                    }
                    else
                    {
                        compareTotalRefundQuantity += "<span class='font-green' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffTotalRefundQuantity + "</span>";
                    }

                    // So sánh số khách mới với tháng trước
                    int diffNewCustomer    = uReport.totalNewCustomer - uReportLastMonth.totalNewCustomer;
                    int percentNewCustomer = uReport.totalNewCustomer * 100 / uReportLastMonth.totalNewCustomer - 100;
                    if (diffNewCustomer > 0)
                    {
                        compareNewCustomer += "<span class='font-green' title='Tăng so với Tổng tháng " + fromdateLastMonth.Month + "'>+" + diffNewCustomer + " (+" + percentNewCustomer + "%)</span>";
                    }
                    else
                    {
                        compareNewCustomer += "<span class='font-red' title='Giảm so với Tổng tháng " + fromdateLastMonth.Month + "'>" + diffNewCustomer + " (" + percentNewCustomer + "%)</span>";
                    }
                }

                // So sánh trung bình số lượng còn lại với tháng này (chỉ so sánh khi số ngày == 1)
                if (totalDays >= 1)
                {
                    // So sánh trung bình số lượng còn lại với tháng trước
                    int diffAverageRemainQuantity    = uReport.averageRemainQuantity - uReportLastMonth.averageRemainQuantity;
                    int percentAverageRemainQuantity = uReport.averageRemainQuantity * 100 / uReportLastMonth.averageRemainQuantity - 100;
                    if (diffAverageRemainQuantity > 0)
                    {
                        compareAverageRemainQuantity += "<span class='font-green' title='Tăng so với Trung bình tháng " + fromdateLastMonth.Month + "'>+" + diffAverageRemainQuantity + " (+" + percentAverageRemainQuantity + "%)</span>";
                    }
                    else
                    {
                        compareAverageRemainQuantity += "<span class='font-red' title='Giảm so với Trung bình tháng " + fromdateLastMonth.Month + "'>" + diffAverageRemainQuantity + " (" + percentAverageRemainQuantity + "%)</span>";
                    }

                    // Tính tháng này
                    DateTime fromdateThisMonth = fromdate.FirstDayOfMonth();
                    DateTime todateThisMonth   = fromdate.LastDayOfMonth().AddDays(1).AddMinutes(-1);
                    if (fromdateThisMonth.Month == DateTime.Today.Month)
                    {
                        todateThisMonth = DateTime.Today.AddDays(1).AddMinutes(-1);
                    }
                    var uReportThisMonth = OrderController.getReport(SKU, CategoryID, user, fromdateThisMonth, todateThisMonth);
                    int diffThisMonthAverageRemainQuantity    = uReport.averageRemainQuantity - uReportThisMonth.averageRemainQuantity;
                    int percentThisMonthAverageRemainQuantity = uReport.averageRemainQuantity * 100 / uReportThisMonth.averageRemainQuantity - 100;
                    if (diffThisMonthAverageRemainQuantity > 0)
                    {
                        compareAverageRemainQuantity += " <span class='font-blue' title='Tăng so với Trung bình tháng " + todateThisMonth.Month + "'>+" + diffThisMonthAverageRemainQuantity + " (+" + percentThisMonthAverageRemainQuantity + "%)</span>";
                    }
                    else if (diffThisMonthAverageRemainQuantity < 0)
                    {
                        compareAverageRemainQuantity += " <span class='font-red' title='Giảm so với Trung bình tháng " + todateThisMonth.Month + "'>" + diffThisMonthAverageRemainQuantity + " (" + percentThisMonthAverageRemainQuantity + "%)</span>";
                    }
                }

                // Tính phần trăm / toàn hệ thống
                double PercentOfSystem = 0;
                if (sysReport.totalProfit > 0)
                {
                    PercentOfSystem = uReport.totalProfit * 100 / sysReport.totalProfit;
                }

                ltrTotalSaleOrder.Text        = uReport.totalSaleOrder + " đơn " + compareTotalSaleOrder;
                ltrAverageSaleOrder.Text      = uReport.averageSaleOrder.ToString() + " đơn/ngày";
                ltrTotalSoldQuantity.Text     = uReport.totalSoldQuantity.ToString() + " cái " + compareTotalSoldQuantity;
                ltrAverageSoldQuantity.Text   = uReport.averageSoldQuantity.ToString() + " cái/ngày";
                ltrTotalRefundQuantity.Text   = uReport.totalRefundQuantity.ToString() + " cái (chiếm " + (uReport.totalRefundQuantity * 100 / (uReport.totalSoldQuantity > 0 ? uReport.totalSoldQuantity : 1)) + "%) " + compareTotalRefundQuantity;
                ltrAverageRefundQuantity.Text = uReport.averageRefundQuantity.ToString() + " cái/ngày";
                ltrTotalRemainQuantity.Text   = uReport.totalRemainQuantity.ToString() + " cái " + compareTotalRemainQuantity;
                ltrAverageRemainQuantity.Text = uReport.averageRemainQuantity.ToString() + " cái/ngày " + compareAverageRemainQuantity;
                ltrPercentOfSystem.Text       = Math.Round(PercentOfSystem, 1).ToString() + "%";
                ltrTotalNewCustomer.Text      = uReport.totalNewCustomer.ToString() + " khách mới " + compareNewCustomer;

                // Xử lý biểu đồ
                int day = Convert.ToInt32((todate - fromdate).TotalDays);
                if (day > 1)
                {
                    string chartLabelDays           = "";
                    string chartTotalNewCustomer    = "";
                    string chartTotalRemainQuantity = "";
                    string chartPercentOfSystem     = "";

                    List <string> dataDays                = new List <string>();
                    List <string> dataTotalNewCustomer    = new List <string>();
                    List <string> dataTotalRemainQuantity = new List <string>();
                    List <string> dataPercentOfSystem     = new List <string>();

                    while (fromdate < todate)
                    {
                        var userReport       = OrderController.getProductReport(SKU, CategoryID, user, fromdate, todate);
                        var userRefundReport = RefundGoodController.getRefundProductReport(SKU, CategoryID, user, fromdate, todate);
                        var newCustomer      = CustomerController.Report(user, fromdate, todate);
                        // Ngày biểu đồ
                        dataDays.Add(String.Format("'{0:d/M}'", fromdate));

                        // Biểu đồ sản lượng
                        int TotalSoldQuantity   = userReport.Where(x => x.reportDate.Date == fromdate).Sum(x => x.totalSold);
                        int TotalRefundQuantity = userRefundReport.Where(x => x.reportDate == fromdate).Sum(x => x.totalRefund);
                        dataTotalRemainQuantity.Add((TotalSoldQuantity - TotalRefundQuantity).ToString());

                        // Biểu đồ khách mới
                        int TotalNewCustomer = newCustomer.Where(x => x.CreatedDate.Value.Date == fromdate).Count();
                        dataTotalNewCustomer.Add(TotalNewCustomer.ToString());

                        // Thêm 1 ngày chạy vòng lặp
                        fromdate = fromdate.AddDays(1);
                    }

                    chartLabelDays           = String.Join(", ", dataDays);
                    chartTotalNewCustomer    = String.Join(", ", dataTotalNewCustomer);
                    chartTotalRemainQuantity = String.Join(", ", dataTotalRemainQuantity);
                    chartPercentOfSystem     = String.Join(", ", dataPercentOfSystem);

                    StringBuilder html = new StringBuilder();
                    html.Append("<script>");
                    html.Append("var lineChartData = {");
                    html.Append("	labels: ["+ chartLabelDays + "],");
                    html.Append("	datasets: [{");
                    html.Append("		label: 'Sản lượng còn lại',");
                    html.Append("		borderColor: 'rgb(255, 99, 132)',");
                    html.Append("		backgroundColor: 'rgb(255, 99, 132)',");
                    html.Append("		fill: false,");
                    html.Append("		data: ["+ chartTotalRemainQuantity + "],");
                    html.Append("		yAxisID: 'y-axis-1',");
                    html.Append("	}]");
                    html.Append("};");
                    html.Append("var lineChartData2 = {");
                    html.Append("	labels: ["+ chartLabelDays + "],");
                    html.Append("	datasets: [{");
                    html.Append("		label: 'Khách mới',");
                    html.Append("		borderColor: 'rgb(54, 162, 235)',");
                    html.Append("		backgroundColor: 'rgb(54, 162, 235)',");
                    html.Append("		fill: false,");
                    html.Append("		data: ["+ chartTotalNewCustomer + "],");
                    html.Append("		yAxisID: 'y-axis-1'");
                    html.Append("	}]");
                    html.Append("};");
                    html.Append("</script>");

                    ltrChartData.Text = html.ToString();
                }
            }
        }
Beispiel #17
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;

            int id = ViewState["ID"].ToString().ToInt(0);

            if (id > 0)
            {
                var d = CustomerController.GetByID(id);
                if (d != null)
                {
                    //Phần thêm ảnh đại diện khách hàng
                    string path   = "/uploads/avatars/";
                    string Avatar = ListAvatarImage.Value;
                    if (UploadAvatarImage.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in UploadAvatarImage.UploadedFiles)
                        {
                            var o = path + Guid.NewGuid() + f.GetExtension();
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                Avatar = o;
                            }
                            catch { }
                        }
                    }

                    if (Avatar != ListAvatarImage.Value)
                    {
                        if (File.Exists(Server.MapPath(ListAvatarImage.Value)))
                        {
                            File.Delete(Server.MapPath(ListAvatarImage.Value));
                        }
                    }

                    int    PaymentType           = ddlPaymentType.SelectedValue.ToInt(0);
                    int    ShippingType          = ddlShippingType.SelectedValue.ToInt(0);
                    int    TransportCompanyID    = ddlTransportCompanyID.SelectedValue.ToInt(0);
                    int    TransportCompanySubID = ddlTransportCompanySubID.SelectedValue.ToInt(0);
                    string note       = txtNote.Text;
                    int    ProvinceID = hdfProvinceID.Value.ToInt(0);
                    int    DistrictID = hdfDistrictID.Value.ToInt(0);
                    int    WardID     = hdfWardID.Value.ToInt(0);

                    string warning = "Cập nhật khách hàng thành công";

                    string CustomerPhone    = d.CustomerPhone;
                    string NewCustomerPhone = Regex.Replace(txtCustomerPhone.Text.Trim(), @"[^\d]", "");
                    // kiểm tra số điện thoại mới
                    if (NewCustomerPhone != d.CustomerPhone)
                    {
                        // kiểm tra số điện thoại mới có khả dụng ko?
                        var c = CustomerController.GetByPhone(NewCustomerPhone);
                        if (c != null && c.ID != d.ID)
                        {
                            warning = "Số điện thoại này đã tồn tại của khách khác!";
                        }
                        else
                        {
                            warning = "Cập nhật khách hàng thành công! Số điện thoại khách hàng đã được đổi.<br>Lưu ý: Các đơn hàng cũ của khách này cũng đã được đổi số điện thoại.";
                            note    = "Số điện thoại cũ: " + d.CustomerPhone + ". " + note;

                            CustomerPhone = NewCustomerPhone;

                            // đổi số mới cho đơn hàng cũ
                            var orders = OrderController.GetByCustomerID(d.ID);
                            foreach (var order in orders)
                            {
                                string update = OrderController.UpdateCustomerPhone(order.ID, CustomerPhone);
                            }

                            // đổi số mới cho đơn hàng đổi trả cũ
                            var refundorders = RefundGoodController.GetByCustomerID(d.ID);
                            foreach (var refundorder in refundorders)
                            {
                                string update = RefundGoodController.UpdateCustomerPhone(refundorder.ID, CustomerPhone);
                            }
                        }
                    }

                    string CustomerPhone2    = "";
                    string NewCustomerPhone2 = Regex.Replace(txtCustomerPhone2.Text.Trim(), @"[^\d]", "");
                    if (NewCustomerPhone2 != "")
                    {
                        // kiểm tra số điện thoại 2 mới
                        var b = CustomerController.GetByPhone(NewCustomerPhone2);
                        if (b == null)
                        {
                            CustomerPhone2 = NewCustomerPhone2;
                        }
                        else
                        {
                            warning = "Số điện thoại 2 đã tồn tại của khách khác!";
                        }
                    }

                    CustomerController.Update(id, txtCustomerName.Text, CustomerPhone, txtAddress.Text, "", 0, 1, ddlUser.SelectedItem.ToString(), DateTime.Now, username, chkIsHidden.Checked, Regex.Replace(txtZalo.Text.Trim(), @"[^\d]", ""), txtFacebook.Text, note, txtNick.Text, Avatar, ShippingType, PaymentType, TransportCompanyID, TransportCompanySubID, CustomerPhone2, ProvinceID, DistrictID, WardID);
                    PJUtils.ShowMessageBoxSwAlert(warning, "s", true, Page);
                }
            }
        }
Beispiel #18
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime currentDate = DateTime.Now;
                string   username    = Request.Cookies["usernameLoginSystem"].Value;
                var      acc         = AccountController.GetByUsername(username);
                if (acc != null)
                {
                    if (acc.RoleID == 0 || acc.RoleID == 2)
                    {
                        #region Lấy thông tin khởi tạo Order
                        // Change user
                        string UserHelp = "";
                        if (username != hdfUsernameCurrent.Value)
                        {
                            UserHelp = username;
                            username = hdfUsernameCurrent.Value;
                        }

                        int    AgentID     = Convert.ToInt32(acc.AgentID);
                        int    OrderType   = hdfOrderType.Value.ToInt();
                        string AdditionFee = "0";
                        string DisCount    = "0";
                        int    CustomerID  = 0;

                        string CustomerPhone   = Regex.Replace(txtPhone.Text.Trim(), @"[^\d]", "");
                        string CustomerName    = txtFullname.Text.Trim().ToLower().ToTitleCase();
                        string CustomerEmail   = "";
                        string CustomerAddress = txtAddress.Text.Trim().ToTitleCase();

                        int ProvinceID = hdfProvinceID.Value.ToInt(0);
                        int DistrictID = hdfDistrictID.Value.ToInt(0);
                        int WardID     = hdfWardID.Value.ToInt(0);

                        var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                        string kq = "";

                        #region Cập nhật thông tin khách hàng
                        if (checkCustomer != null)
                        {
                            CustomerID = checkCustomer.ID;
                            kq         = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", checkCustomer.CustomerLevelID.Value, checkCustomer.Status.Value, checkCustomer.CreatedBy, currentDate, username, false, checkCustomer.Zalo, checkCustomer.Facebook, checkCustomer.Note, checkCustomer.Nick, checkCustomer.Avatar, checkCustomer.ShippingType.Value, checkCustomer.PaymentType.Value, checkCustomer.TransportCompanyID.Value, checkCustomer.TransportCompanySubID.Value, checkCustomer.CustomerPhone2, ProvinceID, DistrictID, WardID);
                        }
                        else
                        {
                            kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, username, false, "", "", "", "", "", 0, 0, 0, 0, "", ProvinceID, DistrictID, WardID);
                            if (kq.ToInt(0) > 0)
                            {
                                CustomerID = kq.ToInt(0);
                            }
                        }
                        #endregion

                        string totalPrice            = hdfTotalPrice.Value.ToString();
                        string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value;
                        int    PaymentStatus         = 3;
                        int    ExcuteStatus          = 2;
                        int    PaymentType           = 1;
                        int    ShippingType          = 1;

                        bool IsHidden = false;
                        int  WayIn    = 1;

                        double DiscountPerProduct = Convert.ToDouble(pDiscount.Value);

                        double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value);
                        string FeeShipping   = pFeeShip.Value.ToString();
                        double GuestPaid     = Convert.ToDouble(pGuestPaid.Value);
                        double GuestChange   = Convert.ToDouble(totalPrice) - GuestPaid;
                        var    couponID      = hdfCouponID.Value.ToInt(0);
                        var    couponValue   = hdfCouponValue.Value.ToDecimal(0);

                        tbl_Order order = new tbl_Order()
                        {
                            AgentID               = AgentID,
                            OrderType             = OrderType,
                            AdditionFee           = AdditionFee,
                            DisCount              = DisCount,
                            CustomerID            = CustomerID,
                            CustomerName          = CustomerName,
                            CustomerPhone         = CustomerPhone,
                            CustomerAddress       = CustomerAddress,
                            CustomerEmail         = CustomerEmail,
                            TotalPrice            = totalPrice,
                            TotalPriceNotDiscount = totalPriceNotDiscount,
                            PaymentStatus         = PaymentStatus,
                            ExcuteStatus          = ExcuteStatus,
                            IsHidden              = IsHidden,
                            WayIn              = WayIn,
                            CreatedDate        = currentDate,
                            CreatedBy          = username,
                            DiscountPerProduct = DiscountPerProduct,
                            TotalDiscount      = TotalDiscount,
                            FeeShipping        = FeeShipping,
                            GuestPaid          = GuestPaid,
                            GuestChange        = GuestChange,
                            PaymentType        = PaymentType,
                            ShippingType       = ShippingType,
                            OrderNote          = String.Empty,
                            DateDone           = DateTime.Now,
                            OtherFeeName       = String.Empty,
                            OtherFeeValue      = 0,
                            PostalDeliveryType = 1,
                            UserHelp           = UserHelp,
                            CouponID           = couponID,
                            CouponValue        = couponValue
                        };

                        var ret = OrderController.InsertOnSystem(order);

                        int OrderID = ret.ID;
                        #endregion

                        #region Khởi tạo Other Fee
                        if (!String.IsNullOrEmpty(hdfOtherFees.Value))
                        {
                            JavaScriptSerializer serializer = new JavaScriptSerializer();
                            var fees = serializer.Deserialize <List <Fee> >(hdfOtherFees.Value);
                            if (fees != null)
                            {
                                foreach (var fee in fees)
                                {
                                    fee.OrderID      = ret.ID;
                                    fee.CreatedBy    = acc.ID;
                                    fee.CreatedDate  = DateTime.Now;
                                    fee.ModifiedBy   = acc.ID;
                                    fee.ModifiedDate = DateTime.Now;
                                }

                                FeeController.Update(ret.ID, fees);
                            }
                        }
                        #endregion

                        #region Cập nhật Coupon
                        if (order.CouponID.HasValue && order.CouponID.Value > 0)
                        {
                            CouponController.updateStatusCouponCustomer(CustomerID, order.CouponID.Value, false);
                        }
                        #endregion

                        if (OrderID > 0)
                        {
                            #region Khởi tạo chi tiết đơn hàng
                            ProductPOS              POS          = JsonConvert.DeserializeObject <ProductPOS>(hdfListProduct.Value);
                            List <tbl_OrderDetail>  orderDetails = new List <tbl_OrderDetail>();
                            List <tbl_StockManager> stockManager = new List <tbl_StockManager>();

                            // Reverser
                            POS.productPOS.Reverse();

                            foreach (ProductGetOut item in POS.productPOS)
                            {
                                orderDetails.Add(
                                    new tbl_OrderDetail()
                                {
                                    AgentID                   = AgentID,
                                    OrderID                   = OrderID,
                                    SKU                       = item.SKU,
                                    ProductID                 = item.ProductType == 1 ? item.ProductID : 0,
                                    ProductVariableID         = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                    ProductVariableDescrition = item.ProductVariableSave,
                                    Quantity                  = item.QuantityInstock,
                                    Price                     = item.Giabanle,
                                    Status                    = 1,
                                    DiscountPrice             = 0,
                                    ProductType               = item.ProductType,
                                    CreatedDate               = currentDate,
                                    CreatedBy                 = username,
                                    IsCount                   = true
                                }
                                    );

                                int parentID = item.ProductID;
                                var variable = ProductVariableController.GetByID(item.ProductVariableID);
                                if (variable != null)
                                {
                                    parentID = Convert.ToInt32(variable.ProductID);
                                }

                                stockManager.Add(
                                    new tbl_StockManager()
                                {
                                    AgentID           = AgentID,
                                    ProductID         = item.ProductType == 1 ? item.ProductID : 0,
                                    ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                    Quantity          = item.QuantityInstock,
                                    QuantityCurrent   = 0,
                                    Type        = 2,
                                    NoteID      = "Xuất kho bán POS",
                                    OrderID     = OrderID,
                                    Status      = 3,
                                    SKU         = item.SKU,
                                    CreatedDate = currentDate,
                                    CreatedBy   = username,
                                    MoveProID   = 0,
                                    ParentID    = parentID
                                }
                                    );
                            }

                            OrderDetailController.Insert(orderDetails);
                            #endregion

                            // Cập nhật lại sô lượng và giá vố vào đơn hàng
                            OrderController.updateQuantityCOGS(OrderID);
                            // Cập nhật lại thông tin kho hàng
                            StockManagerController.Insert(stockManager);

                            #region Khởi tạo đơn hàng đổi trả
                            string refund = hdSession.Value;
                            if (refund != "1")
                            {
                                string[] RefundID = refund.Split('|');
                                var      update   = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID);
                                var      updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username);
                            }
                            #endregion

                            // Hoàn thành khởi tạo đơn hàng nên gán lại giá trị trang lúc ban đầu
                            hdStatusPage.Value = "Create";
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { HoldOn.close(); printInvoice(" + OrderID + ") });", true);
                        }
                    }
                }
            }
            catch (Exception)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { handleErrorSubmit(); });", true);
            }
        }
Beispiel #19
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            int      AgentID     = 0;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;

            if (!string.IsNullOrEmpty(username))
            {
                var a = AccountController.GetByUsername(username);
                if (a != null)
                {
                    AgentID = Convert.ToInt32(a.AgentID);
                    string phone = hdfPhone.Value;
                    if (!string.IsNullOrEmpty(phone))
                    {
                        var cust = CustomerController.GetByPhone(phone);
                        if (cust != null)
                        {
                            #region Tạo đơn hàng đổi tra
                            int    custID        = cust.ID;
                            string totalprice    = hdfTotalPrice.Value;
                            string totalquantity = hdfTotalQuantity.Value;
                            string totalrefund   = hdfTotalRefund.Value;
                            var    agent         = AgentController.GetByID(AgentID);
                            string agentName     = "";
                            if (agent != null)
                            {
                                agentName = agent.AgentName;
                            }
                            //insert ddlstatus, refundnote
                            int    status      = ddlRefundStatus.SelectedValue.ToInt();
                            string RefundsNote = txtRefundsNote.Text;
                            int    rID         = RefundGoodController.Insert(AgentID, totalprice, status, custID, Convert.ToInt32(totalquantity),
                                                                             totalrefund, agentName, cust.CustomerName, cust.CustomerPhone, currentDate, username, RefundsNote);
                            #endregion

                            if (rID > 0)
                            {
                                string   listString = hdfListProduct.Value;
                                string[] items      = listString.Split('|');
                                if (items.Length - 1 > 0)
                                {
                                    for (int i = 0; i < items.Length - 1; i++)
                                    {
                                        #region Tạo chi tiết đơn hàng đổi tra
                                        string[] element                 = items[i].Split(';');
                                        var      sku                     = element[0];
                                        var      orderID                 = element[1].ToInt(0);
                                        var      orderDetailID           = element[2];
                                        var      ProductName             = element[3];
                                        var      GiavonPerProduct        = Convert.ToDouble(element[5]);
                                        var      SoldPricePerProduct     = Convert.ToDouble(element[6]);
                                        var      DiscountPricePerProduct = Convert.ToDouble(element[7]);
                                        var      quantity                = Convert.ToDouble(element[10]);
                                        var      quantityMax             = Convert.ToDouble(element[8]);
                                        var      ProductType             = element[4].ToInt(1);
                                        var      RefundType              = element[9].ToInt(1);
                                        var      RefundFeePerProduct     = Convert.ToDouble(element[11]);
                                        var      TotalPriceRow           = element[12];
                                        var      PriceNotFeeRefund       = SoldPricePerProduct * quantity;
                                        var      rdTotalRefundFee        = RefundFeePerProduct * quantity;

                                        int rdID = RefundGoodDetailController.Insert(rID, AgentID, orderID, ProductName, custID, sku, quantity,
                                                                                     quantityMax, PriceNotFeeRefund.ToString(), ProductType, true, RefundType, RefundFeePerProduct.ToString(),
                                                                                     rdTotalRefundFee.ToString(), GiavonPerProduct.ToString(), DiscountPricePerProduct.ToString(), SoldPricePerProduct.ToString(),
                                                                                     TotalPriceRow, currentDate, username);
                                        #endregion

                                        #region Cập nhật stock
                                        if (rdID > 0)
                                        {
                                            if (RefundType < 3)
                                            {
                                                int    typeRe = 0;
                                                string note   = "";
                                                if (RefundType == 1)
                                                {
                                                    note   = "Đổi size";
                                                    typeRe = 8;
                                                }
                                                else if (RefundType == 2)
                                                {
                                                    note   = "Đổi sản phẩm";
                                                    typeRe = 9;
                                                }
                                                if (ProductType == 1)
                                                {
                                                    var product = ProductController.GetBySKU(sku);
                                                    if (product != null)
                                                    {
                                                        int    productID          = product.ID;
                                                        string ProductImageOrigin = "";
                                                        var    ProductImage       = ProductImageController.GetFirstByProductID(product.ID);
                                                        if (ProductImage != null)
                                                        {
                                                            ProductImageOrigin = ProductImage.ProductImage;
                                                        }
                                                        StockManagerController.Insert(
                                                            new tbl_StockManager {
                                                            AgentID           = AgentID,
                                                            ProductID         = productID,
                                                            ProductVariableID = 0,
                                                            Quantity          = quantity,
                                                            QuantityCurrent   = 0,
                                                            Type        = 1,
                                                            NoteID      = note,
                                                            OrderID     = orderID,
                                                            Status      = typeRe,
                                                            SKU         = sku,
                                                            CreatedDate = currentDate,
                                                            CreatedBy   = username,
                                                            MoveProID   = 0,
                                                            ParentID    = productID,
                                                        });
                                                    }
                                                }
                                                else
                                                {
                                                    string ProductVariableName  = "";
                                                    string ProductVariableValue = "";
                                                    string ProductVariable      = "";
                                                    int    parentID             = 0;
                                                    string parentSKU            = "";
                                                    string ProductImageOrigin   = "";
                                                    int    ID = 0;

                                                    var productvariable = ProductVariableController.GetBySKU(sku);
                                                    if (productvariable != null)
                                                    {
                                                        ID = productvariable.ID;
                                                        ProductImageOrigin = productvariable.Image;
                                                        parentSKU          = productvariable.ParentSKU;
                                                        var variables = ProductVariableValueController.GetByProductVariableID(productvariable.ID);
                                                        if (variables.Count > 0)
                                                        {
                                                            foreach (var v in variables)
                                                            {
                                                                ProductVariable      += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|";
                                                                ProductVariableName  += v.VariableName + "|";
                                                                ProductVariableValue += v.VariableValue + "|";
                                                            }
                                                        }
                                                    }
                                                    if (!string.IsNullOrEmpty(parentSKU))
                                                    {
                                                        var product = ProductController.GetBySKU(parentSKU);
                                                        if (product != null)
                                                        {
                                                            parentID = product.ID;
                                                        }
                                                    }


                                                    StockManagerController.Insert(
                                                        new tbl_StockManager {
                                                        AgentID           = AgentID,
                                                        ProductID         = 0,
                                                        ProductVariableID = ID,
                                                        Quantity          = quantity,
                                                        QuantityCurrent   = 0,
                                                        Type        = 1,
                                                        NoteID      = note,
                                                        OrderID     = orderID,
                                                        Status      = typeRe,
                                                        SKU         = sku,
                                                        CreatedDate = currentDate,
                                                        CreatedBy   = username,
                                                        MoveProID   = 0,
                                                        ParentID    = parentID,
                                                    });
                                                }
                                            }
                                        }
                                        #endregion
                                    }

                                    RefundGoodController.updateQuantityCOGS(rID);

                                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ")", Page);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

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

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

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;
                    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!!!";
            }
        }
Beispiel #21
0
        public static string checkphone(string phonefullname)
        {
            RefundCust rf       = new RefundCust();
            int        AgentID  = 0;
            string     username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;

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

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


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

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

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

                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return(serializer.Serialize(rf));
                }
                else
                {
                    rf.CustleftCanchange = "full";
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return(serializer.Serialize(rf));
                }
            }
            else
            {
                rf.CustleftCanchange = "nocustomer";
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return(serializer.Serialize(rf));
            }
        }
Beispiel #22
0
        public void LoadData()
        {
            string username = Request.Cookies["userLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

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

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

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

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

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

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

                        var rds = RefundGoodDetailController.GetByRefundGoodsID(ID);

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

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

                            ddlRefundStatus.SelectedValue = r.Status.ToString();
                            txtRefundsNote.Text           = r.RefundNote;
                            ltrList.Text = html;
                        }
                        ltrPrint.Text  = "<a href=\"/print-invoice-return?id=" + ID + "\" target=\"_blank\" class=\"btn primary-btn fw-btn not-fullwidth\"><i class=\"fa fa-print\" aria-hidden=\"true\"></i> In hóa đơn</a>";
                        ltrPrint.Text += "<a href=\"/print-return-order-image?id=" + ID + "\" target=\"_blank\" class=\"btn primary-btn fw-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-picture-o\" aria-hidden=\"true\"></i> Lấy ảnh đơn hàng</a>";
                    }
                }
            }
        }
        public void LoadData()
        {
            string   accountName = String.Empty;
            DateTime fromdate    = DateTime.Today;
            DateTime todate      = fromdate.AddDays(1).AddMinutes(-1);

            long   totalSales    = 0;
            double averageSales  = 0D;
            int    totalOutput   = 0;
            int    averageOutput = 0;
            int    totalRefund   = 0;
            int    averageRefund = 0;
            double totalDays     = 0D;

            if (!String.IsNullOrEmpty(Request.QueryString["accountName"]))
            {
                accountName = Request.QueryString["accountName"];
            }

            if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
            {
                fromdate = Convert.ToDateTime(Request.QueryString["fromdate"]);
            }

            if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
            {
                todate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
            }

            ddlAccountInfo.SelectedValue = accountName;
            rFromDate.SelectedDate       = fromdate;
            rToDate.SelectedDate         = todate;
            totalDays = (todate - fromdate).TotalDays;

            // Load trang lan dau hoac la chua chon nhan vien
            if (String.IsNullOrEmpty(accountName))
            {
                this.ltrTotalSales.Text    = String.Empty;
                this.ltrAverageSales.Text  = String.Empty;
                this.ltrTotalOutput.Text   = String.Empty;
                this.ltrAverageOutput.Text = String.Empty;
                this.ltrTotalRefund.Text   = String.Empty;
                this.ltrAverageRefund.Text = String.Empty;

                return;
            }


            totalSales   = OrderController.GetTotalPriceByAccount(accountName, fromdate, todate);
            averageSales = Math.Ceiling(totalSales / totalDays);


            totalOutput   = OrderController.GetTotalProductSalesByAccount(accountName, fromdate, todate);
            averageOutput = totalOutput / Convert.ToInt32(totalDays);

            totalRefund   = RefundGoodController.GetTotalRefundByAccount(accountName, fromdate, todate);
            averageRefund = totalRefund / Convert.ToInt32(totalDays);


            ltrTotalSales.Text    = String.Format("{0:N0}  đ", totalSales);
            ltrAverageSales.Text  = String.Format("{0:N0}   đ/ngày", averageSales);
            ltrTotalOutput.Text   = totalOutput.ToString() + " cái";
            ltrAverageOutput.Text = averageOutput.ToString() + " cái/ngày";
            ltrTotalRefund.Text   = totalRefund.ToString() + " cái";
            ltrAverageRefund.Text = averageRefund.ToString() + " cái/ngày";
        }
Beispiel #24
0
        public void LoadData()
        {
            int n;

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

                        var rds = RefundGoodDetailController.GetByRefundGoodsID(ID);

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

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

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

                        ltrPrint.Text  = "<a href='/print-invoice-return?id=" + ID + "' target='_blank' class='btn primary-btn fw-btn not-fullwidth'><i class='fa fa-print' aria-hidden='true'></i> In hóa đơn</a>";
                        ltrPrint.Text += "<a href='/print-return-order-image?id=" + ID + "' target='_blank' class='btn primary-btn btn-blue fw-btn not-fullwidth print-invoice-merged'><i class='fa fa-picture-o' aria-hidden='true'></i> Lấy ảnh đơn hàng</a>";
                    }
                }
            }
        }
Beispiel #25
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 2)
                {
                    // Change user
                    string OrderNote = "";
                    if (username != hdfUsernameCurrent.Value)
                    {
                        OrderNote = "Được tính tiền giúp bởi " + username;
                        username  = hdfUsernameCurrent.Value;
                    }

                    int    AgentID     = Convert.ToInt32(acc.AgentID);
                    int    OrderType   = hdfOrderType.Value.ToInt();
                    string AdditionFee = "0";
                    string DisCount    = "0";
                    int    CustomerID  = 0;

                    string CustomerPhone   = txtPhone.Text.Trim().Replace(" ", "");
                    string CustomerName    = txtFullname.Text.Trim();
                    string Nick            = txtNick.Text.Trim();
                    string CustomerEmail   = "";
                    string CustomerAddress = txtAddress.Text.Trim();

                    var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                    if (checkCustomer != null)
                    {
                        CustomerID = checkCustomer.ID;
                        string kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, checkCustomer.Zalo, checkCustomer.Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2);
                    }
                    else
                    {
                        string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, username, false, "", "", "", "", Nick);
                        if (kq.ToInt(0) > 0)
                        {
                            CustomerID = kq.ToInt(0);
                        }
                    }

                    string totalPrice            = hdfTotalPrice.Value.ToString();
                    string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value;
                    int    PaymentStatus         = 3;
                    int    ExcuteStatus          = 2;
                    int    PaymentType           = 1;
                    int    ShippingType          = 1;
                    bool   IsHidden = false;
                    int    WayIn    = 1;

                    double DiscountPerProduct = Convert.ToDouble(pDiscount.Value);

                    double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value);
                    string FeeShipping   = pFeeShip.Value.ToString();
                    double GuestPaid     = Convert.ToDouble(pGuestPaid.Value);
                    double GuestChange   = Convert.ToDouble(totalPrice) - GuestPaid;
                    string OtherFeeName  = txtOtherFeeName.Text;
                    double OtherFeeValue = Convert.ToDouble(pOtherFee.Value);

                    var ret = OrderController.InsertOnSystem(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress,
                                                             CustomerEmail, totalPrice, totalPriceNotDiscount, PaymentStatus, ExcuteStatus, IsHidden, WayIn, currentDate, username, DiscountPerProduct,
                                                             TotalDiscount, FeeShipping, GuestPaid, GuestChange, PaymentType, ShippingType, OrderNote, DateTime.Now, OtherFeeName, OtherFeeValue, 1);
                    int OrderID = ret.ID;

                    if (OrderID > 0)
                    {
                        ProductPOS              POS          = JsonConvert.DeserializeObject <ProductPOS>(hdfListProduct.Value);
                        List <tbl_OrderDetail>  orderDetails = new List <tbl_OrderDetail>();
                        List <tbl_StockManager> stockManager = new List <tbl_StockManager>();

                        foreach (ProductGetOut item in POS.productPOS)
                        {
                            orderDetails.Add(
                                new tbl_OrderDetail()
                            {
                                AgentID                   = AgentID,
                                OrderID                   = OrderID,
                                SKU                       = item.SKU,
                                ProductID                 = item.ProductType == 1 ? item.ProductID : 0,
                                ProductVariableID         = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                ProductVariableDescrition = item.ProductVariableSave,
                                Quantity                  = item.QuantityInstock,
                                Price                     = item.Giabanle,
                                Status                    = 1,
                                DiscountPrice             = 0,
                                ProductType               = item.ProductType,
                                CreatedDate               = currentDate,
                                CreatedBy                 = username,
                                IsCount                   = true
                            }
                                );

                            int parentID = item.ProductID;
                            var variable = ProductVariableController.GetByID(item.ProductVariableID);
                            if (variable != null)
                            {
                                parentID = Convert.ToInt32(variable.ProductID);
                            }

                            stockManager.Add(
                                new tbl_StockManager()
                            {
                                AgentID           = AgentID,
                                ProductID         = item.ProductType == 1 ? item.ProductID : 0,
                                ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                Quantity          = item.QuantityInstock,
                                QuantityCurrent   = 0,
                                Type        = 2,
                                NoteID      = "Xuất kho bán POS",
                                OrderID     = OrderID,
                                Status      = 3,
                                SKU         = item.SKU,
                                CreatedDate = currentDate,
                                CreatedBy   = username,
                                MoveProID   = 0,
                                ParentID    = parentID
                            }
                                );
                        }

                        OrderDetailController.Insert(orderDetails);
                        StockManagerController.Insert(stockManager);

                        string refund = Request.Cookies["refund"].Value;
                        if (refund != "1")
                        {
                            string[] RefundID = refund.Split('|');
                            var      update   = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID);
                            var      updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username);
                        }

                        Response.Cookies["refund"].Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(Response.Cookies["refund"]);

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { printInvoice(" + OrderID + ") });", true);
                    }
                }
            }
        }
Beispiel #26
0
        public void LoadData()
        {
            string TextSearch  = "";
            string RefundFee   = "";
            int    Status      = 0;
            string CreatedBy   = "";
            string CreatedDate = "";

            if (Request.QueryString["textsearch"] != null)
            {
                TextSearch = Request.QueryString["textsearch"].Trim();
            }
            if (Request.QueryString["status"] != null)
            {
                Status = Request.QueryString["status"].ToInt();
            }
            if (Request.QueryString["refundfee"] != null)
            {
                RefundFee = Request.QueryString["refundfee"];
            }
            if (Request.QueryString["CreatedBy"] != null)
            {
                CreatedBy = Request.QueryString["createdby"];
            }
            if (Request.QueryString["createddate"] != null)
            {
                CreatedDate = Request.QueryString["createddate"];
            }

            txtSearchOrder.Text          = TextSearch;
            ddlStatus.SelectedValue      = Status.ToString();
            ddlRefundFee.SelectedValue   = RefundFee.ToString();
            ddlCreatedBy.Text            = CreatedBy.ToString();
            ddlCreatedDate.SelectedValue = CreatedDate.ToString();

            List <RefundOrder> rs = new List <RefundOrder>();

            rs = RefundGoodController.Filter(TextSearch, Status, RefundFee, CreatedBy, CreatedDate);

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

            if (acc != null)
            {
                if (acc.RoleID == 0)
                {
                    if (CreatedBy != "")
                    {
                        rs = rs.Where(x => x.CreatedBy == CreatedBy).ToList();
                        pagingall(rs);
                    }
                    else
                    {
                        pagingall(rs);
                    }
                }
                else
                {
                    rs = rs.Where(x => x.CreatedBy == acc.Username).ToList();
                    pagingall(rs);
                }


                // THỐNG KÊ ĐƠN HÀNG
                int TotalOrders = rs.Count;
                int Type1Orders = 0;
                int Type2Orders = 0;

                int    TotalProducts  = 0;
                double TotalMoney     = 0;
                double TotalRefundFee = 0;

                for (int i = 0; i < rs.Count; i++)
                {
                    var item = rs[i];

                    // Tính tổng số sản phẩm trong tổng số đơn hàng
                    TotalProducts += item.Quantity;
                    // Tính tổng đơn hàng sỉ và lẻ

                    if (item.Status == 2)
                    {
                        Type2Orders++;
                    }
                    if (item.Status == 1)
                    {
                        Type1Orders++;
                    }

                    // Tính số tiền
                    TotalMoney     += item.TotalPrice;
                    TotalRefundFee += item.TotalRefundFee;
                }

                ltrTotalOrders.Text = TotalOrders.ToString();
                ltrType2Orders.Text = Type2Orders.ToString();
                ltrType1Orders.Text = Type1Orders.ToString();

                ltrTotalProducts.Text  = TotalProducts.ToString();
                ltrTotalMoney.Text     = string.Format("{0:N0}", Convert.ToDouble(TotalMoney)).ToString();
                ltrTotalRefundFee.Text = string.Format("{0:N0}", Convert.ToDouble(TotalRefundFee)).ToString();

                ltrNumberOfOrder.Text = TotalOrders.ToString();
            }
        }
Beispiel #27
0
        public void LoadData()
        {
            string fromdate = "";
            string todate   = "";

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

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

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

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


                ltrList.Text += "</tr>";
            }
        }
Beispiel #28
0
 public static string getOrderReturn(int customerID)
 {
     return(RefundGoodController.getOrderReturnJSON(customerID));
 }
Beispiel #29
0
        public void LoadData()
        {
            string   accountName = String.Empty;
            DateTime fromdate    = DateTime.Today;
            DateTime todate      = fromdate.AddDays(1).AddMinutes(-1);

            double totalRevenue          = 0;
            double averageRevenue        = 0;
            double totalProfit           = 0;
            int    totalSoldQuantity     = 0;
            int    averageSoldQuantity   = 0;
            int    totalRefundQuantity   = 0;
            int    averageRefundQuantity = 0;
            int    totalDays             = 0;

            if (!String.IsNullOrEmpty(Request.QueryString["accountName"]))
            {
                accountName = Request.QueryString["accountName"];
            }

            if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
            {
                fromdate = Convert.ToDateTime(Request.QueryString["fromdate"]);
            }

            if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
            {
                todate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
            }

            ddlAccountInfo.SelectedValue = accountName;
            rFromDate.SelectedDate       = fromdate;
            rToDate.SelectedDate         = todate;
            totalDays = Convert.ToInt32((todate - fromdate).TotalDays);

            var userReport = OrderController.getUserReport(accountName, fromdate, todate);

            totalRevenue        = userReport.totalRevenue;
            averageRevenue      = totalRevenue / totalDays;
            totalSoldQuantity   = userReport.totalSoldQuantity;
            averageSoldQuantity = totalSoldQuantity / totalDays;

            var userRefundReport = RefundGoodController.getUserReport(accountName, fromdate, todate);

            totalRefundQuantity   = userRefundReport.totalRefundQuantity;
            averageRefundQuantity = totalRefundQuantity / totalDays;
            totalProfit           = (userReport.totalRevenue - userReport.totalCost) - (userRefundReport.totalRevenue - userRefundReport.totalCost) + userRefundReport.totalRefundFee;

            // Tổng hệ thống

            var systemReport       = OrderController.getUserReport("", fromdate, todate);
            var systemRefundReport = RefundGoodController.getUserReport("", fromdate, todate);

            int totalSystemQuantity     = systemReport.totalSoldQuantity - systemRefundReport.totalRefundQuantity;
            int PercentQuantityOfSystem = 0;

            if (totalSystemQuantity > 0)
            {
                PercentQuantityOfSystem = (totalSoldQuantity - totalRefundQuantity) * 100 / totalSystemQuantity;
            }

            double totalSystemProfit     = (systemReport.totalRevenue - systemReport.totalCost) - (systemRefundReport.totalRevenue - systemRefundReport.totalCost) + systemRefundReport.totalRefundFee;
            double PercentProfitOfSystem = 0;

            if (totalSystemProfit > 0)
            {
                PercentProfitOfSystem = totalProfit * 100 / totalSystemProfit;
            }

            // Khách mới
            var newCustomer = CustomerController.Report(accountName, fromdate, todate);

            ltrTotalRevenue.Text            = String.Format("{0:N0}", totalRevenue);
            ltrAverageRevenue.Text          = String.Format("{0:N0}/ngày", averageRevenue);
            ltrTotalSoldQuantity.Text       = totalSoldQuantity.ToString() + " cái";
            ltrAverageSoldQuantity.Text     = averageSoldQuantity.ToString() + " cái/ngày";
            ltrTotalRefundQuantity.Text     = totalRefundQuantity.ToString() + " cái";
            ltrAverageRefundQuantity.Text   = averageRefundQuantity.ToString() + " cái/ngày";
            ltrTotalRemainQuantity.Text     = (totalSoldQuantity - totalRefundQuantity).ToString() + " cái";
            ltrAverageRemainQuantity.Text   = ((totalSoldQuantity - totalRefundQuantity) / totalDays).ToString() + " cái/ngày";
            ltrTotalProfit.Text             = String.Format("{0:N0}", totalProfit);
            ltrQuantityPercentOfSystem.Text = PercentQuantityOfSystem.ToString() + "%";
            ltrProfitPercentOfSystem.Text   = Math.Round(PercentProfitOfSystem, 1).ToString() + "%";
            ltrTotalNewCustomer.Text        = newCustomer.Count() + " khách mới";
        }
Beispiel #30
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));
        }