Tuesday, 4 February 2020

AX 2012 X++ create Transfer journal

 CommaTextIO     csvFile;
    container       readCon;
    Dialog          dialog;
    DialogField     dfFileName;

    int insertCount,updateCount;
    str 200 DistributionId;
    #AviFiles
    SysOperationProgress progress = new SysOperationProgress();
     InventJournalTrans _InventJournalTrans;
    InventDim _InventDim;
    WMSJournalTrans _WMSJournalTrans;
    InventLocation _InventLocation,_InventLocationTo;
     InventLocationId _InventLocationId,_InventLocationIdTo;
    InventSerialId _InventSerialId;
     NumberSeq                             numberSeq;
    NumberSequenceReference     numberSequenceReference;

    int ProgramDay;
        #define.JournalID(1)
        #define.TransDate(2)
        #define.ItemID(3)
        #define.Qty(4)
        #define.Serial(5)
        #define.LocationFrom(6)
        #define.LocationTo(7)
    super();

    #File
    dialog = new Dialog("Pick the file");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);

    if (dialog.run())
    {



        csvFile = new CommaTextIo(dfFileName.value(), 'r');
        csvFile.inFieldDelimiter(',');
        readCon = csvFile.read();



        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();

            if (readCon)
            {
               ttsBegin;
                   _InventJournalTrans.clear();
                  // numberSeq                                   = new NumberSeq();
                  // numberSequenceReference           = InventParameters::numRefInventJournalVoucherId();
                  // numberseq                    = NumberSeq::newGetNum(numberSequenceReference);

                   _InventJournalTrans.initFromInventJournalTable(InventJournalTable::find(_InventJournalTrans.JournalId));
                  // _InventJournalTrans.Voucher           = numberseq.num();
                  _InventJournalTrans.JournalType    = InventJournalType::Transfer;
                  _InventJournalTrans.JournalId=   conPeek(readCon,#JournalID); //cells.item(row, 1).value().bStr();

                  _InventJournalTrans.transdate= str2Date(conPeek(readCon,#TransDate),123);    //cells.item(row, 2).value().date();
                  _InventJournalTrans.itemId= conPeek(readCon,#ItemID);  //cells.item(row,3).value().bStr();
                  _InventJournalTrans.qty= str2num(conPeek(readCon,#Qty)); //cells.item(row,4).value().double()*-1;


                 _InventLocation = InventLocation::find(conPeek(readCon,#LocationFrom));//InventLocation::find(cells.item(row,6).value().bStr());
                 _InventLocationTo = InventLocation::find(conPeek(readCon,#LocationTo));//InventLocation::find(cells.item(row,7).value().bStr());

                _InventDim.clear();
                _InventDim.InventSiteId=_InventLocation.InventSiteId;
                _InventDim.InventSerialId = conPeek(readCon,#Serial);//cells.item(row,5).value().bStr();
               _InventDim.InventLocationId = _InventLocation.InventLocationId;
                 _InventJournalTrans.inventDimId=InventDim::findOrCreate(_InventDim).inventDimId;


               _InventDim.clear();
             _InventDim.InventSiteId=_InventLocationTo.InventSiteId;
            _InventDim.InventSerialId = conPeek(readCon,#Serial);//cells.item(row,5).value().bStr();
            _InventDim.InventLocationId = _InventLocationTo.InventLocationId;
             _InventJournalTrans.ToInventDimId= InventDim::findOrCreate(_InventDim).inventDimId;

              _InventJournalTrans.insert();
                ttsCommit;


                    updateCount++;
                 progress.setCaption("Uploading transfer journal");
                progress.setAnimation(#AviUpdate);
               progress.setText(strfmt("%1 line uploaded", updateCount));
             //   progress.setCount(updateCount, 1);

            }


        }
    }

    info(strFmt("%1 records inserted ",updateCount));

Tuesday, 14 January 2020

AX X++ get the selected grid records

 InventQualityOrderTable _InventQualityOrderTable;
_InventQualityOrderTable = InventQualityOrderTable_DS.getFirst(true);
        while (_InventQualityOrderTable)
        {
         
                 
                  info(strFmt('The order %1 is validated', _InventQualityOrderTable.QualityOrderId));
         

        _InventQualityOrderTable = InventQualityOrderTable_DS.getNext();
        }

AX 2012 X++ validate quality order by code

InventQualityOrderTable _InventQualityOrderTable;
    InventQualityOrderValidate obj ;//= new InventQualityOrderValidate();
   

    obj = InventQualityOrderValidate::construct();
    obj.parmAcceptError(NoYes::Yes);
    obj.parmQualityOrderId('QO19S000009234');
    obj.parmWorker(5637146076);
    obj.run();

Monday, 6 January 2020

AX X++ cancel and UnPick PickList


 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void cancelPickingRoute()
{
    WMSPickingRoute         WMSPickingRoute = WMSPickingRoute::findBySalesId("SO024406");
    WMSPickingLineCancel    WMSPickingLineCancel;
    WMSOrderTrans           WMSOrderTrans;
    WMSOrderTransUnPick     WMSOrderTransUnPick;
    ;

    switch (WMSPickingRoute.expeditionStatus)
    {
        case WMSExpeditionStatus::Complete :
            while select forupdate WMSOrderTrans
                index hint OrderIdx
            where WMSOrderTrans.fullPallet == 0
            &&    WMSOrderTrans.routeId    == WMSPickingRoute.pickingRouteID
            {
                ttsbegin;
                WMSOrderTransUnPick::newWMSOrderTrans(WMSOrderTrans).unPick(WMSOrderTrans.qty);
                ttscommit;
            }

            while select WMSOrderTrans
                index hint OrderIdx
            where WMSOrderTrans.fullPallet == 0
            &&    WMSOrderTrans.routeId    == WMSPickingRoute.pickingRouteID
            {

Thursday, 7 November 2019

Ax 2012 Post Packing Slip Item Arrival journal x++

 Dialog      dialog;
    DialogField field,filedDate;
    JournalCheckPost        journalCheckPost;
    WMSJournalTable _WMSJournalTable;
    PurchFormLetter_PackingSlip _PurchFormLetter_PackingSlip;
    ;
   


    dialog = new Dialog("Batch Receipt");
    dialog.addText("Receipt");
    field = dialog.addField(extendedTypeStr(ProductReceiptId));
    filedDate = dialog.addField(extendedTypeStr(TransDate));

    dialog.run();
    if (dialog.closedOk())
    {
         _WMSJournalTable = WMSJournalTable::find(WMSJournalTable.journalId);
         ttsbegin;

    _PurchFormLetter_PackingSlip = PurchFormLetter::construct(DocumentStatus::PackingSlip);
    _PurchFormLetter_PackingSlip.showQueryForm(false);
    _PurchFormLetter_PackingSlip.update(_WMSJournalTable,
                                                    field.value() ,
                                                   filedDate.value(),
                                                    PurchUpdate::Recorded,
                                                    AccountOrder::None,
                                                    false,
                                                    false);


    ttscommit;
        info("Done");
    }

Wednesday, 4 September 2019

AX7/365 Add new report to print management

1- Create new class and run the report one time

2017-06-03 12_27_47-2017-05-31 08_59_54-_D365 Hoya V6_ auf _LAPTOP012_ - Verbindung mit virtuellen C

2017-06-03 12_38_00-Inked2017-05-31 08_59_54-_D365 Hoya V6_ auf _LAPTOP012_ - Verbindung mit virtuel

2- Then you can select your custom report from the print management
(AR >> Setup >> Form Setup)
2017-06-03 12_39_58-Inked2017-05-31 09_06_23-_D365 Hoya V6_ auf _LAPTOP012_ - Verbindung mit virtuel.png

If doesn't work go to the below table and change it 

PrintMgmtReportFormat

Thursday, 8 August 2019

AX2012 / 365 Convert numbers to Arabic Text تفقيط

public static str real2ArText(real _num)
   
    {
            real    numOfPennies = decround(frac(_num), 2);
            real    test         = _num - frac(_num);
            str     zero;
            str     comma;
            str     and;
            str     cent;
            int     numOfTenths;
            str 20  ones[19], tenths[9], hundreds, thousands, millions, billions, trillions;
       
            int64   temp;
            str 200  returntxt;
       
            real modOperator(real a1, real a2)
       
        {
                int     tmpi;
                real    tmp1, tmp2;
                tmp1 = a1 / a2;
                tmpi = real2int(tmp1);
                tmp2 = tmpi;
                return (tmp1 - tmp2)*a2;
           
        }
       
            str doubleDigit2ARTxt(real doubledigit,boolean _pennies = false)
       
        {
                    str     txt;
                    int     firstDigit;
                    real    tempdigit;
           
                    if(_pennies)
           
            {
                            firstDigit = doubledigit * 10;
                            doubledigit = doubledigit * 100;
                            if(!firstDigit)
               
                {
                                    doubledigit = doubledigit mod 10;
                                    //txt = zero + " " + ones[doubledigit];
                                    txt = ones[doubledigit];
                                    return txt;
                   
                }
               
            }
                    tempdigit = doubledigit;
                    if (tempdigit >= 20)
           
            {
                            tempdigit = tempdigit div 10;
                            txt = tenths[tempdigit];
                            doubledigit = doubledigit mod 10;
               
            }
                    if (doubledigit >= 1)
           
            {
                            txt = txt ?  (ones[doubledigit] + and + txt) : ones[doubledigit];
               
            }
           
                    return txt;
           
        }
       
            real checkPower(real  _test,int64 _power)
       
        {
                    int64   numOfPower;
           
                    if (_test >= _power)
           
            {
                            numOfPower = _test div _power;
                            if (numOfPower >= 100)
               
                {
                                    temp = numOfPower div 100;
                   
                                    if(temp > 9)// The validation was previously on 2
                   
                    {
                                            returntxt = returntxt ? (returntxt + and + ones[temp] + ' ' + hundreds) :(returntxt + ' ' + ones[temp] + ' ' + hundreds);
                       
                    }
                   
                                    else
                   
                    {
                                            switch(temp)
                       
                        {
                           
                                                    Case 1:
                                                            returntxt = returntxt ? (returntxt + and + hundreds) : (returntxt + ' ' + hundreds);
                                                            break;
                                                    Case 2:
                                                            // TO DO need to insert a label for two hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "مائتين") :   returntxt + ' ' + "مائتين";
                                                            break;
                                                    Case 3:
                                                            // TO DO need to insert a label for three hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "ثلاثمائة") :   returntxt + ' ' + 'ثلاثمائة';
                                                            break;
                                                    Case 4:
                                                            // TO DO need to insert a label for four hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "اربعمائة") :   returntxt + ' ' + "اربعمائة";
                                                            break;
                                                    Case 5:
                                                            // TO DO need to insert a label for five hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "خمسمائة") :   returntxt + ' ' + "خمسمائة";
                                                            break;
                                                    Case 6:
                                                            // TO DO need to insert a label for six hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "ستمائة") :   returntxt + ' ' + "ستمائة";
                                                            break;
                                                    Case 7:
                                                            // TO DO need to insert a label for seven hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "سبعمائة") :   returntxt + ' ' + "سبعمائة";
                                                            break;
                                                    Case 8:
                                                            // TO DO need to insert a label for eight hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "ثمانمائة") :   returntxt + ' ' + "ثمانمائة";
                                                            break;
                                                    Case 9:
                                                            // TO DO need to insert a label for nine hundred in Arabic
                                                            returntxt = returntxt ? (returntxt + and + "تسعمائة") :   returntxt + ' ' + "تسعمائة";
                                                            break;
                           
                           
                        }
                       
                    }
                                    numOfPower = numOfPower mod 100;
                   
                }
                            if(numOfPower > 2 && _power > 100)
               
                {
                                    returntxt = returntxt ?  (returntxt + and + doubleDigit2ARTxt(real2int(numOfPower))) : (returntxt  + ' ' + doubleDigit2ARTxt(real2int(numOfPower)));
                   
                }
                            else
               
                {
                                    if(returntxt && numOfPower)
                   
                    {
                                            returntxt = returntxt + and + ' ';
                       
                    }
                   
                }
                            switch(_power)
               
                {
                                    case 1000000000000 :
                   
                    {
                                            if( numOfPower == 2)
                       
                        {
                                                    // TO DO need to insert a label for two trillions in Arabic
                                                    returntxt = returntxt + "تريليونين ";
                           
                        }
                                            else
                       
                        {
                                                    returntxt = numOfPower > 10 ||  numOfPower == 1 || numOfPower == 0 ? (returntxt + ' ' + trillions) : (returntxt + ' ' + "تريليونات");
                           
                        }
                                            _test = modOperator(_test, 1000000000000.00);
                                            break;
                       
                    }
                                    case 1000000000 :
                   
                    {
                                            if( numOfPower == 2)
                       
                        {
                                                    // TO DO need to insert a label for two billions in Arabic
                                                    returntxt = returntxt + "مليارين";
                           
                        }
                                            else
                       
                        {
                                                    returntxt = numOfPower > 10 ||  numOfPower == 1 || numOfPower == 0 ? (returntxt + ' ' + billions) : (returntxt + ' ' + "مليارات");
                           
                        }
                                            _test = modOperator(_test, 1000000000);
                                            break;
                       
                    }
                                    case 1000000 :
                   
                    {
                                            if( numOfPower == 2)
                       
                        {
                                                    // TO DO need to insert a label for two Millions in Arabic
                                                    returntxt = returntxt + "مليونين";
                           
                        }
                                            else
                       
                        {
                           
                                                    returntxt = numOfPower > 10 || numOfPower == 1 || numOfPower == 0 ? (returntxt + ' ' + millions) : (returntxt + ' ' + "ملايين");
                           
                           
                        }
                                            _test = modOperator(_test, 1000000);
                                            break;
                       
                    }
                                    case 1000 :
                   
                    {
                                            if( numOfPower == 2)
                       
                        {
                                                    // TO DO need to insert a label for two Thousands' in Arabic
                                                    returntxt = returntxt + "ألفين";
                           
                        }
                                            else
                       
                        {
                                                    returntxt = numOfPower > 10 ||  numOfPower == 1 || numOfPower == 0  ? (returntxt + ' ' + thousands) : (returntxt + ' ' + "الاف");
                           
                        }
                                            _test = modOperator(_test, 1000);
                                            break;
                       
                    }
                                    case 100 :
                   
                    {
                                            switch (numOfPower)
                       
                        {
                                                    case 2:
                                                    returntxt = returntxt + "مائتين";
                                                    break;
                           
                                                    case 3:
                                                    returntxt = returntxt +"ثلاثمائة";
                                                    break;
                           
                                                    case 4:
                                                    returntxt = returntxt + "اربعمائة";
                                                    break;
                           
                                                    case 5:
                                                    returntxt = returntxt + "خمسمائة";
                                                    break;
                           
                                                    case 6:
                                                    returntxt = returntxt + "ستمائة";
                                                    break;
                           
                                                    case 7:
                                                    returntxt = returntxt + "سبعمائة";
                                                    break;
                           
                                                    case 8:
                                                    returntxt = returntxt + "ثمانمائة";
                                                    break;
                           
                                                    case 9:
                                                    returntxt = returntxt + "تسعمائة";
                                                    break;
                           
                                                    default:
                                                    returntxt = returntxt + ' ' + hundreds;
                           
                        }
                       
                                             _test = modOperator(_test, 100);
                                            break;
                       
                    }
                   
                }
               
               
            }
                    return _test;
           
           
        }
       
           infolog.language("AR");
          //  infolog.language("EN");
       
            and     = ' ' + "و" + ' ';//' ' + "@SYS5534" + ' ';
            comma   = "دينار";
            //comma = "@SYS80142";
            zero    = "صفر";//"@SYS2068";
            cent    = "فلس";
       
            ones[1] = "واحد";//"@SYS26620";
            ones[2] = "اثنان";//"@SYS26621";
            ones[3] = "ثلاثة";//"@SYS26622";
            ones[4] = "اربعة";//"@SYS26626";
            ones[5] = "خمسة";//"@SYS26627";
            ones[6] = "ستة";//"@SYS26628";
            ones[7] = "سبعة";//"@SYS26629";
            ones[8] = "ثمانية";//"@SYS26630";
            ones[9] = "تسعة";//"@SYS26631";
            ones[10] = "عشرة";//"@SYS26632";
            ones[11] = "احد عشر";//"@SYS26633";
            ones[12] = "اثنا عشر";//"@SYS26634";
            ones[13] = "ثلاثة عشر";//"@SYS26635";
            ones[14] = "اربعة عشر";//"@SYS26636";
            ones[15] = "خمسة عشر";//"@SYS26637";
            ones[16] = "سادسة عشر";//"@SYS26638";
            ones[17] = "سابعة عشر";//"@SYS26639";
            ones[18] = "ثامنة عشر";//"@SYS26640";
            ones[19] = "تاسعة عشر";//"@SYS26641";
       
            tenths[1] = 'Not used';
            tenths[2] ="عشرون";// "@SYS26643";
            tenths[3] = "ثلاثون";//"@SYS26644";
            tenths[4] = "اربعون";//"@SYS26645";
            tenths[5] = "خمسون";//"@SYS26646";
            tenths[6] = "ستون";//"@SYS26647";
            tenths[7] = "سبعون";//"@SYS26648";
            tenths[8] = "ثمانون";//"@SYS26649";
            tenths[9] = "تسعون";//"@SYS26650";
       
            hundreds    = "مائة";//"@SYS26651";
            thousands   = "الف";//"@SYS26652";
            millions    = "مليون";//"@SYS26653";
            billions    = "بليون";//"@SYS26654";
            trillions   = "تريليون";//"@SYS101697";
       
            if(test == 0)
       
        {
                    returntxt = zero;
           
        }
            else
       
        {
                    test = checkPower(test, 1000000000000);
                    test = checkPower(test, 1000000000);
                    test = checkPower(test, 1000000);
                    test = checkPower(test, 1000);
                    test = checkPower(test, 100);
           
        }
       
            if(returntxt && test)
       
        {
                    returntxt = returntxt + and + doubleDigit2ARTxt(real2int(test));
           
        }
            else
       
        {
                    returntxt = returntxt + ' ' + doubleDigit2ARTxt(real2int(test));
           
        }
       
            if(numOfPennies)
       
        {
                    //Removing the stars and addin the pound and cent wording to fullfil the Egyptian requierment
                    returntxt = ' فقط ' + returntxt + ' ' + comma + ' ' + and + doubleDigit2ARTxt(numOfPennies,true) + ' ' + cent + ' لاغير ';
                    //returntxt = '***' + returntxt + ' ' + comma + ' ' + doubleDigit2ARTxt(numOfPennies,true);
           
           
        }
            else
       
        {
                    //Removing the stars and the zeros if no cents to fullfil the Egyptian requierment
                    returntxt = ' فقط ' + returntxt + ' ' + comma + ' لاغير ';
           
                    //returntxt = '***' + returntxt + ' ' + comma + ' ' + zero + ' ' + zero;
           
        }
       
               // infolog.language("EN");
       
            return returntxt;
       
    }