Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- The credit note list of the back-office is laid out like the order list of default-twig: one search over the reference, the number, the order and the customer; status, type, date and amount filters in a collapsed panel; chips for the active filters; columns sorted by reference, total, creation or update date; pages of the `BoDataTable` and `BoPagination` components. The id column is gone; the reference opens the modal; the invoice reference of a numbered credit note has its column, with the date of its document underneath; the customer shows the flag of the invoice country, the name and the e-mail; a creation or update date shows its age underneath for 30 days, and only the date afterwards or for a date ahead of the clock. The search matches every word in any field, so the names of a customer can come in any order. The date filter bounds the invoice date, as before: the date of its creation for a credit note not numbered yet, the date of its number once accepted. A parameter of the wrong shape is ignored instead of answering 400. The previous parameters (`status_id` of the side menu, `ref`, `creditNoteDateMin`, `creditNoteDateMax`) still filter; `credit_note_page` and `credit_note_order` are no longer read (the list opens on its first page, newest first). Edit and Delete show only to an administrator with the update or delete right on the module. `CreditNoteHookPresenter::listRows()` is removed, replaced by `CreditNoteListReader` and `CreditNoteListRowPresenter`.
- The back-office screens are translated again: their labels used the `creditnote.bo.default` domain, which the kernel stopped loading once the Smarty back-office (`templates/backOffice/default/`) was removed, since it registers a `<module>.bo.<template>` domain only for a template the module ships. The domain is now `creditnote.bo.default-twig`, its catalogs moved to `I18n/backOffice/default-twig/`; the side menu reads "Avoirs" again in French. A shop that overrode one of these labels in `local/I18n` with a `creditnote.bo.default.` key renames it.
- A credit note has a language (`lang_id`), chosen in the back-office modal: the language of its order by default, of its customer without an order, the default language of the shop otherwise. It stays editable once the credit note is numbered, since it only changes the printed document. The document is printed in it (still within `document_locales`). The update fills the existing credit notes with the language they were printed in: the one of their customer, of their order when the customer has none.
- The colors of the status and type badges are written into `style` attributes only when they are hexadecimal colors, grey otherwise.
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>4.3.1</version>
<version>4.4.0</version>
<author>
<name>Gilles Bourgeat</name>
<email>gbourgeat@openstudio.fr</email>
Expand Down
60 changes: 18 additions & 42 deletions Controller/CreditNoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
use CreditNote\Form\CreditNoteSearchForm;
use CreditNote\Helper\CreditNoteHelper;
use CreditNote\Helper\CriteriaSearchHelper;
use CreditNote\Service\CreditNoteHookPresenter;
use CreditNote\Service\CreditNoteListFilterPresenter;
use CreditNote\Service\CreditNoteListFilters;
use CreditNote\Service\CreditNoteListReader;
use CreditNote\Service\CreditNoteListRowPresenter;
use CreditNote\Service\CreditNoteLanguage;
use CreditNote\Service\CreditNoteModalPresenter;
use CreditNote\Service\CreditNotePdfRenderer;
Expand Down Expand Up @@ -78,54 +81,27 @@ class CreditNoteController extends BaseAdminController
* @return \Thelia\Core\HttpFoundation\Response
*/
#[Route('/credit-note', name: '_list', methods: 'GET')]
public function listAction(Request $request, ParserContext $parserContext, CreditNoteHookPresenter $presenter)
public function listAction(Request $request, CreditNoteListReader $reader, CreditNoteListRowPresenter $rowPresenter, CreditNoteListFilterPresenter $filterPresenter)
{
if (null !== $response = $this->checkAuth([AdminResources::MODULE], [CreditNoteModule::DOMAIN_MESSAGE], AccessManager::VIEW)) {
return $response;
}

$parserContext->addForm($this->createForm(CreditNoteSearchForm::getName()));

return $this->render('credit-note-list', $this->buildListContext($request, $presenter));
}

/**
* Builds the list-page context (search filters + paginated rows), replacing the Smarty
* {loop type="credit-note"} + pagination plugin the Twig BO does not provide.
*
* @return array<string, mixed>
*/
private function buildListContext(Request $request, CreditNoteHookPresenter $presenter): array
{
$page = max(1, (int) $request->query->get('credit_note_page', 1));
$order = (string) $request->query->get('credit_note_order', 'create-date-reverse');
$statusId = $request->query->get('status_id');
$ref = $request->query->get('ref');
$dateMin = $request->query->get('creditNoteDateMin');
$dateMax = $request->query->get('creditNoteDateMax');
$perPage = (int) ConfigQuery::read('number_default_results_per_page.credit_note_list', 20);

$list = $presenter->listRows(
$request->getLocale(),
$page,
$perPage,
$order,
null !== $statusId && '' !== $statusId ? (int) $statusId : null,
$ref !== null && $ref !== '' ? (string) $ref : null,
$dateMin !== null && $dateMin !== '' ? (string) $dateMin : null,
$dateMax !== null && $dateMax !== '' ? (string) $dateMax : null,
$locale = $request->getLocale();
$filters = CreditNoteListFilters::fromRequest($request);
$list = $reader->page(
$filters,
CreditNoteListFilters::pageFromRequest($request),
(int) ConfigQuery::read('number_default_results_per_page.credit_note_list', 20),
);

return [
'credit_notes' => $list['rows'],
'current_page' => $page,
'page_count' => $list['page_count'],
'credit_note_order' => $order,
'filter_ref' => $ref,
'filter_status_id' => $statusId,
'filter_date_min' => $dateMin,
'filter_date_max' => $dateMax,
];
return $this->render('credit-note-list', [
'rows' => $rowPresenter->presentAll($list['rows'], $locale),
'current_page' => $list['current_page'],
'pages' => $list['last_page'],
'filters' => $filterPresenter->present($filters, $locale),
'query_params' => $filters->toQueryParams(),
]);
}

#[Route('/module/credit-note/config', name: '_config_save', methods: 'POST')]
Expand Down
17 changes: 17 additions & 0 deletions I18n/backOffice/default-twig/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
return [
'#' => '#',
'Action' => 'Action',
'Actions' => 'Actions',
'Active filters:' => 'Active filters:',
'Add a free amount' => 'Add a free amount',
'Add a new credit note' => 'Add a new credit note',
'Address :' => 'Address:',
'Address complement :' => 'Address complement:',
'Advanced filters' => 'Advanced filters',
'All Credit Notes' => 'All credit notes',
'Amount with tax' => 'Amount with tax',
'Amount with tax %currency' => 'Amount with tax %currency',
'Amount without tax' => 'Amount without tax',
'Amount without tax %currency' => 'Amount without tax %currency',
'An error has occurred !!!' => 'An error has occurred.',
'An order is required for this credit note type.' => 'An order is required for this credit note type.',
'Apply' => 'Apply',
'Cancel' => 'Cancel',
'City :' => 'City:',
'Clean selection' => 'Clear the fields',
'Clear all' => 'Clear all',
'Close' => 'Close',
'Company :' => 'Company:',
'Country :' => 'Country:',
Expand All @@ -33,12 +38,14 @@
'Credit note for this order' => 'Credit note for this order',
'Credit Note Informations :' => 'Credit note information:',
'Credit Note ref' => 'Credit note ref',
'Credit note pagination' => 'Credit note pagination',
'Credit note ref :' => 'Credit note ref:',
'Credit Note reference' => 'Credit note reference',
'Credit Note used :' => 'Credit note used:',
'Credit note used :' => 'Credit note used:',
'Credit notes' => 'Credit notes',
'Credit Notes' => 'Credit notes',
'Credit notes management' => 'Credit notes management',
'Customer' => 'Customer',
'Customer :' => 'Customer:',
'Delete' => 'Delete',
Expand All @@ -53,17 +60,22 @@
'Free amount :' => 'Free amount:',
'From' => 'From',
'Internal comment :' => 'Internal comment:',
'Inv. ref' => 'Invoice ref',
'Invoice address' => 'Invoice address',
'Invoice date' => 'Invoice date',
'Invoice date between' => 'Invoice date between',
'Invoice ref' => 'Invoice ref',
'Invoice ref :' => 'Invoice ref:',
'Language :' => 'Language:',
'Lastname :' => 'Last name:',
'Max' => 'Max',
'Message content : ' => 'Message:',
'Message sent to the customer when a credit note is created from an order.' => 'Message sent to the customer when a credit note is created from an order.',
'Message status : ' => 'Status:',
'Min' => 'Min',
'No' => 'No',
'No comments found for this credit note' => 'No comment found for this credit note',
'No credit note matches the current filters.' => 'No credit note matches the current filters.',
'No free amount.' => 'No free amount.',
'No results found' => 'No result found',
'Order' => 'Order',
Expand All @@ -79,7 +91,11 @@
'Quantity' => 'Quantity',
'Ref' => 'Ref',
'Ref :' => 'Ref:',
'Reference' => 'Reference',
'Reference, number, order, customer name or email' => 'Reference, number, order, customer name or email',
'Remaining to pay :' => 'Remaining to pay:',
'Remove this filter' => 'Remove this filter',
'Reset' => 'Reset',
'Save' => 'Save',
'Search' => 'Search',
'Search...' => 'Search…',
Expand All @@ -95,6 +111,7 @@
'Title' => 'Title',
'To' => 'To',
'Total' => 'Total',
'Total amount (TTC)' => 'Total amount (TTC)',
'Total credit notes amount' => 'Total credit notes amount',
'Total including discount' => 'Total including discount',
'Total with tax' => 'Total with tax',
Expand Down
17 changes: 17 additions & 0 deletions I18n/backOffice/default-twig/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@
return [
'#' => '#',
'Action' => 'Action',
'Actions' => 'Actions',
'Active filters:' => 'Filtres actifs :',
'Add a free amount' => 'Ajouter un montant libre',
'Add a new credit note' => 'Ajouter un nouvel avoir',
'Address :' => 'Adresse :',
'Address : ' => 'Adresse :',
'Address complement :' => 'Complément d\'adresse :',
'Address complement : ' => 'Complément d\'adresse :',
'Advanced filters' => 'Filtres avancés',
'All Credit Notes' => 'Tous les avoirs',
'Amount with tax' => 'Montant TTC',
'Amount with tax %currency' => 'Montant TTC %currency',
'Amount without tax' => 'Montant HT',
'Amount without tax %currency' => 'Montant HT %currency',
'An error has occurred !!!' => 'Une erreur est survenue',
'An order is required for this credit note type.' => 'Une commande est obligatoire pour ce type d\'avoir.',
'Apply' => 'Appliquer',
'Cancel' => 'Annuler',
'City :' => 'Ville :',
'City : ' => 'Ville :',
'Clean selection' => 'Réinitialiser les champs',
'Clear all' => 'Tout effacer',
'Close' => 'Fermer',
'Combination reference' => 'Référence déclinaison',
'Company :' => 'Société :',
Expand All @@ -37,6 +42,7 @@
'Credit Note Informations :' => 'Informations sur l\'avoir :',
'Credit Note Informations : ' => 'Informations avoir',
'Credit Note ref' => 'Avoir ref',
'Credit note pagination' => 'Pagination des avoirs',
'Credit note ref :' => 'Référence de l\'avoir :',
'Credit note ref : <strong>%ref</strong>' => 'Référence avoir : <strong>%ref</strong>',
'Credit Note reference' => 'Numéro d\'avoir',
Expand All @@ -46,6 +52,7 @@
'Credit note versions : ' => 'Versions de l\'avoir',
'Credit Notes' => 'Avoirs',
'Credit notes' => 'Avoirs',
'Credit notes management' => 'Gestion des avoirs',
'Customer' => 'Client',
'Customer :' => 'Client :',
'Customer : ' => 'Client :',
Expand All @@ -66,18 +73,23 @@
'Home' => 'Accueil',
'Internal comment :' => 'Commentaire interne :',
'Internal comment : ' => 'Commentaire interne',
'Inv. ref' => 'Ref facture',
'Invoice address' => 'Adresse de facturation',
'Invoice date' => 'Date facture',
'Invoice date between' => 'Date de l\'avoir entre',
'Invoice ref' => 'Référence facture',
'Invoice ref :' => 'Référence facture :',
'Invoice ref : <strong>%ref</strong>' => 'Référence facture : <strong>%ref</strong>',
'Language :' => 'Langue :',
'Lastname :' => 'Nom :',
'Lastname : ' => 'Nom :',
'Max' => 'Max',
'Message content : ' => 'Message :',
'Message status : ' => 'Statut :',
'Min' => 'Min',
'No' => 'Non',
'No comments found for this credit note' => 'Aucun commentaire trouvé pour cet avoir',
'No credit note matches the current filters.' => 'Aucun avoir ne correspond aux filtres.',
'No free amount.' => 'Aucun montant libre',
'No results found' => 'Aucun résultat',
'No version found for this credit note' => 'Aucune version trouvée pour cet avoir',
Expand All @@ -97,8 +109,12 @@
'Quantity' => 'Quantité',
'Ref' => 'Ref',
'Ref :' => 'Ref :',
'Reference' => 'Référence',
'Reference, number, order, customer name or email' => 'Référence, numéro, commande, nom ou e-mail du client',
'Remaining to pay :' => 'Reste à payer :',
'Remaining to pay : ' => 'Reste à payer',
'Remove this filter' => 'Retirer ce filtre',
'Reset' => 'Réinitialiser',
'Save' => 'Enregistrer',
'Search' => 'Rechercher',
'Search...' => 'Rechercher ...',
Expand All @@ -119,6 +135,7 @@
'Title' => 'Titre',
'To' => 'Jusqu\'au',
'Total' => 'Total',
'Total amount (TTC)' => 'Montant total (TTC)',
'Total including discount' => 'Total avec réduction',
'Total with tax' => 'Total TTC',
'Total with tax :' => 'Total TTC :',
Expand Down
13 changes: 13 additions & 0 deletions I18n/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@
'The credit notes on order %order% cannot exceed its total (%ceiling%): %granted% already granted, %amount% asked.' => 'The credit notes on order %order% cannot exceed its total (%ceiling%): %granted% already granted, %amount% asked.',
'Languages of the credit note document (locales separated by commas, en_US,fr_FR when empty)' => 'Languages of the credit note document (locales separated by commas, en_US,fr_FR when empty)',
'Enter locales such as fr_FR, separated by commas' => 'Enter locales such as fr_FR, separated by commas',
'Not numbered yet' => 'Not numbered yet',
'%amount% excl. tax' => '%amount% excl. tax',
'Just now' => 'Just now',
'%count% min ago' => '%count% min ago',
'%count% h ago' => '%count% h ago',
'%count% d ago' => '%count% d ago',
'Status' => 'Status',
'Type' => 'Type',
'Invoice date' => 'Invoice date',
'Amount' => 'Amount',
'Search' => 'Search',
'from %value%' => 'from %value%',
'up to %value%' => 'up to %value%',
];
13 changes: 13 additions & 0 deletions I18n/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,17 @@
'The credit notes on order %order% cannot exceed its total (%ceiling%): %granted% already granted, %amount% asked.' => 'Les avoirs de la commande %order% ne peuvent pas dépasser son total (%ceiling%) : %granted% déjà accordés, %amount% demandés.',
'Languages of the credit note document (locales separated by commas, en_US,fr_FR when empty)' => 'Langues du document d\'avoir (locales séparées par des virgules, en_US,fr_FR si vide)',
'Enter locales such as fr_FR, separated by commas' => 'Saisir des locales comme fr_FR, séparées par des virgules',
'Not numbered yet' => 'Pas encore numéroté',
'%amount% excl. tax' => '%amount% HT',
'Just now' => 'À l\'instant',
'%count% min ago' => 'il y a %count% min',
'%count% h ago' => 'il y a %count% h',
'%count% d ago' => 'il y a %count% j',
'Status' => 'Statut',
'Type' => 'Type',
'Invoice date' => 'Date de l\'avoir',
'Amount' => 'Montant',
'Search' => 'Rechercher',
'from %value%' => 'à partir de %value%',
'up to %value%' => 'jusqu\'à %value%',
];
48 changes: 0 additions & 48 deletions Service/CreditNoteHookPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,54 +64,6 @@ public function tableRows(?int $customerId, ?int $orderId, string $locale): arra
return $rows;
}

/**
* Paginated rows + page count for the credit-note list page (replaces the Smarty
* {loop type="credit-note"} + pagination plugin, which the Twig BO does not provide).
*
* @return array{rows: array<int, array<string, mixed>>, page_count: int}
*/
public function listRows(
string $locale,
int $page,
int $perPage,
string $order,
?int $statusId,
?string $ref,
?string $dateMin,
?string $dateMax,
): array {
$query = CreditNoteQuery::create();

if (null !== $statusId) {
$query->filterByStatusId($statusId);
}
if (null !== $ref && '' !== $ref) {
$query->filterByRef('%'.$ref.'%', Criteria::LIKE);
}
if (null !== $dateMin && '' !== $dateMin) {
$query->filterByInvoiceDate(new \DateTime($dateMin), Criteria::GREATER_EQUAL);
}
if (null !== $dateMax && '' !== $dateMax) {
$query->filterByInvoiceDate((new \DateTime($dateMax))->setTime(23, 59, 59), Criteria::LESS_EQUAL);
}

match ($order) {
'create-date' => $query->orderByCreatedAt(Criteria::ASC),
'update-date' => $query->orderByUpdatedAt(Criteria::ASC),
'update-date-reverse' => $query->orderByUpdatedAt(Criteria::DESC),
default => $query->orderByCreatedAt(Criteria::DESC),
};

$pager = $query->paginate($page, max(1, $perPage));

$rows = [];
foreach ($pager as $creditNote) {
$rows[] = $this->row($creditNote, $locale);
}

return ['rows' => $rows, 'page_count' => $pager->getLastPage()];
}

/**
* @return array<string, mixed>
*/
Expand Down
Loading
Loading