Пример #1
0
        private void UnlinkHoursPayButton_Click(object sender, EventArgs e)
        {
            if (IsPaymentSelected() == false)
            {
                return;
            }

            PaymentEntry selectedPayment = (PaymentEntry)PayListViewBox.SelectedItems[0].Tag;

            var selectedItems = HoursListViewBox.SelectedItems;

            foreach (ListViewItem item in selectedItems)
            {
                TimeSheetEntry hoursEntry = (TimeSheetEntry)item.Tag;

                if (item.Checked == true)
                {
                    GlobalConfig.Connection.DeletePayHoursLink(selectedPayment, hoursEntry);
                    item.Checked = false;
                }
            }

            HighlightLinkedHours();

            UpdateExpectedValues();
        }
Пример #2
0
        private void CalcBalances(object row, bool isCalcRGOL, bool DiscOnDiscDate)
        {
            ARAdjust adj = (ARAdjust)row;

            PXCache cache = Caches[typeof(ARAdjust)];

            ARPayment payment = (ARPayment)ARPayment_CustomerID_DocType_RefNbr.Select(adj.CustomerID, adj.AdjgDocType, adj.AdjgRefNbr);

            if (payment == null)
            {
                return;
            }

            PaymentEntry.CalcBalances <ARPayment, ARAdjust>(CurrencyInfo_CuryInfoID, adj.AdjgCuryInfoID, adj.AdjdCuryInfoID, payment, adj);

            if (DiscOnDiscDate)
            {
                PaymentEntry.CalcDiscount <ARPayment, ARAdjust>(adj.AdjgDocDate, payment, adj);
            }

            PaymentEntry.AdjustBalance <ARAdjust>(CurrencyInfo_CuryInfoID, adj);
            if (isCalcRGOL)
            {
                PaymentEntry.CalcRGOL <ARPayment, ARAdjust>(CurrencyInfo_CuryInfoID, payment, adj);
                adj.RGOLAmt = (bool)adj.ReverseGainLoss ? -1m * adj.RGOLAmt : adj.RGOLAmt;
            }
        }
Пример #3
0
        private void PopulatePayListView()
        {
            PayListViewBox.Items.Clear();
            PaymentsListViewItems = Employment.PaymentEntries;

            for (int i = 0; i < PaymentsListViewItems.Count; i++)
            {
                PaymentEntry entry = PaymentsListViewItems[i];

                string[] cols =
                {
                    entry.Date.ToLongDateString(),
                    entry.HoursWorked.ToString(),
                    $"{entry.ExpectedPay:C2}",
                    $"{entry.ActualPay:C2}"
                };

                var listViewItem = new ListViewItem(cols);
                listViewItem.Tag = entry;

                PayListViewBox.Items.Add(listViewItem);
            }

            PayListViewBox.Sort();
            UpdatePayColourCoding();
        }
Пример #4
0
        private void HighlightLinkedHours()
        {
            List <TimeSheetEntry> linked;

            if (IsPaymentSelected() == false)
            {
                linked = new List <TimeSheetEntry>();
            }
            else
            {
                PaymentEntry selectedPayment = (PaymentEntry)PayListViewBox.SelectedItems[0].Tag;

                linked = GlobalConfig.Connection.GetLinkedHours(selectedPayment);
            }

            foreach (ListViewItem item in HoursListViewBox.Items)
            {
                TimeSheetEntry hoursEntry = (TimeSheetEntry)item.Tag;

                if (linked.Contains(hoursEntry, new TimeSheetComparer()) == true)
                {
                    item.BackColor = Color.Gray;
                    item.Checked   = true;
                }
                else
                {
                    item.BackColor = Color.White;
                }
            }
        }
Пример #5
0
        public async Task <BaseResult> AddPayment(PaymentEntry paymentEntry)
        {
            _logger.LogDebug($"Initiating AddPayment Operation");

            BaseResult res = new BaseResult();

            PutItemRequest putRequest = new PutItemRequest
            {
                TableName = _paymentConfig.TableName,
                Item      = paymentEntry.ConvertToDynamoDocument().ToAttributeMap()
            };


            var response = await _dynamoDB.PutItemAsync(putRequest);

            //TODO: When usage increases make a common extension method to determine success of dynamoresponse consumer
            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                res.Success = true;
            }
            else
            {
                res.Success = false; //retry and throw
            }
            res.Message = $"DynamoDB Response HttpStatusCode: {response.HttpStatusCode}";

            _logger.LogDebug($"{res.Message}");

            return(res);
        }
Пример #6
0
        public async Task <BaseResult> ProcessPayment(PaymentEntry paymentEntry)
        {
            BaseResult res = new BaseResult();

            var initialDataAccessRes = await _paymentsDataAcces.AddPayment(paymentEntry);

            var bankRequest = paymentEntry.ConvertToMockPaymentRequest();

            var requestPaymentResponse = _mockBankRepo.RequestPayment(bankRequest);

            paymentEntry.Status         = requestPaymentResponse.Status;
            paymentEntry.BankIdentifier = requestPaymentResponse.Identifier;
            paymentEntry.BankStatus     = requestPaymentResponse.Status;

            //TODO: Replace with partial update
            var updateRes = await _paymentsDataAcces.AddPayment(paymentEntry);


            if (initialDataAccessRes.Success &&
                requestPaymentResponse.HttpStatus == System.Net.HttpStatusCode.OK &&
                updateRes.Success)
            {
                res.Success = true;
            }
            else
            {
                res.Message = $"Error processing payments."; //might be a throw
            }
            return(res);
        }
Пример #7
0
        public void DeletePayment(PaymentEntry payment)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.GetCnnString("WorkTimeSheet")))
            {
                var parameters = new DynamicParameters();
                parameters.Add("@ID", payment.ID);

                connection.Execute("dbo.spPay_DeletePayment", parameters, commandType: CommandType.StoredProcedure);
            }
        }
Пример #8
0
        public void UpdatePaymentActualPay(PaymentEntry payment)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.GetCnnString("WorkTimeSheet")))
            {
                var p = new DynamicParameters();
                p.Add("@ID", payment.ID);
                p.Add("@ActualPay", payment.ActualPay);

                connection.Execute("dbo.spPay_UpdateActualPay", p, commandType: CommandType.StoredProcedure);
            }
        }
Пример #9
0
        public void AddPayHoursLink(PaymentEntry payment, TimeSheetEntry hours)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.GetCnnString("WorkTimeSheet")))
            {
                var parameters = new DynamicParameters();
                parameters.Add("@PayID", payment.ID);
                parameters.Add("@HoursID", hours.ID);

                connection.Execute("dbo.spPayHoursLink_AddLink", parameters, commandType: CommandType.StoredProcedure);
            }
        }
Пример #10
0
        private void PayListViewBox_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            HighlightLinkedHours();

            if (IsPaymentSelected() == true)
            {
                PaymentEntry selected = (PaymentEntry)PayListViewBox.SelectedItems[0].Tag;

                ActualPayTextBox.Text = selected.ActualPay.ToString();
            }
        }
        public override APPayment CreateJointChecks(List <JointPayeePayment> jointPayeePayments)
        {
            JointPayeePayments.Cache.Clear();
            var jointChecks = GenerateJointChecks();

            InvoiceEntry.Views.Caches.Add(typeof(JointPayeePayment));
            InvoiceEntry.Persist();
            MarkPaymentForLienWaiverGeneration(true);
            PaymentEntry.Persist();
            return(jointChecks.FirstOrDefault());
        }
Пример #12
0
 private void updatePaymentEntry(string paymentEntryName)
 {
     if (client != null)
     {
         // retrieve original entry from database (not to lose any invisible information)
         ERPObject    original = client.GetObject(DocType.PaymentEntry, paymentEntryName);
         PaymentEntry payment  = getPaymentFromForm(new PaymentEntry(original));
         ERPObject    updated  = payment.Object;
         client.UpdateObject(DocType.PaymentEntry, paymentEntryName, updated);
     }
 }
Пример #13
0
        private void insertPayment()
        {
            if (client != null)
            {
                PaymentEntry payment = getPaymentFromForm(null);
                ERPObject    obj     = payment.Object;
                client.InsertObject(obj);

                getPaymentEntryList();
            }
        }
Пример #14
0
        private void AddPaymentButton_Click(object sender, EventArgs e)
        {
            DateTime date = DateTime.Parse(SelectedDateLabel.Text);

            PaymentEntry newEntry = new PaymentEntry();

            newEntry.Date = date;

            GlobalConfig.Connection.AddNewPaymentEntry(newEntry, Employment);

            PopulatePayListView();
        }
Пример #15
0
        public void UpdatePaymentExpectedValues(PaymentEntry payment)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.GetCnnString("WorkTimeSheet")))
            {
                var p = new DynamicParameters();
                p.Add("@ID", payment.ID);//, dbType: DbType.Int32);
                p.Add("@HoursWorked", payment.HoursWorked);
                p.Add("@ExpectedPay", payment.ExpectedPay);

                connection.Execute("dbo.spPay_UpdateExpectedValues", p, commandType: CommandType.StoredProcedure);
            }
        }
 public static MockBankPaymentRequest ConvertToMockPaymentRequest(this PaymentEntry paymentEntry)
 {
     return(new MockBankPaymentRequest()
     {
         Amount = paymentEntry.Amount,
         CardNumber = paymentEntry.CardNumber,
         HolderName = paymentEntry.HolderName,
         Cvv = paymentEntry.Cvv,
         ExpiryMonth = paymentEntry.ExpiryMonth,
         ExpiryYear = paymentEntry.ExpiryYear,
         CurrencyCode = paymentEntry.ToString()
     });
 }
Пример #17
0
        public List <TimeSheetEntry> GetLinkedHours(PaymentEntry payment)
        {
            List <TimeSheetEntry> linkedHours;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.GetCnnString("WorkTimeSheet")))
            {
                DynamicParameters p = new DynamicParameters();
                p.Add("@PayID", payment.ID);

                linkedHours = connection.Query <TimeSheetEntry>("dbo.spPayHoursLink_GetByPayID", p, commandType: CommandType.StoredProcedure).ToList();
            }

            return(linkedHours);
        }
        private void SubmitPayment(string type)
        {
            GuardianInfoDB parentinfo = new GuardianInfoDB();

            if (txt_GuardianID.Text.Length == 6 && parentinfo.GuardianIDExists(txt_GuardianID.Text))
            {
                PaymentEntry paymentEntry = new PaymentEntry(txt_GuardianID.Text, this, type);
                paymentEntry.ShowDialog();
            }
            else
            {
                WPFMessageBox.Show("The Parent ID you entered does not exist in the database.  Please verify it is correct.");
                txt_GuardianID.Focus();
            }
        }
Пример #19
0
        private void btn_MakePayment_Click(object sender, RoutedEventArgs e)
        {
            ParentInfoDB parentinfo = new ParentInfoDB();

            if (txt_ParentID.Text.Length == 6 && parentinfo.GuardianIDExists(txt_ParentID.Text))
            {
                PaymentEntry paymentEntry = new PaymentEntry(txt_ParentID.Text, this);
                paymentEntry.Show();
            }
            else
            {
                MessageBox.Show("The Parent ID you entered does not exist in the database.  Please verify it is correct.");
                txt_ParentID.Focus();
            }
        }
Пример #20
0
        public static void CalculateBalancesAR <TInvoice>(PXGraph graph, PXSelectBase <CurrencyInfo> curyInfoSelect, ARAdjust adj, TInvoice invoice, bool isCalcRGOL, bool DiscOnDiscDate)
            where TInvoice : IInvoice
        {
            Customer currentCustomer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Optional <CABankTran.payeeBAccountID> > > > .Select(graph);

            PaymentEntry.CalcBalances <TInvoice, ARAdjust>(curyInfoSelect, adj.AdjgCuryInfoID, adj.AdjdCuryInfoID, invoice, adj);
            if (DiscOnDiscDate)
            {
                PaymentEntry.CalcDiscount <TInvoice, ARAdjust>(adj.AdjgDocDate, invoice, adj);
            }
            PaymentEntry.WarnDiscount <TInvoice, ARAdjust>(graph, adj.AdjgDocDate, invoice, adj);

            CurrencyInfo pay_info   = curyInfoSelect.Select(adj.AdjgCuryInfoID);
            CurrencyInfo vouch_info = curyInfoSelect.Select(adj.AdjdCuryInfoID);

            if (vouch_info != null && string.Equals(pay_info.CuryID, vouch_info.CuryID) == false)
            {
                adj.AdjdCuryRate = Math.Round((vouch_info.CuryMultDiv == "M" ? (decimal)vouch_info.CuryRate : 1 / (decimal)vouch_info.CuryRate) * (pay_info.CuryMultDiv == "M" ? 1 / (decimal)pay_info.CuryRate : (decimal)pay_info.CuryRate), 8, MidpointRounding.AwayFromZero);
            }
            else
            {
                adj.AdjdCuryRate = 1m;
            }

            if (currentCustomer != null && currentCustomer.SmallBalanceAllow == true && adj.AdjgDocType != ARDocType.Refund && adj.AdjdDocType != ARDocType.CreditMemo)
            {
                decimal      payment_smallbalancelimit;
                CurrencyInfo payment_info = curyInfoSelect.Select(adj.AdjgCuryInfoID);
                PXDBCurrencyAttribute.CuryConvCury(curyInfoSelect.Cache, payment_info, currentCustomer.SmallBalanceLimit ?? 0m, out payment_smallbalancelimit);
                adj.CuryWOBal = payment_smallbalancelimit;
                adj.WOBal     = currentCustomer.SmallBalanceLimit;
            }
            else
            {
                adj.CuryWOBal = 0m;
                adj.WOBal     = 0m;
            }

            PaymentEntry.AdjustBalance <ARAdjust>(curyInfoSelect, adj);
            if (isCalcRGOL && (adj.Voided != true))
            {
                PaymentEntry.CalcRGOL <TInvoice, ARAdjust>(curyInfoSelect, invoice, adj);
                adj.RGOLAmt = (bool)adj.ReverseGainLoss ? -1.0m * adj.RGOLAmt : adj.RGOLAmt;
            }
        }
Пример #21
0
        public PaymentEntry AddNewPaymentEntry(PaymentEntry entry, Employment employment)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.GetCnnString("WorkTimeSheet")))
            {
                var parameters = new DynamicParameters();
                parameters.Add("@Date", entry.Date);
                parameters.Add("@EmpID", employment.ID);
                parameters.Add("@ID", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spPay_AddNewPayment", parameters, commandType: CommandType.StoredProcedure);

                entry.ID = parameters.Get <int>("@ID");
            }

            employment.PaymentEntries.Add(entry);

            return(entry);
        }
Пример #22
0
 public static PaymentDetailsResponse ConvertToPaymentDetails(this PaymentEntry entry)
 {
     return(new PaymentDetailsResponse()
     {
         Amount = entry.Amount,
         Currency = entry.Currency,
         Identifier = entry.Identifier.ToString(),
         Reference = entry.RefText,
         CardDetails = new CardDetails()
         {
             CardNumber = entry.CardNumber.MaskCardNumber(),
             Cvv = entry.Cvv,
             ExpiryMonth = entry.ExpiryMonth,
             ExpiryYear = entry.ExpiryYear,
             HolderName = entry.HolderName
         }
     });
 }
Пример #23
0
        private void UpdateExpectedValues()
        {
            PaymentEntry selectedPayment = (PaymentEntry)PayListViewBox.SelectedItems[0].Tag;

            List <TimeSheetEntry> hoursEntries = GlobalConfig.Connection.GetLinkedHours(selectedPayment);

            double hoursWorked = (from entry in hoursEntries
                                  select entry.HoursWorked).Sum();

            decimal expectedPay = (from entry in hoursEntries
                                   select((decimal)entry.HoursWorked) * (entry.HourlyRate)).Sum();

            selectedPayment.HoursWorked = hoursWorked;
            selectedPayment.ExpectedPay = expectedPay;

            GlobalConfig.Connection.UpdatePaymentExpectedValues(selectedPayment);

            PopulatePayListView();
        }
Пример #24
0
        public static PaymentEntry ConvertToPaymentEntry(Dictionary <string, AttributeValue> attributes)
        {
            PaymentEntry entry = new PaymentEntry();

            entry.Identifier      = Guid.Parse(attributes[nameof(entry.Identifier)].S);
            entry.MerchantId      = attributes[nameof(entry.MerchantId)].S;
            entry.RequestDateTime = DateTime.Parse(attributes[nameof(entry.RequestDateTime)].S);
            entry.HolderName      = attributes[nameof(entry.HolderName)].S;
            entry.CardNumber      = attributes[nameof(entry.CardNumber)].S;
            entry.ExpiryMonth     = int.Parse(attributes[nameof(entry.ExpiryMonth)].N);
            entry.ExpiryYear      = int.Parse(attributes[nameof(entry.ExpiryYear)].N);
            entry.Cvv             = attributes[nameof(entry.Cvv)].S;
            entry.Currency        = (CurrencyCode)Enum.Parse(typeof(CurrencyCode), attributes[nameof(entry.Currency)].N);
            entry.Amount          = Decimal.Parse(attributes[nameof(entry.Amount)].N);
            entry.Status          = (PaymentStatus)Enum.Parse(typeof(PaymentStatus), attributes[nameof(entry.Status)].N);
            entry.RefText         = attributes[nameof(entry.RefText)].S;
            entry.BankIdentifier  = attributes[nameof(entry.BankIdentifier)].S;
            entry.BankStatus      = (PaymentStatus)Enum.Parse(typeof(PaymentStatus), attributes[nameof(entry.BankStatus)].N);
            return(entry);
        }
Пример #25
0
        public static Document ConvertToDynamoDocument(this PaymentEntry entry)
        {
            Document doc = new Document();

            doc[nameof(entry.Identifier)]      = entry.Identifier;
            doc[nameof(entry.MerchantId)]      = entry.MerchantId;
            doc[nameof(entry.RequestDateTime)] = entry.RequestDateTime;
            doc[nameof(entry.HolderName)]      = entry.HolderName;
            doc[nameof(entry.CardNumber)]      = entry.CardNumber;
            doc[nameof(entry.ExpiryMonth)]     = entry.ExpiryMonth;
            doc[nameof(entry.ExpiryYear)]      = entry.ExpiryYear;
            doc[nameof(entry.Cvv)]             = entry.Cvv;
            doc[nameof(entry.Currency)]        = (int)entry.Currency;
            doc[nameof(entry.Amount)]          = entry.Amount;
            doc[nameof(entry.Status)]          = (int)entry.Status;
            doc[nameof(entry.RefText)]         = entry.RefText;
            doc[nameof(entry.BankIdentifier)]  = entry.BankIdentifier;
            doc[nameof(entry.BankStatus)]      = (int)entry.BankStatus;
            return(doc);
        }
Пример #26
0
        private void UpdatePayColourCoding()
        {
            foreach (ListViewItem item in PayListViewBox.Items)
            {
                PaymentEntry payItem = (PaymentEntry)item.Tag;

                if (payItem.ActualPay == 0)
                {
                    continue;
                }
                else if (payItem.ActualPay < payItem.ExpectedPay)
                {
                    item.BackColor = Color.OrangeRed;
                }
                else if (payItem.ActualPay >= payItem.ExpectedPay)
                {
                    item.BackColor = Color.LightGreen;
                }
            }
        }
Пример #27
0
        private void DeletePaymentButton_Click(object sender, EventArgs e)
        {
            if (IsPaymentSelected() == false)
            {
                return;
            }

            PaymentEntry selected = (PaymentEntry)PayListViewBox.SelectedItems[0].Tag;

            List <TimeSheetEntry> links = GlobalConfig.Connection.GetLinkedHours(selected);

            if (links.Count != 0)
            {
                MessageBox.Show("Please unlink hours before deleting");
                return;
            }

            GlobalConfig.Connection.DeletePayment(selected);

            Employment.PaymentEntries.Remove(selected);
            PopulatePayListView();
        }
Пример #28
0
        private PaymentEntry getPaymentFromForm(PaymentEntry original)
        {
            PaymentTypes type = PaymentTypes.Receive;

            switch (cmbPaymentType.SelectedItem.ToString())
            {
            case "Receive": type = PaymentTypes.Receive; break;

            case "Pay": type = PaymentTypes.Pay; break;

            default: type = PaymentTypes.InternalTransfer; break;
            }
            string paidFrom  = cmbPaymentFromAccount.SelectedItem.ToString();
            string paidTo    = cmbPaymentToAccount.SelectedItem.ToString();
            string partyType = cmbPaymentPartyType.SelectedItem.ToString();
            string party     = cmbPaymentCustomer.SelectedItem.ToString();

            if (original == null)
            {
                original = new PaymentEntry(datePaymentDate.Value,
                                            type, "OmniPro", paidFrom, paidTo, "CHF",
                                            Convert.ToDouble(numPaymentAmount.Value),
                                            "Customer", party, txtPaymentReference.Text);
            }
            else
            {
                original.PostingDate     = datePaymentDate.Value;
                original.ReferenceDate   = datePaymentDate.Value;
                original.PaymentType     = type;
                original.AccountPaidFrom = paidFrom;
                original.AccountPaidTo   = paidTo;
                original.PaidAmount      = Convert.ToDouble(numPaymentAmount.Value);
                original.ReceivedAmount  = Convert.ToDouble(numPaymentAmount.Value);
                original.Party           = party;
                original.ReferenceNo     = txtPaymentReference.Text;
                original.DocStatus       = Functions.DocStatusFromString(cmbPaymentEntryStatus.SelectedItem.ToString());
            }
            return(original);
        }
Пример #29
0
        private void SetActualPayButton_Click(object sender, EventArgs e)
        {
            if (IsPaymentSelected() == false)
            {
                return;
            }

            bool validActualPay = decimal.TryParse(ActualPayTextBox.Text, out decimal actualPay);

            if (validActualPay == false)
            {
                MessageBox.Show("Invalid pay entered");
                return;
            }

            PaymentEntry selected = (PaymentEntry)PayListViewBox.SelectedItems[0].Tag;

            selected.ActualPay = actualPay;

            GlobalConfig.Connection.UpdatePaymentActualPay(selected);

            PopulatePayListView();
        }
Пример #30
0
        public virtual IEnumerable documents()
        {
            PendingInvoiceFilter filter = Filter.Current;
            Dictionary <CashAcctKey, PendingPaymentSummary> result = new Dictionary <CashAcctKey, PendingPaymentSummary>();

            if (filter == null && !filter.PayDate.HasValue)
            {
                return(result.Values);
            }
            PXSelectBase <APInvoice> sel = new PXSelectJoin <APInvoice,
                                                             InnerJoin <CashAccount, On <CashAccount.cashAccountID, Equal <APInvoice.payAccountID> >,
                                                                        LeftJoin <APAdjust, On <APInvoice.docType, Equal <APAdjust.adjdDocType>,
                                                                                                And <APInvoice.refNbr, Equal <APAdjust.adjdRefNbr>, And <APAdjust.released, Equal <BitOff> > > > > >,
                                                             Where <APInvoice.paySel, Equal <BitOn>,
                                                                    And2 <Where <APInvoice.released, Equal <True>, Or <APInvoice.prebooked, Equal <True> > >,
                                                                          And <APInvoice.openDoc, Equal <BitOn> > > >,
                                                             OrderBy <
                                                                 Asc <APInvoice.docType,
                                                                      Asc <APInvoice.refNbr> > >
                                                             >(this);

            /*if(filter.CuryID != null)
             * {
             *      sel.WhereAnd<Where<APInvoice.curyID, Equal<Current<PendingInvoiceFilter.curyID>>>>();
             * }*/
            if (filter.PayDate != null)
            {
                sel.WhereAnd <Where <APInvoice.payDate, LessEqual <Current <PendingInvoiceFilter.payDate> > > >();
            }

            if (filter.PayAccountID != null)
            {
                sel.WhereAnd <Where <APInvoice.payAccountID, Equal <Current <PendingInvoiceFilter.payAccountID> > > >();
            }

            if (filter.PayTypeID != null)
            {
                sel.WhereAnd <Where <APInvoice.payTypeID, Equal <Current <PendingInvoiceFilter.payTypeID> > > >();
            }

            APInvoiceKey lastInvoice = null;

            foreach (PXResult <APInvoice, CashAccount, APAdjust> it in sel.Select())
            {
                APInvoice   inv    = (APInvoice)it;
                CashAccount acct   = (CashAccount)it;
                APAdjust    adjust = (APAdjust)it;
                if (adjust.AdjdDocType != null)
                {
                    continue;                                     //Skip invoices, having unreleased payments
                }
                APInvoiceKey invNbr = new APInvoiceKey(inv.DocType, inv.RefNbr);
                if (lastInvoice != null && lastInvoice.CompareTo(invNbr) == 0)
                {
                    continue;                     //Skip multiple entries for invoice
                }
                //inv.DocCount = it.RowCount;
                lastInvoice = invNbr;
                CashAcctKey           key = new CashAcctKey(inv.PayAccountID.Value, inv.PayTypeID);
                PendingPaymentSummary res = null;
                if (!result.ContainsKey(key))
                {
                    res = new PendingPaymentSummary();
                    res.PayAccountID = inv.PayAccountID;
                    res.PayTypeID    = inv.PayTypeID;
                    res.CuryID       = acct.CuryID;
                    result[key]      = res;
                    //Assign new CyrrencyInfo - to do conersion correctly. RateTypeID must be taken from the Cash Account
                    CurrencyInfo new_info = new CurrencyInfo();
                    new_info.CuryID         = res.CuryID;
                    new_info.CuryRateTypeID = acct.CuryRateTypeID;
                    new_info.CuryEffDate    = filter.PayDate;
                    new_info       = this.CurrencyInfo_CuryInfoID.Insert(new_info);
                    res.CuryInfoID = new_info.CuryInfoID;
                }
                else
                {
                    res = result[key];
                }

                APAdjust adj = new APAdjust();
                adj.VendorID    = inv.VendorID;
                adj.AdjdDocType = inv.DocType;
                adj.AdjdRefNbr  = inv.RefNbr;
                adj.AdjgDocType = APDocType.Check;
                adj.AdjgRefNbr  = " <NEW>";
                try
                {
                    PaymentEntry.CalcBalances <APInvoice, APAdjust>(this.CurrencyInfo_CuryInfoID, res.CuryInfoID, filter.PayDate, inv, adj);
                }
                catch (PXRateIsNotDefinedForThisDateException ex)
                {
                    Documents.Cache.RaiseExceptionHandling <PendingPaymentSummary.curyID>(res, res.CuryID, new PXSetPropertyException(ex.Message, PXErrorLevel.RowError));
                }
                Aggregate(res, new PXResult <APAdjust, APInvoice> (adj, inv), filter.PayDate);
            }
            return(result.Values);
        }