<?php

include_once "../controller/cExpediente.php";
include_once "../helper/uploadFileClass.php";
$upo = new uploadFile();
$exped = new cExpediente();
if (isset($_POST['obligado'])) {
    $m = $exped->regExpedienteClteObligado('', $_POST['txtApellidoPaterno'], $_POST['txtApellidoMaterno'], $_POST['txtNombre'], $_POST['txtFechaNacimiento'], $_POST['tipoExp'], $_POST['compartir'], $_POST['prestarsinob'], 1, $_POST['ciudadnac'], $_POST['txtEstadoNac'], $_POST['txtTelefono'], $_POST['txtCorreo'], $_POST['txtCURP'], $_POST['txtRFC'], $_POST['txtNacionalidad'], $_POST['generoQ'], $_POST['giro'], $_POST['txtObservaciones'], $_POST['id_persona2']);
} else {
    $m = $exped->regNvoExp('', $_POST['txtApellidoPaterno'], $_POST['txtApellidoMaterno'], $_POST['txtNombre'], $_POST['txtFechaNacimiento'], $_POST['tipoExp'], $_POST['compartir'], $_POST['prestarsinob'], 1, $_POST['ciudadnac'], $_POST['txtEstadoNac'], $_POST['txtTelefono'], $_POST['txtCorreo'], $_POST['txtCURP'], $_POST['txtRFC'], $_POST['txtNacionalidad'], $_POST['generoQ'], $_POST['giro'], $_POST['txtObservaciones'], $_POST['id_persona2']);
}
$exped->creaPerfilTrans($m, $_POST['ingreso'], $_POST['origen_recursos'], $_POST['giro'], $_POST['destino_recursos'], $_POST['montooperaciones'], $_POST['numoperaciones']);
$iddom = $exped->regDomClte($m, $_POST['txtCalle'], $_POST['txtAvenida'], $_POST['txtNumeroEx'], $_POST['txtNumeroIn'], $_POST['txtColonia'], $_POST['txtCodigoPostal'], $_POST['txtCiudad'], $_POST['txtEstado'], '', 1, $_POST['txtDelegacion'], $_POST['txtPais'], 'no def', 'no def', $_POST['referenciaDom'], '', '', 1);
$exped->regDetallesExpe($m, $_POST['txtOcupacion'], $_POST['origen_recursos'], $_POST['destino_recursos'], 0, 1, '', '', '00:00', '', '', '', '');
$exped->regEmpleoClte($m, '', '', '', '', '', '', '', '', $_POST['ingreso'], '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
echo "EXPEDIENTE REGISTRADO CON ÉXITO";
//registra los adjuntos
//identificacion oficial
if (!empty($_FILES['identificacionOficial']['name'])) {
    $upo->guardarArchivo('identificacionOficial', $m);
    $exped->regAdjuntoExpend($_FILES['identificacionOficial']['name'], $m, $_POST['tipoDocIden']);
} else {
    $exped->regAdjuntoExpend("sin adjunto", $m, $_POST['tipoDocIden']);
}
//comprobante de domicilio
if (!empty($_FILES['comprobanteDom']['name'])) {
    $upo->guardarArchivo('comprobanteDom', $m);
    $exped->regAdjuntoDom($iddom, $_FILES['comprobanteDom']['name'], $_POST['tipoDocDom']);
} else {
    $exped->regAdjuntoDom($iddom, "sin adjunto", $_POST['tipoDocDom']);
}
    $m = $expe->regNvoExp('', $_POST['a_pat'], $_POST['a_mat'], $_POST['nombre'], $_POST['fnac'], $_POST['tipoExp'], $_POST['compartir'], $_POST['autorizar'], 1, $_POST['ciudadNac'], $_POST['estadoNac'], $_POST['telefonoPers'], '', $_POST['curp'], $_POST['rfc'], $_POST['nacionalidad'], $_POST['generoQ'], $_POST['actividadeco'], $_POST['observaciones'], $_POST['id_persona2']);
}
//registra la clave agrupadora
if ($_POST['claveAgrup'] == 0 || $_POST['claveAgrup'] == '0') {
    $expe->regClveAgrupadora($m, $m);
} else {
    $expe->regClveAgrupadora($m, $_POST['claveAgrup']);
}
//crea la entrada en el perfil transaccional
$expe->creaPerfilTrans($m, $_POST['txtIngresoMensual'], $_POST['origenRec'], $_POST['actividadeco'], $_POST['destinoRec'], $_POST['montooperaciones'], $_POST['numoperaciones']);
//registra el domicilio
$dom = $expe->regDomClte($m, $_POST['calle'], $_POST['ave'], $_POST['n_ext'], $_POST['n_int'], $_POST['txtColonia'], $_POST['cp'], $_POST['txtCiudadPoblacion'], $_POST['txtEstado'], "", 1, $_POST['localidad'], $_POST['txtPais'], $_POST['txtTiempoDomicilio'], $_POST['txtTiempoPoblacion'], $_POST['refDom'], "", "", $_POST['tipovivienda']);
//registra los detalles del empleo del cliente
$expe->regEmpleoClte($m, $_POST['txtEmpresa'], $_POST['txtPueto'], $_POST['txtTelefonoTrabajo'], $_POST['txtExtencion'], $_POST['txtDomicilioTrabajo'], $_POST['txtColoniaTrabajo'], $_POST['txtCiudadPoblacionTrabajo'], $_POST['txtEstadoTrabajo'], $_POST['txtIngresoMensual'], $_POST['txtTiempoTrabajo'], $_POST['txtCorreoTrabajo'], $_POST['txtCodConvenio'], $_POST['txtConvenio'], $_POST['txtExpediente'], $_POST['txtPlaza'], $_POST['txtNoEmpleado'], $_POST['txtSindicato'], $_POST['txtZonaEscolar'], $_POST['txtFiliacion'], $_POST['txtTipoContrato'], $_POST['txtNoPlaza'], $_POST['txtNoFicha'], $_POST['txtCveCentroTrab'], $_POST['txtNoNomina'], $_POST['txtSucursal'], $_POST['txtArea'], $_POST['txtNoPencion']);
//detalles socioeconomicos
$expe->regDetallesExpe($m, $_POST['profesion'], $_POST['origenRec'], $_POST['destinoRec'], $_POST['pep'], 1, $_POST['cmbEstadoCivil'], $_POST['txtDependientesEconomicos'], $_POST['txtHoraContacto'], $_POST['txtUbicacionNegocio'], $_POST['txtNombreConyuge'], $_POST['txtApellidoPaternoConyuge'], $_POST['txtApellidoMaternoConyuge']);
//referencias personales
$i = 1;
while ($i <= $_POST['numbRefPers']) {
    //nombre,id_cliente,horaContacto,telefono,relacion
    $expe->registroRefCltePers($_POST['txtNombreReferencia' . $i], $m, $_POST['txtHoraContactoReferencia' . $i], $_POST['txtTelefonoReferencia' . $i], $_POST['txtRelacion' . $i]);
    // $expe->regRefCltePers($_POST['txtNombreReferencia'.$i],
    //  $m, $_POST['txtTelefonoReferencia'.$i], '', "", $_POST['txtRelacion'.$i]);
    $i++;
}
//referencias comerciales
$i = 1;
while ($i <= $_POST['numbRefComrs']) {
    $expe->regRefClteCom($_POST['txtComercio' . $i], $_POST['txtReferenciaComercial' . $i], $m, $_POST['cmbTipoRef' . $i]);
    $i++;
}