Merge branch 'master' of git@gitlab.antadis.net:dev-antadis/bebeboutik.git
This commit is contained in:
commit
c261d04612
@ -30,6 +30,9 @@ class Catalog
|
||||
|
||||
public function setContent($version = 'fr')
|
||||
{
|
||||
// Flush to load the good sales
|
||||
CacheRedis::getInstance()->clear('sale*');
|
||||
|
||||
$test_for_tomorrow = (int)Tools::getValue('tomorrow',0);
|
||||
|
||||
$sales_today = array();
|
||||
|
@ -813,7 +813,7 @@ class AdminLogistics extends AdminTab {
|
||||
for(var i=0; i < loaded.logs.length; i++) {
|
||||
content += \'<tr>\
|
||||
<td>\' + loaded.logs[i].date_add + \'</td>\
|
||||
<td>\' + (loaded.logs[i].firstname == "Dropshipping"? "Dropshipping" : loaded.logs[i].firstname + \' \' + loaded.logs[i].lastname) + \'</td>\
|
||||
<td>\' + (loaded.logs[i].lastname == undefined? loaded.logs[i].firstname : loaded.logs[i].firstname + \' \' + loaded.logs[i].lastname) + \'</td>\
|
||||
<td>\' + loaded.logs[i].quantity + \'</td>\
|
||||
<td>\' + loaded.logs[i].product_name.replace(" - ", "<br />") + \'</td>\
|
||||
<td>\' + loaded.logs[i].product_reference + \'</td>\
|
||||
|
@ -227,24 +227,40 @@ if(($id_order = (int) Tools::getValue('id_order'))
|
||||
$link = new Link(2);
|
||||
$products = array();
|
||||
foreach($order->getProductsDetail() as $p) {
|
||||
$p['product_quantity_sent'] = (int) Db::getInstance()->getValue('
|
||||
SELECT IFNULL(SUM(`quantity`), 0) AS `total`
|
||||
$p['product_quantity_sent'] += (int) Db::getInstance()->getValue('
|
||||
SELECT IFNULL(SUM(`quantity`), 0)
|
||||
FROM `'._DB_PREFIX_.'lapostews`
|
||||
WHERE `id_order_detail` = '.(int) $p['id_order_detail'].'
|
||||
') + (int) Db::getInstance()->getValue('
|
||||
SELECT IFNULL(SUM(`quantity`), 0) AS `total`
|
||||
');
|
||||
$p['product_quantity_sent'] += (int) Db::getInstance()->getValue('
|
||||
SELECT IFNULL(SUM(`quantity`), 0)
|
||||
FROM `'._DB_PREFIX_.'exapaqws`
|
||||
WHERE `id_order_detail` = '.(int) $p['id_order_detail'].'
|
||||
');
|
||||
|
||||
/**
|
||||
* @Override MondialRelay
|
||||
*/
|
||||
$p['product_quantity_sent'] += (int) Db::getInstance()->getValue('
|
||||
SELECT IFNULL(SUM(`quantity`), 0) AS `total`
|
||||
SELECT IFNULL(SUM(`quantity`), 0)
|
||||
FROM `'._DB_PREFIX_.'mondialrelay_parcel`
|
||||
WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . '
|
||||
');
|
||||
/**
|
||||
* @Override Philea
|
||||
*/
|
||||
$p['product_quantity_sent'] += (int) Db::getInstance()->getValue('
|
||||
SELECT IFNULL(SUM(`quantity`), 0)
|
||||
FROM `'._DB_PREFIX_.'philea_parcel`
|
||||
WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . '
|
||||
');
|
||||
/**
|
||||
* @Override Dropshipping
|
||||
*/
|
||||
$p['product_quantity_sent'] += (int) Db::getInstance()->getValue('
|
||||
SELECT IFNULL(SUM(`quantity`), 0)
|
||||
FROM `'._DB_PREFIX_.'ant_dropshipping_parcel`
|
||||
WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . '
|
||||
');
|
||||
|
||||
$p['id_image'] = 0;
|
||||
|
||||
@ -345,6 +361,18 @@ if(($id_order = (int) Tools::getValue('id_order'))
|
||||
') as $row) {
|
||||
$shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"';
|
||||
}
|
||||
/*
|
||||
* @Override Philea
|
||||
*/
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT l.`shipping_number`
|
||||
FROM `'._DB_PREFIX_.'philea_parcel` l
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = l.`id_order_detail`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h ON (h.`id_order` = d.`id_order`)
|
||||
WHERE h.`id_order` = '.(int) $order->id.'
|
||||
') as $row) {
|
||||
$shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"';
|
||||
}
|
||||
|
||||
if(((int) $p['product_quantity_sent'] === 0)
|
||||
&& Db::getInstance()->getRow('
|
||||
@ -427,6 +455,21 @@ if(($id_order = (int) Tools::getValue('id_order'))
|
||||
')) {
|
||||
$logs = array_merge($logs, $l);
|
||||
}
|
||||
/*
|
||||
* @Override Philea
|
||||
*/
|
||||
if($l = Db::getInstance()->ExecuteS('
|
||||
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, "Philea" as firstname, c.`name` as carrier
|
||||
FROM `'._DB_PREFIX_.'philea_parcel` l
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail`
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`
|
||||
LEFT JOIN `'._DB_PREFIX_.'carrier` c ON c.`id_carrier` = o.`id_carrier`
|
||||
WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).')
|
||||
AND l.`quantity` > 0
|
||||
ORDER BY l.`date_add` DESC
|
||||
')) {
|
||||
$logs = array_merge($logs, $l);
|
||||
}
|
||||
} else {
|
||||
$logs = array();
|
||||
}
|
||||
|
@ -10,7 +10,25 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
static $_crrlist_cache = NULL;
|
||||
|
||||
public function postProcess() {
|
||||
if(Tools::isSubmit('submitProductSaleCache')) {
|
||||
if(Tools::getIsset('send_to_philea') && Tools::getValue('id_sale')) {
|
||||
$id_sale = (int)Tools::getValue('id_sale');
|
||||
if(Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'philea_sync`
|
||||
WHERE `id_sale` = '.(int) $id_sale.'
|
||||
AND `status` = 7
|
||||
')) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'philea_sync`
|
||||
SET `status` = 8
|
||||
WHERE id_sale = '.(int) $id_sale.'
|
||||
LIMIT 1
|
||||
');
|
||||
echo '<p class="conf">'.$this->l('CDC for this Sale added to queue successfully').'</p><br />';
|
||||
} else {
|
||||
echo '<p class="error">'.$this->l('Sale is not ready').'</p><br />';
|
||||
}
|
||||
} elseif(Tools::isSubmit('submitProductSaleCache')) {
|
||||
global $cookie;
|
||||
$fileName = 'cron_sale_cache.php';
|
||||
$output = shell_exec("ps -ax | grep $fileName | wc -l");
|
||||
@ -167,6 +185,37 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
$filename = Tools::getValue('filename');
|
||||
$this->exportCsv((int) $id_sale, $filename);
|
||||
}
|
||||
elseif(Tools::isSubmit('addNoPhileaSale') && Tools::getValue('id_sale')){
|
||||
$id_sale = (int) Tools::getValue('id_sale');
|
||||
$existing_id = Db::getInstance()->getValue('
|
||||
SELECT `id_sale`
|
||||
FROM `'._DB_PREFIX_.'privatesale`
|
||||
WHERE `id_sale` = '.(int) $id_sale.'
|
||||
');
|
||||
if($id_sale && $id_sale == (int)$existing_id) {
|
||||
if(!Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'philea_sync`
|
||||
WHERE `id_sale` = '.(int) $id_sale.'
|
||||
')) {
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_sync`
|
||||
VALUES (
|
||||
DEFAULT,
|
||||
'.(int) $id_sale.',
|
||||
5,
|
||||
NOW(),
|
||||
0
|
||||
)
|
||||
');
|
||||
echo '<p class="conf">'.$this->l('Sale added to queue successfully').'</p><br />';
|
||||
} else {
|
||||
echo '<p class="error">'.$this->l('Sync already in progress for this sale').'</p><br />';
|
||||
}
|
||||
} else {
|
||||
echo '<p class="error">'.$this->l('Invalid sale id').'</p><br />';
|
||||
}
|
||||
}
|
||||
elseif(Tools::isSubmit('philea_archive_submit')){
|
||||
$id_sales = Tools::getValue('id_sales');
|
||||
if (count($id_sales)){
|
||||
@ -405,6 +454,9 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
.table td .button{
|
||||
padding: 5px 2px;
|
||||
}
|
||||
.table td i.glyphicon{
|
||||
margin-right: 8px;
|
||||
}
|
||||
.div_report_overlay{
|
||||
background: rgb(181,189,200); /* Old browsers */
|
||||
background: -moz-linear-gradient(top, rgba(181,189,200,0.4) 0%, rgba(130,140,149,0.4) 36%, rgba(40,52,59,0.4) 100%); /* FF3.6+ */
|
||||
@ -478,6 +530,23 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
);
|
||||
}
|
||||
|
||||
$id_non_philea_sales = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT p.`id_sale`, c.`name`, c.`id_category`
|
||||
FROM `'._DB_PREFIX_.'privatesale` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = p.`id_category`)
|
||||
WHERE c.`id_lang` = '.$cookie->id_lang.'
|
||||
AND p.`id_sale` NOT IN ('.implode(',',$philea_sales).')
|
||||
AND p.`date_start` > DATE_SUB(NOW(), INTERVAL 3 MONTH)
|
||||
ORDER BY p.`id_sale` DESC
|
||||
') as $row) {
|
||||
$extrafields = Category::getSalesInfos(array((int) $row['id_category']));
|
||||
$id_non_philea_sales[] = array(
|
||||
'label' => (int) $row['id_sale'].' - '.$row['name'].(empty($extrafields[(int) $row['id_category']]['sales'][1])?'':' - '.$extrafields[(int) $row['id_category']]['sales'][1]) ,
|
||||
'value' => (int) $row['id_sale']
|
||||
);
|
||||
}
|
||||
|
||||
$helperForm = new HelperFormBootstrap();
|
||||
$helperForm->_select2 = true;
|
||||
$helperForm->_inputMask = true;
|
||||
@ -602,6 +671,17 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
$form .= '<div class="panel">
|
||||
<div class="panel-title">
|
||||
<h2>Ventes Philéa</h2>
|
||||
<div class="pull-right">
|
||||
<form class="form-inline" action="" method="post">
|
||||
<label>Ajouter une vente (non philéa) : </label>
|
||||
<select class="form-control" id="id_no_philea_sale" name="id_sale">';
|
||||
foreach ($id_non_philea_sales as $key => $sale) {
|
||||
$form.='<option value="'.$sale['value'].'">'.$sale['label'].'</option>';
|
||||
}
|
||||
$form .='</select>
|
||||
<input class="btn btn-primary btn-sm" type="submit" name="addNoPhileaSale" value="Ajouter"/>
|
||||
</form>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="panel-content">
|
||||
@ -643,12 +723,13 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
$auto_sync = (isset($CRR['auto_sync_active']) && $CRR['auto_sync_active']) ? true : false;
|
||||
$title = ($auto_sync ? $this->l('Désactiver l\'envoi automatique pour la vente') : $this->l('Activer l\'envoi automatique pour la vente') );
|
||||
|
||||
if (isset($CRR['date_end']) && $CRR['date_end'] >= $now)
|
||||
if (isset($CRR['date_end']) && $CRR['date_end'] >= $now && isset($CRR['id_shipping']) && $CRR['id_shipping']==1){
|
||||
$auto_sync_btn = '<a title="' . $title . ' '. (int)$CRR['id_sale'] .'" data-id_sale = "' . (int) $CRR['id_sale'] . '" class="text-' . ($auto_sync ? 'green-light' : 'rose') . '" href="' . $currentIndex . '&token=' . $this->token . '&auto_sync&id_sale=' . (int)$CRR['id_sale'] . '&active=' . (int) !$auto_sync . '"><span style="font-size:21px;" class="anticon anticon-rss2"></span></a>';
|
||||
else
|
||||
}else{
|
||||
$auto_sync_btn = '<a title="' . $this->l('La vente est terminée') .'" class="text-' . ($auto_sync ? 'green-light' : 'rose') . '"><span style="opacity: 0.4;font-size:21px;" class="anticon anticon-rss2"></span></a>';
|
||||
}
|
||||
|
||||
$submit_link = $upload_link;// . '&id_sale=' . (int) $CRR['id_sale'] . '&addCDC=1';
|
||||
$submit_link = (isset($CRR['id_shipping']) && $CRR['id_shipping']==1)?$upload_link:$upload_link.'&id_sale=' . (int) $CRR['id_sale'] . '&send_to_philea=1';
|
||||
|
||||
$art_reports = Db::getInstance()->executeS('
|
||||
SELECT `report_data`, `report_date`, `id_sale`
|
||||
@ -702,7 +783,7 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
}
|
||||
$form .= '</td>
|
||||
<td style="text-align: center;">
|
||||
<a class="text-purple-dark upload_link" data-id="' . (int) $CRR['id_sale'] . '" href="'.$submit_link.'" title="'.$this->l('Envoyer à Philéa').'"><span style="font-size:21px;" class="anticon anticon-mail"></span></a> '.$auto_sync_btn.'
|
||||
<a class="text-purple-dark '.((isset($CRR['id_shipping']) && $CRR['id_shipping']==1)?'upload_link':'').'" data-id="' . (int) $CRR['id_sale'] . '" href="'.$submit_link.'" title="'.$this->l('Envoyer à Philéa').'"><i style="font-size:18px;" class="glyphicon glyphicon-send"></i></a>'.$auto_sync_btn.'
|
||||
</td>
|
||||
<td style="text-align: center;">
|
||||
<a class="text-purple-dark" data-toggle="collapse" data-target=".row_more_'.(int) $CRR['id_sale'].'"><span style="font-size:21px;cursor:pointer" class="anticon anticon-info"></span></a>
|
||||
@ -800,6 +881,11 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
|
||||
<script type="text/javascript">
|
||||
$("document").ready(function(){
|
||||
$("#id_no_philea_sale").select2({
|
||||
placeholder: "",
|
||||
allowClear: true
|
||||
});
|
||||
|
||||
$(".see_more").click(function(){
|
||||
$(this).toggleClass("anticon-zoom-in");
|
||||
$(this).toggleClass("anticon-zoom-out");
|
||||
@ -1001,8 +1087,7 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
pm_sync.`products` as `status_sent`,
|
||||
MAX(pm_sync.`date_add`) as `sync_date`
|
||||
FROM `'._DB_PREFIX_.'philea_sync` pm_sync
|
||||
LEFT JOIN `'._DB_PREFIX_.'philea_archive` pm_arch
|
||||
ON pm_arch.`id_sale` = pm_sync.`id_sale`
|
||||
LEFT JOIN `'._DB_PREFIX_.'philea_archive` pm_arch ON (pm_arch.`id_sale` = pm_sync.`id_sale`)
|
||||
WHERE 1
|
||||
AND `pm_arch`.`id_sale` IS NULL
|
||||
GROUP BY pm_sync.`id_sale`
|
||||
@ -1023,8 +1108,9 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
FROM `'._DB_PREFIX_.'philea_reception` pm_r
|
||||
WHERE `id_sale` IN (' . implode(', ', $id_sales) . ')
|
||||
GROUP BY `id_sale`';
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
foreach (Db::getInstance()->executeS($sql) as $row){
|
||||
$receptions[$row['id_sale']] = $row;
|
||||
}
|
||||
|
||||
$sales = array();
|
||||
$sql = '
|
||||
@ -1033,14 +1119,15 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
c.`name`,
|
||||
c.`id_category`,
|
||||
p.`date_start`,
|
||||
p.`date_end`
|
||||
p.`date_end`,
|
||||
pss.`id_shipping`
|
||||
FROM `'._DB_PREFIX_.'privatesale` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` c
|
||||
ON c.`id_category` = p.`id_category`
|
||||
AND c.`id_lang` = 2
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = p.`id_category` AND c.`id_lang` = 2)
|
||||
LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` pss ON (pss.`id_sale` = p.`id_sale`)
|
||||
WHERE p.`id_sale` IN (' .implode(', ', $id_sales) . ')';
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
foreach (Db::getInstance()->executeS($sql) as $row){
|
||||
$sales[(int) $row['id_sale']] = $row;
|
||||
}
|
||||
|
||||
$pm_autosales = array();
|
||||
$sql = '
|
||||
@ -1050,8 +1137,9 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
FROM `'._DB_PREFIX_.'philea_auto_sync` pm_as
|
||||
WHERE `id_sale` IN (' . implode(', ', $id_sales) . ')
|
||||
AND pm_as.`active` = 1';
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
foreach (Db::getInstance()->executeS($sql) as $row){
|
||||
$pm_active[(int) $row['id_sale']] = (int) $row['auto_sync_active'];
|
||||
}
|
||||
|
||||
$pm_sent = array();
|
||||
$sql = '
|
||||
@ -1085,50 +1173,12 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
'auto_sync_active' => $as_active,
|
||||
'date_start' => $sale['date_start'],
|
||||
'date_end' => $sale['date_end'],
|
||||
'id_shipping' => $sale['id_shipping'],
|
||||
'subtitle' => $extrafields[(int) $sales[(int) $id_sale]['id_category']]['sales'][1]
|
||||
);
|
||||
}
|
||||
self::$_crrlist_cache = $CRR_list;
|
||||
return self::$_crrlist_cache;
|
||||
|
||||
// $CRR_files = Db::getInstance()->executeS('
|
||||
// SELECT
|
||||
// pmsync.id_sale,
|
||||
// MAX(pmsync.`date_add`) as `sync_date`,
|
||||
// pmr.`filename`,
|
||||
// MAX(pmr.`date_add`) as `recep_date`,
|
||||
// c.`name`,
|
||||
// MAX(pms.date_add) as `sent_date`,
|
||||
// pmas.`active` as `auto_sync_active`,
|
||||
// p.date_start,
|
||||
// p.date_end
|
||||
// FROM `'._DB_PREFIX_.'philea_sync` pmsync
|
||||
// LEFT JOIN `'._DB_PREFIX_.'philea_sent` pms
|
||||
// ON pms.`id_sale` = pmsync.`id_sale`
|
||||
// LEFT JOIN `'._DB_PREFIX_.'privatesale` p
|
||||
// ON p.`id_sale` = pmsync.`id_sale`
|
||||
// LEFT JOIN `'._DB_PREFIX_.'category_lang` c
|
||||
// ON c.`id_category` = p.`id_category`
|
||||
// LEFT JOIN `'._DB_PREFIX_.'philea_reception` pmr
|
||||
// ON pmsync.`id_sale` = pmr.`id_sale`
|
||||
// LEFT JOIN `'._DB_PREFIX_.'philea_auto_sync` pmas
|
||||
// ON pmas.`id_sale` = pmsync.`id_sale`
|
||||
// LEFT JOIN `'._DB_PREFIX_.'philea_archive` pm_arch
|
||||
// ON pm_arch.`id_sale` = pmsync.`id_sale`
|
||||
// WHERE 1
|
||||
// AND c.id_lang = 2
|
||||
// AND `pm_arch`.id_sale IS NULL
|
||||
// ' . ((int) self::TIME_DISPLAY > 0 ? 'AND pmsync.`date_add` > DATE_SUB(NOW(), INTERVAL ' . self::TIME_DISPLAY . ' DAY)' : '') . '
|
||||
// GROUP BY pmsync.`id_sale`
|
||||
// ' . ((int) self::TIME_DISPLAY > 0 ? '
|
||||
// HAVING (
|
||||
// MAX(pms.date_add) IS NULL
|
||||
// OR MAX(pmsync.`date_add`) > DATE_SUB(NOW(), INTERVAL ' . self::TIME_DISPLAY . ' DAY)
|
||||
// OR pmsync.id_sale = 6304
|
||||
// )' : '') . '
|
||||
// ORDER BY `sync_date` DESC, `recep_date` DESC');
|
||||
// self::$_crrlist_cache = $CRR_files;
|
||||
// return self::$_crrlist_cache;
|
||||
}
|
||||
|
||||
public function displayArchives(){
|
||||
|
@ -13,6 +13,7 @@ if($output > 2){
|
||||
}
|
||||
|
||||
set_time_limit(600);
|
||||
// Default behaviour (state 0 to 4)
|
||||
if($row = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'philea_sync`
|
||||
@ -61,4 +62,55 @@ if($row = Db::getInstance()->getRow('
|
||||
LIMIT 1
|
||||
');
|
||||
system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $row['id_sale']);
|
||||
}
|
||||
|
||||
// Particular behaviour (state 5 to 9)
|
||||
if($row = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'philea_sync`
|
||||
WHERE `status` = 5
|
||||
ORDER BY `date_add` ASC
|
||||
')) {
|
||||
// CHECKING ASSOCIATED PRODUCTS
|
||||
$associated_products = Db::getInstance()->getValue('
|
||||
SELECT COUNT(`id_sale`)
|
||||
FROM `'._DB_PREFIX_.'product_ps_cache`
|
||||
WHERE `id_sale` = '.(int) $row['id_sale'].'
|
||||
');
|
||||
if($associated_products > 0) {
|
||||
// SEND ART01
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'philea_sync`
|
||||
SET `status` = 6
|
||||
WHERE `id_sync` = '.(int) $row['id_sync'].'
|
||||
LIMIT 1
|
||||
');
|
||||
system('cd '.dirname(__FILE__).'/script && php send_article_after.php '.(int) $row['id_sale']);
|
||||
sleep(20);
|
||||
|
||||
// SEND REC01
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'philea_sync`
|
||||
SET `status` = 7
|
||||
WHERE `id_sync` = '.(int) $row['id_sync'].'
|
||||
LIMIT 1
|
||||
');
|
||||
system('cd '.dirname(__FILE__).'/script && php send_recep_orderform_after.php '.(int) $row['id_sale']);
|
||||
}
|
||||
}
|
||||
|
||||
if($row = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'philea_sync`
|
||||
WHERE `status` = 8
|
||||
ORDER BY `date_add` ASC
|
||||
')) {
|
||||
// SEND CDC02
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'philea_sync`
|
||||
SET `status` = 9
|
||||
WHERE `id_sync` = '.(int) $row['id_sync'].'
|
||||
LIMIT 1
|
||||
');
|
||||
system('cd '.dirname(__FILE__).'/script && php send_commande_after.php '.(int) $row['id_sale']);
|
||||
}
|
526
modules/philea_magistor/script/recep_expedition_after.php
Normal file
526
modules/philea_magistor/script/recep_expedition_after.php
Normal file
@ -0,0 +1,526 @@
|
||||
<?php
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
include('../../../config/settings.inc.php');
|
||||
include('../../../config/config.inc.php');
|
||||
|
||||
|
||||
include( dirname(__FILE__) . '/../philea_magistor.php');
|
||||
global $regex_file_in;
|
||||
$regex_file_in = '@^CRE(.*)\.(BAL|DAT)@';
|
||||
@ini_set('display_errors', 'on');
|
||||
$magistorModule = new philea_magistor();
|
||||
|
||||
|
||||
//$id_shipping = 1; // PHILEA
|
||||
|
||||
$CRE = array(
|
||||
'OP_CODE' => array(1,10),
|
||||
'CODE_SOC' => array(11,20),
|
||||
'NO_CLIENT' => array(31,8),
|
||||
'N_CDE' => array(39,50),
|
||||
'NO_COLIS' => array(89,50),
|
||||
'NO_TRACKING' => array(139,50),
|
||||
'NO_EXPEDITION' => array(189,50),
|
||||
'DATE_EXPED' => array(239,8),
|
||||
'TRANSPORTEUR' => array(247,50),
|
||||
'CODE_ART' => array(297, 50),
|
||||
'QTE' => array(347, 10),
|
||||
);
|
||||
|
||||
$tab_conversion_carrier = philea_magistor::getTabState();
|
||||
|
||||
$socol_to_magistor = array(
|
||||
'DOM' => 'SOCOLMDSS',
|
||||
'DOS' => 'SOCOLMDS',
|
||||
'RDV' => 'SOCOLMRDV',
|
||||
'CIT' => 'SOCOLCITY',
|
||||
'BPR' => 'SOCOLMBP',
|
||||
'CDI' => 'SOCOLMBP',
|
||||
'A2P' => 'SOCOLMC',
|
||||
'ACP' => 'SOCOLMBP',
|
||||
);
|
||||
|
||||
$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é
|
||||
);
|
||||
|
||||
$format = $CRE;
|
||||
if($magistorModule->active) {
|
||||
require_once('connection_ftp.php');
|
||||
@set_time_limit(0);
|
||||
|
||||
// Checking for ".bal" files with a "CRE" prefix that has an equivalent ".dat" file and process them...
|
||||
$inFolder = dirname(__FILE__) . '/IN/';
|
||||
|
||||
$iterator = new DirectoryIterator($inFolder);
|
||||
$id_order_state = Configuration::get('PHILEA_MAGISTOR_STATUS_CRE');
|
||||
|
||||
foreach ($iterator as $fileinfo) {
|
||||
if ($fileinfo->isFile()) {
|
||||
if( preg_match('@^CRE(.*)\.BAL@', $fileinfo->getFilename())) {
|
||||
$datFile = $fileinfo->getPath() . '/' . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() );
|
||||
|
||||
if(file_exists($datFile)) {
|
||||
$content = file_get_contents($datFile);
|
||||
$lines = preg_split('@\n@',$content);
|
||||
|
||||
$id_order_details = array();
|
||||
$shipping_numbers = array();
|
||||
$parcel_carrier = array();
|
||||
if(!empty($lines)) {
|
||||
$details = array();
|
||||
$order_details = array();
|
||||
|
||||
// GET DATA
|
||||
foreach( $lines as $line ) {
|
||||
|
||||
$data = array();
|
||||
foreach($format as $field=>$value) {
|
||||
$data[] = substr($line, ($value[0]-1), $value[1]);
|
||||
}
|
||||
|
||||
if(!isset($data[2]) || (isset($data[2]) && !$data[2])){
|
||||
continue;
|
||||
}
|
||||
|
||||
$id_sale = 0;
|
||||
$id_order = (string) $data[3];
|
||||
if(substr($id_order, 0, 2) == 'OP') {
|
||||
$id_order = explode('-', $id_order);
|
||||
if(count($id_order) < 2) {
|
||||
continue;
|
||||
}
|
||||
$id_sale = (int) str_replace('OP', '', $id_order[0]);
|
||||
$id_order = (int) $id_order[1];
|
||||
} else {
|
||||
$id_order = (int) $id_order;
|
||||
}
|
||||
|
||||
if(!isset($details[(int)$id_order])){
|
||||
$details[(int)$id_order] = array();
|
||||
}
|
||||
|
||||
$code_art = explode("_", trim($data[9]));
|
||||
if(count($code_art)>1) {
|
||||
list($id_product, $id_attribute) = $code_art;
|
||||
} else {
|
||||
$id_product = $code_art[0];
|
||||
$id_attribute = 0;
|
||||
}
|
||||
|
||||
$order = new Order((int) $id_order);
|
||||
|
||||
// GET CARRIER ID
|
||||
$carrier_found = false;
|
||||
$id_active_carrier = false;
|
||||
$id_inactive_carrier = false;
|
||||
if (isset($data[8]) && $data[8]){
|
||||
$carrier_name = trim($data[8]);
|
||||
if($carrier_name == 'COLINT') {
|
||||
$carrier_name = 'SOCOLMDSS';
|
||||
}
|
||||
$carriers = philea_magistor::getCarriersIdByRef($carrier_name);
|
||||
if ($carriers){
|
||||
foreach ($carriers as $carrier) {
|
||||
if ($carrier['name'] == 'GLS' && $carrier_name == 'DPD') {
|
||||
continue;
|
||||
}
|
||||
if ($carrier['active'] == 1 && $carrier['deleted'] == 0) {
|
||||
$id_active_carrier = (int) $carrier['id_carrier'];
|
||||
}
|
||||
if ($carrier['active'] == 0 && $carrier['deleted'] == 0) {
|
||||
$id_inactive_carrier = (int) $carrier['id_carrier'];
|
||||
}
|
||||
if ((int) $order->id_carrier == (int) $carrier['id_carrier']){
|
||||
$carrier_found = (int) $order->id_carrier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($carrier_found)
|
||||
$id_carrier = (int) $carrier_found;
|
||||
elseif ($id_active_carrier)
|
||||
$id_carrier = (int) $id_active_carrier;
|
||||
elseif ($id_inactive_carrier)
|
||||
$id_carrier = (int) $id_inactive_carrier;
|
||||
else
|
||||
$id_carrier = (int) $order->id_carrier;
|
||||
|
||||
if(isset($id_carrier) && $id_carrier) {
|
||||
$parcel_carrier[(int) $id_order.'|'.trim($data[5])] = $id_carrier;
|
||||
}
|
||||
|
||||
$shipping_numbers[] = '"'.pSQL(trim($data[5])).'"';
|
||||
|
||||
if(!isset($details[(int)$id_order][$id_product.'_'.$id_attribute])) {
|
||||
$details[(int)$id_order][$id_product.'_'.$id_attribute] = array(
|
||||
'shipping_numbers' => array(),
|
||||
'quantity' => 0
|
||||
);
|
||||
}
|
||||
$details[(int)$id_order][$id_product.'_'.$id_attribute]['quantity'] += (int) trim($data[10]);
|
||||
$details[(int)$id_order][$id_product.'_'.$id_attribute]['shipping_numbers'][] = array(
|
||||
'number' => trim($data[5]),
|
||||
'date' => pSQL(substr($data[7], 0, 4).'-'.substr($data[7], 4, 2).'-'.substr($data[7], 6, 2).' 18:00:00'),
|
||||
'quantity' => (int) trim($data[10])
|
||||
);
|
||||
|
||||
if(!isset($order_details[(int)$id_order])){
|
||||
$order_details[(int)$id_order] = array();
|
||||
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT `id_order_detail`, `product_id`, `product_attribute_id`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'order_detail`
|
||||
WHERE `id_order` = '.(int) $id_order.'
|
||||
') as $key => $row) {
|
||||
$sent = (int) Db::getInstance()->getValue('
|
||||
SELECT SUM(`quantity`)
|
||||
FROM `'._DB_PREFIX_.'philea_parcel`
|
||||
WHERE `id_order_detail` = '.(int) $row['id_order_detail'].'
|
||||
');
|
||||
$id_order_details[] = (int) $row['id_order_detail'];
|
||||
if(Pack::isPack((int)$row['product_id'])) {
|
||||
$items = Pack::getSimplePack($row['product_id']);
|
||||
foreach($items as $item) {
|
||||
if(!isset($order_details[(int)$id_order][$item['id_product_item'].'_0'])) {
|
||||
$order_details[(int)$id_order][$item['id_product_item'].'_0'] = array(
|
||||
'id_order_details' => array(),
|
||||
'quantity_to_sent' => 0
|
||||
);
|
||||
}
|
||||
$order_details[$id_order][$item['id_product_item'].'_0']['quantity_to_sent'] += (($row['quantity'] - $sent) * $item['quantity']);
|
||||
$order_details[$id_order][$item['id_product_item'].'_0']['id_order_details'][$row['id_order_detail']] = array(
|
||||
'detail_quantity' => ($row['quantity'] - $sent),
|
||||
'id_order_detail' => $row['id_order_detail']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if(!isset($order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']])) {
|
||||
$order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']] = array(
|
||||
'id_order_details' => array(),
|
||||
'quantity_to_sent' => 0
|
||||
);
|
||||
}
|
||||
$order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']]['quantity_to_sent'] += ($row['quantity'] - $sent);
|
||||
$order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']]['id_order_details'][$row['id_order_detail']] = array(
|
||||
'detail_quantity' => ($row['quantity'] - $sent),
|
||||
'id_order_detail' => $row['id_order_detail']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end foreach lines
|
||||
|
||||
foreach($order_details as $order => $order_detail){
|
||||
foreach ($order_detail as $key => $product) {
|
||||
if(isset($details[(int)$order][$key])) {
|
||||
if($details[(int)$order][$key]['quantity'] <= $product['quantity_to_sent']) {
|
||||
if(count($details[(int)$order][$key]['shipping_numbers'])>1) {
|
||||
foreach($details[(int)$order][$key]['shipping_numbers'] as $shipping_number) {
|
||||
foreach($product['id_order_details'] as $id_order_detail => $row) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
||||
VALUES (
|
||||
'.(int) $id_order_detail.',
|
||||
'.(int) $row['detail_quantity'].',
|
||||
"'.pSQL(trim($shipping_number['number'])).'",
|
||||
"'.$shipping_number['date'].'"
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach($product['id_order_details'] as $id_order_detail => $row) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
||||
VALUES (
|
||||
'.(int) $id_order_detail.',
|
||||
'.(int) $row['detail_quantity'].',
|
||||
"'.pSQL($details[(int)$order][$key]['shipping_numbers'][0]['number']).'",
|
||||
"'.$details[(int)$order][$key]['shipping_numbers'][0]['date'].'"
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// $message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Quantity to sent : ".$product['quantity_to_sent']."\r\n Quantity : ".$details[(int)$order][$key]['quantity'];
|
||||
// mail('marion@antadis.com', '[BBB] Erreurs quantity expe Philea', $message);
|
||||
}
|
||||
} else {
|
||||
// $message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Produit non présent dans le fichier expe philea";
|
||||
// mail('marion@antadis.com', '[BBB] Erreurs produit expe Philea', $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($details);
|
||||
unset($order_details);
|
||||
} // end if lines
|
||||
|
||||
$id_order_details = array_unique($id_order_details);
|
||||
$shipping_numbers = array_unique($shipping_numbers);
|
||||
|
||||
if(count($id_order_details) > 0) {
|
||||
$id_orders = array();
|
||||
$orders_infos = array();
|
||||
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT d.`id_order`, p.`shipping_number`, p.`date_add`
|
||||
FROM `'._DB_PREFIX_.'philea_parcel` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
|
||||
WHERE d.`id_order_detail` IN ('.implode(', ', $id_order_details).')
|
||||
AND p.`shipping_number` IN ('.implode(', ', $shipping_numbers).')
|
||||
GROUP BY d.`id_order`, p.`shipping_number`
|
||||
') as $row) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'shipping_history`
|
||||
VALUES (
|
||||
'.(int) $row['id_order'].',
|
||||
"'.pSQL($row['shipping_number']).'",
|
||||
"'.pSQL($row['date_add']).'",
|
||||
'.(int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']].',
|
||||
0
|
||||
)
|
||||
');
|
||||
|
||||
$id_orders[] = (int) $row['id_order'];
|
||||
if(!isset($orders_infos[(int) $row['id_order']])) {
|
||||
$orders_infos[(int) $row['id_order']] = array();
|
||||
}
|
||||
$orders_infos[(int) $row['id_order']][] = array($row['shipping_number'], $row['date_add'], (int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']]);
|
||||
}
|
||||
|
||||
$id_orders = array_unique($id_orders);
|
||||
|
||||
$products = Db::getInstance()->ExecuteS('
|
||||
SELECT d.`id_order_detail`, d.`id_order`, c.`id_sale`, d.`product_quantity` - GREATEST(d.`product_quantity_refunded`, d.`product_quantity_return`) AS `quantity`
|
||||
FROM ps_order_detail d
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (d.`product_id` = c.`id_product`)
|
||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||
');
|
||||
|
||||
$sent_sales = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `id_order`, `id_sale`
|
||||
FROM `'._DB_PREFIX_.'shipping_history`
|
||||
WHERE `id_order` IN ('.implode(', ', $id_orders).')
|
||||
AND `id_sale` != 0
|
||||
GROUP BY `id_order`, `id_sale`
|
||||
') as $row) {
|
||||
if(!isset($sent_sales[(int) $row['id_order']])) {
|
||||
$sent_sales[(int) $row['id_order']] = array();
|
||||
}
|
||||
$sent_sales[(int) $row['id_order']][] = (int) $row['id_sale'];
|
||||
}
|
||||
|
||||
$to_send = array();
|
||||
foreach($products as $product) {
|
||||
if ((int) $product['quantity'] > 0
|
||||
&& (!isset($sent_sales[(int) $product['id_order']])
|
||||
|| !in_array((int) $product['id_sale'], $sent_sales[(int) $product['id_order']]))) {
|
||||
$to_send[] = $product;
|
||||
}
|
||||
}
|
||||
|
||||
unset($products);
|
||||
|
||||
$sent_products = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'lapostews` l
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
|
||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||
GROUP BY l.`id_order_detail`
|
||||
') as $row) {
|
||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||
}
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'mondialrelay_parcel` l
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
|
||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||
GROUP BY l.`id_order_detail`
|
||||
') as $row) {
|
||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||
}
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'philea_parcel` l
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
|
||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||
GROUP BY l.`id_order_detail`
|
||||
') as $row) {
|
||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||
}
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` l
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
|
||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||
GROUP BY l.`id_order_detail`
|
||||
') as $row) {
|
||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||
}
|
||||
|
||||
$orders_to_send = array();
|
||||
$orders_list = array();
|
||||
|
||||
$total = count($to_send);
|
||||
|
||||
foreach($to_send as $product) {
|
||||
if(!in_array((int) $product['id_order'], $orders_list)) {
|
||||
$orders_list[] = (int) $product['id_order'];
|
||||
}
|
||||
if(!in_array((int) $product['id_order'], $orders_to_send)) {
|
||||
if(!isset($sent_products[(int) $product['id_order_detail']])
|
||||
|| $product['quantity'] > $sent_products[(int) $product['id_order_detail']]) {
|
||||
$orders_to_send[] = (int) $product['id_order'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($sent_products);
|
||||
unset($to_send);
|
||||
|
||||
$orders_sent = array();
|
||||
foreach($orders_list as $order) {
|
||||
if(!in_array($order, $orders_to_send)) {
|
||||
$orders_sent[] = $order;
|
||||
}
|
||||
}
|
||||
|
||||
unset($orders_list);
|
||||
|
||||
$status_sent = array();
|
||||
$status_partially_sent = array();
|
||||
|
||||
foreach($orders_sent as $order) {
|
||||
if((int) Db::getInstance()->getValue('
|
||||
SELECT `id_order_state`
|
||||
FROM `'._DB_PREFIX_.'order_history`
|
||||
WHERE `id_order` = '.(int) $order.'
|
||||
ORDER BY `date_add` DESC LIMIT 1
|
||||
') != 4) {
|
||||
$status_sent[] = (int) $order;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($id_orders as $order) {
|
||||
if(!in_array($order, $status_sent)) {
|
||||
if(!in_array((int) Db::getInstance()->getValue('
|
||||
SELECT `id_order_state`
|
||||
FROM `'._DB_PREFIX_.'order_history`
|
||||
WHERE `id_order` = '.(int) $order.'
|
||||
ORDER BY `date_add` DESC LIMIT 1
|
||||
'), array(4, 17, 9, 19))) {
|
||||
$status_partially_sent[] = (int) $order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($orders_sent);
|
||||
unset($orders_to_send);
|
||||
|
||||
foreach($orders_infos as $id_order => $parcels) {
|
||||
$order = new Order($id_order);
|
||||
$customer = new Customer((int) $order->id_customer);
|
||||
|
||||
foreach($parcels as $parcel) {
|
||||
$products_sent = '';
|
||||
|
||||
$products_names = array();
|
||||
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT d.`id_order_detail`, d.`product_name`, SUM(p.`quantity`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'philea_parcel` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
|
||||
WHERE d.`id_order` = '.(int) $id_order.'
|
||||
AND p.`shipping_number` = "'.pSQL($parcel[0]).'"
|
||||
AND p.`date_add` = "'.pSQL($parcel[1]).'"
|
||||
GROUP BY d.`id_order_detail`
|
||||
') as $p) {
|
||||
$products_sent .= '<br />'."\r\n".$p['quantity'].' x '.$p['product_name'];
|
||||
}
|
||||
|
||||
$carrier = new Carrier($parcel[2], (int) $order->id_lang);
|
||||
|
||||
if((int) $order->id_lang == 3) {
|
||||
if(preg_match('/colissimo/i', $carrier->name)) {
|
||||
$carrier->url .= '&language=es_ES';
|
||||
}
|
||||
$content_html = '<strong>Contenido del paquete:</strong>';
|
||||
$content_txt = 'Contenido del paquete:';
|
||||
} else {
|
||||
$content_html = '<strong>Contenu du colis :</strong>';
|
||||
$content_txt = 'Contenu du colis :';
|
||||
}
|
||||
|
||||
$templateVars = array(
|
||||
'{followup}' => str_replace('@', $parcel[0], $carrier->url),
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{id_order}' => (int) $order->id,
|
||||
'{product_list}' => !empty($products_sent)? $content_html.$products_sent: '',
|
||||
'{product_list_txt}' => !empty($products_sent)? $content_txt.strip_tags($products_sent): '',
|
||||
);
|
||||
|
||||
$order->shipping_number = $parcel[0];
|
||||
$order->update();
|
||||
|
||||
$last_state = Db::getInstance()->getValue('
|
||||
SELECT `id_order_state`
|
||||
FROM `'._DB_PREFIX_.'order_state_current`
|
||||
WHERE `id_order` ='.(int)$order->id
|
||||
);
|
||||
if(in_array($order->id, $status_sent) && (int)$last_state != 4) {
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int) $order->id;
|
||||
$history->changeIdOrderState(4, (int) $order->id);
|
||||
$history->addWithemail(true, $templateVars);
|
||||
} elseif(in_array($order->id, $status_partially_sent)) {
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int) $order->id;
|
||||
$history->changeIdOrderState(17, (int) $order->id);
|
||||
$history->addWithemail(true, $templateVars);
|
||||
}
|
||||
|
||||
$subjects = array(
|
||||
1 => 'Package in transit',
|
||||
2 => 'Livraison en cours',
|
||||
3 => 'Pedido en tránsito',
|
||||
);
|
||||
|
||||
Mail::Send(
|
||||
intval($order->id_lang),
|
||||
'in_transit',
|
||||
$subjects[(int) $order->id_lang],
|
||||
$templateVars,
|
||||
$customer->email,
|
||||
$customer->firstname.' '.$customer->lastname
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$repo_archive = './archives/IN/LIVRAISON/';
|
||||
$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);
|
||||
}
|
||||
|
||||
copy($datFile, $repo_archive . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ));
|
||||
unlink($inFolder.$fileinfo->getFilename());
|
||||
unlink($datFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'fin';
|
@ -249,12 +249,12 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Quantity to sent : ".$product['quantity_to_sent']."\r\n Quantity : ".$details[(int)$order][$key]['quantity'];
|
||||
mail('marion@antadis.com', '[BBB] Erreurs quantity expe Philea', $message);
|
||||
// $message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Quantity to sent : ".$product['quantity_to_sent']."\r\n Quantity : ".$details[(int)$order][$key]['quantity'];
|
||||
// mail('marion@antadis.com', '[BBB] Erreurs quantity expe Philea', $message);
|
||||
}
|
||||
} else {
|
||||
$message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Produit non présent dans le fichier expe philea";
|
||||
mail('marion@antadis.com', '[BBB] Erreurs produit expe Philea', $message);
|
||||
// $message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Produit non présent dans le fichier expe philea";
|
||||
// mail('marion@antadis.com', '[BBB] Erreurs produit expe Philea', $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -357,6 +357,15 @@
|
||||
') as $row) {
|
||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||
}
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` l
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
|
||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||
GROUP BY l.`id_order_detail`
|
||||
') as $row) {
|
||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||
}
|
||||
|
||||
$orders_to_send = array();
|
||||
$orders_list = array();
|
||||
@ -498,8 +507,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
mail('marion@antadis.com', '[BBB] Recept expe Philea', $datFile);
|
||||
|
||||
$repo_archive = './archives/IN/LIVRAISON/';
|
||||
$repo_paths = array(date('Y'), date('m'));
|
||||
foreach ($repo_paths as $repo_path) {
|
||||
|
229
modules/philea_magistor/script/send_article_after.php
Normal file
229
modules/philea_magistor/script/send_article_after.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['SERVER_PORT'] = 80;
|
||||
|
||||
include(dirname(__FILE__) . '/../../../config/config.inc.php');
|
||||
include( dirname(__FILE__) . '/../philea_magistor.php');
|
||||
include( dirname(__FILE__) . '/../../privatesales/Sale.php');
|
||||
|
||||
$id_sale = (int) $argv[1];
|
||||
|
||||
$_id_shipping = 1; // philea
|
||||
|
||||
if($id_sale == 0) {
|
||||
exit;
|
||||
}
|
||||
$sale = new Sale($id_sale);
|
||||
$dateNow = date('ymdHis');
|
||||
|
||||
function getName($id_product, $id_lang, $id_product_attribute = FALSE) {
|
||||
$name = DB::getInstance()->getValue('
|
||||
SELECT `name`
|
||||
FROM `'._DB_PREFIX_.'product_lang`
|
||||
WHERE `id_product` = '.$id_product.'
|
||||
AND `id_lang` = '.$id_lang.'
|
||||
');
|
||||
|
||||
if($id_product_attribute) {
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT agl.`name` AS group_name, al.`name` AS attribute_name
|
||||
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute` a
|
||||
ON a.`id_attribute` = pac.`id_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag
|
||||
ON ag.`id_attribute_group` = a.`id_attribute_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
|
||||
ON a.`id_attribute` = al.`id_attribute`
|
||||
AND al.`id_lang` = '.(int) $id_lang.'
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
|
||||
ON ag.`id_attribute_group` = agl.`id_attribute_group`
|
||||
AND agl.`id_lang` = '.(int) $id_lang.'
|
||||
WHERE pac.`id_product_attribute` = '.(int) $id_product_attribute.'
|
||||
ORDER BY pac.`id_product_attribute`
|
||||
') as $name_attribute) {
|
||||
$name .= ' - '.$name_attribute['group_name'].' : '.$name_attribute['attribute_name'];
|
||||
}
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
$magistorModule = new philea_magistor();
|
||||
@ini_set('display_errors', 'on');
|
||||
|
||||
if($magistorModule->active) {
|
||||
global $regex_file_out;
|
||||
$regex_file_out = '@^ART01(.*)\.(BAL|DAT)@';
|
||||
@set_time_limit(0);
|
||||
$fileName = dirname(__FILE__) . '/OUT/ART01' . $dateNow;
|
||||
|
||||
$repo_archive = dirname(__FILE__) . '/archives/OUT/ARTICLES/';
|
||||
$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 . 'ART01' . $dateNow;
|
||||
|
||||
$code_societe = (int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
||||
$data = '';
|
||||
|
||||
$db = Db::getInstance();
|
||||
$products = $db->ExecuteS('
|
||||
SELECT * FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)(Configuration::get('PS_LANG_DEFAULT')).'
|
||||
)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c
|
||||
ON c.`id_product` = p.`id_product`
|
||||
WHERE c.`id_sale` = '.(int) $id_sale.'
|
||||
ORDER BY p.`id_product` ASC
|
||||
');
|
||||
if (!$products) {
|
||||
$products = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Override check pack items
|
||||
*/
|
||||
$product_ids = array_map(function($product){ return $product['id_product']; }, $products);
|
||||
foreach(Db::getInstance()->executeS('
|
||||
SELECT p.*, pl.*
|
||||
FROM `'._DB_PREFIX_.'pack` pp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (pp.`id_product_item` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)(Configuration::get('PS_LANG_DEFAULT')).'
|
||||
)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (c.`id_product` = pp.`id_product_pack`)
|
||||
WHERE c.`id_sale` = '.(int) $id_sale.'
|
||||
ORDER BY p.`id_product` ASC
|
||||
') as $row){
|
||||
// do not add product item it's in product list
|
||||
if (!in_array($row['id_product'], $product_ids))
|
||||
$products[] = $row;
|
||||
}
|
||||
|
||||
foreach ($products as $key => $product) {
|
||||
/**
|
||||
* @Override check pack items
|
||||
* Do not add pack item (only content items)
|
||||
*/
|
||||
if (isset($product['cache_is_pack']) && $product['cache_is_pack']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attributes = $db->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.$product['id_product'].'
|
||||
');
|
||||
if(count($attributes) > 0) {
|
||||
foreach ($attributes as $key => $attribute) {
|
||||
$quantity = 0;
|
||||
$result_quantities = Db::getInstance()->executeS('
|
||||
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
|
||||
FROM '._DB_PREFIX_.'order_detail od
|
||||
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`)
|
||||
WHERE od.`product_id` = ' . (int)$attribute['id_product'] .'
|
||||
AND od.`product_attribute_id`= ' . (int)$attribute['id_product_attribute'].'
|
||||
AND o.`valid` != 0'
|
||||
);
|
||||
foreach ($result_quantities as $od) {
|
||||
$quantity += ((int)$od['product_quantity'] - (int)$od['product_quantity_reinjected']);
|
||||
}
|
||||
if($quantity>0){
|
||||
|
||||
if(isset($attribute['ean13']) && !empty($attribute['ean13'])) {
|
||||
$ean = $attribute['ean13'];
|
||||
} else {
|
||||
$ean = $attribute['supplier_reference'];
|
||||
}
|
||||
|
||||
$link = new Link();
|
||||
$cover = Db::getInstance()->getValue('
|
||||
SELECT `id_image`
|
||||
FROM `'._DB_PREFIX_.'image`
|
||||
WHERE id_product = ' . (int) $product['id_product'] . '
|
||||
AND `cover` = 1');
|
||||
$ids = (int) $product['id_product'] . '-' . (int) $cover;
|
||||
$img_link = 'http://'.$link->getImageLink($product['link_rewrite'], $ids, 'thickbox');
|
||||
|
||||
$data .= str_pad('ART01', 10, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad($code_societe, 20, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(str_replace(array("\r", "\n"), '', $product['id_product'].'_'.$attribute['id_product_attribute'])), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(str_replace(array("\r", "\n"), '', getName($product['id_product'], Configuration::get('PS_LANG_DEFAULT'), $attribute['id_product_attribute']))), 0,80), 80, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(1, 10, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad(str_replace(array("\r", "\n"), '', $attribute['ean13']), 14, ' ', STR_PAD_LEFT);
|
||||
$data .= str_pad(str_replace('.', ',', $product['weight'] + $attribute['weight']), 10, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad($product['width'] * $product['height'] * $product['depth'], 10, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad(substr($img_link, 0, 150), 150, ' ', STR_PAD_RIGHT);
|
||||
$data .= PHP_EOL;
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$quantity = 0;
|
||||
$result_quantities = Db::getInstance()->executeS('
|
||||
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
|
||||
FROM '._DB_PREFIX_.'order_detail od
|
||||
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`)
|
||||
WHERE od.`product_id` = ' . (int)$product['id_product'] . ' AND `product_attribute_id` = 0 AND o.`valid` != 0'
|
||||
);
|
||||
foreach ($result_quantities as $od) {
|
||||
$quantity += ((int)$od['product_quantity'] - (int)$od['product_quantity_reinjected']);
|
||||
}
|
||||
if($quantity>0){
|
||||
if(isset($product['ean13']) && !empty($product['ean13'])) {
|
||||
$ean = $product['ean13'];
|
||||
} else {
|
||||
$ean = $product['supplier_reference'];
|
||||
}
|
||||
|
||||
$data .= str_pad('ART01', 10, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad($code_societe, 20, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(str_replace(array("\r", "\n"), '', $product['id_product']), 50, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(substr(utf8_decode(str_replace(array("\r", "\n"), '', $product['name'])), 0, 80), 80, ' ', STR_PAD_RIGHT);
|
||||
$data .= str_pad(1, 10, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad(str_replace(array("\r", "\n"), '', $product['ean13']), 14, ' ', STR_PAD_LEFT);
|
||||
$data .= str_pad(str_replace('.', ',', $product['weight']), 10, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad($product['width'] * $product['height'] * $product['depth'], 10, '0', STR_PAD_LEFT);
|
||||
$data .= str_pad(substr($img_link, 0, 150), 150, ' ', STR_PAD_RIGHT);
|
||||
$data .= PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($data != '') {
|
||||
$file = 'ART01'.$dateNow.'.DAT';
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_syncreport` (`id_sale`, `filename`, `date_add`)
|
||||
VALUES (
|
||||
'.(int)$id_sale.',
|
||||
"'.pSQL($file).'",
|
||||
NOW()
|
||||
)
|
||||
');
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'philea_sync`
|
||||
SET `products` = 1
|
||||
WHERE `id_sale` = '.(int)$id_sale.'
|
||||
LIMIT 1
|
||||
');
|
||||
// mail('marion@antadis.com', '[BBB] Philea - Send article for sale #'.$id_sale, $file); // log
|
||||
file_put_contents($fileName.'.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
||||
file_put_contents($fileArchive.'.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
||||
unset($data);
|
||||
|
||||
chmod($fileName.'.DAT', 0755);
|
||||
file_put_contents($fileName.'.BAL', '');
|
||||
chmod($fileName.'.BAL', 0755);
|
||||
require_once('connection_ftp.php');
|
||||
echo 'fin';
|
||||
}
|
||||
}
|
454
modules/philea_magistor/script/send_commande_after.php
Normal file
454
modules/philea_magistor/script/send_commande_after.php
Normal file
@ -0,0 +1,454 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
$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` > "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) {
|
||||
$carriers_socol = explode(',', Configuration::get('ANT_CARRIERS_SOCOL'));
|
||||
$carriers_mr = explode(',', Configuration::get('ANT_CARRIERS_MR'));
|
||||
|
||||
$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);
|
||||
}
|
189
modules/philea_magistor/script/send_recep_orderform_after.php
Normal file
189
modules/philea_magistor/script/send_recep_orderform_after.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['SERVER_PORT'] = 80;
|
||||
|
||||
include(dirname(__FILE__) . '/../../../config/config.inc.php');
|
||||
include( dirname(__FILE__) . '/../philea_magistor.php');
|
||||
|
||||
$id_sale = (int) $argv[1];
|
||||
if($id_sale == 0)
|
||||
exit;
|
||||
|
||||
$_id_shipping = 1; // philea
|
||||
$dateNow = date('ymdHis');
|
||||
|
||||
## FILE FORMAT
|
||||
/**
|
||||
* CHAMPS VALEURS COMMENTAIRES DEBUT LONGUEUR
|
||||
* OP_CODE « REC01 » « REC01 » : balise fichier de réception 1 10
|
||||
* CODE_SOC ALPHA-NUMERIQUE Code société gestionnaire à définir 11 20
|
||||
* N_PIECE ALPHA-NUMERIQUE Numéro de réception ou numéro de commande d’achat 31 20
|
||||
* DATE_ATTENDUE NUMERIQUE (YYYYMMDD) Date de réception attendue 51 8
|
||||
* CODE_ART ALPHA-NUMERIQUE Code Article 59 50
|
||||
* QTE NUMERIQUE Quantité 109 10
|
||||
* QTE_MONO NUMERIQUE Quantité prévue dans des commandes mono-lignes 119 10
|
||||
* COMMENTAIRE ALPHA-NUMERIQUE Commentaires ou instructions de réception 129 250
|
||||
* NUM_BL ALPHA-NUMERIQUE Numéro du BL fournisseur 379 50
|
||||
* EAN_UVC NUMERIQUE Code ean de l'article (pour l'unité ou pièce) 429 14
|
||||
*/
|
||||
|
||||
$magistorModule = new philea_magistor();
|
||||
@ini_set('display_errors', 'on');
|
||||
|
||||
if($magistorModule->active) {
|
||||
global $regex_file_out;
|
||||
$regex_file_out = '@^REC01(.*)\.(BAL|DAT)@';
|
||||
@set_time_limit(0);
|
||||
|
||||
$repo_archive = dirname(__FILE__) . '/archives/OUT/RECEP/';
|
||||
$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);
|
||||
}
|
||||
|
||||
$code_societe = (int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
||||
$db = Db::getInstance();
|
||||
|
||||
$products = array();
|
||||
$orders = $db->executeS('
|
||||
SELECT d.`id_order_detail`, o.`id_order`, d.`product_id`, d.`product_attribute_id`, (d.`product_quantity` - d.`product_quantity_refunded`) as p_quantity, pl.*,p.*
|
||||
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_.'product` p ON (d.`product_id` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)(Configuration::get('PS_LANG_DEFAULT')).')
|
||||
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
|
||||
ORDER BY `product_id`');
|
||||
foreach ($orders as $key => $row) {
|
||||
if (isset($row['cache_is_pack']) && $row['cache_is_pack']) {
|
||||
$items = $db->executeS('
|
||||
SELECT p.*,pl.*,pp.`id_product_item`,pp.`quantity` as pack_quantity
|
||||
FROM `ps_pack` pp
|
||||
LEFT JOIN `ps_product` p ON (pp.`id_product_item` = p.`id_product`)
|
||||
LEFT JOIN `ps_product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = 2)
|
||||
WHERE pp.`id_product_pack` = '.$row['product_id'].'
|
||||
');
|
||||
foreach ($items as $key => $item) {
|
||||
if(isset($products[$item['id_product_item'].'_0'])){
|
||||
$products[$item['id_product_item'].'_0']['quantity'] += ($row['p_quantity'] * $item['pack_quantity']);
|
||||
} else {
|
||||
$products[$item['id_product_item'].'_0'] = array(
|
||||
'detail' => $item,
|
||||
'quantity' => ($row['p_quantity'] * $item['pack_quantity'])
|
||||
);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($products[$row['product_id'].'_'.$row['product_attribute_id']])){
|
||||
$products[$row['product_id'].'_'.$row['product_attribute_id']]['quantity'] += (int)$row['p_quantity'];
|
||||
} else {
|
||||
$products[$row['product_id'].'_'.$row['product_attribute_id']] = array(
|
||||
'detail' => $row,
|
||||
'quantity' => (int)$row['p_quantity']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$fileName = dirname(__FILE__) . '/OUT/REC01' . $dateNow;
|
||||
$fileArchive = $repo_archive . 'REC01' . $dateNow;
|
||||
|
||||
$data = '';
|
||||
$product_quantities = array();
|
||||
$product_quantities2 = array();
|
||||
foreach($products as $key => $row) {
|
||||
$ids = explode('_', $key);
|
||||
$id_product = (int)$ids[0];
|
||||
$id_attribute = (int)$ids[1];
|
||||
$product = $row['detail'];
|
||||
|
||||
if($id_attribute!=0){
|
||||
$attribute = $db->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.$id_product.' AND `id_product_attribute` = '.$id_attribute.'
|
||||
');
|
||||
|
||||
if(isset($attribute['ean13']) && !empty($attribute['ean13'])) {
|
||||
$ean = $attribute['ean13'];
|
||||
} else {
|
||||
$ean = $attribute['supplier_reference'];
|
||||
}
|
||||
|
||||
$data .= str_pad('REC01', 10, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $code_societe, 20, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( 'OP'.(int) $id_sale, 20, ' ', STR_PAD_RIGHT );
|
||||
$data .= date('Ymd');
|
||||
$data .= str_pad( substr(utf8_decode(str_replace(array("\r", "\n"), "", $id_product.'_'.$id_attribute)),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $row['quantity'], 10, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( '', 250, ' ', STR_PAD_LEFT );
|
||||
$data .= str_pad( '0001', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( str_replace(array("\r", "\n"), "", $ean), 14, ' ', STR_PAD_LEFT );
|
||||
$data .= PHP_EOL;
|
||||
|
||||
$product_quantities[$id_product.'_'.$id_attribute] = (int)$row['quantity'];
|
||||
$product_quantities2[$id_product.'_'.$id_attribute] = 0;
|
||||
} else {
|
||||
|
||||
if(isset($product['ean13']) && !empty($product['ean13'])) {
|
||||
$ean = $product['ean13'];
|
||||
} else {
|
||||
$ean = $product['supplier_reference'];
|
||||
}
|
||||
|
||||
$data .= str_pad('REC01', 10, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $code_societe, 20, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( 'OP'.(int) $id_sale, 20, ' ', STR_PAD_RIGHT );
|
||||
$data .= date('Ymd');
|
||||
$data .= str_pad( substr(utf8_decode(str_replace(array("\r", "\n"), "", $product['product_id'])),0,50), 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( $row['quantity'], 10, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
||||
$data .= str_pad( '', 250, ' ', STR_PAD_LEFT );
|
||||
$data .= str_pad( '0001', 50, ' ', STR_PAD_RIGHT );
|
||||
$data .= str_pad( str_replace(array("\r", "\n"), "", $product['ean13']), 14, ' ', STR_PAD_LEFT );
|
||||
$data .= PHP_EOL;
|
||||
|
||||
$product_quantities[$product['product_id']] = (int)$row['quantity'];
|
||||
$product_quantities2[$product['product_id']] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if($data != '') {
|
||||
$file = 'REC01'.$dateNow.'.DAT';
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `' . _DB_PREFIX_ . 'philea_stock_sync`
|
||||
VALUES
|
||||
(
|
||||
DEFAULT,
|
||||
' . (int) $id_sale . ',
|
||||
0,
|
||||
"'.pSQL(json_encode($product_quantities)).'",
|
||||
"'.pSQL(json_encode($product_quantities2)).'",
|
||||
NOW(),
|
||||
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));
|
||||
|
||||
chmod($fileName . '.DAT', 0755);
|
||||
chmod($fileName . '.BAL', 0755);
|
||||
|
||||
unset($data);
|
||||
|
||||
require_once('connection_ftp.php');
|
||||
}
|
||||
echo 'fin'."\n";
|
||||
}
|
Loading…
Reference in New Issue
Block a user