garancia/export/index.php
2016-10-10 15:24:25 +02:00

138 lines
3.6 KiB
PHP
Executable File

<?php
$data = simplexml_load_file("good_export.xml");
$file = fopen('export.xml', 'w+');
$txt = '<?xml version="1.0" encoding="UTF-8"?>
<ORDERS>';
foreach ($data as $key => $order) {
$dateAnnneMois = date('Ymd');
// <DATECDE>2014-02-04T16:56:21</DATECDE>
// $date = date('')
$date = new DateTime($order->DATECDE);
$invoice_date = str_replace(' ','T', $date->format('Y-m-d H:i:s'));
$data_name = explode(' ', $order->LIVRNOM);
$company = '';
$data_address = explode(' ', $order->LIVADR1);
$data_address = array_reverse($data_address);
$pattern = "#[0-9]{5,5}#";
//
$data1 = preg_split($pattern, $order->LIVADR1);
$cp = preg_match($pattern, $order->LIVADR1, $matches);
$ville = trim(str_replace('FR', '', $data1[1]));
$codpost = $matches[0];
$address1 = trim($data1[0]);
// echo "<pre>";
// print_r($data1);
// echo "</pre>";
// echo "<pre>";
// print_r($matches[0]);
// echo "</pre>";
// echo "<pre>";
// print_r($order->LIVADR1);
// echo "</pre>";
// die;
// unset($data_address[0]);
// $ville = $data_address[1];
// $codpost = $data_address[2];
// unset($data_address[1]);
// unset($data_address[2]);
// $data_address = array_reverse($data_address);
// $address1 = '';
// foreach ($data_address as $key => $data) {
// $address1 .= $data . ' ';
// }
$txt .= '
<ORDER>';
/* Entete commande */
$txt .= '
<CODACTI>GAR</CODACTI>
<LIBACTI>Garancia-GAR</LIBACTI>
<IDORDER>'.substr($order->IDORDER, 20 ,10).$dateAnnneMois.(isset($lettre) ? $lettre : '').'</IDORDER>
<DATECDE>'.$invoice_date.'</DATECDE> ';
/* Donnees de livraison */
$txt .= '
<LIVRNOM>'.str_replace('&amp;','&',$order->LIVRNOM).'</LIVRNOM>
<LIVPNOM></LIVPNOM>
<LIVSCTE>'.str_replace('&amp;','&',$company).'</LIVSCTE>
<LIVADR1>'.substr(str_replace('&amp;','&',$address1), 0, 35).'</LIVADR1>
<LIVADR2></LIVADR2>
<LIVADR3></LIVADR3>
<LIVCPOS>'.$codpost.'</LIVCPOS>
<LIVVILL>'.str_replace('&amp;','&',utf8_encode($ville)).'</LIVVILL>
<LIVPAYS>FR</LIVPAYS>
<LIVRTEL>0685196749</LIVRTEL>
<LIVMAIL></LIVMAIL>
<LIVCOMM></LIVCOMM>';
/* Nom du transporteur */
$txt .= '
<TRPGEST>'.str_replace('&amp;','&','COLISSIMO EXPERT FR GAR').'</TRPGEST>';
/* Point relais */
$txt .= '
<IDPOINT></IDPOINT>';
/* Caddeau */
$txt .= '
<INSTPRP></INSTPRP>';
$txt.='
<LIGNE>
<IDLIGNE>0</IDLIGNE>
<CODARTI>PM</CODARTI>
<QTTECDE>1</QTTECDE>
<DESLANG>'.iconv("UTF-8", "ISO-8859-1",wd_remove_accents("Pschitt Magique Nouvelle Peau®")).'</DESLANG>
</LIGNE>';
$txt.='
<LIGNE>
<IDLIGNE>1</IDLIGNE>
<CODARTI>TROVO2016</CODARTI>
<QTTECDE>1</QTTECDE>
<DESLANG>'.iconv("UTF-8", "ISO-8859-1",wd_remove_accents("Trousse Voyage")).'</DESLANG>
</LIGNE>';
$txt.="
</ORDER>";
}
$txt.="
</ORDERS>
";
fwrite($file, $txt);
fclose($file);
function wd_remove_accents($str, $charset='utf-8')
{
$str = preg_replace('#&amp;#', 'et', $str);
$str = preg_replace('#&#', 'et', $str);
$str = preg_replace('#œ#', 'oe', $str);
$str = preg_replace('#\r\n#', ' ', $str);
$str = htmlentities($str, ENT_NOQUOTES, $charset);
$str = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml|reg);#', '\1', $str);
$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. '&oelig;'
$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
return $str;
}
die;