/** * 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 }
/** * 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 = DataBase.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); }
/// <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); }
/** * 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); //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()); 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 += "??"; } }