442 lines
22 KiB
PHP
442 lines
22 KiB
PHP
<?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_sale = 3966;
|
||
echo $id_sale."\n";
|
||
$_id_shipping = 1; // philea
|
||
|
||
if($id_sale == 0) {
|
||
exit;
|
||
}
|
||
$dateNow = date('ymdHis');
|
||
|
||
$magistorModule = new philea_magistor();
|
||
$id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||
|
||
$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
|
||
);
|
||
|
||
$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;
|
||
|
||
// 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'];
|
||
// }
|
||
|
||
$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'];
|
||
}
|
||
echo '<pre>';var_dump($include_orders);echo "</pre>\n";
|
||
|
||
if(count($include_orders) == 0) {
|
||
exit;
|
||
}
|
||
|
||
$exclude_orders = array();
|
||
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` > "2016-09-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/';
|
||
echo $repo_archive."\n";
|
||
$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');
|
||
echo '<pre>';var_dump($orders);echo "</pre>\n";
|
||
$data = '';
|
||
foreach($orders as $o) {
|
||
$partialOrder = false;
|
||
$order = new Order($o['id_order']);
|
||
|
||
$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;
|
||
}
|
||
|
||
$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.':'];
|
||
}
|
||
|
||
|
||
/*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 );
|
||
|
||
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);
|
||
}
|
||
|
||
$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 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();
|
||
echo '<pre>';var_dump($products);echo "</pre>\n";
|
||
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'].'
|
||
')) {
|
||
$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;
|
||
}
|
||
/**
|
||
* @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 = (int) $pack_item['id_product'];
|
||
if (!isset($product_packs[$p_key])) {
|
||
$product_packs[$p_key] = array(
|
||
str_replace(array("\r", "\n"), '', $ref),
|
||
0,
|
||
substr(utf8_decode(cleanChar($pack_item['name'])),0,50),
|
||
str_replace(array("\r", "\n"), "", $ean)
|
||
);
|
||
}
|
||
$product_packs[$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']);
|
||
$product_rows[(int) $p_key] = array(
|
||
str_replace(array("\r", "\n"), '', $ref),
|
||
max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0),
|
||
substr(utf8_decode(cleanChar($product['product_name'])),0,50),
|
||
str_replace(array("\r", "\n"), "", $ean),
|
||
);
|
||
}
|
||
}
|
||
|
||
// 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;
|
||
}
|
||
// Add pack items to data
|
||
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;
|
||
}
|
||
|
||
foreach ($sales as $key => $sale_id) {
|
||
Db::getInstance()->ExecuteS('
|
||
INSERT INTO `'._DB_PREFIX_.'philea_sent`
|
||
VALUES (
|
||
'.(int) $order->id.',
|
||
'.(int) $sale_id.',
|
||
NOW()
|
||
)
|
||
');
|
||
}
|
||
} //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);
|
||
}
|