<?php $__env->startSection('page_title'); ?>
    OSAA - OWWMP BIA
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>    
    
    OWWMP BIA Administration

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    @parent

    <style type="text/css">
    	h3 {
    		color: #1C43A6 !important;
    	}    	

    	.success_bar {
    		position: fixed;
    		top: 600px;
    		left: 0;
    		width: 100%;
    		padding: 0.25em 0;
    		line-height: 1.5em;
    		background-color: rgba(176, 255, 190, 0.0);
    		border-bottom: 2px solid rgba(13, 88, 27, 0.50);
    		border-top: 2px solid rgba(13, 88, 27, 0.50);
    		z-index: 500;
    	}

    	.success_bar .message {
    		width: 1200px;
    		margin: 0 auto;
    		font-size: 14pt;
    		color: #151515;
    	}    	

    	.page_functions {
    		width: auto !important;
    	}         
        
        .required {
            color: #990000;
            font-weight: bold;
        }

        .placeholder
        {
            color: #aaaaaa !important;
            font-weight: normal !important;
        }

        /* Status Progress Styles */
        .status_progress {
            position: relative;
            margin: 1.5em 0 1em 0;
            border: 1px solid #efefef;
            padding: 1em;
        }

        .status_title {
            position: absolute;
            top: -10px;
            color: #d9d9d9;
            padding: 0 10px;
            background-color: #ffffff;
            font-style: italic;
            letter-spacing: 2px;
            font-weight: bold;
        }

        .status_step {
            position: relative;
            display: inline-block;
            text-align: center;
            color: #cccccc;
            width: 15%;            
        }

        .status_step.show {
            color: #333366;
            font-weight: bold;
        }      

        .status_step .slug {
            font-size: 14pt;
            letter-spacing: 1px;
        }

        .status_step .name {
            font-size: 10pt;
        }        
        

        /* Assessment Table */
        .odd {
            background-color: #efefef;
        }

        .assessment_table {
            border-collapse: collapse;
            width: 100%;
            font-size: 10pt;
        }

        .assessment_table thead {
            background-color: #005FA9;
            color: #ffffff;
        }

        .assessment_table thead th {            
            padding: 4px 2px;
            text-align: left;
        }

        .assessment_table tbody tr {
            line-height: 2em;
        }

        /* Help Dialog */
        .help_dialog {
            font-size: 10pt;
        }

        .help_dialog h1 {
            font-size: 14pt;
            color: #005fa9;
            margin: 1em 0 1em 0;
        }

        .help_dialog h2 {
            font-size: 12pt;
            color: #990000;
            margin: 1em 0 0.5em 0;
        }

        .help_dialog h3 {
            font-size: 10pt;
            color: #000000 !important;
            margin: 0.75em 0 0em 0;
        }

        .help_dialog ul, ol {
            margin-left: 28px;
        }

        .help_dialog dl dt {
            float: left;
            width: 200px;
            text-align: right;
            margin-right: 20px;
            font-weight: bold;
            clear: both;
        }        

    </style>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('jquery_init'); ?>
			
	// Success bar
	$('.success_bar').animate({ 'top' : 32, 'background-color' : 'rgba(176, 255, 190, 1.0)'}, 1600, 'easeOutQuad', function ()
	{		
		$(this).delay(6000).fadeOut(4000);	

		$(this).hover(function ()
		{
			$(this).stop(true).css('opacity', '1.0');
		},
		function ()
		{
			$(this).fadeOut(4000);
		})
	});

    // Placeholder functionality
    $('[data-placeholder]').focus(function()
    {
        var input = $(this);
        if (input.val() == input.attr('data-placeholder'))
        {
            input.val('');
            input.removeClass('placeholder');
        }
    }).blur(function()
    {
        var input = $(this);
        if (input.val() == '' || input.val() == input.attr('data-placeholder'))
        {
            input.addClass('placeholder');
            input.val(input.attr('data-placeholder'));
        }
    }).blur();
    $('[data-placeholder]').parents('form').submit(function()
    {
        $(this).find('[data-placeholder]').each(function()
        {
            var input = $(this);
            if (input.val() == input.attr('data-placeholder'))
            {
                input.val('');
            }
        })
    });   

    // Table row highlighter
    function colorRows ()
    {       
        $('table').each(function ()
        {
            var i = 0;

            $('tbody tr:visible', $(this)).each(function ()
            {
                if (i % 2 == 1)
                {
                    $(this).addClass('odd');
                }
                else
                {
                    $(this).removeClass('odd');
                }
                i = i + 1;
            });     
        });
    }   
    colorRows();    
    

    // Process received button
    $('.process_received')
        .button({'icons':{'primary':'ui-icon-clipboard'}})
        .css({'font-size':'9pt'})
        .click(function(event)
        {
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    draggable : false,
                    resizable : false,
                    modal : true,
                    height : 400,                    
                    width : 500,                    
                    title : 'Payments & Reports',
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            dialog_object.html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");

                            var jqxhr = $.ajax(
                                      {
                                          type : 'GET',
                                          url : '<?php echo url('forms/bia/admin/process-received'); ?>',
                                          dataType : 'html'
                                      })
                                      .done(function (returned_data)
                                      {                               
                                          dialog_object.html(returned_data);
                                      })
                                      .fail(function (jqXHR, status, error)
                                      {                                                   
                                          var response = jqXHR.responseText;
                                          var errorData = $.parseJSON(response);
                                          console.log(errorData);
                                          alert ("There was an error looking up the processing form.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                          $('.school_summary')
                                              .button({'icons':{'secondary':'ui-icon-calculator'}})
                                              .css({'font-size':'9pt'})
                                              .click(function()
                                              {
                                                  window.open('<?php echo url('/forms/bia/admin/process-received/school-summary'); ?>');
                                              });

                                          $('.details_summary')
                                              .button({'icons':{'secondary':'ui-icon-document'}})
                                              .css({'font-size':'9pt'})
                                              .click(function()
                                              {
                                                  window.open('<?php echo url('/forms/bia/admin/process-received/details-summary'); ?>');
                                              });

                                          $('input[type="text"][data-datepicker="true"]')
                                              .datepicker({dateFormat:'yy-mm-dd'})
                                              .on('change', function ()
                                              {
                                                  var value = $(this).val();

                                                  if (value != '')
                                                  {
                                                      $('.next_button').button('enable');
                                                  }
                                                  else
                                                  {
                                                      $('.next_button').button('disable');
                                                  }
                                              });

                                          $('.next_button')
                                              .button({'icons':{'secondary':'ui-icon-arrowthick-1-e'}})
                                              .css({'font-size' : '9pt',
                                                    'float' : 'right'})
                                              .click(function ()
                                              {
                                                  var cutoff_date = $('input[type="text"][data-datepicker="true"]').val();

                                                  dialog_object.html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div><div style='text-align: center; width: 100%; font-size: 8pt;'>Processing<br />" + cutoff_date + "</div>");

                                                  var jqxhr = $.ajax(
                                                  {
                                                      type : 'GET',
                                                      url : '<?php echo url('forms/bia/admin/process-received'); ?>',
                                                      data : {'cutoff_date' : cutoff_date},
                                                      dataType : 'html'
                                                  })
                                                  .done(function (returned_data)
                                                  {                               
                                                      dialog_object.html(returned_data);
                                                  })
                                                  .fail(function (jqXHR, status, error)
                                                  {                                                   
                                                      var response = jqXHR.responseText;
                                                      var errorData = $.parseJSON(response);
                                                      console.log(errorData);
                                                      alert ("There was an error looking up the processing form.\n\nThis page will be reloaded.");
                                                      location.reload();
                                                  })
                                                  .complete(function ()
                                                  {
                                                      var cutoff_date = $('input[name="cutoff_date"]').val();

                                                      $('.assessor_summary')
                                                          .button({'icons':{'secondary':'ui-icon-calculator'}})
                                                          .css({'font-size':'9pt'})
                                                          .click(function()
                                                          {
                                                              window.open('<?php echo url('/forms/bia/admin/process-received/assessor-summary'); ?>?cutoff_date=' + cutoff_date);
                                                          });
                                                     
                                                      $('.mark_done')
                                                          .button({'icons':{'secondary':'ui-icon-mail-open'}})
                                                          .css({'font-size':'9pt'})
                                                          .click(function()
                                                          {
                                                              var result = confirm('Are you sure you want to mark these received forms as paid?  This will change the filtered form\'s status to DONE and archive these reports which cannot be processed again for payment.');

                                                              if (result)
                                                              {
                                                                  window.location= '<?php echo url('/forms/bia/admin/process-received/mark-done'); ?>?cutoff_date=' + cutoff_date;
                                                              }
                                                          });
                                                  }); 
                                              });

                                          $('.next_button').button('disable');
                                      });                            
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);

                            $(dialog_object).remove();
                        }
                });

        });


    // Help button
    /*
    $('.help_button')
        .button({'icons':{'primary':'ui-icon-help'}})
        .css({'font-size':'9pt', 'margin-right':'10px'})
        .click(function(event)
        {
            event.preventDefault();

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    draggable : true,
                    resizable : true,
                    height : 725,
                    minHeight : 400,
                    width : 615,
                    minWidth : 330,
                    modal : false,
                    title : 'Administration Help',                    
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            dialog_object.html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");

                            var jqxhr = $.ajax(
                                      {
                                          type : 'GET',
                                          url : '<?php echo url('forms/bia/help'); ?>',
                                          dataType : 'html'
                                      })
                                      .done(function (returned_data)
                                      {                               
                                          dialog_object.html(returned_data);
                                      })
                                      .fail(function (jqXHR, status, error)
                                      {                                                   
                                          var response = jqXHR.responseText;
                                          var errorData = $.parseJSON(response);
                                          console.log(errorData);
                                          alert ("There was an error looking up help information.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                           
                                      });                            
                            
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);

                            $(dialog_object).remove();
                        }                
                });


        });*/    
     
    // Print form button
    $('.bia_print')
        .css({'width' : '16px',
              'height' : '16px',
              'margin-right' : '5px'})
        .button({ icons : { primary : 'ui-icon-print'},
                  text : false})
        .click(function ()
        {
            var button = $(this);
            var row = button.parents('tr');
            var record = row.attr('data-record');

            window.open('<?php echo url('/forms/bia'); ?>/' + record + '/print'); 
        });

    // Edit form button
    $('.bia_edit')
        .css({'width' : '16px',
              'height' : '16px'})
        .button({ icons : { primary : 'ui-icon-pencil'},
                  text : false})
        .click(function()
        {
            var button = $(this);

            var row = button.parents('tr');
            
            var original_background_color = row.css('background-color');            
            
            var record = row.attr('data-record');            

            var status = row.attr('data-status');

            row.css({'background-color':'yellow'});

            if (status == 'WORK' || status == 'INSF' || <?php echo (Auth::user()->isOsaaUser()) ? 1 : 0; ?>)
            {                            
                window.location = "<?php echo url('/forms/bia'); ?>/" + record + "/edit?admin=true";
            }
            else
            {
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 200,
                        width : 400,                    
                        title : 'Unable to Edit',
                        buttons: [                                
                            {
                                text : "Ok",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />You cannot edit this record.');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }

        });

    // Delete form button
    $('.bia_delete')
        .css({'width' : '16px',
              'height' : '16px',
              'margin-left' : '5px'})
        .button({ icons : { primary : 'ui-icon-trash'},
                  text : false})
        .click(function()
        {
            var button = $(this);

            var row = button.parents('tr');
            
            var original_background_color = row.css('background-color');            
            
            var record = row.attr('data-record');            

            var status = row.attr('data-status');

            row.css({'background-color':'yellow'});

            if (status == 'WORK' || status == 'INSF' || <?php echo (Auth::user()->isOsaaUser()) ? 1 : 0; ?>)
            {                            
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 250,
                        width : 400,                    
                        title : 'Confirm Deletion',
                        buttons: [
                            {
                                text : "Delete",
                                'class' : "float_left",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {                                                       
                                            var data = { record : record };

                                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                                                 .appendTo('body');
                                  
                                            $('<div><div>').appendTo('body')
                                                           .css('width', '225px')
                                                           .css('height', '170px')
                                                           .css('text-align', 'center')
                                                           .css('padding', '0.5em')
                                                           .position({my : "center center", at : "center center", of : window})
                                                           .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons')
                                                           .html('<br />Working...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process.</div>');

                                            // Submit the change
                                            var jqxhr = $.ajax(
                                                {
                                                    type : 'POST',
                                                    url : '<?php echo url('/forms/bia/delete-form'); ?>',
                                                    data : data,
                                                    dataType : 'html'
                                                })
                                                .done(function (data)
                                                {                               
                                                    console.log('Deletion was successful.');
                                                    
                                                    // Reload of refresh is specified                                                
                                                    location.reload();                                                
                                                })
                                                .fail(function (jqXHR, status, error)
                                                {                                                   
                                                    var response = jqXHR.responseText;
                                                    var errorData = $.parseJSON(response);
                                                    console.log(errorData);
                                                    alert ("There was an error deleting the record.\n\nThis page will be reloaded.");
                                                    location.reload();
                                                });              
                                        }
                            },
                            {
                                text : "Cancel",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-cancel'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />Are you sure you want to delete this form with ID = ' + record + '?<br /><br /><div class="ui-state-error" style="font-size: 10.5pt;"><span class="ui-icon ui-icon-alert box_icon"></span> <b>Warning</b><br />If you delete this form, it will no longer exist.</div>');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }
            else
            {
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 200,
                        width : 400,                    
                        title : 'Unable to Delete',
                        buttons: [                                
                            {
                                text : "Ok",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />You cannot delete this record.');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }

        });

    // Un-Delete/Restore form button
    $('.bia_undelete')
        .css({'width' : '16px',
              'height' : '16px',
              'margin-left' : '5px'})
        .button({ icons : { primary : 'ui-icon-arrowreturnthick-1-e'},
                  text : false})
        .click(function()
        {
            var button = $(this);

            var row = button.parents('tr');
            
            var original_background_color = row.css('background-color');            
            
            var record = row.attr('data-record');            

            var status = row.attr('data-status');

            row.css({'background-color':'yellow'});

            if (status == 'DEL')
            {                            
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 250,
                        width : 400,                    
                        title : 'Confirm Restoration',
                        buttons: [
                            {
                                text : "Restore",
                                'class' : "float_left",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {                                                       
                                            var data = { record : record };

                                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                                                 .appendTo('body');
                                  
                                            $('<div><div>').appendTo('body')
                                                           .css('width', '225px')
                                                           .css('height', '170px')
                                                           .css('text-align', 'center')
                                                           .css('padding', '0.5em')
                                                           .position({my : "center center", at : "center center", of : window})
                                                           .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons')
                                                           .html('<br />Working...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process.</div>');

                                            // Submit the change
                                            var jqxhr = $.ajax(
                                                {
                                                    type : 'POST',
                                                    url : '<?php echo url('/forms/bia/restore-form'); ?>',
                                                    data : data,
                                                    dataType : 'html'
                                                })
                                                .done(function (data)
                                                {                               
                                                    console.log('Restoration was successful.');
                                                    
                                                    // Reload
                                                    location.reload();                                                
                                                })
                                                .fail(function (jqXHR, status, error)
                                                {                                                   
                                                    var response = jqXHR.responseText;
                                                    var errorData = $.parseJSON(response);
                                                    console.log(errorData);
                                                    alert ("There was an error restoring the record.\n\nThis page will be reloaded.");
                                                    location.reload();
                                                });              
                                        }
                            },
                            {
                                text : "Cancel",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-cancel'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />Are you sure you want to restore this form with ID = ' + record + '?');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }
            else
            {
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 200,
                        width : 400,                    
                        title : 'Unable to Restore',
                        buttons: [                                
                            {
                                text : "Ok",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />You cannot restore this record because it has not been deleted.');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }

        });

    // Update form button
    $('.bia_update')
        .css({'width' : '16px',
              'height' : '16px',
              'margin-left' : '5px'})
        .button({ icons : { primary : 'ui-icon-arrowrefresh-1-s'},
                  text : false})
        .click(function()
        {
            var button = $(this);

            var row = button.parents('tr');
            
            var original_background_color = row.css('background-color');            
            
            var record = row.attr('data-record');            

            var status = row.attr('data-status');

            row.css({'background-color':'yellow'});

            if (status == 'PEND' || status == 'INSF')
            {                            
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 550,
                        width : 500,                    
                        title : 'Change Form Status',
                        buttons: [
                            {
                                text : "Received",
                                'class' : "float_left",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {                                                       
                                            var data = { record : record,
                                                         status : 'RECD'};

                                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                                                 .appendTo('body');
                                  
                                            $('<div><div>').appendTo('body')
                                                           .css('width', '225px')
                                                           .css('height', '170px')
                                                           .css('text-align', 'center')
                                                           .css('padding', '0.5em')
                                                           .position({my : "center center", at : "center center", of : window})
                                                           .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons')
                                                           .html('<br />Working...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process.</div>');

                                            // Submit the change
                                            var jqxhr = $.ajax(
                                                {
                                                    type : 'POST',
                                                    url : '<?php echo url('/forms/bia/update-form'); ?>',
                                                    data : data,
                                                    dataType : 'html'
                                                })
                                                .done(function (data)
                                                {                               
                                                    console.log('Update was successful.');
                                                    
                                                    // Reload
                                                    location.reload();                                                
                                                })
                                                .fail(function (jqXHR, status, error)
                                                {                                                   
                                                    var response = jqXHR.responseText;
                                                    var errorData = $.parseJSON(response);
                                                    console.log(errorData);
                                                    alert ("There was an error updating the record.\n\nThis page will be reloaded.");
                                                    location.reload();
                                                });              
                                        }
                            },
                            {
                                text : "Insufficient",
                                'class' : "float_left",
                                'style' : "margin-left: 97px;",
                                icons : { primary : 'ui-icon-circle-minus'},
                                click : function()
                                        {                                                       
                                            var data = { 'record' : record,
                                                         'status' : 'INSF',
                                                         'note' : $('[name="note"]').val().replace('\n','<br />')};

                                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                                                 .appendTo('body');
                                  
                                            $('<div><div>').appendTo('body')
                                                           .css('width', '225px')
                                                           .css('height', '170px')
                                                           .css('text-align', 'center')
                                                           .css('padding', '0.5em')
                                                           .position({my : "center center", at : "center center", of : window})
                                                           .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons')
                                                           .html('<br />Working...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process.</div>');

                                            // Submit the change
                                            var jqxhr = $.ajax(
                                                {
                                                    type : 'POST',
                                                    url : '<?php echo url('/forms/bia/update-form'); ?>',
                                                    data : data,
                                                    dataType : 'html'
                                                })
                                                .done(function (data)
                                                {                               
                                                    console.log('Update was successful.');
                                                    
                                                    // Reload
                                                    location.reload();                                                
                                                })
                                                .fail(function (jqXHR, status, error)
                                                {                                                   
                                                    var response = jqXHR.responseText;
                                                    var errorData = $.parseJSON(response);
                                                    console.log(errorData);
                                                    alert ("There was an error updating the record.\n\nThis page will be reloaded.");
                                                    location.reload();
                                                });             
                                        }
                            },
                            {
                                text : "Cancel",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-cancel'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />Use this window to update this form\'s status.<br /><br /><b>Received</b><br /><ul style="font-size: 9pt; margin-left: 20px;"><li>All of the paperwork is in order</li><li>No further information is needed from the assessor</li><li>The next phase is processing payment for this form</li></ul><br /><br /><b>Insufficient</b><br /><ul style="font-size: 9pt; margin-left: 20px;"><li>The form needs additional information or this form in incomplete</li><li>The assessor will be able to edit the form and resubmit</li><li>Once resubmitted, the from\'s status will change from INSF to PEND</li><li>Please provide a specific note below that will be sent to the assessor</li></ul><br /><textarea name="note" style="width: 100%;"></textarea><br /><br />After the form\'s status is changed, an e-mail will be sent to the assessor to this effect.');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }
            else
            {
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 200,
                        width : 400,                    
                        title : 'Unable to Update',
                        buttons: [                                
                            {
                                text : "Ok",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />You cannot update this record because it has not been submitted.');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }

        });

    // Pay form button
    $('.bia_pay')
        .css({'width' : '16px',
              'height' : '16px',
              'margin-left' : '5px'})
        .button({ icons : { primary : 'ui-icon-check'},
                  text : false})
        .click(function()
        {
            var button = $(this);

            var row = button.parents('tr');
            
            var original_background_color = row.css('background-color');            
            
            var record = row.attr('data-record');            

            var status = row.attr('data-status');

            row.css({'background-color':'yellow'});

            if (status == 'RECD')
            {                            
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 550,
                        width : 500,                    
                        title : 'Mark Payment',
                        buttons: [
                            {
                                text : "Received",
                                'class' : "float_left",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {                                                       
                                            var data = { record : record,
                                                         status : 'RECD'};

                                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                                                 .appendTo('body');
                                  
                                            $('<div><div>').appendTo('body')
                                                           .css('width', '225px')
                                                           .css('height', '170px')
                                                           .css('text-align', 'center')
                                                           .css('padding', '0.5em')
                                                           .position({my : "center center", at : "center center", of : window})
                                                           .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons')
                                                           .html('<br />Working...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process.</div>');

                                            // Submit the change
                                            var jqxhr = $.ajax(
                                                {
                                                    type : 'POST',
                                                    url : '<?php echo url('/forms/bia/update-form'); ?>',
                                                    data : data,
                                                    dataType : 'html'
                                                })
                                                .done(function (data)
                                                {                               
                                                    console.log('Update was successful.');
                                                    
                                                    // Reload
                                                    location.reload();                                                
                                                })
                                                .fail(function (jqXHR, status, error)
                                                {                                                   
                                                    var response = jqXHR.responseText;
                                                    var errorData = $.parseJSON(response);
                                                    console.log(errorData);
                                                    alert ("There was an error updating the record.\n\nThis page will be reloaded.");
                                                    location.reload();
                                                });              
                                        }
                            },
                            {
                                text : "Insufficient",
                                'class' : "float_left",
                                'style' : "margin-left: 97px;",
                                icons : { primary : 'ui-icon-circle-minus'},
                                click : function()
                                        {                                                       
                                            var data = { 'record' : record,
                                                         'status' : 'INSF',
                                                         'note' : $('[name="note"]').val().replace('\n','<br />')};

                                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                                                 .appendTo('body');
                                  
                                            $('<div><div>').appendTo('body')
                                                           .css('width', '225px')
                                                           .css('height', '170px')
                                                           .css('text-align', 'center')
                                                           .css('padding', '0.5em')
                                                           .position({my : "center center", at : "center center", of : window})
                                                           .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons')
                                                           .html('<br />Working...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process.</div>');

                                            // Submit the change
                                            var jqxhr = $.ajax(
                                                {
                                                    type : 'POST',
                                                    url : '<?php echo url('/forms/bia/update-form'); ?>',
                                                    data : data,
                                                    dataType : 'html'
                                                })
                                                .done(function (data)
                                                {                               
                                                    console.log('Update was successful.');
                                                    
                                                    // Reload
                                                    location.reload();                                                
                                                })
                                                .fail(function (jqXHR, status, error)
                                                {                                                   
                                                    var response = jqXHR.responseText;
                                                    var errorData = $.parseJSON(response);
                                                    console.log(errorData);
                                                    alert ("There was an error updating the record.\n\nThis page will be reloaded.");
                                                    location.reload();
                                                });             
                                        }
                            },
                            {
                                text : "Cancel",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-cancel'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />Use this window to update this form\'s status.<br /><br /><b>Received</b><br /><ul style="font-size: 9pt; margin-left: 20px;"><li>All of the paperwork is in order</li><li>No further information is needed from the assessor</li><li>The next phase is processing payment for this form</li></ul><br /><br /><b>Insufficient</b><br /><ul style="font-size: 9pt; margin-left: 20px;"><li>The form needs additional information or this form in incomplete</li><li>The assessor will be able to edit the form and resubmit</li><li>Once resubmitted, the from\'s status will change from INSF to PEND</li><li>Please provide a specific note below that will be sent to the assessor</li></ul><br /><textarea name="note" style="width: 100%;"></textarea><br /><br />After the form\'s status is changed, an e-mail will be sent to the assessor to this effect.');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }
            else
            {
                $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        modal : true,
                        height : 200,
                        width : 400,                    
                        title : 'Unable to Mark Payment',
                        buttons: [                                
                            {
                                text : "Ok",
                                'class' : "float_right",
                                'data-autofocus' : "true",
                                icons : { primary : 'ui-icon-check'},
                                click : function()
                                        {
                                            // Close the dialog box
                                            $(this).dialog("close");                           
                                        }
                            }
                        ],
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                dialog_object.html('<br />You cannot mark this record for a payment because this record because it has not been marked as received.');
                                
                                $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                                $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

                                $('[data-autofocus="true"]').focus();
                            },
                        close : function ()
                            {
                                var dialog_object = $(this);

                                row.css({'background-color':original_background_color});

                                $(dialog_object).remove();
                            }                
                    });
                
            }

        });
    
    // Gray out deleted forms
    $('tr[data-status="DEL"]')
        .css({'color' : '#aaaaaa'});


    /*
     * Make the table sortable
     */

    // Up and down sorting arrows
    var down_arrow = '<?php echo asset('/images/icons/bullet_arrow_up.png'); ?>';    
    var up_arrow = '<?php echo asset('/images/icons/bullet_arrow_down.png'); ?>';

    // Bind a click event to table headers that are sortable
    $('thead').on('click', 'th[data-sortable="true"]', function()
    {
        // Remove any sorting images
        $('th[data-sortable="true"] img').remove();
        
        // Get the table and the set of rows
        var table = $(this).parents('table').eq(0);
        var rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()));
        
        // Figure out sorting directions
        this.asc = !this.asc;
        var arrow = down_arrow;     
        if (!this.asc)
        {
            rows = rows.reverse();  
            arrow = up_arrow;       
        }

        // Recreate rows
        for (var i = 0; i < rows.length; i++)
        {
            table.append(rows[i]);
        }

        // Show sorting arrow
        $(this).append('<img src=\'' + arrow + '\' style=\'position: absolute;\' />');

        // Recolor the rows
        colorRows();
    });

    // Bind hover events to the table headers that are sortable
    $('thead').on('mouseover', 'th[data-sortable="true"]', function ()
    {
        $(this).css('cursor', 'pointer');
    });
    
    $('thead').on('mouseout', 'th[data-sortable="true"]', function ()
    {
        $(this).css('cursor', 'auto');
    });
    
    // Compare string values
    function comparer(index)
    {
        return function(a, b)
        {
            var valA = getCellValue(a, index);
            var valB = getCellValue(b, index);
            return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB);
        }
    }
    
    // Get a table cell's value
    function getCellValue(row, index)
    {
        var value = $(row).children('td').eq(index).html();

        // Remove dollar signs and commas from dollar amounts to help enforce numeric comparison
        if (value.match(/\$/))
        {
            value = value.replace(/(\$|,)/g, '');               
        }

        return value;
    }
    
    // Show/hide rows according to the view preferences
    var pref = $.parseJSON('<?php echo json_encode($info['view']); ?>');

    function viewPreferences()
    {           

        $('tbody tr').each(function ()
        {
            var row = $(this);

            var status = row.attr('data-status');            

            if (!pref[status])
            {                   
                row.hide();
            }
            else
            {
                row.show();                
            }
        });

        colorRows();
    }    

    viewPreferences();

    $('.status_step')
        .hover(function()
        {
            $(this).css({'cursor' : 'pointer',
                         'color' : '#E87A00'});
        },
        function()
        {
            $(this).css({'cursor' : 'pointer',
                         'color' : ''});
        })
        .click(function()
        {
            var item = $(this);

            var status = item.attr('data-status');
            var visible = pref[status];

            pref[status] = !visible;

            if (pref[status])
            {
                item.addClass('show');
            }
            else
            {
                item.removeClass('show');
                item.css({'color' : '#cccccc'});
            }

            // Save this user's view preferences
            var jqxhr = $.ajax(
                {
                    type : 'POST',
                    url : '<?php echo url('account/set-osaa-preference'); ?>',
                    data : { 'preference' : 'bia_visible_status',
                             'settings' : pref},
                    dataType : 'html'
                })
                .done(function (data)
                {                               
                    console.log('Preferences were successfully saved.');                    
                })
                .fail(function (jqXHR, status, error)
                {                                                   
                    var response = jqXHR.responseText;
                    var errorData = $.parseJSON(response);
                    console.log(errorData);                    
                }); 

            viewPreferences();
        })
        .each(function()
        {
            var item = $(this);

            var status = item.attr('data-status');
            var visible = pref[status];            

            if (visible)
            {
                item.addClass('show');                
            }
            else
            {
                item.removeClass('show');
                item.css({'color' : '#cccccc'});                
            }
        });

    // Assessor info
    $('.assessor')
        .hover(function ()
        {
            $(this).css({'cursor' : 'pointer',
                         'color' : '#005fa9',
                         'text-decoration' : 'underline'});
        },
        function ()
        {
            $(this).css({'color' : '',
                         'text-decoration' : ''});
        })
        .click(function()
        {
            var item = $(this);
            var assessor_name = item.text();
            var row = item.parents('tr');
            var record = row.attr('data-record');

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : false,
                    draggable : true,
                    resizable : true,
                    height : 250,                    
                    width : 500,
                    title : assessor_name + ', BIA Assessor Information',
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            dialog_object.html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");

                            var jqxhr = $.ajax(
                                      {
                                          type : 'GET',
                                          url : '<?php echo url('forms/bia/'); ?>/' + record + '/assessor-info',
                                          dataType : 'html'
                                      })
                                      .done(function (returned_data)
                                      {                               
                                          dialog_object.html(returned_data);
                                      })
                                      .fail(function (jqXHR, status, error)
                                      {                                                   
                                          var response = jqXHR.responseText;
                                          var errorData = $.parseJSON(response);
                                          console.log(errorData);
                                          alert ("There was an error looking up assessor information.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                           
                                      });                            
                            
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);

                            $(dialog_object).remove();
                        }                
                });
        });

    
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_functions'); ?>  	

    <?php /* <a href="#" class="help_button">Help</a> */ ?>    
    
    <div class="process_received">Payments &amp; Reports</div>

<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content'); ?>    		

 	<?php /*  Success Bar  */ ?>
 	<?php if (Session::has('success')): ?>
		<div class="success_bar">
			<div class="message">				
				<?php echo Session::get('success'); ?>
			</div>			
		</div>
	<?php endif; ?> 

    <?php /*  Errors  */ ?>
     <?php if (Session::has('errors')): ?>                
        <div class="error ui-state-error" style="font-weight: bold; padding: 1em;">
            <span class="ui-icon ui-icon-alert box_icon"></span>
            <?php foreach ($errors->all() as $error): ?>
                <?php echo $error; ?>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>   

    

    <h1><?php echo Session::get('year'); ?>-<?php echo intval(substr(Session::get('year'), 2, 2)) + 1; ?> Reconciliation Report Forms</h1>

    <?php /*  Form Status  */ ?>
    <div class="ui-corner-all status_progress">
        
        <div class="status_title">Form Count by Status</div>
        
        <?php foreach ($info['status_counts'] as $status => $count): ?>
            <div class="status_step" data-status="<?php echo $status; ?>">            
                <div class="slug"><?php echo $count; ?></div>
                <div class="name"><?php echo $status; ?></div>
            </div>
        <?php endforeach; ?>            
    
    </div>

    <?php if (count($info['forms']) > 0): ?>

        <table class="assessment_table">

            <thead>
                <tr>
                    <th data-sortable="true">ID #</th>
                    <th data-sortable="true">Status</th>
                    <th data-sortable="true">Assessor</th>
                    <th data-sortable="true">Total - $</th>
                    <th data-sortable="true">Created At</th>
                    <th data-sortable="true">Received At</th>
                    <th data-sortable="true">Paid At</th>
                    <th></th>
                </tr>
            </thead>

            <tbody>

                <?php foreach ($info['forms'] as $form): ?>

                    <tr data-record="<?php echo $form->id; ?>" data-status="<?php echo $form->status; ?>">
                        <td><?php echo $form->id; ?></td>
                        <td><?php echo $form->status; ?></td>
                        <td><span class="assessor"><?php echo $form->user->getDisplayFullName(); ?></span></td>
                        <td>$<?php echo number_format($form->total_amount, 2); ?></td>
                        <td><?php echo $form->created_at; ?></td>
                        <td><?php echo $form->received_at; ?></td>
                        <td><?php echo $form->paid_at; ?></td>
                        <td style="text-align: right; padding-right: 5px;">
                            <?php if (Helpers::strEqual($form->status, array('PEND', 'INSF', 'RECD', 'DONE'))): ?>
                                <div class="bia_print"></div>
                            <?php endif; ?>                                        
                            <?php if (!Helpers::strEqual($form->status, 'DEL')): ?>
                                <div class="bia_edit"></div>
                            <?php endif; ?>
                            <?php if (Helpers::strEqual($form->status, array('PEND', 'INSF'))): ?>
                                <div class="bia_update"></div>
                            <?php endif; ?>
                            <?php if (Helpers::strEqual($form->status, array('RECD'))): ?>
                                <div class="bia_pay"></div>
                            <?php endif; ?>
                            <?php if (Helpers::strEqual($form->status, 'DEL')): ?>
                                <div class="bia_undelete"></div>
                            <?php else: ?>
                                <div class="bia_delete"></div>
                            <?php endif; ?>
                        </td>
                    </tr>

                <?php endforeach; ?>

            </tbody>

        </table>                                       

    <?php else: ?>
        There are no BIA Assessment Reconciliation Report forms on record to display.
    <?php endif; ?>        

    <br class="clear" />
<?php $__env->stopSection(); ?>
