Skip to content

Commit 374c2c3

Browse files
committed
Initial Support for FlexiBee custom reports
1 parent 394c6b4 commit 374c2c3

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

src/FlexiPeeHP/Report.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* FlexiPeeHP - Custom Report object.
5+
*
6+
* @author Vítězslav Dvořák <[email protected]>
7+
* @copyright (C) 2020 Spoje.Net
8+
*/
9+
10+
namespace FlexiPeeHP;
11+
12+
/**
13+
* Description of Report
14+
*
15+
* @author vitex
16+
*/
17+
class Report extends FlexiBeeRW {
18+
19+
/**
20+
* Evidence užitá objektem.
21+
* Evidence used by object.
22+
*
23+
* @var string
24+
*/
25+
public $evidence = 'report';
26+
27+
/**
28+
* Načte záznam z FlexiBee a uloží v sobě jeho data
29+
* Read FlexiBee record and store it inside od object
30+
*
31+
* @param int|string $id ID or conditions
32+
*
33+
* @return int počet načtených položek
34+
*/
35+
public function loadFromFlexiBee($id = null) {
36+
if (strstr($id, 'code:')) { //Dirty Hack ⚠ Error 400: Entita 'Report' neobsahuje kód nebo ho nelze použít jako ID (není unikátní)
37+
$candidates = $this->getColumnsFromFlexibee(['id', 'kod'], null, 'kod');
38+
if (array_key_exists(\FlexiPeeHP\FlexiBeeRO::uncode($id), $candidates)) {
39+
$id = intval($candidates[\FlexiPeeHP\FlexiBeeRO::uncode($id)]['id']);
40+
}
41+
}
42+
return parent::loadFromFlexiBee($id);
43+
}
44+
45+
/**
46+
* Update $this->apiURL
47+
*/
48+
public function updateApiURL() {
49+
$code = $this->getDataValue('kod');
50+
$this->unsetDataValue('kod');
51+
$result = parent::updateApiURL();
52+
$this->setDataValue('kod',$code);
53+
return $result;
54+
}
55+
56+
}

src/ReportUpdater.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* FlexiPeeHP - Example how to upload new version of custom Report
4+
*
5+
* @author Vítězslav Dvořák <[email protected]>
6+
* @copyright (G) 2020 Vitex Software
7+
*/
8+
9+
namespace Example\FlexiPeeHP;
10+
11+
include_once './config.php';
12+
include_once '../vendor/autoload.php';
13+
14+
15+
define('EASE_APPNAME', 'ReportUploader');
16+
define('EASE_LOGGER', 'syslog|console');
17+
18+
if ($argc < 3) {
19+
echo "usage: " . $argv[0] . " <recordIdent> <formInfoCode> <reportfile> \n";
20+
echo "example: " . $argv[0] . " code:PokladDen pokDenik WinstromReports/vykazAnalyzaZakazky/analyzaZakazky.jrxml \n";
21+
} else {
22+
$reportID = $argv[1];
23+
24+
if ($argc == 3) {
25+
if (is_file($argv[2])) {
26+
$reportFile = $argv[2];
27+
} else {
28+
$formCode = $argv[2];
29+
$reportFile = $argv[3];
30+
}
31+
}
32+
33+
if (strstr($reportFile, '.jrxml')) {
34+
system('jaspercompiler ' . $reportFile); // https://github.com/VitexSoftware/jaspercompiler
35+
$reportFile = str_replace('.jrxml', '.jasper', $reportFile);
36+
}
37+
38+
39+
if (file_exists($reportFile)) {
40+
41+
$reporter = new \FlexiPeeHP\Report($reportID);
42+
$oldReportId = intval($reporter->getDataValue('hlavniReport'));
43+
$attachment = \FlexiPeeHP\Priloha::addAttachmentFromFile($reporter, $reportFile);
44+
if ($reporter->sync(['hlavniReport' => $attachment->getRecordID(), 'id' => $reporter->getRecordID()])) {
45+
if ($oldReportId) {
46+
$attachment->deleteFromFlexiBee($oldReportId);
47+
}
48+
$reporter->addStatusMessage(_('Report updated'), 'success');
49+
}
50+
}
51+
}
52+
53+

0 commit comments

Comments
 (0)