/** * Set Order Line. * Does not set Quantity! * @param oLine order line * @param M_Locator_ID locator * @param Qty used only to find suitable locator */ public void SetOrderLine(MOrderLine oLine, int M_Locator_ID, Decimal Qty) { SetC_OrderLine_ID(oLine.GetC_OrderLine_ID()); SetLine(oLine.GetLine()); SetC_UOM_ID(oLine.GetC_UOM_ID()); MProduct product = oLine.GetProduct(); if (product == null) { SetM_Product_ID(0); SetM_AttributeSetInstance_ID(0); base.SetM_Locator_ID(0); } else { SetM_Product_ID(oLine.GetM_Product_ID()); SetM_AttributeSetInstance_ID(oLine.GetM_AttributeSetInstance_ID()); // if (product.IsItem()) { if (M_Locator_ID == 0) { SetM_Locator_ID(Qty); // requires warehouse, product, asi } else { SetM_Locator_ID(M_Locator_ID); } } else { base.SetM_Locator_ID(0); } } SetC_Charge_ID(oLine.GetC_Charge_ID()); SetDescription(oLine.GetDescription()); SetIsDescription(oLine.IsDescription()); // SetC_Project_ID(oLine.GetC_Project_ID()); SetC_ProjectPhase_ID(oLine.GetC_ProjectPhase_ID()); SetC_ProjectTask_ID(oLine.GetC_ProjectTask_ID()); SetC_Activity_ID(oLine.GetC_Activity_ID()); SetC_Campaign_ID(oLine.GetC_Campaign_ID()); SetAD_OrgTrx_ID(oLine.GetAD_OrgTrx_ID()); SetUser1_ID(oLine.GetUser1_ID()); SetUser2_ID(oLine.GetUser2_ID()); }
/// <summary> /// GetOrderLine /// </summary> /// <param name="ctx"></param> /// <param name="param"></param> /// <returns></returns> public Dictionary <String, String> GetOrderLine(Ctx ctx, string param) { string[] paramValue = param.Split(','); Dictionary <String, String> retDic = new Dictionary <string, string>(); //Assign parameter value int id; id = Util.GetValueOfInt(paramValue[0].ToString()); //End Assign parameter value MOrderLine orderline = new MOrderLine(ctx, id, null); retDic["C_Tax_ID"] = Util.GetValueOfString(orderline.GetC_Tax_ID()); retDic["PriceList"] = Util.GetValueOfString(orderline.GetPriceList()); retDic["PriceLimit"] = Util.GetValueOfString(orderline.GetPriceLimit()); retDic["PriceActual"] = Util.GetValueOfString(orderline.GetPriceActual()); retDic["PriceEntered"] = Util.GetValueOfString(orderline.GetPriceEntered()); retDic["C_Currency_ID"] = Util.GetValueOfString(orderline.GetC_Currency_ID()); retDic["Discount"] = Util.GetValueOfString(orderline.GetDiscount()); retDic["Discount"] = Util.GetValueOfString(orderline.GetDiscount()); retDic["M_Product_ID"] = Util.GetValueOfString(orderline.GetM_Product_ID()); retDic["Qty"] = Util.GetValueOfString(orderline.GetQtyEntered()); retDic["C_UOM_ID"] = Util.GetValueOfString(orderline.GetC_UOM_ID()); retDic["C_BPartner_ID"] = Util.GetValueOfString(orderline.GetC_BPartner_ID()); retDic["PlannedHours"] = Util.GetValueOfString(orderline.GetQtyOrdered()); retDic["M_AttributeSetInstance_ID"] = Util.GetValueOfString(orderline.GetM_AttributeSetInstance_ID()); retDic["QtyOrdered"] = Util.GetValueOfString(orderline.GetQtyOrdered()); retDic["QtyDelivered"] = Util.GetValueOfString(orderline.GetQtyDelivered()); retDic["QtyEntered"] = Util.GetValueOfString(orderline.GetQtyEntered()); retDic["C_Activity_ID"] = Util.GetValueOfString(orderline.GetC_Activity_ID()); retDic["C_Campaign_ID"] = Util.GetValueOfString(orderline.GetC_Campaign_ID()); retDic["C_Project_ID"] = Util.GetValueOfString(orderline.GetC_Project_ID()); retDic["C_ProjectPhase_ID"] = Util.GetValueOfString(orderline.GetC_ProjectPhase_ID()); retDic["C_ProjectTask_ID"] = Util.GetValueOfString(orderline.GetC_ProjectTask_ID()); retDic["AD_OrgTrx_ID"] = Util.GetValueOfString(orderline.GetAD_OrgTrx_ID()); retDic["User1_ID"] = Util.GetValueOfString(orderline.GetUser1_ID()); retDic["User2_ID"] = Util.GetValueOfString(orderline.GetUser2_ID()); retDic["IsReturnTrx"] = Util.GetValueOfString(orderline.GetParent().IsReturnTrx()).ToLower(); retDic["Orig_InOutLine_ID"] = Util.GetValueOfString(orderline.GetOrig_InOutLine_ID()); retDic["Orig_OrderLine_ID"] = Util.GetValueOfString(orderline.GetOrig_OrderLine_ID()); retDic["GetID"] = Util.GetValueOfString(orderline.Get_ID()); return(retDic); }
/// <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); }
} // doIt /// <summary> /// Process Expense Line /// </summary> /// <param name="te">header</param> /// <param name="tel">line</param> /// <param name="bp">bp</param> private void ProcessLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp) { if (_order == null) { log.Info("New Order for " + bp + ", Project=" + tel.GetC_Project_ID()); _order = new MOrder(GetCtx(), 0, Get_TrxName()); _order.SetAD_Org_ID(tel.GetAD_Org_ID()); _order.SetC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); // _order.SetBPartner(bp); if (_order.GetC_BPartner_Location_ID() == 0) { log.Log(Level.SEVERE, "No BP Location: " + bp); AddLog(0, te.GetDateReport(), null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName()); _order = null; return; } _order.SetM_Warehouse_ID(te.GetM_Warehouse_ID()); ////Added By Arpit asked by Surya Sir..................29-12-2015 //_order.SetSalesRep_ID(GetCtx().GetAD_User_ID()); //End if (tel.GetC_Activity_ID() != 0) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (tel.GetC_Project_ID() != 0) { _order.SetC_Project_ID(tel.GetC_Project_ID()); // Optionally Overwrite BP Price list from Project MProject project = new MProject(GetCtx(), tel.GetC_Project_ID(), Get_TrxName()); if (project.GetM_PriceList_ID() != 0) { _order.SetM_PriceList_ID(project.GetM_PriceList_ID()); } } _order.SetSalesRep_ID(te.GetDoc_User_ID()); // if (!_order.Save()) { throw new Exception("Cannot save Order"); } } else { // Update Header info if (tel.GetC_Activity_ID() != 0 && tel.GetC_Activity_ID() != _order.GetC_Activity_ID()) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0 && tel.GetC_Campaign_ID() != _order.GetC_Campaign_ID()) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (!_order.Save()) { new Exception("Cannot save Order"); } } // OrderLine MOrderLine ol = new MOrderLine(_order); // if (tel.GetM_Product_ID() != 0) { ol.SetM_Product_ID(tel.GetM_Product_ID(), tel.GetC_UOM_ID()); } if (tel.GetS_ResourceAssignment_ID() != 0) { ol.SetS_ResourceAssignment_ID(tel.GetS_ResourceAssignment_ID()); } // Set charge ID if (tel.GetC_Charge_ID() != 0) { ol.SetC_Charge_ID(tel.GetC_Charge_ID()); ol.SetPriceActual(tel.GetExpenseAmt()); ol.SetQty(tel.GetQty()); } ol.SetQty(tel.GetQtyInvoiced()); // ol.SetDescription(tel.GetDescription()); // ol.SetC_Project_ID(tel.GetC_Project_ID()); ol.SetC_ProjectPhase_ID(tel.GetC_ProjectPhase_ID()); ol.SetC_ProjectTask_ID(tel.GetC_ProjectTask_ID()); ol.SetC_Activity_ID(tel.GetC_Activity_ID()); ol.SetC_Campaign_ID(tel.GetC_Campaign_ID()); // Decimal price = tel.GetPriceInvoiced(); // if (price.CompareTo(Env.ZERO) != 0) { if (tel.GetC_Currency_ID() != _order.GetC_Currency_ID()) { price = MConversionRate.Convert(GetCtx(), price, tel.GetC_Currency_ID(), _order.GetC_Currency_ID(), _order.GetAD_Client_ID(), _order.GetAD_Org_ID()); } ol.SetPrice(price); } else { ol.SetPrice(); } if (tel.GetC_UOM_ID() != 0 && ol.GetC_UOM_ID() == 0) { ol.SetC_UOM_ID(tel.GetC_UOM_ID()); } ol.SetTax(); if (!ol.Save()) { throw new Exception("Cannot save Order Line"); } // Update TimeExpense Line tel.SetC_OrderLine_ID(ol.GetC_OrderLine_ID()); if (tel.Save()) { log.Fine("Updated " + tel + " with C_OrderLine_ID"); } else { log.Log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID"); } } // processLine
} // doIt /// <summary> /// Process Expense Line /// </summary> /// <param name="te">header</param> /// <param name="tel">line</param> /// <param name="bp">bp</param> private void ProcessLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp) { if (_order == null) { log.Info("New Order for " + bp + ", Project=" + tel.GetC_Project_ID()); _order = new MOrder(GetCtx(), 0, Get_TrxName()); _order.SetAD_Org_ID(tel.GetAD_Org_ID()); _order.SetC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); // _order.SetBPartner(bp); if (_order.GetC_BPartner_Location_ID() == 0) { log.Log(Level.SEVERE, "No BP Location: " + bp); AddLog(0, te.GetDateReport(), null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName()); _order = null; return; } _order.SetM_Warehouse_ID(te.GetM_Warehouse_ID()); //Bhupendra: Add payment term // to check for if payment term is null if (bp.GetC_PaymentTerm_ID() == 0) { // set the default payment method as check int payTerm = GetPaymentTerm(); if (payTerm <= 0) { message = Msg.GetMsg(GetCtx(), "IsActivePaymentTerm"); return; } else { _order.SetC_PaymentTerm_ID(payTerm); } } else { //check weather paymentterm is active or not if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM C_PaymentTerm WHERE C_PaymentTerm_ID=" + bp.GetC_PaymentTerm_ID(), null, Get_Trx())).Equals("Y")) { _order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePaymentTerm"); return; } } // Bhupendra: added a cond to check for payment method if null // Added by mohit - to set payment method and sales rep id. if (bp.GetVA009_PaymentMethod_ID() == 0) { // set the default payment method as check int paymethod = GetPaymentMethod(); if (paymethod <= 0) { message = Msg.GetMsg(GetCtx(), "IsActivePaymentMethod"); return; } else { _order.SetVA009_PaymentMethod_ID(paymethod); } } else { //check weather the PaymentMethod is active or not if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + bp.GetVA009_PaymentMethod_ID(), null, Get_Trx())).Equals("Y")) { _order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePaymentMethod"); return; } } _order.SetSalesRep_ID(te.GetDoc_User_ID()); ////Added By Arpit asked by Surya Sir..................29-12-2015 //_order.SetSalesRep_ID(GetCtx().GetAD_User_ID()); //End if (tel.GetC_Activity_ID() != 0) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (tel.GetC_Project_ID() != 0) { _order.SetC_Project_ID(tel.GetC_Project_ID()); // Optionally Overwrite BP Price list from Project MProject project = new MProject(GetCtx(), tel.GetC_Project_ID(), Get_TrxName()); if (project.GetM_PriceList_ID() != 0) { //check weather the PriceList is active or not if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM M_PriceList WHERE M_PriceList_ID=" + project.GetM_PriceList_ID(), null, Get_Trx())).Equals("Y")) { _order.SetM_PriceList_ID(project.GetM_PriceList_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePriceList"); return; } } } else { if (bp.GetM_PriceList_ID() != 0) { if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM M_PriceList WHERE M_PriceList_ID=" + bp.GetM_PriceList_ID(), null, Get_Trx())).Equals("Y")) { _order.SetM_PriceList_ID(bp.GetM_PriceList_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePriceList"); return; } } } _order.SetSalesRep_ID(te.GetDoc_User_ID()); // if (!_order.Save()) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { message = pp.GetName(); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg("", pp.GetValue()); } } if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg(GetCtx(), "CantSaveOrder"); } return; //throw new Exception("Cannot save Order"); } } else { // Update Header info if (tel.GetC_Activity_ID() != 0 && tel.GetC_Activity_ID() != _order.GetC_Activity_ID()) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0 && tel.GetC_Campaign_ID() != _order.GetC_Campaign_ID()) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (!_order.Save()) { Rollback(); //get error message from ValueNamePair ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { message = pp.GetName(); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg("", pp.GetValue()); } } //it will check message is null or not if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg(GetCtx(), "CantSaveOrder"); } return; //new Exception("Cannot save Order"); } } // OrderLine MOrderLine ol = new MOrderLine(_order); // if (tel.GetM_Product_ID() != 0) { ol.SetM_Product_ID(tel.GetM_Product_ID(), tel.GetC_UOM_ID()); } if (tel.GetS_ResourceAssignment_ID() != 0) { ol.SetS_ResourceAssignment_ID(tel.GetS_ResourceAssignment_ID()); } // Set charge ID if (tel.GetC_Charge_ID() != 0) { ol.SetC_Charge_ID(tel.GetC_Charge_ID()); ol.SetPriceActual(tel.GetExpenseAmt()); ol.SetQty(tel.GetQty()); } ol.SetQty(tel.GetQtyInvoiced()); // ol.SetDescription(tel.GetDescription()); // ol.SetC_Project_ID(tel.GetC_Project_ID()); ol.SetC_ProjectPhase_ID(tel.GetC_ProjectPhase_ID()); ol.SetC_ProjectTask_ID(tel.GetC_ProjectTask_ID()); ol.SetC_Activity_ID(tel.GetC_Activity_ID()); ol.SetC_Campaign_ID(tel.GetC_Campaign_ID()); // Decimal price = tel.GetPriceInvoiced(); // if (price.CompareTo(Env.ZERO) != 0) { if (tel.GetC_Currency_ID() != _order.GetC_Currency_ID()) { price = MConversionRate.Convert(GetCtx(), price, tel.GetC_Currency_ID(), _order.GetC_Currency_ID(), _order.GetAD_Client_ID(), _order.GetAD_Org_ID()); } ol.SetPrice(price); // added by Bhupendra to set the entered price ol.SetPriceEntered(price); } else { ol.SetPrice(); } if (tel.GetC_UOM_ID() != 0 && ol.GetC_UOM_ID() == 0) { ol.SetC_UOM_ID(tel.GetC_UOM_ID()); } ol.SetTax(); if (!ol.Save()) { Rollback(); //get error message from ValueNamePair ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { message = pp.GetName(); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg("", pp.GetValue()); } } //it will check message is null or not if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg(GetCtx(), "CantSaveOrderLine"); } return; //throw new Exception("Cannot save Order Line"); } // Update TimeExpense Line tel.SetC_OrderLine_ID(ol.GetC_OrderLine_ID()); if (tel.Save()) { log.Fine("Updated " + tel + " with C_OrderLine_ID"); } else { log.Log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID"); } } // processLine