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