Skip to content

Commit

Permalink
OO#160 a delivery can only be created once. If try a second time, the…
Browse files Browse the repository at this point in the history
… server will send an error
  • Loading branch information
mcmpp committed Jun 4, 2024
1 parent 4984471 commit 6c8fa1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 18 additions & 6 deletions app/scripts/abotypen/detail/lieferungen/lieferungen.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ angular.module('openolitor-admin')
return $scope.lieferungen !== undefined;
};


$scope.addLieferung = function() {
if ($scope.datumExistiert($scope.template.datum)) {
return;
Expand All @@ -38,7 +39,12 @@ angular.module('openolitor-admin')
vertriebId: $scope.selectedVertrieb.id
});
newModel.$save();
$scope.template.creating = $scope.template.creating + 1;
var newModel = {
daten: [$scope.template.datum],
abotypId: parseInt($routeParams.id),
vertriebId: $scope.selectedVertrieb.id
};
$scope.setupFlagToKnowIfCreating(newModel,[$scope.template.datum]);
$scope.template.datum = undefined;
$scope.status.open = false;
};
Expand Down Expand Up @@ -87,6 +93,14 @@ angular.module('openolitor-admin')
});
}

$scope.setupFlagToKnowIfCreating = function(lieferungenModel,uniqueLieferdaten){
$http.get(appConfig.get().API_URL +
'abotypen/' + lieferungenModel.abotypId + '/vertriebe/' + lieferungenModel.vertriebId + '/allesLieferungen', lieferungenModel).then(function(result) {
var allLieferungenDates = lodash.map(result.data, function(l){return l.datum.getFullYear() + '' + ("0" + (l.datum.getMonth() + 1 )).slice(-2) + '' + ("0" + l.datum.getDate()).slice(-2)});
var dateFormatUniqueLieferdaten = lodash.map(uniqueLieferdaten, function(d){return d.getFullYear() + '' + ("0" + (d.getMonth() + 1 )).slice(-2) + '' + ("0" + d.getDate()).slice(-2)})
$scope.template.creating = $scope.template.creating + dateFormatUniqueLieferdaten.length - lodash.intersectionWith(dateFormatUniqueLieferdaten, allLieferungenDates,lodash.isEqual).length;
});
};

$scope.generateLieferungen = function(lieferdaten) {
var uniqueLieferdaten = lodash.filter(lieferdaten, function(datum) {
Expand All @@ -100,11 +114,9 @@ angular.module('openolitor-admin')
$http.post(appConfig.get().API_URL +
'abotypen/' + newModel.abotypId + '/vertriebe/' + newModel.vertriebId +
'/lieferungen/aktionen/generieren',
newModel).then(function() {
$scope.template.creating = $scope.template.creating +
lieferdaten
.length;
});
newModel).then(function(){
$scope.setupFlagToKnowIfCreating(newModel,uniqueLieferdaten);
});
};

$scope.canGenerateLieferungen = function() {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/abotypen/detail/lieferungen/lieferungen.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="panel panel-default">
<div class="panel-heading clearfix">
<h3 class="panel-title"><span translate>Lieferungen</span>
<span class="pull-right" ng-show="showLoading()"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i></span>
<span class="pull-right" ng-show="loading || template.creating > 0"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i></span>
</h3>
</div>
<div class="panel-body">
Expand All @@ -17,7 +17,7 @@ <h3 class="panel-title"><span translate>Lieferungen</span>
<div class="col-md-8">
<label for="lieferungen" translate>Geplante Lieferdaten</label>
</div>
<div class="col-md-4" ng-if="!showLoading()">
<div class="col-md-4" ng-if="!loading && !template.creating > 0">
<div class="pull-right">
<div uib-dropdown class="dropdown inline" is-open="status.open">
<a role="button" href="" class="btn btn-sm btn-default" uib-dropdown-toggle><span class="glyphicon glyphicon-plus"></span> </a>
Expand Down

0 comments on commit 6c8fa1c

Please sign in to comment.