コード例 #1
0
        private void ExportOrderVoucher(string OrderID)
        {
            #region +++ Report Create ++++
            OrderController order_controller = new OrderController();
            OrderInfo       obj_OrderInfo    = order_controller.GetOrderByID(OrderID);
            //Header Parameters
            ReportParameter rp_orderno            = new ReportParameter("p_orderno", obj_OrderInfo.OrderNo);
            ReportParameter rp_order_date         = new ReportParameter("p_order_date", String.Format("{0:dd-MMM-yyyy}", obj_OrderInfo.OrderDate));
            ReportParameter rp_delivery_date      = new ReportParameter("p_delivery_date", obj_OrderInfo.EstDeliveryDate.ToString());
            ReportParameter rp_order_quantity     = new ReportParameter("p_order_quantity", obj_OrderInfo.OrderQuantity.ToString());
            ReportParameter rp_customer_name      = new ReportParameter("p_customer_name", obj_OrderInfo.CustomerName);
            ReportParameter rp_customer_address   = new ReportParameter("p_customer_address", obj_OrderInfo.CustomerAddress);
            ReportParameter rp_customer_mobile    = new ReportParameter("p_customer_mobile", obj_OrderInfo.CustomerMobile);
            ReportParameter rp_additional_request = new ReportParameter("p_additional_request", obj_OrderInfo.OrderDescription);
            //Total Parameters
            decimal subTotal = Convert.ToDecimal(obj_OrderInfo.OrderAmount - obj_OrderInfo.Tax - obj_OrderInfo.DeliveryCharges);

            ReportParameter rp_sub_total        = new ReportParameter("p_sub_total", String.Format("{0:##,###.00}", subTotal.ToString()));
            ReportParameter rp_tax              = new ReportParameter("p_tax", obj_OrderInfo.Tax.ToString());
            ReportParameter rp_delivery_charges = new ReportParameter("p_delivery_charges", obj_OrderInfo.DeliveryCharges.ToString());
            ReportParameter rp_grand_total      = new ReportParameter("p_grand_total", obj_OrderInfo.OrderAmount.ToString());
            //Report DataSet
            OrderDetailController order_Detail_controller = new OrderDetailController();
            ReportDataSource      rds = new ReportDataSource("DataSet1", order_Detail_controller.GetAllOrderDetailByOrderID(OrderID));

            ReportViewer rvOrderVoucher = new ReportViewer();
            rvOrderVoucher.LocalReport.Refresh();
            rvOrderVoucher.LocalReport.DataSources.Clear();
            rvOrderVoucher.LocalReport.ReportPath = Server.MapPath("RDLC_OrderVoucher.rdlc");
            rvOrderVoucher.LocalReport.SetParameters(new ReportParameter[] { rp_orderno, rp_order_date, rp_delivery_date, rp_order_quantity, rp_customer_name, rp_customer_address, rp_customer_mobile, rp_additional_request, rp_sub_total, rp_delivery_charges, rp_grand_total, rp_tax });
            rvOrderVoucher.LocalReport.DataSources.Add(rds);
            byte[] bytes = rvOrderVoucher.LocalReport.Render("PDF");
            #endregion

            MemoryStream memoryStream = new MemoryStream(bytes);
            memoryStream.Seek(0, SeekOrigin.Begin);

            MailMessage message = new MailMessage();
            message.Subject    = "Order Voucher";
            message.IsBodyHtml = true;
            message.From       = new MailAddress("*****@*****.**");
            message.To.Add(obj_OrderInfo.CustomerEmail);
            //message.CC.Add("*****@*****.**");
            Attachment attachment = new Attachment(memoryStream, obj_OrderInfo.OrderNo + ".pdf");
            message.Attachments.Add(attachment);
            message.Body = String.Format("Dear {0},<p>This is your order voucher. Please see in attached file!</P>", obj_OrderInfo.CustomerName);
            NetworkCredential cred = new NetworkCredential("*****@*****.**", "DDrrmm11@@");

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl             = true;
            smtp.Credentials           = cred;
            smtp.Port = 587;
            smtp.Send(message);

            memoryStream.Close();
            memoryStream.Dispose();
        }
コード例 #2
0
 public OrderDetailControllerTests()
 {
     _categoryServiceMock = new Mock <ICategoryService>();
     _cacheManagerMock    = new Mock <ICacheManager>();
     _productServiceMock  = new Mock <IProductService>();
     _orderServiceMock    = new Mock <IOrderService>();
     _target = new OrderDetailController(_categoryServiceMock.Object, _cacheManagerMock.Object, _orderServiceMock.Object, _productServiceMock.Object);
 }
コード例 #3
0
        public void Controller_Get_Orders_Return_Orders()
        {
            // Arrange
            var orderDetailController = new OrderDetailController(mockOrderDetailService.Object, mockILoggerFactory.Object.CreateLogger <OrderDetailController>());

            var rnd = new Random();
            var ordersDetailsQty = 49;
            var currDate         = DateTime.UtcNow;
            var orders           = Enumerable.Range(1, ordersDetailsQty).Select(x => new OrderDetail()
            {
                OrderDetailId = x,
                Price         = rnd.Next(x * 1000) * 3.1414M + new Random().Next(x) / 100,
                Quantity      = rnd.Next(x * 1000),
                ProductId     = rnd.Next(5),
                OrderId       = x / 10 + 1
            }).ToList();
            var idForCheck    = orders[new Random().Next(ordersDetailsQty)].OrderId;
            var badIdForCheck = -10000;

            var firstNum = rnd.Next(ordersDetailsQty - 1);

            Int32 orderid       = 0;
            var   ordersResults = new List <List <OrderDetail> >();

            mockOrderDetailService.Setup(nt => nt.GetOrderDetails(It.IsAny <Int32>())).Callback <Int32>((x) => {
                orderid = x;
            }).ReturnsAsync(() => {
                var res = orders.Where(x => x.OrderId == orderid).ToList();
                ordersResults.Add(res);
                return(res);
            });

            // Action
            var ordersIds   = orders.Select(x => x.OrderId).Distinct().ToList();
            var result      = orderDetailController.Get(ordersIds[0]).Result;
            var resultId    = orderDetailController.Get(idForCheck).Result;
            var resultbadId = orderDetailController.Get(badIdForCheck).Result;

            // Assert
            mockOrderDetailService.Verify(x => x.GetOrderDetails(ordersIds[0]), Times.Once);
            mockOrderDetailService.Verify(x => x.GetOrderDetails(idForCheck), Times.Once);
            mockOrderDetailService.Verify(x => x.GetOrderDetails(badIdForCheck), Times.Once);

            Assert.AreEqual(3, ordersResults.Count);

            var resultType = typeof(List <OrderDetail>);

            Assert.IsInstanceOfType(result, resultType);
            Assert.IsInstanceOfType(resultId, resultType);
            Assert.IsInstanceOfType(resultbadId, resultType);
        }
コード例 #4
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";
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["OrderID"].ToString() != null)
                {
                    string          OrderID          = Request.QueryString["OrderID"].ToString();;
                    OrderController order_controller = new OrderController();
                    OrderInfo       obj_OrderInfo    = order_controller.GetOrderByID(OrderID);
                    //Header Parameters
                    ReportParameter rp_orderno            = new ReportParameter("p_orderno", obj_OrderInfo.OrderNo);
                    ReportParameter rp_order_date         = new ReportParameter("p_order_date", String.Format("{0:dd-MMM-yyyy}", obj_OrderInfo.OrderDate));
                    ReportParameter rp_delivery_date      = new ReportParameter("p_delivery_date", obj_OrderInfo.EstDeliveryDate.ToString());
                    ReportParameter rp_order_quantity     = new ReportParameter("p_order_quantity", obj_OrderInfo.OrderQuantity.ToString());
                    ReportParameter rp_customer_name      = new ReportParameter("p_customer_name", obj_OrderInfo.CustomerName);
                    ReportParameter rp_customer_address   = new ReportParameter("p_customer_address", obj_OrderInfo.CustomerAddress);
                    ReportParameter rp_customer_mobile    = new ReportParameter("p_customer_mobile", obj_OrderInfo.CustomerMobile);
                    ReportParameter rp_additional_request = new ReportParameter("p_additional_request", obj_OrderInfo.OrderDescription);
                    //Total Parameters
                    //
                    decimal subTotal = Convert.ToDecimal(obj_OrderInfo.OrderAmount - obj_OrderInfo.Tax - obj_OrderInfo.DeliveryCharges);

                    ReportParameter rp_sub_total        = new ReportParameter("p_sub_total", String.Format("{0:##,###.00}", subTotal.ToString()));
                    ReportParameter rp_tax              = new ReportParameter("p_tax", obj_OrderInfo.Tax.ToString());
                    ReportParameter rp_delivery_charges = new ReportParameter("p_delivery_charges", obj_OrderInfo.DeliveryCharges.ToString());
                    ReportParameter rp_grand_total      = new ReportParameter("p_grand_total", obj_OrderInfo.OrderAmount.ToString());
                    //Report DataSet
                    OrderDetailController order_Detail_controller = new OrderDetailController();
                    ReportDataSource      rds = new ReportDataSource("DataSet1", order_Detail_controller.GetAllOrderDetailByOrderID(OrderID));

                    rvOrderVoucher.Reset();
                    rvOrderVoucher.LocalReport.DataSources.Clear();
                    rvOrderVoucher.LocalReport.ReportPath = Server.MapPath("RDLC_OrderVoucher.rdlc");
                    rvOrderVoucher.LocalReport.SetParameters(new ReportParameter[] { rp_orderno, rp_order_date, rp_delivery_date, rp_order_quantity, rp_customer_name, rp_customer_address, rp_customer_mobile, rp_additional_request, rp_sub_total, rp_delivery_charges, rp_grand_total, rp_tax });
                    rvOrderVoucher.LocalReport.DataSources.Add(rds);
                    rvOrderVoucher.DataBind();
                    rvOrderVoucher.LocalReport.Refresh();
                }
            }
        }
コード例 #6
0
        public void printItemList(ref int ID, ref int mergeprint, ref double TotalQuantity, ref double TotalOrder, ref string Print)
        {
            var orderdetails = OrderDetailController.GetByOrderID(ID);

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

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

                        t++;
                        Print += "<tr>";
                        Print += "<td id='" + SKU + "'>" + t + "</td>";

                        if (ProductType == 1)
                        {
                            var product = ProductController.GetBySKU(SKU);
                            if (product != null)
                            {
                                ProductName = product.ProductTitle;
                                if (!string.IsNullOrEmpty(product.ProductImage))
                                {
                                    ProductImage = product.ProductImage;
                                }
                                Print += "<td><image src='" + Thumbnail.getURL(ProductImage, Thumbnail.Size.Large) + "' /></td> ";
                                Print += "<td><strong>" + SKU + "</strong> - " + (product.Old_Price > 0 ? "<span class='sale-icon'>SALE</span> " : "") + PJUtils.Truncate(ProductName, 30) + "</td> ";
                            }
                        }
                        else
                        {
                            var productvariable = ProductVariableController.GetBySKU(SKU);
                            if (productvariable != null)
                            {
                                var parent_product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                                if (parent_product != null)
                                {
                                    ProductName = parent_product.ProductTitle;

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

                                Print += "<td id='" + parent_product.ProductSKU + "'><image src='" + Thumbnail.getURL(ProductImage, Thumbnail.Size.Large) + "' /></td>";
                                Print += "<td><p><strong>" + SKU + "</strong> - " + (parent_product.Old_Price > 0 ? "<span class='sale-icon'>SALE</span> " : "") + PJUtils.Truncate(ProductName, 30) + "</p><p class='variable'>" + item.ProductVariableDescrition.Replace("|", ". ") + "</p></td> ";
                            }
                        }

                        Print += "<td>" + item.Quantity + "</td>";
                        Print += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>";
                        Print += "<td>" + string.Format("{0:N0}", SubTotal) + "</td>";
                        Print += "</tr>";

                        TotalOrder += SubTotal;

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

                            Print += "<div class='print-order-image'>";
                            Print += "<div class='all print print-" + print + "'>";
                            Print += "<div class='body'>";
                            Print += "<div class='table-2'>";
                            Print += "<table>";
                            Print += "<colgroup>";
                            Print += "<col class='order-item' />";
                            Print += "<col class='image' />";
                            Print += "<col class='name' />";
                            Print += "<col class='quantity' />";
                            Print += "<col class='price' />";
                            Print += "<col class='subtotal' />";
                            Print += "</colgroup>";
                            Print += "<thead>";
                            Print += "<th>#</th>";
                            Print += "<th>Hình ảnh</th>";
                            Print += "<th>Sản phẩm</th>";
                            Print += "<th>SL</th>";
                            Print += "<th>Giá</th>";
                            Print += "<th>Tổng</th>";
                            Print += "</thead>";
                            Print += "<tbody>";
                            print++;
                        }
                    }
                }
                else
                {
                    int t     = 0;
                    int print = 1;
                    for (int i = 0; i < orderdetails.Count; i++)
                    {
                        if (orderdetails[i] != null)
                        {
                            t++;
                            Print += "<tr>";
                            Print += "<td>" + t + "</td>";

                            double ItemPrice1  = Convert.ToDouble(orderdetails[i].Price);
                            int    categoryID1 = getCategory(orderdetails[i].SKU, Convert.ToInt32(orderdetails[i].ProductType));

                            int quantity = Convert.ToInt32(orderdetails[i].Quantity);

                            for (int j = i + 1; j < orderdetails.Count; j++)
                            {
                                if (orderdetails[j] != null)
                                {
                                    int categoryID2 = getCategory(orderdetails[j].SKU, Convert.ToInt32(orderdetails[j].ProductType));

                                    double ItemPrice2 = Convert.ToDouble(orderdetails[j].Price);

                                    if (categoryID1 == categoryID2 && orderdetails[i].Price == orderdetails[j].Price)
                                    {
                                        quantity       += Convert.ToInt32(orderdetails[j].Quantity);
                                        orderdetails[j] = null;
                                    }
                                }
                            }

                            var    category = CategoryController.GetByID(categoryID1);
                            double SubTotal = ItemPrice1 * quantity;
                            Print         += "<td>" + category.CategoryName + " " + string.Format("{0:N0}", ItemPrice1) + "</td>";
                            Print         += "<td>" + quantity + "</td>";
                            Print         += "<td>" + string.Format("{0:N0}", ItemPrice1) + "</td>";
                            Print         += "<td>" + string.Format("{0:N0}", SubTotal) + "</td>";
                            Print         += "</tr>";
                            TotalOrder    += SubTotal;
                            TotalQuantity += quantity;
                        }

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

                            Print += "<div class=\"print-order-image\">";
                            Print += "<div class=\"all print print-" + print + "\">";
                            Print += "<div class=\"body\">";
                            Print += "<div class=\"table-2\">";
                            Print += "<table>";
                            Print += "<colgroup>";
                            Print += "<col class=\"order-item\" />";
                            Print += "<col class=\"name\" />";
                            Print += "<col class=\"quantity\" />";
                            Print += "<col class=\"price\" />";
                            Print += "<col class=\"subtotal\"/>";
                            Print += "</colgroup>";
                            Print += "<thead>";
                            Print += "<th>#</th>";
                            Print += "<th>Hình ảnh</th>";
                            Print += "<th>Sản phẩm</th>";
                            Print += "<th>SL</th>";
                            Print += "<th>Giá</th>";
                            Print += "<th>Tổng</th>";
                            Print += "</thead>";
                            Print += "<tbody>";
                            print++;
                        }
                    }
                }
            }
        }
コード例 #7
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!!!";
            }
        }
コード例 #8
0
        public void printItemList(ref int ID, ref int mergeprint, ref double TotalQuantity, ref double TotalOrder, ref string Print)
        {
            var orderdetails = OrderDetailController.GetByIDSortBySKU(ID);

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

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

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

                        if (ProductType == 1)
                        {
                            var product = ProductController.GetBySKU(SKU);
                            if (product != null)
                            {
                                ProductName = product.ProductTitle;
                                Print      += "<td><strong>" + SKU + "</strong> - " + PJUtils.Truncate(ProductName, 20) + "</td> ";
                            }
                        }
                        else
                        {
                            var productvariable = ProductVariableController.GetBySKU(SKU);
                            if (productvariable != null)
                            {
                                var parent_product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                                if (parent_product != null)
                                {
                                    ProductName = parent_product.ProductTitle;
                                }
                                Print += "<td><strong>" + SKU + "</strong> - " + PJUtils.Truncate(ProductName, 20) + " - " + item.ProductVariableDescrition.Replace("|", ". ") + "</td> ";
                            }
                        }

                        Print += "<td>" + item.Quantity + "</td>";
                        Print += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>";
                        Print += "<td>" + string.Format("{0:N0}", SubTotal) + "</td>";
                        Print += "</tr>";

                        TotalOrder += SubTotal;
                    }
                }
                else
                {
                    int t = 0;
                    for (int i = 0; i < orderdetails.Count; i++)
                    {
                        if (orderdetails[i] != null)
                        {
                            t++;
                            Print += "<tr>";
                            Print += "<td>" + t + "</td>";

                            double ItemPrice1  = Convert.ToDouble(orderdetails[i].Price);
                            int    categoryID1 = getCategory(orderdetails[i].SKU, Convert.ToInt32(orderdetails[i].ProductType));

                            int quantity = Convert.ToInt32(orderdetails[i].Quantity);

                            for (int j = i + 1; j < orderdetails.Count; j++)
                            {
                                if (orderdetails[j] != null)
                                {
                                    int categoryID2 = getCategory(orderdetails[j].SKU, Convert.ToInt32(orderdetails[j].ProductType));

                                    double ItemPrice2 = Convert.ToDouble(orderdetails[j].Price);

                                    if (categoryID1 == categoryID2 && orderdetails[i].Price == orderdetails[j].Price)
                                    {
                                        quantity       += Convert.ToInt32(orderdetails[j].Quantity);
                                        orderdetails[j] = null;
                                    }
                                }
                            }

                            var    category = CategoryController.GetByID(categoryID1);
                            double SubTotal = ItemPrice1 * quantity;
                            Print         += "<td>" + category.CategoryName + " " + string.Format("{0:N0}", ItemPrice1) + "</td>";
                            Print         += "<td>" + quantity + "</td>";
                            Print         += "<td>" + string.Format("{0:N0}", ItemPrice1) + "</td>";
                            Print         += "<td>" + string.Format("{0:N0}", SubTotal) + "</td>";
                            Print         += "</tr>";
                            TotalOrder    += SubTotal;
                            TotalQuantity += quantity;
                        }
                    }
                }
            }
        }
コード例 #9
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);
                    }
                }
            }
        }
コード例 #10
0
ファイル: pos.aspx.cs プロジェクト: war-man/ANNsys
        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);
            }
        }
コード例 #11
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 OrderID = ViewState["ID"].ToString().ToInt(0);
                    if (OrderID > 0)
                    {
                        var order = OrderController.GetByID(OrderID);

                        if (order != null)
                        {
                            int ExcuteStatusOld = Convert.ToInt32(order.ExcuteStatus);

                            string OrderNote = txtOrderNote.Text;

                            // Xử lý nhập kho khi chuyển hoàn
                            if (ExcuteStatusOld != 4)
                            {
                                var orderDetails = OrderDetailController.GetByOrderID(order.ID);

                                foreach (tbl_OrderDetail product in orderDetails)
                                {
                                    int parentID = 0;

                                    if (product.ProductID != 0)
                                    {
                                        parentID = product.ProductID.Value;
                                    }
                                    else
                                    {
                                        parentID = ProductVariableController.GetByID(product.ProductVariableID.Value).ProductID.Value;
                                    }

                                    StockManagerController.Insert(
                                        new tbl_StockManager
                                    {
                                        AgentID           = product.AgentID,
                                        ProductID         = product.ProductID,
                                        ProductVariableID = product.ProductVariableID,
                                        Quantity          = product.Quantity,
                                        QuantityCurrent   = 0,
                                        Type        = 1,
                                        NoteID      = "Nhập kho do chuyển hoàn đơn " + product.OrderID,
                                        OrderID     = product.OrderID,
                                        Status      = 13,
                                        SKU         = product.SKU,
                                        CreatedDate = currentDate,
                                        CreatedBy   = product.CreatedBy,
                                        MoveProID   = 0,
                                        ParentID    = parentID
                                    });
                                }
                            }

                            bool updateOrder = OrderController.UpdateExcuteStatus4(order.ID, username, OrderNote);

                            if (updateOrder == true)
                            {
                                Response.Redirect("/thong-tin-don-hang-chuyen-hoan?id=" + order.ID);
                            }
                            else
                            {
                                PJUtils.ShowMessageBoxSwAlertCallFunction("Đã xảy ra lỗi", "s", true, "payAllClicked()", Page);
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
        public void LoadData()
        {
            DateTime        today    = DateTime.Now.Date;
            DateTime        now      = DateTime.Now;
            List <OrderTop> opdertop = new List <OrderTop>();
            var             or       = OrderController.Report(today.ToString(), now.ToString());

            if (or != null)
            {
                foreach (var item in or)
                {
                    List <OrderTop> tam   = new List <OrderTop>();
                    OrderTop        order = new OrderTop();
                    bool            check = opdertop.Any(x => x.CusID == item.CustomerID);
                    if (check == true)
                    {
                        for (int i = 0; i < opdertop.Count(); i++)
                        {
                            if (opdertop[i].CusID == item.CustomerID)
                            {
                                var ordetail = OrderDetailController.GetByOrderID(item.ID);
                                if (ordetail != null)
                                {
                                    int quantityp = 0;
                                    foreach (var temp in ordetail)
                                    {
                                        quantityp += Convert.ToInt32(temp.Quantity);
                                    }
                                    opdertop[i].Quantity += quantityp;
                                }
                                tam.Add(opdertop[i]);
                            }
                            else
                            {
                                tam.Add(opdertop[i]);
                            }
                        }
                        opdertop = tam;
                        tam      = null;
                    }
                    else
                    {
                        var cus = CustomerController.GetByID(item.CustomerID.Value);
                        if (cus != null)
                        {
                            order.CusID      = cus.ID;
                            order.CusName    = cus.CustomerName;
                            order.CreateBy   = cus.CreatedBy;
                            order.CusZalo    = cus.Zalo;
                            order.CusFB      = cus.Facebook;
                            order.CusNick    = cus.Nick;
                            order.CusAddress = cus.CustomerAddress;
                        }
                        var ordetail = OrderDetailController.GetByOrderID(item.ID);
                        if (ordetail != null)
                        {
                            int quantityp = 0;
                            foreach (var temp in ordetail)
                            {
                                quantityp += Convert.ToInt32(temp.Quantity);
                            }
                            order.Quantity = quantityp;
                        }
                        opdertop.Add(order);
                    }
                }
            }

            if (opdertop.Count() > 0)
            {
                pagingall(opdertop.OrderByDescending(x => x.Quantity).Take(10).ToList());
            }
        }
コード例 #13
0
        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!!!";
            }
        }
コード例 #14
0
        public void pagingall(List <tbl_Order> acs)
        {
            int           PageSize = 30;
            StringBuilder html     = new StringBuilder();

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

                Int32 Page = GetIntFromQueryString("Page");

                if (Page == -1)
                {
                    Page = 1;
                }
                int FromRow = (Page - 1) * PageSize;
                int ToRow   = Page * PageSize - 1;
                if (ToRow >= TotalItems)
                {
                    ToRow = TotalItems - 1;
                }
                for (int i = FromRow; i < ToRow + 1; i++)
                {
                    var item = acs[i];
                    html.Append("<tr>");
                    html.Append("   <td><a href=\"/thong-tin-don-hang?id=" + item.ID + "\">" + item.ID + "</a></td>");
                    html.Append("   <td>" + PJUtils.OrderTypeStatus(Convert.ToInt32(item.OrderType)) + "</td>");
                    html.Append("   <td>" + item.CustomerPhone + "</td>");
                    var customer = CustomerController.GetByID(Convert.ToInt32(item.CustomerID));
                    if (customer != null)
                    {
                        if (!string.IsNullOrEmpty(customer.Nick))
                        {
                            html.Append("   <td><a class=\"customer-name-link\" href=\"/thong-tin-don-hang-chuyen-hoan?id=" + item.ID + "\">" + customer.Nick.ToTitleCase() + "</a><br><span class=\"name-bottom-nick\">(" + item.CustomerName.ToTitleCase() + ")</span></td>");
                        }
                        else
                        {
                            html.Append("   <td><a class=\"customer-name-link\" href=\"/thong-tin-don-hang-chuyen-hoan?id=" + item.ID + "\">" + item.CustomerName.ToTitleCase() + "</a></td>");
                        }
                    }
                    else
                    {
                        html.Append("   <td><a class=\"customer-name-link\" href=\"/thong-tin-don-hang-chuyen-hoan?id=" + item.ID + "\">" + item.CustomerName.ToTitleCase() + "</a></td>");
                    }

                    var orderdetails = OrderDetailController.GetByOrderID(item.ID);
                    int quantity     = 0;
                    if (orderdetails.Count > 0)
                    {
                        foreach (var temp in orderdetails)
                        {
                            quantity += Convert.ToInt32(temp.Quantity);
                        }
                    }
                    html.Append("   <td>" + quantity + "</td>");
                    html.Append("   <td>" + PJUtils.OrderPaymentStatus(Convert.ToInt32(item.PaymentStatus)) + "</td>");
                    html.Append("   <td>" + PJUtils.OrderExcuteStatus(Convert.ToInt32(item.ExcuteStatus)) + "</td>");
                    html.Append("   <td>" + PJUtils.PaymentType(Convert.ToInt32(item.PaymentType)) + "</td>");
                    html.Append("   <td>" + PJUtils.ShippingType(Convert.ToInt32(item.ShippingType)) + "</td>");
                    html.Append("   <td>" + string.Format("{0:N0}", Convert.ToDouble(item.TotalPrice)) + "</td>");

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

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

                    html.Append("   <td>");
                    html.Append("       <a href=\"/chi-tiet-khach-hang?id=" + item.CustomerID + "\" title=\"Thông tin khách hàng " + item.CustomerName + "\" target=\"_blank\" class=\"btn primary-btn btn-black h45-btn\"><i class=\"fa fa-user-circle\" aria-hidden=\"true\"></i></a>");
                    html.Append("   </td>");
                    html.Append("</tr>");
                }
            }
            ltrList.Text = html.ToString();
        }
コード例 #15
0
 public OrderDetailControllerTests()
 {
     _orderDetailService = new Mock <IOrderDetailService>();
     _categoryService    = new Mock <ICategoryService>();
     _target             = new OrderDetailController(_orderDetailService.Object, _categoryService.Object);
 }
コード例 #16
0
        public void LoadData()
        {
            int ID         = Request.QueryString["id"].ToInt(0);
            int mergeprint = 0;

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

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

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

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

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

                        ltrOldOrderNote.Text = notehtml.ToString();
                    }

                    #endregion

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

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

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;

                    var orderdetails = OrderDetailController.GetByIDSortBySKU(ID);

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

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

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

                        productPrint += "<div class=\"body\">";
                        productPrint += "<div class=\"table-1\">";
                        productPrint += "<h1>XÁC NHẬN ĐƠN HÀNG #" + order.ID + "</h1>";
                        productPrint += "<div class=\"note\">";
                        productPrint += "<p>- Lưu ý, hình ảnh sản phẩm có thể hiển thị không đúng màu.</p>";
                        productPrint += "<p>- Quý khách vui lòng kiểm tra thuộc tính sản phẩm (Màu, Size).</p>";
                        productPrint += "<p>- Nếu có sai sót, quý khách vui lòng thông báo cho nhân viên.</p>";
                        productPrint += "</div>";
                        productPrint += "<table>";
                        productPrint += "<colgroup >";
                        productPrint += "<col class=\"col-left\"/>";
                        productPrint += "<col class=\"col-right\"/>";
                        productPrint += "</colgroup>";
                        productPrint += "<tbody>";
                        productPrint += "<tr>";
                        productPrint += "<td>Khách hàng</td>";
                        productPrint += "<td class=\"customer-name\">" + order.CustomerName + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Điện thoại</td>";
                        productPrint += "<td>" + order.CustomerPhone + "</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td>Ngày tạo</td>";
                        string date = string.Format("{0:dd/MM/yyyy HH:mm}", order.CreatedDate);
                        productPrint += "<td>" + date + "</td>";
                        productPrint += "</tr>";

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

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

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

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

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

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

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

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

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

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

                        double TotalPrice = TotalOrder;

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

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

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

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

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

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

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

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

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

                        productPrint += "<tr>";
                        productPrint += "<td colspan=\"" + colspan + "\" class=\"strong align-right\">TỔNG CỘNG</td>";
                        productPrint += "<td class=\"strong\">" + string.Format("{0:N0}", TotalOrder) + "</td>";
                        productPrint += "</tr>";


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

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

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


                        if (numberOfOrders.Count < 4)
                        {
                            shtml += "<div class=\"head\">";
                            string address = "";
                            string phone   = "";
                            var    agent   = AgentController.GetByID(Convert.ToInt32(order.AgentID));
                            if (agent != null)
                            {
                                address = agent.AgentAddress;
                                phone   = agent.AgentPhone;
                            }

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

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

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

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

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



                        shtml += productPrint;

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

                        if (error != "")
                        {
                            ltrPrintInvoice.Text = "Xảy ra lỗi: " + error;
                        }
                        else
                        {
                            ltrPrintInvoice.Text = shtml;
                        }
                    }
                }
                else
                {
                    ltrPrintInvoice.Text = "Không tìm thấy đơn hàng " + ID;
                }
            }
            else
            {
                ltrPrintInvoice.Text = "Xảy ra lỗi!!!";
            }
        }
コード例 #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["OrderID"].ToString() != null)
            {
                string CustomerID = "", IsAdmin = "";
                if (Request.Cookies["CustomerID"] != null)
                {
                    CustomerID = Request.Cookies["CustomerID"].Value;
                }
                if (Request.Cookies["IsAdmin"] != null)
                {
                    IsAdmin = Request.Cookies["IsAdmin"].Value;
                }

                string          OrderID       = Request.QueryString["OrderID"].ToString();
                OrderController orderControl  = new OrderController();
                OrderInfo       obj_OrderInfo = orderControl.GetOrderByID(OrderID);
                //Bind to Header
                order_id.InnerText        = OrderID;
                lblOrderNo.Text           = obj_OrderInfo.OrderNo;
                lblOrderDate.Text         = String.Format("{0:dd-MMM-yyyy}", obj_OrderInfo.OrderDate);
                lblCustomerName.Text      = obj_OrderInfo.CustomerName;
                lblCustomerMobile.Text    = obj_OrderInfo.CustomerMobile;
                lblOrderQuantity.Text     = obj_OrderInfo.OrderQuantity.ToString();
                lblCustomerAddress.Text   = obj_OrderInfo.CustomerAddress;
                lblAdditionalRequest.Text = obj_OrderInfo.OrderDescription;
                if (obj_OrderInfo.EstDeliveryDate != null)
                {
                    lblDeliveryDate.Text = Convert.ToDateTime(obj_OrderInfo.EstDeliveryDate).ToString("dd-MMM-yyy");
                }

                //Bind to Total
                lblSubTotal.Text = (obj_OrderInfo.OrderAmount - obj_OrderInfo.Tax - obj_OrderInfo.DeliveryCharges).ToString();
                decimal taxPercentage = Settings.Default.CommercialTax;
                LabelTax.Text           = "Tax (" + taxPercentage.ToString() + "%)";
                lblTax.Text             = obj_OrderInfo.Tax.ToString();
                lblDeliveryCharges.Text = obj_OrderInfo.DeliveryCharges.ToString();
                lblGrandTotal.Text      = obj_OrderInfo.OrderAmount.ToString();

                OrderDetailController orderDetailControl = new OrderDetailController();
                DataTable             dt_Cart            = new DataTable();
                dt_Cart = orderDetailControl.GetAllOrderDetailByOrderID(OrderID);
                //Bind to List View
                productList.DataSource = dt_Cart;
                productList.DataBind();

                //already login and login user is admin
                if (!String.IsNullOrEmpty(CustomerID) && (!String.IsNullOrEmpty(IsAdmin) && Convert.ToBoolean(IsAdmin) == true))
                {
                    btnCheckOrder.Visible = true;
                    //Button Text change and disable/enable
                    if (obj_OrderInfo.OrderStatus == "Created")
                    {
                        deliverydiv.Visible    = true;
                        lbldeliverydiv.Visible = false;

                        btnCheckOrder.Enabled = true;
                        btnCheckOrder.Text    = "Order Confirm";
                    }
                    else if (obj_OrderInfo.OrderStatus == "Confirmed")
                    {
                        deliverydiv.Visible    = false;
                        lbldeliverydiv.Visible = true;

                        btnCheckOrder.Enabled = false;
                        btnCheckOrder.Text    = "Order Confirmed";
                    }
                    else if (obj_OrderInfo.OrderStatus == "Delivered")
                    {
                        deliverydiv.Visible    = false;
                        lbldeliverydiv.Visible = true;

                        btnCheckOrder.Enabled = false;
                        btnCheckOrder.Text    = "Done";
                    }
                }
                else
                {
                    btnCheckOrder.Visible = false;
                    if (obj_OrderInfo.OrderStatus == "Created")
                    {
                        deliverydiv.Visible    = false;
                        lbldeliverydiv.Visible = false;
                    }
                    else
                    {
                        deliverydiv.Visible    = false;
                        lbldeliverydiv.Visible = true;
                    }
                }
            }
        }
コード例 #18
0
        public void pagingall(List <tbl_Discount> acs)
        {
            int           PageSize = 30;
            StringBuilder html     = new StringBuilder();

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

                Int32 Page = GetIntFromQueryString("Page");

                if (Page == -1)
                {
                    Page = 1;
                }
                int FromRow = (Page - 1) * PageSize;
                int ToRow   = Page * PageSize - 1;
                if (ToRow >= TotalItems)
                {
                    ToRow = TotalItems - 1;
                }
                for (int i = FromRow; i < ToRow + 1; i++)
                {
                    var item = acs[i];
                    html.Append("<tr>");
                    //html.Append("   <td>" + item.ID + "</td>");
                    var order         = OrderController.GetByCustomerID(item.ID);
                    int TotalQuantity = 0;
                    if (order != null)
                    {
                        foreach (var temp in order)
                        {
                            var detail = OrderDetailController.GetByOrderID(temp.ID);
                            if (detail != null)
                            {
                                foreach (var vl in detail)
                                {
                                    TotalQuantity += Convert.ToInt32(vl.Quantity);
                                }
                            }
                        }
                    }
                    html.Append("   <td>" + item.ID + "</td>");
                    html.Append("   <td>" + item.Quantity + "</td>");
                    html.Append("   <td>" + string.Format("{0:N0}", Convert.ToDouble(item.DiscountPerProduct)) + "</td>");


                    html.Append("   <td>");
                    //html.Append("       <a href=\"/chi-tiet-khach-hang?id=" + item.ID + "\" class=\"btn primary-btn h45-btn\">Chi tiết</a>");
                    html.Append("       <a href=\"/chi-tiet-chiet-khau?id=" + item.ID + "\" class=\"btn primary-btn h45-btn\">Chi tiết</a>");
                    html.Append("   </td>");
                    html.Append("</tr>");
                }
            }
            ltrList.Text = html.ToString();
        }
コード例 #19
0
        public void pagingall(List <CustomerOut> acs)
        {
            string username = Request.Cookies["userLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            int           PageSize = 30;
            StringBuilder html     = new StringBuilder();

            html.Append("<tr>");
            html.Append("     <th class='image-column'>Ảnh</th>");
            html.Append("     <th class='nick-column'>Nick đặt hàng</th>");
            html.Append("     <th class='name-column'>Họ tên</th>");
            html.Append("     <th class='phone-column'>Điện thoại</th>");
            html.Append("     <th class='zalo-column'>Zalo</th>");
            html.Append("     <th class='facebook-column'>FB</th>");
            html.Append("     <th class='province-column'>Tỉnh</th>");
            html.Append("     <th class='buy-column'>Đơn</th>");
            html.Append("     <th class='buy-column'>Mua</th>");
            if (acc.RoleID == 0)
            {
                html.Append("     <th class='staff-column'>Nhân viên</th>");
            }
            html.Append("     <th class='group-column'>Nhóm</th>");
            html.Append("     <th class='date-column'>Ngày tạo</th>");
            html.Append("     <th class='action-column'></th>");
            html.Append("</tr>");

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

                Int32 Page = GetIntFromQueryString("Page");

                if (Page == -1)
                {
                    Page = 1;
                }
                int FromRow = (Page - 1) * PageSize;
                int ToRow   = Page * PageSize - 1;
                if (ToRow >= TotalItems)
                {
                    ToRow = TotalItems - 1;
                }
                for (int i = FromRow; i < ToRow + 1; i++)
                {
                    var item = acs[i];
                    html.Append("<tr>");

                    var order         = OrderController.GetByCustomerID(item.ID);
                    int TotalQuantity = 0;
                    int TotalOrder    = 0;
                    if (order != null)
                    {
                        foreach (var temp in order)
                        {
                            var detail = OrderDetailController.GetByOrderID(temp.ID);
                            TotalOrder++;
                            if (detail != null)
                            {
                                foreach (var vl in detail)
                                {
                                    TotalQuantity += Convert.ToInt32(vl.Quantity);
                                }
                            }
                        }
                    }

                    html.Append("   <td><a href=\"/chi-tiet-khach-hang?id=" + item.ID + "\"><img src=\"" + item.Avatar + "\"/></a></td>");
                    html.Append("   <td class=\"customer-name-link capitalize\">" + item.Nick + "</td>");
                    html.Append("   <td class=\"customer-name-link capitalize\"><a href=\"/chi-tiet-khach-hang?id=" + item.ID + "\">" + item.CustomerName + "</a></td>");
                    html.Append("   <td>" + item.CustomerPhone + "</td>");
                    html.Append("   <td>" + item.Zalo + "</td>");

                    if (!string.IsNullOrEmpty(item.Facebook))
                    {
                        html.Append("   <td><a class=\"link\" href=\"" + item.Facebook + "\" target=\"_blank\">Xem</a></td>");
                    }
                    else
                    {
                        html.Append("   <td></td>");
                    }

                    if (!string.IsNullOrEmpty(item.Province))
                    {
                        var pro = ProvinceController.GetByID(item.Province.ToInt());
                        if (pro != null)
                        {
                            html.Append("   <td>" + pro.ProvinceName + "</td>");
                        }
                        else
                        {
                            html.Append("   <td></td>");
                        }
                    }
                    else
                    {
                        html.Append("   <td></td>");
                    }

                    if (TotalOrder > 0)
                    {
                        html.Append("   <td>" + TotalOrder + " đơn</td>");
                    }
                    else
                    {
                        html.Append("   <td></td>");
                    }

                    if (TotalQuantity > 0)
                    {
                        html.Append("   <td>" + TotalQuantity + " cái</td>");
                    }
                    else
                    {
                        html.Append("   <td></td>");
                    }

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

                    if (!string.IsNullOrEmpty(item.DiscountName))
                    {
                        string[] dis = item.DiscountName.Split('|');
                        if (dis.Count() > 1)
                        {
                            html.Append("   <td>" + dis[0] + "</br>" + dis[1] + "</td>");
                        }
                    }
                    else
                    {
                        html.Append("   <td>" + item.DiscountName + "</td>");
                    }

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

                    string ishidden = "";
                    if (item.IsHidden != null)
                    {
                        bool IsHidden = Convert.ToBoolean(item.IsHidden);
                        ishidden = PJUtils.IsHiddenStatus(IsHidden);
                    }
                    else
                    {
                        ishidden = PJUtils.IsHiddenStatus(false);
                    }

                    html.Append("   <td>");
                    html.Append("       <a href=\"/danh-sach-don-hang?textsearch=" + item.CustomerPhone + "\" title=\"Xem đơn hàng\" class=\"btn primary-btn h45-btn\"><i class=\"fa fa-shopping-cart\" aria-hidden=\"true\"></i></a>");
                    html.Append("   </td>");
                    html.Append("</tr>");
                }
            }
            else
            {
                if (acc.RoleID == 0)
                {
                    html.Append("<tr><td colspan=\"12\">Không tìm thấy khách hàng...</td></tr>");
                }
                else
                {
                    html.Append("<tr><td colspan=\"11\">Không tìm thấy khách hàng...</td></tr>");
                }
            }

            ltrList.Text = html.ToString();
        }
コード例 #20
0
ファイル: print-invoice.aspx.cs プロジェクト: war-man/ANNsys
        public void LoadData()
        {
            int ID         = Request.QueryString["id"].ToInt(0);
            int mergeprint = 0;

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

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

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

                    double TotalQuantity = 0;
                    double TotalOrder    = 0;


                    var orderdetails = OrderDetailController.GetByIDSortBySKU(ID);

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

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

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

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

                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class='col-left'/>";
                        productPrint += "<col class='col-right'/>";
                        productPrint += "</colgroup>";
                        productPrint += "<tbody>";
                        productPrint += "<tr>";
                        productPrint += "<td>Khách hàng</td>";
                        productPrint += "<td>" + order.CustomerName.ToTitleCase() + "</td>";
                        productPrint += "</tr>";

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

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

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

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

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

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

                        productPrint += "<div class='table-2'>";
                        productPrint += "<table>";
                        productPrint += "<colgroup>";
                        productPrint += "<col class='soluong' />";
                        productPrint += "<col class='gia' />";
                        productPrint += "<col class='tong' />";
                        productPrint += "</colgroup>";
                        productPrint += "<thead>";
                        productPrint += "<th>Số lượng</th>";
                        productPrint += "<th>Giá</th>";
                        productPrint += "<th>Tổng</th>";
                        productPrint += "</thead>";
                        productPrint += "<tbody>";
                        productPrint += Print;
                        productPrint += "</tbody>";
                        productPrint += "</table>";
                        productPrint += "</div>";

                        productPrint += "<div class='table-3'>";
                        productPrint += "<table>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan='2'>Số lượng</td>";
                        productPrint += "<td>" + TotalQuantity + "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                        productPrint += "</tr>";
                        productPrint += "<tr>";
                        productPrint += "<td colspan='2'>Thành tiền</td>";
                        productPrint += "<td>" + string.Format("{0:N0}", TotalOrder) + "&nbsp;</td>";
                        productPrint += "</tr>";

                        double TotalPrice = TotalOrder;

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

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

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

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


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

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

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

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


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

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


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


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

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

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

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

                        if (numberOfOrders.Count < 4)
                        {
                            shtml += "<div class='head'>";
                            shtml += "<div class='logo'><div class='img'><img src='App_Themes/Ann/image/logo.png' /></div></div>";
                            shtml += "<div class='info'>";

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

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

                            shtml += "<div class='ct'>";
                            shtml += "<div class='ct-title'></div>";
                            shtml += "<div class='ct-detail'>http://ann.com.vn</div>";
                            shtml += "</div>";

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

                        shtml += productPrint;

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

                            shtml += "<div class='footer'><h3>CẢM ƠN QUÝ KHÁCH! HẸN GẶP LẠI !</h3></div> ";
                            shtml += "<div class='footer'>" + rule + "</div> ";
                        }
                        else
                        {
                            shtml += "<div class='footer'>";
                            shtml += "<p>ANN rất vui khi quý khách đã mua " + numberOfOrders.Count + " đơn hàng!</p>";
                            shtml += "</div>";
                        }

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

                        if (error != "")
                        {
                            ltrPrintInvoice.Text = "Xảy ra lỗi: " + error;
                            ltrPrintEnable.Text  = "";
                        }
                        else
                        {
                            ltrPrintInvoice.Text = shtml;
                            ltrPrintEnable.Text  = "<div class='print-enable true'></div>";
                        }
                    }
                }
                else
                {
                    ltrPrintInvoice.Text = "Không tìm thấy đơn hàng " + ID;
                }
            }
            else
            {
                ltrPrintInvoice.Text = "Xảy ra lỗi!!!";
            }
        }
コード例 #21
0
        protected void btnCreateOrder_Click(object sender, EventArgs e)
        {
            int     orderQty = 0; decimal totalAmount = 0, discountAmount = 0;
            string  customerID    = txtCustomerID.Text;
            decimal taxPercentage = Convert.ToDecimal(txtTax.Text);

            //============ Detail Data Preparation ============
            ProductDiscountController productDiscountController = new ProductDiscountController();
            List <OrderDetail>        lst_OrderDetailInfo       = new List <OrderDetail>();
            List <CartInfo>           lstCart = GettingJson(customerID);

            foreach (CartInfo obj in lstCart)
            {
                if (obj.Quantity > 0)
                {
                    orderQty      += obj.Quantity;
                    discountAmount = productDiscountController.GetDiscountByProductID(obj.ProductID);

                    OrderDetail obj_OrderDetail = new OrderDetail();
                    obj_OrderDetail.ProductID      = obj.ProductID;
                    obj_OrderDetail.Quantity       = obj.Quantity;
                    obj_OrderDetail.Price          = obj.ProductPrice;
                    obj_OrderDetail.DiscountAmount = discountAmount;
                    lst_OrderDetailInfo.Add(obj_OrderDetail);

                    totalAmount += obj.Quantity * (obj.ProductPrice - discountAmount);
                }
            }
            decimal commercialTax = decimal.Round(totalAmount * (taxPercentage / 100), 2);

            string[] selectedValue   = (ddlTownship.Items[ddlTownship.SelectedIndex].Value).Split('-');
            decimal  deliveryCharges = Convert.ToDecimal(selectedValue[1]);

            //============ Header Data Preparation ============
            OrderInfo obj_OrderInfo = new OrderInfo();

            obj_OrderInfo.OrderDate        = DateTime.Now;
            obj_OrderInfo.OrderQuantity    = orderQty;
            obj_OrderInfo.Tax              = commercialTax;                                 //When I get directly from lable, I can't get last changes amount.
            obj_OrderInfo.DiscountAmount   = Convert.ToDecimal(0);                          //Will add control later.
            obj_OrderInfo.DeliveryCharges  = deliveryCharges;
            obj_OrderInfo.OrderAmount      = totalAmount + commercialTax + deliveryCharges; //When I get directly from lable, I can't get last changes amount.
            obj_OrderInfo.OrderDescription = txtOrderDescription.Text;
            obj_OrderInfo.OrderStatus      = "Created";
            obj_OrderInfo.CustomerID       = customerID;

            //============ Insert Data ============
            OrderController orderControl     = new OrderController();
            OrderInfo       return_OrderInfo = orderControl.InsertOrder(obj_OrderInfo);

            if (return_OrderInfo != null)
            {
                OrderDetailController orderDetailControl = new OrderDetailController();
                orderDetailControl.InsertOrderDetail(return_OrderInfo.OrderID, lst_OrderDetailInfo);

                //============ Delete Json File ============
                File.Delete(Server.MapPath("~/CartJson/" + customerID + "_cart.json"));
            }

            Response.Redirect("OrderInfoList.aspx");
            #region +++ When you want to get data from Listview +++
            ////for (int i = 0; i < productList.Items.Count; i++)
            ////{
            ////    Label lblProductID = (Label)productList.Items[i].FindControl("lbl_ProductID");
            ////    string productID = lblProductID.Text;
            ////}
            #endregion
        }
コード例 #22
0
        public void printItemList(ref int ID, ref double TotalQuantity, ref double TotalOrder, ref string Print)
        {
            var orderdetails = OrderDetailController.GetByOrderID(ID);

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

                    int    ProductType  = Convert.ToInt32(item.ProductType);
                    double ItemPrice    = Convert.ToDouble(item.Price);
                    string SKU          = item.SKU;
                    string ProductName  = "";
                    string ProductImage = "/App_Themes/Ann/image/placeholder.png";
                    int    SubTotal     = Convert.ToInt32(ItemPrice) * Convert.ToInt32(item.Quantity);

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

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

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

                            Print += "<td><image src=\"" + ProductImage + "\" /></td>";
                            Print += "<td><p><strong>" + SKU + "</strong> - " + PJUtils.Truncate(ProductName, 30) + "</p><p class=\"variable\">" + item.ProductVariableDescrition.Replace("|", ". ") + "</p></td> ";
                        }
                    }

                    Print += "<td>" + item.Quantity + "</td>";
                    Print += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>";
                    Print += "<td>" + string.Format("{0:N0}", SubTotal) + "</td>";
                    Print += "</tr>";

                    TotalOrder += SubTotal;

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

                        Print += "<div class=\"print-order-image\">";
                        Print += "<div class=\"all print print-" + print + "\">";
                        Print += "<div class=\"body\">";
                        Print += "<div class=\"table-2\">";
                        Print += "<table>";
                        Print += "<colgroup>";
                        Print += "<col class=\"order-item\" />";
                        Print += "<col class=\"image\" />";
                        Print += "<col class=\"name\" />";
                        Print += "<col class=\"quantity\" />";
                        Print += "<col class=\"price\" />";
                        Print += "<col class=\"subtotal\"/>";
                        Print += "</colgroup>";
                        Print += "<thead>";
                        Print += "<th>#</th>";
                        Print += "<th>Hình ảnh</th>";
                        Print += "<th>Sản phẩm</th>";
                        Print += "<th>SL</th>";
                        Print += "<th>Giá</th>";
                        Print += "<th>Tổng</th>";
                        Print += "</thead>";
                        Print += "<tbody>";
                        print++;
                    }
                }
            }
        }
コード例 #23
0
        public void InserOrder1(string AgentAPIID, string AgentAPICode, int OrderType, string CustomerName, string CustomerPhone, string CustomerEmail,
                                string CustomerAddress, double TotalPrice, int PaymentStatus, int ExcuteStatus, List <ProductOrder> ListProduct, string CreatedBy, string username, string password)
        {
            var rs = new ResponseClass();

            if (Login(username, password))
            {
                DateTime currentDate = DateTime.Now;
                var      agent       = AgentController.GetByAPICodeID(AgentAPIID, AgentAPICode);
                if (agent != null)
                {
                    int    AgentID     = agent.ID;
                    int    CustomerID  = 0;
                    string AdditionFee = "0";
                    string DisCount    = "0";
                    var    checkphone  = CustomerController.GetByPhone(CustomerPhone);
                    if (checkphone != null)
                    {
                        CustomerID = checkphone.ID;
                    }
                    else
                    {
                        string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, CreatedBy, false, "", "", "", "", "");
                        if (kq.ToInt(0) > 0)
                        {
                            CustomerID = kq.ToInt(0);
                        }
                    }
                    bool IsHidden = false;
                    int  Wayin    = 2;

                    var ret = OrderController.Insert(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress,
                                                     CustomerEmail, TotalPrice.ToString(), TotalPrice.ToString(), PaymentStatus, ExcuteStatus, IsHidden, Wayin, currentDate, CreatedBy, 0, 0, "0", 0, 0, DateTime.Now.ToString(), 0, 0, 0, 0, "", 0, 1);
                    int OrderID = ret.ID;
                    if (OrderID > 0)
                    {
                        if (ListProduct.Count > 0)
                        {
                            foreach (var p in ListProduct)
                            {
                                int ProductID         = 0;
                                int ProductVariableID = 0;

                                int    ID          = p.ID;
                                string SKU         = p.SKU;
                                int    producttype = p.ProductType;
                                if (producttype == 1)
                                {
                                    ProductID         = ID;
                                    ProductVariableID = 0;
                                }
                                else
                                {
                                    ProductID         = 0;
                                    ProductVariableID = ID;
                                }

                                string ProductVariableName  = p.ProductVariableName;
                                string ProductVariableValue = p.ProductVariableValue;
                                double Quantity             = Convert.ToDouble(p.Quantity);
                                string ProductName          = p.ProductName;
                                string ProductImageOrigin   = p.ProductImageOrigin;
                                double ProductPrice         = p.Price;
                                string ProductVariableSave  = p.ProductVariableDescription;


                                if (ExcuteStatus == 2 && PaymentStatus == 3)
                                {
                                    OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity,
                                                                 ProductPrice, 1, 0, producttype, currentDate, CreatedBy, true);
                                    if (producttype == 1)
                                    {
                                        StockManagerController.Insert(
                                            new tbl_StockManager()
                                        {
                                            AgentID           = AgentID,
                                            ProductID         = ProductID,
                                            ProductVariableID = 0,
                                            Quantity          = Quantity,
                                            QuantityCurrent   = 0,
                                            Type        = 2,
                                            NoteID      = String.Empty,
                                            OrderID     = OrderID,
                                            Status      = 3,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = CreatedBy,
                                            MoveProID   = 0,
                                            ParentID    = ProductID
                                        });
                                    }
                                    else
                                    {
                                        int    parentID  = 0;
                                        string parentSKU = "";
                                        var    productV  = ProductVariableController.GetByID(ProductVariableID);
                                        if (productV != null)
                                        {
                                            parentSKU = productV.ParentSKU;
                                        }
                                        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 = ProductVariableID,
                                            Quantity          = Quantity,
                                            QuantityCurrent   = 0,
                                            Type        = 2,
                                            NoteID      = String.Empty,
                                            OrderID     = OrderID,
                                            Status      = 3,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = CreatedBy,
                                            MoveProID   = 0,
                                            ParentID    = parentID,
                                        });
                                    }
                                }
                                else
                                {
                                    OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity,
                                                                 ProductPrice, 1, 0, producttype, currentDate, CreatedBy, false);
                                }
                            }
                        }
                        rs.Code    = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS);
                        rs.Status  = APIUtils.ResponseMessage.Success.ToString();
                        rs.Message = "Tạo mới đơn hàng thành công";
                    }
                    else
                    {
                        rs.Code    = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound);
                        rs.Status  = APIUtils.ResponseMessage.Error.ToString();
                        rs.Message = "Có lỗi trong quá trình tạo mới đơn hàng, vui lòng thử lại sau.";
                    }
                }
                else
                {
                    rs.Code    = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound);
                    rs.Status  = APIUtils.ResponseMessage.Error.ToString();
                    rs.Message = "Không tồn tại thông tin đại lý";
                }
            }
            else
            {
                rs.Code   = APIUtils.GetResponseCode(APIUtils.ResponseCode.FAILED);
                rs.Status = APIUtils.ResponseMessage.Fail.ToString();
            }

            Context.Response.ContentType = "application/json";
            Context.Response.Write(JsonConvert.SerializeObject(rs, Formatting.Indented));
            Context.Response.Flush();
            Context.Response.End();
        }
コード例 #24
0
        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));
                }
            }
        }
コード例 #25
0
        public void InserOrderDetail(string AgentAPIID, string AgentAPICode, int OrderID, int ID, string SKU, int ProductType,
                                     string ProductVariableName, string ProductVariableValue, double Quantity, string ProductName, string ProductImageOrigin,
                                     double ProductPrice, string ProductVariableSave, int ExcuteStatus, int PaymentStatus, string CreatedBy, string username, string password)
        {
            var rs = new ResponseClass();

            if (Login(username, password))
            {
                DateTime currentDate = DateTime.Now;
                var      agent       = AgentController.GetByAPICodeID(AgentAPIID, AgentAPICode);
                if (agent != null)
                {
                    int AgentID           = agent.ID;
                    int ProductID         = 0;
                    int ProductVariableID = 0;
                    if (ProductType == 1)
                    {
                        ProductID         = ID;
                        ProductVariableID = 0;
                    }
                    else
                    {
                        ProductID         = 0;
                        ProductVariableID = ID;
                    }

                    if (ExcuteStatus == 2 && PaymentStatus == 3)
                    {
                        OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity,
                                                     ProductPrice, 1, 0, ProductType, currentDate, CreatedBy, true);
                        if (ProductType == 1)
                        {
                            StockManagerController.Insert(
                                new tbl_StockManager
                            {
                                AgentID           = AgentID,
                                ProductID         = ProductID,
                                ProductVariableID = 0,
                                Quantity          = Quantity,
                                QuantityCurrent   = 0,
                                Type        = 2,
                                NoteID      = String.Empty,
                                OrderID     = OrderID,
                                Status      = 3,
                                SKU         = SKU,
                                CreatedDate = currentDate,
                                CreatedBy   = CreatedBy,
                                MoveProID   = 0,
                                ParentID    = ProductID
                            });
                        }
                        else
                        {
                            int    parentID  = 0;
                            string parentSKU = "";
                            var    productV  = ProductVariableController.GetByID(ProductVariableID);
                            if (productV != null)
                            {
                                parentSKU = productV.ParentSKU;
                            }
                            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 = ProductVariableID,
                                Quantity          = Quantity,
                                QuantityCurrent   = 0,
                                Type        = 2,
                                NoteID      = String.Empty,
                                OrderID     = OrderID,
                                Status      = 3,
                                SKU         = SKU,
                                CreatedDate = currentDate,
                                CreatedBy   = CreatedBy,
                                MoveProID   = 0,
                                ParentID    = parentID
                            });
                        }
                    }
                    else
                    {
                        OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity,
                                                     ProductPrice, 1, 0, ProductType, currentDate, CreatedBy, false);
                    }
                    rs.Code    = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS);
                    rs.Status  = APIUtils.ResponseMessage.Success.ToString();
                    rs.Message = "Tạo mới đơn hàng thành công";
                }
                else
                {
                    rs.Code    = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound);
                    rs.Status  = APIUtils.ResponseMessage.Error.ToString();
                    rs.Message = "Không tồn tại thông tin đại lý";
                }
            }
            else
            {
                rs.Code   = APIUtils.GetResponseCode(APIUtils.ResponseCode.FAILED);
                rs.Status = APIUtils.ResponseMessage.Fail.ToString();
            }

            Context.Response.ContentType = "application/json";
            Context.Response.Write(JsonConvert.SerializeObject(rs, Formatting.Indented));
            Context.Response.Flush();
            Context.Response.End();
        }
コード例 #26
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);
                    }
                }
            }
        }
コード例 #27
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            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)
                {
                    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 Nick                  = txtNick.Text.Trim();
                    string CustomerAddress       = txtAddress.Text.Trim().ToTitleCase();
                    string Zalo                  = "";
                    string Facebook              = txtFacebook.Text.Trim();
                    int    PaymentStatus         = ddlPaymentStatus.SelectedValue.ToInt();
                    int    ExcuteStatus          = ddlExcuteStatus.SelectedValue.ToInt();
                    int    PaymentType           = ddlPaymentType.SelectedValue.ToInt();
                    int    ShippingType          = ddlShippingType.SelectedValue.ToInt();
                    int    ProvinceID            = hdfProvinceID.Value.ToInt(0);
                    int    DistrictID            = hdfDistrictID.Value.ToInt(0);
                    int    WardID                = hdfWardID.Value.ToInt(0);
                    int    TransportCompanyID    = ddlTransportCompanyID.SelectedValue.ToInt(0);
                    int    TransportCompanySubID = hdfTransportCompanySubID.Value.ToInt(0);

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

                    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();

                    bool IsHidden = false;
                    int  WayIn    = 1;

                    string datedone = "";

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

                    var couponID    = hdfCouponID.Value.ToInt(0);
                    var couponValue = hdfCouponValue.Value.ToDecimal(0);

                    var orderNew = new tbl_Order()
                    {
                        AgentID               = AgentID,
                        OrderType             = OrderType,
                        AdditionFee           = AdditionFee,
                        DisCount              = DisCount,
                        CustomerID            = CustomerID,
                        CustomerName          = CustomerName,
                        CustomerPhone         = CustomerPhone,
                        CustomerAddress       = CustomerAddress,
                        CustomerEmail         = String.Empty,
                        TotalPrice            = totalPrice,
                        TotalPriceNotDiscount = totalPriceNotDiscount,
                        PaymentStatus         = PaymentStatus,
                        ExcuteStatus          = ExcuteStatus,
                        IsHidden              = IsHidden,
                        WayIn                 = WayIn,
                        CreatedDate           = currentDate,
                        CreatedBy             = username,
                        DiscountPerProduct    = Convert.ToDouble(pDiscount.Value),
                        TotalDiscount         = TotalDiscount,
                        FeeShipping           = FeeShipping,
                        PaymentType           = PaymentType,
                        ShippingType          = ShippingType,
                        GuestPaid             = 0,
                        GuestChange           = 0,
                        TransportCompanyID    = TransportCompanyID,
                        TransportCompanySubID = TransportCompanySubID,
                        OtherFeeName          = String.Empty,
                        OtherFeeValue         = 0,
                        PostalDeliveryType    = 1,
                        CouponID              = couponID,
                        CouponValue           = couponValue
                    };

                    if (!String.IsNullOrEmpty(datedone))
                    {
                        orderNew.DateDone = Convert.ToDateTime(datedone);
                    }

                    var ret = OrderController.Insert(orderNew);

                    // Insert 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);
                        }
                    }
                    // Insert Transfer Bank
                    var bankID = ddlBank.SelectedValue.ToInt(0);
                    if (bankID != 0)
                    {
                        BankTransferController.Create(ret, bankID, acc);
                    }

                    // Inactive code coupon
                    if (orderNew.CouponID.HasValue && orderNew.CouponID.Value > 0)
                    {
                        CouponController.updateStatusCouponCustomer(CustomerID, orderNew.CouponID.Value, false);
                    }

                    int OrderID = ret.ID;

                    if (OrderID > 0)
                    {
                        var    orderDetails = new List <tbl_OrderDetail>();
                        var    stockManager = new List <tbl_StockManager>();
                        string list         = hdfListProduct.Value;
                        var    items        = list.Split(';').Where(x => !String.IsNullOrEmpty(x)).ToList();
                        if (items.Count > 0)
                        {
                            items.Reverse();
                        }

                        foreach (var item in items)
                        {
                            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];

                            orderDetails.Add(new tbl_OrderDetail()
                            {
                                AgentID                   = AgentID,
                                OrderID                   = OrderID,
                                SKU                       = SKU,
                                ProductID                 = ProductID,
                                ProductVariableID         = ProductVariableID,
                                ProductVariableDescrition = ProductVariableSave,
                                Quantity                  = Quantity,
                                Price                     = Price,
                                Status                    = 1,
                                DiscountPrice             = 0,
                                ProductType               = ProductType,
                                CreatedDate               = currentDate,
                                CreatedBy                 = username,
                                IsCount                   = true
                            });

                            stockManager.Add(
                                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,
                            });
                        }

                        OrderDetailController.Insert(orderDetails);
                        OrderController.updateQuantityCOGS(OrderID);
                        StockManagerController.Insert(stockManager);

                        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);
                        }

                        PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng thành công", "s", true, "redirectTo(" + OrderID + ")", Page);
                    }
                }
            }
        }