function reporteE($data) { global $db, $db2, $hoy, $sesIdOficina; $sesIdUsuario = $_SESSION[sesIdUsuario]; $fec1 = $data[fec1]; $fec2 = $data[fec2]; $tipoRep = $data[tipoRep]; $sepa = $data[sepa]; $idNaviera = $data[idNaviera]; // Se crea el archivo $archivo = "../files/Inventario.csv"; $fp = fopen("{$archivo}", "w"); // Encabezado $oficina = getValueTable("oficina", "OFICINA", "id_oficina", $sesIdOficina); $oficina = strtoupper($oficina); $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNaviera); $enc = "El Trebol\n"; fputs($fp, $enc); $enc = "REPORTE DE INVENTARIO \n"; fputs($fp, $enc); $enc = "NAVIERA : {$naviera} \n"; fputs($fp, $enc); $enc = "F.EMISION: {$hoy} \n\n"; fputs($fp, $enc); // ----------------------------------- // COLUMNAS // ----------------------------------- /* $enc = "Fecha".$sepa."Contenedor".$sepa."Tipo".$sepa."Clase".$sepa."Status".$sepa; $enc.="EIR".$sepa."Naviera".$sepa."Lin.Transp.".$sepa."Operador".$sepa."Placas".$sepa."No.Chasis".$sepa; $enc.="Mani.Tipo".$sepa."Mani.QuienPaga".$sepa."Documento".$sepa."Referencia".$sepa."Cuenta".$sepa; $enc.="Costo".$sepa."Recibo".$sepa."Activo/Baja".$sepa."Capturo".$sepa."Fec.Modifica"; */ $enc = "Contenedor" . $sepa . "Tipo" . $sepa . "Fec.Entrada" . $sepa . "Status" . $sepa . "Clase" . $sepa . "Dias" . $sepa . "Notas" . $sepa . "Reforzado" . $sepa . "EIR" . $sepa . "NAVIERA"; $enc .= "\n"; fputs($fp, $enc); // ----------------------------------- // DEPURACION // ----------------------------------- $sql = "SELECT id_contenedor from INVENTARIO_PLUS "; $db->query($sql); while ($db->next_record()) { $idConte = $db->f(id_contenedor); actualizaInventarioPlus($idConte); } // ----------------------------------- // DATOS // ----------------------------------- /* $sql = "SELECT * from INVENTARIO_PLUS where "; if($idNaviera<>'-'){ $sql.="id_naviera='$idNaviera' and id_contenedor>0 and "; } $sql.="id_oficina='1' "; $sql.="order by id_naviera,cap_fec "; */ $sql = "select *,n.id_naviera as IDNAV "; $sql .= " from INVENTARIO_PLUS i,CONTENEDOR c, NAVIERA n "; $sql .= "where "; $sql .= "i.id_contenedor=c.id_contenedor and "; $sql .= "c.id_naviera=n.id_naviera and "; if ($idNaviera != '-') { $sql .= "n.id_naviera='{$idNaviera}' and "; } $sql .= "i.id_oficina='1' order by n.id_naviera,i.cap_fec "; $db->query($sql); while ($db->next_record()) { $capFec = $db->f('cap_fec'); $idConte = $db->f('id_contenedor'); $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $idEq = getValueTable("id_equipo", "CONTENEDOR", "id_contenedor", $idConte); $equipo = getValueTable("equipo", "EQUIPO", "id_equipo", $idEq); //$clase = $db->f('clase'); // Traer el dato mas actual desde el catalogo de contenedores $clase = getValueTable("clase", "CONTENEDOR", "id_contenedor", $idConte); $damage = $db->f('damage'); $eir = "E-" . $db->f('eir'); $idNav = $db->f('IDNAV'); $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNav); $transp = $db->f('transportista'); $operador = $db->f('operador'); $placas = $db->f('placas'); $chasis = $db->f('chasis'); $maniTipo = $db->f('tipo_mani'); $maniQP = $db->f('mani_st_pago'); $maniQP == "M" ? $maniQP = "MERCHANT" : ($maniQP = "CARRIER"); $maniDoc = $db->f('doc_tipo'); $maniDocRef = $db->f('doc_ref'); $maniCuenta = $db->f('cuenta'); $maniCosto = $db->f('mani_costo'); $maniRecibo = $db->f('recibo'); $idOficina = $db->f('id_oficina'); $oficina = getValueTable("oficina", "OFICINA", "id_oficina", $idOficina); $modIdUsr = $db->f('mod_id_usr'); $usr = getValueTable("usuario", "USUARIO", "id_usuario", $modIdUsr); $modFec = $db->f('mod_fec'); $conteEntSal = getValueTable("ent_sal", "CONTENEDOR", "id_contenedor", $idConte); $nota = $db->f(nota); $nota = addslashes($nota); $nota = str_replace("\n", "", $nota); $nota = str_replace("\r", "", $nota); // Comprobar que el contenedor, mismo registro no este dado de baja en Entradas en su mas reciente evento. $sql2 = "select st_reg from ENTRADA where id_contenedor='{$idConte}' order by cap_fec"; $db2->query($sql2); while ($db2->next_record()) { $stReg = $db2->f(st_reg); } if (empty($stReg)) { $stReg = "A"; // Activo } // Escribiendo al archivo. if ($stReg != "B" && $conteEntSal != "S") { /* $row=$capFec.$sepa.$conte.$sepa.$equipo.$sepa.$clase.$sepa.$damage.$sepa; $row.=$eir.$sepa.$naviera.$sepa.$transp.$sepa.$operador.$sepa.$placas.$sepa.$chasis.$sepa; $row.=$maniTipo.$sepa.$maniQP.$sepa.$maniDoc.$sepa.$maniDocRef.$sepa.$maniCuenta.$sepa; $row.=$maniCosto.$sepa.$maniRecibo.$sepa.$stReg.$sepa.$usr.$sepa.$modFec.$sepa; */ $datoX = getLastIn($idConte); $fecEnt = $datoX['fecEnt']; $eir = $datoX['eir']; $damage = getDamage($idConte); $reforzado = getReforzado($idConte); $clase = getValueTable("clase", "CONTENEDOR", "id_contenedor", $idConte); // Calcular los días de almacenaje. $hoy = date("Y-m-d"); $dias = totalDias($fecEnt, $hoy); $row = $conte . $sepa . $equipo . $sepa . $fecEnt . $sepa . $damage . $sepa . $clase . $sepa . $dias . $sepa . $nota . $sepa . $reforzado . $sepa . $eir . $sepa . $naviera; $row .= "\n"; fputs($fp, $row); } } fclose($fp); // ----------------------------- // SALVAR COMO... O ABRIR EN AUTO. // (No modificar) // ----------------------------- if (file_exists("{$archivo}")) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($archivo)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($archivo)); ob_clean(); flush(); readfile("{$archivo}"); exit; } }
function reporteI($data) { global $db, $db2, $db3, $hoy, $sesIdOficina; // ---------------------------------------------------------------------------- // REPORTE DE INVENTARIO_PROC // ---------------------------------------------------------------------------- // 1. Se crean registros en tabla INVENTARIO_PROC donde se eliminan los duplicados. // 2. Es importante dejar esta opcion en el query de consulta : // --> e.cap_fec desc <---- // El primer registro con fecha mayor sera el que pasar a la tabla INVENTARIO_PROC // ---------------------------------------------------------------------------- // Limpiar inventario. $sql = "truncate INVENTARIO_PROC "; $db->query($sql); $sesIdUsuario = $_SESSION[sesIdUsuario]; $fec1 = $data[fec1]; $fec2 = $data[fec2]; $tipoRep = $data[tipoRep]; $sepa = $data[sepa]; $idNaviera = $data[idNaviera]; // Se crea el archivo $archivo = "../files/Inventario.csv"; $fp = fopen("{$archivo}", "w"); // Encabezado $oficina = getValueTable("oficina", "OFICINA", "id_oficina", $sesIdOficina); $oficina = strtoupper($oficina); $enc = "{$oficina}\n"; fputs($fp, $enc); $enc = "REPORTE DE INVENTARIO_PROC \n"; fputs($fp, $enc); $enc = "MODULO : INVENTARIO_PROC \n"; fputs($fp, $enc); $enc = "F.EMISION: {$hoy} \n\n"; fputs($fp, $enc); // ----------------------------------- // COLUMNAS // ----------------------------------- $enc = "No." . $sepa . "Naviera" . $sepa . "Contenedor" . $sepa . "Size" . $sepa . "Tipo" . $sepa; $enc .= "Status" . $sepa . "Calidad" . $sepa . "F.Entrada" . $sepa; $enc .= "Nota" . $sepa . "Reforzado" . $sepa . "Dias-Trans" . $sepa . "Bloque" . $sepa . "Bahia" . $sepa . "Nivel" . $sepa; $enc .= "\n"; fputs($fp, $enc); // ----------------------------------- // DATOS // ----------------------------------- // Consultar el status "ent_sal" en la tabla de CONTENEDOR, ya que este indica el status // actual en que esta ese contenedor sea una Entrada o Salida. // Si si status es Entrada entonces grabarlo a la tabla INVENTARIO_PROC y asi poder validar // los registros duplicados. // Al final se consulta la tabla INVENTARIO_PROC y estos son los contenedores que nos indican // que en realidad esta fisicamente en PATIO. $sql = "select e.id_naviera as ID_NAVIERA, e.id_contenedor as ID_CONTE, c.numero as CONTE, q.equipo as EQUIPO, "; $sql .= "e.damage as DAMAGE,e.clase as CLASE, e.cap_fec as CAP_FEC,"; $sql .= "e.nota as NOTA, e.reforzado as REFORZADO, e.bloque as BLO, e.bahia as BAH, e.nivel as NIV "; $sql .= "from INVENTARIO e, CONTENEDOR c, EQUIPO q where "; if ($idNaviera != '-') { $sql .= "id_naviera='{$idNaviera}' and e.id_oficina='{$sesIdOficina}' and "; } $sql .= "e.id_contenedor=c.id_contenedor and c.id_equipo=q.id_equipo and "; $sql .= "c.ent_sal<>'S' and st_reg<>'B' and e.ent_sal='E' "; $sql .= " order by e.id_naviera,e.cap_fec desc "; $db->query($sql); while ($db->next_record()) { // Reconocer los campos para el Inventario. $idNav = $db->f(ID_NAVIERA); $idConte = $db->f(ID_CONTE); $equipo = $db->f(EQUIPO); $equipo1 = substr($equipo, 0, 2); $equipo2 = substr($equipo, 2, 3); $damage = $db->f(DAMAGE); $clase = $db->f(CLASE); $capFec = $db->f(CAP_FEC); $nota = $db->f(NOTA); $reforzado = $db->f(REFORZADO); $bloque = $db->f(BLO); $bahia = $db->f(BAH); $nivel = $db->f(NIV); // GRABAR AL INVENTARIO_PROC REGISTROS NO DUPLICADOS // --------------------------------------------- // comprobar que no exista el registro en el Inventario, // si existe el registro, entonces esta duplicado el registro. $sql2 = "select id_inventario_proc from INVENTARIO_PROC where "; $sql2 .= "id_contenedor='{$idConte}' and id_naviera='{$idNav}'"; $db2->query($sql2); $nr2 = $db2->num_rows(); if ($nr2 == 0) { // Entonces grabar sin duplicados. $sql3 = "insert into INVENTARIO_PROC ("; $sql3 .= "cap_fec,id_contenedor,id_naviera,equipo1,equipo2,damage,clase,nota,reforzado,"; $sql3 .= "bloque,bahia,nivel,id_oficina"; $sql3 .= ") values ("; $sql3 .= "'{$capFec}','{$idConte}','{$idNav}','{$equipo1}','{$equipo2}','{$damage}','{$clase}','{$nota}','{$reforzado}',"; $sql3 .= "'{$bloque}','{$bahia}','{$nivel}','{$sesIdOficina}'"; $sql3 .= ")"; $db3->query($sql3); } } // --------------------------------------------------------- // CONSULTAR INVENTARIO_PROC // --------------------------------------------------------- $lin = 1; $sql = "select * from INVENTARIO_PROC where id_oficina='{$sesIdOficina}' order by id_naviera,cap_fec"; $db->query($sql); while ($db->next_record()) { // Calcular los dias en el Patio. $capFec = $db->f(cap_fec); $capFecM = getFecha($capFec, 'mes'); $capFecD = getFecha($capFec, 'dia'); $capFecA = getFecha($capFec, 'ano'); $hoyM = date('m'); $hoyD = date('d'); $hoyA = date('Y'); $capFecMK = mktime(0, 0, 0, $capFecM, $capFecD, $capFecA); $hoyMK = mktime(0, 0, 0, $hoyM, $hoyD, $hoyA); $diasTrans = totalDias($capFecMK, $hoyMK); $idConte = $db->f(id_contenedor); $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $idNaviera = $db->f(id_naviera); $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNaviera); $equipo1 = $db->f(equipo1); $equipo2 = $db->f(equipo2); $damage = $db->f(damage); $clase = $db->f(clase); $nota = $db->f(nota); $reforzado = $db->f(reforzado); $bloque = $db->f(bloque); $bahia = $db->f(bahia); $nivel = $db->f(nivel); $nota = str_replace("\n", "", $nota); $nota = str_replace("\r", "", $nota); // Escribiendo al archivo. $row = $lin . $sepa . $naviera . $sepa . $conte . $sepa . $equipo1 . $sepa . $equipo2 . $sepa . $damage . $sepa; $row .= $clase . $sepa . $capFec . $sepa . $nota . $sepa . $reforzado . $sepa . $diasTrans . $sepa; $row .= $bloque . $sepa . $bahia . $sepa . $nivel . $sepa; $row .= "\n"; fputs($fp, $row); $lin++; } fclose($fp); // ----------------------------- // SALVAR COMO... O ABRIR EN AUTO. // (No modificar) // ----------------------------- if (file_exists("{$archivo}")) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($archivo)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($archivo)); ob_clean(); flush(); readfile("{$archivo}"); exit; } }
function reporteEnt($idNaviera) { global $hoy, $db, $db2; // connection with the database $dbhost = "localhost"; $dbuser = "******"; $dbpass = "******"; $dbname = "nesoftwa_ANAKOSTA"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); $hr = substr($hoy, 11, 2); //$hr="17"; if ($idNaviera == 1) { //------------------------------------------- //SI ES MSC Y LA HR DEL REPORTE ES A LA 9 AM //INCLUIRA ENTRADAS Y SALIDAS DE LAS 5PM DEL //DIA ANTERIOR A LAS 9:00 AM DE ESTE DIA //------------------------------------------- if ($hr == "09") { $hr1 = "17:00:00"; $hr2 = "09:00:00"; $hoy = substr($hoy, 0, 10); //$hoy="2013-07-29"; $dias = 1; $ayer = date("Y-m-d", strtotime("{$hoy} -{$dias} day")); } else { if ($hr == "13") { $hr1 = "09:00:00"; $hr2 = "13:00:00"; $hoy = substr($hoy, 0, 10); $ayer = substr($hoy, 0, 10); } else { if ($hr == "17") { $hr1 = "13:00:00"; $hr2 = "17:00:00"; $hoy = substr($hoy, 0, 10); $ayer = substr($hoy, 0, 10); } else { $hoy = substr($hoy, 0, 10); //$hoy="2013-07-29"; $dias = 1; $ayer = date("Y-m-d", strtotime("{$hoy} -{$dias} day")); $hr1 = "00:00:00"; $hr2 = "23:59:59"; } } } } else { $hoy = substr($hoy, 0, 10); //$hoy="2013-07-29"; $dias = 1; $ayer = date("Y-m-d", strtotime("{$hoy} -{$dias} day")); } $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNaviera); // Create a new PHPExcel object $objPHPExcel = new PHPExcel(); $positionInExcel = 0; //Loque mencionaste $objPHPExcel->createSheet($positionInExcel); //Loque mencionaste $objPHPExcel->setActiveSheetIndex(0); //Seleccionar la pestaña deseada $objPHPExcel->getActiveSheet()->setTitle('Entradas'); //Establecer nombre para la pestaña $styleArray = array('font' => array('bold' => true, 'color' => array('rgb' => '010006'), 'size' => 13, 'name' => 'Calibri')); //--------------------- //*****ENTRADAS***** //--------------------- // Encabezados /* $headings = array('FECHA','CONTENEDOR','TIPO','CLASE', 'REFORZADO','FEC.FABRICACION','STATUS','EIR','NAVIERA', 'CONSIG','LIN. TRANSP.','OPERADOR','PLACAS','NO. CHASIS'); */ $headings = array('CONTENEDOR', 'FECHA', 'CLASE', 'STATUS', 'TIPO', 'REFORZADO', 'FEC.FABRICACION', 'EIR', 'NAVIERA', 'CONSIG', 'LIN. TRANSP.', 'OPERADOR', 'PLACAS', 'NO. CHASIS'); // ----------------------------------- // DATOS SI ES MSC // ----------------------------------- if ($idNaviera == 1) { $query = "SELECT * from ENTRADA where "; $query .= "id_naviera='{$idNaviera}' and "; $query .= "st_reg<>'B' and "; $query .= "cap_fec BETWEEN '{$ayer} {$hr1}' and '{$hoy} {$hr2}' order by cap_fec "; } else { $query = "SELECT * from ENTRADA where "; $query .= "id_naviera='{$idNaviera}' and "; $query .= "st_reg<>'B' and "; $query .= "cap_fec BETWEEN '{$ayer} 00:00:00' and '{$hoy} 23:59:59' order by cap_fec "; } if ($result = mysql_query($query) or die(mysql_error())) { //echo"SQL $sql"; //if ($result = mysql_query($query) or die(mysql_error())) { // Escribe los encabezados $objPHPExcel->getActiveSheet()->setCellValue(A1, "ALMARTCON, S.A. de C.V.")->getStyle('A1')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A2, "NAVIERA : {$naviera}")->getStyle('A2')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A3, "FECHA:{$ayer} A {$hoy}")->getStyle('A3')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A4, "ENTRADAS")->getStyle('A4')->applyFromArray($styleArray); $rowNumber = 5; $col = 'A'; foreach ($headings as $heading) { if ($col != "A" && $col != "F") { $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setAutoSize(true); } $objPHPExcel->getActiveSheet()->getStyle($col . $rowNumber)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => '999999'))); $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading); $col++; } // Escribe los Registros $rowNumber = 5; while ($row = mysql_fetch_array($result)) { $idConte = $row[id_contenedor]; $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $ref = getValueTable("reforzado", "CONTENEDOR", "id_contenedor", $idConte); $fecFab = getValueTable("fec_fab", "CONTENEDOR", "id_contenedor", $idConte); $idEq = getValueTable("id_equipo", "CONTENEDOR", "id_contenedor", $idConte); $equipo = getValueTable("equipo", "EQUIPO", "id_equipo", $idEq); $idNav = $row[id_naviera]; $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNav); $objPHPExcel->getActiveSheet()->setCellValue(A . $rowNumber, $conte); $objPHPExcel->getActiveSheet()->setCellValue(B . $rowNumber, $row[cap_fec]); $objPHPExcel->getActiveSheet()->setCellValue(C . $rowNumber, $row[clase]); $objPHPExcel->getActiveSheet()->setCellValue(D . $rowNumber, $row[damage]); $objPHPExcel->getActiveSheet()->setCellValue(E . $rowNumber, $equipo); $objPHPExcel->getActiveSheet()->setCellValue(F . $rowNumber, $ref); $objPHPExcel->getActiveSheet()->setCellValue(G . $rowNumber, $fecFab); $objPHPExcel->getActiveSheet()->setCellValue(H . $rowNumber, $row[eir]); $objPHPExcel->getActiveSheet()->setCellValue(I . $rowNumber, $naviera); $objPHPExcel->getActiveSheet()->setCellValue(J . $rowNumber, $row[consig]); $objPHPExcel->getActiveSheet()->setCellValue(K . $rowNumber, $row[transportista]); $objPHPExcel->getActiveSheet()->setCellValue(L . $rowNumber, $row[operador]); $objPHPExcel->getActiveSheet()->setCellValue(M . $rowNumber, $row[placas]); $objPHPExcel->getActiveSheet()->setCellValue(N . $rowNumber, $row[chasis]); $rowNumber++; } } //--------------------- //*****SALIDAS***** //--------------------- $positionInExcel = 1; //Loque mencionaste $objPHPExcel->createSheet($positionInExcel); //Loque mencionaste $objPHPExcel->setActiveSheetIndex(1); //Seleccionar la pestaña deseada $objPHPExcel->getActiveSheet()->setTitle('Salidas'); //Establecer nombre para la pestaña // Encabezados $headings = array('CONTENEDOR', 'FECHA', 'BOOKING', 'TIPO', 'CLASE', 'REFORZADO', 'FEC. FABRICACIÓN', 'STATUS', 'EIR', 'NAVIERA', 'CONSIG', 'LIN. TRANSP.', 'OPERADOR', 'PLACAS', 'NO. CHASIS', 'SELLO', 'FACTURA'); // ----------------------------------- // DATOS SI ES MSC // ----------------------------------- if ($idNaviera == 1) { $query = "SELECT * from SALIDA where "; $query .= "id_naviera='{$idNaviera}' and "; $query .= "st_reg<>'B' and "; $query .= "cap_fec BETWEEN '{$ayer} {$hr1}' and '{$hoy} {$hr2}' order by cap_fec "; } else { $query = "SELECT * from SALIDA where "; $query .= "id_naviera='{$idNaviera}' and "; $query .= "st_reg<>'B' and "; $query .= "cap_fec BETWEEN '{$ayer} 00:00:00' and '{$hoy} 23:59:59' order by cap_fec "; } //if ($result = mysql_query($query) or die(mysql_error())) { //echo"SQL $sql"; if ($result = mysql_query($query) or die(mysql_error())) { // Escribe los encabezados $objPHPExcel->getActiveSheet()->setCellValue(A1, "ALMARTCON, S.A. de C.V.")->getStyle('A1')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A2, "NAVIERA : {$naviera}")->getStyle('A2')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A3, "FECHA:{$ayer} A {$hoy}")->getStyle('A3')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A4, "SALIDAS")->getStyle('A4')->applyFromArray($styleArray); $rowNumber = 5; $col = 'A'; foreach ($headings as $heading) { if ($col != "A" && $col != "F") { $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setAutoSize(true); } $objPHPExcel->getActiveSheet()->getStyle($col . $rowNumber)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => '999999'))); $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading); $col++; } // Escribe los Registros $rowNumber = 6; while ($row = mysql_fetch_array($result)) { $idConte = $row[id_contenedor]; $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $ref = getValueTable("reforzado", "CONTENEDOR", "id_contenedor", $idConte); $fecFab = getValueTable("fec_fab", "CONTENEDOR", "id_contenedor", $idConte); $idEq = getValueTable("id_equipo", "CONTENEDOR", "id_contenedor", $idConte); $equipo = getValueTable("equipo", "EQUIPO", "id_equipo", $idEq); $idNav = $row[id_naviera]; $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNav); $objPHPExcel->getActiveSheet()->setCellValue(A . $rowNumber, $conte); $objPHPExcel->getActiveSheet()->setCellValue(B . $rowNumber, $row[cap_fec]); $objPHPExcel->getActiveSheet()->setCellValue(C . $rowNumber, $row[bkg]); $objPHPExcel->getActiveSheet()->setCellValue(D . $rowNumber, $equipo); $objPHPExcel->getActiveSheet()->setCellValue(E . $rowNumber, $row[clase]); $objPHPExcel->getActiveSheet()->setCellValue(F . $rowNumber, $ref); $objPHPExcel->getActiveSheet()->setCellValue(G . $rowNumber, $fecFab); $objPHPExcel->getActiveSheet()->setCellValue(H . $rowNumber, $row[damage]); $objPHPExcel->getActiveSheet()->setCellValue(I . $rowNumber, $row[eir]); $objPHPExcel->getActiveSheet()->setCellValue(J . $rowNumber, $naviera); $objPHPExcel->getActiveSheet()->setCellValue(K . $rowNumber, $row[consig]); $objPHPExcel->getActiveSheet()->setCellValue(L . $rowNumber, $row[transportista]); $objPHPExcel->getActiveSheet()->setCellValue(M . $rowNumber, $row[operador]); $objPHPExcel->getActiveSheet()->setCellValue(N . $rowNumber, $row[placas]); $objPHPExcel->getActiveSheet()->setCellValue(O . $rowNumber, $row[chasis]); $objPHPExcel->getActiveSheet()->setCellValue(P . $rowNumber, $row[sello]); $objPHPExcel->getActiveSheet()->setCellValue(Q . $rowNumber, $row[factura]); $rowNumber++; } } //--------------------- //*****INVENTARIOS***** //--------------------- // ----------------------------------- // DEPURACION // ----------------------------------- /* $sql = "SELECT id_contenedor from INVENTARIO_PLUS "; $db->query($sql); while( $db->next_record() ){ $idConte = $db->f(id_contenedor); actualizaInventarioPlus($idConte); } */ $positionInExcel = 2; $objPHPExcel->createSheet($positionInExcel); $objPHPExcel->setActiveSheetIndex(2); //Seleccionar la pestaña deseada $objPHPExcel->getActiveSheet()->setTitle('Inventarios'); //Establecer nombre para la pestaña // Encabezados $headings = array('CONTENEDOR', 'TIPO', 'FEC. ENTRADA', 'STATUS', 'CLASE', 'DIAS', 'REFORZADOS', 'EIR', 'NOTAS'); // Escribe los encabezados $objPHPExcel->getActiveSheet()->setCellValue(A1, "ALMARTCON, S.A. de C.V.")->getStyle('A1')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A2, "NAVIERA : {$naviera}")->getStyle('A2')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A3, "FECHA:{$ayer} A {$hoy}")->getStyle('A3')->applyFromArray($styleArray); $objPHPExcel->getActiveSheet()->setCellValue(A4, "INVENTARIO")->getStyle('A4')->applyFromArray($styleArray); $rowNumber = 5; $col = 'A'; foreach ($headings as $heading) { if ($col != "A" && $col != "F") { $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setAutoSize(true); } $objPHPExcel->getActiveSheet()->getStyle($col . $rowNumber)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => '999999'))); $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading); $col++; } // ----------------------------------- // DATOS // ----------------------------------- $rowNumber = 6; $query = "SELECT * from EQUIPO "; if ($result = mysql_query($query) or die(mysql_error())) { while ($row = mysql_fetch_array($result)) { $idEquipo = $row[id_equipo]; $flgEquipo = "0"; $cont = ""; $query2 = "SELECT * from INVENTARIO_PLUS i, CONTENEDOR c where "; $query2 .= "i.id_naviera='{$idNaviera}' and i.id_contenedor>0 and "; $query2 .= "i.id_contenedor=c.id_contenedor and c.id_equipo='{$idEquipo}'"; if ($result2 = mysql_query($query2) or die(mysql_error())) { while ($row2 = mysql_fetch_array($result2)) { $flgEquipo = "1"; $capFec = $row2[cap_fec]; $idConte = $row2[id_contenedor]; $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $idEq = getValueTable("id_equipo", "CONTENEDOR", "id_contenedor", $idConte); $equipo = getValueTable("equipo", "EQUIPO", "id_equipo", $idEq); $nota = $row2[nota]; $nota = addslashes($nota); $nota = str_replace("\n", "", $nota); $nota = str_replace("\r", "", $nota); $eir = "E-" . $row2[eir]; // Comprobar que el contenedor, mismo registro no este dado de baja en Entradas en su mas reciente evento. $sql2 = "select st_reg from ENTRADA where id_contenedor='{$idConte}' order by cap_fec"; $db2->query($sql2); while ($db2->next_record()) { $stReg = $db2->f(st_reg); } if (empty($stReg)) { $stReg = "A"; // Activo } // Escribiendo al archivo. if ($stReg != "B" && $conteEntSal != "S") { $datoX = getLastIn($idConte); $fecEnt = $datoX['fecEnt']; $eir = $datoX['eir']; $damage = getDamage($idConte); $reforzado = getReforzado($idConte); $clase = getValueTable("clase", "CONTENEDOR", "id_contenedor", $idConte); // Calcular los días de almacenaje. $hoy = date("Y-m-d"); $dias = totalDias($fecEnt, $hoy); $objPHPExcel->getActiveSheet()->setCellValue(A . $rowNumber, $conte); $objPHPExcel->getActiveSheet()->setCellValue(B . $rowNumber, $equipo); $objPHPExcel->getActiveSheet()->setCellValue(C . $rowNumber, $fecEnt); $objPHPExcel->getActiveSheet()->setCellValue(D . $rowNumber, $damage); $objPHPExcel->getActiveSheet()->setCellValue(E . $rowNumber, $clase); $objPHPExcel->getActiveSheet()->setCellValue(F . $rowNumber, $dias); $objPHPExcel->getActiveSheet()->setCellValue(G . $rowNumber, $eir); $objPHPExcel->getActiveSheet()->setCellValue(H . $rowNumber, $reforzado); $objPHPExcel->getActiveSheet()->setCellValue(I . $rowNumber, $nota); $rowNumber++; $cont = $cont + 1; } } } if ($flgEquipo == 1) { $objPHPExcel->getActiveSheet()->setCellValue(B . $rowNumber, $cont); $rowNumber++; } } } //echo 'a problem has occurred... no data retrieved from the database'; // Freeze pane so that the heading line won't scroll $objPHPExcel->getActiveSheet()->freezePane('A2'); // Save as an Excel BIFF (xls) file $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); //header('Content-Type: application/vnd.ms-excel'); //header('Content-Disposition: attachment;filename=../files/reporte.xls'); //header('Cache-Control: max-age=0'); //$objWriter->save('php://output'); $objWriter->save('../files/EntradasNav.xlsx'); //exit(); return; }
function reporteNewExcel($idNaviera, $fec1, $fec2) { // connection with the database $dbhost = "localhost"; $dbuser = "******"; $dbpass = "******"; $dbname = "nesoftwa_ANAKOSTA"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); // require the PHPExcel file require '../Classes/PHPExcel.php'; // simple query $sql = "SELECT cap_fec,id_contenedor,clase,transportista,id_entrada,mani_st_pago "; $sql .= " from ENTRADA where "; if ($idNaviera != '-') { $sql .= "id_naviera='{$idNaviera}' and "; } $sql .= "ent_sal='E' and cap_fec BETWEEN '{$fec1} 00:00:00' and '{$fec2} 23:59:59' order by id_naviera,cap_fec "; // Encabezados $headings = array('Fec.Ingreso', 'Contenedor', 'Tipo', 'Calidad', 'Condiciones', 'Transportista', 'No.EIR', 'Maniobra por cuenta de'); if ($result = mysql_query($sql) or die(mysql_error())) { // Create a new PHPExcel object $objPHPExcel = new PHPExcel(); $objPHPExcel->getActiveSheet()->setTitle('ENTRADAS'); // Escribe los encabezados $rowNumber = 1; $col = 'A'; foreach ($headings as $heading) { $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading); $col++; } // Escribe los Registros $rowNumber = 2; while ($row = mysql_fetch_row($result)) { $capFec = $row[0]; $idConte = $row[1]; $clase = $row[2]; $transp = $row[3]; $eir = $row[4]; $maniStPago = $row[5]; $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $idEq = getValueTable("id_equipo", "CONTENEDOR", "id_contenedor", $idConte); $equipo = getValueTable("equipo", "EQUIPO", "id_equipo", $idEq); $maniStPago == "M" ? $maniStPago = "MERCHANT" : ($maniStPago = "CARRIER"); $rowF[0] = $capFec; $rowF[1] = $conte; $rowF[2] = $equipo; $rowF[3] = $clase; $rowF[4] = $claseCondi; $rowF[5] = $transp; $rowF[6] = $eir; $rowF[7] = $maniStPago; $col = 'A'; foreach ($rowF as $cell) { $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $cell); $col++; } $rowNumber++; } // Freeze pane so that the heading line won't scroll $objPHPExcel->getActiveSheet()->freezePane('A2'); } // ------------------------------------------------------------ // Nueva HOJA 2 Salidas // ------------------------------------------------------------ $objPHPExcel->createSheet(); $objPHPExcel->setActiveSheetIndex(1); //$objPHPExcel->getActiveSheet(1); $objPHPExcel->getActiveSheet()->setTitle('SALIDAS'); // simple query $sql = "SELECT cap_fec,id_contenedor,bkg,consig,transportista,clase,id_entrada,sello,mani_st_pago "; $sql .= "from ENTRADA where "; if ($idNaviera != '-') { $sql .= "id_naviera='{$idNaviera}' and "; } $sql .= "ent_sal='S' and "; $sql .= "cap_fec BETWEEN '{$fec1} 00:00:00' and '{$fec2} 23:59:59' order by id_naviera,cap_fec"; // Encabezados $headings = array('Fec.Salida', 'Contenedor', 'Tipo', 'Booking', 'Cliente', 'Transportista', 'Calidad', 'No.EIR', 'Sello-Salida', 'Maniobra por cuenta de'); if ($result = mysql_query($sql) or die(mysql_error())) { // Escribe los encabezados $rowNumber = 1; $col = 'A'; foreach ($headings as $heading) { $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading); $col++; } // Escribe los Registros $rowNumber = 2; while ($row = mysql_fetch_row($result)) { // Contenedor $capFec = $row[0]; $idConte = $row[1]; $bkg = $row[2]; $consig = $row[3]; $transp = $row[4]; $clase = $row[5]; $eir = $row[6]; $sello = $row[7]; $maniStPago = $row[8]; $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $idEq = getValueTable("id_equipo", "CONTENEDOR", "id_contenedor", $idConte); $equipo = getValueTable("equipo", "EQUIPO", "id_equipo", $idEq); $maniStPago == "M" ? $maniStPago = "MERCHANT" : ($maniStPago = "CARRIER"); $rowF[0] = $capFec; $rowF[1] = $conte; $rowF[2] = $equipo; $rowF[3] = $bkg; $rowF[4] = $consig; $rowF[5] = $transp; $rowF[6] = $clase; $rowF[7] = $eir; $rowF[8] = $sello; $rowF[9] = $maniStPago; $col = 'A'; foreach ($rowF as $cell) { $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $cell); $col++; } $rowNumber++; } // Freeze pane so that the heading line won't scroll $objPHPExcel->getActiveSheet()->freezePane('A2'); } // ---------------------------------------------------------------------------- // Nueva HOJA 3 INVENTARIO // ---------------------------------------------------------------------------- // 1. Se crean registros en tabla INVENTARIO donde se eliminan los duplicados. // 2. Es importante dejar esta opcion en el query de consulta : // --> e.cap_fec desc <---- // El primer registro con fecha mayor sera el que pasar a la tabla INVENTARIO // ---------------------------------------------------------------------------- global $db, $db2, $db3, $hoy, $hoyF; // Limpiar inventario. $sql = "truncate INVENTARIO "; $db->query($sql); $sql = "select e.id_naviera as ID_NAVIERA, e.id_contenedor as ID_CONTE, c.numero as CONTE, q.equipo as EQUIPO, "; $sql .= "e.damage as DAMAGE,e.clase as CLASE, e.cap_fec as CAP_FEC,"; $sql .= "e.nota as NOTA, e.reforzado as REFORZADO "; $sql .= "from ENTRADA e, CONTENEDOR c, EQUIPO q where "; if ($idNaviera != '-') { $sql .= "id_naviera='{$idNaviera}' and "; } $sql .= "e.id_contenedor=c.id_contenedor and c.id_equipo=q.id_equipo and "; $sql .= "c.ent_sal<>'S' and e.ent_sal='E' "; $sql .= " order by e.id_naviera,e.cap_fec desc "; $db->query($sql); while ($db->next_record()) { // Reconocer los campos para el Inventario. $idNav = $db->f(ID_NAVIERA); $idConte = $db->f(ID_CONTE); $equipo = $db->f(EQUIPO); $equipo1 = substr($equipo, 0, 2); $equipo2 = substr($equipo, 2, 3); $damage = $db->f(DAMAGE); $clase = $db->f(CLASE); $capFec = $db->f(CAP_FEC); $nota = $db->f(NOTA); $reforzado = $db->f(REFORZADO); // GRABAR AL INVENTARIO REGISTROS NO DUPLICADOS // --------------------------------------------- // comprobar que no exista el registro en el Inventario ENTRADA_I, // si existe el registro, entonces esta duplicado el registro. $sql2 = "select id_inventario from INVENTARIO where "; $sql2 .= "id_contenedor='{$idConte}' and id_naviera='{$idNav}'"; $db2->query($sql2); $nr2 = $db2->num_rows(); if ($nr2 == 0) { // Entonces grabar sin duplicados. $sql3 = "insert into INVENTARIO ("; $sql3 .= "cap_fec,id_contenedor,id_naviera,equipo1,equipo2,damage,clase,nota,reforzado"; $sql3 .= ") values ("; $sql3 .= "'{$capFec}','{$idConte}','{$idNav}','{$equipo1}','{$equipo2}','{$damage}','{$clase}','{$nota}','{$reforzado}'"; $sql3 .= ")"; $db3->query($sql3); } } // --------------------------------------------------------- // CONSULTAR INVENTARIO, coloca los datos en la Hoja 3 // --------------------------------------------------------- unset($row); unset($rowF); $objPHPExcel->createSheet(); $objPHPExcel->setActiveSheetIndex(2); //$objPHPExcel->getActiveSheet(1); $objPHPExcel->getActiveSheet()->setTitle('INVENTARIO'); // Encabezados // ------------ $headings = array('No.Linea', 'Naviera', 'Contenedor', 'Size', 'Tipo', 'Status', 'Calidad', 'F.Entrada', 'Nota', 'Reforzado', 'Dias-Trans'); // Escribe los encabezados $rowNumber = 1; $col = 'A'; foreach ($headings as $heading) { $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading); $col++; } $sql = "select cap_fec,id_contenedor,id_naviera,equipo1,equipo2,damage,clase,nota,reforzado "; $sql .= "from INVENTARIO order by id_naviera,cap_fec"; if ($result = mysql_query($sql) or die(mysql_error())) { // Escribe los Registros $rowNumber = 2; while ($row = mysql_fetch_row($result)) { // Contenedor $capFec = $row[0]; // Calcular los dias en el Patio. $capFecM = getFecha($capFec, 'mes'); $capFecD = getFecha($capFec, 'dia'); $capFecA = getFecha($capFec, 'ano'); $hoyM = date('m'); $hoyD = date('d'); $hoyA = date('Y'); $capFecMK = mktime(0, 0, 0, $capFecM, $capFecD, $capFecA); $hoyMK = mktime(0, 0, 0, $hoyM, $hoyD, $hoyA); $diasTrans = totalDias($capFecMK, $hoyMK); $idConte = $row[1]; $conte = getValueTable("numero", "CONTENEDOR", "id_contenedor", $idConte); $idNaviera = $row[2]; $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNaviera); $equipo1 = $row[3]; $equipo2 = $row[4]; $damage = $row[5]; $clase = $row[6]; $nota = $row[7]; $reforzado = $row[8]; $rowF[0] = $rowNumber - 1; $rowF[1] = $naviera; $rowF[2] = $conte; $rowF[3] = $equipo1; $rowF[4] = $equipo2; $rowF[5] = $damage; $rowF[6] = $clase; $rowF[7] = $capFec; $rowF[8] = $nota; $rowF[9] = $reforzado; $rowF[10] = $diasTrans; $col = 'A'; foreach ($rowF as $cell) { $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $cell); $col++; } $rowNumber++; } // Freeze pane so that the heading line won't scroll $objPHPExcel->getActiveSheet()->freezePane('A2'); } // ------------------------------------- // Save as an Excel BIFF (xls) file // ------------------------------------- // Opcion1 EXCEL 5 /* header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename=reporte.xls'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); */ // Opcion2 EXCEL 2007 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="reporte.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; //} //echo 'a problem has occurred... no data retrieved from the database'; }
function calcularDemora($idCalculo, $fechaVacio = "", $tipoCalculo, $libDias = "") { /* Esta funcion es la maestra para realizar el calculo de tipo "parcial" y "total" segun se le especifique en los parametros. */ global $dbZ, $mscIdUsuario, $hoy; // Debe actualizar el calculo. // Traemos informacion del registro y se arma un arreglo data. $data = getData($idCalculo); $idCliente = $data[idCliente]; $idGrupo = $data[idGrupo]; $idBl = $data[idBl]; $idConte = $data[idConte]; $idEquipo = $data[idEquipo]; $tipoEq = $data[tipoEq]; $iniLib = $data[iniLibre]; $idRegion = $data[idRegion]; $pol = $data[loading]; $pod = $data[discharge]; $eta = $data[eta]; $sDate = $data[sDate]; // Es para comprobar que exista el Bl y el Contenedor en la base de datos. // Att. Nestor 20120802 if ($idBl > 0 && $idConte > 0) { // Si la fecha de vacio es menor a la fecha de ini.demora // no debera realizar calculos. $flgErrFV = 0; if (!empty($fechaVacio)) { // Timstamp para Fecha de vacio $fvDia = getFecha($fechaVacio, 'dia'); $fvMes = getFecha($fechaVacio, 'mes'); $fvAno = getFecha($fechaVacio, 'ano'); $mFV = mktime(0, 0, 0, $fvMes, $fvDia, $fvAno); // Timestamp para inicio dias libres $ilDia = getFecha($iniLib, 'dia'); $ilMes = getFecha($iniLib, 'mes'); $ilAno = getFecha($iniLib, 'ano'); $mIL = mktime(0, 0, 0, $ilMes, $ilDia, $ilAno); if ($mFV < $mIL) { $flgErrFV = 1; } } // Si la bandera $flErrFV == 0 es que esta ok y procede a calcular. if ($flgErrFV == 0) { // Conocer los dias libres del cliente de acuerdo // al origen/carga del Bl. // Cuando el usr. no aplica dias libres al gusto se tiene que // ejecutar esta funcion. //echo "idRegion= $idRegion <br> "; //echo "libDias!!= $libDias <br> "; // Si el usuario NO ha aplicado cambios manualmente con los dias libres, // el sistema debe reconocer los dias libres. //echo "libDias: $libDias "; if (empty($libDias)) { // pendiente ver si meto las fechas de los acuerdos como paramentros p la funcion. // $libDiasCli = libreDiasPls ( $idCliente, $idGrupo, $idRegion, $tipoEq, $iniLib, $eta,$idCalculo,$pol ); if ($sDate == "0000-00-00") { $sDate = $eta; } $libDiasCli = libreDiasPls($idCliente, $idGrupo, $idRegion, $tipoEq, $iniLib, $sDate, $pol, $pod); // --------------------------------------------- // SHIPPER CON ACUERDOS EN DIAS LIBRES. // --------------------------------------------- $shipper = getValueTable("shipper", "D_CALCULO", "id_calculo", $idCalculo); $shipper = str_replace("'", "", $shipper); $shipper = strtoupper($shipper); if (!empty($shipper)) { // SHIPPER NAME $idShipper = getValueTable("id_shipper", "D_SHIPPER", "shipper", $shipper); if ($idShipper > 0) { $libDiasSh = libreDiasPlsShipper($idShipper, $idRegion, $tipoEq, $iniLib, $sDate, $idCalculo, $pol, $pod); } } // 20131202 // Prioridad el Shipper, pero si no entonces buscar // Ref. Number y buscar el shipper que tenga esta referencia. // De lo contrario brincar a Contract Holder y si no, Import Freight Forwader y si no, Freight Forwarder y si no, Company to invoice. // Detectar si la fecha de vacio entra en el rango de la vigencia. $refNum = getValueTable("ref_num", "D_CALCULO", "id_calculo", $idCalculo); $conHolCod = getValueTable("con_hol_cod", "D_CALCULO", "id_calculo", $idCalculo); $iffCod = getValueTable("iff_cod", "D_CALCULO", "id_calculo", $idCalculo); $frfCod = getValueTable("frf_cod", "D_CALCULO", "id_calculo", $idCalculo); $copInvCod = getValueTable("cop_inv_cod", "D_CALCULO", "id_calculo", $idCalculo); if ($idCalculo == 1461918) { /* echo " <pre> shipper: $shipper libDiasSh: $libDiasSh refNum : $refNum conHolCod : $conHolCod iffCod : $iffCod frfCod : $frfCod copInvCod : $copInvCod </pre> "; */ } if ($libDiasSh == 0 || empty($libDiasSh)) { // --------------------------- // Dias libres del SHIPPER // --------------------------- // REF NUM if (!empty($refNum)) { $idShipper = getValueTable("id_shipper", "D_SHIPPER", "msc_code", $refNum); if ($idShipper > 0) { if ($sDate == "0000-00-00") { $sDate = $eta; } $libDiasSh = libreDiasPlsShipper($idShipper, $idRegion, $tipoEq, $iniLib, $sDate, $idCalculo, $pol, $pod); // echo "REF NUM $libDiasSh - ETA $eta"."<BR>"; } } // CONTRACT HOLDER if (!empty($conHolCod) && ($libDiasSh == 0 || empty($libDiasSh))) { $idShipper = getValueTable("id_shipper", "D_SHIPPER", "msc_code", $conHolCod); if ($idShipper > 0) { if ($sDate == "0000-00-00") { $sDate = $eta; } $libDiasSh = libreDiasPlsShipper($idShipper, $idRegion, $tipoEq, $iniLib, $sDate, $idCalculo, $pol, $pod); // echo "CONTRACT HOLDER $libDiasSh - ETA $eta"."<BR>"; } } // Import Freight ForwarderMsc Code if (!empty($iffCod) && ($libDiasSh == 0 || empty($libDiasSh))) { $idShipper = getValueTable("id_shipper", "D_SHIPPER", "msc_code", $iffCod); if ($idShipper > 0) { if ($sDate == "0000-00-00") { $sDate = $eta; } $libDiasSh = libreDiasPlsShipper($idShipper, $idRegion, $tipoEq, $iniLib, $sDate, $idCalculo, $pol, $pod); // echo " Import Freight ForwarderMsc Code $libDiasSh - ETA $eta" ."<BR>"; } } // Freight Forwarder - Msc Code if (!empty($frfCod) && ($libDiasSh == 0 || empty($libDiasSh))) { $idShipper = getValueTable("id_shipper", "D_SHIPPER", "msc_code", $frfCod); if ($idShipper > 0) { if ($sDate == "0000-00-00") { $sDate = $eta; } $libDiasSh = libreDiasPlsShipper($idShipper, $idRegion, $tipoEq, $iniLib, $sDate, $idCalculo, $pol, $pod); // echo " Freight Forwarder - Msc Code $libDiasSh - ETA $eta"."<BR>"; } } // Company To invoice code if (!empty($copInvCod) && ($libDiasSh == 0 || empty($libDiasSh))) { $idShipper = getValueTable("id_shipper", "D_SHIPPER", "msc_code", $copInvCod); if ($idShipper > 0) { if ($sDate == "0000-00-00") { $sDate = $eta; } $libDiasSh = libreDiasPlsShipper($idShipper, $idRegion, $tipoEq, $iniLib, $sDate, $idCalculo, $pol, $pod); // echo " Company To invoice code $libDiasSh - ETA $eta"."<BR>"; } } /* // POR DEFAULT if( $libDiasSh <=0 || empty($libDiasSh) ){ $idShipper = getValueTable("id_shipper","D_SHIPPER","shipper",$shipper); if($idShipper>0){ $libDiasSh= libreDiasPlsShipper( $idShipper,$idRegion,$tipoEq,$iniLib,$sDate,$idCalculo,$pol,$pod,'SI' ); echo " POR DEFAULT $libDiasSh"."<BR>"; } } */ } // Si el SHIPPER tiene más dias libres que el cliente entonces aplica. // Regla dada por el Capitan Ciro Enero 2009. // Se aplican los dias libres que tengan mas dias. if ($libDiasSh > $libDiasCli && $idShipper > 0) { $libDias = $libDiasSh; $flgAcuShi = 1; } else { $libDias = $libDiasCli; $flgAcuShi = 0; } // -------------------------------------------------- // RELEASE FEE :: SHIPPER // Detecta si el Shipper tiene Exento de Release Fee. // Att. Nestor 2014-03-19 // -------------------------------------------------- if ($idShipper > 0) { $flgCngExento = getValueTable("rf_exento", "D_CLIENTE", "id_cliente", $idCliente); $flgShpExento = getValueTable("rf_exento", "D_SHIPPER", "id_shipper", $idShipper); if ($flgCngExento != "S" && $flgShpExento != "S") { // ------------------------------- // Aplicarlo para el 1 de Abril $hoyN = date("Y-m-d"); $hoyNM = getFecha($hoyN, mes); $hoyND = getFecha($hoyN, dia); $hoyNA = getFecha($hoyN, ano); $hoyNMKT = mktime(0, 0, 0, $hoyNM, $hoyND, $hoyNA); // fecha apartir de cuando aplica. $fecRF = date("2014-04-01"); $fecRFM = getFecha($fecRF, mes); $fecRFD = getFecha($fecRF, dia); $fecRFA = getFecha($fecRF, ano); $fecRFMKT = mktime(0, 0, 0, $fecRFM, $fecRFD, $fecRFA); if ($hoyNMKT >= $fecRFMKT) { $sqlZ = "update EXPO set release_fee_cc='34.80' where Id_expo='{$idBl}' "; $dbZ->query($sqlZ); } // ------------------------------- } } // ---------------------------------------------------------- // TERRESTRE INCLUIDO 3/5 DIAS +. // Si tiene terrestre incluido y sumar 3 dias en equipo seco. // ---------------------------------------------------------- if (existTerrestre($idBl)) { if ($tipoEq == "S") { if ($libDias == 7 || $libDias == 10) { // Nueva mod. segun Cap.Ciro Aiello. 2009-02-06 // Si la carga es Desc=MXZLO Dest.Final=MXMTY asignar 12 dias. $disc = getValueTable("Discharge", "EXPO", "Id_expo", $idBl); $dest = getValueTable("Destiny", "EXPO", "Id_expo", $idBl); if ($disc == "MXZLO" && $dest == "MXMTY") { //$libDias = $libDias + 5; //$libDias = 12; $libDias = 10; // Cambio solicitado por Agustin 2012-06-01 } else { //$libDias = $libDias + 3; // 3 dias mas para precarrier incluido. $libDias = 10; // 3 dias mas para precarrier incluido. } } } } // Actualizar los dias libres a la tabla D_CALCULO para buen funcionamiento. $sql = "update D_CALCULO set libre_dias='{$libDias}',flg_acu_shi='{$flgAcuShi}' "; $sql .= ",id_shipper='{$idShipper}' "; $sql .= "where id_calculo='{$idCalculo}'"; $dbZ->query($sql); } // ---------------------------------------------------------------- // TARIFAS // ---------------------------------------------------------------- if ($idGrupo > 0) { $tarifaTipo = getValueTable("tarifa_tipo", "D_GRUPO", "id_grupo", $idGrupo); } else { $tarifaTipo = getValueTable("tarifa_tipo", "D_CLIENTE", "id_cliente", $idCliente); } if ($tarifaTipo == 'E') { if ($idGrupo > 0) { // Conocer las tarifas esp por grupo especiales. // * Pertenece a grupo. // Conocer las tarifas especiales q tiene el cliente de acuerdo // a la fecha de los acuerdos vs fecha de arribo del barco. // si no coincide debe de darme la tarifa standard. $arrTar = getTariEsp($eta, 0, $idEquipo, $idGrupo); //if( is_array($arrTar) ){ $t1 = $arrTar[0]; $t2 = $arrTar[1]; //} //else{ // return $arrTar; //} /* Antiguo metodo. $sql="select tarifa1,tarifa2 from D_TARIFA_ESPECIAL where "; $sql.="id_grupo='$idGrupo' and id_equipo='$idEquipo' "; $dbZ->query($sql); while($dbZ->next_record()){ $t1=$dbZ->f(tarifa1); $t2=$dbZ->f(tarifa2); echo "tar1 gpo: $t1 <br>"; echo "tar2 gpo: $t2 <br>"; } */ } else { // * No pertenece a grupo. // Conocer las tarifas especiales q tiene el cliente de acuerdo // a la fecha de los acuerdos vs fecha de arribo del barco. // si no coincide debe de darme la tarifa standard. $arrTar = getTariEsp($eta, $idCliente, $idEquipo); $t1 = $arrTar[0]; $t2 = $arrTar[1]; } } else { // Comprobar contra la tabla D_TARIFA_CTRL para saber // que tarifas se van a aplicar por los acuerdos o cambios en tarifas. $tabTari = getTabTari($iniLib); //if(!empty($tabTari)){ $t1 = getValueTable("tarifa1", "{$tabTari}", "id_equipo", $idEquipo); $t2 = getValueTable("tarifa2", "{$tabTari}", "id_equipo", $idEquipo); //}else{ // $errorData = "ERROR: VERIFICAR LA FECHA DE INICIO DE DIAS LIBREAS"; //return $errorData; //} //echo "AQUI $idEquipo <br>"; } // si se forso el mov. para cambiar tarifas entonces... $flgModTar = getValueTable("flg_mod_tar", "D_CALCULO", "id_calculo", $idCalculo); //if($tipoCalculo=='P'){ if ($flgModTar == 1) { $t1 = getValueTable("costo_tar1", "D_CALCULO", "id_calculo", $idCalculo); $t2 = getValueTable("costo_tar2", "D_CALCULO", "id_calculo", $idCalculo); } // ------------------------------------------------------------- // Rutina de ultima hora. // Aut. Nestor / 20041109 // Nota: Si el cliente es VOLKSVAWEN DE MEXICO // Y la region es por Africa debe asignar $5 dll // para contenedores no reefers. Autorizo Armando Jaime. // -------------------------------------------------------------- if ($idCliente == 1036) { if ($idRegion == 1) { // Africa if ($tipoEq == 'S') { $t1 = 10; $t2 = 10; } } } // SHIPPER OWN - TARIFA CERO $idBlConte = getValueTable("id_bl_conte", "D_CALCULO", "id_calculo", $idCalculo); $idConte = getValueTable("id_contenedor", "BL_CONTE", "id_bl_conte", $idBlConte); $soc = getValueTable("soc", "CONTENEDOR", "id_contenedor", $idConte); if ($soc == 1) { $t1 = 0; $t2 = 0; $tipoCalculo = "T"; } //-------------------------------------------------------------- // DIAS DE DEMORAS // Conocer los dias de demora. // ------------------------------------------------------------- $iniLibDia = getFecha($iniLib, dia); $iniLibMes = getFecha($iniLib, mes); $iniLibAno = getFecha($iniLib, ano); $mktLibF1 = mktime(0, 0, 0, $iniLibMes, $iniLibDia, $iniLibAno); $libF1 = date("Y-m-d", $mktLibF1); //echo "------------------------------------<br>"; $mktLibF2 = mktime(0, 0, 0, $iniLibMes, $iniLibDia + ($libDias - 1), $iniLibAno); $libF2 = date("Y-m-d", $mktLibF2); // SHIPPER OWN - TARIFA CERO - FECHA DE VACIO = F.INICIO if ($soc == 1) { $fechaVacio = $iniLib; } $vacioMes = getFecha($fechaVacio, mes); $vacioDia = getFecha($fechaVacio, dia); $vacioAno = getFecha($fechaVacio, ano); //echo "$vacioAno / $vacioMes / $vacioDia <br>"; $mkVacio = mktime(0, 0, 0, $vacioMes, $vacioDia, $vacioAno); $vacio = date("Y-m-d", $mkVacio); $diasDemora = totalDias($mktLibF2, $mkVacio); //echo "diasDemora: $diasDemora <br>"; /*---------------*/ if ($diasDemora < 0) { $diasDemora = 0; } //--------- OPERACION ---------------- // Nota: A continuacin se debe: // 1. Calcular los dias para la vigencia // de la primer tarifa (dias_vig_tar1) y // multiplicarlos por las tarifas // que tenga el cliente de acuerdo al equipo. // Att. Nesmaster. 20030730. if ($idGrupo > 0) { $diasVigTar1 = getValueTable("dias_vig_tar1", "D_GRUPO", "id_grupo", $idGrupo); } else { $diasVigTar1 = getValueTable("dias_vig_tar1", "D_CLIENTE", "id_cliente", $idCliente); } $costoTlTar1 = ""; $costoTlTar2 = ""; $diasD = ""; if ($diasDemora <= $diasVigTar1) { $costoTlTar1 = calcularTarifa($t1, $diasDemora); $diasEtapa1 = $diasDemora; $diasEtapa2 = 0; } elseif ($diasDemora > $diasVigTar1) { $costoTlTar1 = calcularTarifa($t1, $diasVigTar1); $diasD = $diasDemora - $diasVigTar1; $costoTlTar2 = calcularTarifa($t2, $diasD); $diasEtapa1 = $diasVigTar1; $diasEtapa2 = $diasD; } // ----------------------------------------------- // Proceso para calular Pagos y Pendientes de Pago // ----------------------------------------------- // Reconocer si tiene activada la bandera "Remover Iva". // Si es verdad no debe tomar el IVA. /*$flgSinIva = getValueTable ( "flg_sin_iva", "D_CALCULO", "id_calculo", $idCalculo ); if ($flgSinIva == 1) { $iva = 0; } else { // Aplica IVA. $iva = 0.16; } */ $iva = $flgSinIva = getValueTable("iva", "D_CALCULO", "id_calculo", $idCalculo); $descuento = getValueTable("descuento", "D_CALCULO", "id_calculo", $idCalculo); $arrTotal = calcularTotales($iva, $costoTlTar1, $costoTlTar2, $descuento); $total = $arrTotal[total]; // Cuando se sube por 1era vez no hay descuentos. $totalDesc = $arrTotal[totalDesc]; $totalDescIva = $arrTotal[totalIva]; $idBlConte = getValueTable("id_bl_conte", "D_CALCULO", "id_calculo", $idCalculo); $idBl = getValueTable("id_bl", "BL_CONTE", "id_bl_conte", $idBlConte); $idConte = getValueTable("id_contenedor", "BL_CONTE", "id_bl_conte", $idBlConte); $sql = "update D_CALCULO set "; $sql .= "st_tipo_calculo='{$tipoCalculo}',dias_demora='{$diasDemora}',"; $sql .= "fecha_vacio='{$fechaVacio}',dias_vig_tar1='{$diasVigTar1}',"; $sql .= "costo_tar1='{$t1}',costo_tar2='{$t2}',libre_f2='{$libF2}',"; $sql .= "total='{$total}',total_descuento='{$totalDesc}',"; $sql .= "total_descuento_iva='{$totalDescIva}',"; $sql .= "dias_etapa1='{$diasEtapa1}',dias_etapa2='{$diasEtapa2}',"; $sql .= "id_usuario='{$mscIdUsuario}',fecha_captura='{$hoy}' "; $sql .= "where id_calculo='{$idCalculo}'"; $dbZ->query($sql); } } }
function reporteE($data) { global $db, $db2, $hoy; $sepa = $data[sepa]; $idNaviera = $data[idNaviera]; //$idPatio = $data[idPatio]; // Se crea el archivo $archivo = "../files/InventarioN.csv"; $fp = fopen("{$archivo}", "w"); // Encabezado $oficina = getValueTable("oficina", "OFICINA", "id_oficina", idPatio); $oficina = strtoupper($oficina); $naviera = getValueTable("naviera", "NAVIERA", "id_naviera", $idNaviera); $enc = "{$oficina}\n"; fputs($fp, $enc); $enc = "REPORTE DE INVENTARIO \n"; fputs($fp, $enc); $enc = "NAVIERA : {$naviera} \n"; fputs($fp, $enc); $enc = "F.EMISION: {$hoy} \n\n"; fputs($fp, $enc); // ----------------------------------- // COLUMNAS // ----------------------------------- $enc = "Contenedor" . $sepa . "Tipo" . $sepa . "Fec.Entrada" . $sepa . "Status" . $sepa . "Clase" . $sepa . "Dias" . $sepa . "Notas" . $sepa . "Reforzado" . $sepa . "EIR" . $sepa . "Naviera" . $sepa . "Oficina"; $enc .= "\n"; fputs($fp, $enc); // ----------------------------------- // DEPURACION // ----------------------------------- //$sql = "SELECT id_contenedor from INVENTARIO_PLUS where id_oficina='$sesIdOficina'"; $sql = "SELECT id_contenedor from INVENTARIO_PLUS "; $db->query($sql); while ($db->next_record()) { $idConte = $db->f(id_contenedor); // actualizaInventarioPlus($idConte); // Esto estaba haciendo que se tardara mucho el reporte, porque hace un cuello // botella enorme, y por eso ahora se va a realizar a traves de un Job que cada 30 min // ralice la actualizacion. El scrip se llama "inv_automatic.php" } // ----------------------------------- // DATOS // ----------------------------------- $sql = "select\n c.id_contenedor as IDCONTE,\n c.numero as NCONTE,\n c.id_equipo as IDEQ,\n e.equipo as EQP,\n c.clase as CLASE,\n c.st_dmg as DMG,\n i.eir as EIR,\n n.naviera as NAVIERA,\n i.transportista as TRANSP,\n i.operador as OPERADOR,\n i.placas as PLACAS,\n i.chasis as CHASIS,\n i.tipo_mani as TMANI,\n i.mani_st_pago as PMANI,\n i.doc_tipo as DOCTIPO,\n i.doc_ref as DOCREF,\n i.cuenta as CUENTA,\n i.mani_costo as MANICOSTO,\n i.recibo as RECIBO,\n i.id_oficina as IDOFI,\n i.mod_id_usr as IDUSRMOD,\n i.nota as NOTA\n from INVENTARIO_PLUS as i\n INNER JOIN CONTENEDOR as c ON i.id_contenedor = c.id_contenedor\n INNER JOIN NAVIERA as n ON i.id_naviera = n.id_naviera\n INNER JOIN EQUIPO as e ON c.id_equipo = e.id_equipo\n WHERE\n "; if ($idNaviera != '-') { $sql .= "i.id_naviera = '{$idNaviera}' "; } $db->query($sql); while ($db->next_record()) { // $capFec = $db->f('cap_fec'); $idConte = $db->f('IDCONTE'); $conte = $db->f('NCONTE'); // $idEq = $db->f('IDEQ'); $equipo = $db->f('EQP'); //$clase = $db->f('clase'); // Traer el dato mas actual desde el catalogo de contenedores // $clase = $db->f('CLASE'); // $damage = $db->f('DMG'); // $eir = "E-".$db->f('EIR'); //$idNav = $db->f('IDNAV'); $naviera = $db->f('NAVIERA'); // $transp = $db->f('TRANSP'); // $operador = $db->f('OPERADOR'); //$placas = $db->f('PLACAS'); //$chasis = $db->f('CHASIS'); //$maniTipo = $db->f('TMANI'); $maniQP = $db->f('PMANI'); $maniQP == "M" ? $maniQP = "MERCHANT" : ($maniQP = "CARRIER"); //$maniDoc = $db->f('DOCTIPO'); //$maniDocRef = $db->f('DOCREF'); //$maniCuenta = $db->f('CUENTA'); //$maniCosto = $db->f('MANICOSTO'); //$maniRecibo = $db->f('RECIBO'); $idOficina = $db->f('IDOFI'); $oficinaDB = getValueTable("oficina", "OFICINA", "id_oficina", $idOficina); //$modIdUsr = $db->f('IDUSRMOD'); //$usr = getValueTable("usuario","USUARIO","id_usuario",$modIdUsr); //$modFec = $db->f('mod_fec'); $conteEntSal = getValueTable("ent_sal", "CONTENEDOR", "id_contenedor", $idConte); $nota = $db->f('NOTA'); $nota = addslashes($nota); $nota = str_replace("\n", "", $nota); $nota = str_replace("\r", "", $nota); // Comprobar que el contenedor, mismo registro no este dado de baja en Entradas en su mas reciente evento. $sql2 = "select st_reg from ENTRADA where id_contenedor='{$idConte}' order by cap_fec"; $db2->query($sql2); while ($db2->next_record()) { $stReg = $db2->f(st_reg); } if (empty($stReg)) { $stReg = "A"; // Activo } // Escribiendo al archivo. if ($stReg != "B" && $conteEntSal != "S") { $datoX = getLastIn($idConte); $fecEnt = $datoX['fecEnt']; $eir = $datoX['eir']; $damage = getDamage($idConte); $reforzado = getReforzado($idConte); $clase = getValueTable("clase", "CONTENEDOR", "id_contenedor", $idConte); // Calcular los días de almacenaje. $hoy = date("Y-m-d"); $dias = totalDias($fecEnt, $hoy); $row = $conte . $sepa . $equipo . $sepa . $fecEnt . $sepa . $damage . $sepa . $clase . $sepa . $dias . $sepa . $nota . $sepa . $reforzado . $sepa . $eir . $sepa . $naviera . $sepa . $oficinaDB; $row .= "\n"; fputs($fp, $row); } } fclose($fp); // ----------------------------- // SALVAR COMO... O ABRIR EN AUTO. // (No modificar) // ----------------------------- if (file_exists("{$archivo}")) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($archivo)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($archivo)); ob_clean(); flush(); readfile("{$archivo}"); exit; } }
function calcularDemoraD($idCalculo, $fechaVacio = "", $tipoCalculo, $libDias = "") { global $dbf, $mscIdUsuario, $hoy; // Traemos informacion del registro y se arma un arreglo data. $sql = "select id_d_cliente,id_conte,bkg_fec,tar1 "; $sql .= "from DET_CALCULO where id_det_calculo='{$idCalculo}'"; $dbf->query($sql); while ($dbf->next_record()) { $idCliente = $dbf->f(id_d_cliente); $idConte = $dbf->f(id_conte); $idEquipo = getValueTable("id_equipo", "CONTENEDOR", "id_contenedor", $idConte); $tipoEq = getValueTable("tipo", "EQUIPO", "id_equipo", $idEquipo); $iniLib = $dbf->f(bkg_fec); $t1 = $dbf->f(tar1); } // VALIDAR FECHA-CORTE // Si la fecha de corte es menor a la fecha de ini.demora // no debera realizar calculos. $flgErrFV = 0; if (!empty($fechaVacio)) { // Timstamp para Fecha de vacio $fvDia = getFecha($fechaVacio, 'dia'); $fvMes = getFecha($fechaVacio, 'mes'); $fvAno = getFecha($fechaVacio, 'ano'); $mFV = mktime(0, 0, 0, $fvMes, $fvDia, $fvAno); // Timestamp para inicio dias libres $ilDia = getFecha($iniLib, 'dia'); $ilMes = getFecha($iniLib, 'mes'); $ilAno = getFecha($iniLib, 'ano'); $mIL = mktime(0, 0, 0, $ilMes, $ilDia, $ilAno); if ($mFV < $mIL) { $flgErrFV = 1; } } // Si la bandera $flErrFV == 0 es que esta ok y procede a calcular. if ($flgErrFV == 0) { // Si el usuario no ha aplicado cambios manualmente con los dias libres, // el sistema debe reconocer los dias libres. if (empty($libDias)) { // Pendiente ver si meto las fechas de los acuerdos como paramentros p la funcion. if ($tipoEq == "S") { $libDias = getValueTable("lib_sec", "DET_DIAS_NORMAL", "id_det_dias_normal", 1); } else { $libDias = getValueTable("lib_ref", "DET_DIAS_NORMAL", "id_det_dias_normal", 1); } } // Conocer la tarifa // $t1 = getValueTable ( "tarifa1", "D_TARIFA_NORMAL3", "id_equipo", $idEquipo ); // $t2 = getValueTable ( "tarifa2", "D_TARIFA_NORMAL3", "id_equipo", $idEquipo ); //-------------------------------------------------------------- // DIAS DE DEMORAS // Conocer los dias de demora. // ------------------------------------------------------------- $iniLibDia = getFecha($iniLib, dia); $iniLibMes = getFecha($iniLib, mes); $iniLibAno = getFecha($iniLib, ano); $mktLibF1 = mktime(0, 0, 0, $iniLibMes, $iniLibDia, $iniLibAno); $libF1 = date("Y-m-d", $mktLibF1); //echo "------------------------------------<br>"; $mktLibF2 = mktime(0, 0, 0, $iniLibMes, $iniLibDia + ($libDias - 0), $iniLibAno); $libF2 = date("Y-m-d", $mktLibF2); //echo "fechaVacio: $fechaVacio <br>"; $vacioMes = getFecha($fechaVacio, mes); $vacioDia = getFecha($fechaVacio, dia); $vacioAno = getFecha($fechaVacio, ano); //echo "$vacioAno / $vacioMes / $vacioDia <br>"; $mkVacio = mktime(0, 0, 0, $vacioMes, $vacioDia, $vacioAno); $vacio = date("Y-m-d", $mkVacio); $diasDemora = totalDias($mktLibF2, $mkVacio); if ($diasDemora < 0) { $diasDemora = 0; } // ----------------------------------------------- // Actualizar registro // ----------------------------------------------- $sql = "update DET_CALCULO set "; $sql .= "libre_dias='{$libDias}',"; //$sql.="dias_etapa1='$diasEtapa1',dias_etapa2='$diasEtapa2',"; $sql .= "tar1='{$t1}',"; $sql .= "f_corte='{$fechaVacio}',"; $sql .= "dias_demora='{$diasDemora}',"; $sql .= "id_usr='******',f_captura='{$hoy}' "; $sql .= "where id_det_calculo='{$idCalculo}'"; $dbf->query($sql); } }