/** * After Delete * @param success success * @return success */ protected override bool AfterDelete(bool success) { if (success) { // Get Order and decrease invoices MInvoiceLine iLine = new MInvoiceLine(GetCtx(), GetC_InvoiceLine_ID(), Get_TrxName()); int C_OrderLine_ID = iLine.GetC_OrderLine_ID(); if (C_OrderLine_ID == 0) { MInOutLine ioLine = new MInOutLine(GetCtx(), GetM_InOutLine_ID(), Get_TrxName()); C_OrderLine_ID = ioLine.GetC_OrderLine_ID(); } // No Order Found if (C_OrderLine_ID == 0) { return(success); } // Find MatchPO MMatchPO[] mPO = MMatchPO.Get(GetCtx(), C_OrderLine_ID, GetC_InvoiceLine_ID(), Get_TrxName()); for (int i = 0; i < mPO.Length; i++) { if (mPO[i].GetM_InOutLine_ID() == 0) { mPO[i].Delete(true); } else { mPO[i].SetC_InvoiceLine_ID(null); mPO[i].Save(); } } } return(success); }
/// <summary> /// Shipment Line Constructor /// </summary> /// <param name="sLine">shipment line</param> /// <param name="dateTrx">optional date</param> /// <param name="qty">matched quantity</param> public MMatchPO(MInOutLine sLine, DateTime?dateTrx, Decimal qty) : this(sLine.GetCtx(), 0, sLine.Get_Trx()) { SetClientOrg(sLine); SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); SetC_OrderLine_ID(sLine.GetC_OrderLine_ID()); if (dateTrx != null) { SetDateTrx(dateTrx); } SetM_Product_ID(sLine.GetM_Product_ID()); SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); SetQty(qty); SetProcessed(true); // auto }
/** * Generate Shipments * @param pstmt order query * @return info */ private String Generate(IDataReader idr) { DataTable dt = new DataTable(); try { dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows)// while (dr.next ()) { MOrder order = new MOrder(GetCtx(), dr, Get_TrxName()); // New Invoice Location if (!_ConsolidateDocument || (_invoice != null && (_invoice.GetC_BPartner_Location_ID() != order.GetBill_Location_ID() || _invoice.GetC_PaymentTerm_ID() != order.GetC_PaymentTerm_ID()))) { CompleteInvoice(); } bool completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule()); // Schedule After Delivery bool doInvoice = false; if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.Equals(order.GetInvoiceRule())) { _bp = new MBPartner(GetCtx(), order.GetBill_BPartner_ID(), null); if (_bp.GetC_InvoiceSchedule_ID() == 0) { log.Warning("BPartner has no Schedule - set to After Delivery"); order.SetInvoiceRule(MOrder.INVOICERULE_AfterDelivery); order.Save(); } else { MInvoiceSchedule ins = MInvoiceSchedule.Get(GetCtx(), _bp.GetC_InvoiceSchedule_ID(), Get_TrxName()); if (ins.CanInvoice(order.GetDateOrdered(), order.GetGrandTotal())) { doInvoice = true; } else { continue; } } } // Schedule // After Delivery if (doInvoice || MOrder.INVOICERULE_AfterDelivery.Equals(order.GetInvoiceRule())) { MInOut shipment = null; MInOutLine[] shipmentLines = order.GetShipmentLines(); for (int i = 0; i < shipmentLines.Length; i++) { MInOutLine shipLine = shipmentLines[i]; if (shipLine.IsInvoiced()) { continue; } if (shipment == null || shipment.GetM_InOut_ID() != shipLine.GetM_InOut_ID()) { shipment = new MInOut(GetCtx(), shipLine.GetM_InOut_ID(), Get_TrxName()); } if (!shipment.IsComplete() || // ignore incomplete or reversals shipment.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } // CreateLine(order, shipment, shipLine); } // shipment lines _line += 1000; } // After Order Delivered, Immediate else { MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); if (toInvoice.CompareTo(Env.ZERO) == 0 && oLine.GetM_Product_ID() != 0) { continue; } // bool fullyDelivered = oLine.GetQtyOrdered().CompareTo(oLine.GetQtyDelivered()) == 0; // Complete Order if (completeOrder && !fullyDelivered) { log.Fine("Failed CompleteOrder - " + oLine); completeOrder = false; break; } // Immediate else if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } else { log.Fine("Failed: " + order.GetInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine); } } // for all order lines if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { _line += 1000; } } // Complete Order successful if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule())) { MInOut[] shipments = order.GetShipments(true); for (int i = 0; i < shipments.Length; i++) { MInOut ship = shipments[i]; if (!ship.IsComplete() || // ignore incomplete or reversals ship.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } MInOutLine[] shipLines = ship.GetLines(false); for (int j = 0; j < shipLines.Length; j++) { MInOutLine shipLine = shipLines[j]; if (!order.IsOrderLine(shipLine.GetC_OrderLine_ID())) { continue; } if (!shipLine.IsInvoiced()) { CreateLine(order, ship, shipLine); } } // lines _line += 1000; } // all shipments } // complete Order } // for all orders } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, "", e); } finally { if (idr != null) { idr.Close(); } dt = null; } CompleteInvoice(); return("@Created@ = " + _created); }
/// <summary> /// Generate Invoices /// </summary> /// <param name="idr">pstmt order query</param> /// <returns>info</returns> //private String Generate(IDataReader idr) private String Generate(DataTable dt) { //JID_1139 Avoided the duplicate charge line created Invoice(customer) bool isAllownonItem = Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("Y"); foreach (DataRow dr in dt.Rows) { MOrder order = new MOrder(GetCtx(), dr, Get_TrxName()); // Credit Limit check MBPartner bp = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID()); if (bp.GetCreditStatusSettingOn() == "CH") { decimal creditLimit = bp.GetSO_CreditLimit(); string creditVal = bp.GetCreditValidation(); if (creditLimit != 0) { decimal creditAvlb = creditLimit - bp.GetSO_CreditUsed(); if (creditAvlb <= 0) { if (creditVal == "C" || creditVal == "D" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName()); continue; } else if (creditVal == "I" || creditVal == "J" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName()); } } } } // JID_0161 // change here now will check credit settings on field only on Business Partner Header // Lokesh Chauhan 15 July 2019 else if (bp.GetCreditStatusSettingOn() == X_C_BPartner.CREDITSTATUSSETTINGON_CustomerLocation) { MBPartnerLocation bpl = new MBPartnerLocation(GetCtx(), order.GetC_BPartner_Location_ID(), null); //MBPartner bpartner = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID()); //if (bpl.GetCreditStatusSettingOn() == "CL") //{ decimal creditLimit = bpl.GetSO_CreditLimit(); string creditVal = bpl.GetCreditValidation(); if (creditLimit != 0) { decimal creditAvlb = creditLimit - bpl.GetSO_CreditUsed(); if (creditAvlb <= 0) { if (creditVal == "C" || creditVal == "D" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName() + " " + bpl.GetName()); continue; } else if (creditVal == "I" || creditVal == "J" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName()); } } } //} } // Credit Limit End // New Invoice Location // JID_1237 : While creating invoice need to consolidate order on the basis of Org, Payment Term, BP Location (Bill to Location) and Pricelist. if (!_ConsolidateDocument || (_invoice != null && (_invoice.GetC_BPartner_Location_ID() != order.GetBill_Location_ID() || _invoice.GetC_PaymentTerm_ID() != order.GetC_PaymentTerm_ID() || _invoice.GetM_PriceList_ID() != order.GetM_PriceList_ID() || _invoice.GetAD_Org_ID() != order.GetAD_Org_ID() || ((_invoice.GetC_ConversionType_ID() != 0 ? _invoice.GetC_ConversionType_ID() : defaultConversionType) != (order.GetC_ConversionType_ID() != 0 ? order.GetC_ConversionType_ID() : defaultConversionType)) ))) { CompleteInvoice(); } bool completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule()); // Schedule After Delivery bool doInvoice = false; if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.Equals(order.GetInvoiceRule())) { _bp = new MBPartner(GetCtx(), order.GetBill_BPartner_ID(), null); if (_bp.GetC_InvoiceSchedule_ID() == 0) { log.Warning("BPartner has no Schedule - set to After Delivery"); order.SetInvoiceRule(MOrder.INVOICERULE_AfterDelivery); order.Save(); } else { MInvoiceSchedule ins = MInvoiceSchedule.Get(GetCtx(), _bp.GetC_InvoiceSchedule_ID(), Get_TrxName()); if (ins.CanInvoice(order.GetDateOrdered(), order.GetGrandTotal())) { doInvoice = true; } else { continue; } } } // Schedule // After Delivery if (doInvoice || MOrder.INVOICERULE_AfterDelivery.Equals(order.GetInvoiceRule())) { MInOut shipment = null; MInOutLine[] shipmentLines = order.GetShipmentLines(); MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < shipmentLines.Length; i++) { MInOutLine shipLine = shipmentLines[i]; if (shipLine.IsInvoiced()) { continue; } if (shipment == null || shipment.GetM_InOut_ID() != shipLine.GetM_InOut_ID()) { shipment = new MInOut(GetCtx(), shipLine.GetM_InOut_ID(), Get_TrxName()); } if (!shipment.IsComplete() || // ignore incomplete or reversals shipment.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } //JID_1139 Avoided the duplicate charge records if (shipLine.GetM_Product_ID() > 0 || isAllownonItem) { CreateLine(order, shipment, shipLine); } }// shipment lines //JID_1139 Avoided the duplicate charge records if (!isAllownonItem) { for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; if (oLine.GetC_Charge_ID() > 0) { Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } //JID_1139_1 avoided the charge line with 0 qty inserted if (oLine.IsContract() == false && oLine.GetQtyOrdered() > oLine.GetQtyInvoiced()) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } } } } // After Order Delivered, Immediate else { MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); if (toInvoice.CompareTo(Env.ZERO) == 0 && oLine.GetM_Product_ID() != 0) { continue; } // bool fullyDelivered = oLine.GetQtyOrdered().CompareTo(oLine.GetQtyDelivered()) == 0; //JID_1136: While creating the Invoices against the charge system should not check the Ordered qty= Delivered qty. need to check this only in case of products if (completeOrder && oLine.GetC_Charge_ID() > 0) { fullyDelivered = true; if (oLine.GetC_Charge_ID() > 0) { log.Fine("After Order Delivery - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false && !isAllownonItem) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } } // Complete Order if (completeOrder && !fullyDelivered) { log.Fine("Failed CompleteOrder - " + oLine); completeOrder = false; break; } // Immediate else if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } else { log.Fine("Failed: " + order.GetInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine); } } // for all order lines if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { _line += 1000; } } // Complete Order successful if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule())) { MInOut[] shipments = order.GetShipments(true); for (int i = 0; i < shipments.Length; i++) { MInOut ship = shipments[i]; if (!ship.IsComplete() || // ignore incomplete or reversals ship.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } MInOutLine[] shipLines = ship.GetLines(false); for (int j = 0; j < shipLines.Length; j++) { MInOutLine shipLine = shipLines[j]; if (!order.IsOrderLine(shipLine.GetC_OrderLine_ID())) { continue; } if (!shipLine.IsInvoiced()) { CreateLine(order, ship, shipLine); } } // lines _line += 1000; } // all shipments } // complete Order } // for all orders CompleteInvoice(); return("@Created@ = " + _created); }
/** * Split Shipment into confirmed and dispute * @param original original shipment * @param C_DocType_ID target DocType * @param confirmLines confirm lines */ private void SplitInOut(MInOut original, int C_DocType_ID, MInOutLineConfirm[] confirmLines) { MInOut split = new MInOut(original, C_DocType_ID, original.GetMovementDate()); split.AddDescription("Splitted from " + original.GetDocumentNo()); split.SetIsInDispute(true); // new 13 jan int _count = Util.GetValueOfInt(DB.ExecuteScalar("SELECT count(*) FROM AD_Column clm INNER JOIN ad_table tbl on (tbl.ad_table_id=clm.ad_table_id) where tbl.tablename='M_InOutLineConfirm' and clm.columnname = 'M_Locator_ID' ")); //nnayak : Change for bug 1431337 split.SetRef_InOut_ID(original.Get_ID()); if (!split.Save(Get_TrxName())) { throw new Exception("Cannot save Split"); } original.AddDescription("Split: " + split.GetDocumentNo()); if (!original.Save(Get_TrxName())) { throw new Exception("Cannot update original Shipment"); } // Go through confirmations for (int i = 0; i < confirmLines.Length; i++) { MInOutLineConfirm confirmLine = confirmLines[i]; Decimal differenceQty = confirmLine.GetDifferenceQty(); if (differenceQty.CompareTo(Env.ZERO) == 0) { continue; } // MInOutLine oldLine = confirmLine.GetLine(); log.Fine("Qty=" + differenceQty + ", Old=" + oldLine); // MInOutLine splitLine = new MInOutLine(split); splitLine.SetC_OrderLine_ID(oldLine.GetC_OrderLine_ID()); splitLine.SetC_UOM_ID(oldLine.GetC_UOM_ID()); splitLine.SetDescription(oldLine.GetDescription()); splitLine.SetIsDescription(oldLine.IsDescription()); splitLine.SetLine(oldLine.GetLine()); splitLine.SetM_AttributeSetInstance_ID(oldLine.GetM_AttributeSetInstance_ID()); //new 13 jan vikas ,assigne by surya sir if (_count > 0) { if (confirmLine.GetM_Locator_ID() > 0) { splitLine.SetM_Locator_ID(confirmLine.GetM_Locator_ID()); } else { splitLine.SetM_Locator_ID(oldLine.GetM_Locator_ID()); } } else { splitLine.SetM_Locator_ID(oldLine.GetM_Locator_ID()); } //End // splitLine.SetM_Locator_ID(oldLine.GetM_Locator_ID()); splitLine.SetM_Product_ID(oldLine.GetM_Product_ID()); splitLine.SetM_Warehouse_ID(oldLine.GetM_Warehouse_ID()); splitLine.SetRef_InOutLine_ID(oldLine.GetRef_InOutLine_ID()); splitLine.AddDescription("Split: from " + oldLine.GetMovementQty()); // Qtys splitLine.SetQty(differenceQty); // Entered/Movement if (!splitLine.Save(Get_TrxName())) { throw new Exception("Cannot save Split Line"); } // Old oldLine.AddDescription("Splitted: from " + oldLine.GetMovementQty()); oldLine.SetQty(Decimal.Subtract(oldLine.GetMovementQty(), differenceQty)); if (!oldLine.Save(Get_TrxName())) { throw new Exception("Cannot save Splited Line"); } // Update Confirmation Line confirmLine.SetTargetQty(Decimal.Subtract(confirmLine.GetTargetQty(), differenceQty)); confirmLine.SetDifferenceQty(Env.ZERO); if (!confirmLine.Save(Get_TrxName())) { throw new Exception("Cannot save Split Confirmation"); } } // for all confirmations _processMsg = "Split @M_InOut_ID@=" + split.GetDocumentNo() + " - @M_InOutConfirm_ID@="; // Create Dispute Confirmation split.ProcessIt(DocActionVariables.ACTION_PREPARE); // split.createConfirmation(); split.Save(Get_TrxName()); MInOutConfirm[] splitConfirms = split.GetConfirmations(true); if (splitConfirms.Length > 0) { int index = 0; if (splitConfirms[index].IsProcessed()) { if (splitConfirms.Length > 1) { index++; // try just next } if (splitConfirms[index].IsProcessed()) { _processMsg += splitConfirms[index].GetDocumentNo() + " processed??"; return; } } splitConfirms[index].SetIsInDispute(true); splitConfirms[index].Save(Get_TrxName()); _processMsg += splitConfirms[index].GetDocumentNo(); // Set Lines to unconfirmed MInOutLineConfirm[] splitConfirmLines = splitConfirms[index].GetLines(false); for (int i = 0; i < splitConfirmLines.Length; i++) { MInOutLineConfirm splitConfirmLine = splitConfirmLines[i]; splitConfirmLine.SetScrappedQty(Env.ZERO); splitConfirmLine.SetConfirmedQty(Env.ZERO); splitConfirmLine.Save(Get_TrxName()); } } else { _processMsg += "??"; } }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override bool BeforeSave(bool newRecord) { // Set Trx Date if (GetDateTrx() == null) { SetDateTrx(DateTime.Now); } // Set Acct Date if (GetDateAcct() == null) { DateTime?ts = GetNewerDateAcct(); if (ts == null) { ts = GetDateTrx(); } SetDateAcct((DateTime?)ts); } // Set ASI from Receipt if (GetM_AttributeSetInstance_ID() == 0 && GetM_InOutLine_ID() != 0) { MInOutLine iol = new MInOutLine(GetCtx(), GetM_InOutLine_ID(), Get_Trx()); SetM_AttributeSetInstance_ID(iol.GetM_AttributeSetInstance_ID()); } // Find OrderLine if (GetC_OrderLine_ID() == 0) { MInvoiceLine il = null; if (GetC_InvoiceLine_ID() != 0) { il = GetInvoiceLine(); if (il.GetC_OrderLine_ID() != 0) { SetC_OrderLine_ID(il.GetC_OrderLine_ID()); } } // get from invoice if (GetC_OrderLine_ID() == 0 && GetM_InOutLine_ID() != 0) { MInOutLine iol = new MInOutLine(GetCtx(), GetM_InOutLine_ID(), Get_Trx()); if (iol.GetC_OrderLine_ID() != 0) { SetC_OrderLine_ID(iol.GetC_OrderLine_ID()); if (il != null) { il.SetC_OrderLine_ID(iol.GetC_OrderLine_ID()); il.Save(); } } } // get from shipment } // find order line // Price Match Approval if (GetC_OrderLine_ID() != 0 && GetC_InvoiceLine_ID() != 0 && (newRecord || Is_ValueChanged("C_OrderLine_ID") || Is_ValueChanged("C_InvoiceLine_ID"))) { Decimal poPrice = GetOrderLine().GetPriceActual(); Decimal invPrice = GetInvoiceLine().GetPriceActual(); Decimal difference = Decimal.Subtract(poPrice, invPrice); if (Math.Sign(difference) != 0) { difference = Decimal.Multiply(difference, GetQty()); SetPriceMatchDifference(difference); // Approval //MBPGroup group = MBPGroup.getOfBPartner(GetCtx(), GetOrderLine().GetC_BPartner_ID()); Decimal mt = 0; //group.getPriceMatchTolerance(); if (Math.Sign(mt) != 0) { Decimal poAmt = Decimal.Multiply(poPrice, GetQty()); Decimal maxTolerance = Decimal.Multiply(poAmt, mt); //maxTolerance = Math.Abs(maxTolerance) // .divide(Env.ONEHUNDRED, 2, Decimal.ROUND_HALF_UP); maxTolerance = Decimal.Divide(Math.Abs(maxTolerance), Env.ONEHUNDRED); difference = Math.Abs(difference); bool ok = difference.CompareTo(maxTolerance) <= 0; //log.config("Difference=" + GetPriceMatchDifference() // + ", Max=" + maxTolerance + " => " + ok); SetIsApproved(ok); } } else { SetPriceMatchDifference(difference); SetIsApproved(true); } } return(true); }
/** * Find/Create PO(Inv) Match * @param iLine invoice line * @param sLine receipt line * @param dateTrx date * @param qty qty * @return Match Record */ public static MMatchPO Create(MInvoiceLine iLine, MInOutLine sLine, DateTime?dateTrx, Decimal qty) { Trx trxName = null; Ctx ctx = null; int C_OrderLine_ID = 0; if (iLine != null) { trxName = iLine.Get_Trx(); ctx = iLine.GetCtx(); C_OrderLine_ID = iLine.GetC_OrderLine_ID(); } if (sLine != null) { trxName = sLine.Get_Trx(); ctx = sLine.GetCtx(); C_OrderLine_ID = sLine.GetC_OrderLine_ID(); } MMatchPO retValue = null; String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=" + C_OrderLine_ID; // ArrayList list = new ArrayList(); DataSet ds = null; try { ds = DB.ExecuteDataset(sql, null, trxName); foreach (DataRow dr in ds.Tables[0].Rows) { MMatchPO mpo = new MMatchPO(ctx, dr, trxName); if (qty.CompareTo(mpo.GetQty()) == 0) { if (iLine != null) { if (mpo.GetC_InvoiceLine_ID() == 0 || mpo.GetC_InvoiceLine_ID() == iLine.GetC_InvoiceLine_ID()) { mpo.SetC_InvoiceLine_ID(iLine); if (iLine.GetM_AttributeSetInstance_ID() != 0) { if (mpo.GetM_AttributeSetInstance_ID() == 0) { mpo.SetM_AttributeSetInstance_ID(iLine.GetM_AttributeSetInstance_ID()); } else if (mpo.GetM_AttributeSetInstance_ID() != iLine.GetM_AttributeSetInstance_ID()) { continue; } } } else { continue; } } if (sLine != null) { if (mpo.GetM_InOutLine_ID() == 0 || mpo.GetM_InOutLine_ID() == sLine.GetM_InOutLine_ID()) { mpo.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); if (sLine.GetM_AttributeSetInstance_ID() != 0) { if (mpo.GetM_AttributeSetInstance_ID() == 0) { mpo.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); } else if (mpo.GetM_AttributeSetInstance_ID() != sLine.GetM_AttributeSetInstance_ID()) { continue; } } } else { continue; } } retValue = mpo; break; } } } catch (Exception e) { s_log.Log(Level.SEVERE, sql, e); } // Create New if (retValue == null) { if (sLine != null) { retValue = new MMatchPO(sLine, dateTrx, qty); if (iLine != null) { retValue.SetC_InvoiceLine_ID(iLine); } } else if (iLine != null) { retValue = new MMatchPO(iLine, dateTrx, qty); } } return(retValue); }