Merge pull request #73 from exciler/sendcloud

Versanddienstleiter improvement
This commit is contained in:
OpenXE-ERP 2023-04-01 22:10:10 +02:00 committed by GitHub
commit 7ee2bfae5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 41 deletions

View File

@ -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;
}
}

View File

@ -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',

View File

@ -73,7 +73,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
<td>{|Land|}:</td>
<td>
<select v-model="form.country" required>
<option v-for="(value, key) in countries" :value="key">{{value}}</option>
<option v-for="(value, key) in countries" :value="key">{{value.name}}</option>
</select>
</td>
</tr>
@ -156,7 +156,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
<td>{|Produkt|}:</td>
<td>
<select v-model="form.product" required>
<option v-for="prod in products" :value="prod.Id">{{prod.Name}}</option>
<option v-for="prod in products" :value="prod.Id" v-if="productAvailable(prod)">{{prod.Name}}</option>
</select>
</td>
</tr>
@ -170,29 +170,33 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
<div class="col-md-12">
<h2>{|Bestellung|}</h2>
<table>
<tr>
<td>{|Bestellnummer|}:</td>
<td><input type="text" size="36" v-model="form.order_number"></td>
</tr>
<tr>
<td>{|Rechnungsnummer|}:</td>
<td><input type="text" size="36" v-model="form.invoice_number"></td>
</tr>
<tr>
<td>{|Sendungsart|}:</td>
<td>
<select v-model="form.shipment_type">
<option v-for="(value, key) in customs_shipment_types" :value="key">{{value}}</option>
</select>
</td>
</tr>
<tr>
<td>{|Versicherungssumme|}:</td>
<td><input type="text" size="10" v-model="form.total_insured_value"/></td>
</tr>
<tbody>
<tr>
<td>{|Bestellnummer|}:</td>
<td><input type="text" size="36" v-model="form.order_number"></td>
</tr>
<tr>
<td>{|Versicherungssumme|}:</td>
<td><input type="text" size="10" v-model="form.total_insured_value"/></td>
</tr>
</tbody>
<tbody v-if="customsRequired()">
<tr>
<td>{|Rechnungsnummer|}:</td>
<td><input type="text" size="36" v-model="form.invoice_number" required="required"></td>
</tr>
<tr>
<td>{|Sendungsart|}:</td>
<td>
<select v-model="form.shipment_type">
<option v-for="(value, key) in customs_shipment_types" :value="key">{{value}}</option>
</select>
</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-12">
<div class="col-md-12" v-if="customsRequired()">
<table>
<tr>
<th>{|Bezeichnung|}</th>
@ -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;
}
}
}
})

View File

@ -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 (!$this->app->erp->IsEU($json->country)) {
$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;