/// <summary> /// Get Standard Currency Precision /// </summary> /// <param name="ctx">context </param> /// <param name="M_PriceList_ID">price list</param> /// <returns>precision</returns> public static int GetStandardPrecision(Ctx ctx, int M_PriceList_ID) { MPriceList pl = MPriceList.Get(ctx, M_PriceList_ID, null); return(pl.GetStandardPrecision()); }
/** * Prepare Document * @return new status (In Progress or Invalid) */ public String PrepareIt() { try { log.Info(ToString()); _processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE); if (_processMsg != null) { return(DocActionVariables.STATUS_INVALID); } MRequisitionLine[] lines = GetLines(); // Invalid if (GetAD_User_ID() == 0 || GetM_PriceList_ID() == 0 || GetM_Warehouse_ID() == 0 || lines.Length == 0) { return(DocActionVariables.STATUS_INVALID); } // Std Period open? if (!MPeriod.IsOpen(GetCtx(), GetDateDoc(), MDocBaseType.DOCBASETYPE_PURCHASEREQUISITION)) { _processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // is Non Business Day? if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateDoc())) { _processMsg = Common.Common.NONBUSINESSDAY; return(DocActionVariables.STATUS_INVALID); } // Add up Amounts int precision = MPriceList.GetStandardPrecision(GetCtx(), GetM_PriceList_ID()); Decimal totalLines = Env.ZERO; for (int i = 0; i < lines.Length; i++) { MRequisitionLine line = lines[i]; Decimal lineNet = Decimal.Multiply(line.GetQty(), line.GetPriceActual()); lineNet = Decimal.Round(lineNet, precision);//, MidpointRounding.AwayFromZero); if (lineNet.CompareTo(line.GetLineNetAmt()) != 0) { line.SetLineNetAmt(lineNet); line.Save(); } totalLines = Decimal.Add(totalLines, line.GetLineNetAmt()); } if (totalLines.CompareTo(GetTotalLines()) != 0) { SetTotalLines(totalLines); Save(); } _justPrepared = true; } catch (Exception ex) { // MessageBox.Show("MRequisition--PrepareIt"); log.Severe(ex.ToString()); } return(DocActionVariables.STATUS_INPROGRESS); }