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