Reporte Análisis comercial


Empresa:

{{$company->name}}

Fecha:

{{date('Y-m-d')}}

Ruc:

{{$company->number}}

@if(!empty($records))
@foreach($categories as $item) @endforeach @foreach($records as $key => $value) @php $customer = $value; $documents = $value->documents; $country =($customer->country_id)? $customer->country->description : '' ; $district = ($customer->district_id)? '-'.$customer->district->description : '' ; $province = ($customer->province_id)? '-'.$customer->province->description : '' ; $department = ($customer->department_id)? '-'.$customer->department->description : '' ; $zone = "{$country} {$department} {$province} {$district}"; $first_document_date = ($documents) ? ($documents->first() ? $documents->first()->date_of_issue->format('d-m-Y'):null):null; $last_document_date = ($documents) ? ($documents->last() ? $documents->last()->date_of_issue->format('d-m-Y'):null):null; $difference_days = null; $quantity_visit = $documents->count(); $total = $documents->sum('total'); $acum_difference_days = 0; $acum_comparations = 0; if($first_document_date && $last_document_date){ for ($i=0; $i < $quantity_visit; $i++) { $doc = $documents[$i]; // dd($doc->date_of_issue); if(($i+1) < $quantity_visit){ $f_date = $doc->date_of_issue; $acum_difference_days += $f_date->diffInDays($documents[$i+1]->date_of_issue); $acum_comparations++; } } } $prom_difference_days = ($acum_comparations > 0) ? number_format($acum_difference_days / $acum_comparations,2) : 0; $contact_date = (Carbon\Carbon::parse($last_document_date))->addDays($prom_difference_days); $calculate_categories_count = array(); foreach ($categories as $item) { $calculate_categories_count[strtoupper($item)] = 0; } if($quantity_visit > 0){ foreach ($documents as $doc) { foreach ($doc->items as $it) { $item = App\Models\Tenant\Item::findOrFail($it->item_id); if($item->category){ $name_category = strtoupper($item->category->name); $calculate_categories_count[$name_category] = $calculate_categories_count[$name_category] + $it->quantity; } } } } @endphp @foreach($calculate_categories_count as $item) @endforeach @endforeach
# Cliente T. Doc - N° Doc Zona Celular Primera compra Ultima compra Tiempo promedio entre dos compras en dia Cantidad de Visita Total{{$item}} Contactar el
{{$loop->iteration}} {{$customer->name}} {{ $customer->identity_document_type->description}} - {{ $customer->number }}
{{$zone}} {{$customer->telephone}} {{$first_document_date}} {{$last_document_date}} {{$prom_difference_days}} {{$quantity_visit}} {{$total}}{{$item}}{{$contact_date->format('d-m-Y')}}
@else

No se encontraron registros.

@endif