Remaining Qty fix on sales and purchase order

Code
static void JBK_RemainQtyFix(Args _args)
{
    
DataArea dataArea;
    
void doIt()
    {
        
SalesLine sl;
        
PurchLine pl;
        
boolean do1do2;
        
setPrefix(curext());
        while 
select count(RecIdfrom sl
            group SalesStatus
            where 
//sl.SalesStatus == SalesStatus::Backorder &&
                
((sl.RemainInventPhysical && !sl.RemainSalesPhysical) )// ||
                 //(!sl.RemainInventPhysical && sl.RemainSalesPhysical) )// ||
                 //(sl.RemainInventFinancial && !sl.RemainSalesFinancial) ||
                 //(!sl.RemainInventFinancial && sl.RemainSalesFinancial))
        
{
            
info(strFmt("%1 %2"sl.RecIdtableId2name(sl.TableId), sl.SalesStatus));
            
do1 true;
        }
        if (
do1)
            
update_recordset sl
                setting RemainSalesPhysical 
sl.RemainInventPhysical
                where sl
.RemainInventPhysical && !sl.RemainSalesPhysical;
        
info(strFmt("%1 %2"sl.RowCount(), tableId2name(sl.TableId)));

        while 
select count(RecIdfrom pl
            group PurchStatus
            where 
//pl.PurchStatus == PurchStatus::Backorder &&
                
(//(pl.RemainInventPhysical && !pl.RemainPurchPhysical) ||
                 //(!pl.RemainInventPhysical && pl.RemainPurchPhysical) ||
                 //(pl.RemainInventFinancial && !pl.RemainPurchFinancial) ||
                 
(!pl.RemainInventFinancial && pl.RemainPurchFinancial))
        {
            
info(strFmt("%1 %2 %3"pl.RecIdtableId2name(pl.TableId), pl.PurchStatus));
            
do2 true;
        }
        if (
do2)
            
update_recordset pl
                setting RemainInventFinancial 
pl.RemainPurchFinancial
                where 
!pl.RemainInventFinancial && pl.RemainPurchFinancial;
        
info(strFmt("%1 %2"pl.RowCount(), tableId2name(pl.TableId)));
    }
    
setPrefix("Count intercompany errors");
    while 
select dataArea where !dataArea.isVirtual // && dataArea.Id == 'fls'
        
changecompany (dataArea.Id)
            
doIt();
}
PropertiesCreated by jan.kjeldsen@optimat 2015-05-20 11:25:41 (Public)