Exemplo n.º 1
0
        public void SaveHistory(HistoryType ht, RequisitionItem orig, string uid)
        {
            History h = new History();

            h.ObjectTypeName = this.GetType().ToString();
            h.Identifier     = ItemID;
            h.ChangeType     = ht;

            switch (ht)
            {
            case HistoryType.ADD:
                h.OriginalXML = null;
                h.UpdatedXML  = base.Serialize(this);
                break;

            case HistoryType.UPDATE:
                h.OriginalXML = base.Serialize(orig);
                h.UpdatedXML  = base.Serialize(this);
                break;

            case HistoryType.DELETE:
                h.OriginalXML = base.Serialize(this);
                break;
            }

            h.OrganizationID = Requisition.OrganizationID;
            h.Active         = true;
            h.Save(uid);
        }
Exemplo n.º 2
0
        public bool HasChanged()
        {
            bool            Changed  = false;
            RequisitionItem Original = new RequisitionItem(ItemID);

            if (this.GetHashCode() != Original.GetHashCode())
            {
                if (RequisitionID != Original.RequisitionID)
                {
                    Changed = true;
                }
                if (!Changed && Quantity != Original.Quantity)
                {
                    Changed = true;
                }
                if (!Changed && Description != Original.Description)
                {
                    Changed = true;
                }
                if (!Changed && DateNeeded != Original.DateNeeded)
                {
                    Changed = true;
                }
                if (!Changed && CompanyID != Original.CompanyID)
                {
                    Changed = true;
                }
                if (!Changed && FundID != Original.FundID)
                {
                    Changed = true;
                }
                if (!Changed && DepartmentID != Original.DepartmentID)
                {
                    Changed = true;
                }
                if (!Changed && AccountID != Original.AccountID)
                {
                    Changed = true;
                }
                if (!Changed && FYStartDate != Original.FYStartDate)
                {
                    Changed = true;
                }
                if (!Changed && Active != Original.Active)
                {
                    Changed = true;
                }
                if (!Changed && Price != Original.Price)
                {
                    Changed = true;
                }
                if (!Changed && IsExpeditiedShippingAllowed != Original.IsExpeditiedShippingAllowed)
                {
                    Changed = true;
                }
            }

            return(Changed);
        }
Exemplo n.º 3
0
        private Dictionary <string, string> Validate()
        {
            Dictionary <string, string> ValErrors = new Dictionary <string, string>();

            if (ItemID <= 0)
            {
                if (DateNeeded != DateTime.MinValue && DateNeeded < DateTime.Now.Date)
                {
                    ValErrors.Add("Date Needed", "Date Needed can not be in the past.");
                }
            }
            else
            {
                RequisitionItem Original = new RequisitionItem(ItemID);

                if (Original.Quantity != Quantity)
                {
                    if (Quantity < POItems.Where(poi => poi.Active).Select(poi => (int?)poi.Quantity ?? 0).Sum())
                    {
                        ValErrors.Add("Quantity", "Quantity is less than the quantity assigned to purchase orders.");
                    }
                }
            }

            if (Quantity <= 0)
            {
                ValErrors.Add("Quantity", "Quantity must be greater than 0.");
            }
            if (String.IsNullOrEmpty(Description))
            {
                ValErrors.Add("Description", "Description must be provided.");
            }


            if (CompanyID <= 0 || FundID <= 0 || DepartmentID <= 0 || AccountID <= 0 || FYStartDate == DateTime.MinValue)
            {
                ValErrors.Add("Account", "Please select a valid account");
            }
            else if (Account == null || Account.AccountID <= 0)
            {
                ValErrors.Add("Account", "Account not found.");
            }

            if (ItemID <= 0 && FYStartDate.Year < DateTime.Now.Year)
            {
                ValErrors.Add("Fiscal Year", "Fiscal year can not be in the past.");
            }


            //if (Price < 0)
            //    ValErrors.Add("Estimated Cost", "Estimated cost can not be negative.");

            return(ValErrors);
        }
Exemplo n.º 4
0
        private void Init()
        {
            PurchaseOrderItemID = 0;
            PurchaseOrderID     = 0;
            ItemID           = 0;
            Quantity         = 0;
            HasBeenReceived  = false;
            CreatedByUserID  = String.Empty;
            ModifiedByUserID = String.Empty;
            DateCreated      = DateTime.MinValue;
            DateModifed      = DateTime.MinValue;
            Active           = true;
            Price            = 0;

            mPurchaseOrder   = null;
            mRequisitionItem = null;
            mCreatedBy       = null;
            mModifiedBy      = null;
        }
Exemplo n.º 5
0
        public void Save(string uid)
        {
            try
            {
                RequisitionItem             Original = null;
                Enums.HistoryType           ChangeType;
                Dictionary <string, string> ValErrors = Validate();
                if (ValErrors.Count > 0)
                {
                    throw new RequisitionNotValidException("The requested item is not valid.", ValErrors);
                }

                using (PurchasingContext Context = ContextHelper.GetDBContext())
                {
                    RequisitionItemData data;
                    if (ItemID > 0)
                    {
                        data       = Context.RequisitionItemDatas.FirstOrDefault(x => x.requisition_item_id == ItemID);
                        ChangeType = HistoryType.UPDATE;
                        Original   = new RequisitionItem(data);
                    }
                    else
                    {
                        data              = new RequisitionItemData();
                        data.created_by   = uid;
                        data.date_created = DateTime.Now;
                        ChangeType        = HistoryType.ADD;
                    }
                    data.date_modified = DateTime.Now;
                    data.modified_by   = uid;

                    data.requisition_id = RequisitionID;
                    data.quantity       = Quantity;
                    data.description    = Description;

                    if (DateNeeded != DateTime.MinValue)
                    {
                        data.date_needed = DateNeeded;
                    }

                    if (!String.IsNullOrEmpty(ItemNumber))
                    {
                        data.item_number = ItemNumber;
                    }
                    else
                    {
                        data.item_number = null;
                    }

                    data.company_id                    = CompanyID;
                    data.fund_id                       = FundID;
                    data.department_id                 = DepartmentID;
                    data.account_id                    = AccountID;
                    data.active                        = Active;
                    data.fiscal_year_start             = FYStartDate;
                    data.is_expedited_shipping_allowed = IsExpeditiedShippingAllowed;
                    if (Price != 0)
                    {
                        data.price = Price;
                    }
                    else
                    {
                        data.price = null;
                    }

                    if (ItemID == 0)
                    {
                        Context.RequisitionItemDatas.InsertOnSubmit(data);
                    }

                    Context.SubmitChanges();

                    Load(data);

                    SaveHistory(ChangeType, Original, uid);
                }
            }
            catch (Exception ex)
            {
                throw new RequisitionException("An error has occurred while saving requisition item.", ex);
            }
        }
Exemplo n.º 6
0
        private Dictionary <string, string> Validate()
        {
            Dictionary <string, string> ValErrors = new Dictionary <string, string>();

            if (Active != true)
            {
                return(ValErrors);
            }

            if (ItemID <= 0)
            {
                if (DateNeeded != DateTime.MinValue && DateNeeded < DateTime.Now.Date)
                {
                    ValErrors.Add("Date Needed", "Date Needed can not be in the past.");
                }
            }
            else
            {
                RequisitionItem Original = new RequisitionItem(ItemID);

                if (Original.Quantity != Quantity)
                {
                    if (Quantity < POItems.Where(poi => poi.Active).Select(poi => ( int? )poi.Quantity ?? 0).Sum())
                    {
                        ValErrors.Add("Quantity", "Quantity is less than the quantity assigned to purchase orders.");
                    }
                }
            }

            if (Quantity <= 0)
            {
                ValErrors.Add("Quantity", "Quantity must be greater than 0.");
            }
            if (String.IsNullOrEmpty(Description))
            {
                ValErrors.Add("Description", "Description must be provided.");
            }


            if (CompanyID <= 0 || FundID <= 0 || DepartmentID <= 0 || AccountID <= 0 || FYStartDate == DateTime.MinValue)
            {
                ValErrors.Add("Account", "Please select a valid account");
            }
            else if (Account == null || Account.AccountNo <= 0)
            {
                ValErrors.Add("Account", "Account not found.");
            }
            else if (!apiClient.GetLocations().Any(l => l.Id == FundID))
            {
                ValErrors.Add("Account", "Account not found (Location does not exist).");
            }
            else if (!apiClient.GetDepartments().Any(d => d.Id == DepartmentID))
            {
                ValErrors.Add("Account", "Account not found (Department does not exist).");
            }


            if (Account?.RequireProject == "true" && string.IsNullOrWhiteSpace(ProjectId))
            {
                ValErrors.Add("Project", "Project required: The account code you entered requires a project to be entered.");
            }

            if (!string.IsNullOrWhiteSpace(ProjectId))
            {
                if (!ApiClient.GetProjects().Where(p => p.ProjectId == ProjectId).Any())
                {
                    ValErrors.Add("Project", "Project not found: Please enter a valid project code.");
                }
            }

            if (ItemID <= 0 && FYStartDate.Year < DateTime.Now.Year)
            {
                ValErrors.Add("Fiscal Year", "Fiscal year can not be in the past.");
            }


            //if (Price < 0)
            //    ValErrors.Add("Estimated Cost", "Estimated cost can not be negative.");

            return(ValErrors);
        }