public long SaveLabourCost(LabourCost labourCost, string userId)
        {
            double amount = 0, rate = 0;
            var    activity = _activityService.GetActivity(labourCost.ActivityId);

            if (activity != null)
            {
                rate = activity.Charge;
            }
            amount = labourCost.Quantity * rate;
            var labourCostDTO = new DTO.LabourCostDTO()
            {
                LabourCostId = labourCost.LabourCostId,
                BatchId      = labourCost.BatchId,
                Rate         = rate,
                Quantity     = labourCost.Quantity,
                ActivityId   = labourCost.ActivityId,
                BranchId     = labourCost.BranchId,
                Amount       = amount,
                Deleted      = labourCost.Deleted,
                CreatedBy    = labourCost.CreatedBy,
                CreatedOn    = labourCost.CreatedOn,
                SectorId     = labourCost.SectorId,
            };

            var LabourCostId = this._dataService.SaveLabourCost(labourCostDTO, userId);

            return(LabourCostId);
        }
        /// <summary>
        /// Maps LabourCost EF object to LabourCost Model Object and
        /// returns the LabourCost model object.
        /// </summary>
        /// <param name="result">EF LabourCost object to be mapped.</param>
        /// <returns>LabourCost Model Object.</returns>
        public LabourCost MapEFToModel(EF.Models.LabourCost data)
        {
            var labourCost = new LabourCost()
            {
                LabourCostId = data.LabourCostId,
                Amount       = data.Amount,
                SectorId     = data.SectorId,
                BranchId     = data.BranchId,
                BatchId      = data.BatchId,
                Rate         = data.Rate,
                Quantity     = data.Quantity,
                ActivityId   = data.ActivityId,
                ActivityName = data.Activity != null ? data.Activity.Name : "",

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

            return(labourCost);
        }
        /// <summary>
        /// Saves a new LabourCost or updates an already existing LabourCost.
        /// </summary>
        /// <param name="LabourCost">LabourCost to be saved or updated.</param>
        /// <param name="LabourCostId">LabourCostId of the LabourCost creating or updating</param>
        /// <returns>LabourCostId</returns>
        public long SaveLabourCost(LabourCostDTO labourCostDTO, string userId)
        {
            long labourCostId = 0;

            if (labourCostDTO.LabourCostId == 0)
            {
                var labourCost = new LabourCost()
                {
                    Rate       = labourCostDTO.Rate,
                    Quantity   = labourCostDTO.Quantity,
                    Amount     = labourCostDTO.Amount,
                    ActivityId = labourCostDTO.ActivityId,
                    BranchId   = labourCostDTO.BranchId,
                    SectorId   = labourCostDTO.SectorId,
                    BatchId    = labourCostDTO.BatchId,
                    CreatedOn  = DateTime.Now,
                    TimeStamp  = DateTime.Now,
                    CreatedBy  = userId,
                    Deleted    = false,
                };

                this.UnitOfWork.Get <LabourCost>().AddNew(labourCost);
                this.UnitOfWork.SaveChanges();
                labourCostId = labourCost.LabourCostId;
                return(labourCostId);
            }

            else
            {
                var result = this.UnitOfWork.Get <LabourCost>().AsQueryable()
                             .FirstOrDefault(e => e.LabourCostId == labourCostDTO.LabourCostId);
                if (result != null)
                {
                    result.Amount    = labourCostDTO.Amount;
                    result.UpdatedBy = userId;
                    result.Rate      = labourCostDTO.Rate;
                    result.BatchId   = labourCostDTO.BatchId;
                    result.TimeStamp = DateTime.Now;
                    result.Deleted   = labourCostDTO.Deleted;
                    result.BranchId  = labourCostDTO.BranchId;
                    result.SectorId  = labourCostDTO.SectorId;
                    result.DeletedBy = labourCostDTO.DeletedBy;
                    result.DeletedOn = labourCostDTO.DeletedOn;
                    result.Quantity  = labourCostDTO.Quantity;

                    this.UnitOfWork.Get <LabourCost>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
                return(labourCostDTO.LabourCostId);
            }
            return(labourCostId);
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        private List <LabourCost> AddBatchLabourCostsAutomatically(EF.Models.Batch batchObject)
        {
            Batch             batch          = MapEFToModel(batchObject);
            var               supplyBatch    = GetSupplyDetailsInABatch(batch);
            List <LabourCost> labourCostList = new List <LabourCost>();
            var               activities     = _activityService.GetAllActivities();

            foreach (var activity in activities)
            {
                switch (activity.Name)
                {
                case "Stone Sorting":
                    LabourCost sortingLabourCost = new LabourCost()
                    {
                        LabourCostId = 0,
                        Quantity     = supplyBatch.NoOfStoneBags,
                        Amount       = (supplyBatch.NoOfStoneBags * activity.Charge),
                        Rate         = activity.Charge,
                        BatchId      = batch.BatchId,
                        ActivityId   = activity.ActivityId,
                        SectorId     = batch.SectorId,
                        BranchId     = batch.BranchId,
                    };
                    labourCostList.Add(sortingLabourCost);
                    break;

                case "Brand packaging":
                    LabourCost packagingLabourCost = new LabourCost()
                    {
                        LabourCostId = 0,
                        Quantity     = batch.BrandOutPut,
                        Amount       = (batch.BrandOutPut * (activity.Charge / 100)),
                        Rate         = activity.Charge,
                        BatchId      = batch.BatchId,
                        ActivityId   = activity.ActivityId,
                        SectorId     = batch.SectorId,
                        BranchId     = batch.BranchId,
                    };
                    labourCostList.Add(packagingLabourCost);
                    break;

                case "kase sorting":
                    LabourCost kaseLabourCost = new LabourCost()
                    {
                        LabourCostId = 0,
                        Quantity     = batch.BrandOutPut,
                        Amount       = (supplyBatch.TotalQuantity * activity.Charge),
                        Rate         = activity.Charge,
                        BatchId      = batch.BatchId,
                        ActivityId   = activity.ActivityId,
                        SectorId     = batch.SectorId,
                        BranchId     = batch.BranchId,
                    };
                    labourCostList.Add(kaseLabourCost);
                    break;

                case "Machine Operator Mill":
                    LabourCost machineLabourCost = new LabourCost()
                    {
                        LabourCostId = 0,
                        Quantity     = batch.BrandOutPut,
                        Amount       = batch.FlourOutPut * (activity.Charge / 50),
                        Rate         = activity.Charge,
                        BatchId      = batch.BatchId,
                        ActivityId   = activity.ActivityId,
                        SectorId     = batch.SectorId,
                        BranchId     = batch.BranchId,
                    };
                    labourCostList.Add(machineLabourCost);
                    break;

                default:
                    break;
                }
            }
            return(labourCostList);
        }
Esempio n. 6
0
        public long Save(LabourCost model)
        {
            var labourCostId = _labourCostService.SaveLabourCost(model, userId);

            return(labourCostId);
        }