foca-crear-nota-pedido.js
25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
angular.module('focaCrearNotaPedido', ['ngRoute', 'ui.bootstrap', 'focaModalVendedores',
'focaBusquedaProductos', 'focaModalPetroleras', 'focaBusquedaCliente'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/venta-nota-pedido/crear', {
controller: 'notaPedidoListaCtrl',
templateUrl: 'nota-pedido-lista.html'
});
}])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/venta-nota-pedido/abm', {
controller: 'notaPedidoCtrl',
templateUrl: 'nota-pedido.html'
});
}]);
angular.module('focaCrearNotaPedido')
.controller('notaPedidoCtrl',
[
'$scope',
'$uibModal',
'$location',
'crearNotaPedidoService',
function($scope, $uibModal, $location, crearNotaPedidoService) {
$scope.notaPedido = {};
$scope.articulosTabla = [];
var idLista;
var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
$scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1);
crearNotaPedidoService.getPrecioCondicion().then(
function(res) {
$scope.precioCondiciones = res.data;
}
);
if (notaPedidoTemp != undefined) {
notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
$scope.notaPedido = notaPedidoTemp;
$scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
$scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
idLista = $scope.notaPedido.precioCondicion;
crearNotaPedidoService.getArticulosByIdNotaPedido($scope.notaPedido.id).then(
function(res) {
$scope.articulosTabla = res.data;
}
);
crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
function(res) {
$scope.notaPedido.domicilio = res.data;
}
)
} else {
$scope.notaPedido.fechaCarga = new Date();
$scope.notaPedido.domicilio = [{ id: 0 }]
$scope.notaPedido.bomba = '1';
$scope.notaPedido.flete = '1';
idLista = undefined;
}
$scope.addNewDom = function() {
$scope.notaPedido.domicilio.push({ 'id': 0 });
}
$scope.removeNewChoice = function(choice) {
if ($scope.notaPedido.domicilio.length > 1) {
$scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1)
}
}
$scope.crearNotaPedido = function() {
var total = 0;
for (var i = $scope.articulosTabla.length - 1; i >= 0; i--) {
total += $scope.articulosTabla[i].precio * $scope.articulosTabla[i].cantidad;
}
var notaPedido = {
id: 0,
precioCondicion: $scope.notaPedido.precioCondicion,
fechaCarga: $scope.notaPedido.fechaCarga,
vendedor: $scope.notaPedido.vendedor,
cliente: $scope.notaPedido.cliente,
producto: $scope.notaPedido.producto,
bomba: $scope.notaPedido.bomba,
petrolera: $scope.notaPedido.petrolera,
domicilio: $scope.notaPedido.domicilio,
kilometros: $scope.notaPedido.kilometros,
jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB,
costoFinanciacion: $scope.notaPedido.costoFinanciacion,
flete: $scope.notaPedido.flete,
costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete,
total : total
}
crearNotaPedidoService.crearNotaPedido(notaPedido).then(
function(res) {
$location.path('/venta-nota-pedido/crear');
}
)
var articulosNotaPedido = $scope.articulosTabla;
for(var i = 0; i< articulosNotaPedido.length;i++) {
crearNotaPedidoService.crearArticulosParaNotaPedido(articulosNotaPedido[i]).then(
function(res) {
return;
}
)
}
}
$scope.siguienteTab = function() {
$scope.active = 1;
}
$scope.seleccionarArticulo = function() {
if (idLista == undefined) {
alert('primero seleccione una lista de precio y condicion');
return;
}
var modalInstance = $uibModal.open(
{
ariaLabelledBy: 'Busqueda de Productos',
templateUrl: 'modal-busqueda-productos.html',
controller: 'modalBusquedaProductosCtrl',
resolve: { idLista: function() { return idLista } },
size: 'lg'
}
)
modalInstance.result.then(
function(producto) {
var newArt =
{
id: 0,
codigo: producto.FiltroSectorCodigo,
item: $scope.articulosTabla.length + 1,
nombre: producto.descripcion,
precio: producto.precio,
costoUnitario: producto.costo,
cantidad: 1
}
$scope.articulosTabla.unshift(newArt);
}, function() {
// funcion ejecutada cuando se cancela el modal
}
);
}
$scope.seleccionarVendedor = function() {
var modalInstance = $uibModal.open(
{
ariaLabelledBy: 'Busqueda de Vendedores',
templateUrl: 'modal-vendedores.html',
controller: 'modalVendedoresCtrl',
size: 'lg'
}
)
modalInstance.result.then(
function(vendedor) {
$scope.notaPedido.vendedor = vendedor.NomVen;
}, function() {
}
);
}
$scope.seleccionarPetrolera = function() {
var modalInstance = $uibModal.open(
{
ariaLabelledBy: 'Busqueda de Petrolera',
templateUrl: 'modal-petroleras.html',
controller: 'modalPetrolerasCtrl',
size: 'lg'
}
)
modalInstance.result.then(
function(petrolera) {
$scope.notaPedido.petrolera = petrolera.NOM;
}, function() {
}
);
}
$scope.seleccionarCliente = function() {
var modalInstance = $uibModal.open(
{
ariaLabelledBy: 'Busqueda de Cliente',
templateUrl: 'foca-busqueda-cliente-modal.html',
controller: 'focaBusquedaClienteModalController',
size: 'lg'
}
)
modalInstance.result.then(
function(cliente) {
$scope.notaPedido.cliente = cliente.nom;
}, function() {
}
);
}
$scope.obtenerDomicilios = function(id) {
crearNotaPedidoService.getDomicilios(id).then(
function(res) {
$scope.notaPedido.domicilio = res.data;
}
)
}
$scope.getSubTotal = function(item) {
var subTotal = 0;
var array = $scope.articulosTabla.filter(a => a.item <= item);
for (var i = 0; i < array.length; i++) {
subTotal += array[i].precio * array[i].cantidad
}
return subTotal.toFixed(2);
}
$scope.cargarArticulos = function() {
idLista = $scope.notaPedido.precioCondicion;
$scope.articulosTabla = [];
}
}
]
)
.controller('notaPedidoListaCtrl', [
'$scope',
'crearNotaPedidoService',
'$location',
function($scope, crearNotaPedidoService, $location) {
crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
$scope.notaPedidos = datos.data;
});
$scope.editar = function(notaPedido) {
crearNotaPedidoService.setNotaPedido(notaPedido);
$location.path('/venta-nota-pedido/abm/');
}
$scope.crearPedido = function() {
crearNotaPedidoService.clearNotaPedido();
$location.path('/venta-nota-pedido/abm/');
}
}
])
angular.module('focaCrearNotaPedido')
.service('crearNotaPedidoService', ['$http', 'API_ENDPOINT',function($http, API_ENDPOINT) {
var route = API_ENDPOINT.URL;
var notaPedido;
return {
crearNotaPedido: function(notaPedido) {
return $http.post(route + '/nota-pedido', {notaPedido: notaPedido});
},
obtenerNotaPedido: function() {
return $http.get(route +'/nota-pedido');
},
setNotaPedido: function(notaPedido) {
this.notaPedido = notaPedido;
},
clearNotaPedido: function() {
this.notaPedido = undefined;
},
getNotaPedido: function() {
return this.notaPedido;
},
getArticulosByIdNotaPedido: function(id) {
return $http.get(route+'/articulos/nota-pedido/'+id);
},
crearArticulosParaNotaPedido: function(articuloNotaPedido) {
return $http.post(route + '/articulos/nota-pedido', {articuloNotaPedido});
},
getDomiciliosByIdNotaPedido: function(id) {
return $http.get(route +'/nota-pedido/'+id+'/domicilios');
},
//EN DESARROLLO
getDomicilios: function(id) {
// return $http.get(route + '/'+id)
var domicilio = [
{
id: 1,
dom: 'RISSO PATRON 781'
},
{
id: 2,
dom: 'MARIANO MORENO 533'
},
{
id: 3,
dom: 'SALTA 796'
}
]
return domicilio;
},
getPrecioCondicion: function() {
return $http.get(route + '/precio-condicion')
},
getPrecioCondicionById: function(id) {
return $http.get(route + '/precio-condicion/' + id)
},
getPlazoPagoByPrecioCondicion: function(id) {
return $http.get(route + '/plazo-pago/precio-condicion/'+ id)
}
}
}])
angular.module('focaCrearNotaPedido').run(['$templateCache', function($templateCache) {$templateCache.put('nota-pedido-lista.html','<table class="table table-sm table-hover table-nonfluid">\r\n <thead>\r\n <tr>\r\n <th>C\xF3digo</th>\r\n <th>Vendedor</th>\r\n <th>Cliente</th>\r\n <th>Petrolera</th>\r\n <th>Total</th>\r\n <th><button class="btn btn-primary" ng-click="crearPedido()">Crear</button></th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <tr ng-repeat="item in notaPedidos">\r\n <td ng-bind="item.id"></td>\r\n <td ng-bind="item.vendedor"></td>\r\n <td ng-bind="item.cliente"></td>\r\n <td ng-bind="item.petrolera"></td>\r\n <td ng-bind="item.total | currency"></td>\r\n <td>\r\n <button class="btn btn-info" ng-show="false" ng-click="editar(item)"><i class="fa fa-edit"></i></button>\r\n <!-- <button class="btn btn-danger" ng-click="borrar(item.id)"><i class="fa fa-trash"></i></button> -->\r\n </td>\r\n </tr>\r\n </tbody>\r\n</table>\r\n');
$templateCache.put('nota-pedido.html','<form name="formCrearNota" ng-submit="siguienteTab()">\r\n <uib-tabset active="active">\r\n <uib-tab index="0" heading="General">\r\n <input type="hidden" name="id" ng-model="notaPedido.id">\r\n <div>\r\n <div class="col-auto my-2">\r\n <button type="submit" title="Siguiente" class="btn btn-primary float-right">Siguiente</button>\r\n </div>\r\n </div>\r\n <br>\r\n <br>\r\n <div class="row">\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Fecha de carga</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <input type="date" class="form-control" ng-model="notaPedido.fechaCarga" ng-required="true">\r\n </div>\r\n </div>\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Kil\xF3metros</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <input type="number" min="0" step="0.01" class="form-control" placeholder="Kil\xF3metros recorridos para la entrega en el cliente" ng-model="notaPedido.kilometros" ng-required="true">\r\n </div>\r\n </div>\r\n </div>\r\n <div class="row my-3">\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Jurisdicci\xF3n de IIBB</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <input type="text" class="form-control" placeholder="Jurisdicci\xF3n de IIBB donde se realiza la entrega" ng-model="notaPedido.jurisdiccionIIBB" ng-required="true">\r\n </div>\r\n </div>\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Costo de financiaci\xF3n</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <div class="input-group mb-2">\r\n <div class="input-group-prepend">\r\n <div class="input-group-text">$</div>\r\n </div>\r\n <input type="number" min="0" step="0.01" class="form-control" placeholder="Costo de financiaci\xF3n" ng-model="notaPedido.costoFinanciacion">\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n <div class="row">\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Bomba</label>\r\n </div>\r\n </div>\r\n <div class="col-md-1">\r\n <div class="col-auto">\r\n <div class="form-check custom-radio custom-control-inline">\r\n <input class="form-check-input" type="radio" name="radioBomba" value="1" ng-model="notaPedido.bomba">\r\n <label class="form-check-label">\r\n Si\r\n </label>\r\n </div>\r\n <div class="form-check custom-radio custom-control-inline">\r\n <input class="form-check-input" type="radio" name="radioBomba" value="0" ng-model="notaPedido.bomba">\r\n <label class="form-check-label">\r\n No\r\n </label>\r\n </div>\r\n </div>\r\n </div>\r\n <div class="col-md-1">\r\n <div class="col-auto">\r\n <label>Flete</label>\r\n </div>\r\n </div>\r\n <div class="col-md-1">\r\n <div class="col-auto">\r\n <div class="form-check custom-radio custom-control-inline">\r\n <input class="form-check-input" type="radio" name="radioFlete" value="1" ng-model="notaPedido.flete">\r\n <label class="form-check-label">\r\n Si\r\n </label>\r\n </div>\r\n <div class="form-check custom-radio custom-control-inline">\r\n <input class="form-check-input" type="radio" name="radioFlete" value="0" ng-model="notaPedido.flete">\r\n <label class="form-check-label">\r\n FOB\r\n </label>\r\n </div>\r\n </div>\r\n </div>\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Costo unitario kilometro flete</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <div class="input-group mb-2">\r\n <div class="input-group-prepend">\r\n <div class="input-group-text">$</div>\r\n </div>\r\n <input type="number" min="0" step="0.01" class="form-control" placeholder="Costo unitario del kilometro del flete" ng-model="notaPedido.costoUnitarioKmFlete" ng-required="true">\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n <div class="row my-3">\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Vendedor</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <input type="text" class="form-control" placeholder="Seleccione vendedor" ng-model="notaPedido.vendedor" ng-click="seleccionarVendedor()" readonly="readonly">\r\n </div>\r\n </div>\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Petrolera</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <input type="text" class="form-control" placeholder="Seleccione petrolera" ng-model="notaPedido.petrolera" ng-click="seleccionarPetrolera()" readonly="readonly">\r\n </div>\r\n </div>\r\n </div>\r\n \r\n <div class="row">\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Cliente</label>\r\n </div>\r\n </div>\r\n <div class="col-md-3">\r\n <div class="col-auto">\r\n <input type="text" class="form-control" placeholder="Seleccione cliente" ng-model="notaPedido.cliente" ng-click="seleccionarCliente()" ng-change="obtenerDomicilios()" readonly="readonly">\r\n </div>\r\n </div>\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Domicilio</label>\r\n </div>\r\n </div>\r\n <div class="col-md-4">\r\n <div class="col-md-12 row" ng-repeat="domicilio in notaPedido.domicilio">\r\n <div class="col-auto">\r\n <input type="text" ng-model="domicilio.dom" placeholder="Domicilio" uib-typeahead="\r\n domi.dom\r\n for domi\r\n in domiciliosCliente\r\n " typeahead-no-results="sinResultados" typeahead-min-length="0" typeahead-on-select="seleccionar($item)" class="form-control mb-2" ng-disabled="domicilio.id > 0" ng-required="true">\r\n <i ng-show="cargandoClientes" class="fas fa-sync"></i>\r\n <div ng-show="sinResultados">\r\n No se encontraron resultados.\r\n </div>\r\n </div>\r\n <a class="btn" ng-click="removeNewChoice(domicilio)" ng-if="domicilio.id==0">-</a>\r\n <a class="btn" ng-click="addNewDom()">+</a>\r\n </div>\r\n </div>\r\n </div>\r\n </uib-tab>\r\n <uib-tab index="1" heading="Producto" disable="formCrearNota.$invalid">\r\n <div>\r\n <div class="col-auto my-2">\r\n <button ng-click="crearNotaPedido()" type="button" title="Crear nota pedido" class="btn btn-primary float-right">Crear</button>\r\n </div>\r\n </div>\r\n <br>\r\n <br>\r\n <div class="row">\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Precios y condiciones</label>\r\n </div>\r\n </div>\r\n <div class="col-md-4">\r\n <div class="col-auto">\r\n <select class="form-control" ng-change="cargarArticulos()" ng-model="notaPedido.precioCondicion" ng-options="preCond.id as preCond.nombre for preCond in precioCondiciones">\r\n </select>\r\n </div>\r\n </div>\r\n <div class="col-md-2">\r\n <div class="col-auto">\r\n <label>Producto</label>\r\n </div>\r\n </div>\r\n <div class="col-md-4">\r\n <div class="col-auto">\r\n <input type="text" class="form-control" placeholder="Seleccione producto" ng-model="notaPedido.producto" ng-click="seleccionarArticulo()" readonly="readonly">\r\n </div>\r\n </div>\r\n </div>\r\n <div class="col-md-12">\r\n <table class="table my-3 table-hover table-nonfluid">\r\n <thead>\r\n <tr>\r\n <th>C\xF3digo</th>\r\n <th>Nombre</th>\r\n <th>Precio unitario</th>\r\n <th>Costo unitario bruto</th>\r\n <th>Cantidad</th>\r\n <th>Subtotal</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <tr ng-repeat="articulo in articulosTabla">\r\n <td ng-bind="articulo.codigo"></td>\r\n <td ng-bind="articulo.nombre"></td>\r\n <td ng-bind="articulo.precio"></td>\r\n <td ng-bind="articulo.costoUnitario"></td>\r\n <td><input ng-model="articulo.cantidad" class="form-control" type="number" min="0" value="1"></td>\r\n <td ng-bind="getSubTotal(articulo.item)"></td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n </div>\r\n </uib-tab>\r\n </uib-tabset>\r\n</form>');}]);