/// <summary> /// Create Facts (the accounting logic) for /// PJI /// <pre> /// Issue /// ProjectWIP DR /// Inventory CR /// </pre> /// Project Account is either Asset or WIP depending on Project Type /// </summary> /// <param name="?"></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()); MProject project = new MProject(GetCtx(), _issue.GetC_Project_ID(), null); String ProjectCategory = project.GetProjectCategory(); MProduct product = MProduct.Get(GetCtx(), _issue.GetM_Product_ID()); // Line pointers FactLine dr = null; FactLine cr = null; // Issue Cost Decimal?cost = null; if (_issue.GetM_InOutLine_ID() != 0) { cost = GetPOCost(as1); } else if (_issue.GetS_TimeExpenseLine_ID() != 0) { cost = GetLaborCost(as1); } if (cost == null) // standard Product Costs { cost = _line.GetProductCosts(as1, GetAD_Org_ID(), false); } // Project DR int acctType = ACCTTYPE_ProjectWIP; if (MProject.PROJECTCATEGORY_AssetProject.Equals(ProjectCategory)) { acctType = ACCTTYPE_ProjectAsset; } dr = fact.CreateLine(_line, GetAccount(acctType, as1), as1.GetC_Currency_ID(), cost, null); dr.SetQty((Decimal?)Decimal.Negate(Utility.Util.GetValueOfDecimal(_line.GetQty()))); // Inventory CR acctType = ProductCost.ACCTTYPE_P_Asset; if (product.IsService()) { acctType = ProductCost.ACCTTYPE_P_Expense; } cr = fact.CreateLine(_line, _line.GetAccount(acctType, as1), as1.GetC_Currency_ID(), null, cost); cr.SetM_Locator_ID(_line.GetM_Locator_ID()); cr.SetLocationFromLocator(_line.GetM_Locator_ID(), true); // from Loc // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
} // setC_Currency_ID /// <summary> /// Set Rate /// </summary> private void SetRate() { // Source info int C_Currency_ID = GetC_Currency_ID(); int C_ConversionType_ID = GetC_ConversionType_ID(); if (C_Currency_ID == 0 || C_ConversionType_ID == 0) { return; } DateTime?DateAcct = GetDateAcct(); if (DateAcct == null) { DateAcct = DateTime.Now;// new Timestamp(System.currentTimeMillis()); } // int C_AcctSchema_ID = GetC_AcctSchema_ID(); MAcctSchema a = MAcctSchema.Get(GetCtx(), C_AcctSchema_ID); int AD_Client_ID = GetAD_Client_ID(); int AD_Org_ID = GetAD_Org_ID(); Decimal?CurrencyRate = (Decimal?)MConversionRate.GetRate(C_Currency_ID, a.GetC_Currency_ID(), DateAcct, C_ConversionType_ID, AD_Client_ID, AD_Org_ID); log.Fine("rate = " + CurrencyRate); //if (CurrencyRate.Value == null) //{ // CurrencyRate = Env.ZERO; //} SetCurrencyRate(CurrencyRate.Value); } // setRate
/// <summary> /// Create Facts (the accounting logic) for POR. /// <pre> /// Reservation /// Expense CR /// Offset DR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); Fact fact = new Fact(this, as1, Fact.POST_Reservation); SetC_Currency_ID(as1.GetC_Currency_ID()); // // Decimal grossAmt = GetAmount(Doc.AMTTYPE_Gross); // Commitment if (as1.IsCreateReservation()) { Decimal total = Env.ZERO; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; Decimal cost = line.GetAmtSource(); total = Decimal.Add(total, cost); // Account MAccount expense = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); // fact.CreateLine(line, expense, as1.GetC_Currency_ID(), cost, null); } // Offset MAccount offset = GetAccount(ACCTTYPE_CommitmentOffset, as1); if (offset == null) { _error = "@NotFound@ @CommitmentOffset_Acct@"; log.Log(Level.SEVERE, _error); return(null); } fact.CreateLine(null, offset, GetC_Currency_ID(), null, total); facts.Add(fact); } return(facts); }
/// <summary> /// GetAcctSchema Detail /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Dictionary <String, String> GetAcctSchema(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int C_AcctSchema_ID; Dictionary <String, String> retDic = new Dictionary <string, string>(); //Assign parameter value C_AcctSchema_ID = Util.GetValueOfInt(paramValue[0].ToString()); //End Assign parameter value MAcctSchema aas = MAcctSchema.Get(ctx, C_AcctSchema_ID); retDic["StdPrecision"] = aas.GetStdPrecision().ToString(); retDic["C_Currency_ID"] = aas.GetC_Currency_ID().ToString(); return(retDic); }
/// <summary> /// Get PO Costs in Currency of AcctSchema /// </summary> /// <param name="as1"></param> /// <returns>Unit PO Cost</returns> private Decimal?GetPOCost(MAcctSchema as1) { Decimal?retValue = null; // Uses PO Date String sql = "SELECT currencyConvert(ol.PriceActual, o.C_Currency_ID, @param1, o.DateOrdered, o.C_ConversionType_ID, @param2, @param3) " + "FROM C_OrderLine ol" + " INNER JOIN M_InOutLine iol ON (iol.C_OrderLine_ID=ol.C_OrderLine_ID)" + " INNER JOIN C_Order o ON (o.C_Order_ID=ol.C_Order_ID) " + "WHERE iol.M_InOutLine_ID=@param4"; IDataReader idr = null; try { SqlParameter[] param = new SqlParameter[4]; param[0] = new SqlParameter("@param1", as1.GetC_Currency_ID()); param[1] = new SqlParameter("@param2", GetAD_Client_ID()); param[2] = new SqlParameter("@param3", GetAD_Org_ID()); param[3] = new SqlParameter("@param4", _issue.GetM_InOutLine_ID()); idr = DataBase.DB.ExecuteReader(sql, param, null); if (idr.Read()) { retValue = Utility.Util.GetValueOfDecimal(idr[0]);///.getBigDecimal(1); log.Fine("POCost = " + retValue); } else { log.Warning("Not found for M_InOutLine_ID=" + _issue.GetM_InOutLine_ID()); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); idr = null; } log.Log(Level.SEVERE, sql, e); } return(retValue); }
/// <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 Landed Cost accounting & Cost lines /// </summary> /// <param name="as1">accounting schema</param> /// <param name="fact">fact</param> /// <param name="line">document line</param> /// <param name="dr">DR entry (normal api)</param> /// <returns>true if landed costs were created</returns> private bool LandedCost(MAcctSchema as1, Fact fact, DocLine line, bool dr) { int C_InvoiceLine_ID = line.Get_ID(); MLandedCostAllocation[] lcas = MLandedCostAllocation.GetOfInvoiceLine( GetCtx(), C_InvoiceLine_ID, GetTrx()); if (lcas.Length == 0) { return(false); } // Delete Old String sql = "DELETE FROM M_CostDetail WHERE C_InvoiceLine_ID=" + C_InvoiceLine_ID; int no = DataBase.DB.ExecuteQuery(sql, null, GetTrx()); if (no != 0) { log.Config("CostDetail Deleted #" + no); } // Calculate Total Base double totalBase = 0; for (int i = 0; i < lcas.Length; i++) { totalBase += Convert.ToDouble(lcas[i].GetBase());//.doubleValue(); } // Create New MInvoiceLine il = new MInvoiceLine(GetCtx(), C_InvoiceLine_ID, GetTrx()); for (int i = 0; i < lcas.Length; i++) { MLandedCostAllocation lca = lcas[i]; if (Env.Signum(lca.GetBase()) == 0) { continue; } double percent = totalBase / Convert.ToDouble(lca.GetBase()); String desc = il.GetDescription(); if (desc == null) { desc = percent + "%"; } else { desc += " - " + percent + "%"; } if (line.GetDescription() != null) { desc += " - " + line.GetDescription(); } // Accounting ProductCost pc = new ProductCost(GetCtx(), lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(), GetTrx()); Decimal?drAmt = null; Decimal?crAmt = null; if (dr) { drAmt = lca.GetAmt(); } else { crAmt = lca.GetAmt(); } FactLine fl = fact.CreateLine(line, pc.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1), GetC_Currency_ID(), drAmt, crAmt); fl.SetDescription(desc); // Cost Detail - Convert to AcctCurrency Decimal allocationAmt = lca.GetAmt(); if (GetC_Currency_ID() != as1.GetC_Currency_ID()) { allocationAmt = MConversionRate.Convert(GetCtx(), allocationAmt, GetC_Currency_ID(), as1.GetC_Currency_ID(), GetDateAcct(), GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); } if (Env.Scale(allocationAmt) > as1.GetCostingPrecision()) { allocationAmt = Decimal.Round(allocationAmt, as1.GetCostingPrecision(), MidpointRounding.AwayFromZero); } if (!dr) { allocationAmt = Decimal.Negate(allocationAmt); } if (!IsPosted()) { MCostDetail cd = new MCostDetail(as1, lca.GetAD_Org_ID(), lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(), lca.GetM_CostElement_ID(), allocationAmt, lca.GetQty(), // Qty desc, GetTrx()); cd.SetC_InvoiceLine_ID(C_InvoiceLine_ID); bool ok = cd.Save(); if (ok && !cd.IsProcessed()) { MClient client = MClient.Get(as1.GetCtx(), as1.GetAD_Client_ID()); if (client.IsCostImmediate()) { cd.Process(); } } } } log.Config("Created #" + lcas.Length); return(true); }
/// <summary> /// Create 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()); }
} // 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> /// Convert to Accounted Currency /// </summary> /// <returns>true if converted</returns> public bool Convert() { // Document has no currency if (GetC_Currency_ID() == Doc.NO_CURRENCY) { SetC_Currency_ID(_acctSchema.GetC_Currency_ID()); } if (_acctSchema.GetC_Currency_ID() == GetC_Currency_ID()) { SetAmtAcctDr(GetAmtSourceDr()); SetAmtAcctCr(GetAmtSourceCr()); return(true); } // Get Conversion Type from Line or Header int C_ConversionType_ID = 0; int AD_Org_ID = 0; if (_docLine != null) // get from line { C_ConversionType_ID = _docLine.GetC_ConversionType_ID(); AD_Org_ID = _docLine.GetAD_Org_ID(); } if (C_ConversionType_ID == 0) // get from header { if (_doc == null) { log.Severe("No Document VO"); return(false); } C_ConversionType_ID = _doc.GetC_ConversionType_ID(); if (AD_Org_ID == 0) { AD_Org_ID = _doc.GetAD_Org_ID(); } } DateTime?convDate = GetDateAcct(); // For sourceforge bug 1718381: Use transaction date instead of // accounting date for currency conversion when the document is Bank // Statement. Ideally this should apply to all "reconciliation" // accounting entries, but doing just Bank Statement for now to avoid // breaking other things. if (_doc is Doc_Bank) { convDate = GetDateTrx(); } SetAmtAcctDr(MConversionRate.Convert(GetCtx(), GetAmtSourceDr(), GetC_Currency_ID(), _acctSchema.GetC_Currency_ID(), convDate, C_ConversionType_ID, _doc.GetAD_Client_ID(), AD_Org_ID)); //if (GetAmtAcctDr() == null) //{ // return false; //} SetAmtAcctCr(MConversionRate.Convert(GetCtx(), GetAmtSourceCr(), GetC_Currency_ID(), _acctSchema.GetC_Currency_ID(), convDate, C_ConversionType_ID, _doc.GetAD_Client_ID(), AD_Org_ID)); return(true); }
/// <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> /// Get Costs /// </summary> /// <param name="cost">Cost</param> /// <param name="to">where to get costs from </param> /// <returns>costs (could be 0) or null if not found</returns> private Decimal?GetCosts(VAdvantage.Model.MCost cost, String to) { Decimal?retValue = null; // Average Invoice if (to.Equals(TO_AverageInvoice)) { MCostElement ce = GetCostElement(TO_AverageInvoice); if (ce == null) { throw new Exception("CostElement not found: " + TO_AverageInvoice); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Average Invoice History else if (to.Equals(TO_AverageInvoiceHistory)) { MCostElement ce = GetCostElement(TO_AverageInvoice); if (ce == null) { throw new Exception("CostElement not found: " + TO_AverageInvoice); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetHistoryAverage(); } } // Average PO else if (to.Equals(TO_AveragePO)) { MCostElement ce = GetCostElement(TO_AveragePO); if (ce == null) { throw new Exception("CostElement not found: " + TO_AveragePO); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Average PO History else if (to.Equals(TO_AveragePOHistory)) { MCostElement ce = GetCostElement(TO_AveragePO); if (ce == null) { throw new Exception("CostElement not found: " + TO_AveragePO); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetHistoryAverage(); } } // FiFo else if (to.Equals(TO_FiFo)) { MCostElement ce = GetCostElement(TO_FiFo); if (ce == null) { throw new Exception("CostElement not found: " + TO_FiFo); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Future Std Costs else if (to.Equals(TO_FutureStandardCost)) { retValue = cost.GetFutureCostPrice(); } // Last Inv Price else if (to.Equals(TO_LastInvoicePrice)) { MCostElement ce = GetCostElement(TO_LastInvoicePrice); if (ce != null) { VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } if (retValue == null) { MProduct product = MProduct.Get(GetCtx(), cost.GetM_Product_ID()); MAcctSchema as1 = MAcctSchema.Get(GetCtx(), cost.GetC_AcctSchema_ID()); retValue = VAdvantage.Model.MCost.GetLastInvoicePrice(product, cost.GetM_AttributeSetInstance_ID(), cost.GetAD_Org_ID(), as1.GetC_Currency_ID()); } } // Last PO Price else if (to.Equals(TO_LastPOPrice)) { MCostElement ce = GetCostElement(TO_LastPOPrice); if (ce != null) { if (BTR002_IsPickLastPO == "N") { VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } } if (retValue == null) { MProduct product = MProduct.Get(GetCtx(), cost.GetM_Product_ID()); MAcctSchema as1 = MAcctSchema.Get(GetCtx(), cost.GetC_AcctSchema_ID()); retValue = VAdvantage.Model.MCost.GetLastPOPrice(product, cost.GetM_AttributeSetInstance_ID(), cost.GetAD_Org_ID(), as1.GetC_Currency_ID()); } } // FiFo else if (to.Equals(TO_LiFo)) { MCostElement ce = GetCostElement(TO_LiFo); if (ce == null) { throw new Exception("CostElement not found: " + TO_LiFo); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Old Std Costs else if (to.Equals(TO_OldStandardCost)) { retValue = GetOldCurrentCostPrice(cost); } // Price List else if (to.Equals(TO_PriceListLimit)) { retValue = GetPrice(cost); } // Standard Costs else if (to.Equals(TO_StandardCost)) { retValue = cost.GetCurrentCostPrice(); } return(retValue); }
/// <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); }
/** * 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()); }
/// <summary> /// Create Facts (the accounting logic) for /// MMP. /// <pre> /// Production /// Inventory DR CR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Line pointer FactLine fl = null; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; // Calculate Costs Decimal?costs = null; if (line.IsProductionBOM()) { // Get BOM Cost - Sum of individual lines Decimal bomCost = Env.ZERO; for (int ii = 0; ii < _lines.Length; ii++) { DocLine line0 = _lines[ii]; if (line0.GetM_ProductionPlan_ID() != line.GetM_ProductionPlan_ID()) { continue; } if (!line0.IsProductionBOM()) { bomCost = Decimal.Add(bomCost, line0.GetProductCosts(as1, line.GetAD_Org_ID(), false)); } } costs = Decimal.Negate(bomCost); } else { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); } // Inventory DR CR fl = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs); if (fl == null) { _error = "No Costs for Line " + line.GetLine() + " - " + line; return(null); } fl.SetM_Locator_ID(line.GetM_Locator_ID()); fl.SetQty(line.GetQty()); // Cost Detail String description = line.GetDescription(); if (description == null) { description = ""; } if (line.IsProductionBOM()) { description += "(*)"; } if (!IsPosted()) { MCostDetail.CreateProduction(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, Utility.Util.GetValueOfInt(costs), line.GetQty().Value, description, GetTrx(), GetRectifyingProcess()); } } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
/// <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> /// 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 Accounting Entries /// </summary> /// <param name="as1">account schema</param> /// <param name="fact">fact to add lines</param> /// <param name="line">line</param> /// <returns>true if created</returns> public bool CreateEntries(MAcctSchema as1, Fact fact, DocLine line) { // get total index (the Receivables/Liabilities line) Decimal total = Env.ZERO; for (int i = 0; i < _facts.Count; i++) { MFactAcct factAcct = (MFactAcct)_facts[i]; if (factAcct.GetAmtSourceDr().CompareTo(total) > 0) { total = factAcct.GetAmtSourceDr(); _totalIndex = i; } if (factAcct.GetAmtSourceCr().CompareTo(total) > 0) { total = factAcct.GetAmtSourceCr(); _totalIndex = i; } } MFactAcct factAcct1 = (MFactAcct)_facts[_totalIndex]; log.Info("Total Invoice = " + total + " - " + factAcct1); int precision = as1.GetStdPrecision(); for (int i = 0; i < _facts.Count; i++) { // No Tax Line if (i == _totalIndex) { continue; } factAcct1 = (MFactAcct)_facts[i]; log.Info(i + ": " + factAcct1); // Create Tax Account MAccount taxAcct = factAcct1.GetMAccount(); if (taxAcct == null || taxAcct.Get_ID() == 0) { log.Severe("Tax Account not found/created"); return(false); } // Discount Amount if (Env.Signum(_DiscountAmt) != 0) { // Original Tax is DR - need to correct it CR if (Env.ZERO.CompareTo(factAcct1.GetAmtSourceDr()) != 0) { Decimal amount = CalcAmount(factAcct1.GetAmtSourceDr(), total, _DiscountAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, _DiscountAccount, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), null, amount); } } // Original Tax is CR - need to correct it DR else { Decimal amount = CalcAmount(factAcct1.GetAmtSourceCr(), total, _DiscountAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, _DiscountAccount, as1.GetC_Currency_ID(), null, amount); } } } // Discount // WriteOff Amount if (Env.Signum(_WriteOffAmt) != 0) { // Original Tax is DR - need to correct it CR if (Env.ZERO.CompareTo(factAcct1.GetAmtSourceDr()) != 0) { Decimal amount = CalcAmount(factAcct1.GetAmtSourceDr(), total, _WriteOffAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, _WriteOffAccount, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), null, amount); } } // Original Tax is CR - need to correct it DR else { Decimal amount = CalcAmount(factAcct1.GetAmtSourceCr(), total, _WriteOffAmt, precision); if (Env.Signum(amount) != 0) { fact.CreateLine(line, taxAcct, as1.GetC_Currency_ID(), amount, null); fact.CreateLine(line, _WriteOffAccount, as1.GetC_Currency_ID(), null, amount); } } } // WriteOff } // for all lines return(true); }
/// <summary> /// Create Facts (the accounting logic) for /// 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 /// MMM. /// <pre> /// Movement /// Inventory DR CR /// InventoryTo DR CR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Line pointers FactLine dr = null; FactLine cr = null; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; Decimal costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // ** Inventory DR CR dr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), Decimal.Negate(costs)); // from (-) CR if (dr == null) { continue; } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetQty(Decimal.Negate(line.GetQty().Value)); // outgoing // ** InventoryTo DR CR cr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs); // to (+) DR if (cr == null) { continue; } cr.SetM_Locator_ID(line.GetM_LocatorTo_ID()); cr.SetQty(line.GetQty()); // Only for between-org movements if (dr.GetAD_Org_ID() != cr.GetAD_Org_ID()) { String costingLevel = as1.GetCostingLevel(); MProductCategoryAcct pca = MProductCategoryAcct.Get(GetCtx(), line.GetProduct().GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), GetTrx()); if (pca.GetCostingLevel() != null) { costingLevel = pca.GetCostingLevel(); } if (!MAcctSchema.COSTINGLEVEL_Organization.Equals(costingLevel)) { continue; } // String description = line.GetDescription(); if (description == null) { description = ""; } if (!IsPosted()) { // Cost Detail From MCostDetail.CreateMovement(as1, dr.GetAD_Org_ID(), // locator org line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, Decimal.Negate(costs), Decimal.Negate(line.GetQty().Value), true, description + "(|->)", GetTrx(), GetRectifyingProcess()); // Cost Detail To MCostDetail.CreateMovement(as1, cr.GetAD_Org_ID(), // locator org line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, costs, line.GetQty().Value, false, description + "(|<-)", GetTrx(), GetRectifyingProcess()); } } } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
/// <summary> /// Create Facts (the accounting logic) for /// MMI. /// <pre> /// Inventory /// Inventory DR CR /// InventoryDiff DR CR (or Charge) /// </pre> /// </summary> /// <param name="?"></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); if (Env.Signum(costs) == 0) { _error = "No Costs for " + line.GetProduct().GetName(); return(null); } // Inventory DR CR dr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs); // may be zero difference - no line created. if (dr == null) { continue; } dr.SetM_Locator_ID(line.GetM_Locator_ID()); // InventoryDiff DR CR // or Charge MAccount invDiff = line.GetChargeAccount(as1, Decimal.Negate(costs)); if (invDiff == null) { invDiff = GetAccount(Doc.ACCTTYPE_InvDifferences, as1); } cr = fact.CreateLine(line, invDiff, as1.GetC_Currency_ID(), Decimal.Negate(costs)); if (cr == null) { continue; } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetQty(Decimal.Negate(line.GetQty().Value)); if (line.GetC_Charge_ID() != 0) // explicit overwrite for charge { cr.SetAD_Org_ID(line.GetAD_Org_ID()); } if (!IsPosted()) { // Cost Detail MCostDetail.CreateInventory(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, costs, line.GetQty().Value, line.GetDescription(), GetTrx(), GetRectifyingProcess()); } } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }