public override bool AfterSave() { if ((Invoice)ActiveDBItem == null) { return(false); } if (Grid_InvoiceDetails != null && (Grid_InvoiceDetails).Count > 0) { switch (CommonTransactionType) { case DB_CommonTransactionType.CreateNew: foreach (InvoiceDetail invoiceDetail in Grid_InvoiceDetails) { QueueManager manager = MerkDBBusinessLogicEngine.CreateNewQueueManager((Invoice)ActiveDBItem, invoiceDetail); if (manager != null) { manager.SaveChanges(); } } break; case DB_CommonTransactionType.UpdateExisting: if (Grid_InvoiceDetails.Count >= ((Invoice)ActiveDBItem).InvoiceDetails.Count) { foreach (InvoiceDetail invoiceDetail in Grid_InvoiceDetails) { if (((Invoice)ActiveDBItem).List_InvoiceDetails != null && ((Invoice)ActiveDBItem).InvoiceDetails.Count > 0) { if (((Invoice)ActiveDBItem).List_InvoiceDetails.ToList() .Exists(item => Convert.ToInt32(item.ID) .Equals(Convert.ToInt32(invoiceDetail.ID)))) { continue; } } QueueManager manager = MerkDBBusinessLogicEngine.CreateNewQueueManager((Invoice)ActiveDBItem, invoiceDetail); if (manager != null) { manager.SaveChanges(); } } } else { foreach (InvoiceDetail invoiceDetail in ((Invoice)ActiveDBItem).InvoiceDetails) { if (Grid_InvoiceDetails.ToList() .Exists(item => Convert.ToInt32(item.ID).Equals(Convert.ToInt32(invoiceDetail.ID)))) { continue; } QueueManager queueManager = invoiceDetail.QueueManagers.ToList() .Find(item => Convert.ToInt32(item.InvoiceDetailID) .Equals(Convert.ToInt32(invoiceDetail.ID))); if (queueManager == null) { continue; } queueManager.DBCommonTransactionType = DB_CommonTransactionType.UpdateExisting; queueManager.IsOnDuty = false; queueManager.SaveChanges(); } } break; } } return(true); }
public override bool Collect(AbstractDataCollector <TEntity> collector) { if (collector == null) { return(false); } ActiveCollector = collector; ID = ((IPatientInvoiceCreation)ActiveCollector.ActiveViewer).ID; if (ActiveDBItem == null) { return(false); } ((Invoice)ActiveDBItem).DBCommonTransactionType = CommonTransactionType; ((Invoice)ActiveDBItem).InvoiceType_P_ID = (int)InvoiceTypeID; ((Invoice)ActiveDBItem).InvoicePaymentType_P_ID = (int)DB_InvoicePaymentType.CashInvoice; ((Invoice)ActiveDBItem).InvoiceCreationDate = Convert.ToDateTime(InvoiceCreationDate); ((Invoice)ActiveDBItem).Patient_CU_ID = Convert.ToInt32(PatientID); ((Invoice)ActiveDBItem).IsPrinted = false; ((Invoice)ActiveDBItem).InvoiceSerial = null; ((Invoice)ActiveDBItem).PrintingDate = null; ((Invoice)ActiveDBItem).IsPaymentsEnough = Convert.ToBoolean(IsPaymentEnough); ((Invoice)ActiveDBItem).Description = null; ((Invoice)ActiveDBItem).IsOnDuty = true; switch ((DB_InvoiceType)InvoiceTypeID) { case DB_InvoiceType.OutPatientNotPrivate: case DB_InvoiceType.OutPatientPrivate: ((Invoice)ActiveDBItem).IsFinanciallyReviewed = true; break; case DB_InvoiceType.InPatientPrivate: case DB_InvoiceType.InPatientNotPrivate: ((Invoice)ActiveDBItem).IsFinanciallyReviewed = false; break; } ((Invoice)ActiveDBItem).IsMedicallyDone = false; ((Invoice)ActiveDBItem).IsFinanciallyCompleted = false; ((Invoice)ActiveDBItem).IsCancelled = false; ((Invoice)ActiveDBItem).CancelledBy = null; ((Invoice)ActiveDBItem).CancellationDate = null; ((Invoice)ActiveDBItem).IsSuspended = false; ((Invoice)ActiveDBItem).InvoiceShare = new InvoiceShare(); if (AccummulativeServicesPatientShare != null) { ((Invoice)ActiveDBItem).InvoiceShare.TotalPatientShare = Convert.ToDouble(AccummulativeServicesPatientShare); } if (AccummulativeServicesInsuranceShare != null) { ((Invoice)ActiveDBItem).InvoiceShare.TotalInsuranceShare = Convert.ToDouble(AccummulativeServicesInsuranceShare); } ((Invoice)ActiveDBItem).InvoiceShare.TotalPayment = 0; ((Invoice)ActiveDBItem).InvoiceShare.IsInsuranceApplied = Convert.ToBoolean(IsInsuranceAppliedToInvoice); if (InsuranceCarrierID != null) { ((Invoice)ActiveDBItem).InvoiceShare.InsuranceCarrier_CU_ID = Convert.ToInt32(InsuranceCarrierID); } if (InsuranceLevelID != null) { ((Invoice)ActiveDBItem).InvoiceShare.InsuanceLevel_CU_ID = Convert.ToInt32(InsuranceLevelID); } if (InsurancePercentage != null) { ((Invoice)ActiveDBItem).InvoiceShare.InsurancePercentageApplied = Convert.ToDouble(InsurancePercentage) / 100; } if (InsurancePatientMaxAmount != null) { ((Invoice)ActiveDBItem).InvoiceShare.InsurancePatientMaxAmount = Convert.ToDouble(InsurancePatientMaxAmount); } ((Invoice)ActiveDBItem).InvoiceShare.IsSurchargeApplied = Convert.ToBoolean(IsSurchargeAppliedToInvoice); if (SurchargeAmount != null) { ((Invoice)ActiveDBItem).InvoiceShare.TotalSurchargeAccummulativePercentage = Convert.ToDouble(SurchargeAmount); } ((Invoice)ActiveDBItem).InvoiceShare.IsStampApplied = Convert.ToBoolean(IsStampApplied); if (StampAmount != null) { ((Invoice)ActiveDBItem).InvoiceShare.TotalStampAmount = Convert.ToDouble(StampAmount); } ((Invoice)ActiveDBItem).InvoiceShare.IsSurchargeDistributedToInsurancePercentage = true; ((Invoice)ActiveDBItem).InvoiceShare.IsSurchargeAppliedToPatientOnly = false; if (UserID != null) { ((Invoice)ActiveDBItem).InvoiceShare.InsertedBy = Convert.ToInt32(UserID); } ((Invoice)ActiveDBItem).InvoiceShare.IsStampDistributedToInsurancePercentage = true; ((Invoice)ActiveDBItem).InvoiceShare.IsStampAppliedToPatientOnly = false; if (Convert.ToBoolean(IsPaymentAttached) && AmountPaid != null && Convert.ToDouble(AmountPaid) >= 0) { InvoicePayment invoicePayment = DBCommon.CreateNewDBEntity <InvoicePayment>(); invoicePayment.Amount = ((Invoice)ActiveDBItem).InvoiceShare.TotalPayment = Convert.ToDouble(AmountPaid); if (InvoiceCreationDate != null) { invoicePayment.Date = Convert.ToDateTime(InvoiceCreationDate); } invoicePayment.PaymentType_P_ID = (int)DB_PaymentType.CashPayment; invoicePayment.PaymentSerial = "123"; invoicePayment.IsOnDuty = true; invoicePayment.Description = ((Invoice)ActiveDBItem).Description; invoicePayment.IsRemainingReturned = Convert.ToBoolean(IsRemainingReturned); if (UserID != null) { invoicePayment.InsertedBy = Convert.ToInt32(UserID); } ((Invoice)ActiveDBItem).InvoicePayments.Add(invoicePayment); } if (UserID != null) { ((Invoice)ActiveDBItem).InsertedBy = Convert.ToInt32(UserID); } if (Grid_InvoiceDetails != null && Grid_InvoiceDetails.Count > 0) { switch (CommonTransactionType) { case DB_CommonTransactionType.CreateNew: foreach (InvoiceDetail invoiceDetail in Grid_InvoiceDetails) { if (UserID != null) { invoiceDetail.InsertedBy = Convert.ToInt32(UserID); } ((Invoice)ActiveDBItem).InvoiceDetails.Add(invoiceDetail); } break; case DB_CommonTransactionType.UpdateExisting: if (Grid_InvoiceDetails.Count >= ((Invoice)ActiveDBItem).InvoiceDetails.Count) { foreach (InvoiceDetail invoiceDetail in Grid_InvoiceDetails) { if (UserID != null) { invoiceDetail.InsertedBy = Convert.ToInt32(UserID); } if (((Invoice)ActiveDBItem).InvoiceDetails.ToList() .Exists(item => Convert.ToInt32(item.ID).Equals(Convert.ToInt32(invoiceDetail.ID)))) { continue; } if (UserID != null) { invoiceDetail.InsertedBy = Convert.ToInt32(UserID); } invoiceDetail.InvoiceID = ((Invoice)ActiveDBItem).ID; invoiceDetail.SaveChanges(); } } else { foreach (InvoiceDetail invoiceDetail in ((Invoice)ActiveDBItem).InvoiceDetails) { if (Grid_InvoiceDetails.ToList() .Exists(item => Convert.ToInt32(item.ID).Equals(Convert.ToInt32(invoiceDetail.ID)))) { continue; } invoiceDetail.IsOnDuty = false; invoiceDetail.InvoiceID = ((Invoice)ActiveDBItem).ID; invoiceDetail.DBCommonTransactionType = DB_CommonTransactionType.UpdateExisting; invoiceDetail.SaveChanges(); } } break; } } else { return(false); } return(true); }