From b6c23399c6f7acb5eb6d1e09594faa6922812933 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Thu, 30 Mar 2023 22:24:40 +0200 Subject: [PATCH 1/3] Versanddienstleister: display customs form only for non-EU countries, improve product/method selection --- www/lib/class.versanddienstleister.php | 5 +- .../versandarten/content/createshipment.tpl | 70 +++++++++++++------ www/lib/versandarten/sendcloud.php | 26 ++++--- 3 files changed, 66 insertions(+), 35 deletions(-) diff --git a/www/lib/class.versanddienstleister.php b/www/lib/class.versanddienstleister.php index 9fcd29ee..44743e27 100644 --- a/www/lib/class.versanddienstleister.php +++ b/www/lib/class.versanddienstleister.php @@ -409,8 +409,11 @@ abstract class Versanddienstleister $products = array_combine(array_column($products, 'Id'), $products); $address['product'] = $products[0]->Id ?? ''; + $countries = $this->app->DB->SelectArr("SELECT iso, bezeichnung_de name, eu FROM laender ORDER BY bezeichnung_de"); + $countries = array_combine(array_column($countries, 'iso'), $countries); + $json['form'] = $address; - $json['countries'] = $this->app->erp->GetSelectLaenderliste(); + $json['countries'] = $countries; $json['products'] = $products; $json['customs_shipment_types'] = [ CustomsInfo::CUSTOMS_TYPE_GIFT => 'Geschenk', diff --git a/www/lib/versandarten/content/createshipment.tpl b/www/lib/versandarten/content/createshipment.tpl index 04d3f8e1..3ece01dd 100644 --- a/www/lib/versandarten/content/createshipment.tpl +++ b/www/lib/versandarten/content/createshipment.tpl @@ -73,7 +73,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1 {|Land|}: @@ -156,7 +156,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1 {|Produkt|}: @@ -170,29 +170,33 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1

{|Bestellung|}

- - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + +
{|Bestellnummer|}:
{|Rechnungsnummer|}:
{|Sendungsart|}: - -
{|Versicherungssumme|}:
{|Bestellnummer|}:
{|Versicherungssumme|}:
{|Rechnungsnummer|}:
{|Sendungsart|}: + +
-
+
@@ -269,10 +273,30 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1 deletePosition: function (index) { this.form.positions.splice(index, 1); }, + productAvailable: function (product) { + if (product == undefined) + return false; + if (product.WeightMin > this.form.weight || product.WeightMax < this.form.weight) + return false; + return true; + }, serviceAvailable: function (service) { if (!this.products.hasOwnProperty(this.form.product)) return false; return this.products[this.form.product].AvailableServices.indexOf(service) >= 0; + }, + customsRequired: function () { + return this.countries[this.form.country].eu == '0'; + } + }, + beforeUpdate: function () { + if (!this.productAvailable(this.products[this.form.product])) { + for (prod in this.products) { + if (!this.productAvailable(this.products[prod])) + continue; + this.form.product = prod; + break; + } } } }) diff --git a/www/lib/versandarten/sendcloud.php b/www/lib/versandarten/sendcloud.php index 2216cb83..4e4ebe03 100644 --- a/www/lib/versandarten/sendcloud.php +++ b/www/lib/versandarten/sendcloud.php @@ -105,19 +105,21 @@ class Versandart_sendcloud extends Versanddienstleister $parcel->EMail = $json->email; $parcel->Telephone = $json->phone; $parcel->CountryState = $json->state; - $parcel->CustomsInvoiceNr = $json->invoice_number; - $parcel->CustomsShipmentType = $json->shipment_type; $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; + if (!empty($json->shipment_type)) { + $parcel->CustomsInvoiceNr = $json->invoice_number; + $parcel->CustomsShipmentType = $json->shipment_type; + 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; $ret = new CreateShipmentResult(); @@ -154,6 +156,8 @@ class Versandart_sendcloud extends Versanddienstleister $p = new Product(); $p->Id = $item->Id; $p->Name = $item->Name; + $p->WeightMin = $item->MinWeight / 1000; + $p->WeightMax = $item->MaxWeight / 1000; $result[] = $p; } return $result; From 03f51a548aa4503fe3f64d17fe76803d6b6e6d02 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Fri, 31 Mar 2023 10:21:08 +0200 Subject: [PATCH 2/3] Sendcloud: handle field requirement/null for parcels without customs declaration --- .../Carrier/SendCloud/Data/ParcelCreation.php | 16 ++++++++++------ www/lib/versandarten/sendcloud.php | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/classes/Carrier/SendCloud/Data/ParcelCreation.php b/classes/Carrier/SendCloud/Data/ParcelCreation.php index d4014b17..174361b6 100644 --- a/classes/Carrier/SendCloud/Data/ParcelCreation.php +++ b/classes/Carrier/SendCloud/Data/ParcelCreation.php @@ -12,8 +12,9 @@ class ParcelCreation extends ParcelBase { public ?int $SenderAddressId = null; - public function toApiRequest(): array { - return [ + public function toApiRequest(): array + { + $data = [ 'name' => $this->Name, 'company_name' => $this->CompanyName, 'address' => $this->Address, @@ -32,16 +33,19 @@ class ParcelCreation extends ParcelBase 'total_order_value' => number_format($this->TotalOrderValue, 2, '.', null), 'country_state' => $this->CountryState, 'sender_address' => $this->SenderAddressId, - 'customs_invoice_nr' => $this->CustomsInvoiceNr, - 'customs_shipment_type' => $this->CustomsShipmentType, 'external_reference' => $this->ExternalReference, 'total_insured_value' => $this->TotalInsuredValue ?? 0, - 'parcel_items' => array_map(fn(ParcelItem $item)=>$item->toApiRequest(), $this->ParcelItems), + 'parcel_items' => array_map(fn(ParcelItem $item) => $item->toApiRequest(), $this->ParcelItems), 'is_return' => $this->IsReturn, 'length' => $this->Length, 'width' => $this->Width, 'height' => $this->Height, ]; - } + if ($this->CustomsInvoiceNr !== null) + $data['customs_invoice_nr'] = $this->CustomsInvoiceNr; + if ($this->CustomsShipmentType !== null) + $data['customs_shipment_type'] = $this->CustomsShipmentType; + return $data; + } } \ No newline at end of file diff --git a/www/lib/versandarten/sendcloud.php b/www/lib/versandarten/sendcloud.php index 4e4ebe03..2f7082e1 100644 --- a/www/lib/versandarten/sendcloud.php +++ b/www/lib/versandarten/sendcloud.php @@ -107,7 +107,7 @@ class Versandart_sendcloud extends Versanddienstleister $parcel->CountryState = $json->state; $parcel->TotalInsuredValue = $json->total_insured_value; $parcel->OrderNumber = $json->order_number; - if (!empty($json->shipment_type)) { + if (!$this->app->erp->IstEU($json->country)) { $parcel->CustomsInvoiceNr = $json->invoice_number; $parcel->CustomsShipmentType = $json->shipment_type; foreach ($json->positions as $pos) { From e79e2e24d2de5c0bc4e1d4e0adf2ddcad3bab930 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Fri, 31 Mar 2023 22:30:35 +0200 Subject: [PATCH 3/3] Sendcloud: Fix for domestic parcels - use IsEU instead of IstEU :-/ --- www/lib/versandarten/sendcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/lib/versandarten/sendcloud.php b/www/lib/versandarten/sendcloud.php index 2f7082e1..cdda1cce 100644 --- a/www/lib/versandarten/sendcloud.php +++ b/www/lib/versandarten/sendcloud.php @@ -107,7 +107,7 @@ class Versandart_sendcloud extends Versanddienstleister $parcel->CountryState = $json->state; $parcel->TotalInsuredValue = $json->total_insured_value; $parcel->OrderNumber = $json->order_number; - if (!$this->app->erp->IstEU($json->country)) { + if (!$this->app->erp->IsEU($json->country)) { $parcel->CustomsInvoiceNr = $json->invoice_number; $parcel->CustomsShipmentType = $json->shipment_type; foreach ($json->positions as $pos) {
{|Bezeichnung|}