Пример #1
0
        public static void CollectPaymentAndShipPendingOrders(MerchantTribeApplication app)
        {
            OrderSearchCriteria criteria = new OrderSearchCriteria();
            criteria.IsPlaced = true;
            criteria.StatusCode = OrderStatusCode.ReadyForPayment;
            int pageSize = 1000;            
            int totalCount = 0;

            List<OrderSnapshot> orders = app.OrderServices.Orders.FindByCriteriaPaged(criteria, 1, pageSize, ref totalCount);
            if (orders != null)
            {
                foreach (OrderSnapshot os in orders)
                {
                    Order o = app.OrderServices.Orders.FindForCurrentStore(os.bvin);
                    OrderPaymentManager payManager = new OrderPaymentManager(o, app);
                    payManager.CreditCardCompleteAllCreditCards();
                    payManager.PayPalExpressCompleteAllPayments();
                    if (o.PaymentStatus == OrderPaymentStatus.Paid ||
                        o.PaymentStatus == OrderPaymentStatus.Overpaid)
                    {
                        if (o.ShippingStatus == OrderShippingStatus.FullyShipped)
                        {
                            o.StatusCode = OrderStatusCode.Completed;
                            o.StatusName = "Completed";
                        }
                        else
                        {
                            o.StatusCode = OrderStatusCode.ReadyForShipping;
                            o.StatusName = "Ready for Shipping";
                        }
                        app.OrderServices.Orders.Update(o);
                    }
                }
            }
        }
Пример #2
0
        public static void AcceptAllNewOrders(OrderService svc)
        {
            OrderSearchCriteria criteria = new OrderSearchCriteria();

            criteria.IsPlaced   = true;
            criteria.StatusCode = OrderStatusCode.Received;
            int pageSize   = 1000;
            int totalCount = 0;

            List <OrderSnapshot> orders = svc.Orders.FindByCriteriaPaged(criteria, 1, pageSize, ref totalCount);

            if (orders != null)
            {
                foreach (OrderSnapshot o in orders)
                {
                    Order ord = svc.Orders.FindForCurrentStore(o.bvin);
                    if (ord != null)
                    {
                        ord.StatusCode = OrderStatusCode.ReadyForPayment;
                        ord.StatusName = "Ready for Payment";
                        svc.Orders.Update(ord);
                    }
                }
            }
        }
Пример #3
0
        void LoadData()
        {

            try
            {

                TotalSub = 0;
                TotalCount = 0;

                OrderSearchCriteria c = new OrderSearchCriteria();
                c.IsPlaced = false;

                List<OrderSnapshot> found = new List<OrderSnapshot>();
                int totalCarts = 0;
                found = MTApp.OrderServices.Orders.FindByCriteriaPaged(c, 1, 1000, ref totalCarts);

                TotalCount = found.Count;

                foreach (OrderSnapshot o in found)
                {
                    TotalSub += o.TotalOrderBeforeDiscounts;
                }

                dgList.DataSource = found;
                dgList.DataBind();
            }

            catch (Exception Ex)
            {
                msg.ShowException(Ex);
                EventLog.LogEvent(Ex);
            }

        }
Пример #4
0
        public static void AcceptAllNewOrders(OrderService svc)
        {
            OrderSearchCriteria criteria = new OrderSearchCriteria();
            criteria.IsPlaced = true;
            criteria.StatusCode = OrderStatusCode.Received;
            int pageSize = 1000;            
            int totalCount = 0;

            List<OrderSnapshot> orders =  svc.Orders.FindByCriteriaPaged(criteria, 1, pageSize, ref totalCount);
            if (orders != null)
            {
                foreach (OrderSnapshot o in orders)
                {
                    Order ord = svc.Orders.FindForCurrentStore(o.bvin);
                    if (ord != null)
                    {
                        ord.StatusCode = OrderStatusCode.ReadyForPayment;
                        ord.StatusName = "Ready for Payment";
                        svc.Orders.Update(ord);
                    }
                }
            }
        }
Пример #5
0
        public static void CollectPaymentAndShipPendingOrders(MerchantTribeApplication app)
        {
            OrderSearchCriteria criteria = new OrderSearchCriteria();

            criteria.IsPlaced   = true;
            criteria.StatusCode = OrderStatusCode.ReadyForPayment;
            int pageSize   = 1000;
            int totalCount = 0;

            List <OrderSnapshot> orders = app.OrderServices.Orders.FindByCriteriaPaged(criteria, 1, pageSize, ref totalCount);

            if (orders != null)
            {
                foreach (OrderSnapshot os in orders)
                {
                    Order o = app.OrderServices.Orders.FindForCurrentStore(os.bvin);
                    OrderPaymentManager payManager = new OrderPaymentManager(o, app);
                    payManager.CreditCardCompleteAllCreditCards();
                    payManager.PayPalExpressCompleteAllPayments();
                    if (o.PaymentStatus == OrderPaymentStatus.Paid ||
                        o.PaymentStatus == OrderPaymentStatus.Overpaid)
                    {
                        if (o.ShippingStatus == OrderShippingStatus.FullyShipped)
                        {
                            o.StatusCode = OrderStatusCode.Completed;
                            o.StatusName = "Completed";
                        }
                        else
                        {
                            o.StatusCode = OrderStatusCode.ReadyForShipping;
                            o.StatusName = "Ready for Shipping";
                        }
                        app.OrderServices.Orders.Update(o);
                    }
                }
            }
        }
Пример #6
0
        void FillList()
        {

            try
            {

                TotalSub = 0;
                TotalShip = 0;
                TotalHandling = 0;
                TotalTax = 0;
                TotalGrand = 0;
                TotalCount = 0;
                TotalDiscounts = 0;
                TotalShipDiscounts = 0;

                OrderSearchCriteria c = new OrderSearchCriteria();

                // Get Local Times
                TimeZoneInfo timezone = MTApp.CurrentStore.Settings.TimeZone;
                DateTime zonedStart = this.DateRangeField.StartDateForZone(timezone);
                DateTime zonedEnd = this.DateRangeField.EndDateForZone(timezone);

                // Convert to UTC
                DateTime utcStart = TimeZoneInfo.ConvertTimeToUtc(zonedStart, timezone);
                DateTime utcEnd = TimeZoneInfo.ConvertTimeToUtc(zonedEnd, timezone);
                
                c.StartDateUtc = utcStart;
                c.EndDateUtc = utcEnd;

                List<OrderSnapshot> found = new List<OrderSnapshot>();
                found = MTApp.OrderServices.Orders.FindByCriteria(c);

                TotalCount = found.Count;

                foreach (OrderSnapshot o in found)
                {
                    TotalSub += o.TotalOrderBeforeDiscounts;
                    TotalDiscounts += o.TotalOrderDiscounts;
                    TotalShip += o.TotalShippingBeforeDiscounts;
                    TotalShipDiscounts += o.TotalShippingDiscounts;
                    TotalHandling += o.TotalHandling;
                    TotalTax += o.TotalTax + o.TotalTax2;
                    TotalGrand += o.TotalGrand;
                }

                int i = 0;
                string month = string.Empty;
                decimal monthTotal = 0m;
                decimal dayTotal = 0m;
                string day = string.Empty;
                if (found.Count > 0)
                {
                    DateTime zonedTimeOfOrder = TimeZoneInfo.ConvertTimeFromUtc(found[0].TimeOfOrderUtc, timezone);
                    month = zonedTimeOfOrder.Month.ToString() + ":" + zonedTimeOfOrder.Year.ToString();
                    day = zonedTimeOfOrder.DayOfYear.ToString() + ":" + zonedTimeOfOrder.Year.ToString();
                    while (i <= found.Count - 1)
                    {
                        DateTime zonedTime = TimeZoneInfo.ConvertTimeFromUtc(found[i].TimeOfOrderUtc, timezone);
                        monthTotal = monthTotal + found[i].TotalGrand;
                        dayTotal = dayTotal + found[i].TotalGrand;
                        if (zonedTime.DayOfYear.ToString() + ":" + zonedTime.Year.ToString() != day)
                        {
                            day = zonedTime.DayOfYear.ToString() + ":" + zonedTime.Year.ToString();
                            // we need to insert a day total
                            OrderSnapshot order = new OrderSnapshot();
                            order.OrderNumber = "DayTotal";
                            order.TotalGrand = (dayTotal - found[i].TotalGrand);
                            dayTotal = found[i].TotalGrand;
                            found.Insert(i, order);
                            i += 1;
                        }

                        if (zonedTime.Month.ToString() + ":" + zonedTime.Year.ToString() != month)
                        {
                            month = zonedTime.Month.ToString() + ":" + zonedTime.Year.ToString();
                            // we need to insert a month total
                            OrderSnapshot order = new OrderSnapshot();
                            order.OrderNumber = "MonthTotal";
                            order.TotalGrand = (monthTotal - found[i].TotalGrand);
                            monthTotal = found[i].TotalGrand;
                            found.Insert(i, order);
                            i += 1;
                        }
                        i += 1;
                    }
                    if (dayTotal > 0)
                    {
                        // we need to insert a day total
                        OrderSnapshot order = new OrderSnapshot();
                        order.OrderNumber = "DayTotal";
                        order.TotalGrand = dayTotal;
                        found.Add(order);
                    }
                    if (monthTotal > 0)
                    {
                        OrderSnapshot order = new OrderSnapshot();
                        order.OrderNumber = "MonthTotal";
                        order.TotalGrand = monthTotal;
                        found.Add(order);
                    }
                }
                lblResponse.Text = "<b>" + TotalCount + "</b>";
                lblResponse.Text += " Orders Totaling <b>";
                lblResponse.Text += string.Format("{0:c}", TotalGrand);
                lblResponse.Text += "</b>";

                dgList.DataSource = found;
                dgList.DataBind();
            }

            catch (Exception Ex)
            {
                msg.ShowException(Ex);
                EventLog.LogEvent(Ex);
            }

        }
Пример #7
0
        private ActionResult OrderDownload()
        {
            string formLastDate = Request["lastdate"] ?? string.Empty;
            string formLastOrder = Request["lastorder"] ?? string.Empty;
            string formStartNum = Request["startnum"] ?? string.Empty;
            string formBatchSize = Request["batchsize"] ?? string.Empty;
            string formDKey = Request["dkey"] ?? string.Empty;

            // Get Date
            if (formLastDate == string.Empty && formLastOrder == string.Empty)
            {
                return RenderError(StoneEdgeErrorType.General, "Missing LastDate and LastOrder from Request");
            }

            // Get Page Size
            int tempPageSize = 100;
            if (formBatchSize.Length > 0)
            {
                int.TryParse(formBatchSize, out tempPageSize);
            }
            if (tempPageSize < 1) tempPageSize = 100;

            // Get Page Number
            int pageNumber = 1;
            int tempStartRecord = 1;
            if (formStartNum.Length > 0)
            {
                if (int.TryParse(formStartNum, out tempStartRecord))
                {
                    // Stone Edge passes in a 1 based number of record to start with
                    // subtract one to make it zero based, then divide by page size to get 
                    // page number
                    pageNumber = (tempStartRecord - 1) / tempPageSize;

                    // Increase page number because pages are 1-based in MerchantTribe
                    pageNumber += 1;
                }
            }
            if (pageNumber < 1) pageNumber = 1;            

            DateTime startDate = new DateTime(1900, 1, 1);
            bool sendAll = (formLastDate.ToLowerInvariant() == "all" || formLastOrder.ToLowerInvariant() == "all");
            if (!sendAll)
            {
                if (!DateTime.TryParse(formLastDate, out startDate)) return RenderError(StoneEdgeErrorType.General, "Unable to parse date!");
            }
            // Always use start of day!
            startDate = MerchantTribe.Web.Dates.ZeroOutTime(startDate);

            var criteria = new MerchantTribe.Commerce.Orders.OrderSearchCriteria();
            criteria.EndDateUtc = DateTime.UtcNow.AddYears(1);
            criteria.StartDateUtc = TimeZoneInfo.ConvertTimeToUtc(startDate, this.MTApp.CurrentStore.Settings.TimeZone);
            criteria.IsPlaced = true;

            int returnCount = 0;
            var results = this.MTApp.OrderServices.Orders.FindByCriteriaPaged(criteria, pageNumber, tempPageSize, ref returnCount);

            return RenderOrders(results);                        
        }
Пример #8
0
        // Orders
        private ActionResult OrderCount()
        {
            string formLastDate = Request["lastdate"] ?? string.Empty;
            string formLastOrder = Request["lastorder"] ?? string.Empty;                        
            if (formLastDate == string.Empty && formLastOrder == string.Empty)
            {                
                return RenderError(StoneEdgeErrorType.General,"Missing LastDate and LastOrder from Request");
            }

            int returnCount = 0;
            
            DateTime startDate = new DateTime(1900, 1, 1);
            bool sendAll = (formLastDate.ToLowerInvariant() == "all" || formLastOrder.ToLowerInvariant() == "all");
            if (!sendAll)
            {
                if (!DateTime.TryParse(formLastDate, out startDate)) return RenderError(StoneEdgeErrorType.General, "Unable to parse date!");                
            }
            // Always use start of day!
            startDate = MerchantTribe.Web.Dates.ZeroOutTime(startDate);

            var criteria = new MerchantTribe.Commerce.Orders.OrderSearchCriteria();
            criteria.EndDateUtc = DateTime.UtcNow.AddYears(1);
            criteria.StartDateUtc = TimeZoneInfo.ConvertTimeToUtc(startDate, this.MTApp.CurrentStore.Settings.TimeZone);
            criteria.IsPlaced = true;
            
            var results = this.MTApp.OrderServices.Orders.FindByCriteriaPaged(criteria, 1, 1,ref returnCount);
            
            
            return Content(String.Format("SETIResponse: ordercount={0}", returnCount), "text/plain");
        }
Пример #9
0
        protected void btnGoFindOrder_Click(object sender, System.EventArgs e)
        {
            this.lblFindOrderMessage.Text = string.Empty;

            OrderSearchCriteria c = new OrderSearchCriteria();
            c.OrderNumber = this.FindOrderNumberField.Text.Trim();
            c.IsPlaced = true;
            c.StartDateUtc = DateTime.UtcNow.AddYears(-5);
            c.EndDateUtc = DateTime.UtcNow.AddYears(1);

            bool found = false;

            int totalCount = 0;
            List<OrderSnapshot> results = MTApp.OrderServices.Orders.FindByCriteriaPaged(c, 1, 10, ref totalCount);
            if (results != null)
            {
                if (results.Count > 0)
                {
                    found = true;
                    MerchantTribe.Commerce.Controls.UserSelectedEventArgs args = new MerchantTribe.Commerce.Controls.UserSelectedEventArgs();
                    args.UserAccount = MTApp.MembershipServices.Customers.Find(results[0].UserID);
                    this.UserSelected(args);
                }
            }

            if (!found)
            {
                this.lblFindOrderMessage.Text = "<span class=\"errormessage\">That order was not found</span>";
            }
        }
Пример #10
0
        protected void AffiliatesDataList_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (e.Item.DataItem != null)
                {
                    OrderSearchCriteria orderCriteria = new OrderSearchCriteria();
                    AffiliateReferralSearchCriteria referralCriteria = new AffiliateReferralSearchCriteria();

                    Affiliate affiliate = (Affiliate)e.Item.DataItem;

                    orderCriteria.AffiliateId = affiliate.ReferralId;

                    DateTime zonedStart = new DateTime(int.Parse(YearDropDownList.SelectedValue), int.Parse(MonthDropDownList.SelectedValue), 1, 0, 0, 0, 0);
                    orderCriteria.StartDateUtc = TimeZoneInfo.ConvertTimeToUtc(zonedStart, MTApp.CurrentStore.Settings.TimeZone);
                    orderCriteria.EndDateUtc = orderCriteria.StartDateUtc.AddMonths(1);
                    orderCriteria.EndDateUtc = orderCriteria.EndDateUtc.AddSeconds(-1);

                    referralCriteria.AffiliateId = affiliate.Id;
                    referralCriteria.StartDateUtc = orderCriteria.StartDateUtc;
                    referralCriteria.EndDateUtc = orderCriteria.EndDateUtc;

                    List<OrderSnapshot> affiliateOrders = MTApp.OrderServices.Orders.FindByCriteria(orderCriteria);

                    Label currLabel = (Label)e.Item.FindControl("ReferralsLabel");
                    int totalCount = 0;
                    List<AffiliateReferral> referrals = MTApp.ContactServices.AffiliateReferrals.FindByCriteria(referralCriteria, 1, int.MaxValue, ref totalCount);
                    currLabel.Text = referrals.Count.ToString();

                    currLabel = (Label)e.Item.FindControl("SalesLabel");
                    currLabel.Text = affiliateOrders.Count.ToString();

                    currLabel = (Label)e.Item.FindControl("ConversionLabel");
                    double conversion = (double)affiliateOrders.Count / (double)referrals.Count;
                    currLabel.Text = string.Format("{0:p}", conversion);

                    decimal total = 0;

                    foreach (OrderSnapshot order in affiliateOrders)
                    {
                        total += order.TotalOrderBeforeDiscounts;
                    }

                    currLabel = (Label)e.Item.FindControl("CommissionLabel");
                    decimal commission = 0;
                    string commissionText = string.Empty;
                    if (affiliate != null)
                    {
                        if (affiliate.CommissionType == AffiliateCommissionType.FlatRateCommission)
                        {
                            commission = Math.Round(affiliate.CommissionAmount * (decimal)affiliateOrders.Count, 2);
                            commissionText = string.Format("{0:c}", affiliate.CommissionAmount) + " per";
                        }
                        else
                        {
                            commission = Math.Round((affiliate.CommissionAmount / (decimal)100) * total, 2);
                            commissionText = string.Format("{0:p}", (affiliate.CommissionAmount / (decimal)100));
                        }

                        currLabel.Text = commissionText + " = " + string.Format("{0:c}", commission);
                    }

                    GridView gv = (GridView)e.Item.FindControl("OrdersGridView");
                    if (gv != null)
                    {
                        gv.DataSource = affiliateOrders;
                        gv.DataKeyNames = new string[] { "bvin" };
                        gv.DataBind();
                    }

                    Literal openDiv = (Literal)e.Item.FindControl("openDiv");
                    Literal closeDiv = (Literal)e.Item.FindControl("closeDiv");

                    if ((openDiv != null) & (closeDiv != null))
                    {
                        openDiv.Text = "<a href=\"";
                        openDiv.Text += "javascript:toggle('aff" + affiliate.Id + "');";
                        openDiv.Text += "\"><img id=\"aff" + affiliate.Id + "Carrot\" name=\"aff" + affiliate.Id + "Carrot\" src=\"../../../BVAdmin/Images/Buttons/Details.png\" border=\"0\" alt=\"Details\"></a></img><div style=\"display:none\" id=\"aff" + affiliate.Id + "\" class=\"hidden\">";

                        closeDiv.Text = "</div>";
                    }
                }
            }
        }
Пример #11
0
        // Searching
        private void FindOrders(int pageNumber)
        {
            OrderSearchCriteria criteria = new OrderSearchCriteria();
            criteria.IsPlaced = true;
            criteria.StatusCode = this.lstStatus.SelectedValue;
            if (this.lstPaymentStatus.SelectedValue != string.Empty)
            {
                criteria.PaymentStatus = (OrderPaymentStatus)(int.Parse(this.lstPaymentStatus.SelectedValue));
            }
            if (this.lstShippingStatus.SelectedValue != string.Empty)
            {
                criteria.ShippingStatus = (OrderShippingStatus)(int.Parse(this.lstShippingStatus.SelectedValue));
            }
            criteria.StartDateUtc = this.DateRangePicker1.StartDate.ToUniversalTime();
            criteria.EndDateUtc = this.DateRangePicker1.EndDate.ToUniversalTime();
            criteria.Keyword = this.FilterField.Text.Trim();
            criteria.SortDescending = this.chkNewestFirst.Checked;

            int pageSize = 20;
            int totalCount = 0;

            List<OrderSnapshot> orders = MTApp.OrderServices.Orders.FindByCriteriaPaged(criteria, pageNumber, pageSize, ref totalCount);

            RenderOrders(orders);

            this.litPager.Text = MerchantTribe.Web.Paging.RenderPager(Page.ResolveUrl("~/bvadmin/orders/default.aspx?p={0}"), pageNumber, totalCount, pageSize);
            this.litPager2.Text = this.litPager.Text;

            SaveSessionKeys(pageNumber);
            ShowCorrectBatchButtons(criteria.StatusCode);
        }
Пример #12
0
        public List <OrderSnapshot> FindByCriteriaPaged(OrderSearchCriteria criteria, int pageNumber, int pageSize, ref int rowCount)
        {
            List <OrderSnapshot> result = new List <OrderSnapshot>();

            if (pageNumber < 1)
            {
                pageNumber = 1;
            }
            int take = pageSize;
            int skip = (pageNumber - 1) * pageSize;

            IQueryable <Data.EF.bvc_Order> items = repository.Find()
                                                   .Where(y => y.StoreId == context.CurrentStore.Id)
                                                   .Where(y => y.TimeOfOrder >= criteria.StartDateUtc &&
                                                          y.TimeOfOrder <= criteria.EndDateUtc);

            // Order Number
            if (criteria.OrderNumber != string.Empty)
            {
                items = items.Where(y => y.OrderNumber == criteria.OrderNumber);
            }

            // Is Placed
            items = items.Where(y => y.IsPlaced == (criteria.IsPlaced ? 1 : 0));

            // Status Code
            if (criteria.StatusCode != string.Empty)
            {
                items = items.Where(y => y.StatusCode == criteria.StatusCode);
            }

            // Affiliate Id
            if (criteria.AffiliateId != string.Empty)
            {
                items = items.Where(y => y.AffiliateId == criteria.AffiliateId);
            }

            // Payment Status
            if (criteria.PaymentStatus != OrderPaymentStatus.Unknown)
            {
                int tempPay = (int)criteria.PaymentStatus;
                items = items.Where(y => y.PaymentStatus == tempPay);
            }

            // Shipping Status
            if (criteria.ShippingStatus != OrderShippingStatus.Unknown)
            {
                int tempShip = (int)criteria.ShippingStatus;
                items = items.Where(y => y.ShippingStatus == tempShip);
            }

            // Keyword (most expensive operation)
            if (criteria.Keyword != string.Empty)
            {
                items = items.Where(y => y.OrderNumber.Contains(criteria.Keyword) ||
                                    y.UserEmail.Contains(criteria.Keyword) ||
                                    y.BillingAddress.Contains(criteria.Keyword) ||
                                    y.ShippingAddress.Contains(criteria.Keyword));
            }

            // return total item count;
            var counter = items.Count();

            rowCount = counter;

            if (criteria.SortDescending)
            {
                var paged = items.OrderByDescending(y => y.Id).Skip(skip).Take(take);
                return(ListPocoSnapshot(paged));
            }
            else
            {
                var paged2 = items.OrderBy(y => y.Id).Skip(skip).Take(take);
                return(ListPocoSnapshot(paged2));
            }
        }
Пример #13
0
        public List <OrderSnapshot> FindByCriteria(OrderSearchCriteria criteria)
        {
            int temp = -1;

            return(FindByCriteriaPaged(criteria, 1, int.MaxValue, ref temp));
        }