/** * Create Difference Document * @param inout shipment/receipt * @param confirm confirm line * @return true if created */ private bool CreateDifferenceDoc(MInOut inout, MInOutLineConfirm confirm) { if (_processMsg == null) { _processMsg = ""; } else if (_processMsg.Length > 0) { _processMsg += "; "; } // Credit Memo if linked Document if (Env.Signum(confirm.GetDifferenceQty()) != 0 && !inout.IsSOTrx() && !inout.IsReturnTrx() && inout.GetRef_InOut_ID() != 0) { log.Info("Difference=" + confirm.GetDifferenceQty()); if (_creditMemo == null) { _creditMemo = new MInvoice(inout, null); _creditMemo.SetDescription(Msg.Translate(GetCtx(), "M_InOutConfirm_ID") + " " + GetDocumentNo()); _creditMemo.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APCREDITMEMO); if (!_creditMemo.Save(Get_TrxName())) { _processMsg += "Credit Memo not created"; return(false); } SetC_Invoice_ID(_creditMemo.GetC_Invoice_ID()); } MInvoiceLine line = new MInvoiceLine(_creditMemo); line.SetShipLine(confirm.GetLine()); line.SetQty(confirm.GetDifferenceQty()); // Entered/Invoiced if (!line.Save(Get_TrxName())) { _processMsg += "Credit Memo Line not created"; return(false); } confirm.SetC_InvoiceLine_ID(line.GetC_InvoiceLine_ID()); } // Create Inventory Difference if (Env.Signum(confirm.GetScrappedQty()) != 0) { log.Info("Scrapped=" + confirm.GetScrappedQty()); if (_inventory == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), inout.GetM_Warehouse_ID()); _inventory = new MInventory(wh); _inventory.SetDescription(Msg.Translate(GetCtx(), "M_InOutConfirm_ID") + " " + GetDocumentNo()); if (!_inventory.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } SetM_Inventory_ID(_inventory.GetM_Inventory_ID()); } MInOutLine ioLine = confirm.GetLine(); MInventoryLine line = new MInventoryLine(_inventory, ioLine.GetM_Locator_ID(), ioLine.GetM_Product_ID(), ioLine.GetM_AttributeSetInstance_ID(), confirm.GetScrappedQty(), Env.ZERO); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // if (!confirm.Save(Get_TrxName())) { _processMsg += "Confirmation Line not saved"; return(false); } return(true); }
/** * Complete Document * @return new status (Complete, In Progress, Invalid, Waiting ..) */ public String CompleteIt() { // Re-Check if (!_justPrepared) { String status = PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { return(status); } } // Implicit Approval if (!IsApproved()) { ApproveIt(); } log.Info(ToString()); // MInOut inout = new MInOut(GetCtx(), GetM_InOut_ID(), Get_TrxName()); MInOutLineConfirm[] lines = GetLines(false); // Check if we need to split Shipment if (IsInDispute()) { MDocType dt = MDocType.Get(GetCtx(), inout.GetC_DocType_ID()); if (dt.IsSplitWhenDifference()) { if (dt.GetC_DocTypeDifference_ID() == 0) { _processMsg = "No Split Document Type defined for: " + dt.GetName(); return(DocActionVariables.STATUS_INVALID); } SplitInOut(inout, dt.GetC_DocTypeDifference_ID(), lines); _lines = null; } } // All lines for (int i = 0; i < lines.Length; i++) { MInOutLineConfirm confirmLine = lines[i]; confirmLine.Set_TrxName(Get_TrxName()); if (!confirmLine.ProcessLine(inout.IsSOTrx(), GetConfirmType())) { _processMsg = "ShipLine not saved - " + confirmLine; return(DocActionVariables.STATUS_INVALID); } if (confirmLine.IsFullyConfirmed()) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { if (CreateDifferenceDoc(inout, confirmLine)) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { log.Log(Level.SEVERE, "Scrapped=" + confirmLine.GetScrappedQty() + " - Difference=" + confirmLine.GetDifferenceQty()); return(DocActionVariables.STATUS_INVALID); } } } // for all lines if (_creditMemo != null) { _processMsg += " @C_Invoice_ID@=" + _creditMemo.GetDocumentNo(); } if (_inventory != null) { _processMsg += " @M_Inventory_ID@=" + _inventory.GetDocumentNo(); } // User Validation String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE); if (valid != null) { _processMsg = valid; return(DocActionVariables.STATUS_INVALID); } SetProcessed(true); SetDocAction(DOCACTION_Close); return(DocActionVariables.STATUS_COMPLETED); }