Initial Commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12 general-block-decorator">
|
||||
<div class="row">
|
||||
<div class="col-md-12 title title-without-tabs">
|
||||
{intl d='invoiceref.ai' l="Invoice ref Configuration"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{form name="invoiceref_configuration"}
|
||||
|
||||
<form action="{url path="/admin/module/InvoiceRef/configure"}" method="post">
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{include file = "includes/inner-form-toolbar.html"
|
||||
hide_flags = true
|
||||
page_url = "{url path='/admin/module/InvoiceRef'}"
|
||||
close_url = "{url path='/admin/modules'}"
|
||||
}
|
||||
|
||||
{if $form_error}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="alert alert-danger">{$form_error_message}</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
{form_field form=$form field="invoice"}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}" class="control-label">
|
||||
{$label} {if $required} <span class="required">*</span>{/if}
|
||||
|
||||
{form_error form=$form field="invoice"}
|
||||
<br />
|
||||
<span class="error">{$message}</span>
|
||||
{/form_error}
|
||||
<input type="text" {if $required}aria-required="true" required{/if} placeholder="{$label}" id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control" />
|
||||
</label>
|
||||
{/form_field}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{/form}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
31
local/modules/InvoiceRef/Config/config.xml
Normal file
31
local/modules/InvoiceRef/Config/config.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<config xmlns="http://thelia.net/schema/dic/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||
|
||||
<loops>
|
||||
<!-- sample definition
|
||||
<loop name="MySuperLoop" class="InvoiceRef\Loop\MySuperLoop" />
|
||||
-->
|
||||
</loops>
|
||||
|
||||
<forms>
|
||||
<form name="invoiceref_configuration" class="InvoiceRef\Form\ConfigurationForm" />
|
||||
<!--
|
||||
<form name="MyFormName" class="InvoiceRef\Form\MySuperForm" />
|
||||
-->
|
||||
</forms>
|
||||
|
||||
<commands>
|
||||
<!--
|
||||
<command class="InvoiceRef\Command\MySuperCommand" />
|
||||
-->
|
||||
</commands>
|
||||
|
||||
<services>
|
||||
<service id="invoiceRef.listener" class="InvoiceRef\EventListeners\OrderListener">
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
</services>
|
||||
</config>
|
||||
18
local/modules/InvoiceRef/Config/module.xml
Normal file
18
local/modules/InvoiceRef/Config/module.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module>
|
||||
<fullnamespace>InvoiceRef\InvoiceRef</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Manage invoive ref</title>
|
||||
</descriptive>
|
||||
<descriptive locale="fr_FR">
|
||||
<title>Gestion des numéros de facture</title>
|
||||
</descriptive>
|
||||
<version>0.1</version>
|
||||
<author>
|
||||
<name>Manuel Raynaud</name>
|
||||
<email>manu@thelia.net</email>
|
||||
</author>
|
||||
<type>classic</type>
|
||||
<thelia>2.0.0</thelia>
|
||||
<stability>alpha</stability>
|
||||
</module>
|
||||
35
local/modules/InvoiceRef/Config/routing.xml
Normal file
35
local/modules/InvoiceRef/Config/routing.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<!--
|
||||
|
||||
if a /admin/module/invoiceref/ route is provided, a "Configuration" button will be displayed
|
||||
for the module in the module list. Clicking this button will invoke this route.
|
||||
|
||||
<route id="my_route_id" path="/admin/module/invoiceref">
|
||||
<default key="_controller">InvoiceRef\Full\Class\Name\Of\YourConfigurationController::methodName</default>
|
||||
</route>
|
||||
|
||||
<route id="my_route_id" path="/admin/module/invoiceref/route-name">
|
||||
<default key="_controller">InvoiceRef\Full\Class\Name\Of\YourAdminController::methodName</default>
|
||||
</route>
|
||||
|
||||
<route id="my_route_id" path="/my/route/name">
|
||||
<default key="_controller">InvoiceRef\Full\Class\Name\Of\YourOtherController::methodName</default>
|
||||
</route>
|
||||
|
||||
...add as many routes as required.
|
||||
|
||||
<route>
|
||||
...
|
||||
</route>
|
||||
-->
|
||||
|
||||
<route id="invoiceRef.configuration" path="/admin/module/InvoiceRef/configure" methods="post">
|
||||
<default key="_controller">InvoiceRef\Controller\ConfigurationController::configureAction</default>
|
||||
</route>
|
||||
|
||||
</routes>
|
||||
7
local/modules/InvoiceRef/Config/schema.xml
Normal file
7
local/modules/InvoiceRef/Config/schema.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<database defaultIdMethod="native" name="thelia" namespace="InvoiceRef\Model">
|
||||
<!--
|
||||
See propel documentation on http://propelorm.org for all information about schema file
|
||||
-->
|
||||
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
|
||||
</database>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace InvoiceRef\Controller;
|
||||
use InvoiceRef\Form\ConfigurationForm;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
|
||||
/**
|
||||
* Class ConfigurationController
|
||||
* @package InvoiceRef\Controller
|
||||
* @author manuel raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ConfigurationController extends BaseAdminController
|
||||
{
|
||||
|
||||
public function configureAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'invoiceref', AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = new ConfigurationForm($this->getRequest());
|
||||
$response = null;
|
||||
$error_msg = null;
|
||||
try {
|
||||
$configForm = $this->validateForm($form);
|
||||
|
||||
ConfigQuery::write('invoiceRef', $configForm->get('invoice')->getData(), true, true);
|
||||
|
||||
// Redirect to the success URL,
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
// If we have to stay on the same page, redisplay the configuration page/
|
||||
$route = '/admin/module/InvoiceRef';
|
||||
} else {
|
||||
// If we have to close the page, go back to the module back-office page.
|
||||
$route = '/admin/modules';
|
||||
}
|
||||
$response = RedirectResponse::create(URL::getInstance()->absoluteUrl($route));
|
||||
} catch (FormValidationException $e) {
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($e);
|
||||
} catch (\Exception $e) {
|
||||
$error_msg = $e->getMessage();
|
||||
}
|
||||
if (null !== $error_msg) {
|
||||
$this->setupFormErrorContext(
|
||||
'InvoiceRef Configuration',
|
||||
$error_msg,
|
||||
$form,
|
||||
$e
|
||||
);
|
||||
$response = $this->render(
|
||||
'module-configure',
|
||||
['module_code' => 'InvoiceRef']
|
||||
);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
75
local/modules/InvoiceRef/EventListeners/OrderListener.php
Normal file
75
local/modules/InvoiceRef/EventListeners/OrderListener.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace InvoiceRef\EventListeners;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class OrderListener
|
||||
* @package InvoiceRef\EventListeners
|
||||
* @author manuel raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class OrderListener implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
public function implementInvoice(OrderEvent $event)
|
||||
{
|
||||
$order = $event->getOrder();
|
||||
|
||||
if ($order->isPaid() && null === $order->getInvoiceRef()) {
|
||||
$invoiceRef = ConfigQuery::create()
|
||||
->findOneByName('invoiceRef');
|
||||
|
||||
if (null === $invoiceRef) {
|
||||
throw new \RuntimeException("you must set an invoice ref in your admin panel");
|
||||
}
|
||||
$value = $invoiceRef->getValue();
|
||||
$order->setInvoiceRef($value)
|
||||
->save()
|
||||
;
|
||||
|
||||
$invoiceRef->setValue(++$value)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
TheliaEvents::ORDER_UPDATE_STATUS => ['implementInvoice', 100]
|
||||
];
|
||||
}
|
||||
}
|
||||
71
local/modules/InvoiceRef/Form/ConfigurationForm.php
Normal file
71
local/modules/InvoiceRef/Form/ConfigurationForm.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace InvoiceRef\Form;
|
||||
use InvoiceRef\InvoiceRef;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class ConfigurationForm
|
||||
* @package InvoiceRef\Form
|
||||
* @author manuel raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ConfigurationForm extends BaseForm
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add('invoice', 'text', [
|
||||
'constraints' => [
|
||||
new NotBlank()
|
||||
],
|
||||
'label' => Translator::getInstance()->trans('invoice ref', [], InvoiceRef::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'for' => 'invoice-ref'
|
||||
],
|
||||
'data' => ConfigQuery::read('invoiceRef', 0)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'invoiceref_config';
|
||||
}
|
||||
}
|
||||
5
local/modules/InvoiceRef/I18n/AdminIncludes/en_US.php
Normal file
5
local/modules/InvoiceRef/I18n/AdminIncludes/en_US.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'Invoice ref Configuration' => 'Invoice ref Configuration',
|
||||
);
|
||||
5
local/modules/InvoiceRef/I18n/AdminIncludes/fr_FR.php
Normal file
5
local/modules/InvoiceRef/I18n/AdminIncludes/fr_FR.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'Invoice ref Configuration' => 'Configuration du numéro de facture',
|
||||
);
|
||||
5
local/modules/InvoiceRef/I18n/en_US.php
Normal file
5
local/modules/InvoiceRef/I18n/en_US.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'invoice ref' => 'invoice ref',
|
||||
);
|
||||
5
local/modules/InvoiceRef/I18n/fr_FR.php
Normal file
5
local/modules/InvoiceRef/I18n/fr_FR.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'invoice ref' => 'Numéro de facture',
|
||||
);
|
||||
33
local/modules/InvoiceRef/InvoiceRef.php
Normal file
33
local/modules/InvoiceRef/InvoiceRef.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace InvoiceRef;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
class InvoiceRef extends BaseModule
|
||||
{
|
||||
const DOMAIN_NAME = "invoiceref";
|
||||
/*
|
||||
* You may now override BaseModuleInterface methods, such as:
|
||||
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
|
||||
*
|
||||
* Have fun !
|
||||
*/
|
||||
|
||||
public function postActivation(ConnectionInterface $con = null)
|
||||
{
|
||||
ConfigQuery::write('invoiceRef', 1, true, true);
|
||||
}
|
||||
}
|
||||
14
local/modules/InvoiceRef/Readme.md
Normal file
14
local/modules/InvoiceRef/Readme.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Invoice Number module
|
||||
|
||||
This module allows you to manage the invoice number for your orders.
|
||||
|
||||
## Installation
|
||||
|
||||
* Copy the module into ```<thelia_root>/local/modules/``` directory and be sure that the name of the module is InvoiceRef.
|
||||
* Activate it in your thelia administration panel
|
||||
|
||||
## Usage
|
||||
|
||||
Once installed, you have to set the invoice number used by Thelia. After that, this number will be increased after each payment. For example if you start with number 1000, this number will be increased by 1 after each payment so you will have 1000, after 1001, after 1002, etc.
|
||||
|
||||
If you don't set this number, it will start with number 1
|
||||
Reference in New Issue
Block a user