requirement 

invoice header schema names

invoice details schema names

dear team, 

my requirement is when i create a record in invoice header these details are shown in sub grid invoice details.

please suggest me,what can i do what are the steps i will follow.

i have attached my  logic code please look it on.please suggest me real time scenario's websites,blogs to learn . 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;


namespace general_invoice_details
{
    public class invoice : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {

            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
            (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Obtain the organization service reference.
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity entity = (Entity)context.InputParameters["Target"];


                if (entity.LogicalName != "new_invoiceheaderId")

                    return;

                decimal amount = ((Money)entity.Attributes["new_amount"]).Value;
                int terms = Convert.ToInt32(entity.Attributes["new_terms"]);
                int invoiceday = Convert.ToInt32(entity.Attributes["new_invoiceday"]);

                for (int i = 0; 1 < terms; i++)
                {
                    try

                    {
                        Entity invoicedetails = new Entity();
                        invoicedetails.LogicalName = "new_invoicedetails";
                        invoicedetails["new_installmentamount"] = new Money(amount / terms);
                        invoicedetails["new_invoicedate"] = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, invoiceday);
                        invoicedetails["new_invoiceId"] = new EntityReference("new_invoice", entity.Id);
                        service.Create(invoicedetails);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Exception from invoice plugin" + ex.Message);

                    }
                }
            }
        }
    }
}