Basic Sendcloud integration with Shipment rework

This commit is contained in:
Andreas Palm 2022-10-21 10:46:09 +02:00
parent 2b5d01b52a
commit cd93d643f8
24 changed files with 1358 additions and 1390 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
class Document
{
public const TYPE_LABEL = 'label';
public const TYPE_CP71 = 'cp71';
public const TYPE_CN23 = 'cn23';
public const TYPE_CN23_DEFAULT = 'cn23-default';
public const TYPE_COMMERCIAL_INVOICE = 'commercial-invoice';
public string $Type;
public string $Size;
public string $Link;
public static function fromApiResponse(object $data): Document
{
$obj = new Document();
$obj->Type = $data->type;
$obj->Size = $data->size;
$obj->Link = $data->link;
return $obj;
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
abstract class ParcelBase
{
public ?string $Name = null;
public ?string $CompanyName = null;
public ?string $Address = null;
public ?string $Address2 = null;
public ?string $HouseNumber = null;
public ?string $City = null;
public ?string $PostalCode = null;
public ?string $Telephone = null;
public bool $RequestLabel = true;
public ?string $EMail = null;
public ?string $Country = null;
public ?int $ShippingMethodId = null;
/**
* @var ?int weight in grams
*/
public ?int $Weight = null;
public ?string $OrderNumber = null;
public ?string $TotalOrderValueCurrency = null;
public ?float $TotalOrderValue = null;
public ?string $CountryState = null;
public ?string $CustomsInvoiceNr = null;
public ?int $CustomsShipmentType = null;
public ?string $ExternalReference = null;
public ?int $TotalInsuredValue = null;
public ?array $ParcelItems = array();
public bool $IsReturn = false;
public ?string $Length = null;
public ?string $Width = null;
public ?string $Height = null;
}

View File

@ -0,0 +1,41 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
class ParcelCreation extends ParcelBase
{
public ?int $SenderAddressId = null;
public function toApiRequest(): array {
return [
'name' => $this->Name,
'company_name' => $this->CompanyName,
'address' => $this->Address,
'address_2' => $this->Address2,
'house_number' => $this->HouseNumber,
'city' => $this->City,
'postal_code' => $this->PostalCode,
'telephone' => $this->Telephone,
'request_label' => $this->RequestLabel,
'email' => $this->EMail,
'country' => $this->Country,
'shipment' => ['id' => $this->ShippingMethodId],
'weight' => number_format($this->Weight / 1000, 3, '.', null),
'order_number' => $this->OrderNumber,
'total_order_value_currency' => $this->TotalOrderValueCurrency,
'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,
'parcel_items' => array_map(fn(ParcelItem $item)=>$item->toApiRequest(), $this->ParcelItems),
'is_return' => $this->IsReturn,
'length' => $this->Length,
'width' => $this->Width,
'height' => $this->Height,
];
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
class ParcelCreationError
{
public int $Code;
public string $Message;
public string $Request;
}

View File

@ -0,0 +1,51 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
class ParcelItem
{
public string $HsCode;
/**
* @var int weight in grams
*/
public int $Weight;
public int $Quantity;
public string $Description;
public string $OriginCountry;
public float $Price;
public string $PriceCurrency;
public string $Sku;
public string $ProductId;
public function toApiRequest(): array {
return [
'hs_code' => $this->HsCode,
'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,
];
}
public static function fromApiResponse(object $data): ParcelItem
{
$obj = new ParcelItem();
$obj->HsCode = $data->hs_code;
$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->OriginCountry = $data->origin_country;
$obj->Sku = $data->sku;
$obj->ProductId = $data->product_id;
return $obj;
}
}

View File

@ -0,0 +1,76 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
use DateTimeImmutable;
use Exception;
class ParcelResponse extends ParcelBase
{
public int $Id;
public string $CarrierCode;
public DateTimeImmutable $DateCreated;
public DateTimeImmutable $DateUpdated;
public DateTimeImmutable $DateAnnounced;
public string $ShipmentMethodName;
public int $StatusId;
public string $StatusMessage;
public array $Documents;
public ?string $TrackingNumber = null;
public ?string $TrackingUrl = null;
public ?array $Errors;
public function GetDocumentByType(string $type): ?Document
{
/** @var Document $item */
foreach ($this->Documents as $item)
if ($item->Type == $type)
return $item;
return null;
}
/**
* @throws Exception
*/
public static function fromApiResponse(object $data): ParcelResponse
{
$obj = new ParcelResponse();
$obj->Address = $data->address_divided->street;
$obj->Address2 = $data->address_2;
$obj->HouseNumber = $data->address_divided->house_number;
$obj->CarrierCode = $data->carrier->code;
$obj->City = $data->city;
$obj->CompanyName = $data->company_name;
$obj->Country = $data->country->iso_2;
$obj->CustomsInvoiceNr = $data->customs_invoice_nr;
$obj->CustomsShipmentType = $data->customs_shipment_type;
$obj->DateCreated = new DateTimeImmutable($data->date_created);
$obj->DateUpdated = new DateTimeImmutable($data->date_updated);
$obj->DateAnnounced = new DateTimeImmutable($data->date_announced);
$obj->EMail = $data->email;
$obj->Id = $data->id;
$obj->Name = $data->name;
$obj->OrderNumber = $data->order_number;
$obj->ParcelItems = array_map(fn($item)=>ParcelItem::fromApiResponse($item), $data->parcel_items);
$obj->PostalCode = $data->postal_code;
$obj->ExternalReference = $data->external_reference;
$obj->ShippingMethodId = $data->shipment->id;
$obj->ShipmentMethodName = $data->shipment->name;
$obj->StatusId = $data->status->id;
$obj->StatusMessage = $data->status->message;
$obj->Documents = array_map(fn($item)=>Document::fromApiResponse($item), $data->documents);
$obj->Telephone = $data->telephone;
$obj->TotalInsuredValue = $data->total_insured_value;
$obj->TotalOrderValue = $data->total_order_value;
$obj->TotalOrderValueCurrency = $data->total_order_value_currency;
$obj->TrackingNumber = $data->tracking_number;
$obj->TrackingUrl = $data->tracking_url;
$obj->Weight = $data->weight;
$obj->Length = $data->length;
$obj->Height = $data->height;
$obj->Width = $data->width;
$obj->IsReturn = $data->is_return;
$obj->Errors = $data->errors->non_field_errors;
return $obj;
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
class SenderAddress {
public ?string $City;
public ?string $CompanyName;
public ?string $ContactName;
public string $Country;
public ?string $CountryState;
public ?string $Email;
public ?string $HouseNumber;
public int $Id;
public ?string $PostalBox;
public ?string $PostalCode;
public ?string $Street;
public ?string $Telephone;
public ?string $VatNumber;
public ?string $EoriNumber;
public int $BrandId;
public ?string $Label;
public ?string $SignatureFullName;
public ?string $SignatureInitials;
public function __toString(): string
{
return "$this->CompanyName; $this->ContactName; $this->Street $this->HouseNumber; $this->PostalCode; $this->City";
}
public static function fromApiResponse(object $data): SenderAddress {
$obj = new SenderAddress();
$obj->City = $data->city;
$obj->CompanyName = $data->company_name;
$obj->ContactName = $data->contact_name;
$obj->Country = $data->country;
$obj->CountryState = $data->country_state;
$obj->Email = $data->email;
$obj->HouseNumber = $data->house_number;
$obj->Id = $data->id;
$obj->PostalBox = $data->postal_box;
$obj->PostalCode = $data->postal_code;
$obj->Street = $data->street;
$obj->Telephone = $data->telephone;
$obj->VatNumber = $data->vat_number;
$obj->EoriNumber = $data->eori_number;
$obj->BrandId = $data->brand_id;
$obj->Label = $data->label;
$obj->SignatureFullName = $data->signature_full_name;
$obj->SignatureInitials = $data->signature_initials;
return $obj;
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
class ShippingMethod {
public int $Id;
public string $Name;
public ?string $Carrier;
public int $MinWeight;
public int $MaxWeight;
public int $MaxLength;
public int $MaxWidth;
public int $MaxHeight;
public string $Unit;
public static function fromApiResponse(object $data):ShippingMethod {
$obj = new ShippingMethod();
$obj->Id = $data->id;
$obj->Name = $data->name;
$obj->Carrier = $data->carrier ?? null;
$obj->MinWeight = $data->properties->min_weight;
$obj->MaxWeight = $data->properties->max_weight;
$obj->MaxLength = $data->properties->max_dimensions->length;
$obj->MaxWidth = $data->properties->max_dimensions->width;
$obj->MaxHeight = $data->properties->max_dimensions->height;
$obj->Unit = $data->properties->max_dimensions->unit;
return $obj;
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Xentral\Carrier\SendCloud\Data;
class ShippingProduct {
public string $Name;
public string $Carrier;
public string $ServicePointsCarrier;
public string $Code;
public int $MinWeight;
public int $MaxWeight;
public array $ShippingMethods;
public static function fromApiResponse(object $data): ShippingProduct {
$obj = new ShippingProduct();
$obj->Name = $data->name;
$obj->Carrier = $data->carrier;
$obj->ServicePointsCarrier = $data->service_points_carrier;
$obj->Code = $data->code;
$obj->MinWeight = $data->weight_range->min_weight;
$obj->MaxWeight = $data->weight_range->max_weight;
foreach ($data->methods as $method) {
$child = ShippingMethod::fromApiResponse($method);
$child->Carrier = $obj->Carrier;
$obj->ShippingMethods[] = $child;
}
return $obj;
}
}

View File

@ -0,0 +1,124 @@
<?php
namespace Xentral\Carrier\SendCloud;
use Exception;
use Xentral\Carrier\SendCloud\Data\Document;
use Xentral\Carrier\SendCloud\Data\ParcelCreation;
use Xentral\Carrier\SendCloud\Data\ParcelResponse;
use Xentral\Carrier\SendCloud\Data\SenderAddress;
use Xentral\Carrier\SendCloud\Data\ShippingProduct;
class SendCloudApi
{
/**
* @var ?string $public_key
*/
protected ?string $public_key;
/**
* @var ?string $private_key
*/
protected ?string $private_key;
const PROD_BASE_URI = 'https://panel.sendcloud.sc/api/v2';
public function __construct($public_key, $private_key)
{
$this->public_key = $public_key;
$this->private_key = $private_key;
}
public function GetSenderAddresses(): array
{
$uri = self::PROD_BASE_URI . '/user/addresses/sender';
$response = $this->sendRequest($uri);
$res = array();
foreach ($response->sender_addresses as $item)
$res[] = SenderAddress::fromApiResponse($item);
return $res;
}
public function GetShippingProducts(string $sourceCountry, ?string $targetCountry = null, ?int $weight = null,
?int $height = null, ?int $length = null, ?int $width = null): array
{
$uri = self::PROD_BASE_URI . '/shipping-products';
$params = ['from_country' => $sourceCountry];
if ($targetCountry !== null)
$params['to_country'] = $targetCountry;
if ($weight !== null && $weight > 0)
$params['weight'] = $weight;
if ($height !== null && $height > 0) {
$params['height'] = $height;
$params['height_unit'] = 'centimeter';
}
if ($length !== null && $length > 0) {
$params['length'] = $length;
$params['length_unit'] = 'centimeter';
}
if ($width !== null && $width > 0) {
$params['width'] = $width;
$params['width_unit'] = 'centimeter';
}
$response = $this->sendRequest($uri, $params);
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;
return null;
}
public function DownloadDocument(Document $document): string
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $document->Link,
CURLOPT_HTTPHEADER => [
"Authorization: Basic " . base64_encode($this->public_key . ':' . $this->private_key)
],
]);
return curl_exec($curl);
}
function sendRequest(string $uri, array $query_params = null, bool $post = false, array $postFields = null)
{
if (empty($this->public_key) || empty($this->private_key))
return null;
$curl = curl_init();
if (is_array($query_params)) {
$uri .= '?' . http_build_query($query_params);
}
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $uri,
CURLOPT_HTTPHEADER => [
"Authorization: Basic " . base64_encode($this->public_key . ':' . $this->private_key),
'Content-Type: application/json'
],
]);
if ($post === true) {
curl_setopt_array($curl, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($postFields)
]);
}
$output = curl_exec($curl);
curl_close($curl);
return json_decode($output);
}
}

View File

@ -11,35 +11,14 @@ var ShippingMethodCreate = function ($) {
vueElementId: '#shipment-create',
},
search: function (el) {
$.ajax({
url: 'index.php?module=versandarten&action=create&cmd=suche',
type: 'POST',
dataType: 'json',
data: {
val: $(el).val()
}
let val = $(el).val().toLowerCase();
$('.createbutton').each(function() {
let desc = $(this).find('.tilegrid-tile-title').text();
if (desc.toLowerCase().indexOf(val)>=0)
$(this).show();
else
$(this).hide();
})
.done(function (data) {
if (typeof data != 'undefined' && data != null) {
if (typeof data.ausblenden != 'undefined' && data.ausblenden != null) {
me.storage.hideElements = data.ausblenden.split(';');
$.each(me.storage.hideElements, function (k, v) {
if (v != '') {
$('#' + v).hide();
}
});
}
if (typeof data.anzeigen != 'undefined' && data.anzeigen != null) {
me.storage.showElements = data.anzeigen.split(';');
$.each(me.storage.showElements, function (k, v) {
if (v != '') {
$('#' + v).show();
}
});
}
}
});
},
init: function () {
if ($(me.selector.vueElementId).length === 0) {

View File

@ -20463,33 +20463,11 @@ if($id > 0)
}
//@refactor ApplicationCore
function LoadVersandModul($modul, $id)
function LoadVersandModul(string $modul, int $id): Versanddienstleister
{
if(empty($modul) ||
strpos($modul,'..') !== false ||
!@is_file(__DIR__.'/versandarten/'.$modul.'.php')
)
{
return;
}
$class_name = 'Versandart_'.$modul;
$class_name_custom = 'Versandart_'.$modul.'Custom';
if(!class_exists($class_name))
{
if(@is_file(__DIR__.'/versandarten/'.$modul.'_custom.php'))
{
include_once(__DIR__.'/versandarten/'.$modul.'_custom.php');
}else{
include_once(__DIR__.'/versandarten/'.$modul.'.php');
}
}
if(class_exists($class_name_custom))
{
return new $class_name_custom($this->app, $id);
}elseif(class_exists($class_name))
{
return new $class_name($this->app, $id);
}
/** @var Versandarten $versandarten */
$versandarten = $this->app->loadModule('versandarten');
return $versandarten->loadModule($modul, $id);
}
//@refactor versanddiestleister Modul
@ -20562,131 +20540,131 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
}
}
if($sid=="versand")
{
// falche tracingnummer bei DHL da wir in der Funktion PaketmarkeDHLEmbedded sind
if((strlen($tracking) < 12 || strlen($tracking) > 21) && $trackingsubmitcancel=="" && ($typ=="DHL" || $typ=="Intraship"))
if($sid=="versand")
{
header("Location: index.php?module=versanderzeugen&action=frankieren&id=$id&land=$land&tracking_again=1");
exit;
}
else
{
/* $versandartenmodul = $this->app->DB->SelectArr("SELECT id, modul,bezeichnung FROM versandarten WHERE aktiv = 1 AND ausprojekt = 0 AND type = '".$this->app->DB->real_escape_string($typ)."' AND modul != '' AND (projekt = 0 OR projekt = '$projekt') ORDER BY projekt DESC LIMIT 1");
if($versandartenmodul && @is_file(dirname(__FILE__).'/versandarten/'.$versandartenmodul[0]['modul'].'.php'))
// falche tracingnummer bei DHL da wir in der Funktion PaketmarkeDHLEmbedded sind
if((strlen($tracking) < 12 || strlen($tracking) > 21) && $trackingsubmitcancel=="" && ($typ=="DHL" || $typ=="Intraship"))
{
$obj = $this->LoadVersandModul($versandartenmodul[0]['modul'], $versandartenmodul[0]['id']);
if(!empty($obj) && method_exists($obj, 'TrackingReplace'))
{
$tracking = $obj->TrackingReplace($tracking);
}
header("Location: index.php?module=versanderzeugen&action=frankieren&id=$id&land=$land&tracking_again=1");
exit;
}
else
{
/* $versandartenmodul = $this->app->DB->SelectArr("SELECT id, modul,bezeichnung FROM versandarten WHERE aktiv = 1 AND ausprojekt = 0 AND type = '".$this->app->DB->real_escape_string($typ)."' AND modul != '' AND (projekt = 0 OR projekt = '$projekt') ORDER BY projekt DESC LIMIT 1");
if($versandartenmodul && @is_file(dirname(__FILE__).'/versandarten/'.$versandartenmodul[0]['modul'].'.php'))
{
$obj = $this->LoadVersandModul($versandartenmodul[0]['modul'], $versandartenmodul[0]['id']);
if(!empty($obj) && method_exists($obj, 'TrackingReplace'))
{
$tracking = $obj->TrackingReplace($tracking);
}
}
*/
$trackingUser = !empty($this->app->User) && method_exists($this->app->User,'GetParameter')?
$this->app->User->GetParameter('versand_lasttracking'):'';
$trackingUser = !empty($this->app->User) && method_exists($this->app->User,'GetParameter')?
$this->app->User->GetParameter('versand_lasttracking'):'';
if(!empty($trackingUser) && in_array($trackingUser,[$trackingBefore,$tracking])) {
$this->app->User->SetParameter('versand_lasttracking','');
$this->app->User->SetParameter('versand_lasttracking_link','');
$this->app->User->SetParameter('versand_lasttracking_versand', '');
$this->app->User->SetParameter('versand_lasttracking_lieferschein', '');
}
if(!empty($trackingUser) && in_array($trackingUser,[$trackingBefore,$tracking])) {
$this->app->User->SetParameter('versand_lasttracking','');
$this->app->User->SetParameter('versand_lasttracking_link','');
$this->app->User->SetParameter('versand_lasttracking_versand', '');
$this->app->User->SetParameter('versand_lasttracking_lieferschein', '');
}
$this->app->DB->Update("UPDATE versand SET versandunternehmen='$versand', tracking='$tracking',
versendet_am=NOW(),versendet_am_zeitstempel=NOW(), abgeschlossen='1',logdatei=NOW() WHERE id='$id' LIMIT 1");
if($lieferschein = $this->app->DB->Select("SELECT lieferschein FROM versand WHERE id = '$id' LIMIT 1")) {
$this->app->erp->LieferscheinProtokoll($lieferschein,'Verarbeitung im Versandzentrum');
}
$rechnung = $this->app->DB->Select("SELECT rechnung FROM versand WHERE id = '$id' LIMIT 1");
if($lieferschein && ($auftrag = $this->app->DB->Select("SELECT auftragid FROM lieferschein WHERE id = '$lieferschein'"))) {
$this->app->erp->AuftragProtokoll($auftrag,'Verarbeitung im Versandzentrum');
$this->app->DB->Update("UPDATE versand SET versandunternehmen='$versand', tracking='$tracking',
versendet_am=NOW(),versendet_am_zeitstempel=NOW(), abgeschlossen='1',logdatei=NOW() WHERE id='$id' LIMIT 1");
if($lieferschein = $this->app->DB->Select("SELECT lieferschein FROM versand WHERE id = '$id' LIMIT 1")) {
$this->app->erp->LieferscheinProtokoll($lieferschein,'Verarbeitung im Versandzentrum');
}
$rechnung = $this->app->DB->Select("SELECT rechnung FROM versand WHERE id = '$id' LIMIT 1");
if($lieferschein && ($auftrag = $this->app->DB->Select("SELECT auftragid FROM lieferschein WHERE id = '$lieferschein'"))) {
$this->app->erp->AuftragProtokoll($auftrag,'Verarbeitung im Versandzentrum');
if(empty($rechnung)) {
$rechnung = $this->app->DB->Select(
sprintf(
"SELECT id FROM rechnung WHERE auftragid = %d AND status <> 'storniert' AND belegnr <> '' LIMIT 1",
$auftrag
)
);
if($rechnung) {
$this->app->DB->Update(
if(empty($rechnung)) {
$rechnung = $this->app->DB->Select(
sprintf(
'UPDATE versand SET rechnung = %d WHERE id = %d AND rechnung = 0',
$rechnung, $id
"SELECT id FROM rechnung WHERE auftragid = %d AND status <> 'storniert' AND belegnr <> '' LIMIT 1",
$auftrag
)
);
if($rechnung) {
$this->app->DB->Update(
sprintf(
'UPDATE versand SET rechnung = %d WHERE id = %d AND rechnung = 0',
$rechnung, $id
)
);
}
}
}
}
$projekt = $this->app->DB->Select("SELECT projekt FROM lieferschein WHERE id = '$lieferschein' LIMIT 1");
if($lieferschein) {
$projekt = $this->app->DB->Select("SELECT projekt FROM lieferschein WHERE id = '$lieferschein' LIMIT 1");
if($lieferschein) {
$this->PDFArchivieren('lieferschein', $lieferschein, true);
}
$proformaPrinted = false;
$druckennachtracking = $this->app->erp->Projektdaten($projekt,'druckennachtracking');
if($druckennachtracking
&& !($proformarechnung = $this->app->DB->Select(
sprintf(
'SELECT id FROM proformarechnung WHERE lieferschein = %d LIMIT 1',
$lieferschein
$this->PDFArchivieren('lieferschein', $lieferschein, true);
}
$proformaPrinted = false;
$druckennachtracking = $this->app->erp->Projektdaten($projekt,'druckennachtracking');
if($druckennachtracking
&& !($proformarechnung = $this->app->DB->Select(
sprintf(
'SELECT id FROM proformarechnung WHERE lieferschein = %d LIMIT 1',
$lieferschein
)
)
)
)
) {
/** @var Versanderzeugen $versandObj */
$versandObj = $this->LoadModul('versanderzeugen');
if($versandObj !== null && method_exists($versandObj, 'checkPrintCreateProformaInvoice')) {
$druckercode = $this->app->DB->Select("SELECT druckerlogistikstufe2 FROM projekt WHERE id='$projekt' LIMIT 1");
)
) {
/** @var Versanderzeugen $versandObj */
$versandObj = $this->LoadModul('versanderzeugen');
if($versandObj !== null && method_exists($versandObj, 'checkPrintCreateProformaInvoice')) {
$druckercode = $this->app->DB->Select("SELECT druckerlogistikstufe2 FROM projekt WHERE id='$projekt' LIMIT 1");
if($druckercode <=0) {
$druckercode = $this->app->erp->Firmendaten('standardversanddrucker'); // standard = 3 // 2 buchhaltung // 1 empfang
if($druckercode <=0) {
$druckercode = $this->app->erp->Firmendaten('standardversanddrucker'); // standard = 3 // 2 buchhaltung // 1 empfang
}
$userversanddrucker = $this->app->DB->Select("SELECT standardversanddrucker FROM user WHERE id='".$this->app->User->GetID()."'");
if($userversanddrucker>0) {
$druckercode = $userversanddrucker;
}
$deliveryArr = $this->app->DB->SelectRow(
sprintf('SELECT land FROM lieferschein WHERE id = %d', $lieferschein)
);
$country = $deliveryArr['land'];
$versandObj->checkPrintCreateProformaInvoice($lieferschein,$country,$projekt,$druckercode,true);
$proformaPrinted = $druckercode > 0;
}
$userversanddrucker = $this->app->DB->Select("SELECT standardversanddrucker FROM user WHERE id='".$this->app->User->GetID()."'");
if($userversanddrucker>0) {
$druckercode = $userversanddrucker;
}
$deliveryArr = $this->app->DB->SelectRow(
sprintf('SELECT land FROM lieferschein WHERE id = %d', $lieferschein)
}
if($rechnung) {
$this->PDFArchivieren('rechnung', $rechnung, true);
}
elseif($auftrag && $druckennachtracking
&& $this->app->DB->Select(
sprintf(
"SELECT id FROM auftrag WHERE id = %d AND art <> 'lieferung'",
$auftrag
)
)
) {
$rechnung = $this->WeiterfuehrenAuftragZuRechnung($auftrag);
$this->BelegFreigabe('rechnung', $rechnung);
$this->app->DB->Update(
sprintf(
'UPDATE versand SET rechnung = %d WHERE id = %d LIMIT 1',
$rechnung, $id
)
);
$country = $deliveryArr['land'];
$versandObj->checkPrintCreateProformaInvoice($lieferschein,$country,$projekt,$druckercode,true);
$proformaPrinted = $druckercode > 0;
$this->app->DB->Update(
sprintf(
"UPDATE rechnung SET schreibschutz = 1, status = 'versendet' WHERE id = %d",
$rechnung
)
);
$this->PDFArchivieren('rechnung', $rechnung, true);
}
}
if($rechnung) {
$this->PDFArchivieren('rechnung', $rechnung, true);
}
elseif($auftrag && $druckennachtracking
&& $this->app->DB->Select(
sprintf(
"SELECT id FROM auftrag WHERE id = %d AND art <> 'lieferung'",
$auftrag
)
)
) {
$rechnung = $this->WeiterfuehrenAuftragZuRechnung($auftrag);
$this->BelegFreigabe('rechnung', $rechnung);
$this->app->DB->Update(
sprintf(
'UPDATE versand SET rechnung = %d WHERE id = %d LIMIT 1',
$rechnung, $id
)
);
$this->app->DB->Update(
sprintf(
"UPDATE rechnung SET schreibschutz = 1, status = 'versendet' WHERE id = %d",
$rechnung
)
);
$this->PDFArchivieren('rechnung', $rechnung, true);
}
if($rechnung > 0 && $druckennachtracking
&& $this->app->DB->Select("SELECT count(id) FROM versand WHERE lieferschein = '$lieferschein'") <= 1) {
$druckercode = $this->app->DB->Select("SELECT druckerlogistikstufe2 FROM projekt WHERE id='$projekt' LIMIT 1");
if($rechnung > 0 && $druckennachtracking
&& $this->app->DB->Select("SELECT count(id) FROM versand WHERE lieferschein = '$lieferschein'") <= 1) {
$druckercode = $this->app->DB->Select("SELECT druckerlogistikstufe2 FROM projekt WHERE id='$projekt' LIMIT 1");
if($druckercode <=0)
$druckercode = $this->app->erp->Firmendaten("standardversanddrucker"); // standard = 3 // 2 buchhaltung // 1 empfang
@ -20695,32 +20673,12 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
if($userversanddrucker>0)
$druckercode = $userversanddrucker;
$this->app->erp->BriefpapierHintergrundDisable($druckercode);
$this->app->erp->BriefpapierHintergrundDisable($druckercode);
$addressId = $this->app->DB->Select("SELECT `adresse` FROM `rechnung` WHERE `id` = '{$rechnung}' LIMIT 1");
$printInvoice = $this->app->DB->Select("SELECT `rechnung_papier` FROM `adresse` WHERE `id` = '{$addressId}' LIMIT 1");
$amountPrintedInvoices = $this->app->DB->Select("SELECT `rechnung_anzahlpapier` FROM `adresse` WHERE `id` = '{$addressId}' LIMIT 1");
if($printInvoice === '1' && $amountPrintedInvoices > 0){
if(class_exists('RechnungPDFCustom'))
{
$Brief = new RechnungPDFCustom($this->app,$projekt);
}else{
$Brief = new RechnungPDF($this->app,$projekt);
}
$Brief->GetRechnung($rechnung);
$tmpfile = $Brief->displayTMP();
for($i = 1; $i <= $amountPrintedInvoices; $i++) {
$this->app->printer->Drucken($druckercode,$tmpfile);
}
} else {
$autodruckrechnungmenge = $this->app->erp->Projektdaten($projekt,"autodruckrechnungmenge");
$autodruckrechnung= $this->app->erp->Projektdaten($projekt,"autodruckrechnung");
if($autodruckrechnungmenge < 0)$autodruckrechnungmenge = 1;
if($autodruckrechnung > 0)
{
$addressId = $this->app->DB->Select("SELECT `adresse` FROM `rechnung` WHERE `id` = '{$rechnung}' LIMIT 1");
$printInvoice = $this->app->DB->Select("SELECT `rechnung_papier` FROM `adresse` WHERE `id` = '{$addressId}' LIMIT 1");
$amountPrintedInvoices = $this->app->DB->Select("SELECT `rechnung_anzahlpapier` FROM `adresse` WHERE `id` = '{$addressId}' LIMIT 1");
if($printInvoice === '1' && $amountPrintedInvoices > 0){
if(class_exists('RechnungPDFCustom'))
{
$Brief = new RechnungPDFCustom($this->app,$projekt);
@ -20730,88 +20688,108 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
$Brief->GetRechnung($rechnung);
$tmpfile = $Brief->displayTMP();
for($i = 1; $i <= $autodruckrechnungmenge; $i++) {
for($i = 1; $i <= $amountPrintedInvoices; $i++) {
$this->app->printer->Drucken($druckercode,$tmpfile);
}
} else {
$autodruckrechnungmenge = $this->app->erp->Projektdaten($projekt,"autodruckrechnungmenge");
$autodruckrechnung= $this->app->erp->Projektdaten($projekt,"autodruckrechnung");
if($autodruckrechnungmenge < 0)$autodruckrechnungmenge = 1;
if($autodruckrechnung > 0)
{
if(class_exists('RechnungPDFCustom'))
{
$Brief = new RechnungPDFCustom($this->app,$projekt);
}else{
$Brief = new RechnungPDF($this->app,$projekt);
}
$Brief->GetRechnung($rechnung);
$tmpfile = $Brief->displayTMP();
for($i = 1; $i <= $autodruckrechnungmenge; $i++) {
$this->app->printer->Drucken($druckercode,$tmpfile);
}
}
}
}
// Print additional invoices for export
$exportdruckrechnung = $this->app->erp->Projektdaten($projekt,"exportdruckrechnung");
if($exportdruckrechnung)
{
$exportland = $this->app->DB->Select("SELECT land FROM rechnung WHERE id = '$rechnung' LIMIT 1");
$exportdruckrechnung = $this->app->erp->Export($exportland);
// Print additional invoices for export
$exportdruckrechnung = $this->app->erp->Projektdaten($projekt,"exportdruckrechnung");
if($exportdruckrechnung)
{
$mengedruck = $this->app->erp->Projektdaten($projekt,"exportdruckrechnungmenge");
for($mengedruck;$mengedruck > 0;$mengedruck--)
$exportland = $this->app->DB->Select("SELECT land FROM rechnung WHERE id = '$rechnung' LIMIT 1");
$exportdruckrechnung = $this->app->erp->Export($exportland);
if($exportdruckrechnung)
{
$this->app->printer->Drucken($druckercode,$tmpfile);
$mengedruck = $this->app->erp->Projektdaten($projekt,"exportdruckrechnungmenge");
for($mengedruck;$mengedruck > 0;$mengedruck--)
{
$this->app->printer->Drucken($druckercode,$tmpfile);
}
}
}
}
unlink($tmpfile);
if($this->app->erp->Projektdaten($projekt,"automailrechnung")=="1")
{
// aber nur das erste mal also wenn es einen eintrag in der versand tabelle gibt
$rechnungbereitsversendet = $this->app->DB->Select("SELECT versendet FROM rechnung WHERE id = '$rechnung' LIMIT 1");
if($rechnungbereitsversendet!="1")
unlink($tmpfile);
if($this->app->erp->Projektdaten($projekt,"automailrechnung")=="1")
{
$this->app->erp->Rechnungsmail($rechnung);
}
}
$this->BriefpapierHintergrundEnable();
}
if($druckennachtracking && $lieferschein && $this->Export($land)
&& $this->Projektdaten($projekt, 'proformainvoice_amount') && $proformaRechnungId = $this->app->DB->Select(
sprintf(
"SELECT id FROM proformarechnung WHERE lieferschein = %d AND status <> 'storniert' LIMIT 1",
$lieferschein
))
) {
/** @var Versanderzeugen $objProforma */
$objVersand = $this->LoadModul('versanderzeugen');
if($objVersand && method_exists($objVersand,'checkPrintCreateProformaInvoice')){
if(empty($druckercode)) {
$druckercode = $this->app->DB->Select("SELECT druckerlogistikstufe2 FROM projekt WHERE id='$projekt' LIMIT 1");
if($druckercode <= 0) {
$druckercode = $this->app->erp->Firmendaten('standardversanddrucker'); // standard = 3 // 2 buchhaltung // 1 empfang
}
$userversanddrucker = $this->app->DB->Select("SELECT standardversanddrucker FROM user WHERE id='" . $this->app->User->GetID() . "'");
if($userversanddrucker > 0) {
$druckercode = $userversanddrucker;
// aber nur das erste mal also wenn es einen eintrag in der versand tabelle gibt
$rechnungbereitsversendet = $this->app->DB->Select("SELECT versendet FROM rechnung WHERE id = '$rechnung' LIMIT 1");
if($rechnungbereitsversendet!="1")
{
$this->app->erp->Rechnungsmail($rechnung);
}
}
$objVersand->checkPrintCreateProformaInvoice($lieferschein, $land, $projekt, $druckercode, empty($proformaPrinted));
$this->BriefpapierHintergrundEnable();
}
}
if(!$this->app->erp->Firmendaten('versandmail_zwischenspeichern') || !$this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'versandmailsundrueckmeldung' AND aktiv = 1"))
{
$this->VersandAbschluss($id);
$this->RunHook('versanderzeugen_frankieren_hook1', 1, $id);
//versand mail an kunden
$this->Versandmail($id);
}else{
$this->app->DB->Update("UPDATE versand SET cronjob = 1 WHERE id = '$id' LIMIT 1");
}
$weiterespaket=$this->app->Secure->GetPOST("weiterespaket");
$lieferscheinkopie=$this->app->Secure->GetPOST("lieferscheinkopie");
if($weiterespaket=="1")
{
if($lieferscheinkopie=="1") $lieferscheinkopie=0; else $lieferscheinkopie=1;
//$this->app->erp->LogFile("Lieferscheinkopie $lieferscheinkopie");
$all = $this->app->DB->SelectArr("SELECT * FROM versand WHERE id='$id' LIMIT 1");
$this->app->DB->Insert("INSERT INTO versand (id,adresse,rechnung,lieferschein,versandart,projekt,bearbeiter,versender,versandunternehmen,firma,
keinetrackingmail,gelesen,paketmarkegedruckt,papieregedruckt,weitererlieferschein)
VALUES ('','{$all[0]['adresse']}','{$all[0]['rechnung']}','{$all[0]['lieferschein']}','{$all[0]['versandart']}','{$all[0]['projekt']}',
'{$all[0]['bearbeiter']}','{$all[0]['versender']}','{$all[0]['versandunternehmen']}',
'{$all[0]['firma']}','{$all[0]['keinetrackingmail']}','{$all[0]['gelesen']}',0,$lieferscheinkopie,1)");
if($druckennachtracking && $lieferschein && $this->Export($land)
&& $this->Projektdaten($projekt, 'proformainvoice_amount') && $proformaRechnungId = $this->app->DB->Select(
sprintf(
"SELECT id FROM proformarechnung WHERE lieferschein = %d AND status <> 'storniert' LIMIT 1",
$lieferschein
))
) {
/** @var Versanderzeugen $objProforma */
$objVersand = $this->LoadModul('versanderzeugen');
if($objVersand && method_exists($objVersand,'checkPrintCreateProformaInvoice')){
if(empty($druckercode)) {
$druckercode = $this->app->DB->Select("SELECT druckerlogistikstufe2 FROM projekt WHERE id='$projekt' LIMIT 1");
if($druckercode <= 0) {
$druckercode = $this->app->erp->Firmendaten('standardversanddrucker'); // standard = 3 // 2 buchhaltung // 1 empfang
}
$userversanddrucker = $this->app->DB->Select("SELECT standardversanddrucker FROM user WHERE id='" . $this->app->User->GetID() . "'");
if($userversanddrucker > 0) {
$druckercode = $userversanddrucker;
}
}
$objVersand->checkPrintCreateProformaInvoice($lieferschein, $land, $projekt, $druckercode, empty($proformaPrinted));
}
}
if(!$this->app->erp->Firmendaten('versandmail_zwischenspeichern') || !$this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'versandmailsundrueckmeldung' AND aktiv = 1"))
{
$this->VersandAbschluss($id);
$this->RunHook('versanderzeugen_frankieren_hook1', 1, $id);
//versand mail an kunden
$this->Versandmail($id);
}else{
$this->app->DB->Update("UPDATE versand SET cronjob = 1 WHERE id = '$id' LIMIT 1");
}
$weiterespaket=$this->app->Secure->GetPOST("weiterespaket");
$lieferscheinkopie=$this->app->Secure->GetPOST("lieferscheinkopie");
if($weiterespaket=="1")
{
if($lieferscheinkopie=="1") $lieferscheinkopie=0; else $lieferscheinkopie=1;
//$this->app->erp->LogFile("Lieferscheinkopie $lieferscheinkopie");
$all = $this->app->DB->SelectArr("SELECT * FROM versand WHERE id='$id' LIMIT 1");
$this->app->DB->Insert("INSERT INTO versand (id,adresse,rechnung,lieferschein,versandart,projekt,bearbeiter,versender,versandunternehmen,firma,
keinetrackingmail,gelesen,paketmarkegedruckt,papieregedruckt,weitererlieferschein)
VALUES ('','{$all[0]['adresse']}','{$all[0]['rechnung']}','{$all[0]['lieferschein']}','{$all[0]['versandart']}','{$all[0]['projekt']}',
'{$all[0]['bearbeiter']}','{$all[0]['versender']}','{$all[0]['versandunternehmen']}',
'{$all[0]['firma']}','{$all[0]['keinetrackingmail']}','{$all[0]['gelesen']}',0,$lieferscheinkopie,1)");
$newid = $this->app->DB->GetInsertID();
@ -20849,7 +20827,7 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
$this->app->DB->Insert("INSERT INTO versand (id,versandunternehmen, tracking,
versendet_am,abgeschlossen,retoure,
freigegeben,firma,adresse,projekt,gewicht,paketmarkegedruckt,anzahlpakete)
VALUES ('','$versand','$tracking',NOW(),1,'$id',1,'".$this->app->User->GetFirma()."','$adresse','$projekt','$kg','1','1') ");
VALUES ('','$versand','$tracking',NOW(),1,'$id',1,'".$this->app->User->GetFirma()."','$adresse','$projekt','$kg','1','1') ");
$versandid = $this->app->DB->GetInsertID();
if($this->app->DB->Select("SELECT automailversandbestaetigung FROM projekt WHERE id = '$projekt' LIMIT 1"))$this->Versandmail($versandid);
@ -20878,23 +20856,6 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
if($kg=="") {
$kg = $this->VersandartMindestgewicht($id);
}
/*
//Brauchen wir nicht
$versandartenmodul = $this->app->DB->SelectArr("SELECT id, modul,bezeichnung FROM versandarten WHERE aktiv = 1 AND ausprojekt = 0 AND type = '".$this->app->DB->real_escape_string($versand)."' AND modul != '' AND (projekt = 0 OR projekt = '$projekt') ORDER BY projekt DESC LIMIT 1");
if($versandartenmodul && @is_file(dirname(__FILE__).'/versandarten/'.$versandartenmodul[0]['modul'].'.php'))
{
$class_name = 'Versandart_'.$versandartenmodul[0]['modul'];
if(!class_exists($class_name))include_once(dirname(__FILE__).'/versandarten/'.$versandartenmodul[0]['modul'].'.php');
if(class_exists($class_name))
{
$obj = new $class_name($this->app, $versandartenmodul[0]['id']);
if(method_exists($obj, 'TrackingReplace')){
$tracking = $obj->TrackingReplace($tracking);
}
}
}
*/
$trackingUser = !empty($this->app->User) && method_exists($this->app->User,'GetParameter')?
$this->app->User->GetParameter('versand_lasttracking'):'';
@ -20905,9 +20866,9 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
$this->app->User->SetParameter('versand_lasttracking_lieferschein', '');
}
$this->app->DB->Insert("INSERT INTO versand (id,versandunternehmen, tracking, tracking_link,
versendet_am,abgeschlossen,lieferschein,
freigegeben,firma,adresse,projekt,gewicht,paketmarkegedruckt,anzahlpakete)
$this->app->DB->Insert("INSERT INTO versand (id,versandunternehmen, tracking, tracking_link,
versendet_am,abgeschlossen,lieferschein,
freigegeben,firma,adresse,projekt,gewicht,paketmarkegedruckt,anzahlpakete)
VALUES ('','$versand','$tracking', '{$trackingLink}',NOW(),1,'$id',1,'".$this->app->User->GetFirma()."','$adresse','$projekt','$kg','1','1') ");
$versandid = $this->app->DB->GetInsertID();
@ -20928,8 +20889,7 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
'SELECT zahlweise FROM rechnung WHERE id = %d', $rechnung
)
);
}
else{
} else {
$rechnung_projekt = $this->app->DB->Select(
sprintf(
'SELECT projekt FROM auftrag WHERE id = %d', $auftrag
@ -21064,176 +21024,17 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
if($kg=="") $kg=$this->VersandartMindestgewicht($lieferschein);
//$versandartenmodul = $this->app->DB->SelectArr("SELECT id, modul FROM versanddienstleister WHERE aktiv = 1 AND modul = '".$this->app->DB->real_escape_string($typ)."' AND (projekt = 0 OR projekt = '$projekt') ORDER BY projekt DESC LIMIT 1");
$versandartenmodul = $this->app->DB->SelectArr("SELECT id, modul,bezeichnung, einstellungen_json FROM versandarten WHERE aktiv = 1 AND ausprojekt = 0 AND type = '".$this->app->DB->real_escape_string($typ)."' AND modul != '' AND (projekt = 0 OR projekt = '$projekt') ORDER BY projekt DESC LIMIT 1");
if($versandartenmodul && @is_file(dirname(__FILE__).'/versandarten/'.$versandartenmodul[0]['modul'].'.php'))
{
$obj = $this->LoadVersandModul($versandartenmodul[0]['modul'], $versandartenmodul[0]['id']);
$this->app->Tpl->Set("ZUSATZ",$versandartenmodul[0]['bezeichnung']);
if(!empty($obj) && method_exists($obj, 'Paketmarke'))
$versandartenmodul = $this->app->DB->SelectArr("SELECT id, modul,bezeichnung, einstellungen_json FROM versandarten WHERE aktiv = 1 AND ausprojekt = 0 AND type = '".$this->app->DB->real_escape_string($typ)."' AND modul != '' AND (projekt = 0 OR projekt = '$projekt') ORDER BY projekt DESC LIMIT 1");
if($versandartenmodul && @is_file(dirname(__FILE__).'/versandarten/'.$versandartenmodul[0]['modul'].'.php'))
{
$error = $obj->Paketmarke($sid!=''?$sid:'lieferschein',$id);
}else $error[] = 'Versandmodul '.$typ.' fehlerhaft!';
}else{
switch($typ)
{
case "DHL":
if($nachnahme=="" && $versichert=="" && $extraversichert=="")
{
$this->EasylogPaketmarkeStandard($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg);
} else if ($nachnahme=="1" && $versichert=="" && $extraversichert=="")
{
$this->EasylogPaketmarkeNachnahme($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,$betrag,$rechnungsnummer);
} else if ($versichert=="1" && $extraversichert=="" && $nachnahme=="")
{
$this->EasylogPaketmarke2500($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg);
} else if ($versichert=="1" && $extraversichert=="" && $nachnahme=="1")
{
$this->EasylogPaketmarkeNachnahme2500($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,$betrag,$rechnungsnummer);
} else if ($versichert=="" && $extraversichert=="1" && $nachnahme=="1")
{
$this->EasylogPaketmarkeNachnahme25000($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,$betrag,$rechnungsnummer);
} else if ($extraversichert=="1" && $versichert=="" && $nachnahme=="")
{
$this->EasylogPaketmarke25000($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg);
}
break;
case "Intraship":
$kg = (float)str_replace(',','.',$kg);
$obj = $this->LoadVersandModul($versandartenmodul[0]['modul'], $versandartenmodul[0]['id']);
$this->app->Tpl->Set("ZUSATZ",$versandartenmodul[0]['bezeichnung']);
$abholdatum = $this->app->Secure->GetPOST("abholdatum");
$retourenlabel= $this->app->Secure->GetPOST("retourenlabel");
if($retourenlabel)
{
$this->app->Tpl->Set('RETOURENLABEL', ' checked="checked" ');
$zusaetzlich['retourenlabel'] = 1;
}
if($abholdatum){
$this->app->Tpl->Set('ABHOLDATUM',$abholdatum);
$zusaetzlich['abholdatum'] = date('Y-m-d', strtotime($abholdatum));
$this->app->User->SetParameter("paketmarke_abholdatum",$zusaetzlich['abholdatum']);
}
if($altersfreigabe)$zusaetzlich['altersfreigabe'] = 1;
if($nachnahme=="1")
$error = $this->IntrashipPaketmarkeNachnahme($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,$betrag,$rechnungsnummer,$zusaetzlich);
else
$error = $this->IntrashipPaketmarkeStandard($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,"",$rechnungsnummer,$zusaetzlich);
break;
case "UPS":
$error = $this->UPSPaketmarke($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,$betrag,$rechnungsnummer);
break;
case "FEDEX":
$error = $this->FEDEXPaketmarke($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,$betrag,$rechnungsnummer);
break;
case 'Go':
if($name && $strasse && $plz && $ort && (($hausnummer && (!$land || $land == 'DE') || ($land && $land != 'DE'))))
{
$kg = $this->app->Secure->GetPOST("kg");
if($kg=="") $kg=$this->VersandartMindestgewicht($lieferschein);
$kg = str_replace(',','.',$kg);
$frei = $this->app->Secure->GetPOST("frei")==1?1:0;
$auftragid = $this->app->DB->Select("SELECT auftragid FROM lieferschein where id = ".(int)$lieferschein." limit 1");
if($frei){
$this->app->Tpl->Set('FREI',' checked="checked" ');
$zusaetzlich['frei'] = 1;
}
$selbstabholung = $this->app->Secure->GetPOST("selbstabholung");
if($selbstabholung){
$this->app->Tpl->Set('SELBSTABHOLUNG',' checked="checked" ');
$zusaetzlich['selbstabholung'] = 1;
}
$landesvorwahl = $this->app->Secure->GetPOST("landesvorwahl");
if($landesvorwahl){
$this->app->Tpl->Set('LANDESVORWAHL',$landesvorwahl);
$zusaetzlich['landesvorwahl'] = $landesvorwahl;
}
$ortsvorwahl = $this->app->Secure->GetPOST("ortsvorwahl");
if($ortsvorwahl){
$this->app->Tpl->Set('ORTSVORWAHL',$ortsvorwahl);
$zusaetzlich['ortsvorwahl'] = $ortsvorwahl;
}
if($telefon)
{
$this->app->Tpl->Set('TELEFON',$telefon);
$zusaetzlich['telefon'] = $telefon;
}
if($email)
{
$this->app->Tpl->Set('EMAIL',trim($email));
$zusaetzlich['email'] = trim($email);
}
$selbstanlieferung = $this->app->Secure->GetPOST("selbstanlieferung");
if($selbstanlieferung){
$this->app->Tpl->Set('SELBSTANLIEFERUNG',' checked="checked" ');
$zusaetzlich['selbstanlieferung'] = 1;
}
$abholdatum = $this->app->Secure->GetPOST("abholdatum");
if($abholdatum){
$this->app->Tpl->Set('ABHOLDATUM',$abholdatum);
$zusaetzlich['abholdatum'] = $abholdatum;
$this->app->User->SetParameter("paketmarke_abholdatum",$zusaetzlich['abholdatum']);
}
$zustelldatum = $this->app->Secure->GetPOST("zustelldatum");
if(!$zustelldatum)
{
//$zustelldatum = $this->app->DB->Select("SELECT lieferdatum FROM rechnung where id = ".(int)$rechnungid." and lieferdatum > now() limit 1");
$zustelldatum = $this->app->DB->Select("SELECT lieferdatum FROM auftrag where id = ".(int)$auftragid." limit 1");
}
if($zustelldatum){
$this->app->Tpl->Set('ZUSTELLDATUM',$zustelldatum);
$zusaetzlich['zustelldatum'] = $zustelldatum;
}
if(!$abholdatum)
{
//$abholdatum = $this->app->DB->Select("SELECT tatsaechlicheslieferdatum FROM rechnung where id = ".(int)$rechnungid." and tatsaechlicheslieferdatum > now() limit 1");
$abholdatum = $this->app->DB->Select("SELECT date_format(now(),'%d.%m.%Y')");
/*if(!$abholdatum)
{
$projekt = $this->app->DB->Select("SELECT projekt FROM auftrag WHERE id='$auftragid' LIMIT 1");
$differenztage = $this->Projektdaten($projekt,"differenz_auslieferung_tage");
if($differenztage<0) $differenztage=2;
$abholdatum = $this->app->DB->Select("SELECT DATE_SUB(lieferdatum, INTERVAL $differenztage DAY) from auftrag WHERE id='$auftragid' and DATE_SUB(lieferdatum, INTERVAL $differenztage DAY) > now() LIMIT 1");
}*/
if($abholdatum)
{
$this->app->Tpl->Set('ABHOLDATUM',$abholdatum);
$zusaetzlich['abholdatum'] = $abholdatum;
$this->app->User->SetParameter("paketmarke_abholdatum",$zusaetzlich['abholdatum']);
}
}
$Zustellhinweise = $this->app->Secure->GetPOST("Zustellhinweise");
if($Zustellhinweise){
$this->app->Tpl->Set('ZUSTELLHINWEISE',$Zustellhinweise);
$zusaetzlich['Zustellhinweise'] = $Zustellhinweise;
}
$Abholhinweise = $this->app->Secure->GetPOST("Abholhinweise");
if($Abholhinweise){
$this->app->Tpl->Set('ABHOLHINWEISE',$Abholhinweise);
$zusaetzlich['Abholhinweise'] = $Abholhinweise;
}
if($anzahl)$zusaetzlich['menge'] = $anzahl;
$inhalt = $this->app->Secure->GetPOST("inhalt");
if($inhalt){
$this->app->Tpl->Set('INHALT',$inhalt);
$zusaetzlich['inhalt'] = $inhalt;
}
if(isset($nachnahme))$zusaetzlich['nachnahme'] = $nachnahme;
$this->GoPaketmarke($id,$name,$name2,$name3,$strasse,$hausnummer,$plz,$ort,$land,$kg,$betrag,$rechnungsnummer, $zusaetzlich);
} else header("Location: index.php?module=lieferschein&action=paketmarke&id=$id");
break;
}
if(!empty($obj) && method_exists($obj, 'Paketmarke'))
{
$error = $obj->Paketmarke($sid!=''?$sid:'lieferschein',$id);
}else $error[] = 'Versandmodul '.$typ.' fehlerhaft!';
}
if(!isset($error) || !$error)$this->app->DB->Update("UPDATE versand SET gewicht='$kg',paketmarkegedruckt=1,anzahlpakete='$anzahl' WHERE id='$id' LIMIT 1");
}
if(!$error)
@ -21266,8 +21067,7 @@ function Paketmarke($parsetarget,$sid="",$zusatz="",$typ="DHL")
break;
}
$this->app->DB->Insert("INSERT INTO versandpakete (id,versand,gewicht,nr,versender) VALUES ('','$id','$kg','$anzahli','".$this->app->User->GetName()."')");
}
$this->app->DB->Insert("INSERT INTO versandpakete (id,versand,gewicht,nr,versender) VALUES ('','$id','$kg','$anzahli','".$this->app->User->GetName()."')"); }
}

View File

@ -1,65 +1,69 @@
<?php
class Versanddienstleister {
abstract class Versanddienstleister {
/** @var int $id */
public $id;
/** @var Application $app */
public $app;
public function isEtikettenDrucker(): bool {
return false;
}
public function GetAdressdaten($id, $sid)
{
if($sid==='rechnung'){
$rechnung = $id;
$rechnungId = $id;
}
else
{
$rechnung ='';
$rechnungId ='';
}
if($sid==='versand')
{
$tid = $this->app->DB->Select("SELECT lieferschein FROM versand WHERE id='$id' LIMIT 1");
$rechnung = $this->app->DB->Select("SELECT rechnung FROM versand WHERE id='$id' LIMIT 1");
$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 {
$tid = $id;
$lieferscheinId = $id;
if($sid === 'lieferschein'){
$rechnung = $this->app->DB->Select("SELECT id FROM rechnung WHERE lieferschein = '$tid' LIMIT 1");
$rechnungId = $this->app->DB->Select("SELECT id FROM rechnung WHERE lieferschein = '$lieferscheinId' LIMIT 1");
}
if($rechnung<=0) {
$rechnung = $this->app->DB->Select("SELECT rechnungid FROM lieferschein WHERE id='$tid' LIMIT 1");
if($rechnungId<=0) {
$rechnungId = $this->app->DB->Select("SELECT rechnungid FROM lieferschein WHERE id='$lieferscheinId' LIMIT 1");
}
}
$ret['tid'] = $tid;
$ret['rechnung'] = $rechnung;
$ret['lieferscheinId'] = $lieferscheinId;
$ret['rechnungId'] = $rechnungId;
if($rechnung){
$artikel_positionen = $this->app->DB->SelectArr("SELECT * FROM rechnung_position WHERE rechnung='$rechnung'");
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,$tid));
$artikel_positionen = $this->app->DB->SelectArr(sprintf('SELECT * FROM `%s` WHERE `%s` = %d',$sid.'_position',$sid,$lieferscheinId));
}
if($sid==='rechnung' || $sid==='lieferschein' || $sid==='adresse')
{
$docArr = $this->app->DB->SelectRow(sprintf('SELECT * FROM `%s` WHERE id = %d LIMIT 1',$sid, $tid));
$docArr = $this->app->DB->SelectRow("SELECT * FROM `$sid` WHERE id = $lieferscheinId LIMIT 1");
$name = trim($docArr['name']);//trim($this->app->DB->Select("SELECT name FROM $sid WHERE id='$tid' LIMIT 1"));
$name2 = trim($docArr['adresszusatz']);//trim($this->app->DB->Select("SELECT adresszusatz FROM $sid WHERE id='$tid' LIMIT 1"));
$name = trim($docArr['name']);
$name2 = trim($docArr['adresszusatz']);
$abt = 0;
if($name2==='')
{
$name2 = trim($docArr['abteilung']);//trim($this->app->DB->Select("SELECT abteilung FROM $sid WHERE id='$tid' LIMIT 1"));
$name2 = trim($docArr['abteilung']);
$abt=1;
}
$name3 = trim($docArr['ansprechpartner']);//trim($this->app->DB->Select("SELECT ansprechpartner FROM $sid WHERE id='$tid' LIMIT 1"));
$name3 = trim($docArr['ansprechpartner']);
if($name3==='' && $abt!==1){
$name3 = trim($docArr['abteilung']);//trim($this->app->DB->Select("SELECT abteilung FROM $sid WHERE id='$tid' LIMIT 1"));
$name3 = trim($docArr['abteilung']);
}
//unterabteilung versuchen einzublenden
if($name2==='') {
$name2 = trim($docArr['unterabteilung']);//trim($this->app->DB->Select("SELECT unterabteilung FROM $sid WHERE id='$tid' LIMIT 1"));
$name2 = trim($docArr['unterabteilung']);
} else if ($name3==='') {
$name3 = trim($docArr['unterabteilung']);//trim($this->app->DB->Select("SELECT unterabteilung FROM $sid WHERE id='$tid' LIMIT 1"));
$name3 = trim($docArr['unterabteilung']);
}
if($name3!=='' && $name2==='') {
@ -67,10 +71,10 @@ class Versanddienstleister {
$name3='';
}
$ort = trim($docArr['ort']);//trim($this->app->DB->Select("SELECT ort FROM $sid WHERE id='$tid' LIMIT 1"));
$plz = trim($docArr['plz']);//trim($this->app->DB->Select("SELECT plz FROM $sid WHERE id='$tid' LIMIT 1"));
$land = trim($docArr['land']);//trim($this->app->DB->Select("SELECT land FROM $sid WHERE id='$tid' LIMIT 1"));
$strasse = trim($docArr['strasse']);//trim($this->app->DB->Select("SELECT strasse FROM $sid WHERE id='$tid' LIMIT 1"));
$ort = trim($docArr['ort']);
$plz = trim($docArr['plz']);
$land = trim($docArr['land']);
$strasse = trim($docArr['strasse']);
$strassekomplett = $strasse;
$hausnummer = trim($this->app->erp->ExtractStreetnumber($strasse));
@ -82,26 +86,22 @@ class Versanddienstleister {
$strasse = trim($hausnummer);
$hausnummer = '';
}
$telefon = trim($docArr['telefon']);//trim($this->app->DB->Select("SELECT telefon FROM $sid WHERE id='$tid' LIMIT 1"));
$email = trim($docArr['email']);//trim($this->app->DB->Select("SELECT email FROM $sid WHERE id='$tid' LIMIT 1"));
$telefon = trim($docArr['telefon']);
$email = trim($docArr['email']);
$ret['order_number'] = $docArr['auftrag'];
$ret['addressId'] = $docArr['adresse'];
}
// wenn rechnung im spiel entweder durch versand oder direkt rechnung
if($rechnung >0)
if($rechnungId >0)
{
$zahlungsweise = $this->app->DB->Select("SELECT zahlungsweise FROM rechnung WHERE id='$rechnung' LIMIT 1");
$soll = $this->app->DB->Select("SELECT soll FROM rechnung WHERE id='$rechnung' LIMIT 1");
$invoice_data = $this->app->DB->SelectRow("SELECT zahlungsweise, soll, belegnr FROM rechnung WHERE id='$rechnungId' LIMIT 1");
$ret['zahlungsweise'] = $invoice_data['zahlungsweise'];
$ret['betrag'] = $invoice_data['soll'];
$ret['invoice_number'] = $invoice_data['belegnr'];
if($zahlungsweise==='nachnahme'){
$nachnahme = true;
}
if($soll >= 500 && $soll <= 2500){
$versichert = true;
}
if($soll > 2500) {
$extraversichert = true;
if($invoice_data['zahlungsweise']==='nachnahme'){
$ret['nachnahme'] = true;
}
}
@ -109,11 +109,8 @@ class Versanddienstleister {
if(isset($inhalt))$ret['inhalt'] = $inhalt;
if(isset($keinealtersabfrage))$ret['keinealtersabfrage'] = $keinealtersabfrage;
if(isset($altersfreigabe))$ret['altersfreigabe'] = $altersfreigabe;
if(isset($zahlungsweise))$ret['zahlungsweise'] = $zahlungsweise;
if(isset($versichert))$ret['versichert'] = $versichert;
if(isset($soll))$ret['betrag'] = $soll;
if(isset($extraversichert))$ret['extraversichert'] = $extraversichert;
if(isset($nachnahme))$ret['nachnahme'] = $nachnahme;
$ret['name'] = $name;
$ret['name2'] = $name2;
$ret['name3'] = $name3;
@ -139,12 +136,11 @@ class Versanddienstleister {
}
if($sid==="lieferschein"){
$standardkg = $this->app->erp->VersandartMindestgewicht($tid);
$standardkg = $this->app->erp->VersandartMindestgewicht($lieferscheinId);
}
else{
$standardkg = $this->app->erp->VersandartMindestgewicht();
}
//$this->app->erp->PaketmarkeGewichtForm($anzahl, $standardkg, $this->VersandartMindestgewicht());
$ret['standardkg'] = $standardkg;
$ret['anzahl'] = $anzahl;
return $ret;
@ -328,29 +324,15 @@ class Versanddienstleister {
return '';
}
protected abstract function EinstellungenStruktur();
/**
* @param string $target
*
* @return bool
*/
public function checkInputParameters($target = '')
public function checkInputParameters(string $target = ''): bool
{
$error = '';
if (trim($this->app->Secure->GetPOST('bezeichnung')) === '') {
$error = 'Bitte alle Pflichtfelder ausfüllen!';
$this->app->Tpl->Set('MSGBEZEICHNUNG','<span style="color:red">Pflichtfeld!</span>');
}
if (trim($this->app->Secure->GetPOST('typ')) === '') {
$error = 'Bitte alle Pflichtfelder ausfüllen!';
$this->app->Tpl->Set('MSGTYP','<span style="color:red">Pflichtfeld!</span>');
}
if ($error !== '') {
$this->app->Tpl->Add($target, sprintf('<div class="error">%s</div>', $error));
return false;
}
return true;
}
@ -414,5 +396,9 @@ class Versanddienstleister {
$link = '';
return true;
}
public function Paketmarke(string $target, string $doctype, int $docid): void {
}
}

View File

@ -1,79 +1,57 @@
<br><br><table id="paketmarketab" align="center">
<tr>
<td align="center">
<br>
<form action="" method="post">
[ERROR]
<h1>{|Paketmarken Drucker f&uuml;r|} [ZUSATZ]</h1>
<br>
<b>{|Empf&auml;nger|}</b>
<br>
<br>
<table>
<tr><td>
<div class="container-fluid">
<div class="row">
<div>
<form action="" method="post">
[ERROR]
<h1>{|Paketmarken Drucker f&uuml;r|} SendCloud</h1>
</div>
<div class="col-md-6">
<h2>{|Empf&auml;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>{|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]">&nbsp;<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">&nbsp;<input type="text" size="5" name="hausnummer" value="[HAUSNUMMER]"></td></tr>
<table style="float:left;">
<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>{|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>{|Land|}:</td><td>[EPROO_SELECT_LAND]</td></tr>
<tr><td>{|PLZ/Ort|}:</td><td><input type="text" name="plz" size="5" value="[PLZ]">&nbsp;<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">&nbsp;<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="telefon"></td></tr>
[PRODUCT_LIST]
<tr style="[VERSTECKEN]"><td colspan="2">&nbsp;</td></tr>
<tr id="us-states" style="[VERSTECKEN]"><td>{|Bundesland|}:</td><td>[EPROO_SELECT_BUNDESSTAAT]</td></tr>
<tr id="states" style="[VERSTECKEN]"><td>{|Bundesland|}:</td><td><input type="text" size="36" value="[BUNDESLAND]" name="state"></td></tr>
<tr style="[VERSTECKEN]"><td>{|Rechnungsnummer|}:</td><td><input type="text" size="36" value="[RECHNUNGSNUMMER]" name="rechnungsnummer"></td></tr>
<tr style="[VERSTECKEN]"><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 nowrap>{|Extra Versicherung|}:</td><td><input type="checkbox" name="versichert" value="1" [VERSICHERT] /></td></tr>
<tr class="versicherung"><td>{|Versicherungssumme|}:</td><td><input type="text" size="10" id="versicherungssumme" name="versicherungssumme" value="[VERSICHERUNGSSUMME]" /></td></tr>
</table>
<table style="float:right;">
[GEWICHT]
<tr>
<td>{|H&ouml;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&auml;nge (in cm)|}:</td>
<td>
<input type="text" size="10" value="[LENGTH]" name="length">
</td>
</tr>
</table>
<div style="clear:both"></div>
<br><br>
<center><input class="btnGreen" type="submit" value="{|Paketmarke drucken|}" name="drucken">&nbsp;
[TRACKINGMANUELL]
&nbsp;<input type="button" value="{|Andere Versandart auswählen|}" onclick="window.location.href='index.php?module=versanderzeugen&action=wechsel&id=[ID]'" name="anders">&nbsp;
<!--<input type="button" value="Abbrechen">--></center>
</td></tr></table>
</form>
<br><br>
</td></tr></table>
<tr><td>{|Bundesland|}:</td><td><input type="text" size="36" value="[BUNDESLAND]" name="state"></td></tr>
</table>
</div>
<div class="col-md-6">
<h2>{|Paket|}</h2>
<table>
<tr><td>{|Gewicht (in kg)|}:</td><td><input type="text" value="[WEIGHT]" name="weight"></td></tr>
<tr><td>{|H&ouml;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&auml;nge (in cm)|}:</td><td><input type="text" size="10" value="[LENGTH]" name="length"></td></tr>
<tr><td>{|Produkt|}:</td><td>[METHODS]</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>
</table>
</div>
<div>
<input class="btnGreen" type="submit" value="{|Paketmarke drucken|}" name="drucken">&nbsp;
[TRACKINGMANUELL]
<input type="button" value="{|Andere Versandart auswählen|}" name="anders">&nbsp;
</div>
</div>
</div>

View File

@ -0,0 +1,151 @@
<?php
use Xentral\Carrier\SendCloud\Data\Document;
use Xentral\Carrier\SendCloud\Data\ParcelCreation;
use Xentral\Carrier\SendCloud\Data\ParcelResponse;
use Xentral\Carrier\SendCloud\SendCloudApi;
use Xentral\Carrier\SendCloud\Data\SenderAddress;
use Xentral\Carrier\SendCloud\Data\ShippingProduct;
use Xentral\Carrier\SendCloud\Data\ShippingMethod;
require_once dirname(__DIR__) . '/class.versanddienstleister.php';
class Versandart_sendcloud extends Versanddienstleister
{
/* @var SendCloudApi $api */
protected $api;
/* @var array $settings */
protected $settings;
protected $options;
/**
* Versandart_sendcloud constructor.
*
* @param ApplicationCore $app
* @param int $id
*/
public function __construct($app, $id)
{
$this->app = $app;
$this->id = $id;
//TODO move to better place
$res = $this->app->DB->SelectRow("SELECT * FROM versandarten WHERE id=$this->id");
$this->settings = json_decode($res['einstellungen_json']);
$this->type = $res['type'];
$this->paketmarke_drucker = $res['paketmarke_drucker'];
$this->api = new SendCloudApi($this->settings->public_key, $this->settings->private_key);
}
protected function FetchOptionsFromApi()
{
$list = $this->api->GetSenderAddresses();
foreach ($list as $item) {
/* @var SenderAddress $item */
$senderAddresses[$item->Id] = $item;
}
$senderCountry = $senderAddresses[$this->settings->sender_address]->Country ?? 'DE';
$list = $this->api->GetShippingProducts($senderCountry);
foreach ($list as $item) {
/* @var ShippingProduct $item */
$shippingProducts[$item->Code] = $item;
}
$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];
asort($this->options['products']);
}
protected function EinstellungenStruktur()
{
$this->FetchOptionsFromApi();
return [
'public_key' => ['typ' => 'text', 'bezeichnung' => 'API Public Key:'],
'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']],
];
}
public function Paketmarke(string $target, string $doctype, int $docid): void
{
$address = $this->GetAdressdaten($docid, $doctype);
$submit = false;
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
(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");
$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);
}
}
$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']);
$method = $this->app->Secure->GetPOST('method');
$this->FetchOptionsFromApi();
/** @var ShippingProduct $product */
$product = $this->options['selectedProduct'];
$methods = [];
/** @var ShippingMethod $item */
foreach ($product->ShippingMethods as $item)
$methods[$item->Id] = $item->Name;
$this->app->Tpl->addSelect('METHODS', 'method', 'method', $methods, $method);
$this->app->Tpl->Parse($target, 'versandarten_sendcloud.tpl');
}
}

View File

@ -1,46 +1,86 @@
<!-- gehort zu tabview -->
<div id="tabs">
<ul>
<li><a href="#tabs-1"></a></li>
</ul>
<div id="tabs-1">
[MESSAGE]
<form action="" method="post" name="eprooform">
[FORMHANDLEREVENT]
<fieldset>
<legend>{|Einstellungen|}</legend>
<table width="100%" border="0" class="mkTableFormular">
<tr><td>{|Bezeichnung|}: </td><td><input type="text" name="bezeichnung" value="[BEZEICHNUNG]" size="40" data-lang="versandart_bezeichnung_[ID]">[MSGBEZEICHNUNG]</td></tr>
<tr><td>{|Typ|}:</td><td><input type="text" name="typ" value="[TYP]" size="40">[MSGTYP] <i>{|z.B. dhl,ups,etc.|}</i></td></tr>
<tr><td>{|Modul|}:</td><td><select name="selmodul" id="selmodul" onchange="changemodul();">[SELMODUL]</select></td></tr>
<tr><td>{|Projekt|}:</td><td><input type="text" id="projekt" name="projekt" value="[PROJEKT]" size="30"></td></tr>
<tr><td>{|Aktiv|}:</td><td><input type="checkbox" name="aktiv" value="1" [AKTIV]><i>{|Aktiv. Nicht mehr verwendete Versandarten können deaktiviert werden.|}</i></td></tr>
<tr><td>{|Kein Portocheck|}:</td><td><input type="checkbox" name="keinportocheck" value="1" [KEINPORTOCHECK]><i>{|Porto-Check im Auftrag deaktivieren.|}</i></td></tr>
<tr><td>{|Drucker Paketmarke|}:</td><td><select name="paketmarke_drucker" id="paketmarke_drucker">[PAKETMARKE_DRUCKER]</select></td></tr>
<tr><td>{|Drucker Export|}:</td><td><select name="export_drucker" id="export_drucker">[EXPORT_DRUCKER]</select></td></tr>
<tr><td>{|Versandmail|}:</td><td><select name="versandmail" id="versandmail">[SELVERSANDMAIL]</select></td></tr>
<tr class="versandbetreff"><td>{|Textvorlage|}:</td><td><select name="geschaeftsbrief_vorlage" id="geschaeftsbrief_vorlage">[SELGESCHAEFTSBRIEF_VORLAGE]</select></td></tr>
[JSON]
</table>
</fieldset>
<input type="submit" name="speichern" value="{|Speichern|}" id="speichern" style="float:right"/>
</form>
<ul>
<li><a href="#tabs-1"></a></li>
</ul>
<div id="tabs-1">
[MESSAGE]
<form action="" method="post" name="eprooform">
[FORMHANDLEREVENT]
<fieldset>
<legend>{|Einstellungen|}</legend>
<table class="mkTableFormular">
<tr>
<td>{|Bezeichnung|}:</td>
<td>
<input type="text" name="bezeichnung" value="[BEZEICHNUNG]" size="40"
data-lang="versandart_bezeichnung_[ID]">
<span style="color:red">[MSGBEZEICHNUNG]</span>
</td>
</tr>
<tr>
<td>{|Typ|}:</td>
<td>
<input type="text" name="typ" value="[TYP]" size="40">
<span style="color:red">[MSGTYP]</span>
<i>{|z.B. dhl,ups,etc.|}</i>
</td>
</tr>
<tr>
<td>{|Modul|}:</td>
<td>[SELMODUL]</td>
</tr>
<tr>
<td>{|Projekt|}:</td>
<td><input type="text" id="projekt" name="projekt" value="[PROJEKT]" size="30"></td>
</tr>
<tr>
<td>{|Aktiv|}:</td>
<td>
<input type="checkbox" name="aktiv" value="1" [AKTIV]>
<i>{|Aktiv. Nicht mehr verwendete Versandarten können deaktiviert werden.|}</i>
</td>
</tr>
<tr>
<td>{|Kein Portocheck|}:</td>
<td>
<input type="checkbox" name="keinportocheck" value="1" [KEINPORTOCHECK]>
<i>{|Porto-Check im Auftrag deaktivieren.|}</i>
</td>
</tr>
<tr>
<td>{|Drucker Paketmarke|}:</td>
<td>[PAKETMARKE_DRUCKER]</td>
</tr>
<tr>
<td>{|Drucker Export|}:</td>
<td>[EXPORT_DRUCKER]</td>
</tr>
<tr>
<td>{|Versandmail|}:</td>
<td>[SELVERSANDMAIL]</td>
</tr>
<tr class="versandbetreff">
<td>{|Textvorlage|}:</td>
<td>[SELGESCHAEFTSBRIEF_VORLAGE]</td>
</tr>
[JSON]
</table>
</fieldset>
<input type="submit" name="speichern" value="{|Speichern|}" id="speichern" style="float:right"/>
</form>
</div>
</div>
</div>
<script>
var modulname = '[AKTMODUL]';
function changemodul()
{
if($('#selmodul').val() != modulname)
{
if(confirm('{|Wollen Sie das Modul wirklich ändern? Die Einstellungen werden dabei überschrieben|}'))
{
$( '#speichern' ).trigger( 'click' );
}else{
$('#selmodul').val(modulname);
}
var modulname = '[AKTMODUL]';
function changemodul() {
if ($('#selmodul').val() != modulname) {
if (confirm('{|Wollen Sie das Modul wirklich ändern? Die Einstellungen werden dabei überschrieben|}')) {
$('#speichern').trigger('click');
} else {
$('#selmodul').val(modulname);
}
}
}
}
$('#selmodul').on('change', changemodul);
</script>

View File

@ -12,17 +12,10 @@
<fieldset class="moduleList">
<legend>{|Auswahl|}</legend>
<div id="searchdiv">
<label for="suche">{|Suche|}:</label> <input type="text" id="suche" />
<label for="suche">{|Suche|}:</label> <input type="text" id="createSearchInput" />
</div>
[MODULEINSTALLIERT]
</fieldset>
[BEFOREMODULESTOBUY]
<fieldset class="moduleList">
<legend>{|Kaufschnittstellen|}</legend>
[MODULEVERFUEGBAR]
<br />
</fieldset>
[AFTERMODULESTOBUY]
[TAB1NEXT]
</div>

View File

@ -447,36 +447,20 @@ class Lieferschein extends GenLieferschein
function LieferscheinPaketmarke()
{
$id = $this->app->Secure->GetGET("id");
$id = (int)$this->app->Secure->GetGET("id");
$versandart = $this->app->DB->Select("SELECT versandart FROM lieferschein WHERE id='$id' LIMIT 1");
$projekt = $this->app->DB->Select("SELECT projekt FROM lieferschein WHERE id = '$id' LIMIT 1");
$this->LieferscheinMenu();
$this->app->Tpl->Set('TABTEXT',"Paketmarke");
$versandart = strtolower($versandart);
$versandartenmodul = $this->app->DB->SelectArr("SELECT id, modul FROM versandarten WHERE aktiv = 1 AND ausprojekt = 0 AND modul != '' AND type = '".$this->app->DB->real_escape_string($versandart)."' AND (projekt = '$projekt' || projekt = 0) ORDER BY projekt DESC LIMIT 1");
if($versandartenmodul && is_file(dirname(__DIR__).'/lib/versandarten/'.$versandartenmodul[0]['modul'].'.php'))
{
$this->app->erp->Paketmarke('TAB1','lieferschein',"",$versandart);
}else{
if($versandart=="dpd")
$this->app->erp->PaketmarkeDPDEmbedded('TAB1',"lieferschein");
else if($versandart=="express_dpd")
$this->app->erp->PaketmarkeDPDEmbedded('TAB1',"lieferschein","express");
else if($versandart=="export_dpd")
$this->app->erp->PaketmarkeDPDEmbedded('TAB1',"lieferschein","export");
else if($versandart=="ups")
$this->app->erp->PaketmarkeUPSEmbedded('TAB1',"lieferschein");
else if($versandart=="fedex")
$this->app->erp->PaketmarkeFEDEXEmbedded('TAB1',"lieferschein");
else if($versandart=="go")
$this->app->erp->PaketmarkeGo('TAB1',"lieferschein");
else {
$this->app->erp->Paketmarke('TAB1','lieferschein',"","");
}
//$this->app->erp->PaketmarkeDHLEmbedded('TAB1',"lieferschein");
}
$result = $this->app->DB->SelectRow(
"SELECT v.id, v.modul
FROM lieferschein l
LEFT JOIN versandarten v ON (l.versandart=v.type AND v.projekt in (l.projekt, 0))
WHERE l.id=$id
AND v.aktiv = 1 AND v.ausprojekt = 0 AND v.modul != ''
ORDER BY v.projekt DESC LIMIT 1");
$versandmodul = $this->app->erp->LoadVersandModul($result['modul'], $result['id']);
$versandmodul->Paketmarke('TAB1', 'lieferschein', $id);
$this->app->Tpl->Parse('PAGE',"tabview.tpl");
}

File diff suppressed because it is too large Load Diff