/// <summary> /// GetPriceList /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Dictionary <String, String> GetPriceList(Ctx ctx, string fields) { if (fields != null) { string[] paramValue = fields.ToString().Split(','); int M_PriceList_ID; //Assign parameter value M_PriceList_ID = Util.GetValueOfInt(paramValue[0].ToString()); //End Assign parameter value MPriceList prcLst = new MPriceList(ctx, M_PriceList_ID, null); Dictionary <String, String> retDic = new Dictionary <string, string>(); // Reset Orig Shipment MCurrency crncy = new MCurrency(ctx, prcLst.GetC_Currency_ID(), null); //retDic["StdPrecision"] = prcLst.GetPricePrecision().ToString(); //JID_1744 Precision should be as per currency percision retDic["StdPrecision"] = crncy.GetStdPrecision().ToString(); return(retDic); } else { return(null); } }
/// <summary> /// Set Source Amounts /// </summary> /// <param name="C_Currency_ID">currency</param> /// <param name="AmtSourceDr">source amount dr</param> /// <param name="AmtSourceCr">source amount cr</param> /// <returns>true, if any if the amount is not zero</returns> public bool SetAmtSource(int C_Currency_ID, Decimal?AmtSourceDr, Decimal?AmtSourceCr) { SetC_Currency_ID(C_Currency_ID); if (AmtSourceDr != null) { SetAmtSourceDr(AmtSourceDr); } if (AmtSourceCr != null) { SetAmtSourceCr(AmtSourceCr); } // one needs to be non zero if (GetAmtSourceDr().Equals(Env.ZERO) && GetAmtSourceCr().Equals(Env.ZERO)) { return(false); } // Currency Precision int precision = MCurrency.GetStdPrecision(GetCtx(), C_Currency_ID); if (AmtSourceDr != null && Env.Scale(AmtSourceDr.Value) > precision) { Decimal AmtSourceDr1 = Decimal.Round(AmtSourceDr.Value, precision, MidpointRounding.AwayFromZero); log.Warning("Source DR Precision " + AmtSourceDr.Value + " -> " + AmtSourceDr1); SetAmtSourceDr(AmtSourceDr1); } if (AmtSourceCr != null && Env.Scale(AmtSourceCr.Value) > precision) { Decimal AmtSourceCr1 = Decimal.Round(AmtSourceCr.Value, precision, MidpointRounding.AwayFromZero); log.Warning("Source CR Precision " + AmtSourceCr + " -> " + AmtSourceCr1); SetAmtSourceCr(AmtSourceCr1); } return(true); }
/// <summary> /// Get Currency Percision /// </summary> /// <returns>precision</returns> private int GetStdPercision() { if (_precision == -1) { _precision = MCurrency.GetStdPrecision(GetCtx(), GetC_Currency_ID()); } return(_precision); }
/// <summary> /// Get Currency Detail /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Dictionary <string, string> GetCurrency(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); //Assign parameter value int C_Currency_ID = Util.GetValueOfInt(paramValue[0].ToString()); //End Assign parameter MCurrency currency = MCurrency.Get(ctx, C_Currency_ID); Dictionary <string, string> result = new Dictionary <string, string>(); result["StdPrecision"] = currency.GetStdPrecision().ToString(); return(result); }
public MVA009OrderPaySchedule(MOrder order, MPaySchedule paySchedule) : base(order.GetCtx(), 0, order.Get_TrxName()) { _parent = order; SetClientOrg(order); SetC_Order_ID(order.GetC_Order_ID()); SetC_PaySchedule_ID(paySchedule.GetC_PaySchedule_ID()); // Amounts int scale = MCurrency.GetStdPrecision(GetCtx(), order.GetC_Currency_ID()); Decimal due = order.GetGrandTotal(); if (due.CompareTo(Env.ZERO) == 0) { SetDueAmt(Env.ZERO); SetDiscountAmt(Env.ZERO); //SetIsValid(false); } else { //due = due.multiply(paySchedule.getPercentage()).divide(HUNDRED, scale, Decimal.ROUND_HALF_UP); due = Decimal.Multiply(due, Decimal.Divide(paySchedule.GetPercentage(), Decimal.Round(HUNDRED, scale, MidpointRounding.AwayFromZero))); SetDueAmt(due); Decimal discount = Decimal.Multiply(due, Decimal.Divide(paySchedule.GetDiscount(), Decimal.Round(HUNDRED, scale, MidpointRounding.AwayFromZero))); SetDiscountAmt(discount); //SetIsValid(true); } // Dates DateTime dueDate = TimeUtil.AddDays(order.GetDateOrdered(), paySchedule.GetNetDays()); SetDueDate(dueDate); DateTime discountDate = TimeUtil.AddDays(order.GetDateOrdered(), paySchedule.GetDiscountDays()); SetDiscountDate(discountDate); }
protected override String DoIt() { MInvoice obj = new MInvoice(GetCtx(), GetRecord_ID(), Get_Trx()); // get Precision for rounding MCurrency currency = new MCurrency(GetCtx(), obj.GetC_Currency_ID(), Get_Trx()); precision = currency.GetStdPrecision(); MInvoiceLine[] lines = obj.GetLines(); if (_IsCLearDiscount == "N") { if (_DiscountAmt == 0 && _DiscountPercent == 0) { return(Msg.GetMsg(GetCtx(), "PlsSelAtlstOneField")); } if (_DiscountAmt != 0 && _DiscountPercent != 0) { return(Msg.GetMsg(GetCtx(), "PlsSelOneField")); } // get amount on which we have to apply discount subTotal = obj.GetTotalLines(); // when we are giving discount in terms of amount, then we have to calculate discount in term of percentage discountPercentageOnTotalAmount = GetDiscountPercentageOnTotal(subTotal, _DiscountAmt, precision); for (int i = 0; i < lines.Length; i++) { MInvoiceLine ln = lines[i]; // this value represent discount on line net amount discountAmountOnTotal = GetDiscountAmountOnTotal(ln.GetLineNetAmt(), discountPercentageOnTotalAmount != 0 ? discountPercentageOnTotalAmount : _DiscountPercent); // this value represent discount on unit price of 1 qty discountAmountOnTotal = Decimal.Round(Decimal.Divide(discountAmountOnTotal, ln.GetQtyEntered()), precision); ln.SetAmountAfterApplyDiscount(Decimal.Add(ln.GetAmountAfterApplyDiscount(), discountAmountOnTotal)); ln.SetPriceActual(Decimal.Round(Decimal.Subtract(ln.GetPriceActual(), discountAmountOnTotal), precision)); ln.SetPriceEntered(Decimal.Round(Decimal.Subtract(ln.GetPriceEntered(), discountAmountOnTotal), precision)); // set tax amount as 0, so that on before save we calculate tax again on discounted price ln.SetTaxAmt(0); if (!ln.Save(Get_TrxName())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); log.Info("ApplyDiscountInvoiceVendor : Not Saved. Error Value : " + pp.GetValue() + " , Error Name : " + pp.GetName()); throw new Exception(Msg.GetMsg(GetCtx(), "DiscNotApplied")); } } return(Msg.GetMsg(GetCtx(), "DiscAppliedSuccess")); } else { for (int i = 0; i < lines.Length; i++) { MInvoiceLine ln = lines[i]; ln.SetPriceEntered(Decimal.Add(ln.GetPriceEntered(), ln.GetAmountAfterApplyDiscount())); ln.SetPriceActual(Decimal.Add(ln.GetPriceActual(), ln.GetAmountAfterApplyDiscount())); ln.SetAmountAfterApplyDiscount(0); ln.SetTaxAmt(0); if (!ln.Save(Get_TrxName())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); log.Info("ApplyDiscountInvoiceVendor : Not Saved. Error Value : " + pp.GetValue() + " , Error Name : " + pp.GetName()); throw new Exception(Msg.GetMsg(GetCtx(), "DiscNotCleared")); } } return(Msg.GetMsg(GetCtx(), "DiscClearedSuccessfully")); } }
/** * Before Save * @param newRecord new * @return true */ protected override bool BeforeSave(bool newRecord) { if (Is_ValueChanged("DueAmt")) { log.Fine("beforeSave"); SetIsValid(false); } oldDueAmt = Util.GetValueOfDecimal(Get_ValueOld("DueAmt")); if (Env.IsModuleInstalled("VA009_")) { // get invoice currency for rounding MCurrency currency = MCurrency.Get(GetCtx(), GetC_Currency_ID()); SetDueAmt(Decimal.Round(GetDueAmt(), currency.GetStdPrecision())); SetVA009_PaidAmntInvce(Decimal.Round(GetVA009_PaidAmntInvce(), currency.GetStdPrecision())); // when invoice schedule have payment reference then need to check payment mode on payment window & update here if (GetC_Payment_ID() > 0) { #region for payment MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_Trx()); SetVA009_PaymentMethod_ID(payment.GetVA009_PaymentMethod_ID()); // get payment method detail -- update to here DataSet dsPaymentMethod = DB.ExecuteDataset(@"SELECT VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID = " + payment.GetVA009_PaymentMethod_ID(), null, Get_Trx()); if (dsPaymentMethod != null && dsPaymentMethod.Tables.Count > 0 && dsPaymentMethod.Tables[0].Rows.Count > 0) { if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"]))) { SetVA009_PaymentMode(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"])); } if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"]))) { SetVA009_PaymentType(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"])); } SetVA009_PaymentTrigger(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentTrigger"])); } #endregion } else if (GetC_CashLine_ID() > 0) { #region For Cash // when invoice schedule have cashline reference then need to check // payment mode of "Cash" type having currency is null on "Payment Method" window & update here DataSet dsPaymentMethod = (DB.ExecuteDataset(@"SELECT VA009_PaymentMethod_ID, VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod WHERE IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID() + @" AND VA009_PaymentBaseType = 'B' AND NVL(C_Currency_ID , 0) = 0", null, Get_Trx())); if (dsPaymentMethod != null && dsPaymentMethod.Tables.Count > 0 && dsPaymentMethod.Tables[0].Rows.Count > 0) { SetVA009_PaymentMethod_ID(Util.GetValueOfInt(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMethod_ID"])); if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"]))) { SetVA009_PaymentMode(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"])); } if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"]))) { SetVA009_PaymentType(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"])); } SetVA009_PaymentTrigger(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentTrigger"])); } else { #region when we not found record of "Cash" then we will create a new rcord on Payment Method for Cash string sql = @"SELECT AD_TABLE_ID FROM AD_TABLE WHERE tablename LIKE 'VA009_PaymentMethod' AND IsActive = 'Y'"; int tableId = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null)); MTable tbl = new MTable(GetCtx(), tableId, Get_Trx()); PO po = tbl.GetPO(GetCtx(), 0, Get_Trx()); po.SetAD_Client_ID(GetAD_Client_ID()); po.SetAD_Org_ID(0); // Recod will be created in (*) Organization po.Set_Value("Value", "By Cash"); po.Set_Value("VA009_Name", "By Cash"); po.Set_Value("IsActive", true); po.Set_Value("VA009_PaymentBaseType", "B"); po.Set_Value("VA009_PaymentRule", "M"); po.Set_Value("VA009_PaymentMode", "C"); po.Set_Value("VA009_PaymentType", "S"); po.Set_Value("VA009_PaymentTrigger", "S"); po.Set_Value("C_Currency_ID", null); po.Set_Value("VA009_InitiatePay", false); if (!po.Save(Get_Trx())) { ValueNamePair pp = VLogger.RetrieveError(); log.Info("Error Occured when try to save record on Payment Method for Cash. Error Type : " + pp.GetValue()); } else { SetVA009_PaymentMethod_ID(Util.GetValueOfInt(po.Get_Value("VA009_PaymentMethod_ID"))); SetVA009_PaymentMode("C"); SetVA009_PaymentType("S"); SetVA009_PaymentTrigger("S"); } #endregion } #endregion } } return(true); }
/// <summary> /// Get Commitments /// </summary> /// <param name="doc">document</param> /// <param name="maxQty">Qty invoiced/matched</param> /// <param name="C_InvoiceLine_ID">invoice line</param> /// <returns>commitments (order lines)</returns> protected static DocLine[] GetCommitments(Doc doc, Decimal maxQty, int C_InvoiceLine_ID) { int precision = -1; // List <DocLine> list = new List <DocLine>(); String sql = "SELECT * FROM C_OrderLine ol " + "WHERE EXISTS " + "(SELECT * FROM C_InvoiceLine il " + "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND il.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")" + " OR EXISTS " + "(SELECT * FROM M_MatchPO po " + "WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND po.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")"; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, null); while (idr.Read()) { if (Env.Signum(maxQty) == 0) { continue; } MOrderLine line = new MOrderLine(doc.GetCtx(), idr, null); DocLine docLine = new DocLine(line, doc); // Currency if (precision == -1) { doc.SetC_Currency_ID(docLine.GetC_Currency_ID()); precision = MCurrency.GetStdPrecision(doc.GetCtx(), docLine.GetC_Currency_ID()); } // Qty Decimal Qty = Math.Max(line.GetQtyOrdered(), maxQty); docLine.SetQty(Qty, false); // Decimal PriceActual = line.GetPriceActual(); Decimal PriceCost = line.GetPriceCost(); Decimal?LineNetAmt = null; if (Env.Signum(PriceCost) != 0) { LineNetAmt = Decimal.Multiply(Qty, PriceCost); } else if (Qty.Equals(maxQty)) { LineNetAmt = line.GetLineNetAmt(); } else { LineNetAmt = Decimal.Multiply(Qty, PriceActual); } maxQty = Decimal.Subtract(maxQty, Qty); docLine.SetAmount(LineNetAmt); // DR Decimal PriceList = line.GetPriceList(); int C_Tax_ID = docLine.GetC_Tax_ID(); // Correct included Tax if (C_Tax_ID != 0 && line.GetParent().IsTaxIncluded()) { MTax tax = MTax.Get(doc.GetCtx(), C_Tax_ID); if (!tax.IsZeroTax()) { Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt.Value, true, precision); _log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = Decimal.Subtract(LineNetAmt.Value, LineNetAmtTax); Decimal PriceListTax = tax.CalculateTax(PriceList, true, precision); PriceList = Decimal.Subtract(PriceList, PriceListTax); } } // correct included Tax docLine.SetAmount(LineNetAmt, PriceList, Qty); list.Add(docLine); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); idr = null; } _log.Log(Level.SEVERE, sql, e); } // Return Array DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }