name = 'ekstatinvoicelist'; $this->tab = 'export'; $this->version = '1.0.6'; $this->author = 'Ekyss'; $this->need_instance = 0; // $this->ps_versions_compliancy = array('min' => '1.4', 'max' => '1.6'); $this->dependencies = array(); $this->module_key = '3adb3ce6d69b19bdc340546b0b1041ac'; parent::__construct(); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Stat : Invoice List'); $this->description = $this->l('List of invoices over a period.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall the module ').$this->displayName; } public function install() { if (!parent::install()) { return false; } return true; } public function uninstall() { if (!parent::uninstall()) { return false; } return true; } protected function postProcess() { $this->do_export = false; $is_submit = false; $from = $this->_date_from; $to = $this->_date_to; if (Tools::isSubmit('submitDatePicker')) { if (!Validate::isDate($from = Tools::getValue('datepickerFrom')) || !Validate::isDate($to = Tools::getValue('datepickerTo'))) { $this->_errors[] = Tools::displayError('Date specified is invalid'); } $is_submit = true; } if (Tools::isSubmit('submitDateDay')) { $from = date('Y-m-d'); $to = date('Y-m-d'); $is_submit = true; } if (Tools::isSubmit('submitDateDayPrev')) { $yesterday = time() - 60 * 60 * 24; $from = date('Y-m-d', $yesterday); $to = date('Y-m-d', $yesterday); $is_submit = true; } if (Tools::isSubmit('submitDateMonth')) { $from = date('Y-m-01'); $to = date('Y-m-t'); $is_submit = true; } if (Tools::isSubmit('submitDateMonthPrev')) { $m = (date('m') == 1 ? 12 : date('m') - 1); $y = ($m == 12 ? date('Y') - 1 : date('Y')); $from = $y.'-'.$m.'-01'; $to = $y.'-'.$m.date('-t', mktime(12, 0, 0, $m, 15, $y)); $is_submit = true; } if (Tools::isSubmit('submitDateYear')) { $from = date('Y-01-01'); $to = date('Y-12-31'); $is_submit = true; } if (Tools::isSubmit('submitDateYearPrev')) { $from = (date('Y') - 1).date('-01-01'); $to = (date('Y') - 1).date('-12-31'); $is_submit = true; } if (Tools::isSubmit('submitExportCsv')) { if (!Validate::isDate($from = Tools::getValue('datepickerFrom')) || !Validate::isDate($to = Tools::getValue('datepickerTo'))) { $this->_errors[] = Tools::displayError('Date specified is invalid'); } $this->do_export = true; $is_submit = true; } if (!$is_submit) { if (!Validate::isDate($from = Tools::getValue('datepickerFrom')) || !Validate::isDate($to = Tools::getValue('datepickerTo'))) { $this->_errors[] = Tools::displayError('Date specified is invalid'); } } $this->_date_from = $from; $this->_date_to = $to; if (isset($from) && isset($to) && !count($this->_errors)) { $employee = new Employee($this->context->employee->id); $employee->stats_date_from = $from; $employee->stats_date_to = $to; $employee->update(); } // if (sizeof($this->_errors)) // AdminTab::displayErrors(); } public function getHeaderArray() { $head_tbl = array(); $head_tbl[] = $this->l('N° Cmd.'); $head_tbl[] = $this->l('Statut'); $head_tbl[] = $this->l('N° Facture'); $head_tbl[] = $this->l('Date Facture'); $head_tbl[] = $this->l('Client'); $head_tbl[] = $this->l('N° TVA'); $head_tbl[] = $this->l('Livraison'); $head_tbl[] = $this->l('Mode de paiement'); $head_tbl[] = $this->l('Produits Total HT'); $head_tbl[] = $this->l('Produits Total TVA'); $head_tbl[] = $this->l('Produits Total TTC'); $head_tbl[] = $this->l('Produits Réductions TTC'); $head_tbl[] = $this->l('Livraison Total HT'); $head_tbl[] = $this->l('Livraison Taux TVA'); $head_tbl[] = $this->l('Livraison Total TVA'); $head_tbl[] = $this->l('Livraison Total TTC'); $head_tbl[] = $this->l('Total HT'); $head_tbl[] = $this->l('Total TVA'); $head_tbl[] = $this->l('Total TTC'); $head_tbl[] = $this->l('Total Payé'); return $head_tbl; } public function formatMoney($val_money) { $result = number_format($val_money, 2, ',', ''); // $result = str_replace('.', ',', $val_money); return $result; } public function getDataArray() { // $currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT'))); $fact_tbl = array(); // $order_ids = Order::getOrdersIdByDate($this->_date_from, $this->_date_to, null, 'invoice'); $order_ids = Order::getOrdersIdInvoiceByDate($this->_date_from, $this->_date_to, null, 'invoice'); foreach ($order_ids as $order_id) { $order = new Order($order_id); $customer = new Customer($order->id_customer); $address = new Address($order->id_address_invoice); $carrier = new Carrier($order->id_carrier); $state = $order->getCurrentStateFull($this->context->language->id); // $trans_ht = round(((100 - $order->carrier_tax_rate) * $order->total_shipping)/100, 2); $trans_ht = round(100 * $order->total_shipping / (100 + $order->carrier_tax_rate), 2); $total_ht = $order->total_products + $trans_ht; // $total_ht = 0; $total_ttc = $order->total_products_wt - $order->total_discounts + $order->total_shipping; // $total_ttc = 0; $total_tva = $total_ttc - $total_ht; $lgn_tbl = array(); // fb::info($order_id , 'order_id'); // fb::info($order->getCurrentStateFull($this->context->language->id) , 'state'); $lgn_tbl[] = $order->id; $lgn_tbl[] = $state['name']; $lgn_tbl[] = $order->invoice_number; $lgn_tbl[] = Tools::displayDate($order->invoice_date, (int)$this->context->language->id, true); $lgn_tbl[] = $customer->firstname.' '.$customer->lastname; $lgn_tbl[] = $address->vat_number; $lgn_tbl[] = $carrier->name; $lgn_tbl[] = $order->payment; $lgn_tbl[] = $this->formatMoney($order->total_products); $lgn_tbl[] = $this->formatMoney($order->total_products_wt - $order->total_products); $lgn_tbl[] = $this->formatMoney($order->total_products_wt); $lgn_tbl[] = $this->formatMoney(-$order->total_discounts); $lgn_tbl[] = $this->formatMoney($trans_ht); $lgn_tbl[] = number_format($order->carrier_tax_rate, 2, ',', ' ').' %'; $lgn_tbl[] = $this->formatMoney($order->total_shipping - $trans_ht); $lgn_tbl[] = $this->formatMoney($order->total_shipping); $lgn_tbl[] = $this->formatMoney($total_ht); $lgn_tbl[] = $this->formatMoney($total_tva); $lgn_tbl[] = $this->formatMoney($total_ttc); $lgn_tbl[] = $this->formatMoney($order->total_paid_real); // ajout de la ligne au tbl $fact_tbl[] = $lgn_tbl; } return $fact_tbl; } public function getContent() { $employee = new Employee($this->context->employee->id); $this->_date_from = $employee->stats_date_from; $this->_date_to = $employee->stats_date_to; $this->_html = ''; $this->_html .= '
';
// $html .= ''.print_r($this->_errors, true);
// $html .= 'GET = '.print_r($_GET, true);
// $html .= 'POST = '.print_r($_POST, true);
// $html .= '';
// $html .= 'xx'._PS_BASE_URL_.__PS_BASE_URI__.'xx';
$html .= 'Liste des factures
du '.Tools::displayDate($this->_date_from, (int)$this->context->language->id).'
au '.Tools::displayDate($this->_date_to, (int)$this->context->language->id).'.';
$html .= '| '.$head_cell.' | '; } $html .= '
|---|
| '; $html .= $cel_fact; $html .= ' | '; } $html .= '