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 '
Bordereaux générés pour le '.strftime('%A %d %B %Y', strtotime($date)).' :

'; } else { echo '

Aucun bordereau généré


'; } } } public function display() { global $cookie; echo '

Génération des bordereaux d\'envoi






Générer les bordereaux

'; } }