private void FormProviderIncTrans_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         return;
     }
     if (IsNew)
     {
         Payments.Delete(PaymentCur);
     }
 }
        private void butOK_Click(object sender, EventArgs e)
        {
            if (!Security.IsAuthorized(Permissions.PaymentCreate))
            {
                return;
            }
            double splitTotal = _listSplitsCur.Select(x => x.SplitAmt).Sum();

            if (!splitTotal.IsZero())              //income transfer
            {
                MsgBox.Show(this, "Income transfers must have a split total of 0.");
                return;
            }
            _listSplitsCur.RemoveAll(x => x.SplitAmt.IsZero());            //We don't want any zero splits.  They were there just for display purposes.
            if (_listSplitsCur.Count == 0)
            {
                Payments.Delete(_paymentCur);
            }
            else
            {
                foreach (PaySplit split in _listSplitsCur)
                {
                    PaySplits.Insert(split);
                }
                foreach (PaySplits.PaySplitAssociated split in _listSplitsAssociated)
                {
                    //Update the FSplitNum after inserts are made.
                    if (split.PaySplitLinked != null && split.PaySplitOrig != null)
                    {
                        PaySplits.UpdateFSplitNum(split.PaySplitOrig.SplitNum, split.PaySplitLinked.SplitNum);
                    }
                }
                if (_listSplitsCur.Count > 0)               //only make log when a payment with splits was made.
                {
                    string logText = Payments.GetSecuritylogEntryText(_paymentCur, _paymentCur, isNew: true) + ", " + Lans.g(this, "from Income Transfer Manager.");
                    SecurityLogs.MakeLogEntry(Permissions.PaymentCreate, _paymentCur.PatNum, logText);
                }
                string strErrorMsg = Ledgers.ComputeAgingForPaysplitsAllocatedToDiffPats(_patCur.PatNum, _listSplitsCur);
                if (!string.IsNullOrEmpty(strErrorMsg))
                {
                    MessageBox.Show(strErrorMsg);
                }
            }
            DialogResult = DialogResult.OK;
        }
 private void butDeleteAll_Click(object sender, EventArgs e)
 {
     if (!MsgBox.Show(this, true, "Delete?"))
     {
         return;
     }
     try {
         Payments.Delete(PaymentCur);
     }
     catch (ApplicationException ex) {           //error if attached to deposit slip (not possible)
         MessageBox.Show(ex.Message);
         return;
     }
     if (!IsNew)
     {
         SecurityLogs.MakeLogEntry(Permissions.PaymentEdit, 0, Lan.g(this, "Delete Prov income transfer."));
     }
     DialogResult = DialogResult.OK;
 }
 private void FormIncomeTransferManage_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         return;
     }
     //Clean up any potential entities that were inserted during window interactions.
     if (_unallocatedPayNum != 0)
     {
         //user is canceling out of the window and an unallocated transfer was made.
         ODException.SwallowAnyException(() => {
             Payments.Delete(_unallocatedPayNum);
             SecurityLogs.MakeLogEntry(Permissions.PaymentEdit, _patCur.PatNum, $"Automatic transfer deleted for payNum: {_unallocatedPayNum}.");
         });
     }
     if (_claimTransferResult != null)
     {
         //user is canceling out of the window and an claim transfer was made.
         if (_claimTransferResult.ListInsertedClaimProcs.Count > 0)
         {
             ODException.SwallowAnyException(() => {
                 ClaimProcs.DeleteMany(_claimTransferResult.ListInsertedClaimProcs);
                 SecurityLogs.MakeLogEntry(Permissions.PaymentEdit, _patCur.PatNum, $"Automatically transferred claimprocs deleted.");
             });
         }
         if (_claimTransferResult.ListInsertedPaySplits.Count > 0)
         {
             ODException.SwallowAnyException(() => {
                 List <long> listDistinctPayNums = _claimTransferResult.ListInsertedPaySplits.Select(x => x.PayNum).Distinct().ToList();
                 foreach (long payNum in listDistinctPayNums)
                 {
                     Payments.Delete(payNum);
                 }
                 SecurityLogs.MakeLogEntry(Permissions.PaymentEdit, _patCur.PatNum, $"Automatically transferred unearned from claimprocs deleted.");
             });
         }
     }
 }
Ejemplo n.º 5
0
        ///<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);
        }