1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
<?php
// Connect and query the database for the users
require_once('fonction.php');
$connexion = connexion_sql('BD_GESTION');
$sql = "select UPPER(T.Intitule_Livraison) as Societe_ou_Nom, T.DO_Tiers as N_Client, UPPER(T.Intitule_Livraison) as Attention, UPPER(T.Adresse_Livraison_1) as Ad1,
UPPER(T.Adresse_Livraison_2) as Ad2,'' as Ad3, T.Tel_Livraison as Telephone,
UPPER(SUBSTRING(T.CP_Ville_Livraison, 7,200)) as Ville, LEFT(T.CP_Ville_Livraison,5) as Code_Postal, 'FR' as Pays, 'SV' as Service_UPS, 'CP' as Type_Emballage,
'12.4' as Poids, T.Nb_Colis as Nbre_Colis, 'Boucherie-Charcuterie' as Desc_Marchandises, 'Y' as QVN_Option, P.CT_EMail as Mail_QV,'Logo' as Profile_Name,
C.DL_PieceBC as Ref1, '1231231231' as Ref2
FROM F_DOCENTETE as T
INNER JOIN F_COMPTET as P
on P.CT_Num=T.DO_Tiers
INNER JOIN F_DOCLIGNE as C
on C.DO_Piece=T.DO_Piece
where (C.DO_DateLivr between '20131206' and '20131206') and C.DL_PieceBC like 'W%'
GROUP BY T.DO_Tiers, T.Intitule_Livraison, T.DO_Piece, T.Adresse_Livraison_1, T.Adresse_Livraison_2, T.Tel_Livraison, T.CP_Ville_Livraison, T.Nb_Colis,
P.CT_EMail, C.DL_PieceBC";
$results = odbc_execute($connexion,$sql);
// Pick a filename and destination directory for the file
// Remember that the folder where you want to write the file has to be writable
$filename = "C:/ups/ups_".time().".csv";
// Actually create the file
// The w+ parameter will wipe out and overwrite any existing file with the same name
$handle = fopen($filename, 'w+');
// Write the spreadsheet column titles / labels
fputcsv($handle, array(Societe_ou_Nom, N_Client, Attention, Ad1, Ad2, Ad3, Telephone, Ville, Code_Postal, Pays, Service_UPS, Type_Emballage, Poids, Nbre_Colis, Desc_Marchandises,
QVN_Option, Mail_QV, Profile_Name, Ref1, Ref2));
// Write all the user records to the spreadsheet
foreach($results as $row)
{
fputcsv($handle, array($row['Societe_ou_Nom'], $row['N_Client'], $row['Attention'], $row['Ad1'], $row['Ad2'], $row['Ad3']
, $row['Telephone'], $row['Ville'], $row['Code_Postal'], $row['Pays'], $row['Service_UPS'], $row['Type_Emballage'], $row['Poids'], $row['Nbre_Colis']
, $row['Desc_Marchandises'], $row['QVN_Option'], $row['Mail_QV'], $row['Profile_Name'], $row['Ref1'], $row['Ref2']));
}
// Finish writing the file
fclose($handle);
?> |
Partager