Tuesday, 28 December 2021

Cust Tax registration number x++ D365

 public str getCRNum(CustAccount   _custAccount)

    {

        CustTable           custTable   =   CustTable::find(_custAccount);

        DirPartyTable       dirPartyTable;

        DirPartyLocation    dirPartyLocation;

        TaxRegistration     taxRegistration;

        TaxRegistrationType taxRegistrationType;

        TaxRegistrationTypeApplicabilityRule    taxRegistrationTypeApplicabilityRule;


        select taxRegistration

            join taxRegistrationTypeApplicabilityRule

            join taxRegistrationType

            join dirPartyLocation

            join dirPartyTable

            join custTable

            where taxRegistration.DirPartyLocation  ==  dirPartyLocation.RecId

            && taxRegistration.TaxRegistrationTypeApplicabilityRule ==  taxRegistrationTypeApplicabilityRule.RecId

            && taxRegistrationTypeApplicabilityRule.TaxRegistrationType ==  taxRegistrationType.RecId

            && taxRegistrationType.TaxRegstrationType == "CR"

            && dirPartyLocation.Party   ==  dirPartyTable.RecId

            && dirPartyTable.RecId  ==  custTable.Party;

        

        return taxRegistration.RegistrationNumber;

    }

QR Text output x++

qrString        = strFmt("Supplier name: %1", CompanyInfo::findDataArea(_custInvoiceJour.DataAreaId).Name);

                qrString        += strFmt("\nSupplier VAT: %1", CompanyInfo::findDataArea(_custInvoiceJour.DataAreaId).CoRegNum);

                qrString        += strFmt("\nInvoice number: %1", _custInvoiceJour.InvoiceId);

                qrString        += strFmt("\nInvoice Date: %1", _custInvoiceJour.InvoiceDate);

                qrString        += strFmt("\nTotal amount with VAT: %1", _custInvoiceJour.InvoiceAmount);

                qrString        += strFmt("\nVAT amount: %1", _custInvoiceJour.SumTax);


public Bitmap getQR(String255 _qrString)

    {

        str                                 QrCodeBase64String;

        Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder   qrCode;

        System.String                       netString;

        str                                 tempFileName;

        System.Drawing.Bitmap               netBitmap;

        Bitmap                              imageQR;

        FileIOPermission                    perm;

        BinData                             binData;

        container                           imageContainer;

        Str1260                             qrString;

        real                                taxWithoutVat;

        QRCodeGenerator qrGenerator = new QRCodeGenerator();


        qrCode          = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();

        

        netBitmap       = qrCode.Encode(_qrString);

        binData         = new binData();

        QrCodeBase64String  = _qrString;

        tempFileName        = qrCode.GetTempFile(QrCodeBase64String);

        perm  = new FileIOPermission(tempFileName,'RW');

        perm.assert();

        binData.loadFile(tempFileName);

        imageContainer          = binData.getData();


        return imageContainer;

    }


Use bitmap to display QR (Image/bmp) 

QR base64 D365 x++

 public Bitmap hexaDecimalQRCode(Name            _companyName,

                                    VATNum          _vatNum,

                                    CustInvoiceId   _invoiceId,

                                    CreatedDateTime _transdate,

                                    AmountCurNet    _netAmt,

                                    Amount          _vatAmt)

    {

        str             hexaDecimalSellerTag,hexaDecimalVATNumberTag,hexaDecimalTimeStampTag,hexaDecimalInvoiceTotalTag,hexaDecimalVATTotalTag;

        int             hexaDecimalSellerLength,hexaDecimalVATNumberLength,hexaDecimalTimeStampLength,hexaDecimalInvoiceTotalLength,hexaDecimalVATTotalLength;

        str             hexaDecimalSellerValue,hexaDecimalVATNumberValue,hexaDecimalTimeStampValue,hexaDecimalInvoiceTotalValue,hexaDecimalVATTotalValue;

        str             hexaDecimalSeller,hexaDecimalVATNumber,hexaDecimalTimeStamp,hexaDecimalInvoiceTotal,hexaDecimalVATTotal;

        Str             Seller,VATNumber,TimeStamp,InvoiceTotal,VATTotal,hexaDecimal,tempValue,base64Text;

        System.Byte[]   byte;

        bindata         bindata;

        container       con;

        int             i;

        container       qrCode,conStore;

        Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder  qrCode1 = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();

        System.Drawing.Bitmap bitmap;

        System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();



        container      imageContainer;

        hexaDecimalSellerTag        = "01";

        hexaDecimalVATNumberTag     = "02";

        hexaDecimalTimeStampTag     = "03";

        hexaDecimalInvoiceTotalTag  = "04";

        hexaDecimalVATTotalTag      = "05";


        Seller          = _companyName;

        VATNumber       = strFmt("%1",_vatNum);

        TimeStamp       = "2021-12-22 09:26:31";//DateTimeUtil::toStr(_transdate);//"2021-11-01 11:30:28";//"3/26/2018 01:28:18";//strFmt("%1",_transdate);//"2021-11-01 21:30:00";

        InvoiceTotal    = strFmt("%1",_netAmt);

        VATTotal        = strFmt("%1",_vatAmt);


        hexaDecimalSellerLength         = strLen(Seller);

        hexaDecimalVATNumberLength      = strLen(VATNumber);

        hexaDecimalTimeStampLength      = strLen(TimeStamp);

        hexaDecimalInvoiceTotalLength   = strLen(InvoiceTotal);

        hexaDecimalVATTotalLength       = strLen(VATTotal);


        hexaDecimalSellerValue          = int2Hex(hexaDecimalSellerLength);

        hexaDecimalVATNumberValue       = int2Hex(hexaDecimalVATNumberLength);

        hexaDecimalTimeStampValue       = int2Hex(hexaDecimalTimeStampLength);

        hexaDecimalInvoiceTotalValue    = int2Hex(hexaDecimalInvoiceTotalLength);

        hexaDecimalVATTotalValue        = int2Hex(hexaDecimalVATTotalLength);



        if(strLen(hexaDecimalSellerValue) == 1)

        {

            hexaDecimalSellerValue          = "0" + hexaDecimalSellerValue;

        }

        if(strLen(hexaDecimalVATNumberValue) == 1)

        {

            hexaDecimalVATNumberValue       = "0" + hexaDecimalVATNumberValue;

        }

        if(strLen(hexaDecimalTimeStampValue) == 1)

        {

            hexaDecimalTimeStampValue       = "0" + hexaDecimalTimeStampValue;

        }

        if(strLen(hexaDecimalInvoiceTotalValue) == 1)

        {

            hexaDecimalInvoiceTotalValue    = "0" + hexaDecimalInvoiceTotalValue;

        }

        if(strLen(hexaDecimalVATTotalValue) == 1)

        {

            hexaDecimalVATTotalValue    = "0" + hexaDecimalVATTotalValue;

        }


        for (i=1;i<=hexaDecimalSellerLength ;i++)

        {

            hexaDecimalSeller    += int2Hex(char2num(Seller,i));

        }

        for (i=1;i<=hexaDecimalVATNumberLength ;i++)

        {

            hexaDecimalVATNumber    += int2Hex(char2num(VATNumber,i));

        }

        for (i=1;i<=hexaDecimalTimeStampLength ;i++)

        {

            hexaDecimalTimeStamp    += int2Hex(char2num(TimeStamp,i));

        }

        for (i=1;i<=hexaDecimalInvoiceTotalLength ;i++)

        {

            hexaDecimalInvoiceTotal    += int2Hex(char2num(InvoiceTotal,i));

        }

        for (i=1;i<=hexaDecimalVATTotalLength ;i++)

        {

            hexaDecimalVATTotal    += int2Hex(char2num(VATTotal,i));

        }


        hexaDecimal = hexaDecimalSellerTag + hexaDecimalSellerValue +hexaDecimalSeller + hexaDecimalVATNumberTag + hexaDecimalVATNumberValue +  hexaDecimalVATNumber + hexaDecimalTimeStampTag

            + hexaDecimalTimeStampValue + hexaDecimalTimeStamp + hexaDecimalInvoiceTotalTag + hexaDecimalInvoiceTotalValue + hexaDecimalInvoiceTotal + hexaDecimalVATTotalTag + hexaDecimalVATTotalValue + hexaDecimalVATTotal;



        //hexaDecimal =   "011153656465722048656164204f6666696365020f3330303034393035353231303030330313323032312d31322d32322030393a32363a3331040331313105063734342e3135";


        con         = BinData::stringToData(hexadecimal);

        bindata     = new bindata();

        bindata.setData(con);

        base64Text = bindata.base64Encode();

        //base64Text  =   "ARFTZWRlciBIZWFkIE9mZmljZQIPMzAwMDQ5MDU1MjEwMDAzAxMyMDIxLTEyLTIyIDA5OjI2OjMxBAMxMTEFBjc0NC4xNQ==";


        bitmap=qrCode1.Encode(base64Text);


        bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat::get_Jpeg());//get_Jpeg

        imageContainer=Binary::constructFromMemoryStream(memoryStream).getContainer();


        


        qrCode = imageContainer;

        return qrCode;

    }


    public bitmap qrBitMap(str _qrString)

    {

        Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder  qrCode1 = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();

        System.Drawing.Bitmap bitmap;

        System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();

        container           imageContainer;

        container           qrCode,conStore;


        bitmap=qrCode1.Encode(_qrString);


        bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat::get_Jpeg());//get_Jpeg

        imageContainer=Binary::constructFromMemoryStream(memoryStream).getContainer();


        


        qrCode = imageContainer;

        return qrCode;

    }


Use bitmap to display QR (Image/bmp)

Tuesday, 7 December 2021

Pending/Delegated WF user x++

 public static void main(Args _args)

{

    LetterRequestTable        letterRequestTable   =    LetterRequestTable::find("ABC-000003");

    WorkflowWorkItemTable       workflowWorkItemTable;


    select workflowWorkItemTable

        where workflowWorkItemTable.RefRecId == letterRequestTable.RecId

        && workflowWorkItemTable.RefTableId == letterRequestTable.TableId

        && ((workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending) || (workflowWorkItemTable.Status == WorkflowWorkItemStatus::Delegated));


    Info(strFmt("%1", HcmWorker::find(HcmWorker::userId2Worker(workflowWorkItemTable.UserId)).name()));

}