747 lines
25 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
global $exapaq_formats;
$exapaq_formats = array(
'DOM' => '191100005670040Soumis aux conditions générales de vente de la FFOCT et aux conditions
191100005610040particulières de prestation d\'EXAPAQ. Notre responsabilité est contractuellement
191100005540040limitée à EUR 23,00 par KG transporté.
211200005500335EXAPAQ 6
211200005500322FR-06580 PEGOMAS
1Y1100002900320{EXASANTE}
1d0309204560100{EXAPASS_BARCODE}
1X1100005470100l01800003
1X1100004530100l01800003
1X1100002620040b0245018900010001
1X1100002620255l00010188
1X1100000070186b0165025300020002
1e230080000{SHIPPING_ALIGN}{SHIPPING_BC}
1X1100000070113b0071025300010001
1X1100000070040b0040025300010001'
/*FB+
292200203840295G 1/2
FB-*/
.'291100704480250{TOURPRINT}
2911007{TOURALIGN}0250{TOUR}
291100702870250{SMALL}
291100704150215{TRI1}
2911004{LIGNE1_ALIGN}0200{LIGNE1}
291100703150215{TRI2}
2911004{LIGNE2_ALIGN}0200{LIGNE2}
{PRETRI1}
2911008{ACPRINT_ALIGN}0150{ACPRINT}
{PRETRI2}
2e2309203980060C{CBTRI}
191100304330097{EXAPASS_PARCEL}
291100203800042{WEIGHT} kg
291100203200042{DATE}
291100504500010{MSG}
291100102550338Destinataire
291100201950338Tél.: {DADDR_0}
291100302550321{DADDR_1}
291100302550306{DADDR_2}
291100302550291{DADDR_3}
291100302550276{DADDR_4}
291100302550261{DADDR_5}
291100302550246{DADDR_6}
291100302550231{DADDR_7}
FB+
2911A1802550205{LPFX}-{DADDR_8}
FB-
291200202550187{DADDR_9}
291100202550171Expéditeur Tél.: {SADDR_0}
291100202550160{SADDR_1}
291100202550149{SADDR_2}
291100202550138{SADDR_3}
291100202550127{SADDR_4}
291100202550115F-{SADDR_5}
1X1100000070100b0013010000010001
FB+
2911A0801030101Nb.:
2911A08003201011 / 1
FB-
291100202550098N'.chr(248).' réf.:
291100202550085EXP{REFERENCE}
291100202550065{DADDR_INSTR1}
291100202550045{DADDR_INSTR2}
',
'ICI' => '191100005740040ICI Colis est un produit d\'ICI relais, marque appartenant à Exapaq SAS.
191100005670040Soumis aux conditions générales de vente de la FFOCT et aux conditions
191100005610040particulières de prestation d\'EXAPAQ. Notre responsabilité est contractuellement
191100005540040limitée à EUR 23,00 par KG transporté.
291100105780342ICI COLIS
291100105780335www.icirelais.com
1Y1100003400290ICICOLIS
1d0309204560100{EXAPASS_BARCODE}
1X1100005470100l01800003
1X1100004530100l01800003
1X1100002620040b0245018900010001
1X1100002620255l00010188
1X1100000070186b0165025300020002
1e230080000{SHIPPING_ALIGN}{SHIPPING_BC}
1X1100000070113b0071025300010001
1X1100000070040b0040025300010001
291100704480250{TOURPRINT}
2911007{TOURALIGN}0250{TOUR}
291100702870250{SMALL}
291100704150215{TRI1}
2911004{LIGNE1_ALIGN}0200{LIGNE1}
291100703150215{TRI2}
2911004{LIGNE2_ALIGN}0200{LIGNE2}
{PRETRI1}
2911008{ACPRINT_ALIGN}0150{ACPRINT}
{PRETRI2}
2e2309203980060C{CBTRI}
191100304330097{EXAPASS_PARCEL}
291100203800042{WEIGHT} kg
291100203200042{DATE}
291100102550338Destinataire
FB+
2911A1402550315RELAIS : {PR}
FB-
2X1100000090313l00020250
291100102550304Pour :
291100302550290{DADDR_3}
291100302550276{DADDR_4}
2X1100000090274l00020250
291100302550258{DADDR_0}
291100302550244{DADDR_1}
291100302550230F-{DADDR_2}
FB+
2911A0802520213POUR RETOUR CONTACTER L\'EXPEDITEUR
FB-
A5
1X1100000090206l00250249
A2
291100202550171Expéditeur Tél.: {SADDR_0}
291100202550160{SADDR_1}
291100202550149{SADDR_2}
291100202550138{SADDR_3}
291100202550127{SADDR_4}
291100202550115F-{SADDR_5}
1X1100000070100b0013010000010001
FB+
2911A0801030101Nb.:
2911A08003201011 / 1
FB-
291100202550098N'.chr(248).' réf.:
291100202550085EXP{REFERENCE}
291100202550067ICI-PASS
FB+
2911A1202300045{EXAPASS}
FB-
',
);
class ExapaqCarrier {
public $displayName = 'Exapaq';
public function checkavailability() {
return TRUE;
}
public function __toString() {
return $this->displayName;
}
private function stripaccents($str) {
return preg_replace(
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i',
'$1',
htmlentities($str, ENT_NOQUOTES, 'UTF-8')
);
}
public function registerParcel($order, $products, $weight) {
if((int) Db::getInstance()->getValue('
SELECT `id_cart`
FROM `'._DB_PREFIX_.'icirelais_selected`
WHERE `id_cart` = (
SELECT `id_cart`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int) $order->id.'
LIMIT 1
)
')) {
$delivery_mode = 'b2c';
} else {
$delivery_mode = 'b2b';
}
$shipping_number = sprintf('%09d', $this->getShippingNumber((int) $order->id));
$exapass = '250'.sprintf('%03d', Configuration::get('EXAPAQWS_'.strtoupper($delivery_mode).'_AGENCYCODE')).$shipping_number;
$key1 = sprintf('%02d', (98 - ((int) $exapass * 100 % 97)) % 97);
$exapass .= $key1;
$i = (int) substr($exapass, 0, 1) + (int) substr($exapass, 2, 1) + (int) substr($exapass, 4, 1) + (int) substr($exapass, 6, 1) + (int) substr($exapass, 8, 1) + (int) substr($exapass, 10, 1) + (int) substr($exapass, 12, 1) + (int) substr($exapass, 14, 1) + (int) substr($exapass, 16, 1);
$p = (int) substr($exapass, 1, 1) + (int) substr($exapass, 3, 1) + (int) substr($exapass, 5, 1) + (int) substr($exapass, 7, 1) + (int) substr($exapass, 9, 1) + (int) substr($exapass, 11, 1) + (int) substr($exapass, 13, 1) + (int) substr($exapass, 15, 1);
$t = ($i * 3) + $p;
$m = ceil($t / 10) * 10;
$key2 = (($m - $t) + 1) % 10;
$exapass .= $key2;
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223') {
$order->shipping_number = $exapass;
$order->id_carrier_shipping = (int) Configuration::get('ICIRELAIS_ID_CARRIER');
$order->update();
}
return array('', array(
'exapass' => $exapass,
'shipping_number' => $shipping_number,
));
}
public function getShippingNumber($id_order) {
if((int) Db::getInstance()->getValue('
SELECT `id_cart`
FROM `'._DB_PREFIX_.'icirelais_selected`
WHERE `id_cart` = (
SELECT `id_cart`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int) $id_order.'
LIMIT 1
)
')) {
$delivery_mode = 'b2c';
} else {
$delivery_mode = 'b2b';
}
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "exapaq"
AND `delivery_mode` = "'.pSQL($delivery_mode).'"
FOR UPDATE
');
$shipping_number = (int) $res[0]['value'] + 1;
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $shipping_number.'"
WHERE `carrier` = "exapaq"
AND `delivery_mode` = "'.pSQL($delivery_mode).'"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'exapaqws_shippingnumber`
VALUES (
'.(int) $shipping_number.',
'.(int) $id_order.'
)
');
if((int) $shipping_number + 2000 >= (int) Configuration::get('EXAPAQWS_'.strtoupper($delivery_mode).'_SHIPPINGHIGH')) { // TODO: Move to cron
mail('perron@antadis.com', '[PSS] Renouvellement Plage '.strtoupper($delivery_mode).' Exapaq', $shipping_number);
}
return $shipping_number;
}
public function renderLabel($order, $weight, $shipping_data) {
global $cookie, $exapaq_formats;
$exp_firstname = Configuration::get('EXAPAQWS_EXP_FIRSTNAME');
$exp_lastname = Configuration::get('EXAPAQWS_EXP_LASTNAME');
$exp_company = Configuration::get('EXAPAQWS_EXP_COMPANY');
if(!empty($exp_firstname)) {
$sender_lines[] = $exp_firstname.' '.$exp_lastname;
}
if(!empty($exp_company)) {
$sender_lines[] = $exp_company;
}
$sender_lines[] = Configuration::get('EXAPAQWS_EXP_ADDR1');
$sender_lines[] = Configuration::get('EXAPAQWS_EXP_ADDR2');
$sender_line1 = isset($sender_lines[0])? $sender_lines[0]: '';
$sender_line2 = isset($sender_lines[1])? $sender_lines[1]: '';
$sender_line3 = isset($sender_lines[2])? $sender_lines[2]: '';
$sender_line4 = isset($sender_lines[3])? $sender_lines[3]: '';
$sender_postal = Configuration::get('EXAPAQWS_EXP_POSTALCODE');
$sender_city = Configuration::get('EXAPAQWS_EXP_CITY');
$sender_phone = Configuration::get('EXAPAQWS_EXP_PHONE');
if($delivery_infos = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'icirelais_selected`
WHERE `id_cart` = '.(int) $order->id_cart.'
')) {
$delivery_address = new Address((int) $order->id_address_delivery);
if(!Validate::isLoadedObject($delivery_address) || strtoupper(Country::getIsoById($delivery_address->id_country)) != 'FR') {
return FALSE;
}
$route = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'exapaqws_route`
WHERE `iso_code` = "FR"
AND (
("'.pSQL($delivery_infos['postcode']).'" BETWEEN `postcode_start` AND `postcode_end`)
OR (`postcode_start` IS NULL)
OR (`postcode_start` = "")
)
');
if(!$route) {
return 'route_error';
}
$shipping_number = $shipping_data['shipping_number'];
$exapass = $shipping_data['exapass'];
$exapass_legend = substr($exapass, 0, 15);
$i = (int) substr($exapass_legend, 0, 1) + (int) substr($exapass_legend, 2, 1) + (int) substr($exapass_legend, 4, 1) + (int) substr($exapass_legend, 6, 1) + (int) substr($exapass_legend, 8, 1) + (int) substr($exapass_legend, 10, 1) + (int) substr($exapass_legend, 12, 1) + (int) substr($exapass_legend, 14, 1);
$p = (int) substr($exapass_legend, 1, 1) + (int) substr($exapass_legend, 3, 1) + (int) substr($exapass_legend, 5, 1) + (int) substr($exapass_legend, 7, 1) + (int) substr($exapass_legend, 9, 1) + (int) substr($exapass_legend, 11, 1) + (int) substr($exapass_legend, 13, 1);
$t = ($i * 3) + $p;
$m = ceil($t / 10) * 10;
$key3 = $m - $t;
$exapass_legend .= $key3;
$dest_name0 = '';
$dest_name1 = '';
if($delivery_address->company == '') {
$dest_name0 = mb_substr($delivery_address->lastname, 0, 32);
$dest_name1 = mb_substr($delivery_address->firstname, 0, 32);
} else {
$dest_name0 = mb_substr($delivery_address->lastname, 0, 32);
$dest_name1 = mb_substr($delivery_address->company, 0, 32);
}
$shipping_bc = mb_substr(mb_strtoupper($this->stripaccents(str_replace(
array(' ', '', '', '', '“', '”', '„', '†', '‡', '‰', '', '', '♠', '♣', '♥', '♦', '‾', '←', '↑', '→', '↓', '™', '', '!', '“', '#', '$', '%', '&', '', '(', ')', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', ']', '_', '`', '{', '|', '', '}', '~', '', '—', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', ),
'',
trim($delivery_infos['relay_id'])
))), 0, 12);
$format = str_replace(
array(
'{EXAPASS_BARCODE}',
'{SHIPPING_BC}',
'{SHIPPING_ALIGN}',
'{TOURPRINT}',
'{TOUR}',
'{TOURALIGN}',
'{SMALL}',
'{TRI1}',
'{LIGNE1}',
'{LIGNE1_ALIGN}',
'{TRI2}',
'{LIGNE2}',
'{LIGNE2_ALIGN}',
'{ACPRINT}',
'{ACPRINT_ALIGN}',
'{PRETRI1}',
'{PRETRI2}',
'{CBTRI}',
'{EXAPASS_PARCEL}',
'{WEIGHT}',
'{DATE}',
'{PR}',
'{DADDR_0}',
'{DADDR_1}',
'{DADDR_2}',
'{DADDR_3}',
'{DADDR_4}',
'{SADDR_0}',
'{SADDR_1}',
'{SADDR_2}',
'{SADDR_3}',
'{SADDR_4}',
'{SADDR_5}',
'{REFERENCE}',
'{EXAPASS}',
),
array(
$exapass,
$shipping_bc,
strlen($shipping_bc) == 12? '0103': (strlen($shipping_bc) == 11? '0118': (strlen($shipping_bc) == 10? '0136': (strlen($shipping_bc) == 9? '0153': (strlen($shipping_bc) == 8? '0168': (strlen($shipping_bc) == 7? '0183': (strlen($shipping_bc) == 6? '0198': (strlen($shipping_bc) == 5? '0212': (strlen($shipping_bc) == 4? '0233': (strlen($shipping_bc) == 3? '0248': '0263'))))))))),
trim($route['tourprint']),
trim($route['tour']),
strlen(trim($route['tour'])) == 1? '0368': (strlen(trim($route['tour'])) == 2? '0376': '0384'),
(float) $weight <= 1.0? 'P': '',
trim($route['tri1']),
trim($route['ligne1']),
strlen(trim($route['tri1'])) == 1? '0409': '0413',
trim($route['tri2']),
trim($route['ligne2']),
strlen(trim($route['tri2'])) == 1? '0309': '0313',
trim($route['acprint']),
strlen(trim($route['acprint'])) == 1? '0366': (strlen(trim($route['acprint'])) == 2? '0378': '0390'),
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100003950162l00250032': '',
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100002850162l00250032': '',
trim($route['cbtri']),
substr($exapass_legend, 3, 3).' '.substr($exapass_legend, 6, 9).' '.substr($exapass_legend, 15, 1),
number_format($weight * 0.8, 2, '.', ''),
date('d.m.Y'),
$delivery_infos['relay_id'],
mb_substr(mb_strtoupper($this->stripaccents($delivery_infos['company'])), 0, 32),
mb_substr(mb_strtoupper($this->stripaccents($delivery_infos['address1'])), 0, 32),
mb_substr(mb_strtoupper($this->stripaccents($delivery_infos['postcode'].' '.$delivery_infos['city'])), 0, 32),
mb_strtoupper($this->stripaccents($dest_name0)),
mb_strtoupper($this->stripaccents($dest_name1)),
$sender_phone,
$sender_line1,
$sender_line3,
$sender_line4,
$sender_line2,
$sender_postal.' '.$sender_city,
$order->id,
substr($exapass, 0, 3).' '.substr($exapass, 3, 3).' '.substr($exapass, 6, 9).' '.substr($exapass, 15),
),
$exapaq_formats['ICI']
);
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'exapaqws_parcel_route` VALUES (
"'.pSQL($exapass).'",
'.(int) $order->id.',
'.((float) $weight * 0.8).',
"'.pSQL($route['iso_code']).'",
"'.pSQL($route['lpfx']).'",
"'.pSQL($route['tri1']).'",
"'.pSQL($route['ligne1']).'",
"'.pSQL($route['tri2']).'",
"'.pSQL($route['ligne2']).'",
"'.pSQL($route['ac']).'",
"'.pSQL($route['acprint']).'",
"'.pSQL($route['tour']).'",
"'.pSQL($route['tourprint']).'",
"'.pSQL($route['pretri']).'",
"'.pSQL($route['cbtri']).'",
"'.pSQL($route['msg'] == 1? 'EXPORT A REETIQUETER': ($route['msg'] == 2? 'EXPORT A REETIQUETER AU TRI': '')).'"
)
');
return $format;
} else {
$delivery_address = new Address((int) $order->id_address_delivery);
if(!Validate::isLoadedObject($delivery_address)/* || strtoupper(Country::getIsoById($delivery_address->id_country)) != 'FR'*/) {
return FALSE;
}
$route = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'exapaqws_route`
WHERE `iso_code` = "'.pSQL(strtoupper(Country::getIsoById($delivery_address->id_country))).'"
AND (
("'.pSQL($delivery_address->postcode).'" BETWEEN `postcode_start` AND `postcode_end`)
OR (`postcode_start` IS NULL)
OR (`postcode_start` = "")
)
');
if(!$route) {
return 'route_error';
}
$shipping_number = $shipping_data['shipping_number'];
$exapass = $shipping_data['exapass'];
$exapass_legend = substr($exapass, 0, 15);
$i = (int) substr($exapass_legend, 0, 1) + (int) substr($exapass_legend, 2, 1) + (int) substr($exapass_legend, 4, 1) + (int) substr($exapass_legend, 6, 1) + (int) substr($exapass_legend, 8, 1) + (int) substr($exapass_legend, 10, 1) + (int) substr($exapass_legend, 12, 1) + (int) substr($exapass_legend, 14, 1);
$p = (int) substr($exapass_legend, 1, 1) + (int) substr($exapass_legend, 3, 1) + (int) substr($exapass_legend, 5, 1) + (int) substr($exapass_legend, 7, 1) + (int) substr($exapass_legend, 9, 1) + (int) substr($exapass_legend, 11, 1) + (int) substr($exapass_legend, 13, 1);
$t = ($i * 3) + $p;
$m = ceil($t / 10) * 10;
$key3 = $m - $t;
$exapass_legend .= $key3;
$dest_lines = array();
if($delivery_address->company != '') {
$dest_lines[] = trim(mb_substr($delivery_address->company, 0, 32));
}
if(mb_strlen($delivery_address->lastname.' '.$delivery_address->firstname) > 32) {
$dest_lines[] = trim(mb_substr($delivery_address->lastname, 0, 32));
$dest_lines[] = trim(mb_substr($delivery_address->firstname, 0, 32));
} else {
$dest_lines[] = trim(mb_substr($delivery_address->lastname.' '.$delivery_address->firstname, 0, 32));
}
if(mb_strlen($delivery_address->address1) > 32) {
$dest_lines[] = trim(mb_substr($delivery_address->address1, 0, 32));
$dest_lines[] = trim(mb_substr($delivery_address->address1, 32));
} else {
$dest_lines[] = trim($delivery_address->address1);
}
if(mb_strlen($delivery_address->address2) > 32) {
$dest_lines[] = trim(mb_substr($delivery_address->address2, 0, 32));
$dest_lines[] = trim(mb_substr($delivery_address->address2, 32));
} else {
$dest_lines[] = trim($delivery_address->address2);
}
$shipping_bc = mb_substr(mb_strtoupper($this->stripaccents(str_replace(
array(' ', '', '', '', '“', '”', '„', '†', '‡', '‰', '', '', '♠', '♣', '♥', '♦', '‾', '←', '↑', '→', '↓', '™', '', '!', '“', '#', '$', '%', '&', '', '(', ')', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', ']', '_', '`', '{', '|', '', '}', '~', '', '—', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', ),
'',
trim($delivery_address->company != ''? $delivery_address->company: $delivery_address->lastname.' '.$delivery_address->firstname)
))), 0, 12);
$format = str_replace(
array(
'{EXASANTE}',
'{EXAPASS_BARCODE}',
'{SHIPPING_BC}',
'{SHIPPING_ALIGN}',
'{TOURPRINT}',
'{TOUR}',
'{TOURALIGN}',
'{SMALL}',
'{TRI1}',
'{LIGNE1}',
'{LIGNE1_ALIGN}',
'{TRI2}',
'{LIGNE2}',
'{LIGNE2_ALIGN}',
'{ACPRINT}',
'{ACPRINT_ALIGN}',
'{PRETRI1}',
'{PRETRI2}',
'{CBTRI}',
'{EXAPASS_PARCEL}',
'{WEIGHT}',
'{DATE}',
'{MSG}',
'{DADDR_0}',
'{DADDR_1}',
'{DADDR_2}',
'{DADDR_3}',
'{DADDR_4}',
'{DADDR_5}',
'{DADDR_6}',
'{DADDR_7}',
'{DADDR_8}',
'{DADDR_9}',
'{SADDR_0}',
'{SADDR_1}',
'{SADDR_2}',
'{SADDR_3}',
'{SADDR_4}',
'{SADDR_5}',
'{REFERENCE}',
'{DADDR_INSTR1}',
'{DADDR_INSTR2}',
'{LPFX}',
),
array(
(int) Configuration::get('EXPAQWS_EXASANTE')? 'EXASANTE': '',
$exapass,
$shipping_bc,
strlen($shipping_bc) == 12? '0103': (strlen($shipping_bc) == 11? '0118': (strlen($shipping_bc) == 10? '0136': (strlen($shipping_bc) == 9? '0153': (strlen($shipping_bc) == 8? '0168': (strlen($shipping_bc) == 7? '0183': (strlen($shipping_bc) == 6? '0198': (strlen($shipping_bc) == 5? '0212': (strlen($shipping_bc) == 4? '0233': (strlen($shipping_bc) == 3? '0248': '0263'))))))))),
trim($route['tourprint']),
trim($route['tour']),
strlen(trim($route['tour'])) == 1? '0368': (strlen(trim($route['tour'])) == 2? '0376': '0384'),
(float) $weight <= 1.0? 'P': '',
trim($route['tri1']),
trim($route['ligne1']),
strlen(trim($route['tri1'])) == 1? '0409': '0413',
trim($route['tri2']),
trim($route['ligne2']),
strlen(trim($route['tri2'])) == 1? '0309': '0313',
trim($route['acprint']),
strlen(trim($route['acprint'])) == 1? '0366': (strlen(trim($route['acprint'])) == 2? '0378': '0390'),
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100003950162l00250032': '',
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100002850162l00250032': '',
trim($route['cbtri']),
substr($exapass_legend, 3, 3).' '.substr($exapass_legend, 6, 9).' '.substr($exapass_legend, 15, 1),
number_format($weight * 0.8, 2, '.', ''),
date('d.m.Y'),
(int) $route['msg'] == 1? 'EXPORT A REETIQUETER': ((int) $route['msg'] == 2? 'EXPORT A REETIQUETER AU TRI': ''),
$delivery_address->phone_mobile != ''? $delivery_address->phone_mobile: $delivery_address->phone,
isset($dest_lines[0])? $dest_lines[0]: '',
isset($dest_lines[1])? $dest_lines[1]: '',
isset($dest_lines[2])? $dest_lines[2]: '',
isset($dest_lines[3])? $dest_lines[3]: '',
isset($dest_lines[4])? $dest_lines[4]: '',
isset($dest_lines[5])? $dest_lines[5]: '',
isset($dest_lines[6])? $dest_lines[6]: '',
$delivery_address->postcode,
mb_substr(mb_strtoupper($this->stripaccents($delivery_address->city)), 0, 42),
$sender_phone,
$sender_line1,
$sender_line3,
$sender_line4,
$sender_line2,
$sender_postal.' '.$sender_city,
$order->id,
mb_substr($delivery_address->other, 0, 32),
mb_substr($delivery_address->other, 32, 32),
trim($route['lpfx']),
),
$exapaq_formats['DOM']
);
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'exapaqws_parcel_route` VALUES (
"'.pSQL($exapass).'",
'.(int) $order->id.',
'.((float) $weight * 0.8).',
"'.pSQL($route['iso_code']).'",
"'.pSQL($route['lpfx']).'",
"'.pSQL($route['tri1']).'",
"'.pSQL($route['ligne1']).'",
"'.pSQL($route['tri2']).'",
"'.pSQL($route['ligne2']).'",
"'.pSQL($route['ac']).'",
"'.pSQL($route['acprint']).'",
"'.pSQL($route['tour']).'",
"'.pSQL($route['tourprint']).'",
"'.pSQL($route['pretri']).'",
"'.pSQL($route['cbtri']).'",
"'.pSQL($route['msg'] == 1? 'EXPORT A REETIQUETER': ($route['msg'] == 2? 'EXPORT A REETIQUETER AU TRI': '')).'"
)
');
return $format;
}
return FALSE;
}
public function logParcel($shipping_data, $products) {
global $cookie;
foreach($products as $k => $v) {
if($v > 0) {
Db::getInstance()->ExecuteS('
INSERT `'._DB_PREFIX_.'exapaqws` VALUES (
'.(int) $k.',
'.(int) $cookie->id_employee.',
'.(int) $v.',
"'.pSQL($shipping_data['exapass']).'",
NOW()
)
');
}
}
}
public function addOrderHistory($shipping_data, $order, $products_sent) {
global $cookie;
$exapaq_carrier_id = unserialize(Configuration::get('EXAPAQWS_CARRIERS'));
$exapaq_carrier_id = (int) array_pop($exapaq_carrier_id);
$carrier = new Carrier($exapaq_carrier_id? $exapaq_carrier_id: (int) Configuration::get('ICIRELAIS_ID_CARRIER'), (int) $cookie->id_lang);
$customer = new Customer((int) $order->id_customer);
$templateVars = array(
'{followup}' => str_replace('@', $shipping_data['exapass'], $carrier->url),
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
'{product_list}' => !empty($products_sent)? '<strong>Contenu du colis :</strong>'.$products_sent: '',
'{product_list_txt}' => !empty($products_sent)? 'Contenu du colis :'.strip_tags($products_sent): '',
);
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$fully_sent = TRUE;
$products_sent = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'exapaqws` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] > 0) {
$fully_sent = FALSE;
break;
} else {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
$order_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_sale`
FROM `'._DB_PREFIX_.'privatesale`
WHERE `id_category` IN (
SELECT `id_category_default`
FROM `'._DB_PREFIX_.'product`
WHERE `id_product` IN (
SELECT `product_id`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
'.(count($products_sent) > 0? ' AND `id_order_detail` NOT IN ('.implode(', ', $products_sent).')': '').'
)
)
') as $order_sale) {
$order_sales[] = (int) $order_sale['id_sale'];
}
if(Db::getInstance()->getRow('
SELECT `product_id`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
'.(count($products_sent) > 0? ' AND `id_order_detail` NOT IN ('.implode(', ', $products_sent).')': '').'
AND `product_id` IN (
SELECT `id_product` FROM `'._DB_PREFIX_.'product_ps_cache` WHERE `id_sale` = 0
)
')) {
$order_sales[] = 999999;
}
if(count($order_sales) > 0) {
$cpt = array(1 => 0, 2 => 0);
foreach(Db::getInstance()->ExecuteS('
SELECT `id_shipping`, COUNT(`id_sale`) AS `sale_count`
FROM `'._DB_PREFIX_.'privatesale_shipping_sale`
WHERE `id_sale` IN ('.implode(', ', $order_sales).')
AND `id_sale` NOT IN (
SELECT `id_sale`
FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) $order->id.'
AND `id_sale` IN ('.implode(', ', $order_sales).')
)
GROUP BY `id_shipping`
') as $cpt_sale) {
$cpt[(int) $cpt_sale['id_shipping']] = (int) $cpt_sale['sale_count'];
}
if($cpt[1] == 0 && $cpt[2] == 0) {
$fully_sent = TRUE;
}
}
$history->changeIdOrderState(($fully_sent? Configuration::get('PS_OS_SHIPPING'): 17), (int) $order->id);
$history->id_employee = (int) $cookie->id_employee;
$history->addWithemail(TRUE, $templateVars);
global $_LANGMAIL;
$subject = 'Package in transit';
Mail::Send(
intval($order->id_lang),
'in_transit',
(
(is_array($_LANGMAIL) && key_exists($subject, $_LANGMAIL))
? $_LANGMAIL[$subject]
: $subject
),
$templateVars,
$customer->email,
$customer->firstname.' '.$customer->lastname
);
}
}