2016-09-06 15:32:52 +02:00
< ? php
2016-09-06 16:48:13 +02:00
$_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' );
ini_set ( 'memory_limit' , '4G' );
$id_sale = ( int ) $argv [ 1 ];
2016-11-23 12:57:33 +01:00
$_id_shipping = 1 ; // philea
2016-09-06 16:48:13 +02:00
if ( $id_sale == 0 ) {
exit ;
}
2016-10-25 09:34:32 +02:00
$dateNow = date ( 'ymdHis' );
2016-11-30 11:35:55 +01:00
$multi = array ();
2016-09-06 16:48:13 +02:00
$magistorModule = new philea_magistor ();
$id_lang = Configuration :: get ( 'PS_LANG_DEFAULT' );
$tab_conversion_carrier = philea_magistor :: getTabState ();
$socol_to_magistor = array (
2016-12-08 12:31:06 +01:00
'DOMINTER' => 'COLINT' , // Livraison internationnale à domicile
'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
2016-09-06 16:48:13 +02:00
);
$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 );
$db = Db :: getInstance ();
$id_order_state = 2 ;
2016-09-28 16:56:19 +02:00
// for dev
// $include_orders = array();
// foreach($db->ExecuteS('
// SELECT DISTINCT d.`id_order`
// FROM `'._DB_PREFIX_.'order_detail` d
// LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON d.`product_id` = c.`id_product`
// LEFT JOIN `'._DB_PREFIX_.'philea_sent` pms ON (pms.`id_sale` = c.`id_sale` AND pms.`id_order` = d.`id_order`)
// LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = d.`id_order`)
// WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = d.`id_order` GROUP BY moh.`id_order`)
// AND oh.`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'];
// }
2016-09-06 16:48:13 +02:00
$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`
2016-09-07 11:42:38 +02:00
LEFT JOIN `'._DB_PREFIX_.'philea_sent` pms ON ( pms . `id_sale` = c . `id_sale` AND pms . `id_order` = o . `id_order` )
2016-11-30 11:35:55 +01:00
WHERE o . `id_order_state` IN ( 2 , 3 , 12 , 13 , 17 )
2016-09-06 16:48:13 +02:00
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' ];
}
if ( count ( $include_orders ) == 0 ) {
exit ;
}
$exclude_orders = array ();
2016-10-20 09:43:37 +02:00
foreach ( $db -> ExecuteS ( '
SELECT DISTINCT `id_order`
FROM `'._DB_PREFIX_.'philea_sent`
WHERE `id_sale` = '.(int) $id_sale.'
' ) as $row ) {
$exclude_orders [] = ( int ) $row [ 'id_order' ];
}
2016-09-06 16:48:13 +02:00
$orders = $db -> ExecuteS ( '
SELECT * FROM `'._DB_PREFIX_.'orders`
2016-12-26 14:58:42 +01:00
WHERE `date_add` > " 2016-12-20 00:00:00 "
2016-09-06 16:48:13 +02:00
'.(count($exclude_orders) > 0? ' AND `id_order` NOT IN ( '.implode(' , ', $exclude_orders).' ) ': ' ').'
'.(count($include_orders) > 0? ' AND `id_order` IN ( '.implode(' , ', $include_orders).' ) ': ' ').'
' );
if ( count ( $orders ) == 0 ) {
exit ;
}
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' ));
}
2016-09-07 16:17:03 +02:00
$delai_livraison = 2 ; //(int)(Configuration::get('PHILEA_MAGISTOR_DELAI_LIVRAISON'));
2016-09-06 16:48:13 +02:00
//@TODO rendre configurable le champs "reference" entre "reference" et "ean13"
$referenceField = 'reference' ; //Configuration::get('PHILEA_MAGISTOR_REF_FIELD');
2016-10-21 13:39:56 +02:00
$fileName = dirname ( __FILE__ ) . '/OUT/CDC02' . $dateNow ;
2016-09-06 16:48:13 +02:00
$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' ]);
2016-11-30 11:35:55 +01:00
$sales = array ();
$sales [( int ) $id_sale ] = ( int ) $id_sale ;
// ANTADIS - check if multi and order already sent
$other_sales = Db :: getInstance () -> getValue ( '
SELECT COUNT ( `id_sale` )
FROM `'._DB_PREFIX_.'philea_sent`
WHERE `id_order` = '.(int) $o[' id_order '].'
' );
if ( $other_sales > 0 ){
// order already sent to philea
continue ;
}
2016-09-06 16:48:13 +02:00
$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 );
2017-01-11 10:54:50 +01:00
//$carriers_mr = array(90); // fake data
2017-01-02 12:25:33 +01:00
2016-09-06 16:48:13 +02:00
$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` != " "
' );
2017-01-02 12:25:33 +01:00
/* SOCOL */
2016-09-06 16:48:13 +02:00
if ( $delivery_info ) {
2016-12-08 12:31:06 +01:00
if ( $delivery_info [ 'cecountry' ] != 'FR' ) {
$carrier_value = $socol_to_magistor [ 'DOMINTER' ];
} else {
$carrier_value = $socol_to_magistor [ $delivery_info [ 'delivery_mode' ]];
}
2016-09-06 16:48:13 +02:00
$prid = $delivery_info [ 'prid' ];
}
}
2017-01-11 10:54:50 +01:00
//elseif(in_array((int) $order->id_carrier, $carriers_mr) {
// /* MONDIAL RELAY */
// $delivery_info = $db->getRow('
// SELECT mr_m.`col_mode`, mr_m.`dlv_mode`, mr_s.*
// 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($delivery_info) {
// $carrier_value = $mr_to_magistor[$delivery_info['dlv_mode']];
// $prid = substr($delivery_info['MR_Selected_Num'], -5);
// }
// }
2016-09-06 16:48:13 +02:00
2017-01-02 12:25:33 +01:00
2016-09-06 16:48:13 +02:00
if ( ! $carrier_value ) {
2016-12-08 12:31:06 +01:00
if (( int ) $address_delivery -> id_country == 8 ) {
$carrier_value = $tab_conversion_carrier [ $order -> id_carrier . ':' ];
} else {
$carrier_value = $socol_to_magistor [ 'DOMINTER' ];
}
2016-09-06 16:48:13 +02:00
}
/* 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 ( 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 );
2017-01-02 12:25:33 +01:00
// LIVRAISON DOMICILE SOCOL
2016-09-06 16:48:13 +02:00
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 );
2017-01-02 12:25:33 +01:00
}
// LIVRAISON DOMICILE MONDIAL RELAY
2017-01-11 10:54:50 +01:00
// elseif(in_array((int) $order->id_carrier, $carriers_mr)
// && $delivery_info
// && in_array($delivery_info['dlv_mode'], array('LD1', 'LDS', 'HOM'))
// ) {
// $data .= str_pad(substr(utf8_decode(cleanChars($address_delivery->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
// $data .= str_pad(substr(utf8_decode(cleanChars($address_invoice->firstname.' '.$address_invoice->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
// }
2017-01-02 12:25:33 +01:00
else {
2016-09-06 16:48:13 +02:00
$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 );
}
$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 );
2016-09-08 12:40:32 +02:00
$data .= str_pad (( isset ( $address_delivery -> phone_mobile ) ? $address_delivery -> phone_mobile : $address_delivery -> phone ), 50 , ' ' , STR_PAD_RIGHT );
2016-09-06 16:48:13 +02:00
$data .= str_pad ( '' , 50 , ' ' , STR_PAD_RIGHT );
}
2017-01-02 12:25:33 +01:00
// LIVRAISON MONDIAL RELAY
2017-01-11 10:54:50 +01:00
// elseif (in_array((int) $order->id_carrier, $carriers_mr) && $delivery_info) {
// // MR DOMICILE
// if (in_array($delivery_info['dlv_mode'], array('LD1', 'LDS', 'HOM'))){
// $data .= str_pad( substr(utf8_decode(cleanChars($address_delivery->firstname.' '.$address_delivery->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
// $data .= str_pad( substr(utf8_decode(cleanChars($address_delivery->company)), 0, 50), 50, ' ', STR_PAD_RIGHT);
// } else {
// $data .= str_pad( substr(utf8_decode(cleanChars($address_delivery->lastname)), 0, 50), 50, ' ', STR_PAD_RIGHT);
// $data .= str_pad( substr(utf8_decode(cleanChars($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 );
// }
2016-09-06 16:48:13 +02:00
// 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 ( $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
2016-09-07 11:42:38 +02:00
if ( Configuration :: get ( 'PHILEA_MAGISTOR_ASSURANCE' )
&& Configuration :: get ( 'PHILEA_MAGISTOR_ASSURANCE' ) <= ( $order -> total_paid_real - $order -> total_shipping )
2016-09-06 16:48:13 +02:00
&& 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 ;
2016-11-23 12:57:33 +01:00
$product_packs = array ();
$product_rows = array ();
2016-09-06 16:48:13 +02:00
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 '].'
' )) {
2016-11-30 11:35:55 +01:00
$other_sale_id = Db :: getInstance () -> getValue ( '
SELECT `id_sale`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` = '.(int) $product[' product_id '].'
' );
$sales [( int ) $other_sale_id ] = ( int ) $other_sale_id ;
2016-09-06 16:48:13 +02:00
}
2016-11-23 12:57:33 +01:00
/**
* @ Override get pack items
*/
2016-12-02 15:34:57 +01:00
if ( Pack :: isPack (( int ) $product [ 'product_id' ])) {
$pack_items = Pack :: getCompleteSimplePack (( int ) $product [ 'product_id' ]);
foreach ( $pack_items as $pack_item ) {
$ean = ! empty ( $pack_item [ 'ean13' ]) ? $pack_item [ 'ean13' ] : $pack_item [ 'supplier_reference' ];
$ref = $pack_item [ 'id_product' ];
2016-12-08 13:25:39 +01:00
$p_key = $pack_item [ 'id_product' ];
if ( ! isset ( $product_rows [ $p_key ])) {
$product_rows [ $p_key ] = array (
2016-12-02 15:34:57 +01:00
str_replace ( array ( " \r " , " \n " ), '' , $ref ),
0 ,
substr ( utf8_decode ( cleanChar ( $pack_item [ 'name' ])), 0 , 50 ),
str_replace ( array ( " \r " , " \n " ), " " , $ean )
);
2016-11-23 12:57:33 +01:00
}
2016-12-08 13:25:39 +01:00
$product_rows [ $p_key ][ 1 ] += ( max ( $product [ 'product_quantity' ] - max ( $product [ 'product_quantity_return' ], $product [ 'product_quantity_refunded' ]), 0 ) * $pack_item [ 'pack_quantity' ]);
2016-11-23 12:57:33 +01:00
}
} else {
2016-12-02 15:34:57 +01:00
$ean = ! empty ( $product [ 'product_ean13' ]) ? $product [ 'product_ean13' ] : $product [ 'product_supplier_reference' ];
$ref = ( $product [ 'product_attribute_id' ] ? $product [ 'product_id' ] . '_' . $product [ 'product_attribute_id' ] : $product [ 'product_id' ]);
$p_key = ( $product [ 'product_attribute_id' ] ? $product [ 'product_id' ] . '_' . $product [ 'product_attribute_id' ] : $product [ 'product_id' ]);
2016-12-08 13:25:39 +01:00
if ( ! isset ( $product_rows [ $p_key ])) {
$product_rows [ $p_key ] = array (
str_replace ( array ( " \r " , " \n " ), '' , $ref ),
0 ,
substr ( utf8_decode ( cleanChar ( $product [ 'product_name' ])), 0 , 50 ),
str_replace ( array ( " \r " , " \n " ), " " , $ean ),
);
}
$product_rows [ $p_key ][ 1 ] += max ( $product [ 'product_quantity' ] - max ( $product [ 'product_quantity_return' ], $product [ 'product_quantity_refunded' ]), 0 );
2016-11-23 12:57:33 +01:00
}
}
2016-09-06 16:48:13 +02:00
2016-11-23 12:57:33 +01:00
// Add products to data
$nb_ligne = 0 ;
foreach ( $product_rows as $p_key => $product ) {
2016-09-06 16:48:13 +02:00
$nb_ligne ++ ;
$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 );
2016-11-23 12:57:33 +01:00
$data .= str_pad ( $product [ 0 ], 50 , ' ' , STR_PAD_RIGHT ); // ref
$data .= str_pad ( $product [ 1 ], 8 , '0' , STR_PAD_LEFT ); // quantity
$data .= str_pad ( $product [ 2 ], 50 , ' ' , STR_PAD_RIGHT ); // product name
$data .= str_pad ( $product [ 3 ], 14 , ' ' , STR_PAD_LEFT ); // ean
2016-09-06 16:48:13 +02:00
$data .= PHP_EOL ;
}
2016-11-23 12:57:33 +01:00
// Add pack items to data
2016-12-08 13:25:39 +01:00
// foreach ($product_packs as $product) {
// $nb_ligne ++;
// $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( $product[0], 50, ' ', STR_PAD_RIGHT ); // ref
// $data .= str_pad( $product[1], 8, '0', STR_PAD_LEFT ); // quantity
// $data .= str_pad( $product[2], 50, ' ', STR_PAD_RIGHT ); // product name
// $data .= str_pad( $product[3], 14, ' ', STR_PAD_LEFT ); // ean
// $data .= PHP_EOL;
// }
2016-09-06 16:48:13 +02:00
2016-11-30 11:35:55 +01:00
foreach ( $sales as $key => $sale_id ) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'philea_sent`
VALUES (
'.(int) $order->id.' ,
'.(int) $sale_id.' ,
NOW ()
)
' );
}
if ( count ( $sales ) > 1 ) {
$multi [] = ( int ) $order -> id ;
}
2016-09-06 16:48:13 +02:00
} //End if nbproducts
} //End foreach
if ( $orders and is_array ( $orders ))
{
2016-10-25 09:34:32 +02:00
$file = 'CDC02' . $dateNow . '.DAT' ;
2016-10-21 13:39:56 +02:00
Db :: getInstance () -> Execute ( '
INSERT INTO `'._DB_PREFIX_.'philea_syncreport` ( `id_sale` , `filename` , `date_add` )
VALUES (
'.(int)$id_sale.' ,
2016-10-25 09:34:32 +02:00
" '.pSQL( $file ).' " ,
2016-10-21 13:39:56 +02:00
NOW ()
)
' );
2016-11-30 11:38:16 +01:00
if ( ! empty ( $multi )) {
mail ( 'marion@antadis.com' , '[BBB] Philea - Send command with multi' , 'multi : ' . implode ( ',' , $multi ) . ' - file : ' . $file ); // log multi
} else {
mail ( 'marion@antadis.com' , '[BBB] Philea - Send command without multi' , 'Pas de multi - file : ' . $file ); // log multi
}
2016-09-06 16:48:13 +02:00
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 ) {
$unicode_0 = json_decode ( '"\u0006"' );
$unicode_1 = json_decode ( '"\u200b"' );
$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 );
}