86) COC Invent table

 //// <summary>

/// The <c>AvaInventTransferTable_Extension</c> contains the TransMountain eventing logic for the <c>InventtransferTable</c> table.

/// </summary>

[ExtensionOf(tableStr(InventTransferTable))]

final class AvaInventTransferTable_Extension

{


    /// <summary>

    /// diplay method to get the tracking ID of Transfer order.

    /// FDD :- EXT_004_TrackItemShipment

    /// </summary>

    [sysClientCacheDataMethod(true)]

    display public static InventTransferTrackingId avaTrackingID(InventTransferTable _this)

    {

        InventTransferJour  transferJour;


        select firstonly TrackingId from  transferJour

            order by TrackingId desc

            where transferJour.TransferId == _this.TransferId;

            

        return transferJour.TrackingId;


    }


    /// <summary>

    /// Fill the values of work order.

    /// FDD : - EXT_004_TrackItemShipment

    /// </summary>


    public void avaInitFromworkOrderTable(EntAssetWorkOrderLine  _entAssetWorkOrderLine)

    {

        this.InventLocationIdFrom = EntAssetParameters::find().AvaDefaultFromWarehouse;

        this.modifiedField(fieldNum(InventTransferTable, InventLocationIdFrom));

        this.InventLocationIdTo   = _entAssetWorkOrderLine.functionalLocation().InventLocationId;

        this.modifiedField(fieldNum(InventTransferTable, InventLocationIdTo));

        this.AvaWorkOrderTable    = _entAssetWorkOrderLine.workOrderTable().RecId;

        this.FromContactPerson    = HcmWorker::userId2Worker(curUserId());

    }


    /// <summary>

    /// Validate the work id is exist or not  in transfer order form lookup.

    /// FDD : - EXT_004_TrackItemShipment

    /// </summary>

    public boolean avaValidateWorkOrderId()

    {

        boolean                         ret = true;

        

        if(EntAssetWorkOrderTable::findRecId(this.AvaWorkOrderTable).lifecycleState().AvaEnableTransferOrder)

        {

            ret = checkFailed(strFmt("@AvaTransMountain:AVAWorkOrderIDNotFound_Label", EntAssetWorkOrderTable::findRecId(this.AvaWorkOrderTable).WorkOrderId));

           

        }

        return ret;

    }


    public boolean validateField(FieldId _fieldIdToCheck)

    {

        boolean ret;

        

        ret = next validateField(_fieldIdToCheck);

        

        if (ret && _fieldIdToCHeck == fieldNum(InventTransferTable, AvaWorkOrderTable) && this.AvaWorkOrderTable)

        {

            ret = ret && this.avaValidateWorkOrderId();

        }

        return ret;

    }


    /// <summary>

    /// Will update the work order status on the basis of transfer order

    /// FDD : - EXT_004_TrackItemShipment

    /// </summary>

    public void insert()

    {

        next insert();


        InventTransferTable::avaUpdateWorkOrderStatus(this);

    }


    /// <summary>

    /// Will update the work order status on the basis of transfer order

    /// FDD : - EXT_004_TrackItemShipment

    /// </summary>

    public void update()

    {


        next update();


        InventTransferTable::avaUpdateWorkOrderStatus(this);

        //Bug_8993_FDD:EXT_004_TrackItemShipment_04.08.2020_Vinay_Sn

        InventTransferTable::avaUpdateToTransferContact(this);

        //Bug_8993_FDD:EXT_004_TrackItemShipment_04.08.2020_Vinay_En


        

    }


    /// <summary>

    /// Will update the work order status on the basis of transfer order

    /// FDD : - EXT_004_TrackItemShipment

    /// </summary>

    public void delete()

    {

        next delete();


        InventTransferTable::avaUpdateWorkOrderStatus(this);

    }


    /// <summary>

    /// Will update the work order status on the basis of transfer order 

    /// FDD : - EXT_004_TrackItemShipment

    /// </summary>

    public static void avaUpdateWorkOrderStatus(InventTransferTable _invenTransferTable)

    {

        inventTransferTable     inventTransferTable;

        InventTransferStatus    minInventTransferStatus;

        AvaWorkOrderTransferStatus transferStatus;

        

        select AvaWorkOrderTable, minof(TransferStatus) from inventTransferTable

            group by AvaWorkOrderTable

            where inventTransferTable.AvaWorkOrderTable  == _invenTransferTable.AvaWorkOrderTable;


        // Bug_8992_FDD:EXT_004_TrackItemShipment_04.08.2020_VinayT_So

        //if (!inventTransferTable.AvaWorkOrderTable)

        // Bug_8992_FDD:EXT_004_TrackItemShipment_04.08.2020_VinayT_Eo


        // Bug_8992_FDD:EXT_004_TrackItemShipment_04.08.2020_VinayT_Sn

        if (inventTransferTable.AvaWorkOrderTable)

        // Bug_8992_FDD:EXT_004_TrackItemShipment_04.08.2020_VinayT_En

        {

            transferstatus = InventTransferTable::AvaGetorkOrderTransferStatusFromTransferStatus(inventTransferTable.TransferStatus);

        }

        else

        {

            transferStatus = AvaWorkOrderTransferStatus::Blank;

        }


        ttsbegin;


        EntAssetWorkOrderTable workOrderTable = EntAssetWorkOrderTable::findRecId(_invenTransferTable.AvaWorkOrderTable, true);

       

        if (workOrderTable)

        {

            workOrderTable.AvaTransferStatus = transferStatus;

            workOrderTable.doUpdate();

        }


        ttscommit;

    }


    public static AvaWorkOrderTransferStatus avaGetorkOrderTransferStatusFromTransferStatus(InventTransferStatus _inventTransferStatus)

    {

        switch(_inventTransferStatus)

        {

            case InventTransferStatus::Created:

                return AvaWorkOrderTransferStatus::Pending;

            case InventTransferStatus::Shipped:

                return AvaWorkOrderTransferStatus::Shipped;

            case InventTransferStatus::Received:

                return AvaWorkOrderTransferStatus::Received;

            default:

                return AvaWorkOrderTransferStatus::Blank;

        }

    }


    public EntAssetWorkOrderTable avaWorkOrderTable(boolean _forUpdate = false)

    {

        EntAssetWorkOrderTable workOrderTableLocal;

        if (this.AvaWorkOrderTable)

        {

            workOrderTableLocal = EntAssetWorkOrderTable::findRecId(this.AvaWorkOrderTable, _forUpdate);

        }

        return workOrderTableLocal;

    }


    /// <summary>

    /// Update the To Transfer contact when the transfer order status is in received status.

    /// FDD :- EXT_004_TrackItemShipment.

    /// Bug_8993_FDD:EXT_004_TrackItemShipment_04.08.2020_Vinay

    /// </summary>

    public static void avaUpdateToTransferContact(InventTransferTable   _this)

    {

        InventTransferTable inventTransferTable;


        ttsbegin;

        if(_this.Transferstatus ==  InventTransferStatus::Received)

        {

            select forupdate ToContactPerson from inventTransferTable

                where inventTransferTable.TransferId  == _this.TransferId;


            inventTransferTable.ToContactPerson = HcmWorker::userId2Worker(curUserId());

            inventTransferTable.doupdate();

            

        }

        ttscommit;

        

       

    }


}

Comments

Post a Comment

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++