/**
         *  Get Counter document for document type
         *	@param ctx context
         *	@param C_DocType_ID base document
         *	@return counter document C_DocType_ID or 0 or -1 if no counter doc
         */
        public static int GetCounterDocType_ID(Ctx ctx, int C_DocType_ID)
        {
            //	Direct Relationship
            MDocTypeCounter dtCounter = GetCounterDocType(ctx, C_DocType_ID);

            if (dtCounter != null)
            {
                if (!dtCounter.IsCreateCounter() || !dtCounter.IsValid())
                {
                    return(-1);
                }
                return(dtCounter.GetCounter_C_DocType_ID());
            }

            //	Indirect Relationship
            int      Counter_C_DocType_ID = 0;
            MDocType dt = MDocType.Get(ctx, C_DocType_ID);

            if (!dt.IsCreateCounter())
            {
                return(-1);
            }
            String cDocBaseType = "";// = getCounterDocBaseType(dt.getDocBaseType());

            if (cDocBaseType == null)
            {
                return(0);
            }
            MDocType[] counters = MDocType.GetOfDocBaseType(ctx, cDocBaseType);
            for (int i = 0; i < counters.Length; i++)
            {
                MDocType counter = counters[i];
                if (counter.IsDefaultCounterDoc())
                {
                    Counter_C_DocType_ID = counter.GetC_DocType_ID();
                    break;
                }
                if (counter.IsDefault())
                {
                    Counter_C_DocType_ID = counter.GetC_DocType_ID();
                }
                else if (i == 0)
                {
                    Counter_C_DocType_ID = counter.GetC_DocType_ID();
                }
            }
            return(Counter_C_DocType_ID);
        }
Beispiel #2
0
        public bool ReActivateIt()
        {
            try
            {
                log.Info(ToString());

                MDocType dt           = MDocType.Get(GetCtx(), GetC_DocType_ID());
                String   DocSubTypeSO = dt.GetDocSubTypeSO();

                //	Replace Prepay with POS to revert all doc
                if (MDocType.DOCSUBTYPESO_PrepayOrder.Equals(DocSubTypeSO))
                {
                    MDocType   newDT = null;
                    MDocType[] dts   = MDocType.GetOfClient(GetCtx());
                    for (int i = 0; i < dts.Length; i++)
                    {
                        MDocType type = dts[i];
                        if (MDocType.DOCSUBTYPESO_PrepayOrder.Equals(type.GetDocSubTypeSO()))
                        {
                            if (type.IsDefault() || newDT == null)
                            {
                                newDT = type;
                            }
                        }
                    }
                    if (newDT == null)
                    {
                        return(false);
                    }
                    else
                    {
                        SetC_DocType_ID(newDT.GetC_DocType_ID());
                        //SetIsReturnTrx(newDT.IsReturnTrx());
                    }
                }

                //	PO - just re-open
                //if (!IsSOTrx())
                //{
                //    log.Info("Existing documents not modified - " + dt);
                //}
                //	Reverse Direct Documents
                else if (MDocType.DOCSUBTYPESO_OnCreditOrder.Equals(DocSubTypeSO) ||    //	(W)illCall(I)nvoice
                         MDocType.DOCSUBTYPESO_WarehouseOrder.Equals(DocSubTypeSO) ||   //	(W)illCall(P)ickup
                         MDocType.DOCSUBTYPESO_POSOrder.Equals(DocSubTypeSO))           //	(W)alkIn(R)eceipt
                {
                    if (!CreateReversals())
                    {
                        return(false);
                    }
                }
                else
                {
                    log.Info("Existing documents not modified - SubType=" + DocSubTypeSO);
                }

                SetDocAction(DOCACTION_Complete);
                SetProcessed(false);
            }
            catch
            {
                //ShowMessage.Error("MOrder", null, "SetBPartner");
            }
            return(true);
        }