export packing list

This commit is contained in:
glovetleong
2022-01-14 14:03:40 +08:00
parent 3ae4b019ce
commit 96131c5b33
4 changed files with 124 additions and 0 deletions
@@ -0,0 +1,92 @@
<?php
namespace App\Classes\Modules\Exports\Services;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\Container;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithMapping;
use Illuminate\Http\Request;
class ExportsContainerPackingList implements FromQuery, WithHeadingRow, WithMapping
{
use Exportable;
protected $id;
public function headings(): array
{
return [
'Marking',
'Refrence',
'Quantity',
'CBM',
'Status',
'Delivery Phone',
'Delivery Refrence',
'Delivery Address',
'Remark',
'Delivery Date'
];
}
public function setId($id)
{
$this->id = $id;
}
/**
* @return \Illuminate\Support\Collection|mixed
*/
public function query()
{
return Container::find($this->id)->packingLists();
}
/**
* @param Company $container
*
* @return array
*/
public function map($packing_list): array
{
$order = $packing_list->owner()->first();
$address = $order->addresses()->first();
$company = $order->companyModule()->first();
$connection = $company->inviters()->withPivot('invitee_reference')->first();
$marking = $connection ? $connection->pivot->invitee_reference:'';
$quantity = 0;
$cbm = 0;
foreach ($packing_list->packages()->get() as $key => $row) {
$quantity += $row->quantity;
$cbm += (($row->width / 100) * ($row->height / 100) * ($row->length / 100)) * $row->quantity;
}
$status = '';
if ($packing_list->transports()->count() > 0) {
$status = 'Delivery';
}
elseif ($packing_list->status == ApprovalStatus::SUSPENDED) {
$status = 'On Hold';
}
elseif ($packing_list->status != ApprovalStatus::SUSPENDED) {
$status = 'Release';
}
return [
$marking,
$order->reference,
$quantity,
$cbm,
$status,
$address->contacts()->first() ? $address->contacts()->first()->phone : 'n/a',
$address->contacts()->first() ? $address->contacts()->first()->reference : 'n/a',
$address->street_one . ' ' . $address->street_two . ' ' . $address->district->name . ' ' . $address->post_code . ' ' . $address->state->name . ' ' . $address->country->name,
$address->remarks()->first() ? $address->remarks()->first()->content : 'n/a',
$packing_list->transports()->first() ? $packing_list->transports()->current_schedule->eta : 'n/a'
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers\Exports;
use App\Classes\Modules\Exports\Services\ExportsContainerPackingList;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Excel;
class ExportContainerPackingListController
{
public function export(ExportsContainerPackingList $exportsContainerPackingList, Request $request) {
$token = Auth::fromUser(User::find(1));
$request->headers->set('Authorization', 'Bearer '.$token);
$exportsContainerPackingList->setId($request->route('id'));
return $exportsContainerPackingList->download('customer-container-packing-list.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
}
}
@@ -72,6 +72,11 @@
<div class="col-1 text-center">status</div>
<div class="col-3">Delivery Details</div>
<div class="col">Delivery Date</div>
<div class="col">
<div class="text-right">
<a :href="route('container.packaging_list.export', item.id)" target="_blank" class="btn btn-xs btn-primary pointer"><i class="fa fa-file-export m-r-5"></i>Export</a>
</div>
</div>
</div>
</div>
</div>
@@ -131,6 +136,12 @@
},
errorHandler(){
this.index = null;
},
exportContainer(id) {
console.log(id);
window.location.href = (this.route('container.export', $id));
}
},
mixins: [componentHandler]
+2
View File
@@ -184,3 +184,5 @@ Route::get('/yd', function (){
});
Route::get('/export/customer-latest-order-date/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export');
Route::get('/export/packing-list/{id}', 'Exports\ExportContainerPackingListController@export')->name('container.packaging_list.export');