public Order(int id, int jobNumber, int templateID, string status, DateTime?orderDate, string salesman, string salesman2, string rsm, bool payRSMCommission,
                     int customerID, string poNumber, string trackingNumber,
                     string approvedBy, DateTime?approvedDate, string releasedBy, DateTime?releasedDate, string paidBy, DateTime?payDate, DateTime?payrollDate, string comment,
                     List <OrderItem> orderItems,
                     double totalListPrice, double salePrice, double discountAmount, double discountPercent, double dealerCommission, double regionalManagerCommission, double productManagerCommission,
                     string salesOrder, DateTime?estimatedShipDate, DateTime?finalPaymentDate)
        {
            ID         = id;
            JobNumber  = jobNumber;
            Salesman   = salesman;
            TypeOfSale = DEALER_SALE;
            if (Salesman != null && GetSalesmanForID(Salesman).Role == User.ROLE_DSE)
            {
                TypeOfSale = DIRECT_SALE_DSE;
            }
            else if (Salesman != null && GetSalesmanForID(Salesman).Role == User.ROLE_REGIONAL_MANAGER_DSE)
            {
                TypeOfSale = DIRECT_SALE_RSMDSE;
            }
            TemplateID       = templateID;
            CustomerID       = customerID;
            OrderDate        = orderDate;
            PONumber         = poNumber;
            TrackingNumber   = trackingNumber;
            Status           = status;
            Salesman2        = salesman2;
            RSM              = rsm;
            PayRSMCommission = payRSMCommission;
            ApprovedBy       = approvedBy;
            ApprovedDate     = approvedDate;
            ReleasedBy       = releasedBy;
            ReleasedDate     = releasedDate;
            PaidBy           = paidBy;
            PayDate          = payDate;
            PayrollDate      = payrollDate;
            Comment          = comment;

            OrderItems                = orderItems;
            TotalListPrice            = totalListPrice;
            SalePrice                 = salePrice;
            DiscountAmount            = discountAmount;
            DiscountPercent           = discountPercent;
            DealerCommission          = dealerCommission;
            RegionalManagerCommission = regionalManagerCommission;
            ProductManagerCommission  = productManagerCommission;

            SalesOrder        = salesOrder;
            EstimatedShipDate = estimatedShipDate;
            FinalPaymentDate  = finalPaymentDate;

            _template = BystronicDataService.DataSource.GetOrderTemplateFor(TemplateID);
        }
        public Order(Dictionary <string, object> data)
        {
            DateTime date;

            ID               = (int)data["ID"];
            JobNumber        = (int)data["JobNumber"];
            Salesman         = data["Salesman"] as string;
            Salesman2        = data["Salesman2"] as string;
            RSM              = data["RSM"] as string;
            PayRSMCommission = (bool)data["PayRSMCommission"];
            TypeOfSale       = DEALER_SALE;
            if (Salesman != null && GetSalesmanForID(Salesman).Role == User.ROLE_DSE)
            {
                TypeOfSale = DIRECT_SALE_DSE;
            }
            else if (Salesman != null && GetSalesmanForID(Salesman).Role == User.ROLE_REGIONAL_MANAGER_DSE)
            {
                TypeOfSale = DIRECT_SALE_RSMDSE;
            }

            TemplateID     = (int)data["TemplateID"];
            CustomerID     = (int)data["CustomerID"];
            OrderDate      = DateTime.Parse(data["OrderDate"] as string);
            PONumber       = data["PONumber"] as string;
            TrackingNumber = data["TrackingNumber"] as string;
            Status         = data["Status"] as string;
            ApprovedBy     = data["ApprovedBy"] as string;
            ReleasedBy     = data["ReleasedBy"] as string;
            PaidBy         = data["PaidBy"] as string;
            if (DateTime.TryParse(data["ApprovedDate"] as string, out date))
            {
                ApprovedDate = date;
            }
            if (DateTime.TryParse(data["ReleasedDate"] as string, out date))
            {
                ReleasedDate = date;
            }
            if (DateTime.TryParse(data["PayDate"] as string, out date))
            {
                PayDate = date;
            }
            if (DateTime.TryParse(data["PayrollDate"] as string, out date))
            {
                PayrollDate = date;
            }
            Comment = data["Comment"] as string;

            SalesOrder = data["SalesOrder"] as string;

            if (DateTime.TryParse(data["EstimatedShipDate"] as string, out date))
            {
                EstimatedShipDate = date;
            }
            if (DateTime.TryParse(data["FinalPaymentDate"] as string, out date))
            {
                FinalPaymentDate = date;
            }

            _template = BystronicDataService.DataSource.GetOrderTemplateFor(TemplateID);

            OrderItems = new List <OrderItem>();
            var orderItemsData = data["OrderItems"] as object[];

            foreach (var item in orderItemsData)
            {
                OrderItems.Add(new OrderItem(item as Dictionary <string, object>));
            }

            try
            {
                TotalListPrice            = Convert.ToDouble(data["TotalListPrice"]);
                SalePrice                 = Convert.ToDouble(data["SalePrice"]);
                DiscountAmount            = Convert.ToDouble(data["DiscountAmount"]);
                DiscountPercent           = Convert.ToDouble(data["DiscountPercent"]);
                DealerCommission          = Convert.ToDouble(data["DealerCommission"]);
                RegionalManagerCommission = Convert.ToDouble(data["RegionalManagerCommission"]);
                ProductManagerCommission  = Convert.ToDouble(data["ProductManagerCommission"]);
            }
            catch (Exception) { }
        }