BLVCKFX
1/16/2019 - 9:39 AM

[BOF SplitSalesParmLines] Split sales parm lines #bof #lmilo

[BOF SplitSalesParmLines] Split sales parm lines #bof #lmilo

//DLX_GAP046_WMSReadyGoods - 27/11/2017 - LMilo
[DataContractAttribute,
    SysOperationContractProcessingAttribute(classstr(DLX_SplitSalesParmLinesUI))
]
public class DLX_SplitSalesParmLinesDC
{
    Qty         deliveryQty;
    Qty         splitQty;
    RefRecId    salesParmLineRecId;

    [DataMemberAttribute]
    public Qty parmDeliveryQty(Qty _deliveryQty = deliveryQty)
    {
        deliveryQty = _deliveryQty;
        return deliveryQty;
    }

    [DataMemberAttribute,
     SysOperationLabelAttribute(literalStr("@SYS19602"))]
    public Qty parmSplitQty(Qty _splitQty = splitQty)
    {
        splitQty = _splitQty;
        return splitQty;
    }

    [DataMemberAttribute,
     SysOperationControlVisibilityAttribute(false)]
    public RefRecId parmSalesParmLineRecId(RefRecId _salesParmLineRecId = salesParmLineRecId)
    {
        salesParmLineRecId = _salesParmLineRecId;
        return salesParmLineRecId;
    }

}
//DLX_GAP046_WMSReadyGoods - 27/11/2017 - LMilo
class DLX_SplitSalesParmLinesUI extends SysOperationAutomaticUIBuilder
{
    DialogField deliveryQtyDlg;
    DialogField splitQtyDlg;

    Qty         splitQty;

    DLX_SplitSalesParmLinesDC splitSalesParmLinesDC;

    public void getFromDialog()
    {
        splitQty = splitQtyDlg.value();

        splitSalesParmLinesDC.parmSplitQty(splitQty);
    }

    public void postBuild()
    {
        splitSalesParmLinesDC        = this.dataContractObject();

        deliveryQtyDlg      = this.bindInfo().getDialogField(splitSalesParmLinesDC, methodstr(DLX_SplitSalesParmLinesDC, parmDeliveryQty));
        splitQtyDlg       = this.bindInfo().getDialogField(splitSalesParmLinesDC, methodstr(DLX_SplitSalesParmLinesDC, parmSplitQty));

        deliveryQtyDlg.value(splitSalesParmLinesDC.parmDeliveryQty());
        deliveryQtyDlg.enabled(false);

        splitQtyDlg.registerOverrideMethod(methodStr(FormRealControl, Validate), methodStr(DLX_SplitSalesParmLinesUI, Validate), this);

        super();
    }

    private boolean Validate(FormRealControl _ctrl)
    {
        if(str2Num(_ctrl.valueStr()) > splitSalesParmLinesDC.parmDeliveryQty())
        throw error ("@DLX_AppSuiteDeloitteSales:SplitLineQtyError");

        return true;

    }

}
//DLX_GAP046_WMSReadyGoods - 27/11/2017 - LMilo
public class DLX_SplitSalesParmLinesService extends SysOperationServiceBase
{
    DLX_SplitSalesParmLinesDC splitSalesParmLinesDC;

    Qty         splitQty;
    RefRecId    salesParmLineRecId;

    [SysEntryPointAttribute(true)]
    public void splitSalesParmLinesService(DLX_SplitSalesParmLinesDC _splitSalesParmLinesDC)
    {
        DLX_SplitSalesParmLinesMng splitLinesMng = new DLX_SplitSalesParmLinesMng();
        splitLinesMng.initFromDatacontract(_splitSalesParmLinesDC);
        splitLinesMng.run();
    }

}
//DLX_GAP046_WMSReadyGoods - 27/11/2017 - LMilo
class DLX_SplitSalesParmLinesController extends SysOperationServiceController
{
    protected void afterOperation(SysOperationExecutionMode _executionMode, AifAsyncResult _asyncResult)
    {
        super(_executionMode, _asyncResult);
        this.refreshCaller();
    }

    public static DLX_SplitSalesParmLinesController newFromArgs(Args _args)
    {
        DLX_SplitSalesParmLinesController   splitLinesController;
        DLX_SplitSalesParmLinesDC           splitLinesDC;
        SalesParmLine                       salesParmLine;
        ;

        splitLinesController = new DLX_SplitSalesParmLinesController();
        splitLinesController.initializeFromArgs(_args);

        splitLinesDC = splitLinesController.getDataContractObject("_splitSalesParmLinesDC");

        salesParmLine = _args.record();

        splitLinesDC.parmSalesParmLineRecId(salesParmLine.RecId);
        splitLinesDC.parmDeliveryQty(salesParmLine.DeliverNow);

        return splitLinesController;
    }

    public static void main(Args _args)
    {
        DLX_SplitSalesParmLinesController splitLinesController;
        ;

        splitLinesController = DLX_SplitSalesParmLinesController::newFromArgs(_args);
        //splitLinesController.showBatchTab(false);
        splitLinesController.startOperation();
    }

    public void refreshCaller()
    {
        Common          common;
        FormDataSource  callingFormDataSource;

        common = args.record();
        if (common)
        {
            callingFormDataSource = common.dataSource();
            if (callingFormDataSource)
            {
                callingFormDataSource.reread();
                callingFormDataSource.rereadReferenceDataSources();
                callingFormDataSource.research(true);
            }
        }
    }

}
//DLX_GAP046_WMSReadyGoods - 27/11/2017 - LMilo
public class DLX_SplitSalesParmLinesMng
{
    DLX_SplitSalesParmLinesDC   splitLinesDC;
    Qty                         splitQty;
    RefRecId                    salesParmLineRecId;
    SalesParmLine               salesParmLine;
    
    public void initFromDatacontract(DLX_SplitSalesParmLinesDC _splitLinesDC)
    {
        splitLinesDC = _splitLinesDC;
    }

    public void initParameters()
    {
        splitQty            = splitLinesDC.parmSplitQty();
        salesParmLineRecId  = splitLinesDC.parmSalesParmLineRecId();
        SalesParmLine       = SalesParmLine::findRecId(salesParmLineRecId);
    }

    public void initQuery()
    {

    }

    public boolean validate()
    {
        boolean ret = true;

        return ret;
    }

    public void run()
    {
        this.initParameters();
        this.initQuery();
        this.validate();
        this.splitLineProcedure();
    }

    public void splitLineProcedure()
    {
        SalesParmLine newSalesParmLine;
        
        ttsbegin;
        newSalesParmLine.data(salesParmLine);
        newSalesParmLine.recId      = 0;
        newSalesParmLine.LineNum    += 1;
        newSalesParmLine.DeliverNow = splitQty;
        newSalesParmLine.InventNow  = splitQty;
        newSalesParmLine.setLineAmount();
        newSalesParmLine.insert();
        ttscommit;

        ttsbegin;
        salesParmLine.selectForUpdate(true);
        salesParmLine.DeliverNow -= splitQty;
        salesParmLine.InventNow  -= splitQty;
        salesParmLine.setLineAmount();
        salesParmLine.update();
        ttscommit;

    }

}