152 lines
6.6 KiB
PHP
152 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* 2007-2017 Decanet
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
* needs please refer to http://www.decanet.fr for more information.
|
|
*
|
|
* @author Decanet SA <contact@decanet.fr>
|
|
* @copyright 2007-2017 Decanet SA
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
class PrevSepaOrder extends ObjectModel
|
|
{
|
|
public $id_sepa_detail;
|
|
public $id_sepa;
|
|
public $id_order;
|
|
public $sepa_date;
|
|
public $traite;
|
|
/**
|
|
* @see ObjectModel::$definition
|
|
*/
|
|
public static $definition = array(
|
|
'table' => 'prelevementsepa_detail',
|
|
'primary' => 'id_sepa_detail',
|
|
'multilang' => false,
|
|
'fields' => array(
|
|
'id_sepa' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
|
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
|
'traite' => array('type' => self::TYPE_BOOL),
|
|
'sepa_date' => array('type' => self::TYPE_DATE)
|
|
),
|
|
);
|
|
public static function existOrder($id_order)
|
|
{
|
|
$sql = 'SELECT id_sepa_detail FROM `'._DB_PREFIX_.'prelevementsepa_detail`
|
|
WHERE id_order = '.(int)$id_order;
|
|
$list = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
if ($list && is_array($list) && count($list)) {
|
|
return (int)$list[0]['id_sepa_detail'];
|
|
}
|
|
return null;
|
|
}
|
|
public static function getAllActive()
|
|
{
|
|
$sql = 'SELECT `'._DB_PREFIX_.'prelevementsepa_detail`.* FROM `'._DB_PREFIX_.'prelevementsepa_detail`
|
|
LEFT JOIN `'._DB_PREFIX_.'prelevementsepa`
|
|
ON (`'._DB_PREFIX_.'prelevementsepa`.id_sepa=`'._DB_PREFIX_.'prelevementsepa_detail`.id_sepa)
|
|
WHERE `'._DB_PREFIX_.'prelevementsepa`.etat=1 ORDER BY id_sepa_detail DESC';
|
|
$list = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
if ($list && is_array($list) && count($list)) {
|
|
return $list;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getAllTodo()
|
|
{
|
|
$sql = 'SELECT `'._DB_PREFIX_.'prelevementsepa_detail`.* FROM `'._DB_PREFIX_.'prelevementsepa_detail`
|
|
LEFT JOIN `'._DB_PREFIX_.'prelevementsepa`
|
|
ON (`'._DB_PREFIX_.'prelevementsepa`.id_sepa=`'._DB_PREFIX_.'prelevementsepa_detail`.id_sepa)
|
|
WHERE `'._DB_PREFIX_.'prelevementsepa`.etat=1 AND'.
|
|
'`'._DB_PREFIX_.'prelevementsepa_detail`.traite=0 AND'.
|
|
'`'._DB_PREFIX_.'prelevementsepa_detail`.sepa_date<="'.date('Y-m-d').'"
|
|
GROUP BY id_sepa_detail ORDER BY id_sepa_detail DESC';
|
|
$list = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
// die(var_dump($list, $sql));
|
|
if ($list && is_array($list) && count($list)) {
|
|
return $list;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getAllSepa($traite = 0, $etat = 1, $now = true)
|
|
{
|
|
|
|
$sql = 'SELECT `'._DB_PREFIX_.'prelevementsepa_detail`.* FROM `'._DB_PREFIX_.'prelevementsepa_detail`
|
|
WHERE `'._DB_PREFIX_.'prelevementsepa_detail`.traite='.(int)$traite.
|
|
($now ? ' AND `'._DB_PREFIX_.'prelevementsepa_detail`.sepa_date<="'.date('Y-m-d').'" ':' ').
|
|
'GROUP BY id_sepa_detail ORDER BY id_sepa_detail DESC';
|
|
$tmp = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
|
|
$list = array();
|
|
if ($tmp && is_array($tmp) && count($tmp)) {
|
|
foreach ($tmp as $t) {
|
|
if ($t['id_sepa']==0) {
|
|
require_once(dirname(__FILE__).'/PrevSepa.php');
|
|
$order = new Order((int)$t['id_order']);
|
|
$id_sepa = PrevSepa::existCustomer((int)$order->id_customer);
|
|
$t['id_sepa'] = $id_sepa;
|
|
$sepa_order_obj = new PrevSepaOrder((int)$t['id_sepa_detail']);
|
|
$sepa_order_obj->id_sepa = (int)$t['id_sepa'];
|
|
$sepa_order_obj->save();
|
|
}
|
|
$sql2 = 'SELECT `'._DB_PREFIX_.'prelevementsepa`.* FROM `'._DB_PREFIX_.'prelevementsepa`
|
|
WHERE `'._DB_PREFIX_.'prelevementsepa`.etat='.(int)$etat.' AND'.
|
|
'`'._DB_PREFIX_.'prelevementsepa`.id_sepa='.(int)$t['id_sepa'];
|
|
$tmp2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql2);
|
|
if (count($tmp2)>0) {
|
|
$tmp2 = $tmp2[0];
|
|
$list[] = array_merge($t, $tmp2);
|
|
}
|
|
}
|
|
return $list;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getGeneratedSepaList($id_order)
|
|
{
|
|
$id_sepa_traited = Db::getInstance()->getValue('SELECT id_sepa_traited FROM
|
|
`'._DB_PREFIX_.'prelevementsepa_traited_order`
|
|
WHERE id_order='.(int)$id_order);
|
|
if ($id_sepa_traited) {
|
|
$orders = Db::getInstance()->executeS('SELECT id_order FROM `'._DB_PREFIX_.'prelevementsepa_traited_order`
|
|
WHERE id_sepa_traited='.(int)$id_sepa_traited);
|
|
$orders_list = array();
|
|
if ($orders) {
|
|
foreach ($orders as $order) {
|
|
$orders_list[] = $order['id_order'];
|
|
}
|
|
$sql = 'SELECT `'._DB_PREFIX_.'prelevementsepa_detail`.*, rum, iban, bic
|
|
FROM `'._DB_PREFIX_.'prelevementsepa_detail`
|
|
LEFT JOIN `'._DB_PREFIX_.'prelevementsepa`
|
|
ON (`'._DB_PREFIX_.'prelevementsepa`.id_sepa=`'._DB_PREFIX_.'prelevementsepa_detail`.id_sepa)
|
|
WHERE id_order IN ('.implode(',', $orders_list).')
|
|
GROUP BY id_sepa_detail ORDER BY id_sepa_detail DESC';
|
|
return Db::getInstance()->executeS($sql);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|