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