Beispiel #1
0
        public bool DeleteReturnDetail(Session session, int detailID)
        {
            SPG.ReturnDetDataTable details = Adapter.GetReturnDetByID(detailID);
            int rowsAffected = 0;
            int itemID       = 0;
            int quantity     = 0;
            int locationID   = 0;

            if (details.Count() == 1)
            {
                SPG.ReturnDetRow returnDetail = (SPG.ReturnDetRow)details.Rows[0];
                itemID       = returnDetail.ReturnDetItemID;
                quantity     = returnDetail.ReturnDetQty;
                locationID   = session.GetObjectByKey <Receiving>(returnDetail.ReceiveMainID).ReceivingLocation.Oid;
                rowsAffected = Adapter.Delete(detailID, returnDetail.ts);
            }

            if (rowsAffected == 1)
            {
                ItemsBLL items = new ItemsBLL();
                items.UpdateStock(session, itemID, quantity * -1, false, locationID);
            }

            //Return true if precisely one row was deleted, otherwise return false.
            return(rowsAffected == 1);
        }
Beispiel #2
0
        public bool UpdateReturnDetails(Session session, int?detailID, int receivingID, int?itemID, string lot, int?quantity, int?units, float?pallets, string reason, DateTime?expirationDate)
        {
            if (!itemID.HasValue)
            {
                throw new ApplicationException("You must provide return item.");
            }

            if (!quantity.HasValue)
            {
                throw new ApplicationException("You must provide the Quantity returned.");
            }

            SPG.ReturnDetDataTable details = Adapter.GetReturnDetByID(detailID.Value);

            if (details.Count() == 0)
            {
                //It is a new Detail
                return(InsertDetails(session, receivingID, itemID, lot, quantity, units, pallets, reason, expirationDate));
            }

            SPG.ReturnDetRow returnDetail = details[0];
            int  originalItem             = 0;
            int  originalQuantity         = 0;
            int  newQuantity = 0;
            bool itemChanged = false;

            object[] originalRecord = returnDetail.ItemArray;

            originalItem = returnDetail.ReturnDetItemID;
            if (itemID.HasValue && originalItem != itemID.Value)
            {
                itemChanged = true;
            }
            returnDetail.ReturnDetItemID = itemID.Value;
            if (string.IsNullOrEmpty(lot))
            {
                returnDetail.SetReturnDetLotNull();
            }
            else
            {
                returnDetail.ReturnDetLot = lot;
            }
            originalQuantity          = returnDetail.ReturnDetQty;
            newQuantity               = returnDetail.ReturnDetQty - quantity.Value;
            returnDetail.ReturnDetQty = quantity.Value;
            if (!units.HasValue)
            {
                returnDetail.SetintUnitsNull();
            }
            else
            {
                returnDetail.intUnits = units.Value;
            }
            if (!pallets.HasValue)
            {
                returnDetail.SetsngPalletsNull();
            }
            else
            {
                returnDetail.sngPallets = pallets.Value;
            }
            if (string.IsNullOrEmpty(reason))
            {
                returnDetail.SetReasonNull();
            }
            else
            {
                returnDetail.Reason = reason;
            }
            if (expirationDate.HasValue)
            {
                returnDetail.ExpirationDate = expirationDate.Value;
            }
            else
            {
                returnDetail.SetExpirationDateNull();
            }

            if (!(originalRecord == null))
            {
                UpdateAuditTrail(returnDetail, originalRecord);
            }

            int rowsAffected = Adapter.Update(returnDetail);

            if (rowsAffected == 1)
            {
                ItemsBLL items      = new ItemsBLL();
                int      locationID = session.GetObjectByKey <Receiving>(receivingID).ReceivingLocation.Oid;
                if (itemChanged == true)
                {
                    items.UpdateStock(session, originalItem, originalQuantity * -1, false, locationID);
                    items.UpdateStock(session, itemID.Value, quantity.Value, false, locationID);
                }
                else
                {
                    if (newQuantity != 0)
                    {
                        items.UpdateStock(session, itemID.Value, newQuantity * -1, false, locationID);
                    }
                }
            }

            return(rowsAffected == 1);
        }