How to post ship inventory transfer order

boolean postInventTransferOrderShip()
{
    inventTransferParmTable         inventTransferParmTable;
    InventTransferMultiShip         inventTransferMultiShip;
    YIP_InventTransferSectionDetails table, lastShipDetails;
    Num                             parmId;
    boolean                         ret = true;
    InventTransferJour              inventTransferJour;
    InventTransferJourLine          inventTransferJourLine;
    inventTransferLine              inventTransferLine, inventTransferLineUpd;
    str                             errorMsg;
    qty                             packQty, qtyOver, qtyUnOver, minQty, maxQty, qtyDelivery;
    int                             lastSectionId = YIP_InventTranferSection::getLastSectionId(this.TransferId);
    percent                         subOverPct;
    FormDataSource                  fds = this.isFormDataSource() ? this.dataSource() : null;
    ;

    select count(recId) from lastShipDetails
            where lastShipDetails.InventTransId == this.InventTransId   &&
                  lastShipDetails.SectionId     == 1                    &&
                  lastShipDetails.VoucherId     == "";
    if (lastShipDetails.RecId == 1)
    {
        inventTransferLine = this.inventTransferLine();

        packQty     = inventTransferLine.YIP_PackQty;
        qtyDelivery = inventTransferLine.YIP_getQtyShippedSection();

        qtyOver     = packQty * inventTransferLine.OverDeliveryPct / 100;//超交
        qtyUnOver   = packQty * inventTransferLine.UnderDeliveryPct / 100;//欠交
        minQty      = packQty - qtyUnOver;
        maxQty      = packQty + qtyOver;

        subOverPct  = (qtyDelivery - packQty) / (packQty ? packQty : 1) * 100;

        if (subOverPct > inventTransferLine.OverDeliveryPct)
            throw checkFailed(strfmt("@SYS24920",subOverPct,inventTransferLine.OverDeliveryPct));

        subOverPct  = (packQty - qtyDelivery) / (packQty ? packQty : 1) * 100;

        if (subOverPct > inventTransferLine.UnderDeliveryPct)
            throw checkFailed(strfmt("@SYS24921",subOverPct, inventTransferLine.UnderDeliveryPct));

        select sum(qtyPlan) from table
            where table.InventTransId == this.InventTransId &&
                  table.SectionId     == lastSectionId;
        if (!table.QtyPlan)
            throw error(strfmt("请输入本次调拨单[%1]的所有分段.", this.TransferId));
    }
    qtyDelivery = this.QtyDelivery;
    if (!box::yesNo(strfmt("您确认要过账装运吗[实际发货数量(%1)]?", num2str(qtyDelivery, 1, 2, 1, 2)),
        dialogButton::No, "装运过账"))
        return false;

    try
    {
        ttsbegin;
        inventTransferLine = this.inventTransferLine(true);
        inventTransferLine.QtyShipNow       = this.QtyDelivery;
        inventTransferLine.YIP_QtyDelivery += this.QtyDelivery;
        inventTransferLine.doUpdate();

        inventTransferMultiShip = InventTransferMultiShip::construct();
        parmId                  = runBaseMultiParm::getSysParmId();
        inventTransferParmTable.clear();
        inventTransferParmTable.initValue();
        inventTransferParmTable.ParmId          = parmId;
        inventTransferParmTable.TransferId      = this.TransferId;
        inventTransferParmTable.UpdateType      = InventTransferUpdateType::Shipment;
        inventTransferParmTable.ShipUpdateQty   = InventTransferShipUpdateQty::ShipNow;
        inventTransferParmTable.EditLines       = true;
        inventTransferParmTable.ExplodeLines    = true;
        inventTransferParmTable.UpdatedBy       = emplTable::userId2EmplId(curUserId());
        inventTransferParmTable.YIP_RefInventTransId    = this.InventTransId;
        //inventTransferParmTable.AutoReceiveQty  = NoYes::No;
        inventTransferParmTable.insert();// create parameter header and lines

        // post Shipping
        inventTransferMultiShip.runUpdate(inventTransferParmTable);

        // update remain ship qty
        if (lastShipDetails.RecId == 1)
        {
            inventTransferLineUpd = this.inventTransferLine(true);
            inventTransferLineUpd.QtyRemainShip = 0;
            if (inventTransferLineUpd.validateWrite())
            {
                inventTransferLineUpd.updateDeliverRemainder();
            }
        }

        // update section details status
        table = YIP_InventTransferSectionDetails::findRecId(this.RecId, true);
        if (table)
        {
            select firstonly inventTransferJour
                where inventTransferJour.YIP_ParmId == inventTransferParmTable.ParmId;
            if (inventTransferJour)
            {
                table.TransferStatus= InventTransferStatus::Shipped;
                table.VoucherId     = inventTransferJour.VoucherId;
                table.RemainStatus  = InventTransferRemainStatus::Receiving;
                table.write();
            }
        }

        ttscommit;
    }
    catch
    {
        ret = false;
        errorMsg = aifUtil::getClrErrorMessage();
        if (errorMsg)
            error(errorMsg);
        error("catch exception.");
    }
    if (ret && fds)
    {
        fds.reread();
        fds.refresh();
        /*
        ttsbegin;

        select forupdate inventTransferJourLine
            where inventTransferJourLine.TransferId     == this.TransferId &&
                  inventTransferJourLine.InventTransId  == this.InventTransId;

        while select table index hint SectionIndex
            where table.TransferId      == this.TransferId      &&
                  table.InventTransId   == this.InventTransId   &&
                  table.LineNum         == this.LineNum
        {
            table.selectForUpdate(true);
            table.RemainStatus   = InventTransferRemainStatus::Receiving;
            table.RemarkDelivery = strfmt("凭证[%1],转移批次[%2].",inventTransferJourLine.VoucherId,inventTransferJourLine.InventTransId);
            table.doupdate();
        }
        ttscommit;
        */
    }
    return ret;
}



你可能感兴趣的:(X++)