Skip to content

Commit

Permalink
Merge branch 'release/2.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Apr 16, 2024
2 parents 401be30 + 4f363ef commit d5a5bac
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 132 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,6 @@ jobs:
- name: Validate Doctrine schema
run: APP_ENV=prod php bin/console doctrine:schema:validate


validate-publiccode:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Validate publiccode.yml
# https://github.com/italia/publiccode-parser-go#easy-validation-with-docker
run: docker run --interactive italia/publiccode-parser-go /dev/stdin < publiccode.yml

assets-coding-standards:
name: Assets coding standards
runs-on: ubuntu-latest
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.2] - 2024-04-16

* [PR-104](https://github.com/itk-dev/economics/pull/104)
1174: Fixed datetime format in Leantime API calls
* [PR-103](https://github.com/itk-dev/economics/pull/103)
1169: Made sure that Leantime issues have at most one version (milestone)
* [PR-102](https://github.com/itk-dev/economics/pull/102)
1157: Updated external billing export

## [2.1.1] - 2024-04-04

* [PR-100](https://github.com/itk-dev/economics/pull/100)
Expand Down Expand Up @@ -210,7 +219,8 @@ complete process.
* Updated to authorization code flow.
* Changed worklog save button styling to be sticky.

[Unreleased]: https://github.com/itk-dev/economics/compare/2.1.1...HEAD
[Unreleased]: https://github.com/itk-dev/economics/compare/2.1.2...HEAD
[2.1.2]: https://github.com/itk-dev/economics/compare/2.1.1...2.1.2
[2.1.1]: https://github.com/itk-dev/economics/compare/2.1.0...2.1.1
[2.1.0]: https://github.com/itk-dev/economics/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/itk-dev/economics/compare/1.1.2...2.0.0
Expand Down
74 changes: 0 additions & 74 deletions publiccode.yml

This file was deleted.

33 changes: 20 additions & 13 deletions src/Controller/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,26 @@ public function include(Request $request, Project $project, ProjectRepository $p
#[Route('/{id}/sync', name: 'app_project_sync', methods: ['POST'])]
public function sync(Project $project, DataSynchronizationService $dataSynchronizationService): Response
{
$projectId = $project->getId();

if (null == $projectId) {
return new Response('Not found', 404);
try {
$projectId = $project->getId();

if (null == $projectId) {
return new Response('Not found', 404);
}

$dataProvider = $project->getDataProvider();

if (null != $dataProvider) {
$dataSynchronizationService->syncIssuesForProject($projectId, null, $dataProvider);
$dataSynchronizationService->syncWorklogsForProject($projectId, null, $dataProvider);
}

return new JsonResponse([], 200);
} catch (\Throwable $exception) {
return new JsonResponse(
['message' => $exception->getMessage()],
(int) ($exception->getCode() > 0 ? $exception->getCode() : 500)
);
}

$dataProvider = $project->getDataProvider();

if (null != $dataProvider) {
$dataSynchronizationService->syncIssuesForProject($projectId, null, $dataProvider);
$dataSynchronizationService->syncWorklogsForProject($projectId, null, $dataProvider);
}

return new JsonResponse([], 200);
}
}
63 changes: 33 additions & 30 deletions src/Service/BillingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Exception\InvoiceAlreadyOnRecordException;
use App\Repository\InvoiceEntryRepository;
use App\Repository\InvoiceRepository;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Csv;
Expand Down Expand Up @@ -241,6 +242,10 @@ public function exportInvoicesToSpreadsheet(array $invoiceIds): Spreadsheet

$row = 1;

// Convenience helper to set a cell value.
$setCellValue = static fn (int|string $col, int $row, mixed $value) => $sheet->setCellValue((is_string($col) ? $col : Coordinate::stringFromColumnIndex($col)).$row, $value);
$formatDate = static fn (?\DateTimeInterface $date) => null !== $date ? $date->format('d.m.Y') : '';

foreach ($invoiceIds as $invoiceId) {
$invoice = $this->invoiceRepository->findOneBy(['id' => $invoiceId]);

Expand Down Expand Up @@ -268,58 +273,56 @@ public function exportInvoicesToSpreadsheet(array $invoiceIds): Spreadsheet
}

$today = new \DateTime();
$todayString = $today->format('d.m.Y');

$paymentDate = $this->getPaymentDate($today);
$paymentDateString = $paymentDate->format('d.m.Y');

// Generate header line (H).
// 1. "Linietype"
$sheet->setCellValue([1, $row], 'H');
$setCellValue(1, $row, 'H');
// 2. "Ordregiver/Bestiller"
$sheet->setCellValue([2, $row], str_pad($customerKey ?? '', 10, '0', \STR_PAD_LEFT));
$setCellValue(2, $row, str_pad($customerKey ?? '', 10, '0', \STR_PAD_LEFT));
// 4. "Fakturadato"
$recordedDate = $invoice->getRecordedDate();
$sheet->setCellValue([4, $row], null !== $recordedDate ? $recordedDate->format('d.m.Y') : '');
$setCellValue(4, $row, $formatDate($recordedDate));
// 5. "Bilagsdato"
$sheet->setCellValue([5, $row], $todayString);
$setCellValue(5, $row, $formatDate($today));
// 6. "Salgsorganisation"
$sheet->setCellValue([6, $row], '0020');
$setCellValue(6, $row, '0020');
// 7. "Salgskanal"
$sheet->setCellValue([7, $row], $internal ? 10 : 20);
$setCellValue(7, $row, $internal ? 10 : 20);
// 8. "Division"
$sheet->setCellValue([8, $row], '20');
$setCellValue(8, $row, '20');
// 9. "Ordreart"
$sheet->setCellValue([9, $row], $internal ? 'ZIRA' : 'ZRA');
$setCellValue(9, $row, $internal ? 'ZIRA' : 'ZRA');
// 15. "Kunderef.ID"
$sheet->setCellValue([15, $row], substr('Att: '.$contactName, 0, 35));
$setCellValue(15, $row, substr('Att: '.$contactName, 0, 35));
// 16. "Toptekst, yderligere spec i det hvide felt på fakturaen"
$description = $invoice->getDescription() ?? '';
$sheet->setCellValue([16, $row], substr($description, 0, 500));
$setCellValue(16, $row, substr($description, 0, 500));
// 17. "Leverandør"
if ($internal) {
$sheet->setCellValue([17, $row], str_pad($this->invoiceSupplierAccount, 10, '0', \STR_PAD_LEFT));
$setCellValue(17, $row, str_pad($this->invoiceSupplierAccount, 10, '0', \STR_PAD_LEFT));
}
// 18. "EAN nr."
if (!$internal && 13 === \strlen($ean ?? '')) {
$sheet->setCellValue([18, $row], $ean);
$setCellValue(18, $row, $ean);
}

// External invoices.
if (!$internal) {
// 38. Stiftelsesdato
$sheet->setCellValue([24, $row], $invoice->getCreatedAt()?->format('d.m.Y'));
// 39. Periode fra - Same value as in 38 (!)
$sheet->setCellValue([25, $row], $sheet->getCell([24, $row])->getValue());
// 40. Periode fra
$setCellValue(24, $row, $formatDate($invoice->getCreatedAt()));
// 39. Periode fra
$periodFrom = $invoice->getPeriodFrom();
$sheet->setCellValue([26, $row], null !== $periodFrom ? $periodFrom->format('d.m.Y') : '');
$setCellValue('Y', $row, $formatDate($periodFrom));
// 40. Periode til
$periodTo = $invoice->getPeriodTo();
$setCellValue('Z', $row, $formatDate($periodTo));
// 46. Fordringstype oprettelse/valg : KOCIVIL
$sheet->setCellValue([32, $row], 'KOCIVIL');
$setCellValue(32, $row, 'KOCIVIL');
// 49. Forfaldsdato: dagsdato - Same value as 38 (!)
$sheet->setCellValue([35, $row], $sheet->getCell([24, $row])->getValue());
$setCellValue(35, $row, $sheet->getCell([24, $row])->getValue());
// 50. Henstand til: dagsdato + 30 dage. NB det må ikke være før faktura forfald. Skal være en bank dag.
$sheet->setCellValue([36, $row], $paymentDateString);
$setCellValue(36, $row, $formatDate($paymentDate));
}

++$row;
Expand All @@ -338,19 +341,19 @@ public function exportInvoicesToSpreadsheet(array $invoiceIds): Spreadsheet

// Generate invoice lines (L).
// 1. "Linietype"
$sheet->setCellValue([1, $row], 'L');
$setCellValue(1, $row, 'L');
// 2. "Materiale (vare)nr.
$sheet->setCellValue([2, $row], str_pad($materialNumber->value, 18, '0', \STR_PAD_LEFT));
$setCellValue(2, $row, str_pad($materialNumber->value, 18, '0', \STR_PAD_LEFT));
// 3. "Beskrivelse"
$sheet->setCellValue([3, $row], substr($product, 0, 40));
$setCellValue(3, $row, substr($product, 0, 40));
// 4. "Ordremængde"
$sheet->setCellValue([4, $row], number_format($amount, 3, ',', ''));
$setCellValue(4, $row, number_format($amount, 3, ',', ''));
// 5. "Beløb pr. enhed"
$sheet->setCellValue([5, $row], number_format($price, 2, ',', ''));
$setCellValue(5, $row, number_format($price, 2, ',', ''));
// 6. "Priser fra SAP"
$sheet->setCellValue([6, $row], 'NEJ');
$setCellValue(6, $row, 'NEJ');
// 7. "PSP-element nr."
$sheet->setCellValue([7, $row], $account);
$setCellValue(7, $row, $account);

++$row;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Service/DataSynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public function syncIssuesForProject(int $projectId, callable $progressCallback
$issue->setResolutionDate($issueDatum->resolutionDate);
$issue->setStatus($issueDatum->status);

// Leantime (as of now) supports only a single version (milestone) per issue.
if (LeantimeApiService::class === $dataProvider?->getClass()) {
$issue->getVersions()->clear();
}

foreach ($issueDatum->versions as $versionData) {
$version = $this->versionRepository->findOneBy(['projectTrackerId' => $versionData->projectTrackerId]);

Expand All @@ -245,7 +250,7 @@ public function syncIssuesForProject(int $projectId, callable $progressCallback
}
}

$startAt += self::MAX_RESULTS;
$startAt += $pagedIssueData->maxResults;

$this->entityManager->flush();
$this->entityManager->clear();
Expand Down
9 changes: 7 additions & 2 deletions src/Service/LeantimeApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,10 @@ public function getTimesheetsForTicket(string $ticketId): mixed
private function getTimesheets(array $params): mixed
{
return $this->request(self::API_PATH_JSONRPC, 'POST', 'leantime.rpc.timesheets.getAll', $params + [
'dateFrom' => '2000-01-01',
'dateTo' => '3000-01-01',
// The datatime format must match the internal Leantime date format
// (cf. https://github.com/Leantime/leantime/blob/master/app/Core/Support/DateTimeHelper.php#L53)
'dateFrom' => '2000-01-01 00:00:00',
'dateTo' => '3000-01-01 00:00:00',
'invEmpl' => '-1',
'invComp' => '-1',
'paid' => '-1',
Expand Down Expand Up @@ -938,6 +940,9 @@ private function request(string $path, string $type, string $method, array $para

if (isset($data->error)) {
$message = $data->error->message;
if (isset($data->error->data)) {
$message .= ': '.(is_scalar($data->error->data) ? $data->error->data : json_encode($data->error->data));
}
throw new ApiServiceException($message, $data->error->code);
}

Expand Down

0 comments on commit d5a5bac

Please sign in to comment.