'; $menu .= ''; $menu .= ''; $menu .= ''; $menu .= ''; $menu .= ''; $menu .= ''; $menu .= ''; $menu .= ''; $calcdate = new \DateTimeImmutable('today'); $scalcdate = $calcdate->format('Y-m-d'); $where = " aa.id > 0 AND aa.dokument = '$doctype' AND greatest(aa.startdatum, aa.abgerechnetbis) < '$scalcdate' AND (aa.enddatum = '0000-00-00' OR aa.abgerechnetbis < aa.enddatum)"; $sql = "SELECT SQL_CALC_FOUND_ROWS adr.id, '' as open, concat('') as auswahl, adr.kundennummer, adr.name, adr.anschreiben, adr.email, p.abkuerzung, GROUP_CONCAT(DATE_FORMAT(@start := GREATEST(aa.startdatum, aa.abgerechnetbis),'%d.%m.%Y') SEPARATOR '
') as start, GROUP_CONCAT(DATE_FORMAT( @end := CASE WHEN aa.preisart = 'monat' THEN DATE_ADD(@start, INTERVAL TIMESTAMPDIFF(MONTH, @start, IF(aa.enddatum = '0000-00-00' OR aa.enddatum > '$scalcdate', '$scalcdate', aa.enddatum))+1 MONTH) WHEN aa.preisart = 'jahr' THEN DATE_ADD(@start, INTERVAL TIMESTAMPDIFF(YEAR, @start, IF(aa.enddatum = '0000-00-00' OR aa.enddatum > '$scalcdate', '$scalcdate', aa.enddatum))+1 YEAR) WHEN aa.preisart = '30tage' THEN DATE_ADD(@start, INTERVAL (FLOOR(TIMESTAMPDIFF(DAY, @start, IF(aa.enddatum = '0000-00-00' OR aa.enddatum > '$scalcdate', '$scalcdate', aa.enddatum)) / 30)+1)*30 DAY ) END, '%d.%m.%Y') SEPARATOR '
') as end, SUM((100-aa.rabatt)/100 * aa.preis * aa.menge * (CASE WHEN aa.preisart = 'monat' THEN TIMESTAMPDIFF(MONTH, @start, @end) WHEN aa.preisart = 'jahr' THEN TIMESTAMPDIFF(YEAR, @start, @end) WHEN aa.preisart = '30tage' THEN FLOOR(TIMESTAMPDIFF(DAY, @start, @end) / 30) END ) ) as amount, adr.id FROM abrechnungsartikel aa JOIN artikel a ON aa.artikel = a.id JOIN adresse adr ON aa.adresse = adr.id LEFT JOIN projekt p ON aa.projekt = p.id"; $groupby = " GROUP BY aa.adresse, aa.projekt"; $count = "SELECT count(aa.id) FROM `abrechnungsartikel` AS `aa` WHERE $where $groupby"; $menucol = 10; $moreinfo = true; break; case 'rechnungslauf_abos': $allowed['rechnungslauf'] = ['abos']; $heading = array( 'Kunde', 'Kunden Nr.', 'Bezeichnung', 'Nummer', 'Abgerechnet bis', 'Enddatum', 'Preis', 'Rabatt', 'Menge', 'Art', 'Zahlperiode', 'Zahlweise', 'Dokument', 'Menü'); $width = ['10%','5%','15%','1','1','1','1','1','1','1','1','1','1','1']; $findcols = [ 'ad.name', 'ad.kundennummer', 'aa.bezeichnung', 'a.nummer', "DATE_FORMAT(aa.abgerechnetbis, '%d.%m.%Y')", 'aa.enddatum', 'aa.preis', 'aa.rabatt', 'aa.menge', 'aa.preisart', 'aa.zahlzyklus', '', 'aa.dokument' ]; $searchsql = ['ad.name', 'aa.bezeichnung']; $numbercols = [0]; $alignright = [7]; $datecols = [5,6]; $defaultorder = 1; $defaultorderdesc = 0; $menu = "
" . "" . "Conf->WFconf['defaulttheme']}/images/forward.svg\" border=\"0\">" . " 
"; $where = " aa.id > 0 AND (aa.enddatum = '0000-00-00' OR aa.abgerechnetbis < aa.enddatum) "; $sql = "SELECT SQL_CALC_FOUND_ROWS aa.id, ad.name, ad.kundennummer, aa.bezeichnung, a.nummer, DATE_FORMAT(aa.abgerechnetbis, '%d.%m.%Y'), DATE_FORMAT(aa.enddatum, '%d.%m.%Y'), ".$app->erp->FormatPreis('aa.preis', 2).", aa.rabatt, aa.menge, aa.preisart, aa.zahlzyklus, '', aa.dokument, ad.id FROM `abrechnungsartikel` AS `aa` LEFT JOIN `adresse` AS `ad` ON aa.adresse = ad.id LEFT JOIN `artikel` AS `a` ON aa.artikel = a.id"; $count = "SELECT count(aa.id) FROM `abrechnungsartikel` AS `aa` WHERE $where"; break; } $erg = []; foreach($erlaubtevars as $k => $v) { if(isset($$v)) { $erg[$v] = $$v; } } return $erg; } /** * Rechnungslauf constructor. * * @param Application $app * @param bool $intern */ public function __construct($app, $intern = false) { $this->app = $app; if($intern) { return; } $this->app->ActionHandlerInit($this); // ab hier alle Action Handler definieren die das Modul hat $this->app->ActionHandler('rechnungslauf', 'ActionList'); $this->app->ActionHandler('abos', 'ActionAbos'); $this->app->ActionHandler('minidetail', 'ActionMinidetail'); $this->app->ActionHandlerListen($app); } public function MenuList() { $this->app->erp->Headlines("Abolauf"); $this->app->erp->MenuEintrag("index.php?module=rechnungslauf&action=rechnungslauf", "Übersicht"); $this->app->erp->MenuEintrag("index.php?module=rechnungslauf&action=abos", "gebuchte Abos"); $this->app->erp->MenuEintrag("index.php?module=rechnungslauf&action=einstellungen", "Einstellungen"); } public function ActionList() { /** @var SubscriptionModule $module */ $this->MenuList(); $this->app->YUI->TableSearch("TAB_INVOICES", 'rechnungslauf_invoices','show', '', '', basename(__FILE__), __CLASS__); $this->app->YUI->TableSearch("TAB_ORDERS", 'rechnungslauf_orders','show', '', '', basename(__FILE__), __CLASS__); if ($this->app->Secure->GetPOST('createInvoices') !== '') { $selection = $this->app->Secure->GetPOST('selection'); /** @var SubscriptionCycleJobService $subscriptionCycleJobService */ $subscriptionCycleJobService = $this->app->Container->get('SubscriptionCycleJobService'); foreach ($selection as $value) { $subscriptionCycleJobService->deleteJobsByAddressIdAndDoctype($value, 'rechnung'); $subscriptionCycleJobService->create($value, 'rechnung'); $this->app->Tpl->addMessage('info', 'Die Rechnungen werden nun im Hintergrund erstellt', false, 'MESSAGE_INVOICES'); } } else if ($this->app->Secure->GetPOST('createOrders') !== '') { $selection = $this->app->Secure->GetPOST('selection'); /** @var SubscriptionCycleJobService $subscriptionCycleJobService */ $subscriptionCycleJobService = $this->app->Container->get('SubscriptionCycleJobService'); foreach ($selection as $value) { $subscriptionCycleJobService->deleteJobsByAddressIdAndDoctype($value, 'auftrag'); $subscriptionCycleJobService->create($value, 'auftrag'); $this->app->Tpl->addMessage('info', 'Die Aufträge werden nun im Hintergrund erstellt', false, 'MESSAGE_ORDERS'); } } $this->app->Tpl->Parse('PAGE', 'rechnungslauf_list.tpl'); } public function ActionAbos() { $this->MenuList(); $this->app->YUI->TableSearch("TAB1", 'rechnungslauf_abos', 'show', '', '', basename(__FILE__), __CLASS__); $this->app->Tpl->Parse('PAGE', 'rechnungslauf_abos.tpl'); } public function ActionMinidetail() { /** @var SubscriptionModule $module */ $module = $this->app->Container->get('SubscriptionModule'); $address = $this->app->Secure->GetGET('id'); $pos = $module->GetPositions($address, 'rechnung'); foreach ($pos as $p) { $row = ''; $row .= sprintf('%s', $p['bezeichnung']); $row .= sprintf('%s', $p['menge']); $row .= sprintf('%s', $this->app->erp->number_format_variable($p['preis'], 2)); $row .= sprintf('%s', $p['rabatt']); $row .= sprintf('%s', $p['cycles']); $row .= sprintf('%s', $this->app->erp->number_format_variable($p['preis']*$p['menge']*$p['cycles'], 2)); $row .= sprintf('%s', $p['waehrung']); $row .= ''; $this->app->Tpl->Add('INHALT', $row); } $this->app->Tpl->Set('SUBHEADING', 'Kunde'); $this->app->Tpl->Output('rechnungslauf_minidetail.tpl'); $this->app->ExitXentral(); } }