Commit fe047235 authored by Muhammad Fahrul's avatar Muhammad Fahrul

add README.md

parent 65465a28
# Single Settlement Library
This libary creates a settlement based on the provided transaction data.
## Parameters
- `$data`: An array containing transaction data.
## Return Value
- An array containing the status of the operation, message, and data related to the created settlement.
## Description
- Initializes variables for status, message, and data.
- Validates the provided data and returns if it's empty.
- Validates the data and displays errors if any.
- Sorts the transactions by timestamp_format in descending order.
- Calculates the total number of transactions and total amount for specific bank codes.
- Generates content for the settlement file.
- Calculates total rows and banks for the settlement.
- Generates a settlement ID and filename.
- Returns an array with the status, message, and settlement data.
## Example Usage
```php
// Sample operator code
$operatorCode = '0053';
// Sample site code
$siteCode = '0053';
// Sample data array
$data = json_decode('[{"sam_report":"603298407594505900840D706E89064206151301000120F2030000AFB8000023012416510000000006000283386FC8","bank_code":"0","bank_mid":"0001","bank_tid":"06012800","card_no":"6032981000046656","timestamp":"10112023105758","amount":"0000000001","last_deposit":"0000000893"},{"sam_report":"603298407594505900840D706E89064206151301000120F2030000AFB8000023012416510000000006000283386FC8","bank_code":"0","bank_mid":"0001","bank_tid":"06012800","card_no":"6032981000046656","timestamp":"10112023105758","amount":"0000000001","last_deposit":"0000000893"},{"sam_report":"603298407594505900840D706E89064206151301000120F2030000AFB8000023012416510000000006000283386FC8","bank_code":"0","bank_mid":"0001","bank_tid":"06012800","card_no":"6032981000046656","timestamp":"10112023105758","amount":"0000000001","last_deposit":"0000000893"}]', true); // Define your data array here
// Create an instance of the class containing the create method
$instance = new SingleSettlement($operatorCode, $siteCode);
// Call the create method with the data
$result = $instance->create($data);
// Handle the result
if ($result['status']) {
echo "Settlement created successfully.";
} else {
echo "Failed to create settlement. Error: " . $result['message'];
}
......@@ -14,6 +14,7 @@ class SingleSettlement
$results['status'] = false;
$results['message'] = 'Empty data!';
$results['data'] = [];
if (empty($data)) return $results;
// Perform validation
$data = $this->validateData($data);
......@@ -207,6 +208,13 @@ class SingleSettlement
}
foreach ($data as $key => $item) {
$parsingSamReport = $this->parsingSamReport($item['sam_report']);
if (isset($item['bank_code'])) $parsingSamReport['bank_code'] = $item['bank_code'];
if (isset($item['bank_mid'])) $parsingSamReport['bank_mid'] = $item['bank_mid'];
if (isset($item['bank_tid'])) $parsingSamReport['bank_tid'] = $item['bank_tid'];
if (isset($item['card_no'])) $parsingSamReport['card_no'] = $item['card_no'];
if (isset($item['timestamp'])) $parsingSamReport['timestamp'] = $item['timestamp'];
if (isset($item['amount'])) $parsingSamReport['amount'] = $item['amount'];
if (isset($item['last_deposit'])) $parsingSamReport['last_deposit'] = $item['last_deposit'];
$data[$key] = array_merge($item, $parsingSamReport);
}
......@@ -281,15 +289,15 @@ class SingleSettlement
function parsingSamReport($sam_report)
{
$sam_report = explode(',', $sam_report);
$deductReport = $sam_report[0];
$bankCode = $sam_report[1];
$bankMid = $sam_report[2];
$bankTid = $sam_report[3];
$cardNo = $sam_report[4];
$timestamp = $sam_report[5];
$amount = $sam_report[6];
$lastDeposit = $sam_report[7];
$typeFW = !empty($sam_report[8]) ? $sam_report[8] : '1.0.0';
$deductReport = isset($sam_report[0]) ? $sam_report[0] : '';
$bankCode = isset($sam_report[1]) ? $sam_report[1] : '';
$bankMid = isset($sam_report[2]) ? $sam_report[2] : '';
$bankTid = isset($sam_report[3]) ? $sam_report[3] : '';
$cardNo = isset($sam_report[4]) ? $sam_report[4] : '';
$timestamp = isset($sam_report[5]) ? $sam_report[5] : '';
$amount = isset($sam_report[6]) ? $sam_report[6] : '';
$lastDeposit = isset($sam_report[7]) ? $sam_report[7] : '';
$typeFW = isset($sam_report[8]) ? $sam_report[8] : '1.0.0';
$results = [
'deduct_report' => $deductReport,
......
......@@ -8,7 +8,7 @@ echo PHP_EOL;
$siteCode = '00';
echo "Site Code : $siteCode";
echo PHP_EOL;
$data = json_decode('[{"report_sam":"603298407594505900840D706E89064206151301000120F2030000AFB8000023012416510000000006000283386FC8,0,0084,15130100,6032984075945059,23012024165100,0000001010,0000047279,R80.41uc"},{"report_sam":"603298100004665600030D706E86285851060128000120010000007D03000010112310575600060000E802038AF3F2,0,0001,06012800,6032981000046656,23012024105758,0000000001,0000000893,2.0.7"},{"report_sam":"603298407594505900840D706E8906420615130100012001000000A6BC0000220124151700000000000000834D1658,0,0084,15130100,6032984075945059,23012024151700,0000000001,0000048294,R80.41uc"},{"report_sam":"603298407594505900840D706E8906420615130100012001000000AEB80000230124190600000000070003832E39D4,0,0084,15130100,6032984075945059,23012024190600,0000000001,0000047278,R80.41uc"}]', true);
$data = json_decode('[{"sam_report":"603298407594505900840D706E89064206151301000120F2030000AFB8000023012416510000000006000283386FC8","bank_code":"0","bank_mid":"0001","bank_tid":"06012800","card_no":"6032981000046656","timestamp":"10112023105758","amount":"0000000001","last_deposit":"0000000893"},{"sam_report":"603298407594505900840D706E89064206151301000120F2030000AFB8000023012416510000000006000283386FC8","bank_code":"0","bank_mid":"0001","bank_tid":"06012800","card_no":"6032981000046656","timestamp":"10112023105758","amount":"0000000001","last_deposit":"0000000893"},{"sam_report":"603298407594505900840D706E89064206151301000120F2030000AFB8000023012416510000000006000283386FC8","bank_code":"0","bank_mid":"0001","bank_tid":"06012800","card_no":"6032981000046656","timestamp":"10112023105758","amount":"0000000001","last_deposit":"0000000893"}]', true);
$results = (new SingleSettlement($operatorCode, $siteCode))->create($data);
echo "Data : " . json_encode($data, JSON_PRETTY_PRINT);
echo PHP_EOL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment