<?php
    $season_name = array(
        'F' => 'Fall',
        'W' => 'Winter',
        'S' => 'Spring'
    );
?>


<!DOCTYPE html>
<html lang="en">

    <!-- HTML Head -->
    <head>

        <!-- Page Title -->
        <title>OSAA Invoice</title>      
        
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

        <!-- Style -->
        <style type="text/css" media="screen,print">
            
            /* Default Margins and Paddings */
            * {margin: 0; padding: 0;}

            /* No image borders by default */
            img {border: none;}

            /* Page Body */
            html, body {               

                /*width: 2550px;*/
                width: 8in;
                /*height: 3300px;*/
                height: 10.5in;

                font-family: Trebuchet MS, Helvetica, sans-serif;
                font-size: 12pt;                
                
                color: #000000;
                background: #ffffff;

                border: 1px solid white;
            }            

            .full {width: 100%;}
            .half {width: 50%;}
            .quarter {width: 25%;}

            .text_left {text-align: left;}
            .text_right {text-align: right;}
            .text_center {text-align: center;}
            .text_justify {text-align: justify;}

            .italic {font-style: italic;}            
            
            table { border-collapse: collapse; }

            #page {
                width: 8in;
                height: 10.5in;
                margin: 0;
                padding: 0;
                position: relative;
                page-break-after: always;
            }

            #header img {
                width: 1in;
                position: absolute;
                top: 0.25in;
                left: 1px;
            }

            #header .header_address {
                position: absolute;
                top: 0.25in;
                left: 1.1875in;
                font-size: 10pt;
                line-height: 105%;
            }

            #header .invoice_imprint {
                position: absolute;
                top: 0.25in;
                right: 0;
                font-size: 42pt;
                line-height: 36pt; 
            }

            #header .invoice_data table {
                position: absolute;
                top: 0.8in;
                right: 0;
                font-size: 9pt;
                border: 1px solid black;
            }

            #header .invoice_data table thead tr {
                background-color: #d8d8d8;
            }

            #header .invoice_data table thead th {
                width: 1.1in;
                border-bottom: 1px solid black;
                border-right: 1px solid black;
            }

            #header .invoice_data table tbody td {
                text-align: center;
                line-height: 0.25in;                
            }

            #header .invoice_title {
                position: absolute;
                top: 1.35in;
                left: 0;
                font-size: 18pt; 
            }

            #address_window {
                position: absolute;
               
                /*border: 1px solid black;*/
                /*border-radius: 0.25in;*/

                width: 4.5in;
                height: 1.125in;

                top: 1.8125in;
                left: -0.125in;
            }

            #address {
                margin: 0.1875in 0 0 0.875in;
                font-size: 11pt;
                line-height: 105%;
            }

            #invoice_alert {
                position: absolute;
                top: 0.40in;
                transform: rotate(-90deg);
                font-size: 9pt;
                left: 0.25in;
                letter-spacing: 3px;
                padding-bottom: 5px;
                text-decoration: underline;
            }

            #top_sign_note {
                position: absolute;
               
                border: 2px solid black;  
                border-radius: 2px;              
                width: 2.5in;
                height: 0.625in;

                top: 2in;
                right: 0;

                font-size: 11pt;                
                line-height: 110%;

                padding: 0.125in 0.125in 0 0.125in;

                text-align: justify;

                background-color: #d8d8d8;
            }

            #fold_line {
                position: absolute;
                top: 3.375in;
                width: 8in;

                height: 3px;

                border-top: 3px solid black;

                border-bottom: 1px solid black;
            }

            #section_line {
                
                margin: 0.25in auto 0.25in auto;

                width: 6in;

                border-bottom: 1px solid black;
            }

            #invoice_body {
                position: relative;
                top: 3.6in;
                width: 8in;
            }

            #school_info_bar {
                position: relative;
                top: -0.10in;                
                width: 8in;
                font-size: 11pt;
                font-weight: bold;
            }

            #fee_table {
                border-collapse: collapse;
                width: 8in;                
                font-size: 10pt;
            }

            #fee_table thead th {
                text-align: left;
                font-size: 11pt;                
                color: #ffffff;
                background-color: #000000;
            }

            
            .check_box {
                width: 0.125in;
                height: 0.125in;
                border: 1px solid black;
                border-radius: 2px;
                position: relative;
                left: -0.0625in;
                top: 0.025in;
                display: inline-block;
            }

            .check_box.filled {
                background-image: url('http://www.osaa.org/images/icons/check_2_16px.png');                
                background-repeat: no-repeat;
                background-size: 12px 12px;
            }

            #regulations_agreement {
                margin-top: 0.125in;
                font-size: 8pt;
                padding: 0 0.125in;
                text-align: justify;
                position: absolute;
                top: 4in;
            }          

            #return_note {
                text-align: left;
                font-weight: bold;
                margin: 0.1875in 0 0.1875in 0;
                padding: 0.0625in 0.125in;
                background-color: #d8d8d8;
                font-size: 10pt;
                position: absolute;
                width: 7.75in;
                top: 6in;
            }
            
        </style>


        <script type="text/javascript">
            $(document).ready(function ()
            {
                  

            });                

        </script>        
                
    </head>

    <body>               

        <?php foreach ($objects as $object): ?>

        <div id="page">                      

            <div id="header">
                
                <img src="http://www.osaa.org/images/logos/OSAACircleBWjpg.jpg" />                

                <div class="header_address">
                    Oregon School Activities Association<br />
                    25200 SW Parkway Ave, Suite 1<br />
                    Wilsonville OR &nbsp;97070<br />
                    <br />
                    (503) 682-6722<br />
                    Fax: (503) 682-0960
                </div>

                <div class="invoice_imprint">
                    INVOICE
                </div>

                <div class="invoice_data">
                    <table>
                        <thead>
                            <tr>
                                <th>Date</th>
                                <th>Reference #</th>                                
                                <th>Invoice #</th>
                            </tr>
                        </thead>    

                        <tbody>
                            <tr>
                                <td style="border-right: 1px solid black;">
                                    <?php echo date('F j, Y', time()); ?>
                                </td>
                                <td style="border-right: 1px solid black;">
                                    <?php echo $object->invoice->number; ?>
                                </td>
                                <td></td>
                            </tr>   
                        </tbody>
                    </table>
                </div>

                <div class="invoice_title">
                    Fines for OSAA <?php echo $object->invoice->school_year; ?>-<?php echo substr(intval($object->invoice->school_year) + 1, 2, 2); ?> <?php echo $season_name[$season]; ?> Season Ejections
                </div>

            </div>         

            <div id="address_window">
                <div id="invoice_alert">
                    INVOICE
                </div>

                <div id="address">
                    Athletic Department<br />
                    <?php echo $object->school->name; ?><br />
                    <?php echo $object->address->line_1; ?><br />
                    <?php if (!Helpers::strIsEmpty($object->address->line_2)): ?>
                        <?php echo $object->address->line_2; ?><br />
                    <?php endif; ?>
                    <?php echo $object->address->city; ?>, <?php echo $object->address->state; ?> <?php echo $object->address->zip; ?>                    
                </div>
            </div>

            <div id="top_sign_note">
                Refer to the summary below for total amount. Please remit payment within <b><u>30 days</u></b>.*
            </div>            

            <div id="fold_line"></div>

            <div id="invoice_body">

                <div id="school_info_bar">
                    <table>
                        <tr>
                            <td style="width: 5in;">                                
                                <?php echo $object->school->name; ?>
                            </td>

                            <td style="width: 1.5in;">
                                <?php echo $season_name[$season]; ?> Season
                            </td>

                            <td style="width: 1.5in;">
                                Total Ejections: <?php echo $object->data->count; ?>
                            </td>
                        </tr>
                    </table>
                </div>  

                <div style="text-align: center; font-size: 12pt; margin: 0;">
                    - Summary of Ejections -
                </div>                              

                <div style="width: 8in; margin: 0 auto; margin-bottom: 1em; text-align: center; font-size: 9pt;">

                    Your school had the following ejections during this season.  These ejections are final and cannot be waived.

                </div>

            
                <table id="fee_table">
                    <thead>
                        <tr>                            
                            <th style="width: 0.25in;">#</th>
                            <th>ID Number</th>
                            <th>Level - Individual - Reason</th>
                            <th>Date</th>
                            <th>Notes</th>
                            <th style="text-align: right; padding-right: 4px;">Fine</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php foreach ($object->data->ejections as $sport => $ejections): ?>

                            <?php
                                // Skip sports with no ejections
                                if (count($ejections) == 0)
                                {
                                    continue;
                                }

                                $sub_total = 0.0;
                            ?>

                            <tr>
                                <td colspan="6"><b><?php echo Helpers::getActivityName($sport); ?> (<?php echo count($ejections); ?>)</b></td>
                            </tr>

                            <?php foreach ($ejections as $ejection): ?>

                                <tr>
                                    <td><?php echo $ejection->number; ?>.</td>
                                    <td><?php echo $ejection->id; ?></td>
                                    <td><?php echo $ejection->level; ?> - <?php echo $ejection->type; ?> <?php echo $ejection->name; ?> - <?php echo $ejection->reason; ?></td>
                                    <td><?php echo date('n/j/y', strtotime($ejection->date)); ?></td>
                                    <td>
                                        <?php if ($ejection->appealed): ?>
                                            Appealed - 
                                            <?php if ($ejection->granted): ?>
                                                Granted
                                            <?php elseif (!$ejection->fine): ?>
                                                Denied, No Fine
                                            <?php else: ?>
                                                Denied                                                
                                            <?php endif; ?>
                                        <?php elseif (!$ejection->fine): ?>
                                            No Fine
                                        <?php endif; ?>

                                        <?php if ($ejection->last): ?>
                                            (Last Contest)
                                        <?php endif; ?>
                                    </td>
                                    <td style="text-align: right;">$<?php echo number_format($ejection->amount, 2, '.', ','); ?></td>
                                </tr>           

                                <?php
                                    $sub_total += $ejection->amount;
                                ?>                     

                            <?php endforeach; ?>

                            <tr>
                                <td colspan="3" style="border-top: 1px solid #999999;"></td>
                                <td colspan="3" style="border-top: 1px solid #999999; text-align: right;"><?php echo Helpers::getActivityName($sport); ?> sub-total: $<?php echo number_format($sub_total, 2, '.', ','); ?></td>
                            </tr>
                            <tr>
                                <td colspan="6">&nbsp;</td>
                            </tr>

                        <?php endforeach; ?>
                    </tbody>
                </table>
            

                <div style="width: 6in; margin: 0 auto; font-size: 11pt; text-align: right; margin-top: 0.0625in; line-height: 1.75em;">                    
                    
                    <b>Total Amount Due:</b>
                    <div style="display: inline-block; width: 1.5in; text-align: right;">
                        <div style="display: inline-block; width: 100px;">
                            <b>$<?php echo number_format($object->invoice->total_amount, 2, '.', ','); ?></b>
                        </div>
                    </div>    

                    <br />                

                </div>               

                <div id="regulations_agreement">
                    <b>OSAA Executive Board Policy 20: Ejection Policies - Fines</b><br />
                    A. Schools shall be assessed fines for ejections within specific sports programs.  Each sport (e.g., Football, Boys Basketball, Softball) shall be tracked as separate and distinct for the purpose of calculating fines.  When the first participant or coach in a sport is ejected, the school that the participant or coach is representing shall be assessed a $50 fine by the Executive Board.  A second ejection in the same sport during the same season shall result in the assessment of a $100 fine, and each ejection thereafter in that sport during that season shall result in a fine to be increased by $50 increments for each ejection without limitation.
                    <br /><br />
                    <div style="margin-left: 0.25in;">
                        1) <b>EXCEPTION</b>:  The fine for an ejection in the last contest of the season shall be increased by $100 over the greater of the standard fine described above or the most recent fine for that program.<br /><br />
                        2) <b>EXCEPTION</b>:  Soccer Player:  A soccer player who is disqualified because he or she "deliberately handles a ball to prevent it from going into the goal" or "receives two cautions (yellow cards)" shall not be subject to the fine specified in this and other OSAA ejection policies, but shall be subject to the specified suspension.
                    </div>
                    <br />
                    B. A school receiving five or more ejections during one school year shall be required to attend a sportsmanship training class and submit a written Plan of Correction to the OSAA, including timelines for implementation of the Plan.   
                </div>                                

                <div id="return_note">
                    <div style="float: left; font-size: 14pt; margin-right: 0.125in;">*</div> 
                    <div style="float: left; width: 3.5in; margin-right: 1in;">
                        Please make check payable to "Oregon School Activities Association".  Send payment within 30 days to the following address:
                    </div>
                    

                    OSAA<br />
                    25200 SW Parkway Ave Ste 1<br />
                    Wilsonville, OR 97070
                    
                </div>

                             

            </div>

        </div>        

        <?php endforeach; ?>

    </body>    
</html>   
