mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-21 13:34:08 +00:00
Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Models\CompanyModule;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ExportsCustomersOrderLatestDate implements FromQuery, WithHeadingRow, WithMapping
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Marking',
|
||||
'Name',
|
||||
'Email',
|
||||
'Latest Order'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return CompanyModule::where('type', '=', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($company): array
|
||||
{
|
||||
$connection = $company->inviters()->withPivot('invitee_reference')->first();
|
||||
$marking = $connection ? $connection->pivot->invitee_reference:'';
|
||||
|
||||
$employees = $company->employees()->first();
|
||||
|
||||
$order = $company->orders()
|
||||
->join('packing_lists', 'packing_lists.owner_id', '=', 'orders.id')
|
||||
->join('transport_arrangements', 'transport_arrangements.owner_id', '=', 'packing_lists.id')
|
||||
->orderBy('drop_date', 'desc')
|
||||
->first();
|
||||
|
||||
return [
|
||||
$marking,
|
||||
$employees ? $employees->name : '',
|
||||
$employees ? $employees->email : '',
|
||||
$order ? $order->drop_date : ''
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,14 @@ class FetchesDataFromYDPortal
|
||||
* @param string $url
|
||||
* @param string $method
|
||||
* @param $body
|
||||
* @param bool $requiresAuthentication
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function clientRequest(string $url, string $method, $body){
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
|
||||
$body['apicode'] = env('YD_API_CODE');
|
||||
|
||||
$request = $client->requestAsync($method, $url, ['query' => $body]);
|
||||
|
||||
return $request->wait();
|
||||
|
||||
+10
-34
@@ -4,8 +4,6 @@ namespace App\Classes\Modules\PackingLists\Processors;
|
||||
|
||||
use App\Classes\Modules\Orders\Services\FetchesDataFromYDPortal;
|
||||
|
||||
use App\Models\Order;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -23,42 +21,20 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
/**
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @return void
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function execute(?Carbon $start = null, ?Carbon $end = null)
|
||||
{
|
||||
$start = $start ? $start : Carbon::now()->subMonths(2);
|
||||
public function execute(?Carbon $start = null, ?Carbon $end = null) {
|
||||
|
||||
$startLimit = Carbon::parse('01-12-2021');
|
||||
|
||||
if($start->isBefore($startLimit)){
|
||||
$start = $startLimit;
|
||||
}
|
||||
$orderRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/GetOrderList.ashx', 'GET', [
|
||||
'apicode' => '393b1cb4b8b37d09',
|
||||
'begintime' => '1633968000',
|
||||
'endtime' => '1639308222',
|
||||
]);
|
||||
|
||||
$end = $end ? $end : Carbon::now();
|
||||
|
||||
$orderRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/GetOrderList.ashx', 'GET', [
|
||||
'begintime' => $start->timestamp,
|
||||
'endtime' => $end->timestamp,
|
||||
]);
|
||||
|
||||
$rows = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest);
|
||||
|
||||
foreach($rows->data as $row){
|
||||
if (strpos($row->customerno, '/') !== false) { $customerno = explode('/', explode('CIEF/', $row->customerno)[1]); }
|
||||
if(strpos($row->customerno, '-') !== false){ $customerno = explode('-', explode('CIEF-', $row->customerno)[1]); }
|
||||
|
||||
$marking = $customerno[0];
|
||||
$orderNumber = $customerno[1];
|
||||
|
||||
$order = Order::where('reference', $orderNumber)->first();
|
||||
|
||||
if(!$order){
|
||||
continue;
|
||||
}
|
||||
|
||||
dump($order);
|
||||
}
|
||||
$order = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest);
|
||||
|
||||
dd($order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use App\Models\State;
|
||||
use App\Http\Helpers\General;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Classes\Jobs\CurlYdOrderListJob;
|
||||
use App\Jobs\CurlYdOrderListJob;
|
||||
|
||||
class CurlYdOrderListCommand extends Command
|
||||
{
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Exports;
|
||||
|
||||
|
||||
use App\Classes\Modules\Exports\Services\ExportsCustomersOrderLatestDate;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportCustomersToExcelController
|
||||
{
|
||||
public function export(ExportsCustomersOrderLatestDate $exportsCustomers, Request $request){
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
return $exportsCustomers->download('customer-latest-order-date.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Classes\Modules\PackingLists\Processors\FetchOrderListsFromYdPortalProcessor;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CurlYdOrderListJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
(App()->make(FetchOrderListsFromYdPortalProcessor::class))->execute();
|
||||
}
|
||||
}
|
||||
@@ -182,3 +182,5 @@ Route::get('/debug', function (){
|
||||
Route::get('/yd', function (){
|
||||
(App()->make(FetchOrderListsFromYdPortalProcessor::class))->execute();;
|
||||
});
|
||||
|
||||
Route::get('/export/customer-latest-order-date/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export');
|
||||
Reference in New Issue
Block a user