2017-07-19 14:34:05 +02:00

587 lines
22 KiB
PHP
Executable File

<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../../../config/config.inc.php';
$call_prefix = array();
foreach(Db::getInstance()->executeS('
SELECT `id_country`, `call_prefix`
FROM `' . _DB_PREFIX_ . 'country`
') as $row){
$call_prefix[(int) $row['id_country']] = $row['call_prefix'];
}
// $str = 'aaAAäãØÃ#$()+@';
function str_format($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_NOQUOTES, 'UTF-8')
// );
return preg_replace(
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i',
'$1',
preg_replace('~&sup([\w]+);~',
'$1',
htmlentities($str, ENT_NOQUOTES, 'UTF-8')
)
);
}
function phone_format($phone, $id_country = 8){
global $call_prefix;
$prefix = '+' . (isset($call_prefix[$id_country]) ? $call_prefix[$id_country] : '33');
// normalize phone
$phone = str_replace(array(' ', '+'), '', $phone);
if (strlen($phone) > '10'){
if ($phone[0] != 0 && $phone[1] == 0)
$phone = substr($phone, 1);
$phone = substr($phone, 0, 10);
}
if (strlen($phone) == 9){
$phone = '0' . $phone;
}
// add spaces
// $_phone = '';
// for($i=0; $i<strlen($phone); $i++){
// $_phone .= $phone[$i];
// if (($i+1)%2==0)
// $_phone .= ' ';
// }
// $phone = $_phone;
// set format
$phone = $prefix . substr($phone, 1);
return $phone;
}
function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT)
{
$diff = strlen( $input ) - mb_strlen( $input );
return str_pad( $input, $pad_length + $diff, $pad_string, $pad_type );
}
/**
* array(
* 0 => position,
* 1 => size,
* 2 => type,
* 3 => code,
* 4 => value
*/
function addRows($data_rows = array()){
if (!is_array($data_rows) || !count($data_rows))
return '';
$data_result = '';
foreach ($data_rows as $row) {
switch ($row[2]) {
case 'N':
if (isset($row[4]) && is_numeric($row[4]))
$val = sprintf('%0'.(int) $row[1].'d', $row[4]);
else
$val = mb_str_pad(mb_substr(str_format($row[4]), 0, (int) $row[1]), (int) $row[1]);
break;
case 'A':
case 'DT':
default:
$val = mb_str_pad(mb_substr(str_format($row[4]), 0, (int) $row[1]), (int) $row[1]);
break;
}
$data_result .= $val;
}
$data_result .= "\n";
return $data_result;
}
$last_sync = date('Y-m-d H:i:s', strtotime((Configuration::get('MONDIALRELAY_LASTSYNC') ? Configuration::get('MONDIALRELAY_LASTSYNC') : '0000-00-00 00:00:00')));
Configuration::updateValue('MONDIALRELAY_LASTSYNC', date('Y-m-d H:i:s'));
$sql = '
SELECT p.*, o.`id_lang`, o.`id_order`, o.`id_customer`, o.`id_address_delivery`, c.`email`
FROM `'._DB_PREFIX_.'mondialrelay_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON p.`id_order_detail` = d.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON d.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON c.`id_customer` = o.`id_customer`
WHERE p.`date_add` > "'.pSQL($last_sync).'"
AND d.`id_order_detail` IS NOT NULL
AND o.`id_order` IS NOT NULL
GROUP BY p.`shipping_number`
';
$lines = Db::getInstance()->ExecuteS($sql);
if(count($lines)) {
$mr_account_details = unserialize(Configuration::get('MR_ACCOUNT_DETAIL'));
$crt_amount = 0.00; // contre remboursement en EUR
$exp_company = Configuration::get('MONDIALRELAY_EXP_COMPANY');
$exp_addr1 = Configuration::get('MONDIALRELAY_EXP_ADDR1');
$exp_addr2 = Configuration::get('MONDIALRELAY_EXP_ADDR2');
$exp_postcode = Configuration::get('MONDIALRELAY_EXP_POSTALCODE');
$exp_city = Configuration::get('MONDIALRELAY_EXP_CITY');
$exp_country = Db::getInstance()->getValue('
SELECT `iso_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int) Configuration::get('MONDIALRELAY_EXP_COUNTRY').'
');
$exp_phone = Configuration::get('MONDIALRELAY_EXP_PHONE');
$exp_email = Configuration::get('MONDIALRELAY_EXP_EMAIL');
$collection_agency = Db::getInstance()->getValue('
SELECT `modexp`
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `cppay` = "'.pSQL(Db::getInstance()->getValue('
SELECT `iso_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int) $exp_country.'
')).'"
AND `destex` = "'.pSQL($exp_postcode).'"
');
$result = '';
$cpt = 0;
foreach($lines as $line) {
if (!in_array($line['mode'], array('24R', '24L', '24X', 'DRI','LD1','LDR','LDS','HOM')))
continue;
$cpt++;
// $mr_liv_mode = array(
// 'DISCOL' => (in_array($line['mode'], array('DOM', 'HOM', 'LD1', 'LDS', 'LCC'))? 'D': 'R'),
// 'SERCOL' => (in_array($line['mode'], array('DOM', 'HOM', 'LD1'))? '1': (in_array($line['mode'], array('LDS', 'LCC'))? '2': '3')),
// 'COLMOD' => (in_array($line['mode'], array('DOM', 'HOM', 'LD1'))? 'CDR': ($line['mode'] == 'LDS'? 'CDS': ($line['mode'] == 'LCC'? 'CCC': 'REL')))
// );
$mr_liv_mode = array(
'DISCOL' => 'R',
'SERCOL' => '2',
'COLMOD' => 'CCC'
);
switch ($line['mode']) {
case 'DOM':
case 'HOM':
case 'LD1':
case 'LDR':
$mr_liv_mode['DISCOL'] = '';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
// $mr_liv_mode['DISCOL'] = 'D';
// $mr_liv_mode['SERCOL'] = '1';
// $mr_liv_mode['COLMOD'] = 'CDR';
break;
case 'LDS':
$mr_liv_mode['DISCOL'] = '';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
// $mr_liv_mode['DISCOL'] = 'D';
// $mr_liv_mode['SERCOL'] = '2';
// $mr_liv_mode['COLMOD'] = 'CDS';
break;
case 'LCC':
$mr_liv_mode['DISCOL'] = 'D';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
case '24R':
case '24L':
case '24X':
case 'DRI':
$mr_liv_mode['DISCOL'] = '';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
default:
$mr_liv_mode['DISCOL'] = 'R';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
break;
}
$address = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $line['id_address_delivery'].'
');
// $code_marque = mb_substr($line['expedition_number'], 0, 2);
// $expe_number = mb_substr($line['expedition_number'], 2, 8);
$data_rows = array(
array(1, 1, 'A', 'CODFIC', 'A'),
array(2, 1, 'A', 'CODENR', '1'),
array(3, 1, 'A', 'SSCODE', '0'),
array(4, 2, 'A', 'MARQUE', 'F1'),
array(6, 8, 'A', 'NEXPE', $line['expedition_number']),
array(14, 2, 'N', 'NBCOLIS', '01'),
array(16, 1, 'A', 'DISTRI', 'D'),
array(17, 8, 'A', 'CDEST', !empty($line['idrelay'])? $line['idrelay']: $address['postcode']),
array(25, 4, 'N', 'TRANS', $line['modexp']),
array(29, 5, 'N', 'TOURNE', $line['direction']),
array(34, 1, 'N', 'TYPSER', ($line['mode'] == 'DOM' || $line['mode'] == 'HOM'? '0': ($line['mode'] == 'LD1'? '1': ($line['mode'] == 'LDS' || $line['mode'] == 'LCC'? '2': '3')))),
array(35, 3, 'A', 'LIVMOD', $line['mode']),
array(38, 10, 'DT', 'DATREM', date('d.m.Y')),
array(48, 4, 'A', 'SIGLE', ''),
array(52, 28, 'A', 'LVADR1', $address['lastname'].' '.$address['firstname']),
array(80, 30, 'A', 'LVADR2', $address['company']),
array(110, 2, 'A', 'Libre', ''),
array(112, 30, 'A', 'LVADR3', $address['address1']),
array(142, 2, 'A', 'Libre', ''),
array(144, 30, 'A', 'LVADR4', $address['address2']),
array(174, 2, 'A', 'Libre', ''),
array(176, 30, 'A', 'LVADR5', ''),
array(206, 2, 'A', 'Libre', ''),
array(208, 26, 'A', 'LVADR6', $address['city']),
array(234, 2, 'A', 'LVCPAY', $line['cppay']),
array(236, 5, 'A', 'LVCPOS', $address['postcode']),
array(241, 5, 'A', 'LVXPOS', ''),
array(246, 20, 'A', 'LVTEL1', str_replace(' ','',phone_format($address['phone']))),
array(266, 20, 'A', 'LVTEL2', str_replace(' ','',phone_format($address['phone_mobile']))),
array(286, 70, 'A', 'LVEMAI', $line['email']),
array(356, 31, 'A', 'INSLIV1', $address['other']),
array(387, 31, 'A', 'INSLIV2', $address['other']),
array(418, 10, 'A', 'libre', ''),
array(428, 7, 'N', 'POIDS', (float) $line['weight'] * $mr_account_details['MR_WEIGHT_COEFFICIENT']),
array(435, 7, 'N', 'VOLU', ''),
array(442, 3, 'N', 'LONG', ''),
array(445, 6, 'A', 'ORIG', 'BEBEBO'),
array(451, 7, 'N', 'VENTE', ''),
array(458, 3, 'A', 'DEVVTE', 'EUR'),
array(461, 7, 'N', 'CRT', (int) $crt_amount * 100),
array(468, 3, 'A', 'DEVCRT', 'EUR'),
array(471, 15, 'A', 'REFEXT', 'EXP'.$line['id_order']),
array(486, 9, 'A', 'REFCLI', $line['id_customer']),
array(495, 10, 'DT', 'DATFAC', date('d.m.Y')),
array(505, 10, 'DT', 'DATCDE', date('d.m.Y')),
array(515, 5, 'A', 'CALPHA', $address['lastname']),
array(520, 5, 'A', 'PRTMIS', ''),
array(525, 1, 'A', 'COLLEC', ''),
array(526, 1, 'A', 'TOPMDM', 'N'),
array(527, 2, 'A', 'TOPEMB', ''),
array(529, 2, 'N', 'QTLGAR', ''),
array(531, 10, 'DT', 'DATRDV', ''),
array(541, 2, 'A', 'CODCRNRDV', ''),
array(543, 2, 'A', 'DEBCRNLIVANN', ''),
array(545, 2, 'A', 'FINCRNLIVANN', ''),
array(547, 10, 'A', 'Libre', ''),
array(557, 1, 'A', 'TOPAVI', ''),
array(558, 7, 'N', 'TAXAFF', ''),
array(565, 7, 'N', 'TAXCRT', ''),
array(572, 2, 'A', 'Libre', ''),
array(574, 3, 'A', 'TOPKDO', ''),
array(577, 3, 'N', 'TOTDIM', ''),
array(580, 33, 'A', 'Libre', ''),
array(613, 7, 'A', 'TOP-POSIT', ''),
array(620, 1, 'A', 'DISCOL', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $mr_liv_mode['DISCOL'])),
array(621, 8, 'A', 'CCOLL', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : (!empty($line['idrelay'])? $line['idrelay']: $address['postcode']))),
array(629, 4, 'A', 'AGPEC', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $collection_agency)),
array(633, 5, 'A', 'TRNCOL', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $line['direction'])),
array(638, 1, 'A', 'SERCOL', ($mr_liv_mode['SERCOL'] ? $mr_liv_mode['SERCOL'] : 2)),
array(639, 3, 'A', 'COLMOD', ($mr_liv_mode['COLMOD'] ? $mr_liv_mode['COLMOD'] : 'CCC')),
array(642, 4, 'A', 'SIGLE', ''),
array(646, 28, 'A', 'EXADR1', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_company)),
array(674, 30, 'A', 'EXADR2', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : mb_substr($exp_company, 28, 30))),
array(704, 2, 'A', 'Libre', ''),
array(706, 30, 'A', 'EXADR3', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_addr1)),
array(736, 2, 'A', 'Libre', ''),
array(738, 30, 'A', 'EXADR4', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_addr2)),
array(768, 2, 'A', 'Libre', ''),
array(770, 30, 'A', 'EXADR5', ''),
array(800, 2, 'A', 'Libre', ''),
array(802, 26, 'A', 'EXADR6', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_city)),
array(828, 2, 'A', 'EXCPAY', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_country)),
array(830, 5, 'A', 'EXCPOS', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_postcode)),
array(835, 5, 'A', 'EXXCPO', ''),
array(840, 20, 'A', 'EXNTEL', str_replace(' ','',phone_format($exp_phone, (int) $exp_country))),
array(860, 70, 'A', 'EXEMAI', $exp_email),
array(930, 2, 'A', 'LNGCOL', 'FR'),
array(932, 9, 'N', 'RECOL', '999999999'),
array(941, 1, 'A', 'TASSU', ''),
array(942, 2, 'A', 'LNGLIV', ($line['id_lang'] == 3? 'ES': ($line['id_lang'] == 2? 'FR': 'EN'))),
array(944, 58, 'A', 'Linre', '')
);
$result .= addRows($data_rows);
// $result .=
// 'A'
// .'1'
// .'0'
// .str_pad(mb_substr('F1', 0, 2), 2)
// .str_pad(mb_substr($line['expedition_number'], 0, 8), 8)
// .'01'
// .'D'
// .str_pad(mb_substr(!empty($line['idrelay'])? $line['idrelay']: $address['postcode'], 0, 8), 8)
// .str_pad(mb_substr($line['modexp'], 0, 4), 4)
// .str_pad(mb_substr($line['direction'], 0, 5), 5)
// .($line['mode'] == 'DOM' || $line['mode'] == 'HOM'? '1': ($line['mode'] == 'LD1'? '1': ($line['mode'] == 'LDS' || $line['mode'] == 'LCC'? '2': '3')))
// .str_pad(substr($line['mode'], 0, 3), 3)
// .date('d.m.Y')
// .str_pad('', 4)
// .str_pad(mb_substr($address['lastname'].' '.$address['firstname'], 0, 28), 28)
// .str_pad(mb_substr($address['company'], 0, 30), 30)
// .str_pad('', 2)
// .str_pad(mb_substr($address['address1'], 0, 30), 30)
// .str_pad('', 2)
// .str_pad(mb_substr($address['address2'], 0, 30), 30)
// .str_pad('', 2)
// .str_pad('', 30)
// .str_pad('', 2)
// .str_pad(mb_substr($address['city'], 0, 26), 26)
// .str_pad(mb_substr($line['cppay'], 0, 2), 2)
// .str_pad(mb_substr($address['postcode'], 0, 5), 5)
// .str_pad(mb_substr($address['postcode'], 5, 5), 5)
// .str_pad(mb_substr($address['phone'], 0, 20), 20)
// .str_pad(mb_substr($address['phone_mobile'], 0, 20), 20)
// .str_pad(mb_substr($line['email'], 0, 70), 70)
// .str_pad(mb_substr($address['other'], 0, 31), 31)
// .str_pad(mb_substr($address['other'], 31, 31), 31)
// .str_pad(' ', 10)
// .sprintf('%07d', (float) $line['weight'] * $mr_account_details['MR_WEIGHT_COEFFICIENT'])
// .str_pad('', 7)
// .str_pad('', 3)
// .str_pad(mb_substr(Configuration::get('MONDIALRELAY_ORIGIN_CODE', 'BEBEBO'), 0, 6), 6)
// .str_pad('', 7)
// .'EUR'
// .sprintf('%07d', (int) $crt_amount * 100)
// .'EUR'
// .str_pad(mb_substr('EXP'.$line['id_order'], 0, 15), 15)
// .str_pad(mb_substr($line['id_customer'], 0, 9), 9)
// .date('d.m.Y')
// .date('d.m.Y')
// .str_pad(mb_substr($address['lastname'], 0, 5), 5)
// .str_pad('', 5)
// .str_pad('', 1)
// .'N'
// .str_pad('', 2)
// .str_pad('', 2)
// .str_pad('', 10)
// .str_pad('', 2)
// .str_pad('', 2)
// .str_pad('', 2)
// .str_pad('', 10)
// .str_pad('', 1)
// .str_pad('', 7)
// .str_pad('', 7)
// .str_pad('', 2)
// .str_pad('', 3)
// .str_pad('', 3)
// .str_pad('', 33)
// .str_pad('', 7)
// .($mr_liv_mode['COLMOD'] === 'CCC' ? ' ' : $mr_liv_mode['DISCOL'])
// .($mr_liv_mode['COLMOD'] === 'CCC' ? ' ' : str_pad(mb_substr(!empty($line['idrelay'])? $line['idrelay']: $address['postcode'], 0, 8), 8))
// .($mr_liv_mode['COLMOD'] === 'CCC' ? ' ' : mb_substr($collection_agency, 0, 4))
// .($mr_liv_mode['COLMOD'] === 'CCC' ? ' ' : str_pad($line['direction'], 5))
// .($mr_liv_mode['SERCOL'] ? $mr_liv_mode['SERCOL'] : 2)
// .($mr_liv_mode['COLMOD'] ? $mr_liv_mode['COLMOD'] : 'CCC')
// //.'CCC'
// .' '
// .($mr_liv_mode['COLMOD'] === 'CCC' ? str_pad('', 28) : str_pad(mb_substr($exp_company, 0, 28), 28))
// .($mr_liv_mode['COLMOD'] === 'CCC' ? str_pad('', 30) : str_pad(mb_substr($exp_company, 28, 30), 30))
// .' '
// .($mr_liv_mode['COLMOD'] === 'CCC' ? str_pad('', 30) : str_pad(mb_substr($exp_addr1, 0, 30), 30))
// .' '
// .($mr_liv_mode['COLMOD'] === 'CCC' ? str_pad('', 30) : str_pad(mb_substr($exp_addr2, 0, 30), 30))
// .' '
// .' '
// .' '
// .($mr_liv_mode['COLMOD'] === 'CCC' ? str_pad('', 26) : str_pad(mb_substr($exp_city, 0, 26), 26))
// .($mr_liv_mode['COLMOD'] === 'CCC' ? str_pad('', 2) : str_pad(mb_substr($exp_country, 0, 2), 2))
// .($mr_liv_mode['COLMOD'] === 'CCC' ? str_pad('', 5) : str_pad(mb_substr($exp_postcode, 0, 5), 5))
// .str_pad(' ', 5)
// .str_pad(mb_substr($exp_phone, 0, 20), 20)
// .str_pad(mb_substr($exp_email, 0, 70), 70)
// .'FR'
// //.(in_array($line['mode'], array('DOM', 'HOM', 'LD1'))? ' ': ($line['mode'] == 'LDS'? ' ': ($line['mode'] == 'LCC'? '999999999': ' '))) // TODO ref expéditeur
// .'999999999'
// .' '
// .($line['id_lang'] == 3? 'ES': ($line['id_lang'] == 2? 'FR': 'EN'))
// .' '
// ."\n";
$i = 0;
foreach(Db::getInstance()->ExecuteS('
SELECT d.*, p.`quantity`
FROM `'._DB_PREFIX_.'mondialrelay_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON p.`id_order_detail` = d.`id_order_detail`
WHERE p.`shipping_number` = "'.pSQL($line['shipping_number']).'"
AND p.`date_add` = "'.pSQL($line['date_add']).'"
') as $art) {
$cpt++;
$i++;
$data_rows = array(
array(1, 1, 'A', 'CODFIC', 'A'),
array(2, 1, 'A', 'CODENR', '1'),
array(3, 1, 'A', 'SSCODE', '1'),
array(4, 2, 'A', 'MARQUE', 'F1'),
array(6, 8, 'A', 'NEXPE', $line['expedition_number']),
array(14, 2, 'N', 'SEQCAR', $i),
array(16, 1, 'N', 'CODART', '1'),
array(17, 1, 'A', 'FILLER', ''),
array(18, 5, 'N', 'QTART', (int) $art['quantity']),
array(23, 28, 'A', 'LIB', $art['product_name']),
array(51, 7, 'N', 'POIDS', (int) (Db::getInstance()->getValue('
SELECT `weight`
FROM `'._DB_PREFIX_.'product`
WHERE `id_product` = '.(int) $art['product_id'].'
') * $mr_account_details['MR_WEIGHT_COEFFICIENT'])),
array(58, 5, 'N', 'VOLUME', '0'),
array(63, 3, 'N', 'LONG', '0'),
array(66, 2, 'N', 'NBCOLI', '1'),
array(68, 5, 'N', 'Filler', ''),
array(73, 1, 'A', 'Filler', ''),
array(74, 1, 'A', 'Filler', ''),
array(75, 1, 'A', 'TOPSE1', ''),
array(76, 5, 'N', 'QTESE1', ''),
array(81, 1, 'A', 'TOPSE2', ''),
array(82, 5, 'N', 'QTESE2', ''),
array(87, 1, 'A', 'TOPSE3', ''),
array(88, 5, 'N', 'QTESE3', ''),
array(93, 1, 'A', 'TOPSE4', ''),
array(94, 5, 'N', 'QTESE4', ''),
array(99, 1, 'A', 'TOPSE5', ''),
array(100, 5, 'N', 'QTESE5', ''),
array(105, 1, 'A', 'TOPSE6', ''),
array(106, 5, 'N', 'QTESE6', ''),
array(111, 1, 'A', 'TOPSE7', ''),
array(112, 5, 'N', 'QTESE7', ''),
array(117, 1, 'A', 'TOPSE8', ''),
array(118, 5, 'N', 'QTESE8', ''),
array(123, 378, 'A', 'libre', '')
);
$result .= addRows($data_rows);
// $result .= 'A11'
// .'F1'
// .$line['expedition_number']
// .sprintf('%02d', $i)
// .'1'
// .' '
// .sprintf('%05d', (int) $art['quantity'])
// .mb_substr($art['product_name'], 0, 28)
// .sprintf('%07d', (int) (Db::getInstance()->getValue('
// SELECT `weight`
// FROM `'._DB_PREFIX_.'product`
// WHERE `id_product` = '.(int) $art['product_id'].'
// ') * $mr_account_details['MR_WEIGHT_COEFFICIENT']) )
// .'00000'
// .'000'
// .'01'
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// .' '
// ."\n";
}
}
$data_rows = array(
array(1, 1, 'A', 'CODFIC', 'A'),
array(2, 1, 'A', 'CODENR', '0'),
array(3, 3, 'A', 'SOCEMET', 'MR '),
array(6, 3, 'A', 'SOCDEST', 'FRA'),
array(9, 5, 'N', 'SEQFIC', 1),
array(14, 7, 'N', 'NBENR', $cpt + 1),
array(21, 10, 'DT', 'DTTRAN', date('d.m.Y')),
array(31, 5, 'A', 'VERSION', '04.00'),
array(36, 965, 'A', 'libre', ''),
);
$data = addRows($data_rows);
$data .= mb_substr($result, 0, -1);
// $data = 'A0FRAMR 00001'
// .sprintf('%07d', $cpt + 1)
// .date('d.m.Y')
// .'04.00'
// .str_pad(' ', 965)
// ."\n"
// .mb_substr($result, 0, -1);
$fileName = 'dpc.D' . date('ymd') . 'H' . date('His') . '.txt';
// $fileName = 'dpc.test.txt';
$repo_dpc = dirname(__FILE__) . '/dpc/';
$repo_archive = dirname(__FILE__) . '/archives/dpc/';
$repo_paths = array(date('Y'), date('m'));
foreach ($repo_paths as $repo_path) {
$repo_archive .= $repo_path . '/';
if (!file_exists($repo_archive))
mkdir($repo_archive);
}
// file_put_contents($repo_dpc . $fileName, "\xEF\xBB\xBF".utf8_encode($w1252_data));
// file_put_contents($repo_archive . $fileName, "\xEF\xBB\xBF".utf8_encode($w1252_data));
// file_put_contents($repo_dpc . $fileName, mb_convert_encoding($data, "WINDOWS-1252", "UTF-8"));
// file_put_contents($repo_archive . $fileName, mb_convert_encoding($data, "WINDOWS-1252", "UTF-8"));
// file_put_contents($repo_dpc . $fileName, $data);
// file_put_contents($repo_archive . $fileName, $data);
$iconv = iconv('UTF-8', 'Windows-1252//TRANSLIT', $data);
if (!$iconv)
$iconv = $data;
file_put_contents($repo_dpc . $fileName, $iconv);
file_put_contents($repo_archive . $fileName, $iconv);
}
// echo 'A0FRAMR00001'.sprintf('%07d', $cpt + 1).date('d.m.Y').'04.00'."\n".mb_substr($result, 0, -1);
// SEND TO FTP
$mr_ftp_conf = Configuration::getMultiple(array(
'MONDIALRELAYWS_FTP_HOST',
'MONDIALRELAYWS_FTP_LOGIN',
'MONDIALRELAYWS_FTP_PASSWORD'
));
$id_ftp = ftp_connect($mr_ftp_conf['MONDIALRELAYWS_FTP_HOST']);
if (!ftp_login($id_ftp, $mr_ftp_conf['MONDIALRELAYWS_FTP_LOGIN'], $mr_ftp_conf['MONDIALRELAYWS_FTP_PASSWORD']))
die('erreur lors de l\'identification FTP'.chr(10).chr(10));
// //activation du mode passif
// // if (!ftp_pasv($id_ftp, true))
// // die('erreur lors de l\'activation du mode passif'.chr(10).chr(10));
$repo_dpc = dirname(__FILE__) . '/dpc/';
$mr_repo_in = 'versmrelay/';
//envoie du fichier
$list = scandir($repo_dpc);
foreach($list as $file)
{
if (!preg_match('/^dpc\..+\.txt$/', $file))
continue;
if ($file == '.' || $file == '..')
continue;
if (!ftp_put ($id_ftp, $mr_repo_in . $file, $repo_dpc . $file, FTP_BINARY))
print('erreur lors de l\'ouverture du fichier : ' . $file . chr(10));
else
unlink($repo_dpc . $file);
}
ftp_close($id_ftp);