Thursday, January 2, 2014

Post sales packingslip based on shipment ID using X++

static void D_SalesPackingSlipBasedOnShipment(Args _args)
{
    WmsPickingRoute      wmsPickingRoute;
    Set                             wmsShipmentIdSet;
    WMSShipment          shipment;

    SalesFormLetter_PackingSlip     salesFormLetter;
    SalesTable                                  localSalesTable;
    WMSOrderTrans                       localWMSOrderTrans;
    SalesId                                       previousSalesId     = '';
    ;

    ttsBegin;
    select firstonly    wmsPickingRoute
        where wmsPickingRoute.pickingRouteID  ==  "014361_128"
           && wmsPickingRoute.transRefId          ==  "SO13-1332"
           && wmsPickingRoute.expeditionStatus ==  WMSexpeditionStatus::Complete;

    if (wmsPickingRoute)
    {
        shipment                 =  wmsPickingRoute.WMSShipment(true);
        wmsShipmentIdSet =  new Set(Types::String);
        wmsShipmentIdSet.add(shipment.shipmentId);

        while select localSalesTable
            order by salesid
            join  localWMSOrderTrans where localWMSOrderTrans.routeId == wmsPickingRoute.pickingRouteID
                &&  localWMSOrderTrans.inventTransRefId ==localSalesTable.salesid
                &&  localWMSOrderTrans.inventTransType  ==inventTransType::Sales
                &&  localWMSOrderTrans.expeditionStatus ==WMSExpeditionStatus::Complete
            {
                if ( previousSalesId == '' || previousSalesId != localSalesTable.salesId)
                {
                    salesFormLetter = new SalesFormLetter_PackingSlip(true);
                    salesFormLetter.hideProgress(true);
                    salesFormLetter.transDate(_packingSlipDate);
                    salesFormLetter.parmWmsShipmentIdSet(_wmsShipmentIdSet);
                    salesFormLetter.update(localSalesTable,_packingSlipDate,SalesUpdate::PickingList,AccountOrder::None,false,false,false,false);
                }
                previousSalesId = localSalesTable.salesid;
    }
    ttsCommit;
}

No comments:

Post a Comment