How to post purchase order packing slip

// VAR Changed by Xie Yu Fan.Fandy 谢宇帆
boolean postPurchPackingSlip()
{
    PurchFormLetter_PackingSlip purchFormLetter;
    SysQueryRun                 chooseLinesQuery;

    PurchParmUpdate         purchParmUpdate;
    PurchLine               purchLine, updatePurchLine;
    PurchParmTable          purchParmTable;
    PurchParmLine           purchParmLine;
    InventDim               inventDim;
    boolean                 success = true;
    FormDataSource          fds;
    Percent                 percent, subOverPct;
    qty                     qtyPre, qtyPost;
    #task
    ;

    purchLine = this.purchLine();
    if (!this.BillOfLadingId)
        throw error("请输入提单号.");
    if (!this.QtyBillOfLading)
        throw error("请输入提单数量.");
    if (!this.QtyLoad)
        throw error("请输入装船数量.");
    if (!this.QtyArrivalPort)
        throw error("请输入到港数量.");
    if (!this.QtyReceived)
        throw error("请输入实收数量.");
    if (!this.ActDeliveryDate)
        throw error("实际到货日期不能为空.");
    if(!this.checkCoal())
        throw error("煤炭实际值不能为空。");

    ttsbegin;
    chooseLinesQuery = new SysQueryRun(querystr(PurchUpdate));

    chooseLinesQuery.query().dataSourceTable(tablenum(PurchTable)).addRange(fieldnum(PurchTable, PurchId)).value(queryValue(purchLine.PurchId));
    chooseLinesQuery.query().dataSourceTable(tablenum(PurchLine)).addRange(fieldnum(PurchLine, InventTransId)).value(queryValue(purchLine.InventTransId));

    chooseLinesQuery.query().interactive(false);
    chooseLinesQuery.saveUserSetup      (false);

    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);

    purchFormLetter.chooseLinesQuery        (chooseLinesQuery);
    purchFormLetter.purchTable              (PurchTable::find(purchLine.PurchId));
    purchFormLetter.transDate               (systemdateget());
    purchFormLetter.specQty                 (PurchUpdate::All);
    purchFormLetter.printFormLetter         (NoYes::No);
    purchFormLetter.splitDeliveryInformation(NoYes::No);
    purchFormLetter.sumBy                   (AccountOrder::None);

    purchFormLetter.createParmUpdate(false);
    purchFormLetter.chooseLines();
    purchFormLetter.setForUpdatePurchParmTable();

    purchParmTable      = purchFormLetter.currentPurchParmTable();

    if (!purchParmTable)
        throw checkFailed("没有订单行可过账.");

    purchParmTable.selectForUpdate(true);
    purchParmTable.TransDate    = this.ActDeliveryDate;
    purchParmTable.write();

    purchParmLine       = purchParmLine::findInventTransId(purchParmTable.ParmId, this.InventTransId,true);
    if (!purchParmLine)
        throw checkFailed("没有订单行可过账.");

    inventDim                   = this.inventDim();
    //this.YIP_updatePurchOrderedQtyByBatchId(inventDim);

    purchParmLine.InventDimId   = InventDim::findOrCreate(inventDim).inventDimId;
    purchLine                   = PurchLine::findInventTransId(this.InventTransId);
    [purchParmLine.ReceiveNow,  purchParmLine.RemainBefore      , purchParmLine.RemainAfter      ] = purchFormLetter.qtyPurch (purchLine, this.QtyReceived);//purchLine.YIP_calcPurchQty(this.ReceiveQtyNow));
    [purchParmLine.InventNow,   purchParmLine.RemainBeforeInvent, purchParmLine.RemainAfterInvent] = purchFormLetter.qtyInvent(purchLine, purchLine.calcQtyOrdered(this.QtyReceived));//purchLine.this.ReceiveQtyNow);
    purchParmLine.setLineAmount(purchParmLine.ReceiveNow,purchLine);


    purchParmLine.YIP_ReceivedQty           = purchParmLine.ReceiveNow;
    if(purchParmLine.YIP_IsCoal)
    {
        purchParmLine.YIP_ReceivedHeatCar       = this.YIP_ReceivedHeatCar;
        purchParmLine.YIP_ReceivedSulfurPercent = this.YIP_ReceivedSulfurPercent;
        purchParmLine.YIP_ReceivedVdafPercent   = this.YIP_ReceivedVdafPercent;
        purchParmLine.YIP_ReceivedWaterPercent  = this.YIP_ReceivedWaterPercent;
        purchParmLine.YIP_calcHeatCarDiscPrice(false);
        purchParmLine.YIP_calcSulfurDiscPrice(false);
        if(purchParmLine.YIP_calcCoal)
        {
            purchParmLine.YIP_calcVdafDiscPrice(true);
            purchParmLine.YIP_calcReceivedQty();
            purchParmLine.modifiedField(fieldnum(purchParmLine,YIP_ReceivedQty));

        }
        else
        {
            purchParmLine.YIP_calcVdafDiscPrice(false);
        }

        purchParmLine.YIP_calcCoalAmount();
    }
    purchParmLine.update();

    purchFormLetter.reArrangeNow(true);
    purchFormLetter.YIP_parmFromExternalRun(true);
    purchFormLetter.saveLast();
    ttscommit;
    if (!purchFormLetter.prompt())
        return false;
    try
    {
        ttsbegin;
        purchFormLetter.run();
        this.Status         = YIP_PurchScheduleStatus::Complete;
        this.PackingSlipId  = purchParmTable.Num;
        this.update();
        if (this.FreightAmount)
            this.createMarkupTrans();
        ttscommit;
    }
    catch(exception::Error)
    {
        ttsabort;
        success = false;
        error("Catch an error exception.");
    }
    catch(exception::CLRError)
    {
        success = false;
        ttsabort;
        error(AifUtil::getClrErrorMessage());
    }

    if (success && this.isFormDataSource())
    {
        fds = this.dataSource();
        /*
        fds.reread();
        fds.refresh();
        fds.research(-1);
        */
        fds.formRun().task(#taskFormRefresh_F5);
        info("已过账.");
    }
    return success;
}



你可能感兴趣的:(How to post purchase order packing slip)