From 6a2a16c0a685ad372f540f09aa1d096adfa35b43 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sat, 29 Oct 2022 21:38:28 +0200 Subject: [PATCH] Sendcloud bugfixes and improvements --- .../Carrier/SendCloud/Data/ParcelCreation.php | 2 +- classes/Carrier/SendCloud/Data/ParcelItem.php | 17 +- classes/Carrier/SendCloud/SendCloudApi.php | 15 +- www/lib/class.versanddienstleister.php | 111 +++---- .../content/versandarten_sendcloud.tpl | 296 ++++++++++++++---- www/lib/versandarten/sendcloud.php | 137 ++++---- www/pages/versandarten.php | 19 +- 7 files changed, 383 insertions(+), 214 deletions(-) diff --git a/classes/Carrier/SendCloud/Data/ParcelCreation.php b/classes/Carrier/SendCloud/Data/ParcelCreation.php index b234ed4c..f975ef9a 100644 --- a/classes/Carrier/SendCloud/Data/ParcelCreation.php +++ b/classes/Carrier/SendCloud/Data/ParcelCreation.php @@ -29,7 +29,7 @@ class ParcelCreation extends ParcelBase 'customs_invoice_nr' => $this->CustomsInvoiceNr, 'customs_shipment_type' => $this->CustomsShipmentType, 'external_reference' => $this->ExternalReference, - 'total_insured_value' => $this->TotalInsuredValue, + 'total_insured_value' => $this->TotalInsuredValue ?? 0, 'parcel_items' => array_map(fn(ParcelItem $item)=>$item->toApiRequest(), $this->ParcelItems), 'is_return' => $this->IsReturn, 'length' => $this->Length, diff --git a/classes/Carrier/SendCloud/Data/ParcelItem.php b/classes/Carrier/SendCloud/Data/ParcelItem.php index e85439f9..6fe870fe 100644 --- a/classes/Carrier/SendCloud/Data/ParcelItem.php +++ b/classes/Carrier/SendCloud/Data/ParcelItem.php @@ -14,9 +14,8 @@ class ParcelItem public string $Description; public string $OriginCountry; public float $Price; - public string $PriceCurrency; - public string $Sku; - public string $ProductId; + public ?string $Sku = null; + public ?string $ProductId = null; public function toApiRequest(): array { return [ @@ -24,13 +23,10 @@ class ParcelItem 'weight' => number_format($this->Weight / 1000, 3, '.', null), 'quantity' => $this->Quantity, 'description' => $this->Description, - 'price' => [ - 'value' => $this->Price, - 'currency' => $this->PriceCurrency, - ], + 'value' => $this->Price, 'origin_country' => $this->OriginCountry, - 'sku' => $this->Sku, - 'product_id' => $this->ProductId, + 'sku' => $this->Sku ?? '', + 'product_id' => $this->ProductId ?? '', ]; } @@ -41,8 +37,7 @@ class ParcelItem $obj->Weight = intval(floatval($data->weight)*1000); $obj->Quantity = $data->quantity; $obj->Description = $data->description; - $obj->Price = $data->price->value; - $obj->PriceCurrency = $data->price->currency; + $obj->Price = $data->value; $obj->OriginCountry = $data->origin_country; $obj->Sku = $data->sku; $obj->ProductId = $data->product_id; diff --git a/classes/Carrier/SendCloud/SendCloudApi.php b/classes/Carrier/SendCloud/SendCloudApi.php index e4c79f8b..9099f8de 100644 --- a/classes/Carrier/SendCloud/SendCloudApi.php +++ b/classes/Carrier/SendCloud/SendCloudApi.php @@ -63,19 +63,20 @@ class SendCloudApi return array_map(fn($x) => ShippingProduct::fromApiResponse($x), $response ?? []); } - /** - * @throws Exception - */ public function CreateParcel(ParcelCreation $parcel): ParcelResponse|string|null { $uri = self::PROD_BASE_URI . '/parcels'; $response = $this->sendRequest($uri, null, true, [ 'parcel' => $parcel->toApiRequest() ]); - if (isset($response->parcel)) - return ParcelResponse::fromApiResponse($response->parcel); - if (isset($response->error)) - return $response->error->message; + try { + if (isset($response->parcel)) + return ParcelResponse::fromApiResponse($response->parcel); + if (isset($response->error)) + return $response->error->message; + } catch (Exception $e) { + return $e->getMessage(); + } return null; } diff --git a/www/lib/class.versanddienstleister.php b/www/lib/class.versanddienstleister.php index 12507829..567e2b75 100644 --- a/www/lib/class.versanddienstleister.php +++ b/www/lib/class.versanddienstleister.php @@ -26,49 +26,41 @@ abstract class Versanddienstleister { $this->settings = json_decode($row['einstellungen_json']); } - public function isEtikettenDrucker(): bool { return false; } public function GetAdressdaten($id, $sid) { - if($sid==='rechnung'){ + $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"); } - else - { - $rechnungId =''; - } - if($sid==='versand') { - $lieferscheinId = $this->app->DB->Select("SELECT lieferschein FROM versand WHERE id='$id' LIMIT 1"); - $rechnungId = $this->app->DB->Select("SELECT rechnung FROM versand WHERE id='$id' LIMIT 1"); + $versandId = $id; + $lieferscheinId = $this->app->DB->Select("SELECT lieferschein FROM versand WHERE id='$versandId' LIMIT 1"); + $rechnungId = $this->app->DB->Select("SELECT rechnung FROM versand WHERE id='$versandId' LIMIT 1"); $sid = 'lieferschein'; - } else { - $lieferscheinId = $id; - if($sid === 'lieferschein'){ - $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"); - } } - $ret['lieferscheinId'] = $lieferscheinId; - $ret['rechnungId'] = $rechnungId; - if($rechnungId){ - $artikel_positionen = $this->app->DB->SelectArr("SELECT * FROM rechnung_position WHERE rechnung='$rechnungId'"); - } else { - $artikel_positionen = $this->app->DB->SelectArr(sprintf('SELECT * FROM `%s` WHERE `%s` = %d',$sid.'_position',$sid,$lieferscheinId)); - } + 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 = $lieferscheinId LIMIT 1"); + $docArr = $this->app->DB->SelectRow("SELECT * FROM `$sid` WHERE id = $id LIMIT 1"); + + $addressfields = ['name', 'adresszusatz', 'abteilung', 'ansprechpartner', 'unterabteilung', 'ort', 'plz', + 'strasse', 'land', 'telefon', 'email']; + $ret = array_filter($docArr, fn($key)=>in_array($key, $addressfields), ARRAY_FILTER_USE_KEY); - $name = trim($docArr['name']); $name2 = trim($docArr['adresszusatz']); $abt = 0; if($name2==='') @@ -92,14 +84,12 @@ abstract class Versanddienstleister { $name2=$name3; $name3=''; } + $ret['name2'] = $name2; + $ret['name3'] = $name3; - $ort = trim($docArr['ort']); - $plz = trim($docArr['plz']); - $land = trim($docArr['land']); $strasse = trim($docArr['strasse']); - $strassekomplett = $strasse; + $ret['streetwithnumber'] = $strasse; $hausnummer = trim($this->app->erp->ExtractStreetnumber($strasse)); - $strasse = trim(str_replace($hausnummer,'',$strasse)); $strasse = str_replace('.','',$strasse); @@ -108,12 +98,10 @@ abstract class Versanddienstleister { $strasse = trim($hausnummer); $hausnummer = ''; } - $telefon = trim($docArr['telefon']); - $email = trim($docArr['email']); - - $ret['order_number'] = $docArr['auftrag']; - $ret['addressId'] = $docArr['adresse']; + $ret['strasse'] = $strasse; + $ret['hausnummer'] = $hausnummer; } + // wenn rechnung im spiel entweder durch versand oder direkt rechnung if($rechnungId >0) { @@ -127,35 +115,21 @@ abstract class Versanddienstleister { } } - if(isset($frei))$ret['frei'] = $frei; - if(isset($inhalt))$ret['inhalt'] = $inhalt; - if(isset($keinealtersabfrage))$ret['keinealtersabfrage'] = $keinealtersabfrage; - if(isset($altersfreigabe))$ret['altersfreigabe'] = $altersfreigabe; - if(isset($versichert))$ret['versichert'] = $versichert; - if(isset($extraversichert))$ret['extraversichert'] = $extraversichert; - $ret['name'] = $name; - $ret['name2'] = $name2; - $ret['name3'] = $name3; - $ret['ort'] = $ort; - $ret['plz'] = $plz; - $ret['strasse'] = $strasse; - $ret['strassekomplett'] = $strassekomplett; - $ret['hausnummer'] = $hausnummer; - $ret['land'] = $land; - $ret['telefon'] = $telefon; - $ret['phone'] = $telefon; - $ret['email'] = trim($email," \t\n\r\0\x0B\xc2\xa0"); - - $check_date = $this->app->DB->Select("SELECT date_format(now(),'%Y-%m-%d')"); - - $ret['abholdaumt'] = date('d.m.Y', strtotime($check_date)); - - $anzahl = $this->app->Secure->GetGET("anzahl"); - - if($anzahl <= 0) - { - $anzahl=1; - } + $sql = "SELECT + lp.bezeichnung, + lp.menge, + coalesce(nullif(lp.zolltarifnummer, ''), nullif(rp.zolltarifnummer, ''), nullif(a.zolltarifnummer, '')) zolltarifnummer, + coalesce(nullif(lp.herkunftsland, ''), nullif(rp.herkunftsland, ''), nullif(a.herkunftsland, '')) herkunftsland, + coalesce(nullif(lp.zolleinzelwert, '0'), rp.preis *(1-rp.rabatt/100)) zolleinzelwert, + coalesce(nullif(lp.zolleinzelgewicht, 0), a.gewicht) zolleinzelgewicht, + lp.zollwaehrung + FROM lieferschein_position lp + JOIN artikel a on lp.artikel = a.id + LEFT JOIN auftrag_position ap on lp.auftrag_position_id = ap.id + LEFT JOIN rechnung_position rp on ap.id = rp.auftrag_position_id + WHERE lp.lieferschein = $lieferscheinId + ORDER BY lp.sort"; + $ret['positions'] = $this->app->DB->SelectArr($sql); if($sid==="lieferschein"){ $standardkg = $this->app->erp->VersandartMindestgewicht($lieferscheinId); @@ -163,8 +137,7 @@ abstract class Versanddienstleister { else{ $standardkg = $this->app->erp->VersandartMindestgewicht(); } - $ret['standardkg'] = $standardkg; - $ret['anzahl'] = $anzahl; + $ret['weight'] = $standardkg; return $ret; } @@ -315,7 +288,7 @@ abstract class Versanddienstleister { * @param array $form submitted form data * @return array */ - public function CheckInputParameters(array &$form): array + public function ValidateSettings(array &$form): array { return []; } @@ -381,7 +354,7 @@ abstract class Versanddienstleister { return true; } - public function Paketmarke(string $target, string $doctype, int $docid): void { + public function Paketmarke(string $target, string $docType, int $docId): void { } diff --git a/www/lib/versandarten/content/versandarten_sendcloud.tpl b/www/lib/versandarten/content/versandarten_sendcloud.tpl index 4881a604..6ca8a33f 100644 --- a/www/lib/versandarten/content/versandarten_sendcloud.tpl +++ b/www/lib/versandarten/content/versandarten_sendcloud.tpl @@ -1,57 +1,241 @@ -
-
-
-
- [ERROR] -

{|Paketmarken Drucker für|} SendCloud

-
-
-

{|Empfänger|}

- - - - +
+ +
+
{{msg.text}}
+
+

{|Paketmarken Drucker für|} SendCloud

+
+
+

{|Empfänger|}

+
{|Name|}:
{|Name 2|}:
{|Name 3|}:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - -
{|Name|}:
{|Firmenname|}:
{|Strasse/Hausnummer|}: + + +
{|Adresszeile 2|}:
{|PLZ/Ort|}: + +
{|Bundesland|}:
{|Land|}: + +
{|E-Mail|}:
{|Telefon|}:
{|Land|}:
{|PLZ/Ort|}: 
{|Strasse/Hausnummer|}: 
{|E-Mail|}:
{|Telefon|}:
{|Bundesland|}:
-
-
-

{|Paket|}

- - - - - - -
{|Gewicht (in kg)|}:
{|Höhe (in cm)|}:
{|Breite (in cm)|}:
{|Länge (in cm)|}:
{|Produkt|}:[METHODS]
-
-
-
-

{|Bestellung|}

- - - - - -
{|Bestellnummer|}:
{|Rechnungsnummer|}:
{|Sendungsart|}:
{|Versicherungssumme|}:
-
-
-   - [TRACKINGMANUELL] -   -
-
-
\ No newline at end of file + + +
+

vollst. Adresse

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{|Name|}{{form.name}}
{|Ansprechpartner|}{{form.ansprechpartner}}
{|Abteilung|}{{form.abteilung}}
{|Unterabteilung|}{{form.unterabteilung}}
{|Adresszusatz|}{{form.adresszusatz}}
{|Strasse|}{{form.streetwithnumber}}
{|PLZ/Ort|}{{form.plz}} {{form.ort}}
{|Bundesland|}{{form.bundesland}}
{|Land|}{{form.land}}
+
+
+

{|Paket|}

+ + + + + + + + + + + + + + + + + + + + + +
{|Gewicht (in kg)|}:
{|Höhe (in cm)|}:
{|Breite (in cm)|}:
{|Länge (in cm)|}:
{|Produkt|}: + +
+
+
+
+

{|Bestellung|}

+ + + + + + + + + + + + + + + + + +
{|Bestellnummer|}:
{|Rechnungsnummer|}:
{|Sendungsart|}: + +
{|Versicherungssumme|}:
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{|Bezeichnung|}{|Menge|}{|HSCode|}{|Herkunftsland|}{|Einzelwert|}{|Einzelgewicht|}{|Währung|}{|Gesamtwert|}{|Gesamtgewicht|} +
{{Number(pos.menge*pos.zolleinzelwert || 0).toFixed(2)}}{{Number(pos.menge*pos.zolleinzelgewicht || 0).toFixed(3)}}
{{total_value.toFixed(2)}}{{total_weight.toFixed(3)}}
+
+
+   +   +
+ + + + \ No newline at end of file diff --git a/www/lib/versandarten/sendcloud.php b/www/lib/versandarten/sendcloud.php index c89e413d..41392ae5 100644 --- a/www/lib/versandarten/sendcloud.php +++ b/www/lib/versandarten/sendcloud.php @@ -2,6 +2,7 @@ use Xentral\Carrier\SendCloud\Data\Document; use Xentral\Carrier\SendCloud\Data\ParcelCreation; +use Xentral\Carrier\SendCloud\Data\ParcelItem; use Xentral\Carrier\SendCloud\Data\ParcelResponse; use Xentral\Carrier\SendCloud\SendCloudApi; use Xentral\Carrier\SendCloud\Data\SenderAddress; @@ -21,6 +22,13 @@ class Versandart_sendcloud extends Versanddienstleister if (!isset($this->id)) return; $this->api = new SendCloudApi($this->settings->public_key, $this->settings->private_key); + $this->options['customs_shipment_types'] = [ + 0 => 'Geschenk', + 1 => 'Dokumente', + 2 => 'Kommerzielle Waren', + 3 => 'Erprobungswaren', + 4 => 'Rücksendung' + ]; } protected function FetchOptionsFromApi() @@ -40,7 +48,7 @@ class Versandart_sendcloud extends Versanddienstleister $this->options['senders'] = array_map(fn(SenderAddress $x) => strval($x), $senderAddresses ?? []); $this->options['products'] = array_map(fn(ShippingProduct $x) => $x->Name, $shippingProducts ?? []); $this->options['products'][0] = ''; - $this->options['selectedProduct'] = $shippingProducts[$this->settings->shipping_product]; + $this->options['selectedProduct'] = $shippingProducts[$this->settings->shipping_product] ?? []; natcasesort($this->options['products']); } @@ -52,73 +60,84 @@ class Versandart_sendcloud extends Versanddienstleister 'private_key' => ['typ' => 'text', 'bezeichnung' => 'API Private Key:'], 'sender_address' => ['typ' => 'select', 'bezeichnung' => 'Absender-Adresse:', 'optionen' => $this->options['senders']], 'shipping_product' => ['typ' => 'select', 'bezeichnung' => 'Versand-Produkt:', 'optionen' => $this->options['products']], + 'default_customs_shipment_type' => ['typ' => 'select', 'bezeichnung' => 'Sendungsart:', 'optionen' => $this->options['customs_shipment_types']], ]; } - public function Paketmarke(string $target, string $doctype, int $docid): void + public function Paketmarke(string $target, string $docType, int $docId): void { - $address = $this->GetAdressdaten($docid, $doctype); - $submit = false; + $address = $this->GetAdressdaten($docId, $docType); - if ($this->app->Secure->GetPOST('drucken') != '') { - $submit = true; - $parcel = new ParcelCreation(); - $parcel->SenderAddressId = $this->settings->sender_address; - $parcel->ShippingMethodId = $this->app->Secure->GetPOST('method'); - $parcel->Name = $this->app->Secure->GetPOST('name'); - $parcel->CompanyName = $this->app->Secure->GetPOST('name3'); - $parcel->Country = $this->app->Secure->GetPOST('land'); - $parcel->PostalCode = $this->app->Secure->GetPOST('plz'); - $parcel->City = $this->app->Secure->GetPOST('ort'); - $parcel->Address = $this->app->Secure->GetPOST('strasse'); - $parcel->Address2 = $this->app->Secure->GetPOST('name2'); - $parcel->HouseNumber = $this->app->Secure->GetPOST('hausnummer'); - $parcel->EMail = $this->app->Secure->GetPOST('email'); - $parcel->Telephone = $this->app->Secure->GetPOST('phone'); - $parcel->CountryState = $this->app->Secure->GetPOST('state'); - $parcel->CustomsInvoiceNr = $this->app->Secure->GetPOST('rechnungsnummer'); - $parcel->CustomsShipmentType = $this->app->Secure->GetPOST('sendungsart'); - $parcel->TotalInsuredValue = (int)$this->app->Secure->GetPOST('versicherungssumme'); - $parcel->OrderNumber = $this->app->Secure->GetPOST('bestellnummer'); - $weight = $this->app->Secure->GetPOST('weight'); - $parcel->Weight = floatval($weight) * 1000; - $result = $this->api->CreateParcel($parcel); - if ($result instanceof ParcelResponse) { - $sql = "INSERT INTO versand + if (isset($_SERVER['HTTP_CONTENT_TYPE']) && ($_SERVER['HTTP_CONTENT_TYPE'] === 'application/json')) { + $json = json_decode(file_get_contents('php://input')); + $response = []; + if ($json->submit == 'print') { + header('Content-Type: application/json'); + $parcel = new ParcelCreation(); + $parcel->SenderAddressId = $this->settings->sender_address; + $parcel->ShippingMethodId = $json->method; + $parcel->Name = $json->l_name; + $parcel->CompanyName = $json->l_companyname; + $parcel->Country = $json->land; + $parcel->PostalCode = $json->plz; + $parcel->City = $json->ort; + $parcel->Address = $json->strasse; + $parcel->Address2 = $json->l_address2; + $parcel->HouseNumber = $json->hausnummer; + $parcel->EMail = $json->email; + $parcel->Telephone = $json->telefon; + $parcel->CountryState = $json->bundesland; + $parcel->CustomsInvoiceNr = $json->invoice_number; + $parcel->CustomsShipmentType = $json->sendungsart; + $parcel->TotalInsuredValue = $json->total_insured_value; + $parcel->OrderNumber = $json->order_number; + foreach ($json->positions as $pos) { + $item = new ParcelItem(); + $item->HsCode = $pos->zolltarifnummer; + $item->Description = $pos->bezeichnung; + $item->Quantity = $pos->menge; + $item->OriginCountry = $pos->herkunftsland; + $item->Price = $pos->zolleinzelwert; + $item->Weight = $pos->zolleinzelgewicht * 1000; + $parcel->ParcelItems[] = $item; + } + $parcel->Weight = floatval($json->weight) * 1000; + $result = $this->api->CreateParcel($parcel); + if ($result instanceof ParcelResponse) { + $sql = "INSERT INTO versand (adresse, lieferschein, versandunternehmen, gewicht, tracking, tracking_link, anzahlpakete) VALUES ({$address['addressId']}, {$address['lieferscheinId']}, '$this->type', - '$weight', '$result->TrackingNumber', '$result->TrackingUrl', 1)"; - $this->app->DB->Insert($sql); - $this->app->Tpl->addMessage('info', "Paketmarke wurde erfolgreich erstellt: $result->TrackingNumber"); + '$json->weight', '$result->TrackingNumber', '$result->TrackingUrl', 1)"; + $this->app->DB->Insert($sql); + $response['messages'][] = ['class' => 'info', 'text' => "Paketmarke wurde erfolgreich erstellt: $result->TrackingNumber"]; + $response['messages'][] = ['class' => 'info', 'text' => print_r($result, true)]; - $doc = $result->GetDocumentByType(Document::TYPE_LABEL); - $filename = $this->app->erp->GetTMP().join('_', ['Sendcloud', $doc->Type, $doc->Size, $result->TrackingNumber]).'.pdf'; - file_put_contents($filename, $this->api->DownloadDocument($doc)); - $this->app->printer->Drucken($this->paketmarke_drucker, $filename); - } else { - $this->app->Tpl->addMessage('error', $result); + $doc = $result->GetDocumentByType(Document::TYPE_LABEL); + $filename = $this->app->erp->GetTMP() . join('_', ['Sendcloud', $doc->Type, $doc->Size, $result->TrackingNumber]) . '.pdf'; + file_put_contents($filename, $this->api->DownloadDocument($doc)); + $this->app->printer->Drucken($this->labelPrinterId, $filename); + + $doc = $result->GetDocumentByType(Document::TYPE_CN23); + $filename = $this->app->erp->GetTMP() . join('_', ['Sendcloud', $doc->Type, $doc->Size, $result->TrackingNumber]) . '.pdf'; + file_put_contents($filename, $this->api->DownloadDocument($doc)); + $this->app->printer->Drucken($this->documentPrinterId, $filename); + } else { + $response['messages'][] = ['class' => 'error', 'text' => $result]; + } + echo json_encode($response); + $this->app->ExitXentral(); } } - $this->app->Tpl->Set('NAME', $submit ? $this->app->Secure->GetPOST('name') : $address['name']); - $this->app->Tpl->Set('NAME2', $submit ? $this->app->Secure->GetPOST('name2') : $address['name2']); - $this->app->Tpl->Set('NAME3', $submit ? $this->app->Secure->GetPOST('name3') : $address['name3']); - $this->app->Tpl->Set('LAND', $this->app->erp->SelectLaenderliste($submit ? $this->app->Secure->GetPOST('land') : $address['land'])); - $this->app->Tpl->Set('PLZ', $submit ? $this->app->Secure->GetPOST('plz') : $address['plz']); - $this->app->Tpl->Set('ORT', $submit ? $this->app->Secure->GetPOST('ort') : $address['ort']); - $this->app->Tpl->Set('STRASSE', $submit ? $this->app->Secure->GetPOST('strasse') : $address['strasse']); - $this->app->Tpl->Set('HAUSNUMMER', $submit ? $this->app->Secure->GetPOST('hausnummer') : $address['hausnummer']); - $this->app->Tpl->Set('EMAIL', $submit ? $this->app->Secure->GetPOST('email') : $address['email']); - $this->app->Tpl->Set('TELEFON', $submit ? $this->app->Secure->GetPOST('phone') : $address['phone']); - $this->app->Tpl->Set('WEIGHT', $submit ? $this->app->Secure->GetPOST('weight') : $address['standardkg']); - $this->app->Tpl->Set('LENGTH', $submit ? $this->app->Secure->GetPOST('length') : ''); - $this->app->Tpl->Set('WIDTH', $submit ? $this->app->Secure->GetPOST('width') : ''); - $this->app->Tpl->Set('HEIGHT', $submit ? $this->app->Secure->GetPOST('height') : ''); - $this->app->Tpl->Set('ORDERNUMBER', $submit ? $this->app->Secure->GetPOST('order_number') : $address['order_number']); - $this->app->Tpl->Set('INVOICENUMBER', $submit ? $this->app->Secure->GetPOST('invoice_number') : $address['invoice_number']); + $address['l_name'] = empty(trim($address['ansprechpartner'])) ? trim($address['name']) : trim($address['ansprechpartner']); + $address['l_companyname'] = !empty(trim($address['ansprechpartner'])) ? trim($address['name']) : ''; + $address['l_address2'] = join(';', array_filter([ + $address['abteilung'], + $address['unterabteilung'], + $address['adresszusatz'] + ], fn(string $item) => !empty(trim($item)))); - $method = $this->app->Secure->GetPOST('method'); $this->FetchOptionsFromApi(); /** @var ShippingProduct $product */ $product = $this->options['selectedProduct']; @@ -126,7 +145,13 @@ class Versandart_sendcloud extends Versanddienstleister /** @var ShippingMethod $item */ foreach ($product->ShippingMethods as $item) $methods[$item->Id] = $item->Name; - $this->app->Tpl->addSelect('METHODS', 'method', 'method', $methods, $method); + $address['method'] = array_key_first($methods); + $address['sendungsart'] = $this->settings->default_customs_shipment_type; + + $this->app->Tpl->Set('JSON', json_encode($address)); + $this->app->Tpl->Set('JSON_COUNTRIES', json_encode($this->app->erp->GetSelectLaenderliste())); + $this->app->Tpl->Set('JSON_METHODS', json_encode($methods)); + $this->app->Tpl->Set('JSON_CUSTOMS_SHIPMENT_TYPES', json_encode($this->options['customs_shipment_types'])); $this->app->Tpl->Parse($target, 'versandarten_sendcloud.tpl'); } diff --git a/www/pages/versandarten.php b/www/pages/versandarten.php index 31d2c812..01cbd46d 100644 --- a/www/pages/versandarten.php +++ b/www/pages/versandarten.php @@ -185,7 +185,7 @@ class Versandarten { foreach ($obj->AdditionalSettings() as $k => $v) { $form[$k] = $this->app->Secure->GetPOST($k); } - $error = array_merge($error, $obj->CheckInputParameters($form)); + $error = array_merge($error, $obj->ValidateSettings($form)); foreach ($obj->AdditionalSettings() as $k => $v) { $json[$k] = $form[$k]; } @@ -234,19 +234,11 @@ class Versandarten { $obj->RenderAdditionalSettings('MODULESETTINGS', $form); - $drucker_export = $this->app->erp->GetDrucker(); - $drucker_export[0] = ''; - natcasesort($drucker_export); $this->app->Tpl->addSelect('EXPORT_DRUCKER', 'export_drucker', 'export_drucker', - $drucker_export, $form['export_drucker']); + $this->getPrinterByModule($obj, false), $form['export_drucker']); - $drucker_paketmarke = $this->app->erp->GetDrucker(); - if($obj->isEtikettenDrucker()) - $drucker_paketmarke = array_merge($drucker_paketmarke, $this->app->erp->GetEtikettendrucker()); - $drucker_paketmarke[0] = ''; - natcasesort($drucker_paketmarke); $this->app->Tpl->addSelect('PAKETMARKE_DRUCKER', 'paketmarke_drucker', 'paketmarke_drucker', - $drucker_paketmarke, $form['paketmarke_drucker']); + $this->getPrinterByModule($obj), $form['paketmarke_drucker']); $this->app->YUI->HideFormular('versandmail', array('0'=>'versandbetreff','1'=>'dummy')); $this->app->Tpl->addSelect('SELVERSANDMAIL', 'versandmail', 'versandmail', [ @@ -277,12 +269,11 @@ class Versandarten { $this->app->Tpl->Parse('PAGE', 'versandarten_edit.tpl'); } - protected function getPrinterByModule(Versanddienstleister $obj): array + protected function getPrinterByModule(Versanddienstleister $obj, bool $includeLabelPrinter = true): array { - $isLabelPrinter = $obj->isEtikettenDrucker(); $printer = $this->app->erp->GetDrucker(); - if ($isLabelPrinter) { + if ($includeLabelPrinter && $obj->isEtikettenDrucker()) { $labelPrinter = $this->app->erp->GetEtikettendrucker(); $printer = array_merge($printer ?? [], $labelPrinter ?? []); }