Commit a3d93798a6087b8f4e11b53a1070d57e07af405b
Exists in
master
Merge branch 'master' into 'master'
Master See merge request modulos-npm/foca-crear-remito!11
Showing
1 changed file
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearRemito') .controller('remitoController', | 1 | angular.module('focaCrearRemito') .controller('remitoController', |
| 2 | [ | 2 | [ |
| 3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', |
| 4 | 'focaModalService', 'remitoBusinessService', | 4 | 'focaModalService', 'remitoBusinessService', |
| 5 | function( | 5 | function( |
| 6 | $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService, |
| 7 | remitoBusinessService | 7 | remitoBusinessService |
| 8 | ) { | 8 | ) { |
| 9 | $scope.botonera = [ | 9 | $scope.botonera = [ |
| 10 | {texto: 'Nota Pedido', accion: function() {$scope.seleccionarNotaPedido();}}, | 10 | {texto: 'Nota Pedido', accion: function() {$scope.seleccionarNotaPedido();}}, |
| 11 | {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, | 11 | {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, |
| 12 | {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, | 12 | {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, |
| 13 | {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, | 13 | {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, |
| 14 | {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, | 14 | {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, |
| 15 | { | 15 | { |
| 16 | texto: 'Precios y condiciones', | 16 | texto: 'Precios y condiciones', |
| 17 | accion: function() {$scope.abrirModalListaPrecio();}}, | 17 | accion: function() {$scope.abrirModalListaPrecio();}}, |
| 18 | {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, | 18 | {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, |
| 19 | {texto: '', accion: function() {}} | 19 | {texto: '', accion: function() {}} |
| 20 | ]; | 20 | ]; |
| 21 | $scope.datepickerAbierto = false; | 21 | $scope.datepickerAbierto = false; |
| 22 | 22 | ||
| 23 | $scope.show = false; | 23 | $scope.show = false; |
| 24 | $scope.cargando = true; | 24 | $scope.cargando = true; |
| 25 | $scope.dateOptions = { | 25 | $scope.dateOptions = { |
| 26 | maxDate: new Date(), | 26 | maxDate: new Date(), |
| 27 | minDate: new Date(2010, 0, 1) | 27 | minDate: new Date(2010, 0, 1) |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | $scope.remito = { | 30 | $scope.remito = { |
| 31 | vendedor: {}, | 31 | vendedor: {}, |
| 32 | cliente: {}, | 32 | cliente: {}, |
| 33 | proveedor: {}, | 33 | proveedor: {}, |
| 34 | domicilio: {dom: ''}, | 34 | domicilio: {dom: ''}, |
| 35 | moneda: {}, | 35 | moneda: {}, |
| 36 | cotizacion: {} | 36 | cotizacion: {} |
| 37 | }; | 37 | }; |
| 38 | var monedaPorDefecto; | 38 | var monedaPorDefecto; |
| 39 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 39 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
| 40 | crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { | 40 | crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { |
| 41 | monedaPorDefecto = { | 41 | monedaPorDefecto = { |
| 42 | id: res.data[0].ID, | 42 | id: res.data[0].ID, |
| 43 | detalle: res.data[0].DETALLE, | 43 | detalle: res.data[0].DETALLE, |
| 44 | simbolo: res.data[0].SIMBOLO, | 44 | simbolo: res.data[0].SIMBOLO, |
| 45 | cotizaciones: res.data[0].cotizaciones | 45 | cotizaciones: res.data[0].cotizaciones |
| 46 | }; | 46 | }; |
| 47 | addCabecera('Moneda:', monedaPorDefecto.detalle); | 47 | addCabecera('Moneda:', monedaPorDefecto.detalle); |
| 48 | addCabecera('Fecha cotizacion:', | 48 | addCabecera('Fecha cotizacion:', |
| 49 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); | 49 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); |
| 50 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); | 50 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); |
| 51 | $scope.remito.moneda = monedaPorDefecto; | 51 | $scope.remito.moneda = monedaPorDefecto; |
| 52 | $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; | 52 | $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; |
| 53 | }); | 53 | }); |
| 54 | 54 | ||
| 55 | $scope.cabecera = []; | 55 | $scope.cabecera = []; |
| 56 | $scope.showCabecera = true; | 56 | $scope.showCabecera = true; |
| 57 | 57 | ||
| 58 | $scope.now = new Date(); | 58 | $scope.now = new Date(); |
| 59 | $scope.puntoVenta = rellenar(0, 4); | 59 | $scope.puntoVenta = rellenar(0, 4); |
| 60 | $scope.comprobante = rellenar(0, 8); | 60 | $scope.comprobante = rellenar(0, 8); |
| 61 | 61 | ||
| 62 | $scope.articulosTabla = []; | 62 | $scope.articulosTabla = []; |
| 63 | $scope.idLista = undefined; | 63 | $scope.idLista = undefined; |
| 64 | //La pantalla solo se usa para cargar remitos | 64 | //La pantalla solo se usa para cargar remitos |
| 65 | //var remitoTemp = crearRemitoService.getRemito(); | 65 | //var remitoTemp = crearRemitoService.getRemito(); |
| 66 | 66 | ||
| 67 | crearRemitoService.getPrecioCondicion().then( | 67 | crearRemitoService.getPrecioCondicion().then( |
| 68 | function(res) { | 68 | function(res) { |
| 69 | $scope.precioCondiciones = res.data; | 69 | $scope.precioCondiciones = res.data; |
| 70 | } | 70 | } |
| 71 | ); | 71 | ); |
| 72 | 72 | ||
| 73 | crearRemitoService.getNumeroRemito().then( | 73 | crearRemitoService.getNumeroRemito().then( |
| 74 | function(res) { | 74 | function(res) { |
| 75 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 75 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 76 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 76 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); |
| 77 | }, | 77 | }, |
| 78 | function(err) { | 78 | function(err) { |
| 79 | focaModalService.alert('La terminal no esta configurada correctamente'); | 79 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 80 | console.info(err); | 80 | console.info(err); |
| 81 | } | 81 | } |
| 82 | ); | 82 | ); |
| 83 | 83 | ||
| 84 | $scope.seleccionarNotaPedido = function() { | 84 | $scope.seleccionarNotaPedido = function() { |
| 85 | var modalInstance = $uibModal.open( | 85 | var modalInstance = $uibModal.open( |
| 86 | { | 86 | { |
| 87 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 87 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 88 | templateUrl: 'foca-modal-nota-pedido.html', | 88 | templateUrl: 'foca-modal-nota-pedido.html', |
| 89 | controller: 'focaModalNotaPedidoController', | 89 | controller: 'focaModalNotaPedidoController', |
| 90 | size: 'lg' | 90 | size: 'lg' |
| 91 | } | 91 | } |
| 92 | ); | 92 | ); |
| 93 | modalInstance.result.then( | 93 | modalInstance.result.then( |
| 94 | function(notaPedido) { | 94 | function(notaPedido) { |
| 95 | //añado cabeceras | 95 | //añado cabeceras |
| 96 | removeCabecera('Moneda:'); | 96 | removeCabecera('Moneda:'); |
| 97 | removeCabecera('Fecha cotizacion:'); | 97 | removeCabecera('Fecha cotizacion:'); |
| 98 | removeCabecera('Cotizacion:'); | 98 | removeCabecera('Cotizacion:'); |
| 99 | var cabeceras = [ | 99 | var cabeceras = [ |
| 100 | { | 100 | { |
| 101 | label: 'Moneda', | 101 | label: 'Moneda', |
| 102 | valor: notaPedido.cotizacion[0].moneda[0].DETALLE | 102 | valor: notaPedido.cotizacion[0].moneda[0].DETALLE |
| 103 | }, | 103 | }, |
| 104 | { | 104 | { |
| 105 | label: 'Fecha cotizacion', | 105 | label: 'Fecha cotizacion', |
| 106 | valor: $filter('date')(notaPedido.cotizacion[0].FECHA, | 106 | valor: $filter('date')(notaPedido.cotizacion[0].FECHA, |
| 107 | 'dd/MM/yyyy') | 107 | 'dd/MM/yyyy') |
| 108 | }, | 108 | }, |
| 109 | { | 109 | { |
| 110 | label: 'Cotizacion', | 110 | label: 'Cotizacion', |
| 111 | valor: notaPedido.cotizacion[0].VENDEDOR | 111 | valor: notaPedido.cotizacion[0].VENDEDOR |
| 112 | }, | 112 | }, |
| 113 | { | 113 | { |
| 114 | label: 'Cliente:', | 114 | label: 'Cliente:', |
| 115 | valor: notaPedido.cliente[0].NOM | 115 | valor: notaPedido.cliente[0].NOM |
| 116 | }, | 116 | }, |
| 117 | { | 117 | { |
| 118 | label: 'Vendedor:', | 118 | label: 'Vendedor:', |
| 119 | valor: notaPedido.vendedor[0].NomVen | 119 | valor: notaPedido.vendedor[0].NomVen |
| 120 | }, | 120 | }, |
| 121 | { | 121 | { |
| 122 | label: 'Proveedor:', | 122 | label: 'Proveedor:', |
| 123 | valor: notaPedido.proveedor[0].NOM | 123 | valor: notaPedido.proveedor[0].NOM |
| 124 | }, | 124 | }, |
| 125 | { | 125 | { |
| 126 | label: 'Flete:', | 126 | label: 'Flete:', |
| 127 | valor: notaPedido.flete === 1 ? 'Si' : 'No' | 127 | valor: notaPedido.flete === 1 ? 'Si' : 'No' |
| 128 | }, | 128 | }, |
| 129 | { | 129 | { |
| 130 | label: 'FOB:', | 130 | label: 'FOB:', |
| 131 | valor: notaPedido.fob === 1 ? 'Si' : 'No' | 131 | valor: notaPedido.fob === 1 ? 'Si' : 'No' |
| 132 | }, | 132 | }, |
| 133 | { | 133 | { |
| 134 | label: 'Precio condicion:', | 134 | label: 'Precio condicion:', |
| 135 | valor: valorPrecioCondicion() | 135 | valor: valorPrecioCondicion() |
| 136 | } | 136 | } |
| 137 | ]; | 137 | ]; |
| 138 | //TO DO CUANDO MOSTRAR PLAZOS | 138 | //TO DO CUANDO MOSTRAR PLAZOS |
| 139 | function valorPrecioCondicion() { | 139 | function valorPrecioCondicion() { |
| 140 | if(notaPedido.idPrecioCondicion > 0) { | 140 | if(notaPedido.idPrecioCondicion > 0) { |
| 141 | return notaPedido.precioCondicion[0].nombre; | 141 | return notaPedido.precioCondicion[0].nombre; |
| 142 | } else { | 142 | } else { |
| 143 | return 'Ingreso Manual'; | 143 | return 'Ingreso Manual'; |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | if(notaPedido.flete === 1) { | 148 | if(notaPedido.flete === 1) { |
| 149 | var cabeceraBomba = { | 149 | var cabeceraBomba = { |
| 150 | label: 'Bomba', | 150 | label: 'Bomba', |
| 151 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 151 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 152 | }; | 152 | }; |
| 153 | if(notaPedido.kilometros) { | 153 | if(notaPedido.kilometros) { |
| 154 | var cabeceraKilometros = { | 154 | var cabeceraKilometros = { |
| 155 | label: 'Kilometros', | 155 | label: 'Kilometros', |
| 156 | valor: notaPedido.kilometros | 156 | valor: notaPedido.kilometros |
| 157 | }; | 157 | }; |
| 158 | cabeceras.push(cabeceraKilometros); | 158 | cabeceras.push(cabeceraKilometros); |
| 159 | } | 159 | } |
| 160 | cabeceras.push(cabeceraBomba); | 160 | cabeceras.push(cabeceraBomba); |
| 161 | } | 161 | } |
| 162 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 162 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
| 163 | $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; | 163 | if(notaPedido.precioCondicion.length > 0) { |
| 164 | $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; | ||
| 165 | } else { | ||
| 166 | $scope.idLista = -1; | ||
| 167 | } | ||
| 164 | $scope.remito = notaPedido; | 168 | $scope.remito = notaPedido; |
| 165 | $scope.remito.vendedor = notaPedido.vendedor[0]; | 169 | $scope.remito.vendedor = notaPedido.vendedor[0]; |
| 166 | $scope.remito.cliente = notaPedido.cliente[0]; | 170 | $scope.remito.cliente = notaPedido.cliente[0]; |
| 167 | $scope.remito.proveedor = notaPedido.proveedor[0]; | 171 | $scope.remito.proveedor = notaPedido.proveedor[0]; |
| 168 | $scope.remito.moneda = notaPedido.cotizacion[0].moneda[0]; | 172 | $scope.remito.moneda = notaPedido.cotizacion[0].moneda[0]; |
| 169 | $scope.remito.cotizacion = notaPedido.cotizacion[0]; | 173 | $scope.remito.cotizacion = notaPedido.cotizacion[0]; |
| 170 | addArrayCabecera(cabeceras); | 174 | addArrayCabecera(cabeceras); |
| 171 | 175 | ||
| 172 | }, function() { | 176 | }, function() { |
| 173 | // funcion ejecutada cuando se cancela el modal | 177 | // funcion ejecutada cuando se cancela el modal |
| 174 | } | 178 | } |
| 175 | ); | 179 | ); |
| 176 | }; | 180 | }; |
| 177 | 181 | ||
| 178 | $scope.seleccionarRemito = function() { | 182 | $scope.seleccionarRemito = function() { |
| 179 | var modalInstance = $uibModal.open( | 183 | var modalInstance = $uibModal.open( |
| 180 | { | 184 | { |
| 181 | ariaLabelledBy: 'Busqueda de Remito', | 185 | ariaLabelledBy: 'Busqueda de Remito', |
| 182 | templateUrl: 'foca-modal-remito.html', | 186 | templateUrl: 'foca-modal-remito.html', |
| 183 | controller: 'focaModalRemitoController', | 187 | controller: 'focaModalRemitoController', |
| 184 | size: 'lg' | 188 | size: 'lg' |
| 185 | } | 189 | } |
| 186 | ); | 190 | ); |
| 187 | modalInstance.result.then( | 191 | modalInstance.result.then( |
| 188 | function() { | 192 | function(remito) { |
| 189 | // TODO: Implementar carga remito | 193 | //añado cabeceras |
| 194 | removeCabecera('Moneda:'); | ||
| 195 | removeCabecera('Fecha cotizacion:'); | ||
| 196 | removeCabecera('Cotizacion:'); | ||
| 197 | var cabeceras = [ | ||
| 198 | { | ||
| 199 | label: 'Moneda', | ||
| 200 | valor: remito.cotizacion[0].moneda[0].DETALLE | ||
| 201 | }, | ||
| 202 | { | ||
| 203 | label: 'Fecha cotizacion', | ||
| 204 | valor: $filter('date')(remito.cotizacion[0].FECHA, | ||
| 205 | 'dd/MM/yyyy') | ||
| 206 | }, | ||
| 207 | { | ||
| 208 | label: 'Cotizacion', | ||
| 209 | valor: remito.cotizacion[0].VENDEDOR | ||
| 210 | }, | ||
| 211 | { | ||
| 212 | label: 'Cliente:', | ||
| 213 | valor: remito.cliente[0].NOM | ||
| 214 | }, | ||
| 215 | { | ||
| 216 | label: 'Vendedor:', | ||
| 217 | valor: remito.vendedor[0].NomVen | ||
| 218 | }, | ||
| 219 | { | ||
| 220 | label: 'Proveedor:', | ||
| 221 | valor: remito.proveedor[0].NOM | ||
| 222 | }, | ||
| 223 | { | ||
| 224 | label: 'Flete:', | ||
| 225 | valor: remito.flete === 1 ? 'Si' : 'No' | ||
| 226 | }, | ||
| 227 | { | ||
| 228 | label: 'FOB:', | ||
| 229 | valor: remito.fob === 1 ? 'Si' : 'No' | ||
| 230 | }, | ||
| 231 | { | ||
| 232 | label: 'Precio condicion:', | ||
| 233 | valor: valorPrecioCondicion() | ||
| 234 | } | ||
| 235 | ]; | ||
| 236 | //TO DO CUANDO MOSTRAR PLAZOS | ||
| 237 | function valorPrecioCondicion() { | ||
| 238 | if(remito.idPrecioCondicion > 0) { | ||
| 239 | return remito.precioCondicion[0].nombre; | ||
| 240 | } else { | ||
| 241 | return 'Ingreso Manual'; | ||
| 242 | } | ||
| 243 | |||
| 244 | } | ||
| 245 | |||
| 246 | if(remito.flete === 1) { | ||
| 247 | var cabeceraBomba = { | ||
| 248 | label: 'Bomba', | ||
| 249 | valor: remito.bomba === 1 ? 'Si' : 'No' | ||
| 250 | }; | ||
| 251 | if(remito.kilometros) { | ||
| 252 | var cabeceraKilometros = { | ||
| 253 | label: 'Kilometros', | ||
| 254 | valor: remito.kilometros | ||
| 255 | }; | ||
| 256 | cabeceras.push(cabeceraKilometros); | ||
| 257 | } | ||
| 258 | cabeceras.push(cabeceraBomba); | ||
| 259 | } | ||
| 260 | $scope.articulosTabla = remito.articulosRemito; | ||
| 261 | if(remito.precioCondicion.length > 0) { | ||
| 262 | $scope.idLista = remito.precioCondicion[0].idListaPrecio; | ||
| 263 | } else { | ||
| 264 | $scope.idLista = -1; | ||
| 265 | } | ||
| 266 | $scope.remito = remito; | ||
| 267 | $scope.remito.vendedor = remito.vendedor[0]; | ||
| 268 | $scope.remito.cliente = remito.cliente[0]; | ||
| 269 | $scope.remito.proveedor = remito.proveedor[0]; | ||
| 270 | $scope.remito.moneda = remito.cotizacion[0].moneda[0]; | ||
| 271 | $scope.remito.cotizacion = remito.cotizacion[0]; | ||
| 272 | addArrayCabecera(cabeceras); | ||
| 190 | }, function() { | 273 | }, function() { |
| 191 | // funcion ejecutada cuando se cancela el modal | 274 | // funcion ejecutada cuando se cancela el modal |
| 192 | } | 275 | } |
| 193 | ); | 276 | ); |
| 194 | }; | 277 | }; |
| 195 | 278 | ||
| 196 | //La pantalla solo se usa para cargar remitos | 279 | //La pantalla solo se usa para cargar remitos |
| 197 | // if (remitoTemp !== undefined) { | 280 | // if (remitoTemp !== undefined) { |
| 198 | // remitoTemp.fechaCarga = new Date(remitoTemp.fechaCarga); | 281 | // remitoTemp.fechaCarga = new Date(remitoTemp.fechaCarga); |
| 199 | // $scope.remito = remitoTemp; | 282 | // $scope.remito = remitoTemp; |
| 200 | // $scope.remito.flete = ($scope.remito.flete).toString(); | 283 | // $scope.remito.flete = ($scope.remito.flete).toString(); |
| 201 | // $scope.remito.bomba = ($scope.remito.bomba).toString(); | 284 | // $scope.remito.bomba = ($scope.remito.bomba).toString(); |
| 202 | // $scope.idLista = $scope.remito.precioCondicion; | 285 | // $scope.idLista = $scope.remito.precioCondicion; |
| 203 | // crearRemitoService | 286 | // crearRemitoService |
| 204 | // .getArticulosByIdRemito($scope.remito.id).then( | 287 | // .getArticulosByIdRemito($scope.remito.id).then( |
| 205 | // function(res) { | 288 | // function(res) { |
| 206 | // $scope.articulosTabla = res.data; | 289 | // $scope.articulosTabla = res.data; |
| 207 | // } | 290 | // } |
| 208 | // ); | 291 | // ); |
| 209 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR REMITO | 292 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR REMITO |
| 210 | //(NO REQUERIDO EN ESTA VERSION) | 293 | //(NO REQUERIDO EN ESTA VERSION) |
| 211 | // crearRemitoService.getDomiciliosByIdRemito($scope.remito.id).then( | 294 | // crearRemitoService.getDomiciliosByIdRemito($scope.remito.id).then( |
| 212 | // function(res) { | 295 | // function(res) { |
| 213 | // $scope.remito.domicilio = res.data; | 296 | // $scope.remito.domicilio = res.data; |
| 214 | // } | 297 | // } |
| 215 | // ); | 298 | // ); |
| 216 | // } else { | 299 | // } else { |
| 217 | // $scope.remito.fechaCarga = new Date(); | 300 | // $scope.remito.fechaCarga = new Date(); |
| 218 | // $scope.remito.bomba = '0'; | 301 | // $scope.remito.bomba = '0'; |
| 219 | // $scope.remito.flete = '0'; | 302 | // $scope.remito.flete = '0'; |
| 220 | // $scope.idLista = undefined; | 303 | // $scope.idLista = undefined; |
| 221 | // } | 304 | // } |
| 222 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO | 305 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO |
| 223 | // $scope.addNewDom = function() { | 306 | // $scope.addNewDom = function() { |
| 224 | // $scope.remito.domicilio.push({ 'id': 0 }); | 307 | // $scope.remito.domicilio.push({ 'id': 0 }); |
| 225 | // }; | 308 | // }; |
| 226 | // $scope.removeNewChoice = function(choice) { | 309 | // $scope.removeNewChoice = function(choice) { |
| 227 | // if ($scope.remito.domicilio.length > 1) { | 310 | // if ($scope.remito.domicilio.length > 1) { |
| 228 | // $scope.remito.domicilio.splice($scope.remito.domicilio.findIndex( | 311 | // $scope.remito.domicilio.splice($scope.remito.domicilio.findIndex( |
| 229 | // function(c) { | 312 | // function(c) { |
| 230 | // return c.$$hashKey === choice.$$hashKey; | 313 | // return c.$$hashKey === choice.$$hashKey; |
| 231 | // } | 314 | // } |
| 232 | // ), 1); | 315 | // ), 1); |
| 233 | // } | 316 | // } |
| 234 | // }; | 317 | // }; |
| 235 | //validacion por domicilio y por plazo pago | 318 | //validacion por domicilio y por plazo pago |
| 236 | $scope.crearRemito = function() { | 319 | $scope.crearRemito = function() { |
| 237 | if(!$scope.remito.vendedor) { | 320 | if(!$scope.remito.vendedor) { |
| 238 | focaModalService.alert('Ingrese Vendedor'); | 321 | focaModalService.alert('Ingrese Vendedor'); |
| 239 | return; | 322 | return; |
| 240 | } else if(!$scope.remito.cliente) { | 323 | } else if(!$scope.remito.cliente) { |
| 241 | focaModalService.alert('Ingrese Cliente'); | 324 | focaModalService.alert('Ingrese Cliente'); |
| 242 | return; | 325 | return; |
| 243 | } else if(!$scope.remito.proveedor) { | 326 | } else if(!$scope.remito.proveedor) { |
| 244 | focaModalService.alert('Ingrese Proveedor'); | 327 | focaModalService.alert('Ingrese Proveedor'); |
| 245 | return; | 328 | return; |
| 246 | } else if(!$scope.remito.moneda.ID) { | 329 | } else if(!$scope.remito.moneda.ID) { |
| 247 | focaModalService.alert('Ingrese Moneda'); | 330 | focaModalService.alert('Ingrese Moneda'); |
| 248 | return; | 331 | return; |
| 249 | } else if(!$scope.remito.cotizacion.ID) { | 332 | } else if(!$scope.remito.cotizacion.ID) { |
| 250 | focaModalService.alert('Ingrese Cotización'); | 333 | focaModalService.alert('Ingrese Cotización'); |
| 251 | return; | 334 | return; |
| 252 | } else if( | 335 | } else if( |
| 253 | $scope.remito.flete === undefined || $scope.remito.flete === null) | 336 | $scope.remito.flete === undefined || $scope.remito.flete === null) |
| 254 | { | 337 | { |
| 255 | focaModalService.alert('Ingrese Flete'); | 338 | focaModalService.alert('Ingrese Flete'); |
| 256 | return; | 339 | return; |
| 257 | } else if($scope.articulosTabla.length === 0) { | 340 | } else if($scope.articulosTabla.length === 0) { |
| 258 | focaModalService.alert('Debe cargar al menos un articulo'); | 341 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 259 | return; | 342 | return; |
| 260 | } | 343 | } |
| 261 | var date = new Date(); | 344 | var date = new Date(); |
| 262 | var remito = { | 345 | var remito = { |
| 263 | id: 0, | 346 | id: 0, |
| 264 | fechaRemito: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | 347 | fechaRemito: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
| 265 | .toISOString().slice(0, 19).replace('T', ' '),//TODO$filter | 348 | .toISOString().slice(0, 19).replace('T', ' '),//TODO$filter |
| 266 | idCliente: $scope.remito.idCliente, | 349 | idCliente: $scope.remito.idCliente, |
| 267 | nombreCliente: $scope.remito.nombreCliente, | 350 | nombreCliente: $scope.remito.nombreCliente, |
| 268 | cuitCliente: $scope.remito.cuitCliente, | 351 | cuitCliente: $scope.remito.cuitCliente, |
| 269 | responsabilidadIvaCliente: 0,//TODO, | 352 | responsabilidadIvaCliente: 0,//TODO, |
| 270 | descuento: 0,//TODO, | 353 | descuento: 0,//TODO, |
| 271 | importeNeto: 0,//TODO | 354 | importeNeto: 0,//TODO |
| 272 | importeExento: 0,//TODO | 355 | importeExento: 0,//TODO |
| 273 | importeIva: 0,//TODO | 356 | importeIva: 0,//TODO |
| 274 | importeIvaServicios: 0,//TODO | 357 | importeIvaServicios: 0,//TODO |
| 275 | importeImpuestoInterno: 0,//TODO | 358 | importeImpuestoInterno: 0,//TODO |
| 276 | importeImpuestoInterno1: 0,//TODO | 359 | importeImpuestoInterno1: 0,//TODO |
| 277 | importeImpuestoInterno2: 0,//TODO | 360 | importeImpuestoInterno2: 0,//TODO |
| 278 | percepcion: 0,//TODO | 361 | percepcion: 0,//TODO |
| 279 | percepcionIva: 0,//TODO | 362 | percepcionIva: 0,//TODO |
| 280 | redondeo: 0,//TODO | 363 | redondeo: 0,//TODO |
| 281 | total: $scope.getTotal(), | 364 | total: $scope.getTotal(), |
| 282 | numeroNotaPedido: $scope.remito.numeroNotaPedido, | 365 | numeroNotaPedido: $scope.remito.numeroNotaPedido, |
| 283 | anulado: false, | 366 | anulado: false, |
| 284 | planilla: 0,//TODO | 367 | planilla: 0,//TODO |
| 285 | lugar: 0,//TODO | 368 | lugar: 0,//TODO |
| 286 | cuentaMadre: 0,// | 369 | cuentaMadre: 0,// |
| 287 | cuentaContable: 0,//TODO | 370 | cuentaContable: 0,//TODO |
| 288 | asiento: 0,//TODO | 371 | asiento: 0,//TODO |
| 289 | e_hd: '',//TODO | 372 | e_hd: '',//TODO |
| 290 | c_hd: '', | 373 | c_hd: '', |
| 291 | numeroLiquidoProducto: 0,//TODO | 374 | numeroLiquidoProducto: 0,//TODO |
| 292 | idVendedor: $scope.remito.idVendedor, | 375 | idVendedor: $scope.remito.idVendedor, |
| 293 | idProveedor: $scope.remito.idProveedor, | 376 | idProveedor: $scope.remito.idProveedor, |
| 294 | idDomicilio: 0,//TODO | 377 | idDomicilio: 0,//TODO |
| 295 | idCotizacion: $scope.remito.idCotizacion, | 378 | idCotizacion: $scope.remito.idCotizacion, |
| 379 | idPrecioCondicion: $scope.remito.idPrecioCondicion, | ||
| 296 | flete: $scope.remito.flete, | 380 | flete: $scope.remito.flete, |
| 297 | fob: $scope.remito.fob, | 381 | fob: $scope.remito.fob, |
| 298 | bomba: $scope.remito.bomba, | 382 | bomba: $scope.remito.bomba, |
| 299 | kilometros: $scope.remito.kilometros, | 383 | kilometros: $scope.remito.kilometros, |
| 300 | estado: 0,//TODO | 384 | estado: 0,//TODO |
| 301 | destinoVenta: 0,//TODO | 385 | destinoVenta: 0,//TODO |
| 302 | operacionTipo: 0//TODO | 386 | operacionTipo: 0//TODO |
| 303 | }; | 387 | }; |
| 304 | crearRemitoService.crearRemito(remito).then( | 388 | crearRemitoService.crearRemito(remito).then( |
| 305 | function(data) { | 389 | function(data) { |
| 306 | remitoBusinessService.addArticulos($scope.articulosTabla, | 390 | remitoBusinessService.addArticulos($scope.articulosTabla, |
| 307 | data.data.id, $scope.remito.cotizacion.COTIZACION); | 391 | data.data.id, $scope.remito.cotizacion.COTIZACION); |
| 308 | 392 | ||
| 309 | focaModalService.alert('Nota remito creada'); | 393 | focaModalService.alert('Nota remito creada'); |
| 310 | $scope.cabecera = []; | 394 | $scope.cabecera = []; |
| 311 | addCabecera('Moneda:', $scope.remito.moneda.detalle); | 395 | addCabecera('Moneda:', $scope.remito.moneda.detalle); |
| 312 | addCabecera( | 396 | addCabecera( |
| 313 | 'Fecha cotizacion:', | 397 | 'Fecha cotizacion:', |
| 314 | $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy') | 398 | $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy') |
| 315 | ); | 399 | ); |
| 316 | addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION); | 400 | addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION); |
| 317 | $scope.remito.vendedor = {}; | 401 | $scope.remito.vendedor = {}; |
| 318 | $scope.remito.cliente = {}; | 402 | $scope.remito.cliente = {}; |
| 319 | $scope.remito.proveedor = {}; | 403 | $scope.remito.proveedor = {}; |
| 320 | $scope.remito.domicilio = {}; | 404 | $scope.remito.domicilio = {}; |
| 321 | $scope.remito.flete = null; | 405 | $scope.remito.flete = null; |
| 322 | $scope.remito.fob = null; | 406 | $scope.remito.fob = null; |
| 323 | $scope.remito.bomba = null; | 407 | $scope.remito.bomba = null; |
| 324 | $scope.remito.kilometros = null; | 408 | $scope.remito.kilometros = null; |
| 325 | $scope.articulosTabla = []; | 409 | $scope.articulosTabla = []; |
| 326 | } | 410 | } |
| 327 | ); | 411 | ); |
| 328 | }; | 412 | }; |
| 329 | 413 | ||
| 330 | $scope.seleccionarArticulo = function() { | 414 | $scope.seleccionarArticulo = function() { |
| 331 | if ($scope.idLista === undefined) { | 415 | if ($scope.idLista === undefined) { |
| 332 | focaModalService.alert( | 416 | focaModalService.alert( |
| 333 | 'Primero seleccione una lista de precio y condicion'); | 417 | 'Primero seleccione una lista de precio y condicion'); |
| 334 | return; | 418 | return; |
| 335 | } | 419 | } |
| 336 | var modalInstance = $uibModal.open( | 420 | var modalInstance = $uibModal.open( |
| 337 | { | 421 | { |
| 338 | ariaLabelledBy: 'Busqueda de Productos', | 422 | ariaLabelledBy: 'Busqueda de Productos', |
| 339 | templateUrl: 'modal-busqueda-productos.html', | 423 | templateUrl: 'modal-busqueda-productos.html', |
| 340 | controller: 'modalBusquedaProductosCtrl', | 424 | controller: 'modalBusquedaProductosCtrl', |
| 341 | resolve: { | 425 | resolve: { |
| 342 | parametroProducto: { | 426 | parametroProducto: { |
| 343 | idLista: $scope.idLista, | 427 | idLista: $scope.idLista, |
| 344 | cotizacion: $scope.remito.cotizacion.COTIZACION, | 428 | cotizacion: $scope.remito.cotizacion.COTIZACION, |
| 345 | simbolo: $scope.remito.moneda.simbolo | 429 | simbolo: $scope.remito.moneda.simbolo |
| 346 | } | 430 | } |
| 347 | }, | 431 | }, |
| 348 | size: 'lg' | 432 | size: 'lg' |
| 349 | } | 433 | } |
| 350 | ); | 434 | ); |
| 351 | modalInstance.result.then( | 435 | modalInstance.result.then( |
| 352 | function(producto) { | 436 | function(producto) { |
| 353 | var newArt = | 437 | var newArt = |
| 354 | { | 438 | { |
| 355 | id: 0, | 439 | id: 0, |
| 356 | codigo: producto.codigo, | 440 | codigo: producto.codigo, |
| 357 | sector: producto.sector, | 441 | sector: producto.sector, |
| 358 | sectorCodigo: producto.sector + '-' + producto.codigo, | 442 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 359 | descripcion: producto.descripcion, | 443 | descripcion: producto.descripcion, |
| 360 | item: $scope.articulosTabla.length + 1, | 444 | item: $scope.articulosTabla.length + 1, |
| 361 | nombre: producto.descripcion, | 445 | nombre: producto.descripcion, |
| 362 | precio: parseFloat(producto.precio.toFixed(4)), | 446 | precio: parseFloat(producto.precio.toFixed(4)), |
| 363 | costoUnitario: producto.costo, | 447 | costoUnitario: producto.costo, |
| 364 | editCantidad: false, | 448 | editCantidad: false, |
| 365 | editPrecio: false | 449 | editPrecio: false |
| 366 | }; | 450 | }; |
| 367 | $scope.articuloACargar = newArt; | 451 | $scope.articuloACargar = newArt; |
| 368 | $scope.cargando = false; | 452 | $scope.cargando = false; |
| 369 | }, function() { | 453 | }, function() { |
| 370 | // funcion ejecutada cuando se cancela el modal | 454 | // funcion ejecutada cuando se cancela el modal |
| 371 | } | 455 | } |
| 372 | ); | 456 | ); |
| 373 | }; | 457 | }; |
| 374 | 458 | ||
| 375 | $scope.seleccionarVendedor = function() { | 459 | $scope.seleccionarVendedor = function() { |
| 376 | var modalInstance = $uibModal.open( | 460 | var modalInstance = $uibModal.open( |
| 377 | { | 461 | { |
| 378 | ariaLabelledBy: 'Busqueda de Vendedores', | 462 | ariaLabelledBy: 'Busqueda de Vendedores', |
| 379 | templateUrl: 'modal-vendedores.html', | 463 | templateUrl: 'modal-vendedores.html', |
| 380 | controller: 'modalVendedoresCtrl', | 464 | controller: 'modalVendedoresCtrl', |
| 381 | size: 'lg' | 465 | size: 'lg' |
| 382 | } | 466 | } |
| 383 | ); | 467 | ); |
| 384 | modalInstance.result.then( | 468 | modalInstance.result.then( |
| 385 | function(vendedor) { | 469 | function(vendedor) { |
| 386 | addCabecera('Vendedor:', vendedor.NomVen); | 470 | addCabecera('Vendedor:', vendedor.NomVen); |
| 387 | $scope.remito.vendedor.codigo = vendedor.CodVen; | 471 | $scope.remito.vendedor.codigo = vendedor.CodVen; |
| 388 | }, function() { | 472 | }, function() { |
| 389 | 473 | ||
| 390 | } | 474 | } |
| 391 | ); | 475 | ); |
| 392 | }; | 476 | }; |
| 393 | 477 | ||
| 394 | $scope.seleccionarProveedor = function() { | 478 | $scope.seleccionarProveedor = function() { |
| 395 | var modalInstance = $uibModal.open( | 479 | var modalInstance = $uibModal.open( |
| 396 | { | 480 | { |
| 397 | ariaLabelledBy: 'Busqueda de Proveedor', | 481 | ariaLabelledBy: 'Busqueda de Proveedor', |
| 398 | templateUrl: 'modal-proveedor.html', | 482 | templateUrl: 'modal-proveedor.html', |
| 399 | controller: 'focaModalProveedorCtrl', | 483 | controller: 'focaModalProveedorCtrl', |
| 400 | size: 'lg', | 484 | size: 'lg', |
| 401 | resolve: { | 485 | resolve: { |
| 402 | transportista: function() { | 486 | transportista: function() { |
| 403 | return false; | 487 | return false; |
| 404 | } | 488 | } |
| 405 | } | 489 | } |
| 406 | } | 490 | } |
| 407 | ); | 491 | ); |
| 408 | modalInstance.result.then( | 492 | modalInstance.result.then( |
| 409 | function(proveedor) { | 493 | function(proveedor) { |
| 410 | $scope.remito.proveedor.codigo = proveedor.COD; | 494 | $scope.remito.proveedor.codigo = proveedor.COD; |
| 411 | addCabecera('Proveedor:', proveedor.NOM); | 495 | addCabecera('Proveedor:', proveedor.NOM); |
| 412 | }, function() { | 496 | }, function() { |
| 413 | 497 | ||
| 414 | } | 498 | } |
| 415 | ); | 499 | ); |
| 416 | }; | 500 | }; |
| 417 | 501 | ||
| 418 | $scope.seleccionarCliente = function() { | 502 | $scope.seleccionarCliente = function() { |
| 419 | 503 | ||
| 420 | var modalInstance = $uibModal.open( | 504 | var modalInstance = $uibModal.open( |
| 421 | { | 505 | { |
| 422 | ariaLabelledBy: 'Busqueda de Cliente', | 506 | ariaLabelledBy: 'Busqueda de Cliente', |
| 423 | templateUrl: 'foca-busqueda-cliente-modal.html', | 507 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 424 | controller: 'focaBusquedaClienteModalController', | 508 | controller: 'focaBusquedaClienteModalController', |
| 425 | size: 'lg' | 509 | size: 'lg' |
| 426 | } | 510 | } |
| 427 | ); | 511 | ); |
| 428 | modalInstance.result.then( | 512 | modalInstance.result.then( |
| 429 | function(cliente) { | 513 | function(cliente) { |
| 430 | $scope.abrirModalDomicilios(cliente); | 514 | $scope.abrirModalDomicilios(cliente); |
| 431 | }, function() { | 515 | }, function() { |
| 432 | 516 | ||
| 433 | } | 517 | } |
| 434 | ); | 518 | ); |
| 435 | }; | 519 | }; |
| 436 | 520 | ||
| 437 | $scope.abrirModalDomicilios = function(cliente) { | 521 | $scope.abrirModalDomicilios = function(cliente) { |
| 438 | var modalInstanceDomicilio = $uibModal.open( | 522 | var modalInstanceDomicilio = $uibModal.open( |
| 439 | { | 523 | { |
| 440 | ariaLabelledBy: 'Busqueda de Domicilios', | 524 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 441 | templateUrl: 'modal-domicilio.html', | 525 | templateUrl: 'modal-domicilio.html', |
| 442 | controller: 'focaModalDomicilioController', | 526 | controller: 'focaModalDomicilioController', |
| 443 | resolve: { idCliente: function() { return cliente.cod; }}, | 527 | resolve: { idCliente: function() { return cliente.cod; }}, |
| 444 | size: 'lg', | 528 | size: 'lg', |
| 445 | } | 529 | } |
| 446 | ); | 530 | ); |
| 447 | modalInstanceDomicilio.result.then( | 531 | modalInstanceDomicilio.result.then( |
| 448 | function(domicilio) { | 532 | function(domicilio) { |
| 449 | $scope.remito.domicilio.id = domicilio.nivel2; | 533 | $scope.remito.domicilio.id = domicilio.nivel2; |
| 450 | $scope.remito.cliente = cliente; | 534 | $scope.remito.cliente = cliente; |
| 451 | 535 | ||
| 452 | addCabecera('Cliente:', cliente.nom); | 536 | addCabecera('Cliente:', cliente.nom); |
| 453 | addCabecera('Domicilio:', domicilio.dom); | 537 | addCabecera('Domicilio:', domicilio.dom); |
| 454 | }, function() { | 538 | }, function() { |
| 455 | $scope.seleccionarCliente(); | 539 | $scope.seleccionarCliente(); |
| 456 | return; | 540 | return; |
| 457 | } | 541 | } |
| 458 | ); | 542 | ); |
| 459 | }; | 543 | }; |
| 460 | 544 | ||
| 461 | $scope.mostrarFichaCliente = function() { | 545 | $scope.mostrarFichaCliente = function() { |
| 462 | $uibModal.open( | 546 | $uibModal.open( |
| 463 | { | 547 | { |
| 464 | ariaLabelledBy: 'Datos del Cliente', | 548 | ariaLabelledBy: 'Datos del Cliente', |
| 465 | templateUrl: 'foca-crear-remito-ficha-cliente.html', | 549 | templateUrl: 'foca-crear-remito-ficha-cliente.html', |
| 466 | controller: 'focaCrearRemitoFichaClienteController', | 550 | controller: 'focaCrearRemitoFichaClienteController', |
| 467 | size: 'lg' | 551 | size: 'lg' |
| 468 | } | 552 | } |
| 469 | ); | 553 | ); |
| 470 | }; | 554 | }; |
| 471 | 555 | ||
| 472 | $scope.getTotal = function() { | 556 | $scope.getTotal = function() { |
| 473 | var total = 0; | 557 | var total = 0; |
| 474 | var arrayTempArticulos = $scope.articulosTabla; | 558 | var arrayTempArticulos = $scope.articulosTabla; |
| 475 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 559 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 476 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 560 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 477 | } | 561 | } |
| 478 | return parseFloat(total.toFixed(2)); | 562 | return parseFloat(total.toFixed(2)); |
| 479 | }; | 563 | }; |
| 480 | 564 | ||
| 481 | $scope.getSubTotal = function() { | 565 | $scope.getSubTotal = function() { |
| 482 | if($scope.articuloACargar) { | 566 | if($scope.articuloACargar) { |
| 483 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 567 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 484 | } | 568 | } |
| 485 | }; | 569 | }; |
| 486 | 570 | ||
| 487 | $scope.abrirModalListaPrecio = function() { | 571 | $scope.abrirModalListaPrecio = function() { |
| 488 | var modalInstance = $uibModal.open( | 572 | var modalInstance = $uibModal.open( |
| 489 | { | 573 | { |
| 490 | ariaLabelledBy: 'Busqueda de Precio Condición', | 574 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 491 | templateUrl: 'modal-precio-condicion.html', | 575 | templateUrl: 'modal-precio-condicion.html', |
| 492 | controller: 'focaModalPrecioCondicionController', | 576 | controller: 'focaModalPrecioCondicionController', |
| 493 | size: 'lg' | 577 | size: 'lg' |
| 494 | } | 578 | } |
| 495 | ); | 579 | ); |
| 496 | modalInstance.result.then( | 580 | modalInstance.result.then( |
| 497 | function(precioCondicion) { | 581 | function(precioCondicion) { |
| 498 | var cabecera = ''; | 582 | var cabecera = ''; |
| 499 | var plazosConcat = ''; | 583 | var plazosConcat = ''; |
| 500 | if(!Array.isArray(precioCondicion)) { | 584 | if(!Array.isArray(precioCondicion)) { |
| 585 | $scope.remito.idPrecioCondicion = precioCondicion.id; | ||
| 501 | $scope.plazosPagos = precioCondicion.plazoPago; | 586 | $scope.plazosPagos = precioCondicion.plazoPago; |
| 502 | $scope.idLista = precioCondicion.idListaPrecio; | 587 | $scope.idLista = precioCondicion.idListaPrecio; |
| 503 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 588 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 504 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 589 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 505 | } | 590 | } |
| 506 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 591 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 507 | } else { //Cuando se ingresan los plazos manualmente | 592 | } else { //Cuando se ingresan los plazos manualmente |
| 593 | $scope.remito.idPrecioCondicion = 0; | ||
| 508 | $scope.idLista = -1; //-1, el modal productos busca todos los productos | 594 | $scope.idLista = -1; //-1, el modal productos busca todos los productos |
| 509 | $scope.plazosPagos = precioCondicion; | 595 | $scope.plazosPagos = precioCondicion; |
| 510 | for(var j = 0; j < precioCondicion.length; j++) { | 596 | for(var j = 0; j < precioCondicion.length; j++) { |
| 511 | plazosConcat += precioCondicion[j].dias + ' '; | 597 | plazosConcat += precioCondicion[j].dias + ' '; |
| 512 | } | 598 | } |
| 513 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 599 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 514 | } | 600 | } |
| 515 | $scope.articulosTabla = []; | 601 | $scope.articulosTabla = []; |
| 516 | addCabecera('Precios y condiciones:', cabecera); | 602 | addCabecera('Precios y condiciones:', cabecera); |
| 517 | }, function() { | 603 | }, function() { |
| 518 | 604 | ||
| 519 | } | 605 | } |
| 520 | ); | 606 | ); |
| 521 | }; | 607 | }; |
| 522 | 608 | ||
| 523 | $scope.abrirModalFlete = function() { | 609 | $scope.abrirModalFlete = function() { |
| 524 | var modalInstance = $uibModal.open( | 610 | var modalInstance = $uibModal.open( |
| 525 | { | 611 | { |
| 526 | ariaLabelledBy: 'Busqueda de Flete', | 612 | ariaLabelledBy: 'Busqueda de Flete', |
| 527 | templateUrl: 'modal-flete.html', | 613 | templateUrl: 'modal-flete.html', |
| 528 | controller: 'focaModalFleteController', | 614 | controller: 'focaModalFleteController', |
| 529 | size: 'lg', | 615 | size: 'lg', |
| 530 | resolve: { | 616 | resolve: { |
| 531 | parametrosFlete: | 617 | parametrosFlete: |
| 532 | function() { | 618 | function() { |
| 533 | return { | 619 | return { |
| 534 | flete: $scope.remito.flete ? '1' : | 620 | flete: $scope.remito.flete ? '1' : |
| 535 | ($scope.remito.fob ? 'FOB' : | 621 | ($scope.remito.fob ? 'FOB' : |
| 536 | ($scope.remito.flete === undefined ? null : '0')), | 622 | ($scope.remito.flete === undefined ? null : '0')), |
| 537 | bomba: $scope.remito.bomba ? '1' : | 623 | bomba: $scope.remito.bomba ? '1' : |
| 538 | ($scope.remito.bomba === undefined ? null : '0'), | 624 | ($scope.remito.bomba === undefined ? null : '0'), |
| 539 | kilometros: $scope.remito.kilometros | 625 | kilometros: $scope.remito.kilometros |
| 540 | }; | 626 | }; |
| 541 | } | 627 | } |
| 542 | } | 628 | } |
| 543 | } | 629 | } |
| 544 | ); | 630 | ); |
| 545 | modalInstance.result.then( | 631 | modalInstance.result.then( |
| 546 | function(datos) { | 632 | function(datos) { |
| 547 | $scope.remito.flete = datos.flete; | 633 | $scope.remito.flete = datos.flete; |
| 548 | $scope.remito.fob = datos.FOB; | 634 | $scope.remito.fob = datos.FOB; |
| 549 | $scope.remito.bomba = datos.bomba; | 635 | $scope.remito.bomba = datos.bomba; |
| 550 | $scope.remito.kilometros = datos.kilometros; | 636 | $scope.remito.kilometros = datos.kilometros; |
| 551 | 637 | ||
| 552 | addCabecera('Flete:', datos.flete ? 'Si' : | 638 | addCabecera('Flete:', datos.flete ? 'Si' : |
| 553 | ($scope.remito.fob ? 'FOB' : 'No')); | 639 | ($scope.remito.fob ? 'FOB' : 'No')); |
| 554 | if(datos.flete) { | 640 | if(datos.flete) { |
| 555 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); | 641 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); |
| 556 | addCabecera('Kilometros:', datos.kilometros); | 642 | addCabecera('Kilometros:', datos.kilometros); |
| 557 | } else { | 643 | } else { |
| 558 | removeCabecera('Bomba:'); | 644 | removeCabecera('Bomba:'); |
| 559 | removeCabecera('Kilometros:'); | 645 | removeCabecera('Kilometros:'); |
| 560 | $scope.remito.fob = false; | 646 | $scope.remito.fob = false; |
| 561 | $scope.remito.bomba = false; | 647 | $scope.remito.bomba = false; |
| 562 | $scope.remito.kilometros = null; | 648 | $scope.remito.kilometros = null; |
| 563 | } | 649 | } |
| 564 | }, function() { | 650 | }, function() { |
| 565 | 651 | ||
| 566 | } | 652 | } |
| 567 | ); | 653 | ); |
| 568 | }; | 654 | }; |
| 569 | 655 | ||
| 570 | $scope.abrirModalMoneda = function() { | 656 | $scope.abrirModalMoneda = function() { |
| 571 | var modalInstance = $uibModal.open( | 657 | var modalInstance = $uibModal.open( |
| 572 | { | 658 | { |
| 573 | ariaLabelledBy: 'Busqueda de Moneda', | 659 | ariaLabelledBy: 'Busqueda de Moneda', |
| 574 | templateUrl: 'modal-moneda.html', | 660 | templateUrl: 'modal-moneda.html', |
| 575 | controller: 'focaModalMonedaController', | 661 | controller: 'focaModalMonedaController', |
| 576 | size: 'lg' | 662 | size: 'lg' |
| 577 | } | 663 | } |
| 578 | ); | 664 | ); |
| 579 | modalInstance.result.then( | 665 | modalInstance.result.then( |
| 580 | function(moneda) { | 666 | function(moneda) { |
| 581 | $scope.abrirModalCotizacion(moneda); | 667 | $scope.abrirModalCotizacion(moneda); |
| 582 | }, function() { | 668 | }, function() { |
| 583 | 669 | ||
| 584 | } | 670 | } |
| 585 | ); | 671 | ); |
| 586 | }; | 672 | }; |
| 587 | 673 | ||
| 588 | $scope.abrirModalCotizacion = function(moneda) { | 674 | $scope.abrirModalCotizacion = function(moneda) { |
| 589 | var modalInstance = $uibModal.open( | 675 | var modalInstance = $uibModal.open( |
| 590 | { | 676 | { |
| 591 | ariaLabelledBy: 'Busqueda de Cotización', | 677 | ariaLabelledBy: 'Busqueda de Cotización', |
| 592 | templateUrl: 'modal-cotizacion.html', | 678 | templateUrl: 'modal-cotizacion.html', |
| 593 | controller: 'focaModalCotizacionController', | 679 | controller: 'focaModalCotizacionController', |
| 594 | size: 'lg', | 680 | size: 'lg', |
| 595 | resolve: {idMoneda: function() {return moneda.ID;}} | 681 | resolve: {idMoneda: function() {return moneda.ID;}} |
| 596 | } | 682 | } |
| 597 | ); | 683 | ); |
| 598 | modalInstance.result.then( | 684 | modalInstance.result.then( |
| 599 | function(cotizacion) { | 685 | function(cotizacion) { |
| 600 | var articulosTablaTemp = $scope.articulosTabla; | 686 | var articulosTablaTemp = $scope.articulosTabla; |
| 601 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 687 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
| 602 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 688 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 603 | $scope.remito.cotizacion.COTIZACION; | 689 | $scope.remito.cotizacion.COTIZACION; |
| 604 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 690 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 605 | cotizacion.COTIZACION; | 691 | cotizacion.COTIZACION; |
| 606 | } | 692 | } |
| 607 | $scope.articulosTabla = articulosTablaTemp; | 693 | $scope.articulosTabla = articulosTablaTemp; |
| 608 | $scope.remito.moneda = { | 694 | $scope.remito.moneda = { |
| 609 | id: moneda.ID, | 695 | id: moneda.ID, |
| 610 | detalle: moneda.DETALLE, | 696 | detalle: moneda.DETALLE, |
| 611 | simbolo: moneda.SIMBOLO | 697 | simbolo: moneda.SIMBOLO |
| 612 | }; | 698 | }; |
| 613 | $scope.remito.cotizacion = { | 699 | $scope.remito.cotizacion = { |
| 614 | ID: cotizacion.ID, | 700 | ID: cotizacion.ID, |
| 615 | COTIZACION: cotizacion.COTIZACION, | 701 | COTIZACION: cotizacion.COTIZACION, |
| 616 | FECHA: cotizacion.FECHA | 702 | FECHA: cotizacion.FECHA |
| 617 | }; | 703 | }; |
| 618 | addCabecera('Moneda:', moneda.DETALLE); | 704 | addCabecera('Moneda:', moneda.DETALLE); |
| 619 | addCabecera( | 705 | addCabecera( |
| 620 | 'Fecha cotizacion:', | 706 | 'Fecha cotizacion:', |
| 621 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 707 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 622 | ); | 708 | ); |
| 623 | addCabecera('Cotizacion:', cotizacion.COTIZACION); | 709 | addCabecera('Cotizacion:', cotizacion.COTIZACION); |
| 624 | }, function() { | 710 | }, function() { |
| 625 | 711 | ||
| 626 | } | 712 | } |
| 627 | ); | 713 | ); |
| 628 | }; | 714 | }; |
| 629 | 715 | ||
| 630 | $scope.agregarATabla = function(key) { | 716 | $scope.agregarATabla = function(key) { |
| 631 | if(key === 13) { | 717 | if(key === 13) { |
| 632 | if($scope.articuloACargar.cantidad === undefined || | 718 | if($scope.articuloACargar.cantidad === undefined || |
| 633 | $scope.articuloACargar.cantidad === 0 || | 719 | $scope.articuloACargar.cantidad === 0 || |
| 634 | $scope.articuloACargar.cantidad === null ) { | 720 | $scope.articuloACargar.cantidad === null ) { |
| 635 | focaModalService.alert('El valor debe ser al menos 1'); | 721 | focaModalService.alert('El valor debe ser al menos 1'); |
| 636 | return; | 722 | return; |
| 637 | } | 723 | } |
| 638 | delete $scope.articuloACargar.sectorCodigo; | 724 | delete $scope.articuloACargar.sectorCodigo; |
| 639 | $scope.articulosTabla.push($scope.articuloACargar); | 725 | $scope.articulosTabla.push($scope.articuloACargar); |
| 640 | $scope.cargando = true; | 726 | $scope.cargando = true; |
| 641 | } | 727 | } |
| 642 | }; | 728 | }; |
| 643 | 729 | ||
| 644 | $scope.quitarArticulo = function(key) { | 730 | $scope.quitarArticulo = function(key) { |
| 645 | $scope.articulosTabla.splice(key, 1); | 731 | $scope.articulosTabla.splice(key, 1); |
| 646 | }; | 732 | }; |
| 647 | 733 | ||
| 648 | $scope.editarArticulo = function(key, articulo) { | 734 | $scope.editarArticulo = function(key, articulo) { |
| 649 | if(key === 13) { | 735 | if(key === 13) { |
| 650 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 736 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
| 651 | articulo.cantidad === undefined) { | 737 | articulo.cantidad === undefined) { |
| 652 | focaModalService.alert('El valor debe ser al menos 1'); | 738 | focaModalService.alert('El valor debe ser al menos 1'); |
| 653 | return; | 739 | return; |
| 654 | } | 740 | } |
| 655 | articulo.editCantidad = false; | 741 | articulo.editCantidad = false; |
| 656 | articulo.editPrecio = false; | 742 | articulo.editPrecio = false; |
| 657 | } | 743 | } |
| 658 | }; | 744 | }; |
| 659 | 745 | ||
| 660 | $scope.cambioEdit = function(articulo, propiedad) { | 746 | $scope.cambioEdit = function(articulo, propiedad) { |
| 661 | if(propiedad === 'cantidad') { | 747 | if(propiedad === 'cantidad') { |
| 662 | articulo.editCantidad = true; | 748 | articulo.editCantidad = true; |
| 663 | } else if(propiedad === 'precio') { | 749 | } else if(propiedad === 'precio') { |
| 664 | articulo.editPrecio = true; | 750 | articulo.editPrecio = true; |
| 665 | } | 751 | } |
| 666 | }; | 752 | }; |
| 667 | 753 | ||
| 668 | $scope.limpiarFlete = function() { | 754 | $scope.limpiarFlete = function() { |
| 669 | $scope.remito.fleteNombre = ''; | 755 | $scope.remito.fleteNombre = ''; |
| 670 | $scope.remito.chofer = ''; | 756 | $scope.remito.chofer = ''; |
| 671 | $scope.remito.vehiculo = ''; | 757 | $scope.remito.vehiculo = ''; |
| 672 | $scope.remito.kilometros = ''; | 758 | $scope.remito.kilometros = ''; |
| 673 | $scope.remito.costoUnitarioKmFlete = ''; | 759 | $scope.remito.costoUnitarioKmFlete = ''; |
| 674 | $scope.choferes = ''; | 760 | $scope.choferes = ''; |
| 675 | $scope.vehiculos = ''; | 761 | $scope.vehiculos = ''; |
| 676 | }; | 762 | }; |
| 677 | 763 | ||
| 678 | $scope.limpiarPantalla = function() { | 764 | $scope.limpiarPantalla = function() { |
| 679 | $scope.limpiarFlete(); | 765 | $scope.limpiarFlete(); |
| 680 | $scope.remito.flete = '0'; | 766 | $scope.remito.flete = '0'; |
| 681 | $scope.remito.bomba = '0'; | 767 | $scope.remito.bomba = '0'; |
| 682 | $scope.remito.precioCondicion = ''; | 768 | $scope.remito.precioCondicion = ''; |
| 683 | $scope.articulosTabla = []; | 769 | $scope.articulosTabla = []; |
| 684 | $scope.remito.vendedor.nombre = ''; | 770 | $scope.remito.vendedor.nombre = ''; |
| 685 | $scope.remito.cliente = {nombre: ''}; | 771 | $scope.remito.cliente = {nombre: ''}; |
| 686 | $scope.remito.domicilio = {dom: ''}; | 772 | $scope.remito.domicilio = {dom: ''}; |
| 687 | $scope.domiciliosCliente = []; | 773 | $scope.domiciliosCliente = []; |
| 688 | }; | 774 | }; |
| 689 | 775 | ||
| 690 | $scope.resetFilter = function() { | 776 | $scope.resetFilter = function() { |
| 691 | $scope.articuloACargar = {}; | 777 | $scope.articuloACargar = {}; |
| 692 | $scope.cargando = true; | 778 | $scope.cargando = true; |
| 693 | }; | 779 | }; |
| 694 | 780 | ||
| 695 | $scope.selectFocus = function($event) { | 781 | $scope.selectFocus = function($event) { |
| 696 | $event.target.select(); | 782 | $event.target.select(); |
| 697 | }; | 783 | }; |
| 698 | 784 | ||
| 699 | $scope.salir = function() { | 785 | $scope.salir = function() { |
| 700 | $location.path('/'); | 786 | $location.path('/'); |
| 701 | }; | 787 | }; |
| 702 | function addArrayCabecera(array) { | 788 | function addArrayCabecera(array) { |
| 703 | for(var i = 0; i < array.length; i++) { | 789 | for(var i = 0; i < array.length; i++) { |
| 704 | addCabecera(array[i].label, array[i].valor); | 790 | addCabecera(array[i].label, array[i].valor); |
| 705 | } | 791 | } |
| 706 | } | 792 | } |
| 707 | 793 | ||
| 708 | function addCabecera(label, valor) { | 794 | function addCabecera(label, valor) { |
| 709 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 795 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 710 | if(propiedad.length === 1) { | 796 | if(propiedad.length === 1) { |
| 711 | propiedad[0].valor = valor; | 797 | propiedad[0].valor = valor; |
| 712 | } else { | 798 | } else { |
| 713 | $scope.cabecera.push({label: label, valor: valor}); | 799 | $scope.cabecera.push({label: label, valor: valor}); |
| 714 | } | 800 | } |
| 715 | } | 801 | } |
| 716 | 802 | ||
| 717 | function removeCabecera(label) { | 803 | function removeCabecera(label) { |
| 718 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 804 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 719 | if(propiedad.length === 1) { | 805 | if(propiedad.length === 1) { |
| 720 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 806 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
| 721 | } | 807 | } |
| 722 | } | 808 | } |
| 723 | 809 | ||
| 724 | function rellenar(relleno, longitud) { | 810 | function rellenar(relleno, longitud) { |
| 725 | relleno = '' + relleno; | 811 | relleno = '' + relleno; |
| 726 | while (relleno.length < longitud) { | 812 | while (relleno.length < longitud) { |
| 727 | relleno = '0' + relleno; | 813 | relleno = '0' + relleno; |
| 728 | } | 814 | } |
| 729 | 815 | ||
| 730 | return relleno; | 816 | return relleno; |
| 731 | } | 817 | } |
| 732 | } | 818 | } |
| 733 | ] | 819 | ] |
| 734 | ) | 820 | ) |
| 735 | .controller('remitoListaCtrl', [ | 821 | .controller('remitoListaCtrl', [ |
| 736 | '$scope', | 822 | '$scope', |
| 737 | 'crearRemitoService', | 823 | 'crearRemitoService', |
| 738 | '$location', | 824 | '$location', |
| 739 | function($scope, crearRemitoService, $location) { | 825 | function($scope, crearRemitoService, $location) { |
| 740 | crearRemitoService.obtenerRemito().then(function(datos) { | 826 | crearRemitoService.obtenerRemito().then(function(datos) { |
| 741 | $scope.remitos = datos.data; | 827 | $scope.remitos = datos.data; |
| 742 | }); | 828 | }); |
| 743 | $scope.editar = function(remito) { | 829 | $scope.editar = function(remito) { |
| 744 | crearRemitoService.setRemito(remito); | 830 | crearRemitoService.setRemito(remito); |
| 745 | $location.path('/venta-nota-remito/abm/'); | 831 | $location.path('/venta-nota-remito/abm/'); |
| 746 | }; | 832 | }; |
| 747 | $scope.crearRemito = function() { | 833 | $scope.crearRemito = function() { |
| 748 | crearRemitoService.clearRemito(); | 834 | crearRemitoService.clearRemito(); |
| 749 | $location.path('/venta-nota-remito/abm/'); | 835 | $location.path('/venta-nota-remito/abm/'); |
| 750 | }; | 836 | }; |
| 751 | } | 837 | } |
| 752 | ]) | 838 | ]) |
| 753 | .controller('focaCrearRemitoFichaClienteController', [ | 839 | .controller('focaCrearRemitoFichaClienteController', [ |
| 754 | '$scope', | 840 | '$scope', |
| 755 | 'crearRemitoService', | 841 | 'crearRemitoService', |
| 756 | '$location', | 842 | '$location', |
| 757 | function($scope, crearRemitoService, $location) { | 843 | function($scope, crearRemitoService, $location) { |
| 758 | crearRemitoService.obtenerRemito().then(function(datos) { | 844 | crearRemitoService.obtenerRemito().then(function(datos) { |
| 759 | $scope.remitos = datos.data; | 845 | $scope.remitos = datos.data; |
| 760 | }); | 846 | }); |
| 761 | $scope.editar = function(remito) { | 847 | $scope.editar = function(remito) { |
| 762 | crearRemitoService.setRemito(remito); | 848 | crearRemitoService.setRemito(remito); |
| 763 | $location.path('/venta-nota-remito/abm/'); | 849 | $location.path('/venta-nota-remito/abm/'); |
| 764 | }; | 850 | }; |
| 765 | $scope.crearRemito = function() { | 851 | $scope.crearRemito = function() { |
| 766 | crearRemitoService.clearRemito(); | 852 | crearRemitoService.clearRemito(); |
| 767 | $location.path('/venta-nota-remito/abm/'); | 853 | $location.path('/venta-nota-remito/abm/'); |
| 768 | }; | 854 | }; |
| 769 | } | 855 | } |
| 770 | ]); | 856 | ]); |
| 771 | 857 |