From 59c2dfbc7bafd35c9a8663d69a9b378d817938b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=C4=9Bzslav=20Dvo=C5=99=C3=A1k?= Date: Mon, 4 Jan 2021 04:11:07 +0100 Subject: [PATCH] v0.1 release --- README.md | 49 ++++++-------- abraflexi-mailer.1 | 79 ---------------------- bin/abraflexi-send | 4 ++ bin/abraflexi-send-unsent | 2 +- bin/abraflexi-send-unsent-with-attachments | 2 +- bin/abraflexi-show-unsent | 4 ++ debian/changelog | 24 +------ debian/install | 4 +- debian/manpages | 3 - debian/postinst | 3 - debian/rules | 13 +--- src/AbraFlexi/Mailer/Mailer.php | 10 ++- src/SendDocument.php | 73 ++++++++++++++++++++ src/SendUnsent.php | 6 +- src/SendUnsentAttachments.php | 4 +- src/ShowUnsent.php | 4 +- 16 files changed, 126 insertions(+), 158 deletions(-) delete mode 100644 abraflexi-mailer.1 create mode 100644 bin/abraflexi-send create mode 100644 bin/abraflexi-show-unsent delete mode 100644 debian/manpages mode change 100644 => 100755 debian/rules create mode 100644 src/SendDocument.php diff --git a/README.md b/README.md index 9712a4e..46d564c 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,12 @@ Debian/Ubuntu Pro Linux jsou k dispozici .deb balíčky. Prosím použijte repo: + ```shell echo "deb http://repo.vitexsoftware.cz $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vitexsoftware.list sudo wget -O /etc/apt/trusted.gpg.d/vitexsoftware.gpg http://repo.vitexsoftware.cz/keyring.gpg sudo apt update sudo apt install abraflexi-mailer +``` Po instalaci balíku jsou v systému k dispozici tyto nové příkazy: @@ -38,30 +40,11 @@ Po instalaci balíku jsou v systému k dispozici tyto nové příkazy: * **abraflexi-send-unsent-attachments** - odešle neodeslané s přílohami * **abraflexi-show-unsent** - vypíše neodeslané doklady -Závislosti ----------- - -Tento nástroj ke svojí funkci využívá následující knihovny: - - * [**EasePHP Framework**](https://github.com/VitexSoftware/php-ease-core) - pomocné funkce např. logování - * [**AbraFlexi**](https://github.com/Spoje-NET/AbraFlexi) - komunikace s [AbraFlexi](https://flexibee.eu/) - * [**AbraFlexi Bricks**](https://github.com/VitexSoftware/AbraFlexi-Bricks) - používají se třídy Zákazníka, Upomínky a Upomínače - - -Testování: ----------- - -K dispozici je základní test funkcionality spustitelný příkazem **make test** ve zdrojové složce projektu - -Pouze testovací faktury a platby se vytvoří příkazem **make pretest** -![Prepare](https://raw.githubusercontent.com/VitexSoftware/php-abraflexi-mailer/master/doc/preparefortesting.png "Preparation") - -Test sestavení balíčku + test instalace balíčku + test funkce balíčku obstarává [Vagrant](https://www.vagrantup.com/) - Konfigurace ----------- S provádí uvedenín direktiv do .env souboru, jejich definicí jako konstant, nebo nastavením proměnných prostředí. +Debianí balíček konfiurák očekává ve složce /etc/abraflexi-mailer, kde je k dispozici vzorový sobor .env.template ``` @@ -87,6 +70,25 @@ EASE_LOGGER="console|syslog" - způsob logování +Závislosti +---------- + +Tento nástroj ke svojí funkci využívá následující knihovny: + + * [**EasePHP Framework**](https://github.com/VitexSoftware/php-ease-core) - pomocné funkce např. logování + * [**AbraFlexi**](https://github.com/Spoje-NET/php-abraflexi) - komunikace s [AbraFlexi](https://flexibee.eu/) + * [**AbraFlexi Bricks**](https://github.com/VitexSoftware/AbraFlexi-Bricks) - používají se třídy Zákazníka, Upomínky a Upomínače + + + +Poděkování +---------- + +Tento software by nevznikl pez podpory: + +[ ![Spoje.Net](doc/spojenet.gif?raw=true "Spoje.Net s.r.o.") ](https://spoje.net/) + + Další software pro AbraFlexi --------------------------- @@ -97,10 +99,3 @@ Další software pro AbraFlexi * [Monitoring funkce AbraFlexi serveru](https://github.com/VitexSoftware/monitoring-plugins-abraflexi) * [AbraFlexi server bez grafických závislostí](https://github.com/VitexSoftware/abraflexi-server-deb) -Poděkování ----------- - -Tento software by nevznikl pez podpory: - -[ ![Spoje.Net](doc/spojenet.gif?raw=true "Spoje.Net s.r.o.") ](https://spoje.net/) - diff --git a/abraflexi-mailer.1 b/abraflexi-mailer.1 deleted file mode 100644 index 964a001..0000000 --- a/abraflexi-mailer.1 +++ /dev/null @@ -1,79 +0,0 @@ -.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. -.\"See Also: -.\"man mdoc.samples for a complete listing of options -.\"man mdoc for the short list of editing options -.\"/usr/share/misc/mdoc.template -.Dd 8/4/10 \" DATE -.Dt Untitled 1 \" Program name and manual section number -.Os Darwin -.Sh NAME \" Section Header - required - don't modify -.Nm Untitled, -.\" The following lines are read in generating the apropos(man -k) database. Use only key -.\" words here as the database is built based on the words here and in the .ND line. -.Nm Other_name_for_same_program(), -.Nm Yet another name for the same program. -.\" Use .Nm macro to designate other names for the documented program. -.Nd This line parsed for whatis database. -.Sh SYNOPSIS \" Section Header - required - don't modify -.Nm -.Op Fl abcd \" [-abcd] -.Op Fl a Ar path \" [-a path] -.Op Ar file \" [file] -.Op Ar \" [file ...] -.Ar arg0 \" Underlined argument - use .Ar anywhere to underline -arg2 ... \" Arguments -.Sh DESCRIPTION \" Section Header - required - don't modify -Use the .Nm macro to refer to your program throughout the man page like such: -.Nm -Underlining is accomplished with the .Ar macro like this: -.Ar underlined text . -.Pp \" Inserts a space -A list of items with descriptions: -.Bl -tag -width -indent \" Begins a tagged list -.It item a \" Each item preceded by .It macro -Description of item a -.It item b -Description of item b -.El \" Ends the list -.Pp -A list of flags and their descriptions: -.Bl -tag -width -indent \" Differs from above in tag removed -.It Fl a \"-a flag as a list item -Description of -a flag -.It Fl b -Description of -b flag -.El \" Ends the list -.Pp -.\" .Sh ENVIRONMENT \" May not be needed -.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 -.\" .It Ev ENV_VAR_1 -.\" Description of ENV_VAR_1 -.\" .It Ev ENV_VAR_2 -.\" Description of ENV_VAR_2 -.\" .El -.Sh FILES \" File used or created by the topic of the man page -.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact -.It Pa /usr/share/file_name -FILE_1 description -.It Pa /Users/joeuser/Library/really_long_file_name -FILE_2 description -.El \" Ends the list -.\" .Sh DIAGNOSTICS \" May not be needed -.\" .Bl -diag -.\" .It Diagnostic Tag -.\" Diagnostic informtion here. -.\" .It Diagnostic Tag -.\" Diagnostic informtion here. -.\" .El -.Sh SEE ALSO -.\" List links in ascending order by section, alphabetically within a section. -.\" Please do not reference files that do not exist without filing a bug report -.Xr a 1 , -.Xr b 1 , -.Xr c 1 , -.Xr a 2 , -.Xr b 2 , -.Xr a 3 , -.Xr b 3 -.\" .Sh BUGS \" Document known, unremedied bugs -.\" .Sh HISTORY \" Document history if command behaves in a unique manner diff --git a/bin/abraflexi-send b/bin/abraflexi-send new file mode 100644 index 0000000..db70d29 --- /dev/null +++ b/bin/abraflexi-send @@ -0,0 +1,4 @@ +#!/bin/bash +php -f /usr/lib/abraflexi-mailer/SendDocument.php $1 $2 $3 + + diff --git a/bin/abraflexi-send-unsent b/bin/abraflexi-send-unsent index ce46c5f..afa0efd 100644 --- a/bin/abraflexi-send-unsent +++ b/bin/abraflexi-send-unsent @@ -1,2 +1,2 @@ #!/bin/bash -php -f /usr/lib/flexibee-mailer/SendUnsent.php +php -f /usr/lib/abraflexi-mailer/SendUnsent.php diff --git a/bin/abraflexi-send-unsent-with-attachments b/bin/abraflexi-send-unsent-with-attachments index 11667e3..d822847 100644 --- a/bin/abraflexi-send-unsent-with-attachments +++ b/bin/abraflexi-send-unsent-with-attachments @@ -1,2 +1,2 @@ #!/bin/bash -php -f /usr/lib/flexibee-mailer/SendUnsentAttachments.php \ No newline at end of file +php -f /usr/lib/abraflexi-mailer/SendUnsentAttachments.php diff --git a/bin/abraflexi-show-unsent b/bin/abraflexi-show-unsent new file mode 100644 index 0000000..0018d20 --- /dev/null +++ b/bin/abraflexi-show-unsent @@ -0,0 +1,4 @@ +#!/bin/bash +php -f /usr/lib/abraflexi-mailer/ShowUnsent.php + + diff --git a/debian/changelog b/debian/changelog index 53f5568..3c908db 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,29 +1,7 @@ -abraflexi-mailer (0.8.6) UNRELEASED; urgency=medium +abraflexi-mailer (0.1) UNRELEASED; urgency=medium [ vitex ] - * Rename Composer Package in Debian to be Composer 2.0 valid - * Configuration is get from Enviroment if /etc/abraflexi/cliet.json does not exist. - - [ CyberVitexus ] - * create /var/lib/abraflexi-mailer at first install - * debian package installation fix - * Release target added - * Release target added - * Release target added - * separate AbraFlexi mailer init command * "Send Unsent mail" tool added -- CyberVitexus Fri, 14 Aug 2020 15:25:26 +0200 -abraflexi-mailer (0.7.6) experimental; urgency=medium - - [ Vítězslav Dvořák ] - * Initial release - * Package Update - * Deps Update - * Packager deps update - * Deb Fix - * pull-bank command - - - -- vitex Mon, 19 Nov 2018 19:51:04 +0100 diff --git a/debian/install b/debian/install index c7f7ff0..8125715 100644 --- a/debian/install +++ b/debian/install @@ -1,5 +1,5 @@ debian/conf/composer.json usr/lib/abraflexi-mailer/ src/* usr/lib/abraflexi-mailer/ -src/AbraFlexi/Mailer/* usr/lib/abraflexi-mailer/Mailer/ +#src/AbraFlexi/Mailer/* usr/lib/abraflexi-mailer/Mailer/ bin/* usr/bin/ -mailer.json etc/abraflexi/ +.env.template etc/abraflexi-mailer diff --git a/debian/manpages b/debian/manpages deleted file mode 100644 index 6e29edb..0000000 --- a/debian/manpages +++ /dev/null @@ -1,3 +0,0 @@ -abraflexi-mailer.1 -abraflexi-mailer-new2old.1 - diff --git a/debian/postinst b/debian/postinst index 8e961c8..ebbf709 100644 --- a/debian/postinst +++ b/debian/postinst @@ -12,9 +12,6 @@ if [ "$1" = "configure" ]; then mkdir -p /var/lib/composer /var/lib/abraflexi-mailer chown $WEBUSER:$WEBUSER /var/lib/composer /var/lib/abraflexi-mailer /usr/lib/abraflexi-mailer/ -R su - $WEBUSER -s /bin/bash -c 'COMPOSER_HOME="/var/lib/composer" composer --no-dev -o install -d /usr/lib/abraflexi-mailer/' - - abraflexi-mailer-init - fi diff --git a/debian/rules b/debian/rules old mode 100644 new mode 100755 index 23ac438..d5f02be --- a/debian/rules +++ b/debian/rules @@ -5,14 +5,5 @@ override_dh_install: dh_install - sed -i -e 's/..\/vendor/\/var\/lib\/abraflexi-mailer/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/Init.php - sed -i -e 's/..\/vendor/\/var\/lib\/abraflexi-mailer/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/ParujPrijateFaktury.php - sed -i -e 's/..\/vendor/\/var\/lib\/abraflexi-mailer/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/ParujVydaneFaktury.php - sed -i -e 's/..\/vendor/\/var\/lib\/abraflexi-mailer/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/ParujFakturyNew2Old.php - sed -i -e 's/..\/vendor/\/var\/lib\/abraflexi-mailer/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/StahniBanku.php - sed -i -e 's/\.\./\/etc\/abraflexi/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/Init.php - sed -i -e 's/\.\./\/etc\/abraflexi/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/ParujPrijateFaktury.php - sed -i -e 's/\.\./\/etc\/abraflexi/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/ParujVydaneFaktury.php - sed -i -e 's/\.\./\/etc\/abraflexi/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/ParujFakturyNew2Old.php - sed -i -e 's/\.\./\/etc\/abraflexi/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/StahniBanku.php - sed -i -e 's/\.\./\/etc\/abraflexi/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/SendUnsent.php + sed -i -e 's/..\/vendor/\/var\/lib\/abraflexi-mailer/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/*.php + sed -i -e 's/\.\./\/etc\/abraflexi-mailer/g' debian/abraflexi-mailer/usr/lib/abraflexi-mailer/*.php diff --git a/src/AbraFlexi/Mailer/Mailer.php b/src/AbraFlexi/Mailer/Mailer.php index a7e6779..2d71952 100644 --- a/src/AbraFlexi/Mailer/Mailer.php +++ b/src/AbraFlexi/Mailer/Mailer.php @@ -171,18 +171,24 @@ public function addQrCode($size = 200) { ['width' => $size, 'height' => $size, 'title' => $this->document->getRecordCode()])); } + /** + * + * @return array + */ public function addAttachments() { $attachments = Priloha::getAttachmentsList($this->document); - + $attached = []; if ($attachments) { foreach ($attachments as $attachmentID => $attachment) { if (Priloha::saveToFile($attachmentID, sys_get_temp_dir())) { $tmpfile = sys_get_temp_dir() . '/' . $attachment['nazSoub']; $this->addFile($tmpfile, $attachment['contentType']); $this->cleanup[] = $tmpfile; - } + $attached[$attachmentID] = $attachment['nazSoub']; + } } } + return $attached; } public function send() { diff --git a/src/SendDocument.php b/src/SendDocument.php new file mode 100644 index 0000000..055fcda --- /dev/null +++ b/src/SendDocument.php @@ -0,0 +1,73 @@ +loadConfig('../.env', true); +} + +$document = $argv[1]; +$evidence = array_key_exists(2, $argv) ? $argv[2] : 'faktura-vydana'; + +if ($argc > 2) { + + $documentor = new FakturaVydana(RO::code($document), ['evidence' => $evidence, 'ignore404' => true]); + $documentor->logBanner(Functions::cfg('APP_NAME')); + + if ($documentor->lastResponseCode == 200) { + + $to = (array_key_exists(3, $argv) ? $argv[3] : $documentor->getEmail()); + $documentor->addStatusMessage(RO::uncode($documentor->getRecordCode()) . "\t" . RO::uncode($documentor->getDataValue('firma')) . "\t" . $to . "\t" . $documentor->getDataValue('poznam'), 'success'); + + $mailer = new Mailer($documentor, $to); + + if (array_key_exists('poznam', $documentor->getColumnsInfo())) { + preg_match_all('/cc:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/i', $documentor->getDataValue('poznam'), $ccs); + if (!empty($ccs[0])) { + $mailer->setMailHeaders(['Cc' => str_replace('cc:', '', implode(',', $ccs[0]))]); + } + } + + if (array_key_exists('popis', $documentor->getColumnsInfo())) { + $mailer->addItem(new PTag($documentor->getDataValue('popis'))); + } + + $documentor->addStatusMessage(_('Attaching') . ': ' . implode(',', $mailer->addAttachments())); + + if (array_key_exists('juhSum', $documentor->getColumnsInfo())) { + if (Functions::cfg('ADD_QRCODE')) { + $mailer->addQrCode(); + } + } + + if (array_key_exists('stavMailK', $documentor->getColumnsInfo())) { + $result = ($mailer->send() && $documentor->sync(['id' => $documentor->getRecordIdent(), 'stavMailK' => 'stavMail.odeslano'])); + } else { + $result = $mailer->send(); + } + } else { + $documentor->addStatusMessage(sprintf(_('Cannot read %s %s'), $evidence, $document)); + } +} else { + echo _('AbraFlexi Document Sender') . "\n"; + echo "abraflexi-send-document [evidence-code] [recipent@email,another@recipient] \n"; + echo "abraflexi-send-document VF1-7326/2020 faktura-vydana \n"; +} + + diff --git a/src/SendUnsent.php b/src/SendUnsent.php index fc0f985..772fbd4 100644 --- a/src/SendUnsent.php +++ b/src/SendUnsent.php @@ -11,10 +11,8 @@ define('EASE_APPNAME', 'OdeslatNeodeslane'); require_once '../vendor/autoload.php'; $shared = new Shared(); -if (file_exists('../client.json')) { - $shared->loadConfig('../client.json', true); -} -if (file_exists('../.env')) { + +if(file_exists('../.env')){ $shared->loadConfig('../.env', true); } diff --git a/src/SendUnsentAttachments.php b/src/SendUnsentAttachments.php index 4e3af71..2c81a0b 100644 --- a/src/SendUnsentAttachments.php +++ b/src/SendUnsentAttachments.php @@ -15,7 +15,9 @@ define('EASE_LOGGER', 'syslog|console'); require_once '../vendor/autoload.php'; $shared = new Shared(); -$shared->loadConfig('../.env', true); +if(file_exists('../.env')){ + $shared->loadConfig('../.env', true); +} $invoicer = new \AbraFlexi\FakturaVydana(); diff --git a/src/ShowUnsent.php b/src/ShowUnsent.php index 568d0c7..796176e 100644 --- a/src/ShowUnsent.php +++ b/src/ShowUnsent.php @@ -12,7 +12,9 @@ define('EASE_LOGGER', 'syslog|console'); require_once '../vendor/autoload.php'; $shared = new Shared(); -$shared->loadConfig('../.env', true); +if (file_exists('../.env')) { + $shared->loadConfig('../.env', true); +} $invoicer = new \AbraFlexi\FakturaVydana();