Skip to content

Commit

Permalink
finishing application test
Browse files Browse the repository at this point in the history
  • Loading branch information
checkitsedo committed Dec 22, 2019
1 parent 9625732 commit ea9d923
Show file tree
Hide file tree
Showing 17 changed files with 1,942 additions and 1 deletion.
19 changes: 18 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,22 @@
}
],
"minimum-stability": "stable",
"require": {}
"require": {
"apphostbd/laravel-fpdf": "^1.0"
},
"autoload": {
"psr-4": {
"Checkitsedo\\Esrpaymentslip\\": "packages/checkitsedo/esrpaymentslip/src/"
}
},
"extra": {
"laravel": {
"providers": [
"Checkitsedo\\Esrpaymentslip\\EsrpaymentslipServiceProvider"
],
"aliases": {
"EsrpaymentslipHelper": "Checkitsedo\\Esrpaymentslip\\Helpers\\EsrpaymentslipHelper"
}
}
}
}
165 changes: 165 additions & 0 deletions src/Controllers/EsrpaymentslipController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

namespace Checkitsedo\Esrpaymentslip\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Checkitsedo\Esrpaymentslip\Esrpaymentslip;
use EsrpaymentslipHelper;
use Checkitsedo\Esrpaymentslip\Pdf\Download;

class EsrpaymentslipController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$esrpaymentslips = Esrpaymentslip::orderBy('id', 'asc')->paginate(5);

return view('esrpaymentslips::esrpaymentslips.index',compact('esrpaymentslips'))
->with('i', (request()->input('page', 1) - 1) * 5);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('esrpaymentslips::esrpaymentslips.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$esrpaymentslip = new Esrpaymentslip();
$esrpaymentslip->bankName = $request->bankName;
$esrpaymentslip->bankCity = $request->bankCity;
$esrpaymentslip->bankingAccount = $request->bankingAccount;
$esrpaymentslip->bankingCustomerIdentification = $request->bankingCustomerIdentification;
$esrpaymentslip->recipientName = $request->recipientName;
$esrpaymentslip->recipientAddress = $request->recipientAddress;
$esrpaymentslip->recipientCity = $request->recipientCity;
$esrpaymentslip->payerLine1 = $request->payerLine1;
$esrpaymentslip->payerLine2 = $request->payerLine2;
$esrpaymentslip->payerLine3 = $request->payerLine3;
$esrpaymentslip->payerLine4 = $request->payerLine4;
$esrpaymentslip->amount = $request->amount;
$esrpaymentslip->invoiceNumber = $request->invoiceNumber;
$tempInvoiceNumber = $request->invoiceNumber;
$esrpaymentslip->referenceNumber = EsrpaymentslipHelper::calculateReference($tempInvoiceNumber);
$esrpaymentslip->save();

return redirect()->route('esrpaymentslips.index')
->with('success','ESR Payment Slip created successfully.');
}

/**
* Display the specified resource.
*
* @param \Checkitsedo\Esrpaymentslip $esrpaymentslip
* @return \Illuminate\Http\Response
*/
public function show(Esrpaymentslip $esrpaymentslip, $id)
{
$esrpaymentslip = Esrpaymentslip::find($id);
return view('esrpaymentslips::esrpaymentslips.show',compact('esrpaymentslip'));
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Esrpaymentslip $esrpaymentslip
* @return \Illuminate\Http\Response
*/
public function edit(Esrpaymentslip $esrpaymentslip, $id)
{
$esrpaymentslip = Esrpaymentslip::find($id);
return view('esrpaymentslips::esrpaymentslips.edit',compact('esrpaymentslip'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Esrpaymentslip $esrpaymentslip
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$request->validate([
'bankName' => 'required',
'bankCity' => 'required',
'bankingAccount' => 'required',
'bankingCustomerIdentification' => 'required',
'recipientName' => 'required',
'recipientAddress' => 'required',
'recipientCity' => 'required',
'payerLine1' => 'nullable',
'payerLine2' => 'nullable',
'payerLine3' => 'nullable',
'payerLine4' => 'nullable',
'amount' => 'required',
'invoiceNumber' => 'required',
'referenceNumber' => 'nullable',
]);

$tempInvoiceNumber = $request->invoiceNumber;

$update = [
'bankName' => $request->bankName,
'bankCity' => $request->bankCity,
'bankingAccount' => $request->bankingAccount,
'bankingCustomerIdentification' => $request->bankingCustomerIdentification,
'recipientName' => $request->recipientName,
'recipientAddress' => $request->recipientAddress,
'recipientCity' => $request->recipientCity,
'payerLine1' => $request->payerLine1,
'payerLine2' => $request->payerLine2,
'payerLine3' => $request->payerLine3,
'payerLine4' => $request->payerLine4,
'amount' => $request->amount,
'invoiceNumber' => $request->invoiceNumber,
'referenceNumber' => EsrpaymentslipHelper::calculateReference($tempInvoiceNumber),
];

Esrpaymentslip::where('id', $id)->update($update);

return redirect()->route('esrpaymentslips.index')
->with('success','ESR Payment Slip updated successfully');
}

/**
* Remove the specified resource from storage.
*
* @param \App\Esrpaymentslip $esrpaymentslip
* @return \Illuminate\Http\Response
*/
public function destroy(Esrpaymentslip $esrpaymentslip, $id)
{
$esrpaymentslip = Esrpaymentslip::find($id);
$esrpaymentslip->delete();

return redirect()->route('esrpaymentslips.index')
->with('success','ESR Payment Slip deleted successfully');
}

public function download($id)
{
$esrpaymentslip = Esrpaymentslip::find($id);

$download = new Download($esrpaymentslip);
$esr = $download->esr($esrpaymentslip);

exit;
}
}
25 changes: 25 additions & 0 deletions src/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Checkitsedo\Esrpaymentslip\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Checkitsedo\Esrpaymentslip\Home;

class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('esrpaymentslips::home');
}

public function admin()
{
return view('admin');
}
}
25 changes: 25 additions & 0 deletions src/Esrpaymentslip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Checkitsedo\Esrpaymentslip;

use Illuminate\Database\Eloquent\Model;

class Esrpaymentslip extends Model
{
protected $fillable = [
'bankName',
'bankCity',
'bankingAccount',
'bankingCustomerIdentification',
'recipientName',
'recipientAddress',
'recipientCity',
'payerLine1',
'payerLine2',
'payerLine3',
'payerLine4',
'amount',
'invoiceNumber',
'referenceNumber'
];
}
38 changes: 38 additions & 0 deletions src/EsrpaymentslipServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Checkitsedo\Esrpaymentslip;

use Illuminate\Support\ServiceProvider;

class EsrpaymentslipServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->make('Checkitsedo\Esrpaymentslip\Controllers\EsrpaymentslipController');
$this->loadViewsFrom(__DIR__.'/views','esrpaymentslips');

require_once __DIR__.'/Helpers/EsrpaymentslipHelper.php';
require_once __DIR__.'/Pdf/Download.php';
}

/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/routes.php');

$this->loadMigrationsFrom(__DIR__.'/database/migrations');

$this->publishes([
__DIR__.'/public/images' => public_path('checkitsedo/images'),
], 'public');
}
}
40 changes: 40 additions & 0 deletions src/Helpers/EsrpaymentslipHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
//packages/chceckitsedo/esrpaymentslip/src/Helpers/EsrpaymentslipHelper.php
namespace Checkitsedo\Esrpaymentslip\Helpers;

use Illuminate\Support\Facades\DB;

class EsrpaymentslipHelper
{
public static function calculateReference($text)
{
$invoiceNumber = $text;
$referenceNumber = $invoiceNumber;
$referenceNumber = preg_replace('/[^A-Za-z0-9]/', '', $referenceNumber);
$referenceNumber = substr($referenceNumber, 1);

$newReferenceNumber = "";
$array = str_split($referenceNumber);
foreach($array as $char)
{
if (is_numeric($char))
{
//
}
else
{
if ($char)
{
$char = strtolower($char);
$char = ord($char) - 96;
}
else
{
return 0;
}
}
$newReferenceNumber .= $char;
}
return $newReferenceNumber;
}
}
Loading

0 comments on commit ea9d923

Please sign in to comment.