Skip to content

Commit 7ee2bfa

Browse files
authored
Merge pull request #73 from exciler/sendcloud
Versanddienstleiter improvement
2 parents ebc7034 + e79e2e2 commit 7ee2bfa

File tree

4 files changed

+76
-41
lines changed

4 files changed

+76
-41
lines changed

classes/Carrier/SendCloud/Data/ParcelCreation.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class ParcelCreation extends ParcelBase
1212
{
1313
public ?int $SenderAddressId = null;
1414

15-
public function toApiRequest(): array {
16-
return [
15+
public function toApiRequest(): array
16+
{
17+
$data = [
1718
'name' => $this->Name,
1819
'company_name' => $this->CompanyName,
1920
'address' => $this->Address,
@@ -32,16 +33,19 @@ public function toApiRequest(): array {
3233
'total_order_value' => number_format($this->TotalOrderValue, 2, '.', null),
3334
'country_state' => $this->CountryState,
3435
'sender_address' => $this->SenderAddressId,
35-
'customs_invoice_nr' => $this->CustomsInvoiceNr,
36-
'customs_shipment_type' => $this->CustomsShipmentType,
3736
'external_reference' => $this->ExternalReference,
3837
'total_insured_value' => $this->TotalInsuredValue ?? 0,
39-
'parcel_items' => array_map(fn(ParcelItem $item)=>$item->toApiRequest(), $this->ParcelItems),
38+
'parcel_items' => array_map(fn(ParcelItem $item) => $item->toApiRequest(), $this->ParcelItems),
4039
'is_return' => $this->IsReturn,
4140
'length' => $this->Length,
4241
'width' => $this->Width,
4342
'height' => $this->Height,
4443
];
45-
}
44+
if ($this->CustomsInvoiceNr !== null)
45+
$data['customs_invoice_nr'] = $this->CustomsInvoiceNr;
46+
if ($this->CustomsShipmentType !== null)
47+
$data['customs_shipment_type'] = $this->CustomsShipmentType;
4648

49+
return $data;
50+
}
4751
}

www/lib/class.versanddienstleister.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,11 @@ public function Paketmarke(string $target, string $docType, int $docId): void
409409
$products = array_combine(array_column($products, 'Id'), $products);
410410
$address['product'] = $products[0]->Id ?? '';
411411

412+
$countries = $this->app->DB->SelectArr("SELECT iso, bezeichnung_de name, eu FROM laender ORDER BY bezeichnung_de");
413+
$countries = array_combine(array_column($countries, 'iso'), $countries);
414+
412415
$json['form'] = $address;
413-
$json['countries'] = $this->app->erp->GetSelectLaenderliste();
416+
$json['countries'] = $countries;
414417
$json['products'] = $products;
415418
$json['customs_shipment_types'] = [
416419
CustomsInfo::CUSTOMS_TYPE_GIFT => 'Geschenk',

www/lib/versandarten/content/createshipment.tpl

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
7373
<td>{|Land|}:</td>
7474
<td>
7575
<select v-model="form.country" required>
76-
<option v-for="(value, key) in countries" :value="key">{{value}}</option>
76+
<option v-for="(value, key) in countries" :value="key">{{value.name}}</option>
7777
</select>
7878
</td>
7979
</tr>
@@ -156,7 +156,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
156156
<td>{|Produkt|}:</td>
157157
<td>
158158
<select v-model="form.product" required>
159-
<option v-for="prod in products" :value="prod.Id">{{prod.Name}}</option>
159+
<option v-for="prod in products" :value="prod.Id" v-if="productAvailable(prod)">{{prod.Name}}</option>
160160
</select>
161161
</td>
162162
</tr>
@@ -170,29 +170,33 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
170170
<div class="col-md-12">
171171
<h2>{|Bestellung|}</h2>
172172
<table>
173-
<tr>
174-
<td>{|Bestellnummer|}:</td>
175-
<td><input type="text" size="36" v-model="form.order_number"></td>
176-
</tr>
177-
<tr>
178-
<td>{|Rechnungsnummer|}:</td>
179-
<td><input type="text" size="36" v-model="form.invoice_number"></td>
180-
</tr>
181-
<tr>
182-
<td>{|Sendungsart|}:</td>
183-
<td>
184-
<select v-model="form.shipment_type">
185-
<option v-for="(value, key) in customs_shipment_types" :value="key">{{value}}</option>
186-
</select>
187-
</td>
188-
</tr>
189-
<tr>
190-
<td>{|Versicherungssumme|}:</td>
191-
<td><input type="text" size="10" v-model="form.total_insured_value"/></td>
192-
</tr>
173+
<tbody>
174+
<tr>
175+
<td>{|Bestellnummer|}:</td>
176+
<td><input type="text" size="36" v-model="form.order_number"></td>
177+
</tr>
178+
<tr>
179+
<td>{|Versicherungssumme|}:</td>
180+
<td><input type="text" size="10" v-model="form.total_insured_value"/></td>
181+
</tr>
182+
</tbody>
183+
<tbody v-if="customsRequired()">
184+
<tr>
185+
<td>{|Rechnungsnummer|}:</td>
186+
<td><input type="text" size="36" v-model="form.invoice_number" required="required"></td>
187+
</tr>
188+
<tr>
189+
<td>{|Sendungsart|}:</td>
190+
<td>
191+
<select v-model="form.shipment_type">
192+
<option v-for="(value, key) in customs_shipment_types" :value="key">{{value}}</option>
193+
</select>
194+
</td>
195+
</tr>
196+
</tbody>
193197
</table>
194198
</div>
195-
<div class="col-md-12">
199+
<div class="col-md-12" v-if="customsRequired()">
196200
<table>
197201
<tr>
198202
<th>{|Bezeichnung|}</th>
@@ -269,10 +273,30 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
269273
deletePosition: function (index) {
270274
this.form.positions.splice(index, 1);
271275
},
276+
productAvailable: function (product) {
277+
if (product == undefined)
278+
return false;
279+
if (product.WeightMin > this.form.weight || product.WeightMax < this.form.weight)
280+
return false;
281+
return true;
282+
},
272283
serviceAvailable: function (service) {
273284
if (!this.products.hasOwnProperty(this.form.product))
274285
return false;
275286
return this.products[this.form.product].AvailableServices.indexOf(service) >= 0;
287+
},
288+
customsRequired: function () {
289+
return this.countries[this.form.country].eu == '0';
290+
}
291+
},
292+
beforeUpdate: function () {
293+
if (!this.productAvailable(this.products[this.form.product])) {
294+
for (prod in this.products) {
295+
if (!this.productAvailable(this.products[prod]))
296+
continue;
297+
this.form.product = prod;
298+
break;
299+
}
276300
}
277301
}
278302
})

www/lib/versandarten/sendcloud.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,21 @@ public function CreateShipment(object $json, array $address): CreateShipmentResu
105105
$parcel->EMail = $json->email;
106106
$parcel->Telephone = $json->phone;
107107
$parcel->CountryState = $json->state;
108-
$parcel->CustomsInvoiceNr = $json->invoice_number;
109-
$parcel->CustomsShipmentType = $json->shipment_type;
110108
$parcel->TotalInsuredValue = $json->total_insured_value;
111109
$parcel->OrderNumber = $json->order_number;
112-
foreach ($json->positions as $pos) {
113-
$item = new ParcelItem();
114-
$item->HsCode = $pos->zolltarifnummer;
115-
$item->Description = $pos->bezeichnung;
116-
$item->Quantity = $pos->menge;
117-
$item->OriginCountry = $pos->herkunftsland;
118-
$item->Price = $pos->zolleinzelwert;
119-
$item->Weight = $pos->zolleinzelgewicht * 1000;
120-
$parcel->ParcelItems[] = $item;
110+
if (!$this->app->erp->IsEU($json->country)) {
111+
$parcel->CustomsInvoiceNr = $json->invoice_number;
112+
$parcel->CustomsShipmentType = $json->shipment_type;
113+
foreach ($json->positions as $pos) {
114+
$item = new ParcelItem();
115+
$item->HsCode = $pos->zolltarifnummer ?? '';
116+
$item->Description = $pos->bezeichnung;
117+
$item->Quantity = $pos->menge;
118+
$item->OriginCountry = $pos->herkunftsland ?? '';
119+
$item->Price = $pos->zolleinzelwert;
120+
$item->Weight = $pos->zolleinzelgewicht * 1000;
121+
$parcel->ParcelItems[] = $item;
122+
}
121123
}
122124
$parcel->Weight = floatval($json->weight) * 1000;
123125
$ret = new CreateShipmentResult();
@@ -154,6 +156,8 @@ public function GetShippingProducts(): array
154156
$p = new Product();
155157
$p->Id = $item->Id;
156158
$p->Name = $item->Name;
159+
$p->WeightMin = $item->MinWeight / 1000;
160+
$p->WeightMax = $item->MaxWeight / 1000;
157161
$result[] = $p;
158162
}
159163
return $result;

0 commit comments

Comments
 (0)