/// <summary> /// Load Invoice Line. /// 4 amounts /// AMTTYPE_Payment /// AMTTYPE_Statement2 /// AMTTYPE_Charge /// AMTTYPE_Interest /// </summary> /// <param name="bs">bank statement</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MBankStatement bs) { List <DocLine> list = new List <DocLine>(); MBankStatementLine[] lines = bs.GetLines(false); for (int i = 0; i < lines.Length; i++) { MBankStatementLine line = lines[i]; DocLine_Bank docLine = new DocLine_Bank(line, this); // Set Date Acct if (i == 0) { SetDateAcct(line.GetDateAcct()); } MPeriod period = MPeriod.Get(GetCtx(), line.GetDateAcct()); if (period != null && period.IsOpen(MDocBaseType.DOCBASETYPE_BANKSTATEMENT)) { docLine.SetC_Period_ID(period.GetC_Period_ID()); } // list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="journal"></param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MJournal journal) { List <DocLine> list = new List <DocLine>(); MJournalLine[] lines = journal.GetLines(false); for (int i = 0; i < lines.Length; i++) { MJournalLine line = lines[i]; DocLine docLine = new DocLine(line, this); // -- Source Amounts docLine.SetAmount(line.GetAmtSourceDr(), line.GetAmtSourceCr()); // -- Converted Amounts docLine.SetConvertedAmt(_C_AcctSchema_ID, line.GetAmtAcctDr(), line.GetAmtAcctCr()); // -- Account MAccount account = line.GetAccount(); docLine.SetAccount(account); // -- Quantity docLine.SetQty(line.GetQty(), false); // -- Date docLine.SetDateAcct(journal.GetDateAcct()); // -- Organization of Line was set to Org of Account list.Add(docLine); } // Return Array int size = list.Count; DocLine[] dls = new DocLine[size]; dls = list.ToArray(); return(dls); }
/// <summary> /// Create and convert Fact Line. /// Used to create a DR and/or CR entry /// </summary> /// <param name="docLine">the document line or null</param> /// <param name="account">if null, line is not created</param> /// <param name="C_Currency_ID">the currency</param> /// <param name="debitAmt">debit amount, can be null</param> /// <param name="creditAmt">credit amount, can be null</param> /// <returns>Fact Line</returns> public FactLine CreateLine(DocLine docLine, MAccount account, int C_Currency_ID, Decimal?debitAmt, Decimal?creditAmt) { // Data Check if (account == null) { log.Info("No account for " + docLine + ": Amt=" + debitAmt + "/" + creditAmt + " - " + ToString()); return(null); } //Added By Bharat to Handle -ve entry if (debitAmt < 0) { creditAmt = Decimal.Negate(debitAmt.Value); debitAmt = 0; } else if (creditAmt < 0) { debitAmt = Decimal.Negate(creditAmt.Value); creditAmt = 0; } // FactLine line = new FactLine(_doc.GetCtx(), _doc.Get_Table_ID(), _doc.Get_ID(), docLine == null ? 0 : docLine.Get_ID(), _trx); // set accounting schema reference line.SetC_AcctSchema_ID(_acctSchema.GetC_AcctSchema_ID()); // Set Info & Account line.SetDocumentInfo(_doc, docLine); line.SetPostingType(_postingType); line.SetAccount(_acctSchema, account); // Amounts - one needs to not zero if (!line.SetAmtSource(C_Currency_ID, debitAmt, creditAmt)) { if (docLine == null || docLine.GetQty() == null || Env.Signum(Utility.Util.GetValueOfDecimal(docLine.GetQty())) == 0) { log.Fine("Both amounts & qty = 0/Null - " + docLine + " - " + ToString()); return(null); } log.Fine("Both amounts = 0/Null, Qty=" + docLine.GetQty() + " - " + docLine + " - " + ToString()); } // Convert line.Convert(); // Optionally overwrite Acct Amount if (docLine != null && (docLine.GetAmtAcctDr() != null || docLine.GetAmtAcctCr() != null)) { line.SetAmtAcct(docLine.GetAmtAcctDr(), docLine.GetAmtAcctCr()); } // log.Fine(line.ToString()); Add(line); return(line); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="inout">shipment/receipt</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MInOut inout) { List <DocLine> list = new List <DocLine>(); MInOutLine[] lines = inout.GetLines(false); for (int i = 0; i < lines.Length; i++) { MInOutLine line = lines[i]; if (line.IsDescription() || line.GetM_Product_ID() == 0 || Env.Signum(line.GetMovementQty()) == 0) { log.Finer("Ignored: " + line); continue; } // PO Matching if (_MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_PurchaseOrder) || _MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_PurchaseOrderAndInvoice)) { Decimal poDiff = line.GetMatchPODifference(); if (Env.Signum(poDiff) != 0) { _matchProblem += "; Line=" + line.GetLine() + " PO Match diff=" + poDiff; } else if (!line.IsMatchPOPosted()) { _matchProblem += "; PO Match not posted for Line=" + line.GetLine(); } } // Inv Matching else if (_MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_Invoice) || _MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_PurchaseOrderAndInvoice)) { Decimal invDiff = line.GetMatchInvDifference(); if (Env.Signum(invDiff) != 0) { _matchProblem += "; Line=" + line.GetLine() + " PO Match diff=" + invDiff; } else if (!line.IsMatchInvPosted()) { _matchProblem += "; Inv Match not posted for Line=" + line.GetLine(); } } DocLine docLine = new DocLine(line, this); Decimal Qty = line.GetMovementQty(); docLine.SetQty(Qty, GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALDELIVERY)); // sets Trx and Storage Qty // log.Fine(docLine.ToString()); list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
/// <summary> /// Create and convert Fact Line. /// Used to create either a DR or CR entry /// </summary> /// <param name="docLine">Document line or null</param> /// <param name="account">Account to be used</param> /// <param name="C_Currency_ID">Currency</param> /// <param name="Amt">if negative Cr else Dr</param> /// <param name ="AD_Org_ID">Set Line Org</param> /// <returns>FactLine</returns> public FactLine CreateLine(DocLine docLine, MAccount account, int C_Currency_ID, Decimal?Amt, int AD_Org_ID) { if (Env.Signum(Amt.Value) < 0) { return(CreateLine(docLine, account, C_Currency_ID, null, Math.Abs(Amt.Value), AD_Org_ID)); } else { return(CreateLine(docLine, account, C_Currency_ID, Amt.Value, null, AD_Org_ID)); } }
/// <summary> /// is used to set User Element Dimension /// </summary> /// <param name="journalLineDimension">journal line dimension object</param> /// <param name="docLine">document line object</param> private DocLine SetUserDimension(X_GL_LineDimension journalLineDimension, DocLine docLine) { if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement1 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement1(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement2 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement2(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement3 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement3(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement4 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement4(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement5 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement5(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement6 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement6(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement7 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement7(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement8 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement8(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType() == MJournalLine.ELEMENTTYPE_UserElement9 && !String.IsNullOrEmpty(journalLineDimension.GetDimensionValue())) { docLine.SetUserElement9(Convert.ToInt32(journalLineDimension.GetDimensionValue())); } else if (journalLineDimension.GetLineType().Equals(MJournalLine.ELEMENTTYPE_OrgTrx) && journalLineDimension.GetOrg_ID() > 0) { docLine.SetAD_OrgTrx_ID(Convert.ToInt32(journalLineDimension.GetOrg_ID())); } else if (journalLineDimension.GetLineType().Equals(MJournalLine.ELEMENTTYPE_Organization) && journalLineDimension.GetOrg_ID() > 0) { docLine.SetAD_Org_ID(Convert.ToInt32(journalLineDimension.GetOrg_ID())); } return(docLine); }
private DocLine[] LoadLines(MCostUpdate costupdate) { List <DocLine> list = new List <DocLine>(); MCostUpdateLine[] lines = costupdate.GetLines(); for (int i = 0; i < lines.Length; i++) { MCostUpdateLine line = lines[i]; DocLine docLine = new DocLine(line, this); list.Add(docLine); } DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }
/// <summary> /// Create and convert Fact Line. /// Used to create a DR and/or CR entry /// </summary> /// <param name="docLine">the document line or null</param> /// <param name="account">if null, line is not created</param> /// <param name="C_Currency_ID">the currency</param> /// <param name="debitAmt">debit amount, can be null</param> /// <param name="creditAmt">credit amount, can be null</param> /// <returns>Fact Line</returns> public FactLine CreateLine(DocLine docLine, MAccount account, int C_Currency_ID, Decimal?debitAmt, Decimal?creditAmt, int AD_Org_ID) { // Data Check if (account == null) { log.Info("No account for " + docLine + ": Amt=" + debitAmt + "/" + creditAmt + " - " + ToString()); return(null); } // FactLine line = new FactLine(_doc.GetCtx(), _doc.Get_Table_ID(), _doc.Get_ID(), docLine == null ? 0 : (docLine.GetPrimaryKeyValue != 0 ? docLine.GetPrimaryKeyValue : docLine.Get_ID()), _trx); // Set Info & Account line.SetDocumentInfo(_doc, docLine); line.SetPostingType(_postingType); line.SetAccount(_acctSchema, account); if (AD_Org_ID > 0) { line.SetAD_Org_ID(AD_Org_ID); } // Amounts - one needs to not zero if (!line.SetAmtSource(C_Currency_ID, debitAmt, creditAmt)) { if (docLine == null || docLine.GetQty() == null || Env.Signum(Utility.Util.GetValueOfDecimal(docLine.GetQty())) == 0) { log.Fine("Both amounts & qty = 0/Null - " + docLine + " - " + ToString()); return(null); } log.Fine("Both amounts = 0/Null, Qty=" + docLine.GetQty() + " - " + docLine + " - " + ToString()); } // Convert line.Convert(); // Optionally overwrite Acct Amount if (docLine != null && (docLine.GetAmtAcctDr() != null || docLine.GetAmtAcctCr() != null)) { line.SetAmtAcct(docLine.GetAmtAcctDr(), docLine.GetAmtAcctCr()); } // log.Fine(line.ToString()); Add(line); return(line); }
/// <summary> /// Load Cash Line /// </summary> /// <param name="cash">journal</param> /// <param name="cb">cash book</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MCash cash, MCashBook cb) { List <DocLine> list = new List <DocLine>(); MCashLine[] lines = cash.GetLines(false); for (int i = 0; i < lines.Length; i++) { MCashLine line = lines[i]; DocLine_Cash docLine = new DocLine_Cash(line, this); // list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
/// <summary> /// Load Document Details /// </summary> /// <returns>error message or null</returns> public override String LoadDocumentDetails() { SetC_Currency_ID(NO_CURRENCY); _issue = (MProjectIssue)GetPO(); SetDateDoc(_issue.GetMovementDate()); SetDateAcct(_issue.GetMovementDate()); // Pseudo Line _line = new DocLine(_issue, this); _line.SetQty(_issue.GetMovementQty(), true); // sets Trx and Storage Qty // Pseudo Line Check if (_line.GetM_Product_ID() == 0) { log.Warning(_line.ToString() + " - No Product"); } log.Fine(_line.ToString()); return(null); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="move"></param> /// <returns>document lines (DocLine_Material)</returns> private DocLine[] LoadLines(MMovement move) { List <DocLine> list = new List <DocLine>(); MMovementLine[] lines = move.GetLines(false); for (int i = 0; i < lines.Length; i++) { MMovementLine line = lines[i]; DocLine docLine = new DocLine(line, this); docLine.SetQty(line.GetMovementQty(), false); // log.Fine(docLine.ToString()); list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
/// <summary> /// Get Commitment Release. /// Called from MatchInv for accrual and Allocation for Cash Based /// </summary> /// <param name="as1">accounting schema</param> /// <param name="doc">doc</param> /// <param name="Qty">qty invoiced/matched</param> /// <param name="C_InvoiceLine_ID">line</param> /// <param name="multiplier">1 for accrual</param> /// <returns>Fact</returns> public static Fact GetCommitmentRelease(MAcctSchema as1, Doc doc, Decimal Qty, int C_InvoiceLine_ID, Decimal multiplier) { Fact fact = new Fact(doc, as1, Fact.POST_Commitment); DocLine[] commitments = Doc_Order.GetCommitments(doc, Qty, C_InvoiceLine_ID); Decimal total = Env.ZERO; int C_Currency_ID = -1; for (int i = 0; i < commitments.Length; i++) { DocLine line = commitments[i]; if (C_Currency_ID == -1) { C_Currency_ID = line.GetC_Currency_ID(); } else if (C_Currency_ID != line.GetC_Currency_ID()) { doc._error = "Different Currencies of Order Lines"; _log.Log(Level.SEVERE, doc._error); return(null); } Decimal cost = Decimal.Multiply(line.GetAmtSource(), multiplier); total = Decimal.Add(total, cost); // Account MAccount expense = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); fact.CreateLine(line, expense, C_Currency_ID, null, cost); } // Offset MAccount offset = doc.GetAccount(ACCTTYPE_CommitmentOffset, as1); if (offset == null) { doc._error = "@NotFound@ @CommitmentOffset_Acct@"; _log.Log(Level.SEVERE, doc._error); return(null); } fact.CreateLine(null, offset, C_Currency_ID, total, null); return(fact); }
/// <summary> /// Load Requisition Lines /// </summary> /// <param name="req">requisition</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MRequisition req) { List <DocLine> list = new List <DocLine>(); MRequisitionLine[] lines = req.GetLines(); for (int i = 0; i < lines.Length; i++) { MRequisitionLine line = lines[i]; DocLine docLine = new DocLine(line, this); Decimal Qty = line.GetQty(); docLine.SetQty(Qty, false); // Decimal PriceActual = line.GetPriceActual(); Decimal LineNetAmt = line.GetLineNetAmt(); docLine.SetAmount(LineNetAmt); // DR list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="inventory"></param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MInventory inventory) { List <DocLine> list = new List <DocLine>(); MInventoryLine[] lines = inventory.GetLines(false); for (int i = 0; i < lines.Length; i++) { MInventoryLine line = lines[i]; // nothing to post if (line.GetQtyBook().CompareTo(line.GetQtyCount()) == 0 && Env.Signum(line.GetQtyInternalUse()) == 0) { continue; } // DocLine docLine = new DocLine(line, this); Decimal Qty = line.GetQtyInternalUse(); if (Env.Signum(Qty) != 0) { Qty = Decimal.Negate(Qty); // Internal Use entered positive } else { Decimal QtyBook = line.GetQtyBook(); Decimal QtyCount = line.GetQtyCount(); Qty = Decimal.Subtract(QtyCount, QtyBook); } docLine.SetQty(Qty, false); // -5 => -5 // log.Fine(docLine.ToString()); list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
/// <summary> /// Create Facts (the accounting logic) for POR. /// <pre> /// Reservation /// Expense CR /// Offset DR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); Fact fact = new Fact(this, as1, Fact.POST_Reservation); SetC_Currency_ID(as1.GetC_Currency_ID()); // // Decimal grossAmt = GetAmount(Doc.AMTTYPE_Gross); // Commitment if (as1.IsCreateReservation()) { Decimal total = Env.ZERO; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; Decimal cost = line.GetAmtSource(); total = Decimal.Add(total, cost); // Account MAccount expense = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); // fact.CreateLine(line, expense, as1.GetC_Currency_ID(), cost, null); } // Offset MAccount offset = GetAccount(ACCTTYPE_CommitmentOffset, as1); if (offset == null) { _error = "@NotFound@ @CommitmentOffset_Acct@"; log.Log(Level.SEVERE, _error); return(null); } fact.CreateLine(null, offset, GetC_Currency_ID(), null, total); facts.Add(fact); } return(facts); }
/// <summary> /// Create Accounting Entries /// </summary> /// <param name="as1">account schema</param> /// <param name="fact">fact to add lines</param> /// <param name="line">line</param> /// <returns>true if created</returns> public bool CreateEntries(MAcctSchema as1, Fact fact, DocLine line) { // get total index (the Receivables/Liabilities line) Decimal total = Env.ZERO; for (int i = 0; i < _facts.Count; i++) { MFactAcct factAcct = (MFactAcct)_facts[i]; if (factAcct.GetAmtSourceDr().CompareTo(total) > 0) { total = factAcct.GetAmtSourceDr(); _totalIndex = i; } if (factAcct.GetAmtSourceCr().CompareTo(total) > 0) { total = factAcct.GetAmtSourceCr(); _totalIndex = i; } } MFactAcct factAcct1 = (MFactAcct)_facts[_totalIndex]; log.Info("Total Invoice = " + total + " - " + factAcct1); int precision = as1.GetStdPrecision(); for (int i = 0; i < _facts.Count; i++) { // No Tax Line if (i == _totalIndex) { continue; } factAcct1 = (MFactAcct)_facts[i]; log.Info(i + ": " + factAcct1); // Create Tax Account MAccount taxAcct = factAcct1.GetMAccount(); if (taxAcct == null || taxAcct.Get_ID() == 0) { log.Severe("Tax Account not found/created"); return(false); } // Discount Amount if (Env.Signum(_DiscountAmt) != 0) { // Original Tax is DR - need to correct it CR if (Env.ZERO.CompareTo(factAcct1.GetAmtSourceDr()) != 0) { Decimal amount = CalcAmount(factAcct1.GetAmtSourceDr(), total, _DiscountAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, _DiscountAccount, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), null, amount); } } // Original Tax is CR - need to correct it DR else { Decimal amount = CalcAmount(factAcct1.GetAmtSourceCr(), total, _DiscountAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, _DiscountAccount, as1.GetC_Currency_ID(), null, amount); } } } // Discount // WriteOff Amount if (Env.Signum(_WriteOffAmt) != 0) { // Original Tax is DR - need to correct it CR if (Env.ZERO.CompareTo(factAcct1.GetAmtSourceDr()) != 0) { Decimal amount = CalcAmount(factAcct1.GetAmtSourceDr(), total, _WriteOffAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, _WriteOffAccount, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), null, amount); } } // Original Tax is CR - need to correct it DR else { Decimal amount = CalcAmount(factAcct1.GetAmtSourceCr(), total, _WriteOffAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, _WriteOffAccount, as1.GetC_Currency_ID(), null, amount); } } } // WriteOff } // for all lines return(true); }
/// <summary> /// Create Facts (the accounting logic) for /// SOO, POO. /// <pre> /// Reservation (release) /// Expense DR /// Offset CR /// Commitment /// (to be released by Invoice Matching) /// Expense CR /// Offset DR /// </pre> /// </summary> /// <param name="as1">accounting schema</param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // Purchase Order if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_PURCHASEORDER)) { UpdateProductPO(as1); // Decimal grossAmt = getAmount(Doc.AMTTYPE_Gross); // Commitment if (as1.IsCreateCommitment()) { Fact fact = new Fact(this, as1, Fact.POST_Commitment); Decimal total = Env.ZERO; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; Decimal cost = line.GetAmtSource(); total = Decimal.Add(total, cost); // Account MAccount expense = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); fact.CreateLine(line, expense, GetC_Currency_ID(), cost, null); } // Offset MAccount offset = GetAccount(ACCTTYPE_CommitmentOffset, as1); if (offset == null) { _error = "@NotFound@ @CommitmentOffset_Acct@"; log.Log(Level.SEVERE, _error); return(null); } fact.CreateLine(null, offset, GetC_Currency_ID(), null, total); // facts.Add(fact); } // Reverse Reservation if (as1.IsCreateReservation()) { Fact fact = new Fact(this, as1, Fact.POST_Reservation); Decimal total = Env.ZERO; if (_requisitions == null) { _requisitions = LoadRequisitions(); } for (int i = 0; i < _requisitions.Length; i++) { DocLine line = _requisitions[i]; Decimal cost = line.GetAmtSource(); total = Decimal.Add(total, cost); // Account MAccount expense = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); fact.CreateLine(line, expense, GetC_Currency_ID(), null, cost); } // Offset MAccount offset = GetAccount(ACCTTYPE_CommitmentOffset, as1); if (offset == null) { _error = "@NotFound@ @CommitmentOffset_Acct@"; log.Log(Level.SEVERE, _error); return(null); } fact.CreateLine(null, offset, GetC_Currency_ID(), total, null); // facts.Add(fact); } // reservations } // SO return(facts); }
/// <summary> /// Create Landed Cost accounting & Cost lines /// </summary> /// <param name="as1">accounting schema</param> /// <param name="fact">fact</param> /// <param name="line">document line</param> /// <param name="dr">DR entry (normal api)</param> /// <returns>true if landed costs were created</returns> private bool LandedCost(MAcctSchema as1, Fact fact, DocLine line, bool dr) { int C_InvoiceLine_ID = line.Get_ID(); MLandedCostAllocation[] lcas = MLandedCostAllocation.GetOfInvoiceLine( GetCtx(), C_InvoiceLine_ID, GetTrx()); if (lcas.Length == 0) { return(false); } // Delete Old String sql = "DELETE FROM M_CostDetail WHERE C_InvoiceLine_ID=" + C_InvoiceLine_ID; int no = DataBase.DB.ExecuteQuery(sql, null, GetTrx()); if (no != 0) { log.Config("CostDetail Deleted #" + no); } // Calculate Total Base double totalBase = 0; for (int i = 0; i < lcas.Length; i++) { totalBase += Convert.ToDouble(lcas[i].GetBase());//.doubleValue(); } // Create New MInvoiceLine il = new MInvoiceLine(GetCtx(), C_InvoiceLine_ID, GetTrx()); for (int i = 0; i < lcas.Length; i++) { MLandedCostAllocation lca = lcas[i]; if (Env.Signum(lca.GetBase()) == 0) { continue; } double percent = totalBase / Convert.ToDouble(lca.GetBase()); String desc = il.GetDescription(); if (desc == null) { desc = percent + "%"; } else { desc += " - " + percent + "%"; } if (line.GetDescription() != null) { desc += " - " + line.GetDescription(); } // Accounting ProductCost pc = new ProductCost(GetCtx(), lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(), GetTrx()); Decimal?drAmt = null; Decimal?crAmt = null; if (dr) { drAmt = lca.GetAmt(); } else { crAmt = lca.GetAmt(); } FactLine fl = fact.CreateLine(line, pc.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1), GetC_Currency_ID(), drAmt, crAmt); fl.SetDescription(desc); // Cost Detail - Convert to AcctCurrency Decimal allocationAmt = lca.GetAmt(); if (GetC_Currency_ID() != as1.GetC_Currency_ID()) { allocationAmt = MConversionRate.Convert(GetCtx(), allocationAmt, GetC_Currency_ID(), as1.GetC_Currency_ID(), GetDateAcct(), GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); } if (Env.Scale(allocationAmt) > as1.GetCostingPrecision()) { allocationAmt = Decimal.Round(allocationAmt, as1.GetCostingPrecision(), MidpointRounding.AwayFromZero); } if (!dr) { allocationAmt = Decimal.Negate(allocationAmt); } if (!IsPosted()) { MCostDetail cd = new MCostDetail(as1, lca.GetAD_Org_ID(), lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(), lca.GetM_CostElement_ID(), allocationAmt, lca.GetQty(), // Qty desc, GetTrx()); cd.SetC_InvoiceLine_ID(C_InvoiceLine_ID); bool ok = cd.Save(); if (ok && !cd.IsProcessed()) { MClient client = MClient.Get(as1.GetCtx(), as1.GetAD_Client_ID()); if (client.IsCostImmediate()) { cd.Process(); } } } } log.Config("Created #" + lcas.Length); return(true); }
/// <summary> /// Create Fact Cash Based (i.e. only revenue/expense) /// </summary> /// <param name="as1">accounting schema</param> /// <param name="fact">fact to add lines to</param> /// <param name="multiplier">source amount multiplier</param> /// <returns>accounted amount</returns> public Decimal CreateFactCash(MAcctSchema as1, Fact fact, Decimal multiplier) { bool creditMemo = GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARCREDITMEMO) || GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APCREDITMEMO); bool payables = GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APINVOICE) || GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APCREDITMEMO); Decimal acctAmt = Env.ZERO; FactLine fl = null; // Revenue/Cost for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; bool landedCost = false; if (payables) { landedCost = LandedCost(as1, fact, line, false); } if (landedCost && as1.IsExplicitCostAdjustment()) { fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1), GetC_Currency_ID(), null, line.GetAmtSource()); // fl = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1), GetC_Currency_ID(), line.GetAmtSource(), null); String desc = line.GetDescription(); if (desc == null) { desc = "100%"; } else { desc += " 100%"; } fl.SetDescription(desc); } if (!landedCost) { MAccount acct = line.GetAccount( payables ? ProductCost.ACCTTYPE_P_Expense : ProductCost.ACCTTYPE_P_Revenue, as1); if (payables) { // if Fixed Asset if (line.IsItem()) { acct = line.GetAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as1); } } Decimal?amt = (Decimal?)Decimal.Multiply(line.GetAmtSource(), multiplier); Decimal?amt2 = null; if (creditMemo) { amt2 = amt; amt = null; } if (payables) // Vendor = DR { fl = fact.CreateLine(line, acct, GetC_Currency_ID(), amt, amt2); } else // Customer = CR { fl = fact.CreateLine(line, acct, GetC_Currency_ID(), amt2, amt); } if (fl != null) { acctAmt = Decimal.Add(acctAmt, fl.GetAcctBalance()); } } } // Tax for (int i = 0; i < _taxes.Length; i++) { Decimal?amt = (Decimal?)_taxes[i].GetAmount(); Decimal?amt2 = null; if (creditMemo) { amt2 = amt; amt = null; } FactLine tl = null; if (payables) { tl = fact.CreateLine(null, _taxes[i].GetAccount(_taxes[i].GetAPTaxType(), as1), GetC_Currency_ID(), amt, amt2); } else { tl = fact.CreateLine(null, _taxes[i].GetAccount(DocTax.ACCTTYPE_TaxDue, as1), GetC_Currency_ID(), amt2, amt); } if (tl != null) { tl.SetC_Tax_ID(_taxes[i].GetC_Tax_ID()); } } // Set Locations FactLine[] fLines = fact.GetLines(); for (int i = 0; i < fLines.Length; i++) { if (fLines[i] != null) { if (payables) { fLines[i].SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc fLines[i].SetLocationFromOrg(fLines[i].GetAD_Org_ID(), false); // to Loc } else { fLines[i].SetLocationFromOrg(fLines[i].GetAD_Org_ID(), true); // from Loc fLines[i].SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc } } } return(acctAmt); }
/// <summary> /// Create Facts (the accounting logic) for /// ARI, ARC, ARF, API, APC. /// <pre> /// ARI, ARF /// Receivables DR /// Charge CR /// TaxDue CR ///Revenue CR /// ARC /// Receivables CR /// Charge DR /// TaxDue DR /// Revenue RR /// /// API /// Payables CR /// Charge DR /// TaxCredit DR /// Expense DR /// /// APC /// Payables DR /// Charge CR /// TaxCredit CR /// Expense CR /// </pre> /// </summary> /// <param name="as1">accounting schema</param> /// <returns> Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // List <Fact> facts = new List <Fact>(); // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); // Cash based accounting if (!as1.IsAccrual()) { return(facts); } // ** ARI, ARF if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARINVOICE) || GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARPROFORMAINVOICE)) { Decimal grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; Decimal serviceAmt = Env.ZERO; // Header Charge CR Decimal amt = GetAmount(Doc.AMTTYPE_Charge).Value; if (Env.Signum(amt) != 0) { fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_Charge, as1), GetC_Currency_ID(), null, amt); } // TaxDue CR for (int i = 0; i < _taxes.Length; i++) { amt = _taxes[i].GetAmount(); if (Env.Signum(amt) != 0) { FactLine tl = fact.CreateLine(null, _taxes[i].GetAccount(DocTax.ACCTTYPE_TaxDue, as1), GetC_Currency_ID(), null, amt); if (tl != null) { tl.SetC_Tax_ID(_taxes[i].GetC_Tax_ID()); } } } // Revenue CR for (int i = 0; i < _lines.Length; i++) { amt = _lines[i].GetAmtSource(); Decimal?dAmt = null; if (as1.IsTradeDiscountPosted()) { Decimal discount = _lines[i].GetDiscount(); if (Env.Signum(discount) != 0) { amt = Decimal.Add(amt, discount); dAmt = discount; } } fact.CreateLine(_lines[i], _lines[i].GetAccount(ProductCost.ACCTTYPE_P_Revenue, as1), GetC_Currency_ID(), dAmt, amt); if (!_lines[i].IsItem()) { grossAmt = Decimal.Subtract(grossAmt, amt); serviceAmt = Decimal.Add(serviceAmt, amt); } } // Set Locations FactLine[] fLines = fact.GetLines(); for (int i = 0; i < fLines.Length; i++) { if (fLines[i] != null) { fLines[i].SetLocationFromOrg(fLines[i].GetAD_Org_ID(), true); // from Loc fLines[i].SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc } } // Receivables DR int receivables_ID = GetValidCombination_ID(Doc.ACCTTYPE_C_Receivable, as1); int receivablesServices_ID = GetValidCombination_ID(Doc.ACCTTYPE_C_Receivable_Services, as1); if (_allLinesItem || !as1.IsPostServices() || receivables_ID == receivablesServices_ID) { grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; serviceAmt = Env.ZERO; } else if (_allLinesService) { serviceAmt = GetAmount(Doc.AMTTYPE_Gross).Value; grossAmt = Env.ZERO; } if (Env.Signum(grossAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), receivables_ID), GetC_Currency_ID(), grossAmt, null); } if (Env.Signum(serviceAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), receivablesServices_ID), GetC_Currency_ID(), serviceAmt, null); } } // ARC else if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARCREDITMEMO)) { Decimal grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; Decimal serviceAmt = Env.ZERO; // Header Charge DR Decimal amt = GetAmount(Doc.AMTTYPE_Charge).Value; if (Env.Signum(amt) != 0) { fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_Charge, as1), GetC_Currency_ID(), amt, null); } // TaxDue DR for (int i = 0; i < _taxes.Length; i++) { amt = _taxes[i].GetAmount(); if (Env.Signum(amt) != 0) { FactLine tl = fact.CreateLine(null, _taxes[i].GetAccount(DocTax.ACCTTYPE_TaxDue, as1), GetC_Currency_ID(), amt, null); if (tl != null) { tl.SetC_Tax_ID(_taxes[i].GetC_Tax_ID()); } } } // Revenue CR for (int i = 0; i < _lines.Length; i++) { amt = _lines[i].GetAmtSource(); Decimal?dAmt = null; if (as1.IsTradeDiscountPosted()) { Decimal discount = _lines[i].GetDiscount(); if (Env.Signum(discount) != 0) { amt = Decimal.Add(amt, discount); dAmt = discount; } } fact.CreateLine(_lines[i], _lines[i].GetAccount(ProductCost.ACCTTYPE_P_Revenue, as1), GetC_Currency_ID(), amt, dAmt); if (!_lines[i].IsItem()) { grossAmt = Decimal.Subtract(grossAmt, amt); serviceAmt = Decimal.Add(serviceAmt, amt); } } // Set Locations FactLine[] fLines = fact.GetLines(); for (int i = 0; i < fLines.Length; i++) { if (fLines[i] != null) { fLines[i].SetLocationFromOrg(fLines[i].GetAD_Org_ID(), true); // from Loc fLines[i].SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc } } // Receivables CR int receivables_ID = GetValidCombination_ID(Doc.ACCTTYPE_C_Receivable, as1); int receivablesServices_ID = GetValidCombination_ID(Doc.ACCTTYPE_C_Receivable_Services, as1); if (_allLinesItem || !as1.IsPostServices() || receivables_ID == receivablesServices_ID) { grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; serviceAmt = Env.ZERO; } else if (_allLinesService) { serviceAmt = GetAmount(Doc.AMTTYPE_Gross).Value; grossAmt = Env.ZERO; } if (Env.Signum(grossAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), receivables_ID), GetC_Currency_ID(), null, grossAmt); } if (Env.Signum(serviceAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), receivablesServices_ID), GetC_Currency_ID(), null, serviceAmt); } } // ** API else if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APINVOICE)) { Decimal grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; Decimal serviceAmt = Env.ZERO; // Charge DR fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_Charge, as1), GetC_Currency_ID(), GetAmount(Doc.AMTTYPE_Charge), null); // TaxCredit DR for (int i = 0; i < _taxes.Length; i++) { FactLine tl = fact.CreateLine(null, _taxes[i].GetAccount(_taxes[i].GetAPTaxType(), as1), GetC_Currency_ID(), _taxes[i].GetAmount(), null); if (tl != null) { tl.SetC_Tax_ID(_taxes[i].GetC_Tax_ID()); } } // Expense DR for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; bool landedCost = LandedCost(as1, fact, line, true); if (landedCost && as1.IsExplicitCostAdjustment()) { fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1), GetC_Currency_ID(), line.GetAmtSource(), null); // FactLine fl = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1), GetC_Currency_ID(), null, line.GetAmtSource()); String desc = line.GetDescription(); if (desc == null) { desc = "100%"; } else { desc += " 100%"; } fl.SetDescription(desc); } if (!landedCost) { MAccount expense = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); if (line.IsItem()) { expense = line.GetAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as1); } Decimal amt = line.GetAmtSource(); Decimal?dAmt = null; if (as1.IsTradeDiscountPosted() && !line.IsItem()) { Decimal discount = line.GetDiscount(); if (Env.Signum(discount) != 0) { amt = Decimal.Add(amt, discount); dAmt = discount; } } fact.CreateLine(line, expense, GetC_Currency_ID(), amt, dAmt); if (!line.IsItem()) { grossAmt = Decimal.Subtract(grossAmt, amt); serviceAmt = Decimal.Add(serviceAmt, amt); } // if (line.GetM_Product_ID() != 0 && line.GetProduct().IsService()) // otherwise Inv Matching { if (!IsPosted()) { MCostDetail.CreateInvoice(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, // No Cost Element line.GetAmtSource(), line.GetQty().Value, line.GetDescription(), GetTrx(), GetRectifyingProcess()); } } } } // Set Locations FactLine[] fLines = fact.GetLines(); for (int i = 0; i < fLines.Length; i++) { if (fLines[i] != null) { fLines[i].SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc fLines[i].SetLocationFromOrg(fLines[i].GetAD_Org_ID(), false); // to Loc } } // Liability CR int payables_ID = GetValidCombination_ID(Doc.ACCTTYPE_V_Liability, as1); int payablesServices_ID = GetValidCombination_ID(Doc.ACCTTYPE_V_Liability_Services, as1); if (_allLinesItem || !as1.IsPostServices() || payables_ID == payablesServices_ID) { grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; serviceAmt = Env.ZERO; } else if (_allLinesService) { serviceAmt = GetAmount(Doc.AMTTYPE_Gross).Value; grossAmt = Env.ZERO; } if (Env.Signum(grossAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), payables_ID), GetC_Currency_ID(), null, grossAmt); } if (Env.Signum(serviceAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), payablesServices_ID), GetC_Currency_ID(), null, serviceAmt); } // UpdateProductPO(as1); // Only API } // APC else if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APCREDITMEMO)) { Decimal grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; Decimal serviceAmt = Env.ZERO; // Charge CR fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_Charge, as1), GetC_Currency_ID(), null, GetAmount(Doc.AMTTYPE_Charge)); // TaxCredit CR for (int i = 0; i < _taxes.Length; i++) { FactLine tl = fact.CreateLine(null, _taxes[i].GetAccount(_taxes[i].GetAPTaxType(), as1), GetC_Currency_ID(), null, _taxes[i].GetAmount()); if (tl != null) { tl.SetC_Tax_ID(_taxes[i].GetC_Tax_ID()); } } // Expense CR for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; bool landedCost = LandedCost(as1, fact, line, false); if (landedCost && as1.IsExplicitCostAdjustment()) { fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1), GetC_Currency_ID(), null, line.GetAmtSource()); // FactLine fl = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1), GetC_Currency_ID(), line.GetAmtSource(), null); String desc = line.GetDescription(); if (desc == null) { desc = "100%"; } else { desc += " 100%"; } fl.SetDescription(desc); } if (!landedCost) { MAccount expense = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); if (line.IsItem()) { expense = line.GetAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as1); } Decimal amt = line.GetAmtSource(); Decimal?dAmt = null; if (as1.IsTradeDiscountPosted() && !line.IsItem()) { Decimal discount = line.GetDiscount(); if (Env.Signum(discount) != 0) { amt = Decimal.Add(amt, discount); dAmt = discount; } } fact.CreateLine(line, expense, GetC_Currency_ID(), dAmt, amt); if (!line.IsItem()) { grossAmt = Decimal.Subtract(grossAmt, amt); serviceAmt = Decimal.Add(serviceAmt, amt); } // if (line.GetM_Product_ID() != 0 && line.GetProduct().IsService()) // otherwise Inv Matching { if (!IsPosted()) { MCostDetail.CreateInvoice(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, // No Cost Element Decimal.Negate(line.GetAmtSource()), line.GetQty().Value, line.GetDescription(), GetTrx(), GetRectifyingProcess()); } } } } // Set Locations FactLine[] fLines = fact.GetLines(); for (int i = 0; i < fLines.Length; i++) { if (fLines[i] != null) { fLines[i].SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc fLines[i].SetLocationFromOrg(fLines[i].GetAD_Org_ID(), false); // to Loc } } // Liability DR int payables_ID = GetValidCombination_ID(Doc.ACCTTYPE_V_Liability, as1); int payablesServices_ID = GetValidCombination_ID(Doc.ACCTTYPE_V_Liability_Services, as1); if (_allLinesItem || !as1.IsPostServices() || payables_ID == payablesServices_ID) { grossAmt = GetAmount(Doc.AMTTYPE_Gross).Value; serviceAmt = Env.ZERO; } else if (_allLinesService) { serviceAmt = GetAmount(Doc.AMTTYPE_Gross).Value; grossAmt = Env.ZERO; } if (Env.Signum(grossAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), payables_ID), GetC_Currency_ID(), grossAmt, null); } if (Env.Signum(serviceAmt) != 0) { fact.CreateLine(null, MAccount.Get(GetCtx(), payablesServices_ID), GetC_Currency_ID(), serviceAmt, null); } } else { _error = "DocumentType unknown: " + GetDocumentType(); log.Log(Level.SEVERE, _error); fact = null; } // facts.Add(fact); return(facts); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="invoice">invoice</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MInvoice invoice) { List <DocLine> list = new List <DocLine>(); // MInvoiceLine[] lines = invoice.GetLines(false); for (int i = 0; i < lines.Length; i++) { MInvoiceLine line = lines[i]; if (line.IsDescription()) { continue; } DocLine docLine = new DocLine(line, this); // Qty Decimal Qty = line.GetQtyInvoiced(); bool cm = GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARCREDITMEMO) || GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APCREDITMEMO); docLine.SetQty(cm ? Decimal.Negate(Qty) : Qty, invoice.IsSOTrx()); // Decimal LineNetAmt = line.GetLineNetAmt(); Decimal PriceList = line.GetPriceList(); int C_Tax_ID = docLine.GetC_Tax_ID(); // Correct included Tax if (IsTaxIncluded() && C_Tax_ID != 0) { MTax tax = MTax.Get(GetCtx(), C_Tax_ID); if (!tax.IsZeroTax()) { Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt, true, GetStdPercision()); log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = Decimal.Subtract(LineNetAmt, LineNetAmtTax); for (int t = 0; t < _taxes.Length; t++) { if (_taxes[t].GetC_Tax_ID() == C_Tax_ID) { _taxes[t].AddIncludedTax(LineNetAmtTax); break; } } Decimal PriceListTax = tax.CalculateTax(PriceList, true, GetStdPercision()); PriceList = Decimal.Subtract(PriceList, PriceListTax); } } // correct included Tax docLine.SetAmount(LineNetAmt, PriceList, Qty); // qty for discount calc if (docLine.IsItem()) { _allLinesService = false; } else { _allLinesItem = false; } // log.Fine(docLine.ToString()); list.Add(docLine); } // Convert to Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); // Included Tax - make sure that no difference if (IsTaxIncluded()) { for (int i = 0; i < _taxes.Length; i++) { if (_taxes[i].IsIncludedTaxDifference()) { Decimal diff = _taxes[i].GetIncludedTaxDifference(); for (int j = 0; j < dls.Length; j++) { if (dls[j].GetC_Tax_ID() == _taxes[i].GetC_Tax_ID()) { dls[j].SetLineNetAmtDifference(diff); break; } } // for all lines } // tax difference } // for all taxes } // Included Tax difference // Return Array return(dls); }
/// <summary> /// Load Requisitions /// </summary> /// <returns>requisition lines of Order</returns> private DocLine[] LoadRequisitions() { MOrder order = (MOrder)GetPO(); MOrderLine[] oLines = order.GetLines(); Dictionary <int, Decimal> qtys = new Dictionary <int, Decimal>(); for (int i = 0; i < oLines.Length; i++) { MOrderLine line = oLines[i]; qtys.Add(Utility.Util.GetValueOfInt(line.GetC_OrderLine_ID()), line.GetQtyOrdered()); } // List <DocLine> list = new List <DocLine>(); String sql = "SELECT * FROM M_RequisitionLine rl " + "WHERE EXISTS (SELECT * FROM C_Order o " + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) " + "WHERE ol.C_OrderLine_ID=rl.C_OrderLine_ID" + " AND o.C_Order_ID=" + order.GetC_Order_ID() + ") " + "ORDER BY rl.C_OrderLine_ID"; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, null); while (idr.Read()) { MRequisitionLine line = new MRequisitionLine(GetCtx(), idr, null); DocLine docLine = new DocLine(line, this); // Quantity - not more then OrderLine // Issue: Split of Requisition to multiple POs & different price int key = line.GetC_OrderLine_ID(); Decimal maxQty = qtys[key]; Decimal Qty = Math.Max(line.GetQty(), maxQty); if (Env.Signum(Qty) == 0) { continue; } docLine.SetQty(Qty, false); if (qtys.ContainsKey(key)) { qtys.Remove(key); } qtys.Add(key, Decimal.Subtract(maxQty, Qty)); // Decimal PriceActual = line.GetPriceActual(); Decimal LineNetAmt = line.GetLineNetAmt(); if (line.GetQty().CompareTo(Qty) != 0) { LineNetAmt = Decimal.Multiply(PriceActual, Qty); } docLine.SetAmount(LineNetAmt); // DR list.Add(docLine); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); idr = null; } log.Log(Level.SEVERE, sql, e); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); MProductCategoryAcct pca = null; String costingMethodOfSchema = as1.GetCostingMethod(); String costingLevelOfSchema = as1.GetCostingLevel(); // Get the costing method and the costing level of the product Category for the current accounting schema. if (mpc != null) { pca = MProductCategoryAcct.Get(GetCtx(), mpc.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), null); if (pca.GetCostingMethod() != null) { costingMethod = pca.GetCostingMethod(); } else { costingMethod = costingMethodOfSchema; } if (pca.GetCostingLevel() != null) { costingLevel = pca.GetCostingLevel(); } else { costingLevel = costingLevelOfSchema; } // proceed only if the costing method is standard if (!costingMethod.Equals(X_C_AcctSchema.COSTINGMETHOD_StandardCosting)) { return(facts); } } Fact fact = new Fact(this, as1, Fact.POST_Actual); FactLine dr = null; FactLine cr = null; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; if (mpc == null) { pca = MProductCategoryAcct.Get(GetCtx(), MProduct.Get(GetCtx(), line.GetM_Product_ID()). GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), null); if (pca.GetCostingMethod() != null) { costingMethod = pca.GetCostingMethod(); } else { costingMethod = costingMethodOfSchema; } if (pca.GetCostingLevel() != null) { costingLevel = pca.GetCostingLevel(); } else { costingLevel = costingLevelOfSchema; } // proceed only if the costing method is standard if (!costingMethod.Equals(X_C_AcctSchema.COSTINGMETHOD_StandardCosting)) { return(facts); } } Decimal currentCost = Env.ZERO; Decimal oldCost = Env.ZERO; Decimal Qty = Env.ZERO; String sql = " SELECT Sum(CurrentCostPrice), Sum(LastCostPrice), Sum(CurrentQty)" + " FROM M_Cost WHERE M_Product_ID = " + line.GetM_Product_ID() + " AND C_AcctSchema_ID = " + as1.GetC_AcctSchema_ID() + " AND M_CostElement_ID = " + m_ce.GetM_CostElement_ID() + " AND M_CostType_ID = " + as1.GetM_CostType_ID() + " AND AD_Client_ID = " + GetAD_Client_ID(); if (costingLevel.Equals(X_C_AcctSchema.COSTINGLEVEL_Client)) { sql += " AND AD_Org_ID = 0" + " AND M_AttributeSetInstance_ID = 0"; } else if (costingLevel.Equals(X_C_AcctSchema.COSTINGLEVEL_Organization)) { sql += " AND M_AttributeSetInstance_ID = 0"; } else if (costingLevel.Equals(X_C_AcctSchema.COSTINGLEVEL_BatchLot)) { sql += " AND AD_Org_ID = 0"; } IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, GetTrx()); while (idr.Read()) { currentCost = Util.GetValueOfDecimal(idr[0]); oldCost = Util.GetValueOfDecimal(idr[1]); Qty = Util.GetValueOfDecimal(idr[2]); line.SetQty(Qty, costupdate.IsSOTrx()); Decimal PriceCost = Decimal.Subtract(currentCost, oldCost); Decimal amt = Env.ZERO; if (Env.Signum(PriceCost) != 0) { amt = Decimal.Multiply(Qty, PriceCost); } line.SetAmount(amt); if (Env.Signum(amt) == 0) { continue; } MAccount db_acct, cr_acct; /* Decide the Credit and Debit Accounts */ if (Env.Signum(amt) == 1) { db_acct = line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1); cr_acct = line.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1); } else { cr_acct = line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1); db_acct = line.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1); } /* Create Credit and Debit lines*/ dr = fact.CreateLine(line, db_acct, as1.GetC_Currency_ID(), Math.Abs(amt), null); if (dr == null) { log.SaveError("NoProductCosts", "No Product Costs"); return(null); } cr = fact.CreateLine(line, cr_acct, as1.GetC_Currency_ID(), null, Math.Abs(amt)); if (cr == null) { log.SaveError("NoProductCosts", "No Product Costs"); return(null); } } idr.Close(); } catch (Exception e) { log.Log(Level.SEVERE, sql, e); } finally { if (idr != null) { idr.Close(); idr = null; } } } facts.Add(fact); return(facts); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="order">order</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MOrder order) { List <DocLine> list = new List <DocLine>(); MOrderLine[] lines = order.GetLines(); for (int i = 0; i < lines.Length; i++) { MOrderLine line = lines[i]; DocLine docLine = new DocLine(line, this); Decimal Qty = line.GetQtyOrdered(); docLine.SetQty(Qty, order.IsSOTrx()); // // Decimal PriceActual = line.getPriceActual(); Decimal?PriceCost = null; if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_PURCHASEORDER)) // PO { PriceCost = line.GetPriceCost(); } Decimal?LineNetAmt = null; if (PriceCost != null && Env.Signum(PriceCost.Value) != 0) { LineNetAmt = Decimal.Multiply(Qty, PriceCost.Value); } else { LineNetAmt = line.GetLineNetAmt(); } docLine.SetAmount(LineNetAmt); // DR Decimal PriceList = line.GetPriceList(); int C_Tax_ID = docLine.GetC_Tax_ID(); // Correct included Tax if (IsTaxIncluded() && C_Tax_ID != 0) { MTax tax = MTax.Get(GetCtx(), C_Tax_ID); if (!tax.IsZeroTax()) { Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt.Value, true, GetStdPrecision()); log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = Decimal.Subtract(LineNetAmt.Value, LineNetAmtTax); for (int t = 0; t < _taxes.Length; t++) { if (_taxes[t].GetC_Tax_ID() == C_Tax_ID) { _taxes[t].AddIncludedTax(LineNetAmtTax); break; } } Decimal PriceListTax = tax.CalculateTax(PriceList, true, GetStdPrecision()); PriceList = Decimal.Subtract(PriceList, PriceListTax); } } // correct included Tax docLine.SetAmount(LineNetAmt, PriceList, Qty); list.Add(docLine); } // Return Array DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }
/// <summary> /// Create Facts (the accounting logic) for /// MMS, MMR. /// <pre> /// Shipment /// CoGS (RevOrg) DR /// Inventory CR /// Shipment of Project Issue /// CoGS DR /// Project CR /// Receipt /// Inventory DR /// NotInvoicedReceipt CR /// </pre> /// </summary> /// <param name="as1">accounting schema</param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Line pointers FactLine dr = null; FactLine cr = null; // *** Sales - Shipment if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALDELIVERY)) { for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; MInOutLine sLine = new MInOutLine(GetCtx(), line.Get_ID(), null); Decimal costs = 0; if (sLine.GetA_Asset_ID() > 0) { costs = Util.GetValueOfDecimal(DB.ExecuteScalar(@"SELECT cost.CUrrentcostPrice FROM m_cost cost INNER JOIN A_Asset ass ON(ass.a_asset_ID=cost.a_asset_ID) INNER JOIN M_InOutLine IOL ON(IOL.A_Asset_ID =ass.A_Asset_ID) WHERE IOL.M_InOutLine_ID=" + sLine.GetM_InOutLine_ID() + @" ORDER By cost.created desc")); // Change if Cost not found against Asset then get Product Cost if (Env.Signum(costs) == 0) // zero costs OK { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), true); } } else { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), true); } if (Env.Signum(costs) == 0) // zero costs OK { MProduct product = line.GetProduct(); if (product.IsStocked()) { _error = "No Costs for " + line.GetProduct().GetName(); log.Log(Level.WARNING, _error); return(null); } else // ignore service { continue; } } if (!IsReturnTrx()) { // CoGS DR dr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Cogs, as1), as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "FactLine DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc dr.SetAD_Org_ID(line.GetOrder_Org_ID()); // Revenue X-Org dr.SetQty(Decimal.Negate(line.GetQty().Value)); // Inventory CR cr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "FactLine CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc } else // Reverse accounting entries for returns { // CoGS CR cr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Cogs, as1), as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "FactLine CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc cr.SetAD_Org_ID(line.GetOrder_Org_ID()); // Revenue X-Org cr.SetQty(Decimal.Negate(line.GetQty().Value)); // Inventory DR dr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "FactLine DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc } // if (line.GetM_Product_ID() != 0) { if (!IsPosted()) { MCostDetail.CreateShipment(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, costs, IsReturnTrx() ? Decimal.Negate(line.GetQty().Value) : line.GetQty().Value, line.GetDescription(), true, GetTrx(), GetRectifyingProcess()); } } } // for all lines if (!IsPosted()) { UpdateProductInfo(as1.GetC_AcctSchema_ID()); // only for SO! } } // Shipment // *** Purchasing - Receipt else if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALRECEIPT)) { for (int i = 0; i < _lines.Length; i++) { Decimal costs = 0; DocLine line = _lines[i]; MProduct product = line.GetProduct(); /***********************************************************/ //05,Sep,2011 //Special Check to restic Price varience posting in case of //AvarageInvoice Selected on product Category.Then Neglact the AverageInvoice Cost MProductCategoryAcct pca = MProductCategoryAcct.Get(product.GetCtx(), product.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), null); try { if (as1.IsNotPostPOVariance() && line.GetC_OrderLine_ID() > 0) { MOrderLine oLine = new MOrderLine(product.GetCtx(), line.GetC_OrderLine_ID(), null); MOrder order = new MOrder(product.GetCtx(), oLine.GetC_Order_ID(), null); Decimal convertedCost = MConversionRate.Convert(product.GetCtx(), oLine.GetPriceEntered(), order.GetC_Currency_ID(), as1.GetC_Currency_ID(), line.GetDateAcct(), order.GetC_ConversionType_ID(), oLine.GetAD_Client_ID(), line.GetAD_Org_ID()); costs = Decimal.Multiply(convertedCost, oLine.GetQtyEntered()); } else { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // non-zero costs } } catch (Exception ex) { log.SaveError("AccountSchemaColumnError", ex); costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // non-zero costs } /***********************************************************/ //Decimal costs = costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // non-zero costs if (Env.Signum(costs) == 0) { _error = "Resubmit - No Costs for " + product.GetName(); log.Log(Level.WARNING, _error); return(null); } // Inventory/Asset DR MAccount assets = line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1); if (product.IsService()) { assets = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); } if (!IsReturnTrx()) { // Inventory/Asset DR dr = fact.CreateLine(line, assets, as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc dr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc // NotInvoicedReceipt CR cr = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1), as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc cr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc cr.SetQty(Decimal.Negate(line.GetQty().Value)); } else // reverse accounting entries for returns { // Inventory/Asset CR cr = fact.CreateLine(line, assets, as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc cr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc // NotInvoicedReceipt DR dr = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1), as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc dr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc dr.SetQty(Decimal.Negate(line.GetQty().Value)); } } } // Receipt else { _error = "DocumentType unknown: " + GetDocumentType(); log.Log(Level.SEVERE, _error); return(null); } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
/// <summary> /// Create Facts (the accounting logic) for /// MMM. /// <pre> /// Movement /// Inventory DR CR /// InventoryTo DR CR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Line pointers FactLine dr = null; FactLine cr = null; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; Decimal costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // ** Inventory DR CR dr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), Decimal.Negate(costs)); // from (-) CR if (dr == null) { continue; } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetQty(Decimal.Negate(line.GetQty().Value)); // outgoing // ** InventoryTo DR CR cr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs); // to (+) DR if (cr == null) { continue; } cr.SetM_Locator_ID(line.GetM_LocatorTo_ID()); cr.SetQty(line.GetQty()); // Only for between-org movements if (dr.GetAD_Org_ID() != cr.GetAD_Org_ID()) { String costingLevel = as1.GetCostingLevel(); MProductCategoryAcct pca = MProductCategoryAcct.Get(GetCtx(), line.GetProduct().GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), GetTrx()); if (pca.GetCostingLevel() != null) { costingLevel = pca.GetCostingLevel(); } if (!MAcctSchema.COSTINGLEVEL_Organization.Equals(costingLevel)) { continue; } // String description = line.GetDescription(); if (description == null) { description = ""; } if (!IsPosted()) { // Cost Detail From MCostDetail.CreateMovement(as1, dr.GetAD_Org_ID(), // locator org line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, Decimal.Negate(costs), Decimal.Negate(line.GetQty().Value), true, description + "(|->)", GetTrx(), GetRectifyingProcess()); // Cost Detail To MCostDetail.CreateMovement(as1, cr.GetAD_Org_ID(), // locator org line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, costs, line.GetQty().Value, false, description + "(|<-)", GetTrx(), GetRectifyingProcess()); } } } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
/// <summary> /// Get Commitments /// </summary> /// <param name="doc">document</param> /// <param name="maxQty">Qty invoiced/matched</param> /// <param name="C_InvoiceLine_ID">invoice line</param> /// <returns>commitments (order lines)</returns> protected static DocLine[] GetCommitments(Doc doc, Decimal maxQty, int C_InvoiceLine_ID) { int precision = -1; // List <DocLine> list = new List <DocLine>(); String sql = "SELECT * FROM C_OrderLine ol " + "WHERE EXISTS " + "(SELECT * FROM C_InvoiceLine il " + "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND il.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")" + " OR EXISTS " + "(SELECT * FROM M_MatchPO po " + "WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND po.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")"; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, null); while (idr.Read()) { if (Env.Signum(maxQty) == 0) { continue; } MOrderLine line = new MOrderLine(doc.GetCtx(), idr, null); DocLine docLine = new DocLine(line, doc); // Currency if (precision == -1) { doc.SetC_Currency_ID(docLine.GetC_Currency_ID()); precision = MCurrency.GetStdPrecision(doc.GetCtx(), docLine.GetC_Currency_ID()); } // Qty Decimal Qty = Math.Max(line.GetQtyOrdered(), maxQty); docLine.SetQty(Qty, false); // Decimal PriceActual = line.GetPriceActual(); Decimal PriceCost = line.GetPriceCost(); Decimal?LineNetAmt = null; if (Env.Signum(PriceCost) != 0) { LineNetAmt = Decimal.Multiply(Qty, PriceCost); } else if (Qty.Equals(maxQty)) { LineNetAmt = line.GetLineNetAmt(); } else { LineNetAmt = Decimal.Multiply(Qty, PriceActual); } maxQty = Decimal.Subtract(maxQty, Qty); docLine.SetAmount(LineNetAmt); // DR Decimal PriceList = line.GetPriceList(); int C_Tax_ID = docLine.GetC_Tax_ID(); // Correct included Tax if (C_Tax_ID != 0 && line.GetParent().IsTaxIncluded()) { MTax tax = MTax.Get(doc.GetCtx(), C_Tax_ID); if (!tax.IsZeroTax()) { Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt.Value, true, precision); _log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = Decimal.Subtract(LineNetAmt.Value, LineNetAmtTax); Decimal PriceListTax = tax.CalculateTax(PriceList, true, precision); PriceList = Decimal.Subtract(PriceList, PriceListTax); } } // correct included Tax docLine.SetAmount(LineNetAmt, PriceList, Qty); list.Add(docLine); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); idr = null; } _log.Log(Level.SEVERE, sql, e); } // Return Array DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="prod">production</param> /// <returns> DoaLine Array</returns> private DocLine[] LoadLines(X_M_Production prod) { List <DocLine> list = new List <DocLine>(); // Production // -- ProductionPlan // -- -- ProductionLine - the real level String sqlPP = "SELECT * FROM M_ProductionPlan pp " + "WHERE pp.M_Production_ID=@param1 " + "ORDER BY pp.Line"; IDataReader idrPP = null; String sqlPL = "SELECT * FROM M_ProductionLine pl " + "WHERE pl.M_ProductionPlan_ID=@param2 " + "ORDER BY pl.Line"; IDataReader idrPL = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@param1", Get_ID()); idrPP = DataBase.DB.ExecuteReader(sqlPP, param, GetTrx()); //idrPP.setInt(1, get_ID()); //ResultSet rsPP = idrPP.executeQuery(); while (idrPP.Read()) { int M_Product_ID = Utility.Util.GetValueOfInt(idrPP["M_Product_ID"]); int M_ProductionPlan_ID = Utility.Util.GetValueOfInt(idrPP["M_ProductionPlan_ID"]); // try { param = new SqlParameter[1]; param[0] = new SqlParameter("@param2", M_ProductionPlan_ID); idrPL = DataBase.DB.ExecuteReader(sqlPL, param, GetTrx()); //idrPL.setInt(1, M_ProductionPlan_ID); //ResultSet rsPL = idrPL.executeQuery(); while (idrPL.Read()) { X_M_ProductionLine line = new X_M_ProductionLine(GetCtx(), idrPL, GetTrx()); if (Env.Signum(line.GetMovementQty()) == 0) { log.Info("LineQty=0 - " + line); continue; } DocLine docLine = new DocLine(line, this); docLine.SetQty(line.GetMovementQty(), false); // Identify finished BOM Product docLine.SetProductionBOM(line.GetM_Product_ID() == M_Product_ID); // log.Fine(docLine.ToString()); list.Add(docLine); } idrPL.Close(); } catch (Exception ee) { if (idrPL != null) { idrPL.Close(); idrPL = null; } log.Log(Level.SEVERE, sqlPL, ee); } } idrPP.Close(); } catch (Exception e) { if (idrPP != null) { idrPP.Close(); idrPP = null; } log.Log(Level.SEVERE, sqlPP, e); } // Return Array DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="journal"></param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MJournal journal) { MAcctSchema mSc = new MAcctSchema(GetCtx(), _C_AcctSchema_ID, null); List <DocLine> list = new List <DocLine>(); MJournalLine[] lines = journal.GetLines(false); record_Id = lines[0].GetGL_Journal_ID(); for (int i = 0; i < lines.Length; i++) { MJournalLine line = lines[i]; if (line.GetElementType() == null) { DocLine docLine = new DocLine(line, this); // -- Source Amounts docLine.SetAmount(line.GetAmtAcctDr(), line.GetAmtAcctCr()); // -- Converted Amounts // no need to update converted amount here //docLine.SetConvertedAmt(_C_AcctSchema_ID, line.GetAmtAcctDr(), line.GetAmtAcctCr()); // -- Account MAccount account = line.GetAccount(); docLine.SetAccount(account); // -- Quantity docLine.SetQty(line.GetQty(), false); // -- Date docLine.SetDateAcct(journal.GetDateAcct()); // -- Organization of Line was set to Org of Account list.Add(docLine); } else { string sql = "SELECT * FROM GL_LineDimension WHERE GL_JournalLine_ID=" + line.Get_ID(); DataSet ds = DB.ExecuteDataset(sql); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int m = 0; m < ds.Tables[0].Rows.Count; m++) { DataRow dr = ds.Tables[0].Rows[m]; X_GL_LineDimension lDim = new X_GL_LineDimension(GetCtx(), dr, null); DocLine docLine = new DocLine(lDim, this); // -- Source Amounts decimal cRate = line.GetCurrencyRate(); if (cRate == 0) { cRate = 1; } decimal amtAcctCr = 0; decimal amtAcctDr = 0; //MAcctSchema mSc = new MAcctSchema(GetCtx(), _C_AcctSchema_ID, null); if (line.GetAmtSourceDr() != 0) { amtAcctDr = lDim.GetAmount() * cRate; docLine.SetAmount(amtAcctDr, 0); amtAcctDr = Decimal.Round(amtAcctDr, mSc.GetStdPrecision()); } else { amtAcctCr = lDim.GetAmount() * cRate; docLine.SetAmount(0, amtAcctCr); amtAcctCr = Decimal.Round(amtAcctCr, mSc.GetStdPrecision()); } // -- Converted Amounts // no need to update converted amount here //docLine.SetConvertedAmt(_C_AcctSchema_ID, amtAcctDr, amtAcctCr); // -- Account MAccount account = line.GetAccount(); docLine.SetAccount(account); // -- Quantity docLine.SetQty(lDim.GetQty(), false); // -- Date docLine.SetDateAcct(journal.GetDateAcct()); // -- User Dimension docLine = SetUserDimension(lDim, docLine); // -- Organization of Line was set to Org of Account list.Add(docLine); } } } } // Return Array int size = list.Count; DocLine[] dls = new DocLine[size]; dls = list.ToArray(); return(dls); }
/// <summary> /// Create Facts (the accounting logic) for /// MMP. /// <pre> /// Production /// Inventory DR CR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Line pointer FactLine fl = null; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; // Calculate Costs Decimal?costs = null; if (line.IsProductionBOM()) { // Get BOM Cost - Sum of individual lines Decimal bomCost = Env.ZERO; for (int ii = 0; ii < _lines.Length; ii++) { DocLine line0 = _lines[ii]; if (line0.GetM_ProductionPlan_ID() != line.GetM_ProductionPlan_ID()) { continue; } if (!line0.IsProductionBOM()) { bomCost = Decimal.Add(bomCost, line0.GetProductCosts(as1, line.GetAD_Org_ID(), false)); } } costs = Decimal.Negate(bomCost); } else { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); } // Inventory DR CR fl = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs); if (fl == null) { _error = "No Costs for Line " + line.GetLine() + " - " + line; return(null); } fl.SetM_Locator_ID(line.GetM_Locator_ID()); fl.SetQty(line.GetQty()); // Cost Detail String description = line.GetDescription(); if (description == null) { description = ""; } if (line.IsProductionBOM()) { description += "(*)"; } if (!IsPosted()) { MCostDetail.CreateProduction(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, Utility.Util.GetValueOfInt(costs), line.GetQty().Value, description, GetTrx(), GetRectifyingProcess()); } } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }