/// <summary>Only used to void or refund transactions from PayConnectPortal. Creates new cloned payment and paysplits for the refund or void. /// Returns true if the transaction was successful, otherwise false.</summary public static bool VoidOrRefundPayConnectPortalTransaction(PayConnectResponseWeb pcResponseWeb, Payment payment, PayConnectService.transType transType, string refNum, decimal amount) { if (!transType.In(PayConnectService.transType.RETURN, PayConnectService.transType.VOID)) { return(false); } List <PaySplit> listPaySplits = PaySplits.GetForPayment(payment.PayNum); PayConnectService.creditCardRequest _payConnectRequest = new PayConnectService.creditCardRequest(); PayConnectResponse response = null; string receiptStr = ""; _payConnectRequest.TransType = transType; _payConnectRequest.RefNumber = refNum; _payConnectRequest.Amount = amount; PayConnectService.transResponse transResponse = PayConnect.ProcessCreditCard(_payConnectRequest, payment.ClinicNum, x => MsgBox.Show(x)); response = new PayConnectResponse(transResponse, _payConnectRequest); receiptStr = PayConnect.BuildReceiptString(_payConnectRequest, transResponse, null, payment.ClinicNum); if (response == null || response.StatusCode != "0") //error in transaction { return(false); } //Record a new payment for the voided transaction Payment clonePayment = payment.Clone(); clonePayment.PayAmt *= -1; //The negated amount of the original payment clonePayment.PayDate = DateTime.Now; clonePayment.Receipt = receiptStr; clonePayment.PayNote = Lan.g("PayConnectL", "Transaction Type") + ": " + Enum.GetName(typeof(PayConnectService.transType), transType) + Environment.NewLine + Lan.g("PayConnectL", "Status") + ": " + response.Description + Environment.NewLine + Lan.g("PayConnectL", "Amount") + ": " + clonePayment.PayAmt + Environment.NewLine + Lan.g("PayConnectL", "Auth Code") + ": " + response.AuthCode + Environment.NewLine + Lan.g("PayConnectL", "Ref Number") + ": " + response.RefNumber; clonePayment.PaymentSource = pcResponseWeb.CCSource; clonePayment.ProcessStatus = ProcessStat.OfficeProcessed; clonePayment.PayNum = Payments.Insert(clonePayment); List <PaySplit> listClonedPaySplits = new List <PaySplit>(); foreach (PaySplit paySplit in listPaySplits) { PaySplit copy = paySplit.Copy(); copy.SplitAmt *= -1; copy.PayNum = clonePayment.PayNum; copy.DatePay = clonePayment.PayDate; listClonedPaySplits.Add(copy); } PaySplits.InsertMany(listClonedPaySplits); PayConnectResponseWeb newPCResponseWeb = new PayConnectResponseWeb() { PatNum = payment.PatNum, PayNum = clonePayment.PayNum, CCSource = pcResponseWeb.CCSource, Amount = clonePayment.PayAmt, PayNote = Lan.g("PayConnectL", clonePayment.PayNote + Environment.NewLine + "From within Open Dental Proper."), ProcessingStatus = PayConnectWebStatus.Completed, DateTimeEntry = DateTime.Now, DateTimeCompleted = DateTime.Now, IsTokenSaved = false, RefNumber = transResponse.RefNumber, TransType = transType, PaymentToken = pcResponseWeb.PaymentToken, }; PayConnectResponseWebs.Insert(newPCResponseWeb); SecurityLogs.MakeLogEntry(Permissions.PaymentCreate, clonePayment.PatNum, Patients.GetLim(clonePayment.PatNum).GetNameLF() + ", " + clonePayment.PayAmt.ToString("c")); return(true); }
///<summary>Transfers all family balance to the guarantor, balancing the account to the best of our ability. ///Returns a log of what was moved from the family member(s) of the selected guarantor(s)</summary> private string TransferToGuarantor() { string summaryText = ""; //Iterate through every family. foreach (FamilyAccount famAccountCur in _dictCurrentFamilyBatch.Select(x => x.Value)) { double totalTransferAmount = 0; long provNum = famAccountCur.Guarantor.PriProv; Payment payCur = CreatePaymentTransferHelper(famAccountCur.Guarantor); List <PaySplit> listPaySplitsCreated = new List <PaySplit>(); #region Family PaySplits string logText = ""; foreach (Patient pat in famAccountCur.ListFamilyMembers) //Make a counteracting split for each patient. //Don't make a split for the Guarantor yet. { if (pat.PatNum == famAccountCur.Guarantor.PatNum) { continue; } //Check the family member's balance and skip if it is $0.00. double splitAmt = (double)famAccountCur.Account.ListAccountCharges.Where(x => x.PatNum == pat.PatNum).Sum(x => x.AmountEnd); if (splitAmt == 0) { continue; } PaySplit paySplit = new PaySplit(); paySplit.DatePay = datePicker.Value; paySplit.PatNum = pat.PatNum; paySplit.PayNum = payCur.PayNum; paySplit.ProvNum = pat.PriProv; paySplit.ClinicNum = payCur.ClinicNum; //Since we're transferring all family member balances to the guarantor, we set the split amount to their balance. paySplit.SplitAmt = splitAmt; totalTransferAmount += paySplit.SplitAmt; listPaySplitsCreated.Add(paySplit); if (logText != "") { logText += ", "; } logText += paySplit.SplitAmt.ToString("f"); } #endregion Family PaySplits if (listPaySplitsCreated.Count == 0) { //No splits were made, delete payment and skip guarantor. Payments.Delete(payCur); continue; } //Since we skipped the guarantor before, we make one for them now. PaySplit splitGuarantor = new PaySplit(); splitGuarantor.DatePay = datePicker.Value; splitGuarantor.PatNum = famAccountCur.Guarantor.PatNum; splitGuarantor.PayNum = payCur.PayNum; splitGuarantor.ProvNum = provNum; splitGuarantor.ClinicNum = payCur.ClinicNum; splitGuarantor.SplitAmt = 0 - totalTransferAmount; //Split is the opposite amount of the total of the other splits. if (splitGuarantor.SplitAmt != 0) { listPaySplitsCreated.Add(splitGuarantor); } //Insert paysplits all at once for speed. PaySplits.InsertMany(listPaySplitsCreated); List <Patient> listTransferredPats = famAccountCur.ListFamilyMembers.FindAll(x => x.PatNum != famAccountCur.Guarantor.PatNum && listPaySplitsCreated.Select(y => y.PatNum).ToList().Contains(x.PatNum)); payCur.PayNote = "Auto-created by Family Balancer tool " + MiscData.GetNowDateTime().ToString("MM/dd/yyyy") + "\r\n" + "Allocated " + logText + $" transfers from family member{(famAccountCur.ListFamilyMembers.Count>1 ? "s " : " ")}" + string.Join(", ", listTransferredPats.Select(x => x.FName).ToList()) + " to guarantor " + famAccountCur.Guarantor.FName + "."; //Shown after all family members have been processed. summaryText += "PatNum(s):" + string.Join(", ", listTransferredPats.Select(x => x.PatNum).ToList()) + " moved to guarantor: " + famAccountCur.Guarantor.PatNum + "; Amount(s): " + logText + "\r\n"; Payments.Update(payCur, true); } return(summaryText); }