diff --git a/classes/Carrier/SendCloud/Data/Document.php b/classes/Carrier/SendCloud/Data/Document.php new file mode 100644 index 00000000..fa2f0fe8 --- /dev/null +++ b/classes/Carrier/SendCloud/Data/Document.php @@ -0,0 +1,25 @@ +Type = $data->type; + $obj->Size = $data->size; + $obj->Link = $data->link; + return $obj; + } +} \ No newline at end of file diff --git a/classes/Carrier/SendCloud/Data/ParcelBase.php b/classes/Carrier/SendCloud/Data/ParcelBase.php new file mode 100644 index 00000000..944288b1 --- /dev/null +++ b/classes/Carrier/SendCloud/Data/ParcelBase.php @@ -0,0 +1,36 @@ + $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, + ]; + } + +} \ No newline at end of file diff --git a/classes/Carrier/SendCloud/Data/ParcelCreationError.php b/classes/Carrier/SendCloud/Data/ParcelCreationError.php new file mode 100644 index 00000000..2d2946ea --- /dev/null +++ b/classes/Carrier/SendCloud/Data/ParcelCreationError.php @@ -0,0 +1,10 @@ + $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; + } +} \ No newline at end of file diff --git a/classes/Carrier/SendCloud/Data/ParcelResponse.php b/classes/Carrier/SendCloud/Data/ParcelResponse.php new file mode 100644 index 00000000..cfca07e2 --- /dev/null +++ b/classes/Carrier/SendCloud/Data/ParcelResponse.php @@ -0,0 +1,76 @@ +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; + } +} \ No newline at end of file diff --git a/classes/Carrier/SendCloud/Data/SenderAddress.php b/classes/Carrier/SendCloud/Data/SenderAddress.php new file mode 100644 index 00000000..e6004064 --- /dev/null +++ b/classes/Carrier/SendCloud/Data/SenderAddress.php @@ -0,0 +1,52 @@ +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; + } +} \ No newline at end of file diff --git a/classes/Carrier/SendCloud/Data/ShippingMethod.php b/classes/Carrier/SendCloud/Data/ShippingMethod.php new file mode 100644 index 00000000..04617f5d --- /dev/null +++ b/classes/Carrier/SendCloud/Data/ShippingMethod.php @@ -0,0 +1,28 @@ +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; + } +} \ No newline at end of file diff --git a/classes/Carrier/SendCloud/Data/ShippingProduct.php b/classes/Carrier/SendCloud/Data/ShippingProduct.php new file mode 100644 index 00000000..92f7f8da --- /dev/null +++ b/classes/Carrier/SendCloud/Data/ShippingProduct.php @@ -0,0 +1,28 @@ +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; + } +} \ No newline at end of file diff --git a/classes/Carrier/SendCloud/SendCloudApi.php b/classes/Carrier/SendCloud/SendCloudApi.php new file mode 100644 index 00000000..e4c79f8b --- /dev/null +++ b/classes/Carrier/SendCloud/SendCloudApi.php @@ -0,0 +1,124 @@ +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); + } +} \ No newline at end of file diff --git a/classes/Modules/ShippingMethod/www/js/shipping_method_create.js b/classes/Modules/ShippingMethod/www/js/shipping_method_create.js index a7b6a50e..d8d56fad 100644 --- a/classes/Modules/ShippingMethod/www/js/shipping_method_create.js +++ b/classes/Modules/ShippingMethod/www/js/shipping_method_create.js @@ -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) { diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index b915d780..624cf772 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -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()."')"); } } diff --git a/www/lib/class.versanddienstleister.php b/www/lib/class.versanddienstleister.php index 9ebae57e..d744b05d 100644 --- a/www/lib/class.versanddienstleister.php +++ b/www/lib/class.versanddienstleister.php @@ -1,65 +1,69 @@ 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','Pflichtfeld!'); - } - if (trim($this->app->Secure->GetPOST('typ')) === '') { - $error = 'Bitte alle Pflichtfelder ausfüllen!'; - $this->app->Tpl->Set('MSGTYP','Pflichtfeld!'); - } - - if ($error !== '') { - $this->app->Tpl->Add($target, sprintf('
%s
', $error)); - - return false; - } - return true; } @@ -414,5 +396,9 @@ class Versanddienstleister { $link = ''; return true; } + + public function Paketmarke(string $target, string $doctype, int $docid): void { + + } } diff --git a/www/lib/versandarten/content/versandarten_sendcloud.tpl b/www/lib/versandarten/content/versandarten_sendcloud.tpl index b52f65b5..4881a604 100644 --- a/www/lib/versandarten/content/versandarten_sendcloud.tpl +++ b/www/lib/versandarten/content/versandarten_sendcloud.tpl @@ -1,79 +1,57 @@ -

- -
-
-
-[ERROR] -

{|Paketmarken Drucker für|} [ZUSATZ]

-
-{|Empfänger|} -
-
- -
+
+
+
+ + [ERROR] +

{|Paketmarken Drucker für|} SendCloud

+
+
+

{|Empfänger|}

+ + + + + + + -
{|Name|}:
{|Name 2|}:
{|Name 3|}:
{|Land|}:
{|PLZ/Ort|}: 
{|Strasse/Hausnummer|}: 
- - - + + - - - - - - - -[PRODUCT_LIST] - - - - - - - - - -
{|Name|}:
{|Name 2|}:
{|Name 3|}:
{|E-Mail|}:
{|Telefon|}:
{|Land|}:[EPROO_SELECT_LAND]
{|PLZ/Ort|}: 
{|Strasse/Hausnummer|}: 
{|E-Mail|}:
{|Telefon|}:
 
{|Bundesland|}:[EPROO_SELECT_BUNDESSTAAT]
{|Bundesland|}:
{|Rechnungsnummer|}:
{|Sendungsart|}:
{|Extra Versicherung|}:
{|Versicherungssumme|}:
- - -[GEWICHT] - - - - - - - - - - - - -
{|Höhe (in cm)|}: - -
{|Breite (in cm)|}: - -
{|Länge (in cm)|}: - -
- -
- -

-
  -[TRACKINGMANUELL] -   -
-
-
- -

-
+ {|Bundesland|}: + + +
+

{|Paket|}

+ + + + + + +
{|Gewicht (in kg)|}:
{|Höhe (in cm)|}:
{|Breite (in cm)|}:
{|Länge (in cm)|}:
{|Produkt|}:[METHODS]
+
+
+
+

{|Bestellung|}

+ + + + + +
{|Bestellnummer|}:
{|Rechnungsnummer|}:
{|Sendungsart|}:
{|Versicherungssumme|}:
+
+
+   + [TRACKINGMANUELL] +   +
+ + \ No newline at end of file diff --git a/www/lib/versandarten/dhl.php b/www/lib/versandarten/dhl.php_ similarity index 100% rename from www/lib/versandarten/dhl.php rename to www/lib/versandarten/dhl.php_ diff --git a/www/lib/versandarten/dhlversenden.php b/www/lib/versandarten/dhlversenden.php_ similarity index 100% rename from www/lib/versandarten/dhlversenden.php rename to www/lib/versandarten/dhlversenden.php_ diff --git a/www/lib/versandarten/internetmarke.php b/www/lib/versandarten/internetmarke.php_ similarity index 100% rename from www/lib/versandarten/internetmarke.php rename to www/lib/versandarten/internetmarke.php_ diff --git a/www/lib/versandarten/parcelone.php b/www/lib/versandarten/parcelone.php_ similarity index 100% rename from www/lib/versandarten/parcelone.php rename to www/lib/versandarten/parcelone.php_ diff --git a/www/lib/versandarten/sendcloud.php b/www/lib/versandarten/sendcloud.php new file mode 100644 index 00000000..c61bfb3a --- /dev/null +++ b/www/lib/versandarten/sendcloud.php @@ -0,0 +1,151 @@ +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'); + } + +} \ No newline at end of file diff --git a/www/lib/versandarten/sonstiges.php b/www/lib/versandarten/sonstiges.php_ similarity index 100% rename from www/lib/versandarten/sonstiges.php rename to www/lib/versandarten/sonstiges.php_ diff --git a/www/pages/content/versandarten_edit.tpl b/www/pages/content/versandarten_edit.tpl index 1af4eafb..fcb65535 100644 --- a/www/pages/content/versandarten_edit.tpl +++ b/www/pages/content/versandarten_edit.tpl @@ -1,46 +1,86 @@ -
- -
- [MESSAGE] -
- [FORMHANDLEREVENT] -
- {|Einstellungen|} - - - - - - - - - - - - - [JSON] -
{|Bezeichnung|}: [MSGBEZEICHNUNG]
{|Typ|}:[MSGTYP] {|z.B. dhl,ups,etc.|}
{|Modul|}:
{|Projekt|}:
{|Aktiv|}:{|Aktiv. Nicht mehr verwendete Versandarten können deaktiviert werden.|}
{|Kein Portocheck|}:{|Porto-Check im Auftrag deaktivieren.|}
{|Drucker Paketmarke|}:
{|Drucker Export|}:
{|Versandmail|}:
{|Textvorlage|}:
-
- -
+ +
+ [MESSAGE] +
+ [FORMHANDLEREVENT] +
+ {|Einstellungen|} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [JSON] +
{|Bezeichnung|}: + + [MSGBEZEICHNUNG] +
{|Typ|}: + + [MSGTYP] + {|z.B. dhl,ups,etc.|} +
{|Modul|}:[SELMODUL]
{|Projekt|}:
{|Aktiv|}: + + {|Aktiv. Nicht mehr verwendete Versandarten können deaktiviert werden.|} +
{|Kein Portocheck|}: + + {|Porto-Check im Auftrag deaktivieren.|} +
{|Drucker Paketmarke|}:[PAKETMARKE_DRUCKER]
{|Drucker Export|}:[EXPORT_DRUCKER]
{|Versandmail|}:[SELVERSANDMAIL]
{|Textvorlage|}:[SELGESCHAEFTSBRIEF_VORLAGE]
+
+ +
-
+
diff --git a/www/pages/content/versandarten_neu.tpl b/www/pages/content/versandarten_neu.tpl index 716f14ab..d6f9727e 100644 --- a/www/pages/content/versandarten_neu.tpl +++ b/www/pages/content/versandarten_neu.tpl @@ -12,17 +12,10 @@
{|Auswahl|}
- +
[MODULEINSTALLIERT]
- [BEFOREMODULESTOBUY] -
- {|Kaufschnittstellen|} - [MODULEVERFUEGBAR] -
-
- [AFTERMODULESTOBUY] [TAB1NEXT] diff --git a/www/pages/lieferschein.php b/www/pages/lieferschein.php index 74a42eb2..b8dc2564 100644 --- a/www/pages/lieferschein.php +++ b/www/pages/lieferschein.php @@ -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"); } diff --git a/www/pages/versandarten.php b/www/pages/versandarten.php index 890ac976..c80e71a9 100644 --- a/www/pages/versandarten.php +++ b/www/pages/versandarten.php @@ -1,4 +1,4 @@ - +*/ +?> app=$app; + if($intern) { + return; + } + $this->app->ActionHandlerInit($this); + + // ab hier alle Action Handler definieren die das Modul hat + $this->app->ActionHandler("create", "VersandartenCreate"); + $this->app->ActionHandler("edit", "VersandartenEdit"); + $this->app->ActionHandler("list", "VersandartenList"); + $this->app->ActionHandler("delete", "VersandartenDelete"); + $this->app->ActionHandler("copy", 'VersandartenCopy'); + $this->app->ActionHandler('createShipment', 'CreateShipment'); + + $this->app->ActionHandlerListen($app); + } + + public function Install(): void + { + $this->app->erp->GetVersandartAuftrag(); + } + + /** @noinspection PhpUnused */ + public function VersandartenCopy():void + { + $id = (int)$this->app->Secure->GetGET('id'); + $id = $this->app->DB->Select("SELECT `id` FROM `versandarten` WHERE `id` = $id LIMIT 1"); + if(!$id) { + $this->app->Location->execute('index.php?module=versandarten&action=list'); + } + $newId = $this->app->DB->MysqlCopyRow('versandarten', 'id', $id); + if($newId) { + $this->app->DB->Update( + "UPDATE `versandarten` set `aktiv` = 0, `ausprojekt` = 0 WHERE `id` = $newId LIMIT 1" + ); + } + $this->app->Location->execute('index.php?module=versandarten&action=edit&id='.$newId); + } + + /** @noinspection PhpUnused */ + public function VersandartenList(): void + { + $this->app->erp->MenuEintrag('index.php?module=versandarten&action=create','Neue Versandart anlegen'); + $this->app->erp->MenuEintrag('index.php?module=versandarten&action=list','Übersicht'); + $this->app->YUI->TableSearch('TAB1','versandarten_list', 'show','','',basename(__FILE__), __CLASS__); + $this->app->Tpl->Parse('PAGE','versandarten_list.tpl'); + } + + public static function TableSearch(Application $app, string $name, array $erlaubtevars): array { // in dieses switch alle lokalen Tabellen (diese Live Tabellen mit Suche etc.) für dieses Modul switch($name) { case 'versandarten_list': - $allowed['versandarten'] = array('list'); - $allowed['einstellungen'] = array('category'); - $isSettingAction = $app->Secure->GetGET('module') === 'einstellungen' + $allowed['versandarten'] = array('list'); + $allowed['einstellungen'] = array('category'); + $isSettingAction = $app->Secure->GetGET('module') === 'einstellungen' || $app->Secure->GetGET('smodule') === 'einstellungen'; - if($isSettingAction) { - $maxrows = 10; - } - $heading = array('Bezeichnung', 'Typ','Modul', 'Projekt', 'Menü'); - $width = array('39%', '20%', '20%','20%','5%'); + if($isSettingAction) { + $maxrows = 10; + } + $heading = array('Bezeichnung', 'Typ','Modul', 'Projekt', 'Menü'); + $width = array('39%', '20%', '20%','20%','5%'); - $findcols = array('v.bezeichnung', 'v.type','v.modul', "if(v.projekt, (SELECT `abkuerzung` FROM `projekt` WHERE `id` = v.projekt), '')",'v.id'); - $searchsql = array('v.bezeichnung', 'v.type','v.modul', 'v.projekt'); + $findcols = array('v.bezeichnung', 'v.type','v.modul', "if(v.projekt, (SELECT `abkuerzung` FROM `projekt` WHERE `id` = v.projekt), '')",'v.id'); + $searchsql = array('v.bezeichnung', 'v.type','v.modul', 'v.projekt'); - $defaultorder = 1; - $defaultorderdesc = 0; + $defaultorder = 1; + $defaultorderdesc = 0; - $menu = "
" - ."" - ."Conf->WFconf['defaulttheme']}/images/edit.svg\" border=\"0\">"; - $menu .= " " - ."" - ."Conf->WFconf['defaulttheme']}/images/copy.svg\" border=\"0\">"; - if(!$isSettingAction) { + $menu = "
" + ."" + ."Conf->WFconf['defaulttheme']}/images/edit.svg\" alt=\"edit\" style=\"border: 0\">"; $menu .= " " - . "" - . "Conf->WFconf['defaulttheme']}/images/delete.svg\" border=\"0\">"; - } - $menu .= "
"; + ."" + ."Conf->WFconf['defaulttheme']}/images/copy.svg\" alt=\"copy\" style=\"border: 0\">"; + if(!$isSettingAction) { + $menu .= " " + . "" + . "Conf->WFconf['defaulttheme']}/images/delete.svg\" alt=\"delete\" style=\"border: 0\">"; + } + $menu .= "
"; - $where = " v.id > 0 "; + $where = " v.id > 0 "; - $sql = "SELECT SQL_CALC_FOUND_ROWS v.id, if(v.aktiv, v.bezeichnung, CONCAT('',v.bezeichnung,'')), - if(v.aktiv, v.type, CONCAT('',v.type,'')), - if(v.aktiv, v.modul, CONCAT('',v.modul,'')), - if(v.projekt, (SELECT `abkuerzung` FROM `projekt` WHERE `id` = v.projekt), ''), v.id - FROM `versandarten` AS `v`"; + $sql = "SELECT SQL_CALC_FOUND_ROWS v.id, if(v.aktiv, v.bezeichnung, CONCAT('',v.bezeichnung,'')), + if(v.aktiv, v.type, CONCAT('',v.type,'')), + if(v.aktiv, v.modul, CONCAT('',v.modul,'')), + if(v.projekt, (SELECT `abkuerzung` FROM `projekt` WHERE `id` = v.projekt), ''), v.id + FROM `versandarten` AS `v`"; - $count = "SELECT count(v.id) FROM `versandarten` AS `v` WHERE $where"; + $count = "SELECT count(v.id) FROM `versandarten` AS `v` WHERE $where"; break; } @@ -98,494 +145,156 @@ class Versandarten { return $erg; } - /** - * Versandarten constructor. - * - * @param Application $app - * @param bool $intern - */ - public function __construct($app, $intern = false) + /** @noinspection PhpUnused */ + public function VersandartenEdit(): void { - $this->app=$app; - if($intern) { + $id = (int)$this->app->Secure->GetGET('id'); + $save = $this->app->Secure->GetPOST('speichern'); + + if (!$id) return; - } - $this->app->ActionHandlerInit($this); - - // ab hier alle Action Handler definieren die das Modul hat - $this->app->ActionHandler("create", "VersandartenCreate"); - $this->app->ActionHandler("edit", "VersandartenEdit"); - $this->app->ActionHandler("list", "VersandartenList"); - $this->app->ActionHandler("delete", "VersandartenDelete"); - $this->app->ActionHandler("copy", "VersandartenCopy"); - - $this->app->ActionHandlerListen($app); - } - - /** - * @return array - */ - public function getBetaShippingModules(): array - { - /** @var Appstore $appStore */ - $appStore = $this->app->erp->LoadModul('appstore'); - - return $appStore->getBetaModulesByPrefix('versandarten_'); - } - - public function Install(): void - { - $this->app->erp->GetVersandartAuftrag(); - } - - public function VersandartenCopy() - { - $id = (int)$this->app->Secure->GetGET('id'); - $id = $this->app->DB->Select(sprintf('SELECT `id` FROM `versandarten` WHERE `id` = %d LIMIT 1', $id)); - if(!$id) { - $this->app->Location->execute('index.php?module=versandarten&action=list'); - } - $newid = $this->app->DB->MysqlCopyRow('versandarten', 'id', $id); - if($newid) { - $this->app->DB->Update( - sprintf( - 'UPDATE `versandarten` set `aktiv` = 0, `ausprojekt` = 0 WHERE `id` = %d LIMIT 1', - $newid - ) - ); - } - $this->app->Location->execute('index.php?module=versandarten&action=edit&id='.$newid); - } - public function VersandartenMenu() - { - - } - - public function VersandartenList(): void - { - $this->app->erp->MenuEintrag('index.php?module=versandarten&action=create','Neue Versandart anlegen'); - $this->app->erp->MenuEintrag('index.php?module=versandarten&action=list','Übersicht'); - $this->app->YUI->TableSearch('TAB1','versandarten_list', 'show','','',basename(__FILE__), __CLASS__); - $this->app->Tpl->Parse('PAGE','versandarten_list.tpl'); - } - - /** - * @param string $value - * @param bool $retarr - * - * @return string|array|null - */ - function VersandartenSelModul($value = '', $retarr = false) - { - $array = null; - $ret = ''; - $pfad = dirname(__DIR__).'/lib/versandarten'; - $beta = $this->getBetaShippingModules(); - if(is_dir($pfad)) { - $handle = opendir($pfad); - if($handle) { - while (false !== ($file = readdir($handle))) { - $files[] = $file; - } - natcasesort($files); - foreach($files as $file) { - if($file[0] !== '.' && substr($file,-4) === '.php' && is_file($pfad.'/'.$file) - && substr($file,-8) !== '.src.php') { - $modul = str_replace('.php','',$file); - if(substr($modul,-7) === '_custom' - && !$this->app->DB->Select( - "SELECT `id` FROM `versandarten` WHERE `modul` = '".$this->app->DB->real_escape_string($modul)."' LIMIT 1" - ) - ) { - continue; - } - if($modul!=='rocketshipit' && $modul!='') { - include_once dirname(__DIR__).'/lib/versandarten/'.$modul.'.php'; - } - $classname = 'Versandart_'.$modul; - if(class_exists($classname)) { - try { - $r = new ReflectionMethod($classname, '__construct'); - $params = $r->getParameters(); - $anzargs = (!empty($params)?count($params):0); - } - catch(Exception $e) { - $anzargs = 1; - } - if($anzargs > 1) { - $obj = new $classname($this->app, 0); - } - else{ - $obj = new $classname($this->app); - } - } - $array[$modul] = (isset($obj->name)?$obj->name:ucfirst($modul)); - $modulKey = $modul; - if(strpos($modulKey,'versandarten_') !== 0) { - $modulKey = 'versandarten_'.$modul; - } - $ret .= ''; - unset($obj); - } - } - closedir($handle); - } - } - if($retarr){ - return $array; - } - - return $ret; - } - - /** - * @param string $module - * @param int $moduleId - * - * @return mixed|null - */ - public function loadModule($module, $moduleId = 0) - { - if(empty($module)) { - return null; - } - if(strpos($module,'versandarten_') === 0) { - $module = substr($module, 13); - if(empty($module)) { - return null; - } - } - if(strpos($module, '.') !== false || strpos($module, '/') !== false || strpos($module, '\\')) { - return null; - } - $path = dirname(__DIR__).'/lib/versandarten/'.$module.'.php'; - if(!is_file($path)) { - return null; - } - - include_once $path ; - $classname = 'Versandart_'.$module; - if(!class_exists($classname)) { - return null; - } - - return new $classname($this->app, $moduleId); - } - - public function VersandartenEdit() - { - $id = (int)$this->app->Secure->GetGET('id'); - $speichern = $this->app->Secure->GetPOST('speichern'); $this->app->erp->MenuEintrag('index.php?module=versandarten&action=edit&id='.$id,'Details'); $this->app->erp->MenuEintrag('index.php?module=versandarten&action=list','Zurück zur Übersicht'); $input = $this->GetInput(); - $error = ''; - if(is_numeric($id) && $speichern != ''){ - $modulepath = dirname(__DIR__).'/lib/versandarten/'.$input['selmodul'].'.php'; - if (!empty($input['selmodul']) && is_file($modulepath)) { - include_once($modulepath); - $classname = 'Versandart_'.$input['selmodul']; - if(class_exists($classname)) { - $moduleObject = new $classname($this->app, $id); - } - if(!empty($moduleObject) && method_exists($moduleObject, 'checkInputParameters')) { - if (false === $moduleObject->checkInputParameters('MESSAGE')) { - $error = 'error'; - } - } - } else { - $error = sprintf('Versandart "%s" existiert nicht.', $input['selmodul']); + $error = []; + if($save != ''){ + $moduleObject = $this->loadModule($input['selmodul'], $id); + if ($moduleObject === null) + $error[] = sprintf('Versandart "%s" existiert nicht.', $input['selmodul']); + + if(trim($input['bezeichnung']) == '') { + $error[] = 'Bitte alle Pflichtfelder ausfüllen!'; + $this->app->Tpl->Set('MSGBEZEICHNUNG','Pflichtfeld!'); + } + if(trim($input['typ']) == '') + { + $error[] = 'Bitte alle Pflichtfelder ausfüllen!'; + $this->app->Tpl->Set('MSGTYP','Pflichtfeld!'); } - if($id) { - if($error === '') { - $projektid = 0; - if(!empty($input['projekt'])){ - $projektid = $this->app->DB->Select( - sprintf( - "SELECT `id` FROM `projekt` WHERE `abkuerzung` = '%s' LIMIT 1", - $input['projekt'] - ) - ); - } - - $oldtype = $this->app->DB->Select( - sprintf('SELECT `id` FROM `versandarten` WHERE `id` = %d LIMIT 1', $id) - ); - if($oldtype != $input['typ']) - { - while($this->app->DB->Select( - sprintf( - "SELECT `id` FROM `versandarten` WHERE `type` = '%s' AND `id` <> %d LIMIT 1", - $input['typ'], $id - ) - )) - { - $typa = explode('_', $input['typ']); - if((!empty($typa)?(!empty($typa)?count($typa):0):0) == 1 || !is_numeric($typa[count($typa)-1])) - { - $input['typ'] .= '_1'; - }else{ - $counter = $typa[(!empty($typa)?count($typa):0)-1]+1; - unset($typa[(!empty($typa)?count($typa):0)-1]); - $input['typ'] = implode('_', $typa).'_'.$counter; - } - } - } - - $this->app->DB->Update( - sprintf( - "UPDATE `versandarten` - SET `bezeichnung`='%s', `type` ='%s', - `projekt`=%d, `aktiv`=%d, `modul`='%s', - `export_drucker` = %d, - `paketmarke_drucker` = %d, - `ausprojekt` = %d, `versandmail` = %d, - `geschaeftsbrief_vorlage` = %d, - `keinportocheck`=%d - WHERE `id` = %d LIMIT 1", - $input['bezeichnung'], $input['typ'], $projektid,$input['aktiv'],$input['selmodul'], - $input['export_drucker'], $input['paketmarke_drucker'],$input['ausprojekt'], $input['versandmail'], - $input['geschaeftsbrief_vorlage'], $input['keinportocheck'], $id - ) - ); - if($input['aktiv'] == 1){ - $this->app->Tpl->Set('AKTIV', "checked"); - } - if($input['keinportocheck'] == 1){ - $this->app->Tpl->Set('KEINPORTOCHECK', "checked"); - } - $this->app->Tpl->Set('MESSAGE', "
Die Daten wurden erfolgreich gespeichert!
"); - } + $projektid = 0; + if(!empty($input['projekt'])){ + $projektid = $this->app->DB->Select( + "SELECT `id` FROM `projekt` WHERE `abkuerzung` = '{$input['projekt']}' LIMIT 1" + ); } - else { - $error = ''; - if(trim($input['bezeichnung']) == '') - { - $error = 'Bitte alle Pflichtfelder ausfüllen!'; - $this->app->Tpl->Set('MSGBEZEICHNUNG',' Pflichtfeld!'); - } - if(trim($input['typ']) == '') - { - $error = 'Bitte alle Pflichtfelder ausfüllen!'; - $this->app->Tpl->Set('MSGTYP',' Pflichtfeld!'); - } - - if($error!=''){ - $this->app->Tpl->Set('MESSAGE', "
$error
"); - }else { - - if(trim($input['projekt']) == ''){ - $projektid = 0; - }else{ - $projektid = $this->app->DB->Select( - sprintf( - "SELECT `id` FROM `projekt` WHERE `abkuerzung` = '%s' LIMIT 1", - $input['projekt'] - ) - ); - } - - while($this->app->DB->Select(sprintf("SELECT `id` FROM `versandarten` WHERE `type` = '%s' LIMIT 1", $input['typ']))) { - $typa = explode('_', $input['typ']); - if((!empty($typa)?(!empty($typa)?count($typa):0):0) == 1 || !is_numeric($typa[count($typa)-1])) - { - $input['typ'] .= '_1'; - }else{ - $counter = $typa[(!empty($typa)?count($typa):0)-1]+1; - unset($typa[(!empty($typa)?count($typa):0)-1]); - $input['typ'] = implode('_', $typa).'_'.$counter; - } - } - - $this->app->DB->Insert( - sprintf( - "INSERT INTO `versandarten` - (`bezeichnung`, `type`, `projekt`, `aktiv`, `keinportocheck`, - `modul`,`export_drucker`, `paketmarke_drucker`, - `ausprojekt`,`versandmail`, `geschaeftsbrief_vorlage`) - VALUES ('%s', '%s', %d, %d,%d, - '%s',%d,%d, - %d,%d,%d)", - $input['bezeichnung'], $input['typ'],$projektid, $input['aktiv'], $input['keinportocheck'], - $input['selmodul'],$input['export_drucker'],$input['paketmarke_drucker'], - $input['ausprojekt'], $input['versandmail'], $input['geschaeftsbrief_vorlage'] - ) - ); - - $newid = $this->app->DB->GetInsertID(); - $msg = $this->app->erp->base64_url_encode("
Die Daten wurden erfolgreich gespeichert!
"); - $this->app->Location->execute("index.php?module=versandarten&action=edit&id=$newid&msg=$msg"); - } - } - } - $ausprojekt = 0; - - $daten = $this->app->DB->SelectRow( - sprintf('SELECT * FROM `versandarten` WHERE `id` = %d LIMIT 1', $id) - ); - if(!empty($daten)) { - $this->app->erp->Headlines('', $daten['bezeichnung']); - $this->app->Tpl->Set('AKTMODUL', $daten['modul']); - /** @var Versanddienstleister $obj */ - $obj = $this->loadModule($daten['modul'], $daten['id']); - $bezeichnung = $daten['bezeichnung']; - $typ = $daten['type']; - $projekt = $daten['projekt']; - $aktiv = $daten['aktiv']; - $keinportocheck = $daten['keinportocheck']; - $ausprojekt = $daten['ausprojekt']; - $projektname = $this->app->DB->Select(sprintf('SELECT `abkuerzung` FROM `projekt` WHERE `id` = %d', $projekt)); - if(!empty($obj) && method_exists($obj, 'Einstellungen')) { - $obj->Einstellungen('JSON'); + if ($this->app->DB->Select( + "SELECT `id` FROM `versandarten` WHERE `type` = '{$input['typ']}' AND `id` <> $id LIMIT 1" + )) { + $error[] = 'Typ ist bereits für eine andere Versandart vergeben'; } - if(!empty($obj) && method_exists($obj, 'isEtikettenDrucker')) { - $etikettendrucker = $obj->isEtikettenDrucker(); + + foreach ($error as $e) { + $this->app->Tpl->addMessage('error', $e); + } + + $inputCheckResult = $moduleObject->checkInputParameters('MESSAGE'); + if (empty($error) && $inputCheckResult) { + $this->app->DB->Update( + "UPDATE `versandarten` + SET `bezeichnung`='{$input['bezeichnung']}', `type` ='{$input['typ']}', + `projekt`=$projektid, `aktiv`={$input['aktiv']}, `modul`='{$input['selmodul']}', + `export_drucker` = {$input['export_drucker']}, + `paketmarke_drucker` = {$input['paketmarke_drucker']}, + `ausprojekt` = {$input['ausprojekt']}, `versandmail` = {$input['versandmail']}, + `geschaeftsbrief_vorlage` = {$input['geschaeftsbrief_vorlage']}, + `keinportocheck`={$input['keinportocheck']} + WHERE `id` = $id LIMIT 1" + ); + + if($input['aktiv'] == 1){ + $this->app->Tpl->Set('AKTIV', "checked"); + } + if($input['keinportocheck'] == 1){ + $this->app->Tpl->Set('KEINPORTOCHECK', "checked"); + } + $this->app->Tpl->Set('MESSAGE', "
Die Daten wurden erfolgreich gespeichert!
"); } } - else { - $this->app->Tpl->Set('AKTMODUL',''); - } + $daten = $this->app->DB->SelectRow("SELECT * FROM `versandarten` WHERE `id` = $id LIMIT 1"); + if (empty($daten)) + $this->app->Location->execute('index.php?module=versandarten&action=list'); + + $this->app->erp->Headlines('', $daten['bezeichnung']); + $this->app->Tpl->Set('AKTMODUL', $daten['modul']); + $obj = $this->loadModule($daten['modul'], $daten['id']); + $bezeichnung = $daten['bezeichnung']; + $typ = $daten['type']; + $projekt = $daten['projekt']; + $aktiv = $daten['aktiv']; + $keinportocheck = $daten['keinportocheck']; + $projektname = $this->app->erp->Projektdaten($projekt, 'abkuerzung'); + $obj->Einstellungen('JSON'); + $etikettendrucker = $obj->isEtikettenDrucker(); $drucker_export = $this->app->erp->GetDrucker(); - $this->app->Tpl->Set('EXPORT_DRUCKER',''); - if(!empty($drucker_export)){ - foreach($drucker_export as $k => $v) { - $this->app->Tpl->Add( - 'EXPORT_DRUCKER', - '' - ); - } - } + $drucker_export[0] = ''; + asort($drucker_export); + $this->app->Tpl->addSelect('EXPORT_DRUCKER', 'export_drucker', 'export_drucker', + $drucker_export, $daten['export_drucker']); $drucker_paketmarke = $this->app->erp->GetDrucker(); - - if($etikettendrucker) { - $etikettendruckerarr = $this->app->erp->GetEtikettendrucker(); - if($etikettendruckerarr) { - foreach($etikettendruckerarr as $k => $v) { - $drucker_paketmarke[$k] = $v; - } - } - } - $this->app->Tpl->Set('PAKETMARKE_DRUCKER',''); - if($drucker_paketmarke) { - foreach($drucker_paketmarke as $k => $v) { - $this->app->Tpl->Add( - 'PAKETMARKE_DRUCKER', - '' - ); - } - } + if($etikettendrucker) + $drucker_paketmarke = array_merge($drucker_paketmarke, $this->app->erp->GetEtikettendrucker()); + $drucker_paketmarke[0] = ''; + asort($drucker_paketmarke); + $this->app->Tpl->addSelect('PAKETMARKE_DRUCKER', 'paketmarke_drucker', 'paketmarke_drucker', + $drucker_paketmarke, $daten['paketmarke_drucker']); + $this->app->YUI->HideFormular('versandmail', array('0'=>'versandbetreff','1'=>'dummy')); - $this->app->Tpl->Add( - 'SELVERSANDMAIL', - ''); - $this->app->Tpl->Add( - 'SELVERSANDMAIL', - '' - ); - $this->app->Tpl->Add( - 'SELVERSANDMAIL', - '' - ); - - $geschaeftsbrief_vorlagen = $this->app->DB->SelectArr( - "SELECT gv.id, gv.subjekt, p.abkuerzung + $this->app->Tpl->addSelect('SELVERSANDMAIL', 'versandmail', 'versandmail', [ + 0 => 'Standardverhalten', + -1 => 'Keine Versandmail', + 1 => 'Eigene Textvorlage' + ], $daten['versandmail']); + + $geschaeftsbrief_vorlagen = $this->app->DB->SelectPairs( + "SELECT gv.id, CONCAT_WS(' - ', gv.subjekt, p.abkuerzung) as val FROM `geschaeftsbrief_vorlagen` AS `gv` LEFT JOIN `projekt` AS `p` ON gv.projekt = p.id ORDER by gv.subjekt" ); - if($geschaeftsbrief_vorlagen) { - foreach($geschaeftsbrief_vorlagen as $k => $v) { - $this->app->Tpl->Add( - 'SELGESCHAEFTSBRIEF_VORLAGE', - '' - ); - } - } - if($error === ''){ - $selectedModule = isset($daten['modul'])?$daten['modul']:''; + + $this->app->Tpl->addSelect('SELGESCHAEFTSBRIEF_VORLAGE', 'geschaeftsbrief_vorlage', + 'geschaeftsbrief_vorlage', $geschaeftsbrief_vorlagen, $daten['geschaeftsbrief_vorlage']); + + if(empty($error)){ + $selectedModule = $daten['modul'] ?? ''; } else { $selectedModule = $input['selmodul']; } - $this->app->Tpl->Set('SELMODUL', $this->VersandartenSelModul($selectedModule)); - - $this->app->Tpl->Set('BEZEICHNUNG', $error == ''?$bezeichnung:$input['bezeichnung']); - $this->app->Tpl->Set('TYP', $error == ''?$typ:$input['typ']); - $this->app->Tpl->Set('PROJEKT', $error == ''?$projektname:$input['projekt']); - if(($error == '' && $aktiv == 1) || ($error != '' && $input['aktiv'])){ + $this->app->Tpl->addSelect('SELMODUL', 'selmodul', 'selmodul', + $this->VersandartenSelModul(), $selectedModule); + $this->app->Tpl->Set('BEZEICHNUNG', empty($error)?$bezeichnung:$input['bezeichnung']); + $this->app->Tpl->Set('TYP', empty($error)?$typ:$input['typ']); + $this->app->Tpl->Set('PROJEKT', empty($error)?$projektname:$input['projekt']); + if((empty($error) && $aktiv == 1) || (!empty($error) && $input['aktiv'])){ $this->app->Tpl->Set('AKTIV', 'checked'); } - if(($error == '' && $keinportocheck == 1) || ($error != '' && $input['keinportocheck'])){ + if((empty($error) && $keinportocheck == 1) || (!empty($error) && $input['keinportocheck'])){ $this->app->Tpl->Set('KEINPORTOCHECK', 'checked'); } $this->app->YUI->AutoComplete('projekt', 'projektname', 1); - if(!empty($daten['modul'])) { - $beta = $this->getBetaShippingModules(); - if(in_array('versandarten_'.$daten['modul'], $beta)) { - $this->app->Tpl->Add('MESSAGE','
Dieses Modul ist noch im Beta Stadium.
'); - /** @var Appstore $appstore */ - $appstore = $this->app->erp->LoadModul('appstore'); - if($appstore !== null){ - $appstore->addBetaToHeadline(); - } - } - } + if ($obj->Beta ?? false) + $this->app->Tpl->Add('MESSAGE','
Dieses Modul ist noch im Beta Stadium.
'); $this->app->Tpl->Parse('PAGE', 'versandarten_edit.tpl'); } - /** - * @param string $shippingModule - * - * @return array - */ - public function getPrinterByModule($shippingModule = '') + protected function getPrinterByModule(Versanddienstleister $obj): array { - /** @var Versanddienstleister $obj */ - $obj = empty($shippingModule)?null:$this->loadModule($shippingModule); - $isLabelPrinter = $obj !== null - && method_exists($obj, 'isEtikettenDrucker') - && $obj->isEtikettenDrucker(); + $isLabelPrinter = $obj->isEtikettenDrucker(); $printer = $this->app->erp->GetDrucker(); - if(!is_array($printer)) { - $printer = []; - } - if(!$isLabelPrinter) { - return $printer; - } - $labelPrinter = $this->app->erp->GetEtikettendrucker(); - if(empty($labelPrinter)) { - return $printer; + if ($isLabelPrinter) { + $labelPrinter = $this->app->erp->GetEtikettendrucker(); + $printer = array_merge($printer ?? [], $labelPrinter ?? []); } - - foreach($labelPrinter as $k => $v) { - $printer[$k] = $v; - } - + natcasesort($printer); return $printer; } @@ -594,55 +303,44 @@ class Versandarten { * * @return array */ - public function getVuePrinterOptions($shippingModule = '') + protected function getVuePrinterOptions(string $shippingModule = ''): array { try{ - return VueUtil::keyValueArrayToVueOptions($this->getPrinterByModule($shippingModule)); + $obj = $this->loadModule($shippingModule); + return VueUtil::keyValueArrayToVueOptions($this->getPrinterByModule($obj)); } - catch(Exception $e) { + catch(Exception) { return []; } } - /** - * @return array - */ - public function getVueExportPrinterOptions() + public function getVueExportPrinterOptions(): array { $printer = $this->app->erp->GetDrucker(); - if(empty($printer)) { - return []; - } try{ - return VueUtil::keyValueArrayToVueOptions($printer); + return VueUtil::keyValueArrayToVueOptions($printer ?? []); } - catch(Exception $e) { + catch(Exception) { return []; } } - /** - * @return array - */ public function getVueProjects(): array { $projects = array_merge( [ 0 => '', ], $this->app->DB->SelectPairs( - sprintf( - 'SELECT p.id, p.abkuerzung + "SELECT p.id, p.abkuerzung FROM `projekt` AS `p` - WHERE p.geloescht = 0 %s - ORDER BY p.abkuerzung', - $this->app->erp->ProjektRechte() - ) + WHERE p.geloescht = 0 {$this->app->erp->ProjektRechte()} + ORDER BY p.abkuerzung" ) ); try{ return VueUtil::keyValueArrayToVueOptions($projects); } - catch(Exception $e) { + catch(Exception) { return []; } } @@ -656,7 +354,7 @@ class Versandarten { * * @return JsonResponse */ - public function getStep2Page($shippingModule, $shippingModuleName, $requiredForSubmit = null): JsonResponse + public function getStep2Page(string $shippingModule, string $shippingModuleName, ?array $requiredForSubmit = null): JsonResponse { if($requiredForSubmit === null) { $requiredForSubmit = $this->app->Secure->POST; @@ -688,12 +386,9 @@ class Versandarten { ); } - /** - * @return array - */ - public function getFeatureForm($shippingModule): array + public function getFeatureForm(string $shippingModule): array { - $ret = [ + return [ [ 'id' => 0, 'name' => 'projectGroup', @@ -734,59 +429,28 @@ class Versandarten { ], ], ]; - - return $ret; } + /** @noinspection PhpUnused */ public function VersandartenDelete(): void { - $id = $this->app->Secure->GetGET('id'); - $this->app->DB->Delete(sprintf('DELETE FROM `versandarten` WHERE `id` = %d LIMIT 1', $id)); + $id = (int)$this->app->Secure->GetGET('id'); + $this->app->DB->Delete("DELETE FROM `versandarten` WHERE `id` = $id LIMIT 1"); $msg = $this->app->erp->base64_url_encode("
Die Versandart wurde gelöscht!
"); $this->app->Location->execute("index.php?module=versandarten&action=list&msg=$msg"); } - /** - * @param string $val - * - * @return array|null - */ - public function getApps($val = ''): ?array + public function getApps(): ?array { - $val = (string)$val; - /** @var Appstore $appstore */ - $appstore = $this->app->loadModule('appstore'); - $module = $appstore->getAppsListWithPrefix('versandarten_'); - $modularr = $this->VersandartenSelModul('', true); - if($module) { - if(!empty($module['installiert'])) { - foreach($module['installiert'] as $k => $v) { - $module['installiert'][$k]['match'] = $appstore->match($v['Bezeichnung'], $val); - $module['installiert'][$k]['md5'] = md5($v['Bezeichnung']); - $found[] = $v['key']; - } - } - if(!empty($module['kauf'])) { - foreach($module['kauf'] as $k => $v) { - $module['kauf'][$k]['match'] = $appstore->match($v['Bezeichnung'], $val); - $module['kauf'][$k]['md5'] = md5($v['Bezeichnung']); - $found[] = $v['key']; - } - } - } - if($modularr) { - foreach($modularr as $k => $v) { - if(!isset($found) || !in_array('versandarten_'.$k,$found)) { - $found[] = 'versandarten_'.$k; - $module['installiert'][] = [ - 'md5'=>md5($v), - 'Bezeichnung'=>$v, - 'key'=>'versandarten_'.$k, - 'match'=>$appstore->match($v, $val), - 'Icon'=>'Icons_dunkel_9.gif' - ]; - } - } + $module = []; + $modularr = $this->VersandartenSelModul(); + foreach($modularr as $k => $v) { + $module['installiert'][$k] = [ + 'md5'=>md5($v), + 'Bezeichnung'=>$v, + 'key'=> $k, + 'Icon'=>'Icons_dunkel_9.gif' + ]; } if(!empty($module['installiert']) && count($module['installiert']) > 0) { $sort = null; @@ -800,14 +464,9 @@ class Versandarten { } - /** - * @var int $shippingMethodId - * - * @return JsonResponse - */ - public function getVueShippingMethodSuccessPage($shippingMethodId): JsonResponse + public function getVueShippingMethodSuccessPage(int $shippingMethodId): JsonResponse { - $succespage = [ + $successpage = [ 'type' => 'defaultPage', 'icon' => 'add-person-icon', 'headline'=> 'Versandart angelegt', @@ -822,7 +481,7 @@ class Versandarten { ]; return new JsonResponse( - ['page'=>$succespage] + ['page'=>$successpage] ); } @@ -839,7 +498,7 @@ class Versandarten { } $form = $obj->getCreateForm(); if(!empty($form)) { - $form[(!empty($form)?count($form):0) - 1]['link'] = [ + $form[(count($form)) - 1]['link'] = [ 'link' => 'index.php?module=versandarten&action=create&auswahl=' . $module, 'title' => 'Expertenmodus', ]; @@ -908,7 +567,7 @@ class Versandarten { } if($step < 2) { $shippingModuleName = $shippingModule; - if(strpos($shippingModuleName, 'versandarten_') === 0) { + if(str_starts_with($shippingModuleName, 'versandarten_')) { $shippingModuleName = substr($shippingModuleName, 13); } $shippingModuleName = str_replace('_', ' ', ucfirst($shippingModuleName)); @@ -946,7 +605,7 @@ class Versandarten { ); } elseif(!empty($createShippingResult['error'])) { - return new JsonResponse($createShippingResult, JsonResponse::HTTP_BAD_REQUEST); + return new JsonResponse($createShippingResult, Response::HTTP_BAD_REQUEST); } } @@ -955,7 +614,7 @@ class Versandarten { return $this->getVueShippingMethodSuccessPage((int)$shippingMethodId); } - return new JsonResponse($data, JsonResponse::HTTP_BAD_REQUEST); + return new JsonResponse($data, Response::HTTP_BAD_REQUEST); } @@ -963,7 +622,7 @@ class Versandarten { * @param int $shippingMethodId * @param null|array $post */ - public function saveCreateData($shippingMethodId, $post = null): void + public function saveCreateData(int $shippingMethodId, ?array $post = null): void { $shippingMethod = $this->app->DB->SelectRow( sprintf('SELECT * FROM `versandarten` WHERE `id` = %d', $shippingMethodId) @@ -983,7 +642,7 @@ class Versandarten { try { $vueFields = VueUtil::getInputNamesFromVuePages($form); } - catch(Exception $e) { + catch(Exception) { $vueFields = []; } foreach($vueFields as $input) { @@ -1005,84 +664,18 @@ class Versandarten { ); } - /** - * @return JsonResponse - */ - public function HandleSearchAjaxAction(): JsonResponse - { - $module = $this->getApps($this->app->Secure->GetPOST('val')); - $anzeigen = ''; - $ausblenden = ''; - if($module) { - if(isset($module['installiert'])) { - foreach($module['installiert'] as $k => $v) { - if($v['match']) - { - if($anzeigen !== '') - { - $anzeigen .= ';'; - } - $anzeigen .= 'm'.md5($v['Bezeichnung']); - }else{ - if($ausblenden !== '') - { - $ausblenden .= ';'; - } - $ausblenden .= 'm'.md5($v['Bezeichnung']); - } - } - } - if(isset($module['kauf'])) { - foreach($module['kauf'] as $k => $v) { - if($v['match']) { - if($anzeigen !== '') - { - $anzeigen .= ';'; - } - $anzeigen .= 'm'.md5($v['Bezeichnung']); - } - else{ - if($ausblenden !== '') - { - $ausblenden .= ';'; - } - $ausblenden .= 'm'.md5($v['Bezeichnung']); - } - } - } - } - $data = [ - 'anzeigen' => $anzeigen, - 'ausblenden' => $ausblenden, - ]; - - return new JsonResponse($data); - } - /** * @param string $shippingMethodModule * * @return array */ - public function createShippingMethodFromModuleName($shippingMethodModule): array + public function createShippingMethodFromModuleName(string $shippingMethodModule): array { - if(!$this->app->erp->ModulVorhanden($shippingMethodModule)) { - return [ - 'success'=>false, - 'error'=>'Modul nicht vorhanden' - ]; - } - $modules = $this->getApps(); - $modul = substr($shippingMethodModule,13); - $name = ucfirst($modul); - if($modules['installiert']) { - foreach($modules['installiert'] as $key => $installedModule) { - if($installedModule['key'] === $shippingMethodModule && $installedModule['Bezeichnung'] != '') { - $name = $installedModule['Bezeichnung']; - } - } - } - $type = $modul; + $obj = $this->loadModule($shippingMethodModule); + if ($obj === null) + return ['success' => false, 'error' => 'Modul nicht vorhanden']; + $name = $obj->name ?? ucfirst($shippingMethodModule); + $type = $shippingMethodModule; $i = 1; $originalName = $name; while( @@ -1094,7 +687,7 @@ class Versandarten { ) ) { $i++; - $type = $modul.'_'.$i; + $type = $shippingMethodModule.'_'.$i; $name = $originalName.' '.$i; } $versandmail = 0; @@ -1102,12 +695,9 @@ class Versandarten { $versandmail = 1; } $this->app->DB->Insert( - sprintf( "INSERT INTO `versandarten` (`bezeichnung`, `type`,`aktiv`, `geloescht`, `modul`,`ausprojekt`, `versandmail`, `einstellungen_json`) - VALUES ('%s','%s','1','0','%s','0', %d,'')", - $name, $type, $modul, $versandmail - ) + VALUES ('$name','$type','1','0','$shippingMethodModule','0', $versandmail,'')" ); $id = $this->app->DB->GetInsertID(); $this->app->erp->RunHook('versandarten_create', 1, $id); @@ -1117,6 +707,7 @@ class Versandarten { /** * @return JsonResponse|void + * @noinspection PhpUnused */ public function VersandartenCreate() { @@ -1128,81 +719,22 @@ class Versandarten { return $this->HandleSaveAssistantAjaxAction(); } - if($cmd === 'suche') { - return $this->HandleSearchAjaxAction(); - } - $module = $this->getApps($this->app->Secure->GetPOST('val')); - if($this->app->Secure->GetGET('auswahl')) { - //$bezeichnung = $this->app->Secure->GetPOST('bezeichnung'); - $auswahlmodul = $this->app->Secure->GetGET('auswahl'); - if($auswahlmodul === 'custom') { - $this->app->DB->Insert( - "INSERT INTO `versandarten` - (`bezeichnung`, `type`,`aktiv`, `geloescht`, `modul`,`ausprojekt`,`einstellungen_json`) - VALUES ('','','1','0','','0','')" - ); - $id = $this->app->DB->GetInsertID(); - $this->app->Location->execute('index.php?module=versandarten&action=edit&id='.$id); - } - if($this->app->erp->ModulVorhanden($auswahlmodul)) { - $ret = $this->createShippingMethodFromModuleName($auswahlmodul); - if(!empty($ret['id'])) { - $this->app->Location->execute('index.php?module=versandarten&action=edit&id='.$ret['id']); - } - $this->app->Location->execute('index.php?module=versandarten&action=create'); + $modulelist = $this->VersandartenSelModul(); + $auswahlmodul = $this->app->Secure->GetGET('auswahl'); + + if($auswahlmodul && isset($modulelist[$auswahlmodul])) { + $ret = $this->createShippingMethodFromModuleName($auswahlmodul); + if(!empty($ret['id'])) { + $this->app->Location->execute('index.php?module=versandarten&action=edit&id='.$ret['id']); } + $this->app->Location->execute('index.php?module=versandarten&action=create'); } - if($this->app->erp->isIoncube() && $this->app->Secure->GetPOST('testen')) { - $modul = $this->app->Secure->GetPOST('modul'); - if($modul) { - $testapp = $modul; - if(is_file(dirname(__DIR__).'/update.php')) { - $result = ''; - include_once(dirname(__DIR__).'/update.php'); - if($result === 'OK') { - $this->app->Tpl->Add( - 'MESSAGE', - '
Das Modul wurde zum Testen angefragt. Bitte Updaten Sie xentral in frühestens 10 Minuten um das Modul zu laden
' - ); - } - else{ - $this->app->Tpl->Add( - 'MESSAGE', - '
Es ist ein Fehler beim Updaten aufgetreten: '.$result.'
' - ); - } - } - } - } - elseif($this->app->erp->isIoncube()) { - $get = $this->app->Secure->GetGET('get'); - if(!empty($get) && !empty($module) && !empty($module['kauf'])) { - foreach($module['kauf'] as $k => $v) { - if($v['md5'] == $get) { - $mods = $this->app->erp->getAppList(); - foreach($mods as $k2 => $v2) { - if(md5($v2['Bezeichnung']) == $get) { - $this->app->Tpl->Add( - 'MESSAGE', - '
Bitte bestätigen:
' - ); - break; - } - } - } - } - } - } /** @var Appstore $appstore */ $appstore = $this->app->loadModule('appstore'); - $modullist = $this->GetApps(); + $modulelist = $this->GetApps(); $appstore->AddModuleHtml( - $modullist, 'versandarten_', 'index.php?module=versandarten&action=create&get=', - [ - 'title' => 'Custom', - 'link' => 'index.php?module=versandarten&action=create&auswahl=custom', - ] + $modulelist, '', 'index.php?module=versandarten&action=create&get=' ); $this->app->ModuleScriptCache->IncludeWidgetNew('ClickByClickAssistant'); $this->app->Tpl->Parse('PAGE', 'versandarten_neu.tpl'); @@ -1230,23 +762,77 @@ class Versandarten { } /** - * @param array $input + * @param string $module + * @param int $moduleId + * + * @return mixed|null */ - public function SetInput($input): void + public function loadModule(string $module, int $moduleId = 0) : ?Versanddienstleister { - $this->app->Tpl->Set('BEZEICHNUNG', $input['bezeichnung']); - $this->app->Tpl->Set('TYP', $input['typ']); - $this->app->Tpl->Set('PROJEKT', $input['projekt']); - if($input['aktiv']==1){ - $this->app->Tpl->Set('AKTIV', 'checked'); + if(str_starts_with($module, 'versandarten_')) { + $module = substr($module, 13); } - if($input['keinportocheck']==1){ - $this->app->Tpl->Set('KEINPORTOCHECK', 'checked'); + if(empty($module)) { + return null; + } + if(str_contains($module, '.') || str_contains($module, '/') || str_contains($module, '\\')) { + return null; } - if($input['ausprojekt']==1){ - $this->app->Tpl->Set('AUSPROJEKT', 'checked'); + $path = dirname(__DIR__).'/lib/versandarten/'.$module.'.php'; + if(!is_file($path)) { + return null; } + + include_once $path ; + $classname = 'Versandart_'.$module; + if(!class_exists($classname)) { + return null; + } + + return new $classname($this->app, $moduleId); } -} + /** + * Retrieve all Versandarten from lib/versandarten/ + * @return array + */ + function VersandartenSelModul() : array + { + $result = []; + $pfad = dirname(__DIR__).'/lib/versandarten'; + if(!is_dir($pfad)) + return $result; + $handle = opendir($pfad); + $files = []; + if($handle) { + while (($file = readdir($handle)) !== false) { + $files[] = $file; + } + } + closedir($handle); + + foreach($files as $file) { + if(str_starts_with($file, '.') || !str_ends_with($file, '.php') || !is_file($pfad.'/'.$file) + || str_ends_with($file, '.src.php')) + continue; + + $modul = str_replace('.php','',$file); + if(str_ends_with($modul, '_custom') + && !$this->app->DB->Select( + "SELECT `id` FROM `versandarten` WHERE `modul` = '".$this->app->DB->real_escape_string($modul)."' LIMIT 1" + ) + ) + continue; + + if($modul == '' || $modul=='rocketshipit') + continue; + + $obj = $this->loadModule($modul); + $result[$modul] = $obj->name ?? ucfirst($modul); + unset($obj); + } + + return $result; + } +} \ No newline at end of file