Exemple #1
0
        /// <summary>
        /// Maps MachineRepair EF object to MachineRepair Model Object and
        /// returns the MachineRepair model object.
        /// </summary>
        /// <param name="result">EF MachineRepair object to be mapped.</param>
        /// <returns>MachineRepair Model Object.</returns>
        public MachineRepair MapEFToModel(EF.Models.MachineRepair data)
        {
            var machineRepair = new MachineRepair()
            {
                Amount                 = data.Amount,
                NameOfRepair           = data.NameOfRepair,
                BranchId               = data.BranchId,
                Description            = data.Description,
                SectorId               = data.SectorId,
                BatchId                = data.BatchId,
                DateRepaired           = data.DateRepaired,
                TransactionSubTypeId   = data.TransactionSubTypeId,
                TransactionSubTypeName = data.TransactionSubType != null? data.TransactionSubType.Name:"",
                BranchName             = data.Branch != null? data.Branch.Name:"",
                SectorName             = data.Sector != null ? data.Sector.Name : "",
                MachineRepairId        = data.MachineRepairId,
                CreatedOn              = data.CreatedOn,
                TimeStamp              = data.TimeStamp,
                Deleted                = data.Deleted,
                CreatedBy              = _userService.GetUserFullName(data.AspNetUser),
                UpdatedBy              = _userService.GetUserFullName(data.AspNetUser1)
            };

            return(machineRepair);
        }
Exemple #2
0
        /// <summary>
        /// Saves a new MachineRepair or updates an already existing MachineRepair.
        /// </summary>
        /// <param name="MachineRepair">MachineRepair to be saved or updated.</param>
        /// <param name="MachineRepairId">MachineRepairId of the MachineRepair creating or updating</param>
        /// <returns>MachineRepairId</returns>
        public long SaveMachineRepair(MachineRepairDTO machineRepairDTO, string userId)
        {
            long machineRepairId = 0;

            if (machineRepairDTO.MachineRepairId == 0)
            {
                var machineRepair = new MachineRepair()
                {
                    Amount               = machineRepairDTO.Amount,
                    NameOfRepair         = machineRepairDTO.NameOfRepair,
                    BranchId             = machineRepairDTO.BranchId,
                    SectorId             = machineRepairDTO.SectorId,
                    BatchId              = machineRepairDTO.BatchId,
                    TransactionSubTypeId = machineRepairDTO.TransactionSubTypeId,
                    Description          = machineRepairDTO.Description,
                    DateRepaired         = machineRepairDTO.DateRepaired,
                    CreatedOn            = DateTime.Now,
                    TimeStamp            = DateTime.Now,
                    CreatedBy            = userId,
                    Deleted              = false,
                };

                this.UnitOfWork.Get <MachineRepair>().AddNew(machineRepair);
                this.UnitOfWork.SaveChanges();
                machineRepairId = machineRepair.MachineRepairId;
                return(machineRepairId);
            }

            else
            {
                var result = this.UnitOfWork.Get <MachineRepair>().AsQueryable()
                             .FirstOrDefault(e => e.MachineRepairId == machineRepairDTO.MachineRepairId);
                if (result != null)
                {
                    result.Amount               = machineRepairDTO.Amount;
                    result.DateRepaired         = machineRepairDTO.DateRepaired;
                    result.NameOfRepair         = machineRepairDTO.NameOfRepair;
                    result.SectorId             = machineRepairDTO.SectorId;
                    result.BranchId             = machineRepairDTO.BranchId;
                    result.BatchId              = machineRepairDTO.BatchId;
                    result.TransactionSubTypeId = machineRepairDTO.TransactionSubTypeId;
                    result.Description          = machineRepairDTO.Description;
                    result.UpdatedBy            = userId;
                    result.TimeStamp            = DateTime.Now;
                    this.UnitOfWork.Get <MachineRepair>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
                return(machineRepairDTO.MachineRepairId);
            }
        }
Exemple #3
0
        public long SaveMachineRepair(MachineRepair machineRepair, string userId)
        {
            var machineRepairDTO = new DTO.MachineRepairDTO()
            {
                Amount               = machineRepair.Amount,
                NameOfRepair         = machineRepair.NameOfRepair,
                DateRepaired         = machineRepair.DateRepaired,
                BranchId             = machineRepair.BranchId,
                BatchId              = machineRepair.BatchId,
                TransactionSubTypeId = machineRepair.TransactionSubTypeId,
                Description          = machineRepair.Description,
                SectorId             = machineRepair.SectorId,
                MachineRepairId      = machineRepair.MachineRepairId,
                Deleted              = machineRepair.Deleted,
                CreatedBy            = machineRepair.CreatedBy,
                CreatedOn            = machineRepair.CreatedOn
            };

            var machineRepairId = this._dataService.SaveMachineRepair(machineRepairDTO, userId);

            if (machineRepair.MachineRepairId == 0)
            {
                long transactionTypeId  = 0;
                var  transactionSubtype = _transactionSubTypeService.GetTransactionSubType(machineRepairDTO.TransactionSubTypeId);
                if (transactionSubtype != null)
                {
                    transactionTypeId = transactionSubtype.TransactionTypeId;
                }

                var transaction = new TransactionDTO()
                {
                    BranchId             = machineRepairDTO.BranchId,
                    SectorId             = machineRepairDTO.SectorId,
                    Amount               = machineRepair.Amount,
                    TransactionSubTypeId = machineRepairDTO.TransactionSubTypeId,
                    TransactionTypeId    = transactionTypeId,
                    CreatedOn            = DateTime.Now,
                    TimeStamp            = DateTime.Now,
                    CreatedBy            = userId,
                    Deleted              = false,
                };
                var transactionId = _transactionDataService.SaveTransaction(transaction, userId);
            }
            return(machineRepairId);
        }
        /// <summary>
        /// Maps Batch EF object to Batch Model Object and
        /// returns the Batch model object.
        /// </summary>
        /// <param name="result">EF Batch object to be mapped.</param>
        /// <returns>Batch Model Object.</returns>
        public Batch MapEFToModel(EF.Models.Batch data)
        {
            var batch = new Batch()
            {
                BatchId  = data.BatchId,
                Name     = data.Name,
                Quantity = data.Quantity,
                BranchId = data.BranchId,

                BranchName = data.Branch != null ? data.Branch.Name : "",
                SectorName = data.Sector != null ? data.Sector.Name : "",
                SectorId   = data.SectorId,
                CreatedOn  = data.CreatedOn,
                TimeStamp  = data.TimeStamp,
                Deleted    = data.Deleted,
                BranchMillingChargeRate = data.Branch != null? data.Branch.MillingChargeRate:0,
                CreatedBy = _userService.GetUserFullName(data.AspNetUser),
                UpdatedBy = _userService.GetUserFullName(data.AspNetUser1),
            };


            var batchOutPuts = GetAllBatchOutPutsForABatch(data.BatchId);
            List <BatchOutPut> batchOutPutList = new List <BatchOutPut>();

            if (batchOutPuts.Any())
            {
                foreach (var outPut in batchOutPuts)
                {
                    var batchOutPut = new BatchOutPut()
                    {
                        Grades          = outPut.Grades,
                        TotalBuveraCost = outPut.TotalBuveraCost,
                        TotalQuantity   = outPut.TotalQuantity,
                        BrandOutPut     = outPut.BrandOutPut,
                        FlourPercentage = outPut.FlourPercentage,
                        BrandPercentage = outPut.BrandPercentage,
                        FlourOutPut     = outPut.FlourOutPut,
                        LossPercentage  = outPut.LossPercentage,
                        Loss            = outPut.Loss,
                    };
                    batchOutPutList.Add(batchOutPut);
                    batch.TotalBuveraCost = batchOutPut.TotalBuveraCost;
                    batch.TotalQuantity   = batchOutPut.TotalQuantity;
                    batch.FlourOutPut     = batchOutPut.FlourOutPut;
                    batch.LossPercentage  = batchOutPut.LossPercentage;
                    batch.Loss            = Convert.ToDouble(batchOutPut.Loss);
                    batch.BrandOutPut     = batchOutPut.BrandOutPut;
                    batch.BrandPercentage = batchOutPut.BrandPercentage;
                    batch.FlourPercentage = batchOutPut.FlourPercentage;
                    batch.Grades          = batchOutPut.Grades;
                }
            }
            batch.MillingCharge = batch.BranchMillingChargeRate * batch.FlourOutPut;

            var    otherExpenses    = GetAllOtherExpensesForABatch(data.BatchId);
            double otherExpenseCost = 0;
            List <OtherExpense> otherExpenseList = new List <OtherExpense>();

            if (otherExpenses.Any())
            {
                foreach (var other in otherExpenses)
                {
                    var otherExpense = new OtherExpense()
                    {
                        Amount      = other.Amount,
                        Description = other.Description,
                    };
                    otherExpenseList.Add(otherExpense);
                    otherExpenseCost = otherExpenseCost + other.Amount;
                }
                batch.TotalOtherExpenseCost = otherExpenseCost;
                batch.OtherExpenses         = otherExpenseList;
            }

            var            utilities   = GetAllUtilitiesForABatch(data.BatchId);
            double         utilityCost = 0;
            List <Utility> utilityList = new List <Utility>();

            if (utilities.Any())
            {
                foreach (var utility in utilities)
                {
                    var utilityObject = new Utility()
                    {
                        Amount      = utility.Amount,
                        Description = utility.Description,
                    };
                    utilityList.Add(utility);
                    utilityCost = utilityCost + utility.Amount;
                }
                batch.TotalUtilityCost = utilityCost;
                batch.Utilities        = utilityList;
            }

            var    factoryExpenses     = GetAllFactoryExpensesForABatch(data.BatchId);
            double totalFactoryExpense = 0;
            double factoryExpenseCost  = 0;
            List <FactoryExpense> factoryExpenseList = new List <FactoryExpense>();

            if (factoryExpenses.Any())
            {
                foreach (var item in factoryExpenses)
                {
                    var factoryExpense = new FactoryExpense()
                    {
                        Amount      = item.Amount,
                        Description = item.Description,
                    };
                    factoryExpenseList.Add(factoryExpense);
                    factoryExpenseCost = factoryExpenseCost + item.Amount;
                }
                batch.FactoryExpenseCost = factoryExpenseCost;
                batch.FactoryExpenses    = factoryExpenseList;
            }
            var    machineRepairs = GetAllMachineRepairsForABatch(data.BatchId);
            double machineCosts   = 0;
            List <MachineRepair> machineRepairList = new List <MachineRepair>();

            if (machineRepairs.Any())
            {
                foreach (var repair in machineRepairs)
                {
                    var machineRepair = new MachineRepair()
                    {
                        Amount      = repair.Amount,
                        Description = repair.Description,
                    };
                    machineRepairList.Add(machineRepair);
                    machineCosts = machineRepair.Amount + machineCosts;
                }
                batch.MachineRepairs   = machineRepairList;
                batch.TotalMachineCost = machineCosts;
            }
            totalFactoryExpense           = batch.TotalMachineCost + batch.FactoryExpenseCost;
            batch.TotalFactoryExpenseCost = totalFactoryExpense;
            batch.MillingChargeBalance    = ComputeMillingChargeBalance(batch.MillingCharge, batch.TotalFactoryExpenseCost);

            var               labourCosts      = GetAllLabourCostsForABatch(data.BatchId);
            double            totalLabourCosts = 0;
            List <LabourCost> labourCostList   = new List <LabourCost>();

            // labourCostList.AddRange(AddBatchLabourCostsAutomatically(data));
            if (labourCosts.Any())
            {
                foreach (var labour in labourCosts)
                {
                    var labourCost = new LabourCost()
                    {
                        ActivityName = labour.ActivityName,
                        Amount       = labour.Amount,
                        Quantity     = labour.Quantity,
                        Rate         = labour.Rate,
                    };
                    labourCostList.Add(labourCost);
                    totalLabourCosts = totalLabourCosts + labour.Amount;
                }
                batch.TotalLabourCosts = totalLabourCosts;
                batch.LabourCosts      = labourCostList;
            }

            if (data.BatchSupplies != null)
            {
                if (data.BatchSupplies.Any())
                {
                    double        totalSupplyAmount = 0;
                    List <Supply> supplies          = new List <Supply>();
                    var           batchSupplies     = data.BatchSupplies.AsQueryable().Where(m => m.BatchId == data.BatchId);
                    foreach (var batchSupply in batchSupplies)
                    {
                        var supply = new Supply()
                        {
                            SupplyId     = batchSupply.Supply.SupplyId,
                            Quantity     = batchSupply.Supply.Quantity,
                            SupplierId   = batchSupply.Supply.SupplierId,
                            Price        = batchSupply.Supply.Price,
                            Amount       = batchSupply.Supply.Amount,
                            SupplierName = _userService.GetUserFullName(batchSupply.Supply.AspNetUser2),
                        };
                        supplies.Add(supply);
                        totalSupplyAmount = totalSupplyAmount + supply.Amount;
                    }
                    batch.Supplies          = supplies;
                    batch.TotalSupplyAmount = totalSupplyAmount;
                }


                batch.TotalProductionCost = ComputeTotalProductionCost(batch.MillingCharge, batch.TotalLabourCosts, batch.TotalBuveraCost);
            }

            return(batch);
        }
        public long Save(MachineRepair model)
        {
            var machineRepairId = _machineRepairService.SaveMachineRepair(model, userId);

            return(machineRepairId);
        }