htmlpage Pay_Period_Details(PayPeriodID,AgentID,ShowPrint,start_range,end_range)
 
 
  displayname = "Pay Period Details"
 
 
  content
 
 
  <%{
 
 
   /* Get The current Pay Period Record */
 
 
   Int_Pay_Period_ID = PayPeriodID.toLong();
 
 
   Current_Pay_Period_Record = Pay_Period[ID == Int_Pay_Period_ID];
 
 
   Previous_Pay_Period_ID = thisapp.Application.GetPreviousPayPeriodID(Current_Pay_Period_Record.ID);
 
 
   /* Checking Agent ID is a valid Agent ID */
 
 
   if(input.AgentID != null && input.AgentID != "" && FormA[ID == AgentID.toLong()].count() == 1)
 
 
   {
 
 
   //This input parameter is a valid Agent ID
 
 
   Int_Agent_ID = AgentID.toLong();
 
 
   }
 
 
   %>
 
 
  <style>
 
 
    
     .centerAlign
 
 
     {
 
 
    
   text-align:center;
 
 
     }
 
 
     .rightAlign
 
 
     {
 
 
     text-align:right;
 
 
     }
 
 
     .rightAlignTd td
 
 
     {
 
 
     text-align:right;
 
 
     }
 
 
     .boldTd td
 
 
     {
 
 
     font-weight:bold;
 
 
     }
 
 
     .leftAlign
 
 
     {
 
 
     text-align:left;
 
 
     }
 
 
     .width33
 
 
     {
 
 
     width:33%;
 
 
     }
 
 
     .width12
 
 
     {
 
 
     width:12%;
 
 
     }
 
 
     .width8
 
 
     {
 
 
     width:8%;
 
 
     }
 
 
     .customBodyStyle
 
 
     {
 
 
     margin:10px 10px 10px 10px;
 
 
     }
 
 
     .floatRight
 
 
     {
 
 
     float:right;
 
 
     margin-right:10px;
 
 
     }
 
 
    </style>
 
 
    <style media="print">
 
 
    
   .pageBreakBefore
 
 
     {
 
 
     page-break-before:always;
 
 
     }
 
 
    </style>
 
 
    <div style="customBodyStyle">
 
 
  <%
 
 
   /* EACH AGENT CONTAINER */
 
 
   Int_Start_Range = start_range.toLong();
 
 
   Int_End_Range = end_range.toLong();
 
 
   Total_Record_Count = FormA[ID != 0].count();
 
 
   //Initilize Agent Counter
 
 
   Agent_Index = 0;
 
 
   for each  Agent_Record in FormA sort by Last_Name range from Int_Start_Range to Int_End_Range
 
 
   {
 
 
   //When Agent ID has been provided, we render only for that agent or when input agent id is not provided
 
 
   //we loop for all existing agents
 
 
   if(Int_Agent_ID == null || Agent_Record.ID == Int_Agent_ID)
 
 
   {
 
 
   Agent_Daily_Record_Count = FormB[Agent == Agent_Record.ID && Date_field >= Current_Pay_Period_Record.Start_Date && Date_field <= Current_Pay_Period_Record.End_Date].count();
 
 
   // Now we have to include those agents who are either active or have atleast one record in the pay period
 
 
   if(Agent_Record.Status == "Active" || Agent_Daily_Record_Count > 0)
 
 
   {
 
 
   //Initilize
 
 
   /* Previous_Pay_Period_Payout = 0.0; */
 
 
   Running_Total = 0.0;
 
 
   //Determine the previous payout for the agent
 
 
   //Accounting for the fact that Agent counld not have existed in the previous pay period
   
 
 
   if(Previous_Pay_Period_ID != -1 && Pay_Period_Agent[Pay_Period_ID == Previous_Pay_Period_ID && Agent_ID == Agent_Record.ID].count() == 1)
 
 
   {
 
 
   //if ((Previous_Pay_Period_ID  !=  -1)  &&  (Pay_Period_Agent[(Pay_Period_ID == Int_Pay_Period_ID && Agent_ID == Agent_Record.ID)].count()  ==  1))
   
 
 
   Previous_Pay_Period_Agent_Record = Pay_Period_Agent[Pay_Period_ID == Previous_Pay_Period_ID && Agent_ID == Agent_Record.ID];
 
 
   //Previous_Pay_Period_Agent_Record  =  Pay_Period_Agent  [(Pay_Period_ID == Int_Pay_Period_ID && Agent_ID == Agent_Record.ID)];
   
 
 
   /* Previous_Pay_Period_Payout = Previous_Pay_Period_Agent_Record.Payout; */
 
 
   // Running_Total = (Previous_Pay_Period_Agent_Record.Pay_Period_Balance  -  Previous_Pay_Period_Agent_Record.Payout);
 
 
   Running_Total = Previous_Pay_Period_Agent_Record.Pay_Period_Balance;
 
 
   }
 
 
   %>
 
 
  <div
 
 
  <%
 
 
   if(Agent_Index > 0)
 
 
   {
 
 
   %>
 
 
  class="pageBreakBefore"
 
 
  <%
 
 
   }
 
 
   %>
 
 
  >
 
 
  <%
 
 
   Agent_Index = Agent_Index + 1;
 
 
   %>
 
 
  <br/>
 
 
   <table class="zc-viewtable zc-viewrow">
 
 
  <%
 
 
   if(input.ShowPrint == "False")
 
 
   {
 
 
   %>
 
 
  <tr class="zc-grouprow">
 
 
     
   <td colspan="3">
 
 
   Pay Period <%=Current_Pay_Period_Record.Start_Date%> to <%=Current_Pay_Period_Record.End_Date%>
 
 
   </td>
 
 
   </tr>
 
 
  <%
 
 
   }
 
 
   %>
 
 
  <tr class="zc-grouprow">
 
 
     <td class="width33"><%=Agent_Record.Last_Name%>, <%=Agent_Record.Name%> - <%=Agent_Record.Position%>
 
 
  <%
 
 
   if(input.ShowPrint != "False")
 
 
   {
 
 
   %>
 
 
 
  <%
 
 
   }
 
 
   %>
 
 
  </td>
 
 
    <td class="rightAlign width33"></td>
 
 
  <%
 
 
   /* Previous Payout: $ <%=Previous_Pay_Period_Payout%> */
 
 
   %>
 
 
  <td class="rightAlign width33">Previous Balance:$ <%=Running_Total%></td>  
 
 
     </tr>
 
 
   </table>
 
 
   <table class="zc-viewtable">
 
 
     
   <tr class="zc-viewrowheader">
 
 
    <th class="width12 centerAlign">Date</th>
 
 
    <th class="width8 centerAlign">Sales</th>
 
 
    <th class="width8 centerAlign">Front</th>
 
 
    <th class="width8 centerAlign">Comm<br/>pay</th>
 
 
    <th class="width8 centerAlign">Bonus</th>
 
 
    <th class="width8 centerAlign">Cash<br/>Recieved</th>
 
 
    <th class="width8 centerAlign">Supp/<br/>Trans</th>
 
 
    <th class="width8 centerAlign">Total<br/>Cancel</th>
 
 
    <th class="width8 centerAlign">Cancel<br/>comm</th>
 
 
    <th class="width8 centerAlign">Bonuses<br/>Lost</th>
 
 
    <th class="width8 centerAlign">Day Total</th>
 
 
    <th class="width8 centerAlign">End Balance</th>
 
 
   </tr>
 
 
  <%
 
 
   //Initilize the Day Index
 
 
   Date_Index = Current_Pay_Period_Record.Start_Date;
 
 
   //Initilize all Total variables
 
 
   Total_Sales = 0;
 
 
   Total_Commission = 0.0;
 
 
   Total_Total = 0.0;
 
 
   Total_Bonus = 0.0;
 
 
   Total_Draw = 0.0;
 
 
   Total_S_T = 0.0;
 
 
   Total_Total_Cancelations = 0.0;
 
 
   Total_Cancellation_1_Commission_amount = 0.0;
 
 
   Total_Bonus_Lost = 0.0;
 
 
   Total_Ending_Balance = 0.0;
 
 
   for each  Dummy_Record in Dummy
 
 
   {
 
 
   //Making sure that we remain in the bounds of the pay period
 
 
   if(Date_Index <= Current_Pay_Period_Record.End_Date)
 
 
   {
 
 
   //Account for the condition when there are no records for the agent for a given day
 
 
   if(FormB[Agent == Agent_Record.ID && Date_field = Date_Index].count() > 0)
 
 
   {
 
 
   //In this case we pull the records from the database.
 
 
   //There could be multiple day records per agent per day
 
 
   for each  Agent_Day_Record in FormB[Agent == Agent_Record.ID && Date_field = Date_Index] sort by Added_Time
 
 
   {
 
 
   %>
 
 
  <tr class="zc-viewrow rightAlignTd">
 
 
     <td class="leftAlign"><%=Agent_Day_Record.Date_field%></td>
 
 
  <%
 
 
   Total_Sales = Total_Sales + ifnull(Agent_Day_Record.Sales,0);
 
 
   %>
 
 
  <td><%=ifnull(Agent_Day_Record.Sales,0)%></td>
 
 
  <%
 
 
   Total_Commission = Total_Commission + ifnull(Agent_Day_Record.Commission,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Commission,0.0)%></td>
 
 
  <%
 
 
   Total_Total = Total_Total + ifnull(Agent_Day_Record.Total,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Total,0.0)%></td>
 
 
  <%
 
 
   Total_Bonus = Total_Bonus + ifnull(Agent_Day_Record.Bonus,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Bonus,0.0)%></td>
 
 
  <%
 
 
   Total_Draw = Total_Draw + ifnull(Agent_Day_Record.Draw,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Draw,0.0)%></td>
 
 
  <%
 
 
   Total_S_T = Total_S_T + ifnull(Agent_Day_Record.S_T,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.S_T,0.0)%></td>
 
 
  <%
 
 
   Total_Total_Cancelations = Total_Total_Cancelations + ifnull(Agent_Day_Record.Total_Cancelations,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Total_Cancelations,0.0)%></td>
 
 
  <%
 
 
   Total_Cancellation_1_Commission_amount = Total_Cancellation_1_Commission_amount + ifnull(Agent_Day_Record.Cancellation_1_Commission_amount,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Cancellation_1_Commission_amount,0.0)%></td>
 
 
  <%
 
 
   Total_Bonus_Lost = Total_Bonus_Lost + ifnull(Agent_Day_Record.Bonus_Lost,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Bonus_Lost,0.0)%></td>
 
 
  <%
 
 
   Total_Ending_Balance = Total_Ending_Balance + ifnull(Agent_Day_Record.Ending_Balance,0.0);
 
 
   %>
 
 
  <td>$ <%=ifnull(Agent_Day_Record.Ending_Balance,0.0)%></td>
 
 
  <%
 
 
   Running_Total = Running_Total + ifnull(Agent_Day_Record.Ending_Balance,0.0);
 
 
   %>
 
 
  <td>$ <%=Running_Total%></td>
 
 
     </tr>
 
 
  <%
 
 
   }
 
 
   /*END - For each day record */
 
 
   }
 
 
   else
 
 
   {
 
 
   //There is no database record. So we dummy up a 0.0 record
 
 
   %>
 
 
  <tr class="zc-viewrow rightAlignTd">
 
 
    <td class="leftAlign"><%=Date_Index%></td>
 
 
    <td>0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ 0.0</td>
 
 
    <td>$ <%=Running_Total%></td>
 
 
    </tr>
 
 
  <%
 
 
   }
 
 
   /*END - Actual Day Record(s) OR dummy up record */
 
 
   Date_Index = Date_Index.addDay(1);
 
 
   }
 
 
   /* END - Check that Date Index remains in bounds */
 
 
   }
 
 
   /* END - Running Counter on Dummy Record */
 
 
   %>
 
 
  <tr class="zc-viewrow rightAlignTd boldTd">
 
 
   <td></td>
 
 
   <td><%=Total_Sales%></td>
 
 
   <td>$ <%=Total_Commission%></td>
 
 
   <td>$ <%=Total_Total%></td>
 
 
   <td>$ <%=Total_Bonus%></td>
 
 
   <td>$ <%=Total_Draw%></td>
 
 
   <td>$ <%=Total_S_T%></td>
 
 
   <td>$ <%=Total_Total_Cancelations%></td>
 
 
   <td>$ <%=Total_Cancellation_1_Commission_amount%></td>
 
 
   <td>$ <%=Total_Bonus_Lost%></td>
 
 
   <td>$ <%=Total_Ending_Balance%></td>
 
 
   <td>$ <%=Running_Total%></td>
 
 
   </tr>
 
 
    </table>
 
 
    </div>
 
 
  <%
 
 
   }
 
 
   else
 
 
   {
 
 
   if(!input.ShowPrint == "False" && Int_Agent_ID != null)
 
 
   {
 
 
   %>
 
 
  <div class="centerAlign">Agent is Inactive.</div>
 
 
  <%
 
 
   }
 
 
   /* END - Ensure that is not Print */
 
 
   }
 
 
   /* END - If Agent is active or has at least one day record */
 
 
   }
 
 
   /* END - Check on presence of Agent ID */
 
 
   }
 
 
   /* END - Loop on all agents on Agent Table */
 
 
   /* END == EACH AGENT CONTAINER */
 
 
   %>
 
 
  </div>
 
 
  <%
 
 
  
 
 
  }%>