dgtlinf/payslip

Generate professional PDF payslips using salary data from dgtlinf/salary-calculator.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:Blade

pkg:composer/dgtlinf/payslip

v1.0.0 2025-10-06 19:46 UTC

This package is auto-updated.

Last update: 2025-10-06 19:54:12 UTC


README

Latest Version on Packagist License

Professional Laravel package for generating multilingual PDF payslips.
Built on top of dgtlinf/salary-calculator, this package provides an elegant way to render, stream, or download payslips directly from salary calculator data arrays.

πŸš€ Features

  • πŸ‡·πŸ‡Έ Country-specific providers (currently: Serbia)
  • 🧾 PDF generation via barryvdh/laravel-dompdf
  • 🌍 Multilingual templates (English & Serbian)
  • βš™οΈ Stream, download, or preview as HTML
  • 🧩 Simple integration with dgtlinf/salary-calculator
  • 🎨 Easily extendable with custom providers and templates

πŸ“¦ Installation

composer require dgtlinf/payslip

This will also install dependencies like dgtlinf/salary-calculator and barryvdh/laravel-dompdf.

🧩 Configuration

Publish the configuration and templates if you want to customize them:

php artisan vendor:publish --provider="Dgtlinf\Payslip\PayslipServiceProvider"

This will publish:

  • config/payslip.php
  • Blade templates under resources/views/vendor/payslip/
  • Translations under lang/vendor/payslip/

βš™οΈ Usage Example

A typical usage example integrating with dgtlinf/salary-calculator:

use Dgtlinf\SalaryCalculator\Facades\SalaryCalculator;
use Dgtlinf\Payslip\Facades\Payslip;

$months = [
    ['date' => '2025-01-01', 'gross' => 420000],
    ['date' => '2025-02-01', 'gross' => 410000],
    ['date' => '2025-03-01', 'gross' => 435000],
];

$rate = \Dgtlinf\SalaryCalculator\Facades\AverageHourlyRate::calculate($months, 'RS');

$employee = new \Dgtlinf\SalaryCalculator\Models\EmployeeProfile(
    firstName: 'Milan',
    lastName: 'Jovanović',
    address: 'Kralja Petra 10, Beograd',
    idNumber: '0101990123456',
    bankAccount: '160-123456789-01',
    position: 'Software Engineer',
);

$employer = new \Dgtlinf\SalaryCalculator\Models\EmployerProfile(
    name: 'Digital Infinity DOO',
    taxId: '110217311',
    registrationNumber: '21318507',
    address: 'Bulevar Kralja Petra I 89, Novi Sad',
    bankName: 'Raiffeisen Bank',
    bankAccount: '265-0001234567890-00'
);

$context = new \Dgtlinf\SalaryCalculator\Models\SalaryContext(
    2025,
    9,
    'RS',
    vacationDays: 0,
    sickDays: 0,
    sickLeaveFullPay: false,
    yearsInService: 8,
    avgHourlyRateLast12Months: null,
    employee: $employee,
    employer: $employer
);

// Create a calculator instance
$calc = SalaryCalculator::for($context);

// Generate a payslip from net salary
$result = $calc->fromNet(80000);

// Render as HTML (useful for previews)
return Payslip::for($result)->toHtml();

// Or download as PDF
return Payslip::for($result)->download();

// Or stream directly to browser
return Payslip::for($result)->locale('en')->setPaymentDate(now())->stream();

βš™οΈ Config Overview

config/payslip.php

return [
    'default_country' => 'RS',
    'providers' => [
        'RS' => \Dgtlinf\Payslip\Providers\RS\RSPayslipProvider::class,
    ],
    'default_template' => 'default',
    'filename_format' => '{slug}_{year}_{month}_payslip.pdf',
];

🧩 How It Works

  1. Payslip::for($salaryData) β€” accepts a salary result array from SalaryCalculator
  2. locale('en'|'sr') β€” sets the output language
  3. setPaymentDate(Carbon $date) β€” defines the payment date shown on the slip
  4. toHtml() / download() / stream() β€” output options

All salary data is taken directly from the SalaryCalculator array β€” no additional DTOs or models are required.

🧠 Extending

To add a new country provider, extend the BasePayslipProvider class and register it in the config:

'providers' => [
    'DE' => \App\Payslip\Providers\GermanyPayslipProvider::class,
]

Then place your template under:

resources/views/vendor/payslip/DE/default.blade.php

and translations under:

lang/vendor/payslip/de/{locale}/payslip.php

πŸ“‚ Directory Structure

src/
β”œβ”€β”€ PayslipServiceProvider.php
β”œβ”€β”€ PayslipGenerator.php
β”œβ”€β”€ Facades/Payslip.php
β”œβ”€β”€ Providers/
β”‚   β”œβ”€β”€ BasePayslipProvider.php
β”‚   └── RS/RSPayslipProvider.php
└── resources/
    β”œβ”€β”€ views/RS/default.blade.php
    └── lang/rs/{en,sr}/payslip.php

🏷 License

This package is open-sourced under the MIT License.

πŸ§‘β€πŸ’» Author

Digital Infinity d.o.o. Novi Sad
Bulevar Kralja Petra I 89, 21000 Novi Sad, Serbia
www.digitalinfinity.rs

Β© 2025 Digital Infinity. All rights reserved.