"use strict";
appCore.controller("AccountListCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", function ($state, $scope, $http, $timeout, vServices) {
  $scope.$root.page.title = "List of Account";
  $scope.accounts = [];
  $scope.getPercent = (p, aObj) => {
    const total = parseFloat(aObj.partialHoursBillable) + parseFloat(aObj.partialHoursNonBillable);
    return total > 0 ? parseInt((parseFloat(p) / total) * 100) : '50-light';
  };

  const init = function () {
    let countAllocationProj = [];
    vServices.callApi("allocation/allocationByAccount/", "GET", {}).then((res3) => {
      if (res3) {
        countAllocationProj = res3;
      }
    });
    vServices.callApi("allocation/all_accounts", "GET", {}).then(function (res) {
      if (res && res.length > 0) {
        res.forEach(element => {
          element.allocationData=countAllocationProj.filter(x=>x.accId==element.accountDetails.accountid);
          let a,b;
          a=element.partialHoursNonBillable?parseFloat(element.partialHoursNonBillable):0;
          b=element.partialHoursBillable?parseFloat(element.partialHoursBillable):0;
          element.totalAllocation = a+b;
         });
        $scope.accounts = res;
        $scope.$root.callDataTable("#accountList");
      }
    });
  };
  init();
}]);



