现金报告仅显示当天的一个事件

时间:2013-12-22 11:06:25

标签: php mysql report

我已经创建了一个现金报告(进/出钱),但每天只有一个事件。例如:如果我在同一日期添加2个通风口,则报告只显示一个。怎么了。我需要展示所有的活动。这就是代码:(抱歉,有些声音是意大利语)

<?
require "../include/impostazioni.php";
require "../include/funzioni.php"; 

$id_condominio = $_REQUEST['id_condominio'];
$periodo = $_REQUEST['periodo'];
$data = $_REQUEST['data']; 
$saldo = 0;


list($giorno, $mese, $anno) = explode("/",$data);
$nuova_data = strtotime($anno."-".$mese."-".$giorno);

$data_inizio = date("d/m/Y",strtotime("- ".$periodo." months", $nuova_data));

list($giorno, $mese, $anno) = explode("/",$data);
$data1 = $anno."-".$mese."-".$giorno;

list($giorno, $mese, $anno) = explode("/",$data_inizio);
$data2 = $anno."-".$mese."-".$giorno;

$giorni = stampaGiorniTraDate($data2, $data1);

list($anno, $mese, $giorno) = explode("-",$giorni[0]);
$giorno = $giorno."/".$mese."/".$anno;
?>



<div class="widget">
<div class="whead"><h6>Estratto conto - Dal <?echo $data_inizio." al ".$data; ?></h6>      </div>
<div id="anagrafe_table" class="shownpars">
  <a class="tOptions act" title="Options"><img src="images/icons/options.png" alt="" /> </a>
   <table cellpadding="0" cellspacing="0" border="0" id="tab_estratto_conto">
     <thead>
        <tr>
          <th>Data</th>
          <th>Operazione</th>
          <th>Importo</th>
          <th>Saldo</th>
          <th style="display:none;"></th>
        </tr>
      </thead>
      <tbody>
      <?
        if($giorni != ""){

          foreach($giorni as $giorno_ok){
            list($a, $m, $g) = explode("-",$giorno_ok);
            $giorno = $g."/".$m."/".$a;
            $entrata = getEntrataByData($giorno_ok,$id_condominio);
            $uscita = getUscitaByData($giorno_ok,$id_condominio);


            if($entrata != ""){
              $nome_condomino = getCondominoByIdEntrata($entrata[0]['id']);
              $saldo += (float) $entrata[0]['importo_versato'];
            ?>
              <tr class="gradeX">
                <td class="center"><?echo $giorno;?></td>
                <td class="center"><?echo $nome_condomino[0]['nome_cognome'];?></td>
                <td class="center"><b><?echo "&euro; ".$entrata[0]['importo_versato'];?></b></td>
                <td class="center"><?echo "&euro; ".$saldo;?></td>
                <td style="display:none;"><?echo $giorno_ok;?></td>
              </tr>
          <?}
             if($uscita != ""){ 
              $importo = (float) $uscita[0]['importo_netto'] + (float) $uscita[0]['importo_accessori'];
              $saldo -= (float) $importo;
             ?>
              <tr class="gradeX">
                <td class="center"><?echo $giorno;?></td>
                <td class="center"><?echo $uscita[0]['beneficiario'];?></td>
                <td class="center"><b><span style="color:#BD021F;"><?echo "- &euro; ".$importo;?></span></b></td>
                <td class="center"><?echo "&euro; ".$saldo;?></td>
                <td style="display:none;"><?echo $giorno_ok;?></td>
              </tr>
          <?}?>

        <?}?>
      <?}?>
    </tbody>
  </table> 

使用的功能:

 // Find a money add for date
function getEntrataByData($data,$id_condominio){
 $sql = "SELECT * FROM entrate WHERE data = '".$data."' AND id_condominio = '".$id_condominio."'";
 $r = executeQuery($sql);
 return $r;
  }


// Find money out for date
function getUscitaByData($data,$id_condominio){
 $sql = "SELECT * FROM uscite WHERE data = '".$data."' AND id_condominio = '".$id_condominio."'"; 
   $r = executeQuery($sql);
   return $r;
    }

函数stampaGiorniTraDate:

function stampaGiorniTraDate($sStartDate, $sEndDate){  
// Firstly, format the provided dates.  
// This function works best with YYYY-MM-DD  
// but other date formats will work thanks  
// to strtotime().  
$sStartDate = date("Y-m-d", strtotime($sStartDate));  
$sEndDate = date("Y-m-d", strtotime($sEndDate));  

// Start the variable off with the start date  
$aDays[] = $sStartDate;  

// Set a 'temp' variable, sCurrentDate, with  
// the start date - before beginning the loop  
$sCurrentDate = $sStartDate;  

// While the current date is less than the end date  
while($sCurrentDate < $sEndDate){  
  // Add a day to the current date  
  $sCurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));  

  // Add this new day to the aDays array  
  $aDays[] = $sCurrentDate;  
}  

// Once the loop has finished, return the  
// array of days.  
return $aDays;  
}

0 个答案:

没有答案