// error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ALL);
include('includes/configure.php');
function quitarAcentos($s) {
$s = strtoupper($s);
$s = preg_replace("/Á/","A",$s);
$s = preg_replace("/É/","E",$s);
$s = preg_replace("/Í/","I",$s);
$s = preg_replace("/Ó/","O",$s);
$s = preg_replace("/Ú/","U",$s);
$s = preg_replace("/Ñ/","N",$s);
$s = preg_replace("/º/","o",$s);
$s = preg_replace("/ª/","a",$s);
return $s;
}
?>
Archivos para Seur y GLS
WWW.NOCOCINOMAS.ES
Listado de Direcciones de Envío para CROSS EXPRESS, YEFRAT y SEUR
if ($_POST['procesar']=='S' and $mensajeAlerta == "") { ?>
} elseif ($_POST['procesar']=='S' and $mensajeAlerta <> "") { ?>
} ?>
Especifica la Fecha de Entrega
if ($_POST['procesar']=='S') {
$texto_query = "SELECT upper(replace(CONCAT(ad.firstname,' ',ad.lastname),';',',')) delivery_name, upper(replace(CONCAT(ad.address1,' ',ad.address2),';',',')) delivery_street_address, upper(replace(city,';',',')) delivery_city, upper(replace(st.name,';',',')) delivery_state,o.id_carrier, " .
"o.id_customer customers_id, o.id_order orders_id, replace(CONCAT(phone_mobile,' ',phone),';',',') customers_telephone, replace(postcode,';',',') delivery_postcode,phone_mobile,phone, ".
"payment payment_method,round(total_paid_tax_incl,2) totalFinal,dd.tramo_date shipdate,concat(tramo_from,'-',tramo_until) prefEntrega,1 bultos,ca.id_reference, " .
"replace(replace(CONCAT(ifnull(ad.other,''),' ',ifnull(mes.message,'')),';',','),'\\n','') comentariosPedido, cu.email ".
"from ps_orders o " .
"join ps_carrier ca on (o.id_carrier=ca.id_carrier)".
"join ps_address ad on o.id_address_delivery=ad.id_address ".
"join ps_state st on ad.id_state=st.id_state ".
"join ps_cart dd on (dd.id_cart=o.id_cart) " .
"join ps_customer cu on (cu.id_customer=o.id_customer) ".
"left join ps_message mes on (o.id_order=mes.id_order) " .
"WHERE (o.current_state in (2,3,4,5,14,16)) " .
/*"AND (dd.date_delivery = '" . $_POST['fecIni'] . "') " .*/
"AND (dd.tramo_date = '" . $_POST['fecIni'] . "') " .
"and id_reference<>10 ". //son los pedidos que entregaremos nosotros mismos, y que no deben salir en la etiquetas de Seur*/
"order by o.id_order";
$status_query = tep_db_query($texto_query);
//echo $texto_query;
$gestor = fopen('seurEnvios/enviosSeur.txt', 'w');
$gestorCrossExpress = fopen('crossExpressEnvios/enviosCrossExpress.csv', 'w');
$gestorYefrat = fopen('yefrat/yefrat.csv', 'w');
$gestorYefratBarcelona = fopen('yefrat/yefratBarcelona.csv', 'w');
$gestorPaackMadrid = fopen('paackEnvios/paackMadrid.csv', 'w');
$gestorGP = fopen('gp/gp.csv', 'w');
$pedidosMadridCapital = 0;
$linea = '';
$lineaGLS = "REFERENCIA;HORARIO ENTREGA;BULTOS;PESO;NOMBRE;DIRECCION;CP;POBLACION;CONTRAREEMBOLSO;TELEFONO;MOVIL;COMENTARIOS CLIENTE;EMAIL\r\n";
$lineaCrossExpress = "REFERENCIA;HORARIO ENTREGA;BULTOS;PESO;NOMBRE;DIRECCION;CP;POBLACION;CONTRAREEMBOLSO;TELEFONO;COMENTARIOS CLIENTE;EMAIL\r\n";
$lineaYefrat = "REFERENCIA;HORARIO ENTREGA;BULTOS;PESO;NOMBRE;DIRECCION;CP;POBLACION;CONTRAREEMBOLSO;TELEFONO;COMENTARIOS CLIENTE;EMAIL\r\n";
$lineaYefratBarcelona = '';
$lineaPaackMadrid = '';
while ($status_values = tep_db_fetch_array($status_query)) {
$fechaEntrega=$status_values['shipdate'];
/* Calculo el número de platos del pedido tenienod en cuenta los menús*/
$textoQuery0 = "select product_id products_id,product_quantity products_quantity from ps_order_detail where id_order=".$status_values['orders_id'];
$status_query0 = tep_db_query($textoQuery0);
$platos = 0;
while ($status_values0 = tep_db_fetch_array($status_query0)) {
$textoQueryMenus = "SELECT count(*) platos FROM ps_pack m where m.id_product_pack=".$status_values0['products_id'];
$status_queryMenus = tep_db_query($textoQueryMenus);
$platosMenu = tep_db_fetch_array($status_queryMenus);
$tarde = false;
if ($platosMenu['platos']>0) {
$platos = $platos + $status_values0['products_quantity']*$platosMenu['platos'];
} else {
$platos = $platos + $status_values0['products_quantity'];
}
}
/* Fin cálculo de platos*/
if ($platos<=10) {
$min = 1.00;
$max = 1.50;
// Generar un número aleatorio entre 1.00 y 2.00 con dos decimales
$peso=mt_rand($min * 100, $max * 100) / 100;
//$peso = 1;
} elseif ($platos<=20) {
$min = 1.51;
$max = 2.50;
// Generar un número aleatorio entre 1.00 y 2.00 con dos decimales
$peso=mt_rand($min * 100, $max * 100) / 100;
//$peso = 2;
} else {
$min = 2.51;
$max = 3.00;
// Generar un número aleatorio entre 1.00 y 2.00 con dos decimales
$peso=mt_rand($min * 100, $max * 100) / 100;
//$peso = 3;
}
$pesoGls = $platos*0.38;
if (strpos(strtoupper($status_values['payment_method']),'EFECTIVO')==true) {
$importeReembolso=$status_values['totalFinal'];
$importeReembolsoGLS=$status_values['totalFinal'];
$importeReembolsoPaack=$status_values['totalFinal'].';EUR';
$reembolso='F';
} else {
$importeReembolso='';
$importeReembolsoGLS='0';
$importeReembolsoPaack=';';
$reembolso='';
}
$comentariosSinSaltosLinea='';
$comentariosSinSaltosLineaGLS='';
if (strpos(strtoupper($status_values['prefEntrega']),'TARDE')!==false) {
$comentariosSinSaltosLinea = 'ENTREGAR POR LA TARDE POR FAVOR. ';
$comentariosSinSaltosLineaGLS = 'ENTREGAR POR LA TARDE POR FAVOR. ';
$tarde=true;
}
$comentariosSinSaltosLinea .= '-'.preg_replace("/\r\n|\r/", " ", $status_values['comentariosPedido']);
$comentariosSinSaltosLineaGLS .= '-'.preg_replace("/\r\n|\r/", " ", $status_values['comentariosPedido']);
if (strlen($comentariosSinSaltosLineaGLS)==0) {
$comentariosSinSaltosLineaGLS='nada';
}
$movil = $status_values['phone_mobile'];
$fijo = $status_values['phone'];
if (substr($status_values['phone_mobile'],0,1)==6 or substr($status_values['phone_mobile'],0,1)==7) {
$movil = $status_values['phone_mobile'];
$fijo = $status_values['phone'];
} elseif (substr($status_values['phone'],0,1)==6 or substr($status_values['phone'],0,1)==7) {
$movil = $status_values['phone'];
$fijo = $status_values['phone_mobile'];
}
if (strlen($movil)<3) {
if (strpos(strtoupper($status_values['payment_method']),'EFECTIVO')==true and $status_values['id_reference']=='34' and false) { //si es efectivo y GLS
$movil = 636045471; //móvil de Adolfo
} else {
$movil = $fijo;
}
}
if (strlen($fijo<3)) {
$fijo = $movil;
}
if (date('N')==5) {
$servicio = 'SABADOS';
} elseif ($tarde) {
$servicio = '3';
$codServicioGP = 219;
//$codServicioGP = 212;
} else {
$servicio = '2';
$codServicioGP = 215;
//$codServicioGP = 212;
}
$pesoGramos = $peso*1000;
if ($status_values['id_reference']=='2' or $status_values['id_reference']=='17') { /* Para entregas de Seur 9-13:30h, 3-10:00h */
$cb = '9'.zerofill($status_values['orders_id'].'9',11);
$linea .= "15476;".$cb.";9;18;".$status_values['bultos'].";".$peso.";F;".$status_values['delivery_name'].";".$status_values['delivery_street_address']." (TLF:".$status_values['customers_telephone'].")".";".$status_values['delivery_postcode'].";".quitarAcentos($status_values['delivery_city']).";".$reembolso.";".$importeReembolso.";".$movil.";".$movil.";".$comentariosSinSaltosLinea.";".$status_values['email']."\r\n";
//$linea .= "15476;".$status_values['customers_id'].'-'.$status_values['orders_id'].";9;18;".$status_values['bultos'].";".$peso.";F;".$status_values['delivery_name'].";".$status_values['delivery_street_address']." (TLF:".$status_values['customers_telephone'].")".";".$status_values['delivery_postcode'].";".quitarAcentos($status_values['delivery_city']).";".$reembolso.";".$importeReembolso.";".$movil.";".$movil.";".$comentariosSinSaltosLinea."\r\n";
tep_db_query("insert into ps_orders1 (id_order,seguimiento) values (".$status_values['orders_id'].",'https://www.seur.com/miseur/mis-envios/detalle?tracking=".$cb."') on duplicate key update seguimiento='https://www.seur.com/miseur/mis-envios/detalle?tracking=".$cb."'");
} elseif ($status_values['id_reference']=='1') { /*Cross Express*/
if ($movil<>$fijo) {
$telefono = $movil.'-'.$fijo;
} else {
$telefono = $movil;
}
$lineaCrossExpress .= quitarAcentos($status_values['customers_id'].'-'.$status_values['orders_id'].";".substr($status_values['prefEntrega'],0,19).";".$status_values['bultos'].";".$pesoGls.";".$status_values['delivery_name'].";".$status_values['delivery_street_address'].";".$status_values['delivery_postcode'].";".$status_values['delivery_city'].";".$importeReembolsoGLS.";".$telefono.";".$comentariosSinSaltosLineaGLS.";".$status_values['email']."\r\n");
} elseif ($status_values['id_reference']=='22') { /*Yefrat*/
if ($movil<>$fijo) {
$telefono = $movil.'-'.$fijo;
} else {
$telefono = $movil;
}
$lineaYefrat .= quitarAcentos($status_values['customers_id'].'-'.$status_values['orders_id'].";".substr($status_values['prefEntrega'],0,19).";".$status_values['bultos'].";".$pesoGls.";".$status_values['delivery_name'].";".$status_values['delivery_street_address'].";".$status_values['delivery_postcode'].";".$status_values['delivery_city'].";".$importeReembolsoGLS.";".$telefono.";".$comentariosSinSaltosLineaGLS.";".$status_values['email']."\r\n");
} elseif ($status_values['id_reference']=='49') { /*Yefrat Barcelona*/
if ($movil<>$fijo) {
$telefono = $movil.'-'.$fijo;
} else {
$telefono = $movil;
}
$lineaYefratBarcelona .= quitarAcentos($status_values['customers_id'].'-'.$status_values['orders_id'].";".substr($status_values['prefEntrega'],0,19).";".$status_values['bultos'].";".$pesoGls.";".$status_values['delivery_name'].";".$status_values['delivery_street_address'].";".$status_values['delivery_postcode'].";".$status_values['delivery_city'].";".$importeReembolsoGLS.";".$telefono.";".$comentariosSinSaltosLineaGLS.";".$status_values['email']."\r\n");
} else {
$pedidosMadridCapital+=1;
}
}
}
$paackCabecera = "STORE_ID;INICIO_HORA;FIN_HORA;NUMERO_DE_PEDIDO;SERVICE TYPE;NOMBRE;EMAIL;TELEFONO;DIRECCION;CODIGO_POSTAL;CIUDAD;OTRA_INFO;COD;CURRENCY;UNIDADES_PAQUETE_1;PESO_PAQUETE_1;LONGITUD_PAQUETE1_1;ANCHURA_PAQUETE_1;ALTURA_PAQUETE_1;DESCRIPTIVO_PAQUETE_1;TRACKING_NUMBER_1\r\n";
$paackCabecera = '';
$GPCabecera = "Referencia;Fecha expedición;Nombre Destinatario;Dirección Destinatario;CP Destinatario;Poblacion destinatario;Observaciones Destinatario;Bultos;Movil destinatario;Telefono destinatario;Contacto;Cobro contra reembolso\r\n";
//echo $paackCabecera.$lineaPaack;
fwrite($gestor, $linea);
fwrite($gestorGLS, $lineaGLS);
fwrite($gestorCrossExpress, $lineaCrossExpress);
fwrite($gestorYefrat, $lineaYefrat);
/*fwrite($gestorPaack, iconv("ISO-8859-1","UTF-8//TRANSLIT",$paackCabecera.$lineaPaack));*/
fwrite($gestorYefratBarcelona, $paackCabecera.$lineaYefratBarcelona);
fwrite($gestorPaackMadrid, $paackCabecera.$lineaPaackMadrid);
/*fwrite($gestorPaack, utf8_encode($paackCabecera.$lineaPaack));*/
fwrite($gestorGP, $GPCabecera.$lineaGP);
?>