<div class="content_title">Wszystkie rozliczenia afiliantów</div>
<?php
    $lata = $all_faktury_seo;

	if(!empty($lata))
	{
		$controler = $this->uri->segment(1);
		$function = $this->uri->segment(2);
		$param = $this->uri->segment(3);

		if(@$_POST['year']!=null)
		{
			$this->session->set_userdata('rok', $_POST['year']);
			$rok = $this->session->userdata['rok'];
		}
		else
		{
			if (empty($this->session->userdata['rok']))
			{
				$this->session->set_userdata('rok', date("Y"));
				$rok = date("Y");
			}
			else
			{
				$rok = $this->session->userdata['rok'];
			}
		}

        if(@$_POST['month']!=null)
		{
			$this->session->set_userdata('month', $_POST['month']);
			$month = $this->session->userdata['month'];
		}
		else
		{
			if (empty($this->session->userdata['month']))
			{
				$this->session->set_userdata('month', date("m"));
				$month = date("m");
			}
			else
			{
				$month = $this->session->userdata['month'];
			}
		}

		$rok_array = array();
        $month_array = array();

		foreach($lata as $f)
		{
			if(!in_array($f['year'],$rok_array)) $rok_array[]=$f['year'];
            if(!in_array($f['month'],$month_array)) $month_array[]=$f['month'];
		}

        asort($month_array);

		echo '<form action="/'.$controler.'/'.$function.'/'.$param.'" method="post">';
		echo '<table cellspacing="6">';
		echo '<tr><td><b>Zmień rok: </b>';
		echo '<select name="year">';
			  foreach($rok_array as $r)
			  {
				  echo '<option value="'.$r.'"';
				  if ($r==$rok) echo 'selected="selected"';
				  echo '>'.$r.'</option>';
			  }
		echo '</select>';
		echo '</td><td>';
		echo '<input type="submit" value="wybierz" /> (aktualnie ustawiony rok '.$rok.')';
		echo '</td></tr></table>';
		echo '</form><br />';

        echo '<form action="/'.$controler.'/'.$function.'/'.$param.'" method="post">';
		echo '<table cellspacing="6">';
		echo '<tr><td><b>Zmień miesiąc: </b>';
		echo '<select name="month">';
			  foreach($month_array as $r)
			  {
				  echo '<option value="'.$r.'"';
				  if ($r==$month) echo 'selected="selected"';
				  echo '>'.$r.'</option>';
			  }
		echo '</select>';
		echo '</td><td>';
		echo '<input type="submit" value="wybierz" /> (aktualnie ustawiony miesiac '.$month.')';
		echo '</td></tr></table>';
		echo '</form><br />';
	}


   // print_r($month_array);
	//print_r($faktury_seo);

	$this->config->load('global_settings');
	$global_settings = $this->config->item('global_settings');
	$ilosc_dni_na_oplacenie = $global_settings['faktury_seo']['ilosc_dni_na_zaplacenie_faktury'];

?>
<script type="text/javascript">$(function() {$("#tabs").tabs();});</script>

<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Rozliczenia afiliantów za dany miesiąc</a></li>
	</ul>
	<div id="tabs-1">
		<?php
        //print_r($faktury_seo);
        $faktury_seo = $this->baza_payments->get_all_afiliant_factures_period($month,$rok);
       // print_r($faktury_seo);
			foreach($faktury_seo as $f)
			{
               $nr_tmp = '';

               if(!empty($f['nr'])) $nr_tmp = $f['nr'];
               else $nr_tmp = $f['numer_wlasny'];

				if($f['typ']=='Firma')
                {
                    if($f['typ_dostarczenia']=='online')
                        echo '<div class="oplac_fakture"><a href="/payments/faktura_ksiegowosc_pdf_afiliant/'.$f['faktura_id'].'/'.$f['afiliant_id'].'" target="_blank"><img src="/files/pdf.gif" alt="" border="0" align="left" />&nbsp; &nbsp;Faktura nr <b>'.$nr_tmp.'</b><br />&nbsp; &nbsp;'.$f['nazwa'].', '.$f['imie'].' '.$f['nazwisko'].', '.$f['telefon'].', '.$f['email'].'</a></div>';
                    else
                        echo '<div class="oplac_fakture"><a href="/payments/faktura_ksiegowosc_pdf_afiliant/'.$f['faktura_id'].'/'.$f['afiliant_id'].'" target="_blank"><img src="/files/pdf.gif" alt="" border="0" align="left" />&nbsp; &nbsp;Faktura dostarczana samodzielnie<br />&nbsp; &nbsp;'.$f['nazwa'].', '.$f['imie'].' '.$f['nazwisko'].', '.$f['telefon'].', '.$f['email'].'</a></div>';
                }
                else
                    echo '<div class="oplac_fakture"><a href="/payments/rachunek_ksiegowosc_pdf_afiliant/'.$f['faktura_id'].'/'.$f['afiliant_id'].'" target="_blank"><img src="/files/pdf.gif" alt="" border="0" align="left" />&nbsp; &nbsp;Raport nr <b>'.$nr_tmp.'</b><br />&nbsp; &nbsp;'.$f['imie'].' '.$f['nazwisko'].', '.$f['telefon'].', '.$f['email'].'</a></div>';
			}
		?>
	</div>
</div>