/// <summary> /// Create Facts (the accounting logic) for /// GLJ. /// (only for the accounting scheme, it was created) /// <pre> /// account DR CR /// </pre> /// </summary> /// <param name="?"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // Other Acct Schema // need to Post GL Journal for Multiple Accounting Schema that's why commented this section //if (as1.GetC_AcctSchema_ID() != _C_AcctSchema_ID) //{ // return facts; //} // create Fact Header Fact fact = new Fact(this, as1, _PostingType); // get conversion rate from Assigned accounting schema tab - Decimal conversionRate = Util.GetValueOfDecimal(DB.ExecuteScalar(@"SELECT CurrencyRate FROM GL_AssignAcctSchema WHERE C_AcctSchema_ID = " + as1.GetC_AcctSchema_ID() + " AND GL_Journal_ID = " + record_Id, null, null)); // GLJ if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_GLJOURNAL)) { // account DR CR for (int i = 0; i < _lines.Length; i++) { // need to Post GL Journal for Multiple Accounting Schema that's why commented this condition //if (_lines[i].GetC_AcctSchema_ID() == as1.GetC_AcctSchema_ID()) //{ // set conversion rate on line, so that amount to be converted based on that multiply rate if (as1.GetC_AcctSchema_ID() != _C_AcctSchema_ID && _lines[i].GetC_Currency_ID() != as1.GetC_Currency_ID()) { conversionRate = MConversionRate.GetRate(_lines[i].GetC_Currency_ID(), as1.GetC_Currency_ID(), _lines[i].GetDateAcct(), _lines[i].GetC_ConversionType_ID(), as1.GetAD_Client_ID(), _lines[i].GetAD_Org_ID()); _lines[i].SetConversionRate(conversionRate); } else if (as1.GetC_AcctSchema_ID() != _C_AcctSchema_ID) { _lines[i].SetConversionRate(conversionRate); } fact.CreateLine(_lines[i], _lines[i].GetAccount(), _lines[i].GetC_Currency_ID(), _lines[i].GetAmtSourceDr(), _lines[i].GetAmtSourceCr()); //} } // for all lines } else { _error = "DocumentType unknown: " + GetDocumentType(); log.Log(Level.SEVERE, _error); fact = null; } // facts.Add(fact); return(facts); }
/// <summary> /// Create Facts (the accounting logic) for /// CMC. /// <pre> /// Expense /// CashExpense DR /// CashAsset CR ///Receipt /// CashAsset DR /// CashReceipt CR /// Charge /// Charge DR /// CashAsset CR /// Difference /// CashDifference DR /// CashAsset CR /// Invoice /// CashAsset DR /// CashTransfer CR /// Transfer /// BankInTransit DR /// CashAsset CR /// </pre> /// </summary> /// <param name="?"></param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header List <Fact> facts = new List <Fact>(); if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_PROFITLOSS)) { // Decimal grossAmt = getAmount(Doc.AMTTYPE_Gross); SetC_Currency_ID(GetCurrency(as1.GetC_AcctSchema_ID())); // Commitment Fact fact = new Fact(this, as1, Fact.POST_Actual); Decimal total = Env.ZERO, totalCredit = Env.ZERO, totalDebit = Env.ZERO; Decimal credit = Env.ZERO, debit = Env.ZERO; for (int i = 0; i < _lines.Length; i++) { DocLine dline = _lines[i]; MProfitLossLines line = new MProfitLossLines(GetCtx(), dline.Get_ID(), null); credit = Util.GetValueOfDecimal(dline.GetAmtAcctCr()); debit = Util.GetValueOfDecimal(dline.GetAmtAcctDr()); if (credit > 0) { totalCredit = Decimal.Add(totalCredit, credit); } if (debit > 0) { totalDebit = Decimal.Add(totalDebit, debit); } // Account MAccount expense = MAccount.Get(GetCtx(), GetAD_Client_ID(), GetAD_Org_ID(), line.GetC_AcctSchema_ID(), line.GetAccount_ID(), line.GetC_SubAcct_ID(), line.GetM_Product_ID(), line.GetC_BPartner_ID(), line.GetAD_OrgTrx_ID(), line.GetC_LocFrom_ID(), line.GetC_LocTo_ID(), line.GetC_SalesRegion_ID(), line.GetC_Project_ID(), line.GetC_Campaign_ID(), line.GetC_Activity_ID(), line.GetUser1_ID(), line.GetUser2_ID(), line.GetUserElement1_ID(), line.GetUserElement2_ID()); fact.CreateLine(dline, expense, GetCurrency(line.GetC_AcctSchema_ID()), debit, credit); } total = totalCredit - totalDebit; if (total != Env.ZERO) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT IncomeSummary_Acct FROM C_AcctSchema_GL WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); MAccount acct = MAccount.Get(GetCtx(), validComID); fact.CreateLine(null, acct, GetC_Currency_ID(), total); } //if (TotalCurrLoss != Env.ZERO) //{ // int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT C_ValidCombination_ID FROM C_ValidCombination WHERE Account_ID= ( SELECT C_ElementValue_ID FROM C_ElementValue WHERE Value='82540' AND AD_Client_ID = " + GetAD_Client_ID() + " )")); // MAccount acct = MAccount.Get(GetCtx(), validComID); // TotalCurrLoss = MConversionRate.Convert(GetCtx(), TotalCurrLoss, childCashCurrency, headerCashCurrency, GetAD_Client_ID(), GetAD_Org_ID()); // fact.CreateLine(null, acct, // GetC_Currency_ID(), (TotalCurrLoss)); //} facts.Add(fact); } return(facts); }
/// <summary> /// Create Facts (the accounting logic) for /// GLJ. /// (only for the accounting scheme, it was created) /// <pre> /// account DR CR /// </pre> /// </summary> /// <param name="?"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // Other Acct Schema if (as1.GetC_AcctSchema_ID() != _C_AcctSchema_ID) { return(facts); } // create Fact Header Fact fact = new Fact(this, as1, _PostingType); // GLJ if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_GLJOURNAL)) { // account DR CR for (int i = 0; i < _lines.Length; i++) { if (_lines[i].GetC_AcctSchema_ID() == as1.GetC_AcctSchema_ID()) { fact.CreateLine(_lines[i], _lines[i].GetAccount(), GetC_Currency_ID(), _lines[i].GetAmtSourceDr(), _lines[i].GetAmtSourceCr()); } } // for all lines } else { _error = "DocumentType unknown: " + GetDocumentType(); log.Log(Level.SEVERE, _error); fact = null; } // facts.Add(fact); return(facts); }
/// <summary> /// Update ProductPO PriceLastInv /// </summary> /// <param name="as1">accounting schema</param> private void UpdateProductPO(MAcctSchema as1) { MClientInfo ci = MClientInfo.Get(GetCtx(), as1.GetAD_Client_ID()); if (ci.GetC_AcctSchema1_ID() != as1.GetC_AcctSchema_ID()) { return; } StringBuilder sql = new StringBuilder( "UPDATE M_Product_PO po " + "SET PriceLastInv = " // select + "(SELECT currencyConvert(il.PriceActual,i.C_Currency_ID,po.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) " + "FROM C_Invoice i, C_InvoiceLine il " + "WHERE i.C_Invoice_ID=il.C_Invoice_ID" + " AND po.M_Product_ID=il.M_Product_ID AND po.C_BPartner_ID=i.C_BPartner_ID"); //jz + " AND ROWNUM=1 AND i.C_Invoice_ID=").Append(get_ID()).Append(") ") if (DataBase.DB.IsOracle()) //jz { sql.Append(" AND ROWNUM=1 "); } else { sql.Append(" AND i.UPDATED IN (SELECT MAX(i1.UPDATED) " + "FROM C_Invoice i1, C_InvoiceLine il1 " + "WHERE i1.C_Invoice_ID=il1.C_Invoice_ID" + " AND po.M_Product_ID=il1.M_Product_ID AND po.C_BPartner_ID=i1.C_BPartner_ID") .Append(" AND i1.C_Invoice_ID=").Append(Get_ID()).Append(") "); } sql.Append(" AND i.C_Invoice_ID=").Append(Get_ID()).Append(") ") // update .Append("WHERE EXISTS (SELECT * " + "FROM C_Invoice i, C_InvoiceLine il " + "WHERE i.C_Invoice_ID=il.C_Invoice_ID" + " AND po.M_Product_ID=il.M_Product_ID AND po.C_BPartner_ID=i.C_BPartner_ID" + " AND i.C_Invoice_ID=").Append(Get_ID()).Append(")"); int no = DataBase.DB.ExecuteQuery(sql.ToString(), null, GetTrx()); log.Fine("Updated=" + no); }
/// <summary> /// Update ProductPO PriceLastPO /// </summary> /// <param name="as1">accounting schema</param> private void UpdateProductPO(MAcctSchema as1) { MClientInfo ci = MClientInfo.Get(GetCtx(), as1.GetAD_Client_ID()); if (ci.GetC_AcctSchema1_ID() != as1.GetC_AcctSchema_ID()) { return; } StringBuilder sql = new StringBuilder( "UPDATE M_Product_PO po " + "SET PriceLastPO = (SELECT currencyConvert(ol.PriceActual,ol.C_Currency_ID,po.C_Currency_ID,o.DateOrdered,o.C_ConversionType_ID,o.AD_Client_ID,o.AD_Org_ID) " + "FROM C_Order o, C_OrderLine ol " + "WHERE o.C_Order_ID=ol.C_Order_ID" + " AND po.M_Product_ID=ol.M_Product_ID AND po.C_BPartner_ID=o.C_BPartner_ID"); // AND ROWNUM=1 AND o.C_Order_ID=").Append(get_ID()).Append(") ") if (DataBase.DB.IsOracle()) //jz { sql.Append(" AND ROWNUM=1 "); } else { sql.Append(" AND o.UPDATED IN (SELECT MAX(o1.UPDATED) " + "FROM C_Order o1, C_OrderLine ol1 " + "WHERE o1.C_Order_ID=ol1.C_Order_ID" + " AND po.M_Product_ID=ol1.M_Product_ID AND po.C_BPartner_ID=o1.C_BPartner_ID") .Append(" AND o1.C_Order_ID=").Append(Get_ID()).Append(") "); } sql.Append(" AND o.C_Order_ID=").Append(Get_ID()).Append(") ") .Append("WHERE EXISTS (SELECT * " + "FROM C_Order o, C_OrderLine ol " + "WHERE o.C_Order_ID=ol.C_Order_ID" + " AND po.M_Product_ID=ol.M_Product_ID AND po.C_BPartner_ID=o.C_BPartner_ID" + " AND o.C_Order_ID=").Append(Get_ID()).Append(")"); int no = DataBase.DB.ExecuteQuery(sql.ToString(), null, GetTrx()); log.Fine("Updated=" + no); }
/// <summary> /// Create Facts (the accounting logic) for /// MXP. /// <pre> /// Product PPV <difference> /// PPV_Offset <difference> /// </pre> /// </summary> /// <param name="as1"></param> /// <returns></returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // if (GetM_Product_ID() == 0 || // Nothing to do if no Product Env.Signum(Utility.Util.GetValueOfDecimal(GetQty())) == 0 || _M_InOutLine_ID == 0) // No posting if not matched to Shipment { log.Fine("No Product/Qty - M_Product_ID=" + GetM_Product_ID() + ",Qty=" + GetQty()); return(facts); } // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Purchase Order Line Decimal poCost = _oLine.GetPriceCost(); if (Env.Signum(poCost) == 0) { poCost = _oLine.GetPriceActual(); } poCost = Decimal.Multiply(poCost, Utility.Util.GetValueOfDecimal(GetQty())); // Delivered so far // Different currency if (_oLine.GetC_Currency_ID() != as1.GetC_Currency_ID()) { MOrder order = _oLine.GetParent(); Decimal rate = MConversionRate.GetRate( order.GetC_Currency_ID(), as1.GetC_Currency_ID(), order.GetDateAcct(), order.GetC_ConversionType_ID(), _oLine.GetAD_Client_ID(), _oLine.GetAD_Org_ID()); if (rate.ToString() == null) { _error = "Purchase Order not convertible - " + as1.GetName(); return(null); } poCost = Decimal.Multiply(poCost, rate); if (Env.Scale(poCost) > as1.GetCostingPrecision()) { poCost = Decimal.Round(poCost, as1.GetCostingPrecision(), MidpointRounding.AwayFromZero); } } MOrder order1 = _oLine.GetParent(); bool isReturnTrx = order1.IsReturnTrx(); log.Fine("Temp"); if (!IsPosted()) { // Create PO Cost Detail Record firs MCostDetail.CreateOrder(as1, _oLine.GetAD_Org_ID(), GetM_Product_ID(), _M_AttributeSetInstance_ID, _C_OrderLine_ID, 0, // no cost element isReturnTrx ? Decimal.Negate(poCost) : poCost, isReturnTrx ? Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty())) : Utility.Util.GetValueOfDecimal(GetQty()), // Delivered _oLine.GetDescription(), GetTrx(), GetRectifyingProcess()); } // Current Costs String costingMethod = as1.GetCostingMethod(); MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); MProductCategoryAcct pca = MProductCategoryAcct.Get(GetCtx(), product.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), GetTrx()); if (pca.GetCostingMethod() != null) { costingMethod = pca.GetCostingMethod(); } Decimal?costs = _pc.GetProductCosts(as1, GetAD_Org_ID(), costingMethod, _C_OrderLine_ID, false); // non-zero costs // No Costs yet - no PPV if (costs == null || Env.Signum(Utility.Util.GetValueOfDecimal(costs)) == 0) { _error = "Resubmit - No Costs for " + product.GetName(); log.Log(Level.SEVERE, _error); return(null); } // Difference Decimal difference = Decimal.Subtract(poCost, Utility.Util.GetValueOfDecimal(costs)); /***********************************************************************************/ //05,Sep,2011 //Special Check to restic Price varience posting in case of //AvarageInvoice Selected on product Category.Then Neglact the AverageInvoice Cost try { if (as1.IsNotPostPOVariance()) { difference = 0; } } catch (Exception ex) { log.SaveError("AccountSchemaColumnError", ex); } /***********************************************************************************/ // Nothing to post if (Env.Signum(difference) == 0) { log.Log(Level.FINE, "No Cost Difference for M_Product_ID=" + GetM_Product_ID()); facts.Add(fact); return(facts); } // Product PPV FactLine cr = fact.CreateLine(null, _pc.GetAccount(ProductCost.ACCTTYPE_P_PPV, as1), as1.GetC_Currency_ID(), difference); if (cr != null) { cr.SetQty(GetQty()); cr.SetC_BPartner_ID(_oLine.GetC_BPartner_ID()); cr.SetC_Activity_ID(_oLine.GetC_Activity_ID()); cr.SetC_Campaign_ID(_oLine.GetC_Campaign_ID()); cr.SetC_Project_ID(_oLine.GetC_Project_ID()); cr.SetC_UOM_ID(_oLine.GetC_UOM_ID()); cr.SetUser1_ID(_oLine.GetUser1_ID()); cr.SetUser2_ID(_oLine.GetUser2_ID()); } // PPV Offset FactLine dr = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_PPVOffset, as1), as1.GetC_Currency_ID(), Decimal.Negate(difference)); if (dr != null) { dr.SetQty((Decimal?)Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty()))); dr.SetC_BPartner_ID(_oLine.GetC_BPartner_ID()); dr.SetC_Activity_ID(_oLine.GetC_Activity_ID()); dr.SetC_Campaign_ID(_oLine.GetC_Campaign_ID()); dr.SetC_Project_ID(_oLine.GetC_Project_ID()); dr.SetC_UOM_ID(_oLine.GetC_UOM_ID()); dr.SetUser1_ID(_oLine.GetUser1_ID()); dr.SetUser2_ID(_oLine.GetUser2_ID()); } // facts.Add(fact); return(facts); }
/// <summary> /// Create Invoice Line from Shipment /// </summary> /// <param name="order">order</param> /// <param name="ship">shipment header</param> /// <param name="sLine">shipment line</param> private void CreateLine(MOrder order, MInOut ship, MInOutLine sLine) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); int _CountVA009 = Env.IsModuleInstalled("VA009_") ? 1 : 0; if (_CountVA009 > 0) { int _PaymentMethod_ID = order.GetVA009_PaymentMethod_ID(); // during consolidation, payment method need to set that is defined on selected business partner. // If not defined on BP then it will set from order // during sale cycle -- VA009_PaymentMethod_ID // during purchase cycle -- VA009_PO_PaymentMethod_ID int bpPamentMethod_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT " + (order.IsSOTrx() ? " VA009_PaymentMethod_ID " : " VA009_PO_PaymentMethod_ID ") + @" FROM C_BPartner WHERE C_BPartner_ID = " + order.GetC_BPartner_ID(), null, Get_Trx())); if (_ConsolidateDocument && bpPamentMethod_ID != 0) { _PaymentMethod_ID = bpPamentMethod_ID; } if (_PaymentMethod_ID > 0) { _invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } int _CountVA026 = Env.IsModuleInstalled("VA026_") ? 1 : 0; if (_CountVA026 > 0) { _invoice.SetVA026_LCDetail_ID(order.GetVA026_LCDetail_ID()); } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (_invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { _invoice.SetC_IncoTerm_ID(order.GetC_IncoTerm_ID()); } if (Env.IsModuleInstalled("VA077_")) { //.setva077 _invoice.Set_Value("VA077_AdditionalAnnualCharge", order.Get_Value("VA077_AdditionalAnnualCharge")); _invoice.Set_Value("VA077_ChangeStartDate", order.Get_Value("VA077_ChangeStartDate")); _invoice.Set_Value("VA077_ContractCPEndDate", order.Get_Value("VA077_ContractCPEndDate")); _invoice.Set_Value("VA077_ContractCPStartDate", order.Get_Value("VA077_ContractCPStartDate")); _invoice.Set_Value("VA077_HistoricContractDate", order.Get_Value("VA077_HistoricContractDate")); _invoice.Set_Value("VA077_IsLegalEntity", order.Get_Value("VA077_IsLegalEntity")); _invoice.Set_Value("VA077_MarginPercent", order.Get_Value("VA077_MarginPercent")); _invoice.Set_Value("VA077_NewAnnualContractTotal", order.Get_Value("VA077_NewAnnualContractTotal")); _invoice.Set_Value("VA077_OldAnnualContractTotal", order.Get_Value("VA077_OldAnnualContractTotal")); _invoice.Set_Value("VA077_PartialAmtCatchUp", order.Get_Value("VA077_PartialAmtCatchUp")); _invoice.Set_Value("VA077_SalesCoWorker", order.Get_Value("VA077_SalesCoWorker")); _invoice.Set_Value("VA077_SalesCoWorkerPer", order.Get_Value("VA077_SalesCoWorkerPer")); _invoice.Set_Value("VA077_TotalMarginAmt", order.Get_Value("VA077_TotalMarginAmt")); _invoice.Set_Value("VA077_TotalPurchaseAmt", order.Get_Value("VA077_TotalPurchaseAmt")); _invoice.Set_Value("VA077_TotalSalesAmt", order.Get_Value("VA077_TotalSalesAmt")); } if (!_invoice.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not create Invoice (s). " + pp.GetName()); } throw new Exception("Could not create Invoice (s)"); } } #region Comment Create Shipment Comment Line // Create Shipment Comment Line //if (_ship == null // || _ship.GetM_InOut_ID() != ship.GetM_InOut_ID()) //{ // MDocType dt = MDocType.Get(GetCtx(), ship.GetC_DocType_ID()); // if (_bp == null || _bp.GetC_BPartner_ID() != ship.GetC_BPartner_ID()) // { // _bp = new MBPartner(GetCtx(), ship.GetC_BPartner_ID(), Get_TrxName()); // } // // Reference: Delivery: 12345 - 12.12.12 // MClient client = MClient.Get(GetCtx(), order.GetAD_Client_ID()); // String AD_Language = client.GetAD_Language(); // if (client.IsMultiLingualDocument() && _bp.GetAD_Language() != null) // { // AD_Language = _bp.GetAD_Language(); // } // if (AD_Language == null) // { // // MessageBox.Show("Set base Language"); // //AD_Language = Language.getBaseAD_Language(); // } // //java.text.SimpleDateFormat format = DisplayType.getDateFormat // // (DisplayType.Date, Language.getLanguage(AD_Language)); // //String reference = dt.GetPrintName(_bp.GetAD_Language()) // // + ": " + ship.GetDocumentNo() // // + " - " + format.format(ship.GetMovementDate()); // String reference = dt.GetPrintName(_bp.GetAD_Language()) // + ": " + ship.GetDocumentNo() // + " - " + ship.GetMovementDate(); // _ship = ship; // // // MInvoiceLine line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(reference); // line.SetLine(_line + sLine.GetLine() - 2); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line (sh)"); // } // // Optional Ship Address if not Bill Address // if (order.GetBill_Location_ID() != ship.GetC_BPartner_Location_ID()) // { // MLocation addr = MLocation.GetBPLocation(GetCtx(), ship.GetC_BPartner_Location_ID(), null); // line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(addr.ToString()); // line.SetLine(_line + sLine.GetLine() - 1); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line 2 (sh)"); // } // } //} #endregion // MInvoiceLine line1 = new MInvoiceLine(_invoice); line1.SetShipLine(sLine); line1.SetQtyEntered(sLine.GetQtyEntered()); line1.SetQtyInvoiced(sLine.GetMovementQty()); line1.SetLine(_line + sLine.GetLine()); line1.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); if (sLine.GetA_Asset_ID() > 0) { line1.SetA_Asset_ID(sLine.GetA_Asset_ID()); if (line1.Get_ColumnIndex("VAFAM_AssetCost") > 0) { int PAcctSchema_ID = 0; int pCurrency_ID = 0; MAcctSchema as1 = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema(); if (as1 != null) { PAcctSchema_ID = as1.GetC_AcctSchema_ID(); pCurrency_ID = as1.GetC_Currency_ID(); } decimal LineNetAmt = Decimal.Multiply(line1.GetPriceActual(), line1.GetQtyEntered()); decimal AssetCost = GetAssetCost(sLine.GetA_Asset_ID(), sLine.GetM_Product_ID(), PAcctSchema_ID); AssetCost = Decimal.Multiply(AssetCost, line1.GetQtyEntered()); if (LineNetAmt > 0) { LineNetAmt = MConversionRate.Convert(GetCtx(), LineNetAmt, _invoice.GetC_Currency_ID(), pCurrency_ID, _invoice.GetAD_Client_ID(), _invoice.GetAD_Org_ID()); } decimal Diff = LineNetAmt - AssetCost; line1.Set_Value("VAFAM_AssetCost", AssetCost); line1.Set_Value("VAFAM_Difference", Diff); } } if (Env.IsModuleInstalled("VA077_")) { //invoice line line1.Set_Value("VA077_CNAutodesk", sLine.Get_Value("VA077_CNAutodesk")); line1.Set_Value("VA077_Duration", sLine.Get_Value("VA077_Duration")); line1.Set_Value("VA077_MarginAmt", sLine.Get_Value("VA077_MarginAmt")); line1.Set_Value("VA077_MarginPercent", sLine.Get_Value("VA077_MarginPercent")); line1.Set_Value("VA077_OldSN", sLine.Get_Value("VA077_OldSN")); line1.Set_Value("VA077_ProductInfo", sLine.Get_Value("VA077_ProductInfo")); line1.Set_Value("VA077_PurchasePrice", sLine.Get_Value("VA077_PurchasePrice")); line1.Set_Value("VA077_RegEmail", sLine.Get_Value("VA077_RegEmail")); line1.Set_Value("VA077_SerialNo", sLine.Get_Value("VA077_SerialNo")); line1.Set_Value("VA077_UpdateFromVersn", sLine.Get_Value("VA077_UpdateFromVersn")); line1.Set_Value("VA077_UserRef_ID", sLine.Get_Value("VA077_UserRef_ID")); line1.Set_Value("VA077_EndDate", sLine.Get_Value("VA077_EndDate")); line1.Set_Value("VA077_StartDate", sLine.Get_Value("VA077_StartDate")); } if (!line1.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not create Invoice Line (s). " + pp.GetName()); } throw new Exception("Could not create Invoice Line (s)"); } // Link sLine.SetIsInvoiced(true); if (!sLine.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not update Shipment Line. " + pp.GetName()); } throw new Exception("Could not update Shipment Line"); } log.Fine(line1.ToString()); }
/// <summary> /// Create Facts (the accounting logic) for /// CMC. /// <pre> /// Expense /// CashExpense DR /// CashAsset CR ///Receipt /// CashAsset DR /// CashReceipt CR /// Charge /// Charge DR /// CashAsset CR /// Difference /// CashDifference DR /// CashAsset CR /// Invoice /// CashAsset DR /// CashTransfer CR /// Transfer /// BankInTransit DR /// CashAsset CR /// </pre> /// </summary> /// <param name="?"></param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header List <Fact> facts = new List <Fact>(); if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_PROFITLOSS)) { //Change By mohit // Get Assigned Accounting Schemas based on organization MProfitLossLines PLossline = new MProfitLossLines(GetCtx(), _lines[0].Get_ID(), null); MProfitLoss PLoss = new MProfitLoss(GetCtx(), PLossline.GetC_ProfitLoss_ID(), null); MAcctSchema HeaderAcctSchema = new MAcctSchema(GetCtx(), Util.GetValueOfInt(PLoss.Get_Value("C_AcctSchema_ID")), null); List <int> _ListAcctSch = new List <int>(); // Profit & Loss account shall be posted only in accounting schema selected on header (By Ashish - discussed with Mukesh sir) //_ListAcctSch = GetAcctSchemas(PLoss.GetAD_Org_ID()); _ListAcctSch.Add(HeaderAcctSchema.GetC_AcctSchema_ID()); if (_ListAcctSch.Count > 0) { int CurrencyType_ID = GetDefaultConversionType(GetAD_Client_ID(), GetAD_Org_ID()); for (int asch = 0; asch < _ListAcctSch.Count; asch++) { MAcctSchema AccountingSchema = new MAcctSchema(GetCtx(), _ListAcctSch[asch], null); // Decimal grossAmt = getAmount(Doc.AMTTYPE_Gross); SetC_Currency_ID(GetCurrency(AccountingSchema.GetC_AcctSchema_ID())); // Commitment Fact fact = new Fact(this, AccountingSchema, Fact.POST_Actual); Decimal total = Env.ZERO, totalCredit = Env.ZERO, totalDebit = Env.ZERO; Decimal credit = Env.ZERO, debit = Env.ZERO; for (int i = 0; i < _lines.Length; i++) { DocLine dline = _lines[i]; MProfitLossLines line = new MProfitLossLines(GetCtx(), dline.Get_ID(), null); if (Util.GetValueOfInt(HeaderAcctSchema.GetC_Currency_ID()) == Util.GetValueOfInt(AccountingSchema.GetC_Currency_ID())) { credit = Util.GetValueOfDecimal(dline.GetAmtSourceCr()); debit = Util.GetValueOfDecimal(dline.GetAmtSourceDr()); } else { credit = MConversionRate.Convert(GetCtx(), Util.GetValueOfDecimal(dline.GetAmtSourceCr()), HeaderAcctSchema.GetC_Currency_ID(), AccountingSchema.GetC_Currency_ID(), PLoss.GetDateAcct(), CurrencyType_ID, GetAD_Client_ID(), GetAD_Org_ID()); debit = MConversionRate.Convert(GetCtx(), Util.GetValueOfDecimal(dline.GetAmtSourceDr()), HeaderAcctSchema.GetC_Currency_ID(), AccountingSchema.GetC_Currency_ID(), PLoss.GetDateAcct(), CurrencyType_ID, GetAD_Client_ID(), GetAD_Org_ID()); Util.GetValueOfDecimal(dline.GetAmtAcctDr()); } if (credit > 0) { totalCredit = Decimal.Add(totalCredit, credit); } if (debit > 0) { totalDebit = Decimal.Add(totalDebit, debit); } // Account MAccount expense = MAccount.Get(GetCtx(), GetAD_Client_ID(), GetAD_Org_ID(), AccountingSchema.GetC_AcctSchema_ID(), line.GetAccount_ID(), line.GetC_SubAcct_ID(), line.GetM_Product_ID(), line.GetC_BPartner_ID(), line.GetAD_OrgTrx_ID(), line.GetC_LocFrom_ID(), line.GetC_LocTo_ID(), line.GetC_SalesRegion_ID(), line.GetC_Project_ID(), line.GetC_Campaign_ID(), line.GetC_Activity_ID(), line.GetUser1_ID(), line.GetUser2_ID(), line.GetUserElement1_ID(), line.GetUserElement2_ID(), line.GetUserElement3_ID(), line.GetUserElement4_ID(), line.GetUserElement5_ID(), line.GetUserElement6_ID(), line.GetUserElement7_ID(), line.GetUserElement8_ID(), line.GetUserElement9_ID()); fact.CreateLine(dline, expense, GetCurrency(AccountingSchema.GetC_AcctSchema_ID()), debit, credit); } total = totalCredit - totalDebit; if (total != Env.ZERO) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT IncomeSummary_Acct FROM C_AcctSchema_GL WHERE C_AcctSchema_ID=" + AccountingSchema.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); MAccount acct = MAccount.Get(GetCtx(), validComID); fact.CreateLine(null, acct, GetC_Currency_ID(), total); } //if (TotalCurrLoss != Env.ZERO) //{ // int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT C_ValidCombination_ID FROM C_ValidCombination WHERE Account_ID= ( SELECT C_ElementValue_ID FROM C_ElementValue WHERE Value='82540' AND AD_Client_ID = " + GetAD_Client_ID() + " )")); // MAccount acct = MAccount.Get(GetCtx(), validComID); // TotalCurrLoss = MConversionRate.Convert(GetCtx(), TotalCurrLoss, childCashCurrency, headerCashCurrency, GetAD_Client_ID(), GetAD_Org_ID()); // fact.CreateLine(null, acct, // GetC_Currency_ID(), (TotalCurrLoss)); //} facts.Add(fact); } } } return(facts); }
/// <summary> /// Perform Process. /// - Fill Table with QtyOnHand for Warehouse and Valuation Date /// - Perform Price Calculations /// </summary> /// <returns>message</returns> protected override String DoIt() { log.Info("M_Warehouse_ID=" + _M_Warehouse_ID + ",C_Currency_ID=" + _C_Currency_ID + ",DateValue=" + _DateValue + ",M_PriceList_Version_ID=" + _M_PriceList_Version_ID + ",M_CostElement_ID=" + _M_CostElement_ID); MWarehouse wh = MWarehouse.Get(GetCtx(), _M_Warehouse_ID); MClient c = MClient.Get(GetCtx(), wh.GetAD_Client_ID()); MAcctSchema mas = c.GetAcctSchema(); // Delete (just to be sure) StringBuilder sql = new StringBuilder("DELETE FROM T_InventoryValue WHERE AD_PInstance_ID="); sql.Append(GetAD_PInstance_ID()); int no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); MPInstance instance = new MPInstance(GetCtx(), GetAD_PInstance_ID(), null); DateTime Createddate = instance.GetCreated(); Createddate = Createddate.AddHours(-1); string qry = "select MAX(AD_PINSTANCE_ID) from AD_PINSTANCE WHERE AD_Process_ID=" + instance.GetAD_Process_ID() + " AND created< TO_Date('" + Createddate.ToString("MM/dd/yyyy HH:mm:ss") + "', 'MM-DD-YYYY HH24:MI:SS')"; int MaxInstance_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry, null, null)); int no1 = DB.ExecuteQuery("DELETE FROM T_InventoryValue WHERE AD_PInstance_ID <=" + MaxInstance_ID); // Insert Standard Costs sql = new StringBuilder("INSERT INTO T_InventoryValue " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID," + " AD_Client_ID, AD_Org_ID, CostStandard) " + "SELECT ").Append(GetAD_PInstance_ID()) .Append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID," + " w.AD_Client_ID, w.AD_Org_ID, c.CurrentCostPrice " + "FROM M_Warehouse w" + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)" + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)" + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID))" + " INNER JOIN M_CostElement ce ON (c.M_CostElement_ID=ce.M_CostElement_ID AND ce.CostingMethod='S' AND ce.CostElementType='M') " + "WHERE w.M_Warehouse_ID=").Append(_M_Warehouse_ID); int noInsertStd = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("Inserted Std=" + noInsertStd); if (noInsertStd == 0) { return("No Standard Costs found"); } // Insert addl Costs int noInsertCost = 0; if (_M_CostElement_ID != 0) { sql = new StringBuilder("INSERT INTO T_InventoryValue " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID," + " AD_Client_ID, AD_Org_ID, CostStandard, Cost, M_CostElement_ID) " + "SELECT ").Append(GetAD_PInstance_ID()) .Append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID," + " w.AD_Client_ID, w.AD_Org_ID, 0, c.CurrentCostPrice, c.M_CostElement_ID " + "FROM M_Warehouse w" + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)" + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)" + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) " + "WHERE w.M_Warehouse_ID=").Append(_M_Warehouse_ID) .Append(" AND c.M_CostElement_ID=").Append(_M_CostElement_ID) .Append(" AND NOT EXISTS (SELECT * FROM T_InventoryValue iv " + "WHERE iv.AD_PInstance_ID=").Append(GetAD_PInstance_ID()) .Append(" AND iv.M_Warehouse_ID=w.M_Warehouse_ID" + " AND iv.M_Product_ID=c.M_Product_ID" + " AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID)"); noInsertCost = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("Inserted Cost=" + noInsertCost); // Update Std Cost Records sql = new StringBuilder("UPDATE T_InventoryValue iv " + "SET (Cost, M_CostElement_ID)=" + "(SELECT c.CurrentCostPrice, c.M_CostElement_ID " + "FROM M_Warehouse w" + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)" + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)" + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID" + " AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) " + "WHERE c.M_CostElement_ID=" + _M_CostElement_ID + " AND w.M_Warehouse_ID=iv.M_Warehouse_ID" + " AND c.M_Product_ID=iv.M_Product_ID" + " AND c.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID AND rownum=1 AND w.m_warehouse_ID=" + _M_Warehouse_ID + ") " + "WHERE EXISTS (SELECT * FROM T_InventoryValue ivv " + "WHERE ivv.AD_PInstance_ID=" + GetAD_PInstance_ID() + " AND ivv.M_CostElement_ID IS NULL) AND iv.AD_PInstance_ID =" + GetAD_PInstance_ID()); int noUpdatedCost = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("Updated Cost=" + noUpdatedCost); } if ((noInsertStd + noInsertCost) == 0) { return("No Costs found"); } // Update Constants // YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format // String myDate = _DateValue.ToString(); sql = new StringBuilder("UPDATE T_InventoryValue SET ") //.Append("DateValue=To_Date('").Append(myDate.Substring(0,10)) //.Append("23:59:59','MM-DD-YYYY HH24:MI:SS'),") .Append("DateValue=").Append(GlobalVariable.TO_DATE(_DateValue, true)).Append(",") .Append("M_PriceList_Version_ID=").Append(_M_PriceList_Version_ID).Append(",") .Append("C_Currency_ID=").Append(_C_Currency_ID); if (_M_CostElement_ID != 0) { sql.Append(",").Append("M_CostElement_ID=").Append(_M_CostElement_ID); } no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("Constants=" + no); // Get current QtyOnHand with ASI sql = new StringBuilder("UPDATE T_InventoryValue iv SET QtyOnHand = " + "(SELECT SUM(QtyOnHand) FROM M_Storage s" + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) " + "WHERE iv.M_Product_ID=s.M_Product_ID" + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID" + " AND iv.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID) " + "WHERE AD_PInstance_ID=").Append(GetAD_PInstance_ID()) .Append(" AND iv.M_AttributeSetInstance_ID<>0"); no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("QtHand with ASI=" + no); // Get current QtyOnHand without ASI sql = new StringBuilder("UPDATE T_InventoryValue iv SET QtyOnHand = " + "(SELECT SUM(QtyOnHand) FROM M_Storage s" + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) " + "WHERE iv.M_Product_ID=s.M_Product_ID" + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID) " + "WHERE AD_PInstance_ID=").Append(GetAD_PInstance_ID()) .Append(" AND iv.M_AttributeSetInstance_ID=0"); no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("QtHand w/o ASI=" + no); // Adjust for Valuation Date sql = new StringBuilder("UPDATE T_InventoryValue iv " + "SET QtyOnHand=" + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) " + "FROM M_Transaction t" + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) " + "WHERE t.M_Product_ID=iv.M_Product_ID" + " AND t.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID" + " AND t.MovementDate > iv.DateValue" + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) " + "WHERE iv.M_AttributeSetInstance_ID<>0"); no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("Update with ASI=" + no); // sql = new StringBuilder("UPDATE T_InventoryValue iv " + "SET QtyOnHand=" + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) " + "FROM M_Transaction t" + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) " + "WHERE t.M_Product_ID=iv.M_Product_ID" + " AND t.MovementDate > iv.DateValue" + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) " + "WHERE iv.M_AttributeSetInstance_ID=0"); no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("Update w/o ASI=" + no); // Delete Records w/o OnHand Qty sql = new StringBuilder("DELETE FROM T_InventoryValue " + "WHERE (QtyOnHand=0 OR QtyOnHand IS NULL) AND AD_PInstance_ID=").Append(GetAD_PInstance_ID()); int noQty = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("NoQty Deleted=" + noQty); // Update Prices no = DataBase.DB.ExecuteQuery("UPDATE T_InventoryValue iv " + "SET PricePO = " + "(SELECT MAX(currencyConvert (po.PriceList,po.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, po.AD_Client_ID,po.AD_Org_ID))" + " FROM M_Product_PO po WHERE po.M_Product_ID=iv.M_Product_ID" + " AND po.IsCurrentVendor='Y'), " + "PriceList = " + "(SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)" + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp" + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID" + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID" + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), " + "PriceStd = " + "(SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)" + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp" + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID" + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID" + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), " + "PriceLimit = " + "(SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)" + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp" + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID" + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID" + " AND plv.M_PriceList_ID=pl.M_PriceList_ID)" , null, Get_TrxName()); String msg = ""; if (no == 0) { msg = "No Prices"; } // Convert if different Currency if (mas.GetC_Currency_ID() != _C_Currency_ID) { sql = new StringBuilder("UPDATE T_InventoryValue iv " + "SET CostStandard= " + "(SELECT currencyConvert(iv.CostStandard,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) " + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + mas.GetC_AcctSchema_ID() + ")," + " Cost= " + "(SELECT currencyConvert(iv.Cost,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) " + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + mas.GetC_AcctSchema_ID() + ") " + "WHERE AD_PInstance_ID=" + GetAD_PInstance_ID()); no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); log.Fine("Convered=" + no); } // Update Values no = DataBase.DB.ExecuteQuery("UPDATE T_InventoryValue SET " + "PricePOAmt = QtyOnHand * PricePO, " + "PriceListAmt = QtyOnHand * PriceList, " + "PriceStdAmt = QtyOnHand * PriceStd, " + "PriceLimitAmt = QtyOnHand * PriceLimit, " + "CostStandardAmt = QtyOnHand * CostStandard, " + "CostAmt = QtyOnHand * Cost " + "WHERE AD_PInstance_ID=" + GetAD_PInstance_ID(), null, Get_TrxName()); log.Fine("Calculation=" + no); // return(msg); }
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> /// 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); }
/** * Get Charge Account * @param C_Charge_ID charge * @param as account schema * @param amount amount for expense(+)/revenue(-) * @return Charge Account or null */ public static MAccount GetAccount(int C_Charge_ID, MAcctSchema aSchema, Decimal amount) { if (C_Charge_ID == 0 || aSchema == null) { return(null); } int acct_index = 1; // Expense (positive amt) if (amount < 0) { acct_index = 2; // Revenue (negative amt) } String sql = "SELECT CH_Expense_Acct, CH_Revenue_Acct FROM C_Charge_Acct WHERE C_Charge_ID=" + C_Charge_ID + " AND C_AcctSchema_ID=" + aSchema.GetC_AcctSchema_ID(); int Account_ID = 0; IDataReader dr = null; try { // PreparedStatement pstmt = DataBase.prepareStatement(sql, null); // pstmt.setInt (1, C_Charge_ID); // pstmt.setInt (2, aSchema.getC_AcctSchema_ID()); // ResultSet dr = pstmt.executeQuery(); dr = DB.ExecuteReader(sql, null, null); if (dr.Read()) { Account_ID = Util.GetValueOfInt(dr[acct_index - 1].ToString()); } dr.Close(); //pstmt.close(); } catch (SqlException e) { if (dr != null) { dr.Close(); } _log.Log(Level.SEVERE, sql, e); return(null); } finally { if (dr != null) { dr.Close(); } } // No account if (Account_ID == 0) { _log.Severe("NO account for C_Charge_ID=" + C_Charge_ID); return(null); } // Return Account MAccount acct = MAccount.Get(aSchema.GetCtx(), Account_ID); return(acct); } // getAccount
/** * Create Invoice Line from Shipment * @param order order * @param ship shipment header * @param sLine shipment line */ private void CreateLine(MOrder order, MInOut ship, MInOutLine sLine) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); //---------------------------Column Added by Anuj------------------ int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { int _PaymentMethod_ID = order.GetVA009_PaymentMethod_ID(); if (_PaymentMethod_ID > 0) { _invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } //-----------------Column Added by Anuj------------------ int _CountVA026 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA026_' AND IsActive = 'Y'")); if (_CountVA026 > 0) { _invoice.SetVA026_LCDetail_ID(order.GetVA026_LCDetail_ID()); } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (_invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { _invoice.SetC_IncoTerm_ID(order.GetC_IncoTerm_ID()); } if (!_invoice.Save()) { throw new Exception("Could not create Invoice (s)"); } } #region Comment Create Shipment Comment Line // Create Shipment Comment Line //if (_ship == null // || _ship.GetM_InOut_ID() != ship.GetM_InOut_ID()) //{ // MDocType dt = MDocType.Get(GetCtx(), ship.GetC_DocType_ID()); // if (_bp == null || _bp.GetC_BPartner_ID() != ship.GetC_BPartner_ID()) // { // _bp = new MBPartner(GetCtx(), ship.GetC_BPartner_ID(), Get_TrxName()); // } // // Reference: Delivery: 12345 - 12.12.12 // MClient client = MClient.Get(GetCtx(), order.GetAD_Client_ID()); // String AD_Language = client.GetAD_Language(); // if (client.IsMultiLingualDocument() && _bp.GetAD_Language() != null) // { // AD_Language = _bp.GetAD_Language(); // } // if (AD_Language == null) // { // // MessageBox.Show("Set base Language"); // //AD_Language = Language.getBaseAD_Language(); // } // //java.text.SimpleDateFormat format = DisplayType.getDateFormat // // (DisplayType.Date, Language.getLanguage(AD_Language)); // //String reference = dt.GetPrintName(_bp.GetAD_Language()) // // + ": " + ship.GetDocumentNo() // // + " - " + format.format(ship.GetMovementDate()); // String reference = dt.GetPrintName(_bp.GetAD_Language()) // + ": " + ship.GetDocumentNo() // + " - " + ship.GetMovementDate(); // _ship = ship; // // // MInvoiceLine line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(reference); // line.SetLine(_line + sLine.GetLine() - 2); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line (sh)"); // } // // Optional Ship Address if not Bill Address // if (order.GetBill_Location_ID() != ship.GetC_BPartner_Location_ID()) // { // MLocation addr = MLocation.GetBPLocation(GetCtx(), ship.GetC_BPartner_Location_ID(), null); // line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(addr.ToString()); // line.SetLine(_line + sLine.GetLine() - 1); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line 2 (sh)"); // } // } //} #endregion // MInvoiceLine line1 = new MInvoiceLine(_invoice); line1.SetShipLine(sLine); line1.SetQtyEntered(sLine.GetQtyEntered()); line1.SetQtyInvoiced(sLine.GetMovementQty()); line1.SetLine(_line + sLine.GetLine()); line1.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); if (sLine.GetA_Asset_ID() > 0) { line1.SetA_Asset_ID(sLine.GetA_Asset_ID()); if (line1.Get_ColumnIndex("VAFAM_AssetCost") > 0) { int PAcctSchema_ID = 0; int pCurrency_ID = 0; MAcctSchema as1 = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema(); if (as1 != null) { PAcctSchema_ID = as1.GetC_AcctSchema_ID(); pCurrency_ID = as1.GetC_Currency_ID(); } decimal LineNetAmt = Decimal.Multiply(line1.GetPriceActual(), line1.GetQtyEntered()); decimal AssetCost = GetAssetCost(sLine.GetA_Asset_ID(), sLine.GetM_Product_ID(), PAcctSchema_ID); AssetCost = Decimal.Multiply(AssetCost, line1.GetQtyEntered()); if (LineNetAmt > 0) { LineNetAmt = MConversionRate.Convert(GetCtx(), LineNetAmt, _invoice.GetC_Currency_ID(), pCurrency_ID, _invoice.GetAD_Client_ID(), _invoice.GetAD_Org_ID()); } decimal Diff = LineNetAmt - AssetCost; line1.Set_Value("VAFAM_AssetCost", AssetCost); line1.Set_Value("VAFAM_Difference", Diff); } } if (!line1.Save()) { throw new Exception("Could not create Invoice Line (s)"); } // Link sLine.SetIsInvoiced(true); if (!sLine.Save()) { throw new Exception("Could not update Shipment Line"); } log.Fine(line1.ToString()); }
} // copyDefault /// <summary> /// Create Account /// </summary> /// <param name="targetAS">target AS</param> /// <param name="sourceAcct">source account</param> /// <returns>target account</returns> private MAccount CreateAccount(MAcctSchema targetAS, MAccount sourceAcct) { int AD_Client_ID = targetAS.GetAD_Client_ID(); int C_AcctSchema_ID = targetAS.GetC_AcctSchema_ID(); // int AD_Org_ID = 0; int Account_ID = 0; int C_SubAcct_ID = 0; int M_Product_ID = 0; int C_BPartner_ID = 0; int AD_OrgTrx_ID = 0; int C_LocFrom_ID = 0; int C_LocTo_ID = 0; int C_SalesRegion_ID = 0; int C_Project_ID = 0; int C_Campaign_ID = 0; int C_Activity_ID = 0; int User1_ID = 0; int User2_ID = 0; int UserElement1_ID = 0; int UserElement2_ID = 0; // // Active Elements MAcctSchemaElement[] elements = targetAS.GetAcctSchemaElements(); for (int i = 0; i < elements.Length; i++) { MAcctSchemaElement ase = elements[i]; String elementType = ase.GetElementType(); // if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) { AD_Org_ID = sourceAcct.GetAD_Org_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Account)) { Account_ID = sourceAcct.GetAccount_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) { C_SubAcct_ID = sourceAcct.GetC_SubAcct_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) { C_BPartner_ID = sourceAcct.GetC_BPartner_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Product)) { M_Product_ID = sourceAcct.GetM_Product_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) { C_Activity_ID = sourceAcct.GetC_Activity_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) { C_LocFrom_ID = sourceAcct.GetC_LocFrom_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) { C_LocTo_ID = sourceAcct.GetC_LocTo_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) { C_Campaign_ID = sourceAcct.GetC_Campaign_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) { AD_OrgTrx_ID = sourceAcct.GetAD_OrgTrx_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Project)) { C_Project_ID = sourceAcct.GetC_Project_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) { C_SalesRegion_ID = sourceAcct.GetC_SalesRegion_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) { User1_ID = sourceAcct.GetUser1_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) { User2_ID = sourceAcct.GetUser2_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserElement1)) { UserElement1_ID = sourceAcct.GetUserElement1_ID(); } else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserElement2)) { UserElement2_ID = sourceAcct.GetUserElement2_ID(); } // No UserElement } // return(MAccount.Get(GetCtx(), AD_Client_ID, AD_Org_ID, C_AcctSchema_ID, Account_ID, C_SubAcct_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SalesRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, UserElement1_ID, UserElement2_ID)); } // createAccount
/// <summary> /// Create Facts (the accounting logic) for /// CMB. /// <pre> /// BankAsset DR CR (Statement) /// BankInTransit DR CR (Payment) /// Charge DR (Charge) /// Interest DR CR (Interest) /// </pre> /// </summary> /// <param name="as1"></param> /// <returns></returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); // Header -- there may be different currency amounts FactLine fl = null; int AD_Org_ID = GetBank_Org_ID(); // Bank Account Org bool addPost = false; //Check For Module Tuple <String, String, String> aInfo = null; if (Env.HasModulePrefix("ED008_", out aInfo)) { addPost = true; } else { addPost = false; } // Posting Work Done For ED008 Module if (addPost == true) { for (int i = 0; i < _lines.Length; i++) { DocLine_Bank line = (DocLine_Bank)_lines[i]; int C_BPartner_ID = line.GetC_BPartner_ID(); int C_Payment_ID = line.GetC_Payment_ID(); // BankAsset DR CR (Statement) fl = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_BankAsset, as1), line.GetC_Currency_ID(), line.GetStmtAmt()); if (fl != null && AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } if (fl != null && C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } // BankInTransit DR CR (Payment) MAccount acct = null; string tenderType = Util.GetValueOfString(DB.ExecuteScalar("SELECT tendertype FROM C_Payment WHERE C_Payment_ID=" + C_Payment_ID + " AND AD_Client_ID = " + GetAD_Client_ID())); // Tender Type RIBA if ("R".Equals(tenderType)) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RIBA_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=" + GetC_BankAccount_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RIBA_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } } // Tender Type MAV else if ("M".Equals(tenderType)) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_MAV_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=" + GetC_BankAccount_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_MAV_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } } // Tender Type RID else if ("I".Equals(tenderType)) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RID_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=" + GetC_BankAccount_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RID_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } } else { acct = GetAccount(Doc.ACCTTYPE_BankInTransit, as1); } fl = fact.CreateLine(line, acct, line.GetC_Currency_ID(), Decimal.Negate(line.GetTrxAmt())); if (fl != null) { if (C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } if (AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } else { fl.SetAD_Org_ID(line.GetAD_Org_ID(true)); // from payment } } // Charge DR (Charge) fl = fact.CreateLine(line, line.GetChargeAccount(as1, Decimal.Negate(line.GetChargeAmt())), line.GetC_Currency_ID(), Decimal.Negate(line.GetChargeAmt()), null); if (fl != null && C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } // Interest DR CR (Interest) if (Env.Signum(line.GetInterestAmt()) < 0) { fl = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_InterestExp, as1), GetAccount(Doc.ACCTTYPE_InterestExp, as1), line.GetC_Currency_ID(), Decimal.Negate(line.GetInterestAmt())); } else { fl = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_InterestRev, as1), GetAccount(Doc.ACCTTYPE_InterestRev, as1), line.GetC_Currency_ID(), Decimal.Negate(line.GetInterestAmt())); } if (fl != null && C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } } } // Default Posting Logic else { // Lines for (int i = 0; i < _lines.Length; i++) { DocLine_Bank line = (DocLine_Bank)_lines[i]; int C_BPartner_ID = line.GetC_BPartner_ID(); // BankAsset DR CR (Statement) fl = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_BankAsset, as1), line.GetC_Currency_ID(), line.GetStmtAmt()); if (fl != null && AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } if (fl != null && C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } // BankInTransit DR CR (Payment) fl = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_BankInTransit, as1), line.GetC_Currency_ID(), Decimal.Negate(line.GetTrxAmt())); if (fl != null) { if (C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } if (AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } else { fl.SetAD_Org_ID(line.GetAD_Org_ID(true)); // from payment } } // Charge DR (Charge) fl = fact.CreateLine(line, line.GetChargeAccount(as1, Decimal.Negate(line.GetChargeAmt())), line.GetC_Currency_ID(), Decimal.Negate(line.GetChargeAmt()), null); if (fl != null && C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } // Interest DR CR (Interest) if (Env.Signum(line.GetInterestAmt()) < 0) { fl = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_InterestExp, as1), GetAccount(Doc.ACCTTYPE_InterestExp, as1), line.GetC_Currency_ID(), Decimal.Negate(line.GetInterestAmt())); } else { fl = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_InterestRev, as1), GetAccount(Doc.ACCTTYPE_InterestRev, as1), line.GetC_Currency_ID(), Decimal.Negate(line.GetInterestAmt())); } if (fl != null && C_BPartner_ID != 0) { fl.SetC_BPartner_ID(C_BPartner_ID); } // // fact.createTaxCorrection(); } } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
/// <summary> /// Create Facts (the accounting logic) for /// MXI. /// (single line) /// <pre> /// NotInvoicedReceipts DR (Receipt Org) /// InventoryClearing CR /// InvoicePV DR CR (difference) /// Commitment /// Expense CR /// Offset DR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns></returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // Nothing to do if (GetM_Product_ID() == 0 || // no Product Env.Signum(GetQty().Value) == 0 || Env.Signum(_receiptLine.GetMovementQty()) == 0) // Qty = 0 { log.Fine("No Product/Qty - M_Product_ID=" + GetM_Product_ID() + ",Qty=" + GetQty() + ",InOutQty=" + _receiptLine.GetMovementQty()); return(facts); } MMatchInv matchInv = (MMatchInv)GetPO(); // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); /** Needs to be handeled in PO Matching as1 no Receipt info * if (_pc.isService()) * { * log.Fine("Service - skipped"); * return fact; * } **/ // NotInvoicedReceipt DR // From Receipt Decimal multiplier = Math.Abs(Decimal.Round(Decimal.Divide(GetQty().Value, _receiptLine.GetMovementQty()), 12, MidpointRounding.AwayFromZero)); FactLine dr = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1), as1.GetC_Currency_ID(), Env.ONE, null); // updated below if (dr == null) { _error = "No Product Costs"; return(null); } dr.SetQty(GetQty()); // dr.setM_Locator_ID(_receiptLine.getM_Locator_ID()); // MInOut receipt = _receiptLine.getParent(); // dr.setLocationFromBPartner(receipt.getC_BPartner_Location_ID(), true); // from Loc // dr.setLocationFromLocator(_receiptLine.getM_Locator_ID(), false); // to Loc Decimal temp = dr.GetAcctBalance(); // Set AmtAcctCr/Dr from Receipt (sets also Project) if (!dr.UpdateReverseLine(MInOut.Table_ID, // Amt updated _receiptLine.GetM_InOut_ID(), _receiptLine.GetM_InOutLine_ID(), multiplier)) { _error = "Mat.Receipt not posted yet"; return(null); } log.Fine("CR - Amt(" + temp + "->" + dr.GetAcctBalance() + ") - " + dr.ToString()); // InventoryClearing CR // From Invoice MAccount expense = _pc.GetAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as1); if (_pc.IsService()) { expense = _pc.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); } Decimal LineNetAmt = _invoiceLine.GetLineNetAmt(); multiplier = Math.Abs(Decimal.Round(Decimal.Divide(GetQty().Value, _invoiceLine.GetQtyInvoiced()), 12, MidpointRounding.AwayFromZero)); if (multiplier.CompareTo(Env.ONE) != 0) { LineNetAmt = Decimal.Multiply(LineNetAmt, multiplier); } if (_pc.IsService()) { LineNetAmt = dr.GetAcctBalance(); // book out exact receipt amt } FactLine cr = null; if (as1.IsAccrual()) { cr = fact.CreateLine(null, expense, as1.GetC_Currency_ID(), null, LineNetAmt); // updated below if (cr == null) { log.Fine("Line Net Amt=0 - M_Product_ID=" + GetM_Product_ID() + ",Qty=" + GetQty() + ",InOutQty=" + _receiptLine.GetMovementQty()); facts.Add(fact); return(facts); } cr.SetQty(Decimal.Negate(GetQty().Value)); temp = cr.GetAcctBalance(); // Set AmtAcctCr/Dr from Invoice (sets also Project) if (as1.IsAccrual() && !cr.UpdateReverseLine(MInvoice.Table_ID, // Amt updated _invoiceLine.GetC_Invoice_ID(), _invoiceLine.GetC_InvoiceLine_ID(), multiplier)) { _error = "Invoice not posted yet"; return(null); } log.Fine("DR - Amt(" + temp + "->" + cr.GetAcctBalance() + ") - " + cr.ToString()); } else // Cash Acct { MInvoice invoice = _invoiceLine.GetParent(); if (as1.GetC_Currency_ID() == invoice.GetC_Currency_ID()) { LineNetAmt = MConversionRate.Convert(GetCtx(), LineNetAmt, invoice.GetC_Currency_ID(), as1.GetC_Currency_ID(), invoice.GetDateAcct(), invoice.GetC_ConversionType_ID(), invoice.GetAD_Client_ID(), invoice.GetAD_Org_ID()); } cr = fact.CreateLine(null, expense, as1.GetC_Currency_ID(), null, LineNetAmt); cr.SetQty(Decimal.Negate(Decimal.Multiply(GetQty().Value, multiplier))); } cr.SetC_Activity_ID(_invoiceLine.GetC_Activity_ID()); cr.SetC_Campaign_ID(_invoiceLine.GetC_Campaign_ID()); cr.SetC_Project_ID(_invoiceLine.GetC_Project_ID()); cr.SetC_UOM_ID(_invoiceLine.GetC_UOM_ID()); cr.SetUser1_ID(_invoiceLine.GetUser1_ID()); cr.SetUser2_ID(_invoiceLine.GetUser2_ID()); // Invoice Price Variance difference Decimal ipv = Decimal.Negate(Decimal.Add(cr.GetAcctBalance(), dr.GetAcctBalance())); if (Env.Signum(ipv) != 0) { FactLine pv = fact.CreateLine(null, _pc.GetAccount(ProductCost.ACCTTYPE_P_IPV, as1), as1.GetC_Currency_ID(), ipv); pv.SetC_Activity_ID(_invoiceLine.GetC_Activity_ID()); pv.SetC_Campaign_ID(_invoiceLine.GetC_Campaign_ID()); pv.SetC_Project_ID(_invoiceLine.GetC_Project_ID()); pv.SetC_UOM_ID(_invoiceLine.GetC_UOM_ID()); pv.SetUser1_ID(_invoiceLine.GetUser1_ID()); pv.SetUser2_ID(_invoiceLine.GetUser2_ID()); } log.Fine("IPV=" + ipv + "; Balance=" + fact.GetSourceBalance()); MInOut inOut = _receiptLine.GetParent(); bool isReturnTrx = inOut.IsReturnTrx(); if (!IsPosted()) { // Cost Detail Record - data from Expense/IncClearing (CR) record MCostDetail.CreateInvoice(as1, GetAD_Org_ID(), GetM_Product_ID(), matchInv.GetM_AttributeSetInstance_ID(), _invoiceLine.GetC_InvoiceLine_ID(), 0, // No cost element Decimal.Negate(cr.GetAcctBalance()), isReturnTrx ? Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty())) : Utility.Util.GetValueOfDecimal(GetQty()), // correcting GetDescription(), GetTrx(), GetRectifyingProcess()); // Update Costing UpdateProductInfo(as1.GetC_AcctSchema_ID(), MAcctSchema.COSTINGMETHOD_StandardCosting.Equals(as1.GetCostingMethod())); } // facts.Add(fact); /** Commitment release ****/ if (as1.IsAccrual() && as1.IsCreateCommitment()) { fact = Doc_Order.GetCommitmentRelease(as1, this, Utility.Util.GetValueOfDecimal(GetQty()), _invoiceLine.GetC_InvoiceLine_ID(), Env.ONE); if (fact == null) { return(null); } facts.Add(fact); } // Commitment return(facts); }
/// <summary> /// Create Facts (the accounting logic) for /// ARP, APP. ///<pre> /// ARP /// BankInTransit DR /// UnallocatedCash CR /// or Charge/C_Prepayment /// APP /// PaymentSelect DR /// or Charge/V_Prepayment /// BankInTransit CR /// CashBankTransfer /// - /// </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); // Cash Transfer if ("X".Equals(_TenderType)) { List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); } int AD_Org_ID = GetBank_Org_ID(); // Bank Account Org if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARRECEIPT)) { // Work done by Bharat for the posting of ED008 Module bool addPost = false; //Check For Module Tuple <String, String, String> aInfo = null; if (Env.HasModulePrefix("ED008_", out aInfo)) { addPost = true; } else { addPost = false; } if (addPost == true) { // Tender Type RIBA if ("R".Equals(_TenderType)) { MAccount acct = null; MAccount portAcct = null; int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RIBA_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=" + GetC_BankAccount_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RIBA_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } FactLine fl = fact.CreateLine(null, acct, GetC_Currency_ID(), GetAmount(), null); int ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_Portfolio_Acct FROM C_BP_Customer_Acct WHERE C_BPartner_ID=" + GetC_BPartner_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (ComID > 0) { portAcct = MAccount.Get(Env.GetCtx(), ComID); } if (portAcct == null) { ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_Portfolio_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); portAcct = MAccount.Get(Env.GetCtx(), ComID); } fl = fact.CreateLine(null, portAcct, GetC_Currency_ID(), null, GetAmount()); } // Tender Type MAV else if ("M".Equals(_TenderType)) { MAccount acct = null; MAccount portAcct = null; int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_MAV_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=" + GetC_BankAccount_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_MAV_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } FactLine fl = fact.CreateLine(null, acct, GetC_Currency_ID(), GetAmount(), null); int ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_Portfolio_Acct FROM C_BP_Customer_Acct WHERE C_BPartner_ID=" + GetC_BPartner_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (ComID > 0) { portAcct = MAccount.Get(Env.GetCtx(), ComID); } if (portAcct == null) { ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_Portfolio_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); portAcct = MAccount.Get(Env.GetCtx(), ComID); } fl = fact.CreateLine(null, portAcct, GetC_Currency_ID(), null, GetAmount()); } // Tender Type BOE else if ("E".Equals(_TenderType)) { MAccount acct = null; MAccount portAcct = null; string boeType = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT ED008_BOEType FROM C_Payment WHERE C_Payment_ID = " + Get_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); int boeID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED008_BOE_ID FROM C_Payment WHERE C_Payment_ID = " + Get_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if ("T".Equals(boeType)) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOE_Acct FROM ED008_BOEAccounting WHERE ED008_BOE_ID=" + boeID + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOE_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } FactLine fl = fact.CreateLine(null, acct, GetC_Currency_ID(), GetAmount(), null); int ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOETransit_Acct FROM ED008_BOEAccounting WHERE ED008_BOE_ID=" + boeID + " AND AD_Client_ID = " + GetAD_Client_ID())); if (ComID > 0) { portAcct = MAccount.Get(Env.GetCtx(), ComID); } if (portAcct == null) { ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOETransit_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); portAcct = MAccount.Get(Env.GetCtx(), ComID); } fl = fact.CreateLine(null, portAcct, GetC_Currency_ID(), null, GetAmount()); } else if ("R".Equals(boeType)) { FactLine fl = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_BankInTransit, as1), GetC_Currency_ID(), GetAmount(), null); int ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOE_Acct FROM ED008_BOEAccounting WHERE ED008_BOE_ID=" + boeID + " AND AD_Client_ID = " + GetAD_Client_ID())); if (ComID > 0) { portAcct = MAccount.Get(Env.GetCtx(), ComID); } if (portAcct == null) { ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOE_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); portAcct = MAccount.Get(Env.GetCtx(), ComID); } fl = fact.CreateLine(null, portAcct, GetC_Currency_ID(), null, GetAmount()); } } // Tender Type RID else if ("I".Equals(_TenderType)) { MAccount acct = null; MAccount portAcct = null; int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RID_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=" + GetC_BankAccount_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_RID_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } FactLine fl = fact.CreateLine(null, acct, GetC_Currency_ID(), GetAmount(), null); int ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_Portfolio_Acct FROM C_BP_Customer_Acct WHERE C_BPartner_ID=" + GetC_BPartner_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if (ComID > 0) { portAcct = MAccount.Get(Env.GetCtx(), ComID); } if (portAcct == null) { ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_Portfolio_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); portAcct = MAccount.Get(Env.GetCtx(), ComID); } fl = fact.CreateLine(null, portAcct, GetC_Currency_ID(), null, GetAmount()); } else { // Asset FactLine fl = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_BankInTransit, as1), GetC_Currency_ID(), GetAmount(), null); if (fl != null && AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } // MAccount acct = null; if (GetC_Charge_ID() != 0) { acct = MCharge.GetAccount(GetC_Charge_ID(), as1, GetAmount()); } else if (_Prepayment) { acct = GetAccount(Doc.ACCTTYPE_C_Prepayment, as1); } else { acct = GetAccount(Doc.ACCTTYPE_UnallocatedCash, as1); } fl = fact.CreateLine(null, acct, GetC_Currency_ID(), null, GetAmount()); if (fl != null && AD_Org_ID != 0 && GetC_Charge_ID() == 0) // don't overwrite charge { fl.SetAD_Org_ID(AD_Org_ID); } } } // Default Posting Logic else { // Asset FactLine fl = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_BankInTransit, as1), GetC_Currency_ID(), GetAmount(), null); if (fl != null && AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } // MAccount acct = null; if (GetC_Charge_ID() != 0) { acct = MCharge.GetAccount(GetC_Charge_ID(), as1, GetAmount()); } else if (_Prepayment) { acct = GetAccount(Doc.ACCTTYPE_C_Prepayment, as1); } else { acct = GetAccount(Doc.ACCTTYPE_UnallocatedCash, as1); } fl = fact.CreateLine(null, acct, GetC_Currency_ID(), null, GetAmount()); if (fl != null && AD_Org_ID != 0 && GetC_Charge_ID() == 0) // don't overwrite charge { fl.SetAD_Org_ID(AD_Org_ID); } } } // APP else if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APPAYMENT)) { // Work Done For Ed008 Module bool addPost = false; //Check For Module Tuple <String, String, String> aInfo = null; if (Env.HasModulePrefix("ED008_", out aInfo) || Env.HasModulePrefix("ED010_", out aInfo)) { addPost = true; } if (addPost == true) { MAccount acct = null; MAccount portAcct = null; string boeType = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT ED008_BOEType FROM C_Payment WHERE C_Payment_ID = " + Get_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); int boeID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED008_BOE_ID FROM C_Payment WHERE C_Payment_ID = " + Get_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); if ("E".Equals(_TenderType)) { if ("T".Equals(boeType)) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOETransit_Acct FROM ED008_BOEAccounting WHERE ED008_BOE_ID=" + boeID + " AND AD_Client_ID = " + GetAD_Client_ID())); if (validComID > 0) { acct = MAccount.Get(Env.GetCtx(), validComID); } if (acct == null) { validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOETransit_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); acct = MAccount.Get(Env.GetCtx(), validComID); } FactLine f2 = fact.CreateLine(null, acct, GetC_Currency_ID(), GetAmount(), null); int ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOE_Acct FROM ED008_BOEAccounting WHERE ED008_BOE_ID=" + boeID + " AND AD_Client_ID = " + GetAD_Client_ID())); if (ComID > 0) { portAcct = MAccount.Get(Env.GetCtx(), ComID); } if (portAcct == null) { ComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_BOE_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); portAcct = MAccount.Get(Env.GetCtx(), ComID); } f2 = fact.CreateLine(null, portAcct, GetC_Currency_ID(), null, GetAmount()); } } else { FactLine fl = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_BankInTransit, as1), GetC_Currency_ID(), null, GetAmount()); if (fl != null && AD_Org_ID != 0 && GetC_Charge_ID() == 0) // don't overwrite charge { fl.SetAD_Org_ID(AD_Org_ID); } DataSet ds = null; DataSet dsSSCode = null; decimal amount = 0, WithholdingAmt = 0, sscAmt = 0, payAmt = 0; payAmt = GetAmount(); string sql = @"SELECT cl.m_product_id, cl.linenetamt,prd.ed010_sscode_id,holddet.ed010_appliedpercentage,holddet.ed010_actualpercentage,withAcct.Withholding_Acct FROM C_Payment pay INNER JOIN c_invoice inv ON pay.c_invoice_id = inv.c_invoice_id inner join c_invoiceline cl on pay.c_invoice_id=cl.c_invoice_id inner join C_BPartner cb on pay.c_bpartner_id=cb.c_bpartner_id INNER JOIN m_product prd ON prd.m_product_ID = cl.m_product_ID LEFT JOIN c_withholding hold ON hold.C_WithHolding_Id = prd.c_withholding_id LEFT JOIN ed010_withholdingdetails holddet ON holddet.C_WithHolding_Id = hold.C_WithHolding_Id left join C_Withholding_Acct withAcct on hold.C_WithHolding_Id=withAcct.C_WithHolding_Id where cb.ED010_IsWithholding='Y' and cb.ED010_IsSSCode='Y' and pay.ED010_WithholdingAmt > 0 AND " + GlobalVariable.TO_DATE(DateTime.Now.ToLocalTime(), true) + @"BETWEEN holddet.ED010_FromDate AND holddet.ED010_ToDate and pay.AD_Org_ID = " + GetCtx().GetAD_Org_ID() + " and pay.c_payment_id = " + Get_ID(); ds = new DataSet(); ds = DB.ExecuteDataset(sql, null, null); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { MAccount withAcct = null; int validID = 0; amount = (Decimal.Divide(Decimal.Multiply(Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["linenetamt"]), Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["ed010_appliedpercentage"])), 100)); WithholdingAmt = (Decimal.Divide(Decimal.Multiply(amount, Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["ed010_actualpercentage"])), 100)); validID = Util.GetValueOfInt(ds.Tables[0].Rows[i]["Withholding_Acct"]); if (validID > 0) { withAcct = MAccount.Get(Env.GetCtx(), validID); } if (withAcct == null) { validID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT Withholding_Acct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); withAcct = MAccount.Get(Env.GetCtx(), validID); } fl = fact.CreateLine(null, withAcct, GetC_Currency_ID(), null, Decimal.Round(WithholdingAmt, 2)); if (fl != null) { payAmt += Decimal.Round(WithholdingAmt, 2); } if (fl != null && AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } } } } ds.Dispose(); sql = @"SELECT cl.m_product_id,cb.c_bpartner_id,cl.linenetamt,prd.ed010_sscode_id,sdet.ed010_percentagetype,sdet.ed010_maxamt,sdet.ed010_minamt,sdet.ed010_socialsecurityprcnt,sdet.ed010_orgpercentage, sdet.ed010_vendorpercentage,sscAcct.ED000_SecCodeAcct FROM C_Payment pay INNER JOIN c_invoice inv ON pay.c_invoice_id = inv.c_invoice_id inner join c_invoiceline cl on pay.c_invoice_id=cl.c_invoice_id inner join C_BPartner cb on pay.c_bpartner_id=cb.c_bpartner_id INNER JOIN m_product prd ON prd.m_product_ID = cl.m_product_ID LEFT JOIN ed010_sscode scode ON scode.ed010_sscode_ID = prd.ed010_sscode_id LEFT JOIN ed010_sscodedetails sdet ON sdet.ed010_sscode_ID = scode.ed010_sscode_ID left join ED010_SSCode_Acct sscAcct on scode.ED010_SSCode_ID=sscAcct.ED010_SSCode_ID where cb.ED010_IsWithholding='Y' and cb.ED010_IsSSCode='Y' and pay.ED010_WithholdingAmt > 0 AND " + GlobalVariable.TO_DATE(DateTime.Now.ToLocalTime(), true) + @"BETWEEN sdet.ED010_FromDate AND sdet.ED010_ToDate AND pay.AD_Org_ID = " + GetCtx().GetAD_Org_ID() + " and pay.c_payment_id = " + Get_ID(); dsSSCode = new DataSet(); dsSSCode = DB.ExecuteDataset(sql, null, null); if (dsSSCode.Tables.Count > 0) { if (dsSSCode.Tables[0].Rows.Count > 0) { for (int i = 0; i < dsSSCode.Tables[0].Rows.Count; i++) { MAccount sscAcct = null; int vlID = 0; sql = @"SELECT SUM(grandtotal) FROM c_invoice WHERE IsActive = 'Y' AND docstatus = 'CO' AND c_bpartner_Id = " + Util.GetValueOfInt(dsSSCode.Tables[0].Rows[i]["c_bpartner_id"]); decimal result = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, null)); if (result <= Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["ed010_maxamt"]) && result >= Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["ed010_minamt"])) { if (Util.GetValueOfString(dsSSCode.Tables[0].Rows[i]["ed010_percentagetype"]) == "S") { sscAmt = (Decimal.Divide(Decimal.Multiply(Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["linenetamt"]), Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["ed010_socialsecurityprcnt"])), 100)); } else if (Util.GetValueOfString(dsSSCode.Tables[0].Rows[i]["ed010_percentagetype"]) == "M") { // amount = (Decimal.Divide(Decimal.Multiply(Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["linenetamt"]), Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["ed010_vendorpercentage"])), 100)); sscAmt = (Decimal.Divide(Decimal.Multiply(Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["linenetamt"]), Util.GetValueOfDecimal(dsSSCode.Tables[0].Rows[i]["ed010_orgpercentage"])), 100)); } } vlID = Util.GetValueOfInt(dsSSCode.Tables[0].Rows[i]["ED000_SecCodeAcct"]); if (vlID > 0) { sscAcct = MAccount.Get(Env.GetCtx(), vlID); } if (sscAcct == null) { vlID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT ED000_SecCodeAcct FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); sscAcct = MAccount.Get(Env.GetCtx(), vlID); } fl = fact.CreateLine(null, sscAcct, GetC_Currency_ID(), null, Decimal.Round(sscAmt, 2)); if (fl != null) { payAmt += Decimal.Round(sscAmt, 2); } if (fl != null && AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } } } } dsSSCode.Dispose(); fl = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_PaymentSelect, as1), GetC_Currency_ID(), payAmt, null); if (fl != null && AD_Org_ID != 0 && GetC_Charge_ID() == 0) // don't overwrite charge { fl.SetAD_Org_ID(AD_Org_ID); } } } // Default Posting Logic else { MAccount acct = null; if (GetC_Charge_ID() != 0) { acct = MCharge.GetAccount(GetC_Charge_ID(), as1, GetAmount()); } else if (_Prepayment) { acct = GetAccount(Doc.ACCTTYPE_V_Prepayment, as1); } else { acct = GetAccount(Doc.ACCTTYPE_PaymentSelect, as1); } FactLine fl = fact.CreateLine(null, acct, GetC_Currency_ID(), GetAmount(), null); if (fl != null && AD_Org_ID != 0 && GetC_Charge_ID() == 0) // don't overwrite charge { fl.SetAD_Org_ID(AD_Org_ID); } // Asset fl = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_BankInTransit, as1), GetC_Currency_ID(), null, GetAmount()); if (fl != null && AD_Org_ID != 0) { fl.SetAD_Org_ID(AD_Org_ID); } } } else { _error = "DocumentType unknown: " + GetDocumentType(); log.Log(Level.SEVERE, _error); fact = null; } // List <Fact> facts1 = new List <Fact>(); facts1.Add(fact); return(facts1); }
/// <summary> /// Create New Standard Costs /// </summary> /// <param name="as1">accounting schema</param> private void CreateNew(MAcctSchema as1) { if (!as1.GetCostingLevel().Equals(MAcctSchema.COSTINGLEVEL_Client)) { String txt = "Costing Level prevents creating new Costing records for " + as1.GetName(); log.Warning(txt); AddLog(0, null, null, txt); return; } String sql = "SELECT * FROM M_Product p " + "WHERE NOT EXISTS (SELECT * FROM M_Cost c WHERE c.M_Product_ID=p.M_Product_ID" + " AND c.M_CostType_ID=" + as1.GetM_CostType_ID() + " AND c.C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND c.M_CostElement_ID=" + _ce.GetM_CostElement_ID() + " AND c.M_AttributeSetInstance_ID=0) " + "AND AD_Client_ID=" + as1.GetAD_Client_ID(); if (_M_Product_Category_ID != 0) { sql += " AND M_Product_Category_ID=" + _M_Product_Category_ID; } int counter = 0; DataTable dt = null; IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, null); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { if (CreateNew(new MProduct(GetCtx(), dr, null), as1)) { counter++; } } } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } finally { dt = null; if (idr != null) { idr.Close(); } } log.Info("#" + counter); AddLog(0, null, new Decimal(counter), "Created for " + as1.GetName()); }
/// <summary> /// Create Facts (the accounting logic) for /// </summary> /// <param name="?"></param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header List <Fact> facts = new List <Fact>(); if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_INCOMETAX)) { // Decimal grossAmt = getAmount(Doc.AMTTYPE_Gross); // Commitment Fact fact = new Fact(this, as1, Fact.POST_Actual); Decimal total = Env.ZERO; Decimal amount = Env.ZERO; for (int i = 0; i < _lines.Length; i++) { DocLine dline = _lines[i]; MIncomeTaxLines line = new MIncomeTaxLines(GetCtx(), dline.Get_ID(), null); amount = Util.GetValueOfDecimal(line.GetIncomeTaxAmount()); if (amount != Env.ZERO) { total = Decimal.Add(total, amount); } // Account MAccount expense = MAccount.Get(GetCtx(), line.GetC_IncomeTax_Acct()); fact.CreateLine(dline, expense, GetC_Currency_ID(), amount); } if (total != Env.ZERO) { int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT T_Due_Acct FROM C_Tax_Acct WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND AD_Client_ID = " + GetAD_Client_ID())); MAccount acct = MAccount.Get(GetCtx(), validComID); fact.CreateLine(null, acct, GetC_Currency_ID(), Decimal.Negate(total)); } 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); }
} // doIt /// <summary> /// Create GL Journal /// </summary> /// <returns>document info</returns> private String CreateGLJournal() { List <X_T_InvoiceGL> list = new List <X_T_InvoiceGL>(); String sql = "SELECT * FROM T_InvoiceGL " + "WHERE AD_PInstance_ID=" + GetAD_PInstance_ID() + " ORDER BY AD_Org_ID"; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, Get_TrxName()); while (idr.Read()) { list.Add(new X_T_InvoiceGL(GetCtx(), idr, Get_TrxName())); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } if (list.Count == 0) { return(" - No Records found"); } // MAcctSchema aas = MAcctSchema.Get(GetCtx(), _C_AcctSchema_ID); MAcctSchemaDefault asDefaultAccts = MAcctSchemaDefault.Get(GetCtx(), _C_AcctSchema_ID); MGLCategory cat = MGLCategory.GetDefaultSystem(GetCtx()); if (cat == null) { MDocType docType = MDocType.Get(GetCtx(), _C_DocTypeReval_ID); cat = MGLCategory.Get(GetCtx(), docType.GetGL_Category_ID()); } // MJournalBatch batch = new MJournalBatch(GetCtx(), 0, Get_TrxName()); batch.SetDescription(GetName()); batch.SetC_DocType_ID(_C_DocTypeReval_ID); batch.SetDateDoc(DateTime.Now);// new Timestamp(System.currentTimeMillis())); batch.SetDateAcct(_DateReval); batch.SetC_Currency_ID(aas.GetC_Currency_ID()); if (!batch.Save()) { return(GetRetrievedError(batch, "Could not create Batch")); //return " - Could not create Batch"; } // MJournal journal = null; Decimal? drTotal = Env.ZERO; Decimal? crTotal = Env.ZERO; int AD_Org_ID = 0; for (int i = 0; i < list.Count; i++) { X_T_InvoiceGL gl = list[i];//.get(i); if (Env.Signum(gl.GetAmtRevalDrDiff()) == 0 && Env.Signum(gl.GetAmtRevalCrDiff()) == 0) { continue; } MInvoice invoice = new MInvoice(GetCtx(), gl.GetC_Invoice_ID(), null); if (invoice.GetC_Currency_ID() == aas.GetC_Currency_ID()) { continue; } // if (journal == null) { journal = new MJournal(batch); journal.SetC_AcctSchema_ID(aas.GetC_AcctSchema_ID()); journal.SetC_Currency_ID(aas.GetC_Currency_ID()); journal.SetC_ConversionType_ID(_C_ConversionTypeReval_ID); MOrg org = MOrg.Get(GetCtx(), gl.GetAD_Org_ID()); journal.SetDescription(GetName() + " - " + org.GetName()); journal.SetGL_Category_ID(cat.GetGL_Category_ID()); if (!journal.Save()) { return(GetRetrievedError(journal, "Could not create Journal")); //return " - Could not create Journal"; } } // MJournalLine line = new MJournalLine(journal); line.SetLine((i + 1) * 10); line.SetDescription(invoice.GetSummary()); // MFactAcct fa = new MFactAcct(GetCtx(), gl.GetFact_Acct_ID(), null); line.SetC_ValidCombination_ID(MAccount.Get(fa)); Decimal?dr = gl.GetAmtRevalDrDiff(); Decimal?cr = gl.GetAmtRevalCrDiff(); drTotal = Decimal.Add(drTotal.Value, dr.Value); crTotal = Decimal.Add(crTotal.Value, cr.Value); line.SetAmtSourceDr(dr.Value); line.SetAmtAcctDr(dr.Value); line.SetAmtSourceCr(cr.Value); line.SetAmtAcctCr(cr.Value); line.Save(); // if (AD_Org_ID == 0) // invoice org id { AD_Org_ID = gl.GetAD_Org_ID(); } // Change in Org if (AD_Org_ID != gl.GetAD_Org_ID()) { CreateBalancing(asDefaultAccts, journal, drTotal.Value, crTotal.Value, AD_Org_ID, (i + 1) * 10); // AD_Org_ID = gl.GetAD_Org_ID(); drTotal = Env.ZERO; crTotal = Env.ZERO; journal = null; } } CreateBalancing(asDefaultAccts, journal, drTotal.Value, crTotal.Value, AD_Org_ID, (list.Count + 1) * 10); return(" - " + batch.GetDocumentNo() + " #" + list.Count); } // createGLJournal
/// <summary> /// Get Account /// </summary> /// <param name="AcctType"></param> /// <param name="as1"></param> /// <returns>Account</returns> public MAccount GetAccount(int AcctType, MAcctSchema as1) { if (AcctType < 0 || AcctType > 4) { return(null); } // String sql = "SELECT T_Due_Acct, T_Liability_Acct, T_Credit_Acct, T_Receivables_Acct, T_Expense_Acct " + "FROM C_Tax_Acct WHERE C_Tax_ID=" + _C_Tax_ID + " AND C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID(); int validCombination_ID = 0; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, null); if (idr.Read()) { validCombination_ID = Utility.Util.GetValueOfInt(idr[AcctType]);// .getInt(AcctType + 1); // 1..5 } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); idr = null; } log.Log(Level.SEVERE, sql, e); } if (validCombination_ID == 0) { return(null); } return(MAccount.Get(as1.GetCtx(), validCombination_ID)); }
/// <summary> /// Set Account Info /// </summary> /// <param name="acctSchema">account schema</param> /// <param name="acct">account</param> public void SetAccount(MAcctSchema acctSchema, MAccount acct) { _acctSchema = acctSchema; SetC_AcctSchema_ID(acctSchema.GetC_AcctSchema_ID()); // _acct = acct; if (GetAD_Client_ID() == 0) { SetAD_Client_ID(_acct.GetAD_Client_ID()); } SetAccount_ID(_acct.GetAccount_ID()); SetC_SubAcct_ID(_acct.GetC_SubAcct_ID()); // User Defined References MAcctSchemaElement ud1 = _acctSchema.GetAcctSchemaElement( X_C_AcctSchema_Element.ELEMENTTYPE_UserElement1); if (ud1 != null) { String ColumnName1 = ud1.GetDisplayColumnName(); if (ColumnName1 != null) { int ID1 = 0; if (_docLine != null) { ID1 = _docLine.GetValue(ColumnName1); } if (ID1 == 0) { if (_doc == null) { throw new ArgumentException("Document not set yet"); } ID1 = _doc.GetValue(ColumnName1); } if (ID1 != 0) { SetUserElement1_ID(ID1); } } } MAcctSchemaElement ud2 = _acctSchema.GetAcctSchemaElement( X_C_AcctSchema_Element.ELEMENTTYPE_UserElement2); if (ud2 != null) { String ColumnName2 = ud2.GetDisplayColumnName(); if (ColumnName2 != null) { int ID2 = 0; if (_docLine != null) { ID2 = _docLine.GetValue(ColumnName2); } if (ID2 == 0) { if (_doc == null) { throw new ArgumentException("Document not set yet"); } ID2 = _doc.GetValue(ColumnName2); } if (ID2 != 0) { SetUserElement2_ID(ID2); } } } }