public static Order GenerateOrder(int? orderID, int orderTypeID, int orderStatusID, int activityID, int paymentTypeID, string contactPerson, int? requestedBy, int userID, int? refNo = null)
        {
            var requisitionType = new RequisitionType();
            int requisitionTypeID = Convert.ToInt32(requisitionType.LoadIDByCode("DMN")["RequisitionTypeID"]);
            Order or = new Order();
            if (orderID == null)
            {
                or.AddNew();
            }
            else
            {
                or.LoadByPrimaryKey(orderID.Value);
            }

            or.RefNo = refNo == null ? GetNextOrderReference() : refNo.ToString();
            var oldOrderStatus = or.IsColumnNull("OrderStatusID") ? (int?)null : or.OrderStatusID;
            or.OrderStatusID = orderStatusID;
               // or.RequisitionTypeID = RequisitionType.CONSTANTS.DEMAND;
            or.RequisitionTypeID = requisitionTypeID;

            or.EurDate = or.Date = DateTimeHelper.ServerDateTime;

            if (requestedBy != null)
            {
                or.RequestedBy = requestedBy.Value;
            }

            or.FilledBy = userID;
            or.ContactPerson = contactPerson;
            var activity = new Activity();
            activity.LoadByPrimaryKey(activityID);
            or.FromStore = activity.ModeID;
            or.PaymentTypeID = paymentTypeID;
            or.FiscalYearID = FiscalYear.Current.ID;
            or.OrderTypeID = orderTypeID;
            or.Save();
            or.LogRequisitionStatus(or.ID, oldOrderStatus, orderStatusID, CurrentContext.UserId);
            return or;
        }
        private Order GenerateOrder()
        {
            var or = new Order();
            if (OrderID == null)
                or.AddNew();
            else
                or.LoadByPrimaryKey(OrderID.Value);

            or.RefNo = Order.GetNextOrderReference();
            txtRefNo.Text = or.RefNo;

            var oldOrderStatus = or.IsColumnNull("OrderStatusID") ? (int?)null : or.OrderStatusID;
            or.OrderStatusID = OrderStatus.Constant.PICK_LIST_GENERATED;
            //or.Remark = txtRemark.Text;

            or.EurDate = or.Date = DateTimeHelper.ServerDateTime; //Both fields are assigned dates.
            if (TransferTypeID == 1)
                or.RequestedBy = Convert.ToInt32(lkForHub.EditValue);

            or.FilledBy = CurrentContext.UserId;

            or.ContactPerson = txtContactPerson.Text;
            var activity = new Activity();
            activity.LoadByPrimaryKey(Convert.ToInt32(lkAccountType.EditValue));

            or.FromStore = activity.ModeID;

            if (BLL.Settings.IsCenter)
            {
                //What the Hell is this?
                or.PaymentTypeID = PaymentType.Constants.STV;
            }
            else
            {
                or.PaymentTypeID = PaymentType.Constants.STV;
            }
            or.FiscalYearID = FiscalYear.Current.ID;
            or.Save();
            or.LogRequisitionStatus(or.ID, oldOrderStatus, OrderStatus.Constant.PICK_LIST_GENERATED,CurrentContext.UserId);
            return or;
        }