Thursday, July 13, 2023

Workflow Approver Name For PurchRequsition Order

 For First Approver,

this.workflowApprover(purchReqTable.RecId);

    public void workflowApprover(RecId _recId)  // Requsation Table RecId
    {
        WorkflowTrackingStatusTable     workflowTrackingStatus;
        WorkflowTrackingTable       workflowTrackingTable;
        WorkflowTrackingCommentTable    workflowTrackingCommentTable;
        UserInfo    userInfo;
       
        select firstFast RecId, User from workflowTrackingTable
                order by RecId asc
            join workflowTrackingCommentTable
                where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId
            join UserInfo
                where UserInfo.id == WorkflowTrackingTable.User
            exists join workflowTrackingStatus
                where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId
            && workflowTrackingStatus.ContextRecId      == _recId
            && workflowTrackingStatus.ContextTableId    == tableNum(PurchReqTable)// your custom table on which workflow is enabled.
        && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval;
       
        if (workflowTrackingTable.RecId > 0)
        {
            S3_PurchTable_Tmp.RecommendedBy = userInfo.name;
            S3_PurchTable_Tmp.Designation_Recommended = hcmworker::findByPerson(DirPersonUser::find(userInfo.id).PersonParty).title();
            S3_PurchTable_Tmp.RecommendedId = hcmworker::findByPerson(DirPersonUser::find(userInfo.id).PersonParty).PersonnelNumber;
        }
    }

For Last Approver,

this.workflowApprover_last(purchReqTable.RecId);

public void workflowApprover_last(RecId _recId)
    {
        WorkflowTrackingStatusTable     workflowTrackingStatus;
        WorkflowTrackingTable       workflowTrackingTable;
        WorkflowTrackingCommentTable    workflowTrackingCommentTable;
        UserInfo    userInfo;
       
        while select  RecId, User from workflowTrackingTable
                order by RecId asc
            join workflowTrackingCommentTable
                where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId
            join UserInfo
                where UserInfo.id == WorkflowTrackingTable.User
            exists join workflowTrackingStatus
                where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId
            && workflowTrackingStatus.ContextRecId      == _recId
            && workflowTrackingStatus.ContextTableId    == tableNum(PurchReqTable)// your custom table on which workflow is enabled.
        && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval
        {
            if (workflowTrackingTable.RecId > 0)
            {
                S3_PurchTable_Tmp.ApprovedBy = userInfo.name;
                S3_PurchTable_Tmp.Designation_Approved = hcmworker::findByPerson(DirPersonUser::find(userInfo.id).PersonParty).title();
                S3_PurchTable_Tmp.ApproverId = hcmworker::findByPerson(DirPersonUser::find(userInfo.id).PersonParty).PersonnelNumber;
            }
        }
    }

Monday, August 29, 2022

Multi select Lookup on Form using X++

First Set a global Variable,

public SysLookupMultiSelectCtrl    multicltrl;


Create Lookup method to get the value in field,

       public void lookup()

       {

           Query                       query;

           QueryBuildDataSource        queryBuildDataSource;

           QueryBuildFieldList         fieldList;

 

           super();

 

           query                   = new Query();

           queryBuildDataSource    = query.addDataSource(tableNum(CustTable));

           fieldList               = queryBuildDataSource.fields();

           fieldList.addField(fieldNum(CustTable,AccountNum));

           fieldList.addField(fieldNum(CustTable,CustGroup));

           fieldList.addField(fieldNum(CustTable,RecId));

           fieldList.dynamic(QueryFieldListDynamic::No);

 

           container   selectedField = [tableNum(CustTable), fieldNum(CustTable,AccountNum)];

 

           multicltrl = SysLookupMultiSelectCtrl::constructWithQuery(this.formRun(),this,query,false,selectedField);

       

       }

Create Modified Method to set the value in field,

       public boolean modified()

       {

           boolean ret;

       

           ret = super();

           TestTable.CustomField = con2Str(multicltrl.getSelectedFieldValues(), ';');

           return ret;

       }


Process,

Click on Form Field Lookup button,


Select all field which you wanted,



Now you have multi value in field,



Enjoy 👍

Using COC

[ExtensionOf(formDataFieldStr(ProjTableCreate, ProjTable, GropId))]

final class FormDataSource_Extension

{

   public SysLookupMultiSelectCtrl    multicltrl;

 

   public void lookup(FormControl _formControl, str _filterStr)

   {

       Query                       query;

       QueryBuildDataSource        queryBuildDataSource;

       QueryBuildFieldList         fieldList;

       FormRun                 localFormRun = _formControl.formRun();

       next lookup(_formControl,_filterStr);

 

       query                   = new Query();

       queryBuildDataSource    = query.addDataSource(tableNum(ProjValProjCategoryTable));

       fieldList               = queryBuildDataSource.fields();

 

       fieldList.addField(fieldNum(ProjValProjCategoryTable, GroupId));

       fieldList.addField(fieldNum(ProjValProjCategoryTable, Name));

       fieldList.dynamic(QueryFieldListDynamic::No);

 

       container   selectedField = [tableNum(ProjValProjCategoryTable), fieldNum(ProjValProjCategoryTable, GroupId)];

 

 

       multicltrl = SysLookupMultiSelectCtrl::constructWithQuery(localFormRun,_formControl,query,false,selectedField);

   }

 

   /// <summary>

   ///

   /// </summary>

   public void modified()

   {

       FormDataObject formDataObject = any2Object(this) as FormDataObject;

       FormDataSource formDataSource = formDataObject.datasource();

       ProjTable           projTable;

 

       next modified();

 

       projTable = formDataSource.cursor();

       projTable.GropId = con2Str(multicltrl.getSelectedFieldValues(), ';');

   }

 

}

Tuesday, November 23, 2021

Pass Multi Line Record Using Button Clicked

 

Pass multi Line Record using Button

Form A Button clicked Method:
void clicked()
{
    int         recordsCount;
    SalesLine   _salesLine;
    container   con;
    Args        args;
    str         multiSelectString;
 
    args = new Args();
    recordsCount = SalesLine_1_ds.recordsMarked().lastIndex(); // gets the total records selected
    _salesLine = SalesLine_1_ds.getFirst(1);
 
    while (_salesLine)
    {
    con = conIns(con, 1, _salesLine.RecId);
 
    multiSelectString = con2Str(con, ",");
 
    _salesLine = SalesLine_1_ds.getNext(); // moves to next record
    }
    args.parm(multiSelectString);
    new MenuFunction(menuitemDisplayStr(GofyndSalesOrderError), MenuItemType::Display).run(args);
}
 
Form B Init Method:
public void init()
{
    super();
   
    multipleRecords = element.args().parm();
 
    con = str2con(multipleRecords,",");
    for(i = 1; i<= conLen(con);i++)
    {
  SalesLine_ds.query().dataSourceTable(Tablenum(SalesLine)).addRange(fieldNum(SalesLine,RecId)).value(SysQuery::value(conPeek(con,i)));
SalesLine_ds.query().dataSourceTable(tableNum(SalesLine)).addRange(fieldNum(SalesLine,S3_GofyndError)).value(sysquery::valueNotEmptyString());
    }
   

}

 

Sunday, August 1, 2021

Tax Details Using X++

From Tax Document You have to Use TaxDocumentLauncher Class.
this.taxData(purchReqLine,purchReqHead);
public void taxData(PurchReqLine       _line, PurchReqTable   _head)
    {
        TaxableDocumentDescriptor   bundler;
        ClassId                     bundlerId;
        ITaxableDocument            taxableDocument;
        ITaxDocumentLine            taxDocumentLine;
        common                              transactionTable ;
        ITaxableDocumentLine        taxableDocumentLine;
        TaxableDocumentLineObject   taxableDocumentObject;
        ITaxDocumentComponentLine           taxDocumentComponentLine;
        ITaxDocumentComponentLineEnumerator taxDocumentComponentLineEnumerator;
TaxAmount     CGSTValue,CGSTAmt,SGSTValue,SGSTAmt,IGSTValue,IGSTAmt,TaxValue,TaxAmt;

        if(_line)
        {
            transactionTable = TaxEnginePurchReqHeader::findByPurchReqLineRecId(_line.RecId);
            bundler = TaxableDocumentDescriptor::getTaxDocumentdescriptor(54705, transactionTable);
            taxableDocument = TaxableDocumentObject::construct(bundler);
            TaxBusinessService::calculateTax(taxableDocument, false);
            taxableDocumentLine = TaxableDocumentLineObject::construct(_line.TableId, _line.RecId);
            if(taxableDocumentLine)
            {
               
                taxDocumentLine = taxableDocument.parmTaxDocument().findLineByOrig(
                taxableDocumentLine.getTransactionLineTableId(),
                taxableDocumentLine.getTransactionLineRecordId());
                
                if (taxDocumentLine)
                {
                    taxDocumentComponentLineEnumerator = taxDocumentLine.componentLines("GST");
              
                    while (taxDocumentComponentLineEnumerator.moveNext())
                    {
                        taxDocumentComponentLine = taxDocumentComponentLineEnumerator.current();
                        if (taxDocumentComponentLine.metaData().taxComponent() == "CGST")
                        {
                            CGSTAmt = taxDocumentComponentLine.getMeasure("Tax Amount").value().value();
                            CGSTValue = taxDocumentComponentLine.getMeasure("Rate").value().value() * 100;
                        }
                        else if (taxDocumentComponentLine.metaData().taxComponent() == "SGST")
                        {

                            SGSTAmt = taxDocumentComponentLine.getMeasure("Tax Amount").value().value();
                            SGSTValue = taxDocumentComponentLine.getMeasure("Rate").value().value() * 100;
                        }
                        else if (taxDocumentComponentLine.metaData().taxComponent() == "IGST")
                        {
                            IGSTAmt = taxDocumentComponentLine.getMeasure("Tax Amount").value().value();
                            IGSTValue = taxDocumentComponentLine.getMeasure("Rate").value().value() * 100;
                        }
                    }
                }

            }
          
        }
        TaxValue = IGSTValue +  CGSTValue +  SGSTValue;
        TaxAmt =  IGSTAmt +  CGSTAmt + SGSTAmt;
    }


IF you are using TaxGroup and TaxItemGroup::

private TaxValue getTaxPercent(TaxGroup _taxGroup, TaxItemGroup _taxItemGroup)
{
    TaxGroupData    taxGroupData ;
    TaxOnItem       taxOnItem;
    TaxData         taxData;

    select firstonly TaxCode from taxGroupData
        index hint TaxGroupIdx
            where taxGroupData.TaxGroup == _taxGroup
            join taxOnItem
            where taxOnItem.TaxItemGroup == _taxItemGroup &&
                    taxOnItem.TaxCode == taxGroupData.TaxCode;

    select firstonly TaxValue from taxData where taxData.TaxCode == taxGroupData.TaxCode;
    return taxData.TaxValue;

}

Tax::calcTaxAmount(purchLine.TaxGroup, purchLine.TaxItemGroup, Systemdateget(), purchLine.CurrencyCode, purchLine.LineAmount, TaxModuleType::Purch);

After Invoice::
    Code First:
    line.CGSTRate = abs(this.TaxRate(_jour,'CGST', transLine));
    line.SGSTRate = abs(this.TaxRate(_jour,'SGST', transLine));
    line.IGSTRate = abs(this.TaxRate(_jour,'IGST', transLine));

    line.CGST = abs(this.TaxAmount(_jour,'CGST', transLine));
    line.SGST = abs(this.TaxAmount(_jour,'SGST', transLine));
    line.IGST = abs(this.TaxAmount(_jour,'IGST', transLine));
    
        protected Real TaxAmount(CustInvoiceJour  invoiceJour, str    _component, CustInvoiceTrans  invoiceTrans)
    {
        TaxTrans   taxTrans;

        select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxTrans
            where taxTrans.Voucher == invoiceJour.LedgerVoucher
            && taxTrans.TaxCode == _component
            && taxTrans.TransDate == invoiceJour.InvoiceDate
            && taxTrans.InventTransId == invoiceTrans.InventTransId;


        return abs(taxtrans.SourceRegulateAmountCur);
    }

    protected Real TaxRate(CustInvoiceJour  invoiceJour, str    _component, CustInvoiceTrans  invoiceTrans)
    {
        TaxTrans   taxTrans;

        select taxTrans where taxTrans.InventTransId == invoiceTrans.InventTransId
            && taxTrans.Voucher == invoiceJour.LedgerVoucher
            && taxTrans.TaxCode == _component;

        return abs(taxTrans.TaxValue);
    }    
    Code Second:
         protected Real TaxAmount(InventTransferJourLine           _inventTransferJournLine,
                             str                              _component,
                             Amount                           _netAmount)
    {
        TaxTrans        taxtrans, taxtransvalue;

        select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxtrans
            where taxtrans.InventTransId == _inventTransferJournLine.InventTransID
                && taxtrans.Voucher == _inventTransferJournLine.VoucherId
                && taxtrans.TaxCode == _component;

        select taxtransvalue where taxtransvalue.inventtransid == _inventTransferJournLine.InventTransID
            && taxtransvalue.Voucher == _inventTransferJournLine.VoucherId
            && taxtransvalue.TaxCode == _component;

        return abs(taxtrans.SourceRegulateAmountCur);
    }

    protected Real TaxRate(InventTransferJourLine           _inventTransferJournLine,
                           str                              _component,
                           Amount                           _netAmount)
    {
        TaxTrans        taxtrans, taxtransvalue;

        select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxtrans 
            where taxtrans.InventTransId == _inventTransferJournLine.InventTransID
                && taxtrans.Voucher == _inventTransferJournLine.VoucherId
                && taxtrans.TaxCode == _component;

        select taxtransvalue where taxtransvalue.inventtransid == _inventTransferJournLine.InventTransID
            && taxtransvalue.Voucher == _inventTransferJournLine.VoucherId
            && taxtransvalue.TaxCode == _component;

        return abs(taxtransvalue.TaxValue);
    }
    Code Third:
                 //Tax calculations starts
        taxBaseAmount   = 0;
        taxAmount       = 0;

        while select taxTrans
            where taxTrans.SourceTableId    == tableNum(VendInvoiceTrans) &&
                taxTrans.SourceRecId        == vendInvoiceTrans.RecId &&
                taxTrans.Voucher            == vendInvoiceJour.LedgerVoucher &&
                taxTrans.TransDate          == vendInvoiceJour.InvoiceDate &&
                taxTrans.InventTransId      == VendInvoiceTrans.InventTransId//purchLine.InventTransId
        {
            //taxBaseAmount                   = taxTrans.SourceBaseAmountCur * Tax::changeDisplaySign(taxTrans.TaxDirection);
            taxAmount                       += taxTrans.SourceRegulateAmountCur * Tax::changeDisplaySign(taxTrans.TaxDirection);
            rptTmp.TaxPercentage_Invoice    = taxTrans.TaxValue;
            rptTmp.TaxCode_Invoice          = taxTrans.TaxCode;
        }
        rptTmp.TaxBaseAmount =   VendInvoiceTrans.LineAmount;//taxBaseAmount;
        rptTmp.TaxAmount =       taxAmount;
        rptTmp.TotalAmount      = rptTmp.TaxBaseAmount + rptTmp.taxAmount;
        //Tax calculations ends
    Before Invoice::
    this.taxData(PurchReqLine, PurchReqTable);
    Code First:
    public void taxData(PurchReqLine       _line, PurchReqTable   _head)
    {
        TmpTaxDocument                      tmpTax;
        PurchCalcTax                        PurchCalcTax;
        PurchReqTotals                      purchreqtotal;
        ITaxableDocument                    taxableDocument;
        ITaxDocumentComponentLineEnumerator lineEnumerator;
        ITaxDocumentComponentLine           componentLine;
        TaxComponent_IN                     taxComponent;
        ITaxDocument                        taxDocumentObject;
        ITaxDocumentLine                    taxDocumentLine;
        TaxAmount                           taxValue,taxAmount;

        purchreqtotal = PurchReqTotals::construct(_head, PurchUpdate::All);
        taxableDocument = TaxableDocumentObject::construct(purchreqtotal.parmTaxableDocumentDescriptor());
        taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);
        taxDocumentLine = taxDocumentObject.findLineBySource(_line.TableId,_line.RecId);

        if(taxDocumentLine)
        {
            lineEnumerator = taxDocumentLine.componentLines();
            while(lineEnumerator.moveNext())
            {
                componentLine = lineEnumerator.current();
                if(taxComponent)
                {
                    taxComponent = taxComponent + "/" + componentLine.metaData().taxComponent();
                }
                else
                {
                    taxComponent = componentLine.metaData().taxComponent();
                }

                taxValue += componentLine.getMeasure("Rate").value().value() * 100;
                taxAmount += componentLine.getMeasure("Tax Amount").value().value();
            }
            S3_PurchTable_Tmp.TaxCode = taxComponent;
            S3_PurchTable_Tmp.TaxValue = taxValue;
            S3_PurchTable_Tmp.TaxAmount = taxAmount;
        }
    }
    
    Code Second:
    public void taxData(PurchReqLine       _line, PurchReqTable   _head)
    {
        TmpTaxDocument                      tmpTax;
        PurchCalcTax                        PurchCalcTax;
        PurchReqTotals                      purchreqtotal;
        ITaxableDocument                    taxableDocument;
        ITaxDocumentComponentLineEnumerator lineEnumerator;
        ITaxDocumentComponentLine           componentLine;
        ITaxDocument                        taxDocumentObject;
        ITaxDocumentLine                    taxDocumentLine;
        real                                SGSTAmt,CGSTAmt,IGSTAmt;
        TaxAmount                           SGST, CGST, IGST;
        ITaxDocumentMeasure                 taxMeasure;
        ITaxDocumentMeasureEnumerator       taxMeasureEnumerator;
        ITaxDocumentMeasureValue            partyTaxMeasureValue;
        int i;

        purchreqtotal = PurchReqTotals::construct(_head, PurchUpdate::All);
        taxableDocument = TaxableDocumentObject::construct(purchreqtotal.parmTaxableDocumentDescriptor());
        taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);
        

        if (taxDocumentObject)
        {
            // Calculation of Tax amount for Tax type GST and Tax component SGST
            lineEnumerator = taxDocumentObject.componentLines('GST','SGST');
            while (lineEnumerator.moveNext())
            {
                taxMeasureEnumerator = lineEnumerator.current().measures();
                while (taxMeasureEnumerator.moveNext())
                {
                    i++;
                    if (i == 3)
                    {
                        componentLine = lineEnumerator.current();
                        partyTaxMeasureValue = taxMeasureEnumerator.current().value();
                        S3_PurchTable_Tmp.SGSTAmt = partyTaxMeasureValue.amountTransactionCurrency();
                        S3_PurchTable_Tmp.SGSTValue = componentLine.getMeasure("Rate").value().value()*100;
                        i=0;
                        break;
                    }
                }
            }

            // Calculation of Tax amount for Tax type GST and Tax component CGST
            lineEnumerator = taxDocumentObject.componentLines('GST','CGST');
            while (lineEnumerator.moveNext())
            {
                taxMeasureEnumerator = lineEnumerator.current().measures();
                while (taxMeasureEnumerator.moveNext())
                {
                    i++;
                    if (i == 3)
                    {
                        componentLine = lineEnumerator.current();
                        partyTaxMeasureValue = taxMeasureEnumerator.current().value();
                        S3_PurchTable_Tmp.CGSTAmt = partyTaxMeasureValue.amountTransactionCurrency();
                        S3_PurchTable_Tmp.CGSTValue = componentLine.getMeasure("Rate").value().value()*100;
                        i=0;
                        break;
                    }
                }
            }

            // Calculation of Tax amount for Tax type GST and Tax component IGST
            lineEnumerator = taxDocumentObject.componentLines('GST','IGST');
            while (lineEnumerator.moveNext())
            {
                taxMeasureEnumerator = lineEnumerator.current().measures();
                while (taxMeasureEnumerator.moveNext())
                {
                    i++;
                    if (i == 3)
                    {
                        componentLine = lineEnumerator.current();
                        partyTaxMeasureValue = taxMeasureEnumerator.current().value();
                        S3_PurchTable_Tmp.IGSTAmt = partyTaxMeasureValue.amountTransactionCurrency();
                        S3_PurchTable_Tmp.IGSTValue    = componentLine.getMeasure("Rate").value().value()*100;
                        i=0;
                        break;
                    }
                }
            }
        }
        S3_PurchTable_Tmp.TaxAmount = S3_PurchTable_Tmp.CGSTAmt + S3_PurchTable_Tmp.SGSTAmt + S3_PurchTable_Tmp.IGSTAmt;
        S3_PurchTable_Tmp.TaxValue  = S3_PurchTable_Tmp.CGSTValue + S3_PurchTable_Tmp.SGSTValue + S3_PurchTable_Tmp.IGSTValue;

    }

    Code Third:
    public void taxData(PurchReqLine       _line, PurchReqTable   _head)
    {
        ITaxDocument                        taxDocument;
        ITaxDocumentLine                    taxDocumentLine;
        ITaxDocumentComponentLineEnumerator componentLineEnumerator,totalcomponentLineEnumerator;
        ITaxDocumentComponentLine           componentLineObject;
        ITaxDocumentMeasureEnumerator       measureEnumerator;
        TaxAmount                           taxAmount,taxValue;
        TaxComponent_IN                     taxComponent;
        
        taxDocument     = TaxBusinessService::getTaxDocumentBySource(_head.TableId, _head.RecId);
        taxDocumentLine = taxDocument.findLineBySource(_line.TableId,_line.RecId);
        componentLineEnumerator = taxDocumentLine.componentLines();

        while(componentLineEnumerator.moveNext())
        {
            componentLineObject = componentLineEnumerator.current();
            if(taxComponent)
            {
                taxComponent = taxComponent + "/" + componentLineObject.metaData().taxComponent();
            }
            else
            {
                taxComponent = componentLineObject.metaData().taxComponent();
            }
            
            taxValue += componentLineObject.getMeasure("Rate").value().value() * 100;
            taxAmount += componentLineObject.getMeasure("Tax Amount").value().value();
        }
        S3_PurchTable_Tmp.TaxCode = taxComponent;
        S3_PurchTable_Tmp.TaxValue = taxValue;
        S3_PurchTable_Tmp.TaxAmount = taxAmount;  
        
    }

Thursday, July 29, 2021

Simple List Form With Multi Filters

 Filter Form Look:


Modified Method:

        public boolean modified()

        {

            boolean ret;

            ret = super();

            PurchTable_DS.executeQuery();

            return ret;

        }

Lookup Method:

        public void lookup()

        {

            Query   query = new Query();

            super();

            SysTableLookup  SysTableLookup = SysTableLookup::newParameters(tableNum(TableName),this);

            QueryBuildDataSource qbds = query.addDataSource(tableNum(TableName));

            SysTableLookup.addLookupfield(fieldNum(TableName,Field1));

            SysTableLookup.addLookupfield(fieldNum(TableName,Field2));

            sysTableLookup.parmQuery(query);

            sysTableLookup.performFormLookup();

        }

Execute Query Method:

        public void executeQuery()

        {

            PurchTable_DS.query().dataSourceName('PurchTable').clearRanges();

            PurchTable_DS.init();

            if(VendAccount.valueStr())

            {

                str   account = VendAccount.valueStr();

                if(account != '0')

                    this.query().dataSourceTable(tableNum(PurchTable)).addRange(fieldNum(PurchTable, OrderAccount)).value(account);

            }

            if(PurchType.valueStr())

            {

                this.query().dataSourceTable(tableNum(PurchTable)).addRange(fieldNum(PurchTable, PurchStatus)).value(PurchType.valueStr());

            }

            if(InventSiteId.valueStr())

            {

                str   site = InventSiteId.valueStr();

                this.query().dataSourceTable(tableNum(PurchTable)).addRange(fieldNum(PurchTable,InventSiteId)).value(site);

            }

            if (monthfilter.valueStr())

            {

                TransDate               lastDate = endMth(monthfilter.dateValue());

                TransDate               startDate = dateStartMth(monthfilter.dateValue());

                this.query().dataSourceTable(tablenum(PurchTable)).addRange(fieldnum(PurchTable, DeliveryDate)).value(sysQuery::range(startDate, lastDate));

            }

            

            if (!monthfilter.valueStr())

            {

                TransDate               lastDate ;

                TransDate               startDate;

                if(dayOfMth(today()) <16)

                {

                    lastDate = mkDate(15,mthOfYr(today()),Year(today()));

                    startDate = mkDate(16,mthOfYr(today())-1,Year(today()));

                }

                if(dayOfMth(today()) >15)

                {

                    lastDate = mkDate(15,mthOfYr(today())+1,Year(today()));

                    startDate = mkDate(16,mthOfYr(today()),Year(today()));

                }

                this.query().dataSourceTable(tablenum(PurchTable)).addRange(fieldnum(PurchTable, DeliveryDate)).value(sysQuery::range(startDate, lastDate));

            }        this.query().dataSourceTable(tableNum(PurchTable)).addSortField(fieldNum(PurchTable,DeliveryDate),SortOrder::Descending);   

            super();

        }

/// Enjoy 👍

Wednesday, July 28, 2021

Lookup On Form Extension using Event Handler

Check the Event handler Code,

    [FormControlEventHandler(formControlStr(BankParameters, JournalName_VendPaymJourName), FormControlEventType::Lookup)]

    public static void JournalName_VendPaymJourName_OnLookup(FormControl sender, FormControlEventArgs e)

    {

        Query                   query = new Query();

        QueryBuildDataSource    queryBuildDataSource;

        QueryBuildRange         queryBuildRange;

        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(LedgerJournalName), sender);

        sysTableLookup.addLookupField(fieldNum(LedgerJournalName, JournalName));

        sysTableLookup.addLookupField(fieldNum(LedgerJournalName, Name));

        queryBuildDataSource = query.addDataSource(tableNum(LedgerJournalName));

        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();

    }

Enjoy .👍

Tuesday, June 8, 2021

Some Code Example For SSRS Report Data for Transfer Order:

Check Code,

If we are going to find tax data for the transfer order then I think you have RecID of particular Invoiced Transfer Order lets move to the data and some X++ code to find the data in D365 F and O

HSN Code

HSN = HSNCodeTable_IN::find(this.GetHSNCode(inventTransferLine));

    RefRecId GetHSNCode(InventTransferLine inventTransferLine)
    {
        TransTaxInformation                             taxInfo;
        TransTaxInformationRelationView       taxRelation;
              
        select firstonly1 taxRelation
           where taxRelation.TransactionRefRecId    == inventTransferLine.RecId
               && taxRelation.TransactionRefTableId == tablenum(InventTransferLine)
           join taxInfo
            where taxInfo.RecId == taxRelation.TransTaxInformationRefRecId;

        return taxInfo.HSNCodeTable;

    }

ServiceAccountingCode

SAC = ServiceAccountingCodeTable_IN::find(this.GetServiceAccountingCode(inventTransferLine));

    RefRecId GetServiceAccountingCode(InventTransferLine inventTransferLine)
    {
        TransTaxInformation                         taxInfo;
        TransTaxInformationRelationView   taxRelation;

        select firstonly1 taxRelation
            where taxRelation.TransactionRefRecId    == inventTransferLine.RecId
            && taxRelation.TransactionRefTableId == tablenum(InventTransferLine)
           join taxInfo
            where taxInfo.RecId == taxRelation.TransTaxInformationRefRecId;

        return taxInfo.ServiceAccountingCodeTable;

    }

NetAmount

InventTransferJourLine_IN::findByInventTransferJourLineRecId(inventTransferJournLine.RecId).AssessableValue;

Tax Rate

line.CGSTRate = abs(this.TaxRate(inventTransferJournLine,'CGST', line.NetAmount));
line.SGSTRate = abs(this.TaxRate(inventTransferJournLine,'SGST', line.NetAmount));                        line.IGSTRate = abs(this.TaxRate(inventTransferJournLine,'IGST', line.NetAmount));

    protected Real TaxRate(InventTransferJourLine           _inventTransferJournLine,
                           str                              _component,
                           Amount                           _netAmount)
    {
        TaxTrans        taxtrans, taxtransvalue;

        select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxtrans 
            where taxtrans.InventTransId == _inventTransferJournLine.InventTransID
                && taxtrans.Voucher == _inventTransferJournLine.VoucherId
                && taxtrans.TaxCode == _component;

        select taxtransvalue where taxtransvalue.inventtransid == _inventTransferJournLine.InventTransID
            && taxtransvalue.Voucher == _inventTransferJournLine.VoucherId
            && taxtransvalue.TaxCode == _component;

        return abs(taxtransvalue.TaxValue);
 }

Tax Amount

line.CGST = abs(this.TaxAmount(inventTransferJournLine,'CGST', line.NetAmount));
line.SGST = abs(this.TaxAmount(inventTransferJournLine,'SGST', line.NetAmount));
line.IGST = abs(this.TaxAmount(inventTransferJournLine,'IGST', line.NetAmount));

    protected Real TaxAmount(InventTransferJourLine           _inventTransferJournLine,
                             str                              _component,
                             Amount                           _netAmount)
    {
        TaxTrans        taxtrans, taxtransvalue;

        select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxtrans
            where taxtrans.InventTransId == _inventTransferJournLine.InventTransID
                && taxtrans.Voucher == _inventTransferJournLine.VoucherId
                && taxtrans.TaxCode == _component;

        select taxtransvalue where taxtransvalue.inventtransid == _inventTransferJournLine.InventTransID
            && taxtransvalue.Voucher == _inventTransferJournLine.VoucherId
            && taxtransvalue.TaxCode == _component;

        return abs(taxtrans.SourceRegulateAmountCur);
    }

Amount  taxAmount = line.CGST + line.SGST + line.IGST;
line.UnitPrice      = inventTransferJournLine.UnitPrice_IN - (taxAmount / line.Qty);
line.Total          = inventTransferJournLine.QtyShipped * line.UnitPrice;
line.GrossAmount = line.TaxableAmount + taxAmount;
Amount totalAmount += line.GrossAmount;

Now move to Transfer Order Header Details,
Company Related Details:

Address:
LogisticsPostalAddress          fromWhAddress;

select firstonly fromWhAddress where fromWhAddress.RecId == _jour.FromPostalAddress;
header.CompanyAddress    = 'Text' +' '+ fromWhAddress.Street + ',' 
                                 + LogisticsAddressCity::find(fromWhAddress.City).Description + ','                                                         + LogisticsAddressDistrict::findRecId(fromWhAddress.District).Name + ',' 
                                 + LogisticsAddressState::find(fromWhAddress.CountryRegionId, fromWhAddress.State).Name + ',' 
+ LogisticsAddressCountryRegion::find(fromWhAddress.CountryRegionId).displayName() + '-' 
+ fromWhAddress.ZipCode + '.';

GSTIN:

header.CompanyGSTIN     = TaxRegistrationNumbers_IN::find(TaxInformation_IN::findDefaultbyLocation(fromWhAddress.Location).GSTIN).RegistrationNumber;

Transaction ID Or Transaction Date:
ITaxDocument                    taxDocumentObject;
TaxDocumentExtension_IN         taxDocumentExtension;

taxDocumentObject       = TaxBusinessService::getTaxDocumentBySource(_jour.TableId, _jour.RecId);
taxDocumentExtension    = taxDocumentExtension_in::findByTaxDocument(taxDocumentObject.getGUID());

header.InvoiceNumber    = taxDocumentExtension.TaxTransactionId;
header.InvoiceDate      = taxDocumentExtension.TaxTransactionDate;

Customer Related Details:

Address:
LogisticsPostalAddress          ToWhAddress;

select firstonly ToWhAddress where fromWhAddress.RecId == _jour.ToPostalAddress;
header.CompanyAddress    = 'Text' +' '+ ToWhAddress.Street + ',' 
                                 + LogisticsAddressCity::find(ToWhAddress.City).Description + ','                                                         + LogisticsAddressDistrict::findRecId(ToWhAddress.District).Name + ',' 
                                 + LogisticsAddressState::find(ToWhAddress.CountryRegionId, ToWhAddress.State).Name + ',' 
+ LogisticsAddressCountryRegion::find(ToWhAddress.CountryRegionId).displayName() + '-' 
+ ToWhAddress.ZipCode + '.';

GSTIN:

header.CompanyGSTIN     = TaxRegistrationNumbers_IN::find(TaxInformation_IN::findDefaultbyLocation(ToWhAddress.Location).GSTIN).RegistrationNumber;

State Code:

StateCode  = subStr(header.GSTIN, 1, 2);

Enjoy 👍

















Workflow Approver Name For PurchRequsition Order

 For First Approver, this.workflowApprover(purchReqTable.RecId);     public void workflowApprover (RecId _recId)  // Requsation Table RecId ...