Merge branch 'ticket-philea' into develop
This commit is contained in:
commit
542fe9c0b4
@ -1,498 +1,341 @@
|
||||
<?php
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
|
||||
//include(dirname(__FILE__) . '/../../../config/settings.inc.php');
|
||||
include(dirname(__FILE__) . '/../../../config/config.inc.php');
|
||||
include( dirname(__FILE__) . '/../philea_magistor.php');
|
||||
//include(dirname(__FILE__) . '/../../../config/settings.inc.php');
|
||||
include(dirname(__FILE__) . '/../../../config/config.inc.php');
|
||||
include( dirname(__FILE__) . '/../philea_magistor.php');
|
||||
|
||||
ini_set('memory_limit', '4G');
|
||||
ini_set('memory_limit', '4G');
|
||||
|
||||
$id_sale = (int) $argv[1];
|
||||
$id_sale = (int) $argv[1];
|
||||
|
||||
//$_id_shipping = 4; // philea
|
||||
//$_id_shipping = 4; // philea
|
||||
|
||||
if($id_sale == 0) {
|
||||
exit;
|
||||
}
|
||||
if($id_sale == 0) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$magistorModule = new philea_magistor();
|
||||
$id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||||
$magistorModule = new philea_magistor();
|
||||
$id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||||
|
||||
$tab_conversion_carrier = philea_magistor::getTabState();
|
||||
$tab_conversion_carrier = philea_magistor::getTabState();
|
||||
|
||||
$socol_to_magistor = array(
|
||||
'DOM' => 'SOCOLMDSS', // Livraison à domicile
|
||||
'DOS' => 'SOCOLMDS',
|
||||
'RDV' => 'SOCOLMRDV', // Livraison sur Rendez-vous
|
||||
'CIT' => 'SOCOLCITY', // Livraison en Cityssimo
|
||||
'BPR' => 'SOCOLMBP', // Livraison en Bureau de Poste
|
||||
'CDI' => 'SOCOLMBP', // Centre de distribution
|
||||
'A2P' => 'SOCOLMC', // Livraison Commerce de proximité
|
||||
'ACP' => 'SOCOLMBP', // Agence ColiPoste
|
||||
);
|
||||
$socol_to_magistor = array(
|
||||
'DOM' => 'SOCOLMDSS', // Livraison à domicile
|
||||
'DOS' => 'SOCOLMDS',
|
||||
'RDV' => 'SOCOLMRDV', // Livraison sur Rendez-vous
|
||||
'CIT' => 'SOCOLCITY', // Livraison en Cityssimo
|
||||
'BPR' => 'SOCOLMBP', // Livraison en Bureau de Poste
|
||||
'CDI' => 'SOCOLMBP', // Centre de distribution
|
||||
'A2P' => 'SOCOLMC', // Livraison Commerce de proximité
|
||||
'ACP' => 'SOCOLMBP', // Agence ColiPoste
|
||||
);
|
||||
|
||||
$mr_to_magistor = array(
|
||||
'24R' => 'MRMDSS', // Point relais
|
||||
'DRI' => 'MRMDS', // Colis drive
|
||||
'LD1' => 'MRMRDV', // Domicile RDC (1 pers)
|
||||
'LDS' => 'MRCITY', // Domicile spé (2 pers)
|
||||
'HOM' => 'MRMBP', // Domicile spé
|
||||
);
|
||||
$mr_to_magistor = array(
|
||||
'24R' => 'MRMDSS', // Point relais
|
||||
'DRI' => 'MRMDS', // Colis drive
|
||||
'LD1' => 'MRMRDV', // Domicile RDC (1 pers)
|
||||
'LDS' => 'MRCITY', // Domicile spé (2 pers)
|
||||
'HOM' => 'MRMBP', // Domicile spé
|
||||
);
|
||||
|
||||
if($magistorModule->active) {
|
||||
global $regex_file_out;
|
||||
$regex_file_out = '@^CDC02(.*)\.(BAL|DAT)@';
|
||||
@set_time_limit(0);
|
||||
if($magistorModule->active) {
|
||||
global $regex_file_out;
|
||||
$regex_file_out = '@^CDC02(.*)\.(BAL|DAT)@';
|
||||
@set_time_limit(0);
|
||||
|
||||
$db = Db::getInstance();
|
||||
$id_order_state = 2;
|
||||
$db = Db::getInstance();
|
||||
$id_order_state = 2;
|
||||
|
||||
/* @Override include orders */
|
||||
$include_orders = array();
|
||||
foreach($db->ExecuteS('
|
||||
SELECT DISTINCT o.`id_order`
|
||||
FROM `'._DB_PREFIX_.'order_state_current` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
|
||||
ON o.`id_order` = d.`id_order`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c
|
||||
ON d.`product_id` = c.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'philea_magistor_sent` pms
|
||||
ON pms.`id_sale` = c.`id_sale` AND pms.`id_order` = o.`id_order`
|
||||
WHERE o.`id_order_state` IN (2, 3, 4, 9, 13, 17)
|
||||
AND pms.`id_order` IS NULL
|
||||
AND c.`id_sale` = '.(int) $id_sale.'
|
||||
AND CAST(d.`product_quantity` AS SIGNED) - CAST(d.`product_quantity_refunded` AS SIGNED) > 0
|
||||
') as $row) {
|
||||
$include_orders[] = (int) $row['id_order'];
|
||||
}
|
||||
if(count($include_orders) == 0) {
|
||||
exit;
|
||||
}
|
||||
$include_orders = array();
|
||||
foreach($db->ExecuteS('
|
||||
SELECT DISTINCT o.`id_order`
|
||||
FROM `'._DB_PREFIX_.'order_state_current` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON o.`id_order` = d.`id_order`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON d.`product_id` = c.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'philea_magistor_sent` pms ON (pms.`id_sale` = c.`id_sale` AND pms.`id_order` = o.`id_order`)
|
||||
WHERE o.`id_order_state` IN (2, 3, 4, 13, 17, 9, 18, 19)
|
||||
AND c.`id_sale` = '.(int) $id_sale.'
|
||||
AND pms.`id_order` IS NULL
|
||||
AND d.`product_quantity` - d.`product_quantity_refunded` > 0
|
||||
') as $row) {
|
||||
$include_orders[] = (int) $row['id_order'];
|
||||
}
|
||||
|
||||
// get all "not-relay" carriers for the sale
|
||||
$relay_carriers = Carrier::getShippingTypes();
|
||||
$relay_carriers = $relay_carriers[Carrier::SHIPPING_TYPE_RELAY];
|
||||
if(count($include_orders) == 0) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$sale_carriers_full = array();
|
||||
$sale_carriers_wo_relay = array();
|
||||
foreach (Db::getInstance()->executeS('SELECT `id_carrier` FROM `' . _DB_PREFIX_ . 'privatesale_carrier` WHERE `id_sale` = ' . (int) $id_sale) as $carrier){
|
||||
$sale_carriers_full[] = (int) $carrier['id_carrier'];
|
||||
if (!in_array((int) $carrier['id_carrier'], $relay_carriers))
|
||||
$sale_carriers_wo_relay[] = (int) $carrier['id_carrier'];
|
||||
}
|
||||
$exclude_orders = array();
|
||||
// foreach($db->ExecuteS('
|
||||
// SELECT DISTINCT `id_order`
|
||||
// FROM `'._DB_PREFIX_.'philea_magistor_sent`
|
||||
// WHERE `id_sale` = '.(int) $id_sale.'
|
||||
// ') as $row) {
|
||||
// $exclude_orders[] = (int) $row['id_order'];
|
||||
// }
|
||||
|
||||
$exclude_orders = array();
|
||||
// foreach($db->ExecuteS('
|
||||
// SELECT DISTINCT `id_order`
|
||||
// FROM `'._DB_PREFIX_.'philea_magistor_sent`
|
||||
// WHERE `id_sale` = '.(int) $id_sale.'
|
||||
// ') as $row) {
|
||||
// $exclude_orders[] = (int) $row['id_order'];
|
||||
// }
|
||||
$orders = $db->ExecuteS('
|
||||
SELECT * FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `date_add` > "2016-07-05 00:00:00"
|
||||
'.(count($exclude_orders) > 0? 'AND `id_order` NOT IN ('.implode(', ', $exclude_orders).')': '').'
|
||||
'.(count($include_orders) > 0? 'AND `id_order` IN ('.implode(', ', $include_orders).')': '').'
|
||||
');
|
||||
|
||||
$orders = $db->ExecuteS('
|
||||
SELECT o.*, h.`date_add` as `history_date`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h
|
||||
ON h.`id_order` = o.`id_order`
|
||||
AND h.`id_order_state` IN (2, 3, 4, 9, 13, 17)
|
||||
WHERE o.`date_add` > "2015-06-01 00:00:00"
|
||||
AND h.`id_order_history` = (
|
||||
SELECT `id_order_history`
|
||||
FROM `'._DB_PREFIX_.'order_history` oh
|
||||
WHERE oh.`id_order` = o.`id_order`
|
||||
AND oh.`id_order_state` IN (2, 3, 4, 9, 13, 17)
|
||||
ORDER BY oh.`date_add` ASC
|
||||
LIMIT 1
|
||||
)
|
||||
'.(count($exclude_orders) > 0? 'AND o.`id_order` NOT IN ('.implode(', ', $exclude_orders).')': '').'
|
||||
'.(count($include_orders) > 0? 'AND o.`id_order` IN ('.implode(', ', $include_orders).')': '').'
|
||||
ORDER BY `history_date` ASC
|
||||
');
|
||||
if(count($orders) == 0) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// $orders = $db->ExecuteS('
|
||||
// SELECT * FROM `'._DB_PREFIX_.'orders` o
|
||||
// WHERE o.`date_add` > "2015-06-01 00:00:00"
|
||||
// '.(count($exclude_orders) > 0? 'AND o.`id_order` NOT IN ('.implode(', ', $exclude_orders).')': '').'
|
||||
// '.(count($include_orders) > 0? 'AND o.`id_order` IN ('.implode(', ', $include_orders).')': '').'
|
||||
// ');
|
||||
if((int) Db::getInstance()->getValue('
|
||||
SELECT `featured`
|
||||
FROM `'._DB_PREFIX_.'privatesale`
|
||||
WHERE `id_sale` = '.(int) $id_sale.'
|
||||
')) {
|
||||
$code_societe = 78;//(int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
||||
} else {
|
||||
$code_societe = (int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
||||
}
|
||||
|
||||
if(count($orders) == 0) {
|
||||
exit;
|
||||
}
|
||||
$delai_livraison = (int)(Configuration::get('PHILEA_MAGISTOR_DELAI_LIVRAISON'));
|
||||
|
||||
if((int) Db::getInstance()->getValue('
|
||||
SELECT `featured`
|
||||
FROM `'._DB_PREFIX_.'privatesale`
|
||||
WHERE `id_sale` = '.(int) $id_sale.'
|
||||
')) {
|
||||
$code_societe = 78;//(int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
||||
} else {
|
||||
$code_societe = (int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
||||
}
|
||||
//@TODO rendre configurable le champs "reference" entre "reference" et "ean13"
|
||||
$referenceField = 'reference';//Configuration::get('PHILEA_MAGISTOR_REF_FIELD');
|
||||
|
||||
$delai_livraison = (int)(Configuration::get('PHILEA_MAGISTOR_DELAI_LIVRAISON'));
|
||||
$fileName = dirname(__FILE__) . '/OUT/CDC02' . date('ymdHis');
|
||||
|
||||
$repo_archive = dirname(__FILE__) . '/archives/OUT/CMD/';
|
||||
$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);
|
||||
}
|
||||
|
||||
$fileArchive = $repo_archive . 'CDC02' . date('ymdHis');
|
||||
|
||||
$data = '';
|
||||
foreach($orders as $o) {
|
||||
$partialOrder = false;
|
||||
$order = new Order($o['id_order']);
|
||||
|
||||
$products = $order->getProducts();
|
||||
// ANTADIS
|
||||
$products_ids = array();
|
||||
foreach($products as $product) {
|
||||
$products_ids[] = (int) $product['product_id'];
|
||||
}
|
||||
|
||||
$nbProducts = 0;
|
||||
$nbProducts = (int) Db::getInstance()->getValue('
|
||||
SELECT COUNT(d.`id_order_detail`)
|
||||
FROM `'._DB_PREFIX_.'order_detail` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON d.`product_id` = c.`id_product`
|
||||
WHERE c.`id_sale` = '.(int) $id_sale.'
|
||||
AND d.`id_order` = '.(int) $o['id_order'].'
|
||||
AND d.`product_quantity` - d.`product_quantity_refunded` > 0
|
||||
');
|
||||
|
||||
$prid = false;
|
||||
$delivery_info = false;
|
||||
$carrier_value = false;
|
||||
|
||||
if($nbProducts) {
|
||||
/*if(!Db::getInstance()->getValue('
|
||||
SELECT SUM(`product_quantity`)
|
||||
FROM `'._DB_PREFIX_.'order_detail` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c
|
||||
ON c.`id_product` = d.`product_id`
|
||||
WHERE d.`id_order` = '.(int) $order->id.'
|
||||
AND d.`product_quantity` - GREATEST(d.`product_quantity_return`, d.`product_quantity_refunded`) > 0
|
||||
AND c.`id_sale` = '.(int) $id_sale.'
|
||||
')) {
|
||||
continue;
|
||||
}*/
|
||||
$carriers_socol = array(67,87,88,89);
|
||||
$customer = new Customer($order->id_customer);
|
||||
$address_invoice = new Address($order->id_address_invoice);
|
||||
$address_delivery = new Address($order->id_address_delivery);
|
||||
|
||||
if(in_array((int) $order->id_carrier, $carriers_socol)) {
|
||||
$delivery_info = $db->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
|
||||
WHERE `id_cart` = '.(int) $order->id_cart.'
|
||||
AND `delivery_mode` != ""
|
||||
');
|
||||
|
||||
if($delivery_info) {
|
||||
$carrier_value = $socol_to_magistor[$delivery_info['delivery_mode']];
|
||||
$prid = $delivery_info['prid'];
|
||||
}
|
||||
}
|
||||
|
||||
if(!$carrier_value) {
|
||||
$carrier_value = $tab_conversion_carrier[$order->id_carrier];
|
||||
}
|
||||
|
||||
|
||||
//@TODO rendre configurable le champs "reference" entre "reference" et "ean13"
|
||||
$referenceField = 'reference';//Configuration::get('PHILEA_MAGISTOR_REF_FIELD');
|
||||
/*if ($carrier_value == 'EXAPAQ_B2B' || $carrier_value == 'EXAPAQ')
|
||||
$carrier_value = 'DPD';*/
|
||||
|
||||
$fileName = dirname(__FILE__) . '/OUT/CDC02' . date('ymdHis');
|
||||
## ASSIGN DATA
|
||||
$data .= str_pad( 'E01', 10, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $code_societe, 20, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( 'OP'.(int) $id_sale.'-'.$order->id, 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $order->id_customer, 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( date('Ymd',strtotime($order->date_add)+86400*$delai_livraison), 8, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( '', 4, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( $carrier_value , 50, ' ', STR_PAD_RIGHT );//$db->getValue('SELECT name FROM `'._DB_PREFIX_.'carrier` WHERE id_carrier = '.$order->id_carrier)
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_invoice->firstname.' '.$address_invoice->lastname)),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_invoice->company)),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_invoice->address1)),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_invoice->address2)),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_invoice->other)),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->postcode),0,8), 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->city),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( utf8_decode($db->getValue('SELECT iso_code FROM `'._DB_PREFIX_.'country` WHERE id_country = '.$address_invoice->id_country)), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( (!empty($address_invoice->phone_mobile)?$address_invoice->phone_mobile:$address_invoice->phone), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($customer->email), 0, 50), 50, ' ', STR_PAD_RIGHT );
|
||||
|
||||
$repo_archive = dirname(__FILE__) . '/archives/OUT/CMD/';
|
||||
$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);
|
||||
}
|
||||
if(in_array((int) $order->id_carrier, $carriers_socol)
|
||||
&& $delivery_info
|
||||
&& $delivery_info['delivery_mode'] == 'DOM'
|
||||
) {
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_invoice->firstname.' '.$address_invoice->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
} else {
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->firstname.' '.$address_delivery->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->company)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
$fileArchive = $repo_archive . 'CDC02' . date('ymdHis');
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->address1)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->address2)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->other)),0, 50), 50, ' ', STR_PAD_RIGHT); //ADRESSE 3
|
||||
$data .= str_pad(substr(utf8_decode($address_delivery->postcode), 0, 8), 8, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode($address_delivery->city), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(utf8_decode($db->getValue('SELECT iso_code FROM `'._DB_PREFIX_.'country` WHERE id_country = '.$address_delivery->id_country)), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad((!empty($address_delivery->phone_mobile)?$address_delivery->phone_mobile:$address_delivery->phone), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
// LIVRAISON SOCOL
|
||||
if(in_array((int) $order->id_carrier, $carriers_socol) && $delivery_info) {
|
||||
if($delivery_info['delivery_mode'] == 'DOM') {
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->firstname.' '.$address_delivery->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->company)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
} else {
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_invoice->firstname.' '.$address_invoice->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
}
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->address1)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->address2)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($address_delivery->other)), 0, 50), 50, ' ', STR_PAD_RIGHT); //ADRESSE 3
|
||||
$data .= str_pad(substr(utf8_decode($address_delivery->postcode), 0, 8), 8, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode($address_delivery->city), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(utf8_decode($db->getValue('SELECT `iso_code` FROM `'._DB_PREFIX_.'country` WHERE `id_country` = '.$address_delivery->id_country)), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(getPhone($address_delivery->phone_mobile, $address_delivery->phone, $address_delivery->id_country), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad('', 50, ' ', STR_PAD_RIGHT);
|
||||
}
|
||||
// LIVRAISON DOMICILE
|
||||
else{
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);//ADRESSE 3
|
||||
$data .= str_pad( '', 8, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
$data = '';
|
||||
foreach( $orders as $o ) {
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_1
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_2
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_3
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_4
|
||||
$data .= str_pad($prid? $prid: '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_5
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_6
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_7
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT); // INFO_RELAIS_8
|
||||
|
||||
$partialOrder = false;
|
||||
$order = new Order($o['id_order']);
|
||||
$products = $order->getProducts();
|
||||
if(Configuration::get('PHILEA_MAGISTOR_ASSURANCE')
|
||||
&& Configuration::get('PHILEA_MAGISTOR_ASSURANCE') <= ($order->total_paid_real - $order->total_shipping)
|
||||
&& Configuration::get('PHILEA_MAGISTOR_ASSURANCE') > 0
|
||||
) {
|
||||
$data .= str_pad( str_replace('.',',',($order->total_paid_real - $order->total_shipping)), 50, ' ', STR_PAD_RIGHT ); // VALEUR DE COMMANDE
|
||||
} else {
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT ); // VALEUR DE COMMANDE
|
||||
}
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );// ZONE_10
|
||||
$data .= str_pad(utf8_decode(cleanChar($address_delivery->other)), 400, ' ', STR_PAD_RIGHT );
|
||||
$data .= PHP_EOL;
|
||||
$products = $order->getProducts();
|
||||
|
||||
$nb_ligne = 0;
|
||||
foreach($products as $product)
|
||||
{
|
||||
if(!Db::getInstance()->getRow('
|
||||
SELECT `id_product`
|
||||
FROM `'._DB_PREFIX_.'product_ps_cache`
|
||||
WHERE `id_sale` = '.(int) $id_sale.'
|
||||
AND `id_product` = '.(int) $product['product_id'].'
|
||||
')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$nb_ligne++;
|
||||
|
||||
$ean = !empty($product['product_ean13'])? $product['product_ean13']: $product['product_supplier_reference'];
|
||||
|
||||
$data .= str_pad('L01', 10, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad('OP'.(int) $id_sale.'-'.$order->id, 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad($nb_ligne, 4, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad(str_replace(array("\r", "\n"), '', $ean), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0), 8, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad(substr(utf8_decode(cleanChar($product['product_name'])), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(str_replace(array("\r", "\n"), '', $ean), 14, ' ', STR_PAD_LEFT);
|
||||
$data .= PHP_EOL;
|
||||
}
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_magistor_sent`
|
||||
VALUES (
|
||||
'.(int) $order->id.',
|
||||
'.(int) $id_sale.',
|
||||
NOW()
|
||||
)
|
||||
');
|
||||
} //End if nbproducts
|
||||
}//End foreach
|
||||
|
||||
|
||||
if (!in_array($order->id_carrier, $relay_carriers)){ // not a relay carrier
|
||||
$sale_carriers = $sale_carriers_wo_relay;
|
||||
}
|
||||
else{ // relay carrier
|
||||
$sale_carriers = $sale_carriers_full;
|
||||
}
|
||||
if($orders and is_array($orders))
|
||||
{
|
||||
file_put_contents($fileName . '.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
||||
file_put_contents($fileName . '.BAL', '');
|
||||
|
||||
$nbProducts = 0;
|
||||
/*foreach($products as $product)
|
||||
{
|
||||
$productObj = new Product($product['product_id']);
|
||||
file_put_contents($fileArchive . '.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
||||
|
||||
if($productObj->send_philea)
|
||||
$nbProducts++;
|
||||
require_once('connection_ftp.php');
|
||||
}
|
||||
|
||||
unset($productObj);
|
||||
}*/
|
||||
// ANTADIS
|
||||
$products_ids = array();
|
||||
foreach($products as $product) {
|
||||
$products_ids[] = (int) $product['product_id'];
|
||||
}
|
||||
$nbProducts = (int) Db::getInstance()->getValue('
|
||||
SELECT COUNT(s.`id_shipping`)
|
||||
FROM `'._DB_PREFIX_.'product_ps_cache` c
|
||||
WHERE c.`id_product` IN ('.implode(', ', $products_ids).')
|
||||
AND c.`id_sale` = '.(int) $id_sale.'
|
||||
');
|
||||
//
|
||||
}
|
||||
|
||||
if($nbProducts)
|
||||
{
|
||||
if(!Db::getInstance()->getValue('
|
||||
SELECT SUM(`product_quantity`)
|
||||
FROM `'._DB_PREFIX_.'order_detail` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c
|
||||
ON c.`id_product` = d.`product_id`
|
||||
WHERE d.`id_order` = '.(int) $order->id.'
|
||||
AND d.`product_quantity` - GREATEST(d.`product_quantity_return`, d.`product_quantity_refunded`) > 0
|
||||
AND c.`id_sale` = '.(int) $id_sale.'
|
||||
')) {
|
||||
continue;
|
||||
}
|
||||
function cleanChar($string) {
|
||||
$unicode_0 = json_decode('"\u0006"');
|
||||
$unicode_1 = json_decode('"\u200b"');
|
||||
|
||||
$customer = new Customer($order->id_customer);
|
||||
$address_invoice = new Address($order->id_address_invoice);
|
||||
$address_delivery = new Address($order->id_address_delivery);
|
||||
|
||||
## GET KEY CARRIER
|
||||
/**
|
||||
* @Override
|
||||
* MR relay point
|
||||
*/
|
||||
$relay_point = array(
|
||||
'code' => FALSE,
|
||||
'id' => FALSE
|
||||
);
|
||||
$socol_relay = FALSE;
|
||||
$mr_relay = FALSE;
|
||||
|
||||
// SOCOLISSIMO RELAY POINT
|
||||
$socol_relay = $db->getRow('
|
||||
SELECT `delivery_mode`, `prid`
|
||||
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
|
||||
WHERE `id_cart` = ' . (int) $order->id_cart
|
||||
);
|
||||
if ($socol_relay){
|
||||
$relay_point['code'] = (isset($socol_relay['delivery_mode']) ? $socol_relay['delivery_mode'] : false);
|
||||
$relay_point['id'] = (isset($socol_relay['prid']) ? $socol_relay['prid'] : false);
|
||||
}
|
||||
else{
|
||||
// MONDIAL RELAY RELAY POINT
|
||||
// check if MR_Selected_Num is registered AND if Order->carrier eq mr_selected_method->carrier
|
||||
$mr_relay = $db->getRow('
|
||||
SELECT mr_m.`col_mode`, mr_m.`dlv_mode`, mr_s.`MR_Selected_Num`
|
||||
FROM `'._DB_PREFIX_.'mr_selected` mr_s
|
||||
LEFT JOIN `'._DB_PREFIX_.'mr_method` mr_m
|
||||
ON (mr_m.id_mr_method = mr_s.id_method)
|
||||
WHERE mr_s.`id_cart` = ' . (int) $order->id_cart . '
|
||||
AND mr_m.`id_carrier` = ' . (int) $order->id_carrier . '
|
||||
AND `MR_Selected_Num` IS NOT NULL
|
||||
');
|
||||
if ($mr_relay){
|
||||
$relay_point['code'] = (isset($mr_relay['dlv_mode']) ? $mr_relay['dlv_mode'] : false);
|
||||
$relay_point['id'] = (isset($mr_relay['MR_Selected_Num']) ? substr($mr_relay['MR_Selected_Num'], -5) : false);
|
||||
}
|
||||
}
|
||||
|
||||
// DEFAULT KEY CARRIER
|
||||
$key_carrier = $order->id_carrier . ':';
|
||||
// RELAY POINT DELIVERY
|
||||
if (isset($relay_point['code']) && $relay_point['code'])
|
||||
$key_carrier = $order->id_carrier . ':' . ((isset($relay_point['code']) && $relay_point['code']) ? $relay_point['code'] : '');
|
||||
// NOT A RELAY POINT DELIVERY : GET SALE CARRIER
|
||||
else{
|
||||
|
||||
// SALE HAVE ONLY ONE CARRIER : GET IT
|
||||
if (count($sale_carriers) == 1)
|
||||
$key_carrier = $order->id_carrier . ':' . ((isset($relay_point['code']) && $relay_point['code']) ? $relay_point['code'] : '');
|
||||
// SALE HAVE MANY CARRIERS
|
||||
elseif (count($sale_carriers) > 1){
|
||||
|
||||
// get customer groups
|
||||
$groups = $customer->getGroups();
|
||||
if (!is_array($groups) || empty($groups))
|
||||
$groups = array(1);
|
||||
|
||||
// get available carriers for delivery address
|
||||
$id_zone = (int) Db::getInstance()->getValue('
|
||||
SELECT `id_zone`
|
||||
FROM `' . _DB_PREFIX_ . 'country`
|
||||
WHERE `id_country` = ' . (int) $address_delivery->id_country);
|
||||
$carriers = Carrier::getCarriers((int)$order->id_lang, true, false, (int) $id_zone, $groups/*, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE*/);
|
||||
|
||||
// Get availbale carriers in sale_carriers
|
||||
$_carriers = array();
|
||||
foreach ($carriers as $carrier) {
|
||||
if (in_array( (int) $carrier['id_carrier'], $sale_carriers)){
|
||||
if ((int) $carrier['id_carrier'] == $order->id_carrier){
|
||||
$_carriers = array($carrier);
|
||||
break;
|
||||
}
|
||||
$_carriers[] = $carrier;
|
||||
}
|
||||
}
|
||||
// @todo find another way to get carrier
|
||||
// get first carrier
|
||||
if (count($_carriers))
|
||||
$key_carrier = (int) $_carriers[0]['id_carrier'] . ':';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## GET CARRIER VALUE
|
||||
if ($socol_relay && $relay_point['code'] && isset($socol_to_magistor[$relay_point['code']])) {
|
||||
$carrier_value = $socol_to_magistor[$relay_point['code']];
|
||||
}
|
||||
elseif ($mr_relay && $relay_point['code'] && isset($mr_to_magistor[$relay_point['code']])) {
|
||||
$carrier_value = $mr_to_magistor[$relay_point['code']];
|
||||
} else {
|
||||
if(!isset($tab_conversion_carrier[$key_carrier])) {
|
||||
$carrier_value = $socol_to_magistor['DOM']; // 'EXAPAQ_B2B'
|
||||
} else {
|
||||
$carrier_value = $tab_conversion_carrier[$key_carrier];
|
||||
}
|
||||
}
|
||||
|
||||
if ($carrier_value == 'EXAPAQ_B2B' || $carrier_value == 'EXAPAQ')
|
||||
$carrier_value = 'DPD';
|
||||
|
||||
## ASSIGN DATA
|
||||
$data .= str_pad( 'E01', 10, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $code_societe, 20, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( 'OP'.(int) $id_sale.'-'.$order->id, 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $order->id_customer, 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( date('Ymd',strtotime($order->date_add)+86400*$delai_livraison), 8, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( '', 4, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( $carrier_value , 50, ' ', STR_PAD_RIGHT );//$db->getValue('SELECT name FROM `'._DB_PREFIX_.'carrier` WHERE id_carrier = '.$order->id_carrier)
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->firstname.' '.$address_invoice->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->company),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->address1),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->address2),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_invoice->other)),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->postcode),0,8), 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->city),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( utf8_decode($db->getValue('SELECT iso_code FROM `'._DB_PREFIX_.'country` WHERE id_country = '.$address_invoice->id_country)), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( (!empty($address_invoice->phone_mobile)?$address_invoice->phone_mobile:$address_invoice->phone), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($customer->email), 0, 50), 50, ' ', STR_PAD_RIGHT );
|
||||
|
||||
if ($socol_relay && $relay_point['code'] && !in_array($relay_point['code'], array('DOM')))
|
||||
{
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->firstname.' '.$address_invoice->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
// LIVRAISON RELAIS MONDIAL RELAY
|
||||
elseif($mr_relay && $relay_point['code'] && !in_array($relay_point['code'], array('LD1', 'LDS', 'HOM'))){
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->firstname.' '.$address_invoice->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
// LIVRAISON DOMICILE
|
||||
else{
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->firstname.' '.$address_delivery->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->company),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->address1),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->address2),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_delivery->other)),0,50), 50, ' ', STR_PAD_RIGHT );//ADRESSE 3
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->postcode),0,8), 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->city),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( utf8_decode($db->getValue('SELECT iso_code FROM `'._DB_PREFIX_.'country` WHERE id_country = '.$address_delivery->id_country)), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( (!empty($address_delivery->phone_mobile)?$address_delivery->phone_mobile:$address_delivery->phone), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
// LIVRAISON SOCOL
|
||||
if ($socol_relay && $relay_point['code']){
|
||||
// SOCOL DOMICILE
|
||||
if (in_array($relay_point['code'], array('DOM'))){
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->firstname.' '.$address_delivery->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->company),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
else{
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->firstname.' '.$address_invoice->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->address1),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->address2),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_delivery->other)),0,50), 50, ' ', STR_PAD_RIGHT );//ADRESSE 3
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->postcode),0,8), 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->city),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( utf8_decode($db->getValue('SELECT iso_code FROM `'._DB_PREFIX_.'country` WHERE id_country = '.$address_delivery->id_country)), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( (isset($address_delivery->phone_mobile)?$address_delivery->phone_mobile:$address_delivery->phone), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
// LIVRAISON MONDIAL RELAY
|
||||
elseif ($mr_relay && $relay_point['code']){
|
||||
// MR DOMICILE
|
||||
if (in_array($relay_point['code'], array('LD1', 'LDS', 'HOM'))){
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->firstname.' '.$address_delivery->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->company),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
else{
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_invoice->firstname.' '.$address_invoice->lastname),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->address1),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->address2),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($address_delivery->other)),0,50), 50, ' ', STR_PAD_RIGHT );//ADRESSE 3
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->postcode),0,8), 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( substr(utf8_decode($address_delivery->city),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( utf8_decode($db->getValue('SELECT iso_code FROM `'._DB_PREFIX_.'country` WHERE id_country = '.$address_delivery->id_country)), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( (isset($address_delivery->phone_mobile)?$address_delivery->phone_mobile:$address_delivery->phone), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
// LIVRAISON DOMICILE
|
||||
else{
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//ADRESSE 3
|
||||
$data .= str_pad( '', 8, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );
|
||||
}
|
||||
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_1
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_2
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_3
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_4
|
||||
$data .= str_pad( ($relay_point['id']?$relay_point['id']:''), 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_5
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_6
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_7
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );//INFO_RELAIS_8
|
||||
if(Configuration::get('PHILEA_MAGISTOR_ASSURANCE') AND Configuration::get('PHILEA_MAGISTOR_ASSURANCE') <= ($order->total_paid_real - $order->total_shipping) AND Configuration::get('PHILEA_MAGISTOR_ASSURANCE') > 0)
|
||||
$data .= str_pad( str_replace('.',',',($order->total_paid_real - $order->total_shipping)), 50, ' ', STR_PAD_RIGHT ); // VALEUR DE COMMANDE
|
||||
else
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT ); // VALEUR DE COMMANDE
|
||||
$data .= str_pad( '', 50, ' ', STR_PAD_RIGHT );// ZONE_10
|
||||
$data .= str_pad( utf8_decode(cleanChar($address_delivery->other)), 400, ' ', STR_PAD_RIGHT );
|
||||
$data .= PHP_EOL;
|
||||
$products = $order->getProducts();
|
||||
|
||||
$nb_ligne = 0;
|
||||
foreach($products as $product)
|
||||
{
|
||||
$productObj = new Product($product['product_id']);
|
||||
|
||||
// ANTADIS
|
||||
$product_shipping = (int) Db::getInstance()->getValue('
|
||||
SELECT s.`id_shipping`
|
||||
FROM `'._DB_PREFIX_.'product_ps_cache` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` s
|
||||
ON s.`id_sale` = c.`id_sale`
|
||||
WHERE c.`id_product` = '.(int) $productObj->id.'
|
||||
AND s.`id_sale` = '.(int) $id_sale.'
|
||||
');
|
||||
//
|
||||
|
||||
if($product_shipping === $_id_shipping)
|
||||
{
|
||||
$nb_ligne++;
|
||||
|
||||
$ean = !empty($product['product_ean13'])? $product['product_ean13']: substr($product['product_supplier_reference'],0 ,13);
|
||||
if($code_societe == 78) {
|
||||
$ref = !empty($product['product_ean13'])? $product['product_ean13']: $product['product_supplier_reference'];
|
||||
} else {
|
||||
$ref = ($product['product_attribute_id']?$product['product_id'].'_'.$product['product_attribute_id']:$product['product_id']);
|
||||
}
|
||||
|
||||
$data .= str_pad( 'L01', 10, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( 'OP'.(int) $id_sale.'-'.$order->id, 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $nb_ligne, 4, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( $ref, 50, ' ', STR_PAD_RIGHT ); //$product['product_supplier_reference'], 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0), 8, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( substr(utf8_decode(cleanChar($product['product_name'])),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( str_replace(array("\r", "\n"), "", $ean), 14, ' ', STR_PAD_LEFT );
|
||||
$data .= PHP_EOL;
|
||||
}
|
||||
else
|
||||
$partialOrder = true;
|
||||
}
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_magistor_sent`
|
||||
VALUES (
|
||||
'.(int) $order->id.',
|
||||
'.(int) $id_sale.',
|
||||
NOW()
|
||||
)
|
||||
');
|
||||
} //End if nbproducts
|
||||
}//End foreach
|
||||
|
||||
|
||||
if($orders and is_array($orders))
|
||||
{
|
||||
file_put_contents($fileName . '.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
||||
file_put_contents($fileName . '.BAL', '');
|
||||
|
||||
file_put_contents($fileArchive . '.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
||||
|
||||
require_once('connection_ftp.php');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cleanChar($string)
|
||||
{
|
||||
$string = str_replace(chr(13),' ',$string);
|
||||
$string = str_replace(chr(10),' ',$string);
|
||||
$string = str_replace(chr(13).chr(10),' ',$string);
|
||||
$string = str_replace(chr(10).chr(13),' ',$string);
|
||||
return $string;
|
||||
|
||||
}
|
||||
$string = str_replace("\r\n",' ',$string);
|
||||
$string = str_replace("\r",' ',$string);
|
||||
$string = str_replace("\r",' ',$string);
|
||||
$string = str_replace("\n",' ',$string);
|
||||
$string = str_replace("\n",' ',$string);
|
||||
$string = str_replace(array('®', '©', '™'), array('', '' ,''), $string);
|
||||
$string = str_replace(
|
||||
array('"', 'ľ', '°', 'º', 'ª', 'Á', '°', 'º', 'º', 'º', 'ª', "\t", "\n", "\r", ' ', '–', '', $unicode_0, $unicode_1, '«', '»',),
|
||||
array('', 'l\'', '.', '.', '.', 'A', '', '', '', '', 'a', ' ', ' ', ' ', ' ', '-', '', '', '', '', '',),
|
||||
$string
|
||||
);
|
||||
return str_replace(array('°', 'º', 'ª', '&', ';'), '', $string);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user