protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (userAction != (int)Enums.UserAction.Add)
                {
                    model = inventoryRepo.GetInventoryDeliveriesByID(invDelID);

                    if (model != null)
                    {
                        GetInventoryDeliveriesProvider().SetInventoryDeliveriesModel(model);
                        FillForm();
                    }
                }

                FillDefaultValues();
                UserActionConfirmBtnUpdate(btnSaveChanges, userAction);
            }
            else
            {
                if (model == null && SessionHasValue(Enums.InventoryDeliveriesSession.InventoryDeliveriesModel))
                {
                    model = GetInventoryDeliveriesProvider().GetInventoryDeliveriesModel();
                }
            }
        }
Esempio n. 2
0
        private void CalculateInventoryStock(InventoryDeliveriesLocation item, InventoryDeliveries delivery, UnitOfWork unitOfWork)
        {
            bool locationFromWarehouse = false, locationToWarehouse = false;
            XPQuery <InventoryStock> inventoryStock = unitOfWork.Query <InventoryStock>();

            locationFromWarehouse = locationRepo.IsLocationWarehouse(item.LocationFromID.LocationID);
            locationToWarehouse   = locationRepo.IsLocationWarehouse(item.LocationToID.LocationID);


            //16.11.2020 Boris
            InventoryStock recordInventoryFromWarehouseStock = inventoryStock.Where(invS => invS.ProductID.ProductID == delivery.DeliveryNoteItemID.ProductID.ProductID && invS.LocationID == item.LocationFromID).FirstOrDefault();
            InventoryStock recordInventoryToWarehouseStock = inventoryStock.Where(invS => invS.ProductID.ProductID == delivery.DeliveryNoteItemID.ProductID.ProductID && invS.LocationID == item.LocationToID).FirstOrDefault();

            if (locationFromWarehouse)
            {
                if (recordInventoryFromWarehouseStock != null)
                {
                    //odštejemo zalogo, ker smo prestavili iz skladišča na drugo lokacijo
                    recordInventoryFromWarehouseStock.Quantity    -= delivery.Quantity; // količina v kg
                    recordInventoryFromWarehouseStock.QuantityPcs -= 1;                 // količina v kos
                }
                else
                {
                    CreateNewRecordForStock(false, item.LocationFromID, item, delivery, unitOfWork);
                }
            }

            if (locationToWarehouse)
            {
                if (recordInventoryToWarehouseStock != null)
                {
                    //odštejemo zalogo, ker smo prestavili iz skladišča na drugo lokacijo
                    recordInventoryToWarehouseStock.Quantity    += delivery.Quantity;
                    recordInventoryToWarehouseStock.QuantityPcs += 1;
                }
                else
                {
                    CreateNewRecordForStock(true, item.LocationToID, item, delivery, unitOfWork);
                }
            }
            // 16.11.2020 Boris

            //if (recordInventoryStock != null)
            //{
            //    if (locationFromWarehouse && !locationToWarehouse)
            //    { //odštejemo zalogo, ker smo prestavili iz skladišča na drugo lokacijo
            //        recordInventoryStock.Quantity -= delivery.Quantity;
            //        recordInventoryStock.QuantityPcs -= 1;
            //    }
            //    else if (!locationFromWarehouse && locationToWarehouse)
            //    {//seštejemo zalogo, ker smo prenseli nazaj v skladišče
            //        recordInventoryStock.Quantity += delivery.Quantity;
            //        recordInventoryStock.QuantityPcs += 1;
            //    }

            //    //TODO: Potrebno urediti še ko so bodo prevzemi delali iz skladišča na skladišče

            //    recordInventoryStock.Save();
            //}
        }
Esempio n. 3
0
 public bool DeleteInventoryDeliveries(InventoryDeliveries model)
 {
     try
     {
         model.Delete();
         return(true);
     }
     catch (Exception ex)
     {
         string error = "";
         CommonMethods.getError(ex, ref error);
         throw new Exception(CommonMethods.ConcatenateErrorIN_DB(DB_Exception.res_36, error, CommonMethods.GetCurrentMethodName()));
     }
 }
Esempio n. 4
0
        public int SaveInventoryDeliveries(InventoryDeliveries model, int userID = 0)
        {
            try
            {
                model.tsUpdate       = DateTime.Now;
                model.tsUpdateUserID = userID;

                if (model.InventoryDeliveriesID == 0)
                {
                    model.tsInsert       = DateTime.Now;
                    model.tsInsertUserID = userID;
                }

                model.Save();

                return(model.InventoryDeliveriesID);
            }
            catch (Exception ex)
            {
                string error = "";
                CommonMethods.getError(ex, ref error);
                throw new Exception(CommonMethods.ConcatenateErrorIN_DB(DB_Exception.res_35, error, CommonMethods.GetCurrentMethodName()));
            }
        }
Esempio n. 5
0
        //InventoryDeliveries

        public void SaveInventoryDeliveries(List <Item> model, int deliveryNoteID, int locationID, int userID = 0, bool isRepacking = false)
        {
            try
            {
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    List <DeliveryNoteItem> deliveryNoteItems = GetDeliveryNoteItemsByDeliveryNoteID(deliveryNoteID, uow);

                    foreach (var obj in model)
                    {
                        //v InventoryDeliveries shranimo vsaki atom v svoj zapis, skupaj z hierarhijo in ostalimi podatki
                        InventoryDeliveries item = new InventoryDeliveries(uow);
                        item.InventoryDeliveriesID = 0;

                        string topLevelPackageSID = GetTopLevelSID(obj, isRepacking);
                        var    deliveryNoteItem   = deliveryNoteItems.Where(dni => !String.IsNullOrEmpty(topLevelPackageSID) && dni.SID == topLevelPackageSID).FirstOrDefault();
                        item.DeliveryNoteItemID = deliveryNoteItem;

                        item.SupplierProductCode = deliveryNoteItem.SupplierProductCode;
                        item.AtomeUID250         = obj.UID;
                        item.PackagesUIDs        = obj.PackagesUIDs;
                        item.PackagesSIDs        = obj.PackagesSIDs;

                        if (deliveryNoteItem.ProductID != null)//preverimi če artikel obstaja. Če obstaja poiščemo zapis pregled zaloge in ga nastavimo na inventorydeliveries
                        {
                            var inventoryProd = productRepo.GetInventroyStockByProductIDAndLocationID(deliveryNoteItem.ProductID.ProductID, locationID, uow);

                            if (inventoryProd != null)
                            {
                                item.InventoryStockID = inventoryProd;
                            }
                        }
                        //item.Notes = "";

                        item.LastLocationID = locationRepo.GetLocationByID(locationID, uow);

                        item.tsUpdate       = DateTime.Now;
                        item.tsUpdateUserID = userID;

                        item.tsInsert       = DateTime.Now;
                        item.tsInsertUserID = userID;

                        item.Quantity        = obj.Quantity;
                        item.UnitOfMeasureID = measureRepo.GetMeasuringUnitByCode(obj.MeasuringUnitCode, uow);

                        int id = 0;
                        if (obj.Parents != null)
                        {
                            for (int i = obj.Parents.Count - 1; i >= 0; i--) //v seznamu imamo shranjeno hierarhijo paketov od očeta do otroka.
                                                                             //tukaj sezam bere v obratnem vrstem redu (od otroka do očeta, ker v tabeli InventoryDeliveriesPackages shranjujemo hirerahijo
                                                                             //v vrstem redu od otroka do očeta (from bottom to top)).
                            {
                                Item parent = null;
                                //preverimo če obstaja na i+1 mestu starš
                                if (i + 1 <= obj.Parents.Count - 1)
                                {
                                    parent = obj.Parents[i + 1];
                                }

                                InventoryDeliveriesPackages idp = new InventoryDeliveriesPackages(session);
                                idp.InventoryDeliveriesPackagesID = 0;
                                idp.ElementUID250   = obj.Parents[i].UID;
                                idp.ParentElementID = parent != null?GetInventoryDeliveriesPackagesIDByUID(parent.UID) : 0;

                                idp.tsUpdate       = DateTime.Now;
                                idp.tsUpdateUserID = userID;

                                idp.tsInsert       = DateTime.Now;
                                idp.tsInsertUserID = userID;

                                //če ne obstaja takšen zapis v tabeli ki ima enak uid in parent id potem ga lahko shranimo. (zapisi so se podvajali po zgornji kodi)
                                var invDeliveriesPackage = InventoryDeliveriesPackagesExist(idp.ElementUID250, idp.ParentElementID);
                                if (invDeliveriesPackage == null)
                                {
                                    idp.Save();
                                    id = idp.InventoryDeliveriesPackagesID;
                                }
                                else
                                {
                                    id = invDeliveriesPackage.InventoryDeliveriesPackagesID;
                                }

                                if (i == 0)
                                {
                                    item.InventoryDeliveriesPackagesID = uow.GetObjectByKey <InventoryDeliveriesPackages>(id);
                                }
                            }
                        }

                        if (item.InventoryStockID != null)
                        {
                            //tukaj shranjujemo aktualne lokacije artiklov oz. atomov iz dobavnice.
                            InventoryDeliveriesLocation invDelLoc = new InventoryDeliveriesLocation(uow);
                            invDelLoc.InventoryDeliveriesID         = item;
                            invDelLoc.InventoryDeliveriesLocationID = 0;
                            invDelLoc.LocationToID   = locationRepo.GetLocationByID(item.InventoryStockID.LocationID.LocationID, uow);
                            invDelLoc.LocationFromID = null;
                            invDelLoc.UserID         = userRepo.GetUserByID(userID, uow);
                            invDelLoc.tsInsert       = DateTime.Now;
                            invDelLoc.tsInsertUserID = 0;
                            invDelLoc.tsUpdate       = DateTime.Now;
                            invDelLoc.tsUpdateUserID = 0;
                        }
                    }

                    uow.CommitChanges();
                }

                var dn = GetDeliveryNoteByID(deliveryNoteID, session);
                dn.DeliveryNoteStatusID = GetDeliveryNoteStatusByCode(Enums.DeliveryNoteStatus.Completed, session);
                dn.Save();
            }
            catch (Exception ex)
            {
                string error = "";
                CommonMethods.getError(ex, ref error);
                throw new Exception(CommonMethods.ConcatenateErrorIN_DB(DB_Exception.res_26, error, CommonMethods.GetCurrentMethodName()));
            }
        }
Esempio n. 6
0
        private void CreateNewRecordForStock(bool bAddItems, Location cLocation, InventoryDeliveriesLocation item, InventoryDeliveries delivery, UnitOfWork unitOfWork)
        {
            // naredimo zapis za to skladišče in ta produkt
            // gremo v minus zalogo, da bomo pozneje odkrivali napake
            InventoryStock InvStock = new InventoryStock(unitOfWork);

            InvStock.ProductID   = delivery.DeliveryNoteItemID.ProductID;
            InvStock.LocationID  = cLocation;
            InvStock.Quantity    = (bAddItems) ? InvStock.Quantity + delivery.Quantity : InvStock.Quantity - delivery.Quantity;
            InvStock.QuantityPcs = (bAddItems) ? InvStock.QuantityPcs + 1 : InvStock.QuantityPcs - 1;
            InvStock.Notes       = "";

            if (InvStock.InventoryStockID == 0)
            {
                InvStock.tsInsert       = DateTime.Now;
                InvStock.tsInsertUserID = item.UserID.UserID;
            }

            InvStock.Save();

            unitOfWork.CommitChanges();
        }
Esempio n. 7
0
        // zakaj si tole kloniral?
        private InventoryDeliveriesLocation CreateNewInstance(InventoryDeliveriesLocation itemToClone, InventoryDeliveries delivery, UnitOfWork unitOfWork)
        {
            CloneHelper clone = new CloneHelper(unitOfWork);
            var         clonedInventoryDeliveriesLocation = new InventoryDeliveriesLocation(unitOfWork);//clone.Clone(itemToClone);

            clonedInventoryDeliveriesLocation.ParentID = itemToClone.InventoryDeliveriesLocationID;
            clonedInventoryDeliveriesLocation.InventoryDeliveriesLocationID = 0;
            clonedInventoryDeliveriesLocation.InventoryDeliveriesID         = delivery;
            clonedInventoryDeliveriesLocation.NeedsMatching       = false;
            clonedInventoryDeliveriesLocation.LocationFromID      = itemToClone.LocationFromID;
            clonedInventoryDeliveriesLocation.LocationToID        = itemToClone.LocationToID;
            clonedInventoryDeliveriesLocation.Notes               = itemToClone.Notes;
            clonedInventoryDeliveriesLocation.UserID              = itemToClone.UserID;
            clonedInventoryDeliveriesLocation.tsInsert            = DateTime.Now;
            clonedInventoryDeliveriesLocation.tsUpdate            = DateTime.Now;
            clonedInventoryDeliveriesLocation.IsMobileTransaction = itemToClone.IsMobileTransaction;
            //clonedInventoryDeliveriesLocation.MobileTransactions = new XPCollection<MobileTransaction>(unitOfWork, itemToClone.MobileTransactions);

            delivery.LastLocationID = clonedInventoryDeliveriesLocation.LocationToID;
            //delivery.Save();

            //clonedInventoryDeliveriesLocation.Save();

            CalculateInventoryStock(itemToClone, delivery, unitOfWork);

            return(clonedInventoryDeliveriesLocation);
        }