Commit 4d3c8061b6d32797b5cbb60014d892321fa65ecf
Exists in
master
Merge branch 'master' into 'master'
Master See merge request modulos-npm/foca-crear-nota-pedido!73
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', 'focaSeguimientoService', 'notaPedidoBusinessService', | 4 | 'focaModalService', 'focaSeguimientoService', 'notaPedidoBusinessService', |
| 5 | '$rootScope', | ||
| 5 | function( | 6 | function( |
| 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, | 7 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, |
| 7 | focaSeguimientoService, notaPedidoBusinessService | 8 | focaSeguimientoService, notaPedidoBusinessService, $rootScope |
| 8 | ) { | 9 | ) { |
| 9 | $scope.botonera = [ | 10 | $scope.botonera = [ |
| 10 | {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, | 11 | {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, |
| 11 | {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, | 12 | {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, |
| 12 | {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, | 13 | {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, |
| 13 | {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, | 14 | {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, |
| 14 | { | 15 | { |
| 15 | texto: 'Precios y condiciones', | 16 | texto: 'Precios y condiciones', |
| 16 | accion: function() {$scope.abrirModalListaPrecio();}}, | 17 | accion: function() {$scope.abrirModalListaPrecio();}}, |
| 17 | {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, | 18 | {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, |
| 18 | {texto: '', accion: function() {}}, | 19 | {texto: '', accion: function() {}}, |
| 19 | {texto: '', accion: function() {}} | 20 | {texto: '', accion: function() {}} |
| 20 | ]; | 21 | ]; |
| 21 | $scope.datepickerAbierto = false; | 22 | $scope.datepickerAbierto = false; |
| 22 | 23 | ||
| 23 | $scope.show = false; | 24 | $scope.show = false; |
| 24 | $scope.cargando = true; | 25 | $scope.cargando = true; |
| 25 | $scope.dateOptions = { | 26 | $scope.dateOptions = { |
| 26 | maxDate: new Date(), | 27 | maxDate: new Date(), |
| 27 | minDate: new Date(2010, 0, 1) | 28 | minDate: new Date(2010, 0, 1) |
| 28 | }; | 29 | }; |
| 29 | 30 | ||
| 30 | $scope.notaPedido = { | 31 | $scope.notaPedido = { |
| 31 | vendedor: {}, | 32 | vendedor: {}, |
| 32 | cliente: {}, | 33 | cliente: {}, |
| 33 | proveedor: {}, | 34 | proveedor: {}, |
| 34 | domicilio: {dom: ''}, | 35 | domicilio: {dom: ''}, |
| 35 | moneda: {}, | 36 | moneda: {}, |
| 36 | cotizacion: {} | 37 | cotizacion: {} |
| 37 | }; | 38 | }; |
| 38 | var monedaPorDefecto; | 39 | var monedaPorDefecto; |
| 39 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 40 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
| 40 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 41 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
| 41 | monedaPorDefecto = { | 42 | monedaPorDefecto = { |
| 42 | id: res.data[0].ID, | 43 | id: res.data[0].ID, |
| 43 | detalle: res.data[0].DETALLE, | 44 | detalle: res.data[0].DETALLE, |
| 44 | simbolo: res.data[0].SIMBOLO, | 45 | simbolo: res.data[0].SIMBOLO, |
| 45 | cotizaciones: res.data[0].cotizaciones | 46 | cotizaciones: res.data[0].cotizaciones |
| 46 | }; | 47 | }; |
| 47 | addCabecera('Moneda:', monedaPorDefecto.detalle); | 48 | addCabecera('Moneda:', monedaPorDefecto.detalle); |
| 48 | addCabecera('Fecha cotizacion:', | 49 | addCabecera('Fecha cotizacion:', |
| 49 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); | 50 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); |
| 50 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); | 51 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); |
| 51 | $scope.notaPedido.moneda = monedaPorDefecto; | 52 | $scope.notaPedido.moneda = monedaPorDefecto; |
| 52 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | 53 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; |
| 53 | }); | 54 | }); |
| 54 | 55 | ||
| 55 | $scope.cabecera = []; | 56 | $scope.cabecera = []; |
| 56 | $scope.showCabecera = true; | 57 | $scope.showCabecera = true; |
| 57 | 58 | ||
| 58 | $scope.now = new Date(); | 59 | $scope.now = new Date(); |
| 59 | $scope.puntoVenta = '0000'; | 60 | $scope.puntoVenta = '0000'; |
| 60 | $scope.comprobante = '00000000'; | 61 | $scope.comprobante = '00000000'; |
| 61 | $scope.articulosTabla = []; | 62 | $scope.articulosTabla = []; |
| 62 | $scope.idLista = undefined; | 63 | $scope.idLista = undefined; |
| 63 | //La pantalla solo se usa para cargar pedidos | 64 | //La pantalla solo se usa para cargar pedidos |
| 64 | //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); | 65 | //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); |
| 65 | 66 | ||
| 66 | crearNotaPedidoService.getPrecioCondicion().then( | 67 | crearNotaPedidoService.getPrecioCondicion().then( |
| 67 | function(res) { | 68 | function(res) { |
| 68 | $scope.precioCondiciones = res.data; | 69 | $scope.precioCondiciones = res.data; |
| 69 | } | 70 | } |
| 70 | ); | 71 | ); |
| 71 | 72 | ||
| 72 | crearNotaPedidoService.getNumeroNotaPedido().then( | 73 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 73 | function(res) { | 74 | function(res) { |
| 74 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 75 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 75 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 76 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
| 76 | }, | 77 | }, |
| 77 | function(err) { | 78 | function(err) { |
| 78 | focaModalService.alert('La terminal no esta configurada correctamente'); | 79 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 79 | console.info(err); | 80 | console.info(err); |
| 80 | } | 81 | } |
| 81 | ); | 82 | ); |
| 82 | //La pantalla solo se usa para cargar pedidos | 83 | //La pantalla solo se usa para cargar pedidos |
| 83 | // if (notaPedidoTemp !== undefined) { | 84 | // if (notaPedidoTemp !== undefined) { |
| 84 | // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); | 85 | // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); |
| 85 | // $scope.notaPedido = notaPedidoTemp; | 86 | // $scope.notaPedido = notaPedidoTemp; |
| 86 | // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); | 87 | // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); |
| 87 | // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); | 88 | // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); |
| 88 | // $scope.idLista = $scope.notaPedido.precioCondicion; | 89 | // $scope.idLista = $scope.notaPedido.precioCondicion; |
| 89 | // crearNotaPedidoService | 90 | // crearNotaPedidoService |
| 90 | // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( | 91 | // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( |
| 91 | // function(res) { | 92 | // function(res) { |
| 92 | // $scope.articulosTabla = res.data; | 93 | // $scope.articulosTabla = res.data; |
| 93 | // } | 94 | // } |
| 94 | // ); | 95 | // ); |
| 95 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO | 96 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO |
| 96 | //(NO REQUERIDO EN ESTA VERSION) | 97 | //(NO REQUERIDO EN ESTA VERSION) |
| 97 | // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( | 98 | // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( |
| 98 | // function(res) { | 99 | // function(res) { |
| 99 | // $scope.notaPedido.domicilio = res.data; | 100 | // $scope.notaPedido.domicilio = res.data; |
| 100 | // } | 101 | // } |
| 101 | // ); | 102 | // ); |
| 102 | // } else { | 103 | // } else { |
| 103 | // $scope.notaPedido.fechaCarga = new Date(); | 104 | // $scope.notaPedido.fechaCarga = new Date(); |
| 104 | // $scope.notaPedido.bomba = '0'; | 105 | // $scope.notaPedido.bomba = '0'; |
| 105 | // $scope.notaPedido.flete = '0'; | 106 | // $scope.notaPedido.flete = '0'; |
| 106 | // $scope.idLista = undefined; | 107 | // $scope.idLista = undefined; |
| 107 | // } | 108 | // } |
| 108 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO | 109 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO |
| 109 | // $scope.addNewDom = function() { | 110 | // $scope.addNewDom = function() { |
| 110 | // $scope.notaPedido.domicilio.push({ 'id': 0 }); | 111 | // $scope.notaPedido.domicilio.push({ 'id': 0 }); |
| 111 | // }; | 112 | // }; |
| 112 | // $scope.removeNewChoice = function(choice) { | 113 | // $scope.removeNewChoice = function(choice) { |
| 113 | // if ($scope.notaPedido.domicilio.length > 1) { | 114 | // if ($scope.notaPedido.domicilio.length > 1) { |
| 114 | // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( | 115 | // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( |
| 115 | // function(c) { | 116 | // function(c) { |
| 116 | // return c.$$hashKey === choice.$$hashKey; | 117 | // return c.$$hashKey === choice.$$hashKey; |
| 117 | // } | 118 | // } |
| 118 | // ), 1); | 119 | // ), 1); |
| 119 | // } | 120 | // } |
| 120 | // }; | 121 | // }; |
| 121 | 122 | ||
| 122 | $scope.crearNotaPedido = function() { | 123 | $scope.crearNotaPedido = function() { |
| 123 | if(!$scope.notaPedido.vendedor.codigo) { | 124 | if(!$scope.notaPedido.vendedor.codigo) { |
| 124 | focaModalService.alert('Ingrese Vendedor'); | 125 | focaModalService.alert('Ingrese Vendedor'); |
| 125 | return; | 126 | return; |
| 126 | } else if(!$scope.notaPedido.cliente.cod) { | 127 | } else if(!$scope.notaPedido.cliente.cod) { |
| 127 | focaModalService.alert('Ingrese Cliente'); | 128 | focaModalService.alert('Ingrese Cliente'); |
| 128 | return; | 129 | return; |
| 129 | } else if(!$scope.notaPedido.proveedor.codigo) { | 130 | } else if(!$scope.notaPedido.proveedor.codigo) { |
| 130 | focaModalService.alert('Ingrese Proveedor'); | 131 | focaModalService.alert('Ingrese Proveedor'); |
| 131 | return; | 132 | return; |
| 132 | } else if(!$scope.notaPedido.moneda.id) { | 133 | } else if(!$scope.notaPedido.moneda.id) { |
| 133 | focaModalService.alert('Ingrese Moneda'); | 134 | focaModalService.alert('Ingrese Moneda'); |
| 134 | return; | 135 | return; |
| 135 | } else if(!$scope.notaPedido.cotizacion.ID) { | 136 | } else if(!$scope.notaPedido.cotizacion.ID) { |
| 136 | focaModalService.alert('Ingrese Cotización'); | 137 | focaModalService.alert('Ingrese Cotización'); |
| 137 | return; | 138 | return; |
| 138 | } else if(!$scope.plazosPagos) { | 139 | } else if(!$scope.plazosPagos) { |
| 139 | focaModalService.alert('Ingrese Precios y Condiciones'); | 140 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 140 | return; | 141 | return; |
| 141 | } else if( | 142 | } else if( |
| 142 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 143 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
| 143 | { | 144 | { |
| 144 | focaModalService.alert('Ingrese Flete'); | 145 | focaModalService.alert('Ingrese Flete'); |
| 145 | return; | 146 | return; |
| 146 | } else if(!$scope.notaPedido.domicilio.id) { | 147 | } else if(!$scope.notaPedido.domicilio.id) { |
| 147 | focaModalService.alert('Ingrese Domicilio'); | 148 | focaModalService.alert('Ingrese Domicilio'); |
| 148 | return; | 149 | return; |
| 149 | } else if($scope.articulosTabla.length === 0) { | 150 | } else if($scope.articulosTabla.length === 0) { |
| 150 | focaModalService.alert('Debe cargar al menos un articulo'); | 151 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 151 | return; | 152 | return; |
| 152 | } | 153 | } |
| 153 | var date = new Date(); | 154 | var date = new Date(); |
| 154 | var notaPedido = { | 155 | var notaPedido = { |
| 155 | id: 0, | 156 | id: 0, |
| 156 | fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | 157 | fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
| 157 | .toISOString().slice(0, 19).replace('T', ' '), | 158 | .toISOString().slice(0, 19).replace('T', ' '), |
| 158 | idVendedor: $scope.notaPedido.vendedor.codigo, | 159 | idVendedor: $scope.notaPedido.vendedor.codigo, |
| 159 | idCliente: $scope.notaPedido.cliente.cod, | 160 | idCliente: $scope.notaPedido.cliente.cod, |
| 160 | nombreCliente: $scope.notaPedido.cliente.nom, | 161 | nombreCliente: $scope.notaPedido.cliente.nom, |
| 161 | cuitCliente: $scope.notaPedido.cliente.cuit, | 162 | cuitCliente: $scope.notaPedido.cliente.cuit, |
| 162 | idProveedor: $scope.notaPedido.proveedor.codigo, | 163 | idProveedor: $scope.notaPedido.proveedor.codigo, |
| 163 | idDomicilio: $scope.notaPedido.domicilio.id, | 164 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 164 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 165 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 165 | cotizacion: $scope.notaPedido.cotizacion.COTIZACION, | 166 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 166 | flete: $scope.notaPedido.flete, | 167 | flete: $scope.notaPedido.flete, |
| 167 | fob: $scope.notaPedido.fob, | 168 | fob: $scope.notaPedido.fob, |
| 168 | bomba: $scope.notaPedido.bomba, | 169 | bomba: $scope.notaPedido.bomba, |
| 169 | kilometros: $scope.notaPedido.kilometros, | 170 | kilometros: $scope.notaPedido.kilometros, |
| 170 | estado: 0, | 171 | estado: 0, |
| 171 | total: $scope.getTotal() | 172 | total: $scope.getTotal() |
| 172 | }; | 173 | }; |
| 173 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 174 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 174 | function(data) { | 175 | function(data) { |
| 175 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 176 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
| 176 | data.data.id, $scope.notaPedido.cotizacion.COTIZACION); | 177 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 177 | focaSeguimientoService.guardarPosicion('crear nota pedido', ''); | 178 | focaSeguimientoService.guardarPosicion('crear nota pedido', ''); |
| 178 | var plazos = $scope.plazosPagos; | 179 | var plazos = $scope.plazosPagos; |
| 179 | 180 | ||
| 180 | for(var j = 0; j < plazos.length; j++) { | 181 | for(var j = 0; j < plazos.length; j++) { |
| 181 | var json = { | 182 | var json = { |
| 182 | idPedido: data.data.id, | 183 | idPedido: data.data.id, |
| 183 | dias: plazos[j].dias | 184 | dias: plazos[j].dias |
| 184 | }; | 185 | }; |
| 185 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); | 186 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); |
| 186 | } | 187 | } |
| 187 | notaPedidoBusinessService.addEstado(data.data.id, | 188 | notaPedidoBusinessService.addEstado(data.data.id, |
| 188 | $scope.notaPedido.vendedor.codigo); | 189 | $scope.notaPedido.vendedor.codigo); |
| 189 | 190 | ||
| 190 | focaModalService.alert('Nota pedido creada'); | 191 | focaModalService.alert('Nota pedido creada'); |
| 191 | $scope.cabecera = []; | 192 | $scope.cabecera = []; |
| 192 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); | 193 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); |
| 193 | addCabecera( | 194 | addCabecera( |
| 194 | 'Fecha cotizacion:', | 195 | 'Fecha cotizacion:', |
| 195 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 196 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
| 196 | ); | 197 | ); |
| 197 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.COTIZACION); | 198 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); |
| 198 | $scope.notaPedido.vendedor = {}; | 199 | $scope.notaPedido.vendedor = {}; |
| 199 | $scope.notaPedido.cliente = {}; | 200 | $scope.notaPedido.cliente = {}; |
| 200 | $scope.notaPedido.proveedor = {}; | 201 | $scope.notaPedido.proveedor = {}; |
| 201 | $scope.notaPedido.domicilio = {}; | 202 | $scope.notaPedido.domicilio = {}; |
| 202 | $scope.notaPedido.flete = null; | 203 | $scope.notaPedido.flete = null; |
| 203 | $scope.notaPedido.fob = null; | 204 | $scope.notaPedido.fob = null; |
| 204 | $scope.notaPedido.bomba = null; | 205 | $scope.notaPedido.bomba = null; |
| 205 | $scope.notaPedido.kilometros = null; | 206 | $scope.notaPedido.kilometros = null; |
| 206 | $scope.articulosTabla = []; | 207 | $scope.articulosTabla = []; |
| 207 | }, | 208 | }, |
| 208 | function(error) { | 209 | function(error) { |
| 209 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 210 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 210 | console.info(error); | 211 | console.info(error); |
| 211 | } | 212 | } |
| 212 | ); | 213 | ); |
| 213 | }; | 214 | }; |
| 214 | 215 | ||
| 215 | $scope.seleccionarArticulo = function() { | 216 | $scope.seleccionarArticulo = function() { |
| 216 | if ($scope.idLista === undefined) { | 217 | if ($scope.idLista === undefined) { |
| 217 | focaModalService.alert( | 218 | focaModalService.alert( |
| 218 | 'Primero seleccione una lista de precio y condicion'); | 219 | 'Primero seleccione una lista de precio y condicion'); |
| 219 | return; | 220 | return; |
| 220 | } | 221 | } |
| 221 | var modalInstance = $uibModal.open( | 222 | var modalInstance = $uibModal.open( |
| 222 | { | 223 | { |
| 223 | ariaLabelledBy: 'Busqueda de Productos', | 224 | ariaLabelledBy: 'Busqueda de Productos', |
| 224 | templateUrl: 'modal-busqueda-productos.html', | 225 | templateUrl: 'modal-busqueda-productos.html', |
| 225 | controller: 'modalBusquedaProductosCtrl', | 226 | controller: 'modalBusquedaProductosCtrl', |
| 226 | resolve: { | 227 | resolve: { |
| 227 | parametroProducto: { | 228 | parametroProducto: { |
| 228 | idLista: $scope.idLista, | 229 | idLista: $scope.idLista, |
| 229 | cotizacion: $scope.notaPedido.cotizacion.COTIZACION, | 230 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 230 | simbolo: $scope.notaPedido.moneda.simbolo | 231 | simbolo: $scope.notaPedido.moneda.simbolo |
| 231 | } | 232 | } |
| 232 | }, | 233 | }, |
| 233 | size: 'lg' | 234 | size: 'lg' |
| 234 | } | 235 | } |
| 235 | ); | 236 | ); |
| 236 | modalInstance.result.then( | 237 | modalInstance.result.then( |
| 237 | function(producto) { | 238 | function(producto) { |
| 238 | var newArt = | 239 | var newArt = |
| 239 | { | 240 | { |
| 240 | id: 0, | 241 | id: 0, |
| 241 | codigo: producto.codigo, | 242 | codigo: producto.codigo, |
| 242 | sector: producto.sector, | 243 | sector: producto.sector, |
| 243 | sectorCodigo: producto.sector + '-' + producto.codigo, | 244 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 244 | descripcion: producto.descripcion, | 245 | descripcion: producto.descripcion, |
| 245 | item: $scope.articulosTabla.length + 1, | 246 | item: $scope.articulosTabla.length + 1, |
| 246 | nombre: producto.descripcion, | 247 | nombre: producto.descripcion, |
| 247 | precio: parseFloat(producto.precio.toFixed(4)), | 248 | precio: parseFloat(producto.precio.toFixed(4)), |
| 248 | precioUnitario: producto.costo, | 249 | precioUnitario: producto.costo, |
| 249 | editCantidad: false, | 250 | editCantidad: false, |
| 250 | editPrecio: false | 251 | editPrecio: false |
| 251 | }; | 252 | }; |
| 252 | $scope.articuloACargar = newArt; | 253 | $scope.articuloACargar = newArt; |
| 253 | $scope.cargando = false; | 254 | $scope.cargando = false; |
| 254 | }, function() { | 255 | }, function() { |
| 255 | // funcion ejecutada cuando se cancela el modal | 256 | // funcion ejecutada cuando se cancela el modal |
| 256 | } | 257 | } |
| 257 | ); | 258 | ); |
| 258 | }; | 259 | }; |
| 259 | 260 | ||
| 260 | $scope.seleccionarVendedor = function() { | 261 | $scope.seleccionarVendedor = function() { |
| 261 | var modalInstance = $uibModal.open( | 262 | var modalInstance = $uibModal.open( |
| 262 | { | 263 | { |
| 263 | ariaLabelledBy: 'Busqueda de Vendedores', | 264 | ariaLabelledBy: 'Busqueda de Vendedores', |
| 264 | templateUrl: 'modal-vendedores.html', | 265 | templateUrl: 'modal-vendedores.html', |
| 265 | controller: 'modalVendedoresCtrl', | 266 | controller: 'modalVendedoresCtrl', |
| 266 | size: 'lg' | 267 | size: 'lg' |
| 267 | } | 268 | } |
| 268 | ); | 269 | ); |
| 269 | modalInstance.result.then( | 270 | modalInstance.result.then( |
| 270 | function(vendedor) { | 271 | function(vendedor) { |
| 271 | addCabecera('Vendedor:', vendedor.NomVen); | 272 | addCabecera('Vendedor:', vendedor.NomVen); |
| 272 | $scope.notaPedido.vendedor.codigo = vendedor.CodVen; | 273 | $scope.notaPedido.vendedor.codigo = vendedor.CodVen; |
| 273 | }, function() { | 274 | }, function() { |
| 274 | 275 | ||
| 275 | } | 276 | } |
| 276 | ); | 277 | ); |
| 277 | }; | 278 | }; |
| 278 | 279 | ||
| 279 | $scope.seleccionarProveedor = function() { | 280 | $scope.seleccionarProveedor = function() { |
| 280 | var modalInstance = $uibModal.open( | 281 | var modalInstance = $uibModal.open( |
| 281 | { | 282 | { |
| 282 | ariaLabelledBy: 'Busqueda de Proveedor', | 283 | ariaLabelledBy: 'Busqueda de Proveedor', |
| 283 | templateUrl: 'modal-proveedor.html', | 284 | templateUrl: 'modal-proveedor.html', |
| 284 | controller: 'focaModalProveedorCtrl', | 285 | controller: 'focaModalProveedorCtrl', |
| 285 | size: 'lg' | 286 | size: 'lg' |
| 286 | } | 287 | } |
| 287 | ); | 288 | ); |
| 288 | modalInstance.result.then( | 289 | modalInstance.result.then( |
| 289 | function(proveedor) { | 290 | function(proveedor) { |
| 290 | $scope.notaPedido.proveedor.codigo = proveedor.COD; | 291 | $scope.notaPedido.proveedor.codigo = proveedor.COD; |
| 291 | addCabecera('Proveedor:', proveedor.NOM); | 292 | addCabecera('Proveedor:', proveedor.NOM); |
| 292 | }, function() { | 293 | }, function() { |
| 293 | 294 | ||
| 294 | } | 295 | } |
| 295 | ); | 296 | ); |
| 296 | }; | 297 | }; |
| 297 | 298 | ||
| 298 | $scope.seleccionarCliente = function() { | 299 | $scope.seleccionarCliente = function() { |
| 299 | 300 | ||
| 300 | var modalInstance = $uibModal.open( | 301 | var modalInstance = $uibModal.open( |
| 301 | { | 302 | { |
| 302 | ariaLabelledBy: 'Busqueda de Cliente', | 303 | ariaLabelledBy: 'Busqueda de Cliente', |
| 303 | templateUrl: 'foca-busqueda-cliente-modal.html', | 304 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 304 | controller: 'focaBusquedaClienteModalController', | 305 | controller: 'focaBusquedaClienteModalController', |
| 305 | size: 'lg' | 306 | size: 'lg' |
| 306 | } | 307 | } |
| 307 | ); | 308 | ); |
| 308 | modalInstance.result.then( | 309 | modalInstance.result.then( |
| 309 | function(cliente) { | 310 | function(cliente) { |
| 310 | $scope.abrirModalDomicilios(cliente); | 311 | $scope.abrirModalDomicilios(cliente); |
| 311 | }, function() { | 312 | }, function() { |
| 312 | 313 | ||
| 313 | } | 314 | } |
| 314 | ); | 315 | ); |
| 315 | }; | 316 | }; |
| 316 | 317 | ||
| 317 | $scope.abrirModalDomicilios = function(cliente) { | 318 | $scope.abrirModalDomicilios = function(cliente) { |
| 318 | var modalInstanceDomicilio = $uibModal.open( | 319 | var modalInstanceDomicilio = $uibModal.open( |
| 319 | { | 320 | { |
| 320 | ariaLabelledBy: 'Busqueda de Domicilios', | 321 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 321 | templateUrl: 'modal-domicilio.html', | 322 | templateUrl: 'modal-domicilio.html', |
| 322 | controller: 'focaModalDomicilioController', | 323 | controller: 'focaModalDomicilioController', |
| 323 | resolve: { idCliente: function() { return cliente.cod; }}, | 324 | resolve: { idCliente: function() { return cliente.cod; }}, |
| 324 | size: 'lg', | 325 | size: 'lg', |
| 325 | } | 326 | } |
| 326 | ); | 327 | ); |
| 327 | modalInstanceDomicilio.result.then( | 328 | modalInstanceDomicilio.result.then( |
| 328 | function(domicilio) { | 329 | function(domicilio) { |
| 329 | $scope.notaPedido.domicilio.id = domicilio.nivel2; | 330 | $scope.notaPedido.domicilio.id = domicilio.nivel2; |
| 330 | $scope.notaPedido.cliente = cliente; | 331 | $scope.notaPedido.cliente = cliente; |
| 331 | 332 | ||
| 332 | addCabecera('Cliente:', cliente.nom); | 333 | addCabecera('Cliente:', cliente.nom); |
| 333 | addCabecera('Domicilio:', domicilio.Calle + ' ' + domicilio.Numero); | 334 | addCabecera('Domicilio:', domicilio.Calle + ' ' + domicilio.Numero); |
| 334 | }, function() { | 335 | }, function() { |
| 335 | $scope.seleccionarCliente(); | 336 | $scope.seleccionarCliente(); |
| 336 | return; | 337 | return; |
| 337 | } | 338 | } |
| 338 | ); | 339 | ); |
| 339 | }; | 340 | }; |
| 340 | 341 | ||
| 341 | $scope.mostrarFichaCliente = function() { | 342 | $scope.mostrarFichaCliente = function() { |
| 342 | $uibModal.open( | 343 | $uibModal.open( |
| 343 | { | 344 | { |
| 344 | ariaLabelledBy: 'Datos del Cliente', | 345 | ariaLabelledBy: 'Datos del Cliente', |
| 345 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', | 346 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', |
| 346 | controller: 'focaCrearNotaPedidoFichaClienteController', | 347 | controller: 'focaCrearNotaPedidoFichaClienteController', |
| 347 | size: 'lg' | 348 | size: 'lg' |
| 348 | } | 349 | } |
| 349 | ); | 350 | ); |
| 350 | }; | 351 | }; |
| 351 | 352 | ||
| 352 | $scope.getTotal = function() { | 353 | $scope.getTotal = function() { |
| 353 | var total = 0; | 354 | var total = 0; |
| 354 | var arrayTempArticulos = $scope.articulosTabla; | 355 | var arrayTempArticulos = $scope.articulosTabla; |
| 355 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 356 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 356 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 357 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 357 | } | 358 | } |
| 358 | return parseFloat(total.toFixed(2)); | 359 | return parseFloat(total.toFixed(2)); |
| 359 | }; | 360 | }; |
| 360 | 361 | ||
| 361 | $scope.getSubTotal = function() { | 362 | $scope.getSubTotal = function() { |
| 362 | if($scope.articuloACargar) { | 363 | if($scope.articuloACargar) { |
| 363 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 364 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 364 | } | 365 | } |
| 365 | }; | 366 | }; |
| 366 | 367 | ||
| 367 | $scope.abrirModalListaPrecio = function() { | 368 | $scope.abrirModalListaPrecio = function() { |
| 368 | var modalInstance = $uibModal.open( | 369 | var modalInstance = $uibModal.open( |
| 369 | { | 370 | { |
| 370 | ariaLabelledBy: 'Busqueda de Precio Condición', | 371 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 371 | templateUrl: 'modal-precio-condicion.html', | 372 | templateUrl: 'modal-precio-condicion.html', |
| 372 | controller: 'focaModalPrecioCondicionController', | 373 | controller: 'focaModalPrecioCondicionController', |
| 373 | size: 'lg' | 374 | size: 'lg' |
| 374 | } | 375 | } |
| 375 | ); | 376 | ); |
| 376 | modalInstance.result.then( | 377 | modalInstance.result.then( |
| 377 | function(precioCondicion) { | 378 | function(precioCondicion) { |
| 378 | var cabecera = ''; | 379 | var cabecera = ''; |
| 379 | var plazosConcat = ''; | 380 | var plazosConcat = ''; |
| 380 | if(!Array.isArray(precioCondicion)) { | 381 | if(!Array.isArray(precioCondicion)) { |
| 381 | $scope.plazosPagos = precioCondicion.plazoPago; | 382 | $scope.plazosPagos = precioCondicion.plazoPago; |
| 382 | $scope.idLista = precioCondicion.idListaPrecio; | 383 | $scope.idLista = precioCondicion.idListaPrecio; |
| 383 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 384 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 384 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 385 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 385 | } | 386 | } |
| 386 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 387 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 387 | } else { //Cuando se ingresan los plazos manualmente | 388 | } else { //Cuando se ingresan los plazos manualmente |
| 388 | $scope.idLista = -1; //-1, el modal productos busca todos los productos | 389 | $scope.idLista = -1; //-1, el modal productos busca todos los productos |
| 389 | $scope.plazosPagos = precioCondicion; | 390 | $scope.plazosPagos = precioCondicion; |
| 390 | for(var j = 0; j < precioCondicion.length; j++) { | 391 | for(var j = 0; j < precioCondicion.length; j++) { |
| 391 | plazosConcat += precioCondicion[j].dias + ' '; | 392 | plazosConcat += precioCondicion[j].dias + ' '; |
| 392 | } | 393 | } |
| 393 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 394 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 394 | } | 395 | } |
| 395 | $scope.articulosTabla = []; | 396 | $scope.articulosTabla = []; |
| 396 | addCabecera('Precios y condiciones:', cabecera); | 397 | addCabecera('Precios y condiciones:', cabecera); |
| 397 | }, function() { | 398 | }, function() { |
| 398 | 399 | ||
| 399 | } | 400 | } |
| 400 | ); | 401 | ); |
| 401 | }; | 402 | }; |
| 402 | 403 | ||
| 403 | $scope.abrirModalFlete = function() { | 404 | $scope.abrirModalFlete = function() { |
| 404 | var modalInstance = $uibModal.open( | 405 | var modalInstance = $uibModal.open( |
| 405 | { | 406 | { |
| 406 | ariaLabelledBy: 'Busqueda de Flete', | 407 | ariaLabelledBy: 'Busqueda de Flete', |
| 407 | templateUrl: 'modal-flete.html', | 408 | templateUrl: 'modal-flete.html', |
| 408 | controller: 'focaModalFleteController', | 409 | controller: 'focaModalFleteController', |
| 409 | size: 'lg', | 410 | size: 'lg', |
| 410 | resolve: { | 411 | resolve: { |
| 411 | parametrosFlete: | 412 | parametrosFlete: |
| 412 | function() { | 413 | function() { |
| 413 | return { | 414 | return { |
| 414 | flete: $scope.notaPedido.flete ? '1' : | 415 | flete: $scope.notaPedido.flete ? '1' : |
| 415 | ($scope.notaPedido.fob ? 'FOB' : | 416 | ($scope.notaPedido.fob ? 'FOB' : |
| 416 | ($scope.notaPedido.flete === undefined ? null : '0')), | 417 | ($scope.notaPedido.flete === undefined ? null : '0')), |
| 417 | bomba: $scope.notaPedido.bomba ? '1' : | 418 | bomba: $scope.notaPedido.bomba ? '1' : |
| 418 | ($scope.notaPedido.bomba === undefined ? null : '0'), | 419 | ($scope.notaPedido.bomba === undefined ? null : '0'), |
| 419 | kilometros: $scope.notaPedido.kilometros | 420 | kilometros: $scope.notaPedido.kilometros |
| 420 | }; | 421 | }; |
| 421 | } | 422 | } |
| 422 | } | 423 | } |
| 423 | } | 424 | } |
| 424 | ); | 425 | ); |
| 425 | modalInstance.result.then( | 426 | modalInstance.result.then( |
| 426 | function(datos) { | 427 | function(datos) { |
| 427 | $scope.notaPedido.flete = datos.flete; | 428 | $scope.notaPedido.flete = datos.flete; |
| 428 | $scope.notaPedido.fob = datos.FOB; | 429 | $scope.notaPedido.fob = datos.FOB; |
| 429 | $scope.notaPedido.bomba = datos.bomba; | 430 | $scope.notaPedido.bomba = datos.bomba; |
| 430 | $scope.notaPedido.kilometros = datos.kilometros; | 431 | $scope.notaPedido.kilometros = datos.kilometros; |
| 431 | 432 | ||
| 432 | addCabecera('Flete:', datos.flete ? 'Si' : | 433 | addCabecera('Flete:', datos.flete ? 'Si' : |
| 433 | ($scope.notaPedido.fob ? 'FOB' : 'No')); | 434 | ($scope.notaPedido.fob ? 'FOB' : 'No')); |
| 434 | if(datos.flete) { | 435 | if(datos.flete) { |
| 435 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); | 436 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); |
| 436 | addCabecera('Kilometros:', datos.kilometros); | 437 | addCabecera('Kilometros:', datos.kilometros); |
| 437 | } else { | 438 | } else { |
| 438 | removeCabecera('Bomba:'); | 439 | removeCabecera('Bomba:'); |
| 439 | removeCabecera('Kilometros:'); | 440 | removeCabecera('Kilometros:'); |
| 440 | $scope.notaPedido.fob = false; | 441 | $scope.notaPedido.fob = false; |
| 441 | $scope.notaPedido.bomba = false; | 442 | $scope.notaPedido.bomba = false; |
| 442 | $scope.notaPedido.kilometros = null; | 443 | $scope.notaPedido.kilometros = null; |
| 443 | } | 444 | } |
| 444 | }, function() { | 445 | }, function() { |
| 445 | 446 | ||
| 446 | } | 447 | } |
| 447 | ); | 448 | ); |
| 448 | }; | 449 | }; |
| 449 | 450 | ||
| 450 | $scope.abrirModalMoneda = function() { | 451 | $scope.abrirModalMoneda = function() { |
| 451 | var modalInstance = $uibModal.open( | 452 | var modalInstance = $uibModal.open( |
| 452 | { | 453 | { |
| 453 | ariaLabelledBy: 'Busqueda de Moneda', | 454 | ariaLabelledBy: 'Busqueda de Moneda', |
| 454 | templateUrl: 'modal-moneda.html', | 455 | templateUrl: 'modal-moneda.html', |
| 455 | controller: 'focaModalMonedaController', | 456 | controller: 'focaModalMonedaController', |
| 456 | size: 'lg' | 457 | size: 'lg' |
| 457 | } | 458 | } |
| 458 | ); | 459 | ); |
| 459 | modalInstance.result.then( | 460 | modalInstance.result.then( |
| 460 | function(moneda) { | 461 | function(moneda) { |
| 461 | $scope.abrirModalCotizacion(moneda); | 462 | $scope.abrirModalCotizacion(moneda); |
| 462 | }, function() { | 463 | }, function() { |
| 463 | 464 | ||
| 464 | } | 465 | } |
| 465 | ); | 466 | ); |
| 466 | }; | 467 | }; |
| 467 | 468 | ||
| 468 | $scope.abrirModalCotizacion = function(moneda) { | 469 | $scope.abrirModalCotizacion = function(moneda) { |
| 469 | var modalInstance = $uibModal.open( | 470 | var modalInstance = $uibModal.open( |
| 470 | { | 471 | { |
| 471 | ariaLabelledBy: 'Busqueda de Cotización', | 472 | ariaLabelledBy: 'Busqueda de Cotización', |
| 472 | templateUrl: 'modal-cotizacion.html', | 473 | templateUrl: 'modal-cotizacion.html', |
| 473 | controller: 'focaModalCotizacionController', | 474 | controller: 'focaModalCotizacionController', |
| 474 | size: 'lg', | 475 | size: 'lg', |
| 475 | resolve: {idMoneda: function() {return moneda.ID;}} | 476 | resolve: {idMoneda: function() {return moneda.ID;}} |
| 476 | } | 477 | } |
| 477 | ); | 478 | ); |
| 478 | modalInstance.result.then( | 479 | modalInstance.result.then( |
| 479 | function(cotizacion) { | 480 | function(cotizacion) { |
| 480 | var articulosTablaTemp = $scope.articulosTabla; | 481 | var articulosTablaTemp = $scope.articulosTabla; |
| 481 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 482 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
| 482 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 483 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 483 | $scope.notaPedido.cotizacion.COTIZACION; | 484 | $scope.notaPedido.cotizacion.VENDEDOR; |
| 484 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 485 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 485 | cotizacion.COTIZACION; | 486 | cotizacion.VENDEDOR; |
| 486 | } | 487 | } |
| 487 | $scope.articulosTabla = articulosTablaTemp; | 488 | $scope.articulosTabla = articulosTablaTemp; |
| 488 | $scope.notaPedido.moneda = { | 489 | $scope.notaPedido.moneda = { |
| 489 | id: moneda.ID, | 490 | id: moneda.ID, |
| 490 | detalle: moneda.DETALLE, | 491 | detalle: moneda.DETALLE, |
| 491 | simbolo: moneda.SIMBOLO | 492 | simbolo: moneda.SIMBOLO |
| 492 | }; | 493 | }; |
| 493 | $scope.notaPedido.cotizacion = { | 494 | $scope.notaPedido.cotizacion = cotizacion; |
| 494 | ID: cotizacion.ID, | ||
| 495 | COTIZACION: cotizacion.COTIZACION, | ||
| 496 | FECHA: cotizacion.FECHA | ||
| 497 | }; | ||
| 498 | addCabecera('Moneda:', moneda.DETALLE); | 495 | addCabecera('Moneda:', moneda.DETALLE); |
| 499 | addCabecera( | 496 | addCabecera( |
| 500 | 'Fecha cotizacion:', | 497 | 'Fecha cotizacion:', |
| 501 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 498 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 502 | ); | 499 | ); |
| 503 | addCabecera('Cotizacion:', cotizacion.COTIZACION); | 500 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); |
| 504 | }, function() { | 501 | }, function() { |
| 505 | 502 | ||
| 506 | } | 503 | } |
| 507 | ); | 504 | ); |
| 508 | }; | 505 | }; |
| 509 | 506 | ||
| 510 | $scope.agregarATabla = function(key) { | 507 | $scope.agregarATabla = function(key) { |
| 511 | if(key === 13) { | 508 | if(key === 13) { |
| 512 | if($scope.articuloACargar.cantidad === undefined || | 509 | if($scope.articuloACargar.cantidad === undefined || |
| 513 | $scope.articuloACargar.cantidad === 0 || | 510 | $scope.articuloACargar.cantidad === 0 || |
| 514 | $scope.articuloACargar.cantidad === null ){ | 511 | $scope.articuloACargar.cantidad === null ){ |
| 515 | focaModalService.alert('El valor debe ser al menos 1'); | 512 | focaModalService.alert('El valor debe ser al menos 1'); |
| 516 | return; | 513 | return; |
| 517 | } | 514 | } |
| 518 | delete $scope.articuloACargar.sectorCodigo; | 515 | delete $scope.articuloACargar.sectorCodigo; |
| 519 | $scope.articulosTabla.push($scope.articuloACargar); | 516 | $scope.articulosTabla.push($scope.articuloACargar); |
| 520 | $scope.cargando = true; | 517 | $scope.cargando = true; |
| 521 | } | 518 | } |
| 522 | }; | 519 | }; |
| 523 | 520 | ||
| 524 | $scope.quitarArticulo = function(key) { | 521 | $scope.quitarArticulo = function(key) { |
| 525 | $scope.articulosTabla.splice(key, 1); | 522 | $scope.articulosTabla.splice(key, 1); |
| 526 | }; | 523 | }; |
| 527 | 524 | ||
| 528 | $scope.editarArticulo = function(key, articulo) { | 525 | $scope.editarArticulo = function(key, articulo) { |
| 529 | if(key === 13) { | 526 | if(key === 13) { |
| 530 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 527 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
| 531 | articulo.cantidad === undefined){ | 528 | articulo.cantidad === undefined){ |
| 532 | focaModalService.alert('El valor debe ser al menos 1'); | 529 | focaModalService.alert('El valor debe ser al menos 1'); |
| 533 | return; | 530 | return; |
| 534 | } | 531 | } |
| 535 | articulo.editCantidad = false; | 532 | articulo.editCantidad = false; |
| 536 | articulo.editPrecio = false; | 533 | articulo.editPrecio = false; |
| 537 | } | 534 | } |
| 538 | }; | 535 | }; |
| 539 | 536 | ||
| 540 | $scope.cambioEdit = function(articulo, propiedad) { | 537 | $scope.cambioEdit = function(articulo, propiedad) { |
| 541 | if(propiedad === 'cantidad') { | 538 | if(propiedad === 'cantidad') { |
| 542 | articulo.editCantidad = true; | 539 | articulo.editCantidad = true; |
| 543 | } else if(propiedad === 'precio') { | 540 | } else if(propiedad === 'precio') { |
| 544 | articulo.editPrecio = true; | 541 | articulo.editPrecio = true; |
| 545 | } | 542 | } |
| 546 | }; | 543 | }; |
| 547 | 544 | ||
| 548 | $scope.limpiarFlete = function() { | 545 | $scope.limpiarFlete = function() { |
| 549 | $scope.notaPedido.fleteNombre = ''; | 546 | $scope.notaPedido.fleteNombre = ''; |
| 550 | $scope.notaPedido.chofer = ''; | 547 | $scope.notaPedido.chofer = ''; |
| 551 | $scope.notaPedido.vehiculo = ''; | 548 | $scope.notaPedido.vehiculo = ''; |
| 552 | $scope.notaPedido.kilometros = ''; | 549 | $scope.notaPedido.kilometros = ''; |
| 553 | $scope.notaPedido.costoUnitarioKmFlete = ''; | 550 | $scope.notaPedido.costoUnitarioKmFlete = ''; |
| 554 | $scope.choferes = ''; | 551 | $scope.choferes = ''; |
| 555 | $scope.vehiculos = ''; | 552 | $scope.vehiculos = ''; |
| 556 | }; | 553 | }; |
| 557 | 554 | ||
| 558 | $scope.limpiarPantalla = function() { | 555 | $scope.limpiarPantalla = function() { |
| 559 | $scope.limpiarFlete(); | 556 | $scope.limpiarFlete(); |
| 560 | $scope.notaPedido.flete = '0'; | 557 | $scope.notaPedido.flete = '0'; |
| 561 | $scope.notaPedido.bomba = '0'; | 558 | $scope.notaPedido.bomba = '0'; |
| 562 | $scope.notaPedido.precioCondicion = ''; | 559 | $scope.notaPedido.precioCondicion = ''; |
| 563 | $scope.articulosTabla = []; | 560 | $scope.articulosTabla = []; |
| 564 | $scope.notaPedido.vendedor.nombre = ''; | 561 | $scope.notaPedido.vendedor.nombre = ''; |
| 565 | $scope.notaPedido.cliente = {nombre: ''}; | 562 | $scope.notaPedido.cliente = {nombre: ''}; |
| 566 | $scope.notaPedido.domicilio = {dom: ''}; | 563 | $scope.notaPedido.domicilio = {dom: ''}; |
| 567 | $scope.domiciliosCliente = []; | 564 | $scope.domiciliosCliente = []; |
| 568 | }; | 565 | }; |
| 569 | 566 | ||
| 570 | $scope.resetFilter = function() { | 567 | $scope.resetFilter = function() { |
| 571 | $scope.articuloACargar = {}; | 568 | $scope.articuloACargar = {}; |
| 572 | $scope.cargando = true; | 569 | $scope.cargando = true; |
| 573 | }; | 570 | }; |
| 574 | //Recibe aviso si el teclado está en uso | 571 | //Recibe aviso si el teclado está en uso |
| 575 | $rootScope.$on('usarTeclado', function(event, data) { | 572 | $rootScope.$on('usarTeclado', function(event, data) { |
| 576 | if(data) { | 573 | if(data) { |
| 577 | $scope.mostrarTeclado = true; | 574 | $scope.mostrarTeclado = true; |
| 578 | return; | 575 | return; |
| 579 | } | 576 | } |
| 580 | $scope.mostrarTeclado = false; | 577 | $scope.mostrarTeclado = false; |
| 581 | }) | 578 | }) |
| 582 | $scope.selectFocus = function($event) { | 579 | $scope.selectFocus = function($event) { |
| 583 | // Si el teclado esta en uso no selecciona el valor | 580 | // Si el teclado esta en uso no selecciona el valor |
| 584 | if($scope.mostrarTeclado) { | 581 | if($scope.mostrarTeclado) { |
| 585 | return; | 582 | return; |
| 586 | } | 583 | } |
| 587 | $event.target.select(); | 584 | $event.target.select(); |
| 588 | }; | 585 | }; |
| 589 | 586 | ||
| 590 | $scope.salir = function() { | 587 | $scope.salir = function() { |
| 591 | $location.path('/'); | 588 | $location.path('/'); |
| 592 | }; | 589 | }; |
| 593 | 590 | ||
| 594 | $scope.parsearATexto = function(articulo) { | 591 | $scope.parsearATexto = function(articulo) { |
| 595 | articulo.cantidad = parseFloat(articulo.cantidad); | 592 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 596 | articulo.precio = parseFloat(articulo.precio); | 593 | articulo.precio = parseFloat(articulo.precio); |
| 597 | }; | 594 | }; |
| 598 | 595 | ||
| 599 | function addCabecera(label, valor) { | 596 | function addCabecera(label, valor) { |
| 600 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 597 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 601 | if(propiedad.length === 1) { | 598 | if(propiedad.length === 1) { |
| 602 | propiedad[0].valor = valor; | 599 | propiedad[0].valor = valor; |
| 603 | } else { | 600 | } else { |
| 604 | $scope.cabecera.push({label: label, valor: valor}); | 601 | $scope.cabecera.push({label: label, valor: valor}); |
| 605 | } | 602 | } |
| 606 | } | 603 | } |
| 607 | 604 | ||
| 608 | function removeCabecera(label) { | 605 | function removeCabecera(label) { |
| 609 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 606 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 610 | if(propiedad.length === 1){ | 607 | if(propiedad.length === 1){ |
| 611 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 608 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
| 612 | } | 609 | } |
| 613 | } | 610 | } |
| 614 | 611 | ||
| 615 | function rellenar(relleno, longitud) { | 612 | function rellenar(relleno, longitud) { |
| 616 | relleno = '' + relleno; | 613 | relleno = '' + relleno; |
| 617 | while (relleno.length < longitud) { | 614 | while (relleno.length < longitud) { |
| 618 | relleno = '0' + relleno; | 615 | relleno = '0' + relleno; |
| 619 | } | 616 | } |
| 620 | 617 | ||
| 621 | return relleno; | 618 | return relleno; |
| 622 | } | 619 | } |
| 623 | } | 620 | } |
| 624 | ] | 621 | ] |
| 625 | ) | 622 | ) |
| 626 | .controller('notaPedidoListaCtrl', [ | 623 | .controller('notaPedidoListaCtrl', [ |
| 627 | '$scope', | 624 | '$scope', |
| 628 | 'crearNotaPedidoService', | 625 | 'crearNotaPedidoService', |
| 629 | '$location', | 626 | '$location', |
| 630 | function($scope, crearNotaPedidoService, $location) { | 627 | function($scope, crearNotaPedidoService, $location) { |
| 631 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 628 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
| 632 | $scope.notaPedidos = datos.data; | 629 | $scope.notaPedidos = datos.data; |
| 633 | }); | 630 | }); |
| 634 | $scope.editar = function(notaPedido) { | 631 | $scope.editar = function(notaPedido) { |
| 635 | crearNotaPedidoService.setNotaPedido(notaPedido); | 632 | crearNotaPedidoService.setNotaPedido(notaPedido); |
| 636 | $location.path('/venta-nota-pedido/abm/'); | 633 | $location.path('/venta-nota-pedido/abm/'); |
| 637 | }; | 634 | }; |
| 638 | $scope.crearPedido = function() { | 635 | $scope.crearPedido = function() { |
| 639 | crearNotaPedidoService.clearNotaPedido(); | 636 | crearNotaPedidoService.clearNotaPedido(); |
| 640 | $location.path('/venta-nota-pedido/abm/'); | 637 | $location.path('/venta-nota-pedido/abm/'); |
| 641 | }; | 638 | }; |
| 642 | } | 639 | } |
| 643 | ]) | 640 | ]) |
| 644 | .controller('focaCrearNotaPedidoFichaClienteController', [ | 641 | .controller('focaCrearNotaPedidoFichaClienteController', [ |
| 645 | '$scope', | 642 | '$scope', |
| 646 | 'crearNotaPedidoService', | 643 | 'crearNotaPedidoService', |
| 647 | '$location', | 644 | '$location', |
| 648 | function($scope, crearNotaPedidoService, $location) { | 645 | function($scope, crearNotaPedidoService, $location) { |
| 649 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 646 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
| 650 | $scope.notaPedidos = datos.data; | 647 | $scope.notaPedidos = datos.data; |
| 651 | }); | 648 | }); |
| 652 | $scope.editar = function(notaPedido) { | 649 | $scope.editar = function(notaPedido) { |
| 653 | crearNotaPedidoService.setNotaPedido(notaPedido); | 650 | crearNotaPedidoService.setNotaPedido(notaPedido); |
| 654 | $location.path('/venta-nota-pedido/abm/'); | 651 | $location.path('/venta-nota-pedido/abm/'); |
| 655 | }; | 652 | }; |
| 656 | $scope.crearPedido = function() { | 653 | $scope.crearPedido = function() { |
| 657 | crearNotaPedidoService.clearNotaPedido(); | 654 | crearNotaPedidoService.clearNotaPedido(); |
| 658 | $location.path('/venta-nota-pedido/abm/'); | 655 | $location.path('/venta-nota-pedido/abm/'); |
| 659 | }; | 656 | }; |
| 660 | } | 657 | } |
| 661 | ]); | 658 | ]); |