public static void clearReservedPhysical(SalesLine salesLine)
    {
        InventTrans             inventTrans;
        InventTransOrigin       inventTransOrigin;
        WHSWorkLine             whsWorkLine;
        WHSWorkTable            whsWorkTable;

        
        // find the record on sales line base on recid
      //  salesLine = SalesLine::findRecId(_recId);

       while select inventTransOrigin
            where inventTransOrigin.InventTransId == salesLine.InventTransId
            && inventTransOrigin.dataareaId == salesLine.dataareaId
            join inventTrans
            where inventTrans.InventTransOrigin == inventTransOrigin.RecId
            &&  inventTrans.StatusReceipt == StatusReceipt::None
            && (inventTrans.StatusIssue                 == StatusIssue::ReservPhysical
             ||  inventTrans.StatusIssue                 == StatusIssue::ReservOrdered)
           && inventTransOrigin.dataareaId == inventTrans.dataareaId
           && salesLine.dataareaId == curExt()
        {
            if(inventTrans.RecId)
            {
                select firstonly whsWorkLine
                join whsWorkTable
                where whsWorkLine.WorkId == whsWorkTable.WorkId
                && whsWorkLine.InventTransId == inventTransOrigin.InventTransId
                && whsWorkLine.itemId == SalesLine.ItemId
                && whsWorkLine.dataareaId == SalesLine.DataAreaId
                && whsWorkTable.WorkStatus == WHSWorkStatus::Open;
           
                // if no any line contain OPEN work, will update invent reser
                if(!whsWorkLine)
                {
                    InventMovement          inventMovement;
                    InventUpd_Reservation   reservation ;
      
                    ttsbegin;
                    inventMovement = inventTrans.inventmovement(true);
                    // here we set the paramater for InventUpd_Reservation check class InventUpd_Reservation for more info
                    reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTrans.inventDim(),-1 * inventTrans.Qty, false);
                    reservation.updatenow();
                    //info(strFmt("%1",salesLine.reservedPhysicalSalesUnit()));

                    ttscommit;

                }
            }
        }

       

    }

    public static void updateReservedPhysical( SalesLine salesLine)
    {
        InventTrans             inventTrans;
        InventTransOrigin       inventTransOrigin;
        InventMovement          inventMovement;
        InventUpd_Reservation   reservation ;  
        Qty                     qty;

        Qty reservePhysical =  SalesLine.THK_ReservedQuantity;
        Qty reservedPhysical =  SalesLine.orig().THK_ReservedQuantity;
       
        /* here we check the condetion
    and set the qty to add or deduct for physical reserver qty
    */
        if (reservePhysical < reservedPhysical)
        {
            qty = reservedPhysical - reservePhysical;
        }
        else if(reservePhysical > reservedPhysical)
        {
            qty = reservedPhysical - reservePhysical;
        }

        // find the record on sales line base on recid
        //salesLine = SalesLine::findRecId(_recId);


    //    select inventTransOrigin
    //where inventTransOrigin.InventTransId == salesLine.InventTransId
    //join inventTrans
    //where inventTrans.InventTransOrigin == inventTransOrigin.RecId
    //&&  inventTrans.StatusReceipt == StatusReceipt::None;

        select firstonly inventTransOrigin
            where inventTransOrigin.InventTransId == salesLine.InventTransId
            && inventTransOrigin.dataareaId == salesLine.dataareaId
            join inventTrans
            where inventTrans.InventTransOrigin == inventTransOrigin.RecId
            &&  inventTrans.StatusReceipt == StatusReceipt::None
           && inventTransOrigin.dataareaId == inventTrans.dataareaId
           && salesLine.dataareaId == curExt();

        //if inventTrans.RecId is not 0 then we continue
        if(inventTrans.RecId)
        {
            inventMovement = inventTrans.inventmovement(true);
            // here we set the paramater for InventUpd_Reservation check class InventUpd_Reservation for more info
            reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTrans.inventDim(),qty, false);
            reservation.updatenow();

        }

        //info(strFmt("%1",salesLine.reservedPhysicalSalesUnit()));

    }

arrow
arrow

    lionlionchopper 發表在 痞客邦 留言(0) 人氣()