import com.adaequare.mapro.model.data.*;
import com.adaequare.mapro.model.detail.*;
import com.adaequare.usermgmt.model.*;
import java.util.InputMismatchException;
import java.util.List;
import com.adaequare.library.*;
import com.adaequare.mapro.vo.common.*;
import com.adaequare.common.utils.SpringBeanFinder;
import org.json.JSONArray;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import groovy.json.StreamingJsonBuilder;
import org.apache.commons.io.*;
import java.io.InputStream;
import java.util.Date;
import java.util.UUID;
import java.math.*;
import java.util.Date;
import com.adaequare.mapro.model.detail.AssetDetail;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
import java.sql.Timestamp;
import com.adaequare.mapro.library.AssetDevelopmentLibrary;
import com.adaequare.mapro.model.detail.EntityRecordDetail;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.apache.http.*;
import org.apache.http.util.EntityUtils;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import com.adaequare.mapro.library.HttpCallLibrary;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.ContentType;
import java.sql.Timestamp;
String transactionSubtype = '';
String transactionType = "";
String supplierState = '';
String supplierGstin = '';
String reverseCharge = "";
String dispatcher_phone_number, dispatcher_emailid, dispatch_pincode, dispatch_state, dispatch_city, dispatch_address2, dispatch_address1, dispatchname, dispatchcode, dispatchGstin, organisation_Gstin, ecommerceGstin, gstRate, portCode, goodsServices, supplierPan, supplyType, placeOfSupply, flag_for_supply_covered_undersec7_of_igst_act1, buyerGstin, shipToGstin, preceINVNumber, othRefNumber, receiptAdviceNumber, lotbatchRefNumber, contactRefNumber, externalRefNumber, projectRefNumber, shiptoLegalname, buyerPincode, buyerState, uqc, taxpayerTypeSupplier, supplyCategory, shiptoState;
Double igstamount, cgstamount, sgstamount, totalamount, quantity, dicountBeforegst, grossVal, ratePerQuantity, compensationCessAmount, stateCessAmount, statecessNonAdvolAmount, CessNonAdvolValue;
Date expiryDate, warrantyDate, invoicePeriodStartDate, poDate, invoicePeriodEndDate, receiptAdviceDate,
preceINVDate;
Double tot_Taxable_val = 0;
Double taxableValue = 0;
Double totalTaxableValue = 0;
Double totalIgstAmount = 0;
Double totalCgstAmount = 0;
Double totalSgstAmount = 0;
Double totalStateCessAmount = 0.0;
Double totalGstAndCessAmount = 0.0;
Double totalCessAmount = 0.0;
Double totalGst = 0.0;
Double totalIgstAmt = 0.0;
Double totalCgstAmt = 0.0;
Double totalSgstAmt = 0.0;
Double cessAmount = 0.0;
Double totalStateCessAmt = 0.0;
Double totalCessAmt = 0.0;
Double igstAmt = 0.0;
Double cgstAmt = 0.0;
Double sgstAmt = 0.0;
Double stateCessAmt = 0.0;
Double totalItemvalue = 0;
Double igstamt = 0;
Double sgstamt = 0;
Double cgstamt = 0;
Double invoiceValue = 0.0;
Double roundingOffAmtvalue = 0.0;
Double cessRate = 0.0;
Double igstRate = 0.0;
Double cgstRate = 0.0;
Double sgstRate = 0.0;
int lineItemId = 0;


IAssetData assetData = assetData;

IEntityData invoiceHeaders = Entities.getEntityById(assetData, 'header');
IEntityData Details = Entities.getEntityById(assetData, 'details');
if (invoiceHeaders != null) {
    Iterator < IEntityRecordData > invoiceHeadersRecords = invoiceHeaders.recordIterator();
    while (invoiceHeadersRecords.hasNext()) {
        IEntityRecordData entityRowData1 = invoiceHeadersRecords.next();
        supplyType = Fields.isNull(Fields.getFieldById(entityRowData1, "supplytype")) ? null : Fields.getFieldById(entityRowData1, "supplytype").getValue();
        transactionType = Fields.isNull(Fields.getFieldById(entityRowData1, "transactiontype")) ? null : Fields.getFieldById(entityRowData1, "transactiontype").getValue();
        transactionSubType = Fields.isNull(Fields.getFieldById(entityRowData1, "transactionsubtype")) ? null : Fields.getFieldById(entityRowData1, "transactionsubtype").getValue();
        supplierPan = Fields.isNull(Fields.getFieldById(entityRowData1, "supplierpan")) ? null : Fields.getFieldById(entityRowData1, "supplierpan").getValue();
        reverseCharge = Fields.isNull(Fields.getFieldById(entityRowData1, "reversecharge")) ? null : Fields.getFieldById(entityRowData1, "reversecharge").getValue();
        organisation_Gstin = Fields.isNull(Fields.getFieldById(entityRowData1, "organisationgstinoruin")) ? null : Fields.getFieldById(entityRowData1, "organisationgstinoruin").getValue();
        invoiceValue = Fields.isNull(Fields.getFieldById(entityRowData1, "invoicevalue")) ? 0 : Fields.getFieldById(entityRowData1, "invoicevalue").getValue();
        taxpayerTypeSupplier = Fields.isNull(Fields.getFieldById(entityRowData1, "taxpayertypesupplier")) ? null : Fields.getFieldById(entityRowData1, "taxpayertypesupplier").getValue();
        placeOfSupply = Fields.isNull(Fields.getFieldById(entityRowData1, "placeofsupply")) ? null : Fields.getFieldById(entityRowData1, "placeofsupply").getValue();



        if ("Outward".equals(supplyType) && !("Tax Invoice".equals(transactionType) || "Debit Note for Sales".equals(transactionType) || "Credit Note for Sales".equals(transactionType) || "Delivery Challan".equals(transactionType) || "Bill Of Supply".equals(transactionType) || "Other Document".equals(transactionType))) {
            Assets.addError(assetData, "INV-001 : If supply Type is Outward then 'Transaction Type' should be 'Tax Invoice/ Debit Note for Sales/ Credit Note for Sales/ Delivery Challan/ Bill Of Supply/ Other Document'. ");
        }

        if ("Inward".equals(supplyType) && !("Tax Invoice".equals(transactionType) || "Debit Note for Purchases".equals(transactionType) || "Credit Note for Purchases".equals(transactionType) || "B2C RCM Purchase Invoice".equals(transactionType) || "Bill Of Entry".equals(transactionType) || "Other Document".equals(transactionType))) {
            Assets.addError(assetData, "INV-002 : If supply type is  Inward then 'Transaction Type' should be 'Tax Invoice/ Debit Note for Purchases/ Credit Note for Purchases/ B2C RCM Purchase Invoice/ Bill Of Entry/ Other Document'.");
        }
        if ("Outward".equals(supplyType) && !("Regular".equals(transactionSubType) || "SEZ With Payment".equals(transactionSubType) || "SEZ Without Payment".equals(transactionSubType) || "Export With Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType) || "Deemed Exports".equals(transactionSubType))) {
            Assets.addError(assetData, "INV-003 : If Supply Type is Outward then 'Transaction SubType' should be 'Regular/ SEZ With Payment/ SEZ Without Payment/ Export With Payment/ Export Without Payment/ Deemed Exports. ");
        }
        if ("Inward".equals(supplyType) && !("Regular".equals(transactionSubType) || "Purchase from SEZ".equals(transactionSubType) || "Imports".equals(transactionSubType))) {
            Assets.addError(assetData, "INV-004 : If Supply Type is Inward then 'Transaction SubType' should be 'Regular/ Purchase from SEZ/ Imports ");
        }
        if ("B2C RCM Purchase Invoice".equals(transactionType)) {
            if (supplierPan == null) {
                Assets.addError(assetData, "INV-026 : Supplier PAN' is mandatory in case of 'Transaction Subtype' is 'B2C RCM Purchase Invoice' ");
            }
        }
        if ("B2C RCM Purchase Invoice".equals(transactionType) || "Imports".equalsIgnoreCase(transactionSubtype)) {
            if (!("Yes".equalsIgnoreCase(reverseCharge))) {
                Assets.addError(assetData, "INV-027,INV-028 : Reverse Charge'should be 'Yes' in case of 'Transaction Subtype' is 'B2C RCM Purchase Invoice' or Reverse Charge'should be 'Yes' in case of 'Transaction Subtype' is 'Imports");
            }
        }
        if ("Export With Payment".equalsIgnoreCase(transactionSubType) || "Export Without Payment".equalsIgnoreCase(transactionSubType)) {
            if (!("No".equalsIgnoreCase(reverseCharge))) {
                Assets.addError(assetData, "INV-029 : Reverse Charge'should be 'No' in case of 'Transaction Subtype' is 'Exports With Payment or Export Without Payment'");
            }
        }
        if ("Imports".equalsIgnoreCase(transactionSubType) && (!"Bill Of Entry".equalsIgnoreCase(transactionType))) {

            Assets.addError(assetData, "INV-080: Transaction subtype should be 'Bill of Entry (boe)' for Import of Goods");
        }

        if ("Purchase from SEZ".equalsIgnoreCase(transactionSubType) && (!"Bill Of Entry".equalsIgnoreCase(transactionType))) {

            Assets.addError(assetData, "INV-081: Transaction subtype should be 'Bill of Entry' for Purchase of goods from SEZ");
        }



    }
}

if (Details != null) {
    Iterator < IEntityRecordData > DetailsRecords = Details.recordIterator();
    while (DetailsRecords.hasNext()) {
        IEntityRecordData entityRowData2 = DetailsRecords.next();
        supplierState = Fields.isNull(Fields.getFieldById(entityRowData2, "supplierstate")) ? null : Fields.getFieldById(entityRowData2, "supplierstate").getValue();
        flag_for_supply_covered_undersec7_of_igst_act1 = Fields.isNull(Fields.getFieldById(entityRowData2, "flagforsupplycoveredundersec7ofigstact")) ? null : Fields.getFieldById(entityRowData2, "flagforsupplycoveredundersec7ofigstact").getValue();
        buyerGstin = Fields.isNull(Fields.getFieldById(entityRowData2, "buyergstin")) ? null : Fields.getFieldById(entityRowData2, "buyergstin").getValue();
        shipToGstin = Fields.isNull(Fields.getFieldById(entityRowData2, "shiptogstin")) ? null : Fields.getFieldById(entityRowData2, "shiptogstin").getValue();
        supplierGstin = Fields.isNull(Fields.getFieldById(entityRowData2, "suppliergstin")) ? null : Fields.getFieldById(entityRowData2, "suppliergstin").getValue();
        portCode = Fields.isNull(Fields.getFieldById(entityRowData2, "portcode")) ? null : Fields.getFieldById(entityRowData2, "portcode").getValue();
        ecommerceGstin = Fields.isNull(Fields.getFieldById(entityRowData2, "ecommercegstin1")) ? null : Fields.getFieldById(entityRowData2, "ecommercegstin1").getValue();
        dispatchGstin = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchgstin")) ? null : Fields.getFieldById(entityRowData2, "dispatchgstin").getValue();
        dispatchcode = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchcode")) ? null : Fields.getFieldById(entityRowData2, "dispatchcode").getValue();
        dispatchname = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchname")) ? null : Fields.getFieldById(entityRowData2, "dispatchname").getValue();
        dispatch_address1 = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchaddress1")) ? null : Fields.getFieldById(entityRowData2, "dispatchaddress1").getValue();
        dispatch_address2 = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchaddress2")) ? null : Fields.getFieldById(entityRowData2, "dispatchaddress2").getValue();
        dispatch_city = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchcity")) ? null : Fields.getFieldById(entityRowData2, "dispatchcity").getValue();
        dispatch_state = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchstate")) ? null : Fields.getFieldById(entityRowData2, "dispatchstate").getValue();
        dispatch_pincode = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatchpincode")) ? null : Fields.getFieldById(entityRowData2, "dispatchpincode").getValue();
        dispatcher_emailid = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatcheremailid")) ? null : Fields.getFieldById(entityRowData2, "dispatcheremailid").getValue();
        dispatcher_phone_number = Fields.isNull(Fields.getFieldById(entityRowData2, "dispatcherphonenumber")) ? null : Fields.getFieldById(entityRowData2, "dispatcherphonenumber").getValue();
        preceINVNumber = Fields.isNull(Fields.getFieldById(entityRowData2, "precedinginvoicenumber")) ? null : Fields.getFieldById(entityRowData2, "precedinginvoicenumber").getValue();
        preceINVDate = Fields.isNull(Fields.getFieldById(entityRowData2, "precedinginvoicedate")) ? null : Fields.getFieldById(entityRowData2, "precedinginvoicedate").getValue();
        othRefNumber = Fields.isNull(Fields.getFieldById(entityRowData2, "otherreferencenumber")) ? null : Fields.getFieldById(entityRowData2, "otherreferencenumber").getValue();
        receiptAdviceNumber = Fields.isNull(Fields.getFieldById(entityRowData2, "receiptadvicenumber")) ? null : Fields.getFieldById(entityRowData2, "receiptadvicenumber").getValue();
        receiptAdviceDate = Fields.isNull(Fields.getFieldById(entityRowData2, "receiptadvicedate")) ? null : Fields.getFieldById(entityRowData2, "receiptadvicedate").getValue();
        lotbatchRefNumber = Fields.isNull(Fields.getFieldById(entityRowData2, "lotorbatchreferencenumber")) ? null : Fields.getFieldById(entityRowData2, "lotorbatchreferencenumber").getValue();
        contactRefNumber = Fields.isNull(Fields.getFieldById(entityRowData2, "contractreferencenumber")) ? null : Fields.getFieldById(entityRowData2, "contractreferencenumber").getValue();
        externalRefNumber = Fields.isNull(Fields.getFieldById(entityRowData2, "externalreferencenumber")) ? null : Fields.getFieldById(entityRowData2, "externalreferencenumber").getValue();
        projectRefNumber = Fields.isNull(Fields.getFieldById(entityRowData2, "projectreferencenumber")) ? null : Fields.getFieldById(entityRowData2, "projectreferencenumber").getValue();
        poDate = Fields.isNull(Fields.getFieldById(entityRowData2, "podate")) ? null : Fields.getFieldById(entityRowData2, "podate").getValue();
        invoicePeriodStartDate = Fields.isNull(Fields.getFieldById(entityRowData2, "invoiceperiodstartdate")) ? null : Fields.getFieldById(entityRowData2, "invoiceperiodstartdate").getValue();
        invoicePeriodEndDate = Fields.isNull(Fields.getFieldById(entityRowData2, "invoiceperiodenddate")) ? null : Fields.getFieldById(entityRowData2, "invoiceperiodenddate").getValue();
        shiptoLegalname = Fields.isNull(Fields.getFieldById(entityRowData2, "shiptolegalname")) ? null : Fields.getFieldById(entityRowData2, "shiptolegalname").getValue();
        buyerPincode = Fields.isNull(Fields.getFieldById(entityRowData2, "buyerpincode")) ? null : Fields.getFieldById(entityRowData2, "buyerpincode").getValue();
        buyerState = Fields.isNull(Fields.getFieldById(entityRowData2, "buyerstate")) ? null : Fields.getFieldById(entityRowData2, "buyerstate").getValue();
        roundingOffAmtvalue = Fields.isNull(Fields.getFieldById(entityRowData2, "roundingoffamount")) ? null : Fields.getFieldById(entityRowData2, "roundingoffamount").getValue();
        shiptoState = Fields.isNull(Fields.getFieldById(entityRowData2, "shiptostate")) ? null : Fields.getFieldById(entityRowData2, "shiptostate").getValue();
        totalCessAmount = Fields.isNull(Fields.getFieldById(entityRowData2, "totalcessamount")) ? 0 : Fields.getFieldById(entityRowData2, "totalcessamount").getValue();
        totalTaxableValue = Fields.isNull(Fields.getFieldById(entityRowData2, "totaltaxablevalue")) ? 0 : Fields.getFieldById(entityRowData2, "totaltaxablevalue").getValue();
        totalIgstAmount = Fields.isNull(Fields.getFieldById(entityRowData2, "totaligstamount")) ? null : Fields.getFieldById(entityRowData2, "totaligstamount").getValue();
        totalCgstAmount = Fields.isNull(Fields.getFieldById(entityRowData2, "totalcgstamount")) ? null : Fields.getFieldById(entityRowData2, "totalcgstamount").getValue();
        totalSgstAmount = Fields.isNull(Fields.getFieldById(entityRowData2, "totalsgstorutgstamount")) ? 0 : Fields.getFieldById(entityRowData2, "totalsgstorutgstamount").getValue();
        totalStateCessAmount = Fields.isNull(Fields.getFieldById(entityRowData2, "totalstatecessamount")) ? 0 : Fields.getFieldById(entityRowData2, "totalstatecessamount").getValue();





        if ("Export With Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType)) {
            if (!("URP".equals(buyerGstin) || !"URP".equals(shipToGstin))) {
                Assets.addError(assetData, " INV-022 : If 'Transaction Sub Type ' is 'Export With Payment/Export Without Payment' then 'Buyer GSTIN/Ship to GSTIN' should be URP");
            }
        }
        if ("SEZ Without Payment".equals(transactionSubType) || "SEZ With Payment".equals(transactionSubType) || "Deemed Exports".equals(transactionSubType)) {
            if ((buyerGstin != null) || "URP".equals(buyerGstin)) {
                Assets.addError(assetData, " INV-023 :If 'Transaction Sub Type ' is 'SEZ With Payment/SEZ Without Payment/Deemed Exports' then 'Buyer GSTIN should not be URP and a Valid GSTIN is Required");
            }
        }
        if ("Imports".equals(transactionSubType)) {
            if (!("URP".equals(supplierGstin))) {
                Assets.addError(assetData, "INV-024 :If 'Transaction Sub Type ' is 'Imports' then 'Supplier GSTIN/UIN' should be URP");
            }
        }
        if ("Purchase from SEZ".equals(transactionSubType)) {
            if ((supplierGstin != null) || "URP".equals(supplierGstin)) {
                Assets.addError(assetData, "INV-025 :If 'Transaction Sub Type ' is 'Purchase from SEZ' then 'Supplier GSTIN/UIN' should not be URP and a Valid GSTIN is Required");
            }
        }
        if ("Export With Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType)) {
            if (!("OTH".equalsIgnoreCase(placeOfSupply))) {
                Assets.addError(assetData, "INV-034 : Place of supply' should be OTH in case of  'Exports' ")
            }
        }
        if (!("Export With Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType) || "SEZ With Payment".equals(transactionSubType) || ("SEZ Without Payment".equals(transactionSubType)))) {
            if (!("OTH".equalsIgnoreCase(placeOfSupply))) {
                Assets.addError(assetData, "INV-035 : Place of Supply' should not be 'OTH' in case of 'Transaction Subtype' is not " +
                    "Exports With Payment  or " +
                    "SEZ With Payment  or " +
                    "Export Without Payment  or " +
                    "SEZ Without Payment ");
            }
        }
        if ("Imports".equals(transactionSubType)) {
            if (!("OTH".equals(supplierState))) {
                Assets.addError(assetData, "INV-036 :Supplier State should be OTH in case of Transaction subtype is Imports");
            }
        }
        if ("Imports".equals(transactionSubType)) {
            if (("OTH".equals(supplierState))) {
                Assets.addError(assetData, "INV-037 : Supplier State should not be OTH in case of Transaction Subtype is not" +
                    "Imports ");
            }
        }
        if (buyerGstin != null) {
            if (buyerGstin.substring(0, 2) == '99') {
                Assets.addError(assetData, "INV-038: [Buyer GSTIN] should not begin with '99'");
            }
        }

        if (dispatchGstin != null) {
            if (dispatchGstin.substring(0, 2) == '99') {
                Assets.addError(assetData, "INV-038:[Ship to GSTIN] should not begin with '99'");
            }
            SimpleDateFormat gmtDateFormat = new SimpleDateFormat("dd/MM/yyyy");
            Assets.addWarning(assetData, "converted date ::" + gmtDateFormat);

            String timezoneDate = gmtDateFormat.format(new Date());
            Assets.addWarning(assetData, "timezoneDate  ::" + timezoneDate);

            SimpleDateFormat dateConversion = new SimpleDateFormat("dd/MM/yyyy");
            Assets.addWarning(assetData, "dateConversion date ::" + dateConversion);


            futureDate = dateConversion.parse(timezoneDate)
            Assets.addWarning(assetData, "futureDate date ::" + futureDate);



            Date fd = futureDate;
            Assets.addWarning(assetData, "fd date ::" + fd);

            if (poDate.after(futureDate)) {

                Assets.addError(assetData, "INV-049 : poDate Date cannot be Future Date")

            }
            if (shippingBillDate.after(futureDate)) {

                Assets.addError(assetData, "INV-049 : shippingBillDate Date cannot be Future Date")

            }

            if ("Tax Invoice".equals(transactionType) || "Debit Note for Sales".equals(transactionType) || "Credit Note for Sales".equals(transactionType)) {
                if ((organisation_Gstin).equals(shipToGstin) || (organisation_Gstin).equals(buyerGstin) || (organisation_Gstin).equals(ecommerceGstin)) {
                    Assets.addError(assetData, "INV-050 : If Transaction Type is Tax Invoice/Debit Note for Sales/Credit Note for Sales then Organisation GSTIN/UIN should not be equal to " +
                        "Customer GSTIN / UIN, Ship to GSTIN / E Commerce GSTIN ");
                }
            }
            if ((ecommerceGstin).equals(shipToGstin) || (ecommerceGstin).equals(buyerGstin) || (ecommerceGstin).equals(dispatchGstin)) {
                Assets.addError(assetData, "INV-051 : " +
                    "Customer GSTIN / UIN / Dispatch GSTIN / Ship to GSTIN  should not be equal to E Commerce GSTIN");
            }
            if ((dispatchLegalName != null || dispatch_address1 != null || dispatch_address2 != null || dispatch_city != null || dispatch_state != null || dispatch_pincode != null) && (dispatchLegalName == null || dispatch_address1 == null || dispatch_address2 != null || dispatch_city == null || dispatch_state == null || dispatch_pincode == null)) {

                Assets.addError(assetData, "INV-052: If the  data is present in any one of the fields i.e in [Dispatch Legal Name] or [Dispatch From Add 1] or [Dispatch From Add 2] or [Dispatch From City] or [Dispatch From State] or [Dispatch From Pincode]  then [Dispatch Legal Name] and [Dispatch From Add 1] and [Dispatch From Add 2] and [Dispatch From City] and [Dispatch From State] and [Dispatch From Pincode] are Mandatory");
            }

            if ((shiptoLegalname != null || shiptoTradename != null || shipToGstin != null || shiptoAdd1 != null || shiptoAdd2 != null || shiptoCity != null || shiptoState != null || shiptoPincode != null) && (shiptoLegalname == null || shiptoAdd1 == null || shiptoCity == null || shiptoState == null || shiptoPincode == null)) {
                Assets.addError(assetData, "INV-053: Ship to Legal Name,Ship to Trade Name, Ship to GSTIN,Ship to Address 1 ,Ship to Address 2, Ship to City, Ship to State, Ship to PIN Code  if the  data is present in any one of the mentioned fields then Ship to Legal Name,Ship to Address 1 , Ship to City, Ship to State, Ship to PIN Code are Mandatory");
            }
            if ((preceINVNumber != null || preceINVDate != null || othRefNumber != null) && (preceINVNumber == null || preceINVDate == null)) {
                Assets.addError(assetData, "INV-054: Preceding Invoice Number, Preceding Invoice Date, Other Reference Number If the data is present in any one the mentioned fields then Preceding Invoice Number, Preceding Invoice Date are Mandatory ");
            }

            if ((receiptAdviceNumber != null || receiptAdviceDate != null || lotbatchRefNumber != null || contactRefNumber != null || externalRefNumber != null || projectRefNumber != null || poDate != null || poNumber != null) && (invoicePeriodStartDate == null || invoicePeriodEndDate == null) {

                    Assets.addError(assetData, "INV-055: Receipt Advice Number,  Receipt Advice Date,Lot/Batch Reference Number,Contract Reference Number,External Reference Number,Project Reference Number,PO Number,PO Date if the data is present in any one of the mentioned fields then Invoice Period Start Date ,Invoice Period End Date  is Mandatory");
                }
                if (invoicePeriodStartDate != null || invoicePeriodEndDate != null) && (invoicePeriodStartDate == null || invoicePeriodEndDate == null) 
                {

                    Assets.addError(assetData, "INV-056: Invoice Period Start Date, Invoice Period End Date if data is present in any one of the mentioned fields then Invoice Period Start Date , Invoice Period End Date  are Mandatory");
                }

                if ("B2C RCM Purchase Invoice".equals(transactionType) && !("URP").equals(supplierGSTIN)) 
                {

                    Assets.addError(assetData, "INV-058: Supplier GSTIN' should be 'URP' or'Blank' in case of 'Transaction Subtype' is 'B2C RCM Purchase Invoice'");
                }
                if ("Outward".equals(supplyType) && (orgGstin != null)) {
                    if (orgState != null) {
                        String orgStatecode = stateCodes.get(orgState.toUpperCase());
                        String orgGSTN = orgGstin.substring(0, 2);
                        if (orgStatecode != orgGSTN) {

                            Assets.addError(assetData, "INV-060: Supplier State doesn’t belong to GSTIN provided");
                        }
                    }

                }
                if ((shiptoState != null) && !("SEZ With Payment".equals(transactionSubType) || "SEZ Without Payment".equals(transactionSubType) || "Export With Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType))) {
                    if (!placeOfSupply.equals(shiptoState)) {
                        Assets.addError(assetData, "INV-062  :Place of Supply should be equal to Ship to State");
                    }
                }


                if (("Export With Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType)) && (shiptoLegalname == null || dispatch_address1 == null || dispatch_city == null || dispatch_state == null || dispatch_pincode == null)) {

                    Assets.addError(assetData, "INV-065: In case of export transactions, the ‘Ship-To’ address should be of the place or port from where the goods are being exported");
                }
                if ("SEZ With Payment".equals(transactionSubType) || "SEZ Without Payment".equals(transactionSubType)) {
                    if (!("Others".equals(placeOfSupply))) {
                        Assets.addError(assetData, "INV-067 : Place of supply should be 'OTH" in
                            case SEZ transactions ")
                        }
                    }
                    if (("Regular".equals(transactionSubType) && (buyerGstin != null))) {
                        if (buyerPincode == null) {
                            Assets.addError(assetData, "INV-069 :Buyer PIN Code is Mandatory for Domestic B2B transactions");
                        }
                    }
                    if (("SEZ With Payment".equalsIgnoreCase(transactionSubtype) || "SEZ Without Payment".equalsIgnoreCase(transactionSubtype)) && !"Others".equalsIgnoreCase(buyerState)) {
                        Assets.addError(assetData, "INV-082: Buyer State should be 'OTH' in case SEZ Transactions");
                    }

                    if (("Export With Payment".equalsIgnoreCase(transactionSubtype) || "Export Without Payment".equalsIgnoreCase(transactionSubtype)) && !"Others".equalsIgnoreCase(buyerState)) {

                        Assets.addError(assetData, "INV-083: Buyer State should be 'OTH' in case Export Transactions");
                    }
                    if ("Regular".equals(transactionSubType)) {
                        if ("URP".equals(buyerGstin)) {
                            Assets.addError(assetData, "INV-089 : If Transaction Subtype is Regular  then Customer GSTIN/UIN should be Valid GSTIN/UIN");
                        }
                    }
                    if ("Unregistered".equals(transactionSubType)) {
                        if (!("URP".equals(buyerGstin))) {
                            Assets.addError(assetData, "INV-090 : If Transaction Subtype is Unregistered  then Customer GSTIN/UIN should be blank or URP");
                        }
                    }
                    if (roundingOffAmtvalue > 99.99 || roundingOffAmtvalue < -99.99) {
                        Assets.addError(assetData, "INV-087: Rounding off Amount must be between 99.99 and -99.99");
                    }



                    IEntityData itemdetails = Entities.getEntityById(entityRowData2.entityIterator(), "lineitemdetails");
                    if (itemdetails != null) {
                        Iterator < IEntityRecordData > itemDetailsRecords = itemdetails.recordIterator();
                        while (itemDetailsRecords.hasNext()) {
                            IEntityRecordData itementityRowData = itemDetailsRecords.next();
                            igstamount = Fields.isNull(Fields.getFieldById(itementityRowData, "igstamount")) ? 0 : Fields.getFieldById(itementityRowData, "igstamount").getValue();
                            cgstamount = Fields.isNull(Fields.getFieldById(itementityRowData, "cgstamount")) ? 0 : Fields.getFieldById(itementityRowData, "cgstamount").getValue();
                            sgstamount = Fields.isNull(Fields.getFieldById(itementityRowData, "sgstorutgstamount")) ? 0 : Fields.getFieldById(itementityRowData, "sgstorutgstamount").getValue();
                            taxableValue = Fields.isNull(Fields.getFieldById(itementityRowData, "taxablevalue")) ? 0 : Fields.getFieldById(itementityRowData, "taxablevalue").getValue();
                            hsnCode = Fields.isNull(Fields.getFieldById(itementityRowData, "hsncode")) ? null : Fields.getFieldById(itementityRowData, "hsncode").getValue();
                            goodsServices = Fields.isNull(Fields.getFieldById(itementityRowData, "goodsorservices")) ? null : Fields.getFieldById(itementityRowData, "goodsorservices").getValue();
                            gstRate = Fields.isNull(Fields.getFieldById(itementityRowData, "gstrate")) ? 0 : Fields.getFieldById(itementityRowData, "gstrate").getValue();
                            uqc = Fields.isNull(Fields.getFieldById(itementityRowData, "uqc")) ? 0 : Fields.getFieldById(itementityRowData, "uqc").getValue();
                            quantity = Fields.isNull(Fields.getFieldById(itementityRowData, "quantity")) ? 0 : Fields.getFieldById(itementityRowData, "quantity").getValue();
                            grossVal = Fields.isNull(Fields.getFieldById(itementityRowData, "grossvalue")) ? 0 : Fields.getFieldById(itementityRowData, "grossvalue").getValue();
                            dicountBeforegst = Fields.isNull(Fields.getFieldById(itementityRowData, "discountbeforegst")) ? 0 : Fields.getFieldById(itementityRowData, "discountbeforegst").getValue();
                            ratePerQuantity = Fields.isNull(Fields.getFieldById(itementityRowData, "rateperquantity")) ? 0 : Fields.getFieldById(itementityRowData, "rateperquantity").getValue();
                            batchNameLineitem = Fields.isNull(Fields.getFieldById(itementityRowData, "batchname")) ? null : Fields.getFieldById(itementityRowData, "batchname").getValue();
                            warrantyDate = Fields.isNull(Fields.getFieldById(itementityRowData, "warrantydate")) ? null : Fields.getFieldById(itementityRowData, "warrantydate").getValue();
                            expiryDate = Fields.isNull(Fields.getFieldById(itementityRowData, "expirydate")) ? null : Fields.getFieldById(itementityRowData, "expirydate").getValue();
                            cessRate = Fields.isNull(Fields.getFieldById(itementityRowData, "cessrate")) ? 0 : Fields.getFieldById(itementityRowData, "cessrate").getValue();
                            igstRate = Fields.isNull(Fields.getFieldById(itementityRowData, "igstrate")) ? 0 : Fields.getFieldById(itementityRowData, "igstrate").getValue();
                            cgstRate = Fields.isNull(Fields.getFieldById(itementityRowData, "cgstrate")) ? 0 : Fields.getFieldById(itementityRowData, "cgstrate").getValue();
                            sgstRate = Fields.isNull(Fields.getFieldById(itementityRowData, "sgstrate")) ? 0 : Fields.getFieldById(itementityRowData, "sgstrate").getValue();
                            compensationCessAmount = Fields.isNull(Fields.getFieldById(itementityRowData, "compensationcessamount")) ? 0 : Fields.getFieldById(itementityRowData, "compensationcessamount").getValue();
                            supplyCategory = Fields.isNull(Fields.getFieldById(itementityRowData, "supplycategory")) ? null : Fields.getFieldById(itementityRowData, "supplycategory").getValue();
                            totalamount = Fields.isNull(Fields.getFieldById(itementityRowData, "totalamount")) ? 0 : Fields.getFieldById(itementityRowData, "totalamount").getValue();
                            stateCessAmount = Fields.isNull(Fields.getFieldById(itementityRowData, "statecessamount")) ? 0 : Fields.getFieldById(itementityRowData, "statecessamount").getValue();
                            statecessNonAdvolAmount = Fields.isNull(Fields.getFieldById(itementityRowData, "statecessnonadvolamount")) ? 0 : Fields.getFieldById(itementityRowData, "statecessnonadvolamount").getValue();
                            CessNonAdvolValue = Fields.isNull(Fields.getFieldById(itementityRowData, "cessnonadvolvalue")) ? 0 : Fields.getFieldById(itementityRowData, "cessnonadvolvalue").getValue();
                            cessAmount = Fields.isNull(Fields.getFieldById(itementityRowData, "cessamount")) ? null : Fields.getFieldById(itementityRowData, "cessamount").getValue();
                            lineItemId = Fields.isNull(Fields.getFieldById(itementityRowData, "lineitemid")) ? null : Fields.getFieldById(itementityRowData, "lineitemid").getValue();



                            totalGstAndCessAmount = totalGst + totalCessAmount;

                            totalamount = igstamount + cgstamount + sgstamount + compensationCessAmount + stateCessAmount + statecessNonAdvolAmount + CessNonAdvolValue;

                            igstamt = igstamt + igstamount;
                            sgstamt = sgstamt + sgstamount;
                            cgstamt = cgstamt + cgstamount;

                            if ("SEZ Without Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType)) {
                                if (totalamount > 0) {
                                    Assets.addError(assetData, "INV-018,INV-019 : If 'Transaction Subtype' is 'SEZ Without Payment' or ' Export Without Payment ', then 'Total GST amount + Total Cess amount' should be zero");
                                }
                            }


                            if ("Regular".equals(transactionSubType) || "Deemed Exports".equals(transactionSubType)) {
                                if (!"supplierState".equals(placeOfSupply) && (cgstamount > 0 && sgstamount > 0)) {
                                    Assets.addError(assetData, "INV-005 and INV-010 : CGST / SGST is not applicable to inter-state transactions.");
                                }
                            }
                            if (("Others".equals(supplierState) || "97".equals(supplierState)) && (cgstamount > 0 && sgstamount > 0)) {
                                Assets.addError(assetData, "INV-006 : CGST / SGST is not applicable when supplier state is Others");
                            }
                            if ("97".equals(organisation_Gstin) && (cgstamount > 0 && sgstamount > 0)) {
                                Assets.addError(assetData, "INV-007 : CGST / SGST is not applicable when ORG GSTIN starts with 97");
                            }
                            if (("Others".equals(placeOfSupply) || "97".equals(placeOfSupply)) && (cgstamount > 0 && sgstamount > 0)) {
                                Assets.addError(assetData, "INV-008 : CGST / SGST is not applicable when place Of Supply is Others");
                            }
                            if ("yes".equals(flag_for_supply_covered_undersec7_of_igst_act1) && (cgstamount > 0 && sgstamount > 0)) {
                                Assets.addError(assetData, "INV-009:CGST / SGST is not applicable when IGST is applicable under section 7 of IGST");
                            }


                            if ("Regular".equals(transactionSubType) || "Deemed Exports".equals(transactionSubType)) {
                                if (supplierState.equals(placeOfSupply) && (igstamount > 0)) {
                                    Assets.addError(assetData, "INV-011 and INV-012 : IGST is not applicable to intra-state transactions.");
                                }
                            }
                            if (("97".equals(supplierGstin)) && igstAmt <= 0) {
                                Assets.addError(assetData, "INV-013 : If Supplier GSTIN starts with 97 then only IGST is only allowed");
                            }


                            if ("SEZ With Payment".equals(transactionSubType) || "Imports".equals(transactionSubType) || "Purchase from SEZ".equals(transactionSubType) || "Export With Payment".equals(transactionSubType)) {
                                if (sgstamount > 0 && cgstamount > 0) {
                                    Assets.addError(assetData, "INV-014,INV-015,INV-016,INV-017: CGST/SGST is not allowed if 'Transaction Subtype' is ' [${transactionSubType}]'");
                                }
                            }
                            Assets.addWarning(assetData, transactionSubType);
                            Assets.addWarning(assetData, "sgstamount " + sgstamount);
                            Assets.addWarning(assetData, "cgstamount+ " + cgstamount);

                            if ("Input service Distributor(ISD)".equals(taxpayerTypeSupplier)) {
                                if (!("Services".equals(goodsServices))) {
                                    Assets.addError(assetData, "INV-030 Goods are not allowed for 'Goods/Services' whenSupplier-Tax Payer Type is 'Input service Distributor (ISD)'");
                                }
                            }

                            if (cgstamount != null && sgstamount != null) {
                                if (cgstamount != sgstamount) {
                                    Assets.addError(assetData, "INV-031 :" +
                                        "CGST Amount Should be equal to SGST / UT GST Amount");
                                }
                            }
                            //  if ("Nil Rated".equals(supplyCategory) || "Exempted".equals(supplyCategory) || "Non GST".equals(supplyCategory)) {
                            // if (gstRate != 0 && totalGstAndCessAmount != 0) {
                            //  Assets.addError(assetData, "INV-032 : If 'GST Supply Category' is'Nil Rated/ Exempted /Non GST', then 'GST Rate' and 'Total GST amount + Total Cess amount' Should be zero");
                            //  }
                            //    }
                            if ("Nil Rated".equals(supplyCategory) || "Exempted".equals(supplyCategory) || "Non GST".equals(supplyCategory)) {
                                if (!("No".equals(reverseCharge))) {
                                    Assets.addError(assetData, "INV-033 : Reverse Charge should be 'No' in case of  'GST Supply Category' is 'Nil Rated/ Exempted /Non GST'");
                                }
                            }

                            if (hsnCode != "null" && "Services".equalsIgnoreCase(goodsServices)) {
                                if (!(hsnCode.substring(0, 2) == '99')) {
                                    Assets.addError(assetData, "INV-039 : For 'Services' HSN code should start with '99'");
                                }
                            }
                            if (hsnCode != "null" && "Goods".equalsIgnoreCase(goodsServices)) {
                                if ((hsnCode.substring(0, 2) == '99')) {
                                    Assets.addError(assetData, "INV-040 : For 'Services' HSN code should  not start with '99'");
                                }
                            }
                            if ("Imports".equals(transactionSubType) && "Goods".equalsIgnoreCase(goodsServices)) {
                                if (!("Bill of Entry".equals(transactionType))) {
                                    Assets.addError(assetData, "INV-041 :If 'Transaction Subtype' is 'Imports' and 'Goods/Services' is 'Goods', then 'Transaction Type' should be 'Bill of Entry'");
                                }
                            }
                            if ("Purchase from SEZ".equals(transactionSubType) && !("Goods".equalsIgnoreCase(goodsServices))) {
                                if (!("Bill of Entry".equals(transactionType))) {
                                    Assets.addError(assetData, "INV-042 :If 'Transaction Subtype' is 'Imports' and 'Goods/Services' is 'Goods', then 'Transaction Type' should be 'Bill of Entry'");
                                }
                            }
                            if (!("Imports".equals(transactionSubType) && "Goods".equalsIgnoreCase(goodsServices))) {
                                if (("Bill of Entry".equals(transactionType))) {
                                    Assets.addError(assetData, "INV-043 :If 'Transaction Subtype' is 'Imports' and 'Goods/Services' is 'Goods', then 'Transaction Type' should be 'Bill of Entry'");
                                }
                            }
                            if (!("Purchase from SEZ".equals(transactionSubType) && "Goods".equalsIgnoreCase(goodsServices))) {
                                if (("Bill of Entry".equals(transactionType))) {
                                    Assets.addError(assetData, "INV-044 :If 'Transaction Subtype' is 'Imports' and 'Goods/Services' is 'Goods', then 'Transaction Type' should be 'Bill of Entry'");
                                }
                            }
                            if ("Imports".equals(transactionSubType) || "Purchase from SEZ".equals(transactionSubType) && "Goods".equalsIgnoreCase(goodsServices)) {
                                if (portCode == null) {
                                    Assets.addError(assetData, "INV-045 :Port Code' is Mandatory in case 'Transaction Sub Type' is 'Imports' or 'Purchase from SEZ' & 'Goods/Services' is 'Goods'");
                                }
                            }
                            if ("Deemed Exports".equals(transactionSubType) && "Goods".equalsIgnoreCase(goodsServices)) {
                                Assets.addError(assetData, "INV-046 : If 'Transaction SubType' is 'Deemed Exports' then 'Goods/Service'  should be 'Goods'");
                            }
                            if ("Bill of Supply".equals(transactionType) || "Delivery Challan".equals(transactionType)) {
                                if (gstRate != 0) {
                                    Assets.addError(assetData, "INV-047 , INV-048 :If Transaction  Type is Bill of Supply or Delivery Challan then GST rate should be zero");
                                }
                            }
                            if ((batchNameLineitem != null || warrantyDate != null || expiryDate != null) && (batchNameLineitem == null)) {

                                Assets.addError(assetData, "INV-057: If the data is present in any one of the fields i.e in [Batch Name] or [Warranty Date] or [Expiry Date] then [Batch Name] is Mandatory");
                            }



                            if ("Goods".equals(goodsServices)) {
                                if (uqc == null && quantity == 0) {
                                    Assets.addError(assetData, "INV-070 For Goods UQC & Qunatity are required");
                                }
                            }
                            if (taxableValue != (grossVal - dicountBeforegst)) {
                                Assets.addError(assetData, "INV-071 : Taxable Value should be equal to [Gross Value -Discount]");
                            }
                            if ("Goods".equals(goodsServices)) {
                                if (grossVal != (quantity) * (ratePerQuantity)) {
                                    Assets.addError(assetData, "INV-072 Gross Value should be equal to [Unitprice* Quantity]");
                                }
                            }
                            totalItemvalue = igstamt + sgstamt + cgstamt;
                            if (invoiceValue != totalItemvalue) {
                                Assets.addError(assetData, "INV-079:  [Invoice Value] should be equal to Sum of all [Total Item Values] of Line Items");
                            }
                            Double tax_val_and_cess_rate = taxableValue * cessRate / 100;
                            Double tax_val_and_sgst_rate = taxableValue * sgstRate / 100;
                            Double tax_val_and_cgst_rate = taxableValue * cgstRate / 100;
                            Double tax_val_and_igst_rate = taxableValue * igstRate / 100;
                            if (!("Debit Note for Purchases".equals(transactionType) || "Credit Note for Purchases".equals(transactionType) || "Debit Note for Sales".equals(transactionType) || "Credit Note for Sales".equals(transactionType)) || (!("SEZ Without Payment".equals(transactionSubType) || "Export Without Payment".equals(transactionSubType)))) {
                                if (igstamount != tax_val_and_igst_rate) {
                                    Assets.addError(assetData, "INV-084: IGST Amount should be equal to [Taxable Value * GST Rate/100]");

                                }
                            }
                            if (!("Debit Note for Purchases".equals(transactionType) || "Credit Note for Purchases".equals(transactionType) || "Debit Note for Sales".equals(transactionType) || "Credit Note for Sales".equals(transactionType))) {
                                if (sgstamount != tax_val_and_sgst_rate) {
                                    Assets.addError(assetData, "INV-086: SGST Amount should be equal to [Taxable Value * SGST Rate/100]");

                                }
                            }
                            if (!("Debit Note for Purchases".equals(transactionType) || "Credit Note for Purchases".equals(transactionType) || "Debit Note for Sales".equals(transactionType) || "Credit Note for Sales".equals(transactionType))) {
                                if (cgstamount != tax_val_and_cgst_rate) {
                                    Assets.addError(assetData, "INV-085: CGST Amount should be equal to [Taxable Value * CGST Rate/100]]");

                                }
                            }
                            if (!("Debit Note for Purchases".equals(transactionType) || "Credit Note for Purchases".equals(transactionType) || "Debit Note for Sales".equals(transactionType) || "Credit Note for Sales".equals(transactionType))) {
                                if (compensationCessAmount != tax_val_and_cess_rate) {
                                    Assets.addError(assetData, "INV-088:  Compensation cess  Amount should be equal to [Taxable Value * Cess Rate/100]]");
                                }
                            }


                            tot_Taxable_val = tot_Taxable_val + taxableValue;


                            if (tot_Taxable_val != totalTaxableValue) {
                                Assets.addError(assetData, "INV-073:  [Total Taxable Value] should be equal to Sum of all [Taxable Values] of Line Items");
                            }
                            totalCgstAmt = totalCgstAmt + cgstamount;
                            if (totalCgstAmount != totalCgstAmt) {
                                Assets.addError(assetData, "INV-075:  [Total CGST Value] should be equal to Sum of all [CGST Values] of Line Items");
                            }
                            totalSgstAmt = totalSgstAmt + sgstamount;
                            if (totalSgstAmount != totalSgstAmt) {
                                Assets.addError(assetData, "INigstamountV-076:  [Total SGST Value] should be equal to Sum of all [SGST Values] of Line Items");
                            }

                            totalIgstAmt = totalIgstAmt + igstamount;
                            if (totalIgstAmount != totalIgstAmt) {
                                Assets.addError(assetData, "INV-074:  [Total IGST Value] should be equal to Sum of all [IGST Values] of Line Items");
                            }
                            totalCessAmt = totalCessAmt + cessAmount;
                            if (totalCessAmount != totalCessAmt) {
                                Assets.addError(assetData, "INV-077:  [Total Cess Value] should be equal to Sum of all [Cess Values] of Line Items");
                            }
                            totalStateCessAmt = totalStateCessAmt + stateCessAmount;
                            if (totalStateCessAmount != totalStateCessAmt) {
                                Assets.addError(assetData, "INV-078:  [Total State Cess Value] should be equal to Sum of all [State Cess Values] of Line Items");
                            }


                        }
                    }
                }
            } 

Groovy online compiler

Write, Run & Share Groovy code online using OneCompiler's Groovy online compiler for free. It's one of the robust, feature-rich online compilers for Groovy language, running the latest Groovy version 2.6. Getting started with the OneCompiler's Groovy editor is easy and fast. The editor shows sample boilerplate code when you choose language as Groovy and start coding.

Read inputs from stdin

OneCompiler's Groovy online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Groovy program which takes name as input and prints hello message with your name.

def name = System.in.newReader().readLine()
println "Hello " + name

About Groovy

Groovy is an object-oriented programming language based on java. Apache Groovy is a dynamic and agile language which is similar to Python, Ruby, Smalltalk etc.

Key Features

  • It's not a replacement for java but it's an enhancer to Java with extra features like DSL support, dynamic typing, closures etc.
  • Accepts Java code as it extends JDK
  • Greater flexibility
  • Concise and much simpler compared to Java
  • Can be used as both programming language and scripting language.

Syntax help

Data Types

Data typeDescriptionRange
StringTo represent text literalsNA
charTo represent single character literalNA
intTo represent whole numbers-2,147,483,648 to 2,147,483,647
shortTo represent short numbers-32,768 to 32,767
longTo represent long numbers-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
doubleTo represent 64 bit floating point numbers4.94065645841246544e-324d to 1.79769313486231570e+308d
floatTo represent 32 bit floating point numbers1.40129846432481707e-45 to 3.40282346638528860e+38
byteTo represent byte value-128 to 127
booleanTo represent boolean values either true or falseTrue or False

Variables

You can define variables in two ways

Syntax:

data-type variable-name;

[or]

def variable-name;

Loops

0.upto(n) {println "$it"}

or

n.times{println "$it"}

where n is the number of loops and 0 specifies the starting index

Decision-Making

1. If / Nested-If / If-Else:

When ever you want to perform a set of operations based on a condition or set of conditions, then If / Nested-If / If-Else is used.

if(conditional-expression) {
  // code
} else {
  // code
}

2. Switch:

Switch is an alternative to If-Else-If ladder and to select one among many blocks of code.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 //code to be executed when all the above cases are not matched;    
} 

List

List allows you to store ordered collection of data values.

Example:

def mylist = [1,2,3,4,5];
List MethodsDescription
size()To find size of elements
sort()To sort the elements
add()To append new value at the end
contains()Returns true if this List contains requested value.
get()Returns the element of the list at the definite position
pop()To remove the last item from the List
isEmpty()Returns true if List contains no elements
minus()This allows you to exclude few specified elements from the elements of the original
plus()This allows you to add few specified elements to the elements of the original
remove()To remove the element present at the specific position
reverse()To reverse the elements of the original List and creates new list