_html .= '
'.$this->l('Registration complete, label sent to printer').'
';
$this->renderLabel('', '6A12345123451', 323, 0.24);
} elseif(Tools::getValue('getProducts') && $id_order = (int) Tools::getValue('id_order')) {
echo json_encode(Db::getInstance()->ExecuteS('
SELECT d.`product_id`, d.`product_attribute_id`, d.`product_name`, d.`product_quantity`, d.`product_reference`, d.`product_quantity_refunded`, c.`firstname`, c.`lastname`, IF(d.`product_attribute_id` = 0, (SELECT p.`location` FROM `'._DB_PREFIX_.'product` p WHERE p.`id_product` = d.`product_id` LIMIT 1), (SELECT p.`location` FROM `'._DB_PREFIX_.'product_attribute` p WHERE p.`id_product_attribute` = d.`product_attribute_id` LIMIT 1)) AS `location`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON o.`id_order` = d.`id_order`
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON c.`id_customer` = o.`id_customer`
WHERE d.`id_order` = '.(int) $id_order.'
'));
exit;
} elseif(Tools::isSubmit('submitShip') && ($id_order = (int) Tools::getValue('id_order'))) {
$order = new Order((int) $id_order);
if(Validate::isLoadedObject($order)) {
$weight = (float) Tools::getValue('weight', 0.24);
$parcel = new Parcel();
$parcel->attachOrder($id_order);
$parcel->setWeight($weight);
$result = $parcel->send();
if(!$result || $result && (get_class($result) == 'SoapFault')) {
$this->_html .= ''.$this->l('An error happened during the parcel registration process').'
';
} else {
if($result->getLetterColissimoReturn->errorID != 0 && ((string) $result->getLetterColissimoReturn->error) != '') {
$this->_html .= ''.$result->getLetterColissimoReturn->error.'
';
} else {
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223') {
$socolissimo_carrier = Db::getInstance()->getRow('
SELECT `id_carrier`
FROM `'._DB_PREFIX_.'carrier`
WHERE `external_module_name` = "socolissimo"
AND `deleted` = 0
ORDER BY `id_carrier` DESC
');
$order->shipping_number = $result->getLetterColissimoReturn->parcelNumber;
$order->update();
}
$render = $this->renderLabel($result->getLetterColissimoReturn->PdfUrl, $result->getLetterColissimoReturn->parcelNumber, $order->id, $weight);
if($render === TRUE) {
$this->_html .= ''.$this->l('Registration complete, label sent to printer').'
';
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223') {
Db::getInstance()->ExecuteS('
INSERT `'._DB_PREFIX_.'lapostews2` VALUES (
'.(int) $order->id.',
'.(int) $cookie->id_employee.',
"'.pSQL($result->getLetterColissimoReturn->parcelNumber).'",
NOW()
)
');
$carrier = new Carrier((int) $order->id_carrier, (int) $cookie->id_lang);
$customer = new Customer((int) $order->id_customer);
$templateVars = array(
'{followup}' => str_replace('@', $result->getLetterColissimoReturn->parcelNumber, $carrier->url),
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
'{product_list}' => '',
'{product_list_txt}' => '',
);
$history = new OrderHistory();
$history->id_order = $id_order;
$history->changeIdOrderState(Configuration::get('PS_OS_SHIPPING'), $id_order);
$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
);
}
} elseif($render === 'pr_error') {
$this->_html .= ''.$this->l('Unknown delivery point').'
';
} else {
$this->_html .= ''.$this->l('An error happened during the label rendering').'
';
}
}
}
}
echo $this->_html;
exit;
}
}
public function display() {
global $cookie;
setlocale(LC_CTYPE, 'fr_FR');
if(!$this->checkServiceAvailability()) {
$this->_html .= ''.$this->l('Webservices are unavailable at the moment, please try again later.').'
';
} else {
include_once _PS_ROOT_DIR_.'/modules/privatesales/Sale.php';
$sales_list = array();
if(isset($_COOKIE['lpws_sales'])) {
foreach(explode('-', $_COOKIE['lpws_sales']) as $chunk) {
$sales_list[] = (int) $chunk;
}
}
$this->_html .= '
';
$this->_html .= '
'.$this->l('Barcode input:').'
';
if(count($sales_list) > 0) {
$orders_cache = array();
$sales_cache = array();
$this->_html .= '
'.$this->l('Single sale orders').'
'.$this->l('ID order').'
'.$this->l('Customer').'
'.$this->l('Date').'
'.$this->l('Already sent').'
'.$this->l('Actions').'
';
foreach($sales_list as $id_sale) {
$sales_cache[$id_sale] = new Sale($id_sale);
$sale_orders = $sales_cache[$id_sale]->getOrdersFromSale(NULL, TRUE);
$orders_cache = array_merge($orders_cache, $sale_orders);
foreach(Db::getInstance()->ExecuteS('
SELECT o.`id_order`, o.`id_customer`, c.`firstname`, c.`lastname`, o.`date_add`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON c.`id_customer` = o.`id_customer`
WHERE o.`id_order` IN ('.implode(', ', $sale_orders).')
AND o.`valid` = 1
') as $order) {
$this->_html .= '
'.(int) $order['id_order'].'
'.$order['firstname'].' '.mb_strtoupper($order['lastname']).'
'.$order['date_add'].'
'.(int) Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'lapostews2` WHERE `id_order` = '.(int) $order['id_order']).'
'.$this->l('Product list').'
'.$this->l('Register the parcel and print the label').'
';
}
}
$this->_html .= '
'.$this->l('Multi-sales orders').'
'.$this->l('ID order').'
'.$this->l('Customer').'
'.$this->l('Date').'
'.$this->l('Already sent').'
'.$this->l('Actions').'
';
foreach($sales_list as $id_sale) {
$sale_orders = $sales_cache[$id_sale]->getOrdersFromSale(NULL, FALSE);
foreach(Db::getInstance()->ExecuteS('
SELECT o.`id_order`, o.`id_customer`, c.`firstname`, c.`lastname`, o.`date_add`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON c.`id_customer` = o.`id_customer`
WHERE o.`id_order` IN ('.implode(', ', $sale_orders).')
AND o.`id_order` NOT IN ('.implode(', ', $orders_cache).')
AND o.`valid` = 1
') as $order) {
$this->_html .= '
'.(int) $order['id_order'].'
'.$order['firstname'].' '.mb_strtoupper($order['lastname']).'
'.$order['date_add'].'
'.(int) Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'lapostews2` WHERE `id_order` = '.(int) $order['id_order']).'
'.$this->l('Product list').'
'.$this->l('Register the parcel and print the label').'
';
}
}
$this->_html .= '
';
}
}
echo $this->_html;
}
public function checkServiceAvailability() {
return trim(file_get_contents('http://ws.colissimo.fr/supervision-pudo-frame/supervision.jsp')) === '[OK]';
}
public function renderLabel($url=FALSE, $shipping_number=FALSE, $id_order=0, $weight=0.24) {
global $cookie;
$weight = 0.24;
/* Label print ***************************************************************/
$order = new Order((int) $id_order);
$delivery_address = new Address($order->id_address_delivery);
$invoice_address = new Address($order->id_address_invoice);
if(strlen($invoice_address->phone) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $invoice_address->phone)) {
$invoice_address->phone = '0'.substr(substr($invoice_address->phone, -10), 1);
}
}
if(strlen($invoice_address->phone_mobile) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $invoice_address->phone_mobile)) {
$invoice_address->phone_mobile = '0'.substr(substr($invoice_address->phone_mobile, -10), 1);
}
}
if(strlen($delivery_address->phone) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $delivery_address->phone)) {
$delivery_address->phone = '0'.substr(substr($delivery_address->phone, -10), 1);
}
}
if(strlen($delivery_address->phone_mobile) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $delivery_address->phone_mobile)) {
$delivery_address->phone_mobile = '0'.substr(substr($delivery_address->phone_mobile, -10), 1);
}
}
if($deliveryInfos = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $order->id_cart.'
')) {
$parceltype = $deliveryInfos['delivery_mode'];
if(in_array($parceltype, array('ACP', 'BPR', 'CDI', 'A2P', 'CIT'))) {
$dest_company = $invoice_address->company;
$dest_gender = ''; // '', 'M.', 'Mme', 'Mlle'
$dest_firstname = $invoice_address->firstname;
$dest_lastname = $invoice_address->lastname;
$dest_lines = array();
if(strlen($invoice_address->address1) > 34) {
$dest_lines[] = substr($invoice_address->address1, 0, 34);
$dest_lines[] = substr($invoice_address->address1, 34);
} else {
$dest_lines[] = $invoice_address->address1;
}
if(strlen($invoice_address->address2) > 34) {
$dest_lines[] = substr($invoice_address->address2, 0, 34);
$dest_lines[] = substr($invoice_address->address2, 34);
} else {
$dest_lines[] = $invoice_address->address2;
}
$dest_line1 = isset($dest_lines[0])? $dest_lines[0]: '';
$dest_line2 = isset($dest_lines[1])? $dest_lines[1]: '';
$dest_line3 = isset($dest_lines[2])? $dest_lines[2]: '';
$dest_line4 = isset($dest_lines[3])? $dest_lines[3]: '';
$dest_postal = $invoice_address->postcode;
$dest_postal_cab = $delivery_address->postcode;
$dest_city = $invoice_address->city;
$dest_phone = (!empty($invoice_address->phone)? $invoice_address->phone: $invoice_address->phone_mobile);
$dest_mobile = $invoice_address->phone_mobile;
$dest_code1 = '';
$dest_code2 = '';
$dest_interphone = '';
$dest_instructions = '';
$dest_bpr_infos = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'lapostews_pr`
WHERE `id_pr` = "'.pSQL($deliveryInfos['prid']).'"
');
if(!$dest_bpr_infos) {
return 'pr_error';
}
$dest_bpr_name = $dest_bpr_infos['name'];
$bpr_lines = array();
if(!empty($dest_bpr_infos['address1'])) {
$bpr_lines[] = $dest_bpr_infos['address1'];
}
if(!empty($dest_bpr_infos['address2'])) {
$bpr_lines[] = $dest_bpr_infos['address2'];
}
if(!empty($dest_bpr_infos['address3'])) {
$bpr_lines[] = $dest_bpr_infos['address3'];
}
if(!empty($dest_bpr_infos['address4'])) {
$bpr_lines[] = $dest_bpr_infos['address4'];
}
$dest_bpr_line1 = isset($bpr_lines[0])? $bpr_lines[0]: '';
$dest_bpr_line2 = isset($bpr_lines[1])? $bpr_lines[1]: '';
$dest_bpr_line3 = isset($bpr_lines[2])? $bpr_lines[2]: '';
$dest_bpr_postal = $dest_bpr_infos['postcode'];
$dest_bpr_city = $dest_bpr_infos['city'];
$dest_bpr_code1 = $dest_bpr_infos['code1'];
$dest_bpr_code2 = $dest_bpr_infos['code2'];
} else {
if($deliveryInfos['prfirstname'] == 'So Colissimo' && $deliveryInfos['delivery_mode'] == 'BPR') {
$dest_company = $deliveryInfos['prname'];
$dest_gender = ''; // '', 'M.', 'Mme', 'Mlle'
$dest_firstname = $delivery_address->firstname;
$dest_lastname = $delivery_address->lastname;
} else {
$dest_company = !empty($deliveryInfos['cecompanyname'])? $deliveryInfos['cecompanyname']: $deliveryInfos['prcompladress'];
$dest_gender = ''; // '', 'M.', 'Mme', 'Mlle'
$dest_firstname = $deliveryInfos['prfirstname'];
$dest_lastname = $deliveryInfos['prname'];
}
$dest_line1 = $deliveryInfos['pradress1'];
$dest_line2 = $deliveryInfos['pradress2'];
$dest_line3 = $deliveryInfos['pradress3'];
$dest_line4 = $deliveryInfos['pradress4'];
$dest_postal = $deliveryInfos['przipcode'];
$dest_postal_cab = $deliveryInfos['przipcode'];
$dest_city = $deliveryInfos['prtown'];
$dest_phone = (!empty($deliveryInfos['cephonenumber'])? $deliveryInfos['cephonenumber']: '');
$dest_mobile = $deliveryInfos['cephonenumber'];
if(strlen($dest_phone) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dest_phone)) {
$dest_phone = '0'.substr(substr($dest_phone, -10), 1);
}
}
if(strlen($dest_mobile) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $$dest_mobile)) {
$dest_mobile = '0'.substr(substr($dest_mobile, -10), 1);
}
}
$dest_code1 = $deliveryInfos['cedoorcode1'];
$dest_code2 = $deliveryInfos['cedoorcode2'];
$dest_interphone = '';
$dest_instructions = $deliveryInfos['cedeliveryinformation'];
$dest_bpr_name = '';
$dest_bpr_line1 = '';
$dest_bpr_line2 = '';
$dest_bpr_line3 = '';
$dest_bpr_postal = '';
$dest_bpr_city = '';
}
} else {
// TODO: better country handling
if($delivery_address->id_country != 8) { // not France
return FALSE;
}
$parceltype = 'COLD';
$dest_company = $delivery_address->company;
$dest_gender = ''; // '', 'M.', 'Mme', 'Mlle'
$dest_firstname = $delivery_address->firstname;
$dest_lastname = $delivery_address->lastname;
$dest_lines = array();
if(strlen($delivery_address->address1) > 34) {
$dest_lines[] = substr($delivery_address->address1, 0, 34);
$dest_lines[] = substr($delivery_address->address1, 34);
} else {
$dest_lines[] = $delivery_address->address1;
}
if(strlen($delivery_address->address2) > 34) {
$dest_lines[] = substr($delivery_address->address2, 0, 34);
$dest_lines[] = substr($delivery_address->address2, 34);
} else {
$dest_lines[] = $delivery_address->address2;
}
$dest_line1 = isset($dest_lines[0])? $dest_lines[0]: '';
$dest_line2 = isset($dest_lines[1])? $dest_lines[1]: '';
$dest_line3 = isset($dest_lines[2])? $dest_lines[2]: '';
$dest_line4 = isset($dest_lines[3])? $dest_lines[3]: '';
$dest_postal = $delivery_address->postcode;
$dest_postal_cab = $delivery_address->postcode;
$dest_city = $delivery_address->city;
$dest_phone = (!empty($delivery_address->phone)? $delivery_address->phone: $delivery_address->phone_mobile);
$dest_mobile = $delivery_address->phone_mobile;
$dest_code1 = '';
$dest_code2 = '';
$dest_interphone = '';
$dest_instructions = '';
$dest_bpr_name = '';
$dest_bpr_line1 = '';
$dest_bpr_line2 = '';
$dest_bpr_line3 = '';
$dest_bpr_postal = '';
$dest_bpr_city = '';
}
$qty = 1; // number of labels to print
$ref_client = $order->id;
$sender_lines = array();
$exp_firstname = Configuration::get('LAPOSTEWS_EXP_FIRSTNAME');
$exp_lastname = Configuration::get('LAPOSTEWS_EXP_LASTNAME');
$exp_company = Configuration::get('LAPOSTEWS_EXP_COMPANY');
if(!empty($exp_firstname)) {
$sender_lines[] = $exp_firstname.' '.$exp_lastname;
}
if(!empty($exp_company)) {
$sender_lines[] = $exp_company;
}
$sender_lines[] = Configuration::get('LAPOSTEWS_EXP_ADDR1');
$sender_lines[] = Configuration::get('LAPOSTEWS_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('LAPOSTEWS_EXP_POSTALCODE');
$sender_city = Configuration::get('LAPOSTEWS_EXP_CITY');
$sender_phone = Configuration::get('LAPOSTEWS_EXP_PHONE');
$contract = Configuration::get('LAPOSTEWS_API_CONTRACT');
$site = Configuration::get('LAPOSTEWS_SHIPPING_SITE');
$tracking = $shipping_number;
$tracking_fmt = substr($tracking, 0, 2).' '.substr($tracking, 2, 5).' '.substr($tracking, 7, 5).' '.substr($tracking, 12);
/* Format:
0..2 : Code produit => Valeur fixe : 6..
3 : Reconnaissance de tri => Valeur fixe : 1
4..9 : Code postal de livraison (ex : 72240 en FRANCE) ou (ex : AD100 en ANDORRE)
10..16 : Identifiant du client (ex : 900001)
17..20 : Poids exprimé en décagrammes (ex : 0860 = 8,6 kg)
21..22 : Tranche d'Assurance Ad Valorem ou niveau de recommandation : de 00 = 0 euro à 10 = 1500 euros,
21= R1, 22 = R2, 23 = R3
23 : Non mécanisable (0 = NON, 1 = OUI)
24 : (Zone réservée) => Valeur fixe : 0
25 : Lien de contrôle entre les 2 codes à barres de l’étiquette (suivi et prise en charge). Ce chiffre est égal au 12ème caractère du code de suivi
26 : Clé sur les 15 précédents caractères (à partir de la droite du lien de contrôle jusqu’à l’identifiant du client
compris)
La détermination du rang des caractères se fait à partir de la droite de la série de chiffres, c'est à dire de la position de la clé de
contrôle, qui reçoit le rang 1.
1. Somme de tous les chiffres de rang pair en partant de la droite
2. Multiplication de cette somme par 3
3. Somme des chiffres de rang impair en partant du caractère de rang 3
4. Somme des résultats obtenus en 2 et 3
5. Différence entre le résultat 4 et la dizaine supérieure. Le résultat de cette opération est la valeur de la clé de contrôle. Si le résultat est égal à 10 la clé prend la valeur 0.
*/
$handling = substr($tracking, 0, 2).'1'.($parceltype == 'A2P'? '91500': $dest_postal_cab).$contract.sprintf('%04d', $weight * 100).'00'.'0'.'0'.substr($tracking, 11, 1);
$key_chunks = str_split(substr(strrev($handling), 0, 15));$key_chunks_e = ($key_chunks[0] + $key_chunks[2] + $key_chunks[4] + $key_chunks[6] + $key_chunks[8] + $key_chunks[10] + $key_chunks[12] + $key_chunks[14]) * 3;
$key_chunks_o = $key_chunks[1] + $key_chunks[3] + $key_chunks[5] + $key_chunks[7] + $key_chunks[9] + $key_chunks[11] + $key_chunks[13];
$key_chunks_eo = $key_chunks_e + $key_chunks_o;
$handling_key = ((ceil($key_chunks_eo / 10) * 10) - $key_chunks_eo) % 10;
$handling .= $handling_key;
$handling_fmt = substr($handling, 0, 3).' '.substr($handling, 3, 5).' '.substr($handling, 8, 6).' '.substr($handling, 14, 4).' '.substr($handling, 18);
$result = chr(2).'n' /* Inch mode */.'
'.chr(2).'O0100' /* Start position */.'
'.chr(2).'L
'.'C0000'.'
'.'D11'.'
'.chr(2).'L
';
if($parceltype == 'DOM') { // SO à domicile
$result .= 'rDOM'.'
';
} elseif($parceltype == 'RDV') { // SO sur RDV
$result .= 'rRDV'.'
';
} elseif($parceltype == 'BPR') { // SO en bureau de poste
$result .= 'rBPR'.'
';
} elseif($parceltype == 'ACP') { // SO en agence ColiPoste
$result .= 'rBPR'.'
';
} elseif($parceltype == 'CDI') { // SO en centre de distribution
$result .= 'rBPR'.'
';
} elseif($parceltype == 'A2P') { // SO en commerce de proximité
$result .= 'rA2P'.'
';
} elseif($parceltype == 'MRL') { // SO à domicile (+?)
$result .= 'rMRL'.'
';
} elseif($parceltype == 'CIT') { // SO en cityssimo
$result .= 'rCIT'.'
';
} elseif($parceltype == 'DOS') { // SO à domicile contre signature
$result .= 'rDOS'.'
';
} elseif($parceltype == 'COLI') { // Colissimo Expert Inter
$result .= 'rCOLI'.'
';
} elseif($parceltype == 'COL') { // Colissimo Expert France
$result .= 'rCOL'.'
';
} elseif($parceltype == 'COM') { // Colissimo Access OM
$result .= 'rCOM'.'
';
} elseif($parceltype == 'COLD') { // Colissimo Access France
/*$result .= 'rCOLD'.'
';*/
$result .= 'rDOM'.'
';
} elseif($parceltype == 'COE') { // Colissimo Eco OM
// FORMAT MANQUANT
} elseif($parceltype == 'CORE') { // Colissimo Service France
$result .= 'rCORE'.'
';
} elseif($parceltype == 'CDS') { // Colissimo Expert OM
$result .= 'rCDS'.'
';
} elseif($parceltype == 'COP') { // Colissimo Expert Interne
// FORMAT MANQUANT
}
// Sender left block, max length: 24
if(in_array($parceltype, array('DOM', 'DOS', 'COL', 'COLD', 'RDV', 'ACP', 'BPR', 'CDI'))) {
$result .= '1911A0805000015'.mb_strtoupper(substr($sender_line1, 0, 24)).'
1911A0804880015'.mb_strtoupper(substr($sender_line2, 0, 26)).'
1911A0804760015'.mb_strtoupper(substr($sender_line3, 0, 26)).'
1911A0804640015'.mb_strtoupper(substr($sender_line4, 0, 26)).'
1911A0804520015'.mb_strtoupper(substr($sender_postal.' '.$sender_city, 0, 24)).'
1911A0804420015T'.chr(130).'l : '.mb_strtoupper(substr($sender_phone, 0, 18)).'
';
} elseif($parceltype == 'A2P') {
$result .= '1911A0605000242'.mb_strtoupper(substr($sender_line1, 0, 24)).'
1911A0604900242'.mb_strtoupper(substr($sender_line2, 0, 26)).'
1911A0604800242'.mb_strtoupper(substr($sender_line3, 0, 26)).'
1911A0604700242'.mb_strtoupper(substr($sender_line4, 0, 26)).'
1911A0604600242'.mb_strtoupper(substr($sender_postal.' '.$sender_city, 0, 24)).'
1911A0604500242T'.chr(130).'l : '.mb_strtoupper(substr($sender_phone, 0, 18)).'
';
} elseif($parceltype == 'CIT') {
$result .= '1911A0605000242'.mb_strtoupper(substr($sender_line1, 0, 24)).'
1911A0604900242'.mb_strtoupper(substr($sender_line2, 0, 26)).'
1911A0604800242'.mb_strtoupper(substr($sender_line3, 0, 26)).'
1911A0604700242'.mb_strtoupper(substr($sender_line4, 0, 26)).'
1911A0604600242'.mb_strtoupper(substr($sender_postal.' '.$sender_city, 0, 24)).'
1911A0604500242T'.chr(130).'l : '.mb_strtoupper(substr($sender_phone, 0, 18)).'
';
}
// Sender right block
if(in_array($parceltype, array('DOM', 'DOS', 'COL', 'COLD', 'RDV', 'ACP', 'BPR', 'CDI'))) {
$result .= '1911A0804880210SITE PCH: '.mb_strtoupper(substr($site, 0, 16)).'
1911A0805000210CODE CLIENT: '.$contract.'
1911A0804760210N'.chr(248).' Colis : '.$tracking_fmt.'
1911A0804640210Poids : '.sprintf('%.02f', $weight).' kg
1911A0804520210Edit'.chr(130).' le : '.date('d/m/Y').'
';
} elseif($parceltype == 'A2P') {
$result .= '1911A0604300244COMPTE CLIENT: '.$contract.'
1911A0604200244SITE PCH :'.mb_strtoupper(substr($site, 0, 16)).'
1911A0604100244N'.chr(248).' Colis : '.$tracking_fmt.'
1911A0604000244Poids : '.sprintf('%.02f', $weight).' kg
1911A0603900244Edit'.chr(130).' le : '.date('d/m/Y').'
';
} elseif($parceltype == 'CIT') {
$result .= '1911A0604300244COMPTE CLIENT: '.$contract.'
1911A0604200244SITE PCH :'.mb_strtoupper(substr($site, 0, 16)).'
1911A0604100244N'.chr(248).' Colis : '.$tracking_fmt.'
1911A0604000244Poids : '.sprintf('%.02f', $weight).' kg
1911A0603900244Edit'.chr(130).' le : '.date('d/m/Y').'
';
}
// Top line, customer reference
if(in_array($parceltype, array('DOM', 'DOS', 'COL', 'COLD', 'RDV', 'ACP', 'BPR', 'CDI'))) {
$result .= '1911A0805150130R'.chr(130).'f Client
1911A0805150180EXP'.mb_strtoupper(substr($ref_client, 0, 16)).'
';
} elseif($parceltype == 'A2P') {
$result .= '1911A0805150010R'.chr(130).'f Client: EXP'.mb_strtoupper(substr($ref_client, 0, 16)).'
';
} elseif($parceltype == 'CIT') {
$result .= '1911A0805150010R'.chr(130).'f Client: EXP'.mb_strtoupper(substr($ref_client, 0, 16)).'
';
}
// Tracking barcode
if(in_array($parceltype, array('DOM', 'DOS', 'COL', 'COLD', 'RDV', 'ACP', 'BPR', 'CDI'))) {
$result .= '
1e2310703250030B'.substr($tracking, 0, 3).'&D'.substr($tracking, 3).'
1911A0803080030N'.chr(248).' de colis : '.$tracking_fmt.'
';
} elseif($parceltype == 'A2P') {
$result .= '1e2310704000025B'.substr($tracking, 0, 3).'&D'.substr($tracking, 3).'
1911A0803830030N'.chr(248).' Colis: '.$tracking_fmt.'
';
} elseif($parceltype == 'CIT') {
$result .= '1e2310704000025B'.substr($tracking, 0, 3).'&D'.substr($tracking, 3).'
1911A0803830030N'.chr(248).' Colis: '.$tracking_fmt.'
';
}
// Right block
if(in_array($parceltype, array('DOM', 'DOS', 'COL', 'COLD', 'RDV'))) {
$result .= '4911A0603150330Code Porte 1 : '.mb_strtoupper(substr($dest_code1, 0, 8)).'
4911A0603150340Code Porte 2 : '.mb_strtoupper(substr($dest_code2, 0, 8)).'
4911A0603150350Interphone : '.mb_strtoupper(substr($dest_interphone, 0, 11)).'
4911A0603150360'.mb_strtoupper(substr($dest_interphone, 11, 19)).'
4911A0603150370Telephone Portable : '.mb_strtoupper(substr($dest_mobile, 0, 14)).'
4911A0603150380Telephone : '.mb_strtoupper(substr($dest_phone, 0, 14)).'
';
} elseif(in_array($parceltype, array('ACP', 'BPR', 'CDI'))) {
$result .= '4911A0603120305'.mb_strtoupper(substr($dest_line1, 0, 28)).'
4911A0603120315'.mb_strtoupper(substr($dest_line2, 0, 28)).'
4911A0603120325'.mb_strtoupper(substr($dest_line3, 0, 28)).'
4911A0603120335'.mb_strtoupper(substr($dest_line4, 0, 28)).'
4911A0603120345
4211A0603120355'.$dest_postal.' '.mb_strtoupper(substr($dest_city, 0, 16)).'
4211A0603120365'.mb_strtoupper(substr($dest_city, 16, 22)).'
4911A0603120375T'.chr(130).'l'.chr(130).'phone portable : '.substr($dest_mobile, 0, 14).'
';
}
// Recipient block
if(in_array($parceltype, array('DOM', 'DOS', 'COL', 'COLD', 'RDV'))) {
$result .= '1911A0802900027DESTINATAIRE
';
$lines = array();
if(!empty($dest_lastname)) {
$lines[] = (!empty($dest_gender)? $dest_gender.' ': '').$dest_lastname.' '.$dest_firstname;
}
if(!empty($dest_company)) {
$lines[] = $dest_company;
}
$lines[] = $dest_line1; // etage
$lines[] = $dest_line2; // batiment
$lines[] = $dest_line3; // rue
$lines[] = $dest_line4; // lieu dit
$result .= '1311A1202700027'.mb_strtoupper(substr($lines[0], 0, 38)).'
1311A0802520027'.mb_strtoupper(substr($lines[1], 0, 44)).'
1311A0802340027'.mb_strtoupper(substr($lines[2], 0, 34)).'
1311A0802160027'.mb_strtoupper(substr($lines[3], 0, 34)).'
1311A0801980027'.mb_strtoupper(substr($lines[4], 0, 34)).'
1111A0801500027T'.chr(130).'l : '.mb_strtoupper(substr($dest_phone, 0, 14)).'
1611A2401650027'.substr($dest_postal, 0, 5).'
1411A1001700120'.mb_strtoupper(substr($dest_city, 0, 22)).'
1411A1001500180'.mb_strtoupper(substr($dest_city, 22, 13)).'
1111A0601420027'.mb_strtoupper(substr($dest_instructions, 0, 70)).'
';
} elseif(in_array($parceltype, array('ACP', 'BPR', 'CDI'))) {
$result .= '1911A0802900027DESTINATAIRE
';
$result .= '1311A1202700027'.mb_strtoupper(substr($dest_bpr_name, 0, 44)).'
1311A0802520027'.mb_strtoupper(substr((!empty($dest_gender)? $dest_gender.' ': '').$dest_lastname.' '.$dest_firstname, 0, 44)).'
1311A0802340027'.mb_strtoupper(substr($dest_bpr_line1, 0, 34)).'
1311A0802160027'.mb_strtoupper(substr($dest_bpr_line2, 0, 34)).'
1311A0801980027'.mb_strtoupper(substr($dest_bpr_line3, 0, 34)).'
1611A2401650027'.substr($dest_bpr_postal, 0, 5).'
1411A1001700120'.mb_strtoupper(substr($dest_bpr_city, 0, 22)).'
1411A1001500180'.mb_strtoupper(substr($dest_bpr_city, 22, 13)).'
';
} elseif($parceltype == 'A2P') {
$result .= '1911A0803700027DESTINATAIRE
1311A0803500027'.mb_strtoupper(substr($dest_bpr_name, 0, 38)).'
1311A0803320027'.mb_strtoupper(substr((!empty($dest_gender)? $dest_gender.' ': '').$dest_lastname.' '.$dest_firstname, 0, 44)).'
1311A0803160027'.mb_strtoupper(substr($dest_bpr_line1, 0, 34)).'
1311A0802980027'.mb_strtoupper(substr($dest_bpr_line2, 0, 34)).'
1311A0802800027'.substr($dest_bpr_postal, 0, 5).' '.mb_strtoupper(substr($dest_bpr_city, 0, 28)).'
1611A240248002791500
1411A1002500120HUB RELAIS
1111A0602420027N'.chr(248).' de tel portable : '.substr($dest_mobile, 0, 16).'
';
} elseif($parceltype == 'CIT') {
$result .= '1911A0803700027DESTINATAIRE
1311A0803500027'.mb_strtoupper(substr($dest_bpr_name, 0, 38)).'
1311A0803320027'.mb_strtoupper(substr((!empty($dest_gender)? $dest_gender.' ': '').$dest_lastname.' '.$dest_firstname, 0, 44)).'
1311A0803160027'.mb_strtoupper(substr($dest_bpr_line1, 0, 34)).'
1311A0802980027'.mb_strtoupper(substr($dest_bpr_line2, 0, 34)).'
1311A0802800027'.mb_strtoupper(substr($dest_bpr_line3, 0, 34)).'
1611A2402450027'.substr($dest_bpr_postal, 0, 5).'
1411A1002500120'.mb_strtoupper(substr($dest_bpr_city, 0, 28)).'
';
}
// Handling barcode
if(in_array($parceltype, array('DOM', 'DOS', 'COL', 'COLD', 'RDV', 'ACP', 'CDI', 'BPR'))) {
$result .= '1e2310800300050B'.substr($handling, 0, 2).'&D'.substr($handling, 2).'
1911A0800150130N'.chr(248).' de PCH : '.$handling_fmt.'
';
} elseif($parceltype == 'A2P') {
$result .= '1e2310401350050B'.substr($handling, 0, 2).'&D'.substr($handling, 2).'
1911A0801170130N'.chr(248).' de PCH: '.$handling_fmt.'
';
} elseif($parceltype == 'CIT') {
$result .= '1e2310201370050B'.substr($handling, 0, 2).'&D'.substr($handling, 2).'
1911A0801220130N'.chr(248).' de PCH: '.$handling_fmt.'
';
}
// Hub barcode
if($parceltype == 'A2P') {
$hub_barcode = sprintf('%07d', $dest_bpr_postal).$tracking.'0'.'849'.'250';
$hub_key = '';
$iso = array(0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F', 16 => 'G', 17 => 'H', 18 => 'I', 19 => 'J', 20 => 'K', 21 => 'L', 22 => 'M', 23 => 'N', 24 => 'O', 25 => 'P', 26 => 'Q', 27 => 'R', 28 => 'S', 29 => 'T', 30 => 'U', 31 => 'V', 32 => 'W', 33 => 'X', 34 => 'Y', 35 => 'Z',);
$hub_barcode_chunks = str_split($hub_barcode);
$hub_mod = 36;
$hub_cs = 36;
for($i=0, $l=count($hub_barcode_chunks); $i<$l; $i++) {
$y = array_search($hub_barcode_chunks[$i], $iso);
$hub_cs += $y;
if($hub_cs > $hub_mod) {
$hub_cs -= $hub_mod;
}
$hub_cs *= 2;
if($hub_cs > $hub_mod) {
$hub_cs -= $hub_mod - 1;
}
}
$hub_cs = $hub_mod + 1 - $hub_cs;
if($hub_cs == $hub_mod) {
$hub_cs = 0;
}
$hub_key = $iso[$hub_cs];
$result .= '1911A1800890030'.$dest_bpr_code1.'
1911A1400900150SA13 REL
1911A1800890300'.$dest_bpr_code2.'
1911A0800000100'.substr($hub_barcode, 0, 4).' '.substr($hub_barcode, 4, 4).' '.substr($hub_barcode, 8, 4).' '.substr($hub_barcode, 12, 4).' '.substr($hub_barcode, 16, 4).' '.substr($hub_barcode, 20, 4).' '.substr($hub_barcode, 24).$hub_key.'
1e2308000110025B%&D'.substr($hub_barcode, 0, 8).'&E'.'M'.'&D'.substr($hub_barcode, 8).'
';
} elseif($parceltype == 'CIT') {
$lines = array();
if(!empty($dest_lastname)) {
$lines[] = (!empty($dest_gender)? $dest_gender.' ': '').$dest_lastname.' '.$dest_firstname;
}
if(!empty($dest_company)) {
$lines[] = $dest_company;
}
$lines[] = $dest_line1; // etage
$lines[] = $dest_line2; // batiment
$lines[] = $dest_line3; // rue
$lines[] = $dest_line4; // lieu dit
$result .= '1X1100000200190P0050001011001900110037000200370
1911A0600950195'.mb_strtoupper(substr($lines[0], 0, 38)).'
1911A0600850195'.mb_strtoupper(substr($lines[1], 0, 44)).'
1911A0600750195'.mb_strtoupper(substr($lines[2], 0, 34)).'
1911A0600650195'.mb_strtoupper(substr($lines[3], 0, 34)).'
1911A0600550195'.mb_strtoupper(substr($lines[4], 0, 34)).'
1211A0600450195'.substr($dest_postal, 0, 5).' '.mb_strtoupper(substr($dest_city, 0, 22)).'
1211A0600350195'.mb_strtoupper(substr($dest_city, 22, 28)).'
1911A0600250195T'.chr(130).'l'.chr(130).'phone : '.mb_strtoupper(substr($dest_phone, 0, 14)).'
';
}
// Number of labels to print
$result .= 'Q'.sprintf('%04d', $qty).'
';
// End
$result .= 'E
';
$result = $this->isoreplace($result);
/*****************************************************************************/
//require dirname(__FILE__).'/predis/autoload.php'; // Conflicts with Prestashop autoload
require_once dirname(__FILE__).'/predis/lib/Predis/Option/OptionInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/AbstractOption.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Command/Processor/CommandProcessingInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Command/PrefixableCommandInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Command/CommandInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Command/AbstractCommand.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Command/PrefixableCommand.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Command/PubSubPublish.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/ConnectionInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/SingleConnectionInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/AbstractConnection.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/StreamConnection.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/ConnectionParametersInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/ConnectionParameters.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/ConnectionFactoryInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Connection/ConnectionFactory.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Profile/ServerProfileInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Profile/ServerProfile.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Profile/ServerVersion26.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientCluster.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientPrefix.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientExceptions.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientReplication.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientConnectionFactory.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientProfile.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientOptionsInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Option/ClientOptions.php';
require_once dirname(__FILE__).'/predis/lib/Predis/BasicClientInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/ClientInterface.php';
require_once dirname(__FILE__).'/predis/lib/Predis/Client.php';
if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
$redis = new Predis\Client('tcp://127.0.0.1:6379');
} else {
$redis = new Predis\Client('tcp://91.121.174.216:6379');
}
$redis->publish(Configuration::get('LAPOSTEWS_EMPL_'.(int) $cookie->id_employee), json_encode(array('data' => base64_encode($result))));
return TRUE;
}
}