mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-14 20:17:14 +01:00
Sendcloud bugfixes and improvements
This commit is contained in:
parent
1ddee4350c
commit
6a2a16c0a6
@ -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,
|
||||
|
@ -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,
|
||||
],
|
||||
'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;
|
||||
|
@ -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()
|
||||
]);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
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");
|
||||
$sid = 'lieferschein';
|
||||
} else {
|
||||
if($sid==='lieferschein') {
|
||||
$lieferscheinId = $id;
|
||||
if($sid === 'lieferschein'){
|
||||
$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) {
|
||||
if($rechnungId <= 0)
|
||||
$rechnungId = $this->app->DB->Select("SELECT rechnungid FROM lieferschein WHERE id='$lieferscheinId' LIMIT 1");
|
||||
}
|
||||
if($sid==='versand')
|
||||
{
|
||||
$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';
|
||||
}
|
||||
$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 {
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,57 +1,241 @@
|
||||
<div class="container-fluid">
|
||||
<div class="container-fluid" id="sendcloudapp">
|
||||
<form action="" method="post" v-on:submit.prevent="submit">
|
||||
<div class="row">
|
||||
<div v-for="msg in messages" :class="msg.class">{{msg.text}}</div>
|
||||
<div>
|
||||
<form action="" method="post">
|
||||
[ERROR]
|
||||
<h1>{|Paketmarken Drucker für|} SendCloud</h1>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<h2>{|Empfänger|}</h2>
|
||||
<table>
|
||||
<tr><td>{|Name|}:</td><td><input type="text" size="36" value="[NAME]" name="name" id="name"><script type="text/javascript">document.getElementById("name").focus(); </script></td></tr>
|
||||
<tr><td>{|Name 2|}:</td><td><input type="text" size="36" value="[NAME2]" name="name2"></td></tr>
|
||||
<tr><td>{|Name 3|}:</td><td><input type="text" size="36" value="[NAME3]" name="name3"></td></tr>
|
||||
<tr>
|
||||
<td>{|Name|}:</td>
|
||||
<td><input type="text" size="36" v-model="form.l_name"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Firmenname|}:</td>
|
||||
<td><input type="text" size="36" v-model="form.l_companyname"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Strasse/Hausnummer|}:</td>
|
||||
<td>
|
||||
<input type="text" size="30" v-model="form.strasse">
|
||||
<input type="text" size="5" v-model="form.hausnummer">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Adresszeile 2|}:</td>
|
||||
<td><input type="text" size="36" v-model="form.l_address2"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|PLZ/Ort|}:</td>
|
||||
<td><input type="text" size="5" v-model="form.plz">
|
||||
<input type="text" size="30" v-model="form.ort">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Bundesland|}:</td>
|
||||
<td><input type="text" size="36" v-model="form.bundesland"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Land|}:</td>
|
||||
<td>
|
||||
<select v-model="form.land">
|
||||
<option v-for="(value, key) in countries" :value="key">{{value}}</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|E-Mail|}:</td>
|
||||
<td><input type="text" size="36" v-model="form.email"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Telefon|}:</td>
|
||||
<td><input type="text" size="36" v-model="form.telefon"></td>
|
||||
</tr>
|
||||
|
||||
<tr><td>{|Land|}:</td><td><select name="land">[LAND]</select></td></tr>
|
||||
<tr><td>{|PLZ/Ort|}:</td><td><input type="text" name="plz" size="5" value="[PLZ]"> <input type="text" size="30" name="ort" value="[ORT]"></td></tr>
|
||||
<tr><td>{|Strasse/Hausnummer|}:</td><td><input type="text" size="30" value="[STRASSE]" name="strasse"> <input type="text" size="5" name="hausnummer" value="[HAUSNUMMER]"></td></tr>
|
||||
|
||||
<tr><td>{|E-Mail|}:</td><td><input type="text" size="36" value="[EMAIL]" name="email"></td></tr>
|
||||
<tr><td>{|Telefon|}:</td><td><input type="text" size="36" value="[TELEFON]" name="phone"></td></tr>
|
||||
|
||||
<tr><td>{|Bundesland|}:</td><td><input type="text" size="36" value="[BUNDESLAND]" name="state"></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4" v-once>
|
||||
<h2>vollst. Adresse</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td>{|Name|}</td>
|
||||
<td>{{form.name}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Ansprechpartner|}</td>
|
||||
<td>{{form.ansprechpartner}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Abteilung|}</td>
|
||||
<td>{{form.abteilung}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Unterabteilung|}</td>
|
||||
<td>{{form.unterabteilung}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Adresszusatz|}</td>
|
||||
<td>{{form.adresszusatz}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Strasse|}</td>
|
||||
<td>{{form.streetwithnumber}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|PLZ/Ort|}</td>
|
||||
<td>{{form.plz}} {{form.ort}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Bundesland|}</td>
|
||||
<td>{{form.bundesland}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Land|}</td>
|
||||
<td>{{form.land}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h2>{|Paket|}</h2>
|
||||
<table>
|
||||
<tr><td>{|Gewicht (in kg)|}:</td><td><input type="text" value="[WEIGHT]" name="weight"></td></tr>
|
||||
<tr><td>{|Höhe (in cm)|}:</td><td><input type="text" size="10" value="[HEIGHT]" name="height"></td></tr>
|
||||
<tr><td>{|Breite (in cm)|}:</td><td><input type="text" size="10" value="[WIDTH]" name="width"></td></tr>
|
||||
<tr><td>{|Länge (in cm)|}:</td><td><input type="text" size="10" value="[LENGTH]" name="length"></td></tr>
|
||||
<tr><td>{|Produkt|}:</td><td>[METHODS]</td></tr>
|
||||
<tr>
|
||||
<td>{|Gewicht (in kg)|}:</td>
|
||||
<td><input type="text" v-model="form.weight"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Höhe (in cm)|}:</td>
|
||||
<td><input type="text" size="10" v-model="form.height"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Breite (in cm)|}:</td>
|
||||
<td><input type="text" size="10" v-model="form.width"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Länge (in cm)|}:</td>
|
||||
<td><input type="text" size="10" v-model="form.length"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{|Produkt|}:</td>
|
||||
<td>
|
||||
<select v-model="form.method">
|
||||
<option v-for="(value, key, index) in methods" :value="key">{{value}}</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="col-md-12">
|
||||
<h2>{|Bestellung|}</h2>
|
||||
<table>
|
||||
<tr><td>{|Bestellnummer|}:</td><td><input type="text" size="36" value="[ORDERNUMBER]" name="bestellnummer"></td></tr>
|
||||
<tr><td>{|Rechnungsnummer|}:</td><td><input type="text" size="36" value="[INVOICENUMBER]" name="rechnungsnummer"></td></tr>
|
||||
<tr><td>{|Sendungsart|}:</td><td><select name="sendungsart">
|
||||
<option value="0">{|Geschenk|}</option>
|
||||
<option value="1">{|Dokumente|}</option>
|
||||
<option value="2" selected>{|Kommerzielle Waren|}</option>
|
||||
<option value="3">{|Erprobungswaren|}</option>
|
||||
<option value="4">{|Rücksendung|}</option>
|
||||
</select></td></tr>
|
||||
<tr><td>{|Versicherungssumme|}:</td><td><input type="text" size="10" id="versicherungssumme" name="versicherungssumme" value="[VERSICHERUNGSSUMME]" /></td></tr>
|
||||
<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.sendungsart">
|
||||
<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>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<table>
|
||||
<tr>
|
||||
<th>{|Bezeichnung|}</th>
|
||||
<th>{|Menge|}</th>
|
||||
<th>{|HSCode|}</th>
|
||||
<th>{|Herkunftsland|}</th>
|
||||
<th>{|Einzelwert|}</th>
|
||||
<th>{|Einzelgewicht|}</th>
|
||||
<th>{|Währung|}</th>
|
||||
<th>{|Gesamtwert|}</th>
|
||||
<th>{|Gesamtgewicht|}</th>
|
||||
<th><a v-on:click="addPosition"><img src="themes/new/images/add.png"></a></</th>
|
||||
</tr>
|
||||
<tr v-for="(pos, index) in form.positions">
|
||||
<td><input type="text" v-model="pos.bezeichnung" required></td>
|
||||
<td><input type="text" v-model="pos.menge" required></td>
|
||||
<td><input type="text" v-model="pos.zolltarifnummer" required></td>
|
||||
<td><input type="text" v-model="pos.herkunftsland" required></td>
|
||||
<td><input type="text" v-model="pos.zolleinzelwert" required></td>
|
||||
<td><input type="text" v-model="pos.zolleinzelgewicht" required></td>
|
||||
<td><input type="text" v-model="pos.zollwaehrung" required></td>
|
||||
<td>{{Number(pos.menge*pos.zolleinzelwert || 0).toFixed(2)}}</td>
|
||||
<td>{{Number(pos.menge*pos.zolleinzelgewicht || 0).toFixed(3)}}</td>
|
||||
<td><a v-on:click="deletePosition(index)"><img src="themes/new/images/delete.svg"></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="7"></td>
|
||||
<td>{{total_value.toFixed(2)}}</td>
|
||||
<td>{{total_weight.toFixed(3)}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<input class="btnGreen" type="submit" value="{|Paketmarke drucken|}" name="drucken">
|
||||
[TRACKINGMANUELL]
|
||||
<input type="button" value="{|Andere Versandart auswählen|}" name="anders">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
const sendcloudApp = new Vue({
|
||||
el: '#sendcloudapp',
|
||||
data: {
|
||||
form: [JSON],
|
||||
countries: [JSON_COUNTRIES],
|
||||
methods: [JSON_METHODS],
|
||||
customs_shipment_types: [JSON_CUSTOMS_SHIPMENT_TYPES],
|
||||
messages: []
|
||||
},
|
||||
computed: {
|
||||
total_value() {
|
||||
let sum = 0;
|
||||
for(const pos of this.form.positions) {
|
||||
sum += pos.menge * pos.zolleinzelwert;
|
||||
}
|
||||
return sum;
|
||||
},
|
||||
total_weight() {
|
||||
let sum = 0;
|
||||
for(const pos of this.form.positions) {
|
||||
sum += pos.menge * pos.zolleinzelgewicht;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit: function() {
|
||||
let app = this;
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', location.href, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.onload = function () {
|
||||
let json = JSON.parse(this.response);
|
||||
app.messages = json.messages;
|
||||
}
|
||||
xhr.send(JSON.stringify($.extend({submit:'print'}, this.form)));
|
||||
},
|
||||
addPosition: function() {
|
||||
this.form.positions.push({ });
|
||||
},
|
||||
deletePosition: function(index) {
|
||||
this.form.positions.splice(index, 1);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
@ -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;
|
||||
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 = $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;
|
||||
$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)";
|
||||
'$json->weight', '$result->TrackingNumber', '$result->TrackingUrl', 1)";
|
||||
$this->app->DB->Insert($sql);
|
||||
$this->app->Tpl->addMessage('info', "Paketmarke wurde erfolgreich erstellt: $result->TrackingNumber");
|
||||
$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';
|
||||
$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);
|
||||
$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 {
|
||||
$this->app->Tpl->addMessage('error', $result);
|
||||
$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');
|
||||
}
|
||||
|
||||
|
@ -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 ?? []);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user