bebeboutik/modules/lapostews/AdminLaPosteWS.php
Srv Bebeboutik 6c0978166c add modules
2016-01-04 12:49:26 +01:00

1672 lines
52 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
if(!defined('_PS_VERSION_')) {
exit;
}
include dirname(__FILE__).'/webservice.php';
class AdminLaPosteWS extends AdminTab {
public $_html = '';
public function isoreplace($str) {
// ISO/CEI 646
return str_replace(array(
'Ç',
'ü',
'é',
'â',
'ä',
'à',
'å',
'ç',
'ê',
'ë',
'è',
'ï',
'î',
'ì',
'Ä',
'Å',
'É',
'æ',
'Æ',
'ô',
'ö',
'ò',
'û',
'ù',
'ÿ',
'Ö',
'Ü',
'¢',
'£',
'¥',
'₧',
'ƒ',
'á',
'í',
'ó',
'ú',
'ñ',
'Ñ',
'ª',
'º',
'¿',
'⌐',
'¬',
'½',
'¼',
'¡',
'«',
'»',
'░',
'▒',
'▓',
'│',
'┤',
'╡',
'╢',
'╖',
'╕',
'╣',
'║',
'╗',
'╝',
'╜',
'╛',
'┐',
'└',
'┴',
'┬',
'├',
'─',
'┼',
'╞',
'╟',
'╚',
'╔',
'╩',
'╦',
'╠',
'═',
'╬',
'╧',
'╨',
'╤',
'╥',
'╙',
'╘',
'╒',
'╓',
'╫',
'╪',
'┘',
'┌',
'█',
'▄',
'▌',
'▐',
'▀',
'α',
'ß',
'Γ',
'π',
'Σ',
'σ',
'µ',
'τ',
'Φ',
'Θ',
'Ω',
'δ',
'∞',
'φ',
'ε',
'∩',
'≡',
'±',
'≥',
'≤',
'⌠',
'⌡',
'÷',
'≈',
'°',
'∙',
'·',
'√',
'ⁿ',
'²',
'■',
), array(
chr(128),
chr(129),
chr(130),
chr(131),
chr(132),
chr(133),
chr(134),
chr(135),
chr(136),
chr(137),
chr(138),
chr(139),
chr(140),
chr(141),
chr(142),
chr(143),
chr(144),
chr(145),
chr(146),
chr(147),
chr(148),
chr(149),
chr(150),
chr(151),
chr(152),
chr(153),
chr(154),
chr(155),
chr(156),
chr(157),
chr(158),
chr(159),
chr(160),
chr(161),
chr(162),
chr(163),
chr(164),
chr(165),
chr(166),
chr(167),
chr(165),
chr(166),
chr(167),
chr(168),
chr(169),
chr(170),
chr(171),
chr(172),
chr(173),
chr(174),
chr(175),
chr(176),
chr(177),
chr(178),
chr(179),
chr(180),
chr(181),
chr(182),
chr(183),
chr(184),
chr(185),
chr(186),
chr(187),
chr(188),
chr(189),
chr(190),
chr(191),
chr(192),
chr(193),
chr(194),
chr(195),
chr(196),
chr(197),
chr(198),
chr(199),
chr(200),
chr(201),
chr(202),
chr(203),
chr(204),
chr(205),
chr(206),
chr(207),
chr(208),
chr(209),
chr(210),
chr(211),
chr(209),
chr(210),
chr(211),
chr(212),
chr(213),
chr(214),
chr(215),
chr(216),
chr(217),
chr(218),
chr(219),
chr(220),
chr(221),
chr(222),
chr(223),
chr(224),
chr(225),
chr(226),
chr(227),
chr(228),
chr(229),
chr(230),
chr(231),
chr(232),
chr(233),
chr(234),
chr(235),
chr(236),
chr(237),
chr(238),
chr(239),
chr(240),
chr(241),
chr(242),
chr(243),
chr(244),
chr(245),
chr(246),
chr(247),
chr(248),
chr(249),
chr(250),
chr(251),
chr(252),
chr(253),
chr(254),
), $str);
}
public function ajaxProcess() {
global $cookie;
if(Tools::getValue('submitTest')) {
$this->_html .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
$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 .= '<p class="error">'.$this->l('An error happened during the parcel registration process').'</p><br />';
} else {
if($result->getLetterColissimoReturn->errorID != 0 && ((string) $result->getLetterColissimoReturn->error) != '') {
$this->_html .= '<p class="error">'.$result->getLetterColissimoReturn->error.'</p><br />';
} 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 .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
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 .= '<p class="error">'.$this->l('Unknown delivery point').'</p><br />';
} else {
$this->_html .= '<p class="error">'.$this->l('An error happened during the label rendering').'</p><br />';
}
}
}
}
echo $this->_html;
exit;
}
}
public function display() {
global $cookie;
setlocale(LC_CTYPE, 'fr_FR');
if(!$this->checkServiceAvailability()) {
$this->_html .= '<p class="error">'.$this->l('Webservices are unavailable at the moment, please try again later.').'</p>';
} 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 .= '
<style type="text/css">
@import "'.__PS_BASE_URI__.'modules/lapostews/jquery-ui-1.8.20.custom.css";
legend.right {
position: absolute;
right: 15px;
top: 0px;
}
legend.right a {
font-weight: normal;
cursor: pointer;
text-decoration: underline;
}
legend.right .active {
font-weight: bold;
text-decoration: none;
}
#barcodeinput::-webkit-input-placeholder {
color: #bcbcbc;
}
#barcodeinput:-moz-placeholder {
color: #bcbcbc;
}
table.table.std th .button {
float: right;
margin-top: -26px;
}
table.table.std th.width1 {
width: 48px;
}
table.table.std th.width2 {
width: 70px;
}
table.table.std td {
font-size: 14px;
padding: 5px 0px;
}
table.table.std td.red {
color: #ffffff;
background: #ff0000;
}
table.table.std td.green {
color: #004000;
background: #c0ffc0;
}
table.table.std td.center {
text-align: center;
}
table.table.std td.right {
text-align: right;
}
table.table.std td.shipped input[type="text"] {
width: 30px;
text-align: right;
}
.infos {
line-height: 1.5em;
margin-bottom: 20px;
}
.infos strong {
width: 200px;
display: inline-block;
}
.short_infos {
display: none;
}
.actions {
margin-bottom. 20px;
padding: 0px 0px 20px;
}
.actions a {
margin-right: 10px;
padding: 4px 8px;
}
tr.grey {
background: #cdcdcd;
}
tr.blocked {
background: #ff9966;
}
tr.fed_ship {
background: #ff9966;
}
tr.blocked img {
display: none;
}
.actions div.form {
float: right;
margin-top: -6px;
}
table.table.std {
width: 100%;
}
.ui-multiselect {
padding: 2px 0 2px 4px;
text-align: left;
}
.ui-multiselect span.ui-icon {
float: right;
}
.ui-multiselect-single .ui-multiselect-checkboxes input {
left: -9999px;
position: absolute !important;
top: auto !important;
}
.ui-multiselect-single .ui-multiselect-checkboxes label {
padding: 5px !important;
}
.ui-multiselect-header {
margin-bottom: 3px;
padding: 3px 0 3px 4px;
}
.ui-multiselect-header ul {
font-size: 0.9em;
}
.ui-multiselect-header ul li {
float: left;
padding: 0 10px 0 0;
}
.ui-multiselect-header a {
text-decoration: none;
}
.ui-multiselect-header a:hover {
text-decoration: underline;
}
.ui-multiselect-header span.ui-icon {
float: left;
}
.ui-multiselect-header li.ui-multiselect-close {
float: right;
padding-right: 0;
text-align: right;
}
.ui-multiselect-menu {
display: none;
padding: 3px;
position: absolute;
text-align: left;
z-index: 10000;
width: 842px;
}
.ui-multiselect-checkboxes {
overflow-y: scroll;
position: relative;
}
.ui-multiselect-checkboxes label {
border: 1px solid transparent;
cursor: default;
display: block;
padding: 3px 1px;
float: none;
text-align: left;
width: auto;
}
.ui-multiselect-checkboxes label input {
position: relative;
top: 1px;
margin-right: 5px;
}
.ui-multiselect-checkboxes li {
clear: both;
font-size: 0.9em;
padding-right: 3px;
}
.ui-multiselect-checkboxes li.ui-multiselect-optgroup-label {
border-bottom: 1px solid;
font-weight: bold;
text-align: center;
}
.ui-multiselect-checkboxes li.ui-multiselect-optgroup-label a {
display: block;
margin: 1px 0;
padding: 3px;
text-decoration: none;
}
* html .ui-multiselect-checkboxes label {
border: medium none;
}
#orders, #orders_multi {
margin-top: 20px;
}
#orders .button, #orders_multi .button {
cursor: pointer;
}
#orders tbody:hover tr, #orders_multi tbody:hover tr {
opacity: .2;
}
#orders tr:hover, #orders_multi tr:hover {
opacity: 1 !important;
}
.ui-multiselect-hasfilter ul { position:relative; top:2px }
.ui-multiselect-filter { float:left; margin-right:10px; font-size:11px }
.ui-multiselect-filter input { width:300px; font-size:10px; margin-left:5px; height:15px; padding:2px; border:1px solid #999999; -webkit-appearance:textfield; -webkit-box-sizing:content-box; }
.ui-pnotify {
top: 25px;
right: 25px;
position: absolute;
height: auto;
z-index: 9999;
}
html > body .ui-pnotify {
position: fixed;
}
.ui-pnotify .ui-pnotify-shadow {
-webkit-box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5);
-moz-box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5);
box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5);
}
.ui-pnotify-container {
background-position: 0 0;
padding: .8em;
height: 100%;
margin: 0;
}
.ui-pnotify-sharp {
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
}
.ui-pnotify-closer, .ui-pnotify-sticker {
float: right;
margin-left: .2em;
}
.ui-pnotify-title {
display: block;
margin-bottom: .4em;
}
.ui-pnotify-text {
display: block;
}
.ui-pnotify-icon, .ui-pnotify-icon span {
display: block;
float: left;
margin-right: .2em;
}
.ui-pnotify-history-container {
position: absolute;
top: 0;
right: 18px;
width: 70px;
border-top: none;
padding: 0;
-webkit-border-top-left-radius: 0;
-moz-border-top-left-radius: 0;
border-top-left-radius: 0;
-webkit-border-top-right-radius: 0;
-moz-border-top-right-radius: 0;
border-top-right-radius: 0;
z-index: 10000;
}
.ui-pnotify-history-container .ui-pnotify-history-header {
padding: 2px;
}
.ui-pnotify-history-container button {
cursor: pointer;
display: block;
width: 100%;
}
.ui-pnotify-history-container .ui-pnotify-history-pulldown {
display: block;
margin: 0 auto;
}
.alert {
padding: 8px 35px 8px 14px;
margin-bottom: 0px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
background-color: #fcf8e3;
border: 1px solid #fbeed5;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
max-height: 24px;
}
.alert,
.alert h4 {
color: #c09853;
}
.alert h4 {
margin: 0;
}
.alert .close {
position: relative;
top: -2px;
right: -21px;
line-height: 20px;
}
.alert-success {
background-color: #dff0d8;
border-color: #d6e9c6;
color: #468847;
}
.alert-success h4 {
color: #468847;
}
.alert-danger,
.alert-error {
background-color: #f2dede;
border-color: #eed3d7;
color: #b94a48;
}
.alert-danger h4,
.alert-error h4 {
color: #b94a48;
}
.alert-info {
background-color: #d9edf7;
border-color: #bce8f1;
color: #3a87ad;
}
.alert-info h4 {
color: #3a87ad;
}
.alert-block {
padding-top: 14px;
padding-bottom: 14px;
}
.alert-block > p,
.alert-block > ul {
margin-bottom: 0;
}
.alert-block p + p {
margin-top: 5px;
}
.well, .btn {
display: none;
}
.ui-pnotify.stack-bottomright {
right: auto;
top: auto;
}
#products_frame {
background: #FFFFFF;
box-shadow: 0px 0px 5px rgba(0, 0, 0, .5);
height: 400px;
left: 50%;
position: fixed;
top: 50%;
width: 980px;
z-index: 50;
margin-left: -480px;
margin-top: -200px;
overflow-y: auto;
}
#products_frame h1 {
margin: 15px 0px;
}
#products_frame .close {
position: fixed;
top: 50%;
margin-top: -190px;
left: 50%;
margin-left: 470px;
color: #ffffff;
font-size: 14px;
font-weight: bold;
padding: 6px;
background: #000000;
cursor: pointer;
}
#background_frame {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .8);
z-index: 45;
}
</style>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/lapostews/jquery.hotkeys.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/lapostews/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/lapostews/jquery.multiselect.min.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/lapostews/jquery.multiselect.filter.min.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/lapostews/jquery.pnotify.min.js"></script>
<script type="text/javascript">
var stack_bottomright = {"dir1": "up", "dir2": "left", "firstpos1": 25, "firstpos2": 25};
function do_notify(type, title) {
$.pnotify({
title: title,
addclass: "stack-bottomright",
stack: stack_bottomright,
type: type
});
}
function printLabel(element, id_order) {
var size = $(element).width();
$(element).hide().after($("<a style=\'width: " + (size + 8) + "px; text-align: center; display: inline-block;\' id=\'loading_" + id_order + "\'>'.$this->l('Loading, please wait').'</a>"));
$.post("'.__PS_BASE_URI__.'adm/ajax-tab.php?tab=AdminLaPosteWS&token='.Tools::getAdminTokenLite('AdminLaPosteWS').'&id_order=" + id_order, { submitShip: 1 }, function(loaded) {
if(loaded) {
if(loaded.indexOf("\"conf\"") === -1) {
do_notify("error", $(loaded).text());
} else {
do_notify("success", $(loaded).text());
$("#order_" + id_order + " td:eq(3)").text(parseInt($("#order_" + id_order + " td:eq(3)").text()) + 1);
}
}
$("#loading_" + id_order).remove();
$(element).show();
});
}
function getProducts(element, id_order) {
$.post("'.__PS_BASE_URI__.'adm/ajax-tab.php?tab=AdminLaPosteWS&token='.Tools::getAdminTokenLite('AdminLaPosteWS').'&getProducts=1&id_order=" + id_order, function(loaded) {
if(loaded) {
loaded = $.parseJSON(loaded);
var content = "<div id=\'background_frame\'></div>\
<div id=\'products_frame\'><a class=\'close\' onclick=\'$(\"#background_frame, #products_frame\").remove();\'>X</a>\
<h1>'.$this->l('Order #').'" + id_order + " " + loaded[0].firstname + " " + loaded[0].lastname + "</h1>\
<table class=\'std table\'>\
<thead>\
<tr>\
<th></th>\
<th>'.$this->l('Product').'</th>\
<th>'.$this->l('Reference / Location').'</th>\
<th>'.$this->l('Quantity').'</th>\
</tr>\
</thead>\
<tbody>";
for(var i=0; i < loaded.length; i++) {
content += "<tr>\
<td><img alt=\'\' src=\'/img/tmp/product_mini_" + loaded[i].product_id + "_" + loaded[i].product_attribute_id + ".jpg\' /></td>\
<td>" + loaded[i].product_name + "</td>\
<td>" + loaded[i].product_reference + (loaded[i].location != ""? "<br />" + loaded[i].location: "") + "</td>\
<td>" + loaded[i].product_quantity + (loaded[i].product_quantity_refunded != 0? "<br /> " + loaded[i].product_quantity_refunded + "<br />= " + (loaded[i].product_quantity - loaded[i].product_refunded): "") + "</td>\
</tr>";
}
content += "</tbody>\
</table></div>";
$("body").append($(content));
}
});
}
</script>
';
$this->_html .= '<form action="'.__PS_BASE_URI__.'modules/lapostews/select_sale.php?token='.Tools::getValue('token').'&id_employee='.(int) $cookie->id_employee.'" method="POST">
<div><select multiple="true" id="filter_id_sale" name="filter_id_sale[]" style="display: none;">
';
foreach(Db::getInstance()->ExecuteS('
SELECT s.`id_sale`, c.`name`
FROM `'._DB_PREFIX_.'privatesale` s
LEFT JOIN `'._DB_PREFIX_.'category_lang` c
ON c.`id_category` = s.`id_category`
WHERE c.`id_lang` = 2
AND (
s.`date_end` > DATE_SUB(NOW(), INTERVAL 90 DAY)
OR s.`public` = 1
)
') as $row) {
$this->_html .= '<option value="'.(int) $row['id_sale'].'"'.(in_array((int) $row['id_sale'], $sales_list)? ' selected="selected"': '').'>'.(int) $row['id_sale'].' - '.htmlentities($row['name']).'</option>';
}
$this->_html .= '</select><input class="button" type="submit" value="Valider" style="float: right;" /><br style="clear: both" /></div></form>
<p style="margin-top: 20px;">
<label for="barcodeinput" style="display: inline; float: none; width: auto;">'.$this->l('Barcode input:').'</label>
<input type="text" id="barcodeinput" value="" autocomplete="off" placeholder="'.$this->l('Click here and scan a barcode').'" style="width: 250px;" />
</p>
<script type="text/javascript">
<!--
$(document).ready(function() {
$("#filter_id_sale").multiselect({
selectedList: 7,
selectedText: function(numChecked, numTotal, checkedItems){
var seltext = "";
$(checkedItems).each(function(id, el) {
seltext += ", " + $(el).parent().text();
});
return (numChecked > 1? "Ventes sélectionnées : ": "Vente sélectionnée : ") + seltext.slice(2);
},
checkAllText: "Tout sélectionner",
uncheckAllText: "Tout désélectionner",
noneSelectedText: "Sélectionnez une ou plusieurs ventes",
minWidth: 850
}).multiselectfilter({
label: "Filtrer :",
autoReset: false,
placeholder: "Entrez un nom ou un ID de vente"
});
$("#barcodeinput").focus(function() {
$(this).attr("placeholder", "'.$this->l('Waiting for a barcode scan').'");
});
$("#barcodeinput").blur(function() {
$(this).attr("placeholder", "'.$this->l('Click here and scan a barcode').'");
});
$("#barcodeinput").keyup(function(event) {
if(!(event.keyCode == 112 || event.keyCode == 113 || event.keyCode == 114 || event.keyCode == 115 || event.keyCode == 123)) {
if(event.keyCode == 32) {
printLabel($("<div />"), $.trim($(this).val().split("-")[1]));
$(this).val("");
}
}
});
$("#barcodeinput").trigger("focus");
});
-->
</script>
';
if(count($sales_list) > 0) {
$orders_cache = array();
$sales_cache = array();
$this->_html .= '
<br /><br />
<strong>'.$this->l('Single sale orders').'</strong>
<table class="table std" id="orders">
<thead>
<tr>
<th>'.$this->l('ID order').'</th>
<th>'.$this->l('Customer').'</th>
<th>'.$this->l('Date').'</th>
<th>'.$this->l('Already sent').'</th>
<th>'.$this->l('Actions').'</th>
</thead>
<tbody>';
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 .= '<tr id="order_'.(int) $order['id_order'].'">
<td class="center"><a href="/adm/index.php?tab=AdminOrders&id_order='.(int) $order['id_order'].'&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'" onclick="window.open(this.href); return false;">'.(int) $order['id_order'].'</a></td>
<td><a href="/adm/index.php?tab=AdminCustomers&id_customer='.(int) $order['id_customer'].'&viewcustomer&token='.Tools::getAdminTokenLite('AdminCustomers').'" onclick="window.open(this.href); return false;">'.$order['firstname'].' '.mb_strtoupper($order['lastname']).'</a></td>
<td>'.$order['date_add'].'</td>
<td class="center">'.(int) Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'lapostews2` WHERE `id_order` = '.(int) $order['id_order']).'</td>
<td class="right">
<a class="button" onclick="getProducts(this, '.(int) $order['id_order'].'); return false;">'.$this->l('Product list').'</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a class="button" onclick="printLabel(this, '.(int) $order['id_order'].'); return false;">'.$this->l('Register the parcel and print the label').'</a>
</td>
</tr>';
}
}
$this->_html .= '</tbody>
</table>
<br /><br /><br />
<strong>'.$this->l('Multi-sales orders').'</strong>
<table class="table std" id="orders_multi">
<thead>
<tr>
<th>'.$this->l('ID order').'</th>
<th>'.$this->l('Customer').'</th>
<th>'.$this->l('Date').'</th>
<th>'.$this->l('Already sent').'</th>
<th>'.$this->l('Actions').'</th>
</thead>
<tbody>';
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 .= '<tr id="order_'.(int) $order['id_order'].'">
<td class="center"><a href="/adm/index.php?tab=AdminOrders&id_order='.(int) $order['id_order'].'&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'" onclick="window.open(this.href); return false;">'.(int) $order['id_order'].'</a></td>
<td><a href="/adm/index.php?tab=AdminCustomers&id_customer='.(int) $order['id_customer'].'&viewcustomer&token='.Tools::getAdminTokenLite('AdminCustomers').'" onclick="window.open(this.href); return false;">'.$order['firstname'].' '.mb_strtoupper($order['lastname']).'</a></td>
<td>'.$order['date_add'].'</td>
<td class="center">'.(int) Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'lapostews2` WHERE `id_order` = '.(int) $order['id_order']).'</td>
<td class="right">
<a class="button" onclick="getProducts(this, '.(int) $order['id_order'].'); return false;">'.$this->l('Product list').'</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a class="button" onclick="printLabel(this, '.(int) $order['id_order'].'); return false;">'.$this->l('Register the parcel and print the label').'</a>
</td>
</tr>';
}
}
$this->_html .= '</tbody>
</table>
';
}
}
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à lidentifiant 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;
}
}