109 lines
6.6 KiB
PHP
109 lines
6.6 KiB
PHP
<?php
|
|
if(isset($_SERVER['REMOTE_ADDR'])) {
|
|
exit;
|
|
}
|
|
|
|
$_SERVER['HTTP_PORT'] = 80;
|
|
include dirname(__FILE__).'/../../../../config/config.inc.php';
|
|
|
|
$count = (int) Configuration::get('EXAPAQWS_CRONCOUNT') + 1;
|
|
if($count > 99) {
|
|
Configuration::updateValue('EXAPAQWS_CRONCOUNT', 0);
|
|
$count = 1;
|
|
}
|
|
|
|
|
|
function stripaccents($str) {
|
|
return preg_replace(
|
|
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i',
|
|
'$1',
|
|
htmlentities($str, ENT_QUOTES, 'UTF-8')
|
|
);
|
|
}
|
|
|
|
|
|
$csv = fopen(dirname(__FILE__).'/summaries/'.strtolower(str_replace(' ', '', trim(stripaccents(Configuration::get('EXAPAQWS_EXP_COMPANY'))))).date('dmHis').sprintf('%02d', $count).'.txt', 'w');
|
|
|
|
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'exapaqws_parcel_route`
|
|
WHERE `date_add` >= "'.pSQL($lastsummary = Configuration::get('EXAPAQWS_LASTSUMMARY')? $lastsummary: '0000-00-00 00:00:00').'"
|
|
ORDER BY `date_add` ASC
|
|
') as $row) {
|
|
$order = new Order((int) $row['id_order']);
|
|
|
|
if(!Validate::isLoadedObject($order)) {
|
|
// TODO
|
|
continue;
|
|
}
|
|
|
|
$delivery_infos = Db::getInstance()->getRow('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'icirelais_selected`
|
|
WHERE `id_cart` = '.(int) $order->id_cart.'
|
|
');
|
|
|
|
$customer = new Customer((int) $order->id_customer);
|
|
$delivery_address = new Address($order->id_address_delivery);
|
|
|
|
fputcsv($csv, array(
|
|
substr($row['shipping_number'], 0, 18), // exapass
|
|
number_format($row['weight'], 2, '.', ''), // weight
|
|
substr('EXP'.(int) $order->id, 0, 35), // ref 1
|
|
'', // ref 2
|
|
'', // order id
|
|
'', // consolidation
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_COMPANY'))), 0, 12)), // exp company
|
|
date('d.m.Y', strtotime($row['date_add'])), // exp date
|
|
date('H:i:s', strtotime($row['date_add'])), // exp time
|
|
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_'.($delivery_infos? 'B2C': 'B2B').'_COUNTRY_RETURN'))), 0, 6), // exp country
|
|
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $row['ac'])), 0, 3), // ac
|
|
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $row['tour'])), 0, 3), // tour
|
|
'', // value
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_address->lastname.' '.$delivery_address->firstname: ($delivery_address->company != ''? $delivery_address->company.' ': '').$delivery_address->lastname.' '.$delivery_address->firstname)), 0, 35)), // dest name
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['address1']: $delivery_address->address1)), 0, 35)), // dest addr 1
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['address2']: $delivery_address->address2)), 0, 35)), // dest addr 2
|
|
'', // dest addr 3
|
|
'', // dest addr 4
|
|
'', // dest addr 5
|
|
'', // dest addr 6
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['postcode']: $delivery_address->postcode)), 0, 10)), // dest postcode
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['city']: $delivery_address->city)), 0, 35)), // dest city
|
|
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $row['lpfx'])), 0, 3), // dest country
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_address->phone)), 0, 35)), // dest phone
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_COMPANY'))), 0, 35)), // exp company
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_ADDR1'))), 0, 35)), // exp addr 1
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_ADDR2'))), 0, 35)), // exp addr 2
|
|
'', // exp addr 3
|
|
'', // exp addr 4
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_POSTALCODE'))), 0, 10)), // exp postcode
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_CITY'))), 0, 35)), // exp city
|
|
strtoupper(Country::getIsoById((int) Configuration::get('EXAPAQWS_EXP_COUNTRY'))), // exp country
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_PHONE'))), 0, 30)), // exp phone
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_EMAIL'))), 0, 80)), // exp email
|
|
'', // exp mobile
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $customer->email)), 0, 80)), // dest email
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_address->phone_mobile)), 0, 35)), // dest mobile
|
|
'', // consolidation
|
|
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_'.($delivery_infos? 'B2C': 'B2B').'_COUNTRY_AGENCY'))), 0, 6), // country + agency
|
|
'', // exasanté
|
|
$delivery_infos? 101: 1, // notification options
|
|
$delivery_infos? 2: 1, // service type
|
|
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_'.($delivery_infos? 'B2C': 'B2B').'_CHARGING_ACCOUNT'))), 0, 6), // charging account
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', substr($delivery_address->lastname, 0, 30))), // dest lastname
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', substr($delivery_address->firstname, 0, 20))), // dest firstname
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['relay_id'], 0, 20): '')), // relay id
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['company'], 0, 50): '')), // relay company
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['address1'], 0, 40): '')), // relay addr 1
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['address2'], 0, 40): '')), // relay addr 2
|
|
'', // relay addr 3
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['postcode'], 0, 5): '')), // relay postcode
|
|
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['city'], 0, 30): '')), // relay city
|
|
10, // keeping duration
|
|
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_COMPANY'))), 0, 35)), // company name
|
|
), '|', '"');
|
|
}
|
|
|
|
fclose($csv);
|