mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-24 13:40:29 +01:00
mahnwesen initial
This commit is contained in:
parent
73725a31bb
commit
1f6caa8632
@ -36096,6 +36096,18 @@ function Firmendaten($field,$projekt="")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recalculate payment status and skonto
|
||||
* using module rechnung
|
||||
*/
|
||||
public function rechnung_zahlstatus_berechnen() {
|
||||
$rechnung = $this->app->loadModule('rechnung', false);
|
||||
if($rechnung !== null && method_exists($rechnung, 'rechnung_zahlstatus_berechnen')) {
|
||||
return $rechnung->rechnung_zahlstatus_berechnen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function ANABREGSNeuberechnen($id,$art,$force=false)
|
||||
{
|
||||
if($id <= 0 || empty($art))
|
||||
|
56
www/pages/content/mahnwesen_list.tpl
Normal file
56
www/pages/content/mahnwesen_list.tpl
Normal file
@ -0,0 +1,56 @@
|
||||
<div id="tabs">
|
||||
<ul>
|
||||
<li><a href="#tabs-1">[TABTEXT1]</a></li>
|
||||
</ul>
|
||||
<div id="tabs-1">
|
||||
|
||||
<form method="post" action="#">
|
||||
|
||||
<div class="filter-box filter-usersave">
|
||||
<div class="filter-block filter-inline">
|
||||
<div class="filter-title">{|Filter|}</div>
|
||||
<ul class="filter-list">
|
||||
<li class="filter-item">
|
||||
<label for="inkl_bezahlte" class="switch">
|
||||
<input type="checkbox" id="inkl_bezahlte">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
<label for="inkl_bezahlte">{|Inkl. bezahlte|}</label>
|
||||
</li>
|
||||
<li class="filter-item">
|
||||
<label for="inkl_gesperrte" class="switch">
|
||||
<input type="checkbox" id="inkl_gesperrte">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
<label for="inkl_gesperrte">{|Inkl. gesperrte|}</label>
|
||||
</li>
|
||||
</ul>
|
||||
<input type="submit" class="btnBlue" name="zahlungsstatus_berechnen" value="{|Zahlungsstatus berechnen|}" />
|
||||
</div>
|
||||
</div>
|
||||
[MESSAGE]
|
||||
[TAB1]
|
||||
[TAB1NEXT]
|
||||
<fieldset>
|
||||
<legend>{|Stapelverarbeitung|}</legend>
|
||||
<input type="checkbox" id="auswahlalle" onchange="alleauswaehlen();" /> {|alle markieren|}
|
||||
<select id="sel_aktion" name="sel_aktion">
|
||||
<option value="">{|bitte wählen|} ...</option>
|
||||
[ALSBEZAHLTMARKIEREN]
|
||||
<option value="offen">{|als offen markieren|}</option>
|
||||
<option value="mahnen">{|Mahnenstufe erhöhen|}</option>
|
||||
<option value="email">{|Mahnungen versenden (E-Mail)|}</option>
|
||||
<option value="drucken">{|Mahnungen drucken|}</option>
|
||||
</select> {|Drucker|}: <select name="seldrucker">[SELDRUCKER]</select> <input type="submit" class="btnBlue" name="ausfuehren" value="{|ausführen|}" />
|
||||
</fieldset>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function alleauswaehlen()
|
||||
{
|
||||
var wert = $('#auswahlalle').prop('checked');
|
||||
$('#mahnwesen_list').find(':checkbox').prop('checked',wert);
|
||||
}
|
||||
</script>
|
454
www/pages/mahnwesen.php
Normal file
454
www/pages/mahnwesen.php
Normal file
@ -0,0 +1,454 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 OpenXE project
|
||||
*/
|
||||
|
||||
use Xentral\Components\Database\Exception\QueryFailureException;
|
||||
|
||||
class Mahnwesen {
|
||||
|
||||
function __construct($app, $intern = false) {
|
||||
$this->app = $app;
|
||||
if ($intern)
|
||||
return;
|
||||
|
||||
$this->app->ActionHandlerInit($this);
|
||||
$this->app->ActionHandler("list", "mahnwesen_list");
|
||||
$this->app->ActionHandler("create", "mahnwesen_edit"); // This automatically adds a "New" button
|
||||
$this->app->ActionHandler("edit", "mahnwesen_edit");
|
||||
$this->app->ActionHandler("delete", "mahnwesen_delete");
|
||||
$this->app->DefaultActionHandler("list");
|
||||
$this->app->ActionHandlerListen($app);
|
||||
}
|
||||
|
||||
public function Install() {
|
||||
/* Fill out manually later */
|
||||
}
|
||||
|
||||
public function TableSearch($app, $name, $erlaubtevars) {
|
||||
switch ($name) {
|
||||
case "mahnwesen_list":
|
||||
|
||||
$extended_mysql55 = ",'de_DE'";
|
||||
|
||||
$allowed['mahnwesen_list'] = array('list');
|
||||
$heading = array('', '', 'Rechnung', 'Vom', 'Kd-Nr.', 'Kunde', 'Land', 'Projekt', 'Zahlung', 'Betrag (brutto)', 'Währung', 'Zahlstatus', 'Differenz', 'Status','Mahnstufe','Mahn-Datum','Gemahnt','Sperre','Interne Bemerkung','Menü');
|
||||
$width = array('1%','1%','01%', '01%', '01%', '05%', '01%', '01%', '01%', '01%', '01%', '01%', '01%', '01%', '01%', '01%', '01%', '01%', '20%', '1%'); // Fill out manually later
|
||||
|
||||
// columns that are aligned right (numbers etc)
|
||||
// $alignright = array(4,5,6,7,8);
|
||||
|
||||
$findcols = array('r.id','r.id','r.belegnr', $app->erp->FormatDateShort('r.datum'), 'r.kundennummer','r.name', 'r.land','p.abkuerzung','r.zahlungsweise','r.soll','r.waehrung','r.zahlungsstatus','r.soll','r.status','r.mahnwesen');
|
||||
$searchsql = array('belegnr', 'kunde', 'datum');
|
||||
|
||||
$defaultorder = 1;
|
||||
$defaultorderdesc = 0;
|
||||
|
||||
$dropnbox = "'<img src=./themes/new/images/details_open.png class=details>' AS `open`, CONCAT('<input type=\"checkbox\" name=\"auswahl[]\" value=\"',r.id,'\" />') AS `auswahl`";
|
||||
|
||||
$menu = "<table cellpadding=0 cellspacing=0><tr><td nowrap>" . "<a href=\"index.php?module=rechnung&action=edit&id=%value%\"><img src=\"./themes/{$app->Conf->WFconf['defaulttheme']}/images/edit.svg\" border=\"0\"></a>" . "</td></tr></table>";
|
||||
|
||||
$sql = "SELECT SQL_CALC_FOUND_ROWS
|
||||
r.id,
|
||||
$dropnbox,
|
||||
r.belegnr,
|
||||
".$app->erp->FormatDateShort('r.datum')." as vom,
|
||||
if(r.kundennummer <> '',r.kundennummer,adr.kundennummer),
|
||||
CONCAT(" . $app->erp->MarkerUseredit("r.name", "r.useredittimestamp") . ", if(r.internebezeichnung!='',CONCAT('<br><i style=color:#999>',r.internebezeichnung,'</i>'),'')) as kunde,
|
||||
r.land as land,
|
||||
p.abkuerzung as projekt,
|
||||
r.zahlungsweise as zahlungsweise,
|
||||
FORMAT(r.soll,2{$extended_mysql55} ) as soll,
|
||||
ifnull(r.waehrung,'EUR'),
|
||||
r.zahlungsstatus as zahlung,
|
||||
if(r.soll-r.ist!=0 AND r.ist > 0,FORMAT(r.ist-r.soll,2{$extended_mysql55}),FORMAT((r.soll-r.ist)*-1,2{$extended_mysql55})) as fehlt,
|
||||
if(r.status = 'storniert' AND r.teilstorno = 1,'TEILSTORNO',UPPER(r.status)) as status,
|
||||
r.mahnwesen,
|
||||
".$app->erp->FormatDateShort('mahnwesen_datum')." as datum,
|
||||
if(r.versendet_mahnwesen,'Ja',''),
|
||||
if(r.mahnwesen_gesperrt,'Ja',''),
|
||||
REPLACE(r.mahnwesen_internebemerkung,'\r\n','<br> '),
|
||||
r.id
|
||||
FROM rechnung r LEFT JOIN projekt p ON p.id=r.projekt LEFT JOIN adresse adr ON r.adresse=adr.id LEFT JOIN auftrag au ON au.id = r.auftragid ";
|
||||
|
||||
$where = " r.belegnr <> ''";
|
||||
|
||||
// Toggle filters
|
||||
$this->app->Tpl->Add('JQUERYREADY', "$('#inkl_bezahlte').click( function() { fnFilterColumn1( 0 ); } );");
|
||||
$this->app->Tpl->Add('JQUERYREADY', "$('#inkl_gesperrte').click( function() { fnFilterColumn2( 0 ); } );");
|
||||
|
||||
for ($r = 1;$r <= 2;$r++) {
|
||||
$this->app->Tpl->Add('JAVASCRIPT', '
|
||||
function fnFilterColumn' . $r . ' ( i )
|
||||
{
|
||||
if(oMoreData' . $r . $name . '==1)
|
||||
oMoreData' . $r . $name . ' = 0;
|
||||
else
|
||||
oMoreData' . $r . $name . ' = 1;
|
||||
|
||||
$(\'#' . $name . '\').dataTable().fnFilter(
|
||||
\'\',
|
||||
i,
|
||||
0,0
|
||||
);
|
||||
}
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
$more_data1 = $app->Secure->GetGET("more_data1");
|
||||
if ($more_data1 == 1) {
|
||||
} else {
|
||||
$where .= " AND r.zahlungsstatus <> 'bezahlt' ";
|
||||
}
|
||||
|
||||
$more_data2 = $app->Secure->GetGET("more_data2");
|
||||
if ($more_data2 == 1) {
|
||||
}
|
||||
else {
|
||||
$where .= " AND NOT r.mahnwesen_gesperrt ";
|
||||
}
|
||||
// END Toggle filters
|
||||
|
||||
|
||||
$count = "SELECT count(DISTINCT id) FROM rechnung r WHERE $where";
|
||||
// $groupby = "";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$erg = false;
|
||||
|
||||
foreach ($erlaubtevars as $k => $v) {
|
||||
if (isset($$v)) {
|
||||
$erg[$v] = $$v;
|
||||
}
|
||||
}
|
||||
return $erg;
|
||||
}
|
||||
|
||||
function mahnwesen_list() {
|
||||
$this->app->erp->MenuEintrag("index.php?module=mahnwesen&action=list", "Übersicht");
|
||||
// $this->app->erp->MenuEintrag("index.php?module=mahnwesen&action=create", "Neu anlegen");
|
||||
$this->app->erp->MenuEintrag("index.php", "Zurück");
|
||||
|
||||
if($this->app->Secure->GetPOST('zahlungsstatus_berechnen') && $this->app->erp->RechteVorhanden('rechnung', 'edit')) {
|
||||
$this->app->erp->rechnung_zahlstatus_berechnen();
|
||||
}
|
||||
|
||||
if($this->app->Secure->GetPOST('sel_aktion') && $this->app->erp->RechteVorhanden('rechnung', 'edit'))
|
||||
{
|
||||
$drucker = $this->app->Secure->GetPOST('seldrucker');
|
||||
$aktion = $this->app->Secure->GetPOST('sel_aktion');
|
||||
$auswahl = $this->app->Secure->GetPOST('auswahl');
|
||||
if($drucker > 0) {
|
||||
$this->app->erp->BriefpapierHintergrundDisable($drucker);
|
||||
}
|
||||
if(is_array($auswahl)) {
|
||||
foreach($auswahl as $auswahlKey => $auswahlValue) {
|
||||
if((int)$auswahlValue > 0) {
|
||||
$auswahl[$auswahlKey] = (int)$auswahlValue;
|
||||
}
|
||||
else {
|
||||
unset($auswahl[$auswahlKey]);
|
||||
}
|
||||
}
|
||||
switch($aktion)
|
||||
{
|
||||
case 'bezahlt':
|
||||
$this->app->DB->Update("UPDATE rechnung SET zahlungsstatus='bezahlt', bezahlt_am = now(), mahnwesenfestsetzen='1',mahnwesen_internebemerkung=CONCAT(mahnwesen_internebemerkung,'\r\n','Manuell als bezahlt markiert am ".date('d.m.Y')."') WHERE id IN (".implode(', ',$auswahl).')');
|
||||
break;
|
||||
case 'offen':
|
||||
$this->app->DB->Update("UPDATE rechnung SET zahlungsstatus='offen',bezahlt_am = NULL, mahnwesen_internebemerkung=CONCAT(mahnwesen_internebemerkung,'\r\n','Manuell als bezahlt entfernt am ".date('d.m.Y')."') WHERE id IN (".implode(', ',$auswahl).')');
|
||||
break;
|
||||
case 'mail':
|
||||
$auswahl = $this->app->DB->SelectFirstCols(
|
||||
sprintf(
|
||||
"SELECT id FROM rechnung WHERE belegnr <> '' AND id IN (%s)",
|
||||
implode(', ', $auswahl)
|
||||
)
|
||||
);
|
||||
foreach($auswahl as $v) {
|
||||
if(!$v) {
|
||||
continue;
|
||||
}
|
||||
$checkpapier = $this->app->DB->Select(
|
||||
"SELECT a.rechnung_papier FROM rechnung AS r
|
||||
LEFT JOIN adresse AS a ON r.adresse=a.id
|
||||
WHERE r.id='$v'
|
||||
LIMIT 1"
|
||||
);
|
||||
if($checkpapier!=1 &&
|
||||
$this->app->DB->Select(
|
||||
"SELECT r.id
|
||||
FROM rechnung AS r
|
||||
INNER JOIN adresse AS a ON r.adresse = a.id
|
||||
WHERE r.id = '$v' AND r.email <> '' OR a.email <> ''
|
||||
LIMIT 1"
|
||||
)
|
||||
) {
|
||||
$this->app->erp->PDFArchivieren('rechnung', $v, true);
|
||||
$this->app->erp->Rechnungsmail($v);
|
||||
}
|
||||
else if($checkpapier && $drucker) {
|
||||
$this->app->erp->PDFArchivieren('rechnung', $v, true);
|
||||
$projekt = $this->app->DB->Select(
|
||||
"SELECT projekt FROM rechnung WHERE id='$v' LIMIT 1"
|
||||
);
|
||||
if(class_exists('RechnungPDFCustom')) {
|
||||
$Brief = new RechnungPDFCustom($this->app,$projekt);
|
||||
}
|
||||
else {
|
||||
$Brief = new RechnungPDF($this->app,$projekt);
|
||||
}
|
||||
$Brief->GetRechnung($v);
|
||||
$tmpfile = $Brief->displayTMP();
|
||||
$Brief->ArchiviereDocument();
|
||||
$this->app->printer->Drucken($drucker,$tmpfile);
|
||||
unlink($tmpfile);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'versendet':
|
||||
$auswahl = $this->app->DB->SelectFirstCols(
|
||||
sprintf(
|
||||
"SELECT id FROM rechnung WHERE belegnr <> '' AND id IN (%s)",
|
||||
implode(', ', $auswahl)
|
||||
)
|
||||
);
|
||||
foreach($auswahl as $v) {
|
||||
if($v) {
|
||||
$reArr = $this->app->DB->SelectRow(
|
||||
sprintf(
|
||||
"SELECT projekt,belegnr,status,usereditid,
|
||||
DATE_SUB(NOW(), INTERVAL 30 SECOND) < useredittimestamp AS `open`
|
||||
FROM rechnung WHERE id=%d LIMIT 1",
|
||||
$v
|
||||
)
|
||||
);
|
||||
if($reArr['belegnr'] === '' || ($reArr['open'] && $reArr['status'] === 'freigegeben')) {
|
||||
continue;
|
||||
}
|
||||
$this->markInvoiceAsClosed($v);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'drucken':
|
||||
if($drucker) {
|
||||
$auswahl = $this->app->DB->SelectFirstCols(
|
||||
sprintf(
|
||||
"SELECT id FROM rechnung WHERE belegnr <> '' AND id IN (%s)",
|
||||
implode(', ', $auswahl)
|
||||
)
|
||||
);
|
||||
foreach($auswahl as $v) {
|
||||
$reArr = $this->app->DB->SelectRow(
|
||||
sprintf(
|
||||
"SELECT projekt,belegnr,status,usereditid,adresse,
|
||||
DATE_SUB(NOW(), INTERVAL 30 SECOND) < useredittimestamp AS `open`
|
||||
FROM rechnung WHERE id=%d LIMIT 1",
|
||||
$v
|
||||
)
|
||||
);
|
||||
if($reArr['belegnr'] === '' || ($reArr['open'] && $reArr['status'] === 'freigegeben')) {
|
||||
continue;
|
||||
}
|
||||
if($reArr['status'] === 'freigegeben') {
|
||||
$this->app->erp->RechnungNeuberechnen($v);
|
||||
}
|
||||
$projekt = $reArr['projekt'];//$this->app->DB->Select("SELECT projekt FROM rechnung WHERE id='$v' LIMIT 1");
|
||||
$this->app->erp->RechnungProtokoll($v,'Rechnung gedruckt');
|
||||
$this->app->DB->Update("UPDATE rechnung SET schreibschutz=1, versendet = 1 WHERE id = '$v' LIMIT 1");
|
||||
$this->app->DB->Update("UPDATE rechnung SET status='versendet' WHERE id = '$v' AND status!='storniert' LIMIT 1");
|
||||
$this->app->erp->PDFArchivieren('rechnung', $v, true);
|
||||
if(class_exists('RechnungPDFCustom')) {
|
||||
$Brief = new RechnungPDFCustom($this->app,$projekt);
|
||||
}
|
||||
else{
|
||||
$Brief = new RechnungPDF($this->app,$projekt);
|
||||
}
|
||||
$Brief->GetRechnung($v);
|
||||
$tmpfile = $Brief->displayTMP();
|
||||
$Brief->ArchiviereDocument();
|
||||
$this->app->printer->Drucken($drucker,$tmpfile);
|
||||
$doctype = 'rechnung';
|
||||
$this->app->erp->RunHook('dokumentsend_ende', 5, $doctype, $v, $projekt, $reArr['adresse'], $aktion);
|
||||
@unlink($tmpfile);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'pdf':
|
||||
$tmpfile = [];
|
||||
foreach($auswahl as $v) {
|
||||
$projekt = $this->app->DB->Select("SELECT projekt FROM rechnung WHERE id=$v LIMIT 1");
|
||||
if(class_exists('RechnungPDFCustom')) {
|
||||
$Brief = new RechnungPDFCustom($this->app,$projekt);
|
||||
}
|
||||
else {
|
||||
$Brief = new RechnungPDF($this->app,$projekt);
|
||||
}
|
||||
$Brief->GetRechnung($v);
|
||||
$tmpfile[] = $Brief->displayTMP();
|
||||
}
|
||||
|
||||
if((!empty($tmpfile)?count($tmpfile):0) > 0) {
|
||||
try {
|
||||
/** @var PdfMerger $pdfMerger */
|
||||
$pdfMerger = $this->app->Container->get('PdfMerger');
|
||||
$mergeOutputPath = realpath($this->app->erp->GetTMP()) . '/' . uniqid('sammelpdf_', true) . '.pdf';
|
||||
$pdfMerger->merge($tmpfile, $mergeOutputPath);
|
||||
|
||||
foreach($tmpfile as $key=>$value) {
|
||||
unlink($value);
|
||||
}
|
||||
|
||||
header('Content-type:application/pdf');
|
||||
header('Content-Disposition: attachment;filename='.md5(microtime(true)).'.pdf');
|
||||
readfile($mergeOutputPath);
|
||||
$this->app->ExitXentral();
|
||||
} catch (PdfComponentExceptionInterface $exception) {
|
||||
echo 'Fehler beim Generieren der Sammelpdf: ' . htmlspecialchars($exception->getMessage());
|
||||
$this->app->ExitXentral();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ende ausfuehren
|
||||
|
||||
if($this->app->erp->RechteVorhanden('rechnung', 'manuellbezahltmarkiert')){
|
||||
$this->app->Tpl->Set('ALSBEZAHLTMARKIEREN', '<option value="bezahlt">{|als bezahlt markieren|}</option>');
|
||||
}
|
||||
|
||||
$this->app->Tpl->Set('SELDRUCKER', $this->app->erp->GetSelectDrucker($this->app->User->GetParameter('rechnung_list_drucker')));
|
||||
|
||||
$this->app->YUI->TableSearch('TAB1', 'mahnwesen_list', "show", "", "", basename(__FILE__), __CLASS__);
|
||||
$this->app->Tpl->Parse('PAGE', "mahnwesen_list.tpl");
|
||||
}
|
||||
|
||||
public function mahnwesen_delete() {
|
||||
$id = (int) $this->app->Secure->GetGET('id');
|
||||
|
||||
$this->app->DB->Delete("DELETE FROM `mahnwesen` WHERE `id` = '{$id}'");
|
||||
$this->app->Tpl->Set('MESSAGE', "<div class=\"error\">Der Eintrag wurde gelöscht.</div>");
|
||||
|
||||
$this->mahnwesen_list();
|
||||
}
|
||||
|
||||
/*
|
||||
* Edit mahnwesen item
|
||||
* If id is empty, create a new one
|
||||
*/
|
||||
|
||||
function mahnwesen_edit() {
|
||||
$id = $this->app->Secure->GetGET('id');
|
||||
|
||||
// Check if other users are editing this id
|
||||
if($this->app->erp->DisableModul('artikel',$id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->app->Tpl->Set('ID', $id);
|
||||
|
||||
$this->app->erp->MenuEintrag("index.php?module=mahnwesen&action=edit&id=$id", "Details");
|
||||
$this->app->erp->MenuEintrag("index.php?module=mahnwesen&action=list", "Zurück zur Übersicht");
|
||||
$id = $this->app->Secure->GetGET('id');
|
||||
$input = $this->GetInput();
|
||||
$submit = $this->app->Secure->GetPOST('submit');
|
||||
|
||||
if (empty($id)) {
|
||||
// New item
|
||||
$id = 'NULL';
|
||||
}
|
||||
|
||||
if ($submit != '')
|
||||
{
|
||||
|
||||
// Write to database
|
||||
|
||||
// Add checks here
|
||||
|
||||
$columns = "id, ";
|
||||
$values = "$id, ";
|
||||
$update = "";
|
||||
|
||||
$fix = "";
|
||||
|
||||
foreach ($input as $key => $value) {
|
||||
$columns = $columns.$fix.$key;
|
||||
$values = $values.$fix."'".$value."'";
|
||||
$update = $update.$fix.$key." = '$value'";
|
||||
|
||||
$fix = ", ";
|
||||
}
|
||||
|
||||
// echo($columns."<br>");
|
||||
// echo($values."<br>");
|
||||
// echo($update."<br>");
|
||||
|
||||
$sql = "INSERT INTO mahnwesen (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update;
|
||||
|
||||
// echo($sql);
|
||||
|
||||
$this->app->DB->Update($sql);
|
||||
|
||||
if ($id == 'NULL') {
|
||||
$msg = $this->app->erp->base64_url_encode("<div class=\"success\">Das Element wurde erfolgreich angelegt.</div>");
|
||||
header("Location: index.php?module=mahnwesen&action=list&msg=$msg");
|
||||
} else {
|
||||
$this->app->Tpl->Set('MESSAGE', "<div class=\"success\">Die Einstellungen wurden erfolgreich übernommen.</div>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Load values again from database
|
||||
$dropnbox = "'<img src=./themes/new/images/details_open.png class=details>' AS `open`, CONCAT('<input type=\"checkbox\" name=\"auswahl[]\" value=\"',m.id,'\" />') AS `auswahl`";
|
||||
$result = $this->app->DB->SelectArr("SELECT SQL_CALC_FOUND_ROWS m.id, $dropnbox, m.name, m.rest, m.test, m.id FROM mahnwesen m"." WHERE id=$id");
|
||||
|
||||
foreach ($result[0] as $key => $value) {
|
||||
$this->app->Tpl->Set(strtoupper($key), $value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add displayed items later
|
||||
*
|
||||
|
||||
$this->app->Tpl->Add('KURZUEBERSCHRIFT2', $email);
|
||||
$this->app->Tpl->Add('EMAIL', $email);
|
||||
$this->app->Tpl->Add('ANGEZEIGTERNAME', $angezeigtername);
|
||||
*/
|
||||
|
||||
// $this->SetInput($input);
|
||||
$this->app->Tpl->Parse('PAGE', "mahnwesen_edit.tpl");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all paramters from html form and save into $input
|
||||
*/
|
||||
public function GetInput(): array {
|
||||
$input = array();
|
||||
//$input['EMAIL'] = $this->app->Secure->GetPOST('email');
|
||||
|
||||
$input['name'] = $this->app->Secure->GetPOST('name');
|
||||
$input['rest'] = $this->app->Secure->GetPOST('rest');
|
||||
$input['test'] = $this->app->Secure->GetPOST('test');
|
||||
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set all fields in the page corresponding to $input
|
||||
*/
|
||||
function SetInput($input) {
|
||||
// $this->app->Tpl->Set('EMAIL', $input['email']);
|
||||
|
||||
$this->app->Tpl->Set('NAME', $input['name']);
|
||||
$this->app->Tpl->Set('REST', $input['rest']);
|
||||
$this->app->Tpl->Set('TEST', $input['test']);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1816,7 +1816,7 @@ class Rechnung extends GenRechnung
|
||||
|
||||
if($bezahlt_am=='--')$bezahlt_am='0000-00-00';
|
||||
$alte_mahnstufe = $this->app->DB->Select("SELECT mahnwesen FROM rechnung WHERE id='$id' LIMIT 1");
|
||||
if($alte_mahnstufe!=$mahnwesen) $versendet=0; else $versendet=1;
|
||||
if($alte_mahnstufe!=$mahnwesen) $versendet=0;
|
||||
|
||||
/* if($mahnwesenfestsetzen=='1')
|
||||
{*/
|
||||
@ -2239,68 +2239,7 @@ class Rechnung extends GenRechnung
|
||||
} // ende ausfuehren
|
||||
|
||||
if($this->app->Secure->GetPOST('zahlungsstatus_berechnen') && $this->app->erp->RechteVorhanden('rechnung', 'edit')) {
|
||||
|
||||
// START RECALCULATE
|
||||
$this->app->erp->fibu_rebuild_tables();
|
||||
$offene_rechnungen = $this->app->DB->SelectArr(" SELECT
|
||||
id,
|
||||
soll,
|
||||
waehrung,
|
||||
datum,
|
||||
zahlungszieltage,
|
||||
DATE_ADD(datum, INTERVAL zahlungszieltage DAY) as zieldatum,
|
||||
CURRENT_DATE > DATE_ADD(datum, INTERVAL zahlungszieltage DAY) as faellig,
|
||||
zahlungszielskonto,
|
||||
TRUNCATE(soll*(1-(zahlungszielskonto/100)),2) as skontosoll,
|
||||
zahlungszieltageskonto,
|
||||
DATE_ADD(datum, INTERVAL zahlungszieltageskonto DAY) as zieldatumskonto
|
||||
FROM
|
||||
rechnung
|
||||
WHERE
|
||||
belegnr <> ''
|
||||
");
|
||||
|
||||
foreach ($offene_rechnungen as $offene_rechnung) {
|
||||
$saldo = $this->app->erp->GetSaldoDokument($offene_rechnung['id'],'rechnung');
|
||||
if (!empty($saldo)) {
|
||||
if ($saldo['waehrung'] == $offene_rechnung['waehrung']) {
|
||||
$offene_rechnung['ist'] = $offene_rechnung['soll']+$saldo['betrag'];
|
||||
// Check for skonto
|
||||
$skontorelevante_zahlungen = $this->app->erp->GetSaldoDokument($offene_rechnung['id'],'rechnung','zubuchung',$offene_rechnung['zieldatumskonto'])['betrag'];
|
||||
$zielkonforme_zahlungen = $this->app->erp->GetSaldoDokument($offene_rechnung['id'],'rechnung','zubuchung',$offene_rechnung['zieldatum'])['betrag'];
|
||||
// Check overall value
|
||||
if ($saldo['betrag'] == 0) {
|
||||
// ok -> will be marked as paid
|
||||
} else if ($skontorelevante_zahlungen >= $offene_rechnung['skontosoll']) {
|
||||
// Skonto ok -> book difference
|
||||
$sachkonto = $this->app->erp->Firmendaten('rechnung_skonto_kontorahmen');
|
||||
if (!empty($sachkonto)) {
|
||||
$this->app->erp->fibu_buchungen_buchen('rechnung',$offene_rechnung['id'],'kontorahmen',$sachkonto,-$saldo['betrag'],$offene_rechnung['waehrung'],'CURRENT_DATE','');
|
||||
$offene_rechnung['ist'] = $offene_rechnung['soll'];
|
||||
} else {
|
||||
}
|
||||
} else if ($offene_rechnung['faellig']) {
|
||||
// Overdue
|
||||
} else {
|
||||
// Not due
|
||||
}
|
||||
// Update rechnung
|
||||
$sql = "UPDATE
|
||||
rechnung
|
||||
SET
|
||||
ist = ".$saldo['betrag']."+soll,
|
||||
zahlungsstatus = IF(".$saldo['betrag']." = 0,'bezahlt','offen')
|
||||
WHERE id=".$offene_rechnung['id'];
|
||||
$this->app->DB->Update($sql);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->app->DB->Update("UPDATE rechnung SET ist = null WHERE id=".$offene_rechnung['id']);
|
||||
}
|
||||
}
|
||||
$this->app->erp->fibu_rebuild_tables();
|
||||
// END RECALCULATE
|
||||
|
||||
$this->rechnung_zahlstatus_berechnen();
|
||||
}
|
||||
|
||||
$this->app->Tpl->Set('UEBERSCHRIFT','Rechnungen');
|
||||
@ -2801,5 +2740,71 @@ class Rechnung extends GenRechnung
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recalculate the payments status with skonto
|
||||
*/
|
||||
|
||||
function rechnung_zahlstatus_berechnen() {
|
||||
// START RECALCULATE
|
||||
$this->app->erp->fibu_rebuild_tables();
|
||||
$offene_rechnungen = $this->app->DB->SelectArr(" SELECT
|
||||
id,
|
||||
soll,
|
||||
waehrung,
|
||||
datum,
|
||||
zahlungszieltage,
|
||||
DATE_ADD(datum, INTERVAL zahlungszieltage DAY) as zieldatum,
|
||||
CURRENT_DATE > DATE_ADD(datum, INTERVAL zahlungszieltage DAY) as faellig,
|
||||
zahlungszielskonto,
|
||||
TRUNCATE(soll*(1-(zahlungszielskonto/100)),2) as skontosoll,
|
||||
zahlungszieltageskonto,
|
||||
DATE_ADD(datum, INTERVAL zahlungszieltageskonto DAY) as zieldatumskonto
|
||||
FROM
|
||||
rechnung
|
||||
WHERE
|
||||
belegnr <> ''
|
||||
");
|
||||
|
||||
foreach ($offene_rechnungen as $offene_rechnung) {
|
||||
$saldo = $this->app->erp->GetSaldoDokument($offene_rechnung['id'],'rechnung');
|
||||
if (!empty($saldo)) {
|
||||
if ($saldo['waehrung'] == $offene_rechnung['waehrung']) {
|
||||
$offene_rechnung['ist'] = $offene_rechnung['soll']+$saldo['betrag'];
|
||||
// Check for skonto
|
||||
$skontorelevante_zahlungen = $this->app->erp->GetSaldoDokument($offene_rechnung['id'],'rechnung','zubuchung',$offene_rechnung['zieldatumskonto'])['betrag'];
|
||||
$zielkonforme_zahlungen = $this->app->erp->GetSaldoDokument($offene_rechnung['id'],'rechnung','zubuchung',$offene_rechnung['zieldatum'])['betrag'];
|
||||
// Check overall value
|
||||
if ($saldo['betrag'] == 0) {
|
||||
// ok -> will be marked as paid
|
||||
} else if ($skontorelevante_zahlungen >= $offene_rechnung['skontosoll']) {
|
||||
// Skonto ok -> book difference
|
||||
$sachkonto = $this->app->erp->Firmendaten('rechnung_skonto_kontorahmen');
|
||||
if (!empty($sachkonto)) {
|
||||
$this->app->erp->fibu_buchungen_buchen('rechnung',$offene_rechnung['id'],'kontorahmen',$sachkonto,-$saldo['betrag'],$offene_rechnung['waehrung'],'CURRENT_DATE','');
|
||||
$offene_rechnung['ist'] = $offene_rechnung['soll'];
|
||||
} else {
|
||||
}
|
||||
} else if ($offene_rechnung['faellig']) {
|
||||
// Overdue
|
||||
} else {
|
||||
// Not due
|
||||
}
|
||||
// Update rechnung
|
||||
$sql = "UPDATE
|
||||
rechnung
|
||||
SET
|
||||
ist = ".$saldo['betrag']."+soll,
|
||||
zahlungsstatus = IF(".$saldo['betrag']." = 0,'bezahlt','offen')
|
||||
WHERE id=".$offene_rechnung['id'];
|
||||
$this->app->DB->Update($sql);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->app->DB->Update("UPDATE rechnung SET ist = null WHERE id=".$offene_rechnung['id']);
|
||||
}
|
||||
}
|
||||
$this->app->erp->fibu_rebuild_tables();
|
||||
// END RECALCULATE
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user