2022-11-14 22:29:42 +01:00
|
|
|
<?php
|
2023-02-28 13:36:25 +01:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2022 Andreas Palm
|
|
|
|
* SPDX-FileCopyrightText: 2019 Xentral (c) Xentral ERP Software GmbH, Fuggerstrasse 11, D-86150 Augsburg, Germany
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
|
|
|
*/
|
2022-11-14 22:29:42 +01:00
|
|
|
|
|
|
|
use Xentral\Modules\ShippingMethod\Model\CreateShipmentResult;
|
|
|
|
use Xentral\Modules\ShippingMethod\Model\CustomsInfo;
|
|
|
|
use Xentral\Modules\ShippingMethod\Model\Product;
|
|
|
|
|
|
|
|
abstract class Versanddienstleister
|
|
|
|
{
|
2022-10-27 13:17:19 +02:00
|
|
|
protected int $id;
|
2023-01-29 23:33:33 +01:00
|
|
|
protected ApplicationCore $app;
|
2022-10-27 13:17:19 +02:00
|
|
|
protected string $type;
|
|
|
|
protected int $projectId;
|
|
|
|
protected ?int $labelPrinterId;
|
|
|
|
protected ?int $documentPrinterId;
|
|
|
|
protected bool $shippingMail;
|
|
|
|
protected ?int $businessLetterTemplateId;
|
2022-10-30 23:02:42 +01:00
|
|
|
protected ?object $settings;
|
2022-10-27 13:17:19 +02:00
|
|
|
|
2023-01-29 23:33:33 +01:00
|
|
|
public function __construct(ApplicationCore $app, ?int $id)
|
2022-10-27 13:17:19 +02:00
|
|
|
{
|
|
|
|
$this->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']);
|
|
|
|
}
|
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
public function isEtikettenDrucker(): bool
|
|
|
|
{
|
2022-10-21 10:46:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
public abstract function GetName(): string;
|
|
|
|
|
|
|
|
public function GetAdressdaten($id, $sid): array
|
2021-05-21 08:49:41 +02:00
|
|
|
{
|
2022-10-29 21:38:28 +02:00
|
|
|
$auftragId = $lieferscheinId = $rechnungId = $versandId = 0;
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($sid === 'rechnung')
|
2022-10-21 10:46:09 +02:00
|
|
|
$rechnungId = $id;
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($sid === 'lieferschein') {
|
2022-10-29 21:38:28 +02:00
|
|
|
$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");
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($rechnungId <= 0)
|
2022-10-29 21:38:28 +02:00
|
|
|
$rechnungId = $this->app->DB->Select("SELECT rechnungid FROM lieferschein WHERE id='$lieferscheinId' LIMIT 1");
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($sid === 'versand') {
|
2022-10-29 21:38:28 +02:00
|
|
|
$versandId = $id;
|
|
|
|
$lieferscheinId = $this->app->DB->Select("SELECT lieferschein FROM versand WHERE id='$versandId' LIMIT 1");
|
2022-11-14 22:29:42 +01:00
|
|
|
$rechnungId = $this->app->DB->Select("SELECT rechnung FROM versand WHERE id='$versandId' LIMIT 1");
|
2021-05-21 08:49:41 +02:00
|
|
|
$sid = 'lieferschein';
|
|
|
|
}
|
|
|
|
|
2022-10-29 21:38:28 +02:00
|
|
|
if ($auftragId <= 0 && $rechnungId > 0)
|
|
|
|
$auftragId = $this->app->DB->Select("SELECT auftragid FROM rechnung WHERE id=$rechnungId LIMIT 1");
|
2021-05-21 08:49:41 +02:00
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($sid === 'rechnung' || $sid === 'lieferschein' || $sid === 'adresse') {
|
2022-10-29 21:38:28 +02:00
|
|
|
$docArr = $this->app->DB->SelectRow("SELECT * FROM `$sid` WHERE id = $id LIMIT 1");
|
2022-11-14 22:29:42 +01:00
|
|
|
$ret['addressId'] = $docArr['adresse'];
|
|
|
|
$ret['auftragId'] = $auftragId;
|
|
|
|
$ret['rechnungId'] = $rechnungId;
|
|
|
|
$ret['lieferscheinId'] = $lieferscheinId;
|
2022-10-29 21:38:28 +02:00
|
|
|
|
|
|
|
$addressfields = ['name', 'adresszusatz', 'abteilung', 'ansprechpartner', 'unterabteilung', 'ort', 'plz',
|
2023-10-18 14:35:35 +02:00
|
|
|
'strasse', 'land'];
|
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
$ret['original'] = array_filter($docArr, fn($key) => in_array($key, $addressfields), ARRAY_FILTER_USE_KEY);
|
2021-05-21 08:49:41 +02:00
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
$ret['name'] = empty(trim($docArr['ansprechpartner'])) ? trim($docArr['name']) : trim($docArr['ansprechpartner']);
|
2022-11-22 00:21:57 +01:00
|
|
|
$ret['name2'] = !empty(trim($docArr['ansprechpartner'])) ? trim($docArr['name']) : '';
|
|
|
|
$ret['name3'] = join(';', array_filter([
|
2022-11-14 22:29:42 +01:00
|
|
|
$docArr['abteilung'],
|
2022-11-22 00:21:57 +01:00
|
|
|
$docArr['unterabteilung']
|
2022-11-14 22:29:42 +01:00
|
|
|
], fn(string $item) => !empty(trim($item))));
|
2022-11-22 00:21:57 +01:00
|
|
|
$ret['address2'] = $docArr['adresszusatz'];
|
2022-11-14 22:29:42 +01:00
|
|
|
|
|
|
|
$ret['city'] = $docArr['ort'];
|
|
|
|
$ret['zip'] = $docArr['plz'];
|
|
|
|
$ret['country'] = $docArr['land'];
|
|
|
|
$ret['phone'] = $docArr['telefon'];
|
|
|
|
$ret['email'] = $docArr['email'];
|
2022-11-22 00:21:57 +01:00
|
|
|
$ret['addresstype'] = 0;
|
2021-05-21 08:49:41 +02:00
|
|
|
|
2022-10-21 10:46:09 +02:00
|
|
|
$strasse = trim($docArr['strasse']);
|
2022-10-29 21:38:28 +02:00
|
|
|
$ret['streetwithnumber'] = $strasse;
|
2021-05-21 08:49:41 +02:00
|
|
|
$hausnummer = trim($this->app->erp->ExtractStreetnumber($strasse));
|
2022-11-14 22:29:42 +01:00
|
|
|
$strasse = trim(str_replace($hausnummer, '', $strasse));
|
|
|
|
$strasse = str_replace('.', '', $strasse);
|
2021-05-21 08:49:41 +02:00
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($strasse == '') {
|
2021-05-21 08:49:41 +02:00
|
|
|
$strasse = trim($hausnummer);
|
|
|
|
$hausnummer = '';
|
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
$ret['street'] = $strasse;
|
|
|
|
$ret['streetnumber'] = $hausnummer;
|
2022-11-22 00:21:57 +01:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:12:01 +01:00
|
|
|
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'];
|
|
|
|
}
|
2023-10-26 20:46:07 +02:00
|
|
|
$orderNumberParts[] = ucfirst($sid)." ".$docArr['belegnr'];
|
2023-01-31 12:12:01 +01:00
|
|
|
$ret['order_number'] = implode(' / ', $orderNumberParts);
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
2022-10-29 21:38:28 +02:00
|
|
|
|
2021-05-21 08:49:41 +02:00
|
|
|
// wenn rechnung im spiel entweder durch versand oder direkt rechnung
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($rechnungId > 0) {
|
|
|
|
$invoice_data = $this->app->DB->SelectRow("SELECT zahlungsweise, soll, belegnr FROM rechnung WHERE id='$rechnungId' LIMIT 1");
|
2022-10-21 10:46:09 +02:00
|
|
|
$ret['zahlungsweise'] = $invoice_data['zahlungsweise'];
|
|
|
|
$ret['betrag'] = $invoice_data['soll'];
|
|
|
|
$ret['invoice_number'] = $invoice_data['belegnr'];
|
2021-05-21 08:49:41 +02:00
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($invoice_data['zahlungsweise'] === 'nachnahme') {
|
2022-10-21 10:46:09 +02:00
|
|
|
$ret['nachnahme'] = true;
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 21:38:28 +02:00
|
|
|
$sql = "SELECT
|
|
|
|
lp.bezeichnung,
|
|
|
|
lp.menge,
|
2023-02-05 22:15:54 +01:00
|
|
|
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,
|
2023-01-31 12:12:01 +01:00
|
|
|
coalesce(nullif(lp.zolleinzelwert, '0'), rp.preis *(1-rp.rabatt/100), 0) as zolleinzelwert,
|
2022-11-14 22:29:42 +01:00
|
|
|
coalesce(nullif(lp.zolleinzelgewicht, 0), a.gewicht) as zolleinzelgewicht,
|
2022-10-29 21:38:28 +02:00
|
|
|
lp.zollwaehrung
|
|
|
|
FROM lieferschein_position lp
|
|
|
|
JOIN artikel a on lp.artikel = a.id
|
2023-03-23 23:22:45 +01:00
|
|
|
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
|
2022-10-29 21:38:28 +02:00
|
|
|
WHERE lp.lieferschein = $lieferscheinId
|
2023-02-05 22:15:54 +01:00
|
|
|
AND a.lagerartikel = 1
|
|
|
|
AND r.status != 'storniert'
|
2022-10-29 21:38:28 +02:00
|
|
|
ORDER BY lp.sort";
|
2023-03-23 23:22:45 +01:00
|
|
|
$ret['positions'] = $this->app->DB->SelectArr($sql) ?? [];
|
2021-05-21 08:49:41 +02:00
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($sid === "lieferschein") {
|
2022-10-21 10:46:09 +02:00
|
|
|
$standardkg = $this->app->erp->VersandartMindestgewicht($lieferscheinId);
|
2022-11-14 22:29:42 +01:00
|
|
|
} else {
|
2021-05-21 08:49:41 +02:00
|
|
|
$standardkg = $this->app->erp->VersandartMindestgewicht();
|
|
|
|
}
|
2022-10-29 21:38:28 +02:00
|
|
|
$ret['weight'] = $standardkg;
|
2021-05-21 08:49:41 +02:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-27 13:17:19 +02:00
|
|
|
* 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
|
|
|
|
* ]
|
|
|
|
* ]
|
2021-05-21 08:49:41 +02:00
|
|
|
*
|
2022-10-27 13:17:19 +02:00
|
|
|
* @return array
|
|
|
|
*/
|
2022-11-14 22:29:42 +01:00
|
|
|
public function AdditionalSettings(): array
|
|
|
|
{
|
2022-10-27 13:17:19 +02:00
|
|
|
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
|
2021-05-21 08:49:41 +02:00
|
|
|
*/
|
2022-10-27 13:17:19 +02:00
|
|
|
public function RenderAdditionalSettings(string $target, array $form): void
|
2021-05-21 08:49:41 +02:00
|
|
|
{
|
2022-10-27 13:17:19 +02:00
|
|
|
$fields = $this->AdditionalSettings();
|
2022-11-14 22:29:42 +01:00
|
|
|
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)) {
|
2021-05-21 08:49:41 +02:00
|
|
|
$json = @json_decode($json, true);
|
2022-11-14 22:29:42 +01:00
|
|
|
} else {
|
2021-05-21 08:49:41 +02:00
|
|
|
$json = array();
|
2022-11-14 22:29:42 +01:00
|
|
|
foreach ($fields as $name => $val) {
|
|
|
|
if (isset($val['default'])) {
|
2021-05-21 08:49:41 +02:00
|
|
|
$json[$name] = $val['default'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
if (empty($json)) {
|
2021-05-21 08:49:41 +02:00
|
|
|
$json = null;
|
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
foreach ($fields as $name => $val) {
|
2021-05-21 08:49:41 +02:00
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
if ($modul === $this->app->Secure->GetPOST('modul_name')) {
|
|
|
|
$json[$name] = $this->app->Secure->GetPOST($name, '', '', 1);
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
|
|
|
|
if (isset($val['replace'])) {
|
|
|
|
switch ($val['replace']) {
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'lieferantennummer':
|
2022-11-14 22:29:42 +01:00
|
|
|
$json[$name] = $this->app->erp->ReplaceLieferantennummer(1, $json[$name], 1);
|
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$json_str = $this->app->DB->real_escape_string(json_encode($json));
|
2022-11-14 22:29:42 +01:00
|
|
|
$this->app->DB->Update("UPDATE versandarten SET einstellungen_json = '$json_str' WHERE id = '" . $this->id . "' LIMIT 1");
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
|
|
|
$html = '';
|
2022-11-14 22:29:42 +01:00
|
|
|
|
|
|
|
foreach ($fields as $name => $val) // set missing default values
|
2021-05-21 08:49:41 +02:00
|
|
|
{
|
2022-11-14 22:29:42 +01:00
|
|
|
if (isset($val['default']) && !isset($form[$name])) {
|
2022-10-27 13:17:19 +02:00
|
|
|
$form[$name] = $val['default'];
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
foreach ($fields as $name => $val) {
|
|
|
|
if (isset($val['heading']))
|
|
|
|
$html .= '<tr><td colspan="2"><b>' . html_entity_decode($val['heading']) . '</b></td></tr>';
|
|
|
|
|
|
|
|
$html .= '<tr><td>' . ($val['bezeichnung'] ?? $name) . '</td><td>';
|
|
|
|
if (isset($val['replace'])) {
|
|
|
|
switch ($val['replace']) {
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'lieferantennummer':
|
2022-11-14 22:29:42 +01:00
|
|
|
$form[$name] = $this->app->erp->ReplaceLieferantennummer(0, $form[$name], 0);
|
2022-10-27 13:17:19 +02:00
|
|
|
$this->app->YUI->AutoComplete($name, 'lieferant', 1);
|
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'shop':
|
2022-11-14 22:29:42 +01:00
|
|
|
$form[$name] .= ($form[$name] ? ' ' . $this->app->DB->Select("SELECT bezeichnung FROM shopexport WHERE id = '" . (int)$form[$name] . "'") : '');
|
2022-10-27 13:17:19 +02:00
|
|
|
$this->app->YUI->AutoComplete($name, 'shopnameid');
|
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'etiketten':
|
2022-10-27 13:17:19 +02:00
|
|
|
$this->app->YUI->AutoComplete($name, 'etiketten');
|
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
switch ($val['typ'] ?? 'text') {
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'textarea':
|
2022-11-14 22:29:42 +01:00
|
|
|
$html .= '<textarea name="' . $name . '" id="' . $name . '">' . ($form[$name] ?? '') . '</textarea>';
|
2022-10-27 13:17:19 +02:00
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'checkbox':
|
2022-11-14 22:29:42 +01:00
|
|
|
$html .= '<input type="checkbox" name="' . $name . '" id="' . $name . '" value="1" ' . ($form[$name] ?? false ? ' checked="checked" ' : '') . ' />';
|
2022-10-27 13:17:19 +02:00
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'select':
|
2022-10-27 13:17:19 +02:00
|
|
|
$html .= $this->app->Tpl->addSelect('return', $name, $name, $val['optionen'], $form[$name]);
|
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'submit':
|
2022-11-14 22:29:42 +01:00
|
|
|
if (isset($val['text']))
|
|
|
|
$html .= '<form method="POST"><input type="submit" name="' . $name . '" value="' . $val['text'] . '"></form>';
|
2022-10-27 13:17:19 +02:00
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
case 'custom':
|
2022-11-14 22:29:42 +01:00
|
|
|
if (isset($val['function'])) {
|
2021-05-21 08:49:41 +02:00
|
|
|
$tmpfunction = $val['function'];
|
2022-11-14 22:29:42 +01:00
|
|
|
if (method_exists($this, $tmpfunction)) {
|
2021-05-21 08:49:41 +02:00
|
|
|
$html .= $this->$tmpfunction();
|
|
|
|
}
|
|
|
|
}
|
2022-10-27 13:17:19 +02:00
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
default:
|
2022-10-27 13:17:19 +02:00
|
|
|
$html .= '<input type="text"'
|
2022-11-14 22:29:42 +01:00
|
|
|
. (!empty($val['size']) ? ' size="' . $val['size'] . '"' : '')
|
|
|
|
. (!empty($val['placeholder']) ? ' placeholder="' . $val['placeholder'] . '"' : '')
|
|
|
|
. ' name="' . $name . '" id="' . $name . '" value="' . (isset($form[$name]) ? htmlspecialchars($form[$name]) : '') . '" />';
|
|
|
|
break;
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
if (isset($val['info']) && $val['info'])
|
|
|
|
$html .= ' <i>' . $val['info'] . '</i>';
|
|
|
|
|
2021-05-21 08:49:41 +02:00
|
|
|
$html .= '</td></tr>';
|
|
|
|
}
|
|
|
|
$this->app->Tpl->Add($target, $html);
|
|
|
|
}
|
|
|
|
|
2022-10-27 13:17:19 +02:00
|
|
|
/**
|
|
|
|
* Validate form data for this module
|
|
|
|
* Form data is passed by reference so replacements (id instead of text) can be performed here as well
|
|
|
|
* @param array $form submitted form data
|
|
|
|
* @return array
|
|
|
|
*/
|
2022-10-29 21:38:28 +02:00
|
|
|
public function ValidateSettings(array &$form): array
|
2021-05-21 08:49:41 +02:00
|
|
|
{
|
2022-11-14 22:29:42 +01:00
|
|
|
return [];
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $tracking
|
2022-11-14 22:29:42 +01:00
|
|
|
* @param int $versand
|
|
|
|
* @param int $lieferschein
|
2021-05-21 08:49:41 +02:00
|
|
|
*/
|
2022-11-14 22:29:42 +01:00
|
|
|
public function SetTracking($tracking, $versand = 0, $lieferschein = 0, $trackingLink = '')
|
2021-05-21 08:49:41 +02:00
|
|
|
{
|
|
|
|
//if($versand > 0) $this->app->DB->Update("UPDATE versand SET tracking=CONCAT(tracking,if(tracking!='',';',''),'".$tracking."') WHERE id='$versand' LIMIT 1");
|
2022-11-14 22:29:42 +01:00
|
|
|
$this->app->User->SetParameter('versand_lasttracking', $tracking);
|
|
|
|
$this->app->User->SetParameter('versand_lasttracking_link', $trackingLink);
|
2021-05-21 08:49:41 +02:00
|
|
|
$this->app->User->SetParameter('versand_lasttracking_versand', $versand);
|
|
|
|
$this->app->User->SetParameter('versand_lasttracking_lieferschein', $lieferschein);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $tracking
|
|
|
|
*/
|
|
|
|
public function deleteTrackingFromUserdata($tracking)
|
|
|
|
{
|
2022-11-14 22:29:42 +01:00
|
|
|
if (empty($tracking)) {
|
2021-05-21 08:49:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
$trackingUser = !empty($this->app->User) && method_exists($this->app->User, 'GetParameter') ?
|
|
|
|
$this->app->User->GetParameter('versand_lasttracking') : '';
|
|
|
|
if (empty($trackingUser) || $trackingUser !== $tracking) {
|
2021-05-21 08:49:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
$this->app->User->SetParameter('versand_lasttracking', '');
|
|
|
|
$this->app->User->SetParameter('versand_lasttracking_link', '');
|
2021-05-21 08:49:41 +02:00
|
|
|
$this->app->User->SetParameter('versand_lasttracking_versand', '');
|
|
|
|
$this->app->User->SetParameter('versand_lasttracking_lieferschein', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $tracking
|
|
|
|
*
|
|
|
|
* @return string mixed
|
|
|
|
*/
|
|
|
|
public function TrackingReplace($tracking)
|
|
|
|
{
|
|
|
|
return $tracking;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $tracking
|
2022-11-14 22:29:42 +01:00
|
|
|
* @param int $notsend
|
2021-05-21 08:49:41 +02:00
|
|
|
* @param string $link
|
|
|
|
* @param string $rawlink
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-11-14 22:29:42 +01:00
|
|
|
public function Trackinglink($tracking, &$notsend, &$link, &$rawlink)
|
|
|
|
{
|
2021-05-21 08:49:41 +02:00
|
|
|
$notsend = 0;
|
|
|
|
$rawlink = '';
|
|
|
|
$link = '';
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-21 10:46:09 +02:00
|
|
|
|
2023-10-20 15:47:37 +02:00
|
|
|
public function Paketmarke(string $target, string $docType, int $docId, $versandpaket = null): void
|
2022-11-14 22:29:42 +01:00
|
|
|
{
|
|
|
|
$address = $this->GetAdressdaten($docId, $docType);
|
2023-01-29 21:11:12 +01:00
|
|
|
if (isset($_SERVER['CONTENT_TYPE']) && ($_SERVER['CONTENT_TYPE'] === 'application/json')) {
|
2022-11-14 22:29:42 +01:00
|
|
|
$json = json_decode(file_get_contents('php://input'));
|
|
|
|
$ret = [];
|
|
|
|
if ($json->submit == 'print') {
|
|
|
|
$result = $this->CreateShipment($json, $address);
|
|
|
|
if ($result->Success) {
|
2023-10-20 15:47:37 +02:00
|
|
|
if (empty($versandpaket)) {
|
|
|
|
$sql = "INSERT INTO versandpakete
|
|
|
|
(
|
|
|
|
lieferschein_ohne_pos,
|
|
|
|
gewicht,
|
|
|
|
tracking,
|
|
|
|
tracking_link,
|
|
|
|
status,
|
|
|
|
versandart,
|
|
|
|
versender
|
|
|
|
)
|
|
|
|
VALUES
|
|
|
|
(
|
|
|
|
{$address['lieferscheinId']},
|
|
|
|
'$json->weight',
|
|
|
|
'$result->TrackingNumber',
|
|
|
|
'$result->TrackingUrl',
|
|
|
|
'neu',
|
|
|
|
'$this->type',
|
|
|
|
'".$this->app->User->GetName()."'
|
|
|
|
)";
|
|
|
|
$this->app->DB->Insert($sql);
|
|
|
|
$versandpaket = $this->app->DB->GetInsertID();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sql = "UPDATE versandpakete SET
|
|
|
|
gewicht = '".$json->weight."',
|
|
|
|
tracking = '".$result->TrackingNumber."',
|
|
|
|
tracking_link = '".$result->TrackingUrl."'
|
|
|
|
WHERE id = '".$versandpaket."'
|
|
|
|
";
|
|
|
|
$this->app->DB->Update($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
$filename = join('_', [$this->type, 'Label', $result->TrackingNumber]) . '.pdf';
|
|
|
|
$filefullpath = $this->app->erp->GetTMP() . $filename;
|
|
|
|
file_put_contents($filefullpath, $result->Label);
|
|
|
|
$this->app->erp->CreateDateiWithStichwort(
|
|
|
|
$filename,
|
|
|
|
'Paketmarke '.$this->type.' '.$result->TrackingNumber,
|
|
|
|
'Paketmarke Versandpaket Nr. '.$versandpaket,
|
|
|
|
'',
|
|
|
|
$filefullpath,
|
|
|
|
$this->app->User->GetName(),
|
|
|
|
'paketmarke',
|
|
|
|
'versandpaket',
|
|
|
|
$versandpaket
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->app->printer->Drucken($this->labelPrinterId, $filefullpath);
|
|
|
|
|
|
|
|
if (isset($result->ExportDocuments)) {
|
|
|
|
$filefullpath = $this->app->erp->GetTMP() . join('_', [$this->type, 'ExportDoc', $result->TrackingNumber]) . '.pdf';
|
|
|
|
file_put_contents($filefullpath, $result->ExportDocuments);
|
|
|
|
$this->app->printer->Drucken($this->documentPrinterId, $filefullpath);
|
|
|
|
}
|
|
|
|
$ret['messages'][] = ['class' => 'info', 'text' => "Paketmarke wurde erfolgreich erstellt: $result->TrackingNumber"];
|
2022-11-14 22:29:42 +01:00
|
|
|
} else {
|
2023-10-20 15:47:37 +02:00
|
|
|
$ret['messages'] = array_map(fn(string $item) => ['class' => 'error', 'text' => $item], array_unique($result->Errors));
|
2022-11-14 22:29:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($ret);
|
|
|
|
$this->app->ExitXentral();
|
|
|
|
}
|
|
|
|
|
2023-02-01 15:42:03 +01:00
|
|
|
$address['shipment_type'] = CustomsInfo::CUSTOMS_TYPE_GOODS;
|
2022-11-14 22:29:42 +01:00
|
|
|
$products = $this->GetShippingProducts();
|
|
|
|
$products = array_combine(array_column($products, 'Id'), $products);
|
|
|
|
$address['product'] = $products[0]->Id ?? '';
|
2022-10-21 10:46:09 +02:00
|
|
|
|
2023-03-30 22:24:40 +02:00
|
|
|
$countries = $this->app->DB->SelectArr("SELECT iso, bezeichnung_de name, eu FROM laender ORDER BY bezeichnung_de");
|
2023-10-22 18:41:08 +02:00
|
|
|
if(!empty($countries)) {
|
|
|
|
$countries = array_combine(array_column($countries, 'iso'), $countries);
|
|
|
|
} else {
|
|
|
|
$countries = Array();
|
|
|
|
$this->app->Tpl->addMessage('error', 'Länderliste ist leer. Siehe Einstellungen -> Länderliste.', false, 'PAGE');
|
|
|
|
}
|
2023-03-30 22:24:40 +02:00
|
|
|
|
2022-11-14 22:29:42 +01:00
|
|
|
$json['form'] = $address;
|
2023-03-30 22:24:40 +02:00
|
|
|
$json['countries'] = $countries;
|
2022-11-14 22:29:42 +01:00
|
|
|
$json['products'] = $products;
|
|
|
|
$json['customs_shipment_types'] = [
|
|
|
|
CustomsInfo::CUSTOMS_TYPE_GIFT => 'Geschenk',
|
|
|
|
CustomsInfo::CUSTOMS_TYPE_DOCUMENTS => 'Dokumente',
|
|
|
|
CustomsInfo::CUSTOMS_TYPE_GOODS => 'Handelswaren',
|
|
|
|
CustomsInfo::CUSTOMS_TYPE_SAMPLE => 'Erprobungswaren',
|
|
|
|
CustomsInfo::CUSTOMS_TYPE_RETURN => 'Rücksendung'
|
|
|
|
];
|
|
|
|
$json['messages'] = [];
|
2024-03-27 00:14:39 +01:00
|
|
|
$json['submitting'] = false;
|
2022-11-14 22:29:42 +01:00
|
|
|
$json['form']['services'] = [
|
|
|
|
Product::SERVICE_PREMIUM => false
|
|
|
|
];
|
|
|
|
$this->app->Tpl->Set('JSON', json_encode($json));
|
|
|
|
$this->app->Tpl->Set('CARRIERNAME', $this->GetName());
|
|
|
|
$this->app->Tpl->Parse($target, 'createshipment.tpl');
|
2022-10-21 10:46:09 +02:00
|
|
|
}
|
2022-11-14 22:29:42 +01:00
|
|
|
|
|
|
|
public abstract function CreateShipment(object $json, array $address): CreateShipmentResult;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Product[]
|
|
|
|
*/
|
|
|
|
public abstract function GetShippingProducts(): array;
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|