[WIP] 🚧 deduplicate products in view
This commit is contained in:
parent
986eef7b99
commit
bd483ac877
|
@ -32,8 +32,49 @@
|
|||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="new-display">
|
||||
|
||||
<h2>new display without duplicates:</h2>
|
||||
<button class="btn btn-warning" ng-click="removeAll()">
|
||||
<i class="fa fa-trash"></i> enlever Tout
|
||||
</button>
|
||||
<div ng-repeat="group in activeSellingFiltered track by $index">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<div class="input-group">
|
||||
<input type="text" ng-model="group.name">
|
||||
<!--<span class="btn btn-warning input-group-addon remove-item"-->
|
||||
<!--ng-click="removeProductGroup(group.id)">-->
|
||||
<!--<i class="fa fa-trash"></i>-->
|
||||
<!--</span>-->
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4 text-right">
|
||||
<strong>
|
||||
<!--<input type="number" ng-model="p.price">-->
|
||||
{{group.unitPrice}}
|
||||
€ </strong>
|
||||
<span class="badge badge-default" ng-if="group.count">
|
||||
<i class="fa fa-times"></i> {{group.count}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4 text-right">
|
||||
|
||||
|
||||
<strong>
|
||||
<!--<input type="number" ng-model="p.price">-->
|
||||
{{group.totalPrice}}
|
||||
€ </strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="old-display">
|
||||
|
||||
<h2>old display:</h2>
|
||||
|
||||
<div ng-repeat="p in activeSelling track by $index">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
|
@ -52,6 +93,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* test to import things
|
||||
*/
|
||||
export class DashboardStuff{
|
||||
sayHi(){
|
||||
console.log('hiiiiiiii! from dashboard stuff');
|
||||
}
|
||||
sayHo(){
|
||||
console.log('hoooo');
|
||||
}
|
||||
};
|
|
@ -15,6 +15,8 @@ $(document).ready(function () {
|
|||
console.log('hello console for main.js');
|
||||
var stuff = ['initialstuff'];
|
||||
|
||||
|
||||
// TODO split controllers in other files
|
||||
angular
|
||||
.module('caisse', [])
|
||||
.controller('CaisseCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
|
||||
|
@ -34,6 +36,7 @@ angular
|
|||
};
|
||||
$scope.activeItemsSold = []; // list of products ID to sell
|
||||
$scope.activeSelling = []; // list of products to sell
|
||||
$scope.activeSellingFiltered = []; // list of products to sell
|
||||
$scope.activeFestival = { // an event where selling take place
|
||||
id: null,
|
||||
name: "le festival",
|
||||
|
@ -42,6 +45,43 @@ angular
|
|||
clientsCount: 0,
|
||||
commentaire: ""
|
||||
};
|
||||
/**
|
||||
* deduplicate the active selling items in the view,
|
||||
* show a count for each of them when there are more than one
|
||||
*/
|
||||
$scope.refreshDeduplicateSellings = () => {
|
||||
let soldObjectsIdsCount = {}
|
||||
$scope.activeSellingFiltered = {};
|
||||
console.log("$scope.activeSelling", $scope.activeSelling);
|
||||
console.log("#####refreshDeduplicateSellings $scope.activeSelling", $scope.activeSelling);
|
||||
|
||||
$scope.activeSelling.forEach(elem => {
|
||||
let groupId = elem.id;
|
||||
let group = soldObjectsIdsCount[groupId];
|
||||
console.log("elem.price", elem.price);
|
||||
if (group) { // sort elements by the product id corresponding
|
||||
console.log("add to total", group.totalPrice);
|
||||
group.count++;
|
||||
group.totalPrice += (elem.price * 1);
|
||||
group.sellings.push(elem);
|
||||
console.log("total is now", group.totalPrice);
|
||||
} else {
|
||||
|
||||
soldObjectsIdsCount[groupId] = {
|
||||
groupId: groupId,
|
||||
count: 1,
|
||||
name: elem.name,
|
||||
unitPrice: elem.price * 1,
|
||||
totalPrice: elem.price * 1,
|
||||
sellings: [elem],
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log("#####refreshDeduplicateSellings soldObjectsIdsCount", soldObjectsIdsCount);
|
||||
$scope.activeSellingFiltered = soldObjectsIdsCount;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get the sum of products prices
|
||||
* @param list
|
||||
|
@ -70,6 +110,7 @@ angular
|
|||
$scope.activeItemsSold.push(obj.id);
|
||||
}
|
||||
$scope.paidAmount += $scope.sumOfList($scope.activeSelling);
|
||||
|
||||
};
|
||||
$scope.stuff = stuff;
|
||||
$scope.setActiveSelling = function (selling) {
|
||||
|
@ -87,6 +128,7 @@ angular
|
|||
$scope.activeSelling.push(product);
|
||||
$scope.activeItemsSold.push(product.id);
|
||||
$scope.regenActiveSellingIds();
|
||||
$scope.refreshDeduplicateSellings();
|
||||
};
|
||||
/**
|
||||
* remove from current sell list
|
||||
|
@ -95,6 +137,12 @@ angular
|
|||
$scope.removeProduct = function (product, index) {
|
||||
product.stockCount++;
|
||||
$scope.activeSelling.splice($index, 1);
|
||||
$scope.regenActiveSellingIds();
|
||||
$scope.refreshDeduplicateSellings();
|
||||
};
|
||||
$scope.removeAll = function () {
|
||||
|
||||
$scope.activeSelling = [];
|
||||
$scope.regenActiveSellingIds()
|
||||
};
|
||||
$scope.pauseSelling = function () {
|
||||
|
@ -189,6 +237,7 @@ angular
|
|||
},
|
||||
data: lesParams // pass in data as strings
|
||||
}).then(function (rep) {
|
||||
activeSelling
|
||||
$scope.clearCurrentSelling();
|
||||
// if successful, bind success message to message
|
||||
$scope.successMessage = rep.data.message;
|
||||
|
|
Loading…
Reference in New Issue