angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', [ '$scope', '$uibModal', 'crearNotaPedidoService', function ($scope, $uibModal, crearNotaPedidoService) { $scope.notaPedido = {}; var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); var domiciliosCliente = [ { dom: 'sanjuan', id: 3 }, { dom: 'mendoza', id: 2 } ] if (notaPedidoTemp != undefined) { notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); $scope.notaPedido = notaPedidoTemp; $scope.notaPedido.domicilio = domiciliosCliente; } else { $scope.notaPedido.fechaCarga = new Date(); $scope.notaPedido.domicilio = domiciliosCliente; } $scope.precioCondiciones = [ { nombre: 'Precio y condicion 1' }, { nombre: 'Precio y condicion 2' }, { nombre: 'Precio y condicion 3' } ] $scope.articulosTabla = [ { codigo: '1', item: 1, nombre: 'naftaaskdahsñodaskdjhañslkdjahslñkjdhalskjdhaksjdhkasjhasddddddddddddddddddddddddddddddddddddddddddddddddd', precio: '14,50', costoUnitario: '14', cantidad: 1, subtotal: '19,22' } ] $scope.notaPedido.bomba = '1'; $scope.notaPedido.flete = '1'; $scope.addNewDom = function () { $scope.notaPedido.domicilio.push({ 'id': 0 }); } $scope.removeNewChoice = function (choice) { if ($scope.notaPedido.domicilio.length > 1) { $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1) } } $scope.crearNotaPedido = function () { var notaPedido = { idNotaPedido: 0, precioCondicion: $scope.notaPedido.precioCondicion, fechaCarga: $scope.notaPedido.clientefechaCarga, vendedor: $scope.notaPedido.vendedor, cliente: $scope.notaPedido.cliente, producto: $scope.notaPedido.producto, bomba: $scope.notaPedido.bomba, petrolera: $scope.notaPedido.petrolera, domicilio: $scope.notaPedido.domicilio, kilometros: $scope.notaPedido.kilometros, jurisdiccionIIBB: $scope.notaPedido.jurisdiccion, costoFinanciacion: $scope.notaPedido.costoFinanciacion, flete: $scope.notaPedido.flete, costoUnitarioKmFlete: $scope.costoUnitarioKmFlete } crearNotaPedidoService.crearNotaPedido(notaPedido).then( function (res) { alert('Nota pedido creada') } ) } $scope.siguienteTab = function () { $scope.active = 1; } $scope.seleccionarArticulo = function () { var modalIntance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Productos', templateUrl: 'modal-busqueda-productos.html', controller: 'modalBusquedaProductosCtrl', size: 'md' } ) modalInstance.result.then( function (producto) { console.info(producto); // variable producto tiene el producto seleccionado en el modal }, function () { // funcion ejecutada cuando se cancela el modal } ); } $scope.obtenerDomicilios = function (id) { crearNotaPedidoService.getDomicilios(id).then( function (res) { $scope.notaPedido.domicilio = res.data; } ) } } ] ) .controller('notaPedidoListaCtrl', [ '$scope', 'crearNotaPedidoService', '$location', function ($scope, crearNotaPedidoService, $location) { crearNotaPedidoService.obtenerNotaPedido().then(function (datos) { $scope.notaPedidos = datos.data; }); $scope.editar = function (notaPedido) { crearNotaPedidoService.setNotaPedido(notaPedido); $location.path('/venta-nota-pedido/abm/'); }; } ])