--- /dev/null
+'use strict';
+
+alloWebadminControllers
+ .controller('CustomerListCtrl', ['$scope', '$routeParams', '$http', 'Customer',
+ function ($scope, $routeParams, $http, Customer) {
+ $scope.customers = [];
+ $scope.customersPerPage = 20;
+ $scope.itemsPerPage = $scope.customersPerPage;
+ $scope.orderProp = 'name';
+ getResultsPage(1);
+
+ $scope.pagination = {
+ current: 1
+ };
+
+ $scope.pageChanged = function() {
+ getResultsPage($scope.pagination.current);
+ };
+
+ function getResultsPage(pageNumber) {
+ var offset = (pageNumber-1)*$scope.customersPerPage;
+ if(offset == null || offset == undefined || offset < 0) {
+ offset = 0;
+ }
+ Customer.all({limit: $scope.customersPerPage, offset: offset}).$promise.then(function(data) {
+ $scope.customers = data;
+ });
+ Customer.nb().$promise.then(function(data) {
+ $scope.totalCustomers = data;
+ $scope.totalItems = $scope.totalCustomers.result;
+ });
+ }
+ }])
+ .controller('CustomerDetailCtrl', ['$scope', '$routeParams', '$http', 'Customer', 'Appliance', 'Product',
+ function ($scope, $routeParams, $http, Customer, Appliance, Product) {
+ $scope.contracts = [];
+ $scope.appliances = [];
+ $scope.products = [];
+ $scope.appliancesChangelog = [];
+ $scope.previousPage = {
+ message: "Liste des clients",
+ url: "/#/customers"
+ };
+ getAll();
+
+ function getAll() {
+ //noinspection JSUnresolvedVariable
+ Customer.info({id: $routeParams.customer_id}).$promise.then(function(data) {
+ $scope.customer = data.result;
+ $scope.message = data.message;
+ $scope.retour = data.retour;
+ //noinspection JSUnresolvedVariable
+ $scope.sugarLink = "http://"+$scope.sugar_fqdn+"/index.php?module=Accounts&action=DetailView&record="+data.result.sugar_id;
+ getContractsForCustomer(data.result);
+ getAppliancesForCustomer(data.result);
+ getProducts();
+ });
+ }
+
+ $scope.applianceDeleted = function(id) {
+ Appliance.delete({id: id}).$promise.then(function(data) {
+ $scope.response = data;
+ getAll();
+ });
+ };
+
+ function getContractsForCustomer(customer) {
+ //noinspection JSUnresolvedVariable
+ Customer.get_contracts({ap_id: customer.ap_id}).$promise.then(function(data) {
+ $scope.contracts[customer.id] = data;
+ for(var item in $scope.contracts[customer.id].result) {
+ //noinspection JSUnfilteredForInLoop,JSUnresolvedVariable
+ var contract = $scope.contracts[customer.id].result[item],
+ dateOptions = {timeZone:'UTC', year: "numeric", month: "numeric", day: "numeric"},
+ sugar_id = contract.sugar_id,
+ dirty_state = contract.state;
+ contract.start_date = new Date(contract.start_date).toLocaleDateString("fr-FR", dateOptions);
+ contract.end_date = new Date(contract.end_date).toLocaleDateString("fr-FR", dateOptions);
+ contract.sugarLink = "http://"+$scope.sugar_fqdn+"/index.php?module=maint_contrat_maintenance&action=DetailView&record="+sugar_id;
+ contract.state = dirty_state.replace(/[&\/\\#,+()$~%^.'":*?<>{}]/g,'');
+ }
+ });
+ }
+
+ function getAppliancesForCustomer(customer) {
+ Customer.get_appliances({customer_id: customer.id}).$promise.then(function(data) {
+ $scope.appliances[customer.id] = data;
+ if(data.result.length > 0) {
+ for(var item in data.result) {
+ //noinspection JSUnfilteredForInLoop
+ getChangelogForAppliance(data.result[item]);
+ }
+ } else {
+ getChangelogForAppliance(data.result);
+ }
+ });
+ }
+
+ function getProducts() {
+ Product.all().$promise.then(function(data) {
+ $scope.products = data;
+ });
+ }
+
+ function getChangelogForAppliance(appliance) {
+ Appliance.get_changelog({id: appliance.id}).$promise.then(function(data) {
+ $scope.appliancesChangelog[appliance.id] = data;
+ for(var item in data.result) {
+ //noinspection JSUnfilteredForInLoop
+ var applianceChangelog = $scope.appliancesChangelog[appliance.id].result[item],
+ dateOptions = {timeZone:'UTC', year: "numeric", month: "numeric", day: "numeric"};
+ applianceChangelog.creation_date = new Date(applianceChangelog.creation_date.replace(/-/g,"/")).toLocaleDateString("fr-FR", dateOptions);
+ }
+ });
+ }
+ }]
+ );
\ No newline at end of file