Wednesday, 22 January 2020

amount in words 3 decimal precision x++

static TempStr numeralsToTxtThreeDecimal(real _num)
{
int     numOfPennies = any2int(decRound(frac(_num), 3) * 1000) mod 1000;
real    test         = _num - frac(_num);

int64   numOfTenths;
str 20  ones[19], tenths[9], hundreds, thousands, millions, billions, trillions;

int64   temp;
str 200 returntxt;
int64   testLoc;

real modOperator(real a1, real a2)
{
int tmpi;
real tmp1, tmp2;
tmp1 = a1 / a2;
tmpi = real2int(tmp1);
tmp2 = tmpi;
return (tmp1 - tmp2)*a2;
}

real checkPower(real  _test, int64 _power)
{
int64   numOfPower;

if (_test >= _power)
{
testLoc = any2int64(_test);
numOfPower = testLoc div _power;

if (numOfPower >= 100)
{
temp = numOfPower div 100;
returntxt = returntxt + ' ' + ones[temp] + ' ' + hundreds;
numOfPower = numOfPower mod 100;
}
if (numOfPower >= 20)
{
temp = numOfPower div 10;
returntxt = returntxt + ' ' + tenths[temp];
numOfPower = numOfPower mod 10;
}
if (numOfPower >= 1)
{
returntxt = returntxt + ' ' + ones[numOfPower];
numOfPower = numOfPower mod 10;
}
switch(_power)
{
case 1000000000000 :
returntxt = returntxt + ' ' + trillions;
_test = modOperator(_test, 1000000000000.00);
break;
case 1000000000 :
returntxt = returntxt + ' ' + billions;
_test = modOperator(_test, 1000000000);
break;
case 1000000 :
returntxt = returntxt + ' ' + millions;
_test = modOperator(_test, 1000000);
break;
case 1000 :
returntxt = returntxt + ' ' + thousands;
_test = modOperator(_test, 1000);
break;
case 100 :
returntxt = returntxt + ' ' + hundreds;
_test = modOperator(_test, 100);
break;
}
}
return _test;
}
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";


test = checkPower(test, 1000000000000);
test = checkPower(test, 1000000000);
test = checkPower(test, 1000000);
test = checkPower(test, 1000);
test = checkPower(test, 100);

if (test >= 20)
{
testLoc = any2int64(test);
numOfTenths = testLoc div 10;

returntxt = returntxt + ' ' + tenths[numofTenths];
numOfTenths = numOfTenths mod 10;
test = real2int(test) mod 10;
}
if (test >= 1)
{
numOfTenths = real2int(test);
returntxt = returntxt + ' ' + ones[numOfTenths];
}

if (numOfPennies)
{
returntxt = '***' + returntxt + ' ' + "@SYS5534" + ' ' + num2str(numOfPennies,0,0,0,0) + '/1000';
}
else
{
returntxt = '***' + returntxt + ' ' + "@SYS5534" + ' ' + '000/1000';
}
return returntxt;
}

Sunday, 19 January 2020

dialog box x++

if (Box::okCancel("Settled records exceeded than page limit", DialogButton::Cancel) == DialogButton::Ok)

Thursday, 16 January 2020

Ledger Journal marked settlement transactions x++

LedgerJournalTrans ledgerJournalTrans
SpecTrans        specTrans;
VendTransOpen    vendTransOpen;
VendTrans        vendTrans

select first only ledgerJournalTrans where ledgerJournalTrans.RecId == _recId; //pass line recId

while select specTrans
join vendTransOpen
join vendTrans
where specTrans.SpecCompany == ledgerJournalTrans.DataAreaId
&& specTrans.SpecTableId    == ledgerJournalTrans.TableId
&& specTrans.SpecRecId      == ledgerJournalTrans.RecId
&& specTrans.RefCompany     == vendTransOpen.DataAreaId
&& specTrans.RefTableId     == vendTransOpen.TableId
&& specTrans.RefRecId       == vendTransOpen.RecId
&& vendTransOpen.RefRecId   == vendTrans.RecId
&& vendTransOpen.AccountNum == vendTrans.AccountNum
{
info(strfmt("%1--%2--%3", ledgerJournalTrans.Voucher, vendTrans.Invoice, vendTransOpen.AmountCur));
}

SO Invoice / PO Conformation new design in D365 FO

Create a new report with proposed design (Report, designName)

//Print management SO&PO

class AC_PrintMgtDocTypeHandlersExt
{
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {

        switch (_docType)
        {
            case PrintMgmtDocumentType::SalesOrderInvoice :
                _result.result(ssrsReportStr(AC_SalesInvoice, Report));
                break;

            case PrintMgmtDocumentType::PurchaseOrderConfirmationRequest :
                _result.result(ssrsReportStr(AC_PurchPurchaseOrder, Report));
                break;
        }
    }

}

//Controller CoC for SO

[ExtensionOf(classStr(SalesInvoiceController))]
final class AC_SalesInvoiceController_Extension
{
    protected void outputReport()
    {
        PrintMgmtPrintSettingDetail     printSettingDetail;
        FormLetterReport                formLetterReport;
        SRSCatalogItemName              reportDesign;

        formLetterReport = this.formLetterReport;
        printSettingDetail = formLetterReport.getCurrentPrintSetting();

        reportDesign = ssrsReportStr(AC_SalesInvoice, Report);

        this.parmReportName(reportDesign);
        this.parmReportContract().parmReportName(reportDesign);
        formletterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
        next outputReport();
    }

}

//Controller CoC for PO

[ExtensionOf(classStr(PurchPurchaseOrderController))]
final class AC_PurchPurchaseOrderController_Extension
{
    protected void outputReport()
    {
        PrintMgmtPrintSettingDetail     printSettingDetail;
        FormLetterReport                formLetterReport;
        SRSCatalogItemName              reportDesign;

        formLetterReport = this.formLetterReport;
        printSettingDetail = formLetterReport.getCurrentPrintSetting();

        reportDesign = ssrsReportStr(AC_PurchPurchaseOrder, Report);

        this.parmReportName(reportDesign);
        this.parmReportContract().parmReportName(reportDesign);
        formletterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
        next outputReport();
    }

}

//PO Header CoC

[ExtensionOf(tableStr(PurchPurchaseOrderHeader))]
final class AC_PurchPurchaseOrderHeader_Extension
{
    public void insert()
    {
        PurchTable                  purchTable;
        VendTable                   vendTable;
        PurchLine                   purchline;
        PurchRFQReplyLinePurchLine  purchRFQReplyLine;
        AmountMST                   totalValue;
        PurchLine                   purchLineLocal;
        LogisticsElectronicAddress  logisticsElectronicAddress;
        DirPartyTable               dirPartyTable;
        TaxJournalTrans             taxJournalTrans;
        VendPurchOrderJour          vendPurchOrderJour;

        purchTable = PurchTable::find(this.PurchId);
        vendTable = purchTable.vendTable_OrderAccount();

        select vendPurchOrderJour where vendPurchOrderJour.PurchOrderDocNum  ==  this.PurchOrderDocNum;

        select sum(TaxAmount) from taxJournalTrans
            where taxJournalTrans.TransTableId   ==  vendPurchOrderJour.TableId
            && taxJournalTrans.TransRecId   ==  vendPurchOrderJour.RecId;

        select firstonly * from purchline where purchline.PurchId == purchTable.PurchId;
        select sum(LineAmount) from purchLineLocal where purchLineLocal.PurchId == purchTable.PurchId;

        this.AC_VendCity        =   vendTable.countryRegionName();
        this.AC_VendTelephone   =   vendTable.phone();
        this.AC_VendFax         =   vendTable.telefax();
        this.AC_CompanyURL      =   purchTable.companyInfo().url();

        select firstOnly logisticsElectronicAddress
            where logisticsElectronicAddress.RecId == DirPartyTable::findRec
            (VendTable::find(vendTable.AccountNum).Party).PrimaryContactFax
            && logisticsElectronicAddress.IsPrimary ==  NoYes::Yes;
     
        this.CompanyVATNum      =   TaxRegistration::getCompanyTaxRegNum_W(this.PurchOrderDate);
        this.AC_TotalVATAmount  =   taxJournalTrans.TaxAmount;
        this.AC_TotalAmount     =   purchLineLocal.LineAmount + taxJournalTrans.TaxAmount;
        this.AC_AmountInWords   =   Global::numeralsToTxt(this.AC_TotalAmount);
     
        //this.CompanyVATNum =  companyInfo.CoRegNum;
        //this.INTC_VATNum = this.getTax(vendTable.postalAddress().Location);
        //this.AC_VendFax   = logisticsElectronicAddress.Locator;
        next insert();
    }

    public TaxRegistrationNumber getTax(LogisticsLocationRecId   _location)
    {
        TaxRegistration                         taxRegistration;
        TaxRegistrationType                     taxRegistrationType;
        TaxRegistrationTypeApplicabilityRule    taxRegistrationRule;
        LogisticsLocation                       logisticsLocation;
        DirPartyLocation                        dirPartyLocation;

        logisticsLocation = LogisticsLocation::find(_location);

        select taxRegistration
            join taxRegistrationRule
            where taxRegistrationRule.RecId ==  taxRegistration.TaxRegistrationTypeApplicabilityRule
            join taxRegistrationType
            where taxRegistrationType.RecId == taxRegistrationRule.TaxRegistrationType
            join dirPartyLocation
            where taxRegistration.DirPartyLocation == dirPartyLocation.RecID
            && dirPartyLocation.Location == logisticsLocation.RecId;

        return taxRegistration.RegistrationNumber;
    }

    public void initFromCompanyInfoOnBlankPaper(CompanyInfo _companyInfo)
    {
        next initFromCompanyInfoOnBlankPaper(_companyInfo);
        this.CompanyEmail   = _companyInfo.email();
    }

    public void initFromVendPurchOrderJour(VendPurchOrderJour _vendPurchOrderJour)
    {
        next initFromVendPurchOrderJour(_vendPurchOrderJour);
        this.NetAmount  = _vendPurchOrderJour.netAmount();
    }

}

//PO line CoC

[ExtensionOf(tableStr(PurchPurchaseOrderTmp))]
final class AC_PurchPurchaseOrderTmp_Extension
{
    public void insert()
    {
        PurchTable              purchTable;
        PurchLine               purchLine;
        VendPurchOrderJour      vendPurchOrderJour;
        PurchLineAllVersions    purchLineAllVersions;
        TaxJournalTrans         taxJournalTrans;
        PurchTableAllVersions   PurchTableAllVersions;
        TaxTable                taxTable;

        select VendPurchOrderJour
            where VendPurchOrderJour.RecId == this.JournalRecId
            join PurchTableAllVersions
            join PurchLineAllVersions
            join taxJournalTrans
            join purchLine
            where PurchTableAllVersions.PurchTableVersionRecId ==        VendPurchOrderJour.PurchTableVersion
            && PurchLineAllVersions.PurchTableVersionRecId == PurchTableAllVersions.PurchTableVersionRecId
            && PurchLineAllVersions.ItemId == this.ItemId
            && taxJournalTrans.TransTableId == vendPurchOrderJour.TableId
            && taxJournalTrans.TransRecId == vendPurchOrderJour.RecId
            && taxJournalTrans.InventTransId == PurchLineAllVersions.InventTransId
            && purchLine.SourceDocumentLine == PurchLineAllVersions.SourceDocumentLine;

        select taxTable where taxTable.TaxCode == taxJournalTrans.TaxCode;

        this.AC_VATAmount   =   abs(taxJournalTrans.SourceTaxAmountCur);
        this.AC_VATPerc     =   taxTable.showTaxValue();
        this.AC_TotalAmount =   this.AC_VATAmount + this.LineAmount;
       
        next insert();
    }

}

//SO Header CoC

[ExtensionOf(tableStr(SalesInvoiceHeaderFooterTmp))]
final class AC_SalesInvoiceHeaderFooter_Extension
{
    public void insert()
    {
        SalesTable                  salesTable;
        LogisticsElectronicAddress  logisticsElectronicAddress;
        DirPartyTable               dirPartyTable;
        TaxJournalTrans             taxJournalTrans;
        VendPurchOrderJour          vendPurchOrderJour;
        CustInvoiceJour             custInvoiceJour;

        salesTable  =   SalesTable::find(this.SalesId);
        select custInvoiceJour where custInvoiceJour.RecId == this.JournalRecId;
       
        this.AC_CustName    =   CustTable::find(this.InvoiceAccount).name();
        this.AC_CustCity    =   CustTable::find(this.InvoiceAccount).cityName_BR();
        this.AC_CustCountry =   CustTable::find(this.InvoiceAccount).countryName();
        this.AC_InvoiceNum  =   custInvoiceJour.InvoiceId;
     
        next insert();
    }

}

//SO Line CoC

[ExtensionOf(tableStr(SalesInvoiceTmp))]
final class AC_SalesInvoiceTmp_Extension
{
    public void insert()
    {
        SalesTable          salesTable;
        SalesLine           salesLine;
        real                tax1;
        InventTable         inventTable =   InventTable::find(this.ItemId);
        real                totalAmount;
        TaxTrans            taxTrans;
        CustInvoiceTrans    custInvoiceTrans;
        CustInvoiceJour     custInvoiceJour;

        real                taxAmount;
        real                salesPrice;
        select custInvoiceJour where custInvoiceJour.RecId == this.JournalRecId;

        select custInvoiceTrans
            where custInvoiceTrans.SalesId == custInvoiceJour.SalesId
            && custInvoiceTrans.InvoiceId   ==  custInvoiceJour.InvoiceId
            && custInvoiceTrans.InvoiceDate ==  custInvoiceJour.InvoiceDate
            && custInvoiceTrans.numberSequenceGroup ==  custInvoiceJour.numberSequenceGroup
            && custInvoiceTrans.ItemId  ==  this.ItemId;
     
        select taxTrans where taxTrans.InventTransId == custInvoiceTrans.InventTransId;
        this.TaxAmount          =   abs(taxTrans.TaxAmount);
        this.AC_VATPerc         =   taxTrans.TaxValue;
        this.AC_TotalAmount     =   this.LineAmount + this.TaxAmount;
        this.AC_SalesPrice      =   this.AC_TotalAmount/this.Qty;

        next insert();
    }

}

Build and deploy your report.
Select your design in print management settings level.