protected static void Clear(ARStatement aDest) { aDest.AgeBalance00 = aDest.AgeBalance01 = aDest.AgeBalance02 = aDest.AgeBalance03 = aDest.AgeBalance04 = Decimal.Zero; aDest.CuryAgeBalance00 = aDest.CuryAgeBalance01 = aDest.CuryAgeBalance02 = aDest.CuryAgeBalance03 = aDest.CuryAgeBalance04 = Decimal.Zero; aDest.BegBalance = aDest.EndBalance = Decimal.Zero; aDest.CuryBegBalance = aDest.CuryEndBalance = Decimal.Zero; }
protected static void Copy(ARStatement aDest, Customer aSrc) { aDest.StatementType = aSrc.StatementType; aDest.StatementCycleId = aSrc.StatementCycleId; aDest.DontPrint = aSrc.PrintStatements != true; aDest.DontEmail = aSrc.SendStatementByEmail != true; }
protected static void Copy(ARStatementDetail aDest, ARStatement aSrc) { aDest.CustomerID = aSrc.CustomerID; aDest.CuryID = aSrc.CuryID; aDest.StatementDate = aSrc.StatementDate; //BranchID is copied earlier - from the document to both StatementHeader and details }
protected static void Accumulate(ARStatement aDest, ARRegister aSrc1, ARStatementCycle aSrc2, bool isNewDoc, bool aAgeCredits) { ARInvoice inv = aSrc1 as ARInvoice; Copy(aDest, aSrc2); if (isNewDoc) { aDest.EndBalance = (aDest.EndBalance ?? Decimal.Zero) + ((aSrc1.Payable ?? false) ? aSrc1.OrigDocAmt : (-aSrc1.OrigDocAmt)); aDest.CuryEndBalance = (aDest.CuryEndBalance ?? Decimal.Zero) + ((aSrc1.Payable ?? false) ? aSrc1.CuryOrigDocAmt : (-aSrc1.CuryOrigDocAmt)); } //ARDocType.SmallCreditWO - is an invoice, but it must be processed as payment int days = 0; if (inv != null && inv.DocType != ARDocType.SmallCreditWO) { TimeSpan diff = (aDest.StatementDate.Value.Subtract(inv.DueDate.Value)); days = diff.Days; } else { TimeSpan diff = (aDest.StatementDate.Value.Subtract(aSrc1.DocDate.Value)); days = diff.Days; } if ((inv != null && inv.DocType != ARDocType.SmallCreditWO) || aAgeCredits) { Decimal docBal = ((bool)aSrc1.Paying) ? -aSrc1.DocBal.Value : aSrc1.DocBal.Value; Decimal curyDocBal = ((bool)aSrc1.Paying) ? -aSrc1.CuryDocBal.Value : aSrc1.CuryDocBal.Value; if (days <= 0) { aDest.AgeBalance00 = (aDest.AgeBalance00 ?? Decimal.Zero) + docBal; aDest.CuryAgeBalance00 = (aDest.CuryAgeBalance00 ?? Decimal.Zero) + curyDocBal; } else if (!aSrc2.AgeDays00.HasValue || days <= aSrc2.AgeDays00) { aDest.AgeBalance01 = (aDest.AgeBalance01 ?? Decimal.Zero) + docBal; aDest.CuryAgeBalance01 = (aDest.CuryAgeBalance01 ?? Decimal.Zero) + curyDocBal; } else if (!aSrc2.AgeDays01.HasValue || days <= aSrc2.AgeDays01) { aDest.AgeBalance02 = (aDest.AgeBalance02 ?? Decimal.Zero) + docBal; aDest.CuryAgeBalance02 = (aDest.CuryAgeBalance02 ?? Decimal.Zero) + curyDocBal; } else if (!aSrc2.AgeDays02.HasValue || days <= aSrc2.AgeDays02) { aDest.AgeBalance03 = (aDest.AgeBalance03 ?? Decimal.Zero) + docBal; aDest.CuryAgeBalance03 = (aDest.CuryAgeBalance03 ?? Decimal.Zero) + curyDocBal; } else { aDest.AgeBalance04 = (aDest.AgeBalance04 ?? Decimal.Zero) + docBal; aDest.CuryAgeBalance04 = (aDest.CuryAgeBalance04 ?? Decimal.Zero) + curyDocBal; } } else { //Payments, when credits are not aged aDest.AgeBalance04 = aDest.AgeBalance04 - aSrc1.DocBal; //After completion we must apply resedual payments to previous buckets aDest.CuryAgeBalance04 = aDest.CuryAgeBalance04 - aSrc1.CuryDocBal; } }
protected static void Recalculate(ARStatement aDest) { if (aDest.StatementType == StatementTypes.CS_BALANCE_BROUGHT_FORWARD) { aDest.CuryEndBalance += aDest.CuryBegBalance; aDest.EndBalance += aDest.BegBalance; } }
protected static void Copy(ARStatement aDest, ARStatementCycle aSrc) { aDest.StatementCycleId = aSrc.StatementCycleId; aDest.AgeDays00 = 0; aDest.AgeDays01 = aSrc.AgeDays00; aDest.AgeDays02 = aSrc.AgeDays01; aDest.AgeDays03 = aSrc.AgeDays02; }
protected static void AccumulateAgeBalances(ARStatement statement, ARRegister document, bool ageCredits) { ARInvoice inv = document as ARInvoice; //ARDocType.SmallCreditWO - is an invoice, but it must be processed as payment int days = 0; if (inv != null && inv.DocType != ARDocType.SmallCreditWO) { TimeSpan diff = (statement.StatementDate.Value.Subtract(inv.DueDate.Value)); days = diff.Days; } else { TimeSpan diff = (statement.StatementDate.Value.Subtract(document.DocDate.Value)); days = diff.Days; } if ((inv != null && inv.DocType != ARDocType.SmallCreditWO) || ageCredits) { Decimal docBal = ((bool)document.Paying) ? -document.DocBal.Value : document.DocBal.Value; Decimal curyDocBal = ((bool)document.Paying) ? -document.CuryDocBal.Value : document.CuryDocBal.Value; if (days <= 0) { statement.AgeBalance00 = (statement.AgeBalance00 ?? Decimal.Zero) + docBal; statement.CuryAgeBalance00 = (statement.CuryAgeBalance00 ?? Decimal.Zero) + curyDocBal; } else if (!statement.AgeDays00.HasValue || days <= statement.AgeDays01) { statement.AgeBalance01 = (statement.AgeBalance01 ?? Decimal.Zero) + docBal; statement.CuryAgeBalance01 = (statement.CuryAgeBalance01 ?? Decimal.Zero) + curyDocBal; } else if (!statement.AgeDays01.HasValue || days <= statement.AgeDays02) { statement.AgeBalance02 = (statement.AgeBalance02 ?? Decimal.Zero) + docBal; statement.CuryAgeBalance02 = (statement.CuryAgeBalance02 ?? Decimal.Zero) + curyDocBal; } else if (!statement.AgeDays02.HasValue || days <= statement.AgeDays03) { statement.AgeBalance03 = (statement.AgeBalance03 ?? Decimal.Zero) + docBal; statement.CuryAgeBalance03 = (statement.CuryAgeBalance03 ?? Decimal.Zero) + curyDocBal; } else { statement.AgeBalance04 = (statement.AgeBalance04 ?? Decimal.Zero) + docBal; statement.CuryAgeBalance04 = (statement.CuryAgeBalance04 ?? Decimal.Zero) + curyDocBal; } } else { //Payments, when credits are not aged statement.AgeBalance04 = statement.AgeBalance04 - document.DocBal; //After completion we must apply resedual payments to previous buckets statement.CuryAgeBalance04 = statement.CuryAgeBalance04 - document.CuryDocBal; } }
public DateTime?FindLastCstmStatementDate(int?aCustomer, DateTime?aBeforeDate) { PXSelectBase <ARStatement> sel = new PXSelect <ARStatement, Where <ARStatement.customerID, Equal <Required <ARStatement.customerID> >, And <ARStatement.statementDate, Less <Required <ARStatement.statementDate> > > >, OrderBy <Desc <ARStatement.statementDate> > >(this); ARStatement stmt = (ARStatement)sel.View.SelectSingle(aCustomer, aBeforeDate); if (stmt != null) { return(stmt.StatementDate); } return(null); }
public DateTime?FindLastCycleStatementDate(string aCycleID, DateTime aBeforeDate) { PXSelectBase <ARStatement> sel = new PXSelect <ARStatement, Where <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> >, And <ARStatement.statementDate, Less <Required <ARStatement.statementDate> > > >, OrderBy <Desc <ARStatement.statementDate> > >(this); ARStatement stmt = (ARStatement)sel.View.SelectSingle(aCycleID, aBeforeDate); if (stmt != null) { return(stmt.StatementDate); } return(null); }
public virtual void ARStatement_RowDeleted(PXCache cache, PXRowDeletedEventArgs e) { ARStatement row = (ARStatement)e.Row; foreach (Customer iCstm in this.Customer.Select(row.CustomerID)) { if (row.StatementDate == iCstm.StatementLastDate) { iCstm.StatementLastDate = this.FindLastCstmStatementDate(row.CustomerID, row.StatementDate); this.Customer.Update(iCstm); } } }
public virtual void Copy(ARStatement aSrc, Customer cust) { this.CustomerId = cust.BAccountID; this.UseCurrency = cust.PrintCuryStatements; this.StatementBalance = aSrc.EndBalance ?? decimal.Zero; this.AgeBalance00 = aSrc.AgeBalance00 ?? decimal.Zero; this.CuryID = aSrc.CuryID; this.CuryStatementBalance = aSrc.CuryEndBalance ?? decimal.Zero; this.CuryAgeBalance00 = aSrc.CuryAgeBalance00 ?? decimal.Zero; this.DontPrint = aSrc.DontPrint; this.Printed = aSrc.Printed; this.DontEmail = aSrc.DontEmail; this.Emailed = aSrc.Emailed; }
protected virtual IEnumerable details() { ARStatementDetailsParameters header = Filter.Current; List <DetailsResult> result = new List <DetailsResult>(); if (header == null) { return(result); } GL.Company company = PXSelect <GL.Company> .Select(this); foreach (PXResult <ARStatement, Customer> it in PXSelectJoin <ARStatement, InnerJoin <Customer, On <Customer.bAccountID, Equal <ARStatement.statementCustomerID> > >, Where <ARStatement.statementDate, Equal <Required <ARStatement.statementDate> >, And <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> > > >, OrderBy <Asc <ARStatement.statementCustomerID, Asc <ARStatement.curyID> > > > .Select(this, header.StatementDate, header.StatementCycleId)) { DetailsResult res = new DetailsResult(); ARStatement st = (ARStatement)it; Customer cust = (Customer)it; res.Copy(st, cust); if (cust.PrintCuryStatements ?? false) { DetailsResult last = result.Count > 0 ? result[result.Count - 1] : null; if (last != null && last.CustomerId == res.CustomerId && last.CuryID == res.CuryID) { last.Append(res); } else { result.Add(res); } } else { res.ResetToBaseCury(company.BaseCuryID); DetailsResult last = result.Count > 0 ? result[result.Count - 1] : null; if (last != null && last.CustomerId == res.CustomerId) { last.Append(res); } else { result.Add(res); } } } return(result); }
public virtual void Copy(ARStatement aSrc, Customer cust) { this.StatementCycleId = aSrc.StatementCycleId; this.StatementDate = aSrc.StatementDate; this.StatementBalance = aSrc.EndBalance ?? decimal.Zero; this.AgeBalance00 = aSrc.AgeBalance00 ?? decimal.Zero; this.CuryID = aSrc.CuryID; this.CuryStatementBalance = aSrc.CuryEndBalance ?? decimal.Zero; this.CuryAgeBalance00 = aSrc.CuryAgeBalance00 ?? decimal.Zero; this.DontPrint = aSrc.DontPrint; this.Printed = aSrc.Printed; this.DontEmail = aSrc.DontEmail; this.Emailed = aSrc.Emailed; this.BranchID = aSrc.BranchID; }
protected virtual ARStatement AddARStatement(Dictionary <StatementKey, ARStatement> statements, StatementKey key, ARStatementCycle cycle, Customer customer, DateTime statementDate) { ARStatement statement; if (!statements.TryGetValue(key, out statement)) { statement = new ARStatement(); Clear(statement); Copy(statement, customer); Copy(statement, cycle); Copy(statement, key); statement.StatementDate = statementDate; statements[key] = statement; } return(statement); }
public virtual IEnumerable NextStatementDate(PXAdapter adapter) { PrintParameters filter = this.Filter.Current; if (filter != null && !string.IsNullOrEmpty(filter.StatementCycleId)) { ARStatement statement = PXSelect <ARStatement, Where <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> >, And < Where <ARStatement.statementDate, Greater <Required <ARStatement.statementDate> >, Or <Required <ARStatement.statementDate>, IsNull> > > >, OrderBy <Asc <ARStatement.statementDate> > > .Select(this, filter.StatementCycleId, filter.StatementDate, filter.StatementDate); if (statement != null) { filter.StatementDate = statement.StatementDate; } } Details.Cache.Clear(); return(adapter.Get()); }
protected static ARStatement StatementTrace(ARStatement statement) { var trace = new ARStatement { BranchID = statement.BranchID, CuryID = statement.CuryID, CustomerID = statement.CustomerID, StatementDate = statement.StatementDate, PrevPrintedCnt = statement.PrevPrintedCnt, PrevEmailedCnt = statement.PrevEmailedCnt }; if (statement.Printed == true) { trace.PrevPrintedCnt++; } if (statement.Emailed == true) { trace.PrevEmailedCnt++; } return(trace); }
protected static void ApplyFIFORule(ARStatement aDest, bool aAgeCredits) { //Apply Extra payment in the correct sequence - first to oldest, then - to closer debts //We assume, that allpayments are already applyed to oldest -this function propagates them up. if (!aAgeCredits) { if (aDest.AgeBalance04 < 0) //|| (aDest.AgeDays03 == null)) //Extra payments { aDest.AgeBalance03 += aDest.AgeBalance04; aDest.AgeBalance04 = Decimal.Zero; aDest.CuryAgeBalance03 += aDest.CuryAgeBalance04; aDest.CuryAgeBalance04 = Decimal.Zero; } if (aDest.AgeBalance03 < 0) //|| (aDest.AgeDays02 == null)) { aDest.AgeBalance02 += aDest.AgeBalance03; aDest.AgeBalance03 = Decimal.Zero; aDest.CuryAgeBalance02 += aDest.CuryAgeBalance03; aDest.CuryAgeBalance03 = Decimal.Zero; } if (aDest.AgeBalance02 < 0) //|| (aDest.AgeDays01 == null)) { aDest.AgeBalance01 += aDest.AgeBalance02; aDest.AgeBalance02 = Decimal.Zero; aDest.CuryAgeBalance01 += aDest.CuryAgeBalance02; aDest.CuryAgeBalance02 = Decimal.Zero; } if (aDest.AgeBalance01 < 0) { aDest.AgeBalance00 += aDest.AgeBalance01; aDest.AgeBalance01 = Decimal.Zero; aDest.CuryAgeBalance00 += aDest.CuryAgeBalance01; aDest.CuryAgeBalance01 = Decimal.Zero; } } }
protected virtual void GenerateCustomerStatement(ARStatementCycle aCycle, Customer customer, DateTime aStatementDate, Dictionary <Tuple <int, string, int, DateTime>, ARStatement> statementsTrace) { PXSelectBase <Customer> selectCustomer = new PXSelect <Customer, Where <Customer.statementCycleId, Equal <Required <Customer.statementCycleId> > > >(this); PXSelectBase <ARRegister> selectOpenDocs = new PXSelectJoin <ARRegister, LeftJoin <ARInvoice, On <ARInvoice.docType, Equal <ARRegister.docType>, And <ARInvoice.refNbr, Equal <ARRegister.refNbr> > > >, Where <ARRegister.customerID, Equal <Required <ARRegister.customerID> >, And <ARRegister.released, Equal <BQLConstants.BitOn>, And <ARRegister.docDate, LessEqual <Required <ARRegister.docDate> >, And <Where <ARRegister.openDoc, Equal <BQLConstants.BitOn>, Or <ARRegister.statementDate, IsNull> > > > > > >(this); PXSelectBase <ARStatementDetail> selectDocsStmDetail = new PXSelect <ARStatementDetail, Where <ARStatementDetail.customerID, Equal <Required <ARStatementDetail.customerID> >, And <ARStatementDetail.docType, Equal <Required <ARStatementDetail.docType> >, And <ARStatementDetail.refNbr, Equal <Required <ARStatementDetail.refNbr> > > > >, OrderBy <Asc <ARStatementDetail.statementDate> > >(this); PXSelectBase <ARStatement> selectAllPreviousByCustomer = new PXSelect <ARStatement, Where <ARStatement.customerID, Equal <Required <ARStatement.customerID> > >, OrderBy <Asc <ARStatement.curyID, Desc <ARStatement.statementDate> > > >(this); PXSelectBase <ARStatement> selectPreviousStatement = new PXSelect <ARStatement, Where <ARStatement.branchID, Equal <Required <ARStatement.branchID> >, And <ARStatement.customerID, Equal <Required <ARStatement.customerID> >, And <ARStatement.curyID, Equal <Required <ARStatement.curyID> > > > >, OrderBy <Desc <ARStatement.statementDate> > >(this); bool ageCredits = (this.ARSetup.Current.AgeCredits ?? false); Dictionary <StatementKey, ARStatement> statements = new Dictionary <StatementKey, ARStatement>(); List <ARStatementDetail> details = new List <ARStatementDetail>(); foreach (PXResult <ARRegister, ARInvoice> iDoc in selectOpenDocs.Select(customer.BAccountID, aStatementDate)) { ARStatement header = null; ARRegister doc = (ARRegister)iDoc; ARInvoice inv = (ARInvoice)iDoc; ARStatementDetail statementDetail = (ARStatementDetail)selectDocsStmDetail.Select(doc.CustomerID, doc.DocType, doc.RefNbr); bool isNewDoc = (statementDetail == null); StatementKey key = new StatementKey(doc.BranchID.Value, doc.CuryID); if (IsMultipleInstallmentMaster(inv)) { continue; //Skip invoice, which is the first in multiple installments sequence (master) } if (!statements.ContainsKey(key)) { header = new ARStatement(); Clear(header); Copy(header, customer); Copy(header, aCycle); Copy(header, doc); header.StatementDate = aStatementDate; ARStatement trace = null; bool gotTrace = statementsTrace.TryGetValue(new Tuple <int, string, int, DateTime>(header.BranchID.Value, header.CuryID, header.CustomerID.Value, header.StatementDate.Value), out trace); if (gotTrace) { header.PrevPrintedCnt = trace.PrevPrintedCnt; header.PrevEmailedCnt = trace.PrevEmailedCnt; } statements[key] = header; } else { header = statements[key]; } ARStatementDetail det = new ARStatementDetail(); Copy(det, header); Copy(det, doc); if (doc.DocType != AR.ARDocType.CashSale && doc.DocType != AR.ARDocType.CashReturn) { Accumulate(header, (doc.Payable == true ? inv : doc), aCycle, isNewDoc, ageCredits); } details.Add(det); } //Merge with previous statements - is needed for Balance Brought Forward Dictionary <StatementKey, DateTime> lastCuryStatement = new Dictionary <StatementKey, DateTime>(); foreach (ARStatement iPrev in selectAllPreviousByCustomer.Select(customer.BAccountID)) { ARStatement header = null; StatementKey key = new StatementKey(iPrev.BranchID.Value, iPrev.CuryID); if (lastCuryStatement.ContainsKey(key) && lastCuryStatement[key] > iPrev.StatementDate) { continue; } if (!statements.ContainsKey(key)) { header = new ARStatement(); Clear(header); header.BranchID = iPrev.BranchID; header.CuryID = iPrev.CuryID; header.CustomerID = iPrev.CustomerID; header.StatementDate = aStatementDate; Copy(header, customer); Copy(header, aCycle); statements[key] = header; } else { header = statements[key]; } header.BegBalance = iPrev.EndBalance; header.CuryBegBalance = iPrev.CuryEndBalance; Recalculate(header); lastCuryStatement[key] = iPrev.StatementDate.Value; } foreach (ARStatement iH in statements.Values) { ARStatement prev = selectPreviousStatement.Select(iH.CustomerID, iH.BranchID, iH.CuryID); if (prev != null) { iH.BegBalance = prev.EndBalance; iH.CuryBegBalance = prev.CuryEndBalance; } ApplyFIFORule(iH, ageCredits); } PersistStatement(customer.BAccountID, aStatementDate, statements.Values, details); }
protected virtual void GenerateCustomerStatement(StatementCreateBO statementGraph, ARStatementCycle aCycle, Customer customer, DateTime aStatementDate, Dictionary <Tuple <int, string, int, DateTime>, ARStatement> statementsTrace, IList <PXResult <ARRegister, ARInvoice> > familyDocuments) { PXSelectBase <ARRegister> selectOpenDocs = new PXSelectJoin <ARRegister, LeftJoin <ARInvoice, On <ARInvoice.docType, Equal <ARRegister.docType>, And <ARInvoice.refNbr, Equal <ARRegister.refNbr> > > >, Where <ARRegister.customerID, Equal <Required <ARRegister.customerID> >, And <ARRegister.released, Equal <BQLConstants.BitOn>, And <ARRegister.docDate, LessEqual <Required <ARRegister.docDate> >, And <Where <ARRegister.openDoc, Equal <BQLConstants.BitOn>, Or <ARRegister.statementDate, IsNull> > > > > > >(this); PXSelectBase <ARStatementDetail> selectDocsStmDetail = new PXSelect <ARStatementDetail, Where <ARStatementDetail.customerID, Equal <Required <ARStatementDetail.customerID> >, And <ARStatementDetail.docType, Equal <Required <ARStatementDetail.docType> >, And <ARStatementDetail.refNbr, Equal <Required <ARStatementDetail.refNbr> > > > >, OrderBy <Asc <ARStatementDetail.statementDate> > >(this); PXSelectBase <ARStatement> selectAllPreviousByCustomer = new PXSelect <ARStatement, Where <ARStatement.customerID, Equal <Required <ARStatement.customerID> > >, OrderBy <Asc <ARStatement.curyID, Desc <ARStatement.statementDate> > > >(this); PXSelectBase <ARStatement> selectPreviousStatement = new PXSelect <ARStatement, Where <ARStatement.branchID, Equal <Required <ARStatement.branchID> >, And <ARStatement.customerID, Equal <Required <ARStatement.customerID> >, And <ARStatement.curyID, Equal <Required <ARStatement.curyID> > > > >, OrderBy <Desc <ARStatement.statementDate> > >(this); bool ageCredits = (this.ARSetup.Current.AgeCredits ?? false); bool isParent = customer.StatementCustomerID == customer.BAccountID; Dictionary <StatementKey, ARStatement> statements = new Dictionary <StatementKey, ARStatement>(); if (isParent) { foreach (PXResult <ARRegister, ARInvoice> res in familyDocuments) { ARRegister doc = res; StatementKey key = new StatementKey(doc.BranchID.Value, doc.CuryID); AddARStatement(statements, key, aCycle, customer, aStatementDate); } } List <ARStatementDetail> details = new List <ARStatementDetail>(); foreach (PXResult <ARRegister, ARInvoice> iDoc in selectOpenDocs.Select(customer.BAccountID, aStatementDate)) { ARRegister doc = iDoc; ARInvoice inv = iDoc; ARStatementDetail statementDetail = selectDocsStmDetail.Select(doc.CustomerID, doc.DocType, doc.RefNbr); bool isNewDoc = statementDetail == null; StatementKey key = new StatementKey(doc.BranchID.Value, doc.CuryID); familyDocuments.Add(iDoc); if (IsMultipleInstallmentMaster(inv)) { continue; //Skip invoice, which is the first in multiple installments sequence (master) } ARStatement header = AddARStatement(statements, key, aCycle, customer, aStatementDate); if (header.Processed != true) { ARStatement prevStatement = selectPreviousStatement.Select(header.BranchID, header.CustomerID, header.CuryID); if (prevStatement != null) { header.PrevStatementDate = prevStatement.StatementDate; } ARStatement trace; if (statementsTrace.TryGetValue(new Tuple <int, string, int, DateTime>(header.BranchID.Value, header.CuryID, header.CustomerID.Value, header.StatementDate.Value), out trace)) { header.PrevPrintedCnt = trace.PrevPrintedCnt; header.PrevEmailedCnt = trace.PrevEmailedCnt; } header.Processed = true; } ARStatementDetail det = new ARStatementDetail(); Copy(det, header); Copy(det, doc); if (doc.DocType != AR.ARDocType.CashSale && doc.DocType != AR.ARDocType.CashReturn) { var document = (doc.Payable == true ? inv : doc); if (header.StatementType == StatementTypes.CS_BALANCE_BROUGHT_FORWARD && isNewDoc) { header.EndBalance = (header.EndBalance ?? 0m) + document.SignBalance * document.OrigDocAmt; header.CuryEndBalance = (header.CuryEndBalance ?? 0m) + document.SignBalance * document.CuryOrigDocAmt; } else if (header.StatementType == StatementTypes.CS_OPEN_ITEM) { header.EndBalance = (header.EndBalance ?? 0m) + document.SignBalance * document.DocBal; header.CuryEndBalance = (header.CuryEndBalance ?? 0m) + document.SignBalance * document.CuryDocBal; } } details.Add(det); } if (isParent) { AccumulateAgeBalancesIntoStatements(familyDocuments, statements, ageCredits); } //Merge with previous statements - is needed for Balance Brought Forward Dictionary <StatementKey, DateTime> lastCuryStatement = new Dictionary <StatementKey, DateTime>(); foreach (ARStatement iPrev in selectAllPreviousByCustomer.Select(customer.BAccountID)) { StatementKey key = new StatementKey(iPrev.BranchID.Value, iPrev.CuryID); if (lastCuryStatement.ContainsKey(key) && lastCuryStatement[key] > iPrev.StatementDate) { continue; } ARStatement header = AddARStatement(statements, key, aCycle, customer, aStatementDate); header.BegBalance = iPrev.EndBalance; header.CuryBegBalance = iPrev.CuryEndBalance; Recalculate(header); lastCuryStatement[key] = iPrev.StatementDate.Value; } foreach (ARStatement iH in statements.Values) { ARStatement prev = selectPreviousStatement.Select(iH.CustomerID, iH.BranchID, iH.CuryID); if (prev != null) { iH.BegBalance = prev.EndBalance; iH.CuryBegBalance = prev.CuryEndBalance; } ApplyFIFORule(iH, ageCredits); } PersistStatement(statementGraph, customer.BAccountID, aStatementDate, statements.Values, details); }
protected static void Recalculate(ARStatement aDest) { aDest.CuryEndBalance += aDest.CuryBegBalance; aDest.EndBalance += aDest.BegBalance; }
protected virtual IEnumerable history() { this.History.Cache.Clear(); ARStatementHistoryParameters header = Filter.Current; if (header == null) { yield break; } Dictionary <string, Dictionary <DateTime, int> > result = new Dictionary <string, Dictionary <DateTime, int> >(); Dictionary <string, string> dictARStatementCycle = new Dictionary <string, string>(); int? prevCustomerID = null; string prevCuryID = null; HistoryResult prevRec = null; foreach (PXResult <ARStatement, ARStatementCycle, Customer> item in PXSelectJoin <ARStatement, LeftJoin <ARStatementCycle, On <ARStatementCycle.statementCycleId, Equal <ARStatement.statementCycleId> >, LeftJoin <Customer, On <Customer.bAccountID, Equal <ARStatement.customerID> > > >, Where <ARStatement.statementDate, GreaterEqual <Required <ARStatement.statementDate> >, And <ARStatement.statementDate, LessEqual <Required <ARStatement.statementDate> >, And <Where <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> >, Or <Required <ARStatement.statementCycleId>, IsNull> > > > >, OrderBy <Asc <ARStatement.statementCycleId, Asc <ARStatement.statementDate, Asc <ARStatement.customerID, Asc <ARStatement.curyID> > > > > > .Select(this, header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId)) { ARStatement st = item; Customer cust = item; HistoryResult rec = new HistoryResult(); rec.StatementCycleId = st.StatementCycleId; rec.StatementDate = st.StatementDate; rec.Descr = ((ARStatementCycle)item).Descr; rec.DontPrintCount = 0; rec.DontEmailCount = 0; rec.PrintedCount = 0; rec.EmailedCount = 0; rec.NoActionCount = 0; rec = (HistoryResult)this.History.Cache.Locate(rec) ?? this.History.Insert(rec); if (rec != null) { if (prevRec != rec) { prevCustomerID = null; prevCuryID = null; } if (prevCustomerID != st.CustomerID || (cust.PrintCuryStatements == true && prevCuryID != st.CuryID)) { rec.NumberOfDocuments += 1; rec.DontPrintCount += ((st.DontPrint ?? false) == true) ? 1 : 0; rec.DontEmailCount += ((st.DontEmail ?? false) == true) ? 1 : 0; rec.NoActionCount += ((st.DontEmail ?? false) == true && (st.DontPrint ?? false) == true) ? 1 : 0; rec.PrintedCount += ((st.Printed ?? false) == true) ? 1 : 0; rec.EmailedCount += ((st.Emailed ?? false) == true) ? 1 : 0; } prevRec = rec; prevCustomerID = st.CustomerID; prevCuryID = st.CuryID; } /* * if (result.ContainsKey(((ARStatement)st).StatementCycleId)) * { * if (result[((ARStatement)st).StatementCycleId].ContainsKey(((ARStatement)st).StatementDate ?? DateTime.MinValue)) * { * result[((ARStatement)st).StatementCycleId][((ARStatement)st).StatementDate ?? DateTime.MinValue] = result[((ARStatement)st).StatementCycleId][((ARStatement)st).StatementDate ?? DateTime.MinValue] + 1; * } * else * { * result[((ARStatement)st).StatementCycleId].Add(((ARStatement)st).StatementDate ?? DateTime.MinValue, 1); * } * } * else * { * Dictionary<DateTime, int> dictValue = new Dictionary<DateTime, int>(); * dictValue.Add(((ARStatement)st).StatementDate ?? DateTime.MinValue, 1); * result.Add(((ARStatement)st).StatementCycleId, dictValue); * } * if(dictARStatementCycle.ContainsKey (((ARStatement)st).StatementCycleId) == false) * dictARStatementCycle.Add(((ARStatement)st).StatementCycleId, ((ARStatementCycle)st).Descr); */ } this.History.Cache.IsDirty = false; foreach (HistoryResult ret in this.History.Cache.Inserted) { yield return(ret); } /* * foreach (string statementCycleId in result.Keys) * { * foreach (DateTime statementDate in result[statementCycleId].Keys) * { * HistoryResult res = new HistoryResult(); * res.StatementCycleId = statementCycleId; * res.StatementDate = statementDate; * res.NumberOfDocuments = result[statementCycleId][statementDate]; * res.Descr = dictARStatementCycle[statementCycleId]; * yield return res; * } * } */ }
protected static void Export(Dictionary <string, string> aRes, ARStatement aSrc) { aRes[ARStatementReportParams.Fields.StatementCycleID] = aSrc.StatementCycleId; aRes[ARStatementReportParams.Fields.StatementDate] = aSrc.StatementDate.Value.ToString("d", CultureInfo.InvariantCulture); aRes[ARStatementReportParams.Fields.CustomerID] = aSrc.CustomerID.ToString(); }
protected virtual IEnumerable history() { this.History.Cache.Clear(); ARStatementHistoryParameters header = Filter.Current; if (header == null) { yield break; } int? prevCustomerID = null; string prevCuryID = null; HistoryResult prevRec = null; PXResultset <ARStatement> res; List <object> stored = new List <object>(); PXSelectBase <ARStatement> select = new PXSelectJoin <ARStatement, LeftJoin <ARStatementCycle, On <ARStatementCycle.statementCycleId, Equal <ARStatement.statementCycleId> >, LeftJoin <Customer, On <Customer.bAccountID, Equal <ARStatement.statementCustomerID> > > >, Where <ARStatement.statementCustomerID, Equal <ARStatement.customerID>, And <ARStatement.statementDate, GreaterEqual <Required <ARStatement.statementDate> >, And <ARStatement.statementDate, LessEqual <Required <ARStatement.statementDate> >, And <Where <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> >, Or <Required <ARStatement.statementCycleId>, IsNull> > > > > >, OrderBy <Asc <ARStatement.statementCycleId, Asc <ARStatement.statementDate, Asc <ARStatement.customerID, Asc <ARStatement.curyID> > > > > >(this); using (new PXFieldScope(select.View, typeof(ARStatement.branchID), typeof(ARStatement.statementCycleId), typeof(ARStatement.statementDate), typeof(ARStatement.customerID), typeof(ARStatement.statementCustomerID), typeof(ARStatement.curyID), typeof(ARStatement.dontPrint), typeof(ARStatement.dontEmail), typeof(ARStatement.printed), typeof(ARStatement.emailed), typeof(ARStatementCycle.descr), typeof(Customer.printCuryStatements))) { res = select.Select(header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId); } foreach (PXResult <ARStatement, ARStatementCycle, Customer> item in res) { stored.Add(item); ARStatement st = item; ARStatementCycle cycle = item; Customer cust = item; HistoryResult rec = new HistoryResult { StatementCycleId = st.StatementCycleId, StatementDate = st.StatementDate, Descr = cycle.Descr, DontPrintCount = 0, DontEmailCount = 0, PrintedCount = 0, EmailedCount = 0, NoActionCount = 0 }; rec = (HistoryResult)this.History.Cache.Locate(rec) ?? this.History.Insert(rec); if (rec != null) { if (prevRec != rec) { prevCustomerID = null; prevCuryID = null; } if (prevCustomerID != st.CustomerID || (cust.PrintCuryStatements == true && prevCuryID != st.CuryID)) { rec.NumberOfDocuments += 1; rec.DontPrintCount += st.DontPrint == true ? 1 : 0; rec.DontEmailCount += st.DontEmail == true ? 1 : 0; rec.NoActionCount += st.DontEmail == true && st.DontPrint == true ? 1 : 0; rec.PrintedCount += st.Printed == true ? 1 : 0; rec.EmailedCount += st.Emailed == true ? 1 : 0; } prevRec = rec; prevCustomerID = st.CustomerID; prevCuryID = st.CuryID; } } select.StoreCached(new PXCommandKey(new object[] { header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId }), stored); this.History.Cache.IsDirty = false; foreach (HistoryResult ret in this.History.Cache.Inserted) { yield return(ret); } }
protected virtual IEnumerable details() { ARSetup setup = ARSetup.Current; PrintParameters header = Filter.Current; List <DetailsResult> result = new List <DetailsResult>(); if (header == null) { yield break; } GL.Company company = PXSelect <GL.Company> .Select(this); foreach (PXResult <ARStatement, Customer> it in PXSelectJoin <ARStatement, InnerJoin <Customer, On <Customer.bAccountID, Equal <ARStatement.statementCustomerID> > >, Where <ARStatement.statementDate, Equal <Required <ARStatement.statementDate> >, And <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> > > >, OrderBy <Asc <ARStatement.statementCustomerID, Asc <ARStatement.curyID> > > > .Select(this, header.StatementDate, header.StatementCycleId)) { DetailsResult res = new DetailsResult(); ARStatement st = it; Customer cust = it; res.Copy(st, cust); if (setup.ConsolidatedStatement != true && st.BranchID != header.BranchID) { continue; } if (Filter.Current.Action == 0 && header.ShowAll != true && (st.DontPrint == true || st.Printed == true)) { continue; } if ((Filter.Current.Action == 1 || Filter.Current.Action == 2) && header.ShowAll != true && (st.DontEmail == true || st.Emailed == true)) { continue; } if (cust.PrintCuryStatements == true) { if (Filter.Current.CuryStatements != true) { continue; } DetailsResult last = result.Count > 0 ? result[result.Count - 1] : null; if (last?.CustomerID == res.CustomerID && last?.CuryID == res.CuryID) { last.Append(res); } else { result.Add(res); } } else { if (Filter.Current.CuryStatements == true) { continue; } res.ResetToBaseCury(company.BaseCuryID); DetailsResult last = result.Count > 0 ? result[result.Count - 1] : null; if (last?.CustomerID == res.CustomerID) { last.Append(res); } else { result.Add(res); } } } foreach (var item in result) { var located = Details.Cache.Locate(item); if (located != null) { yield return(located); } else { Details.Cache.SetStatus(item, PXEntryStatus.Held); yield return(item); } } Details.Cache.IsDirty = false; }
protected static void Copy(ARStatement aDest, ARRegister aSrc) { aDest.CustomerID = aSrc.CustomerID; aDest.CuryID = aSrc.CuryID; aDest.BranchID = aSrc.BranchID; }
protected static void Copy(ARStatement aDest, StatementKey key) { aDest.BranchID = key.first; aDest.CuryID = key.second; }