1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
<?php
namespace FlexiPeeHP\Bricks;
class Upominka extends \FlexiPeeHP\FlexiBeeRW
{
public $evidence = 'sablona-upominky';
public $mailer = null;
public $firmer = null;
public $invoicer = null;
public function __construct($init = null, $options = array())
{
parent::__construct($init, $options);
$this->invoicer = new \FlexiPeeHP\FakturaVydana();
$this->firmer = new \FlexiPeeHP\Adresar();
}
public function loadTemplate($template)
{
$this->takeData(current($this->getColumnsFromFlexibee('*',
['typSablonyK' => 'typSablony.'.$template])));
}
public function compile($cid, $clientDebts)
{
$result = false;
$kontakt = $this->firmer->getColumnsFromFlexibee(['nazev', 'email'],
['id' => $cid]);
if (strlen($kontakt[0]['email'])) {
$sumCelkem = 0;
$invoices = [];
foreach ($clientDebts as $debt) {
$sumCelkem += $debt['zbyvaUhradit'];
$ddiff = Upominac::poSplatnosti($debt['datSplat']);
$invoices[] = $debt['kod'].' v.s.: '.$debt['varSym'].' '.$debt['zbyvaUhradit'].' '.str_replace('code:',
'',
$debt['mena'].' '.\FlexiPeeHP\FlexiBeeRO::flexiDateToDateTime($debt['datSplat'])->format('d.m.Y').' ('.$ddiff.' dní po splatnosti)');
}
$to = $kontakt[0]['email'];
$dnes = new \DateTime();
$subject = $this->getDataValue('hlavicka').' ke dni '.$dnes->format('d.m.Y');
$body = $this->getDataValue('uvod').
"\n\n".$this->getDataValue('textNad')."\n\n".
sprintf(_("%s \n\n-----------------------\n celkem za %s,-"),
implode("\n", $invoices), $sumCelkem).
"\n\n".$this->getDataValue('textPod')."\n".
"\n\n".$this->getDataValue('zapati')."\n";
$this->mailer = new \Ease\Mailer($to, $subject, $body);
$this->addAttachments($clientDebts);
$result = true;
} else {
$this->addStatusMessage(sprintf(_('Klient %s nema email %s !!!'),
$kontakt[0]['nazev'],
$this->firmer->getEvidenceURL('adresar/'.$cid)), 'error');
}
return $result;
}
public function addAttachments($clientDebts)
{
foreach ($clientDebts as $debt) {
$this->invoicer->setMyKey($debt['id']);
$this->mailer->addFile($this->invoicer->downloadInFormat('pdf',
'/tmp/'),
\FlexiPeeHP\Formats::$formats['PDF']['content-type']);
$this->mailer->addFile($this->invoicer->downloadInFormat('isdocx',
'/tmp/'),
\FlexiPeeHP\Formats::$formats['ISDOCx']['content-type']);
}
}
public function send()
{
return $this->mailer->send();
}
}