mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-09-02 11:23:58 +00:00
import bank record
This commit is contained in:
@@ -5,25 +5,24 @@ namespace App\Classes\Modules\Imports\Services;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Company;
|
||||
|
||||
use App\Models\Transaction;
|
||||
use Maatwebsite\Excel\Concerns\ToModel;
|
||||
use Maatwebsite\Excel\Concerns\toCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithBatchInserts;
|
||||
use Maatwebsite\Excel\Concerns\WithValidation;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
|
||||
class ImportsBankRecord implements ToModel, WithHeadingRow, WithBatchInserts, WithValidation
|
||||
class ImportsBankRecord implements WithHeadingRow, WithBatchInserts, WithValidation
|
||||
{
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
public function model($row = [])
|
||||
public function collection($collection)
|
||||
{
|
||||
$date = Date::excelToDateTimeObject($row['date']);
|
||||
$credit = (float) $row['credit'];
|
||||
$date = Date::excelToDateTimeObject($collection['date']);
|
||||
$credit = (float) $collection['credit'];
|
||||
$systemReference = null;
|
||||
|
||||
$transaction = Transaction::whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
@@ -36,41 +35,17 @@ class ImportsBankRecord implements ToModel, WithHeadingRow, WithBatchInserts, Wi
|
||||
$systemReference = $transaction->pluck('owner.marking')->flatten()->implode(', ');
|
||||
}
|
||||
|
||||
$matches = $systemReference === $row['remarkreferences'] ? 'Yes' : 'No';
|
||||
$matches = $systemReference === $collection['remarkreferences'] ? 'Yes' : 'No';
|
||||
|
||||
echo '<tr>
|
||||
<td>'.$date->format('d-m-Y').'</td>
|
||||
<td>'.$row['description'].'</td>
|
||||
<td>'.$collection['description'].'</td>
|
||||
<td>'.$credit.'</td>
|
||||
<td>'.$systemReference.'</td>
|
||||
<td>'.$row['remarkreferences'].'</td>
|
||||
<td>'.$collection['remarkreferences'].'</td>
|
||||
<td>'.$matches.'</td>
|
||||
</tr>';
|
||||
// dump([
|
||||
// 'date' => $date->format('d-m-Y'),
|
||||
// 'credit' => $credit,
|
||||
// 'payments' =>
|
||||
// ]);
|
||||
|
||||
|
||||
// try {
|
||||
// preg_match_all('/([0-9]{3,4}[a-zA-Z]{3,4})/', $row['desc2'], $matches);
|
||||
//
|
||||
// foreach ($matches[0] as $match){
|
||||
// $reference = $match;
|
||||
// $debtor = $row['code'];
|
||||
// $company = Company::where('reference', $reference)->whereNull('debtor')->first();
|
||||
//
|
||||
// if ($company) {
|
||||
// $company->debtor = $debtor;
|
||||
// $company->update();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// } catch (\Exception $exception){
|
||||
// dd($exception);
|
||||
// }
|
||||
}
|
||||
|
||||
public function batchSize(): int
|
||||
|
||||
@@ -4,8 +4,14 @@ namespace App\Http\Controllers\Imports;
|
||||
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Imports\Services\ImportsBankRecord;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
|
||||
class ImportBankRecordController
|
||||
{
|
||||
@@ -16,7 +22,61 @@ class ImportBankRecordController
|
||||
*/
|
||||
public function import(Request $request) {
|
||||
// $object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports');
|
||||
Excel::import(new ImportsBankRecord(), 'daily_transaction_nov.xlsx');
|
||||
return [];
|
||||
|
||||
echo '<table>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Bank</th>
|
||||
<th>Description</th>
|
||||
<th>Credit</th>
|
||||
<th>Credit</th>
|
||||
<th>System Reference</th>
|
||||
<th>Human Reference</th>
|
||||
<th>Match?</th>
|
||||
</tr>';
|
||||
|
||||
$collection = Excel::toCollection(new ImportsBankRecord(), 'daily_transaction_nov.xlsx');
|
||||
|
||||
$branches = [
|
||||
0 => 'MBB Cyber',
|
||||
1 => 'MBB SS2'
|
||||
];
|
||||
|
||||
foreach ($collection as $key => $sheet){
|
||||
$branch = $branches[$key];
|
||||
foreach ($sheet as $row) {
|
||||
$date = Date::excelToDateTimeObject($row['date']);
|
||||
$credit = (float) $row['credit'];
|
||||
$systemReference = null;
|
||||
|
||||
$transaction = Transaction::whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->where('type', TransactionType::PAYMENT)->WhereDate('created_at', $date->format('Y-m-d'))
|
||||
->where('amount', '>=', $credit)->where('amount', '<', ($credit + 0.01))
|
||||
->get();
|
||||
|
||||
if(count($transaction)) {
|
||||
if($transaction->owner instanceof Booking::class){
|
||||
$systemReference = $transaction->pluck('owner.marking')->flatten()->implode(', ');
|
||||
}
|
||||
|
||||
if($transaction->owner instanceof Wallet::class){
|
||||
$systemReference = $transaction->bill_no;
|
||||
}
|
||||
}
|
||||
|
||||
$matches = $systemReference === $row['remarkreferences'] ? 'Yes' : 'No';
|
||||
|
||||
echo '<tr>
|
||||
<td>'.$date->format('d-m-Y').'</td>
|
||||
<td>'.$branch.'</td>
|
||||
<td>'.$row['description'].'</td>
|
||||
<td>'.$credit.'</td>
|
||||
<td>'.$systemReference.'</td>
|
||||
<td>'.$row['remarkreferences'].'</td>
|
||||
<td>'.$matches.'</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
// return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user