public AdjustmentVoucherViewModel GetAdjustmentVoucher(string adjustmentID, HttpSessionStateBase session)
 {
     if (adjustmentID != null)
     {
         if (db.Adjustments.Find(adjustmentID) != null)
         {
             Adjustment adjustment                    = db.Adjustments.Find(adjustmentID);
             AdjustmentVoucherViewModel  avvm         = new AdjustmentVoucherViewModel();
             Dictionary <string, string> storeEmpList = GetStoreEmployeeList("mstan", "mstan");
             avvm.clerkIDName      = storeEmpList["clerk"];
             avvm.supervisorIDName = storeEmpList["supervisor"];
             avvm.managerIDName    = storeEmpList["manager"];
             avvm.status           = adjustment.status;
             avvm.needAuthority    = adjustment.needAuthority == null ? false : true;
             avvm.voucherDate      = adjustment.date;
             avvm.voucherID        = adjustment.voucherId;
             avvm.adjustmentValue  = adjustment.adjustmentValue;
             avvm.itemList         = new List <AdjustmentVoucherViewModelDetail>();
             List <AdjustmentDetail> adjustmentDetails = db.AdjustmentDetails.Where(x => x.voucherId == adjustmentID).ToList();
             foreach (AdjustmentDetail adjDet in adjustmentDetails)
             {
                 AdjustmentVoucherViewModelDetail avvmd = new AdjustmentVoucherViewModelDetail();
                 avvmd.itemID          = adjDet.itemId;
                 avvmd.itemDescription = db.Catalogues.Find(adjDet.itemId).description;
                 avvmd.itemQty         = adjDet.quantity;
                 avvmd.remark          = adjDet.remark;
                 avvm.itemList.Add(avvmd);
             }
             return(avvm);
         }
         return(null);
     }
     return(null);
 }
        public void DeleteItem(AdjustmentVoucherViewModel avvm, string itemIDComposite)
        {
            string itemID = itemIDComposite.Substring(itemIDComposite.Length - 4, 4);

            if (!avvm.itemList.Any())
            {
                //nothing to delete
                return;
            }
            else
            {
                if (avvm.itemList.Where(x => x.itemID == itemID).Any())
                {
                    AdjustmentVoucherViewModelDetail avvmd = avvm.itemList.Where(x => x.itemID == itemID).First();
                    avvm.itemList.Remove(avvmd);
                }
                return;
            }
        }
        public AdjustmentVoucherViewModel AddItem(AdjustmentVoucherViewModel avvm, string itemIDComposite, int ItemQty)
        {
            string itemID = itemIDComposite.Substring(itemIDComposite.Length - 4, 4);

            if (avvm.itemList.Any())
            {
                if (avvm.itemList.Where(x => x.itemID == itemID).Any())
                {
                    AdjustmentVoucherViewModelDetail oldItem = avvm.itemList.Where(x => x.itemID == itemID).First();
                    if (oldItem != null)
                    {
                        oldItem.itemQty += ItemQty;
                        return(null);
                    }
                }
            }
            //prepare the substring since the addition is composite (only last 4 character is the itemcode)

            Catalogue catalog = db.Catalogues.Find(itemID);

            if (catalog is null)
            {
                return(null);
            }
            AdjustmentVoucherViewModelDetail newItem = new AdjustmentVoucherViewModelDetail();

            newItem.itemID                = itemID;
            newItem.itemDescription       = catalog.description;
            newItem.itemInventoryLocation = 1;
            newItem.itemQty               = ItemQty;
            newItem.itemStoreQty          = db.Inventories.Find(itemID).storeQuantity;
            newItem.itemDisburseQty       = db.Inventories.Find(itemID).disburseQuantity;
            newItem.remark                = null;
            avvm.itemList.Add(newItem);
            AdjustmentVoucherViewModel newavvm = avvm;

            return(newavvm);
        }