app = $app; if ($id === null || $id === 0) return; $this->id = $id; $row = $this->app->DB->SelectRow("SELECT * FROM versandarten WHERE id=$this->id"); $this->type = $row['type']; $this->projectId = $row['projekt']; $this->labelPrinterId = $row['paketmarke_drucker']; $this->documentPrinterId = $row['export_drucker']; $this->shippingMail = $row['versandmail']; $this->businessLetterTemplateId = $row['geschaeftsbrief_vorlage']; $this->settings = json_decode($row['einstellungen_json']); } public function isEtikettenDrucker(): bool { return false; } public abstract function GetName(): string; public function GetAdressdaten($id, $sid): array { $auftragId = $lieferscheinId = $rechnungId = $versandId = 0; if ($sid === 'rechnung') $rechnungId = $id; if ($sid === 'lieferschein') { $lieferscheinId = $id; $auftragId = $this->app->DB->Select("SELECT auftragid FROM lieferschein WHERE id=$lieferscheinId LIMIT 1"); $rechnungId = $this->app->DB->Select("SELECT id FROM rechnung WHERE lieferschein = '$lieferscheinId' LIMIT 1"); if ($rechnungId <= 0) $rechnungId = $this->app->DB->Select("SELECT rechnungid FROM lieferschein WHERE id='$lieferscheinId' LIMIT 1"); } if ($auftragId <= 0 && $rechnungId > 0) $auftragId = $this->app->DB->Select("SELECT auftragid FROM rechnung WHERE id=$rechnungId LIMIT 1"); if ($sid === 'rechnung' || $sid === 'lieferschein' || $sid === 'adresse') { $docArr = $this->app->DB->SelectRow("SELECT * FROM `$sid` WHERE id = $id LIMIT 1"); $ret['addressId'] = $docArr['adresse']; $ret['auftragId'] = $auftragId; $ret['rechnungId'] = $rechnungId; $ret['lieferscheinId'] = $lieferscheinId; $addressfields = ['name', 'adresszusatz', 'abteilung', 'ansprechpartner', 'unterabteilung', 'ort', 'plz', 'strasse', 'land']; $ret['original'] = array_filter($docArr, fn($key) => in_array($key, $addressfields), ARRAY_FILTER_USE_KEY); $ret['name'] = empty(trim($docArr['ansprechpartner'])) ? trim($docArr['name']) : trim($docArr['ansprechpartner']); $ret['name2'] = !empty(trim($docArr['ansprechpartner'])) ? trim($docArr['name']) : ''; $ret['name3'] = join(';', array_filter([ $docArr['abteilung'], $docArr['unterabteilung'] ], fn(string $item) => !empty(trim($item)))); $ret['address2'] = $docArr['adresszusatz']; $ret['city'] = $docArr['ort']; $ret['zip'] = $docArr['plz']; $ret['country'] = $docArr['land']; $ret['phone'] = $docArr['telefon']; $ret['email'] = $docArr['email']; $ret['addresstype'] = 0; $strasse = trim($docArr['strasse']); $ret['streetwithnumber'] = $strasse; $hausnummer = trim($this->app->erp->ExtractStreetnumber($strasse)); $strasse = trim(str_replace($hausnummer, '', $strasse)); $strasse = str_replace('.', '', $strasse); if ($strasse == '') { $strasse = trim($hausnummer); $hausnummer = ''; } $ret['street'] = $strasse; $ret['streetnumber'] = $hausnummer; if (str_contains($docArr['strasse'], 'Packstation')) { $ret['addresstype'] = 1; $ret['parcelstationNumber'] = $hausnummer; } else if (str_contains($docArr['strasse'], 'Postfiliale')) { $ret['addresstype'] = 2; $ret['postofficeNumber'] = $hausnummer; } $tmp = join(' ', [$docArr['ansprechpartner'], $docArr['abteilung'], $docArr['unterabteilung']]); if (preg_match("/\d{6,10}/", $tmp, $match)) { $ret['postnumber'] = $match[0]; } if ($auftragId > 0) { $internet = $this->app->DB->Select("SELECT internet FROM auftrag WHERE id = $auftragId LIMIT 1"); if (!empty($internet)) $orderNumberParts[] = $internet; } if (!empty($docArr['ihrebestellnummer'])) { $orderNumberParts[] = $docArr['ihrebestellnummer']; } $orderNumberParts[] = ucfirst($sid)." ".$docArr['belegnr']; $ret['order_number'] = implode(' / ', $orderNumberParts); } // wenn rechnung im spiel entweder durch versand oder direkt rechnung if ($rechnungId > 0) { $invoice_data = $this->app->DB->SelectRow("SELECT zahlungsweise, soll, belegnr FROM rechnung WHERE id='$rechnungId' LIMIT 1"); $ret['zahlungsweise'] = $invoice_data['zahlungsweise']; $ret['betrag'] = $invoice_data['soll']; $ret['invoice_number'] = $invoice_data['belegnr']; if ($invoice_data['zahlungsweise'] === 'nachnahme') { $ret['nachnahme'] = true; } } $sql = "SELECT lp.bezeichnung, lp.menge, coalesce(nullif(lp.zolltarifnummer, '0'), nullif(rp.zolltarifnummer, '0'), nullif(a.zolltarifnummer, '')) as zolltarifnummer, coalesce(nullif(lp.herkunftsland, '0'), nullif(rp.herkunftsland, '0'), nullif(a.herkunftsland, '')) as herkunftsland, coalesce(nullif(lp.zolleinzelwert, '0'), rp.preis *(1-rp.rabatt/100), 0) as zolleinzelwert, coalesce(nullif(lp.zolleinzelgewicht, 0), a.gewicht) as zolleinzelgewicht, lp.zollwaehrung FROM lieferschein_position lp JOIN artikel a on lp.artikel = a.id LEFT OUTER JOIN auftrag_position ap on lp.auftrag_position_id = ap.id LEFT OUTER JOIN rechnung_position rp on ap.id = rp.auftrag_position_id LEFT OUTER JOIN rechnung r on rp.rechnung = r.id WHERE lp.lieferschein = $lieferscheinId AND a.lagerartikel = 1 AND r.status != 'storniert' ORDER BY lp.sort"; $ret['positions'] = $this->app->DB->SelectArr($sql) ?? []; if ($sid === "lieferschein") { $standardkg = $this->app->erp->VersandartMindestgewicht($lieferscheinId); } else { $standardkg = $this->app->erp->VersandartMindestgewicht(); } $ret['weight'] = $standardkg; return $ret; } /** * Returns an array of additional field definitions to be stored for this module: * [ * 'field_name' => [ * 'typ' => text(default)|textarea|checkbox|select * 'default' => default value * 'optionen' => just for selects [key=>value] * 'size' => size attribute for text fields * 'placeholder' => placeholder attribute for text fields * ] * ] * * @return array */ public function AdditionalSettings(): array { return []; } /** * Renders all additional settings as fields into $target * @param string $target template placeholder for rendered output * @param array $form data for form values (from database or form submit) * @return void */ public function RenderAdditionalSettings(string $target, array $form): void { $fields = $this->AdditionalSettings(); if ($this->app->Secure->GetPOST('speichern')) { $json = $this->app->DB->Select("SELECT einstellungen_json FROM versandarten WHERE id = '" . $this->id . "' LIMIT 1"); $modul = $this->app->DB->Select("SELECT modul FROM versandarten WHERE id = '" . $this->id . "' LIMIT 1"); if (!empty($json)) { $json = @json_decode($json, true); } else { $json = array(); foreach ($fields as $name => $val) { if (isset($val['default'])) { $json[$name] = $val['default']; } } } if (empty($json)) { $json = null; } foreach ($fields as $name => $val) { if ($modul === $this->app->Secure->GetPOST('modul_name')) { $json[$name] = $this->app->Secure->GetPOST($name, '', '', 1); } if (isset($val['replace'])) { switch ($val['replace']) { case 'lieferantennummer': $json[$name] = $this->app->erp->ReplaceLieferantennummer(1, $json[$name], 1); break; } } } $json_str = $this->app->DB->real_escape_string(json_encode($json)); $this->app->DB->Update("UPDATE versandarten SET einstellungen_json = '$json_str' WHERE id = '" . $this->id . "' LIMIT 1"); } $html = ''; foreach ($fields as $name => $val) // set missing default values { if (isset($val['default']) && !isset($form[$name])) { $form[$name] = $val['default']; } } foreach ($fields as $name => $val) { if (isset($val['heading'])) $html .= '