245 lines
9.4 KiB
PHP
245 lines
9.4 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
|
|
*/
|
|
|
|
require_once(dirname(__FILE__).'/../../prelevementsepa.php');
|
|
|
|
class AdminSepaMandateController extends ModuleAdminController
|
|
{
|
|
public $module = 'prelevementsepa';
|
|
public $name = 'prelevementsepa';
|
|
private $extensions = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
|
|
|
|
public function __construct()
|
|
{
|
|
$this->path = _PS_MODULE_DIR_.$this->module.'/';
|
|
$this->className = 'prelevementsepa';
|
|
$this->display = 'edit';
|
|
$this->multishop_context = Shop::CONTEXT_ALL;
|
|
$this->id_lang = (int)Context::getContext()->language->id;
|
|
$this->lang = true;
|
|
$this->deleted = false;
|
|
$this->colorOnBackground = false;
|
|
$this->url = __PS_BASE_URI__.basename(_PS_MODULE_DIR_).'/'.$this->name.'/';
|
|
$this->images = $this->url.'views/img/';
|
|
$this->context = Context::getContext();
|
|
$this->bootstrap = true;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
public function postProcess()
|
|
{
|
|
$return = parent::postProcess();
|
|
return $return;
|
|
}
|
|
|
|
public function processSave()
|
|
{
|
|
$obj = parent::processSave();
|
|
return $obj;
|
|
}
|
|
public function renderForm()
|
|
{
|
|
$id = Tools::getIsset('id_sepa')?(int)Tools::getValue('id_sepa'):0;
|
|
$customers = Customer::getCustomers(true);
|
|
foreach ($customers as &$cust) {
|
|
$cust['name'] = $cust['firstname'].' '.$cust['lastname'];
|
|
}
|
|
array_unshift($customers, array('id_customer' => 0, 'name' => ''));
|
|
$file = array(
|
|
'type' => 'file',
|
|
'label' => $this->l('Mandate'),
|
|
'name' => 'file'
|
|
);
|
|
if ($id>0) {
|
|
require_once(dirname(__FILE__).'/../../classes/PrevSepa.php');
|
|
$sepa_obj = new PrevSepa((int)$id);
|
|
foreach ($this->extensions as $e) {
|
|
if (file_exists(_PS_UPLOAD_DIR_.'sepa/'.sha1($sepa_obj->rum.$sepa_obj->id_customer).$e)) {
|
|
$file['file'] = __PS_BASE_URI__.basename(_PS_UPLOAD_DIR_)
|
|
.'/sepa/'.sha1($sepa_obj->rum.$sepa_obj->id_customer).$e;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$fields_form = array(
|
|
'form' => array(
|
|
'legend' => array(
|
|
'title' => ($id>0)?$this->l('Edit a Sepa mandate'):$this->l('Add a Sepa mandate'),
|
|
'icon' => 'icon-cogs'
|
|
),
|
|
|
|
'input' => array(
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Customer\'s account'),
|
|
'name' => 'id_customer',
|
|
'options' => array(
|
|
'query' => $customers,
|
|
'id' => 'id_customer',
|
|
'name' => 'name'
|
|
),
|
|
'col' => '4'
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Customer\'s name'),
|
|
'name' => 'sepa_name'
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Customer\'s address'),
|
|
'name' => 'sepa_address'
|
|
),
|
|
array(
|
|
'type' => 'switch',
|
|
'label' => $this->l('State'),
|
|
'name' => 'sepa_state',
|
|
'values' => array(
|
|
array(
|
|
'id' => 'state_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Yes')
|
|
),
|
|
array(
|
|
'id' => 'state_off',
|
|
'value' => 0,
|
|
'label' => $this->l('No')
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('RUM'),
|
|
'name' => 'sepa_rum'
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('IBAN'),
|
|
'name' => 'sepa_iban'
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('BIC/BNC'),
|
|
'name' => 'sepa_bic'
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Type'),
|
|
'name' => 'sepa_type',
|
|
'options' => array(
|
|
'query' => array(array('name'=>'FRST'),array('name'=>'RCUR')),
|
|
'id' => 'name',
|
|
'name' => 'name'
|
|
),
|
|
'col' => '4'
|
|
),
|
|
array(
|
|
'type' => 'date',
|
|
'label' => $this->l('Validate date'),
|
|
'name' => 'datevalid'
|
|
),
|
|
$file,
|
|
array(
|
|
'type' => 'hidden',
|
|
'name' => 'id_sepa'
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'name' => 'send_sepamandate',
|
|
'title' => ($id==0)?$this->l('New Sepa Mandate'):$this->l('Save Sepa Mandate'),
|
|
)
|
|
),
|
|
);
|
|
|
|
$helper = new HelperForm();
|
|
$helper->show_toolbar = false;
|
|
$helper->table = $this->table;
|
|
$helper->identifier = $this->identifier;
|
|
$helper->submit_action = 'sepaMandate';
|
|
$helper->show_cancel_button = true;
|
|
$helper->back_url = $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
|
|
.'&configure='.$this->name.'&update_sepa='.(int)$id
|
|
.'&module_name='.$this->name;
|
|
$helper->back_url .= '&token='.Tools::getAdminTokenLite('AdminModules').'&module_tab=mandates';
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
if ($id == 0) {
|
|
$helper->tpl_vars = array(
|
|
'fields_value' => array(
|
|
'sepa_name' => '',
|
|
'sepa_address' => '',
|
|
'sepa_state' => 0,
|
|
'sepa_rum' => 'UI'.date('Ymd').Tools::passwdGen(12, 'NUMERIC'),
|
|
'sepa_iban' => '',
|
|
'sepa_bic' => '',
|
|
'id_customer' => 0,
|
|
'datevalid' => '',
|
|
'sepa_type' => 'RCUR',
|
|
'id_sepa' => $id
|
|
)
|
|
);
|
|
} else {
|
|
if (Tools::strlen($sepa_obj->rum) < 3) {
|
|
$sepa_obj->rum = 'UI'.date('Ymd').Tools::passwdGen(12, 'NUMERIC');
|
|
}
|
|
$helper->tpl_vars = array(
|
|
'fields_value' => array(
|
|
'sepa_name' => $sepa_obj->name,
|
|
'sepa_address' => $sepa_obj->address,
|
|
'sepa_state' => $sepa_obj->etat,
|
|
'sepa_rum' => $sepa_obj->rum,
|
|
'sepa_iban' => $sepa_obj->iban,
|
|
'sepa_bic' => $sepa_obj->bic,
|
|
'id_customer' => $sepa_obj->id_customer,
|
|
'datevalid' => $sepa_obj->datevalid,
|
|
'sepa_type' => $sepa_obj->sepa_type,
|
|
'id_sepa' => $id
|
|
)
|
|
);
|
|
}
|
|
return $helper->generateForm(array($fields_form));
|
|
}
|
|
|
|
public function ajaxProcessCheckAddress()
|
|
{
|
|
$address = new Address(Address::getFirstCustomerAddressId(Tools::getValue('cid')));
|
|
echo $address->address1.' '.$address->postcode.' - '.$address->city.', '.$address->country;
|
|
die();
|
|
}
|
|
|
|
public function setMedia($isNewTheme = false)
|
|
{
|
|
parent::setMedia($isNewTheme);
|
|
|
|
$this->addJS(__PS_BASE_URI__.$this->admin_webpath.'/themes/'
|
|
.$this->bo_theme.'/js/vendor/test.min.js');
|
|
$this->addJqueryUI('ui.autocomplete');
|
|
$this->addJqueryPlugin('validate');
|
|
$this->addJS($this->path.'views/js/sepa_bo.js');
|
|
$this->addCSS($this->path.'views/css/sepa_bo.css');
|
|
}
|
|
}
|