public long SaveSupply(Supply supply, string userId)
        {
            var amount = (supply.Price * supply.Quantity);

            var supplyDTO = new DTO.SupplyDTO()
            {
                Quantity         = supply.Quantity,
                SupplyDate       = supply.SupplyDate,
                SupplyNumber     = supply.SupplyNumber,
                BranchId         = supply.BranchId,
                SupplierId       = supply.SupplierId,
                Amount           = amount,
                TruckNumber      = supply.TruckNumber,
                Used             = supply.Used,
                SupplyId         = supply.SupplyId,
                WeightNoteNumber = supply.WeightNoteNumber,
                MoistureContent  = supply.MoistureContent,
                NormalBags       = supply.NormalBags,
                BagsOfStones     = supply.BagsOfStones,
                Price            = supply.Price,
                IsPaid           = supply.IsPaid,
                StatusId         = supply.StatusId,
                CreatedOn        = supply.CreatedOn,
                TimeStamp        = supply.TimeStamp,
                CreatedBy        = supply.CreatedBy,
                Deleted          = supply.Deleted,
                StoreId          = supply.StoreId,
            };

            var supplyId = this._dataService.SaveSupply(supplyDTO, userId);

            var storeMaizeStock = new StoreMaizeStock()
            {
                SupplyId = supplyId,
                Quantity = supply.Quantity,
                StoreId  = supply.StoreId,
                BranchId = supply.BranchId,
                SectorId = Convert.ToInt64(sectorId),
            };

            SaveStoreMaizeStock(storeMaizeStock, true);
            var notes           = "Maize supply";
            var accountActivity = new AccountTransactionActivity()
            {
                AspNetUserId = supply.SupplierId,

                Amount = amount,
                Notes  = notes,

                Action               = "+",
                BranchId             = supply.BranchId,
                TransactionSubTypeId = Convert.ToInt64(supplyTransactionSubTypeId),
                SectorId             = Convert.ToInt64(sectorId),
                Deleted              = supply.Deleted,
                CreatedBy            = userId,
            };
            var accountActivityId = this._accountTransactionActivityService.SaveAccountTransactionActivity(accountActivity, userId);

            return(supplyId);
        }
Beispiel #2
0
        public long SaveSupply(Supply supply, string userId)
        {
            double amount = 0, totalBags = 0, offloadingFee = 0, amountToPay = 0;

            amount = (supply.Price * supply.Quantity);

            var supplies = GetAllSuppliesForAParticularSupplier(supply.SupplierId);

            if (supplies.Any())
            {
                foreach (var supplierSupply in supplies)
                {
                    bool equals = supplierSupply.WeightNoteNumber.Equals(supply.WeightNoteNumber, StringComparison.OrdinalIgnoreCase);

                    if (equals)
                    {
                        return(-1);
                    }
                }
            }

            if (supply.Offloading == "NO")
            {
                totalBags     = supply.NormalBags + supply.BagsOfStones;
                offloadingFee = totalBags * (Convert.ToDouble(offloadingRate));
                amountToPay   = amount - offloadingFee;
            }
            else
            {
                amountToPay = amount;
            }
            var supplyDTO = new DTO.SupplyDTO()
            {
                Quantity   = supply.Quantity,
                SupplyDate = supply.SupplyDate,
                //SupplyNumber = supply.SupplyNumber,
                BranchId         = supply.BranchId,
                SupplierId       = supply.SupplierId,
                Amount           = amount,
                TruckNumber      = supply.TruckNumber,
                AmountToPay      = amountToPay,
                Used             = supply.Used,
                SupplyId         = supply.SupplyId,
                WeightNoteNumber = supply.WeightNoteNumber,
                MoistureContent  = supply.MoistureContent,
                NormalBags       = supply.NormalBags,
                BagsOfStones     = supply.BagsOfStones,
                Price            = supply.Price,
                IsPaid           = supply.IsPaid,
                StatusId         = supply.StatusId,
                CreatedOn        = supply.CreatedOn,
                TimeStamp        = supply.TimeStamp,
                CreatedBy        = supply.CreatedBy,
                Deleted          = supply.Deleted,
                StoreId          = supply.StoreId,
                Offloading       = supply.Offloading,
            };

            var supplyId = this._dataService.SaveSupply(supplyDTO, userId);

            var storeMaizeStock = new StoreMaizeStock()
            {
                SupplyId = supplyId,
                Quantity = supply.Quantity,
                StoreId  = supply.StoreId,
                BranchId = supply.BranchId,
                SectorId = Convert.ToInt64(sectorId),
            };

            SaveStoreMaizeStock(storeMaizeStock, true);
            var notes           = "Maize supply";
            var accountActivity = new AccountTransactionActivity()
            {
                AspNetUserId = supply.SupplierId,

                Amount               = amount,
                Notes                = notes,
                Action               = "+",
                BranchId             = supply.BranchId,
                TransactionSubTypeId = Convert.ToInt64(supplyTransactionSubTypeId),
                SectorId             = Convert.ToInt64(sectorId),
                Deleted              = supply.Deleted,
                CreatedBy            = userId,
                SupplyId             = supplyId,
            };
            var accountActivityId = this._accountTransactionActivityService.SaveAccountTransactionActivity(accountActivity, userId);



            var offLoadingNotes           = "Offloading fee";
            var accountActivityOffloading = new AccountTransactionActivity()
            {
                AspNetUserId = supply.SupplierId,

                Amount               = offloadingFee,
                Notes                = offLoadingNotes,
                Action               = "-",
                BranchId             = supply.BranchId,
                TransactionSubTypeId = Convert.ToInt64(offLoadingTransactionSubTypeId),
                SectorId             = Convert.ToInt64(sectorId),
                Deleted              = supply.Deleted,
                CreatedBy            = userId,
                SupplyId             = supplyId,
            };
            var accountActivityOffloadingId = this._accountTransactionActivityService.SaveAccountTransactionActivity(accountActivityOffloading, userId);



            return(supplyId);
        }