All COC assignments (Extensions)

 [ExtensionOf(formDataFieldStr(SalesTable,SalesLine,SalesQty))]

final class BAS_SalesLineModified_Extension

{

        // public void modified()

        //{

        //    next modified();

        //    SalesLine salesLineSelectedRecord;

        //    FormDataSource ds;

        //    FormDataObject df = any2Object(this) as FormDataObject;


        //    ds=df.datasource();

        //    salesLineSelectedRecord = ds.cursor();


        //    InventTable  inventTable;


        //    select BAS_MaxSales,BAS_MinSales from inventTable

        //    where InventTable.ItemId == salesLineSelectedRecord.ItemId;


        // //   salesLineSelectedRecord.SalesQty = inventTable.BAS_MinSales;

        //    if(salesLineSelectedRecord.SalesQty < inventTable.BAS_MinSales || salesLineSelectedRecord.SalesQty > inventTable.BAS_MaxSales)

        //    {

        //        checkFailed(strFmt("Sales quantity must be in b/n the range"));

        //    }


        //}


}

[ExtensionOf(FormDataSourceStr(SalesTable,SalesLine))]


final class BAS_SalesLine_Extension

{

//    public void initValue()

//    {

//    next initValue();


//    FormDataSource formDS = this;


//    SalesLine sale = this.cursor();


//    sale.ItemId = "0009";


//    sale.SalesQty = 8;


//    FormControl formc = this.formRun().design().controlName(formControlStr(SalesLine, ItemName));


//    if(sale.ItemId == "0001")

//    {

//        formc.visible(false);

//    }

//    else

//    {

//        formc.visible(true);

//    }

//    }






//  //  //public void create(boolean append)

//  //  //{

//  //  //    next create();


//  //  //    FormDataSource df = this;


//  //  //    SalesLine sl = this.cursor();


//  //  //   // sl.LinePercent = 70.98;


//  //  //    sl.LineDisc = 7.5;


//  //  //}


//  //  //public boolean  validateWrite()

//  //  //{


//  //  //    boolean  ok = next validatewrite();


//  //  //    Info("Validation Started");


//  //  //    FormDataSource fm = this;


//  //  //    SalesLine sl = this.cursor();


//  //  //    if(sl.LinePercent > 50.00)

//  //  //    {

//  //  //        warning("Greater than 50");

//  //  //        return ok;

//  //  //    }

//  //  //    return ok;



//  //  //}

//  //  //public boolean  validateWrite()

//  //  //{


//  //  //boolean ret;

//  //  //ret = next validateWrite();


//  //  //FormDataSource formDS = this;


//  //  //SalesLine salesLine = this.cursor();


//  //  //if(ret)

//  //  //{

//  //  //    if(!salesLine.SalesDeliverNow)

//  //  //    {

//  //  //        throw Error ("The field DeliverNow cannot be null");

//  //  //    }

//  //  //}

//  //  //return ret;

//  //  //}


//  ////public boolean  validateWrite()

//  //// {


//  ////     boolean ret;


//  ////     ret = next validateWrite();


//  ////     FormDataSource formDS = this;


//  ////     SalesLine salesLine = this.cursor();


//  ////     if(ret)

//  ////     {

//  ////         if(!salesLine.LinePercent)

//  ////         {

//  ////             throw Error ("The field Linepercent cannot be null");

//  ////         }

//  ////      }

//  ////      return ret;

//  ////  }


//  //  //public boolean validate()

//  //  //{

//  //  //    boolean ret;


//  //  //    ret = next Validate();



//  //  //    FormDataSource formDS = this;


//  //  //    SalesTable salesLine = this.cursor();


//  //  //    if(ret)

//  //  //    {

//  //  //        if(!salesLine.BAS_Phone)

//  //  //        {

//  //  //            throw Error ("The field Linepercent cannot be null");

//  //  //        }

//  //  //    }

//  //  //    return ret;

//}

   


}

[ExtensionOf(tableStr(SalesLine))]

 final class BAS_SalesLineTable_Extension    

 {          

            //public void initValue(SalesType _salesType)       

            //{             

            //    Info(strFmt("Working on SalesLine"));

            //    next initValue();

            //    this.CostPrice = 12.12;

            //    this.LineDisc = 5.5;

            //    this.LinePercent = 50.25;

            //    info(strFmt("The field has been updated"));     

            //}


    //    public boolean  validateWrite(boolean _skipCreditLimitCheck)

    //{

    //    boolean ok = next validateWrite();


    //    Info("ValidateWrite Condition");


    //    if(this.LinePercent<50.00)

    //    {

    //        warning("Percentage is less than 50");

    //        return ok;

    //    }

    //    return ok;

    //}


}

[ExtensionOf(tableStr(SalesTable))]


final class BAS_SalesTable_Extension

{

   //public void initValue(SalesType _salesType)

   // {

   //     Info(strFmt("Working on Sales Table"));


   //     next initValue();


   //     this.BAS_Madule = "AccountReceivable";


   //    info(strFmt("The field has been updated"));

   // }


    ////public boolean validateWrite()

    ////{

    ////    boolean ret;


    ////    ret = next validateWrite();


    ////    if(this.LineDisc != "")


    ////        warning(" Please fill the address value");


    ////    return ret;

    ////}


}

/// <summary>

/// This class is an extension of Sales table list page

/// </summary>

[ExtensionOf(formDataSourceStr(SalesTableListPage,SalesTable))]

final class BASPOcreationButtonControl_Extension

{

    /// <summary>

    ///Checks Salestatus in sales table list page  form if Status is Invoiced 

    ///Disable the Create purchase order buttom

    /// </summary>

    /// <returns>active()</returns>

     public int active()

     {

        int ret;

        ret = next active();

        SalesTable salesTable = this.cursor();


        FormControl poCreate = this.formRun().design().controlName(formControlStr(SalesTableListPage,BAS_POCreation));


        if(salesTable.SalesStatus == SalesStatus::Invoiced)

        {

            poCreate.enabled(false);

        }

        else

        {

            poCreate.enabled(true);

        }

      

        return ret;

     }


}


/// <summary>

/// This class is an extension of Purchtable list page

/// </summary>

[ExtensionOf(formDataSourceStr(PurchTable,PurchTable))]

final class BASPurchTableFormButton_Extension

{

    /// <summary>

    ///Checks Purchstatus in purch table table list page  form if Status is Invoiced

    ///Disable the Receive items buttom

    /// </summary>

    /// <returns>active()</returns>

    public int active()

    {

        int ret;

       

        PurchTable purchTable    = this.cursor();


        FormControl itemReceive  = this.formRun().design().controlName(formControlStr(PurchTable,BAS_ItemReceive));


        if(purchTable.PurchStatus == PurchStatus::Received || purchTable.PurchStatus == PurchStatus::Invoiced)

        {

            itemReceive.enabled(false);

        }

        else

        {

            itemReceive.enabled(true);

        }

        ret = next active();

        return ret;

    }


}


[ExtensionOf(formDataFieldStr(PurchTable, PurchLine, ItemId))]

final class BASSupplement_Extension

{

    public void modified()

    {

        //FormDataObject formDataObject = any2Object(this) as FormDataObject;

        //FormDataSource formDataSource = formDataObject.datasource();

        //PurchLine purchLine;

        //SuppItemTable supplementItem;

        //int item;


        next modified();


        ////Getting form records

        //purchLine = formDataSource.cursor();

        ////Fetching the Supplementery items for a particular item

        //while select * from supplementItem

        //    where supplementItem.ItemRelation == purchLine.ItemId

        //{

        //    item++;

        //    //Inserting Supplement items to the PO

        //    PurchPurchaseOrderLineV2Entity    purchLineEntity;

        //    purchLineEntity.initValue();

        //    purchLineEntity.PurchaseOrderNumber = purchLine.PurchId;

        //    purchLineEntity.ItemNumber = supplementItem.SuppItemId;

        //    purchLineEntity.insert();

        //    purchLineEntity.clear();

        //}


        //if(item > 0)

        //{

        //    info("Supplementery items have been updated");

        //}


        //formDataSource.research();

        //formDataSource.refresh();

    }


}


[ExtensionOf(FormDataSourcestr(PurchTable, PurchLine))]

final class BASSupplimenteryItemInsert_Extension

{

    public boolean validateWrite()

    {

        boolean ret = next validateWrite();

        FormDataSource formDataSource = this;

        PurchLine purchLine = formDataSource.cursor();

        SuppItemTable supplementItem;


        select count(RecId) from supplementItem

            where supplementItem.ItemRelation == purchLine.ItemId;

        if(supplementItem.RecId != 0)

        {

            DialogButton  dialogButton;

            //Initial focus is on the No button.

            dialogButton = Box::yesNo('Do you want to add supplementery items',dialogButton::Yes, "Proceed or Dont");

            if(dialogButton == DialogButton::Yes)

            {

                PurchLine supplementLine;


                while select SuppItemId from supplementItem

                    where supplementItem.ItemRelation == purchLine.ItemId

                {

                    ttsbegin;

                    PurchTable purchTable = PurchTable::find(purchLine.PurchId);

                    supplementLine.initFromPurchTable(purchTable);

                    supplementLine.PurchId = purchLine.PurchId;

                    supplementLine.ItemId = supplementItem.SuppItemId;

                    // supplementLine.skipDataSourceValidateField(fieldNum(PurchLine,ItemId),true);

                    supplementLine.insert();

                    //supplementLine.createLine(true, true, true, true, true, false);

                    supplementLine.clear();

                    ttscommit;

                }


                //formDataSource.reread();

                formDataSource.refresh();

                // formDataSource.research();

                info("Supplementery items have been added");

            }

            else if (dialogButton == DialogButton::No)

            {

                ret = checkFailed("Supplementery items must be added");

            }

        }

        

        return ret;

    }


    public boolean validateDelete()

    {

        boolean ret;

        ret = next validateDelete();

        FormDataSource formDataSource = this;

        PurchLine selectedPurchLine = formDataSource.cursor();

        purchLine purchLine,purch;

        SuppItemTable supplementItem,supplyItem;


        //Master item validation

        //here ItemRelation field is master item and SuppitemId is Supplement Item

        while select ItemRelation,SuppItemId from supplementItem

            where supplementItem.ItemRelation == selectedPurchLine.ItemId

        {

            delete_from purchLine where purchLine.ItemId == supplementItem.SuppItemId

                && purchLine.PurchId == selectedPurchLine.PurchId;


            //ret = info(strFmt("Master item %1",selectedPurchLine.ItemId));

          

        }


        //Supplement item validation

        while select ItemRelation,SuppItemId from supplementItem

            where supplementItem.SuppItemId == selectedPurchLine.ItemId

        {

            while select ItemId from purchLine

                where purchLine.PurchId == selectedPurchLine.PurchId

                && purchLine.ItemId == supplementItem.ItemRelation

            {

                if(supplementItem.ItemRelation && purchLine.ItemId)

                {

                    ret = checkFailed(strFmt("cannot delete Item %1 has master item %2",selectedPurchLine.ItemId,purchLine.ItemId));

                }

            }

        }

      

        formDataSource.research();

        return ret;

    }


}

Comments

Popular posts from this blog

How to Create a wizard in x++ d365

how to post trade agreement journals automatically using x++ code

X++ code to CREATE AND POST A TRADE AGREEMENT IN MICROSOFT DYNAMICS 365 in D365 F & O