Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/je 403 sync project lead #51

Merged
merged 11 commits into from
Jan 3, 2024
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ API_SERVICE_SPRINT_NAME_REGEX="/(?<weeks>(?:-?\d+-?)*)\.(?<year>\d+)$/"
APP_WEEK_GOAL_LOW=25.0
APP_WEEK_GOAL_HIGH=34.5
APP_INVOICE_RECEIVER_ACCOUNT=APP_INVOICE_RECEIVER_ACCOUNT
APP_INVOICE_DEFAULT_DESCRIPTION=APP_INVOICE_DEFAULT_DESCRIPTION
APP_INVOICE_DEFAULT_DESCRIPTION="Spørgsmål vedrørende fakturaen rettes til %name%, %email%."
###< Planning ###

###> itk-dev/openid-connect-bundle ###
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Added project lead to client when syncing projects.
* Remove description from create invoice page.
* Added generate description button to invoice when client is set.
* Fixed texts.
* Fixed classes for choices.js fields and disabled state.

## [1.1.2]

* Changed how project billing is put on record, to allow for finishing a partially
Expand Down
6 changes: 5 additions & 1 deletion assets/controllers/choices_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export default class extends Controller {

connect() {
this.choicesTargets.forEach((target) => {
new Choices(target, {allowHTML: true, itemSelectText: ''});
const notDisabled = !target.disabled;

if (notDisabled) {
new Choices(target, {allowHTML: true, itemSelectText: ''});
}
})
}
}
33 changes: 33 additions & 0 deletions assets/controllers/generate-description_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Controller} from '@hotwired/stimulus';

export default class extends Controller {
static targets = ['description'];

endpoint;

connect() {
this.endpoint = this.element.dataset.endpoint;
}

generate() {
fetch(this.endpoint, {
method: 'GET',
mode: 'same-origin',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
}).then(async (resp) => {
if (resp.ok) {
const target = this.descriptionTarget;

resp.json().then((data) => {
target.value = data.description;
});
}
});
}
}
2 changes: 1 addition & 1 deletion config/packages/monolog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ when@dev:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
channels: ["!event", "!doctrine", "!deprecation"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
Expand Down
4 changes: 3 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ imports:
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
app.default_invoice_description: '%env(APP_INVOICE_DEFAULT_DESCRIPTION)%'
app.jira_custom_fields:
'Epic Link': '%env(JIRA_API_SERVICE_CUSTOM_FIELD_EPIC_LINK)%'
'Account': '%env(JIRA_API_SERVICE_CUSTOM_FIELD_ACCOUNT)%'
Expand All @@ -19,6 +18,9 @@ services:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

bind:
$defaultInvoiceDescriptionTemplate: '%env(APP_INVOICE_DEFAULT_DESCRIPTION)%'

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
Expand Down
31 changes: 31 additions & 0 deletions migrations/Version20231219130737.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231219130737 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE client ADD project_lead_name VARCHAR(255) DEFAULT NULL, ADD project_lead_mail VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE client DROP project_lead_name, DROP project_lead_mail');
}
}
25 changes: 24 additions & 1 deletion src/Controller/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PhpOffice\PhpSpreadsheet\Writer\Csv;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
Expand Down Expand Up @@ -132,7 +133,7 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo
$form->add('client', null, [
'label' => 'invoices.client',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
Expand Down Expand Up @@ -170,6 +171,28 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo
]);
}

#[Route('/{id}/generate-description', name: 'app_invoices_generate_description', methods: ['GET'])]
public function generateDescription(Invoice $invoice, $defaultInvoiceDescriptionTemplate): JsonResponse
{
$description = $defaultInvoiceDescriptionTemplate;

// Default description.
if (!empty($invoice->getClient())) {
$projectLeadName = $invoice->getClient()?->getProjectLeadName() ?? null;
$projectLeadMail = $invoice->getClient()?->getProjectLeadMail() ?? null;
tuj marked this conversation as resolved.
Show resolved Hide resolved

if ($projectLeadName) {
$description = str_replace('%name%', $projectLeadName, $description);
}

if ($projectLeadMail) {
$description = str_replace('%email%', $projectLeadMail, $description);
}
}

return new JsonResponse(['description' => $description]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$description may equal "Spørgsmål vedrørende fakturaen rettes til %name%, %email%." here, so it may be a better idea to reply with {"description": null} if name and email cannot be found.

}

#[Route('/{id}', name: 'app_invoices_delete', methods: ['POST'])]
public function delete(Request $request, Invoice $invoice, InvoiceRepository $invoiceRepository): Response
{
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/InvoiceEntryWorklogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function worklogs(Request $request, Invoice $invoice, InvoiceEntry $invoi
'required' => false,
'label' => 'worklog.version',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
Expand All @@ -69,7 +69,7 @@ public function worklogs(Request $request, Invoice $invoice, InvoiceEntry $invoi
'required' => false,
'label' => 'worklog.epic',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
Expand Down
30 changes: 30 additions & 0 deletions src/Entity/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class Client
#[ORM\Column(length: 255, nullable: true)]
private ?string $customerKey = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $projectLeadName = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $projectLeadMail = null;

public function __construct()
{
$this->invoices = new ArrayCollection();
Expand Down Expand Up @@ -243,4 +249,28 @@ public function setCustomerKey(?string $customerKey): self

return $this;
}

public function getProjectLeadName(): ?string
{
return $this->projectLeadName;
}

public function setProjectLeadName(?string $projectLeadName): static
{
$this->projectLeadName = $projectLeadName;

return $this;
}

public function getProjectLeadMail(): ?string
{
return $this->projectLeadMail;
}

public function setProjectLeadMail(?string $projectLeadMail): static
{
$this->projectLeadMail = $projectLeadMail;

return $this;
}
}
5 changes: 0 additions & 5 deletions src/Form/InvoiceNewType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Entity\Invoice;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand All @@ -18,10 +17,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'required' => true,
'attr' => ['class' => 'form-element'],
])
->add('description', TextareaType::class, [
'required' => true,
'attr' => ['class' => 'form-element', 'rows' => 4],
])
->add('project', null, [
'required' => true,
'query_builder' => function (EntityRepository $er) {
Expand Down
6 changes: 3 additions & 3 deletions src/Form/InvoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'help' => 'invoices.name_helptext',
])
->add('description', TextareaType::class, [
'required' => true,
'required' => false,
'label' => 'invoices.description',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'attr' => ['class' => 'form-element', 'rows' => 4],
'attr' => ['class' => 'form-element', 'data-generate-description-target' => 'description', 'rows' => 4],
'help' => 'invoices.description_helptext',
])
->add('client', null, [
'label' => 'invoices.client',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => ['class' => 'form-element'],
'help' => 'invoices.client_helptext',
])
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Invoices/ClientData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ class ClientData
public ?string $psp = null;
public ?string $ean = null;
public ?string $salesChannel = null;
public ?string $projectLeadName = null;
public ?string $projectLeadMail = null;
}
2 changes: 2 additions & 0 deletions src/Service/BillingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ public function syncProjects(callable $progressCallback): void
$client->setStandardPrice($clientData->standardPrice);
$client->setCustomerKey($clientData->customerKey);
$client->setSalesChannel($clientData->salesChannel);
$client->setProjectLeadName($clientData->projectLeadName);
$client->setProjectLeadMail($clientData->projectLeadMail);

if (!$client->getProjects()->contains($client)) {
$client->addProject($project);
Expand Down
2 changes: 2 additions & 0 deletions src/Service/JiraApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@ public function getClientDataForProject(string $projectId): array
$client->account = $account->key ?? null;
$client->customerKey = $account->customer->key ?? null;
$client->salesChannel = $account->category->key ?? null;
$client->projectLeadName = $account->lead->displayName ?? null;
$client->projectLeadMail = $account->lead->emailAddress ?? null;

switch ($account->category->name ?? null) {
case 'INTERN':
Expand Down
7 changes: 6 additions & 1 deletion templates/invoices/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
<div class="grid-split selections" {{ stimulus_controller('choices') }}>
<div>
{{ form_row(form.name) }}
{{ form_row(form.description) }}
<div {{ stimulus_controller('generate-description') }} data-endpoint="{{ path('app_invoices_generate_description', {'id': invoice.id}) }}">
{% if invoice.client %}
<button type="button" class="link" style="font-size: .8em; float: right" {{ stimulus_action('generate-description', 'generate') }}>{{ 'invoices.generate_description'|trans }}</button>
{% endif %}
{{ form_row(form.description) }}
</div>
{{ form_row(form.client) }}
{{ form_row(form.periodFrom) }}
{{ form_row(form.periodTo) }}
Expand Down
1 change: 0 additions & 1 deletion templates/invoices/new.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
{{ form_start(form) }}
<div class="selections" {{ stimulus_controller('choices') }}>
{{ form_row(form.name) }}
{{ form_row(form.description) }}
{{ form_row(form.project) }}

<button class="button">{{ 'invoices.action_create'|trans }}</button>
Expand Down
4 changes: 3 additions & 1 deletion translations/messages.da.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ invoices:
client_helptext: 'Vælg hvilken kundekonto fakturaen skal udstedes til.'
default_material_number_helptext: 'Vælg forudvalgt "Materialenummer". Det bliver sat automatisk i alle fakturaindgange.'
default_receiver_account_helptext: 'Vælg forudvalgt "Til konto". Det bliver sat automatisk i alle fakturaindgange.'
payer_account_helptext: 'Hvis valgt indsættes følgende først i tekstfeltet i fakturaen: "Betales af [KONTO]".'
payer_account_helptext: 'Anvendes kun når der er tale om ITK projekt posteringer på PSP-element. Hvis valgt indsættes følgende i starten af tekstfeltet i fakturaen: "Betales af [KONTO]".'
tuj marked this conversation as resolved.
Show resolved Hide resolved
client_type_internal: 'Intern'
client_type_external: 'Ekstern'
client_ean: 'EAN'
Expand Down Expand Up @@ -226,6 +226,7 @@ invoices:
action_export_selected: 'Eksporter valg'
action_view: 'Se'
list_exported_date: 'Eksportdato'
generate_description: 'Autoudfyld'

material_number_enum:
internal: "Interne: 103361"
Expand Down Expand Up @@ -268,6 +269,7 @@ worklog:
period_to_helptext: ''
worker_helptext: ''
version_helptext: ''
epic_helptext: ''
owned_by_other: 'Anden faktura'
action_save: 'Gem valgte worklogs'
error_already_billed: 'Fejl: Indeholder worklog der allerede er faktureret. Prøv at genindlæse siden...'
Expand Down
Loading