<?php
$array_months = array('1' => 'January','2' => 'February','3' => 'March','4' => 'April','5' => 'May','6' => 'June','7' => 'July ','8' => 'August','9' => 'September','10' => 'October','11' => 'November','12' => 'December');
// $array_payment_methods = ["1" => 'Cash',"2" => 'Cheque',"3" => 'Credit card',"4" => 'Online banking',"5" => 'Club Membership',"6" => 'Complementary',"7" => 'Replacement',"8" => 'Invoice'];

$paymentMethods_display = unserialize(paymentMethods_display);
?>
<link rel="stylesheet" href="<?php echo base_url();?>assets/js/validationEngine.jquery.css" type="text/css" />
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/cust_paginition.css" type="text/css" />
<div class="layout-app">
    <div class="container">
        <div class="row row-app">
            <div class="col-md-12">
                <div class="col-md-12">
                    <div style="clear: both"></div>
                    <br />
                    <?php
					$disply = 'display:none;';
					if(count($_GET) > 0){
						$disply = 'display:block;';
					}
				?>
                    <div class="widget allMagazines">
                        <div class="widget-head">
                            <h4 class="heading">Finance Reports</h4>
                        </div>
                        <div class="widget-body innerAll inner-2x" style="display: inline-block;">
                            <?php $this->load->view('admin/flashdata_admin'); ?>
                            <form action="" method="POST" onsubmit="return fp_validation();">
                                <table class="table table-white table-vertical-center margin-none footable" align="left">
                                    <tr>
                                        <td class="col-sm-2" style="vertical-align:top !important;">
                                            Payment Method
                                            <select class="form-control" name="fb_payment_method" id="fb_payment_method">
                                                <option value="">Select One</option>
                                                <?php
											foreach ($paymentMethods_display as $payment_method_id => $payment_method) {
												echo '<option value="'.$payment_method_id.'"'; 
												echo ($this->input->post('fb_payment_method') == $payment_method_id) ? ' selected ="selected " ' : '';
												echo '>'.$payment_method.'</option>';
											}
										   ?>
                                            </select>
                                            <span class="text-danger" style="color:red;"></span>
                                        </td>
                                        <td class="col-sm-2" style="vertical-align:top !important;">
                                            Year
                                            <select class="form-control" name="fb_year" id="fb_year">
                                                <option value="">Select One</option>
                                                <?php
										   for ($i=2015; $i <= 2025; $i++) { 
												echo '<option value="'.$i.'"'; 
												echo ($this->input->post('fb_year') == $i) ? ' selected ="selected " ' : '';
												echo '>'.$i.'</option>';
										   }
										   ?>
                                            </select>
                                            <span class="text-danger" style="color:red;"></span>
                                        </td>
                                        <td class="col-sm-2" style="vertical-align:top !important;">
                                            From Month
                                            <select class="form-control" name="fb_from_month" id="fb_from_month">
                                                <option value="">Select One</option>
                                                <?php
											foreach ($array_months as $month_number => $month_name) {
												echo '<option value="'.$month_number.'"';
												echo ($this->input->post('fb_from_month') == $month_number) ? ' selected ="selected " ' : '';
												echo '>'.$month_name.'</option>';
											}
										   ?>
                                            </select>
                                            <span class="text-danger" style="color:red;"></span>
                                        </td>
                                        <td class="col-sm-2" style="vertical-align:top !important;">
                                            To Month
                                            <select class="form-control" name="fb_to_month" id="fb_to_month">
                                                <option value="">Select One</option>
                                                <?php
											foreach ($array_months as $month_number => $month_name) {
												echo '<option value="'.$month_number.'"'; 
												echo ($this->input->post('fb_to_month') == $month_number) ? ' selected ="selected " ' : '';
												echo '>'.$month_name.'</option>';
											}
										   ?>
                                            </select>
                                            <span class="text-danger" style="color:red;"></span>
                                        </td>
                                        <td class="col-sm-4" style="vertical-align:top !important;">
                                            Campaign name
                                            <select class="form-control" name="fb_campaign_id" id="fb_campaign_id">
                                                <option value="">Select One</option>
                                                <?php
											foreach ($campaigns as $key => $campaign) {
												echo '<option value="'.$campaign['id'].'"'; 
												echo ($this->input->post('fb_campaign_id') == $campaign['id']) ? ' selected ="selected " ' : '';
												echo '>'.$campaign['name'].'</option>';
											}
										   ?>
                                            </select>
                                            <span class="text-danger" style="color:red;"></span>
                                        </td>
                                    </tr>
                                    <tr>     
                                        <td style="border: 0px;" colspan="5">
                                            &nbsp; <button type="submit" class="btn btn-primary" >SEARCH</button>
                                        </td>
                                    </tr>
                                    <?php  if($displayDownload == 1 ){ 


									$downloadLink = base_url().'index.php/postings/excelFinanceReports/?pm='.$pm.'&y='.$y.'&fm='.$fm.'&tm='.$tm.'&cid='.$cid;
									?>
                                    <tr>
                                        <td colspan="5">
                                            <a href="<?php echo $downloadLink;?>" class="btn btn-info downloadLink pull-right">Download</a>
                                        </td>
                                    </tr>
                                    <?php } else {  ?>
                                    <tr>
                                        <td>
                                            <?php echo $noData;?>
                                        </td>
                                    </tr>
                                    <?php }  ?>
                                </table>
                            </form>
                            <!-- <table class="table"> -->
                            	<div >
                            	<?php if($displayDownload == 1 ){

                            		echo $table;
                            	}?>
                            	</div>
                               <!--  <thead>
                                    <tr>
							<th>Campaign name</th>
							<th>Payment Method</th>
							<th>Payment Date</th>
								<?php

								// foreach ($magazineCodes as $key => $magazineCode) {
								// 	echo '<th>';
								// 		echo $magazineCode['magazine_code'];
								// 	echo '</th>';
								// }

								?>
							</tr> -->
                                <!-- </thead>
                                <tbody> -->
                                    <?php //if($displayDownload == 1 ){


          //                           foreach ($magazineCodes as $key => $magazineCode) {

										// $snCount = 1;
										// $transactionDate = [];  
				      //           		$transactionAmount = 0;

				      //           		foreach ($transactionsListings as $transactionsListing) {
				      //           			if($transactionsListing['magazine_code'] == $magazineCode['magazine_code']) {
				      //           				$transactionDate[] = $transactionsListing['transaction_date'];
				      //           			}
						    //             }


						    //             $transactionDate = array_unique($transactionDate);

						    //             foreach ($transactionDate as $date) {
						    //                 $dayAmount = 0;
						    //                 foreach ($transactionsListings as $transactionsListing) {
						    //                     if($transactionsListing['transaction_date'] == $date && $transactionsListing['magazine_code'] == $magazineCode['magazine_code']) {
						    //                         $dayAmount += $transactionsListing['amount'];
						    //                     }
						    //                 }

						    //                 	echo '<tr>';
										// 		  echo '<td>'.$transactionsListing['campaign_name'].'</td>';
										// 		  echo '<td>'.$array_payment_methods[$this->input->post('fb_payment_method')].'</td>';
										// 		  echo '<td>'.date('d M Y', strtotime($date)).'</td>';
										// 		  echo '<td>'.$dayAmount.'</td>';
										// 		echo '<tr>';
						    //             }

						    //         }
									 ?>
                                    <?php //} ?>
                                <!-- </tbody> -->
                        </div>
                    </div>
                </div>
                <hr />
            </div>
        </div>
        <script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script>
        <script src="<?php echo base_url();?>assets/js/custom.js" type="text/javascript"></script>
        <script src="<?php echo base_url();?>assets/plugins/forms_elements_multiselect/js/jquery.multi-select.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
        <script src="<?php echo base_url();?>assets/plugins/forms_elements_bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
        <script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.js"></script>
        <script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.init.js"></script>
        <script src="<?php echo base_url();?>assets/components/forms_elements_fuelux-radio/fuelux-radio.init.js"></script>
        <script src="<?php echo base_url();?>assets/components/forms_elements_multiselect/multiselect.init.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
        <script src="<?php echo base_url();?>assets/js/jquery.validationEngine-en.js" type="text/javascript"></script>
        <script src="<?php echo base_url();?>assets/js/jquery.validationEngine.js" type="text/javascript"></script>
        <script src="<?php echo base_url(); ?>assets/js/subscriber.js"></script>
        <script>
        $(function() {

            $('#fb_payment_method, #fb_year, #fb_from_month, #fb_to_month, #fb_campaign_id').change(function() {
                $('.downloadLink').hide();
            });
        });

        function fp_validation() {

            var fb_payment_method = $('#fb_payment_method').val();
            var fb_year = $('#fb_year').val();
            var fb_from_month = $('#fb_from_month').val();
            var fb_to_month = $('#fb_to_month').val();
            var fb_campaign_id = $('#fb_campaign_id').val();

            $('#fb_payment_method').next('span').text('');
            $('#fb_year').next('span').text('');
            $('#fb_from_month').next('span').text('');
            $('#fb_to_month').next('span').text('');
            $('#fb_campaign_id').next('span').text('');

            var form_errors = 0;

            if (fb_payment_method == '') {
                $('#fb_payment_method').next('span').text('Payment Method is required.');
                form_errors = 1;
            }
            if (fb_year == '') {
                $('#fb_year').next('span').text('Year is required.');
                form_errors = 1;
            }
            if (fb_from_month == '') {
                $('#fb_from_month').next('span').text('From Month is required.');
                form_errors = 1;
            }
            if (fb_to_month == '') {
                $('#fb_to_month').next('span').text('To Month is required.');
                form_errors = 1;
            }
            if (fb_campaign_id == '') {
                $('#fb_campaign_id').next('span').text('Campaign is required.');
                form_errors = 1;
            }

            if (parseInt(fb_from_month) > parseInt(fb_to_month)) {
                $('#fb_to_month').next('span').text('Invalid Month');
                form_errors = 1;
            }

            if (form_errors == 1) {
                return false;
            }


        }
        </script>