public void SaveApplicationCash(Cash cash, string userId) { var application = _dataService.GetApplicationDetails(); double startAmount = 0; double OldBalance = 0; double newBalance = 0; if (application != null) { OldBalance = application.TotalCash; startAmount = OldBalance; if (cash.Action == "-") { newBalance = OldBalance - cash.Amount; } else { newBalance = OldBalance + cash.Amount; } var applicatinDTO = new DTO.ApplicationDTO() { ApplicationId = application.ApplicationId, TotalCash = newBalance, Name = application.Name, TimeStamp = application.TimeStamp, }; this._dataService.UpdateApplicationCash(applicatinDTO); long transactionTypeId = 0; var transactionSubType = _transactionSubTypeService.GetTransactionSubType(cash.TransactionSubTypeId); if (transactionSubType != null) { transactionTypeId = transactionSubType.TransactionTypeId; var transaction = new TransactionDTO() { BranchId = Convert.ToInt64(cash.BranchId), SectorId = cash.SectorId, Amount = cash.Amount, TransactionSubTypeId = cash.TransactionSubTypeId, TransactionTypeId = transactionTypeId, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; var transactionId = _transactionDataService.SaveTransaction(transaction, userId); } } }
public long SaveDelivery(Delivery delivery, string userId) { var customerName = string.Empty; var customer = _userService.GetAspNetUser(delivery.CustomerId); if (customer != null) { customerName = customer.FirstName + ' ' + customer.LastName; } var deliveryDTO = new DTO.DeliveryDTO() { CustomerName = customerName, DeliveryCost = delivery.DeliveryCost, OrderId = delivery.OrderId, VehicleNumber = delivery.VehicleNumber, BranchId = delivery.BranchId, SectorId = delivery.SectorId, Location = delivery.Location, TransactionSubTypeId = delivery.TransactionSubTypeId, MediaId = delivery.MediaId, DeliveryId = delivery.DeliveryId, DriverName = delivery.DriverName, DriverNIN = delivery.DriverNIN, Deleted = delivery.Deleted, CreatedBy = delivery.CreatedBy, CreatedOn = delivery.CreatedOn, }; var deliveryId = this._dataService.SaveDelivery(deliveryDTO, userId); long transactionTypeId = 0; var transactionSubtype = _transactionSubTypeService.GetTransactionSubType(deliveryDTO.TransactionSubTypeId); if (transactionSubtype != null) { transactionTypeId = transactionSubtype.TransactionTypeId; } var transaction = new TransactionDTO() { BranchId = deliveryDTO.BranchId, SectorId = deliveryDTO.SectorId, Amount = deliveryDTO.DeliveryCost, TransactionSubTypeId = deliveryDTO.TransactionSubTypeId, TransactionTypeId = transactionTypeId, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; var transactionId = _transactionDataService.SaveTransaction(transaction, userId); return(deliveryId); }
public void SaveTransaction(Transaction transaction) { var dto = transaction.GetDto(); if (dto.Id == null) { _service.InsertTransaction(dto.Account, dto.Description, dto.CurrencyCode, dto.Amount); } else { _service.SaveTransaction(dto); } }
public long SaveInventory(Inventory inventory, string userId) { var inventoryDTO = new DTO.InventoryDTO() { ItemName = inventory.ItemName, Description = inventory.Description, PurchaseDate = inventory.PurchaseDate, Price = inventory.Price, Quantity = inventory.Quantity, InventoryCategoryId = inventory.InventoryCategoryId, Amount = inventory.Amount, BranchId = inventory.BranchId, SectorId = inventory.SectorId, StoreId = inventory.StoreId, TransactionSubTypeId = inventory.TransactionSubTypeId, InventoryId = inventory.InventoryId, Deleted = inventory.Deleted, CreatedBy = inventory.CreatedBy, CreatedOn = inventory.CreatedOn }; var InventoryId = this._dataService.SaveInventory(inventoryDTO, userId); if (inventory.InventoryId == 0) { long transactionTypeId = 0; var transactionSubtype = _transactionSubTypeService.GetTransactionSubType(inventoryDTO.TransactionSubTypeId); if (transactionSubtype != null) { transactionTypeId = transactionSubtype.TransactionTypeId; } var transaction = new TransactionDTO() { BranchId = inventoryDTO.BranchId, SectorId = inventoryDTO.SectorId, Amount = inventoryDTO.Amount, TransactionSubTypeId = inventoryDTO.TransactionSubTypeId, TransactionTypeId = transactionTypeId, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; var transactionId = _transactionDataService.SaveTransaction(transaction, userId); } return(InventoryId); }
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); }
public long SaveAccountTransactionActivity(AccountTransactionActivity accountTransactionActivity, string userId) { long accountTransactionActivityId = 0; double startAmount = 0; double OldBalance = 0; double NewBalance = 0; if (accountTransactionActivity.AspNetUserId != null) { OldBalance = GetBalanceForLastAccountAccountTransactionActivity(accountTransactionActivity.AspNetUserId); startAmount = OldBalance; } else { OldBalance = GetBalanceForLastAccountAccountTransactionActivity(Convert.ToString(accountTransactionActivity.CasualWorkerId)); startAmount = OldBalance; } if (accountTransactionActivity.Action == "-") { NewBalance = OldBalance - accountTransactionActivity.Amount; } else { NewBalance = OldBalance + accountTransactionActivity.Amount; } var accountTransactionActivityDTO = new DTO.AccountTransactionActivityDTO() { AspNetUserId = accountTransactionActivity.AspNetUserId, CasualWorkerId = accountTransactionActivity.CasualWorkerId, Amount = accountTransactionActivity.Amount, StartAmount = startAmount, Balance = NewBalance, Notes = accountTransactionActivity.Notes, AccountTransactionActivityId = accountTransactionActivity.AccountTransactionActivityId, Action = accountTransactionActivity.Action, BranchId = accountTransactionActivity.BranchId, TransactionSubTypeId = accountTransactionActivity.TransactionSubTypeId, SectorId = accountTransactionActivity.SectorId, Deleted = accountTransactionActivity.Deleted, CreatedBy = accountTransactionActivity.CreatedBy, CreatedOn = accountTransactionActivity.CreatedOn }; accountTransactionActivityId = this._dataService.SaveAccountTransactionActivity(accountTransactionActivityDTO, userId); long transactionTypeId = 0; List <string> transactionSubTypeNames = new List <string>(); var transactionSubType = _transactionSubTypeService.GetTransactionSubType(accountTransactionActivity.TransactionSubTypeId); if (transactionSubType != null) { transactionTypeId = transactionSubType.TransactionTypeId; if (transactionSubType.Name == "Credit" || transactionSubType.Name == "Advance" || accountTransactionActivity.PaymentMode == "Credit") { var debtorDTO = new DTO.DebtorDTO() { AspNetUserId = accountTransactionActivity.AspNetUserId, Action = false, Amount = accountTransactionActivity.Amount, CasualWorkerId = accountTransactionActivity.CasualWorkerId, BranchId = Convert.ToInt64(accountTransactionActivity.BranchId), SectorId = accountTransactionActivity.SectorId, Deleted = accountTransactionActivity.Deleted, CreatedBy = accountTransactionActivity.CreatedBy, CreatedOn = accountTransactionActivity.CreatedOn }; var debtorId = _debtorDataService.SaveDebtor(debtorDTO, userId); } else if (transactionSubType.Name == "Deposit" || transactionSubType.Name == "maize purchase" || transactionSubType.Name == "Casual labour") { var creditorDTO = new DTO.CreditorDTO() { AspNetUserId = accountTransactionActivity.AspNetUserId, Action = false, Amount = accountTransactionActivity.Amount, CasualWorkerId = accountTransactionActivity.CasualWorkerId, BranchId = Convert.ToInt64(accountTransactionActivity.BranchId), SectorId = accountTransactionActivity.SectorId, Deleted = accountTransactionActivity.Deleted, CreatedBy = accountTransactionActivity.CreatedBy, CreatedOn = accountTransactionActivity.CreatedOn }; var creditorId = _creditorDataService.SaveCreditor(creditorDTO, userId); } else if (transactionSubType.Name == "OffLoading") { double offloadingAmount = 0; if (accountTransactionActivity.Amount > 0) { offloadingAmount = accountTransactionActivity.Amount * -1; } var creditorDTO = new DTO.CreditorDTO() { AspNetUserId = accountTransactionActivity.AspNetUserId, Action = false, Amount = offloadingAmount, CasualWorkerId = accountTransactionActivity.CasualWorkerId, BranchId = Convert.ToInt64(accountTransactionActivity.BranchId), SectorId = accountTransactionActivity.SectorId, Deleted = accountTransactionActivity.Deleted, CreatedBy = accountTransactionActivity.CreatedBy, CreatedOn = accountTransactionActivity.CreatedOn }; var creditorId = _creditorDataService.SaveCreditor(creditorDTO, userId); } var transaction = new TransactionDTO() { BranchId = Convert.ToInt64(accountTransactionActivity.BranchId), SectorId = accountTransactionActivity.SectorId, Amount = accountTransactionActivity.Amount, TransactionSubTypeId = accountTransactionActivity.TransactionSubTypeId, TransactionTypeId = transactionTypeId, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; var transactionId = _transactionDataService.SaveTransaction(transaction, userId); } return(accountTransactionActivityId); }
public long SaveDelivery(Delivery delivery, string userId) { long deliveryId = 0; MakeDelivery makeDelivery = new MakeDelivery(); if (delivery.OrderId != 0) { //var order = _orderService.GetOrder(delivery.OrderId); if (delivery.ProductId == 2) { var deliveryDTO = new DTO.DeliveryDTO() { StoreId = delivery.StoreId, CustomerId = delivery.CustomerId, DeliveryCost = delivery.DeliveryCost, OrderId = delivery.OrderId, VehicleNumber = delivery.VehicleNumber, BranchId = delivery.BranchId, SectorId = delivery.SectorId, PaymentModeId = delivery.PaymentModeId, BatchId = delivery.BatchId, Price = delivery.Price, Quantity = delivery.Quantity, ProductId = delivery.ProductId, Amount = delivery.Amount, Location = delivery.Location, TransactionSubTypeId = delivery.TransactionSubTypeId, MediaId = delivery.MediaId, DeliveryId = delivery.DeliveryId, DriverName = delivery.DriverName, DriverNIN = delivery.DriverNIN, Deleted = delivery.Deleted, CreatedBy = delivery.CreatedBy, CreatedOn = delivery.CreatedOn, }; makeDelivery = MakeBrandDeliveryRecord(delivery.StoreId, delivery, userId); if (makeDelivery.StockReduced && (makeDelivery.OrderQuantityBalance == 0 || makeDelivery.OrderQuantityBalance > 0)) { deliveryId = this._dataService.SaveDelivery(deliveryDTO, userId); //StringBuilder sb = new StringBuilder(); //string strNewPath = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["MbaleReceipt"]); //using (StreamReader sr = new StreamReader(strNewPath)) //{ // while (!sr.EndOfStream) // { // sb.Append(sr.ReadLine()); // } //} //string body = sb.ToString().Replace("#CUSTOMERNAME#", deliveryDTO.CustomerId); //body = body.Replace("#AMOUNT#", deliveryDTO.Amount); //try //{ //} //catch (Exception ex) //{ // logger.Debug("receipt Not generated: " + ex.Message); //} var deliveryStockDTO = new DeliveryStockDTO() { StockId = makeDelivery.StockId, DeliveryId = deliveryId, }; _dataService.SaveDeliveryStock(deliveryStockDTO); _orderService.UpdateOrderWithCompletedStatus(delivery.OrderId, orderStatusIdComplete, userId); } else if (makeDelivery.StockReduced && makeDelivery.OrderQuantityBalance < 0) { deliveryId = this._dataService.SaveDelivery(deliveryDTO, userId); if (makeDelivery.OrderQuantityBalance != 0) { var deliveryStockDTO = new DeliveryStockDTO() { StockId = makeDelivery.StockId, DeliveryId = deliveryId, }; _dataService.SaveDeliveryStock(deliveryStockDTO); _orderService.UpdateOrderWithInProgressStatus(delivery.OrderId, orderStatusIdInProgress, userId); } } } else { //if order.ProductId == 1 var deliveryDTO = new DTO.DeliveryDTO() { StoreId = delivery.StoreId, CustomerId = delivery.CustomerId, DeliveryCost = delivery.DeliveryCost, OrderId = delivery.OrderId, VehicleNumber = delivery.VehicleNumber, BranchId = delivery.BranchId, SectorId = delivery.SectorId, PaymentModeId = delivery.PaymentModeId, BatchId = delivery.BatchId, Price = delivery.Price, ProductId = delivery.ProductId, Amount = delivery.Amount, Quantity = delivery.Quantity, Location = delivery.Location, TransactionSubTypeId = delivery.TransactionSubTypeId, MediaId = delivery.MediaId, DeliveryId = delivery.DeliveryId, DriverName = delivery.DriverName, DriverNIN = delivery.DriverNIN, Deleted = delivery.Deleted, CreatedBy = delivery.CreatedBy, CreatedOn = delivery.CreatedOn, }; makeDelivery = MakeFlourDeliveryRecord(delivery.StoreId, delivery, userId); if (makeDelivery.StockReduced && makeDelivery.OrderQuantityBalance == 0) { deliveryId = this._dataService.SaveDelivery(deliveryDTO, userId); var deliveryStockDTO = new DeliveryStockDTO() { StockId = makeDelivery.StockId, DeliveryId = deliveryId, }; _dataService.SaveDeliveryStock(deliveryStockDTO); _orderService.UpdateOrderWithCompletedStatus(delivery.OrderId, orderStatusIdComplete, userId); List <DeliveryGradeSize> deliveryGradeSizeList = new List <DeliveryGradeSize>(); foreach (var grade in delivery.Grades) { long sizeId = 0; double amount = 0, price = 0, quantity = 0; foreach (var denomination in grade.Denominations) { sizeId = denomination.DenominationId; price = denomination.Price; quantity = denomination.Quantity; amount = (denomination.Quantity * denomination.Price); var deliveryGradeSize = new DeliveryGradeSize() { DeliveryId = deliveryId, GradeId = grade.GradeId, SizeId = sizeId, Quantity = quantity, Price = price, Amount = amount, TimeStamp = DateTime.Now, }; deliveryGradeSizeList.Add(deliveryGradeSize); } } this._dataService.PurgeDeliveryGradeSize(deliveryId); this.SaveDeliveryGradeSizeList(deliveryGradeSizeList); } else { deliveryId = this._dataService.SaveDelivery(deliveryDTO, userId); if (makeDelivery.OrderQuantityBalance != 0) { var deliveryStockDTO = new DeliveryStockDTO() { StockId = makeDelivery.StockId, DeliveryId = deliveryId, }; _dataService.SaveDeliveryStock(deliveryStockDTO); _orderService.UpdateOrderWithInProgressStatus(delivery.OrderId, orderStatusIdInProgress, userId); List <DeliveryGradeSize> deliveryGradeSizeList = new List <DeliveryGradeSize>(); foreach (var grade in delivery.Grades) { long sizeId = 0; double amount = 0, price = 0, quantity = 0; foreach (var denomination in grade.Denominations) { sizeId = denomination.DenominationId; price = denomination.Price; quantity = denomination.Quantity; amount = (denomination.Quantity * denomination.Price); var deliveryGradeSize = new DeliveryGradeSize() { DeliveryId = deliveryId, GradeId = grade.GradeId, SizeId = sizeId, Quantity = quantity, Price = price, Amount = amount, TimeStamp = DateTime.Now, }; deliveryGradeSizeList.Add(deliveryGradeSize); } } this._dataService.PurgeDeliveryGradeSize(deliveryId); this.SaveDeliveryGradeSizeList(deliveryGradeSizeList); } } long transactionSubTypeId = 0; var notes = string.Empty; if (delivery.ProductId == 1) { transactionSubTypeId = flourTransactionSubTypeId; notes = "Maize Flour Sale"; } else if (delivery.ProductId == 2) { transactionSubTypeId = branTransactionSubTypeId; notes = "Bran Sale"; } var paymentMode = _accountTransactionActivityService.GetPaymentMode(delivery.PaymentModeId); var paymentModeName = paymentMode.Name; if (paymentModeName == "Credit") { var accountActivity = new AccountTransactionActivity() { AspNetUserId = delivery.CustomerId, Amount = delivery.Amount, Notes = notes, Action = "-", BranchId = delivery.BranchId, TransactionSubTypeId = transactionSubTypeId, SectorId = delivery.SectorId, Deleted = delivery.Deleted, CreatedBy = userId, PaymentMode = paymentModeName, }; var accountActivityId = this._accountTransactionActivityService.SaveAccountTransactionActivity(accountActivity, userId); } if (delivery.Amount == 0) { return(deliveryId); } else { long transactionTypeId = 0; var transactionSubtype = _transactionSubTypeService.GetTransactionSubType(delivery.TransactionSubTypeId); if (transactionSubtype != null) { transactionTypeId = transactionSubtype.TransactionTypeId; } var transaction = new TransactionDTO() { BranchId = delivery.BranchId, SectorId = delivery.SectorId, Amount = delivery.DeliveryCost, TransactionSubTypeId = delivery.TransactionSubTypeId, TransactionTypeId = transactionTypeId, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; var transactionId = _transactionDataService.SaveTransaction(transaction, userId); return(deliveryId); } } } return(deliveryId); }