Thursday, December 5, 2019

Sales line picking list

Sales line picking list


public static void RetailCWItemSalesLinePick(SalesLine salesLine)
        {
            TmpInventTransWMS       tmpinventTransWMS;
            InventTrans             inventTrans;
            InventTransWMS_Pick     inventTransWMS_Pick;
            Query                   inventTransQuery;
            QueryBuildDataSource    qbdsInventTrans;
            QueryBuildRange         qbRange;
            InventTransChildType    inventTransChildType;
            InventTransChildRefId   inventTransChildRefId;
            ItemFreeTxt             rangeStr;
            counter                 inventTransChildTypeInt;
            InventMovement          inventMovement;
            InventTransOriginId     inventTransOriginId;
   
            inventTransQuery = new Query();
   
            qbdsInventTrans = inventTransQuery.addDataSource(tableNum(inventTrans));
            qbdsInventTrans.addRange(fieldNum(InventTrans,StatusReceipt)).value(SysQuery::value(StatusReceipt::None));
            qbdsInventTrans.addRange(fieldNum(InventTrans,StatusIssue)).value(SysQuery::range(StatusIssue::Picked,StatusIssue::OnOrder));
   
            inventMovement      = InventTransWMS_Pick::inventMovement(salesLine);
            inventTransOriginId = inventMovement.inventTransOriginId();
   
            if (inventMovement)
            {
                if (inventMovement.transChildType())
                {
                    inventTransChildType  = inventMovement.transChildType();
                    inventTransChildRefId = inventMovement.transChildRefId();
                }
                else
                {
                    inventTransChildType  = InventTransChildType::None;
                    inventTransChildRefId = '';
                }
            }
            inventTransChildTypeInt = inventTransChildType; // Avoid query problems with special characters in enum label.
            //range over all loaded movements
            qbRange = qbdsInventTrans.addRange(fieldNum(InventTrans,InventTransOrigin));
            rangeStr = strFmt('((%1.%2 == %3) && (%4.%5 == %6)',
                            qbdsInventTrans.name(),
                            fieldStr(InventTrans,InventTransOrigin),
                            queryValue(inventTransOriginId),
                            qbdsInventTrans.name(),
                            fieldStr(InventTrans,TransChildType),
                            inventTransChildTypeInt);

            if (inventTransChildRefId)
            {
                rangeStr = rangeStr + strFmt(' && (%1.%2 == \"%3\"))',
                            qbdsInventTrans.name(),
                            fieldStr(InventTrans,TransChildRefId),
                            queryValue(inventTransChildRefId));
            }
            else
            {
                // To avoid 2 times double quotes for the childRefId.
                rangeStr = rangeStr + strFmt(' && (%1.%2 == \"\"))',
                            qbdsInventTrans.name(),
                            fieldStr(InventTrans,TransChildRefId));
            }
            qbRange.value(rangeStr);
   
            ttsBegin;
            inventTransWMS_Pick = InventTransWMS_Pick::newStandard(tmpinventTransWMS,inventTransQuery);
            inventTrans         = InventTrans::findTransId(salesLine.InventTransId);
   
            inventTransWMS_Pick.createFromInventTrans(inventTrans);
            tmpinventTransWMS   = inventTransWMS_Pick.parmTmpInventTransWMS();
   
            select firstOnly forUpdate tmpinventTransWMS where tmpinventTransWMS.InventTrans == inventTrans.RecId;
            tmpinventTransWMS.InventQty = salesLine.RemainInventPhysical;
            tmpinventTransWMS.update();
            inventTransWMS_Pick.writeTmpInventTransWMS(tmpinventTransWMS);
   
            inventTransWMS_Pick.updateInvent();
   
            ttsCommit;


        }


No comments:

Post a Comment