251 lines
8.6 KiB
PHP
251 lines
8.6 KiB
PHP
|
<?php
|
||
|
if(!defined('_PS_VERSION_')) {
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
|
||
|
class AdminLaPosteSummary extends AdminTab {
|
||
|
public $_html = '';
|
||
|
|
||
|
public function postProcess() {
|
||
|
global $cookie, $smarty;
|
||
|
|
||
|
if(($date = Tools::getValue('print')) && (preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $date))) {
|
||
|
include dirname(__FILE__).'/mpdf/mpdf.php';
|
||
|
|
||
|
$mpdf = new mPDF();
|
||
|
$mpdf->DeflMargin = 5;
|
||
|
$mpdf->DefrMargin = 5;
|
||
|
$mpdf->SetMargins(5, 5, 5, 5);
|
||
|
|
||
|
$delivery = Tools::getValue('type');
|
||
|
|
||
|
$parcels = Db::getInstance()->ExecuteS('
|
||
|
SELECT o.`id_order`, l.`shipping_number`, o.`id_cart`
|
||
|
FROM `'._DB_PREFIX_.'lapostews2` l
|
||
|
LEFT JOIN `'._DB_PREFIX_.'orders` o
|
||
|
ON o.`id_order` = l.`id_order`
|
||
|
WHERE l.`date_add` >= "'.date('Y-m-d 00:00:00', strtotime($date)).'"
|
||
|
AND l.`date_add` <= DATE_ADD("'.date('Y-m-d 00:00:00', strtotime($date)).'", INTERVAL 1 DAY)
|
||
|
GROUP BY l.`shipping_number`
|
||
|
');
|
||
|
|
||
|
$orders = array();
|
||
|
$id_carts = array();
|
||
|
foreach($parcels as $order) {
|
||
|
$orders[$order['shipping_number']] = $order;
|
||
|
$id_carts[$order['id_cart']] = $order['shipping_number'];
|
||
|
}
|
||
|
|
||
|
$delivery_modes = array(
|
||
|
'dom' => array(),
|
||
|
'cit' => array(),
|
||
|
'acp' => array(),
|
||
|
'cdi' => array(),
|
||
|
'col' => array(),
|
||
|
'a2p' => array(),
|
||
|
'dos' => array(),
|
||
|
'rdv' => array(),
|
||
|
'bpr' => array(),
|
||
|
'cold' => array(),
|
||
|
|
||
|
'mrl' => array(),
|
||
|
'coli' => array(),
|
||
|
'com' => array(),
|
||
|
'coe' => array(),
|
||
|
'core' => array(),
|
||
|
'cds' => array(),
|
||
|
'cop' => array(),
|
||
|
);
|
||
|
|
||
|
$delivery_titles = array(
|
||
|
'dom' => 'So Colissimo Domicile sans signature',
|
||
|
'cit' => 'So Colissimo Espace Cityssimo',
|
||
|
'acp' => 'So Colissimo Agence ColiPoste',
|
||
|
'cdi' => 'So Colissimo Centre de distribution',
|
||
|
'col' => 'Colissimo Expert France',
|
||
|
'a2p' => 'So Colissimo Mon Commerçant',
|
||
|
'dos' => 'So Colissimo Domicile avec signature',
|
||
|
'rdv' => 'So Colissimo Domicile sur rendez-vous',
|
||
|
'bpr' => 'So Colissimo Bureau de Poste',
|
||
|
'cold' => 'Colissimo Access',
|
||
|
|
||
|
'mrl' => 'SO à domicile',
|
||
|
'coli' => 'Colissimo Expert Inter',
|
||
|
'com' => 'Colissimo Access OM',
|
||
|
'coe' => 'Colissimo Eco OM',
|
||
|
'core' => 'Colissimo Service France',
|
||
|
'cds' => 'Colissimo Expert OM',
|
||
|
'cop' => 'Colissimo Expert Interne',
|
||
|
);
|
||
|
|
||
|
foreach(Db::getInstance()->ExecuteS('
|
||
|
SELECT *
|
||
|
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
|
||
|
WHERE `id_cart` IN ('.implode(', ', array_keys($id_carts)).')
|
||
|
AND `delivery_mode` = "'.pSQL($delivery).'"
|
||
|
') as $info) {
|
||
|
if(!empty($info['pradress1'])) {
|
||
|
$orders[$id_carts[$info['id_cart']]]['address1'] = $info['pradress1'];
|
||
|
} elseif(!empty($info['pradress2'])) {
|
||
|
$orders[$id_carts[$info['id_cart']]]['address1'] = $info['pradress2'];
|
||
|
} elseif(!empty($info['pradress3'])) {
|
||
|
$orders[$id_carts[$info['id_cart']]]['address1'] = $info['pradress3'];
|
||
|
} elseif(!empty($info['pradress4'])) {
|
||
|
$orders[$id_carts[$info['id_cart']]]['address1'] = $info['pradress4'];
|
||
|
}
|
||
|
|
||
|
$orders[$id_carts[$info['id_cart']]]['lastname'] = $info['prname'];
|
||
|
$orders[$id_carts[$info['id_cart']]]['postcode'] = $info['przipcode'];
|
||
|
|
||
|
$delivery_modes[strtolower($info['delivery_mode'])][] = $id_carts[$info['id_cart']];
|
||
|
}
|
||
|
|
||
|
foreach(array_keys($orders) as $shipping_nbr) {
|
||
|
$found = FALSE;
|
||
|
foreach($delivery_modes as $mode => $numbers) {
|
||
|
if(in_array($shipping_nbr, $numbers)) {
|
||
|
$found = TRUE;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if(!$found) {
|
||
|
$address = new Address((int) Db::getInstance()->getValue('
|
||
|
SELECT `id_address_delivery`
|
||
|
FROM `'._DB_PREFIX_.'orders`
|
||
|
WHERE `id_order` = '.(int) $orders[$shipping_nbr]['id_order'].'
|
||
|
'));
|
||
|
$orders[$shipping_nbr]['address1'] = strtoupper($address->address1);
|
||
|
$orders[$shipping_nbr]['address2'] = strtoupper($address->address2);
|
||
|
$orders[$shipping_nbr]['postcode'] = $address->postcode;
|
||
|
$orders[$shipping_nbr]['lastname'] = $address->lastname;
|
||
|
$delivery_modes['dom'][] = $shipping_nbr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$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;
|
||
|
}
|
||
|
|
||
|
if(($line = Configuration::get('LAPOSTEWS_EXP_ADDR1')) != '') {
|
||
|
$sender_lines[] = $line;
|
||
|
}
|
||
|
if(($line = Configuration::get('LAPOSTEWS_EXP_ADDR2')) != '') {
|
||
|
$sender_lines[] = $line;
|
||
|
}
|
||
|
|
||
|
$sender_postal = Configuration::get('LAPOSTEWS_EXP_POSTALCODE');
|
||
|
$sender_city = Configuration::get('LAPOSTEWS_EXP_CITY');
|
||
|
$sender_phone = Configuration::get('LAPOSTEWS_EXP_PHONE');
|
||
|
|
||
|
$result_links = array();
|
||
|
|
||
|
$delivery_orders = $delivery_modes[$delivery];
|
||
|
|
||
|
if(count($delivery_orders) > 0) {
|
||
|
$_orders = array();
|
||
|
foreach($delivery_orders as $shipping_number) {
|
||
|
$_orders[] = $orders[$shipping_number];
|
||
|
}
|
||
|
|
||
|
$smarty->assign(array(
|
||
|
'orders' => $_orders,
|
||
|
'count_orders' => count($_orders),
|
||
|
'total_weight' => count($_orders) * .24,
|
||
|
'contract' => Configuration::get('LAPOSTEWS_API_CONTRACT'),
|
||
|
'site' => Configuration::get('LAPOSTEWS_SHIPPING_SITE'),
|
||
|
'site_code' => Configuration::get('LAPOSTEWS_SHIPPING_SITE_CODE'),
|
||
|
'sender_lines' => $sender_lines,
|
||
|
'sender_postal' => $sender_postal,
|
||
|
'sender_city' => $sender_city,
|
||
|
'summary_number' => Configuration::get('LAPOSTEWS_SUMMARIES_COUNT'),
|
||
|
'date' => date('d/m/Y', strtotime($date)),
|
||
|
'title' => $delivery_titles[$delivery],
|
||
|
));
|
||
|
|
||
|
Configuration::updateValue('LAPOSTEWS_SUMMARIES_COUNT', ((int) Configuration::get('LAPOSTEWS_SUMMARIES_COUNT')) + 1);
|
||
|
|
||
|
$mpdf->WriteHTML($smarty->fetch(dirname(__FILE__).'/print_summary.tpl'));
|
||
|
|
||
|
$result_links[] = array(date('Ymd', strtotime($date)), $delivery);
|
||
|
|
||
|
$mpdf->Output(dirname(__FILE__).'/summaries/'.$date.'_'.$delivery.'.pdf', 'F');
|
||
|
}
|
||
|
|
||
|
if(count($result_links) > 0) {
|
||
|
setlocale(LC_TIME, 'fr_FR.UTF-8');
|
||
|
echo '<div class="conf">Bordereaux générés pour le '.strftime('%A %d %B %Y', strtotime($date)).' :<br /><ul>';
|
||
|
foreach($result_links as $result_link) {
|
||
|
echo '<li><a href="'.__PS_BASE_URI__.'modules/lapostews/getsummary.php?token='.Tools::getAdminToken('AdminLaPosteSummary'.(int) Tab::getIdFromClassName('AdminLaPosteSummary').(int) $cookie->id_employee).'&date='.$result_link[0].'&dm='.$result_link[1].'&id_employee='.(int) $cookie->id_employee.'" onclick="window.open(this.href); return false;">'.strtoupper($result_link[1]).'</a></li>';
|
||
|
}
|
||
|
echo '</ul></div><br />';
|
||
|
} else {
|
||
|
echo '<p class="error">Aucun bordereau généré</p><br />';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function display() {
|
||
|
global $cookie;
|
||
|
|
||
|
echo '
|
||
|
<script type="text/javascript">
|
||
|
function checkSummaries() {
|
||
|
$.get("'.__PS_BASE_URI__.'modules/lapostews/ajax_summary.php?id_employee='.(int) $cookie->id_employee.'&token='.Tools::getValue('token').'&date=" + $("#summary_date").val(), function(loaded) {
|
||
|
if(loaded) {
|
||
|
var loaded = $.parseJSON(loaded);
|
||
|
|
||
|
$("#summary_type option").hide();
|
||
|
$.each(loaded, function(id, el) {
|
||
|
$("#summary_type option[value=" + el + "]").show();
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$(document).ready(function() {
|
||
|
checkSummaries();
|
||
|
});
|
||
|
</script>
|
||
|
|
||
|
<h2>Génération des bordereaux d\'envoi</h2>
|
||
|
<br />
|
||
|
<fieldset>
|
||
|
<p class="text">
|
||
|
<label for="summary_date">Date :</label>
|
||
|
<input type="text" value="'.date('Y-m-d').'" id="summary_date" onblur="checkSummaries();" />
|
||
|
<br /><br />
|
||
|
</p>
|
||
|
<p class="text">
|
||
|
<label for="summary_date">Type :</label>
|
||
|
<select id="summary_type">
|
||
|
<option value="dom">So Colissimo Domicile sans signature</option>
|
||
|
<option value="cit">So Colissimo Espace Cityssimo</option>
|
||
|
<option value="acp">So Colissimo Agence ColiPoste</option>
|
||
|
<option value="cdi">So Colissimo Centre de distribution</option>
|
||
|
<option value="col">Colissimo Expert France</option>
|
||
|
<option value="a2p">So Colissimo Mon Commerçant</option>
|
||
|
<option value="dos">So Colissimo Domicile avec signature</option>
|
||
|
<option value="rdv">So Colissimo Domicile sur rendez-vous</option>
|
||
|
<option value="bpr">So Colissimo Bureau de Poste</option>
|
||
|
<option value="cold">Colissimo Access</option>
|
||
|
</select>
|
||
|
<br /><br />
|
||
|
</p>
|
||
|
<p class="submit" style="padding-left: 210px;">
|
||
|
<a class="button" onclick="window.location.href=\'/adm/index.php?tab=AdminLaPosteSummary&type=\' + $(\'#summary_type\').val() + \'&token='.Tools::getAdminTokenLite('AdminLaPosteSummary').'&print=\'+$(\'#summary_date\').val(); return false;" href="">Générer les bordereaux</a>
|
||
|
</p>
|
||
|
</fieldset>
|
||
|
';
|
||
|
}
|
||
|
}
|