PHP code example of innonazarene / dbm-salary-grade-parser
1. Go to this page and download the library: Download innonazarene/dbm-salary-grade-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
innonazarene / dbm-salary-grade-parser example snippets
use PhSalaryGrade\SalaryGradeParser;
// From a PDF file — extracts text then parses the salary table
$schedule = SalaryGradeParser::parseFile('/path/to/nbc601.pdf');
// Parse a specific table region (e.g. "First Class" in LGU circulars)
// The parser will skip everything until it finds the specified keyword
$firstClassSchedule = SalaryGradeParser::parseFile('/path/to/lbc165.pdf', 'First Class');
// $schedule is keyed by salary grade, each value is an array of step amounts
// [
// 1 => [14061, 14164, 14278, 14393, 14509, 14626, 14743, 14862],
// 2 => [14925, 15035, ...],
// ...
// 30 => [203200, 206401, ...],
// ]
// Access a specific grade + step
$grade15step3 = $schedule[15][2]; // step index is 0-based → 41006
// Or use the SalaryGrade lookup class with built-in NBC 601 data
use PhSalaryGrade\SalaryGrade;
$salary = SalaryGrade::get(15, 3); // → 41006
use PhSalaryGrade\SalaryGradeParser;
$text = file_get_contents('salary_text.txt');
$schedule = SalaryGradeParser::parse($text);
// Or with a keyword to target a specific table
$schedule = SalaryGradeParser::parse($text, 'Special Cities');
use PhSalaryGrade\PdfExtractor;
$text = PdfExtractor::extract('/path/to/nbc601.pdf');
echo $text; // raw text from all pages
use PhSalaryGrade\SalaryGrade;
// Get salary for Grade 15, Step 3
$salary = SalaryGrade::get(15, 3);
// → 41006
// Get salary for Grade 10, Step 1 (default)
$salary = SalaryGrade::get(10);
// → 25586
// Get all 8 steps for a grade
$steps = SalaryGrade::getSteps(24);
// → [1 => 98185, 2 => 99721, 3 => 101283, ..., 8 => 109431]
// Get the full salary schedule (all grades and steps)
$all = SalaryGrade::all();
// → [1 => [1 => 14061, ...], 2 => [...], ..., 30 => [...]]
// Find which grade/step a specific amount belongs to
$match = SalaryGrade::find(40208);
// → ['grade' => 15, 'step' => 1]
// Get all grade/step combinations within a salary range
$results = SalaryGrade::range(40000, 45000);
// → [['grade' => 15, 'step' => 1, 'amount' => 40208], ...]
// Convenience: min and max salaries
SalaryGrade::min(); // → 14061 (Grade 1, Step 1)
SalaryGrade::max(); // → 226319 (Grade 30, Step 8)
public function up()
{
Schema::create('salary_tranches', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('circular_no')->nullable();
$table->string('pdf_path')->nullable();
$table->string('csv_path')->nullable();
$table->json('parsed_data'); // Stores the array of salary grades
$table->timestamps();
});
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SalaryTranche extends Model
{
protected $fillable = ['title', 'circular_no', 'pdf_path', 'csv_path', 'parsed_data'];
protected $casts = [
'parsed_data' => 'array',
];
}
use App\Http\Controllers\SalaryTrancheController;
// Upload a PDF and generate a CSV
Route::post('/salary-tranches', [SalaryTrancheController::class, 'store']);
// Download the generated CSV for review
Route::get('/salary-tranches/{id}/download-csv', [SalaryTrancheController::class, 'downloadCsv']);
// Upload the reviewed CSV to finalize and save the data
Route::post('/salary-tranches/upload-csv', [SalaryTrancheController::class, 'storeCsv']);
namespace App\Http\Controllers;
use App\Models\SalaryTranche;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use PhSalaryGrade\SalaryGradeParser;
class SalaryTrancheController extends Controller
{
/**
* Step 1: Upload a PDF. The package parses it and generates a CSV.
*/
public function store(Request $request)
{
$request->validate([
'title' => 'rd/region if provided)
$parsedData = SalaryGradeParser::parseFile($fullPdfPath, $request->region);
// Generate a CSV for user review
$csvPath = 'salary-tranches/csvs/salary_tranche_' . time() . '.csv';
Storage::disk('public')->makeDirectory('salary-tranches/csvs');
$csvFile = fopen(Storage::disk('public')->path($csvPath), 'w');
fputcsv($csvFile, ['Salary Grade', 'Step 1', 'Step 2', 'Step 3', 'Step 4', 'Step 5', 'Step 6', 'Step 7', 'Step 8']);
foreach ($parsedData as $row) {
fputcsv($csvFile, [
$row['salary_grade'] ?? '', $row['step_1'] ?? '', $row['step_2'] ?? '',
$row['step_3'] ?? '', $row['step_4'] ?? '', $row['step_5'] ?? '',
$row['step_6'] ?? '', $row['step_7'] ?? '', $row['step_8'] ?? ''
]);
}
fclose($csvFile);
$tranche = SalaryTranche::create([
'title' => $request->title,
'circular_no' => $request->circular_no,
'pdf_path' => $pdfPath,
'csv_path' => $csvPath,
'parsed_data' => $parsedData,
]);
return response()->json([
'message' => 'PDF parsed and CSV generated.',
'download_csv_url' => url('/api/salary-tranches/' . $tranche->id . '/download-csv')
]);
}
/**
* Step 2: Download the generated CSV for manual review/correction.
*/
public function downloadCsv($id)
{
$tranche = SalaryTranche::findOrFail($id);
return Storage::disk('public')->download($tranche->csv_path, 'salary_table.csv');
}
/**
* Step 3: Upload the reviewed CSV. Saves data to DB and deletes the CSV automatically.
*/
public function storeCsv(Request $request)
{
$request->validate([
'title' => '
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.