change posting date to invoice date for shipping portal when export invoice to autocount

This commit is contained in:
Steve Ng
2024-01-03 09:08:54 +08:00
parent 8d30467486
commit 02a37caf5a
2 changed files with 30 additions and 3 deletions
@@ -0,0 +1,22 @@
<?php
namespace App\Classes\General\Services;
class GuzzleShippingPortal
{
public function execute($route, $requests)
{
try {
$url = 'https://izyim.cief-malaysia.com/public/api/v1/'.$route;
$client = new \GuzzleHttp\Client(['verify' => false]);
$response = $client->request('GET', $url . '?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&'. $requests);
$body = $response->getBody();
$data = json_decode($body, true);
$payload = $data['payload'];
return $payload['data'];
} catch (\Exception $exception) {
Log::error($exception->getMessage());
return [];
}
}
}
@@ -19,6 +19,7 @@ use App\Classes\ValueObjects\Constants\TransactionType;
use Illuminate\Support\Facades\Log;
use App\Classes\General\Eloquent\ApplyFiltersToQuery;
use App\Models\StatementTransaction;
use App\Classes\General\Services\GuzzleShippingPortal;
class ExportsInvoiceTransactions implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
{
@@ -124,12 +125,11 @@ class ExportsInvoiceTransactions implements FromQuery, WithHeadings, WithHeading
$textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' Shipping Portal Respnose ' . json_encode($row) . PHP_EOL;
file_put_contents($errorFilePath, $textToAppend, FILE_APPEND);
Log::info('Error in Exports Invoice Transactions ' . $this->counter);
$transactionShippingPortal = $this->getFromShippingPortal($statementTransactionOwner->owner_id);
return [
'Transaction Not Found',
$transaction->posting_date->format('m/d/Y H:m'),
(isset($transactionShippingPortal['created_at']) ? Carbon::parse($transactionShippingPortal['created_at'])->format('m/d/Y H:m') : null),
$transaction->transaction_description.' - '.$transaction->transaction_description_2,
$statementTransactionOwner->system,
'',
@@ -167,4 +167,9 @@ class ExportsInvoiceTransactions implements FromQuery, WithHeadings, WithHeading
];
}
}
private function getFromShippingPortal($id){
$data = (new guzzleShippingPortal)->execute('transactions/mappable/query','filters={"id":'.$id.'}');
return (count($data) > 0 ? $data[0] : null);
}
}