2016-08-18 3 views
1

Я строю проект с угловыми и php. У меня есть опция «выбрать», где я выбираю конкретную дату, и она показывает мне все детали в таблице и рассчитывает на несколько вещей, и все отлично работает. но когда я выбираю дату, я хочу, чтобы она показывала все результаты по конкретному месяцу, а не по конкретной дате (например, -> теперь я выбираю дату, подобную этому - «2016-4-15», она даст мне всю информацию, относящуюся к эту дату, а не месяц, как мне нужно). может кто-то помочь? в моей базе данных значение даты - дата.как фильтровать даты с угловыми?

Php запрос:

$query=" SELECT `description` ,`total_price` , `name`,`supplier_id`,`date` FROM `suppliers`,`expenses` 
    where `supplier_id` = `refer_supplier_id` "; 

Html:

<select ng-model="supplierExpenses.selectedOption" ng-change="setTotals(supplierExpenses)" 
     ng-options = "item.date for item in supplierExpenses | 
     unique:'date'" > 

     <option value="">בחר תאריך</option> 
     </select> 



<div class="table-responsive"> 
<table class="customer-list table table-striped" > 
      <thead> 
       <tr > 

        <th class="Column-Header">מספר ספק</th> 
        <th class="Column-Header">שם ספק</th> 
        <th class="Column-Header">כמות מוצרים שנקנו</th> 
        <th class="Column-Header">מחיר הוצאה</th> 

       </tr> 
      </thead> 
      <tbody> 
       <tr ng-repeat="item in supplierExpenses" ng-if = "item.date == supplierExpenses.selectedOption.date" 
        > 

        <td>{{item.supplier_id}}</td> 
        <td>{{item.name}}</td> 
        <td>{{item.description}}</td> 
        <td>{{item.total_price}}</td> 

       </tr> 
      </tbody> 
      <tfoot> 

       <tr class="bg-warning"> 
        <td><font size="6">סה"כ הוצאות</font></td> 
        <td><font size="6">{{totalExpenses}}</font></td> 
        <td></td> 
       </tr> 
      </tfoot> 

     </table> 


</div> 

Контроллер:

"use strict"; 
angular.module('dataSystem').controller('supplierExpensesCtrl', function ($scope, $route, $location, $http) { 
    $http({method:'GET', url:'api/reports-tab/supplier-expenses-by-mounth.php/'}) 
     .then(function(response) { 
     var arr = JSON.parse(JSON.parse(response.data)); 
     $scope.supplierExpenses = arr; 
     }) 

     // This will log you the error code and trace, if there is an error. 
     .catch(function(err) { 
     console.log('err', err) 
     }); 

     $scope.totalExpenses = 0; 
     $scope.setTotals = function(totalItem){ 
     $scope.totalExpenses = 0; 
     for(var item =0; item< totalItem.length; item++){ 
      // console.log(totalItem[item]); 
      if (totalItem[item] && (totalItem[item].date == $scope.supplierExpenses.selectedOption.date)){ 

      $scope.totalExpenses += parseInt(totalItem[item].total_price); 
      } 
     } 
    } 
}); 
+0

Вы хотите «GROUP BY month» или 'WHERE row.date = @ month'? покажите нам пример данных текущего и ожидаемого результата. Пожалуйста, прочитайте [** How-to-Ask **] (http://stackoverflow.com/help/how-to-ask) \t \t И вот отличное место для [** START **] (http : //spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/), чтобы узнать, как улучшить качество вопроса и получить лучшие ответы. –

+0

@JuanCarlosOropeza благодарит за советы. Я хочу выбрать месяц и получить все данные за этот конкретный месяц. – tanyaa

+0

Возможный дубликат [Как фильтровать по месяцам в AngularJs с фильтром] (http://stackoverflow.com/questions/29241696/how-to-filter-by -month-in-angleularjs-with-filter) –

ответ

1

Привет рад вам удастся с общей ^^ я изменить мой ответ с рабочим раствором для дата выпуска

$http({method:'GET', url:'api/reports-tab/supplier-expenses-by-mounth.php/'}) 
     .then(function(response) { 
      var arr = JSON.parse(JSON.parse(response.data)), month, date; 
      for(var i = 0; i< arr.length; i++){ 
       date = new Date(arr[i].date); //we convert the string into javascript date 
       month = date.getMonth()+1; 
       if(month.length === 1){ 
        month = '0'+month; //we add a 0 if needed 
       } 
       var year = date.getFullYear(); 
       arr[i].date = month+'/'+year; //we use only the month and year 
      } 
      $scope.supplierExpenses = arr; 

     }) 
+0

эй !! Спасибо, я попробую сейчас – tanyaa

+0

это не работает :(таблица отображается без меня, выбирая дату. – tanyaa

+0

можете ли вы добавить функцию formatedDate(), чтобы увидеть, что может быть неправильным? – DMCISSOKHO

Смежные вопросы