Thursday 27 June 2019

AX7/365 Get the sales from the sales order totals x++

elow job gives Sales Total details i.e. fetching sales order totals (Total Discount, Subtotal Amount & Invoice Amount)




  static void ShyamSalesTotalJob(Args _args)
    {

//Total Discount from Sales Totals form
        SalesTable salesTable1;
        salesTable1= SalesTable::find(“000746”,false);
        SalesTotals salesTotals;
        salesTotals  =  SalesTotals::construct(salesTable1, salesUpdate::All);
        container   displayFields;
        displayFields = SalesTotals::displayFieldsServer(salesTable1,SalesUpdate::All,salesTotals.CurrencyCode());

        DiscAmount      totalDisc=0;RealBase subTotal=0;AmountCur invoiceAmount=0;

//Total Discount
        totalDisc   = conpeek(displayFields, TradeTotals::posEndDisc());
 info(Strfmt("Total discount %1", totalDisc));

//Subtotal Amount
        subTotal=conpeek(displayFields, TradeTotals::posBalance());
        info(Strfmt("Subtotal Amount %1", subTotal));

//Invoice Amount
        invoiceAmount =conpeek(displayFields, TradeTotals::posTotalAmount());
            info(Strfmt("Invoice Amount %1", invoiceAmount));


}

AX7/365 Consume Custom web service

 First We need to configure the application Registration in Azure
1-Open the Azure Portal Portal.Azure.com
2-Type the user name and password of the admin



3-Create New Registration Type any name

4-A new Application or Client ID will be created


5- Add new redirect URI(AxUrl/YorServiceGroupName)



6-Add permissions as the screen below



7-Grant Access for the admin

8-Create the Secrete Key



string aosUri = "https://usnconeboxax1aos.cloud.onebox.dynamics.com";
            string activeDirectoryTenant = "https://login.windows.net/albabtaingroupkw.onmicrosoft.com";
            string activeDirectoryClientAppId = "b99f1271-0da6-407a-8054-dcc452688d02";
            string activeDirectoryClientAppSecret = "@yKp*b.Hxr]wQkDo1zdTICP0Xoa6L16v";
            string activeDirectoryResource = "https://usnconeboxax1aos.cloud.onebox.dynamics.com";


            AuthenticationContext authenticationContext = new AuthenticationContext(activeDirectoryTenant);
            string aadClientAppSecret = activeDirectoryClientAppSecret;
            ClientCredential creadential = new ClientCredential(activeDirectoryClientAppId, activeDirectoryClientAppSecret);
            AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(activeDirectoryResource, creadential).Result;
            string oAuthHeader = authenticationResult.CreateAuthorizationHeader();
            string serviceName = "TestServiceGroup";
            string soapServiceUriString = GetSoapServiceUriString(serviceName, aosUri);
            EndpointAddress endpointAddress = new EndpointAddress(soapServiceUriString);
            Binding binding = GetBinding();
            //string soapServiceUriString = GetSoapServiceUriString(serviceName, aosUri);

            myService.GenerateUniqueStringClient objClient = new myService.GenerateUniqueStringClient(binding, endpointAddress);
            myService.CallContext callContext = new myService.CallContext { Company = "USMF" };
            IClientChannel objChannel = objClient.InnerChannel;
            var strOut = "";

            using (OperationContextScope dimServiceOperContext = new OperationContextScope(objChannel))
            {
                HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                requestMessage.Headers[OAuthHelper.OAuthHeader] = oAuthHeader;
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

                //  IList dimensionContracts = ((myService.GenerateUniqueString)objChannel).HelloWorld(new myService.HelloWorld()).result;
                strOut = ((myService.GenerateUniqueString)objChannel).HelloWorld(new myService.HelloWorld(callContext,"Hesham ")).result;


                IList customers = ((myService.GenerateUniqueString)objChannel).getCustomers(new myService.getCustomers()).result;

                foreach (myService.myCustTable dimensionContract in customers)
                {
                    Console.WriteLine(dimensionContract.ParmCustName);
                }

            }



            Console.WriteLine(strOut);
            Console.Read();

Monday 24 June 2019

AX 2012/365 x++ 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;
}

Tuesday 11 June 2019

AX x++ get the item sales price

 InventTable::find(tempTable.ItemId).salesPriceAgreement(systemDateGet(),_InventDim,1,tempTable.SalesUnitTxt,"",tempTable.CurrencyCode,"");