WIP: Sicherheitsnetz vor Phase-1-R\u00fcckbau
Enth\u00e4lt gemischt: Laravel-10-Upgrade + Phase 1 (Contacts-Modul, Duplicats-Commands, Soft-Delete+Merge-Fields) + Phase 2 Code-Umstellungen (inquiry_id, $table='contacts'/'inquiries') + Offers-Modul (Migrationen, Models, offer_id in Booking, offer-Disk in filesystems.php). Phase 2 + Offers werden im folgenden Commit nach dev/backups/phase2-offers-2026-04-17/ verschoben, damit der Workspace auf Phase-1-only (= Test-System-Stand) reduziert ist und direkt auf Live deploybar wird. Tarball-Backup zus\u00e4tzlich unter: ../backups-safety/workspace-pre-phase1-rollback-2026-04-17.tar.gz Made-with: Cursor
This commit is contained in:
parent
389d5d1820
commit
e3dc1afd8e
165 changed files with 21914 additions and 3516 deletions
|
|
@ -8,42 +8,37 @@ use App\Services\BookingImport;
|
|||
|
||||
class BookingController extends Controller
|
||||
{
|
||||
private $successStatus = 200;
|
||||
private $successKey = 'f6077389c9ce710e554763a5de02c8ec';
|
||||
|
||||
protected $draftRepo;
|
||||
private int $successStatus = 200;
|
||||
private string $successKey;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->successKey = config('app.success_key');
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
|
||||
$request = \Request::all();
|
||||
if(!isset($request['key']) || $request['key'] !== $this->successKey){
|
||||
if (!isset($request['key']) || $request['key'] !== $this->successKey) {
|
||||
return response()->json(['error' => "key"], 401);
|
||||
}
|
||||
$travel_booking = TravelBooking::find($request['travel_booking_id']);
|
||||
|
||||
//# vor testing
|
||||
//$travel_booking = TravelBooking::find(2922);
|
||||
if(!isset($travel_booking) || !$travel_booking){
|
||||
if (!$travel_booking) {
|
||||
return response()->json(['error' => 'no-booking-found'], $this->successStatus);
|
||||
}
|
||||
|
||||
$booking = BookingImport::importFrom($travel_booking);
|
||||
|
||||
$ret= [
|
||||
'url_v1' => make_old_url('/index.php/booking/'.$booking->id.'/edit'),
|
||||
$ret = [
|
||||
'url_v1' => make_old_url('/index.php/booking/' . $booking->id . '/edit'),
|
||||
'url_v3' => route('booking_detail', $booking->id),
|
||||
'lead_id' => $booking->lead_id
|
||||
// API-Feld bleibt `lead_id` aus Abwärtskompatibilität für API-Konsumenten;
|
||||
// Wert kommt nach Modul 3 Phase 2 aus booking.inquiry_id.
|
||||
'lead_id' => $booking->inquiry_id
|
||||
];
|
||||
return response()->json(['success' => "import", "ret" => $ret], $this->successStatus);
|
||||
//return response()->json(['error' => 'no-node'], $this->successStatus);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -400,10 +400,10 @@ class ReportController extends Controller
|
|||
$price = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
if(!in_array($v->booking->lead_id, $isset)){
|
||||
if(!in_array($v->booking->inquiry_id, $isset)){
|
||||
$price += $v->booking->isCanceled() ? $v->booking->getPriceCanceledRaw() : $v->booking->getPriceRaw();
|
||||
}
|
||||
$isset[] = $v->booking->lead_id;
|
||||
$isset[] = $v->booking->inquiry_id;
|
||||
|
||||
}
|
||||
return Util::_number_format($price);
|
||||
|
|
@ -416,8 +416,8 @@ class ReportController extends Controller
|
|||
$price = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
$price += in_array($v->booking->lead_id, $isset) ? 0 : $v->booking->getPriceTotalRaw();
|
||||
$isset[] = $v->booking->lead_id;
|
||||
$price += in_array($v->booking->inquiry_id, $isset) ? 0 : $v->booking->getPriceTotalRaw();
|
||||
$isset[] = $v->booking->inquiry_id;
|
||||
}
|
||||
return Util::_number_format($price);
|
||||
})
|
||||
|
|
@ -429,8 +429,8 @@ class ReportController extends Controller
|
|||
$proceeds = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
$proceeds += in_array($v->booking->lead_id, $isset) ? 0 : $v->booking->proceeds(true);
|
||||
$isset[] = $v->booking->lead_id;
|
||||
$proceeds += in_array($v->booking->inquiry_id, $isset) ? 0 : $v->booking->proceeds(true);
|
||||
$isset[] = $v->booking->inquiry_id;
|
||||
}
|
||||
return Util::_number_format($proceeds);
|
||||
/*$all = $query->get();
|
||||
|
|
@ -562,7 +562,7 @@ class ReportController extends Controller
|
|||
$ctemps[$export->booking->id][] = array(
|
||||
'Zähler' => $new ? $export->getCounter() : "",
|
||||
'MyJack Nr.' => $new ? $export->booking->merlin_order_number : "",
|
||||
'CRM Nr' => $new ? $export->booking->lead_id : "",
|
||||
'CRM Nr' => $new ? $export->booking->inquiry_id : "",
|
||||
'Kunde' => $new ? $export->booking->customer->name : "",
|
||||
'Reisedatum' => $new ? $export->booking->getStartDateFormat() : "",
|
||||
'Organisation' => $new ? ($export->booking->isCanceled() ? $export->booking->price_canceled : $export->booking->price) : "",
|
||||
|
|
@ -630,7 +630,7 @@ class ReportController extends Controller
|
|||
$ctemps[$export->booking->id][] = array(
|
||||
'Zähler' => $new ? $export->getCounter() : "",
|
||||
'MyJack Nr.' => $new ? $export->booking->merlin_order_number : "",
|
||||
'CRM Nr' => $new ? $export->booking->lead_id : "",
|
||||
'CRM Nr' => $new ? $export->booking->inquiry_id : "",
|
||||
'Kunde' => $new ? $export->booking->customer->name : "",
|
||||
'Reisedatum' => $new ? $export->booking->getStartDateFormat() : "",
|
||||
'Reiseland' => $new && $export->booking->travel_country ? $export->booking->travel_country->name : "",
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class ReportLeadsController extends Controller
|
|||
{
|
||||
|
||||
$query = Lead::with('customer')->with('sf_guard_user')->with('status')
|
||||
->select('lead.*');
|
||||
->select('inquiries.*');
|
||||
//->where('deleted_at', '=', null);
|
||||
|
||||
/*
|
||||
|
|
@ -132,7 +132,7 @@ class ReportLeadsController extends Controller
|
|||
// $q->select('sent_at')->where('sent_at', DB::raw("(select max('sent_at') customer_mails)")); //)
|
||||
})->orderBy(
|
||||
LeadMail::select('sent_at')
|
||||
->whereColumn('lead_id', 'lead.id')
|
||||
->whereColumn('lead_id', 'inquiries.id')
|
||||
->orderBy('sent_at', 'DESC')
|
||||
->limit(1)
|
||||
, $order);
|
||||
|
|
|
|||
|
|
@ -104,10 +104,10 @@ class ReportProviderController extends Controller
|
|||
$price = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
if(!in_array($v->booking->lead_id, $isset)){
|
||||
if(!in_array($v->booking->inquiry_id, $isset)){
|
||||
$price += $v->booking->isCanceled() ? $v->booking->getPriceCanceledRaw() : $v->booking->getPriceRaw();
|
||||
}
|
||||
$isset[] = $v->booking->lead_id;
|
||||
$isset[] = $v->booking->inquiry_id;
|
||||
|
||||
}
|
||||
return Util::_number_format($price);
|
||||
|
|
@ -120,8 +120,8 @@ class ReportProviderController extends Controller
|
|||
$price = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
$price += in_array($v->booking->lead_id, $isset) ? 0 : $v->booking->getPriceTotalRaw();
|
||||
$isset[] = $v->booking->lead_id;
|
||||
$price += in_array($v->booking->inquiry_id, $isset) ? 0 : $v->booking->getPriceTotalRaw();
|
||||
$isset[] = $v->booking->inquiry_id;
|
||||
}
|
||||
return Util::_number_format($price);
|
||||
})
|
||||
|
|
@ -133,8 +133,8 @@ class ReportProviderController extends Controller
|
|||
$proceeds = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
$proceeds += in_array($v->booking->lead_id, $isset) ? 0 : $v->booking->proceeds(true);
|
||||
$isset[] = $v->booking->lead_id;
|
||||
$proceeds += in_array($v->booking->inquiry_id, $isset) ? 0 : $v->booking->proceeds(true);
|
||||
$isset[] = $v->booking->inquiry_id;
|
||||
}
|
||||
return Util::_number_format($proceeds);
|
||||
/*$all = $query->get();
|
||||
|
|
@ -272,7 +272,7 @@ class ReportProviderController extends Controller
|
|||
$ctemps[$export->booking->id][] = array(
|
||||
'Zähler' => $new ? $export->getCounter() : "",
|
||||
'MyJack Nr.' => $new ? $export->booking->merlin_order_number : "",
|
||||
'CRM Nr' => $new ? $export->booking->lead_id : "",
|
||||
'CRM Nr' => $new ? $export->booking->inquiry_id : "",
|
||||
'Kunde' => $new ? $export->booking->customer->name : "",
|
||||
'Reisedatum' => $new ? $export->booking->getStartDateFormat() : "",
|
||||
'bis' => $new ? $export->booking->getEndDateFormat() : "",
|
||||
|
|
@ -346,7 +346,7 @@ class ReportProviderController extends Controller
|
|||
$ctemps[$export->booking->id][] = array(
|
||||
'Zähler' => $new ? $export->getCounter() : "",
|
||||
'MyJack Nr.' => $new ? $export->booking->merlin_order_number : "",
|
||||
'CRM Nr' => $new ? $export->booking->lead_id : "",
|
||||
'CRM Nr' => $new ? $export->booking->inquiry_id : "",
|
||||
'Kunde' => $new ? $export->booking->customer->name : "",
|
||||
'Reisedatum' => $new ? $export->booking->getStartDateFormat() : "",
|
||||
'bis' => $new ? $export->booking->getEndDateFormat() : "",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Request;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingFile;
|
||||
use App\Models\Participant;
|
||||
|
|
@ -60,11 +60,9 @@ class BookingController extends Controller
|
|||
return view('booking.detail', $data);
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
public function store(Request $request, $id)
|
||||
{
|
||||
// \Session()->flash('alert-save', '1');
|
||||
|
||||
$data = Request::all();
|
||||
$data = $request->all();
|
||||
|
||||
if ($id === "new") {
|
||||
$booking = new Booking();
|
||||
|
|
@ -308,11 +306,11 @@ class BookingController extends Controller
|
|||
return $redirect;
|
||||
}
|
||||
|
||||
public function loadModal()
|
||||
public function loadModal(Request $request)
|
||||
{
|
||||
$data = Request::all();
|
||||
$data = $request->all();
|
||||
$ret = "";
|
||||
if (Request::ajax()) {
|
||||
if ($request->ajax()) {
|
||||
if ($data['action'] === "new-customer-mail" || $data['action'] === "reply-customer-mail" || $data['action'] === "show-customer-mail" || $data['action'] === "edit-customer-mail") {
|
||||
$data['customers'] = [];
|
||||
if ($data['action'] === "new-customer-mail" && isset($data['booking_id']) && $booking = Booking::find($data['booking_id'])) {
|
||||
|
|
@ -374,7 +372,7 @@ class BookingController extends Controller
|
|||
$bookingFileRepo->_set('booking_id', $data['booking_id']);
|
||||
$bookingFileRepo->_set('dir', '/files/' . date('Y/m') . '/');
|
||||
$bookingFileRepo->_set('identifier', 'booking');
|
||||
return $bookingFileRepo->uploadFile(Request::all());
|
||||
return $bookingFileRepo->uploadFile($request->all());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -391,7 +389,7 @@ class BookingController extends Controller
|
|||
return redirect(route('booking_detail', [$booking->id]) . "#collapseBookingOrganisation");
|
||||
}
|
||||
|
||||
public function action($action, $id = false)
|
||||
public function action(Request $request, $action, $id = false)
|
||||
{
|
||||
|
||||
if (!$booking = Booking::find($id)) {
|
||||
|
|
@ -400,7 +398,7 @@ class BookingController extends Controller
|
|||
|
||||
if ($action === 'change_travel_dates') {
|
||||
$draftRepo = new DraftRepository($booking);
|
||||
$draftRepo->change_dates_drafts_from_booking(Request::get('change_travel_start_date'));
|
||||
$draftRepo->change_dates_drafts_from_booking($request->get('change_travel_start_date'));
|
||||
\Session()->flash('alert-success', __('Datum der Reise wurde geändert'));
|
||||
return redirect(route('booking_detail', [$booking->id]) . "#collapseBookingOrganisation");
|
||||
}
|
||||
|
|
|
|||
312
app/Http/Controllers/ContactController.php
Normal file
312
app/Http/Controllers/ContactController.php
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Contact;
|
||||
use App\Repositories\ContactRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
public function __construct(private readonly ContactRepository $contactRepo)
|
||||
{
|
||||
$this->middleware(['admin', '2fa']);
|
||||
}
|
||||
|
||||
public function index(): \Illuminate\View\View
|
||||
{
|
||||
return view('contact.index');
|
||||
}
|
||||
|
||||
public function detail(string $id): \Illuminate\View\View
|
||||
{
|
||||
if ($id === 'new') {
|
||||
$contact = new Contact();
|
||||
} else {
|
||||
$contact = Contact::with(['salutation', 'leads', 'bookings', 'mergedContacts'])
|
||||
->findOrFail((int) $id);
|
||||
}
|
||||
|
||||
return view('contact.detail', [
|
||||
'contact' => $contact,
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request, string $id): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$data = $request->except('_token');
|
||||
|
||||
if (!isset($data['action'])) {
|
||||
abort(403, 'keine Action');
|
||||
}
|
||||
|
||||
if ($id === 'new') {
|
||||
$contact = $this->contactRepo->createContact($data);
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('contact_detail', [$contact->id]) . '#collapseContactDetail');
|
||||
}
|
||||
|
||||
$this->contactRepo->updateContact($id, $data);
|
||||
\Session()->flash('alert-save', '1');
|
||||
|
||||
return redirect(route('contact_detail', [$id]) . '#collapseContactDetail');
|
||||
}
|
||||
|
||||
public function history(int $id): \Illuminate\View\View
|
||||
{
|
||||
$contact = Contact::with([
|
||||
'leads.sf_guard_user',
|
||||
'bookings.travel_country',
|
||||
'bookings.travel_agenda',
|
||||
'bookings.sf_guard_user',
|
||||
'bookings.lead',
|
||||
])->findOrFail($id);
|
||||
|
||||
return view('contact._detail_history', [
|
||||
'contact' => $contact,
|
||||
'modal' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$contact = Contact::withoutGlobalScope('not_merged')->findOrFail($id);
|
||||
|
||||
$leadsCount = $contact->leads()->count();
|
||||
$bookingCount = $contact->bookings()->count();
|
||||
|
||||
if ($leadsCount > 0 || $bookingCount > 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => sprintf(
|
||||
'Kontakt kann nicht gelöscht werden: %s%s vorhanden.',
|
||||
$leadsCount > 0 ? $leadsCount . ' Anfrage(n)' : '',
|
||||
$bookingCount > 0 ? ($leadsCount > 0 ? ' und ' : '') . $bookingCount . ' Buchung(en)' : ''
|
||||
),
|
||||
], 422);
|
||||
}
|
||||
|
||||
$contact->delete();
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function duplicates(): \Illuminate\View\View
|
||||
{
|
||||
$counts = [
|
||||
'HIGH' => $this->countDuplicateGroups('email'),
|
||||
'MEDIUM' => $this->countDuplicateGroups('name_birthdate'),
|
||||
'LOW' => $this->countDuplicateGroups('name_zip'),
|
||||
];
|
||||
|
||||
return view('contact.duplicates', compact('counts'));
|
||||
}
|
||||
|
||||
public function getDuplicateGroups(Request $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$confidence = strtoupper($request->input('confidence', 'HIGH'));
|
||||
|
||||
$groups = match ($confidence) {
|
||||
'HIGH' => $this->findByEmail(),
|
||||
'MEDIUM' => $this->findByNameBirthdate(),
|
||||
'LOW' => $this->findByNameZip(),
|
||||
default => [],
|
||||
};
|
||||
|
||||
// Für jede Gruppe die vollständigen Kontakt-Daten laden
|
||||
$result = [];
|
||||
foreach ($groups as $ids) {
|
||||
$contacts = Contact::withoutGlobalScopes()
|
||||
->withCount(['leads', 'bookings'])
|
||||
->whereIn('id', $ids)
|
||||
->whereNull('merged_into_id')
|
||||
->whereNull('deleted_at')
|
||||
->orderByRaw('FIELD(id, ' . implode(',', $ids) . ')')
|
||||
->get(['id', 'firstname', 'name', 'email', 'zip', 'city', 'phone', 'phonemobile', 'birthdate', 'created_at', 'updated_at']);
|
||||
|
||||
if ($contacts->count() < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'master' => $contacts->first(),
|
||||
'duplicates' => $contacts->skip(1)->values(),
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
public function merge(Request $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$masterId = (int) $request->input('master_id');
|
||||
$dupeId = (int) $request->input('duplicate_id');
|
||||
|
||||
if (!$masterId || !$dupeId || $masterId === $dupeId) {
|
||||
return response()->json(['success' => false, 'message' => 'Ungültige IDs.'], 422);
|
||||
}
|
||||
|
||||
$master = Contact::withoutGlobalScopes()->find($masterId);
|
||||
$dupe = Contact::withoutGlobalScopes()->find($dupeId);
|
||||
|
||||
if (!$master || !$dupe) {
|
||||
return response()->json(['success' => false, 'message' => 'Kontakt nicht gefunden.'], 404);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($masterId, $dupeId) {
|
||||
DB::table('inquiries')->where('customer_id', $dupeId)->update(['customer_id' => $masterId]);
|
||||
DB::table('booking')->where('customer_id', $dupeId)->update(['customer_id' => $masterId]);
|
||||
DB::table('customer_mails')->where('customer_id', $dupeId)->update(['customer_id' => $masterId]);
|
||||
DB::table('lead_mails')->where('customer_id', $dupeId)->update(['customer_id' => $masterId]);
|
||||
DB::table('contacts')->where('id', $dupeId)->update([
|
||||
'merged_into_id' => $masterId,
|
||||
'merged_at' => now(),
|
||||
]);
|
||||
});
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
// ── Duplikat-Hilfs-Queries ────────────────────────────────────────────────
|
||||
|
||||
private function countDuplicateGroups(string $type): int
|
||||
{
|
||||
return match ($type) {
|
||||
'email' => DB::table('contacts')->selectRaw('COUNT(*) as cnt')->whereNotNull('email')->where('email', '!=', '')->whereNull('merged_into_id')->whereNull('deleted_at')->groupBy('email')->havingRaw('COUNT(*) > 1')->get()->count(),
|
||||
'name_birthdate' => DB::table('contacts')->selectRaw('COUNT(*) as cnt')->whereNotNull('name')->whereNotNull('firstname')->whereNotNull('birthdate')->whereNull('merged_into_id')->whereNull('deleted_at')->groupBy('name', 'firstname', 'birthdate')->havingRaw('COUNT(*) > 1')->get()->count(),
|
||||
'name_zip' => DB::table('contacts')->selectRaw('COUNT(*) as cnt')->whereNotNull('name')->whereNotNull('firstname')->whereNotNull('zip')->where('zip', '!=', '')->whereNull('merged_into_id')->whereNull('deleted_at')->groupBy('name', 'firstname', 'zip')->havingRaw('COUNT(*) > 1')->get()->count(),
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
|
||||
private function findByEmail(): array
|
||||
{
|
||||
return DB::table('contacts')
|
||||
->selectRaw('GROUP_CONCAT(id ORDER BY updated_at DESC, id DESC) as ids')
|
||||
->whereNotNull('email')->where('email', '!=', '')
|
||||
->whereNull('merged_into_id')->whereNull('deleted_at')
|
||||
->groupBy('email')->havingRaw('COUNT(*) > 1')
|
||||
->pluck('ids')->map(fn ($s) => array_map('intval', explode(',', $s)))->all();
|
||||
}
|
||||
|
||||
private function findByNameBirthdate(): array
|
||||
{
|
||||
return DB::table('contacts')
|
||||
->selectRaw('GROUP_CONCAT(id ORDER BY updated_at DESC, id DESC) as ids')
|
||||
->whereNotNull('name')->whereNotNull('firstname')->whereNotNull('birthdate')
|
||||
->whereNull('merged_into_id')->whereNull('deleted_at')
|
||||
->groupBy('name', 'firstname', 'birthdate')->havingRaw('COUNT(*) > 1')
|
||||
->pluck('ids')->map(fn ($s) => array_map('intval', explode(',', $s)))->all();
|
||||
}
|
||||
|
||||
private function findByNameZip(): array
|
||||
{
|
||||
return DB::table('contacts')
|
||||
->selectRaw('GROUP_CONCAT(id ORDER BY updated_at DESC, id DESC) as ids')
|
||||
->whereNotNull('name')->whereNotNull('firstname')
|
||||
->whereNotNull('zip')->where('zip', '!=', '')
|
||||
->whereNull('merged_into_id')->whereNull('deleted_at')
|
||||
->groupBy('name', 'firstname', 'zip')->havingRaw('COUNT(*) > 1')
|
||||
->pluck('ids')->map(fn ($s) => array_map('intval', explode(',', $s)))->all();
|
||||
}
|
||||
|
||||
public function restore(int $id): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$contact = Contact::onlyTrashed()->withoutGlobalScope('not_merged')->findOrFail($id);
|
||||
$contact->restore();
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function getContacts(Request $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$showDeleted = $request->filled('filter_deleted');
|
||||
|
||||
// Reihenfolge wichtig: select() zuerst, dann withCount() — sonst überschreibt
|
||||
// select() die COUNT-Subqueries die withCount() per addSelect() eingetragen hat.
|
||||
$query = $showDeleted
|
||||
? Contact::onlyTrashed()->withoutGlobalScope('not_merged')->select('contacts.*')->withCount(['leads', 'bookings'])
|
||||
: Contact::select('contacts.*')->withCount(['leads', 'bookings']);
|
||||
|
||||
// Zusatzfilter aus der UI (werden als extra GET-Parameter gesendet)
|
||||
if ($request->filled('filter_has_leads')) {
|
||||
$query->has('leads');
|
||||
}
|
||||
if ($request->filled('filter_has_bookings')) {
|
||||
$query->has('bookings');
|
||||
}
|
||||
if ($request->filled('filter_has_email')) {
|
||||
$query->whereNotNull('email')->where('email', '!=', '');
|
||||
}
|
||||
|
||||
return DataTables::eloquent($query)
|
||||
->addColumn('action_edit', function (Contact $contact) use ($showDeleted) {
|
||||
if ($showDeleted) {
|
||||
return '';
|
||||
}
|
||||
return '<a href="' . route('contact_detail', [$contact->id]) . '" class="btn icon-btn btn-sm btn-primary" title="Öffnen"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('action_delete', function (Contact $contact) use ($showDeleted) {
|
||||
if ($showDeleted) {
|
||||
return '<button class="btn icon-btn btn-xs btn-success ml-1 btn-contact-restore" '
|
||||
. 'data-id="' . $contact->id . '" '
|
||||
. 'data-name="' . e($contact->fullName()) . '" '
|
||||
. 'title="Wiederherstellen"><span class="fa fa-undo"></span></button>';
|
||||
}
|
||||
return '<button class="btn icon-btn btn-xs btn-danger ml-1 btn-contact-delete" '
|
||||
. 'data-id="' . $contact->id . '" '
|
||||
. 'data-name="' . e($contact->fullName()) . '" '
|
||||
. 'title="Löschen"><span class="fa fa-trash"></span></button>';
|
||||
})
|
||||
->addColumn('id', function (Contact $contact) use ($showDeleted) {
|
||||
if ($showDeleted) {
|
||||
return '<span data-order="' . $contact->id . '">' . $contact->id . '</span>';
|
||||
}
|
||||
return '<a data-order="' . $contact->id . '" href="' . route('contact_detail', [$contact->id]) . '">' . $contact->id . '</a>';
|
||||
})
|
||||
->addColumn('raw_id', fn(Contact $contact) => $contact->id)
|
||||
->addColumn('leads_count', fn(Contact $contact) => $contact->leads_count)
|
||||
->addColumn('bookings_count', fn(Contact $contact) => $contact->bookings_count)
|
||||
->addColumn('deleted_at', fn(Contact $contact) => $contact->deleted_at?->format('d.m.Y H:i') ?? '')
|
||||
->orderColumn('id', 'customer.id $1')
|
||||
->orderColumn('deleted_at', 'customer.deleted_at $1')
|
||||
->filterColumn('id', function ($query, $keyword) {
|
||||
if ($keyword !== '') {
|
||||
$query->where('contacts.id', 'LIKE', '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('name', function ($query, $keyword) {
|
||||
if ($keyword !== '') {
|
||||
$query->where(function ($q) use ($keyword) {
|
||||
$q->where('name', 'LIKE', '%' . $keyword . '%')
|
||||
->orWhere('firstname', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filter(function ($query) use ($request) {
|
||||
$location = $request->input('filter_location');
|
||||
if ($location && $location !== '') {
|
||||
$query->where(function ($q) use ($location) {
|
||||
$q->where('zip', 'LIKE', '%' . $location . '%')
|
||||
->orWhere('city', 'LIKE', '%' . $location . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$search = $request->input('search.value');
|
||||
if ($search && $search !== '') {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('firstname', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('email', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('phone', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('phonemobile', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
}, true)
|
||||
->rawColumns(['action_edit', 'action_delete', 'id'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ class CustomerController extends Controller
|
|||
|
||||
public function getCustomers()
|
||||
{
|
||||
$query = Customer::with('salutation')->select('customer.*');
|
||||
$query = Customer::with('salutation')->select('contacts.*');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('action_edit', function (Customer $customer) {
|
||||
|
|
|
|||
|
|
@ -14,15 +14,6 @@ use Request;
|
|||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ class LeadController extends Controller
|
|||
|
||||
public function getLeads()
|
||||
{
|
||||
$query = Lead::with('customer')->with('sf_guard_user')->with('status')->select('lead.*');
|
||||
$query = Lead::with('customer')->with('sf_guard_user')->with('status')->select('inquiries.*');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('action_edit', function (Lead $lead) {
|
||||
|
|
@ -296,7 +296,7 @@ class LeadController extends Controller
|
|||
// $q->select('sent_at')->where('sent_at', DB::raw("(select max('sent_at') customer_mails)")); //)
|
||||
})->orderBy(
|
||||
LeadMail::select('sent_at')
|
||||
->whereColumn('lead_id', 'lead.id')
|
||||
->whereColumn('lead_id', 'inquiries.id')
|
||||
->orderBy('sent_at', 'DESC')
|
||||
->limit(1)
|
||||
, $order);
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class RequestController extends Controller
|
|||
wirte old where has state to new has travel_documents
|
||||
$bs = Booking::whereHas('arrangements', function($q){
|
||||
$q->where('state', '!=', NULL);
|
||||
})->where('lead_id', '!=', NULL)->where('new_drafts', 0)->get();
|
||||
})->where('inquiry_id', '!=', NULL)->where('new_drafts', 0)->get();
|
||||
|
||||
foreach ($bs as $b){
|
||||
$b->travel_documents = true;
|
||||
|
|
@ -101,7 +101,7 @@ class RequestController extends Controller
|
|||
private function getSearchRequests()
|
||||
{
|
||||
|
||||
$query = Booking::with('lead')->with('customer')->with('customer_mails')->with('customer_mails')->select('booking.*')->where('lead_id', '!=', NULL);
|
||||
$query = Booking::with('lead')->with('customer')->with('customer_mails')->with('customer_mails')->select('booking.*')->where('inquiry_id', '!=', NULL);
|
||||
|
||||
if (Request::get('full_firstname_search') != "") {
|
||||
$query->whereHas('customer', function ($q) {
|
||||
|
|
@ -241,7 +241,7 @@ class RequestController extends Controller
|
|||
}
|
||||
|
||||
if (Request::get('full_lead_id_search') != "") {
|
||||
$query->where('lead_id', 'LIKE', '%' . Request::get('full_lead_id_search') . '%');
|
||||
$query->where('inquiry_id', 'LIKE', '%' . Request::get('full_lead_id_search') . '%');
|
||||
}
|
||||
if (Request::get('full_booking_id_search') != "") {
|
||||
$query->where('id', 'LIKE', '%' . Request::get('full_booking_id_search') . '%');
|
||||
|
|
@ -398,10 +398,10 @@ class RequestController extends Controller
|
|||
return '<a data-order="' . $booking->id . '" href="' . make_old_url('booking/' . $booking->id . '/edit') . '" data-id="' . $booking->id . '">' . $booking->id . '</a>';
|
||||
})
|
||||
->addColumn('action_lead_edit', function (Booking $booking) {
|
||||
return '<a href="' . route('lead_detail', [$booking->lead_id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
return '<a href="' . route('lead_detail', [$booking->inquiry_id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('lead_id', function (Booking $booking) {
|
||||
return '<a data-order="' . $booking->lead_id . '" href="' . make_old_url('leads/' . $booking->lead_id . '/edit') . '" data-id="' . $booking->lead_id . '">' . $booking->lead_id . '</a>';
|
||||
return '<a data-order="' . $booking->inquiry_id . '" href="' . make_old_url('leads/' . $booking->inquiry_id . '/edit') . '" data-id="' . $booking->inquiry_id . '">' . $booking->inquiry_id . '</a>';
|
||||
})
|
||||
->addColumn('travel_country_id', function (Booking $booking) {
|
||||
return '<span data-order="' . ($booking->travel_country_id ? $booking->travel_country_id : 0) . '">' . ($booking->travel_country_id ? $booking->travel_country->name : "-") . '</span>';
|
||||
|
|
@ -523,7 +523,7 @@ class RequestController extends Controller
|
|||
}
|
||||
})
|
||||
*/
|
||||
->orderColumn('lead_id', 'lead_id $1')
|
||||
->orderColumn('lead_id', 'inquiry_id $1')
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('travel_country_id', 'travel_country_id $1')
|
||||
->orderColumn('travelagenda_id', 'travelagenda_id $1')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue