2017-10-19 15:40:22 +02:00
< ? php
$_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 ];
$_id_shipping = 1 ; // philea
if ( $id_sale == 0 ) {
exit ;
}
$dateNow = date ( 'ymdHis' );
$multi = array ();
$magistorModule = new philea_magistor ();
$id_lang = Configuration :: get ( 'PS_LANG_DEFAULT' );
$tab_conversion_carrier = philea_magistor :: getTabState ();
$socol_to_magistor = array (
'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
);
$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 ;
$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_sent` pms ON ( pms . `id_sale` = c . `id_sale` AND pms . `id_order` = o . `id_order` )
WHERE o . `id_order_state` IN ( 2 , 3 , 12 , 13 , 17 )
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 ;
}
2017-11-13 12:05:56 +01:00
$exclude_orders = array ();
2017-10-19 15:40:22 +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'];
// }
$orders = $db -> ExecuteS ( '
SELECT * FROM `'._DB_PREFIX_.'orders`
WHERE `date_add` > " 2017-10-30 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).' ) ': ' ').'
' );
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' ));
}
$delai_livraison = 2 ; //(int)(Configuration::get('PHILEA_MAGISTOR_DELAI_LIVRAISON'));
//@TODO rendre configurable le champs "reference" entre "reference" et "ean13"
$referenceField = 'reference' ; //Configuration::get('PHILEA_MAGISTOR_REF_FIELD');
$fileName = dirname ( __FILE__ ) . '/OUT/CDC02' . $dateNow ;
$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 ) {
$order = new Order ( $o [ 'id_order' ]);
$sales = array ();
$sales [( int ) $id_sale ] = ( int ) $id_sale ;
$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 ) {
2017-11-13 12:05:56 +01:00
$carriers_socol = explode ( ',' , Configuration :: get ( 'ANT_CARRIERS_SOCOL' ));
$carriers_mr = explode ( ',' , Configuration :: get ( 'ANT_CARRIERS_MR' ));
2017-10-19 15:40:22 +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` != " "
' );
/* SOCOL */
if ( $delivery_info ) {
if ( $delivery_info [ 'cecountry' ] != 'FR' ) {
$carrier_value = $socol_to_magistor [ 'DOMINTER' ];
} else {
$carrier_value = $socol_to_magistor [ $delivery_info [ 'delivery_mode' ]];
}
$prid = $delivery_info [ 'prid' ];
}
} 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 );
}
}
if ( ! $carrier_value ) {
if (( int ) $address_delivery -> id_country == 8 ) {
$carrier_value = $tab_conversion_carrier [ $order -> id_carrier . ':' ];
} else {
$carrier_value = $socol_to_magistor [ 'DOMINTER' ];
}
}
## 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 );
$data .= str_pad ( substr ( utf8_decode ( cleanChar ( $address_invoice -> firstname . ' ' . $address_invoice -> lastname )), 0 , 50 ), 50 , ' ' , STR_PAD_RIGHT );
if ( in_array (( int ) $order -> id_carrier , $carriers_mr )
&& $delivery_info
&& ! in_array ( $delivery_info [ 'dlv_mode' ], array ( 'LD1' , 'LDS' , 'HOM' ))
) {
// no company name for a delivery in relay point
$data .= str_pad ( '' , 50 , ' ' , STR_PAD_RIGHT );
} else {
$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 );
// LIVRAISON DOMICILE SOCOL
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 );
}
// LIVRAISON DOMICILE MONDIAL RELAY
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 ( 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 );
}
// LIVRAISON MR (NO DOMICILE)
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 ( cleanChar ( $address_delivery -> firstname . ' ' . $address_delivery -> lastname )), 0 , 50 ), 50 , ' ' , STR_PAD_RIGHT );
// no company name for a delivery in relay point
$data .= str_pad ( '' , 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 );
}
$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 (( 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 ( 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 ( 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 ( $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 ( $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
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 ;
$product_packs = array ();
$product_rows = array ();
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 ;
}
/**
* @ Override get pack items
*/
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' ];
$p_key = $pack_item [ 'id_product' ];
if ( ! isset ( $product_rows [ $p_key ])) {
$product_rows [ $p_key ] = array (
str_replace ( array ( " \r " , " \n " ), '' , $ref ),
0 ,
substr ( utf8_decode ( cleanChar ( $pack_item [ 'name' ])), 0 , 50 ),
substr ( str_replace ( array ( " \r " , " \n " ), " " , $ean ), 0 , 14 )
);
}
$product_rows [ $p_key ][ 1 ] += ( max ( $product [ 'product_quantity' ] - max ( $product [ 'product_quantity_return' ], $product [ 'product_quantity_refunded' ]), 0 ) * $pack_item [ 'pack_quantity' ]);
}
} else {
$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' ]);
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 ),
substr ( str_replace ( array ( " \r " , " \n " ), " " , $ean ), 0 , 14 ),
);
}
$product_rows [ $p_key ][ 1 ] += max ( $product [ 'product_quantity' ] - max ( $product [ 'product_quantity_return' ], $product [ 'product_quantity_refunded' ]), 0 );
}
}
// Add products to data
$nb_ligne = 0 ;
foreach ( $product_rows as $p_key => $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 ;
}
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 ;
}
} //End if nbproducts
} //End foreach
if ( $orders and is_array ( $orders ))
{
$file = 'CDC02' . $dateNow . '.DAT' ;
Db :: getInstance () -> Execute ( '
INSERT INTO `'._DB_PREFIX_.'philea_syncreport` ( `id_sale` , `filename` , `date_add` )
VALUES (
'.(int)$id_sale.' ,
" '.pSQL( $file ).' " ,
NOW ()
)
' );
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 );
}