2016-01-04 12:49:26 +01:00
< ? php
if ( ! defined ( '_PS_VERSION_' )) {
exit ;
}
global $logistics_carriers ;
2017-01-11 15:33:44 +01:00
foreach ( array_map ( function ( $value ) {
2016-01-04 12:49:26 +01:00
return str_replace ( '.' , '' , $value );
}, array_diff ( scandir ( dirname ( __FILE__ ) . '/carriers' ), array ( '.' , '..' ))) as $lg ) {
if ( is_dir ( dirname ( __FILE__ ) . '/carriers/' . $lg )) {
include dirname ( __FILE__ ) . '/carriers/' . $lg . '/' . $lg . '.php' ;
$name = ucfirst ( $lg ) . 'Carrier' ;
$logistics_carriers [ $lg ] = new $name ();
}
2017-01-11 15:33:44 +01:00
}
//include dirname(__FILE__).'/carriers/laposte/laposte.php';
//$logistics_carriers['laposte'] = new LaposteCarrier();
2016-01-04 12:49:26 +01:00
include _PS_ROOT_DIR_ . '/modules/privatesales/Sale.php' ;
class AdminLogistics extends AdminTab {
public $_html = '' ;
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' )
);
}
private 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 );
}
2017-07-04 15:32:17 +02:00
private function printLabel ( $data , $mr = false ) {
2016-01-04 12:49:26 +01:00
global $cookie ;
//require dirname(__FILE__).'/libs/predis/autoload.php'; // Conflicts with Prestashop autoload
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/OptionInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/AbstractOption.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Command/Processor/CommandProcessingInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Command/PrefixableCommandInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Command/CommandInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Command/AbstractCommand.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Command/PrefixableCommand.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Command/PubSubPublish.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/ConnectionInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/SingleConnectionInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/AbstractConnection.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/StreamConnection.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/ConnectionParametersInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/ConnectionParameters.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/ConnectionFactoryInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Connection/ConnectionFactory.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Profile/ServerProfileInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Profile/ServerProfile.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Profile/ServerVersion26.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientCluster.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientPrefix.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientExceptions.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientReplication.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientConnectionFactory.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientProfile.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientOptionsInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Option/ClientOptions.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/BasicClientInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/ClientInterface.php' ;
require_once dirname ( __FILE__ ) . '/libs/predis/lib/Predis/Client.php' ;
$redis = new Predis\Client ();
2017-07-04 15:32:17 +02:00
if ( $mr ){
$redis -> publish (
Configuration :: get ( 'LOGISTICS_QUEUE_' . ( int ) $cookie -> id_employee ),
json_encode ( array ( 'data' => base64_encode (
chr ( 2 ) . 'n' . " \n " // Inch mode
. chr ( 2 ) . 'O0100' . " \n " // Start position
. chr ( 2 ) . 'L' . " \n "
. 'C0000' . " \n "
. 'D11' . " \n "
. chr ( 2 ) . 'L' . " \n "
. $this -> isoreplace ( $data )
. 'Q0001' . " \n " // Number of labels to print
. 'E' . " \n " // End
)))
);
} else {
$redis -> publish (
Configuration :: get ( 'LOGISTICS_QUEUE_' . ( int ) $cookie -> id_employee ),
json_encode ( array ( 'data' => base64_encode (
/* chr ( 2 ) . 'n' . " \n " // Inch mode
. chr ( 2 ) . 'O0100' . " \n " // Start position
. chr ( 2 ) . 'L' . " \n "
. 'C0000' . " \n "
. 'D11' . " \n "
. chr ( 2 ) . 'L' . " \n "
. $this -> isoreplace ( $data )
. 'Q0001' . " \n " // Number of labels to print
. 'E' . " \n " // End*/
$data
)))
);
}
2016-01-04 12:49:26 +01:00
return TRUE ;
}
public function postProcess () {
global $cookie , $logistics_carriers ;
if ((
2016-10-28 10:54:34 +02:00
( int ) $cookie -> profile == 1 || ( int ) $cookie -> profile == 9 || ( int ) $cookie -> profile == 7 || ( int ) $cookie -> profile == 14
2016-01-04 12:49:26 +01:00
) && (
$delete_number = Tools :: getValue ( 'delete_number' )
)) {
if ( $delete = ( int ) Tools :: getValue ( 'delete_laposte' )) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'lapostews`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = " '.pSQL( $delete_number ).' "
' );
if ( ! Db :: getInstance () -> getRow ( '
SELECT l . `shipping_number`
FROM `'._DB_PREFIX_.'lapostews` l
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON l . `id_order_detail` = d . `id_order_detail`
WHERE l . `shipping_number` = " '.pSQL( $delete_number ).' "
AND d . `id_order` = '.(int) Tools::getValue(' id_order ').'
' )) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue(' id_order ').'
AND `shipping_number` = " '.pSQL( $delete_number ).' "
' );
}
} elseif ( $delete = ( int ) Tools :: getValue ( 'delete_exapaq' )) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'exapaqws`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = " '.pSQL( $delete_number ).' "
' );
if ( ! Db :: getInstance () -> getRow ( '
SELECT `shipping_number`
FROM `'._DB_PREFIX_.'exapaqws`
WHERE `shipping_number` = " '.pSQL( $delete_number ).' "
' )) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue(' id_order ').'
AND `shipping_number` = " '.pSQL( $delete_number ).' "
' );
}
2017-01-11 15:33:44 +01:00
} elseif ( $delete = ( int ) Tools :: getValue ( 'delete_mondialrelay' )) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'mondialrelay_parcel`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = " '.pSQL( $delete_number ).' "
' );
if ( ! Db :: getInstance () -> getRow ( '
SELECT `shipping_number`
FROM `'._DB_PREFIX_.'mondialrelay_parcel`
WHERE `shipping_number` = " '.pSQL( $delete_number ).' "
' )) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue(' id_order ').'
AND `shipping_number` = " '.pSQL( $delete_number ).' "
' );
}
2016-01-04 12:49:26 +01:00
}
$id_order_details = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) Tools::getValue(' id_order ').'
' ) as $row ) {
$id_order_details [] = ( int ) $row [ 'id_order_detail' ];
}
if ( ! Db :: getInstance () -> getRow ( '
SELECT *
FROM `'._DB_PREFIX_.'lapostews`
WHERE `id_order_detail` IN ( '.implode(' , ', $id_order_details).' )
' )) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'order_history` VALUES (
DEFAULT ,
'.(int) $cookie->id_employee.' ,
'.(int) Tools::getValue(' id_order ').' ,
'.(int) Configuration::get(' PS_OS_PAYMENT ').' ,
NOW ()
)
' );
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'order_state_current` VALUES (
'.(int) Tools::getValue(' id_order ').' ,
'.(int) Configuration::get(' PS_OS_PAYMENT ').' ,
NOW ()
)
ON DUPLICATE KEY UPDATE
`id_order_state` = '.(int) Configuration::get(' PS_OS_PAYMENT ').' ,
`date_upd` = NOW ()
' );
}
Tools :: redirectLink ( 'http://' . $_SERVER [ 'SERVER_NAME' ] . '/adm/index.php?tab=AdminLogistics&token=' . Tools :: getAdminTokenLite ( 'AdminLogistics' ) . '&id_order=' . ( int ) Tools :: getValue ( 'id_order' ) . '&mode=' . Tools :: getValue ( 'mode' , '' ) . '#' . Tools :: getValue ( 'mode' , '' ));
}
2016-09-01 11:17:43 +02:00
if ( ( Tools :: isSubmit ( 'submitReprintShip' ))
2016-10-28 10:54:34 +02:00
&& (( int ) $cookie -> profile == 1 || ( int ) $cookie -> profile == 9 || ( int ) $cookie -> profile == 7 || ( int ) $cookie -> profile == 14 )
2016-08-25 12:14:34 +02:00
&& (
2016-09-01 11:17:43 +02:00
( $id_order = Tools :: getValue ( 'id_order_reprint' ))
&& ( $products = Tools :: getValue ( 'products_reprint' ))
&& ( $parcel_carrier = Tools :: getValue ( 'carrier_reprint' ))
2016-08-25 12:14:34 +02:00
)
2016-08-23 18:05:47 +02:00
) {
2016-08-31 16:25:49 +02:00
$weight = 0.24 ;
2016-08-25 12:14:34 +02:00
$order = new Order (( int ) $id_order );
2016-08-26 12:00:54 +02:00
if ( Validate :: isLoadedObject ( $order )) {
$parcel_carrier == 'laposte' ? $weight = 0.24 : TRUE ;
$result = $logistics_carriers [ $parcel_carrier ] -> registerParcel ( $order , $products , $weight );
if ( $result [ 0 ] != '' ) {
$this -> _html .= $result [ 0 ];
return ;
}
2016-08-25 12:14:34 +02:00
2016-08-26 12:00:54 +02:00
$render = $logistics_carriers [ $parcel_carrier ] -> renderLabel ( $order , $weight , $result [ 1 ]);
2016-08-25 12:14:34 +02:00
2016-08-26 12:00:54 +02:00
if ( $render === 'pr_error' ) {
$this -> _html .= '<p class="error">' . $this -> l ( 'Unknown delivery point' ) . '</p><br />' ;
} elseif ( $render === 'route_error' ) {
$this -> _html .= '<p class="error">' . $this -> l ( 'Route not found' ) . '</p><br />' ;
} elseif ( $render !== FALSE ) {
$this -> printLabel ( $render );
2016-08-25 12:14:34 +02:00
2016-08-26 12:00:54 +02:00
$this -> _html .= '<p class="conf">' . $this -> l ( 'Registration complete, label sent to printer' ) . '</p><br />' ;
2016-08-25 12:14:34 +02:00
2016-08-26 12:00:54 +02:00
if ( $_SERVER [ 'REMOTE_ADDR' ] != '109.190.53.175'
&& $_SERVER [ 'REMOTE_ADDR' ] != '78.226.56.137'
&& $_SERVER [ 'REMOTE_ADDR' ] != '88.163.22.223'
&& $_SERVER [ 'REMOTE_ADDR' ] != '37.160.139.229'
&& substr ( $_SERVER [ 'REMOTE_ADDR' ], 0 , 2 ) != '37' ) {
2016-08-25 12:14:34 +02:00
2016-08-26 16:35:02 +02:00
$products_names = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
2016-08-26 12:00:54 +02:00
SELECT `id_order_detail` , `product_name`
FROM `'._DB_PREFIX_.'order_detail`
2016-08-26 16:35:02 +02:00
WHERE `id_order_detail` IN ( '.implode(' , ', array_keys($products)).' )
' ) as $p ) {
$products_names [( int ) $p [ 'id_order_detail' ]] = $p [ 'product_name' ];
}
$logistics_carriers [ $parcel_carrier ] -> logParcel ( $result [ 1 ], $products );
2016-08-25 12:14:34 +02:00
2016-08-26 16:35:02 +02:00
foreach ( $products as $k => $v ) {
if ( $v > 0 ) {
$products_sent .= '<br />' . " \r \n " . $v . ' x ' . ( isset ( $products_names [ $k ]) ? $products_names [ $k ] : '--' );
}
2016-08-26 12:00:54 +02:00
}
2016-08-25 12:14:34 +02:00
2016-08-26 12:00:54 +02:00
$logistics_carriers [ $parcel_carrier ] -> addOrderHistory ( $result [ 1 ], $order , $products_sent );
}
} else {
$this -> html .= '<p class="error">' . $this -> l ( 'An error happened during the label rendering' ) . '</p><br />' ;
2016-08-25 12:14:34 +02:00
}
2016-08-25 16:59:26 +02:00
}
2016-08-25 12:14:34 +02:00
//$this->printLabel($logistics_carriers['laposte']->renderLabel(new Order((int) $id_order), $weight, $reprint_number));
2016-08-23 18:05:47 +02:00
} elseif ( Tools :: isSubmit ( 'submitTestLaposte' )) {
2016-01-04 12:49:26 +01:00
$this -> _html .= '<p class="conf">' . $this -> l ( 'Registration complete, label sent to printer' ) . '</p><br />' ;
//$this->printLabel($logistics_carriers['laposte']->renderLabel(new Order(23336), 0.24, '6A12345123451'));
$this -> printLabel ( $logistics_carriers [ 'laposte' ] -> renderLabel ( new Order ( 223001 ), 0.24 , '6J12345123451' ));
} elseif ( Tools :: isSubmit ( 'submitTestExapaq' )) {
$this -> _html .= '<p class="conf">' . $this -> l ( 'Registration complete, label sent to printer' ) . '</p><br />' ;
$this -> printLabel ( $logistics_carriers [ 'exapaq' ] -> renderLabel ( new Order ( 23336 ), 0.24 , array ( 'shipping_number' => '100000000' , 'exapass' => '250094100000000068' )));
2017-01-11 15:33:44 +01:00
} elseif ( Tools :: isSubmit ( 'submitTestMondialrelay' )) {
$this -> _html .= '<p class="conf">' . $this -> l ( 'Registration complete, label sent to printer' ) . '</p><br />' ;
2017-07-04 15:32:17 +02:00
$weight = 0.12 ;
$id_order = 578808 ;
$id_order_detail = 1844105 ;
$product = array ( '5154233' => " 1 " );
2017-02-15 12:10:01 +01:00
$result = $logistics_carriers [ 'mondialrelay' ] -> _getRegisteredParcel ( new Order ( $id_order ), $id_order_detail , $product , $weight );
$render = $logistics_carriers [ 'mondialrelay' ] -> renderLabel ( new Order ( $id_order ), $weight , $result [ 1 ]);
$f = fopen ( dirname ( __FILE__ ) . '/label_mr.txt' , 'a+' );
fwrite ( $f , $render );
fclose ( $f );
2017-07-04 15:32:17 +02:00
$this -> printLabel ( $render , true );
2016-01-04 12:49:26 +01:00
} elseif ( Tools :: isSubmit ( 'submitShip' ) && ( $id_order = ( int ) Tools :: getValue ( 'id_order' ))) {
$order = new Order (( int ) $id_order );
$to_ship = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT d . `id_order_detail` , SUM ( d . `product_quantity` ) AS `product_quantity` , SUM ( d . `product_quantity_refunded` ) AS `product_quantity_refunded` , SUM ( d . `product_quantity_return` ) AS `product_quantity_return` , SUM ( w . `quantity` ) AS `quantity_sent`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'lapostews` w
ON d . `id_order_detail` = w . `id_order_detail`
WHERE d . `id_order` = '.$id_order.'
GROUP BY d . `id_order_detail`
' ) as $p ) {
$to_ship [( int ) $p [ 'id_order_detail' ]] = $p [ 'product_quantity' ] - ( $p [ 'product_quantity_refunded' ] > 0 ? $p [ 'product_quantity_refunded' ] : $p [ 'product_quantity_return' ]) - ( int ) $p [ 'quantity_sent' ];
}
if ( Validate :: isLoadedObject ( $order )) {
$parcel_carrier = Tools :: getValue ( 'parcel_carrier' , 'laposte' );
if (( $weight = Tools :: getValue ( 'weight' )) && ( $products = Tools :: getValue ( 'shipped' ))) {
$parcel_carrier == 'laposte' ? $weight = 0.24 : TRUE ;
$total_products = 0 ;
foreach ( $products as $k => $v ) {
if ( $v > 0 ) {
if ( $cookie -> profile == 1 ) {
$total_products = 1 ;
break ;
} else {
if ( isset ( $to_ship [ $k ]) && $to_ship [ $k ] > 0 && $v <= $to_ship [ $k ]) {
$total_products ++ ;
} else {
$total_products = 0 ;
break ;
}
}
}
}
if ( $total_products != 0 ) {
$result = $logistics_carriers [ $parcel_carrier ] -> registerParcel ( $order , $products , $weight );
if ( $result [ 0 ] != '' ) {
$this -> _html .= $result [ 0 ];
return ;
}
$render = $logistics_carriers [ $parcel_carrier ] -> renderLabel ( $order , $weight , $result [ 1 ]);
if ( $render === 'pr_error' ) {
$this -> _html .= '<p class="error">' . $this -> l ( 'Unknown delivery point' ) . '</p><br />' ;
} elseif ( $render === 'route_error' ) {
$this -> _html .= '<p class="error">' . $this -> l ( 'Route not found' ) . '</p><br />' ;
} elseif ( $render !== FALSE ) {
2017-07-04 15:32:17 +02:00
if ( $parcel_carrier == 'mondialrelay' ) {
$this -> printLabel ( $render , true );
} else {
$this -> printLabel ( $render );
}
2016-01-04 12:49:26 +01:00
$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'
&& $_SERVER [ 'REMOTE_ADDR' ] != '37.160.139.229'
&& substr ( $_SERVER [ 'REMOTE_ADDR' ], 0 , 2 ) != '37' ) {
$products_sent = '' ;
$products_names = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_order_detail` , `product_name`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order_detail` IN ( '.implode(' , ', array_keys($products)).' )
' ) as $p ) {
$products_names [( int ) $p [ 'id_order_detail' ]] = $p [ 'product_name' ];
}
$logistics_carriers [ $parcel_carrier ] -> logParcel ( $result [ 1 ], $products );
foreach ( $products as $k => $v ) {
if ( $v > 0 ) {
$products_sent .= '<br />' . " \r \n " . $v . ' x ' . ( isset ( $products_names [ $k ]) ? $products_names [ $k ] : '--' );
}
}
$logistics_carriers [ $parcel_carrier ] -> addOrderHistory ( $result [ 1 ], $order , $products_sent );
}
} else {
$this -> html .= '<p class="error">' . $this -> l ( 'An error happened during the label rendering' ) . '</p><br />' ;
}
} else {
$this -> _html .= '<p class="error">' . $this -> l ( 'Please enter a weight and select at least one product' ) . '</p><br />' ;
}
} else {
$this -> _html .= '<p class="error">' . $this -> l ( 'Please enter a weight and select at least one product' ) . '</p><br />' ;
}
}
2016-07-06 16:07:22 +02:00
} elseif ( Tools :: isSubmit ( 'submitMod' ) && ( $id_order = ( int ) Tools :: getValue ( 'id_order' ))) {
2016-06-20 15:32:06 +02:00
$product_ids = Tools :: getValue ( 'product_ids' );
2016-06-20 18:27:54 +02:00
foreach ( $product_ids as $id ) {
$id_sale = Db :: getInstance () -> getValue ( '
SELECT `id_sale`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` = ' . ( int ) $id
);
if ( ! $id_sale ) {
$id_sale = 0 ;
}
Db :: getInstance () -> ExecuteS ( '
INSERT IGNORE INTO `'._DB_PREFIX_.'logistics_pending`
VALUES ( '.(int) $id_order.' , '.(int) $id.' , '.(int) $id_sale.' )
' );
2016-06-22 11:26:51 +02:00
}
2016-06-20 18:27:54 +02:00
2016-06-22 11:26:51 +02:00
$id_order_state = Db :: getInstance () -> getRow ( '
SELECT `id_order_state`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order` = '.(int) $id_order.'
ORDER BY `id_order_history` DESC
' );
2016-06-20 18:27:54 +02:00
// commande en attente
2016-06-22 11:26:51 +02:00
if (( int ) $id_order_state [ 'id_order_state' ] != 19 ) {
$history = new OrderHistory ();
$history -> id_order = ( int ) $id_order ;
$history -> id_employee = ( int )( $cookie -> id_employee );
$history -> changeIdOrderState ( 19 , ( int )( $id_order ));
if ( $history -> add ()) {
$this -> _html .= '<p class="conf">' . $this -> l ( 'Order status changed' ) . '</p><br />' ;
} else {
$this -> _html .= '<p class="error">' . $this -> l ( 'Error occured' ) . '</p><br />' ;
}
} else {
$this -> _html .= '<p class="conf">' . $this -> l ( 'Order in pending' ) . '</p><br />' ;
2016-06-20 18:27:54 +02:00
}
2016-01-04 12:49:26 +01:00
}
}
public function display () {
global $cookie , $logistics_carriers ;
/* if ( ! in_array ( $cookie -> id_employee , array ( 1 , 2 , 3 , 10 , 68 , 70 , 89 , 91 ))) {
echo 'Fonctionnalité indisponible actuellement' ; return ;
} */
$unavailable_carriers = array ();
foreach ( $logistics_carriers as $name => $class ) {
if ( ! $class -> checkavailability ()) {
$unavailable_carriers [] = $name ;
$this -> _html .= '<p class="error">' . $class -> displayName . ' – ' . $this -> l ( 'Webservices are unavailable at the moment, please try again later.' ) . '</p>' ;
}
}
$locked_products = array ();
$_locked_products = Configuration :: get ( 'LOGISTICS_LOCK' );
if ( $_locked_products === FALSE || $_locked_products == 0 || $_locked_products == 's:8:"s:1:"0"' || empty ( $_locked_products )) {
$_locked_products = serialize ( array ());
}
foreach ( unserialize ( $_locked_products ) as $id_s ) {
$_s = new Sale ( $id_s );
foreach ( $_s -> getProducts () as $p ) {
$locked_products [] = $p ;
}
}
$sales_list = array ();
if ( isset ( $_COOKIE [ 'logistics_sales' ])) {
foreach ( explode ( '-' , $_COOKIE [ 'logistics_sales' ]) as $chunk ) {
$sales_list [] = ( int ) $chunk ;
}
}
$this -> _html .= '
< style type = " text/css " >
@ import " '.__PS_BASE_URI__.'modules/logistics/styles.css?v=2 " ;
</ style >
< script type = " text/javascript " >
<!--
$ ( " .qtyblock a " ) . live ( " click " , function ( e ){
$ ( " #eaninput " ) . focus ();
});
var carriers = ' ;
$js_carriers = array ();
foreach ( $logistics_carriers as $k => $v ) {
$js_carriers [ $k ] = $v -> displayName ;
}
//array_walk($logistics_carriers, function($v, $k, $js_carriers) { $js_carriers[$k] = $v->displayName; }, &$js_carriers);
$this -> _html .= json_encode ( $js_carriers );
$this -> _html .= ' ;
var carriers_laposte = $ . parseJSON ( " '.addslashes(json_encode(unserialize(Configuration::get('LAPOSTEWS_CARRIERS')))).' " );
var carriers_exapaq = $ . parseJSON ( " '.addslashes(json_encode(unserialize(Configuration::get('EXAPAQWS_CARRIERS')))).' " );
2017-01-12 13:03:48 +01:00
var carriers_mondialrelay = $ . parseJSON ( " '.addslashes(json_encode(unserialize(Configuration::get('MONDIALRELAYWS_CARRIERS')))).' " );
2016-01-04 12:49:26 +01:00
var locked_products = $ . parseJSON ( " '.addslashes(json_encode( $locked_products )).' " );
var sales_list = $ . parseJSON ( " '.addslashes(json_encode( $sales_list )).' " );
var req = null ;
function loadOrder ( id_order , ean_focus ) {
if ( ! ( typeof id_order == " number " )) {
if ( $ ( " #barcodeinput:focus " ) . length > 0 ) {
var bc = $ ( " #barcodeinput " ) . val ();
if ( bc . substr ( 0 , 2 ) == " O- " && bc . length > 3 ) {
if ( bc . indexOf ( " " ) != - 1 ) {
id_order = parseInt ( bc . substr ( 2 ) . replace ( " " , " " ));
$ ( " #barcodeinput " ) . val ( " " );
} else {
id_order = parseInt ( bc . substr ( 2 ));
}
}
if ( typeof id_order == " undefined " ) {
return ;
}
} else {
id_order = parseInt ( $ ( " #manualinput " ) . val ());
}
}
try {
$ ( " #orderInfos " ) . hide ();
req . cancel ();
} catch ( e ) {}
isRelay = 0 ;
lockPrint = false ;
req = $ . get ( " '.__PS_BASE_URI__.'modules/logistics/ajax.php?id_employee='.(int) $cookie->id_employee .'&token='.Tools::getValue('token').'&id_order= " + id_order , function ( loaded ) {
if ( loaded ) {
var loaded = $ . parseJSON ( loaded );
2017-01-17 12:41:02 +01:00
isRelay = $ . inArray ( parseInt ( loaded . delivery_address . id_country ), [ 1 , 2 , 3 , 6 , 10 , 12 , 13 , 17 , 26 , 40 , 148 , 245 ]) != - 1
? 0
: ( loaded . delivery_infos_laposte
? ( loaded . delivery_infos_laposte . delivery_mode != \ ' DOM\ '
? 1
: 0 )
: ( loaded . delivery_infos_exapaq
? 2
: ( loaded . delivery_infos_mr
? ( loaded . delivery_infos_mr . dlv_mode != \ ' LD1\ ' && loaded . delivery_infos_mr . dlv_mode != \ ' LDS\ ' && loaded . delivery_infos_mr . dlv_mode != \ ' HOM\ '
? 3
: 0
)
: 0
)
)
);
2016-01-04 12:49:26 +01:00
lockPrint = false ;
if ( ! loaded . errors ) {
var content = \ ' \
< div class = " infos " > \
< strong > '.$this->l(' Order ID : ').' </ strong > \ ' + loaded . order . id + \ ' < br /> \
< strong > '.$this->l(' Cart ID : ').' </ strong > \ ' + loaded . order . id_cart + \ ' < br /> \
< strong > '.$this->l(' Customer : ').' </ strong > \ ' + loaded . customer + \ ' < br /> \
< strong > '.$this->l(' Date : ').' </ strong > \ ' + loaded . order . date_add + \ ' < br /> \
< strong > '.$this->l(' Payment gateway : ').' </ strong > \ ' + loaded . order . payment + \ ' < br /> \
< strong > '.$this->l(' Order status : ').' </ strong > \ ' + loaded . status + \ ' < br /> \
< strong > '.$this->l(' Carrier : ').' </ strong > \ ' + loaded . carrier + \ ' < br /> \
</ div > \
< div class = " short_infos " > \
< strong > '.$this->l(' Order ID : ').' </ strong > \ ' + loaded.order.id + \', <strong>' . $this -> l ( 'Carrier:' ) . '</strong> \' + loaded.carrier + \', <strong>' . $this -> l ( 'Order status:' ) . ' </ strong > \ ' + loaded . status + \ ' \
</ div > \
\
< div class = " addresses \ ' + (loaded.delivery_infos_laposte || loaded.delivery_infos_exapaq? \ 'span3 \ ': \ 'span2 \ ') + \ ' " > \
\ ' + ( loaded . delivery_infos_laposte ?
\ ' < div class = " address " > \
< strong > '.$this->l(' SoColissimo address ').' </ strong >< a style = " float: right; " onclick = " var p = window.open( \\ \ 'scaddressedit.php?id_cart= \ ' + loaded.order.id_cart + \ ' \\ \ ', \\ \ ''. $this->l ('SoColissimo address update').' \\ \ ', \\ \ 'width=720, height=390, resizable=1, scrollbars=1 \\ \ '); p.onunload = function() { window.location.reload(); }; return false; " >< img src = " ../img/admin/edit.gif " alt = " " /></ a >< br /> \
\ ' + ( loaded . delivery_infos_laposte . prcompladress ? loaded . delivery_infos_laposte . prcompladress + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . delivery_infos_laposte . prfirstname + \ ' \ ' + loaded . delivery_infos_laposte . prname + \ ' < br /> \
\ ' + loaded . delivery_infos_laposte . cefirstname + \ ' \ ' + loaded . delivery_infos_laposte . cename + \ ' < br /> \
\ ' + ( loaded . delivery_infos_laposte . pradress1 ? loaded . delivery_infos_laposte . pradress1 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . delivery_infos_laposte . pradress2 ? loaded . delivery_infos_laposte . pradress2 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . delivery_infos_laposte . pradress3 ? loaded . delivery_infos_laposte . pradress3 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . delivery_infos_laposte . pradress4 ? loaded . delivery_infos_laposte . pradress4 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . delivery_infos_laposte . przipcode + \ ' \ ' + loaded . delivery_infos_laposte . prtown + \ ' < br /> \
\ ' + loaded . delivery_infos_laposte . country_name + \ ' < br /> \
\ ' + ( loaded . delivery_infos_laposte . cephonenumber ? loaded . delivery_infos_laposte . cephonenumber + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
</ div > \
\ ' : ( loaded . delivery_infos_exapaq ?
\ ' < div class = " address " > \
< strong > '.$this->l(' Exapaq address ').' </ strong >< br /> \
\ ' + ( loaded . delivery_infos_exapaq . company ? loaded . delivery_infos_exapaq . company + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . delivery_address . firstname + \ ' \ ' + loaded . delivery_address . lastname + \ ' < br /> \
\ ' + ( loaded . delivery_infos_exapaq . address1 ? loaded . delivery_infos_exapaq . address1 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . delivery_infos_exapaq . address2 ? loaded . delivery_infos_exapaq . address2 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . delivery_infos_exapaq . postcode + \ ' \ ' + loaded . delivery_infos_exapaq . city + \ ' < br /> \
France < br /> \
\ ' + ( loaded . delivery_infos_exapaq . cephonenumber ? loaded . delivery_infos_exapaq . cephonenumber + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
</ div > \
\ ' : \ ' \ ' )) + \ ' \
< div class = " address " > \
< strong > '.$this->l(' Invoice address ').' </ strong >< br /> \
\ ' + ( loaded . invoice_address . company ? loaded . invoice_address . company + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . invoice_address . firstname + \ ' \ ' + loaded . invoice_address . lastname + \ ' < br /> \
\ ' + ( loaded . invoice_address . address1 ? loaded . invoice_address . address1 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . invoice_address . address2 ? loaded . invoice_address . address2 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . invoice_address . postcode + \ ' \ ' + loaded . invoice_address . city + \ ' < br /> \
\ ' + ( loaded . invoice_address . country ? loaded . invoice_address . country + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . invoice_address . phone ? loaded . invoice_address . phone + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . invoice_address . phone_mobile ? loaded . invoice_address . phone_mobile + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
</ div > \
< div class = " address \ ' + (loaded.invoice_address.country != \ 'France \ '? \ ' foreign \ ': \ ' \ ') + \ ' " > \
< strong > '.$this->l(' Delivery address ').' </ strong >< br /> \
\ ' + ( loaded . delivery_address . company ? loaded . delivery_address . company + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . delivery_address . firstname + \ ' \ ' + loaded . delivery_address . lastname + \ ' < br /> \
\ ' + ( loaded . delivery_address . address1 ? loaded . delivery_address . address1 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . delivery_address . address2 ? loaded . delivery_address . address2 + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + loaded . delivery_address . postcode + \ ' \ ' + loaded . delivery_address . city + \ ' < br /> \
\ ' + ( loaded . delivery_address . country ? loaded . delivery_address . country + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . delivery_address . phone ? loaded . delivery_address . phone + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
\ ' + ( loaded . delivery_address . phone_mobile ? loaded . delivery_address . phone_mobile + \ ' < br /> \ ' : \ ' \ ' ) + \ ' \
</ div > \
</ div > \ ' ;
if ( loaded . france_address_error ) {
content += \ '<div class="warning" style="width: 888px; margin: 20px 0px;"><strong>' . addslashes ( $this -> l ( 'Warning: postcode and city do not seem to match.' )) . ' </ strong > \ ' ;
if ( loaded . france_address_suggestions . length > 0 ) {
content += \ '<br />' . addslashes ( $this -> l ( 'Suggestions:' )) . ' < br /> \ ' ;
for ( var i in loaded . france_address_suggestions ) {
content += loaded . france_address_suggestions [ i ] . postcode + \ ' - \ ' + loaded . france_address_suggestions [ i ] . city + \ ' < br /> \ ' ;
}
}
content += \ ' </ div > \ ' ;
}
content += \ ' \
< form id = " button_form " method = " POST " action = " '.str_replace(array('&mode=&mode=', '&mode=0&mode=0', '&mode=1&mode=1'), array('&mode=', '&mode=0', '&mode=1'), preg_replace('/ \ &id_order=[0-9]+/', '', $_SERVER['REQUEST_URI'] )).'&mode= \ ' + window.location.hash.replace( \ '# \ ', \ ' \ ') + \ '&id_order= \ ' + loaded.order.id + window.location.hash + \ ' " > \
< div class = " actions " > \
< a id = " button1 " class = " button " onclick = " window.open(this.href); return false; " href = " '.__PS_BASE_URI__.'adm/index.php?tab=AdminCustomers&id_customer= \ ' + loaded.order.id_customer + \ '&viewcustomer&token='.Tools::getAdminTokenLite('AdminCustomers').' " > [ F4 ] '.$this->l(' View customer ').' </ a > \
< a id = " button2 " class = " button " onclick = " window.open(this.href); return false; " href = " '.__PS_BASE_URI__.'adm/index.php?tab=AdminOrders&id_order= \ ' + loaded.order.id + \ '&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').' " > [ F3 ] '.$this->l(' View order ').' </ a > \
< a id = " button3 " class = " button " onclick = " window.open(this.href); return false; " href = " '.__PS_BASE_URI__.'adm/pdf.php?id_order= \ ' + loaded.order.id + \ '&pdf " > [ F2 ] '.$this->l(' View invoice ').' </ a > \
\
< div class = " form " > \ ' ;
/* if ( $ . inArray ( parseInt ( loaded . delivery_address . id_country ), [ 1 , 2 , 3 , 6 , 8 , 10 , 12 , 13 , 17 , 26 , 40 , 148 , 245 ]) == - 1 ) {
confirm ( " Impression bloquée : l \ 'envoi de cette commande requiert des documents douaniers " );
} */
'./*($_SERVER[' REMOTE_ADDR '] != ' 78.226 . 56.137 ' && !in_array((int) $cookie->id_employee, array(70, 77))? ' if ( $ . inArray ( parseInt ( loaded . delivery_address . id_country ), [ 8 ]) == - 1 ) {
confirm ( " Impression bloquée : envoi à l \ 'international indisponible " );
} ': ' ').*/'
if ((
$ . inArray ( loaded . order . id_carrier , carriers_laposte ) > 0
|| $ . inArray ( loaded . order . id_carrier , carriers_exapaq ) > 0
2017-01-11 15:33:44 +01:00
|| $ . inArray ( loaded . order . id_carrier , carriers_mondialrelay ) >= 0
2016-01-04 12:49:26 +01:00
)
2017-02-02 17:22:42 +01:00
&& $ . inArray ( parseInt ( loaded . delivery_address . id_country ), [ 1 , 2 , 3 , 6 , 8 , 10 , 12 , 13 , 15 , 17 , 26 , 40 , 148 , 245 ]) != - 1 ) {
2016-01-04 12:49:26 +01:00
content += \ '<label for="parcel_carrier">' . $this -> l ( 'Carrier' ) . ' </ label >< select onchange = " changeCarrier(); " id = " parcel_carrier " name = " parcel_carrier " > \
' ;
foreach ( $logistics_carriers as $name => $class ) {
$this -> _html .= '<option value="' . $name . '">' . $class -> displayName . '</option>' ;
}
$this -> _html .= ' \
</ select > \ ' ;
content += \ '<label for="weight">' . $this -> l ( 'Weight:' ) . '</label> <input type="text" value="\' + /*ps_round(loaded.weight, 3)*/ \'0\' + \'" name="weight" id="weight" /> kg <input id="button4" onclick="checkPrinting(); return false;" type="submit" class="button" name="submitShip" value="[F1] ' . addslashes ( $this -> l ( 'Register the parcel and print the label' )) . ' " > \ ';
}
content += \ ' </ div ></ div > \
\
< table class = " std table " > \
< thead > \
< tr > \
< td colspan = " 8 " style = " text-align: center; padding-bottom: 2px; " > \
< label style = " width: auto; font-size: 12px; float: none; " > '.$this->l(' EAN13 entry : ').' </ label > < input type = " text " value = " " autocomplete = " off " id = " eaninput " onkeydown = " return filterKeys(event); " onkeyup = " checkEAN(); " /> \
</ td > \
</ tr > \
< tr > \
< th class = " width1 " ></ th > \
< th > '.$this->l(' Product ').' </ th > \
< th class = " width2 " > '.$this->l(' Reference ').' </ th > \
< th class = " width2 " style = " display: none; " > '.$this->l(' Supplier reference ').' </ th > \
< th class = " width2 " title = " '. $this->l ('Bought / Refunded / Sent').' " > '.$this->l(' Quantities ').' </ th > \
< th class = " width2 " > '.$this->l(' Quantity to ship ').' </ th > \
2016-06-20 15:09:13 +02:00
< th class = " width2 " > '.$this->l(' Att ').' </ th > \
2016-01-04 12:49:26 +01:00
< th class = " width2 " >< span style = " margin-right: 65px; " > '.$this->l(' Quantity shipped ').' </ span ></ th > \
</ tr > \
</ thead > \
< tbody > \ ' ;
for ( var i = 0 ; i < loaded . products . length ; i ++ ) {
content += \ ' \
< tr data - weight = " \ ' + (parseFloat(loaded.products[i].product_weight) == 0.001? 0.24: loaded.products[i].product_weight) + \ ' " data - carrier = " \ ' + loaded.products[i].carriers.join( \ ', \ ') + \ ' " rel = " \ ' + (loaded.products[i].product_ean13? loaded.products[i].product_ean13: \ ' \ ') + \ ' " class = " \ ' + (loaded.products[i].id_shipping == 2? \ 'fed_ship \ ': \ ' \ ') + ( $ .inArray(loaded.products[i].product_id, locked_products) != -1? \ 'blocked \ ': \ ' \ ') + ((loaded.products[i].product_quantity - (loaded.products[i].product_quantity_refunded > 0? loaded.products[i].product_quantity_refunded: loaded.products[i].product_quantity_return) - loaded.products[i].product_quantity_sent > 0) && ( $ .inArray(parseInt(loaded.products[i].id_sale), sales_list) != -1)? \ ' \ ': \ 'grey \ ') + (Math.max( $ .inArray(loaded.products[i].product_id, locked_products) != -1? \ '0 \ ': (loaded.products[i].product_quantity - (loaded.products[i].product_quantity_refunded > 0? loaded.products[i].product_quantity_refunded: loaded.products[i].product_quantity_return) - loaded.products[i].product_quantity_sent), 0) > 1? \ ' blue \ ': \ ' \ ') + \ ' " > \
< td >< img src = " \ ' + loaded.products[i].image + \ ' " alt = " " width = " 200 " height = " 200 " /></ td > \
< td > \ ' + loaded . products [ i ] . product_name . replace ( " - " , " <br /> " ) + \ ' </ td > \
< td class = " right " > \ ' + ( loaded . products [ i ] . product_reference ? loaded . products [ i ] . product_reference + \ ' < br /> \ ' : \ ' \ ' ) + ( loaded . products [ i ] . product_ean13 ? loaded . products [ i ] . product_ean13 : \ ' \ ' ) + ( loaded . products [ i ] . location ? \ ' < br />< span class = " location " > \ ' + loaded . products [ i ] . location + \ ' </ span > \ ' : \ ' \ ' ) + \ ' </ td > \
< td class = " right " style = " display: none; " > \ ' + ( loaded . products [ i ] . product_supplier_reference ? loaded . products [ i ] . product_supplier_reference : \ ' \ ' ) + \ ' </ td > \
< td class = " center " >< span style = " opacity: .4 " > \ ' + loaded . products [ i ] . product_quantity + \ ' / \ ' + ( loaded . products [ i ] . product_quantity_refunded > 0 ? loaded . products [ i ] . product_quantity_refunded : loaded . products [ i ] . product_quantity_return ) + \ ' / \ ' + loaded . products [ i ] . product_quantity_sent + \ ' </ span ></ td > \
< td class = " center toship \ ' + (loaded.products[i].product_quantity - loaded.products[i].product_quantity_return - loaded.products[i].product_quantity_sent == 0? \ ' red \ ': \ ' \ ') + \ ' " >< strong > \ ' + Math . max ( $ . inArray ( loaded . products [ i ] . product_id , locked_products ) != - 1 ? \ ' 0 \ ' : ( loaded . products [ i ] . product_quantity - ( loaded . products [ i ] . product_quantity_refunded > 0 ? loaded . products [ i ] . product_quantity_refunded : loaded . products [ i ] . product_quantity_return ) - loaded . products [ i ] . product_quantity_sent ), 0 ) + \ ' </ strong ></ td > \
2016-06-20 18:27:54 +02:00
< td class = " center " >< input type = " checkbox " name = " product_ids[] " value = " \ ' + loaded.products[i].product_id + \ ' " \ ' + ( loaded . products [ i ] . is_pending > 0 ? \ ' checked disabled\ ' : \ ' \ ' ) + \ ' /></ td > \
2016-01-04 12:49:26 +01:00
< td class = " shipped " > \ ' ;
2016-09-01 11:17:43 +02:00
if ( loaded . products [ i ] . id_shipping != 2
|| ( loaded . products [ i ] . id_shipping == 2
&& '.( ($cookie->profile == 1 || $cookie->profile == 7) ? ' true ': ' false ').' ) )
2016-01-04 12:49:26 +01:00
{
content += \ ' < input readonly = " true " onchange = " checkParcelCarrier( $ (this)); " name = " shipped[ \ ' + loaded.products[i].id_order_detail + \ '] " type = " text " value = " \ ' + /*(loaded.products[i].id_shipping == 2? \ '0 \ ': ( $ .inArray(loaded.products[i].product_id, locked_products) != -1? \ '0 \ ': (loaded.products[i].product_quantity - (loaded.products[i].product_quantity_refunded > 0? loaded.products[i].product_quantity_refunded: loaded.products[i].product_quantity_return) - loaded.products[i].product_quantity_sent > 0? loaded.products[i].product_quantity - (loaded.products[i].product_quantity_refunded > 0? loaded.products[i].product_quantity_refunded: loaded.products[i].product_quantity_return) - loaded.products[i].product_quantity_sent: \ '0 \ '))) +*/ \ '0 " autocomplete = " off " />< span class = " qtyblock " >< a onclick = " qtyUp( $ (this), \ ' + ( $ .inArray(loaded.products[i].product_id, locked_products) != -1? 0: Math.max((loaded.products[i].product_quantity - (loaded.products[i].product_quantity_refunded > 0? loaded.products[i].product_quantity_refunded: loaded.products[i].product_quantity_return) - loaded.products[i].product_quantity_sent), 0)) + \ '); return false; " >+</ a >< a onclick = " qtyDown( $ (this)); return false; " >-</ a ></ span > \ ' ;
}
content += \ ' \
</ td > \
</ tr > \
\ ' ;
}
content += \ ' \
</ tbody > \
2016-06-20 15:32:06 +02:00
< tfoot > \
< tr > \
2016-06-20 18:27:54 +02:00
< td colspan = " 5 " ></ td > \
< td style = " text-align: center; " >< input type = " submit " class = " button " name = " submitMod " value = " '. $this->l ('MOD').' " /></ td > \
2016-06-20 15:32:06 +02:00
< td ></ td > \
</ tr > \
</ tfoot > \
2016-01-04 12:49:26 +01:00
</ table > \ ' ;
if ( loaded . logs . length > 0 ) {
content += \ ' < div id = " shippingLogs " > \
< strong > '.$this->l(' Shipping logs ').' </ strong >< br /> \
< table class = " logs " > \
< thead > \
< tr > \
< th > '.$this->l(' Date ').' </ th > \
< th > '.$this->l(' Employee ').' </ th > \
< th > '.$this->l(' Quantity sent ').' </ th > \
< th > '.$this->l(' Product ').' </ th > \
< th > '.$this->l(' Reference ').' </ th > \
< th > '.$this->l(' Supplier reference ').' </ th > \
< th > '.$this->l(' Shipping number ').' </ th > \
< th > '.$this->l(' Carrier ').' </ th > \
2016-10-28 10:54:34 +02:00
' . ((( int ) $cookie -> profile == 1 || ( int ) $cookie -> profile == 9 || ( int ) $cookie -> profile == 7 || ( int ) $cookie -> profile == 14 ) ?
2016-01-04 12:49:26 +01:00
'<th></th>' : '' ) . ' \
2016-10-28 10:54:34 +02:00
' . ((( int ) $cookie -> profile == 1 || ( int ) $cookie -> profile == 9 || ( int ) $cookie -> profile == 7 || ( int ) $cookie -> profile == 14 ) ?
2016-08-23 18:05:47 +02:00
'<th></th>' : '' ) . ' \
2016-01-04 12:49:26 +01:00
</ tr > \
</ thead > \
< tbody > \ ' ;
for ( var i = 0 ; i < loaded . logs . length ; i ++ ) {
content += \ ' < tr > \
< td > \ ' + loaded . logs [ i ] . date_add + \ ' </ td > \
< td > \ ' + loaded . logs [ i ] . firstname + \ ' \ ' + loaded . logs [ i ] . lastname + \ ' </ td > \
< td > \ ' + loaded . logs [ i ] . quantity + \ ' </ td > \
< td > \ ' + loaded . logs [ i ] . product_name . replace ( " - " , " <br /> " ) + \ ' </ td > \
< td > \ ' + loaded . logs [ i ] . product_reference + \ ' </ td > \
< td > \ ' + loaded . logs [ i ] . product_supplier_reference + \ ' </ td > \
< td > \ ' + loaded . logs [ i ] . shipping_number + \ ' </ td > \
< td > \ ' + carriers [ loaded . logs [ i ] . carrier ] + \ ' </ td > \
2016-10-28 10:54:34 +02:00
' . ((( int ) $cookie -> profile == 1 || ( int ) $cookie -> profile == 9 || ( int ) $cookie -> profile == 7 || ( int ) $cookie -> profile == 14 ) ?
2016-01-04 12:49:26 +01:00
'<td><a href="/adm/index.php?tab=AdminLogistics&token=' . Tools :: getAdminTokenLite ( 'AdminLogistics' ) . '&id_order=\' + loaded.order.id + \'&delete_\' + loaded.logs[i].carrier + \'=\' + loaded.logs[i].id_order_detail + \'&delete_number=\' + loaded.logs[i].shipping_number + \'">x</a></td>' : '' ) . ' \
2016-10-28 10:54:34 +02:00
' . ((( int ) $cookie -> profile == 1 || ( int ) $cookie -> profile == 9 || ( int ) $cookie -> profile == 7 || ( int ) $cookie -> profile == 14 ) ?
2016-08-25 12:14:34 +02:00
'<td><a title="Re print" class="reprint ui-icon ui-icon-arrowthickstop-1-s" data-product="\' + loaded.logs[i].product_name.replace(" - ", "<br />") + \'" data-ref="\' + loaded.logs[i].product_reference + \'" data-id_order="\' + loaded.order.id + \'" data-carrier="\' + loaded.logs[i].carrier + \'" data-id_order_detail="\' + loaded.logs[i].id_order_detail + \'">+</a></td>' : '' ) . ' \
2016-01-04 12:49:26 +01:00
</ tr > \ ' ;
}
content += \ ' </ tbody ></ table ></ div > \ ' ;
2016-08-25 12:14:34 +02:00
content += \ ' \
< div id = " form-reprint-label " > \
2016-09-01 11:17:43 +02:00
< fieldset style = " margin-top:30px; " > \
< legend > '.$this->l(' Print another Label ').' </ legend > \
< p > < label > '.$this->l(' Product : ').' </ label > < span id = " product-name " ></ span ></ p > \
< p > < label > '.$this->l(' Ref : ').' </ label > < span id = " product-ref " ></ span ></ p > \
< p > < label for = " products " > '.$this->l(' Quantity : ').' </ label > < input type = " text " value = " \ ' + \ '1 \ ' + \ ' " name = " products_reprint[] " id = " quantity-reprint " /></ p > \
< input type = " hidden " value = " laposte " name = " carrier_reprint " id = " carrier-reprint " /> \
< input type = " hidden " value = " 0 " name = " id_order_reprint " id = " id_order-reprint " /> \
< p style = " padding-left: 200px; " > < input id = " button5 " type = " submit " class = " button " name = " submitReprintShip " value = " '.addslashes( $this->l ('Register the parcel and print the label')).' " > </ p > \
</ fieldset > \
2016-08-25 12:14:34 +02:00
\
</ div > \ ' ;
2016-01-04 12:49:26 +01:00
}
' ;
2016-10-28 10:54:34 +02:00
if (( int ) $cookie -> profile == 1 || ( int ) $cookie -> profile == 2 || ( int ) $cookie -> profile == 7 || ( int ) $cookie -> profile == 14 ) {
2016-01-04 12:49:26 +01:00
$this -> _html .= '
content += \ ' < br />< br /> \ ' ;
' ;
foreach ( $logistics_carriers as $name => $class ) {
$this -> _html .= '
content += \ '<input type="submit" class="button" name="submitTest' . ucfirst ( $name ) . '" value="' . addslashes ( $this -> l ( 'Print a test label' )) . ' (' . $class -> displayName . ' ) " > \ ';
' ;
}
}
$this -> _html .= '
content += \ ' </ form > \ ' ;
2016-08-25 12:14:34 +02:00
2016-01-04 12:49:26 +01:00
$ ( " #orderInfos " ) . html ( content );
2017-07-04 15:29:26 +02:00
if ( $ . inArray ( String ( loaded . order . id_carrier ), carriers_laposte ) != - 1 ) {
$ ( " #parcel_carrier option[value= \ 'lasposte \ '] " ) . attr ( " selected " , " selected " );
} else if ( $ . inArray ( String ( loaded . order . id_carrier ), carriers_exapaq ) != - 1 ) {
$ ( " #parcel_carrier option[value= \ 'exapaq \ '] " ) . attr ( " selected " , " selected " );
} else if ( $ . inArray ( String ( loaded . order . id_carrier ), carriers_mondialrelay ) != - 1 ) {
$ ( " #parcel_carrier option[value= \ 'mondialrelay \ '] " ) . attr ( " selected " , " selected " );
2016-01-04 12:49:26 +01:00
}
$ ( " #orderInfos " ) . show ();
$ ( " #main table.std tbody " ) . append ( $ ( " #main table.std tbody tr " ) . get () . sort ( function ( a , b ) {
return $ ( a ) . attr ( " class " ) == " grey " ;
}));
if ( ean_focus ) {
$ ( " #eaninput " ) . focus ();
}
2016-08-25 12:14:34 +02:00
$ ( " .reprint " ) . each ( function (){
$ ( this ) . click ( function ( e ){
e . preventDefault ();
2016-08-31 16:25:49 +02:00
$ ( " span#product-name " ) . html ( $ ( this ) . data ( " product " ));
2016-08-26 12:00:54 +02:00
$ ( " span#product-ref " ) . text ( $ ( this ) . data ( " ref " ));
$ ( " #carrier-reprint " ) . val ( $ ( this ) . data ( " carrier " ));
$ ( " #id_order-reprint " ) . val ( $ ( this ) . data ( " id_order " ));
2016-09-01 11:17:43 +02:00
$ ( " #quantity-reprint " ) . attr ( " name " , " products_reprint[ " + $ ( this ) . data ( " id_order_detail " ) + " ] " );
2016-08-26 16:35:02 +02:00
/*$("#form-reprint-labels").hide();*/
2016-08-25 12:14:34 +02:00
$ ( " #form-reprint-label " ) . show ();
});
});
2016-08-26 16:35:02 +02:00
$ ( " #reprint_label2 " ) . click ( function ( e ){
e . preventDefault ();
$ ( " #id_order-reprint2 " ) . val ( $ ( this ) . data ( " id_order " ));
$ ( " #form-reprint-label " ) . hide ();
$ ( " #form-reprint-labels " ) . show ();
});
2016-01-04 12:49:26 +01:00
}
}
});
}
-->
</ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'modules/logistics/libs/jquery.hotkeys.js " ></ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'modules/logistics/libs/jquery.simplemodal.js " ></ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'modules/logistics/libs/jquery-ui-1.8.20.custom.min.js " ></ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'modules/logistics/libs/jquery.multiselect.min.js " ></ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'modules/logistics/libs/jquery.multiselect.filter.min.js " ></ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'modules/logistics/scripts.js?v=7 " ></ script >
<!-- modal content -->
< div id = " confirm " >
< div class = " header " >< span > Erreur </ span ></ div >
< div class = " message " ></ div >
< div class = " buttons " >
< div class = " no simplemodal-close " > OK </ div >
</ div >
</ div >
<!-- prompt content -->
< div id = " prompt " >
< div class = " header " >< span > Confirmation </ span ></ div >
< div class = " message " ></ div >
< div class = " buttons " >
< div class = " yes simplemodal-close " > Valider </ div >
< div class = " no simplemodal-close " > Annuler </ div >
</ div >
</ div >
<!-- preload the images -->
< div style = " display:none " >
< img src = " '.__PS_BASE_URI__.'modules/logistics/img/confirm/header.gif " alt = " " />
< img src = " '.__PS_BASE_URI__.'modules/logistics/img/confirm/button.gif " alt = " " />
</ div >
< form action = " '.__PS_BASE_URI__.'modules/logistics/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 >
< fieldset style = " overflow: auto; position: relative; margin-top: 30px;'.( $cookie->profile == 1 || count( $sales_list ) > 0? ' display: block;': 'display: none;').' " >
< legend > '.$this->l(' Order selection ').' </ legend >
< legend class = " right " style = " right: 185px; " > [ F11 ] '.$this->l(' Mode : ').' < a '.(Tools::getValue(' mode ') == ' light '? ' class = " active " ': ' ').' onclick = " toggleMode(this); " href = " #light " > '.$this->l(' light ').' </ a > | < a '.(Tools::getValue(' mode ') == ' light '? ' ': ' class = " active " ').' onclick = " toggleMode(this); " href = " #normal " > '.$this->l(' complete ').' </ a ></ legend >
< legend class = " right " > [ F12 ] '.$this->l(' EAN13 entry ').' </ legend >
< legend class = " right " style = " right: 400px; " >< a style = " cursor: pointer; " onclick = " window.open( \ '/modules/shippingstats/showstats.php?token='.Tools::getValue('token').'&id_employee='.(int) $cookie->id_employee .' \ ', \ ' \ ', \ 'menubar=no, status=no, width=400, height=400 \ '); " > Statistiques </ a ></ legend >
< p style = " float: left; width: 435px; " >
< 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 >
< p style = " float: right; width: 435px; margin-top:15px " >
< label for = " manualinput " style = " display: inline; float: none; width: auto; " > '.$this->l(' Manual input : ').' </ label >
< input type = " text " id = " manualinput " value = " " autocomplete = " off " placeholder = " '. $this->l ('Enter an order id here').' " style = " width: 250px; " />
< p style = " font-size: 11px; margin-left: 124px; float: right; clear:both; " > Saisir un id de commande puis appuyer sur ENTREE </ p >
</ p >
</ fieldset >
< div id = " orderInfos " style = " display: none; " ></ div >
' ;
echo $this -> _html ;
}
}