/// <summary> /// Saves a new FactoryExpense or updates an already existing FactoryExpense. /// </summary> /// <param name="FactoryExpense">FactoryExpense to be saved or updated.</param> /// <param name="FactoryExpenseId">FactoryExpenseId of the FactoryExpense creating or updating</param> /// <returns>FactoryExpenseId</returns> public long SaveFactoryExpense(FactoryExpenseDTO factoryExpenseDTO, string userId) { long factoryExpenseId = 0; if (factoryExpenseDTO.FactoryExpenseId == 0) { var factoryExpense = new FactoryExpense() { Amount = factoryExpenseDTO.Amount, Description = factoryExpenseDTO.Description, BranchId = factoryExpenseDTO.BranchId, SectorId = factoryExpenseDTO.SectorId, BatchId = factoryExpenseDTO.BatchId, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; this.UnitOfWork.Get <FactoryExpense>().AddNew(factoryExpense); this.UnitOfWork.SaveChanges(); factoryExpenseId = factoryExpense.FactoryExpenseId; return(factoryExpenseId); } else { var result = this.UnitOfWork.Get <FactoryExpense>().AsQueryable() .FirstOrDefault(e => e.FactoryExpenseId == factoryExpenseDTO.FactoryExpenseId); if (result != null) { result.Amount = factoryExpenseDTO.Amount; result.UpdatedBy = userId; result.Description = factoryExpenseDTO.Description; result.BatchId = factoryExpenseDTO.BatchId; result.TimeStamp = DateTime.Now; result.Deleted = factoryExpenseDTO.Deleted; result.BranchId = factoryExpenseDTO.BranchId; result.SectorId = factoryExpenseDTO.SectorId; result.DeletedBy = factoryExpenseDTO.DeletedBy; result.DeletedOn = factoryExpenseDTO.DeletedOn; this.UnitOfWork.Get <FactoryExpense>().Update(result); this.UnitOfWork.SaveChanges(); } return(factoryExpenseDTO.FactoryExpenseId); } return(factoryExpenseId); }
public long SaveFactoryExpense(FactoryExpense factoryExpense, string userId) { var factoryExpenseDTO = new DTO.FactoryExpenseDTO() { FactoryExpenseId = factoryExpense.FactoryExpenseId, BatchId = factoryExpense.BatchId, Description = factoryExpense.Description, BranchId = factoryExpense.BranchId, Amount = factoryExpense.Amount, Deleted = factoryExpense.Deleted, CreatedBy = factoryExpense.CreatedBy, CreatedOn = factoryExpense.CreatedOn, SectorId = factoryExpense.SectorId, }; var factoryExpenseId = this._dataService.SaveFactoryExpense(factoryExpenseDTO, userId); return(factoryExpenseId); }
/// <summary> /// Maps FactoryExpense EF object to FactoryExpense Model Object and /// returns the FactoryExpense model object. /// </summary> /// <param name="result">EF FactoryExpense object to be mapped.</param> /// <returns>FactoryExpense Model Object.</returns> public FactoryExpense MapEFToModel(EF.Models.FactoryExpense data) { var factoryExpense = new FactoryExpense() { FactoryExpenseId = data.FactoryExpenseId, Amount = data.Amount, SectorId = data.SectorId, BranchId = data.BranchId, BatchId = data.BatchId, Description = data.Description, 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(factoryExpense); }
/// <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(FactoryExpense model) { var factoryExpenseId = _factoryExpenseService.SaveFactoryExpense(model, userId); return(factoryExpenseId); }