Está en la página 1de 28

.

jsp:
<%-- <!-- DE AQUI TENGO QUE COMENTAR-->
=======
<!------------------------inventoryInputId---------------------------------------------------------->
>>>>>>> .r305
<div class="row">
<div class="col-md-4">
<div class="form-group">
<input type="text" class="form-control" tooltippopup-delay="1000"
tooltip="Id de la Entrada de Inventario"
placeholder="Id de la Entrada de Inventario"
ng-model="inventoryInputId" ngchange="inventoryInputIdEmpty()" maxlength="11"
pattern = "[0-9]+"
oninvalid="setCustomValidity('Ingrese un
valor numrico entero')"
oninput="setCustomValidity('')">

<span class="help-block with-errors"></span>


</div>
</div>
<c:if test="${not empty ex}">
<h1>${ex}</h1>
</c:if>
<!-- search -->
<div class=" col-md-1">
<a ng-click="searchInventoryInputs()" href="#"
class="btn btn-info"><span

class="glyphicon glyphiconsearch"></span></a>
</div>
<!-- remove -->
<div class = "col-md-1">
<a ng-show="editing" ng-click="remove()" href="#"
class="btn btn-danger">
<span class="glyphicon glyphicontrash"></span>
</a>
</div>

</div>

<!------------------------inventoryMasterId---------------------------------------------------------->
<div class="row">
<div class="col-md-4">
<label for="inventoryMasterId" >Id del Maestro de
Inventario</label>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<input type="text" class="form-control" tooltippopup-delay="1000"
tooltip="Id del Maestro de Inventario"
placeholder="Id del Maestro de Inventario"
ng-model="inventoryMasterId" ngchange="" pattern = "[0-9]+"

oninvalid="setCustomValidity('Ingrese un valor numrico entero')"


oninput="setCustomValidity('')"
required>
<span class="help-block with-errors"></span>
</div>
</div>
<c:if test="${not empty ex}">
<h1>${ex}</h1>
</c:if>
<!-- search -->
<div class=" col-md-1">
<a ng-click="searchInventoryMasters()" href="#"
class="btn btn-info"><span
class="glyphicon glyphiconsearch"></span></a>
</div>
</div>

<!-- -----------------------amount and


unitCost--------------------------------------------------------->

<br>
<div class="row">
<div class="col-md-4">
<h5> Cantidad </h5>
<div class="form-group">
<input type="text" class="form-control" ngmodel="amount"
placeholder="Cantidad" tooltip-popupdelay="1000"

tooltip="Cantidad" pattern = "[0-9]+(\.[09]+)?"


oninvalid="setCustomValidity('Ingrese una
valor numrico adecuado')"
oninput="setCustomValidity('')" required>
<span class="help-block with-errors"></span>
</div>
</div>
<div class="col-md-4">
<h5> Costo Unitario </h5>
<div class="form-group">
<input type="text" class="form-control" ngmodel="unitCost"
placeholder="Costo Unitario" tooltippopup-delay="1000"
tooltip="Costo Unitario" pattern = "[0-9]+
(\.[0-9]+)?"
oninvalid="setCustomValidity('Ingrese una
valor numrico adecuado')"
oninput="setCustomValidity('')" required>
<span class="help-block with-errors"></span>
</div>
</div>
</div>

<!-- -----------------------date----------------------------------------------------------------------->
<br>
<div class="row">
<div class="col-md-4">
<div class="input-group">

<input block-right-click type="text"


placeholder="Fecha" class="form-control"
datepicker-popup="{{format}}" ngmodel="date"
ng-change="setDate()" isopen="inOpened" min-date="" max-date="dateMax"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)" ngrequired="true"
close-text="Cerrar" current-text="Hoy"
clear-text="Borrar" tooltip-popup-delay="1000"
tooltip="Fecha"/>
<span class="input-group-btn" required>
<button type="button"
class="btn btn-default glyphicon
glyphicon-calendar"
ngclick="open($event,'dateEvent')" style="margin-top: -1px;"></button>
</span>
</div>
</div>

<!-- -----------------------time----------------------------------------------------------------------->

<div class="col-md-4 col-md-push-1 ">


<div class="form-group">
<label class="controllabel">Hora</label>
<timepicker ng-model="time" ngchange="changed()"
hour-step="hstep" minutestep="mstep" show-meridian="ismeridian"></timepicker>

</div>
</div>
</div> --%>

.js
// calendar settings.
$scope.dateMax = new Date();

$scope.open = function($event, option)


{
$event.preventDefault();
$event.stopPropagation();
if (option == "dateEvent") {
$scope.inOpened = !$scope.inOpened;
}
};

$scope.setDate = function()
{
console.log("Selected date: "+ $scope.date);
$scope.date = $scope.date;
}

$scope.dateOptions = {
formatYear : 'yy',
startingDay : 1

};

$scope.formats = [ 'dd-MM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy',


'shortDate' ];
$scope.format = $scope.formats[0];
// end calendar settings.

//time settings.

//settings
$scope.time = new Date();

$scope.hstep = 1;
$scope.mstep = 10;
$scope.ismeridian = true;

//reset
var d = new Date();
$scope.time = d;
//end time Settings

/*
//Function to clear the window form
$scope.clearForm = function()
{
$scope.inventoryInputId= "";
$scope.inventoryMasterId= "";

$scope.useId = "";
$scope.amount= "";
$scope.unitCost= "";

//With the names as they

appear in the Object


$scope.date = "";
$scope.time = "";

$scope.editing = false;
$scope.searched = false;
}

//Function to check if the inventoryInputId input is empty


$scope.inventoryInputIdEmpty = function() //This function is on when
you type in the Id input field
{
if($scope.inventoryInputId == "" || $scope.inventoryInputId ==
null)
{
console.log("Id inventoryI esta vacio; unico lugar donde
se usa clearform");
$scope.isInventoryInputIdInputEmpty = true;
$scope.editing = false;
$scope.clearForm();

//$scope.isUseIdInputEmpty = true;
}
else if($scope.inventoryInputId !="" ||
$scope.inventoryInputId != null)
{
console.log("Id inventoryM tiene algo");

$scope.isInventoryInputIdInputEmpty=false;
}
}

//Function to search an Inventory Input with a given Inventory Input id


or to show a modal dialog with a list of Inventory Inputs
//to select one
$scope.searchInventoryInputs = function()
{
var url = "http://localhost:8080/argusinventory/protected/guests/inventoryInput/list";

$http.get(url).success(function(data)
{

$rootScope.inventoryInput = data;

if($scope.isInventoryInputIdInputEmpty == true)
{
var modalData = {};
modalData.list =
$rootScope.inventoryInput;
modalData.keyName = 'id';
modalData.selectWhat = 'la
Entrada de Inventario';
modalData.femOrMale = 'fem';

var modalInstance =
$modal.open({

templateUrl :
'http://localhost:8080/argusinventory/protected/admin/dialogs/itemSelectorDialog.jsp',
controller :
'modalController1',
resolve : {
data : function() {
return
modalData;
}
}
});

modalInstance.result.then(function(selectedItem1)
{
if(selectedItem1 == null)
return;

$scope.editing = true;
$scope.searched = true;

$scope.inventoryInputId =
selectedItem1.id;
$scope.inventoryMasterId =
selectedItem1.inventoryMasterId.id;
$scope.amount =
selectedItem1.amount;
$scope.unitCost =
selectedItem1.unitCost;
$scope.date =
selectedItem1.date;

//set Time
var colonPos =
selectedItem1.time.search(":");
var hours =
selectedItem1.time.substring(0, colonPos);
var auxStr =
selectedItem1.time.substring(colonPos + 1);

colonPos =
auxStr.search(":");
var minutes =
auxStr.substring(0, colonPos);

var d = new Date();


d.setHours(parseInt(hours));

d.setMinutes(parseInt(minutes));
$scope.time = d;

console.log(selectedItem1);

}, function() {
$log.info('Modal dismissed
at: ' + new Date());
});
}

else
{

url= "http://localhost:8080/argusinventory/protected/guests/inventoryInput/findOne"

var inventoryInputString = {};


inventoryInputString.id =
parseInt($scope.inventoryInputId);

var config = {
params :
{
inventoryInputData :
inventoryInputString
}
};

$http.post(url, null, config)


.success(function(data, status, headers, config)
{
if(data.error_code == 998)
sweetAlert("Oops...",
"Esta Entrada de Inventario
NO existe",
"error");
else
{

$scope.editing =
true;
$scope.searched =
true;

$scope.inventoryInputId = selectedItem.id;

$scope.inventoryMasterId = selectedItem.inventoryMaster.id;
$scope.amount =
selectedItem.amount;
$scope.unitCost =
selectedItem.unitCost;

selectedItem.date;

$scope.date=
//With the names as they appear in the model
$scope.time =

selectedItem.time;
}

}).error(function(data, status, headers, config)


{
sweetAlert("Oops...",
"Error conectando con el servidor",
"error");

});

}).error(function() {

console.log("Error en inventoryInput.js linea 187");


});

};

//Function to show a modal dialog with an Inventory Masters list and


the option to select one
$scope.searchInventoryMasters = function()
{

var url = "http://localhost:8080/argusinventory/protected/admin/inventoryMaster/list";

$http.get(url).success(function(data)
{

$rootScope.inventoryMaster = data;

if($scope.isInventoryMasterIdInputEmpty == true)
{
var modalData = {};
modalData.list =
$rootScope.inventoryMaster;
modalData.firstKey = 'id';

modalData.secondKey =
'description';
modalData.selectWhat = 'el
Maestro de Inventario';
modalData.femOrMale = 'male';

var modalInstance =
$modal.open({
templateUrl :
'http://localhost:8080/argusinventory/protected/admin/dialogs/itemSelectorDialogTwoKeys.jsp',
controller :
'modalController',
resolve : {
data : function() {
return
modalData;
}
}
});

modalInstance.result.then(function(selectedItem)
{
if(selectedItem == null)
return;

$scope.inventoryMasterId =
selectedItem.id;

console.log(selectedItem);

}, function() {
$log.info('Modal dismissed
at: ' + new Date());
});
}

}).error(function() {

console.log("Error en inventoryInput.js linea 270");


});

};

/*

$scope.remove= function()
{
if($scope.editing == false )
return;

var url = "http://localhost:8080/argusinventory/protected/guests/inventoryInput/remove";

var inventoryInputString = {};


inventoryInputString.id = parseInt($scope.inventoryInputId);
console.log("Remove:" + $scope.inventoryInputId);

var config = {
params : {

inventoryInputData : inventoryInputString
}
};

$http.post(url, null,config)
.success(function(data, status, headers, config)
{
if (data.error_code == 997)
sweetAlert("Oops...",
"Esta Entrada de Inventario no esta
registrada",
"error");

else
{
swal({ title: "Operacion Exitosa!",
text: "Entrada de Inventario
eliminada",
type: "success",
showCancelButton: false,
confirmButtonText: "Ok",
closeOnConfirm: false
}, function(){
location.reload();
});
}
}).error(function(data, status, headers, config)
{
sweetAlert("Oops...",

"Error eliminando la Entrada de


Inventario",
"error");
});
}

//Function to create and edit


$('#inventoryInputForm').validator().on('submit', function(e)
{
if (e.isDefaultPrevented())
{
sweetAlert("Oops...",
"Debe llenar todos los campos requeridos",
"warning");
}
else
{
var inventoryInputString = {};

inventoryInputString.inventoryInputId =
parseInt($scope.inventoryInputId);
inventoryInputString.inventoryMasterId =
parseInt($scope.inventoryMasterId);
inventoryInputString.amount =
parseFloat($scope.amount);
inventoryInputString.unitCost =
parseFloat($scope.unitCost);
//get date
inventoryInputString.date = $scope.date;

console.log($scope.date);
//get time
inventoryInputString.time = $scope.time.getHours() +
":" +
$scope.time.getMinutes();

console.log("Time: " + $scope.time.getHours() +


":" + $scope.time.getMinutes() );

var config = {
params : {
inventoryInputData : inventoryInputString
}
};

var url ='http://localhost:8080/argusinventory/protected/guests/inventoryInput/create';

if ($scope.editing)
url = 'http://localhost:8080/argusinventory/protected/guests/inventoryInput/update';

$http.post(url, null, config)


.success(function(data,status, headers, config)
{
if(data.error_code == 999)
sweetAlert("Oops...",
"Entrada de Inventario ya existe",

"error");
else if(data.error_code == 998)
sweetAlert("Oops...",
"Verifique que el Maestro de
Inventario y el Usuario Existan",
"error");
else if(data.error_code == 977)
sweetAlert("Oops...",
"Error Creando los Record de
Entradas Asociados a su Entrada de Inventario",
"error");
else
{
swal({title: "Operacion Exitosa!",
text: "Entrada de Inventario " +
($scope.editing ? "editada!" : "creada!"),
type: "success"},
function()
{
location.reload()
}
);

}
}).error(function(data, status, headers, config)
{
sweetAlert("Oops...",
"Error creando la Entrada de Inventario",
"error");

});

console.log("Array" +
JSON.stringify(inventoryInputString));
}
})
*/

});

})(window.angular);

//MODAL DIALOG TO SHOW A INVENTORYMASTER LIST AND SELECT ONE


(function(angular) {
'use strict';

var argusWeb = angular.module('argusWeb');

argusWeb.controller('modalController', function($scope, $modalInstance,


data,
$http, $filter)
{

$scope.list = data.list;
$scope.firstKey = data.firstKey;
$scope.secondKey = data.secondKey;
$scope.selectWhat = data.selectWhat;
$scope.femOrMale = data.femOrMale == 'fem' ? 'a': 'o'; //this is for

the label: selectWhat seleccionad@: ...

$scope.selectedIndex = 0;

$scope.itemClicked = function($index, item)


{
$scope.selectedIndex = $index;
$scope.selectedItem = item;
};

$scope.ok = function()
{
$modalInstance.close($scope.selectedItem);
};

$scope.cancel = function()
{
$modalInstance.dismiss('cancel');
};
});

})(window.angular);

/*
//MODAL DIALOG TO SHOW A INVENTORYMASTER LIST AND SELECT ONE
(function(angular) {
'use strict';

var argusWeb = angular.module('argusWeb');

argusWeb.controller('modalController1', function($scope, $modalInstance,


data,
$http, $filter)
{

$scope.list = data.list;
$scope.keyName = data.keyName;
$scope.selectWhat = data.selectWhat;
$scope.femOrMale = data.femOrMale == 'fem' ? 'a': 'o'; //this is for
the label: selectWhat seleccionad@: ...

$scope.selectedIndex = 0;

$scope.itemClicked = function($index, item)


{
$scope.selectedIndex = $index;
$scope.selectedItem1 = item;
};

$scope.ok = function()
{
$modalInstance.close($scope.selectedItem1);
};

$scope.cancel = function()
{
$modalInstance.dismiss('cancel');

};
});

})(window.angular); */

--------------Controller-------------@SuppressWarnings("unchecked")
@RequestMapping(value = "/protected/guests/inventoryInput/create", method
= RequestMethod.POST)
public @ResponseBody JSONObject
createInventoryInput(@RequestParam(required = true) String inventoryInputData,
final HttpServletResponse response) throws
JsonProcessingException,
IOException
{

JSONObject result = new JSONObject();


ObjectMapper mapper = new ObjectMapper();

JsonNode actualObj = mapper.readTree(inventoryInputData);

InventoryInput inventoryInput = new InventoryInput();

String date = actualObj.findValue("date").getValueAsText();


date = (date.split("T"))[0];
System.out.println("Date: " + date);

InventoryMaster inventoryMaster = inventoryMasterService.

getInventoryMasterById(actualObj.findValue("inventoryMasterId").getIntValue());

int userauxid= 1; //userid just to test the table, we'd need set a user
strategy later
User user = userService.getUserByID(userauxid);

if(inventoryMaster == null || user == null)


{
result.put("status", "error");
result.put("error_code", "998");

return result;

inventoryInput.setInventoryMasterId(inventoryMaster);
inventoryInput.setUserId(user);
inventoryInput.setAmount((float)
(actualObj.findValue("amount").getDoubleValue()));
inventoryInput.setUnitCost((float)
(actualObj.findValue("unitCost").getDoubleValue()));

//setDate
Date dateD = Date.valueOf(date);
inventoryInput.setDate(dateD);

//setTime

inventoryInput.setTime(actualObj.findValue("time").getTextValue());

InventoryInput inventoryInputSaved =
inventoryInputService.create(inventoryInput);

if(inventoryInputSaved == null)
{
result.put("status", "error");
result.put("error_code", "999");

return result;
}

int inputRecordAmount= (int)inventoryInputSaved.getAmount();

for(int i=0;i<inputRecordAmount;i++)
{
InputRecord inputRecord = new InputRecord();

inputRecord.setInventoryInputId(inventoryInputSaved);

InputRecord inputRecordCreated =
inputRecordService.create(inputRecord);

if(inputRecordCreated == null)
{

result.put("status", "error");
result.put("error_code", "977");

System.out.println("Error creando los records de


entradas");

return result;
}
}

result.put("status", "success");
return result;
}

@SuppressWarnings("unchecked")
@RequestMapping(value = "/protected/guests/inventoryInput/remove",
method = RequestMethod.POST)
public @ResponseBody JSONObject
removeInventoryInput(@RequestParam(required = true) String inventoryInputData,
final HttpServletResponse response) throws
JsonProcessingException,
IOException
{
JSONObject result = new JSONObject();
ObjectMapper mapper = new ObjectMapper();

JsonNode actualObj = mapper.readTree(inventoryInputData);

InventoryInput inventoryInput = new InventoryInput();

inventoryInput.setId((actualObj.findValue("id").getIntValue()));
System.err.println("Estoy en el controlador luego de validar");

InventoryInput inventoryInputremoved =
inventoryInputService.remove(inventoryInput);

if(inventoryInputremoved == null)
{
result.put("status", "error");
result.put("error_code", "998");

return result;
}

result.put("status", "success");
return result;
}