/// <summary> /// Gets the fAArmortizations. /// </summary> /// <param name="request">The request.</param> /// <returns>FAArmortizationResponse.</returns> public FAArmortizationResponse GetFAArmortizations(FAArmortizationRequest request) { var response = new FAArmortizationResponse(); if (request.LoadOptions.Contains("FixedAssetArmortizations")) { if (request.LoadOptions.Contains("RefType")) { response.FAArmortizations = FAArmortizationDao.GetFAArmortizationsByRefTypeId(request.RefType); } else if (request.LoadOptions.Contains("RefDate")) { if (request.LoadOptions.Contains("CurrencyCode")) { response.FAArmortizations = FAArmortizationDao.GetFAArmortizationsByRefDate(DateTime.Parse(request.RefDate), request.CurrencyCode); } else { response.FAArmortizations = FAArmortizationDao.GetFAArmortizationsByRefDate(DateTime.Parse(request.RefDate)); } } else { response.FAArmortizations = FAArmortizationDao.GetFAArmortizations(); } if (request.LoadOptions.Contains("IncludeDetail")) { foreach (var fAArmortization in response.FAArmortizations) { fAArmortization.FAArmortizationDetails = FAArmortizationDetailDao.GetFAArmortizationDetailsByFAArmortization(fAArmortization.RefId); } } } if (request.LoadOptions.Contains("FixedAssetArmortization")) { var fAArmortization = FAArmortizationDao.GetFAArmortization(request.RefId); if (request.LoadOptions.Contains("IncludeDetail")) { if (request.LoadOptions.Contains("AutoGenerate")) { fAArmortization = fAArmortization ?? new FAArmortizationEntity(); fAArmortization.FAArmortizationDetails = FAArmortizationDetailDao.GetAutoFAArmortizationDetailsByCurrencyCode(request.CurrencyCode, request.YearOfDeprecation); } else { fAArmortization = fAArmortization ?? new FAArmortizationEntity(); fAArmortization.FAArmortizationDetails = FAArmortizationDetailDao.GetFAArmortizationDetailsByFAArmortization(fAArmortization.RefId); } } response.FAArmortization = fAArmortization; } if (request.LoadOptions.Contains("FAArmortizationCheck")) { var a = FAArmortizationDetailDao.GetFAArmortizationByFAIncrement(request.RefId); response.FADecrementDetails = a; } return(response); }
/// <summary> /// Sets the fAArmortizations. /// </summary> /// <param name="request">The request.</param> /// <returns>FAArmortizationResponse.</returns> public FAArmortizationResponse SetFAArmortizations(FAArmortizationRequest request) { var response = new FAArmortizationResponse(); var fAArmortizationEntity = request.FAArmortization; //var auditingLog = new AudittingLogEntity { ComponentName = "KHAU HAO TSCD", EventAction = (int)request.Action }; if (request.Action != PersistType.Delete) { if (!fAArmortizationEntity.Validate()) { foreach (var error in fAArmortizationEntity.ValidationErrors) { response.Message += error + Environment.NewLine; } response.Acknowledge = AcknowledgeType.Failure; return(response); } } try { if (request.Action == PersistType.Insert) { using (var scope = new TransactionScope()) { var getFAArmortizationsByRefDate = FAArmortizationDao.GetFAArmortizationsByRefDate(fAArmortizationEntity.RefDate, fAArmortizationEntity.CurrencyCode); if (getFAArmortizationsByRefDate != null && getFAArmortizationsByRefDate.Count > 0) { response.Acknowledge = AcknowledgeType.Failure; response.Message = "Chứng từ tiền " + fAArmortizationEntity.CurrencyCode + " đã tồn tại trong năm !"; scope.Dispose(); return(response); } foreach (var fAArmortizationDetail in fAArmortizationEntity.FAArmortizationDetails) { fAArmortizationEntity.TotalAmountOC = fAArmortizationEntity.TotalAmountOC + fAArmortizationDetail.AmountOC; fAArmortizationEntity.TotalAmountExchange = fAArmortizationEntity.TotalAmountExchange + fAArmortizationDetail.AmountExchange; } fAArmortizationEntity.RefId = FAArmortizationDao.InsertFAArmortization(fAArmortizationEntity); if (fAArmortizationEntity.RefId == 0) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert detail foreach (var fAArmortizationDetail in fAArmortizationEntity.FAArmortizationDetails) { if (!fAArmortizationDetail.Validate()) { foreach (string error in fAArmortizationDetail.ValidationErrors) { response.Message += error + Environment.NewLine; } response.Acknowledge = AcknowledgeType.Failure; return(response); } fAArmortizationDetail.RefId = fAArmortizationEntity.RefId; fAArmortizationDetail.RefDetailId = FAArmortizationDetailDao.InsertFAArmortizationDetail(fAArmortizationDetail); if (fAArmortizationDetail.RefDetailId == 0) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert jounaral entry var journalEntryAccount = AddJournalEntryAccount(fAArmortizationEntity, fAArmortizationDetail); if (!journalEntryAccount.Validate()) { foreach (var error in journalEntryAccount.ValidationErrors) { response.Message += error + Environment.NewLine; } response.Acknowledge = AcknowledgeType.Failure; return(response); } JournalEntryAccountDao.InsertDoubleJournalEntryAccount(journalEntryAccount); //insert AccountBalance InsertAccountBalance(fAArmortizationEntity, fAArmortizationDetail); } //insert fixedasset ledger var fixedAssetLedgers = InitFixedAssetLedgers(fAArmortizationEntity); foreach (var fixedAssetLedgerEntity in fixedAssetLedgers) { fixedAssetLedgerEntity.FixedAssetLedgerId = FixedAssetLedgerDao.InsertFixedAssetLedger(fixedAssetLedgerEntity); if (fixedAssetLedgerEntity.FixedAssetLedgerId != 0) { continue; } response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert auto number var autoNumber = AutoNumberDao.GetAutoNumberByRefType(fAArmortizationEntity.RefTypeId); //------------------------------------------------------------------ //LinhMC 29/11/2014 //Lưu giá trị số tự động tăng theo loại tiền //--------------------------------------------------------------- if (fAArmortizationEntity.CurrencyCode == "USD") { autoNumber.Value += 1; } else { autoNumber.ValueLocalCurency += 1; } response.Message = AutoNumberDao.UpdateAutoNumber(autoNumber); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert log //auditingLog.Reference = "Thêm mới CT khấu hao " + fAArmortizationEntity.RefNo; //auditingLog.Amount = 0; //AudittingLogDao.InsertAudittingLog(auditingLog); scope.Complete(); } } else if (request.Action == PersistType.Update) { using (var scope = new TransactionScope()) { foreach (var fAArmortizationDetail in fAArmortizationEntity.FAArmortizationDetails) { fAArmortizationEntity.TotalAmountOC = fAArmortizationEntity.TotalAmountOC + fAArmortizationDetail.AmountOC; fAArmortizationEntity.TotalAmountExchange = fAArmortizationEntity.TotalAmountExchange + fAArmortizationDetail.AmountExchange; } response.Message = FAArmortizationDao.UpdateFAArmortization(fAArmortizationEntity); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //update account balance response.Message = UpdateAccountBalance(fAArmortizationEntity); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //delete JournalEntryAccount response.Message = JournalEntryAccountDao.DeleteJournalEntryAccount(fAArmortizationEntity.RefId, fAArmortizationEntity.RefTypeId); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //delete detail response.Message = FAArmortizationDetailDao.DeleteFAArmortizationDetailByFAArmortizationId(fAArmortizationEntity.RefId); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert detail foreach (var fAArmortizationDetail in fAArmortizationEntity.FAArmortizationDetails) { if (!fAArmortizationDetail.Validate()) { foreach (var error in fAArmortizationDetail.ValidationErrors) { response.Message += error + Environment.NewLine; } response.Acknowledge = AcknowledgeType.Failure; return(response); } fAArmortizationDetail.RefId = fAArmortizationEntity.RefId; fAArmortizationDetail.RefDetailId = FAArmortizationDetailDao.InsertFAArmortizationDetail(fAArmortizationDetail); if (fAArmortizationDetail.RefDetailId == 0) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert jounaral entry var journalEntryAccount = AddJournalEntryAccount(fAArmortizationEntity, fAArmortizationDetail); if (!journalEntryAccount.Validate()) { foreach (var error in journalEntryAccount.ValidationErrors) { response.Message += error + Environment.NewLine; } response.Acknowledge = AcknowledgeType.Failure; return(response); } JournalEntryAccountDao.InsertDoubleJournalEntryAccount(journalEntryAccount); //insert AccountBalance InsertAccountBalance(fAArmortizationEntity, fAArmortizationDetail); } //delete ledger response.Message = FixedAssetLedgerDao.DeleteFixedAssetLedgerByRefId(fAArmortizationEntity.RefId, fAArmortizationEntity.RefTypeId); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert ledger var fixedAssetLedgers = InitFixedAssetLedgers(fAArmortizationEntity); foreach (var fixedAssetLedgerEntity in fixedAssetLedgers) { fixedAssetLedgerEntity.FixedAssetLedgerId = FixedAssetLedgerDao.InsertFixedAssetLedger(fixedAssetLedgerEntity); if (fixedAssetLedgerEntity.FixedAssetLedgerId != 0) { continue; } response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert log //auditingLog.Reference = "Cập nhật CT khấu hao " + fAArmortizationEntity.RefNo; //auditingLog.Amount = 0; //AudittingLogDao.InsertAudittingLog(auditingLog); scope.Complete(); } } else { using (var scope = new TransactionScope()) { var fAArmortizationrEntityForDelete = FAArmortizationDao.GetFAArmortization(request.RefId); //update account balance response.Message = UpdateAccountBalance(fAArmortizationrEntityForDelete); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //delete JournalEntryAccount response.Message = JournalEntryAccountDao.DeleteJournalEntryAccount(fAArmortizationrEntityForDelete.RefId, fAArmortizationrEntityForDelete.RefTypeId); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert master response.Message = FAArmortizationDao.DeleteFAArmortization(fAArmortizationrEntityForDelete); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //delete fixed asset ledger response.Message = FixedAssetLedgerDao.DeleteFixedAssetLedgerByRefId(fAArmortizationrEntityForDelete.RefId, fAArmortizationrEntityForDelete.RefTypeId); if (response.Message != null) { response.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(response); } //insert log //auditingLog.Reference = "Xóa CT khấu hao " + fAArmortizationrEntityForDelete.RefNo; //auditingLog.Amount = 0; //AudittingLogDao.InsertAudittingLog(auditingLog); scope.Complete(); } } } catch (Exception ex) { response.Acknowledge = AcknowledgeType.Failure; response.Message = ex.Message; return(response); } response.RefId = fAArmortizationEntity != null ? fAArmortizationEntity.RefId : 0; response.Acknowledge = response.Message != null ? AcknowledgeType.Failure : AcknowledgeType.Success; return(response); }