public function testNuevoAval() { //Crear un cliente $a = ClientesController::nuevo(time() . "cliente"); //crear su aval $b = ClientesController::nuevo(time() . "aval"); //asignar el aval al cliente ClientesController::NuevoAval(array(array("id_aval" => $b["id_cliente"], "tipo_aval" => "prendario")), $a["id_cliente"]); $r = ClienteAvalDAO::getByPK($a["id_cliente"], $b["id_cliente"]); $this->assertNotNull($r); }
public static function NuevoAval($avales, $id_cliente) { //avales debe ser un arreglo if (!is_array($avales)) { throw new InvalidDataException("Avales debe ser un array"); } foreach ($avales as $a) { if (!is_array($a)) { $a = object_to_array($a); } if (!isset($a["id_aval"])) { throw new InvalidDataException("avales debe ser un arreglo de arreglos, falta id_aval"); } if (!isset($a["tipo_aval"])) { throw new InvalidDataException("avales debe ser un arreglo de arreglos falta tipo_aval"); } //tipos //if($a["tipo_aval"]) if (is_null($a["id_aval"])) { throw new InvalidDataException("el aval " . $a["id_aval"] . "no existe"); } } //validar que existan clientes y avales if (is_null($id_cliente)) { throw new InvalidDataException("el cliente a avalar no existe"); } foreach ($avales as $a) { if (!is_array($a)) { $a = object_to_array($a); } if ($a["id_aval"] == $id_cliente) { //no se puede ser aval de sí mismo continue; } $clienteAval = new ClienteAval(); $clienteAval->setIdAval($a["id_aval"]); $clienteAval->setIdCliente($id_cliente); $clienteAval->setTipoAval($a["tipo_aval"]); try { Logger::log("Salvando nuevo aval a DB"); ClienteAvalDAO::save($clienteAval); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } } }
$dform->createComboBoxJoin("id_ciudad", "nombre", CiudadDAO::getAll(), $direccionObj->getIdCiudad()); $page->addComponent($dform); } /* * ******************************************************* * Avales * * ******************************************************** */ $page->nextTab("Avales"); $page->addComponent(new TitleComponent("Nuevo Aval", 3)); $clientes_component = new ClienteSelectorComponent(); $clientes_component->addJsCallback("( function(record){ Ext.get('add_aval').setStyle({'display':'block'}); id_usuario = record.get('id_usuario'); nombre = record.get('nombre'); id_este_usuario = " . $este_usuario->getIdUsuario() . "; if(id_usuario == id_este_usuario){ Ext.core.Element.fly(\"agregar_aval_btn\").setVisible(false); Ext.get(\"nombre_aval_a_agregar\").update('No se puede ser aval de si mismo');}else{ Ext.core.Element.fly(\"agregar_aval_btn\").setVisible(true); Ext.get(\"nombre_aval_a_agregar\").update('Nuevo Aval: '+record.get('nombre'));} } )"); $page->addComponent($clientes_component); $page->addComponent(new FreeHtmlComponent("<div id= \"nombre_aval_a_agregar\" style =\"display:block; font-size=14; font-weight:bold;\" ></div>")); $page->addComponent(new FreeHtmlComponent("<br><div id = \"add_aval\" style = \"display:none;\" ><form name = \"tipo_aval\" id = \"tipo_aval\"> <input id = \"radio_hipoteca\" type='Radio' name='taval' value='hipoteca' checked> hipoteca <input id = \"radio_prendario\"type='Radio' name='taval' value='prendario'> prendario</form> <br> <div id=\"agregar_aval_btn\" class='POS Boton' onClick = \"nuevoClienteAval(nombre, id_usuario, id_este_usuario)\" >Agregar como aval</div></div>")); $page->addComponent(new TitleComponent("Lista de Avales", 3)); $avales = ClienteAvalDAO::search(new ClienteAval(array("id_cliente" => $este_usuario->getIdUsuario()))); $array_avales = array(); foreach ($avales as $aval) { array_push($array_avales, $aval->asArray()); } $tabla_avales = new TableComponent(array("id_aval" => "Nombre", "tipo_aval" => "Tipo de Aval"), $array_avales); function funcion_nombre_aval($id_usuario) { return UsuarioDAO::getByPK($id_usuario)->getNombre(); } $tabla_avales->addColRender("id_aval", "funcion_nombre_aval"); $page->addComponent($tabla_avales); /* * ******************************************************* * Seguimientos * * ******************************************************** */