Exemple #1
0
        //This function deletes incoming Goods based on the id of the selected Incoming Goods.
        // Notice this function will decrease the qty of the deleted item
        //  also will delete Inv Transaction
        public async Task <bool> DeleteIncomingGoods(int IgId)
        {
            try
            {
                IncomingGood IncomingGood = _db.IncomingGood.FirstOrDefault(ig => ig.Id == IgId);

                int    ProdId = IncomingGood.ProdId.GetValueOrDefault();
                int    WhId   = IncomingGood.WhId.GetValueOrDefault();
                double Qty    = IncomingGood.Qty;
                // DateTime TransDate = IncomingGood.CreatedDateTime;

                //updating Qty of InvStockQty
                ChangeStockQty(ProdId, WhId, Qty, "Out");

                // Delete add trans ID
                DeleteInvTransaction(ProdId, WhId, Qty, SD.Incoming);

                _db.IncomingGood.Remove(IncomingGood);

                // Save changes
                await _db.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return(false);
            }
        }
Exemple #2
0
        public async Task <string> CreateIncomingGoods(int SelectedWhId, List <IncomingGood> IG)
        {
            try
            {
                DateTime InDateTime       = DateTime.Now;
                string   sqlFormattedDate = InDateTime.ToString("yyyy-MM-dd HH:mm:ss");

                // create new products here


                int ProdId;

                foreach (var income in IG)
                {
                    ProdId = _db.ProdInfo.FirstOrDefault(pro => pro.ProdCode == income.ProdInfo.ProdCode).Id;

                    IncomingGood IncomingGood = new IncomingGood
                    {
                        ProdId      = ProdId,
                        WhId        = SelectedWhId,
                        Qty         = income.Qty,
                        Note        = income.Note,
                        CreatedById = GetLoggedInUserId(),

                        CreatedDateTime = InDateTime
                    };

                    //adding new incoming goods to the list
                    _db.IncomingGood.Add(IncomingGood);

                    //updating Qty of InvStockQty
                    //ChangeStockQty(ProdId, SelectedWhId, income.Qty, "In");

                    // Creating a new stock in inv stock qty table
                    CreateProdInWh(ProdId, SelectedWhId, income.Qty);

                    // creating transaction
                    CreateInvTransaction(ProdId, SelectedWhId, income.Qty, SD.Incoming);
                }

                // Save changes
                await _db.SaveChangesAsync();

                return("تمت اضافة المواد الواردة");
            }
            catch (Exception ex)
            {
                return("Error! حصل خطا. لم تتم اضافة المواد");
            }
        }