Esempio n. 1
0
        private TVerificationResultCollection PostAPDocument(AccountsPayableTDS AMainDS, DateTime APostingDate,
                                                             ref List <int> ADocumentIds, bool AReversal = false)
        {
            string AssertFailMessage = AReversal ? "Failed to post AP document reversal: " : "Problems posting AP document: ";
            TVerificationResultCollection VerificationResult;

            if (!AReversal)
            {
                ADocumentIds.Add(AMainDS.AApDocument[0].ApDocumentId);
            }

            Int32 glBatchNumber;

            if (!TAPTransactionWebConnector.PostAPDocuments(FLedgerNumber,
                                                            ADocumentIds,
                                                            APostingDate,
                                                            AReversal,
                                                            out glBatchNumber,
                                                            out VerificationResult))
            {
                Assert.Fail(AssertFailMessage +
                            VerificationResult.BuildVerificationResultString());
            }

            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage);   // Guard Assert

            return(VerificationResult);
        }
        /// <summary>
        /// post and pay all invoices in the given period, but leave some (or none) unposted
        /// </summary>
        public static bool PostAndPayInvoices(int AYear, int APeriod, int ALeaveInvoicesUnposted = 0)
        {
            TLogging.LogAtLevel(1, "PostAndPayInvoices for year " + AYear.ToString() + " / period " + APeriod.ToString());

            AccountsPayableTDS MainDS = new AccountsPayableTDS();

            string sqlLoadDocuments =
                "SELECT * FROM PUB_a_ap_document WHERE a_ledger_number_i = ? AND a_date_issued_d >= ? AND a_date_issued_d <= ? AND a_document_status_c='APPROVED'";

            DateTime PeriodStartDate, PeriodEndDate;

            TFinancialYear.GetStartAndEndDateOfPeriod(FLedgerNumber, APeriod, out PeriodStartDate, out PeriodEndDate, null);

            List <OdbcParameter> parameters = new List <OdbcParameter>();

            OdbcParameter parameter;

            parameter       = new OdbcParameter("ledgernumber", OdbcType.Int);
            parameter.Value = FLedgerNumber;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("startDate", OdbcType.DateTime);
            parameter.Value = PeriodStartDate;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("endDate", OdbcType.DateTime);
            parameter.Value = PeriodEndDate;
            parameters.Add(parameter);

            DBAccess.GDBAccessObj.SelectDT(MainDS.AApDocument, sqlLoadDocuments, null, parameters.ToArray(), -1, -1);

            int countUnPosted = MainDS.AApDocument.Count;

            List <int> DocumentIdsToPost = new List <int>();

            foreach (AApDocumentRow invoice in MainDS.AApDocument.Rows)
            {
                if (countUnPosted <= ALeaveInvoicesUnposted)
                {
                    break;
                }

                DocumentIdsToPost.Add(invoice.ApDocumentId);

                countUnPosted--;
            }

            TVerificationResultCollection VerificationResult;

            if ((DocumentIdsToPost.Count > 0) &&
                !TAPTransactionWebConnector.PostAPDocuments(FLedgerNumber, DocumentIdsToPost, PeriodEndDate, false, out VerificationResult))
            {
                TLogging.Log(VerificationResult.BuildVerificationResultString());
                return(false);
            }

            // TODO pay the invoices as well

            return(true);
        }