Conf->WFconf['defaulttheme']}/images/delete.svg\" border=\"0\"> |
";
$sql = "SELECT SQL_CALC_FOUND_ROWS b.id, b.bezeichnung,CONCAT(UCASE(LEFT(b.belegtyp, 1)), SUBSTRING(b.belegtyp, 2)), pr.abkuerzung, b.id FROM belegevorlagen b LEFT JOIN projekt pr ON b.projekt = pr.id";
$where = $app->erp->ProjektRechte('b.projekt');
break;
case "belegevorlagen_list2":
$belegtyp = $app->Secure->GetGET('smodule');
$heading = array('Bezeichnung','Projekt','Menü');
$width = array('50%','49%','1%');
$findcols = array('b.bezeichnung','pr.abkuerzung','b.id');
$searchsql = array('b.bezeichnung','pr.abkuerzung');
$menu = "";
$sql = "SELECT SQL_CALC_FOUND_ROWS b.id, b.bezeichnung, pr.abkuerzung, b.id FROM belegevorlagen b LEFT JOIN projekt pr ON b.projekt = pr.id";
$where = "belegtyp = '$belegtyp' ".$app->erp->ProjektRechte('b.projekt');
break;
}
$erg = false;
foreach($erlaubtevars as $k => $v)
{
if(isset($$v))$erg[$v] = $$v;
}
return $erg;
}
function __construct(&$app, $intern = false)
{
$this->app=&$app;
$this->artikel = $this->app->erp->GetKonfiguration('gesamtrabatt_artikel');
if($intern)return;
$this->app->ActionHandlerInit($this);
$this->app->ActionHandler("list","BelegevorlagenList");
$this->app->ActionHandler("einstellungen","BelegevorlagenEinstellungen");
$this->app->DefaultActionHandler("list");
$this->app->ActionHandlerListen($app);
}
function BelegevorlagenMenu(){
$this->app->erp->MenuEintrag("index.php?module=belegevorlagen&action=list","Übersicht");
$this->app->erp->MenuEintrag("index.php?module=belegevorlagen&action=einstellungen","Einstellungen");
}
function BelegevorlagenList()
{
if($this->app->Secure->GetGET('cmd') == 'delvorlage')
{
$id = (int)$this->app->Secure->GetPOST('lid');
$this->app->DB->Delete("DELETE FROM belegevorlagen WHERE id = '$id' LIMIT 1");
echo json_encode(array('status'=>1));
exit;
}
$this->BelegevorlagenMenu();
$this->app->YUI->TableSearch('TAB1', "belegevorlagen_list", "show","","",basename(__FILE__), __CLASS__);
$this->app->Tpl->Parse('PAGE','belegevorlagen_list.tpl');
}
function BelegevorlagenEinstellungen()
{
$this->BelegevorlagenMenu();
$this->app->Tpl->Set('PREISEAKTUALISIEREN',$this->app->erp->GetKonfiguration('belegevorlagen_preiseaktualisieren')=='on'?'checked':'');
$this->app->YUI->AutoSaveKonfiguration('preiseaktualisieren','belegevorlagen_preiseaktualisieren');
$this->app->Tpl->Parse('PAGE','belegevorlagen_einstellungen.tpl');
}
function Install()
{
$this->app->erp->CheckTable('belegevorlagen');
$this->app->erp->CheckColumn("id","int(11)","belegevorlagen","DEFAULT '0' NOT NULL AUTO_INCREMENT");
$this->app->erp->CheckColumn("belegtyp", "varchar(255)", "belegevorlagen", "DEFAULT '' NOT NULL");
$this->app->erp->CheckColumn("bezeichnung", "varchar(255)", "belegevorlagen", "DEFAULT '' NOT NULL");
$this->app->erp->CheckColumn("projekt", "int(11)", "belegevorlagen", "DEFAULT '0' NOT NULL");
$this->app->erp->CheckColumn("json", "MEDIUMTEXT", "belegevorlagen", "DEFAULT '' NOT NULL");
$this->app->erp->CheckColumn("bearbeiter", "varchar(255)", "belegevorlagen", "DEFAULT '' NOT NULL");
$this->app->erp->CheckColumn("zeitstempel", "timestamp", "belegevorlagen","DEFAULT CURRENT_TIMESTAMP NOT NULL");
$this->app->erp->RegisterHook('BelegPositionenButtons', 'belegevorlagen', 'BelegevorlagenBelegPositionenButtons');
$this->app->erp->RegisterHook('AARLGPositionen_cmds_end', 'belegevorlagen', 'BelegevorlagenAARLGPositionen_cmds_end');
$this->app->erp->RegisterHook('ajax_filter_hook1', 'belegevorlagen', 'Belegevorlagenajax_filter_hook1');
}
function Belegevorlagenajax_filter_hook1($filtername,&$newarr, $term, $term2, $term3)
{
if($filtername == 'belegvorlagen')
{
$arr = $this->app->DB->SelectArr("SELECT CONCAT(b.id,' ',b.bezeichnung) as bezeichnung FROM belegevorlagen b
WHERE (b.bezeichnung LIKE '%$term%') ".$this->app->erp->ProjektRechte('b.projekt'));
if($arr)
{
for($i=0;$iapp->Tpl->Set('ID', $id);
$this->app->Tpl->Set('MODULE', $module);
$this->app->YUI->AutoComplete('bestehendevorlage','belegvorlagen');
$this->app->YUI->TableSearch('BELEGEVORLAGENTABELLE', "belegevorlagen_list2", "show","","",basename(__FILE__), __CLASS__);
$this->app->Tpl->Add($target, " ".$this->app->Tpl->Parse($target,'belegevorlagen_widget.tpl'));
}
}
function BelegevorlagenAARLGPositionen_cmds_end($id){
$module = $this->app->Secure->GetGET('module');
if(!$module)return;
$projekt = $this->app->DB->Select("SELECT projekt FROM $module WHERE id='$id' LIMIT 1");
if($projekt <=0) $projekt=0;
if($this->app->Secure->GetGET('cmd') == 'deletebelegvorlage')
{
$status = 1;
$lid = (int)$this->app->Secure->GetPOST('lid');
$this->app->DB->Delete("DELETE FROM belegevorlagen WHERE id = '$lid' AND belegtyp = '$module' LIMIT 1");
echo json_encode(array('status'=>$status));
exit;
}
if($this->app->Secure->GetGET('cmd') == 'loadbelegvorlage')
{
$status = 0;
$lid = (int)$this->app->Secure->GetPOST('lid');
$json = (String)$this->app->DB->Select("SELECT json FROM belegevorlagen WHERE id = '$lid' AND belegtyp = '$module' LIMIT 1");
if($json !== '')
{
$json = json_decode($json, true);
$maxsort = (int)$this->app->DB->Select("SELECT max(sort) FROM $module"."_position WHERE $module = '$id' LIMIT 1");
if(isset($json['positionen']))
{
foreach($json['positionen'] as $v)
{
$v[$module] = $id;
if($this->app->erp->GetKonfiguration('belegevorlagen_preiseaktualisieren')=='on'){
if($v['artikel'] != '0'){
$v['preis'] = $this->app->erp->GetVerkaufspreis($v['artikel'],$v['menge']);
}
}
$v['sort'] += $maxsort;
$this->app->DB->Insert("INSERT INTO $module"."_position (id) VALUES ('')");
$idnew = $this->app->DB->GetInsertID();
$oldtonew[$v['id']] = $idnew;
if($v['explodiert_parent'] && isset($oldtonew) && isset($oldtonew[$v['explodiert_parent']]))$v['explodiert_parent'] = $oldtonew[$v['explodiert_parent']];
unset($v['id']);
$this->app->DB->UpdateArr($module.'_position',$idnew,"id",$v, true);
if(is_null($v['steuersatz']))$this->app->DB->Update("UPDATE ".$module."_position SET steuersatz = NULL WHERE id = '$idnew' LIMIT 1");
}
}
if(isset($json['zwischenpositionen']))
{
$maxpos = $this->app->DB->SelectArr("SELECT id,sort FROM beleg_zwischenpositionen WHERE doctype = '$module' AND doctypeid = '$id' AND pos='$maxsort' ORDER BY sort DESC LIMIT 1");
if($maxpos)
{
$sortoffset = 1 + $maxpos[0]['sort'];
}else{
$sortoffset = 0;
}
foreach($json['zwischenpositionen'] as $v)
{
if($v['pos'] == 0)$v['sort'] += $sortoffset;
$v['doctypeid'] = $id;
$v['pos'] += $maxsort;
unset($v['id']);
$this->app->DB->Insert("INSERT INTO beleg_zwischenpositionen (id) VALUES ('')");
$idnew = $this->app->DB->GetInsertID();
$this->app->DB->UpdateArr('beleg_zwischenpositionen',$idnew,"id",$v, true);
}
}
$status = 1;
$this->app->erp->ANABREGSNeuberechnen($id,$module);
}
echo json_encode(array('status'=>$status));
exit;
}
if($this->app->Secure->GetGET('cmd') == 'savebelegevorlage')
{
$json = null;
$status = 0;
$bestehendevorlage = (int)reset(explode(' ',$this->app->Secure->GetPOST('bestehendevorlage')));
$bezeichnung = (String)$this->app->Secure->GetPOST('bezeichnung');
$vorlagetyp = $this->app->Secure->GetPOST('vorlagetyp');
$bearbeiter = $this->app->DB->real_escape_string($this->app->User->GetName());
$lid = null;
if($vorlagetyp == 'neu')
{
if($bezeichnung !== '')
{
$this->app->DB->Insert("INSERT INTO belegevorlagen (bezeichnung, belegtyp, bearbeiter, zeitstempel,projekt) VALUES ('$bezeichnung','$module','$bearbeiter',now(),'$projekt')");
$lid = $this->app->DB->GetInsertID();
}
}else{
$lid = $this->app->DB->Select("SELECT id FROM belegevorlagen WHERE id = '$bestehendevorlage' LIMIT 1");
if($lid && $bezeichnung !== '')$this->app->DB->Update("UPDATE belegevorlagen set bezeichnung = '$bezeichnung' WHERE id = '$bestehendevorlage' LIMIT 1");
}
if($lid)
{
$json['positionen'] = $this->app->DB->SelectArr("SELECT * FROM $module"."_position WHERE $module = '$id' ORDER BY sort");
$json['zwischenpositionen'] = $this->app->DB->SelectArr("SELECT * FROM beleg_zwischenpositionen WHERE doctype = '$module' AND doctypeid = '$id' ORDER BY pos, sort");
$json = $this->app->DB->real_escape_string(json_encode($json));
$this->app->DB->Update("UPDATE belegevorlagen set json = '$json', zeitstempel = now(), bearbeiter = '$bearbeiter' WHERE id = '$lid' LIMIT 1");
$status = 1;
}
echo json_encode(array('status'=>$status));
exit;
}
}
}
?>