/// <summary> /// Enlists a <see cref="UnitOfWorkScope"/> instance with the transaction manager, /// with the specified transaction mode. /// </summary> /// <param name="scope">The <see cref="IUnitOfWorkScope"/> to register.</param> /// <param name="mode">A <see cref="TransactionMode"/> enum specifying the transaciton /// mode of the unit of work.</param> public void EnlistScope(IUnitOfWorkScope scope, TransactionMode mode) { _logger.Info(x => x("Enlisting scope {0} with transaction manager {1} with transaction mode {2}", scope.ScopeId, _transactionManagerId, mode)); var uowFactory = _scopeFactory; //Container.Resolve<IUnitOfWorkFactory>(); if (_transactions.Count == 0 || mode == TransactionMode.New || mode == TransactionMode.Supress) { _logger.Debug(x => x("Enlisting scope {0} with mode {1} requires a new TransactionScope to be created.", scope.ScopeId, mode)); var txScope = TransactionScopeHelper.CreateScope(_isolationLevel, mode); var unitOfWork = uowFactory.Create(); Guard.Against <ArgumentException>(!(unitOfWork is IExUnitOfWork), "Ошибка создания UnitOfWork: тек. объект не реализует IExUnitOfWork"); var transaction = new UnityUnitOfWorkTransaction((IExUnitOfWork)unitOfWork, txScope, _subject); transaction.TransactionDisposing += OnTransactionDisposing; transaction.EnlistScope(scope); _transactions.AddFirst(transaction); return; } CurrentTransaction.EnlistScope(scope); }
public void MakeAffectedChangesByReceiptNotes(string drugStoreID, params int[] noteIds) { var allModiDeliveryItemIds = new List <int>(); var allModiReceiptItemIds = new List <int>(); var allModiDrugIds = new List <int>(); var refPriceRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedReportContext, ReceiptDrugPriceRef> >(); using (var trans = TransactionScopeHelper.CreateReadUncommitted()) { var modiResult = GetAffectedNoteItemsByReceiptNotes(drugStoreID, noteIds); if (modiResult == null) { return; } var modiDItemIds = refPriceRepo.GetAll().Where(i => i.DrugStoreCode == drugStoreID && !i.IsDeleted && modiResult.ItemIds.Contains(i.ReceiptNoteItemId) && modiResult.DrugIds.Contains(i.DrugId)) .Select(i => i.DeliveryNoteItemId).Distinct().ToList(); var modiDeliveryResult = GetAffectedNoteItemsByDeliveryNoteItems(drugStoreID, modiDItemIds.ToArray()); allModiReceiptItemIds.AddRange(modiResult.ItemIds); allModiDrugIds.AddRange(modiResult.DrugIds); if (modiDeliveryResult != null) { allModiDeliveryItemIds.AddRange(modiDeliveryResult.ItemIds); allModiDrugIds.AddRange(modiDeliveryResult.DrugIds); } trans.Complete(); } UpdateAffectedItems(drugStoreID, allModiDeliveryItemIds, allModiReceiptItemIds, allModiDrugIds); }
public async Task Create(PurchaseCreateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var supplier = await _supplierRepo.GetById(dto.SupplierId).ConfigureAwait(false) ?? throw new Exception("Supplier not found!!!"); var purchase = new Purchase(supplier, dto.Discount); foreach (var data in dto.PurchaseDetails) { var item = await _itemRepo.GetById(data.ItemId).ConfigureAwait(false) ?? throw new Exception("Item not found!"); purchase.AddPurchaseDetails(item, data.Qty, data.Rate, data.SalesRate); item.AddQty(data.Qty); item.UpdateRate(data.SalesRate); await _itemRepo.UpdateAsync(item).ConfigureAwait(false); } await _purchaseRepo.InsertAsync(purchase).ConfigureAwait(false); tx.Complete(); }
public bool RollbackDrugStore(string drugStoreCode) { var retVal = false; try { using (var tran = TransactionScopeHelper.CreateLockAllForWrite()) { var ownerDrugStoreCodes = GetOwnerDrugStoreCodes(drugStoreCode); var drugStoreRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, NhaThuoc> >(); if (ownerDrugStoreCodes.Any()) { drugStoreRepo.UpdateMany(i => ownerDrugStoreCodes.Contains(i.MaNhaThuoc), i => new NhaThuoc() { HoatDong = true }); var userRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, UserProfile> >(); userRepo.UpdateMany(i => ownerDrugStoreCodes.Contains(i.MaNhaThuoc), i => new UserProfile() { Enable_NT = true }); } tran.Complete(); } } catch (Exception ex) { FaultHandler.Instance.Handle(ex, this, "DeleteDrugStore"); } return(retVal); }
/// <summary> /// Saves (or updates) the entity in the database. /// </summary> /// /// <param name="entity"> /// Entity to save or update. /// </param> /// /// <param name="options"> /// Optional options. /// </param> /// /// <returns> /// The number of affected rows. /// </returns> public override int Save(ref VahapYigit.Test.Models.UserRole entity, SaveOptions options = null) { ConditionChecker.Required( entity != null, new ArgumentNullException("entity")); if (options == null) { options = SaveOptions.Default; } int rowCount = 0; using (var scope = TransactionScopeHelper.CreateDefaultTransactionScope()) { this.OnSaving(ref entity, options); if (options.SaveChildren) { rowCount = this.PersistWithChildren(ref entity, new ObjectIDGenerator(), options); } else { rowCount = this.Persist(ref entity, options); } this.OnSaved(ref entity, options); scope.Complete(); } return(rowCount); }
public ActionResult ReDisableStores(string SID) { string[] strIds = SID.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); List <int> list = new List <int>(); foreach (string id in strIds) { list.Add(int.Parse(id)); } var flag = false; IStoresService storesService = ServiceFactory.Create <IStoresService>(); using (TransactionScope scope = TransactionScopeHelper.GetTran()) { foreach (var item in list) { var data = storesService.GetEntity(item); data.Disabled = false; storesService.UpdateEntity(data); } scope.Complete(); flag = true; } return(Json(new Result(flag, ResultType.Other), JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteUsers(string IDs) { List <int> idArr = IDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList(); IUsersService usersService = ServiceFactory.Create <IUsersService>(); var data = usersService.GetEntities(idArr); bool flage = true; using (TransactionScope scope = TransactionScopeHelper.GetTran()) { foreach (var item in data) { item.Disabled = true; flage = usersService.UpdateEntity(item); if (flage == false) { break; } } scope.Complete(); } return(Json(new Result(flage, ResultType.Other), JsonRequestBehavior.AllowGet)); }
public async Task Create(ItemCreateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var item = new Item(dto.Unit, dto.ItemName, dto.Price); await _itemRepo.InsertAsync(item); tx.Complete(); }
public SynthesisReportResponse GetSynthesisReportData(string drugStoreCode, FilterObject filter) { GenerateReportData(drugStoreCode); var result = new SynthesisReportResponse(); using (var trans = TransactionScopeHelper.CreateReadUncommitted()) { var deliveryService = IoC.Container.Resolve <IDeliveryNoteService>(); var rpService = IoC.Container.Resolve <IReportService>(); var warehouseSysnthesis = rpService.GetDrugWarehouseSyntheises(drugStoreCode, filter); var inOutCommingSummary = rpService.GetInOutCommingValueSumary(drugStoreCode, filter); // I.1. Tổng giá trị nhập kho result.ReceiptValueTotal = warehouseSysnthesis.Values.Sum(i => i.ReceiptInventoryValueInPeriod); // I.2. Tổng giá trị xuất kho result.DeliveryValueTotal = warehouseSysnthesis.Values.Sum(i => i.DeliveryInventoryValueInPeriod); // I.3. Tổng giá trị kho hàng result.WarehousingValueTotal = warehouseSysnthesis.Values.Sum(i => i.LastInventoryValue); // I.4. Tổng nợ khách hàng // I.4.1 Nợ bán hàng result.DeliveryDueTotal = inOutCommingSummary.DeliveryDueTotal; // I.4.2 Các khoản nợ khác result.DeliveryOtherDueTotal = inOutCommingSummary.DeliveryOtherDueTotal; // I.5. Tổng nợ nhà cung cấp // I.5.1 Nợ mua hàng result.ReceiptDueTotal = inOutCommingSummary.ReceiptDueTotal; // I.5.2 Các khoản nợ khác result.ReceiptOtherDueTotal = inOutCommingSummary.ReceiptOtherDueTotal; // II.1. Tổng thu // II.1.1. Bán hàng hóa/dịch vụ result.DeliveryIncomingTotal = inOutCommingSummary.DeliveryIncomingTotal; // II.1.2. Các nguồn thu khác result.OtherIncommingTotal = inOutCommingSummary.OtherIncommingTotal; // II.2. Tổng chi // II.2.1. Mua hàng hóa/ dịch vụ result.ReceiptOutcomingTotal = inOutCommingSummary.ReceiptOutcomingTotal; // TODO: // II.2.2. Chi phí kinh doanh result.BusinessCostsTotal = inOutCommingSummary.BusinessCostsTotal; // II.2.3. Các khoản chi khác result.OtherOutcomingTotal = inOutCommingSummary.OtherOutcomingTotal; // II.3. Lãi gộp == II.3.1 + II.1.2 // II.3.1. Lợi nhuận bán thuốc result.DeliveryRevenueTotal = deliveryService.GetDeliveryRevenueTotal(drugStoreCode, filter); trans.Complete(); } return(result); }
public async Task Create(UnitCreateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); await ValidateUnit(dto.Name); var Unit = new Unit(dto.Name); await _unitRepo.InsertAsync(Unit).ConfigureAwait(false); tx.Complete(); }
public async Task Delete(long id) { using var tx = TransactionScopeHelper.GetInstance(); var item = await _itemRepo.GetById(id).ConfigureAwait(false); await _itemRepo.DeleteAsync(item); tx.Complete(); }
public async Task Create(SupplierCreateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); await ValidateSupplierNumber(dto.Phone); var supplier = new Supplier(dto.Name, dto.Address, dto.Email, dto.Phone); await _supplierRepo.InsertAsync(supplier).ConfigureAwait(false); tx.Complete(); }
public async Task Create(CustomerTransactionCreateDto dto) { using var tx = TransactionScopeHelper.GetInstance(); var customer = await _customerRepo.GetById(dto.CustomerId).ConfigureAwait(false) ?? throw new CustomerNotFoundException(); CustomerTransaction Transaction = new CustomerTransaction(customer, dto.Amount, dto.Type, dto.ExtraId); await _transactionRepo.InsertAsync(Transaction).ConfigureAwait(false); tx.Complete(); }
public async Task Update(ItemUpdateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var item = await _itemRepo.GetById(dto.ItemId).ConfigureAwait(false) ?? throw new ItemNotFoundException(); item.Update(dto.Unit, dto.Name, dto.Price); await _itemRepo.UpdateAsync(item); tx.Complete(); }
public NearExpiredDrugResponse GetNearExpiredDrugWarningData(string drugStoreCode, DrugStoreSetting setting, FilterObject filter, int expiredOption = (int)ExpiredFilterType.OnlyExpired) { GenerateReportData(drugStoreCode); var result = new NearExpiredDrugResponse(); using (var trans = TransactionScopeHelper.CreateReadUncommitted()) { var resultItems = GetRemainQuantityReceiptDrugItems(drugStoreCode, setting); var totalCount = resultItems.Count; if (totalCount < 1) { trans.Complete(); result.PagingResultModel = new PagingResultModel <RemainQuantityReceiptDrugItem>(resultItems, totalCount); return(result); } var drugIds = resultItems.Select(i => i.ItemId).Distinct().ToArray(); var drugService = IoC.Container.Resolve <IDrugManagementService>(); var drugsDict = drugService.GetCacheDrugs(drugStoreCode, drugIds).ToDictionary(i => i.DrugId, i => i); trans.Complete(); resultItems.ForEach(i => { if (drugsDict.ContainsKey(i.ItemId)) { var drugItem = drugsDict[i.ItemId]; var retailUnit = drugItem.Units.Where(u => u.UnitId == drugItem.RetailUnitId).FirstOrDefault(); if (retailUnit != null) { i.UnitName = retailUnit.UnitName; } if (i.NoteTypeID == (int)NoteInOutType.InitialInventory) { i.ItemDate = drugItem.CreatedDateTime; } } }); if (expiredOption == (int)ExpiredFilterType.OnlyExpired) { resultItems = resultItems.Where(i => i.IsExpired || i.IsLittleTrans).ToList(); } else if (expiredOption == (int)ExpiredFilterType.All) { resultItems = resultItems.Where(i => i.ExpiredDate.HasValue).ToList(); } totalCount = resultItems.Count(); result.PagingResultModel = new PagingResultModel <RemainQuantityReceiptDrugItem>(resultItems, totalCount); } return(result); }
public async Task Deactivate(long id) { using var tx = TransactionScopeHelper.GetInstance(); var supplier = await _supplierRepo.GetById(id).ConfigureAwait(false) ?? throw new System.Exception("Supplier Not Found."); supplier.Disable(); await _supplierRepo.UpdateAsync(supplier).ConfigureAwait(false); tx.Complete(); }
public async Task Deactivate(long id) { using var tx = TransactionScopeHelper.GetInstance(); var item = await _unitRepo.GetById(id).ConfigureAwait(false); item.Disable(); await _unitRepo.UpdateAsync(item).ConfigureAwait(false); tx.Complete(); }
public async Task Update(UnitUpdateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var Unit = await _unitRepo.GetById(dto.UnitId).ConfigureAwait(false); await ValidateUnit(dto.Name, Unit); Unit.Update(dto.Name); await _unitRepo.UpdateAsync(Unit); tx.Complete(); }
public async Task Update(SupplierUpdateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var supplier = await _supplierRepo.GetById(dto.Id).ConfigureAwait(false) ?? throw new System.Exception("Supplier Not Found."); await ValidateSupplierNumber(dto.Phone, supplier); supplier.Update(dto.Name, dto.Address, dto.Email, dto.Phone); await _supplierRepo.UpdateAsync(supplier); tx.Complete(); }
public void DeleteForeverDrugs(string drugStoreID, params int[] drugIds) { if (drugIds == null || !drugIds.Any()) { return; } var rNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuNhapChiTiet> >(); var dNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuXuatChiTiet> >(); var invNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuKiemKeChiTiet> >(); var sumPeriodNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, TongKetKyChiTiet> >(); var sumPeriodNoteRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, TongKetKy> >(); var invRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, Inventory> >(); var drugMappingRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, DrugMapping> >(); var drugRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, Thuoc> >(); var priceRefRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedReportContext, ReceiptDrugPriceRef> >(); var reduceRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedReportContext, ReduceNoteItem> >(); var snapshotRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedReportContext, DeliveryNoteItemSnapshotInfo> >(); using (var trans = TransactionScopeHelper.CreateReadCommittedForWrite()) { priceRefRepo.Delete(i => i.DrugStoreCode == drugStoreID && drugIds.Contains(i.DrugId)); reduceRepo.Delete(i => i.DrugStoreCode == drugStoreID && drugIds.Contains(i.DrugID)); snapshotRepo.Delete(i => i.DrugStoreCode == drugStoreID && drugIds.Contains(i.DrugId)); rNoteItemRepo.Delete(i => i.NhaThuoc_MaNhaThuoc == drugStoreID && drugIds.Contains(i.Thuoc_ThuocId.Value)); dNoteItemRepo.Delete(i => i.NhaThuoc_MaNhaThuoc == drugStoreID && drugIds.Contains(i.Thuoc_ThuocId.Value)); invNoteItemRepo.Delete(i => drugIds.Contains(i.Thuoc_ThuocId.Value)); sumPeriodNoteItemRepo.Delete(i => i.NhaThuoc_MaNhaThuoc == drugStoreID && drugIds.Contains(i.Thuoc_ThuocId.Value)); sumPeriodNoteRepo.Delete(i => i.NhaThuoc_MaNhaThuoc == drugStoreID && drugIds.Contains(i.Thuoc_ThuocId.Value)); invRepo.Delete(i => i.DrugStoreID == drugStoreID && drugIds.Contains(i.DrugID)); drugMappingRepo.Delete(i => i.DrugStoreID == drugStoreID && drugIds.Contains(i.SlaveDrugID)); drugRepo.Delete(i => i.NhaThuoc_MaNhaThuoc == drugStoreID && drugIds.Contains(i.ThuocId)); trans.Complete(); } }
public async Task Create(CustomerCreateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); await ValidateCustomerNumber(dto.PhoneNumber); var customer = new Customer(dto.FullName); customer.Email = dto.Email; customer.Address = dto.Address; customer.PhoneNumber = dto.PhoneNumber; customer.Gender = dto.Gender; await _customerRepo.InsertAsync(customer); tx.Complete(); }
public async Task Update(CustomerUpdateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var customer = await _customerRepo.GetById(dto.CusId).ConfigureAwait(false); await ValidateCustomerNumber(dto.PhoneNumber, customer).ConfigureAwait(false); customer.Update(dto.FullName); customer.Email = dto.Email; customer.PhoneNumber = dto.PhoneNumber; customer.Gender = dto.Gender; customer.Address = dto.Address; await _customerRepo.UpdateAsync(customer); tx.Complete(); }
/// <summary> /// 设置用户角色 /// </summary> /// <param name="UserIDs"></param> /// <param name="RoleIDs"></param> /// <returns></returns> public JsonResult SetUserRole(string UserIDs, string RoleIDs) { if (string.IsNullOrWhiteSpace(UserIDs) || string.IsNullOrWhiteSpace(RoleIDs)) { return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet)); } List <int> userIDArr = UserIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList(); List <int> roleIDArr = RoleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList(); if (!CurrentInfo.IsAdministrator && userIDArr.Contains(1330)) { return(Json(new Result(false, "拒绝修改"), JsonRequestBehavior.AllowGet)); } IRelationUserRoleService relationUserRoleService = ServiceFactory.Create <IRelationUserRoleService>(); List <RelationUserRole> listRelationUserRole = new List <RelationUserRole>(); int addCount = 0; using (TransactionScope scope = TransactionScopeHelper.GetTran()) { foreach (var userID in userIDArr) { //删除当前人员的所有的权限,然后在添加新的权限 var userRoles = relationUserRoleService.GetEntities(t => t.UserID == userID); relationUserRoleService.DeleteEntities(userRoles.ToList()); foreach (var roleID in roleIDArr) { RelationUserRole model = new RelationUserRole(); model.UserID = userID; model.RoleID = roleID; model.CreateUserID = CurrentInfo.CurrentUser.ID; model.CreateTime = DateTime.Now; listRelationUserRole.Add(model); } } addCount = relationUserRoleService.AddEntities(listRelationUserRole).Count(); scope.Complete(); } return(Json(new Result(addCount > 0, "成功分配用户角色"), JsonRequestBehavior.AllowGet)); }
private void UpdateChangesByDrugs(string drugStoreID, params int[] drugIds) { if (drugIds == null || !drugIds.Any()) { return; } var dNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuXuatChiTiet> >(); var rNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuNhapChiTiet> >(); var refPriceRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedReportContext, ReceiptDrugPriceRef> >(); using (var trans = TransactionScopeHelper.CreateReadCommittedForWrite()) { dNoteItemRepo.UpdateMany(i => i.NhaThuoc_MaNhaThuoc == drugStoreID && drugIds.Contains(i.Thuoc_ThuocId.Value), i => new PhieuXuatChiTiet() { IsModified = true }); } }
private void UpdateAffectedItems(string drugStoreID, List <int> deliveryItemIds, List <int> receiptItemIds, List <int> drugIds) { deliveryItemIds = deliveryItemIds.Distinct().ToList(); receiptItemIds = receiptItemIds.Distinct().ToList(); drugIds = drugIds.Distinct().ToList(); var dNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuXuatChiTiet> >(); var rNoteItemRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuNhapChiTiet> >(); var refPriceRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedReportContext, ReceiptDrugPriceRef> >(); using (var trans = TransactionScopeHelper.CreateReadCommittedForWrite()) { if (deliveryItemIds.Any()) { dNoteItemRepo.UpdateMany(i => deliveryItemIds.Contains(i.MaPhieuXuatCt), i => new PhieuXuatChiTiet() { IsModified = true }); } if (receiptItemIds.Any()) { rNoteItemRepo.UpdateMany(i => receiptItemIds.Contains(i.MaPhieuNhapCt), i => new PhieuNhapChiTiet() { IsModified = true }); } if ((deliveryItemIds.Any() || receiptItemIds.Any()) && drugIds.Any()) { refPriceRepo.UpdateMany(i => (receiptItemIds.Contains(i.ReceiptNoteItemId) || deliveryItemIds.Contains(i.DeliveryNoteItemId)) && i.DrugStoreCode == drugStoreID && drugIds.Contains(i.DrugId) && !i.IsDeleted, i => new ReceiptDrugPriceRef() { IsDeleted = true }); } trans.Complete(); } }
/// <summary> /// Deletes the entity given its unique ID. /// </summary> /// /// <param name="id"> /// Unique ID. /// </param> /// /// <returns> /// The number of affected rows. /// </returns> public override int Delete(long id) { int rowCount = 0; using (var et = new ExecutionTracerService()) using (var scope = TransactionScopeHelper.CreateDefaultTransactionScope()) { this.OnDeleting(id); var parameters = new Dictionary <string, object>(); parameters.Add("@UserRole_Id", id); rowCount = base.ExecuteScalar <int>("UserRole_Delete", parameters); this.OnDeleted(id); scope.Complete(); } return(rowCount); }
public bool MarkAsDeleteForeverDrugs(string drugStoreCode, params int[] drugIds) { if (drugIds == null || !drugIds.Any()) { return(false); } var retVal = true; try { using (var tran = TransactionScopeHelper.CreateReadCommittedForWrite()) { //if (CheckDrugsHasDeals(drugStoreCode, drugIds)) //{ // tran.Complete(); // return false; //} var drugRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, Thuoc> >(); drugRepo.UpdateMany(i => i.NhaThuoc_MaNhaThuoc == drugStoreCode && drugIds.Contains(i.ThuocId), i => new Thuoc() { RecordStatusID = (byte)RecordStatus.DeletedForever }); //var sqlCommands = GetDeleteDrugsCommands(drugStoreCode, drugIds); //drugRepo.ExecuteSqlCommand(sqlCommands); tran.Complete(); } } catch (Exception ex) { retVal = false; FaultHandler.Instance.Handle(ex, this); } return(retVal); }
public bool DeleteDrugStore(string drugStoreCode) { var retVal = false; try { using (var tran = TransactionScopeHelper.CreateLockAllForWrite()) { var drugStoreRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, NhaThuoc> >(); drugStoreRepo.UpdateMany(i => i.MaNhaThuoc == drugStoreCode || i.MaNhaThuocCha == drugStoreCode, i => new NhaThuoc() { HoatDong = false }); tran.Complete(); } } catch (Exception ex) { FaultHandler.Instance.Handle(ex, this, "DeleteDrugStore"); } return(retVal); }
public DrugTransHistoryResponse GetDrugTransHistoryData(string drugStoreCode, FilterObject filter, int noteTypeId) { var drugTransHisItems = new List <DrugTransHistoryItem>(); var result = new DrugTransHistoryResponse(); var totalCount = 0; using (var trans = TransactionScopeHelper.CreateReadUncommitted()) { if (noteTypeId == (int)NoteInOutType.Receipt) { var drugTransHisQable = _dataFilterService.GetValidReceiptNoteItems(drugStoreCode, filter).Where(i => i.NoteNumber >= 0 && i.NoteDate > MedConstants.MinProductionDataDate); totalCount = drugTransHisQable.Count(); var candidates = drugTransHisQable.OrderByDescending(i => i.NoteDate).ToPagedQueryable(filter.PageIndex, filter.PageSize, totalCount); drugTransHisItems = candidates .Select(i => new DrugTransHistoryItem() { ItemId = i.NoteId, DrugId = i.DrugId, DrugName = i.DrugName, DrugCode = i.DrugCode, UnitId = i.UnitId, UnitName = i.UnitName, Price = i.Price, Quantity = i.Quantity, Discount = i.Discount, VAT = i.VAT, Amount = i.Quantity * i.Price * (1 - i.Discount / 100) * (1 + i.VAT / 100), ItemDate = i.NoteDate.Value, ItemNumber = (int)i.NoteNumber }).ToList(); } else if (noteTypeId == (int)NoteInOutType.Delivery) { var drugTransHisQable = _dataFilterService.GetValidDeliveryNoteItems(drugStoreCode, filter).Where(i => i.NoteNumber >= 0 && i.NoteDate > MedConstants.MinProductionDataDate); totalCount = drugTransHisQable.Count(); var candidates = drugTransHisQable.OrderByDescending(i => i.NoteDate).ToPagedQueryable(filter.PageIndex, filter.PageSize, totalCount); drugTransHisItems = candidates .Select(i => new DrugTransHistoryItem() { ItemId = i.NoteId, DrugId = i.DrugId, DrugName = i.DrugName, DrugCode = i.DrugCode, UnitId = i.UnitId, UnitName = i.UnitName, Price = i.Price, Quantity = i.Quantity, Discount = i.Discount, VAT = i.VAT, Amount = i.Quantity * i.Price * (1 - i.Discount / 100) * (1 + i.VAT / 100), ItemDate = i.NoteDate.Value, ItemNumber = (int)i.NoteNumber }).ToList(); } trans.Complete(); } var order = filter.PageIndex * filter.PageSize; drugTransHisItems.ForEach(i => { order++; i.Order = order; }); result.PagingResultModel = new PagingResultModel <DrugTransHistoryItem>(drugTransHisItems, totalCount); return(result); }
public RevenueDrugSynthesisResponse GetRevenueDrugSynthesis(string drugStoreCode, FilterObject filter) { var revenueDrugItems = new List <RevenueDrugItem>(); var result = new RevenueDrugSynthesisResponse() { Total = 0.0, Revenue = 0.0, DeliveryTotal = 0.0, DebtTotal = 0.0 }; var rpDataService = IoC.Container.Resolve <IReportGenDataService>(); rpDataService.GenerateReceiptDrugPriceRefs(drugStoreCode); using (var tran = TransactionScopeHelper.CreateReadUncommitted()) { var deliveryService = IoC.Container.Resolve <IDeliveryNoteService>(); var deliveryStatuses = new int[] { (int)NoteInOutType.Delivery }; var deliveryItems = deliveryService.GetDeliveryNoteItems(drugStoreCode, filter, deliveryStatuses); if (deliveryItems.Count <= 0) { result.PagingResultModel = new PagingResultModel <RevenueDrugItem>(revenueDrugItems, revenueDrugItems.Count); return(result); } var candidates = deliveryItems.OrderBy(i => i.NoteDate).GroupBy(i => i.NoteId); var order = 0; foreach (var cand in candidates) { order++; var idx = 0; var subItems = cand.ToList(); foreach (var di in subItems) { var revenueDrugItem = new RevenueDrugItem() { Order = idx == 0 ? order.ToString() : string.Empty, DeliveryNoteId = di.NoteId, CustomerName = idx == 0 ? di.CustomerName : string.Empty, DrugCode = di.DrugCode, DrugName = di.DrugName, UnitName = di.UnitName, //Quantity = di.FinalRealQuantity, Quantity = di.Quantity, Price = di.Price, Discount = di.Discount, Amount = di.FinalAmount, // Effected by discount & VAT Revenue = di.Revenue, NoteNumber = idx == 0 ? di.NoteNumber.ToString() : string.Empty, VAT = idx == 0 ? (double?)di.VAT : null, DebtAmount = idx == 0 ? di.DebtAmount : 0 }; revenueDrugItems.Add(revenueDrugItem); result.DeliveryTotal += revenueDrugItem.Amount; result.Revenue += revenueDrugItem.Revenue; result.DebtTotal += revenueDrugItem.DebtAmount; idx++; } } var receiptNoteService = IoC.Container.Resolve <IReceiptNoteService>(); var noteItemsReturnFromCustomers = receiptNoteService.GetReceiptNoteItems(drugStoreCode, filter, new int[] { (int)NoteInOutType.ReturnFromCustomer }); var returnedCandidates = noteItemsReturnFromCustomers.OrderBy(i => i.NoteDate).GroupBy(i => i.NoteId); foreach (var cand in returnedCandidates) { order++; var idx = 0; var subItems = cand.ToList(); foreach (var di in subItems) { var revenueDrugItem = new RevenueDrugItem() { Order = idx == 0 ? order.ToString() : string.Empty, DeliveryNoteId = di.NoteId, CustomerName = idx == 0 ? String.Format("{0} (trả hàng)", di.CustomerName) : string.Empty, DrugCode = di.DrugCode, DrugName = di.DrugName, UnitName = di.UnitName, Quantity = di.Quantity, Price = di.Price, Discount = di.Discount, Amount = -di.Amount, Revenue = 0, NoteNumber = idx == 0 ? di.NoteNumber.ToString() : string.Empty, VAT = idx == 0 ? (double?)di.VAT : null, IsReturnFromCustomer = true }; revenueDrugItems.Add(revenueDrugItem); result.DeliveryTotal += revenueDrugItem.Amount; //result.Revenue += -di.RetailAmount; idx++; } } } result.Total = result.DeliveryTotal - result.DebtTotal; result.PagingResultModel = new PagingResultModel <RevenueDrugItem>(revenueDrugItems, revenueDrugItems.Count); return(result); }