public static void updateTransfer(BankTransfer transfer)
        {
            string username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            // Update transfer infor
            transfer.UUID         = Guid.NewGuid();
            transfer.CreatedBy    = acc.ID;
            transfer.CreatedDate  = DateTime.Now;
            transfer.ModifiedBy   = acc.ID;
            transfer.ModifiedDate = DateTime.Now;

            BankTransferController.Update(transfer);
        }
示例#2
0
 public static string getTransferLast(int customerID)
 {
     return(BankTransferController.getTransferLastJSON(customerID));
 }
        public static string getTransferLast(int orderID, int cusID)
        {
            var last = BankTransferController.getTransferLast(orderID, cusID);

            return(new JavaScriptSerializer().Serialize(last));
        }
示例#4
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);
                    }
                }
            }
        }