Commit 7319d2a9146b764c47bd121392abbee733e8599a
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master (pmarco) See merge request modulos-npm/foca-crear-nota-pedido!83
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', 'focaSeguimientoService', |
| 5 | function( | 5 | function( |
| 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, |
| 7 | notaPedidoBusinessService, $rootScope | 7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService |
| 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 | // Al guardar los datos de la nota de pedido logueamos la | 177 | // Al guardar los datos de la nota de pedido logueamos la |
| 178 | // actividad para su seguimiento. | 178 | // actividad para su seguimiento. |
| 179 | focaSeguimientoService.guardarPosicion( | 179 | focaSeguimientoService.guardarPosicion( |
| 180 | $scope.notaPedido.vendedor.codigo, | 180 | $scope.notaPedido.vendedor.codigo, |
| 181 | 'Nota de pedido', | 181 | 'Nota de pedido', |
| 182 | 'Nº: ' + $filter('comprobante')([ | 182 | 'Nº: ' + $filter('comprobante')([ |
| 183 | $scope.puntoVenta, | 183 | $scope.puntoVenta, |
| 184 | $scope.comprobante | 184 | $scope.comprobante |
| 185 | ]) | 185 | ]) |
| 186 | ); | 186 | ); |
| 187 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 187 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
| 188 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 188 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 189 | var plazos = $scope.plazosPagos; | 189 | var plazos = $scope.plazosPagos; |
| 190 | 190 | ||
| 191 | for(var j = 0; j < plazos.length; j++) { | 191 | for(var j = 0; j < plazos.length; j++) { |
| 192 | var json = { | 192 | var json = { |
| 193 | idPedido: data.data.id, | 193 | idPedido: data.data.id, |
| 194 | dias: plazos[j].dias | 194 | dias: plazos[j].dias |
| 195 | }; | 195 | }; |
| 196 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); | 196 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); |
| 197 | } | 197 | } |
| 198 | notaPedidoBusinessService.addEstado(data.data.id, | 198 | notaPedidoBusinessService.addEstado(data.data.id, |
| 199 | $scope.notaPedido.vendedor.codigo); | 199 | $scope.notaPedido.vendedor.codigo); |
| 200 | 200 | ||
| 201 | focaModalService.alert('Nota pedido creada'); | 201 | focaModalService.alert('Nota pedido creada'); |
| 202 | $scope.cabecera = []; | 202 | $scope.cabecera = []; |
| 203 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); | 203 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); |
| 204 | addCabecera( | 204 | addCabecera( |
| 205 | 'Fecha cotizacion:', | 205 | 'Fecha cotizacion:', |
| 206 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 206 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
| 207 | ); | 207 | ); |
| 208 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); | 208 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); |
| 209 | $scope.notaPedido.vendedor = {}; | 209 | $scope.notaPedido.vendedor = {}; |
| 210 | $scope.notaPedido.cliente = {}; | 210 | $scope.notaPedido.cliente = {}; |
| 211 | $scope.notaPedido.proveedor = {}; | 211 | $scope.notaPedido.proveedor = {}; |
| 212 | $scope.notaPedido.domicilio = {}; | 212 | $scope.notaPedido.domicilio = {}; |
| 213 | $scope.notaPedido.flete = null; | 213 | $scope.notaPedido.flete = null; |
| 214 | $scope.notaPedido.fob = null; | 214 | $scope.notaPedido.fob = null; |
| 215 | $scope.notaPedido.bomba = null; | 215 | $scope.notaPedido.bomba = null; |
| 216 | $scope.notaPedido.kilometros = null; | 216 | $scope.notaPedido.kilometros = null; |
| 217 | $scope.articulosTabla = []; | 217 | $scope.articulosTabla = []; |
| 218 | }, | 218 | }, |
| 219 | function(error) { | 219 | function(error) { |
| 220 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 220 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 221 | console.info(error); | 221 | console.info(error); |
| 222 | } | 222 | } |
| 223 | ); | 223 | ); |
| 224 | }; | 224 | }; |
| 225 | 225 | ||
| 226 | $scope.seleccionarArticulo = function() { | 226 | $scope.seleccionarArticulo = function() { |
| 227 | if ($scope.idLista === undefined) { | 227 | if ($scope.idLista === undefined) { |
| 228 | focaModalService.alert( | 228 | focaModalService.alert( |
| 229 | 'Primero seleccione una lista de precio y condicion'); | 229 | 'Primero seleccione una lista de precio y condicion'); |
| 230 | return; | 230 | return; |
| 231 | } | 231 | } |
| 232 | var modalInstance = $uibModal.open( | 232 | var modalInstance = $uibModal.open( |
| 233 | { | 233 | { |
| 234 | ariaLabelledBy: 'Busqueda de Productos', | 234 | ariaLabelledBy: 'Busqueda de Productos', |
| 235 | templateUrl: 'modal-busqueda-productos.html', | 235 | templateUrl: 'modal-busqueda-productos.html', |
| 236 | controller: 'modalBusquedaProductosCtrl', | 236 | controller: 'modalBusquedaProductosCtrl', |
| 237 | resolve: { | 237 | resolve: { |
| 238 | parametroProducto: { | 238 | parametroProducto: { |
| 239 | idLista: $scope.idLista, | 239 | idLista: $scope.idLista, |
| 240 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 240 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 241 | simbolo: $scope.notaPedido.moneda.simbolo | 241 | simbolo: $scope.notaPedido.moneda.simbolo |
| 242 | } | 242 | } |
| 243 | }, | 243 | }, |
| 244 | size: 'lg' | 244 | size: 'lg' |
| 245 | } | 245 | } |
| 246 | ); | 246 | ); |
| 247 | modalInstance.result.then( | 247 | modalInstance.result.then( |
| 248 | function(producto) { | 248 | function(producto) { |
| 249 | var newArt = | 249 | var newArt = |
| 250 | { | 250 | { |
| 251 | id: 0, | 251 | id: 0, |
| 252 | codigo: producto.codigo, | 252 | codigo: producto.codigo, |
| 253 | sector: producto.sector, | 253 | sector: producto.sector, |
| 254 | sectorCodigo: producto.sector + '-' + producto.codigo, | 254 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 255 | descripcion: producto.descripcion, | 255 | descripcion: producto.descripcion, |
| 256 | item: $scope.articulosTabla.length + 1, | 256 | item: $scope.articulosTabla.length + 1, |
| 257 | nombre: producto.descripcion, | 257 | nombre: producto.descripcion, |
| 258 | precio: parseFloat(producto.precio.toFixed(4)), | 258 | precio: parseFloat(producto.precio.toFixed(4)), |
| 259 | costoUnitario: producto.costo, | 259 | costoUnitario: producto.costo, |
| 260 | editCantidad: false, | 260 | editCantidad: false, |
| 261 | editPrecio: false, | 261 | editPrecio: false, |
| 262 | rubro: producto.CodRub, | 262 | rubro: producto.CodRub, |
| 263 | exentoUnitario: producto.precio, | 263 | exentoUnitario: producto.precio, |
| 264 | ivaUnitario: producto.IMPIVA, | 264 | ivaUnitario: producto.IMPIVA, |
| 265 | impuestoInternoUnitario: producto.ImpInt, | 265 | impuestoInternoUnitario: producto.ImpInt, |
| 266 | impuestoInterno1Unitario: producto.ImpInt2, | 266 | impuestoInterno1Unitario: producto.ImpInt2, |
| 267 | impuestoInterno2Unitario: producto.ImpInt3, | 267 | impuestoInterno2Unitario: producto.ImpInt3, |
| 268 | precioLista: producto.precio, | 268 | precioLista: producto.precio, |
| 269 | combustible: 1, | 269 | combustible: 1, |
| 270 | facturado: 0 | 270 | facturado: 0 |
| 271 | }; | 271 | }; |
| 272 | $scope.articuloACargar = newArt; | 272 | $scope.articuloACargar = newArt; |
| 273 | $scope.cargando = false; | 273 | $scope.cargando = false; |
| 274 | }, function() { | 274 | }, function() { |
| 275 | // funcion ejecutada cuando se cancela el modal | 275 | // funcion ejecutada cuando se cancela el modal |
| 276 | } | 276 | } |
| 277 | ); | 277 | ); |
| 278 | }; | 278 | }; |
| 279 | 279 | ||
| 280 | $scope.seleccionarVendedor = function() { | 280 | $scope.seleccionarVendedor = function() { |
| 281 | var modalInstance = $uibModal.open( | 281 | var modalInstance = $uibModal.open( |
| 282 | { | 282 | { |
| 283 | ariaLabelledBy: 'Busqueda de Vendedores', | 283 | ariaLabelledBy: 'Busqueda de Vendedores', |
| 284 | templateUrl: 'modal-vendedores.html', | 284 | templateUrl: 'modal-vendedores.html', |
| 285 | controller: 'modalVendedoresCtrl', | 285 | controller: 'modalVendedoresCtrl', |
| 286 | size: 'lg' | 286 | size: 'lg' |
| 287 | } | 287 | } |
| 288 | ); | 288 | ); |
| 289 | modalInstance.result.then( | 289 | modalInstance.result.then( |
| 290 | function(vendedor) { | 290 | function(vendedor) { |
| 291 | addCabecera('Vendedor:', vendedor.NomVen); | 291 | addCabecera('Vendedor:', vendedor.NomVen); |
| 292 | $scope.notaPedido.vendedor.codigo = vendedor.CodVen; | 292 | $scope.notaPedido.vendedor.codigo = vendedor.CodVen; |
| 293 | }, function() { | 293 | }, function() { |
| 294 | 294 | ||
| 295 | } | 295 | } |
| 296 | ); | 296 | ); |
| 297 | }; | 297 | }; |
| 298 | 298 | ||
| 299 | $scope.seleccionarProveedor = function() { | 299 | $scope.seleccionarProveedor = function() { |
| 300 | var modalInstance = $uibModal.open( | 300 | var modalInstance = $uibModal.open( |
| 301 | { | 301 | { |
| 302 | ariaLabelledBy: 'Busqueda de Proveedor', | 302 | ariaLabelledBy: 'Busqueda de Proveedor', |
| 303 | templateUrl: 'modal-proveedor.html', | 303 | templateUrl: 'modal-proveedor.html', |
| 304 | controller: 'focaModalProveedorCtrl', | 304 | controller: 'focaModalProveedorCtrl', |
| 305 | size: 'lg', | 305 | size: 'lg', |
| 306 | resolve: { | 306 | resolve: { |
| 307 | transportista: function() { | 307 | transportista: function() { |
| 308 | return false; | 308 | return false; |
| 309 | } | 309 | } |
| 310 | } | 310 | } |
| 311 | } | 311 | } |
| 312 | ); | 312 | ); |
| 313 | modalInstance.result.then( | 313 | modalInstance.result.then( |
| 314 | function(proveedor) { | 314 | function(proveedor) { |
| 315 | $scope.notaPedido.proveedor.codigo = proveedor.COD; | 315 | $scope.notaPedido.proveedor.codigo = proveedor.COD; |
| 316 | addCabecera('Proveedor:', proveedor.NOM); | 316 | addCabecera('Proveedor:', proveedor.NOM); |
| 317 | }, function() { | 317 | }, function() { |
| 318 | 318 | ||
| 319 | } | 319 | } |
| 320 | ); | 320 | ); |
| 321 | }; | 321 | }; |
| 322 | 322 | ||
| 323 | $scope.seleccionarCliente = function() { | 323 | $scope.seleccionarCliente = function() { |
| 324 | 324 | ||
| 325 | var modalInstance = $uibModal.open( | 325 | var modalInstance = $uibModal.open( |
| 326 | { | 326 | { |
| 327 | ariaLabelledBy: 'Busqueda de Cliente', | 327 | ariaLabelledBy: 'Busqueda de Cliente', |
| 328 | templateUrl: 'foca-busqueda-cliente-modal.html', | 328 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 329 | controller: 'focaBusquedaClienteModalController', | 329 | controller: 'focaBusquedaClienteModalController', |
| 330 | size: 'lg' | 330 | size: 'lg' |
| 331 | } | 331 | } |
| 332 | ); | 332 | ); |
| 333 | modalInstance.result.then( | 333 | modalInstance.result.then( |
| 334 | function(cliente) { | 334 | function(cliente) { |
| 335 | $scope.abrirModalDomicilios(cliente); | 335 | $scope.abrirModalDomicilios(cliente); |
| 336 | }, function() { | 336 | }, function() { |
| 337 | 337 | ||
| 338 | } | 338 | } |
| 339 | ); | 339 | ); |
| 340 | }; | 340 | }; |
| 341 | 341 | ||
| 342 | $scope.abrirModalDomicilios = function(cliente) { | 342 | $scope.abrirModalDomicilios = function(cliente) { |
| 343 | var modalInstanceDomicilio = $uibModal.open( | 343 | var modalInstanceDomicilio = $uibModal.open( |
| 344 | { | 344 | { |
| 345 | ariaLabelledBy: 'Busqueda de Domicilios', | 345 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 346 | templateUrl: 'modal-domicilio.html', | 346 | templateUrl: 'modal-domicilio.html', |
| 347 | controller: 'focaModalDomicilioController', | 347 | controller: 'focaModalDomicilioController', |
| 348 | resolve: { idCliente: function() { return cliente.cod; }}, | 348 | resolve: { idCliente: function() { return cliente.cod; }}, |
| 349 | size: 'lg', | 349 | size: 'lg', |
| 350 | } | 350 | } |
| 351 | ); | 351 | ); |
| 352 | modalInstanceDomicilio.result.then( | 352 | modalInstanceDomicilio.result.then( |
| 353 | function(domicilio) { | 353 | function(domicilio) { |
| 354 | $scope.notaPedido.domicilio.id = domicilio.id; | 354 | $scope.notaPedido.domicilio.id = domicilio.id; |
| 355 | $scope.notaPedido.cliente = cliente; | 355 | $scope.notaPedido.cliente = cliente; |
| 356 | addCabecera('Cliente:', cliente.nom); | 356 | addCabecera('Cliente:', cliente.nom); |
| 357 | var domicilioStamp = | 357 | var domicilioStamp = |
| 358 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 358 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 359 | domicilio.Localidad + ', ' + domicilio.Provincia; | 359 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 360 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 360 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 361 | addCabecera('Domicilio:', domicilioStamp); | 361 | addCabecera('Domicilio:', domicilioStamp); |
| 362 | }, function() { | 362 | }, function() { |
| 363 | $scope.seleccionarCliente(); | 363 | $scope.seleccionarCliente(); |
| 364 | return; | 364 | return; |
| 365 | } | 365 | } |
| 366 | ); | 366 | ); |
| 367 | }; | 367 | }; |
| 368 | 368 | ||
| 369 | $scope.mostrarFichaCliente = function() { | 369 | $scope.mostrarFichaCliente = function() { |
| 370 | $uibModal.open( | 370 | $uibModal.open( |
| 371 | { | 371 | { |
| 372 | ariaLabelledBy: 'Datos del Cliente', | 372 | ariaLabelledBy: 'Datos del Cliente', |
| 373 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', | 373 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', |
| 374 | controller: 'focaCrearNotaPedidoFichaClienteController', | 374 | controller: 'focaCrearNotaPedidoFichaClienteController', |
| 375 | size: 'lg' | 375 | size: 'lg' |
| 376 | } | 376 | } |
| 377 | ); | 377 | ); |
| 378 | }; | 378 | }; |
| 379 | 379 | ||
| 380 | $scope.getTotal = function() { | 380 | $scope.getTotal = function() { |
| 381 | var total = 0; | 381 | var total = 0; |
| 382 | var arrayTempArticulos = $scope.articulosTabla; | 382 | var arrayTempArticulos = $scope.articulosTabla; |
| 383 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 383 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 384 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 384 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 385 | } | 385 | } |
| 386 | return parseFloat(total.toFixed(2)); | 386 | return parseFloat(total.toFixed(2)); |
| 387 | }; | 387 | }; |
| 388 | 388 | ||
| 389 | $scope.getSubTotal = function() { | 389 | $scope.getSubTotal = function() { |
| 390 | if($scope.articuloACargar) { | 390 | if($scope.articuloACargar) { |
| 391 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 391 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 392 | } | 392 | } |
| 393 | }; | 393 | }; |
| 394 | 394 | ||
| 395 | $scope.abrirModalListaPrecio = function() { | 395 | $scope.abrirModalListaPrecio = function() { |
| 396 | var modalInstance = $uibModal.open( | 396 | var modalInstance = $uibModal.open( |
| 397 | { | 397 | { |
| 398 | ariaLabelledBy: 'Busqueda de Precio Condición', | 398 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 399 | templateUrl: 'modal-precio-condicion.html', | 399 | templateUrl: 'modal-precio-condicion.html', |
| 400 | controller: 'focaModalPrecioCondicionController', | 400 | controller: 'focaModalPrecioCondicionController', |
| 401 | size: 'lg' | 401 | size: 'lg' |
| 402 | } | 402 | } |
| 403 | ); | 403 | ); |
| 404 | modalInstance.result.then( | 404 | modalInstance.result.then( |
| 405 | function(precioCondicion) { | 405 | function(precioCondicion) { |
| 406 | var cabecera = ''; | 406 | var cabecera = ''; |
| 407 | var plazosConcat = ''; | 407 | var plazosConcat = ''; |
| 408 | if(!Array.isArray(precioCondicion)) { | 408 | if(!Array.isArray(precioCondicion)) { |
| 409 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 409 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 410 | $scope.plazosPagos = precioCondicion.plazoPago; | 410 | $scope.plazosPagos = precioCondicion.plazoPago; |
| 411 | $scope.idLista = precioCondicion.idListaPrecio; | 411 | $scope.idLista = precioCondicion.idListaPrecio; |
| 412 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 412 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 413 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 413 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 414 | } | 414 | } |
| 415 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 415 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 416 | } else { //Cuando se ingresan los plazos manualmente | 416 | } else { //Cuando se ingresan los plazos manualmente |
| 417 | $scope.notaPedido.idPrecioCondicion = 0; | 417 | $scope.notaPedido.idPrecioCondicion = 0; |
| 418 | $scope.idLista = -1; //-1, el modal productos busca todos los productos | 418 | $scope.idLista = -1; //-1, el modal productos busca todos los productos |
| 419 | $scope.plazosPagos = precioCondicion; | 419 | $scope.plazosPagos = precioCondicion; |
| 420 | for(var j = 0; j < precioCondicion.length; j++) { | 420 | for(var j = 0; j < precioCondicion.length; j++) { |
| 421 | plazosConcat += precioCondicion[j].dias + ' '; | 421 | plazosConcat += precioCondicion[j].dias + ' '; |
| 422 | } | 422 | } |
| 423 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 423 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 424 | } | 424 | } |
| 425 | $scope.articulosTabla = []; | 425 | $scope.articulosTabla = []; |
| 426 | addCabecera('Precios y condiciones:', cabecera); | 426 | addCabecera('Precios y condiciones:', cabecera); |
| 427 | }, function() { | 427 | }, function() { |
| 428 | 428 | ||
| 429 | } | 429 | } |
| 430 | ); | 430 | ); |
| 431 | }; | 431 | }; |
| 432 | 432 | ||
| 433 | $scope.abrirModalFlete = function() { | 433 | $scope.abrirModalFlete = function() { |
| 434 | var modalInstance = $uibModal.open( | 434 | var modalInstance = $uibModal.open( |
| 435 | { | 435 | { |
| 436 | ariaLabelledBy: 'Busqueda de Flete', | 436 | ariaLabelledBy: 'Busqueda de Flete', |
| 437 | templateUrl: 'modal-flete.html', | 437 | templateUrl: 'modal-flete.html', |
| 438 | controller: 'focaModalFleteController', | 438 | controller: 'focaModalFleteController', |
| 439 | size: 'lg', | 439 | size: 'lg', |
| 440 | resolve: { | 440 | resolve: { |
| 441 | parametrosFlete: | 441 | parametrosFlete: |
| 442 | function() { | 442 | function() { |
| 443 | return { | 443 | return { |
| 444 | flete: $scope.notaPedido.flete ? '1' : | 444 | flete: $scope.notaPedido.flete ? '1' : |
| 445 | ($scope.notaPedido.fob ? 'FOB' : | 445 | ($scope.notaPedido.fob ? 'FOB' : |
| 446 | ($scope.notaPedido.flete === undefined ? null : '0')), | 446 | ($scope.notaPedido.flete === undefined ? null : '0')), |
| 447 | bomba: $scope.notaPedido.bomba ? '1' : | 447 | bomba: $scope.notaPedido.bomba ? '1' : |
| 448 | ($scope.notaPedido.bomba === undefined ? null : '0'), | 448 | ($scope.notaPedido.bomba === undefined ? null : '0'), |
| 449 | kilometros: $scope.notaPedido.kilometros | 449 | kilometros: $scope.notaPedido.kilometros |
| 450 | }; | 450 | }; |
| 451 | } | 451 | } |
| 452 | } | 452 | } |
| 453 | } | 453 | } |
| 454 | ); | 454 | ); |
| 455 | modalInstance.result.then( | 455 | modalInstance.result.then( |
| 456 | function(datos) { | 456 | function(datos) { |
| 457 | $scope.notaPedido.flete = datos.flete; | 457 | $scope.notaPedido.flete = datos.flete; |
| 458 | $scope.notaPedido.fob = datos.FOB; | 458 | $scope.notaPedido.fob = datos.FOB; |
| 459 | $scope.notaPedido.bomba = datos.bomba; | 459 | $scope.notaPedido.bomba = datos.bomba; |
| 460 | $scope.notaPedido.kilometros = datos.kilometros; | 460 | $scope.notaPedido.kilometros = datos.kilometros; |
| 461 | 461 | ||
| 462 | addCabecera('Flete:', datos.flete ? 'Si' : | 462 | addCabecera('Flete:', datos.flete ? 'Si' : |
| 463 | ($scope.notaPedido.fob ? 'FOB' : 'No')); | 463 | ($scope.notaPedido.fob ? 'FOB' : 'No')); |
| 464 | if(datos.flete) { | 464 | if(datos.flete) { |
| 465 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); | 465 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); |
| 466 | addCabecera('Kilometros:', datos.kilometros); | 466 | addCabecera('Kilometros:', datos.kilometros); |
| 467 | } else { | 467 | } else { |
| 468 | removeCabecera('Bomba:'); | 468 | removeCabecera('Bomba:'); |
| 469 | removeCabecera('Kilometros:'); | 469 | removeCabecera('Kilometros:'); |
| 470 | $scope.notaPedido.fob = false; | 470 | $scope.notaPedido.fob = false; |
| 471 | $scope.notaPedido.bomba = false; | 471 | $scope.notaPedido.bomba = false; |
| 472 | $scope.notaPedido.kilometros = null; | 472 | $scope.notaPedido.kilometros = null; |
| 473 | } | 473 | } |
| 474 | }, function() { | 474 | }, function() { |
| 475 | 475 | ||
| 476 | } | 476 | } |
| 477 | ); | 477 | ); |
| 478 | }; | 478 | }; |
| 479 | 479 | ||
| 480 | $scope.abrirModalMoneda = function() { | 480 | $scope.abrirModalMoneda = function() { |
| 481 | var modalInstance = $uibModal.open( | 481 | var modalInstance = $uibModal.open( |
| 482 | { | 482 | { |
| 483 | ariaLabelledBy: 'Busqueda de Moneda', | 483 | ariaLabelledBy: 'Busqueda de Moneda', |
| 484 | templateUrl: 'modal-moneda.html', | 484 | templateUrl: 'modal-moneda.html', |
| 485 | controller: 'focaModalMonedaController', | 485 | controller: 'focaModalMonedaController', |
| 486 | size: 'lg' | 486 | size: 'lg' |
| 487 | } | 487 | } |
| 488 | ); | 488 | ); |
| 489 | modalInstance.result.then( | 489 | modalInstance.result.then( |
| 490 | function(moneda) { | 490 | function(moneda) { |
| 491 | $scope.abrirModalCotizacion(moneda); | 491 | $scope.abrirModalCotizacion(moneda); |
| 492 | }, function() { | 492 | }, function() { |
| 493 | 493 | ||
| 494 | } | 494 | } |
| 495 | ); | 495 | ); |
| 496 | }; | 496 | }; |
| 497 | 497 | ||
| 498 | $scope.abrirModalCotizacion = function(moneda) { | 498 | $scope.abrirModalCotizacion = function(moneda) { |
| 499 | var modalInstance = $uibModal.open( | 499 | var modalInstance = $uibModal.open( |
| 500 | { | 500 | { |
| 501 | ariaLabelledBy: 'Busqueda de Cotización', | 501 | ariaLabelledBy: 'Busqueda de Cotización', |
| 502 | templateUrl: 'modal-cotizacion.html', | 502 | templateUrl: 'modal-cotizacion.html', |
| 503 | controller: 'focaModalCotizacionController', | 503 | controller: 'focaModalCotizacionController', |
| 504 | size: 'lg', | 504 | size: 'lg', |
| 505 | resolve: {idMoneda: function() {return moneda.ID;}} | 505 | resolve: {idMoneda: function() {return moneda.ID;}} |
| 506 | } | 506 | } |
| 507 | ); | 507 | ); |
| 508 | modalInstance.result.then( | 508 | modalInstance.result.then( |
| 509 | function(cotizacion) { | 509 | function(cotizacion) { |
| 510 | var articulosTablaTemp = $scope.articulosTabla; | 510 | var articulosTablaTemp = $scope.articulosTabla; |
| 511 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 511 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
| 512 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 512 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 513 | $scope.notaPedido.cotizacion.VENDEDOR; | 513 | $scope.notaPedido.cotizacion.VENDEDOR; |
| 514 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 514 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 515 | cotizacion.VENDEDOR; | 515 | cotizacion.VENDEDOR; |
| 516 | } | 516 | } |
| 517 | $scope.articulosTabla = articulosTablaTemp; | 517 | $scope.articulosTabla = articulosTablaTemp; |
| 518 | $scope.notaPedido.moneda = { | 518 | $scope.notaPedido.moneda = { |
| 519 | id: moneda.ID, | 519 | id: moneda.ID, |
| 520 | detalle: moneda.DETALLE, | 520 | detalle: moneda.DETALLE, |
| 521 | simbolo: moneda.SIMBOLO | 521 | simbolo: moneda.SIMBOLO |
| 522 | }; | 522 | }; |
| 523 | $scope.notaPedido.cotizacion = cotizacion; | 523 | $scope.notaPedido.cotizacion = cotizacion; |
| 524 | addCabecera('Moneda:', moneda.DETALLE); | 524 | addCabecera('Moneda:', moneda.DETALLE); |
| 525 | addCabecera( | 525 | addCabecera( |
| 526 | 'Fecha cotizacion:', | 526 | 'Fecha cotizacion:', |
| 527 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 527 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 528 | ); | 528 | ); |
| 529 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); | 529 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); |
| 530 | }, function() { | 530 | }, function() { |
| 531 | 531 | ||
| 532 | } | 532 | } |
| 533 | ); | 533 | ); |
| 534 | }; | 534 | }; |
| 535 | 535 | ||
| 536 | $scope.agregarATabla = function(key) { | 536 | $scope.agregarATabla = function(key) { |
| 537 | if(key === 13) { | 537 | if(key === 13) { |
| 538 | if($scope.articuloACargar.cantidad === undefined || | 538 | if($scope.articuloACargar.cantidad === undefined || |
| 539 | $scope.articuloACargar.cantidad === 0 || | 539 | $scope.articuloACargar.cantidad === 0 || |
| 540 | $scope.articuloACargar.cantidad === null ) { | 540 | $scope.articuloACargar.cantidad === null ) { |
| 541 | focaModalService.alert('El valor debe ser al menos 1'); | 541 | focaModalService.alert('El valor debe ser al menos 1'); |
| 542 | return; | 542 | return; |
| 543 | } | 543 | } |
| 544 | delete $scope.articuloACargar.sectorCodigo; | 544 | delete $scope.articuloACargar.sectorCodigo; |
| 545 | $scope.articulosTabla.push($scope.articuloACargar); | 545 | $scope.articulosTabla.push($scope.articuloACargar); |
| 546 | $scope.cargando = true; | 546 | $scope.cargando = true; |
| 547 | } | 547 | } |
| 548 | }; | 548 | }; |
| 549 | 549 | ||
| 550 | $scope.quitarArticulo = function(key) { | 550 | $scope.quitarArticulo = function(key) { |
| 551 | $scope.articulosTabla.splice(key, 1); | 551 | $scope.articulosTabla.splice(key, 1); |
| 552 | }; | 552 | }; |
| 553 | 553 | ||
| 554 | $scope.editarArticulo = function(key, articulo) { | 554 | $scope.editarArticulo = function(key, articulo) { |
| 555 | if(key === 13) { | 555 | if(key === 13) { |
| 556 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 556 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
| 557 | articulo.cantidad === undefined) { | 557 | articulo.cantidad === undefined) { |
| 558 | focaModalService.alert('El valor debe ser al menos 1'); | 558 | focaModalService.alert('El valor debe ser al menos 1'); |
| 559 | return; | 559 | return; |
| 560 | } | 560 | } |
| 561 | articulo.editCantidad = false; | 561 | articulo.editCantidad = false; |
| 562 | articulo.editPrecio = false; | 562 | articulo.editPrecio = false; |
| 563 | } | 563 | } |
| 564 | }; | 564 | }; |
| 565 | 565 | ||
| 566 | $scope.cambioEdit = function(articulo, propiedad) { | 566 | $scope.cambioEdit = function(articulo, propiedad) { |
| 567 | if(propiedad === 'cantidad') { | 567 | if(propiedad === 'cantidad') { |
| 568 | articulo.editCantidad = true; | 568 | articulo.editCantidad = true; |
| 569 | } else if(propiedad === 'precio') { | 569 | } else if(propiedad === 'precio') { |
| 570 | articulo.editPrecio = true; | 570 | articulo.editPrecio = true; |
| 571 | } | 571 | } |
| 572 | }; | 572 | }; |
| 573 | 573 | ||
| 574 | $scope.limpiarFlete = function() { | 574 | $scope.limpiarFlete = function() { |
| 575 | $scope.notaPedido.fleteNombre = ''; | 575 | $scope.notaPedido.fleteNombre = ''; |
| 576 | $scope.notaPedido.chofer = ''; | 576 | $scope.notaPedido.chofer = ''; |
| 577 | $scope.notaPedido.vehiculo = ''; | 577 | $scope.notaPedido.vehiculo = ''; |
| 578 | $scope.notaPedido.kilometros = ''; | 578 | $scope.notaPedido.kilometros = ''; |
| 579 | $scope.notaPedido.costoUnitarioKmFlete = ''; | 579 | $scope.notaPedido.costoUnitarioKmFlete = ''; |
| 580 | $scope.choferes = ''; | 580 | $scope.choferes = ''; |
| 581 | $scope.vehiculos = ''; | 581 | $scope.vehiculos = ''; |
| 582 | }; | 582 | }; |
| 583 | 583 | ||
| 584 | $scope.limpiarPantalla = function() { | 584 | $scope.limpiarPantalla = function() { |
| 585 | $scope.limpiarFlete(); | 585 | $scope.limpiarFlete(); |
| 586 | $scope.notaPedido.flete = '0'; | 586 | $scope.notaPedido.flete = '0'; |
| 587 | $scope.notaPedido.bomba = '0'; | 587 | $scope.notaPedido.bomba = '0'; |
| 588 | $scope.notaPedido.precioCondicion = ''; | 588 | $scope.notaPedido.precioCondicion = ''; |
| 589 | $scope.articulosTabla = []; | 589 | $scope.articulosTabla = []; |
| 590 | $scope.notaPedido.vendedor.nombre = ''; | 590 | $scope.notaPedido.vendedor.nombre = ''; |
| 591 | $scope.notaPedido.cliente = {nombre: ''}; | 591 | $scope.notaPedido.cliente = {nombre: ''}; |
| 592 | $scope.notaPedido.domicilio = {dom: ''}; | 592 | $scope.notaPedido.domicilio = {dom: ''}; |
| 593 | $scope.domiciliosCliente = []; | 593 | $scope.domiciliosCliente = []; |
| 594 | }; | 594 | }; |
| 595 | 595 | ||
| 596 | $scope.resetFilter = function() { | 596 | $scope.resetFilter = function() { |
| 597 | $scope.articuloACargar = {}; | 597 | $scope.articuloACargar = {}; |
| 598 | $scope.cargando = true; | 598 | $scope.cargando = true; |
| 599 | }; | 599 | }; |
| 600 | //Recibe aviso si el teclado está en uso | 600 | //Recibe aviso si el teclado está en uso |
| 601 | $rootScope.$on('usarTeclado', function(event, data) { | 601 | $rootScope.$on('usarTeclado', function(event, data) { |
| 602 | if(data) { | 602 | if(data) { |
| 603 | $scope.mostrarTeclado = true; | 603 | $scope.mostrarTeclado = true; |
| 604 | return; | 604 | return; |
| 605 | } | 605 | } |
| 606 | $scope.mostrarTeclado = false; | 606 | $scope.mostrarTeclado = false; |
| 607 | }); | 607 | }); |
| 608 | 608 | ||
| 609 | $scope.selectFocus = function($event) { | 609 | $scope.selectFocus = function($event) { |
| 610 | // Si el teclado esta en uso no selecciona el valor | 610 | // Si el teclado esta en uso no selecciona el valor |
| 611 | if($scope.mostrarTeclado) { | 611 | if($scope.mostrarTeclado) { |
| 612 | return; | 612 | return; |
| 613 | } | 613 | } |
| 614 | $event.target.select(); | 614 | $event.target.select(); |
| 615 | }; | 615 | }; |
| 616 | 616 | ||
| 617 | $scope.salir = function() { | 617 | $scope.salir = function() { |
| 618 | $location.path('/'); | 618 | $location.path('/'); |
| 619 | }; | 619 | }; |
| 620 | 620 | ||
| 621 | $scope.parsearATexto = function(articulo) { | 621 | $scope.parsearATexto = function(articulo) { |
| 622 | articulo.cantidad = parseFloat(articulo.cantidad); | 622 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 623 | articulo.precio = parseFloat(articulo.precio); | 623 | articulo.precio = parseFloat(articulo.precio); |
| 624 | }; | 624 | }; |
| 625 | 625 | ||
| 626 | function addCabecera(label, valor) { | 626 | function addCabecera(label, valor) { |
| 627 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 627 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 628 | if(propiedad.length === 1) { | 628 | if(propiedad.length === 1) { |
| 629 | propiedad[0].valor = valor; | 629 | propiedad[0].valor = valor; |
| 630 | } else { | 630 | } else { |
| 631 | $scope.cabecera.push({label: label, valor: valor}); | 631 | $scope.cabecera.push({label: label, valor: valor}); |
| 632 | } | 632 | } |
| 633 | } | 633 | } |
| 634 | 634 | ||
| 635 | function removeCabecera(label) { | 635 | function removeCabecera(label) { |
| 636 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 636 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 637 | if(propiedad.length === 1) { | 637 | if(propiedad.length === 1) { |
| 638 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 638 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
| 639 | } | 639 | } |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | function rellenar(relleno, longitud) { | 642 | function rellenar(relleno, longitud) { |
| 643 | relleno = '' + relleno; | 643 | relleno = '' + relleno; |
| 644 | while (relleno.length < longitud) { | 644 | while (relleno.length < longitud) { |
| 645 | relleno = '0' + relleno; | 645 | relleno = '0' + relleno; |
| 646 | } | 646 | } |
| 647 | 647 | ||
| 648 | return relleno; | 648 | return relleno; |
| 649 | } | 649 | } |
| 650 | } | 650 | } |
| 651 | ] | 651 | ] |
| 652 | ) | 652 | ) |
| 653 | .controller('notaPedidoListaCtrl', [ | 653 | .controller('notaPedidoListaCtrl', [ |
| 654 | '$scope', | 654 | '$scope', |
| 655 | 'crearNotaPedidoService', | 655 | 'crearNotaPedidoService', |
| 656 | '$location', | 656 | '$location', |
| 657 | function($scope, crearNotaPedidoService, $location) { | 657 | function($scope, crearNotaPedidoService, $location) { |
| 658 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 658 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
| 659 | $scope.notaPedidos = datos.data; | 659 | $scope.notaPedidos = datos.data; |
| 660 | }); | 660 | }); |
| 661 | $scope.editar = function(notaPedido) { | 661 | $scope.editar = function(notaPedido) { |
| 662 | crearNotaPedidoService.setNotaPedido(notaPedido); | 662 | crearNotaPedidoService.setNotaPedido(notaPedido); |
| 663 | $location.path('/venta-nota-pedido/abm/'); | 663 | $location.path('/venta-nota-pedido/abm/'); |
| 664 | }; | 664 | }; |
| 665 | $scope.crearPedido = function() { | 665 | $scope.crearPedido = function() { |
| 666 | crearNotaPedidoService.clearNotaPedido(); | 666 | crearNotaPedidoService.clearNotaPedido(); |
| 667 | $location.path('/venta-nota-pedido/abm/'); | 667 | $location.path('/venta-nota-pedido/abm/'); |
| 668 | }; | 668 | }; |
| 669 | } | 669 | } |
| 670 | ]) | 670 | ]) |
| 671 | .controller('focaCrearNotaPedidoFichaClienteController', [ | 671 | .controller('focaCrearNotaPedidoFichaClienteController', [ |
| 672 | '$scope', | 672 | '$scope', |
| 673 | 'crearNotaPedidoService', | 673 | 'crearNotaPedidoService', |
| 674 | '$location', | 674 | '$location', |
| 675 | function($scope, crearNotaPedidoService, $location) { | 675 | function($scope, crearNotaPedidoService, $location) { |
| 676 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 676 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
| 677 | $scope.notaPedidos = datos.data; | 677 | $scope.notaPedidos = datos.data; |
| 678 | }); | 678 | }); |
| 679 | $scope.editar = function(notaPedido) { | 679 | $scope.editar = function(notaPedido) { |
| 680 | crearNotaPedidoService.setNotaPedido(notaPedido); | 680 | crearNotaPedidoService.setNotaPedido(notaPedido); |
| 681 | $location.path('/venta-nota-pedido/abm/'); | 681 | $location.path('/venta-nota-pedido/abm/'); |
| 682 | }; | 682 | }; |
| 683 | $scope.crearPedido = function() { | 683 | $scope.crearPedido = function() { |
| 684 | crearNotaPedidoService.clearNotaPedido(); | 684 | crearNotaPedidoService.clearNotaPedido(); |
| 685 | $location.path('/venta-nota-pedido/abm/'); | 685 | $location.path('/venta-nota-pedido/abm/'); |
| 686 | }; | 686 | }; |
| 687 | } | 687 | } |
| 688 | ]); | 688 | ]); |
| 689 | 689 |