2015-03-31 69 views
0

我想在我的網站中添加一些統計數據,我想每個月顯示我的收入,當汽車從租金回報(當天:預期回報月)。 我想計算每個月的收入(租賃價格)總額(預期退貨日期),有人可以幫助我,我該怎麼做? enter image description here計算一個數組在php中的總數CakePHP

,這是查看/位置/ admin_index.ctp:


 
<div class="row" > 
 
<!--<meta http-equiv="refresh" content="5; URL=http://dhafer.com/admin/locations">--> 
 
     
 
    <div class="col-lg-12"> 
 
               
 
     <h1 class="page-header" style="font-family: Kaushan Script';">Administrator<small> Locations management</small></h1> 
 
      <ol class="breadcrumb"> 
 
       <li class="active"> 
 
        <i class="fa fa-car"></i> Locations 
 
       </li> 
 
      </ol> 
 
    
 
     <div class="panel panel-default"> 
 
          
 
          
 
       <div class="panel-heading" style="font-family: Kaushan Script';"><h3> Locations </h3></div> 
 

 
        <div class="table-responsive"> 
 

 
         <table class="table table-bordered table-hover table-striped" style="font-family: 'Montserrat';"> 
 
           <thead> 
 
            <tr > 
 
            \t 
 

 

 

 
\t \t \t \t \t \t \t \t \t \t <th class="actions"><?php echo __('Actions'); ?></th> 
 
\t \t \t \t \t \t \t \t \t \t <th><?php echo $this->Paginator->sort('id'); ?></th> 
 
\t \t \t \t \t \t \t \t \t \t <th><?php echo $this->Paginator->sort('status'); ?></th> 
 
\t \t \t \t \t \t \t \t \t \t <th><?php echo $this->Paginator->sort('departure_date'); ?></th> 
 
\t \t \t \t \t \t \t \t \t \t <th><?php echo $this->Paginator->sort('expected_return_date'); ?></th> 
 
\t \t \t \t \t \t \t \t \t \t <th><?php echo $this->Paginator->sort('user_id'); ?></th> 
 
\t \t \t \t \t \t \t \t \t \t <th><?php echo $this->Paginator->sort('agency_id'); ?></th> 
 
\t \t \t \t \t \t \t \t \t \t <th><?php echo $this->Paginator->sort('car_id'); ?></th> 
 
        <th class="actions"><?php echo __('Decision'); ?></th> 
 
        <th ><?php echo __('Days'); ?></th> 
 
        <th ><?php echo __('Rental price '); ?></th> 
 
             
 
             
 
            </tr> 
 
           </thead> 
 
           <tbody> 
 
           
 
           
 

 
            
 
            <?php foreach ($locations as $location): ?> 
 
            \t <tr class="<?php if($location['Location']['status']== '0'):echo "danger";else: echo "success";endif; ?>" style="color:black;"> 
 
            <td class="actions"> 
 
        <?php echo $this->Html->link(' <i class="fa fa-eye" style="color:black;"></i>', array('action' => 'view', $location['Location']['id']),array('class'=>'btn-sm btn-sousse','escape' => false)); ?> 
 
              
 

 
              <?php echo $this->Html->link('<i class="fa fa-pencil-square-o" style="color:white;"></i>', array('action' => 'edit', $location['Location']['id']),array('class'=>'btn-sm btn-primary','escape' => false)); ?> 
 
              
 
      <?php echo $this->Html->link('<i class="fa fa-times-circle" style="color:white;"></i>', array('action' => 'delete', $location['Location']['id']),array('class'=>'btn-sm btn-slama','escape' => false), array(), __('Are you sure you want to delete # %s?', $location['Location']['id'])); ?> 
 
             </td> 
 
             <td style="font-family: 'Montserrat';"><?php echo $this->Html->link($location['User']['id'], array('controller' => 'users', 'action' => 'view', $location['User']['id'])); ?></td> 
 
             <td style="font-family: 'Montserrat';"> 
 
<?php 
 
        if($location['Location']['status'] != 0){ 
 
        echo __('Accepted');}else{ 
 
        echo __('Waiting response'); 
 
        } 
 
        ?> 
 
             </td> 
 
             <td style="font-family: 'Montserrat';"><?php echo h($location['Location']['departure_date']); ?></td> 
 
             
 
             <td style="font-family: 'Montserrat';"><?php echo h($location['Location']['expected_return_date']); ?></td> 
 
             <td style="font-family: 'Montserrat';"><?php echo h($location['User']['first_name']); ?></td> 
 
             
 
             <td style="font-family: 'Montserrat';"><?php echo $this->Html->link($location['Agency']['name'], array('controller' => 'agencies', 'action' => 'view', $location['Agency']['id'])); ?></td> 
 
             
 
             
 
             
 
             <td style="font-family: 'Montserrat';"><?php echo $this->Html->link($location['Car']['title'], array('controller' => 'cars', 'action' => 'view', $location['Car']['id'])); ?></td> 
 
             <td style="font-family: 'Montserrat';"> 
 
<?php 
 
        if($location['Location']['status'] != 0){ 
 
        echo $this->Html->link( "Delete", array('action'=>'delete', $location['Location']['id']),array('class'=>'btn btn-danger'));}else{ 
 
        echo $this->Html->link( "Accept", array('action'=>'activate', $location['Location']['id']),array('class'=>'btn btn-success')); 
 
        } 
 
        ?> 
 
             </td> 
 
<td style="font-family: 'Montserrat';"> 
 
             <?php 
 

 

 
    
 

 
$temp1=$location['Location']['expected_return_date']; 
 
$temp2 = $location['Location']['departure_date']; 
 

 
$date1 = new DateTime($temp1); 
 
$date2 = new DateTime($temp2); 
 

 
$diff=$date1->diff($date2); 
 
$days=$diff->format('%a days'); 
 
echo $days ; 
 

 
    
 

 

 
    ?></td><td style="font-family: 'Montserrat';"> 
 
     
 
    <?php 
 

 

 
      echo '$ '.$location['Car']['price'] * $days; 
 

 

 
     ;?> 
 
    </td> 
 
             
 
            </tr> 
 

 
           <?php endforeach; ?> 
 
            
 
           
 
           </tbody> 
 
          </table> 
 
          <p> 
 
          <?php 
 
          echo $this->Paginator->counter(array(
 
          'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}') 
 
          )); 
 
          ?> </p> 
 
          <div class="paging"> 
 
          <?php 
 
           echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled')); 
 
           echo $this->Paginator->numbers(array('separator' => '')); 
 
           echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled')); 
 
          ?> 
 
          </div> 
 
        </div> 
 
       </div> 
 
       <?php echo $this->Html->link(' <i class="fa fa-rss-square fa-1x" style="color:orange;"></i>', array('action' => 'admin_getlocations.xml'),array('class'=>'btn-lg btn-default','escape' => false)); ?> 
 
       </div> 
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
      </div> 
 

 

 

 

 
<script type="text/javascript"> 
 
//setTimeout(function(){ 
 
    //window.location.reload(1); 
 
//}, 10000); 
 

 

 
</script>

有人能幫助我嗎?

回答

0

我相信你應該通過執行SUM()COUNT()帶日期/時間函數的查詢來統計控制器中的統計信息(除非你想要每頁)。有很多非常強大的功能可以幫助你計算日期間隔。

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html

(我假設你用mysql或者類似的東西。)

請添加一些相關的DB-結構,所以我可以幫助你建立一個查詢。